Skip to content

Commit

Permalink
Fix disk "Used" value
Browse files Browse the repository at this point in the history
Showing "allocation" in the UI doesn't make much sense. According to
the manpage [1] it describes "offset of highest written sector in
bytes". Showing the "physical size of source file in bytes" is much more
useful.

Thanks to @shodanshok for figuring this out!

Fixes cockpit-project#1423

[1] https://www.libvirt.org/manpages/virsh.html
  • Loading branch information
martinpitt committed Feb 28, 2024
1 parent 9759a39 commit 9d20f71
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/components/storagePools/storagePool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export const getStoragePoolRow = ({ storagePool, vms, onAddErrorNotification })
{ storagePool.name }
</span>
);
const allocation = parseFloat(convertToUnit(storagePool.allocation, units.B, units.GiB).toFixed(2));
const physical = parseFloat(convertToUnit(storagePool.physical, units.B, units.GiB).toFixed(2));
const capacity = parseFloat(convertToUnit(storagePool.capacity, units.B, units.GiB).toFixed(2));
const sizeLabel = String(cockpit.format("$0 / $1 GiB", allocation, capacity));
const sizeLabel = String(cockpit.format("$0 / $1 GiB", physical, capacity));
const size = (
<Progress value={Number(storagePool.allocation)}
<Progress value={Number(storagePool.physical)}
min={0}
max={Number(storagePool.capacity)}
label={sizeLabel}
Expand Down
4 changes: 2 additions & 2 deletions src/components/storagePools/storagePoolVolumesTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export class StoragePoolVolumesTab extends React.Component {
const rows = volumes
.sort(sortFunction)
.map(volume => {
const allocation = parseFloat(convertToUnit(volume.allocation, units.B, units.GiB).toFixed(2));
const physical = parseFloat(convertToUnit(volume.physical, units.B, units.GiB).toFixed(2));
const capacity = parseFloat(convertToUnit(volume.capacity, units.B, units.GiB).toFixed(2));
const columns = [
{ title: <div id={`${storagePoolIdPrefix}-volume-${volume.name}-name`}>{volume.name}</div> },
{ title: <div id={`${storagePoolIdPrefix}-volume-${volume.name}-usedby`}>{(isVolumeUsed[volume.name] || []).join(', ')}</div>, },
{ title: <div id={`${storagePoolIdPrefix}-volume-${volume.name}-size`}>{`${allocation} / ${capacity} GB`}</div> },
{ title: <div id={`${storagePoolIdPrefix}-volume-${volume.name}-size`}>{`${physical} / ${capacity} GB`}</div> },
];
return { columns, selected: volume.selected, props: { key: volume.name } };
});
Expand Down
8 changes: 4 additions & 4 deletions src/components/vm/disks/vmDisksCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class VmDisksCardLibvirt extends React.Component {
if (!vm.disks[target] || (vm.disks[target].type !== 'volume' && !vm.disksStats[target])) {
return false; // not yet retrieved, can't decide about disk stats support
}
return vm.disks[target].type == 'volume' || !isNaN(vm.disksStats[target].capacity) || !isNaN(vm.disksStats[target].allocation);
return vm.disks[target].type == 'volume' || !isNaN(vm.disksStats[target].capacity) || !isNaN(vm.disksStats[target].physical);
});
}

Expand All @@ -104,11 +104,11 @@ export class VmDisksCardLibvirt extends React.Component {
prepareDiskData(disk, diskStats, idPrefix, storagePools) {
diskStats = diskStats || {};

let used = diskStats.allocation;
let used = diskStats.physical;
let capacity = diskStats.capacity;

/*
* For disks of type `volume` allocation and capacity stats are not
* For disks of type `volume` physical and capacity stats are not
* fetched with the virConnectGetAllDomainStats API so we need to get
* them from the volume.
*
Expand All @@ -125,7 +125,7 @@ export class VmDisksCardLibvirt extends React.Component {

if (volume) {
capacity = volume.capacity;
used = volume.allocation;
used = volume.physical;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libvirt-xml-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,8 @@ export function parseStoragePoolDumpxml(connectionName, storagePoolXml, objPath)
result.capacity = storagePoolElem.getElementsByTagName('capacity')[0].childNodes[0].nodeValue;
result.available = storagePoolElem.getElementsByTagName('available')[0].childNodes[0].nodeValue;
result.allocation = storagePoolElem.getElementsByTagName('allocation')[0].childNodes[0].nodeValue;
const physicalElem = storagePoolElem.getElementsByTagName('physical')[0];
result.physical = physicalElem ? physicalElem.childNodes[0].nodeValue : NaN;

// Fetch path property if target is contained for this type of pool
if (['dir', 'fs', 'netfs', 'logical', 'disk', 'iscsi', 'scsi', 'mpath', 'zfs'].indexOf(result.type) > -1) {
Expand Down

0 comments on commit 9d20f71

Please sign in to comment.