rbd: add support to create clone in different pool

added support to create image in different pool.
if the snapshot/rbd image exists in one pool we
can create a clone the clone of the rbd image to
a different pool.

Co-authored-by: Madhu Rajanna <madhupr007@gmail.com>
Signed-off-by: Yug <yuggupta27@gmail.com>
This commit is contained in:
Yug
2021-03-18 16:53:08 +05:30
committed by mergify[bot]
parent 671d6a7767
commit 961c1d12fd
4 changed files with 20 additions and 7 deletions

View File

@ -1079,11 +1079,19 @@ func (rv *rbdVolume) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) err
return err
}
func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *rbdSnapshot) error {
image := rv.RbdImageName
func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *rbdSnapshot, parentVol *rbdVolume) error {
var err error
logMsg := "rbd: clone %s %s (features: %s) using mon %s"
err = parentVol.openIoctx()
if err != nil {
return fmt.Errorf("failed to get parent IOContext: %w", err)
}
defer func() {
defer parentVol.ioctx.Destroy()
parentVol.ioctx = nil
}()
options := librbd.NewRbdImageOptions()
defer options.Destroy()
@ -1096,7 +1104,7 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *r
}
util.DebugLog(ctx, logMsg,
pSnapOpts, image, rv.imageFeatureSet.Names(), rv.Monitors)
pSnapOpts, rv, rv.imageFeatureSet.Names(), rv.Monitors)
if rv.imageFeatureSet != 0 {
err = options.SetUint64(librbd.RbdImageOptionFeatures, uint64(rv.imageFeatureSet))
@ -1110,12 +1118,13 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *r
return fmt.Errorf("failed to set image features: %w", err)
}
// As the clone is yet to be created, open the Ioctx.
err = rv.openIoctx()
if err != nil {
return fmt.Errorf("failed to get IOContext: %w", err)
}
err = librbd.CloneImage(rv.ioctx, pSnapOpts.RbdImageName, pSnapOpts.RbdSnapName, rv.ioctx, rv.RbdImageName, options)
err = librbd.CloneImage(parentVol.ioctx, pSnapOpts.RbdImageName, pSnapOpts.RbdSnapName, rv.ioctx, rv.RbdImageName, options)
if err != nil {
return fmt.Errorf("failed to create rbd clone: %w", err)
}