mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
rbd: use DeepCopy to create a thick-provisioned clone
To create a full-allocated RBD image from a snapshot/clone DeepCopy() can be used. This is needed when the parent of the new volume is thick-provisioner, so that the new volume is independent of the parent and thick-provisioned as well. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
334f237e23
commit
6cc11c15d3
@ -152,6 +152,8 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol
|
||||
}
|
||||
defer j.Destroy()
|
||||
|
||||
// TODO: if rv exists, delete the image and start over?
|
||||
|
||||
err = rv.doSnapClone(ctx, parentVol)
|
||||
if err != nil {
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
@ -170,6 +172,19 @@ func (rv *rbdVolume) createCloneFromImage(ctx context.Context, parentVol *rbdVol
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: copy thick provision config
|
||||
thick, err := parentVol.isThickProvisioned()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed checking thick-provisioning of %q: %w", parentVol, err)
|
||||
}
|
||||
|
||||
if thick {
|
||||
err = rv.setThickProvisioned()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed mark %q thick-provisioned: %w", rv, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = j.StoreImageID(ctx, rv.JournalPool, rv.ReservedID, rv.ImageID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to store volume %s: %v", rv, err)
|
||||
@ -221,11 +236,19 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if rv.ThickProvision {
|
||||
err = tempClone.DeepCopy(rv)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to deep copy %q into %q: %w", parentVol, rv, err)
|
||||
}
|
||||
} else {
|
||||
// flatten clone
|
||||
errFlatten = tempClone.flattenRbdImage(ctx, rv.conn.Creds, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||
if errFlatten != nil {
|
||||
return errFlatten
|
||||
}
|
||||
|
||||
// create snap of temp clone from temporary cloned image
|
||||
// create final clone
|
||||
// delete snap of temp clone
|
||||
@ -235,6 +258,7 @@ func (rv *rbdVolume) doSnapClone(ctx context.Context, parentVol *rbdVolume) erro
|
||||
errFlatten = errors.New("failed to create user requested cloned image")
|
||||
return errClone
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1508,6 +1508,32 @@ func (rv *rbdVolume) RepairThickProvision() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy creates an independent image (dest) from the source image. This
|
||||
// process may take some time when the image is large.
|
||||
func (rv *rbdVolume) DeepCopy(dest *rbdVolume) error {
|
||||
opts := librbd.NewRbdImageOptions()
|
||||
defer opts.Destroy()
|
||||
|
||||
// when doing DeepCopy, also flatten the new image
|
||||
err := opts.SetUint64(librbd.ImageOptionFlatten, 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dest.openIoctx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
image, err := rv.open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
return image.DeepCopy(dest.ioctx, dest.RbdImageName, opts)
|
||||
}
|
||||
|
||||
func (rv *rbdVolume) listSnapshots() ([]librbd.SnapInfo, error) {
|
||||
image, err := rv.open()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user