mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-18 04:10:22 +00:00
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:
parent
671d6a7767
commit
961c1d12fd
@ -101,7 +101,7 @@ func (rv *rbdVolume) checkCloneImage(ctx context.Context, parentVol *rbdVolume)
|
||||
// need to check for flatten here.
|
||||
// as the snap exists,create clone image and delete temporary snapshot
|
||||
// and add task to flatten temporary cloned image
|
||||
err = rv.cloneRbdImageFromSnapshot(ctx, snap)
|
||||
err = rv.cloneRbdImageFromSnapshot(ctx, snap, parentVol)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to clone rbd image %s from snapshot %s: %v", rv.RbdImageName, snap.RbdSnapName, err)
|
||||
err = fmt.Errorf("failed to clone rbd image %s from snapshot %s: %w", rv.RbdImageName, snap.RbdSnapName, err)
|
||||
|
@ -464,8 +464,12 @@ func (cs *ControllerServer) createVolumeFromSnapshot(ctx context.Context, cr *ut
|
||||
|
||||
// update parent name(rbd image name in snapshot)
|
||||
rbdSnap.RbdImageName = rbdSnap.RbdSnapName
|
||||
parentVol := generateVolFromSnap(rbdSnap)
|
||||
// as we are operating on single cluster reuse the connection
|
||||
parentVol.conn = rbdVol.conn.Copy()
|
||||
|
||||
// create clone image and delete snapshot
|
||||
err = rbdVol.cloneRbdImageFromSnapshot(ctx, rbdSnap)
|
||||
err = rbdVol.cloneRbdImageFromSnapshot(ctx, rbdSnap, parentVol)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to clone rbd image %s from snapshot %s: %v", rbdVol, rbdSnap, err)
|
||||
return err
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func createRBDClone(ctx context.Context, parentVol, cloneRbdVol *rbdVolume, snap
|
||||
|
||||
snap.RbdImageName = parentVol.RbdImageName
|
||||
// create clone image and delete snapshot
|
||||
err = cloneRbdVol.cloneRbdImageFromSnapshot(ctx, snap)
|
||||
err = cloneRbdVol.cloneRbdImageFromSnapshot(ctx, snap, parentVol)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to clone rbd image %s from snapshot %s: %v", cloneRbdVol.RbdImageName, snap.RbdSnapName, err)
|
||||
err = fmt.Errorf("failed to clone rbd image %s from snapshot %s: %w", cloneRbdVol.RbdImageName, snap.RbdSnapName, err)
|
||||
|
Loading…
Reference in New Issue
Block a user