Permalink
Browse files

cinder/rbd: flatten volume upon EINVAL rbd map error

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.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
  • Loading branch information...
bergwolf committed Aug 15, 2018
1 parent dd3f6c6 commit 35bafa0ce7bc340188b0ced0c27ad6a962639757
Showing with 17 additions and 1 deletion.
  1. +17 −1 pkg/volume/cinder/drivers/rbd.go
@@ -116,7 +116,23 @@ 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 %s failed: %v", volume.Name, 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))

0 comments on commit 35bafa0

Please sign in to comment.