Skip to content

Commit

Permalink
Verify that the volume is not yet mounted on the target. (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe authored Apr 12, 2024
1 parent 02aa352 commit 3fd4c01
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions pkg/lustre-driver/service/node.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021, 2022 Hewlett Packard Enterprise Development LP
* Copyright 2021, 2022, 2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
Expand Down Expand Up @@ -73,18 +73,34 @@ func (s *service) NodePublishVolume(
return nil, status.Errorf(codes.Internal, "NodePublishVolume - Mountpoint mkdir Failed: Error %v", err)
}

// 2. Perform the mount
// 2. Verify that it's not yet mounted.
mounter := mount.New("")
err = mounter.Mount(
req.GetVolumeId(),
req.GetTargetPath(),
req.GetVolumeCapability().GetMount().GetFsType(),
req.GetVolumeCapability().GetMount().GetMountFlags())

isMounted := false
mountpoints, err := mounter.List()
if err != nil {
return nil, status.Errorf(codes.Internal, "NodePublishVolume - Mount Failed: Error %v", err)
} else {
log.WithField("source", req.GetVolumeId()).WithField("target", req.GetTargetPath()).Info("Mounted")
return nil, status.Errorf(codes.Internal, "NodePublishVolume - List mounts failed: Error %v", err)
}
for idx := range mountpoints {
if mountpoints[idx].Path == req.GetTargetPath() && mountpoints[idx].Device == req.GetVolumeId() {
log.WithField("source", req.GetVolumeId()).WithField("target", req.GetTargetPath()).Info("Already mounted")
isMounted = true
break
}
}

// 3. Perform the mount.
if !isMounted {
err := mounter.Mount(
req.GetVolumeId(),
req.GetTargetPath(),
req.GetVolumeCapability().GetMount().GetFsType(),
req.GetVolumeCapability().GetMount().GetMountFlags())

if err != nil {
return nil, status.Errorf(codes.Internal, "NodePublishVolume - Mount Failed: Error %v", err)
} else {
log.WithField("source", req.GetVolumeId()).WithField("target", req.GetTargetPath()).Info("Mounted")
}
}

return &csi.NodePublishVolumeResponse{}, nil
Expand Down

0 comments on commit 3fd4c01

Please sign in to comment.