* [pve-devel] [PATCH storage 2/2] btrfs: forcefully set image to readwrite
2024-07-09 11:51 [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
@ 2024-07-09 11:51 ` Maximiliano Sandoval
2024-08-19 11:27 ` [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Maximiliano Sandoval @ 2024-07-09 11:51 UTC (permalink / raw)
To: pve-devel
When a subvolume is transferred via btrfs send/receive the resulting
image contains the received_uuid property set. This property is required
to do incremental snapshots.
A downside though is that once the received_uuid property is set, it is
not possible to make the image readwrite again without the force (-f)
flag, and in such case the received_uuid property is lost. Since we know
the images are only set to rw for the duration of the move, it is safe
to set the flag forcefully and then in a future commit add the
received_uuid proprty by force.
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
src/PVE/Storage/BTRFSPlugin.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm
index dc0420d..9a9dd51 100644
--- a/src/PVE/Storage/BTRFSPlugin.pm
+++ b/src/PVE/Storage/BTRFSPlugin.pm
@@ -870,7 +870,7 @@ sub volume_import {
# Rotate the disk into place, first the current state:
# Note that read-only subvolumes cannot be moved into different directories, but for the
# "current" state we also want a writable copy, so start with that:
- $class->btrfs_cmd(['property', 'set', "$tmppath/$diskname\@$snapshot", 'ro', 'false']);
+ $class->btrfs_cmd(['property', 'set', '-f', "$tmppath/$diskname\@$snapshot", 'ro', 'false']);
PVE::Tools::renameat2(
-1,
"$tmppath/$diskname\@$snapshot",
@@ -892,7 +892,7 @@ sub volume_import {
# Now go through the remaining snapshots (if any)
foreach my $snap (@snapshots) {
- $class->btrfs_cmd(['property', 'set', "$tmppath/$diskname\@$snap", 'ro', 'false']);
+ $class->btrfs_cmd(['property', 'set', '-f', "$tmppath/$diskname\@$snap", 'ro', 'false']);
PVE::Tools::renameat2(
-1,
"$tmppath/$diskname\@$snap",
--
2.39.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot
2024-07-09 11:51 [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
2024-07-09 11:51 ` [pve-devel] [PATCH storage 2/2] btrfs: forcefully set image to readwrite Maximiliano Sandoval
@ 2024-08-19 11:27 ` Maximiliano Sandoval
2024-08-20 14:01 ` Hannes Laimer
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Maximiliano Sandoval @ 2024-08-19 11:27 UTC (permalink / raw)
To: pve-devel
Ping.
Maximiliano Sandoval <m.sandoval@proxmox.com> writes:
> 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@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@proxmox.com>
--
Maximiliano
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot
2024-07-09 11:51 [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
2024-07-09 11:51 ` [pve-devel] [PATCH storage 2/2] btrfs: forcefully set image to readwrite Maximiliano Sandoval
2024-08-19 11:27 ` [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
@ 2024-08-20 14:01 ` Hannes Laimer
2024-09-10 13:13 ` Fiona Ebner
2024-09-13 13:43 ` Maximiliano Sandoval
4 siblings, 0 replies; 7+ messages in thread
From: Hannes Laimer @ 2024-08-20 14:01 UTC (permalink / raw)
To: Proxmox VE development discussion
Tested these two patches on PVE 8 and they work as advertised, fixing
the problem described in [1]. So, consider this
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
code also looks good, but I don't think R-b is warranted here.
[1] https://bugzilla.proxmox.com/show_bug.cgi?id=3873
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot
2024-07-09 11:51 [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
` (2 preceding siblings ...)
2024-08-20 14:01 ` Hannes Laimer
@ 2024-09-10 13:13 ` Fiona Ebner
2024-09-13 13:51 ` Maximiliano Sandoval
2024-09-13 13:43 ` Maximiliano Sandoval
4 siblings, 1 reply; 7+ messages in thread
From: Fiona Ebner @ 2024-09-10 13:13 UTC (permalink / raw)
To: Proxmox VE development discussion, Maximiliano Sandoval
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@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@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.
> + if (index($path, $_[1]) < 0) {
> + return
> + }
> push @$cmd, "$path\@$_[2]" if !(defined($snapshot) && $_[2] eq $snapshot);
> });
> }
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot
2024-09-10 13:13 ` Fiona Ebner
@ 2024-09-13 13:51 ` Maximiliano Sandoval
0 siblings, 0 replies; 7+ messages in thread
From: Maximiliano Sandoval @ 2024-09-13 13:51 UTC (permalink / raw)
To: Fiona Ebner; +Cc: Proxmox VE development discussion
Fiona Ebner <f.ebner@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@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@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
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot
2024-07-09 11:51 [pve-devel] [PATCH storage 1/2] fix #3873: btrfs: check for correct subvolume taking snapshot Maximiliano Sandoval
` (3 preceding siblings ...)
2024-09-10 13:13 ` Fiona Ebner
@ 2024-09-13 13:43 ` Maximiliano Sandoval
4 siblings, 0 replies; 7+ messages in thread
From: Maximiliano Sandoval @ 2024-09-13 13:43 UTC (permalink / raw)
To: pve-devel
Maximiliano Sandoval <m.sandoval@proxmox.com> writes:
> 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@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@proxmox.com>
For the sake of documenting this, one can reproduce the error via:
- Create a 2-node cluster
- Add a BTRFS storage named "test" on both nodes
- Create a new VM on node 1
- Add a new disk using "test" as a storage
- take a snapshot
- Add a new disk using "test" as a storage
- take a snapshot
- migrate to node 2
This will throw a warning without this patch.
--
Maximiliano
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread