umount nfs on detach storage

This commit is contained in:
wanyaoqi
2020-09-27 20:22:10 +08:00
parent a675971d90
commit 02f7c5ac35
5 changed files with 32 additions and 0 deletions
+1
View File
@@ -125,6 +125,7 @@ type IStorage interface {
disksBackingFile, srcSnapshots jsonutils.JSONObject, rebaseDisks bool, diskDesc jsonutils.JSONObject) error
Accessible() error
Detach() error
}
type SBaseStorage struct {
+4
View File
@@ -174,6 +174,10 @@ func (s *SLocalStorage) Accessible() error {
}
func (s *SLocalStorage) Detach() error {
return nil
}
func (s *SLocalStorage) DeleteDiskfile(diskpath string) error {
log.Infof("Start Delete %s", diskpath)
if options.HostOptions.RecycleDiskfile {
+20
View File
@@ -17,6 +17,7 @@ package storageman
import (
"context"
"fmt"
"path"
"strings"
"time"
@@ -129,3 +130,22 @@ func (s *SNFSStorage) checkAndMount() error {
}
return nil
}
func (s *SNFSStorage) Detach() error {
if !strings.HasPrefix(s.Path, "/opt/cloud") {
tmpPath := path.Join(TempBindMountPath, s.Path)
out, err := procutils.NewCommand("umount", s.Path).Output()
if err != nil {
return errors.Wrapf(err, "1. umount %s failed %s", s.Path, out)
}
out, err = procutils.NewRemoteCommandAsFarAsPossible("umount", tmpPath).Output()
if err != nil {
return errors.Wrapf(err, "2. umount %s failed %s", tmpPath, out)
}
}
out, err := procutils.NewRemoteCommandAsFarAsPossible("umount", s.Path).Output()
if err != nil {
return errors.Wrapf(err, "3. umount %s failed %s", s.Path, out)
}
return nil
}
+4
View File
@@ -640,6 +640,10 @@ func (s *SRbdStorage) Accessible() error {
return err
}
func (s *SRbdStorage) Detach() error {
return nil
}
func (s *SRbdStorage) SaveToGlance(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
data, ok := params.(*jsonutils.JSONDict)
if !ok {
@@ -136,6 +136,9 @@ func storageDetach(ctx context.Context, body jsonutils.JSONObject) (interface{},
if storage == nil {
return nil, httperrors.NewBadRequestError("ShareStorage[%s] Has detach from host ...", name)
}
if err := storage.Detach(); err != nil {
log.Errorf("detach storage %s failed: %s", storage.GetPath(), err)
}
storageman.GetManager().Remove(storage)
return nil, nil
}