Skip to content

Commit 402c41b

Browse files
committed
rbd: add support for rbd_diff_iterate3 api
This commit adds support for rbd_diff_iterate3 through DiffIterateByID() which performs diff interate using snapshot id instead of snapshot name. This is useful in cases such as when rbd snapshot is in trash or rbd(group) snapshot in in group namespace. refer: - https://tracker.ceph.com/issues/65720 - ceph/ceph#60844 Signed-off-by: Rakshith R <rar@redhat.com>
1 parent d284200 commit 402c41b

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

docs/api-status.json

+6
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,12 @@
19531953
"comment": "GroupSnapGetInfo returns a slice of RBD image snapshots that are part of a\ngroup snapshot.\n\nImplements:\n\n\tint rbd_group_snap_get_info(rados_ioctx_t group_p,\n\t const char *group_name,\n\t const char *snap_name,\n\t rbd_group_snap_info2_t *snaps);\n",
19541954
"added_in_version": "v0.30.0",
19551955
"expected_stable_version": "v0.32.0"
1956+
},
1957+
{
1958+
"name": "Image.DiffIterateByID",
1959+
"comment": "DiffIterateByID calls a callback on changed extents of an image.\n\nCalling DiffIterateByID will cause the callback specified in the\nDiffIterateConfig to be called as many times as there are changed\nregions in the image (controlled by the parameters as passed to librbd).\n\nSee the documentation of DiffIterateCallback for a description of the\narguments to the callback and the return behavior.\n\nImplements:\n\n\tint rbd_diff_iterate3(rbd_image_t image,\n\t uint64_t from_snap_id,\n\t uint64_t ofs, uint64_t len,\n\t uint8_t include_parent, uint8_t whole_object,\n\t int (*cb)(uint64_t, size_t, int, void *),\n\t void *arg);\n",
1960+
"added_in_version": "$NEXT_RELEASE",
1961+
"expected_stable_version": "$NEXT_RELEASE_STABLE"
19561962
}
19571963
]
19581964
},

docs/api-status.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Conn.GetAddrs | v0.31.0 | v0.33.0 |
2525
Name | Added in Version | Expected Stable Version |
2626
---- | ---------------- | ----------------------- |
2727
GroupSnapGetInfo | v0.30.0 | v0.32.0 |
28+
Image.DiffIterateByID | $NEXT_RELEASE | $NEXT_RELEASE_STABLE |
2829

2930
### Deprecated APIs
3031

rbd/diff_iterate_by_id.go

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//go:build ceph_preview
2+
3+
package rbd
4+
5+
/*
6+
#cgo LDFLAGS: -lrbd
7+
#undef _GNU_SOURCE
8+
#include <errno.h>
9+
#include <stdlib.h>
10+
#include <rbd/librbd.h>
11+
12+
// inline wrapper to cast uintptr_t to void*
13+
static inline int wrap_rbd_diff_iterate3(rbd_image_t image,
14+
uint64_t from_snap_id, uint64_t ofs, uint64_t len, uint8_t include_parent,
15+
uint8_t whole_object, uintptr_t arg) {
16+
return rbd_diff_iterate3(image, from_snap_id, ofs, len, include_parent,
17+
whole_object, (void*)diffIterateCallback, (void*)arg);
18+
};
19+
*/
20+
import "C"
21+
22+
import (
23+
"fmt"
24+
"sync"
25+
26+
"github.com/ceph/go-ceph/internal/dlsym"
27+
)
28+
29+
var (
30+
diffIterateByIDOnce sync.Once
31+
diffIterateByIdErr error
32+
)
33+
34+
// DiffIterateByIDConfig is used to define the parameters of a DiffIterateByID call.
35+
// Callback, Offset, and Length should always be specified when passed to
36+
// DiffIterateByID. The other values are optional.
37+
type DiffIterateByIDConfig struct {
38+
FromSnapID uint64
39+
Offset uint64
40+
Length uint64
41+
IncludeParent DiffIncludeParent
42+
WholeObject DiffWholeObject
43+
Callback DiffIterateCallback
44+
Data interface{}
45+
}
46+
47+
// DiffIterateByID calls a callback on changed extents of an image.
48+
//
49+
// Calling DiffIterateByID will cause the callback specified in the
50+
// DiffIterateConfig to be called as many times as there are changed
51+
// regions in the image (controlled by the parameters as passed to librbd).
52+
//
53+
// See the documentation of DiffIterateCallback for a description of the
54+
// arguments to the callback and the return behavior.
55+
//
56+
// Implements:
57+
//
58+
// int rbd_diff_iterate3(rbd_image_t image,
59+
// uint64_t from_snap_id,
60+
// uint64_t ofs, uint64_t len,
61+
// uint8_t include_parent, uint8_t whole_object,
62+
// int (*cb)(uint64_t, size_t, int, void *),
63+
// void *arg);
64+
func (image *Image) DiffIterateByID(config DiffIterateByIDConfig) error {
65+
if err := image.validate(imageIsOpen); err != nil {
66+
return err
67+
}
68+
if config.Callback == nil {
69+
return getError(C.EINVAL)
70+
}
71+
72+
diffIterateByIDOnce.Do(func() {
73+
_, diffIterateByIdErr = dlsym.LookupSymbol("rbd_diff_iterate3")
74+
})
75+
76+
if diffIterateByIdErr != nil {
77+
return fmt.Errorf("%w: %w", ErrNotImplemented, diffIterateByIdErr)
78+
}
79+
80+
cbIndex := diffIterateCallbacks.Add(config)
81+
defer diffIterateCallbacks.Remove(cbIndex)
82+
83+
ret := C.wrap_rbd_diff_iterate3(
84+
image.image,
85+
C.uint64_t(config.FromSnapID),
86+
C.uint64_t(config.Offset),
87+
C.uint64_t(config.Length),
88+
C.uint8_t(config.IncludeParent),
89+
C.uint8_t(config.WholeObject),
90+
C.uintptr_t(cbIndex))
91+
92+
return getError(ret)
93+
}

0 commit comments

Comments
 (0)