diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 5d916a80ee41..2186616769f5 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -676,15 +676,13 @@ func (rv *rbdVolume) deleteImage(ctx context.Context) error { // otherwise removes the image from trash. func (rv *rbdVolume) trashRemoveImage(ctx context.Context) error { // attempt to use Ceph manager based deletion support if available + log.DebugLog(ctx, "rbd: adding task to remove image %s with id %s from trash", rv, rv.ImageID) - ra, err := rv.conn.GetRBDAdmin() + ta, err := rv.conn.GetTaskAdmin() if err != nil { return err } - log.DebugLog(ctx, "rbd: adding task to remove image %s with id %s from trash", rv, rv.ImageID) - - ta := ra.Task() _, err = ta.AddTrashRemove(admin.NewImageSpec(rv.Pool, rv.RadosNamespace, rv.ImageID)) rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err) @@ -828,14 +826,13 @@ func (rv *rbdVolume) flattenRbdImage( return nil } - ra, err := rv.conn.GetRBDAdmin() + log.DebugLog(ctx, "rbd: adding task to flatten image %q", rv) + + ta, err := rv.conn.GetTaskAdmin() if err != nil { return err } - log.DebugLog(ctx, "rbd: adding task to flatten image %s", rv) - - ta := ra.Task() _, err = ta.AddFlatten(admin.NewImageSpec(rv.Pool, rv.RadosNamespace, rv.RbdImageName)) rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err) if rbdCephMgrSupported { diff --git a/internal/util/connection.go b/internal/util/connection.go index 0aef6848bbd1..44cc149599da 100644 --- a/internal/util/connection.go +++ b/internal/util/connection.go @@ -131,6 +131,16 @@ func (cc *ClusterConnection) GetRBDAdmin() (*ra.RBDAdmin, error) { return ra.NewFromConn(cc.conn), nil } +// GetTaskAdmin returns TaskAdmin to add tasks on rbd images. +func (cc *ClusterConnection) GetTaskAdmin() (*ra.TaskAdmin, error) { + rbdAdmin, err := cc.GetRBDAdmin() + if err != nil { + return nil, err + } + + return rbdAdmin.Task(), nil +} + // DisableDiscardOnZeroedWriteSame enables the // `rbd_discard_on_zeroed_write_same` option in the cluster connection, so that // writing zero blocks of data are actual writes on the OSDs (doing