[pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot

Maximiliano Sandoval m.sandoval at proxmox.com
Fri Sep 13 15:51:32 CEST 2024


Fiona Ebner <f.ebner at proxmox.com> writes:

> Am 09.07.24 um 13:51 schrieb Maximiliano Sandoval:
>> Suppose we are doing a snapshot of disk 0 for VM 100. The
>> dir_glob_foreach runs over $path=/subvolume/images/100, lists all
>> snapshot names and appends their names to the path of the disk, e.g.
>> /subvolume/images/vm-100-disk-0 at SNAP_NAME, but the original directory
>> $path might contain a second disk `vm-100-disk-1` which is also listed
>> by the dir_glib_foreach.
>> 
>> The patch skips images which reference other disks.
>> 
>> Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
>> ---
>>  src/PVE/Storage/BTRFSPlugin.pm | 3 +++
>>  1 file changed, 3 insertions(+)
>> 
>> diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm
>> index 42815cb..dc0420d 100644
>> --- a/src/PVE/Storage/BTRFSPlugin.pm
>> +++ b/src/PVE/Storage/BTRFSPlugin.pm
>> @@ -767,6 +767,9 @@ sub volume_export {
>>  	push @$cmd, (map { "$path\@$_" } ($with_snapshots // [])->@*), $path;
>>      } else {
>>  	dir_glob_foreach(dirname($path), $BTRFS_VOL_REGEX, sub {
>
> I feel like this would be a bit nicer (and slightly more robust) if it
> used foreach_subvol() and would check the basename like done in
> free_image(). Or even better, introduce a new helper that iterates over
> all snapshots of a specific volume to not repeat ourselves here and in
> free_image(). Since foreach_subvol() is only used once (i.e. in
> free_image()), we could even replace that. There's another pre-existing
> thing that's a bit confusing, which is that BTRFS_VOL_REGEX only matches
> snapshot volumes and not the actual volume itself AFAICS.

Agreed, I will submit a patch improving the situation (mostly for
readability reasons) once I am back from vacations. Imho this could be
merged as-is as this is rather self-contained and already tested.

-- 
Maximiliano




More information about the pve-devel mailing list