From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id D8BC11FF13A for ; Wed, 22 Jul 2026 14:45:43 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id A7AFD214DE; Wed, 22 Jul 2026 14:45:43 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 22 Jul 2026 14:45:08 +0200 Message-Id: From: "Daniel Kral" To: "Thomas Ellmenreich" , Subject: Re: [PATCH qemu-server v2 1/2] refactor checks for absolute path as drive X-Mailer: aerc 0.21.0-147-g43ac7b685014-dirty References: <20260722095251.89606-1-t.ellmenreich@proxmox.com> <20260722095251.89606-2-t.ellmenreich@proxmox.com> In-Reply-To: <20260722095251.89606-2-t.ellmenreich@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784724280803 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.249 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ISPRJNVRHC24GJBDOHILUFDS7Y5NU5IL X-Message-ID-Hash: ISPRJNVRHC24GJBDOHILUFDS7Y5NU5IL X-MailFrom: d.kral@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Thanks for the quick v2! On Wed Jul 22, 2026 at 11:52 AM CEST, Thomas Ellmenreich wrote: > Previously there were a bunch of separate checks for whether a drive was > an absolute path. These have been refactored to use two checks in > QemuServer::Drive and QemuServer::Helpers. > > Signed-off-by: Thomas Ellmenreich > --- > src/PVE/QemuConfig.pm | 2 +- > src/PVE/QemuMigrate.pm | 2 +- > src/PVE/QemuServer.pm | 20 ++++++++------------ > src/PVE/QemuServer/Blockdev.pm | 4 ++-- > src/PVE/QemuServer/Drive.pm | 8 +++++++- > src/PVE/QemuServer/Helpers.pm | 5 +++++ > 6 files changed, 24 insertions(+), 17 deletions(-) > [ snip ] > diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm > index 191ae549..ce832c8e 100644 > --- a/src/PVE/QemuServer.pm > +++ b/src/PVE/QemuServer.pm > @@ -75,6 +75,7 @@ use PVE::QemuServer::Drive qw( > checked_volume_format > drive_is_cloudinit > drive_is_cdrom > + drive_is_absolute_path nit: should be sorted alphabetically > parse_drive > print_drive > storage_allows_io_uring_default > @@ -913,7 +914,7 @@ PVE::JSONSchema::register_format( > sub verify_volume_id_or_absolute_path { > my ($volid, $noerr) =3D @_; > =20 > - return $volid if $volid =3D~ m|^/|; > + return $volid if PVE::QemuServer::Helpers::is_absolute_path($volid); > =20 > $volid =3D eval { PVE::JSONSchema::check_format('pve-volume-id', $vo= lid, '') }; > if ($@) { > @@ -1555,7 +1556,7 @@ sub print_vga_device { > sub vm_is_volid_owner { > my ($storecfg, $vmid, $volid) =3D @_; > =20 > - if ($volid !~ m|^/|) { > + if (!PVE::QemuServer::Helpers::is_absolute_path($volid)) { > my ($path, $owner); > eval { ($path, $owner) =3D PVE::Storage::path($storecfg, $volid)= ; }; > log_warn("ownership of volume '$volid' could not be determined: = $@") if $@; > @@ -1841,11 +1842,9 @@ sub destroy_vm { > { include_unused =3D> 1 }, > sub { > my ($ds, $drive) =3D @_; > - return if drive_is_cdrom($drive); > + return if drive_is_cdrom($drive) || drive_is_absolute_pa= th($drive); > =20 > my $volid =3D $drive->{file}; > - return if !$volid || $volid =3D~ m|^/|; Hm, the !$volid check should be included in the check above as well as drive_is_absolute_path() doesn't check this and shouldn't need to. Though if there's good reason that !$volid will never be true here, this can be removed in a previous commit with a clear reasoning why. > - > my $result =3D eval { PVE::Storage::volume_is_base_and_u= sed($storecfg, $volid) }; > # early check, removal of volume will fail later anyway,= so warning here is fine > log_warn("failed to check if volume '$volid' is used by = linked clones: $@") > @@ -1859,10 +1858,9 @@ sub destroy_vm { > my $volids =3D {}; > my $remove_owned_drive =3D sub { > my ($ds, $drive) =3D @_; > - return if drive_is_cdrom($drive, 1); > + return if drive_is_cdrom($drive, 1) || drive_is_absolute_path($d= rive); > =20 > my $volid =3D $drive->{file}; > - return if !$volid || $volid =3D~ m|^/|; > return if $volids->{$volid}; same here > =20 > my ($path, $owner) =3D eval { PVE::Storage::path($storecfg, $vol= id) }; > @@ -6085,7 +6083,7 @@ sub get_vm_volumes { > sub { > my ($volid, $attr) =3D @_; > =20 > - return if $volid =3D~ m|^/|; > + return if PVE::QemuServer::Helpers::is_absolute_path($volid)= ; > =20 > my ($sid, $volname) =3D PVE::Storage::parse_volume_id($volid= , 1); > return if !$sid; > @@ -6485,7 +6483,7 @@ sub tar_restore_cleanup { > if ($line =3D~ m/vzdump:([^\s:]*):(\S+)$/) { > my $volid =3D $2; > eval { > - if ($volid =3D~ m|^/|) { > + if (PVE::QemuServer::Helpers::is_absolute_path($voli= d)) { > unlink $volid || die 'unlink failed\n'; > } else { > PVE::Storage::vdisk_free($storecfg, $volid); > @@ -6530,11 +6528,9 @@ my $restore_cleanup_oldconf =3D sub { > sub { > my ($ds, $drive) =3D @_; > =20 > - return if drive_is_cdrom($drive, 1); > + return if drive_is_cdrom($drive, 1) || drive_is_absolute_pat= h($drive); > =20 > my $volid =3D $drive->{file}; > - return if !$volid || $volid =3D~ m|^/|; same here > - > my ($path, $owner) =3D PVE::Storage::path($storecfg, $volid)= ; > return if !$path || !$owner || ($owner !=3D $vmid); > =20 > diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev= .pm > index 101c747c..78a53ff5 100644 > --- a/src/PVE/QemuServer/Blockdev.pm > +++ b/src/PVE/QemuServer/Blockdev.pm > @@ -11,7 +11,7 @@ use JSON; > use PVE::JSONSchema qw(json_bool); > use PVE::Storage; > =20 > -use PVE::QemuServer::Drive qw(drive_is_cdrom); > +use PVE::QemuServer::Drive qw(drive_is_cdrom drive_is_absolute_path); nit: should also be alphabetically sorted > use PVE::QemuServer::Helpers; > use PVE::QemuServer::Machine; > use PVE::QemuServer::Monitor qw(mon_cmd qmp_cmd qsd_qmp_peer vm_qmp_peer= ); > @@ -299,7 +299,7 @@ sub generate_file_blockdev { > } elsif ($drive->{file} eq 'cdrom') { > my $path =3D PVE::QemuServer::Drive::get_iso_path($storecfg, $dr= ive->{file}); > $blockdev =3D { driver =3D> 'host_cdrom', filename =3D> "$path" = }; > - } elsif ($drive->{file} =3D~ m|^/|) { > + } elsif (drive_is_absolute_path($drive)) { > my $path =3D $drive->{file}; > # The 'file' driver only works for regular files. The check belo= w is taken from > # block/file-posix.c:hdev_probe_device() in QEMU. To detect CD-R= OM host devices, QEMU issues > diff --git a/src/PVE/QemuServer/Drive.pm b/src/PVE/QemuServer/Drive.pm > index b80b7dbb..35256acf 100644 > --- a/src/PVE/QemuServer/Drive.pm > +++ b/src/PVE/QemuServer/Drive.pm > @@ -23,6 +23,7 @@ our @EXPORT_OK =3D qw( > checked_volume_format > drive_is_cloudinit > drive_is_cdrom > + drive_is_absolute_path nit: should be sorted alphabetically > parse_drive > print_drive > storage_allows_io_uring_default > @@ -766,6 +767,11 @@ sub drive_is_cdrom { > return $drive && $drive->{media} && ($drive->{media} eq 'cdrom'); > } > =20 > +sub drive_is_absolute_path { > + my ($drive) =3D @_; > + return PVE::QemuServer::Helpers::is_absolute_path($drive->{file}); > +} > + > sub parse_drive_interface { > my ($key) =3D @_; > =20 > @@ -1061,7 +1067,7 @@ sub get_scsi_device_type { > if (drive_is_cdrom($drive) || drive_is_cloudinit($drive)) { > $devicetype =3D 'cd'; > } else { > - if ($drive->{file} =3D~ m|^/|) { > + if (drive_is_absolute_path($drive)) { > $path =3D $drive->{file}; > if (my $info =3D path_is_scsi($path)) { > if ($info->{type} =3D=3D 0 && $drive->{scsiblock}) { > diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.p= m > index dd17eef5..5cc3e8b5 100644 > --- a/src/PVE/QemuServer/Helpers.pm > +++ b/src/PVE/QemuServer/Helpers.pm > @@ -389,4 +389,9 @@ sub get_host_phys_address_bits { > return; # undef, cannot really do anything.. > } > =20 > +sub is_absolute_path { the subroutine name is rather short in description, this should be at least volid_is_absolute_path() or volumeid_is_absolute_path() or something different. > + my ($volid) =3D @_; > + return $volid =3D~ m|^/|; > +} > + > 1;