mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
unmap rbd image if connection timeout.
Sometime rbd images are mapped even if the connection timeout error occurs, this will try to unmap if the received error message is connection timeout.This will fix stale maps and rbd image deletion issue Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
0da4bd5151
commit
e557438f87
@ -44,6 +44,7 @@ const (
|
|||||||
// NOTE: When using devicePath instead of imageSpec, the error strings are different
|
// NOTE: When using devicePath instead of imageSpec, the error strings are different
|
||||||
rbdUnmapCmdkRbdMissingMap = "rbd: %s: not a mapped image or snapshot"
|
rbdUnmapCmdkRbdMissingMap = "rbd: %s: not a mapped image or snapshot"
|
||||||
rbdUnmapCmdNbdMissingMap = "rbd-nbd: %s is not mapped"
|
rbdUnmapCmdNbdMissingMap = "rbd-nbd: %s is not mapped"
|
||||||
|
rbdMapConnectionTimeout = "Connection timed out"
|
||||||
)
|
)
|
||||||
|
|
||||||
var hasNBD = false
|
var hasNBD = false
|
||||||
@ -193,6 +194,7 @@ func attachRBDImage(volOptions *rbdVolume, cr *util.Credentials) (string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createPath(volOpt *rbdVolume, cr *util.Credentials) (string, error) {
|
func createPath(volOpt *rbdVolume, cr *util.Credentials) (string, error) {
|
||||||
|
isNbd := false
|
||||||
image := volOpt.RbdImageName
|
image := volOpt.RbdImageName
|
||||||
imagePath := fmt.Sprintf("%s/%s", volOpt.Pool, image)
|
imagePath := fmt.Sprintf("%s/%s", volOpt.Pool, image)
|
||||||
|
|
||||||
@ -209,6 +211,7 @@ func createPath(volOpt *rbdVolume, cr *util.Credentials) (string, error) {
|
|||||||
// Choose access protocol
|
// Choose access protocol
|
||||||
accessType := accessTypeKRbd
|
accessType := accessTypeKRbd
|
||||||
if volOpt.Mounter == rbdTonbd && hasNBD {
|
if volOpt.Mounter == rbdTonbd && hasNBD {
|
||||||
|
isNbd = true
|
||||||
accessType = accessTypeNbd
|
accessType = accessTypeNbd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +222,13 @@ func createPath(volOpt *rbdVolume, cr *util.Credentials) (string, error) {
|
|||||||
output, err := execCommand(rbd, mapOptions)
|
output, err := execCommand(rbd, mapOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Warningf("rbd: map error %v, rbd output: %s", err, string(output))
|
klog.Warningf("rbd: map error %v, rbd output: %s", err, string(output))
|
||||||
|
// unmap rbd image if connection timeout
|
||||||
|
if strings.Contains(err.Error(), rbdMapConnectionTimeout) {
|
||||||
|
detErr := detachRBDImageOrDeviceSpec(imagePath, true, isNbd)
|
||||||
|
if detErr != nil {
|
||||||
|
klog.Warningf("rbd: %s unmap error %v", imagePath, detErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
return "", fmt.Errorf("rbd: map failed %v, rbd output: %s", err, string(output))
|
return "", fmt.Errorf("rbd: map failed %v, rbd output: %s", err, string(output))
|
||||||
}
|
}
|
||||||
devicePath := strings.TrimSuffix(string(output), "\n")
|
devicePath := strings.TrimSuffix(string(output), "\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user