rbd: Implement create and delete snapshot with go-ceph

Implement create and delete snapshot with go-ceph

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-06-24 12:36:29 +05:30 committed by mergify[bot]
parent 6ba0cd58b9
commit f08118a8e5

View File

@ -754,39 +754,35 @@ func (rv *rbdVolume) hasSnapshotFeature() bool {
return (uint64(rv.imageFeatureSet) & librbd.FeatureLayering) == librbd.FeatureLayering return (uint64(rv.imageFeatureSet) & librbd.FeatureLayering) == librbd.FeatureLayering
} }
func createSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credentials) error { func (rv *rbdVolume) createSnapshot(ctx context.Context, pOpts *rbdSnapshot) error {
var output []byte
klog.V(4).Infof(util.Log(ctx, "rbd: snap create %s using mon %s"), pOpts, pOpts.Monitors) klog.V(4).Infof(util.Log(ctx, "rbd: snap create %s using mon %s"), pOpts, pOpts.Monitors)
args := []string{"snap", "create", pOpts.String(), "--id", cr.ID, "-m", pOpts.Monitors, "--keyfile=" + cr.KeyFile} image, err := rv.open()
output, err := execCommand("rbd", args)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to create snapshot, command output: %s", string(output)) return err
}
defer image.Close()
_, err = image.CreateSnapshot(pOpts.RbdSnapName)
return err
} }
return nil func (rv *rbdVolume) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) error {
}
func deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credentials) error {
var output []byte
klog.V(4).Infof(util.Log(ctx, "rbd: snap rm %s using mon %s"), pOpts, pOpts.Monitors) klog.V(4).Infof(util.Log(ctx, "rbd: snap rm %s using mon %s"), pOpts, pOpts.Monitors)
args := []string{"snap", "rm", pOpts.String(), "--id", cr.ID, "-m", pOpts.Monitors, "--keyfile=" + cr.KeyFile} image, err := rv.open()
output, err := execCommand("rbd", args)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to delete snapshot, command output: %s", string(output)) return err
} }
defer image.Close()
if err := undoSnapReservation(ctx, pOpts, cr); err != nil { snap := image.GetSnapshot(pOpts.RbdSnapName)
klog.Errorf(util.Log(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s): %s"), if snap == nil {
pOpts.RequestName, pOpts, err) return errors.Errorf("snapshot value is nil for %s", pOpts.RbdSnapName)
} }
err = snap.Remove()
return nil if err == librbd.ErrNotFound {
return ErrSnapNotFound{snapName: pOpts.RbdSnapName, err: err}
}
return err
} }
// nolint: interfacer // nolint: interfacer