Skip to content
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

refactor command funcs arguments set up #226

Merged

Conversation

phlogistonjohn
Copy link
Collaborator

Why we may want to do this:
The various *Command and *CommandWithInputBuffer functions all behave similarly but we are effectively copy-n-pasting the argument and result processing over and over. These changes establish a new cutil internal package to help with this and other future c-and-go conversions that are common. It makes two new types one for handling the input, and one for the output. Then we convert the functions in rados and cephfs.

Why we may not want to do this:
Go's cgo support is pretty nice when used entirely within one package but the current design of go/cgo is pretty hostile to allowing cgo details to transition across packages. You can not use the cgo types directly and thus have to resort to workarounds, like overuse (abuse?) of unsafe.Pointer.
As this is an internal package I'm less conerened about unsafe.Pointer because we are not advertising these types for general use, and we who work on the library itself should know what we're doing (famous last words).
It does mean that the code reduction is smaller than I'd like.

Checklist

  • Added tests for features and functional changes
  • Public functions and types are documented
  • Standard formatting is applied to Go code

@phlogistonjohn phlogistonjohn force-pushed the jjm-command-funcs-args-refactor branch from 04300ac to 997e802 Compare April 21, 2020 15:39
@phlogistonjohn phlogistonjohn force-pushed the jjm-command-funcs-args-refactor branch 2 times, most recently from 5c086df to 87589cc Compare April 28, 2020 18:41
@phlogistonjohn phlogistonjohn changed the title [RFC] refactor command funcs arguments set up refactor command funcs arguments set up Apr 28, 2020
rados/command.go Show resolved Hide resolved
rados/command.go Outdated Show resolved Hide resolved
Now we have sufficient boilerplate in our code for interacting with
various types and ceph calls with similar needs we establish a new
internal package, "cutil" (C utilities).

Note that many of the return types are wrapped. This is due to the
limits placed on us by cgo.  Despite the irritating limitations Go
places on "exporting" C types it still ought to help in the long run for
patterns that are very common or patterns that are subtle and we want to
write specific tests for.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Replace the argument handling (wrangling?) around *_command functions,
such as MonCommand, with the new command input and output helper types
from the internal/cutil package.
No external change should be visible.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Similar to the functions in the rados pkg, cephfs package has a function
MdsCommand that is mostly boilerplate that to set up the C function's
arguments. Replace it with the types from the new cutil internal
package.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
The *_command functions in librados and libcephfs document the use
of specific free functions for data allocated. These functions are
currently just wrappers around C's free() function. However, to be
more strictly compliant this change adds a free-function callback
to the CommandOutput type and the specific free functions are now
used outside the unit tests.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
@phlogistonjohn phlogistonjohn force-pushed the jjm-command-funcs-args-refactor branch from 29e2edf to 2b54175 Compare May 8, 2020 14:24
@phlogistonjohn phlogistonjohn merged commit e2a78ee into ceph:master May 12, 2020
@phlogistonjohn phlogistonjohn deleted the jjm-command-funcs-args-refactor branch May 20, 2020 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants