Re: Looking to understand *_command API calls better

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 10, 2020 at 5:31 AM John Mulligan
<phlogistonjohn@xxxxxxxxxxxxx> wrote:
>
> Hello ceph-devel,
>

hi John,

> I'm one of the members of the team currently maintaining, and hopefully
> improving, go-ceph (ceph library bindings for Go) [1].
>
> An issue I keep returning to is the nature of api calls such as:
> - rados_mon_command
> - rados_mgr_command
> - ceph_mds_command
> ... etc
>
> The argument named cmd for these functions is of type `const char **cmd` and
> is followed by a `size_t cmdlen`. I'd like to better understand the rationale
> for array-of-char* strings and how this is intended to be used.
>
> When I first saw the function I initially thought it was meant to support
> multiple "commands" getting issued at once but later started thinking that a
> single command could be split across multiple strings, and experimentation
> demonstrated that this does indeed work. I've attempted reading the sources
> but nothing jumps out at me to explain this approach. Most callers of these
> functions seem to only use a single "command string".

yes, see https://github.com/ceph/ceph/blob/master/src/test/librados/cmd.cc
and https://github.com/ceph/ceph/blob/master/src/test/librados/cmd_cxx.cc
. if you look these test cases closely, you might have two findings:

1. actually, one can pass multiple strings (not commands) to
*_command() methods.
2. the cmd array should compose a serialized JSON

>
> I also tried looking to see how the code makes use of the array (or vector
> after the transition to C++) but I will admit I'm not very familiar with C++
> and get a bit lost in some of the templates and overloading.

see https://github.com/ceph/ceph/blob/master/src/common/cmdparse.cc#L292,
the elements in `cmd` vector will be concatenated into a single string
which is in turn fed to a JSON parser. and the JSON parser will parse
that string to a dictionary. in general, the value of "prefix" would
be the string identifying a command handled by one of the daemons
targeted by the *_command() method. for instance, MonCommands.h
defines the commands served by monitor.

>
> Could someone who is familiar with this better explain how this argument and
> it's type is meant to be used?

i am not sure why we need to do the boxing-unboxing dance to set the
JSON string to an array (vector) of strings, and then concatenate them
again. but probably, it's designed to ease the pain to set different
argument with a template. something like:

vector<string> config_set{
  "{",
  R"("prefix": "df",)",
  R"("format": )",
  "", // json, xml, plain ....
  "}"
};
config_set[3] = quoted("json");
rados.mon_command(config_set, input_bufferlist, &output_bufferlist, nullptr);

one can do quite the same in C language:

char* config_set[] =
  "{",
  "\"prefix\": \"df\",",
  "\"format\": ",
  NULL, // json, xml, plain ....
  "}"
};
config_set[3] = "\"json\""; // or it could be a variable or command
line argument
int r = rados_mon_command(config_set, sizeof(config_set) / sizeof(*config_set),
  NULL, 0,
  buf, &buf_len
  out, &out_len);

HTH,

> I want to make sure we're making good use of the apis that ceph provides in
> the wrapper library, or at the very least I want to make sure we're not mis-
> using the apis. :-)
>
> Thank you for your time.
>
> 1 - https://github.com/ceph/go-ceph
>
> _______________________________________________
> Dev mailing list -- dev@xxxxxxx
> To unsubscribe send an email to dev-leave@xxxxxxx



-- 
Regards
Kefu Chai
_______________________________________________
Dev mailing list -- dev@xxxxxxx
To unsubscribe send an email to dev-leave@xxxxxxx



[Index of Archives]     [CEPH Users]     [Ceph Devel]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux