mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
rbd: check rbd image status only duing DeleteVolume RPC
currently, various calls to deleteImage does not need the rbdStatus check. That is only required when calling from DeleteVolume. This PR optimizes the rbd image deletion by removing the status check. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
44d79e3bda
commit
7a87db39e6
@ -547,6 +547,16 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
||||
}
|
||||
defer cs.VolumeLocks.Release(rbdVol.RequestName)
|
||||
|
||||
found, _, err := rbdStatus(ctx, rbdVol, cr)
|
||||
if err != nil {
|
||||
klog.Errorf(util.Log(ctx, "failed getting information for image (%s): (%s)"), rbdVol, err)
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
if found {
|
||||
klog.Errorf(util.Log(ctx, "rbd %s is still being used"), rbdVol)
|
||||
return nil, status.Errorf(codes.Internal, "rbd %s is still being used", rbdVol.RbdImageName)
|
||||
}
|
||||
|
||||
// Deleting rbd image
|
||||
klog.V(4).Infof(util.Log(ctx, "deleting image %s"), rbdVol.RbdImageName)
|
||||
if err = deleteImage(ctx, rbdVol, cr); err != nil {
|
||||
|
@ -339,21 +339,8 @@ func addRbdManagerTask(ctx context.Context, pOpts *rbdVolume, arg []string) (boo
|
||||
// deleteImage deletes a ceph image with provision and volume options.
|
||||
func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
|
||||
image := pOpts.RbdImageName
|
||||
found, _, err := rbdStatus(ctx, pOpts, cr)
|
||||
if err != nil {
|
||||
klog.Errorf(util.Log(ctx, "failed getting information for image (%s): (%s)"), pOpts, err)
|
||||
if strings.Contains(err.Error(), "rbd: error opening image "+image+
|
||||
": (2) No such file or directory") {
|
||||
return ErrImageNotFound{image, err}
|
||||
}
|
||||
return err
|
||||
}
|
||||
if found {
|
||||
klog.Errorf(util.Log(ctx, "rbd %s is still being used"), image)
|
||||
return fmt.Errorf("rbd %s is still being used", image)
|
||||
}
|
||||
// Support deleting the older rbd images whose imageID is not stored in omap
|
||||
err = pOpts.getImageID()
|
||||
err := pOpts.getImageID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user