@@ -19,7 +19,6 @@ package smb
1919import (
2020 "context"
2121 "fmt"
22- "io/fs"
2322 "os"
2423 "os/exec"
2524 "path/filepath"
@@ -92,12 +91,17 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
9291 }
9392
9493 volCap := volumeCapabilities [0 ]
95- if volCap .GetMount () != nil && ! createSubDir {
94+ if volCap .GetMount () != nil {
9695 options := volCap .GetMount ().GetMountFlags ()
97- if hasGuestMountOptions (options ) {
96+ if ! createSubDir && hasGuestMountOptions (options ) {
9897 klog .V (2 ).Infof ("guest mount option(%v) is provided, create subdirectory" , options )
9998 createSubDir = true
10099 }
100+ // set default file/dir mode
101+ volCap .GetMount ().MountFlags = appendMountOptions (options , map [string ]string {
102+ fileMode : defaultFileMode ,
103+ dirMode : defaultDirMode ,
104+ })
101105 }
102106
103107 if acquired := d .volumeLocks .TryAcquire (name ); ! acquired {
@@ -159,18 +163,22 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
159163 }
160164 defer d .volumeLocks .Release (volumeID )
161165
162- var volCap * csi.VolumeCapability
163166 secrets := req .GetSecrets ()
164167 mountOptions := getMountOptions (secrets )
165168 if mountOptions != "" {
166169 klog .V (2 ).Infof ("DeleteVolume: found mountOptions(%v) for volume(%s)" , mountOptions , volumeID )
167- volCap = & csi.VolumeCapability {
168- AccessType : & csi.VolumeCapability_Mount {
169- Mount : & csi.VolumeCapability_MountVolume {
170- MountFlags : []string {mountOptions },
171- },
170+ }
171+ // set default file/dir mode
172+ volCap := & csi.VolumeCapability {
173+ AccessType : & csi.VolumeCapability_Mount {
174+ Mount : & csi.VolumeCapability_MountVolume {
175+ MountFlags : appendMountOptions ([]string {mountOptions },
176+ map [string ]string {
177+ fileMode : defaultFileMode ,
178+ dirMode : defaultDirMode ,
179+ }),
172180 },
173- }
181+ },
174182 }
175183
176184 if smbVol .onDelete == "" {
@@ -224,14 +232,6 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
224232 return nil , status .Errorf (codes .Internal , "archive subdirectory(%s, %s) failed with %v" , internalVolumePath , archivedInternalVolumePath , err )
225233 }
226234 } else {
227- if _ , err2 := os .Lstat (internalVolumePath ); err2 == nil {
228- err2 := filepath .WalkDir (internalVolumePath , func (path string , _ fs.DirEntry , _ error ) error {
229- return os .Chmod (path , 0777 )
230- })
231- if err2 != nil {
232- klog .Errorf ("failed to chmod subdirectory: %v" , err2 )
233- }
234- }
235235 klog .V (2 ).Infof ("Removing subdirectory at %v" , internalVolumePath )
236236 if err = os .RemoveAll (internalVolumePath ); err != nil {
237237 return nil , status .Errorf (codes .Internal , "failed to delete subdirectory: %v" , err )
0 commit comments