Skip to content

Commit

Permalink
Disable xfs uuids
Browse files Browse the repository at this point in the history
  • Loading branch information
jsafrane committed Jun 9, 2021
1 parent 93264f6 commit 1ea2f79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 24 additions & 6 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ func (d *nodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
fsType = defaultFsType
}

var mountOptions []string
for _, f := range mountVolume.MountFlags {
if !hasMountOption(mountOptions, f) {
mountOptions = append(mountOptions, f)
}
}
mountOptions := collectMountOptions(fsType, mountVolume.MountFlags)

if ok := d.inFlight.Insert(volumeID); !ok {
return nil, status.Errorf(codes.Aborted, VolumeOperationAlreadyExists, volumeID)
Expand Down Expand Up @@ -624,6 +619,8 @@ func (d *nodeService) nodePublishVolumeForFileSystem(req *csi.NodePublishVolumeR
fsType = defaultFsType
}

mountOptions = collectMountOptions(fsType, mountOptions)

klog.V(4).Infof("NodePublishVolume: mounting %s at %s with option %s as fstype %s", source, target, mountOptions, fsType)
if err := d.mounter.Mount(source, target, fsType, mountOptions); err != nil {
if removeErr := os.Remove(target); removeErr != nil {
Expand Down Expand Up @@ -659,3 +656,24 @@ func hasMountOption(options []string, opt string) bool {
}
return false
}

// collectMountOptions returns array of mount options from
// VolumeCapability_MountVolume and special mount options for
// given filesystem.
func collectMountOptions(fsType string, mntFlags []string) []string {
var options []string
for _, opt := range mntFlags {
if !hasMountOption(options, opt) {
options = append(options, opt)
}
}

// By default, xfs does not allow mounting of two volumes with the same filesystem uuid.
// Force ignore this uuid to be able to mount volume + its clone / restored snapshot on the same node.
if fsType == FSTypeXfs {
if !hasMountOption(options, "nouuid") {
options = append(options, "nouuid")
}
}
return options
}
4 changes: 2 additions & 2 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func TestNodePublishVolume(t *testing.T) {
},
},
{
name: "success fstype",
name: "success fstype xfs",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
Expand All @@ -628,7 +628,7 @@ func TestNodePublishVolume(t *testing.T) {
}

mockMounter.EXPECT().MakeDir(gomock.Eq(targetPath)).Return(nil)
mockMounter.EXPECT().Mount(gomock.Eq(stagingTargetPath), gomock.Eq(targetPath), gomock.Eq(FSTypeXfs), gomock.Eq([]string{"bind"})).Return(nil)
mockMounter.EXPECT().Mount(gomock.Eq(stagingTargetPath), gomock.Eq(targetPath), gomock.Eq(FSTypeXfs), gomock.Eq([]string{"bind", "nouuid"})).Return(nil)

req := &csi.NodePublishVolumeRequest{
PublishContext: map[string]string{DevicePathKey: devicePath},
Expand Down

0 comments on commit 1ea2f79

Please sign in to comment.