Skip to content

Commit

Permalink
rbd: add support for CloneImageByID()
Browse files Browse the repository at this point in the history
RBD image groups can be used to create consistent snapshots of all
images that are part of the group. The new rbd_clone4() API makes it
possible to create a new RBD image from a single snapshot that was
created as part of the group snapshot.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic committed Jun 21, 2024
1 parent 0fc95cf commit f6e5469
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions rbd/clone_squid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//go:build !(nautilus || octopus) && ceph_preview

package rbd

// #cgo LDFLAGS: -lrbd
// #include <errno.h>
// #include <rados/librados.h>
// #include <rbd/librbd.h>
import "C"

import (
"unsafe"

"github.com/ceph/go-ceph/rados"
)

// CloneImageByID creates a clone of the image from of snapshot with the given
// ID in the provided io-context with the given name and image options.
//
// Implements:
//
// int rbd_clone4(rados_ioctx_t p_ioctx, const char *p_name,
// uint64_t p_snap_id, rados_ioctx_t c_ioctx,
// const char *c_name, rbd_image_options_t c_opts);
func CloneImageByID(ioctx *rados.IOContext, parentName string, snapID uint64,
destctx *rados.IOContext, name string, rio *ImageOptions) error {

if rio == nil {
return rbdError(C.EINVAL)
}

cParentName := C.CString(parentName)
defer C.free(unsafe.Pointer(cParentName))
cCloneName := C.CString(name)
defer C.free(unsafe.Pointer(cCloneName))

ret := C.rbd_clone4(
cephIoctx(ioctx),
cParentName,
C.uint64_t(snapID),
cephIoctx(destctx),
cCloneName,
C.rbd_image_options_t(rio.options))
return getError(ret)
}

0 comments on commit f6e5469

Please sign in to comment.