Skip to content
Permalink
Browse files

Merge pull request #174 from bergwolf/rbd-flatten

cinder/rbd: flatten rbd volumes upon rbd map error 22 (EINVAL)
  • Loading branch information...
resouer committed Aug 24, 2018
2 parents 704359f + 35bafa0 commit fee6bbd3385c40ab1504277cf57f048762352e88
Showing with 18 additions and 2 deletions.
  1. +18 −2 pkg/volume/cinder/drivers/rbd.go
@@ -116,15 +116,31 @@ func (d *RBDDriver) Format(volumeData map[string]interface{}, fsType string) err

mappedDeviceByte, err := exec.Command(rbdPath, "map", volume.Name).CombinedOutput()
if err != nil {
return fmt.Errorf("rbd map failed: %v", err)
// when we get status 22 (EINVAL), it might be because the volume has
// too many (>22) parent layers. Let's flatten it and try again.
if strings.Contains(err.Error(), "status 22") {
glog.Warningf("rbd map volume %s failed: %v. try to flatten it", volume.Name, err)
_, errFlatten := exec.Command(rbdPath, "flatten", volume.Name).CombinedOutput()
if errFlatten != nil {
glog.Warningf("rbd flatten volume %s failed: %v", volume.Name, errFlatten)
return fmt.Errorf("rbd map %s failed: %v", volume.Name, err)
}
mappedDeviceByte, err = exec.Command(rbdPath, "map", volume.Name).CombinedOutput()
if err != nil {
glog.Warningf("rbd map after flatten volume %s failed: %v", volume.Name, err)
return fmt.Errorf("rbd map %s failed: %v", volume.Name, err)
}
} else {
return fmt.Errorf("rbd map %s failed: %v", volume.Name, err)
}
}

mappedDevice := strings.TrimSpace(string(mappedDeviceByte))
defer d.unmapRBD(rbdPath, mappedDevice)

deviceInfo, err := exec.Command(filePath, "-s", mappedDevice).CombinedOutput()
if err != nil {
return fmt.Errorf("rbd map failed: %v", err)
return fmt.Errorf("file -s on volume %s failed: %v", volume.Name, err)
}

if !strings.Contains(string(deviceInfo), fmt.Sprintf("%s filesystem", fsType)) {

0 comments on commit fee6bbd

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.