rbd: implement rbd clone with go-ceph

moved the implementation of clone
from CLI to go-ceph

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-06-24 12:47:21 +05:30 committed by mergify[bot]
parent c30f91eead
commit d95b07e39b

View File

@ -757,18 +757,33 @@ func (rv *rbdVolume) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) err
return err return err
} }
// nolint: interfacer func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *rbdSnapshot) error {
func restoreSnapshot(ctx context.Context, pVolOpts *rbdVolume, pSnapOpts *rbdSnapshot, cr *util.Credentials) error { image := rv.RbdImageName
var output []byte var err error
klog.V(4).Infof(util.Log(ctx, "rbd: clone %s %s using mon %s"), pSnapOpts, image, rv.Monitors)
klog.V(4).Infof(util.Log(ctx, "rbd: clone %s using mon %s"), pVolOpts, pVolOpts.Monitors) options := librbd.NewRbdImageOptions()
args := []string{"clone", pSnapOpts.String(), pVolOpts.String(), defer options.Destroy()
"--id", cr.ID, "-m", pVolOpts.Monitors, "--keyfile=" + cr.KeyFile} if rv.imageFeatureSet != 0 {
err = options.SetUint64(librbd.RbdImageOptionFeatures, uint64(rv.imageFeatureSet))
output, err := execCommand("rbd", args) if err != nil {
return errors.Wrapf(err, "failed to set image features")
}
}
err = options.SetUint64(imageOptionCloneFormat, 2)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to restore snapshot, command output: %s", string(output)) return errors.Wrapf(err, "failed to set image features")
}
err = rv.openIoctx()
if err != nil {
return errors.Wrapf(err, "failed to get IOContext")
}
err = librbd.CloneImage(rv.ioctx, pSnapOpts.RbdImageName, pSnapOpts.RbdSnapName, rv.ioctx, rv.RbdImageName, options)
if err != nil {
return errors.Wrapf(err, "failed to create rbd clone")
} }
return nil return nil