In list context, the file_size_info() function in Plugin.pm would return 0 for the size of a subvol directory, but in scalar context 1. As reported in the community forum [0], the change in commit e50dde0 ("volume export: rely on storage plugin's format"), changing the caller in volume_export() to scalar context exposed the inconsistency in the return value for the size. This led to breakage of migration with unsized btrfs subvolumes.
Align the returned values to avoid such surprises. Caller that would treat 0 as an error should use list context and check if it is a subvol, if they are able to handle them. NOTE: it is not possible to attach either a subvol, or a volume with zero size to a VM. Existing callers of file_size_info() do not break with this change: GuestImport/OVF.pm - parse_ovf() + API/Qemu.pm - create_disks(): Doesn't support subvol directories, dies if size is 0. Storage/Plugin.pm - create_base() + Storage/{BTRFS,}Plugin.pm - list_images(): Checks for definedness of $size. Storage/{BTRFS,ESXi,}Plugin.pm - volume_size_info(): Transitive, see below. Storage/Plugin.pm - volume_export(): Regressed by commit e50dde0, this change will restore previous behavior. Storage/Plugin.pm - volume_export_formats() + GuestImport.pm - extract_disk_from_import_file() + Storage.pm - assert_iso_content(): Doesn't use the result. CLI/qm.pm - importdisk: Dies early if source is a directory. CLI/qm.pm - importovf: Calls parse_ovf() earlier. Existing callers of volume_size_info() do not break with this change: API2/Storage/Content.pm - info: Uses list context, not affected by change. QemuMigrate.pm - scan_local_volumes() + API2/Qemu.pm - create_disks(), first call: Uses list context, not affected by change, does not support subvol directories. API2/Qemu.pm - create_disks(), second call + API2/Qemu.pm - import_from_volid(): Doesn't support subvol directories, dies if size is 0. API2/Qemu.pm - resize_vm + VZDump/QemuServer.pm - prepare() + QemuServer.pm - clone_disk() + QemuServer.pm - create_efidisk(): Doesn't support subvol directories (see NOTE above), but would not die directly if size is 0. (In case of create_efidisk(), the size of the just created disk is queried.) API2/LXC.pm - resize_vm: For directory plugins, the subsequent call to resize_volume() fails with "can't resize this image format". For BTRFS, quotas are currently not supported and the call to resize_volume() fails with "failed to get btrfs subvolume ID from:". This is because the btrfs 'subvol show' command is invoked with '-q', so there is no output. Even if it would work, it would be more correct to use 0 as the current size to add to the new quota rather than 1. LXC/Config.pm - rescan_volume(): This will happily use size=1 from before this change, but that is not correct. A subsequent 'pct rescan' will correct the size to 0. It is only used when hotplugging an existing subvol directory. LXC.pm - copy_volume(): This will happily use size=1 from before this change, but that is not correct and will lead to failure "mkfs.ext4: Device size reported to be zero.". That is because with non-zero size, the allocation of the volume for the clone will be done with 'raw' format by the alloc_disk() helper in LXC.pm rather than 'subvol'. This change will make cloning containers with unsized subvol directories possible. QemuServer/Cloudinit.pm - commit_cloudinit_disk(): Doesn't support subvol directories (see NOTE above), will allocate a new volume when size is 0. [0]: https://forum.proxmox.com/threads/162943/ Fixes: e50dde0 ("volume export: rely on storage plugin's format") Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- Changes in v2: * Improve commit message regarding clone src/PVE/Storage/Plugin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 65cf43f..ce1530e 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1007,7 +1007,7 @@ sub file_size_info { if (S_ISDIR($st->mode)) { $handle_error->("expected format '$file_format', but '$filename' is a directory\n") if $file_format && $file_format ne 'subvol'; - return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 1; + return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 0; } elsif ($file_format && $file_format eq 'subvol') { $handle_error->("expected format '$file_format', but '$filename' is not a directory\n"); } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel