Skip to content

Commit 2347cae

Browse files
committed
fix: set gid of volume mount point to avoid the issue of time exceeding
1 parent 452606b commit 2347cae

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/blob/nodeserver.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
385385
}
386386

387387
if volumeMountGroup != "" && fsGroupChangePolicy != FSGroupChangeNone {
388-
klog.V(2).Infof("set gid of volume(%s) as %s using fsGroupChangePolicy(%s)", volumeID, volumeMountGroup, fsGroupChangePolicy)
389-
if err := volumehelper.SetVolumeOwnership(targetPath, volumeMountGroup, fsGroupChangePolicy); err != nil {
390-
return nil, status.Error(codes.Internal, fmt.Sprintf("SetVolumeOwnership with volume(%s) on %s failed with %v", volumeID, targetPath, err))
388+
klog.V(2).Infof("set gid of volume(%s) as %s and fsGroupChangePolicy(%s)", volumeID, volumeMountGroup, fsGroupChangePolicy)
389+
// set the GID of the volume mount point to the group ID specified in the volumeMountGroup
390+
// and files and directories in NFS share will inherit the group ID of its parent directory
391+
gid, err := strconv.Atoi(volumeMountGroup)
392+
if err != nil {
393+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("convert %s to int failed with %v", volumeMountGroup, err))
394+
}
395+
if err := os.Chown((targetPath), -1, gid); err != nil {
396+
return nil, status.Error(codes.Internal, fmt.Sprintf("Failed to set GID of root directory %s to %d failed with %v", targetPath, gid, err))
391397
}
392398
}
393399

0 commit comments

Comments
 (0)