[pve-devel] [PATCH v2 storage] fix #2085: Handle non-default mount point in path() by introducing new mountpoint property
Fabian Ebner
f.ebner at proxmox.com
Thu Nov 7 09:33:43 CET 2019
A new mountpoint property is added to the schema for ZFSPool storages.
When needed for the first time, the current mount point is determined and
written to the storage config.
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
Changes from v1:
* expanded eval around the zfs_request
* check if the returned value is valid
PVE/Storage/ZFSPoolPlugin.pm | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index 16fb0d6..7a81b17 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -32,6 +32,10 @@ sub properties {
description => "use sparse volumes",
type => 'boolean',
},
+ mountpoint => {
+ description => "mount point",
+ type => 'string', format => 'pve-storage-path',
+ },
};
}
@@ -44,6 +48,7 @@ sub options {
disable => { optional => 1 },
content => { optional => 1 },
bwlimit => { optional => 1 },
+ mountpoint => { optional => 1 },
};
}
@@ -148,11 +153,31 @@ sub path {
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
my $path = '';
+ my $mountpoint = $scfg->{mountpoint};
+
+ # automatically write mountpoint to storage config if it is not present
+ if (!$mountpoint) {
+ eval {
+ $mountpoint = $class->zfs_request($scfg, undef, 'get', '-o', 'value',
+ 'mountpoint', '-H', $scfg->{pool});
+ chomp($mountpoint);
+ PVE::JSONSchema::check_format(properties()->{mountpoint}->{format}, $mountpoint);
+
+ PVE::Storage::lock_storage_config(sub {
+ my $cfg = PVE::Storage::config();
+ $cfg->{ids}->{$storeid}->{mountpoint} = $mountpoint;
+ PVE::Storage::write_config($cfg);
+ }, "update storage config failed");
+ };
+ if (my $err = $@) {
+ warn "determining mount point failed: " . $err . " - using default mount point instead\n";
+ $mountpoint = "/$scfg->{pool}";
+ }
+ }
if ($vtype eq "images") {
if ($name =~ m/^subvol-/ || $name =~ m/^basevol-/) {
- # fixme: we currently assume standard mount point?!
- $path = "/$scfg->{pool}/$name";
+ $path = "$mountpoint/$name";
} else {
$path = "/dev/zvol/$scfg->{pool}/$name";
}
--
2.20.1
More information about the pve-devel
mailing list