Merge pull request #340 from andyzhangx/check-before-chmod
fix: bypass chmod if mounting point permissions are correct
This commit is contained in:
commit
09c83624be
@ -121,10 +121,19 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
|||||||
}
|
}
|
||||||
|
|
||||||
if performChmodOp {
|
if performChmodOp {
|
||||||
klog.V(2).Infof("volumeID(%v): chmod targetPath(%s) with permissions(0%o)", volumeID, targetPath, mountPermissions)
|
info, err := os.Lstat(targetPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
perm := info.Mode() & os.ModePerm
|
||||||
|
if perm != os.FileMode(mountPermissions) {
|
||||||
|
klog.V(2).Infof("volumeID(%v): chmod targetPath(%s, mode:0%o) with permissions(0%o)", volumeID, targetPath, info.Mode(), mountPermissions)
|
||||||
if err := os.Chmod(targetPath, os.FileMode(mountPermissions)); err != nil {
|
if err := os.Chmod(targetPath, os.FileMode(mountPermissions)); err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
klog.V(2).Infof("skip chmod on targetPath(%s) since mode is already 0%o)", targetPath, info.Mode())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
klog.V(2).Infof("skip chmod on targetPath(%s) since mountPermissions is set as 0", targetPath)
|
klog.V(2).Infof("skip chmod on targetPath(%s) since mountPermissions is set as 0", targetPath)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user