fix #2641: allow mounting of CIFS subdirectories

CIFS/SMB supports directly mounting subdirectories, so it makes sense to
also allow the --subdir parameter for these storages. The subdir
parameter was moved from CephFSPlugin.pm to Plugin.pm, because it isn't
specific to CephFS anymore.

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
This commit is contained in:
Leo Nunner
2022-12-01 12:32:55 +01:00
committed by Thomas Lamprecht
parent acff89540a
commit 362159a831
3 changed files with 26 additions and 22 deletions

View File

@ -13,11 +13,16 @@ use base qw(PVE::Storage::Plugin);
# CIFS helper functions # CIFS helper functions
sub cifs_is_mounted { sub cifs_is_mounted : prototype($$) {
my ($server, $share, $mountpoint, $mountdata) = @_; my ($scfg, $mountdata) = @_;
my $mountpoint = $scfg->{path};
my $server = $scfg->{server};
my $share = $scfg->{share};
my $subdir = $scfg->{subdir} // "/";
$server = "[$server]" if Net::IP::ip_is_ipv6($server); $server = "[$server]" if Net::IP::ip_is_ipv6($server);
my $source = "//${server}/$share"; my $source = "//${server}/$share$subdir";
$mountdata = PVE::ProcFSTools::parse_proc_mounts() if !$mountdata; $mountdata = PVE::ProcFSTools::parse_proc_mounts() if !$mountdata;
return $mountpoint if grep { return $mountpoint if grep {
@ -63,11 +68,16 @@ sub get_cred_file {
return undef; return undef;
} }
sub cifs_mount { sub cifs_mount : prototype($$$$$) {
my ($server, $share, $mountpoint, $storeid, $smbver, $user, $domain) = @_; my ($scfg, $storeid, $smbver, $user, $domain) = @_;
my $mountpoint = $scfg->{path};
my $server = $scfg->{server};
my $share = $scfg->{share};
my $subdir = $scfg->{subdir} // "/";
$server = "[$server]" if Net::IP::ip_is_ipv6($server); $server = "[$server]" if Net::IP::ip_is_ipv6($server);
my $source = "//${server}/$share"; my $source = "//${server}/$share$subdir";
my $cmd = ['/bin/mount', '-t', 'cifs', $source, $mountpoint, '-o', 'soft', '-o']; my $cmd = ['/bin/mount', '-t', 'cifs', $source, $mountpoint, '-o', 'soft', '-o'];
@ -131,6 +141,7 @@ sub options {
'content-dirs' => { optional => 1 }, 'content-dirs' => { optional => 1 },
server => { fixed => 1 }, server => { fixed => 1 },
share => { fixed => 1 }, share => { fixed => 1 },
subdir => { optional => 1 },
nodes => { optional => 1 }, nodes => { optional => 1 },
disable => { optional => 1 }, disable => { optional => 1 },
maxfiles => { optional => 1 }, maxfiles => { optional => 1 },
@ -205,12 +216,8 @@ sub status {
$cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts() $cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts()
if !$cache->{mountdata}; if !$cache->{mountdata};
my $path = $scfg->{path};
my $server = $scfg->{server};
my $share = $scfg->{share};
return undef return undef
if !cifs_is_mounted($server, $share, $path, $cache->{mountdata}); if !cifs_is_mounted($scfg, $cache->{mountdata});
return $class->SUPER::status($storeid, $scfg, $cache); return $class->SUPER::status($storeid, $scfg, $cache);
} }
@ -222,17 +229,15 @@ sub activate_storage {
if !$cache->{mountdata}; if !$cache->{mountdata};
my $path = $scfg->{path}; my $path = $scfg->{path};
my $server = $scfg->{server};
my $share = $scfg->{share};
if (!cifs_is_mounted($server, $share, $path, $cache->{mountdata})) { if (!cifs_is_mounted($scfg, $cache->{mountdata})) {
mkpath $path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir}); mkpath $path if !(defined($scfg->{mkdir}) && !$scfg->{mkdir});
die "unable to activate storage '$storeid' - " . die "unable to activate storage '$storeid' - " .
"directory '$path' does not exist\n" if ! -d $path; "directory '$path' does not exist\n" if ! -d $path;
cifs_mount($server, $share, $path, $storeid, $scfg->{smbversion}, cifs_mount($scfg, $storeid, $scfg->{smbversion},
$scfg->{username}, $scfg->{domain}); $scfg->{username}, $scfg->{domain});
} }
@ -246,10 +251,8 @@ sub deactivate_storage {
if !$cache->{mountdata}; if !$cache->{mountdata};
my $path = $scfg->{path}; my $path = $scfg->{path};
my $server = $scfg->{server};
my $share = $scfg->{share};
if (cifs_is_mounted($server, $share, $path, $cache->{mountdata})) { if (cifs_is_mounted($scfg, $cache->{mountdata})) {
my $cmd = ['/bin/umount', $path]; my $cmd = ['/bin/umount', $path];
run_command($cmd, errmsg => 'umount error'); run_command($cmd, errmsg => 'umount error');
} }

View File

@ -127,10 +127,6 @@ sub properties {
description => "Mount CephFS through FUSE.", description => "Mount CephFS through FUSE.",
type => 'boolean', type => 'boolean',
}, },
subdir => {
description => "Subdir to mount.",
type => 'string', format => 'pve-storage-path',
},
'fs-name' => { 'fs-name' => {
description => "The Ceph filesystem name.", description => "The Ceph filesystem name.",
type => 'string', format => 'pve-configid', type => 'string', format => 'pve-configid',

View File

@ -169,6 +169,11 @@ my $defaultData = {
type => 'boolean', type => 'boolean',
optional => 1, optional => 1,
}, },
subdir => {
description => "Subdir to mount.",
type => 'string', format => 'pve-storage-path',
optional => 1,
},
'format' => { 'format' => {
description => "Default image format.", description => "Default image format.",
type => 'string', format => 'pve-storage-format', type => 'string', format => 'pve-storage-format',