-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rbd: add support for rbd_diff_iterate3 api #1064
Draft
Rakshith-R
wants to merge
1
commit into
ceph:master
Choose a base branch
from
Rakshith-R:snap-id-diff
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//go:build ceph_preview | ||
|
||
package rbd | ||
|
||
/* | ||
#cgo LDFLAGS: -lrbd | ||
#undef _GNU_SOURCE | ||
#include <errno.h> | ||
#include <stdlib.h> | ||
#include <rbd/librbd.h> | ||
|
||
// inline wrapper to cast uintptr_t to void* | ||
static inline int wrap_rbd_diff_iterate3(rbd_image_t image, | ||
uint64_t from_snap_id, uint64_t ofs, uint64_t len, uint8_t include_parent, | ||
uint8_t whole_object, uintptr_t arg) { | ||
return rbd_diff_iterate3(image, from_snap_id, ofs, len, include_parent, | ||
whole_object, (void*)diffIterateCallback, (void*)arg); | ||
}; | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/ceph/go-ceph/internal/dlsym" | ||
) | ||
|
||
var ( | ||
diffIterateByIDOnce sync.Once | ||
diffIterateByIdErr error | ||
) | ||
|
||
// DiffIterateByIDConfig is used to define the parameters of a DiffIterateByID call. | ||
// Callback, Offset, and Length should always be specified when passed to | ||
// DiffIterateByID. The other values are optional. | ||
type DiffIterateByIDConfig struct { | ||
FromSnapID uint64 | ||
Offset uint64 | ||
Length uint64 | ||
IncludeParent DiffIncludeParent | ||
WholeObject DiffWholeObject | ||
Callback DiffIterateCallback | ||
Data interface{} | ||
} | ||
|
||
// DiffIterateByID calls a callback on changed extents of an image. | ||
// | ||
// Calling DiffIterateByID will cause the callback specified in the | ||
// DiffIterateConfig to be called as many times as there are changed | ||
// regions in the image (controlled by the parameters as passed to librbd). | ||
// | ||
// See the documentation of DiffIterateCallback for a description of the | ||
// arguments to the callback and the return behavior. | ||
// | ||
// Implements: | ||
// | ||
// int rbd_diff_iterate3(rbd_image_t image, | ||
// uint64_t from_snap_id, | ||
// uint64_t ofs, uint64_t len, | ||
// uint8_t include_parent, uint8_t whole_object, | ||
// int (*cb)(uint64_t, size_t, int, void *), | ||
// void *arg); | ||
func (image *Image) DiffIterateByID(config DiffIterateByIDConfig) error { | ||
if err := image.validate(imageIsOpen); err != nil { | ||
return err | ||
} | ||
if config.Callback == nil { | ||
return getError(C.EINVAL) | ||
} | ||
|
||
diffIterateByIDOnce.Do(func() { | ||
_, diffIterateByIdErr = dlsym.LookupSymbol("rbd_diff_iterate3") | ||
}) | ||
|
||
if diffIterateByIdErr != nil { | ||
return fmt.Errorf("%w: %w", ErrNotImplemented, diffIterateByIdErr) | ||
} | ||
|
||
cbIndex := diffIterateCallbacks.Add(config) | ||
defer diffIterateCallbacks.Remove(cbIndex) | ||
|
||
ret := C.wrap_rbd_diff_iterate3( | ||
image.image, | ||
C.uint64_t(config.FromSnapID), | ||
C.uint64_t(config.Offset), | ||
C.uint64_t(config.Length), | ||
C.uint8_t(config.IncludeParent), | ||
C.uint8_t(config.WholeObject), | ||
C.uintptr_t(cbIndex)) | ||
|
||
return getError(ret) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linking against librdb will fail when
rbd_diff_iterate3
does not exists. The solution is to use thedlsym
package and discover therbd_diff_iterate3
function dynamically.You can see how that is done for
rbd_clobe4
. There is some indirection involved, but it is possible to build go-ceph applications with the newCloneImageByID
function, even if it is not part of librbd.