mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
umount nfs on detach storage
This commit is contained in:
@@ -125,6 +125,7 @@ type IStorage interface {
|
||||
disksBackingFile, srcSnapshots jsonutils.JSONObject, rebaseDisks bool, diskDesc jsonutils.JSONObject) error
|
||||
|
||||
Accessible() error
|
||||
Detach() error
|
||||
}
|
||||
|
||||
type SBaseStorage struct {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user