Skip to content

Commit

Permalink
libflux/rpc: rename getf->get_unpack
Browse files Browse the repository at this point in the history
Rename flux_rpc_getf() to flux_rpc_get_unpack() per discussion
in flux-framework#1094.

Update users across flux-core, and unit tests.
  • Loading branch information
garlick committed Jul 10, 2017
1 parent 674d906 commit acdc6ec
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 45 deletions.
4 changes: 2 additions & 2 deletions doc/man3/trpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ int main (int argc, char **argv)
"{s:s}", "name", "rank")))
log_err_exit ("flux_rpcf");

if (flux_rpc_getf (f, "{s:s}", "value", &rankstr) < 0)
log_err_exit ("flux_rpc_getf");
if (flux_rpc_get_unpack (f, "{s:s}", "value", &rankstr) < 0)
log_err_exit ("flux_rpc_get_unpack");

printf ("rank is %s\n", rankstr);
flux_future_destroy (f);
Expand Down
4 changes: 2 additions & 2 deletions doc/man3/trpc_then.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ void continuation (flux_future_t *f, void *arg)
{
const char *rankstr;

if (flux_rpc_getf (f, "{s:s}", "value", &rankstr) < 0)
log_err_exit ("flux_rpc_getf");
if (flux_rpc_get_unpack (f, "{s:s}", "value", &rankstr) < 0)
log_err_exit ("flux_rpc_get_unpack");

printf ("rank is %s\n", rankstr);
flux_future_destroy (f);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/builtin/hwloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static struct hwloc_topo * hwloc_topo_create (optparse_t *p)
if (!(t->f = flux_rpc (t->h, "resource-hwloc.topo", NULL, 0, 0)))
log_err_exit ("flux_rpc");

if (flux_rpc_getf (t->f, "{ s:s }", "topology", &t->topo) < 0)
log_err_exit ("flux_rpc_getf");
if (flux_rpc_get_unpack (t->f, "{ s:s }", "topology", &t->topo) < 0)
log_err_exit ("flux_rpc_get_unpack");

return (t);
}
Expand Down
19 changes: 10 additions & 9 deletions src/cmd/builtin/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ static void delrole (flux_t *h, uint32_t userid, uint32_t rolemask)
"rolemask", rolemask);
if (!f)
log_err_exit ("userdb.delrole");
if (flux_rpc_getf (f, "{s:i s:i}", "userid", &userid,
"rolemask", &final) < 0) {
if (flux_rpc_get_unpack (f, "{s:i s:i}", "userid", &userid,
"rolemask", &final) < 0) {
if (errno == ENOSYS)
log_msg_exit ("userdb module is not loaded");
if (errno == ENOENT)
Expand All @@ -132,11 +132,12 @@ static void addrole (flux_t *h, uint32_t userid, uint32_t rolemask)

f = flux_rpc_pack (h, "userdb.addrole", FLUX_NODEID_ANY, 0,
"{s:i s:i}", "userid", userid,
"rolemask", rolemask);
"rolemask", rolemask);
if (!f)
log_err_exit ("userdb.addrole");
if (flux_rpc_getf (f, "{s:i s:i}", "userid", &userid,
"rolemask", &final) < 0) {
if (flux_rpc_get_unpack (f, "{s:i s:i}",
"userid", &userid,
"rolemask", &final) < 0) {
if (errno == ENOSYS)
log_msg_exit ("userdb module is not loaded");
if (errno == ENOENT)
Expand Down Expand Up @@ -190,8 +191,8 @@ static int internal_user_list (optparse_t *p, int ac, char *av[])
f = flux_rpc (h, "userdb.getnext", NULL, FLUX_NODEID_ANY, 0);
if (!f)
log_err_exit ("userdb.getnext");
if (flux_rpc_getf (f, "{s:i s:i}", "userid", &userid,
"rolemask", &rolemask) < 0) {
if (flux_rpc_get_unpack (f, "{s:i s:i}", "userid", &userid,
"rolemask", &rolemask) < 0) {
if (errno == ENOSYS)
log_msg_exit ("userdb module is not loaded");
if (errno != ENOENT)
Expand Down Expand Up @@ -234,8 +235,8 @@ static int internal_user_lookup (optparse_t *p, int ac, char *av[])
"{s:i}", "userid", userid);
if (!f)
log_err_exit ("userdb.lookup");
if (flux_rpc_getf (f, "{s:i s:i}", "userid", &userid,
"rolemask", &rolemask) < 0) {
if (flux_rpc_get_unpack (f, "{s:i s:i}", "userid", &userid,
"rolemask", &rolemask) < 0) {
if (errno == ENOSYS)
log_msg_exit ("userdb module is not loaded");
if (errno == ENOENT)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/flux-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ int cmd_debug (optparse_t *p, int argc, char **argv)
if (!(f = flux_rpc_pack (h, topic, FLUX_NODEID_ANY, 0, "{s:s s:i}",
"op", op, "flags", flags)))
log_err_exit ("%s", topic);
if (flux_rpc_getf (f, "{s:i}", "flags", &flags) < 0)
if (flux_rpc_get_unpack (f, "{s:i}", "flags", &flags) < 0)
log_err_exit ("%s", topic);
printf ("0x%x\n", flags);
flux_future_destroy (f);
Expand Down
5 changes: 3 additions & 2 deletions src/common/libflux/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ static int attr_get_rpc (attr_ctx_t *ctx, const char *name, attr_t **attrp)
if (!(f = flux_rpc_pack (ctx->h, "attr.get", FLUX_NODEID_ANY, 0,
"{s:s}", "name", name)))
goto done;
if (flux_rpc_getf (f, "{s:s, s:i}", "value", &val, "flags", &flags) < 0)
if (flux_rpc_get_unpack (f, "{s:s, s:i}",
"value", &val, "flags", &flags) < 0)
goto done;
if (!(attr = attr_create (val, flags)))
goto done;
Expand Down Expand Up @@ -170,7 +171,7 @@ static int attr_list_rpc (attr_ctx_t *ctx)

if (!(f = flux_rpc (ctx->h, "attr.list", NULL, FLUX_NODEID_ANY, 0)))
goto done;
if (flux_rpc_getf (f, "{s:o}", "names", &array) < 0)
if (flux_rpc_get_unpack (f, "{s:o}", "names", &array) < 0)
goto done;
zlist_destroy (&ctx->names);
if (!(ctx->names = zlist_new ()))
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/flog.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int dmesg_rpc_get (flux_future_t *f, int *seq, flux_log_f fun, void *arg)
const char *buf;
int rc = -1;

if (flux_rpc_getf (f, "{s:i s:s}", "seq", seq, "buf", &buf) < 0)
if (flux_rpc_get_unpack (f, "{s:i s:s}", "seq", seq, "buf", &buf) < 0)
goto done;
fun (buf, strlen (buf), arg);
rc = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/common/libflux/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int flux_rpc_get_raw (flux_future_t *f, void *data, int *len)
return rc;
}

static int flux_rpc_vgetf (flux_future_t *f, const char *fmt, va_list ap)
static int flux_rpc_get_vunpack (flux_future_t *f, const char *fmt, va_list ap)
{
const flux_msg_t *msg;
int rc = -1;
Expand All @@ -126,13 +126,13 @@ static int flux_rpc_vgetf (flux_future_t *f, const char *fmt, va_list ap)
return rc;
}

int flux_rpc_getf (flux_future_t *f, const char *fmt, ...)
int flux_rpc_get_unpack (flux_future_t *f, const char *fmt, ...)
{
va_list ap;
int rc;

va_start (ap, fmt);
rc = flux_rpc_vgetf (f, fmt, ap);
rc = flux_rpc_get_vunpack (f, fmt, ap);
va_end (ap);

return rc;
Expand Down
2 changes: 1 addition & 1 deletion src/common/libflux/rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ flux_future_t *flux_rpc_raw (flux_t *h, const char *topic,

int flux_rpc_get (flux_future_t *f, const char **json_str);

int flux_rpc_getf (flux_future_t *f, const char *fmt, ...);
int flux_rpc_get_unpack (flux_future_t *f, const char *fmt, ...);

int flux_rpc_get_raw (flux_future_t *f, void *data, int *len);

Expand Down
2 changes: 1 addition & 1 deletion src/common/libkvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ int kvs_get_version (flux_t *h, int *versionp)

if (!(f = flux_rpc (h, "kvs.getroot", NULL, FLUX_NODEID_ANY, 0)))
goto done;
if (flux_rpc_getf (f, "{ s:i }", "rootseq", &version) < 0)
if (flux_rpc_get_unpack (f, "{ s:i }", "rootseq", &version) < 0)
goto done;
if (versionp)
*versionp = version;
Expand Down
4 changes: 2 additions & 2 deletions src/common/libkvs/kvs_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int flux_kvs_lookup_get (flux_future_t *f, const char **json_str)
char *s;

if (!(s = flux_future_aux_get (f, auxkey))) {
if (flux_rpc_getf (f, "{s:o}", "val", &obj) < 0)
if (flux_rpc_get_unpack (f, "{s:o}", "val", &obj) < 0)
return -1;
if (!(s = json_dumps (obj, JSON_COMPACT|JSON_ENCODE_ANY))) {
errno = EINVAL;
Expand All @@ -94,7 +94,7 @@ int flux_kvs_lookup_unpack (flux_future_t *f, const char *fmt, ...)
json_t *obj;
int rc;

if (flux_rpc_getf (f, "{s:o}", "val", &obj) < 0)
if (flux_rpc_get_unpack (f, "{s:o}", "val", &obj) < 0)
return -1;
va_start (ap, fmt);
if ((rc = json_vunpack_ex (obj, NULL, 0, fmt, ap) < 0))
Expand Down
2 changes: 1 addition & 1 deletion src/modules/connector-local/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static int lookup_userdb (flux_t *h, uint32_t userid, uint32_t *rolemask)
if (!(f = flux_rpc_pack (h, "userdb.lookup", FLUX_NODEID_ANY, 0,
"{s:i}", "userid", userid)))
goto done;
if (flux_rpc_getf (f, "{s:i}", "rolemask", rolemask) < 0)
if (flux_rpc_get_unpack (f, "{s:i}", "rolemask", rolemask) < 0)
goto done;
rc = 0;
done:
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cron/cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ static int64_t next_cronid (flux_t *h)
goto out;
}

if (flux_rpc_getf (f, "{ s:I }", "value", &ret) < 0) {
flux_log_error (h, "next_cronid: rpc_getf");
if (flux_rpc_get_unpack (f, "{ s:I }", "value", &ret) < 0) {
flux_log_error (h, "next_cronid: rpc_get_unpack");
goto out;
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/kvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,9 @@ static int getroot_rpc (kvs_ctx_t *ctx, int *rootseq, href_t rootdir)

if (!(f = flux_rpc (ctx->h, "kvs.getroot", NULL, FLUX_NODEID_UPSTREAM, 0)))
goto done;
if (flux_rpc_getf (f, "{ s:i s:s }",
"rootseq", rootseq,
"rootdir", &ref) < 0)
if (flux_rpc_get_unpack (f, "{ s:i s:s }",
"rootseq", rootseq,
"rootdir", &ref) < 0)
goto done;
if (strlen (ref) > sizeof (href_t) - 1) {
errno = EPROTO;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/wreck/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ static int64_t next_jobid (flux_t *h)
flux_log_error (h, "next_jobid: flux_rpc");
goto out;
}
if ((flux_rpc_getf (f, "{s:I}", "value", &ret)) < 0) {
flux_log_error (h, "rpc_getf");
if ((flux_rpc_get_unpack (f, "{s:I}", "value", &ret)) < 0) {
flux_log_error (h, "rpc_get_unpack");
goto out;
}
out:
Expand Down
2 changes: 1 addition & 1 deletion t/kvs/watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int get_watch_stats (flux_t *h, int *count)

if (!(f = flux_rpc (h, "kvs.stats.get", NULL, FLUX_NODEID_ANY, 0)))
goto done;
if (flux_rpc_getf (f, "{ s:i }", "#watchers", count) < 0)
if (flux_rpc_get_unpack (f, "{ s:i }", "#watchers", count) < 0)
goto done;
rc = 0;
done:
Expand Down
20 changes: 10 additions & 10 deletions t/rpc/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ void test_encoding (flux_t *h)
ok ((r = flux_rpc_pack (h, "rpctest.incr", FLUX_NODEID_ANY, 0,
"{s:i}", "n", 107)) != NULL,
"flux_rpc_pack works");
ok (flux_rpc_getf (r, NULL) < 0
ok (flux_rpc_get_unpack (r, NULL) < 0
&& errno == EINVAL,
"flux_rpc_getf fails with EINVAL");
ok (flux_rpc_getf (r, "{s:i}", "n", &i) == 0,
"flux_rpc_getf works");
"flux_rpc_get_unpack fails with EINVAL");
ok (flux_rpc_get_unpack (r, "{s:i}", "n", &i) == 0,
"flux_rpc_get_unpack works");
ok (i == 108,
"and service returned incremented value");
flux_future_destroy (r);
Expand All @@ -292,28 +292,28 @@ void test_encoding (flux_t *h)
"{ s:i }", "foo", 42)) != NULL,
"flux_rpc_pack with payload when none is expected works, at first");
errno = 0;
ok (flux_rpc_getf (r, "{}") < 0
ok (flux_rpc_get_unpack (r, "{}") < 0
&& errno == EPROTO,
"flux_rpc_getf fails with EPROTO");
"flux_rpc_get_unpack fails with EPROTO");
flux_future_destroy (r);

/* cause local EPROTO (user incorrectly expects payload) */
ok ((r = flux_rpc_pack (h, "rpcftest.hello", FLUX_NODEID_ANY, 0, "{}")) != NULL,
"flux_rpc_pack with empty payload works");
errno = 0;
ok (flux_rpc_getf (r, "{ s:i }", "foo", &i) < 0
ok (flux_rpc_get_unpack (r, "{ s:i }", "foo", &i) < 0
&& errno == EPROTO,
"flux_rpc_getf fails with EPROTO");
"flux_rpc_get_unpack fails with EPROTO");
flux_future_destroy (r);

/* cause local EPROTO (user incorrectly expects empty payload) */
errno = 0;
ok ((r = flux_rpc_pack (h, "rpctest.echo", FLUX_NODEID_ANY, 0, "{ s:i }", "foo", 42)) != NULL,
"flux_rpc_pack with payload works");
errno = 0;
ok (flux_rpc_getf (r, "{ ! }") < 0
ok (flux_rpc_get_unpack (r, "{ ! }") < 0
&& errno == EPROTO,
"flux_rpc_getf fails with EPROTO");
"flux_rpc_get_unpack fails with EPROTO");
flux_future_destroy (r);

diag ("completed encoding/api test");
Expand Down

0 comments on commit acdc6ec

Please sign in to comment.