Skip to content

Commit f6e5469

Browse files
committed
rbd: add support for CloneImageByID()
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 <ndevos@ibm.com>
1 parent 0fc95cf commit f6e5469

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

rbd/clone_squid.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//go:build !(nautilus || octopus) && ceph_preview
2+
3+
package rbd
4+
5+
// #cgo LDFLAGS: -lrbd
6+
// #include <errno.h>
7+
// #include <rados/librados.h>
8+
// #include <rbd/librbd.h>
9+
import "C"
10+
11+
import (
12+
"unsafe"
13+
14+
"github.com/ceph/go-ceph/rados"
15+
)
16+
17+
// CloneImageByID creates a clone of the image from of snapshot with the given
18+
// ID in the provided io-context with the given name and image options.
19+
//
20+
// Implements:
21+
//
22+
// int rbd_clone4(rados_ioctx_t p_ioctx, const char *p_name,
23+
// uint64_t p_snap_id, rados_ioctx_t c_ioctx,
24+
// const char *c_name, rbd_image_options_t c_opts);
25+
func CloneImageByID(ioctx *rados.IOContext, parentName string, snapID uint64,
26+
destctx *rados.IOContext, name string, rio *ImageOptions) error {
27+
28+
if rio == nil {
29+
return rbdError(C.EINVAL)
30+
}
31+
32+
cParentName := C.CString(parentName)
33+
defer C.free(unsafe.Pointer(cParentName))
34+
cCloneName := C.CString(name)
35+
defer C.free(unsafe.Pointer(cCloneName))
36+
37+
ret := C.rbd_clone4(
38+
cephIoctx(ioctx),
39+
cParentName,
40+
C.uint64_t(snapID),
41+
cephIoctx(destctx),
42+
cCloneName,
43+
C.rbd_image_options_t(rio.options))
44+
return getError(ret)
45+
}

0 commit comments

Comments
 (0)