all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-storage v3] fix #6561: zfspool: track refquota for subvolumes via user properties
@ 2025-07-29 12:11 Shannon Sterz
  2025-07-29 13:18 ` [pve-devel] applied: " Fiona Ebner
  0 siblings, 1 reply; 2+ messages in thread
From: Shannon Sterz @ 2025-07-29 12:11 UTC (permalink / raw)
  To: pve-devel

zfs itself does not track the refquota per snapshot so we need handle
this ourselves. otherwise rolling back a volume that has been resize
since the snapshot, will retain the new size. this is problematic, as
it means the value in the guest config does not longer match the size
of the disk on the storage.

this implementation tries to do so by leveraging a user property per
snapshot.

Reported-by: Lukas Wagner <l.wagner@proxmox.com>
Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
---

Notes:
    keeping fiona's R-b from v2 as v3 basically just incorporates her
    suggestions (or suggestions she signed off on), but i'd drop the T-b
    as these patches now behave somewhat differently (warning on unknown
    values).

    hope that reasoning is sound!

    changes since v2, thanks @ Fiona Ebner:
    - use variable for the snapshot name instead of constructing it
      multiple times
    - use `zfs_get_properties` to extract properties instead of
      `zfs_request`
    - warn on unknown refquota user property values

    changes since v1:
    - remove useless if statement
    - reword commit message and comments to make them clearer
    - add missing Suggested-by and Reported-by trailers

 src/PVE/Storage/ZFSPoolPlugin.pm | 38 +++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
index cdf5868..d8d8d0f 100644
--- a/src/PVE/Storage/ZFSPoolPlugin.pm
+++ b/src/PVE/Storage/ZFSPoolPlugin.pm
@@ -482,9 +482,25 @@ sub volume_size_info {
 sub volume_snapshot {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;

-    my $vname = ($class->parse_volname($volname))[1];
+    my (undef, $vname, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
+    my $snapshot_name = "$scfg->{pool}/$vname\@$snap";

-    $class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$vname\@$snap");
+    $class->zfs_request($scfg, undef, 'snapshot', $snapshot_name);
+
+    # if this is a subvol, track refquota information via user properties. zfs
+    # does not track this property for snapshosts and consequently does not roll
+    # it back. so track this information manually.
+    if ($format eq 'subvol') {
+        my $refquota = $class->zfs_get_properties($scfg, 'refquota', "$scfg->{pool}/$vname");
+
+        $class->zfs_request(
+            $scfg,
+            undef,
+            'set',
+            "pve-storage:refquota=${refquota}",
+            $snapshot_name,
+        );
+    }
 }

 sub volume_snapshot_delete {
@@ -500,8 +516,24 @@ sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;

     my (undef, $vname, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
+    my $snapshot_name = "$scfg->{pool}/$vname\@$snap";

-    my $msg = $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$vname\@$snap");
+    my $msg = $class->zfs_request($scfg, undef, 'rollback', $snapshot_name);
+
+    # if this is a subvol, check if we tracked the refquota manually via user
+    # properties and if so, set it appropriatelly again.
+    if ($format eq 'subvol') {
+        my $refquota = $class->zfs_get_properties($scfg, 'pve-storage:refquota', $snapshot_name);
+
+        if ($refquota =~ m/^\d+$/) {
+            $class->zfs_request(
+                $scfg, undef, 'set', "refquota=${refquota}", "$scfg->{pool}/$vname",
+            );
+        } elsif ($refquota ne "-") {
+            # refquota user property was set, but not a number -> warn
+            warn "property for refquota tracking contained unknown value '$refquota'\n";
+        }
+    }

     # we have to unmount rollbacked subvols, to invalidate wrong kernel
     # caches, they get mounted in activate volume again
--
2.47.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] 2+ messages in thread

* [pve-devel] applied: [PATCH pve-storage v3] fix #6561: zfspool: track refquota for subvolumes via user properties
  2025-07-29 12:11 [pve-devel] [PATCH pve-storage v3] fix #6561: zfspool: track refquota for subvolumes via user properties Shannon Sterz
@ 2025-07-29 13:18 ` Fiona Ebner
  0 siblings, 0 replies; 2+ messages in thread
From: Fiona Ebner @ 2025-07-29 13:18 UTC (permalink / raw)
  To: pve-devel, Shannon Sterz

On Tue, 29 Jul 2025 14:11:51 +0200, Shannon Sterz wrote:
> zfs itself does not track the refquota per snapshot so we need handle
> this ourselves. otherwise rolling back a volume that has been resize
> since the snapshot, will retain the new size. this is problematic, as
> it means the value in the guest config does not longer match the size
> of the disk on the storage.
> 
> this implementation tries to do so by leveraging a user property per
> snapshot.
> 
> [...]

Applied, thanks! Fixed up the capitalization in the commit message and
made some minor wording changes.

[1/1] fix #6561: zfspool: track refquota for subvolumes via user properties
      commit: a9315a0ed32293d11a56470d2e19598a5212e8e3

>   keeping fiona's R-b from v2 as v3 basically just incorporates her
>   suggestions (or suggestions she signed off on), but i'd drop the T-b
>   as these patches now behave somewhat differently (warning on unknown
>   values).

Personally, I prefer if the R-b is dropped if there are non-trivial
changes and that such earlier reviews are rather mentioned as part of
the changelog for context.


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-29 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-29 12:11 [pve-devel] [PATCH pve-storage v3] fix #6561: zfspool: track refquota for subvolumes via user properties Shannon Sterz
2025-07-29 13:18 ` [pve-devel] applied: " Fiona Ebner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal