-
Notifications
You must be signed in to change notification settings - Fork 256
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
Detect rbd_clone4
support by using dlsym()
#1013
Conversation
6e69c32
to
9ff7eea
Compare
Very interesting. I will try to dig into it in more detail soon! also cc: @ansiwen |
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.
lgtm.
No specific concerns, technically well done. My only concern is, that I think this is a case of over-engineering to add the libdl dependency in general for such an edge-case. I'm not really sure about the side effects on non-Linux and MUSL systems. But I will not veto it, if a majority prefers this change. I just wanted to note here that I would prefer to just not support the first release of Squid. |
@ansiwen, one of the issues is that the Ceph team considers other new librdb APIs (features) as backports for minor Ceph releases. The I am not an enormous fan of the proposed solution either, but it is simpler for users of go-ceph than handling build-tags for each API that gets backported. |
That's a fair point, would a tag like |
It works for new functions and structs, not enums or functions that were changed. Modifying existing public functions is not something that should be done in any case, it will break existing applications that use them. Introduction of new functions while keeping (possibly deprecating) the old ones is a more sane approach. |
9ff7eea
to
b6a9d69
Compare
@ansiwen and @phlogistonjohn I've dropped the CGo linker directive to link against Do you have any other concerns that I should address? |
Oh, interesting! Local testing with the |
8faeec4
to
91e143f
Compare
internal/dlsym/dlsym.go
Outdated
// clear dlerror before looking up the symbol | ||
C.dlerror() | ||
// resolve the address of the symbol | ||
sym := C.dlsym(nil /* C.RTLD_DEFAULT */, cSymName) |
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.
On MacOS this must be set to RTLD_DEFAULT
, NULL
doesn't work.
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.
Unfortunately C.RTLD_DEFAULT
could not be found for some reason. Maybe a header or define is missing, I'll try to figure that out.
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.
Added a define for RTLD_DEFAULT
, it should be in the header, but migth be missing in some Ceph container(s)?
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.
That's weird. Would be good to know why. How can dlsym be defined, but RTLD_DEFAULT not? 🤔
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.
That's weird. Would be good to know why. How can dlsym be defined, but RTLD_DEFAULT not? 🤔
Yeah, I was not able to find out. Each dlfcn.h
that I checked had RTLD_DEFAULT
without #ifdef ...
or something around it.
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.
#1026 might be the key here.
91e143f
to
a2ec69d
Compare
The dlsym package provides LookupSymbol() which resolves a named symbol (like "rbd_clone4") and returns a unsafe.Pointer to it. The caller is expected to cast the symbol to function that can be called. Signed-off-by: Niels de Vos <ndevos@ibm.com>
When there is a failure during the CloneFromGroupSnap test case, the rbd-group snapshot was not removed, preventing images from being deleted as well. Signed-off-by: Niels de Vos <ndevos@ibm.com>
Some versions of librbd provide the rbd_clone4 function, and others do not. Squid will have the function backported in the 1st update, the initial release of Squid does not have it. This makes checking for the function based on the named Ceph version impractical. With the new dlsym.LookupSymbol() function, it is now possible to check the availability of rbd_clone4 during runtime. If the symbol is not found ErrNotImplemented is returned, which can be used to detect the unavailability of the function. Signed-off-by: Niels de Vos <ndevos@ibm.com>
a2ec69d
to
cafbdc2
Compare
Shouldn't we document the situation with enums/variables from original Ceph API referenced in the corresponding go-ceph API? Nevertheless I think its good to have this new approach documented within development.md. |
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.
LGTM now, I wondered if we could simplify the whole construct, and make it more reusable, but we can do that, when the second case comes in.
I set do-not-merge
to give @nixpanic a chance to react to my further comments. Just remove it when you are ready to merge.
@anoopcs9 , I think enums and other |
Even otherwise I was more interested in documenting the LookupSymbol() helper from I'm removing the |
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.
lgtm.
The dlsym package provides LookupSymbol() which resolves a named symbol
(like "rbd_clone4") and returns a unsafe.Pointer to it. The caller is
expected to cast the symbol to function that can be called.
Some versions of librbd provide the rbd_clone4 function, and others do
not. Squid will have the function backported in the 1st update, the
initial release of Squid does not have it. This makes checking for the
function based on the named Ceph version impractical.
With the new dlsym.LookupSymbol() function, it is now possible to check
the availability of rbd_clone4 during runtime. If the symbol is not
found ErrNotImplemented is returned, which can be used to detect the
unavailability of the function.
Checklist
//go:build ceph_preview
make api-update
to record new APIsNew or infrequent contributors may want to review the go-ceph Developer's Guide including the section on how we track API Status and the API Stability Plan.
The go-ceph project uses mergify. View the mergify command guide for information on how to interact with mergify. Add a comment with
@Mergifyio
rebase
to rebase your PR when github indicates that the PR is out of date with the base branch.