diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 96b4a7b1663d64509f88829434448271a733ff82..02ed044e41ec27ff7bf0d310ced650662386b1de 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -996,6 +996,10 @@ static const vshCmdOptDef opts_vol_info[] = { .type = VSH_OT_BOOL, .help = N_("sizes are represented in bytes rather than pretty units") }, + {.name = "physical", + .type = VSH_OT_BOOL, + .help = N_("return the physical size of the volume in allocation field") + }, {.name = NULL} }; @@ -1005,14 +1009,25 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) virStorageVolInfo info; virStorageVolPtr vol; bool bytes = vshCommandOptBool(cmd, "bytes"); + bool physical = vshCommandOptBool(cmd, "physical"); bool ret = true; + int rc; + unsigned int flags = 0; if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; vshPrint(ctl, "%-15s %s\n", _("Name:"), virStorageVolGetName(vol)); - if (virStorageVolGetInfo(vol, &info) == 0) { + if (physical) + flags |= VIR_STORAGE_VOL_GET_PHYSICAL; + + if (flags) + rc = virStorageVolGetInfoFlags(vol, &info, flags); + else + rc = virStorageVolGetInfo(vol, &info); + + if (rc == 0) { double val; const char *unit; @@ -1028,11 +1043,18 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) } if (bytes) { - vshPrint(ctl, "%-15s %llu %s\n", _("Allocation:"), - info.allocation, _("bytes")); + if (physical) + vshPrint(ctl, "%-15s %llu %s\n", _("Physical:"), + info.allocation, _("bytes")); + else + vshPrint(ctl, "%-15s %llu %s\n", _("Allocation:"), + info.allocation, _("bytes")); } else { val = vshPrettyCapacity(info.allocation, &unit); - vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit); + if (physical) + vshPrint(ctl, "%-15s %2.2lf %s\n", _("Physical:"), val, unit); + else + vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit); } } else { ret = false; diff --git a/tools/virsh.pod b/tools/virsh.pod index 940c64611c5d679cbdb163770756c8c5e1336b63..ef9122379321efd0a21b65c38497ff3ba2156db9 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3879,13 +3879,17 @@ is in. I is the name or key or path of the volume to output the XML of. =item B [I<--pool> I] I -[I<--bytes>] +[I<--bytes>] [I<--physical>] Returns basic information about the given storage volume. I<--pool> I is the name or UUID of the storage pool the volume is in. I is the name or key or path of the volume to return information for. If I<--bytes> is specified the sizes are not -converted to human friendly units. +converted to human friendly units. If I<--physical> is specified, then the host +physical size is returned and displayed instead of the allocation value. The +physical value for some file types, such as qcow2 may have a different (larger) +physical value than is shown for allocation. Additionally sparse files will +have different physical and allocation values. =item B [I<--pool> I] [I<--details>]