From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 21BD01FF2AD for ; Thu, 4 Jul 2024 16:47:47 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 827D8350C7; Thu, 4 Jul 2024 16:48:03 +0200 (CEST) Message-ID: <16f29fdd-8a9c-4c7f-8fdd-8664d0a2c041@proxmox.com> Date: Thu, 4 Jul 2024 16:47:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Proxmox VE development discussion , Maximiliano Sandoval References: <20240704120213.351520-1-m.sandoval@proxmox.com> From: Aaron Lauterer In-Reply-To: <20240704120213.351520-1-m.sandoval@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL -0.291 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URI_NOVOWEL 0.5 URI hostname has long non-vowel sequence Subject: Re: [pve-devel] [PATCH storage v3] fix #4272: btrfs: add rename feature X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" gave it a try and it does what it should. by enabling the rename feature only for `raw` we avoid potential pitfalls if we encounter a non regular situation on BTRFS. For example, an images/{vmid}/vm-{vmid}-disk-X.qcow2 file directly instead of the images/{vmid}/vm-{vmid}-disk-X/disk.raw as is the way the BTRFS plugin handles it in subvolumes. But if we add the following diff, it seems to handle the case of a qcow2 file in the same directory structure just fine: diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index 7376ae4..143442c 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -619,7 +619,7 @@ sub volume_has_feature { current => { qcow2 => 1, raw => 1, vmdk => 1 }, }, rename => { - current => { raw => 1 }, + current => { qcow2 => 1, raw => 1}, }, }; @@ -939,6 +939,10 @@ sub rename_volume { my $format = ($class->parse_volname($source_volname))[6]; + if ($format ne 'raw' && $format ne 'subvol') { + return $class->SUPER::rename_volume($scfg, $storeid, $source_volname, $target_vmid, $target_volname); + } + my $ppath = $class->filesystem_path($scfg, $source_volname); $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1) Since we do have that in the other functions (alloc_image, free_image), we might want to add it here as well, just to be safe. If we aren't concerned about this, then consider this: Reviewed-By: Aaron Lauterer Tested-By: Aaron Lauterer On 2024-07-04 14:02, Maximiliano Sandoval wrote: > Adds the ability to change the owner of a guest image. > > Btrfs does not need special commands to rename a subvolume and this can > be achieved the same as in Storage/plugin.pm's rename_volume taking > special care of how the directory structure used by Btrfs. > > Signed-off-by: Maximiliano Sandoval > --- > Differences from v2: > - use indices instead of assigning to undef 5 times > > Differences from v1: > - avoid assigning unused values of returned list to variables > > src/PVE/Storage/BTRFSPlugin.pm | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm > index 42815cb..7376ae4 100644 > --- a/src/PVE/Storage/BTRFSPlugin.pm > +++ b/src/PVE/Storage/BTRFSPlugin.pm > @@ -618,6 +618,9 @@ sub volume_has_feature { > base => { qcow2 => 1, raw => 1, vmdk => 1 }, > current => { qcow2 => 1, raw => 1, vmdk => 1 }, > }, > + rename => { > + current => { raw => 1 }, > + }, > }; > > my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = $class->parse_volname($volname); > @@ -930,4 +933,32 @@ sub volume_import { > return "$storeid:$volname"; > } > > +sub rename_volume { > + my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_; > + die "no path found\n" if !$scfg->{path}; > + > + my $format = ($class->parse_volname($source_volname))[6]; > + > + my $ppath = $class->filesystem_path($scfg, $source_volname); > + > + $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1) > + if !$target_volname; > + $target_volname = "$target_vmid/$target_volname"; > + > + my $basedir = $class->get_subdir($scfg, 'images'); > + > + mkpath "${basedir}/${target_vmid}"; > + my $source_dir = raw_name_to_dir($source_volname); > + my $target_dir = raw_name_to_dir($target_volname); > + > + my $old_path = "${basedir}/${source_dir}"; > + my $new_path = "${basedir}/${target_dir}"; > + > + die "target volume '${target_volname}' already exists\n" if -e $new_path; > + rename $old_path, $new_path || > + die "rename '$old_path' to '$new_path' failed - $!\n"; > + > + return "${storeid}:$target_volname"; > +} > + > 1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel