rbd: add function (cc *ClusterConnection) GetTaskAdmin()

This function returns new go-ceph TaskAdmin to add
tasks on rbd volumes.

Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
Rakshith R 2021-11-16 16:06:18 +05:30 committed by mergify[bot]
parent 420aa9ec57
commit c19264e996
2 changed files with 15 additions and 8 deletions

View File

@ -676,15 +676,13 @@ func (rv *rbdVolume) deleteImage(ctx context.Context) error {
// otherwise removes the image from trash. // otherwise removes the image from trash.
func (rv *rbdVolume) trashRemoveImage(ctx context.Context) error { func (rv *rbdVolume) trashRemoveImage(ctx context.Context) error {
// attempt to use Ceph manager based deletion support if available // 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 { if err != nil {
return err 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)) _, err = ta.AddTrashRemove(admin.NewImageSpec(rv.Pool, rv.RadosNamespace, rv.ImageID))
rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err) rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err)
@ -828,14 +826,13 @@ func (rv *rbdVolume) flattenRbdImage(
return nil 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 { if err != nil {
return err 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)) _, err = ta.AddFlatten(admin.NewImageSpec(rv.Pool, rv.RadosNamespace, rv.RbdImageName))
rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err) rbdCephMgrSupported := isCephMgrSupported(ctx, rv.ClusterID, err)
if rbdCephMgrSupported { if rbdCephMgrSupported {

View File

@ -131,6 +131,16 @@ func (cc *ClusterConnection) GetRBDAdmin() (*ra.RBDAdmin, error) {
return ra.NewFromConn(cc.conn), nil 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 // DisableDiscardOnZeroedWriteSame enables the
// `rbd_discard_on_zeroed_write_same` option in the cluster connection, so that // `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 // writing zero blocks of data are actual writes on the OSDs (doing