From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id E26AC1FF189
	for <inbox@lore.proxmox.com>; Fri, 21 Mar 2025 11:52:44 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 220B91B979;
	Fri, 21 Mar 2025 11:52:42 +0100 (CET)
To: pve-devel@lists.proxmox.com
Date: Fri, 21 Mar 2025 11:52:09 +0100
MIME-Version: 1.0
Message-ID: <mailman.42.1742554361.359.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: Hugo via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: Hugo <hugo@pml.blue>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH] fix #4499: prevent superblock read errors for
 containers on CIFS storage
Content-Type: multipart/mixed; boundary="===============4302077413281949686=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============4302077413281949686==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <hugo@pml.blue>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
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 3D887C89EB
	for <pve-devel@lists.proxmox.com>; Fri, 21 Mar 2025 11:52:41 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 23E661B8EE
	for <pve-devel@lists.proxmox.com>; Fri, 21 Mar 2025 11:52:41 +0100 (CET)
Received: from mail.pml.blue (srv732495.hstgr.cloud [IPv6:2a02:4780:28:1bfd::1])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Fri, 21 Mar 2025 11:52:40 +0100 (CET)
Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 301B268C97;
	Fri, 21 Mar 2025 11:52:33 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pml.blue; s=dkim;
	t=1742554353;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding;
	bh=AQAagAMGh2b+kt0JXNbAnMtY/ydsxL8tfrjRYdWjcEo=;
	b=UEEO6RE+2skarDVpSL1LxEIq3Fs2sjmejzqS3psY9YrR0UYXJDqU9qU/MGkmUP5DTVllRm
	P3+r2uFjlrzwSm4jQBAVa62NRoOtadvzKvxLxT1t01yV8y1LUN5FFabiKvah5X1HZ53Ks1
	iwzHqXBrunkpW8jcqEaIAWSjJIViqz8W8XYE/NS6WHMBW6gu2f3FQubqKuYmueabX1JOjH
	Lasca9HzTapWRFb9KUh3TWE5EVgLdUydiDuVv8yxiWH1f/Gl4ec0GT/1Pvjw8myt6Aqmru
	7nKAsG8GnSt+QOLD7rX+j39nvwMhAAMmtg5HD4c9EYtys2sU4Xt1O6mc9QVvug==
From: Hugo <hugo@pml.blue>
To: pve-devel@lists.proxmox.com
Subject: [PATCH] fix #4499: prevent superblock read errors for containers on CIFS storage
Date: Fri, 21 Mar 2025 11:52:09 +0100
Message-ID: <20250321105209.626382-1-hugo@pml.blue>
X-Mailer: git-send-email 2.49.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Last-TLS-Session-Version: TLSv1.3
X-SPAM-LEVEL: Spam detection results:  0
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DKIM_SIGNED               0.1 Message has a DKIM or DK signature, not necessarily valid
	DKIM_VALID               -0.1 Message has at least one valid DKIM or DK signature
	DKIM_VALID_AU            -0.1 Message has a valid DKIM or DK signature from author's domain
	DKIM_VALID_EF            -0.1 Message has a valid DKIM or DK signature from envelope-from domain
	DMARC_PASS               -0.1 DMARC pass policy
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_SOFTFAIL            0.665 SPF: sender does not match SPF record (softfail)
	URIBL_BLOCKED           0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked.  See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [pml.blue,cifsplugin.pm]

Signed-off-by: Hugo <hugo@pml.blue>
---
 src/PVE/Storage/CIFSPlugin.pm | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/PVE/Storage/CIFSPlugin.pm b/src/PVE/Storage/CIFSPlugin.pm
index 475065a..9a8a02c 100644
--- a/src/PVE/Storage/CIFSPlugin.pm
+++ b/src/PVE/Storage/CIFSPlugin.pm
@@ -78,13 +78,17 @@ sub cifs_mount : prototype($$$$$) {
     my $cmd = ['/bin/mount', '-t', 'cifs', $source, $mountpoint, '-o', 'soft', '-o'];
 
     if (my $cred_file = get_cred_file($storeid)) {
-	push @$cmd, "username=$user", '-o', "credentials=$cred_file";
-	push @$cmd, '-o', "domain=$domain" if defined($domain);
+        push @$cmd, "username=$user", '-o', "credentials=$cred_file";
+        push @$cmd, '-o', "domain=$domain" if defined($domain);
     } else {
-	push @$cmd, 'guest,username=guest';
+        push @$cmd, 'guest,username=guest';
     }
 
-    push @$cmd, '-o', defined($smbver) ? "vers=$smbver" : "vers=default";
+    push @$cmd, '-o', defined($smbver) ? "vers=$smbver" : "vers=3.0";
+    
+    # Fix inode issue
+    push @$cmd, '-o', 'noserverino,cache=none,actimeo=0';
+
     push @$cmd, '-o', $options if $options;
 
     run_command($cmd, errmsg => "mount error");
@@ -248,13 +252,27 @@ sub deactivate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
 
     $cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts()
-	if !$cache->{mountdata};
+        if !$cache->{mountdata};
 
     my $path = $scfg->{path};
 
     if (cifs_is_mounted($scfg, $cache->{mountdata})) {
-	my $cmd = ['/bin/umount', $path];
-	run_command($cmd, errmsg => 'umount error');
+        system('/bin/sync');
+
+        my $output = `lsof +D $path 2>/dev/null`;
+        if ($output) {
+            warn "Warning: Processes still using CIFS mount at $path. Trying lazy unmount...\n";
+            system('/bin/umount', '-l', $path);
+        } else {
+            system('/bin/umount', $path);
+        }
+
+        
+        sleep 1; # Give time for unmount
+        if (cifs_is_mounted($scfg, PVE::ProcFSTools::parse_proc_mounts())) {
+            warn "Unmount failed, forcing unmount...\n";
+            system('/bin/umount', '-f', $path);
+        }
     }
 }
 
-- 
2.48.1



--===============4302077413281949686==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

--===============4302077413281949686==--