NAME
get_vm_disk_info.sh - report record size and virtual/current size of a VM disk
SYNOPSIS
/opt/omnicube/sbin/get_vm_disk_info.sh zone_path disk
DESCRIPTION
get_vm_disk_info.sh prints, as a small JSON object on standard output, three facts about one virtual machine disk image: the recordsize of the ZFS dataset mounted at the zone path, and the virtual and allocated sizes of the image as reported by qemu-img. It is meant to be called by other tools and by the management interface rather than read by hand.
The dataset is found by matching zone_path against the mountpoint column of zfs list -H -o name,mountpoint, as an exact string comparison on that column alone, so a dot or another regular expression metacharacter in the path cannot match an unrelated dataset. A trailing slash on zone_path is ignored. The two sizes come from two pfexec qemu-img info runs, taking the third field of the virtual and disk lines respectively.
Output has the form
{
"recordsize": "128K",
"vitual_size": "200G",
"current_size": "37G"
}
with no trailing newline. Note the spelling of the second key, which is part of the interface.
Unlike the other tools in this suite, this script does not source /opt/omnicube/lib/common/utils.sh. It sets its own PATH to /usr/sbin:/sbin:/opt/ooce/sbin:/usr/bin:/opt/ooce/bin and carries a standalone copy of the run-level guard: it exits 0 without output when the host is at run level 0, 1, 5, 6, S or s, or when /etc/nologin exists, unless OC_IGNORE_RUNLEVEL is set. It performs no cluster operation and no ssh.
OPERANDS
This command takes no options.
EXAMPLES
Example 1: inspect the boot disk of a bhyve zone
get_vm_disk_info.sh /zones/zbeio01 \\
/zones/zbeio01/disks/disk0.raw
Example 2: extract a single value
get_vm_disk_info.sh /zones/zfoo /zones/zfoo/disks/disk0.raw \\
| ggrep current_size
EXIT STATUS
FILES
ENVIRONMENT
SECURITY
qemu-img is invoked through pfexec, because VM disk images live under root-owned zone paths and are not readable by an ordinary user. That makes the command a privileged read, so disk is constrained to an existing regular file below zone_path, with .. rejected, to keep it from being used as an arbitrary-file-read-as-root primitive against, for example, /etc/shadow or a raw device. The pfexec grant comes from the root-equivalent OmniCube Administration profile in /etc/security/exec_attr.d/omnicube.
SEE ALSO
omnicube(7), create_iscsi_lun.sh(8), create_zone_pool.sh(8), manage_zone.sh(8), qemu-monitor-command(8), zone_monitor.sh(8).
NOTES
The recordsize reported is that of the dataset mounted at zone_path, not of the dataset the image itself sits in; on a layout where the disks live in a separate child dataset the two can differ.
Nothing is quoted or escaped in the JSON output, and no check is made that qemu-img actually returned a value. If a size cannot be determined the corresponding key is emitted with an empty value rather than the command failing.