[PATCH] fix #4499: prevent superblock read errors for containers on CIFS storage

Hugo hugo at pml.blue
Fri Mar 21 11:52:09 CET 2025


Signed-off-by: Hugo <hugo at 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




More information about the pve-devel mailing list