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

rados: add MgrCommand & MgrCommandWithInputBuffer functions #221

Merged
merged 3 commits into from Apr 27, 2020

Conversation

phlogistonjohn
Copy link
Collaborator

@phlogistonjohn phlogistonjohn commented Apr 11, 2020

First, the *Command functions and tests are moved into separate files to reduce the amount of stuff in conn.go & friends. The function signatures are simplified a bit.

Then new functions MgrCommand & MgrCommandWithInputBuffer are added that wrap rados_mgr_command are added along with tests.

Fixes #216

Checklist

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

@ansiwen ansiwen changed the title rados: add MgrCommand & MgrCommandWithInutBuffer functions rados: add MgrCommand & MgrCommandWithInputBuffer functions Apr 21, 2020
Copy link
Collaborator

@ansiwen ansiwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here my first review. Didn’t review the tests yet though...

}

// MonCommandWithInputBuffer sends a command to one of the monitors, with an input buffer
func (c *Conn) MonCommandWithInputBuffer(args, inputBuffer []byte) ([]byte, string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason that you wrap a function with identical signature? (I don't have an issue with it actually, just curious.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the way it was previously done in the codebase before we got here. I've actually considered changing it so that Command calls CommandWithInputBuffer but I didn't want to make those kinds of refactorings here.

}

func (c *Conn) monCommand(args, inputBuffer []byte) ([]byte, string, error) {
argv := C.CString(string(args))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find argv confusing here, because argv is normally a pointer to a string array. Also, why is the parameter called args, suggesting it's an array of arguments, but in reality it's the string of the first argument. Why is it a byte array, and not a string? Later the PGCommand uses [][]byte as type for args, so its also not consistent. (There is also a CBytes() converter, but I see, we need a char* for the rados API.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this predates my involvement in the project.
The naming and the type conistency stuff is something I do want to tackle, but in a somewhat backwards compatible way.

)
inbuf := C.CString(string(inputBuffer))
inbufLen := len(inputBuffer)
defer C.free(unsafe.Pointer(inbuf))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: One line up?


if outslen > 0 {
info = C.GoStringN(outs, C.int(outslen))
C.free(unsafe.Pointer(outs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs say: the caller is expected to release that memory with rados_buffer_free() but you are using the standard free. Also wouldn't it be a safer pattern to defer that in the main scope, since free(NULL) is a noop?

}
if outbuflen > 0 {
buffer = C.GoBytes(unsafe.Pointer(outbuf), C.int(outbuflen))
C.free(unsafe.Pointer(outbuf))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito


if outslen > 0 {
info = C.GoStringN(outs, C.int(outslen))
C.free(unsafe.Pointer(outs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t check the docs, but probably you also should use the rados_buffer_free() here?

}
if outbuflen > 0 {
buffer = C.GoBytes(unsafe.Pointer(outbuf), C.int(outbuflen))
C.free(unsafe.Pointer(outbuf))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dito

argc := len(args)
argv := make([]*C.char, argc)

for i, arg := range args {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha... 😉


if outslen > 0 {
info = C.GoStringN(outs, C.int(outslen))
C.free(unsafe.Pointer(outs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

}
if outbuflen > 0 {
buffer = C.GoBytes(unsafe.Pointer(outbuf), C.int(outbuflen))
C.free(unsafe.Pointer(outbuf))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@phlogistonjohn
Copy link
Collaborator Author

@ansiwen please take a look at my WIP/RFC pr #226. It addresses some of your points about consistency and repeated code.
There would be more to do that just that but I try to keep my prs small(ish) and task oriented. The first patch in this pr is only a code move ... I probably should not have even tried cleaning up the return names in this series but I got ahead of myself. Let's discuss clean-ups and consistency in #226.

@ansiwen
Copy link
Collaborator

ansiwen commented Apr 23, 2020

@phlogistonjohn Yeah, I should have reviewed the individual commits, so that I see what is copied and what is from you. But at least the missing rados_buffer_free() is a valid point that we should already fix here, even if you just move the code, don't you think so? The other stuff, I agree, can go into other PRs.

@phlogistonjohn
Copy link
Collaborator Author

The code in that function in ceph is just a wrapper around free ATM. I agree that we may want to use the proper cleanup function in case ceph chooses to do something more in the future. But I'd still like to tackle that task in #226 or later.

@phlogistonjohn
Copy link
Collaborator Author

@ansiwen I just pushed 43c4575 to PR #226 which now uses the dedicated free funcs for the buffers that are allocated by the ceph *_command calls.

Organize the rados package a bit more by moving functions that wrap
rados_xyz_command functions into a dedicated file. Move related test to
a separate file as well.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add functions for issuing commands to ceph mgrs with
MgrCommand and MgrCommandWithInputBuffer, implemented simliarly
to the other *Command style functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
@phlogistonjohn phlogistonjohn merged commit fb2736d into ceph:master Apr 27, 2020
@phlogistonjohn phlogistonjohn deleted the jjm-rados-command-funcs branch April 28, 2020 18:40
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.

Add support for rados mgr command functions
2 participants