Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify that the volume is not yet mounted on the target. #71

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shame that this isn't built into the library.


// 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
Loading