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

Revert "<carry>: Umount volumes with force" #86

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 1 addition & 53 deletions pkg/nfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package nfs
import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
"golang.org/x/net/context"
Expand All @@ -39,11 +37,6 @@ type NodeServer struct {
mounter mount.Interface
}

const (
// Deadline for unmount. After this time, umount -f is performed.
unmountTimeout = time.Minute
)

// NodePublishVolume mount the volume
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
volCap := req.GetVolumeCapability()
Expand Down Expand Up @@ -156,23 +149,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
return &csi.NodePublishVolumeResponse{}, nil
}

func (ns *NodeServer) IsNotMountPoint(path string) (bool, error) {
mtab, err := ns.mounter.List()
if err != nil {
return false, err
}

for _, mnt := range mtab {
// This is how a directory deleted on the NFS server looks like
deletedDir := fmt.Sprintf("%s\\040(deleted)", mnt.Path)

if mnt.Path == path || mnt.Path == deletedDir {
return false, nil
}
}
return true, nil
}

// NodeUnpublishVolume unmount the volume
func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
volumeID := req.GetVolumeId()
Expand All @@ -183,6 +159,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
if len(targetPath) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}

klog.V(2).Infof("NodeUnpublishVolume: unmounting volume %s on %s", volumeID, targetPath)
err := mount.CleanupMountPoint(targetPath, ns.mounter, true /*extensiveMountPointCheck*/)
if err != nil {
Expand All @@ -193,35 +170,6 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return &csi.NodeUnpublishVolumeResponse{}, nil
}

// tryUnmount calls plain "umount" and waits for unmountTimeout for it to finish.
func (ns *NodeServer) tryUnmount(path string) error {
ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout)
defer cancel()

cmd := exec.CommandContext(ctx, "umount", path)
out, cmderr := cmd.CombinedOutput()

// CombinedOutput() does not return DeadlineExceeded, make sure it's
// propagated on timeout.
if ctx.Err() != nil {
return ctx.Err()
}

if cmderr != nil {
return fmt.Errorf("failed to unmount volume: %s: %s", cmderr, string(out))
}
return nil
}

func (ns *NodeServer) forceUnmount(path string) error {
cmd := exec.Command("umount", "-f", path)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to force-unmount volume: %s: %s", err, string(out))
}
return nil
}

// NodeGetInfo return info of the node on which this plugin is running
func (ns *NodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
return &csi.NodeGetInfoResponse{
Expand Down
7 changes: 2 additions & 5 deletions pkg/nfs/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nfs
import (
"context"
"errors"
"fmt"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -197,7 +198,7 @@ func TestNodeUnpublishVolume(t *testing.T) {

errorTarget := testutil.GetWorkDirPath("error_is_likely_target", t)
targetTest := testutil.GetWorkDirPath("target_test", t)
//targetFile := testutil.GetWorkDirPath("abc.go", t)
targetFile := testutil.GetWorkDirPath("abc.go", t)

tests := []struct {
desc string
Expand All @@ -216,19 +217,15 @@ func TestNodeUnpublishVolume(t *testing.T) {
req: csi.NodeUnpublishVolumeRequest{VolumeId: "vol_1"},
expectedErr: status.Error(codes.InvalidArgument, "Target path missing in request"),
},
/* Not relevant due to carry patch https://github.com/openshift/csi-driver-nfs/commit/59fe400d433137c48de81650026922a88e167177
// Downstream doesn't call IsLikelyNotMountPoint, and doesn't raise any error if the target is not mounted
{
desc: "[Error] Unmount error mocked by IsLikelyNotMountPoint",
req: csi.NodeUnpublishVolumeRequest{TargetPath: errorTarget, VolumeId: "vol_1"},
expectedErr: fmt.Errorf("fake IsLikelyNotMountPoint: fake error"),
},
// Downstream doesn't raise any error if the target is not mounted
{
desc: "[Success] Volume not mounted",
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
},
*/
}

// Setup
Expand Down