* [pve-devel] [PATCH pve-storage v2] fix #6561: zfspool: track refquota for subvolumes via user properties
@ 2025-07-29 9:41 Shannon Sterz
2025-07-29 9:59 ` Fiona Ebner
2025-07-29 12:13 ` Shannon Sterz
0 siblings, 2 replies; 3+ messages in thread
From: Shannon Sterz @ 2025-07-29 9:41 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>
---
src/PVE/Storage/ZFSPoolPlugin.pm | 44 +++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
index cdf5868..d329abc 100644
--- a/src/PVE/Storage/ZFSPoolPlugin.pm
+++ b/src/PVE/Storage/ZFSPoolPlugin.pm
@@ -482,9 +482,28 @@ 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);
$class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$vname\@$snap");
+
+ # 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_request(
+ $scfg, undef, 'get', 'refquota', '-o', 'value', '-Hp', "$scfg->{pool}/$vname",
+ );
+
+ chomp($refquota);
+
+ $class->zfs_request(
+ $scfg,
+ undef,
+ 'set',
+ "pve-storage:refquota=${refquota}",
+ "$scfg->{pool}/$vname\@$snap",
+ );
+ }
}
sub volume_snapshot_delete {
@@ -503,6 +522,29 @@ sub volume_snapshot_rollback {
my $msg = $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$vname\@$snap");
+ # 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_request(
+ $scfg,
+ undef,
+ 'get',
+ 'pve-storage:refquota',
+ '-o',
+ 'value',
+ '-Hp',
+ "$scfg->{pool}/$vname\@$snap",
+ );
+
+ chomp($refquota);
+
+ if ($refquota =~ m/^\d+$/) {
+ $class->zfs_request(
+ $scfg, undef, 'set', "refquota=${refquota}", "$scfg->{pool}/$vname",
+ );
+ }
+ }
+
# we have to unmount rollbacked subvols, to invalidate wrong kernel
# caches, they get mounted in activate volume again
# see zfs bug #10931 https://github.com/openzfs/zfs/issues/10931
--
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] 3+ messages in thread
* Re: [pve-devel] [PATCH pve-storage v2] fix #6561: zfspool: track refquota for subvolumes via user properties
2025-07-29 9:41 [pve-devel] [PATCH pve-storage v2] fix #6561: zfspool: track refquota for subvolumes via user properties Shannon Sterz
@ 2025-07-29 9:59 ` Fiona Ebner
2025-07-29 12:13 ` Shannon Sterz
1 sibling, 0 replies; 3+ messages in thread
From: Fiona Ebner @ 2025-07-29 9:59 UTC (permalink / raw)
To: Proxmox VE development discussion, Shannon Sterz
Am 29.07.25 um 11:42 AM schrieb Shannon Sterz:
> 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>
Tested-by: Fiona Ebner <f.ebner@proxmox.com>
with some suggestions:
> ---
> src/PVE/Storage/ZFSPoolPlugin.pm | 44 +++++++++++++++++++++++++++++++-
> 1 file changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
> index cdf5868..d329abc 100644
> --- a/src/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/src/PVE/Storage/ZFSPoolPlugin.pm
> @@ -482,9 +482,28 @@ 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);
>
> $class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$vname\@$snap");
> +
> + # 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_request(
> + $scfg, undef, 'get', 'refquota', '-o', 'value', '-Hp', "$scfg->{pool}/$vname",
> + );
We have a dedicated zfs_get_properties() helper you could use, that
should also avoid the need for chomp()
> +
> + chomp($refquota);
> +
> + $class->zfs_request(
> + $scfg,
> + undef,
> + 'set',
> + "pve-storage:refquota=${refquota}",
> + "$scfg->{pool}/$vname\@$snap",
Might be nice to create a variable for this and its other use in the
function.
> + );
> + }
> }
>
> sub volume_snapshot_delete {
> @@ -503,6 +522,29 @@ sub volume_snapshot_rollback {
>
> my $msg = $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$vname\@$snap");
>
> + # 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_request(
> + $scfg,
> + undef,
> + 'get',
> + 'pve-storage:refquota',
> + '-o',
> + 'value',
> + '-Hp',
> + "$scfg->{pool}/$vname\@$snap",
Might be nice to create a variable for this and its other use in the
function.
> + );
> +
> + chomp($refquota);
> +
> + if ($refquota =~ m/^\d+$/) {
> + $class->zfs_request(
> + $scfg, undef, 'set', "refquota=${refquota}", "$scfg->{pool}/$vname",
> + );
> + }
Maybe warn if it doesn't match the regex?
> + }
> +
> # we have to unmount rollbacked subvols, to invalidate wrong kernel
> # caches, they get mounted in activate volume again
> # see zfs bug #10931 https://github.com/openzfs/zfs/issues/10931
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pve-devel] [PATCH pve-storage v2] fix #6561: zfspool: track refquota for subvolumes via user properties
2025-07-29 9:41 [pve-devel] [PATCH pve-storage v2] fix #6561: zfspool: track refquota for subvolumes via user properties Shannon Sterz
2025-07-29 9:59 ` Fiona Ebner
@ 2025-07-29 12:13 ` Shannon Sterz
1 sibling, 0 replies; 3+ messages in thread
From: Shannon Sterz @ 2025-07-29 12:13 UTC (permalink / raw)
To: Shannon Sterz, pve-devel
Superseeded-by: https://lore.proxmox.com/pve-devel/20250729121151.159797-1-s.sterz@proxmox.com/T/#u
On Tue Jul 29, 2025 at 11:41 AM CEST, 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.
>
> 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>
> ---
> src/PVE/Storage/ZFSPoolPlugin.pm | 44 +++++++++++++++++++++++++++++++-
> 1 file changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
> index cdf5868..d329abc 100644
> --- a/src/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/src/PVE/Storage/ZFSPoolPlugin.pm
> @@ -482,9 +482,28 @@ 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);
>
> $class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$vname\@$snap");
> +
> + # 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_request(
> + $scfg, undef, 'get', 'refquota', '-o', 'value', '-Hp', "$scfg->{pool}/$vname",
> + );
> +
> + chomp($refquota);
> +
> + $class->zfs_request(
> + $scfg,
> + undef,
> + 'set',
> + "pve-storage:refquota=${refquota}",
> + "$scfg->{pool}/$vname\@$snap",
> + );
> + }
> }
>
> sub volume_snapshot_delete {
> @@ -503,6 +522,29 @@ sub volume_snapshot_rollback {
>
> my $msg = $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$vname\@$snap");
>
> + # 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_request(
> + $scfg,
> + undef,
> + 'get',
> + 'pve-storage:refquota',
> + '-o',
> + 'value',
> + '-Hp',
> + "$scfg->{pool}/$vname\@$snap",
> + );
> +
> + chomp($refquota);
> +
> + if ($refquota =~ m/^\d+$/) {
> + $class->zfs_request(
> + $scfg, undef, 'set', "refquota=${refquota}", "$scfg->{pool}/$vname",
> + );
> + }
> + }
> +
> # we have to unmount rollbacked subvols, to invalidate wrong kernel
> # caches, they get mounted in activate volume again
> # see zfs bug #10931 https://github.com/openzfs/zfs/issues/10931
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-29 12:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-29 9:41 [pve-devel] [PATCH pve-storage v2] fix #6561: zfspool: track refquota for subvolumes via user properties Shannon Sterz
2025-07-29 9:59 ` Fiona Ebner
2025-07-29 12:13 ` Shannon Sterz
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.