mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rbd: Add support for smart cloning
Added support for RBD PVC to PVC cloning, below commands are executed to create a PVC-PVC clone from RBD side. * Check the depth(n) of the cloned image if n>=(hard limit -2) or ((soft limit-2) Add a task to flatten the image and return about (to avoid image leak) **Note** will try to flatten the temp clone image in the chain if available * Reserve the key and values in omap (this will help us to avoid the leak as it's not reserved earlier as we have returned ABORT (the request may not come back)) * Create a snapshot of rbd image * Clone the snapshot (temp clone) * Delete the snapshot * Snapshot the temp clone * Clone the snapshot (final clone) * Delete the snapshot ```bash 1) check the image depth of the parent image if flatten required add a task to flatten image and return ABORT to avoid leak (hardlimit-2 and softlimit-2 check will be done) 2) Reserve omap keys 2) rbd snap create <RBD image for src k8s volume>@<random snap name> 3) rbd clone --rbd-default-clone-format 2 --image-feature layering,deep-flatten <RBD image for src k8s volume>@<random snap> <RBD image for temporary snap image> 4) rbd snap rm <RBD image for src k8s volume>@<random snap name> 5) rbd snap create <cloned RBD image created in snapshot process>@<random snap name> 6) rbd clone --rbd-default-clone-format 2 --image-feature <k8s dst vol config> <RBD image for temporary snap image>@<random snap name> <RBD image for k8s dst vol> 7)rbd snap rm <RBD image for src k8s volume>@<random snap name> ``` * Delete temporary clone image created as part of clone(delete if present) * Delete rbd image Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
9077c25c15
commit
a0fd805a8b
@ -433,7 +433,7 @@ func flattenClonedRbdImages(ctx context.Context, snaps []snapshotInfo, pool, mon
|
||||
for _, s := range snaps {
|
||||
if s.Namespace.Type == "trash" {
|
||||
rv.RbdImageName = s.Namespace.OriginalName
|
||||
err = rv.flattenRbdImage(ctx, cr, true)
|
||||
err = rv.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||
if err != nil {
|
||||
klog.Errorf(util.Log(ctx, "failed to flatten %s; err %v"), rv, err)
|
||||
continue
|
||||
@ -443,7 +443,7 @@ func flattenClonedRbdImages(ctx context.Context, snaps []snapshotInfo, pool, mon
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials, forceFlatten bool) error {
|
||||
func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials, forceFlatten bool, hardlimit, softlimit uint) error {
|
||||
var depth uint
|
||||
var err error
|
||||
|
||||
@ -453,10 +453,10 @@ func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
klog.Infof(util.Log(ctx, "clone depth is (%d), configured softlimit (%d) and hardlimit (%d) for %s"), depth, rbdSoftMaxCloneDepth, rbdHardMaxCloneDepth, rv)
|
||||
klog.Infof(util.Log(ctx, "clone depth is (%d), configured softlimit (%d) and hardlimit (%d) for %s"), depth, softlimit, hardlimit, rv)
|
||||
}
|
||||
|
||||
if forceFlatten || (depth >= rbdHardMaxCloneDepth) || (depth >= rbdSoftMaxCloneDepth) {
|
||||
if forceFlatten || (depth >= hardlimit) || (depth >= softlimit) {
|
||||
args := []string{"flatten", rv.Pool + "/" + rv.RbdImageName, "--id", cr.ID, "--keyfile=" + cr.KeyFile, "-m", rv.Monitors}
|
||||
supported, err := addRbdManagerTask(ctx, rv, args)
|
||||
if supported {
|
||||
@ -464,13 +464,13 @@ func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials,
|
||||
klog.Errorf(util.Log(ctx, "failed to add task flatten for %s : %v"), rv, err)
|
||||
return err
|
||||
}
|
||||
if forceFlatten || depth >= rbdHardMaxCloneDepth {
|
||||
if forceFlatten || depth >= hardlimit {
|
||||
return ErrFlattenInProgress{err: fmt.Errorf("flatten is in progress for image %s", rv.RbdImageName)}
|
||||
}
|
||||
}
|
||||
if !supported {
|
||||
klog.Errorf(util.Log(ctx, "task manager does not support flatten,image will be flattened once hardlimit is reached: %v"), err)
|
||||
if forceFlatten || depth >= rbdHardMaxCloneDepth {
|
||||
if forceFlatten || depth >= hardlimit {
|
||||
err = rv.Connect(cr)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -1008,30 +1008,29 @@ func (rv *rbdVolume) getImageInfo() error {
|
||||
}
|
||||
|
||||
/*
|
||||
getSnapInfo queries rbd about the snapshots of the given image and returns its metadata, and
|
||||
returns ErrImageNotFound if provided image is not found, and ErrSnapNotFound if provided snap
|
||||
is not found in the images snapshot list
|
||||
checkSnapExists queries rbd about the snapshots of the given image and returns
|
||||
ErrImageNotFound if provided image is not found, and ErrSnapNotFound if
|
||||
provided snap is not found in the images snapshot list
|
||||
*/
|
||||
func (rv *rbdVolume) getSnapInfo(rbdSnap *rbdSnapshot) (librbd.SnapInfo, error) {
|
||||
invalidSnap := librbd.SnapInfo{}
|
||||
func (rv *rbdVolume) checkSnapExists(rbdSnap *rbdSnapshot) error {
|
||||
image, err := rv.open()
|
||||
if err != nil {
|
||||
return invalidSnap, err
|
||||
return err
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
snaps, err := image.GetSnapshotNames()
|
||||
if err != nil {
|
||||
return invalidSnap, err
|
||||
return err
|
||||
}
|
||||
|
||||
for _, snap := range snaps {
|
||||
if snap.Name == rbdSnap.RbdSnapName {
|
||||
return snap, nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return invalidSnap, ErrSnapNotFound{rbdSnap.RbdSnapName, fmt.Errorf("snap %s not found", rbdSnap.String())}
|
||||
return ErrSnapNotFound{rbdSnap.RbdSnapName, fmt.Errorf("snap %s not found", rbdSnap.String())}
|
||||
}
|
||||
|
||||
// rbdImageMetadataStash strongly typed JSON spec for stashed RBD image metadata
|
||||
|
Reference in New Issue
Block a user