Be a little more careful when removing mount points.

This commit is contained in:
Brendan Burns 2015-01-29 18:10:13 -08:00
parent ac2f435aca
commit 7f06fbb081
2 changed files with 33 additions and 5 deletions

View File

@ -194,7 +194,28 @@ func (pd *gcePersistentDisk) SetUp() error {
globalPDPath := makeGlobalPDName(pd.plugin.host, pd.pdName, pd.readOnly)
err = pd.mounter.Mount(globalPDPath, pd.GetPath(), "", mount.FlagBind|flags, "")
if err != nil {
os.RemoveAll(pd.GetPath())
mountpoint, mntErr := isMountPoint(pd.GetPath())
if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr)
return err
}
if mountpoint {
if mntErr = pd.mounter.Unmount(pd.GetPath(), 0); mntErr != nil {
glog.Errorf("Failed to unmount: %v", mntErr)
return err
}
mountpoint, mntErr := isMountPoint(pd.GetPath())
if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr)
return err
}
if mountpoint {
// This is very odd, we don't expect it. We'll try again next sync loop.
glog.Errorf("%s is still mounted, despite call to unmount(). Will try again next sync loop.", pd.GetPath())
return err
}
}
os.Remove(pd.GetPath())
// TODO: we should really eject the attach/detach out into its own control loop.
detachDiskLogError(pd)
return err
@ -223,7 +244,7 @@ func (pd *gcePersistentDisk) TearDown() error {
return err
}
if !mountpoint {
return os.RemoveAll(pd.GetPath())
return os.Remove(pd.GetPath())
}
devicePath, refCount, err := getMountRefCount(pd.mounter, pd.GetPath())
@ -241,8 +262,15 @@ func (pd *gcePersistentDisk) TearDown() error {
return err
}
}
if err := os.RemoveAll(pd.GetPath()); err != nil {
mountpoint, mntErr := isMountPoint(pd.GetPath())
if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr)
return err
}
if !mountpoint {
if err := os.Remove(pd.GetPath()); err != nil {
return err
}
}
return nil
}

View File

@ -87,7 +87,7 @@ func (util *GCEDiskUtil) AttachDisk(pd *gcePersistentDisk) error {
if !mountpoint {
err = pd.mounter.Mount(devicePath, globalPDPath, pd.fsType, flags, "")
if err != nil {
os.RemoveAll(globalPDPath)
os.Remove(globalPDPath)
return err
}
}
@ -127,7 +127,7 @@ func (util *GCEDiskUtil) DetachDisk(pd *gcePersistentDisk, devicePath string) er
if err := pd.mounter.Unmount(globalPDPath, 0); err != nil {
return err
}
if err := os.RemoveAll(globalPDPath); err != nil {
if err := os.Remove(globalPDPath); err != nil {
return err
}
gce, err := cloudprovider.GetCloudProvider("gce", nil)