public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef
@ 2023-01-10 12:52 Fiona Ebner
  2023-01-10 12:52 ` [pve-devel] [PATCH storage 2/3] zfs: list zvol: skip different pools during parsing already Fiona Ebner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fiona Ebner @ 2023-01-10 12:52 UTC (permalink / raw)
  To: pve-devel

Avoids the need for the fallback for the (only existing) caller.

Note that the old my $list = (); is a rather intransparent way of
assigning undef.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/Storage/ZFSPoolPlugin.pm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index f829b86..bce360f 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -254,7 +254,7 @@ sub free_image {
 sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
-    my $zfs_list = $class->zfs_list_zvol($scfg) // {};
+    my $zfs_list = $class->zfs_list_zvol($scfg);
 
     my $res = [];
 
@@ -381,9 +381,9 @@ sub zfs_list_zvol {
 	$scfg->{pool},
     );
     my $zvols = zfs_parse_zvol_list($text);
-    return undef if !$zvols;
+    return {} if !$zvols;
 
-    my $list = ();
+    my $list = {};
     foreach my $zvol (@$zvols) {
 	# The "pool" in $scfg is not the same as ZFS pool, so it's necessary to filter here.
 	next if $scfg->{pool} ne $zvol->{pool};
-- 
2.30.2





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

* [pve-devel] [PATCH storage 2/3] zfs: list zvol: skip different pools during parsing already
  2023-01-10 12:52 [pve-devel] [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Fiona Ebner
@ 2023-01-10 12:52 ` Fiona Ebner
  2023-01-10 12:52 ` [pve-devel] [PATCH storage 3/3] zfs: list zvol: limit recursion depth to 1 Fiona Ebner
  2023-01-10 13:46 ` [pve-devel] applied-series: [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Fiona Ebner @ 2023-01-10 12:52 UTC (permalink / raw)
  To: pve-devel

The 'pool' property in the result of zfs_parse_zvol_list() was not
used for anything else.

No functional change is intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/Storage/ZFSPoolPlugin.pm | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index bce360f..b971c7a 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -58,7 +58,7 @@ sub options {
 # static zfs helper methods
 
 sub zfs_parse_zvol_list {
-    my ($text) = @_;
+    my ($text, $pool) = @_;
 
     my $list = ();
 
@@ -73,12 +73,12 @@ sub zfs_parse_zvol_list {
 	my @parts = split /\//, $dataset;
 	next if scalar(@parts) < 2; # we need pool/name
 	my $name = pop @parts;
-	my $pool = join('/', @parts);
+	my $parsed_pool = join('/', @parts);
+	next if $parsed_pool ne $pool;
 
 	next unless $name =~ m!^(vm|base|subvol|basevol)-(\d+)-(\S+)$!;
 	$zvol->{owner} = $2;
 
-	$zvol->{pool} = $pool;
 	$zvol->{name} = $name;
 	if ($type eq 'filesystem') {
 	    if ($refquota eq 'none') {
@@ -380,14 +380,11 @@ sub zfs_list_zvol {
 	'-Hrp',
 	$scfg->{pool},
     );
-    my $zvols = zfs_parse_zvol_list($text);
+    my $zvols = zfs_parse_zvol_list($text, $scfg->{pool});
     return {} if !$zvols;
 
     my $list = {};
     foreach my $zvol (@$zvols) {
-	# The "pool" in $scfg is not the same as ZFS pool, so it's necessary to filter here.
-	next if $scfg->{pool} ne $zvol->{pool};
-
 	my $name = $zvol->{name};
 	my $parent = $zvol->{origin};
 	if($zvol->{origin} && $zvol->{origin} =~ m/^$scfg->{pool}\/(\S+)$/){
-- 
2.30.2





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

* [pve-devel] [PATCH storage 3/3] zfs: list zvol: limit recursion depth to 1
  2023-01-10 12:52 [pve-devel] [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Fiona Ebner
  2023-01-10 12:52 ` [pve-devel] [PATCH storage 2/3] zfs: list zvol: skip different pools during parsing already Fiona Ebner
@ 2023-01-10 12:52 ` Fiona Ebner
  2023-01-10 13:46 ` [pve-devel] applied-series: [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Fiona Ebner @ 2023-01-10 12:52 UTC (permalink / raw)
  To: pve-devel

To be correct in all cases, it's still necessary to filter by "pool"
in zfs_parse_zvol_list(), because $scfg->{pool} could be e.g.
'foo/vm-123-disk-0' which looks like an image name and would pass the
other "should skip"-checks in zfs_parse_zvol_list().

No change in the result of zfs_list_zvol() is intended.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/Storage/ZFSPoolPlugin.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index b971c7a..9fbd149 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -377,9 +377,12 @@ sub zfs_list_zvol {
 	'name,volsize,origin,type,refquota',
 	'-t',
 	'volume,filesystem',
-	'-Hrp',
+	'-d1',
+	'-Hp',
 	$scfg->{pool},
     );
+    # It's still required to have zfs_parse_zvol_list filter by pool, because -d1 lists
+    # $scfg->{pool} too and while unlikely, it could be named to be mistaken for a volume.
     my $zvols = zfs_parse_zvol_list($text, $scfg->{pool});
     return {} if !$zvols;
 
-- 
2.30.2





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

* [pve-devel] applied-series: [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef
  2023-01-10 12:52 [pve-devel] [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Fiona Ebner
  2023-01-10 12:52 ` [pve-devel] [PATCH storage 2/3] zfs: list zvol: skip different pools during parsing already Fiona Ebner
  2023-01-10 12:52 ` [pve-devel] [PATCH storage 3/3] zfs: list zvol: limit recursion depth to 1 Fiona Ebner
@ 2023-01-10 13:46 ` Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2023-01-10 13:46 UTC (permalink / raw)
  To: Fiona Ebner; +Cc: pve-devel

applied, thanks




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

end of thread, other threads:[~2023-01-10 13:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 12:52 [pve-devel] [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Fiona Ebner
2023-01-10 12:52 ` [pve-devel] [PATCH storage 2/3] zfs: list zvol: skip different pools during parsing already Fiona Ebner
2023-01-10 12:52 ` [pve-devel] [PATCH storage 3/3] zfs: list zvol: limit recursion depth to 1 Fiona Ebner
2023-01-10 13:46 ` [pve-devel] applied-series: [PATCH storage 1/3] zfs: list zvol: return empty hash rather than undef Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal