mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
parent
8d25cc3193
commit
e7bd00b0b8
@ -363,7 +363,19 @@ func (mounter *Mounter) Unmount(target string) error {
|
|||||||
command := exec.Command("umount", target)
|
command := exec.Command("umount", target)
|
||||||
output, err := command.CombinedOutput()
|
output, err := command.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return checkUmountError(target, command, output, err, mounter.withSafeNotMountedBehavior)
|
if err.Error() == errNoChildProcesses {
|
||||||
|
if command.ProcessState.Success() {
|
||||||
|
// We don't consider errNoChildProcesses an error if the process itself succeeded (see - k/k issue #103753).
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Rewrite err with the actual exit error of the process.
|
||||||
|
err = &exec.ExitError{ProcessState: command.ProcessState}
|
||||||
|
}
|
||||||
|
if mounter.withSafeNotMountedBehavior && strings.Contains(string(output), errNotMounted) {
|
||||||
|
klog.V(4).Infof("ignoring 'not mounted' error for %s", target)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", err, target, string(output))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -371,11 +383,11 @@ func (mounter *Mounter) Unmount(target string) error {
|
|||||||
// UnmountWithForce unmounts given target but will retry unmounting with force option
|
// UnmountWithForce unmounts given target but will retry unmounting with force option
|
||||||
// after given timeout.
|
// after given timeout.
|
||||||
func (mounter *Mounter) UnmountWithForce(target string, umountTimeout time.Duration) error {
|
func (mounter *Mounter) UnmountWithForce(target string, umountTimeout time.Duration) error {
|
||||||
err := tryUnmount(target, mounter.withSafeNotMountedBehavior, umountTimeout)
|
err := tryUnmount(mounter, target, umountTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == context.DeadlineExceeded {
|
if err == context.DeadlineExceeded {
|
||||||
klog.V(2).Infof("Timed out waiting for unmount of %s, trying with -f", target)
|
klog.V(2).Infof("Timed out waiting for unmount of %s, trying with -f", target)
|
||||||
err = forceUmount(target, mounter.withSafeNotMountedBehavior)
|
err = forceUmount(target)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -787,13 +799,13 @@ func (mounter *Mounter) IsMountPoint(file string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tryUnmount calls plain "umount" and waits for unmountTimeout for it to finish.
|
// tryUnmount calls plain "umount" and waits for unmountTimeout for it to finish.
|
||||||
func tryUnmount(target string, withSafeNotMountedBehavior bool, unmountTimeout time.Duration) error {
|
func tryUnmount(mounter *Mounter, path string, unmountTimeout time.Duration) error {
|
||||||
klog.V(4).Infof("Unmounting %s", target)
|
klog.V(4).Infof("Unmounting %s", path)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), unmountTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
command := exec.CommandContext(ctx, "umount", target)
|
cmd := exec.CommandContext(ctx, "umount", path)
|
||||||
output, err := command.CombinedOutput()
|
out, cmderr := cmd.CombinedOutput()
|
||||||
|
|
||||||
// CombinedOutput() does not return DeadlineExceeded, make sure it's
|
// CombinedOutput() does not return DeadlineExceeded, make sure it's
|
||||||
// propagated on timeout.
|
// propagated on timeout.
|
||||||
@ -801,35 +813,22 @@ func tryUnmount(target string, withSafeNotMountedBehavior bool, unmountTimeout t
|
|||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if cmderr != nil {
|
||||||
return checkUmountError(target, command, output, err, withSafeNotMountedBehavior)
|
if mounter.withSafeNotMountedBehavior && strings.Contains(string(out), errNotMounted) {
|
||||||
|
klog.V(4).Infof("ignoring 'not mounted' error for %s", path)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", cmderr, path, string(out))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func forceUmount(target string, withSafeNotMountedBehavior bool) error {
|
func forceUmount(path string) error {
|
||||||
command := exec.Command("umount", "-f", target)
|
cmd := exec.Command("umount", "-f", path)
|
||||||
output, err := command.CombinedOutput()
|
out, cmderr := cmd.CombinedOutput()
|
||||||
|
|
||||||
if err != nil {
|
if cmderr != nil {
|
||||||
return checkUmountError(target, command, output, err, withSafeNotMountedBehavior)
|
return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", cmderr, path, string(out))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkUmountError checks a result of umount command and determine a return value.
|
|
||||||
func checkUmountError(target string, command *exec.Cmd, output []byte, err error, withSafeNotMountedBehavior bool) error {
|
|
||||||
if err.Error() == errNoChildProcesses {
|
|
||||||
if command.ProcessState.Success() {
|
|
||||||
// We don't consider errNoChildProcesses an error if the process itself succeeded (see - k/k issue #103753).
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Rewrite err with the actual exit error of the process.
|
|
||||||
err = &exec.ExitError{ProcessState: command.ProcessState}
|
|
||||||
}
|
|
||||||
if withSafeNotMountedBehavior && strings.Contains(string(output), errNotMounted) {
|
|
||||||
klog.V(4).Infof("ignoring 'not mounted' error for %s", target)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("unmount failed: %v\nUnmounting arguments: %s\nOutput: %s", err, target, string(output))
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user