diff options
| author | Jeremy Kerr <jk@ozlabs.org> | 2018-08-09 10:41:10 +0800 |
|---|---|---|
| committer | Jeremy Kerr <jk@ozlabs.org> | 2018-08-09 13:46:19 +0800 |
| commit | 13bb28fc42c9cb279bc72f083540360ea94d4a75 (patch) | |
| tree | 3da0258a38578c8ae9c3b74f6d133a6dde7093bd | |
| parent | 6f9c4330df5fb85504d21e1aa6973b302d80a5b9 (diff) | |
| download | jsnbd-13bb28fc42c9cb279bc72f083540360ea94d4a75.tar.gz jsnbd-13bb28fc42c9cb279bc72f083540360ea94d4a75.zip | |
nbd-proxy: Add metadata facility
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
| -rw-r--r-- | config.sample.json | 5 | ||||
| -rw-r--r-- | nbd-proxy.c | 39 |
2 files changed, 41 insertions, 3 deletions
diff --git a/config.sample.json b/config.sample.json index dc8e0f2..461046a 100644 --- a/config.sample.json +++ b/config.sample.json @@ -2,7 +2,10 @@ "timeout": 30, "configurations": { "0": { - "nbd-device": "/dev/nbd0" + "nbd-device": "/dev/nbd0", + "metadata": { + "description": "Virtual media device" + } } } } diff --git a/nbd-proxy.c b/nbd-proxy.c index 3ce8879..6b23d6a 100644 --- a/nbd-proxy.c +++ b/nbd-proxy.c @@ -389,6 +389,24 @@ static int run_proxy(struct ctx *ctx) return rc ? -1 : 0; } +static void print_metadata(struct ctx *ctx) +{ + struct json_object *md; + int i; + + md = json_object_new_object(); + + for (i = 0; i < ctx->n_configs; i++) { + struct config *config = &ctx->configs[i]; + json_object_object_add(md, config->name, + config->metadata); + } + + puts(json_object_get_string(md)); + + json_object_put(md); +} + static void config_free_one(struct config *config) { if (config->metadata) @@ -548,17 +566,26 @@ static int config_select(struct ctx *ctx, const char *name) } static const struct option options[] = { - { .name = "help", .val = 'h' }, + { .name = "help", .val = 'h' }, + { .name = "metadata", .val = 'm' }, { 0 }, }; +enum action { + ACTION_PROXY, + ACTION_METADATA, +}; + static void print_usage(const char *progname) { - fprintf(stderr, "usage: %s [configuration]\n", progname); + fprintf(stderr, "usage:\n"); + fprintf(stderr, "\t%s [configuration]\n", progname); + fprintf(stderr, "\t%s --metadata\n", progname); } int main(int argc, char **argv) { + enum action action = ACTION_PROXY; const char *config_name; struct ctx _ctx, *ctx; int rc; @@ -571,6 +598,9 @@ int main(int argc, char **argv) break; switch (c) { + case 'm': + action = ACTION_METADATA; + break; case 'h': case '?': print_usage(argv[0]); @@ -590,6 +620,11 @@ int main(int argc, char **argv) if (rc) goto out_free; + if (action == ACTION_METADATA) { + print_metadata(ctx); + goto out_free; + } + rc = config_select(ctx, config_name); if (rc) goto out_free; |

