Force unmount the mount point of the Longhorn volume
UnmountWithForce will do graceful umount. If failed, do the force unmount.
Longhorn 5296
@@ -8,6 +8,7 @@ import (
"os"
"strconv"
"strings"
+ "time"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/pkg/errors"
@@ -27,6 +28,8 @@ import (
const (
// defaultStaleReplicaTimeout set to 48 hours (2880 minutes)
defaultStaleReplicaTimeout = 2880
+
+ defaultForceUmountTimeout = 30 * time.Second
)
// NewForcedParamsExec creates a osExecutor that allows for adding additional params to later occurring Run calls
@@ -247,8 +250,16 @@ func ensureMountPoint(targetPath string, mounter mount.Interface) (bool, error)
}
func unmount(targetPath string, mounter mount.Interface) error {
- logrus.Debugf("trying to unmount potential mount point %v", targetPath)
- err := mounter.Unmount(targetPath)
+ var err error
+
+ forceUnmounter, ok := mounter.(mount.MounterForceUnmounter)
+ if ok {
+ logrus.Debugf("Trying to force unmount potential mount point %v", targetPath)
+ err = forceUnmounter.UnmountWithForce(targetPath, defaultForceUmountTimeout)
+ } else {
+ logrus.Debugf("Trying to unmount potential mount point %v", targetPath)
+ err = mounter.Unmount(targetPath)
+ }
if err == nil {
return nil
}
