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:
Niels de Vos
2021-05-27 09:09:49 +02:00
committed by mergify[bot]
parent 334f237e23
commit 6cc11c15d3
2 changed files with 63 additions and 13 deletions

View File

@ -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 {