From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A930ED6B4 for ; Thu, 1 Dec 2022 12:34:00 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8C08728C69 for ; Thu, 1 Dec 2022 12:33:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 1 Dec 2022 12:33:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6F17A44AC1 for ; Thu, 1 Dec 2022 12:33:29 +0100 (CET) From: Leo Nunner To: pve-devel@lists.proxmox.com Date: Thu, 1 Dec 2022 12:32:55 +0100 Message-Id: <20221201113257.57225-2-l.nunner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221201113257.57225-1-l.nunner@proxmox.com> References: <20221201113257.57225-1-l.nunner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.070 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.pm, cifsplugin.pm, cephfsplugin.pm] Subject: [pve-devel] [PATCH storage 1/1] fix #2641: allow mounting of CIFS subdirectories X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Dec 2022 11:34:00 -0000 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 --- PVE/Storage/CIFSPlugin.pm | 39 ++++++++++++++++++++----------------- PVE/Storage/CephFSPlugin.pm | 4 ---- PVE/Storage/Plugin.pm | 5 +++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/PVE/Storage/CIFSPlugin.pm b/PVE/Storage/CIFSPlugin.pm index 982040a..dc41e0b 100644 --- a/PVE/Storage/CIFSPlugin.pm +++ b/PVE/Storage/CIFSPlugin.pm @@ -13,11 +13,16 @@ use base qw(PVE::Storage::Plugin); # CIFS helper functions -sub cifs_is_mounted { - my ($server, $share, $mountpoint, $mountdata) = @_; +sub cifs_is_mounted : prototype($$) { + 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); - my $source = "//${server}/$share"; + my $source = "//${server}/$share$subdir"; $mountdata = PVE::ProcFSTools::parse_proc_mounts() if !$mountdata; return $mountpoint if grep { @@ -63,11 +68,16 @@ sub get_cred_file { return undef; } -sub cifs_mount { - my ($server, $share, $mountpoint, $storeid, $smbver, $user, $domain) = @_; +sub cifs_mount : prototype($$$$$) { + 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); - my $source = "//${server}/$share"; + my $source = "//${server}/$share$subdir"; my $cmd = ['/bin/mount', '-t', 'cifs', $source, $mountpoint, '-o', 'soft', '-o']; @@ -130,6 +140,7 @@ sub options { path => { fixed => 1 }, server => { fixed => 1 }, share => { fixed => 1 }, + subdir => { optional => 1 }, nodes => { optional => 1 }, disable => { optional => 1 }, maxfiles => { optional => 1 }, @@ -204,12 +215,8 @@ sub status { $cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts() if !$cache->{mountdata}; - my $path = $scfg->{path}; - my $server = $scfg->{server}; - my $share = $scfg->{share}; - 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); } @@ -221,17 +228,15 @@ sub activate_storage { if !$cache->{mountdata}; 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}); die "unable to activate storage '$storeid' - " . "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}); } @@ -245,10 +250,8 @@ sub deactivate_storage { if !$cache->{mountdata}; 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]; run_command($cmd, errmsg => 'umount error'); } diff --git a/PVE/Storage/CephFSPlugin.pm b/PVE/Storage/CephFSPlugin.pm index 4976747..944f0b8 100644 --- a/PVE/Storage/CephFSPlugin.pm +++ b/PVE/Storage/CephFSPlugin.pm @@ -127,10 +127,6 @@ sub properties { description => "Mount CephFS through FUSE.", type => 'boolean', }, - subdir => { - description => "Subdir to mount.", - type => 'string', format => 'pve-storage-path', - }, 'fs-name' => { description => "The Ceph filesystem name.", type => 'string', format => 'pve-configid', diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index 8a41df1..af53a99 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -169,6 +169,11 @@ my $defaultData = { type => 'boolean', optional => 1, }, + subdir => { + description => "Subdir to mount.", + type => 'string', format => 'pve-storage-path', + optional => 1, + }, 'format' => { description => "Default image format.", type => 'string', format => 'pve-storage-format', -- 2.30.2