Skip to content

Commit

Permalink
Reorder isMounted for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
wongma7 committed Oct 11, 2021
1 parent 085e5e2 commit bc2e526
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/kubernetes/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example shows how to create a EBS volume and consume it from a Windows cont

1. A 1.18+ Windows node. Windows support has only been tested on 1.18 EKS Windows nodes. https://docs.aws.amazon.com/eks/latest/userguide/windows-support.html
2. [csi-proxy](https://github.com/kubernetes-csi/csi-proxy) v1.0.0+ installed on the Windows node.
3. Driver v1.3.2 from GCR k8s.gcr.io/provider-aws/aws-ebs-csi-driver:v1.3.2. It can be built and pushed to another image registry with the command `TAG=$MY_TAG REGISTRY=$MY_REGISTRY make all-push` where `MY_TAG` refers to the image tag to push and `MY_REGISTRY` to the destination image registry like "XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com"
3. Driver v1.3.2 from GCR: `k8s.gcr.io/provider-aws/aws-ebs-csi-driver:v1.3.2`. It can be built and pushed to another image registry with the command `TAG=$MY_TAG REGISTRY=$MY_REGISTRY make all-push` where `MY_TAG` refers to the image tag to push and `MY_REGISTRY` to the destination image registry like "XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com"
4. The driver installed with the Node plugin on the Windows node and the Controller plugin on a Linux node: `helm upgrade --install aws-ebs-csi-driver --namespace kube-system ./charts/aws-ebs-csi-driver --set node.enableWindows=true --set image.repository=$MY_REGISTRY/aws-ebs-csi-driver --set image.tag=$MY_TAG`

## Usage
Expand Down
42 changes: 23 additions & 19 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ func (d *nodeService) nodePublishVolumeForBlock(req *csi.NodePublishVolumeReques
return nil
}

// isMounted checks if target is mounted. It does NOT return an error if target
// doesn't exist.
func (d *nodeService) isMounted(source string, target string) (bool, error) {
/*
Checking if it's a mount point using IsLikelyNotMountPoint. There are three different return values,
Expand All @@ -623,24 +625,29 @@ func (d *nodeService) isMounted(source string, target string) (bool, error) {
if pathErr != nil && d.mounter.IsCorruptedMnt(pathErr) {
klog.V(4).Infof("NodePublishVolume: Target path %q is a corrupted mount. Trying to unmount.", target)
if mntErr := d.mounter.Unmount(target); mntErr != nil {
return !notMnt, status.Errorf(codes.Internal, "Unable to unmount the target %q : %v", target, mntErr)
return false, status.Errorf(codes.Internal, "Unable to unmount the target %q : %v", target, mntErr)
}
//After successful unmount, the device is ready to be mounted.
return !notMnt, nil
return false, nil
}
return !notMnt, status.Errorf(codes.Internal, "Could not check if %q is a mount point: %v, %v", target, err, pathErr)
return false, status.Errorf(codes.Internal, "Could not check if %q is a mount point: %v, %v", target, err, pathErr)
}

// Do not return os.IsNotExist error. Other errors were handled above. The
// Existence of the target should be checked by the caller explicitly and
// independently because sometimes prior to mount it is expected not to exist
// (in Windows, the target must NOT exist before a symlink is created at it)
// and in others it is an error (in Linux, the target mount directory must
// exist before mount is called on it)
if err != nil && os.IsNotExist(err) {
klog.V(5).Infof("[Debug] NodePublishVolume: Target path %q does not exist", target)
return false, nil
}

if !notMnt {
klog.V(4).Infof("NodePublishVolume: Target path %q is already mounted", target)
return !notMnt, nil
}

// Do not return os.IsNotExist error. Other errors were handled above. It is
// the responsibility of the caller to check whether the given target path
// exists (in Linux, the target mount directory must exist before mount is
// called on it) or not (in Windows, the target must NOT exist before a
// symlink is created at it)
return !notMnt, nil
}

Expand All @@ -659,23 +666,20 @@ func (d *nodeService) nodePublishVolumeForFileSystem(req *csi.NodePublishVolumeR
return status.Errorf(codes.Internal, err.Error())
}

fsType := mode.Mount.GetFsType()
if len(fsType) == 0 {
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)

//Checking if the target directory is already mounted with a device.
mounted, err := d.isMounted(source, target)

if err != nil {
return status.Errorf(codes.Internal, "Could not check if %q is mounted: %v", target, err)
}

if !mounted {
fsType := mode.Mount.GetFsType()
if len(fsType) == 0 {
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 {
return status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err)
}
Expand Down

0 comments on commit bc2e526

Please sign in to comment.