Avoid RbdDiskManager's DetachDisk never execute again

This commit is contained in:
Jeremy Xu
2019-07-09 23:29:02 +08:00
parent 7e7bb5cf3a
commit d8fc13791a
3 changed files with 79 additions and 9 deletions

View File

@@ -57,6 +57,12 @@ const (
rbdImageSizeUnitMiB = 1024 * 1024
)
// A struct contains rbd image info.
type rbdImageInfo struct {
pool string
name string
}
func getDevFromImageAndPool(pool, image string) (string, bool) {
device, found := getRbdDevFromImageAndPool(pool, image)
if found {
@@ -789,3 +795,15 @@ func (util *RBDUtil) rbdStatus(b *rbdMounter) (bool, string, error) {
return false, output, nil
}
}
// getRbdImageInfo try to get rbdImageInfo from deviceMountPath.
func getRbdImageInfo(deviceMountPath string) (*rbdImageInfo, error) {
deviceMountedPathSeps := strings.Split(filepath.Base(deviceMountPath), "-image-")
if len(deviceMountedPathSeps) != 2 {
return nil, fmt.Errorf("Can't found devicePath for %s ", deviceMountPath)
}
return &rbdImageInfo{
pool: deviceMountedPathSeps[0],
name: deviceMountedPathSeps[1],
}, nil
}