From 87a4205e3cc3d677b056b0b207ee835cd4d2502f Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Thu, 16 Feb 2023 16:31:33 -0600 Subject: [PATCH] Consolidate CLI output functions It seemed like every tool defined its own `syntax()` and/or `fatal()`. By making a single a definition for each in libhse-cli, we can cut down all the redefinitions. This also has the added benefit of reducing the number of tools needing tools/common.c. Less compilation. Yay! Signed-off-by: Tristan Partin --- cli/include/hse/cli/output.h | 21 +++++ cli/lib/meson.build | 1 + cli/lib/output.c | 77 ++++++++++++++++++ cli/meson.build | 2 + tools/attack/attack.c | 29 +------ tools/bnt/bnt.c | 13 +-- tools/boundcur/boundcur.c | 18 +--- tools/capput/capput.c | 18 +--- tools/cn_metrics/cn_metrics.c | 18 +--- tools/cndump/cndb_dump.c | 8 +- tools/cndump/cndb_reader.c | 8 +- tools/cndump/cndb_record.c | 6 +- tools/cndump/cndump.c | 2 +- tools/cndump/fatal.c | 41 ---------- tools/cndump/fatal.h | 18 ---- tools/cndump/kvset_dump.c | 32 ++++---- tools/common.c | 46 ----------- tools/ctxn_validation/ctxn_validation.c | 36 +------- tools/hsettp/hsettp.c | 14 +--- tools/include/hse/tools/common.h | 7 -- tools/kmt/kmt.c | 14 +--- tools/ksync/ksync.c | 13 +-- tools/kvs_helper.c | 2 + tools/kvt/kvt.c | 13 +-- tools/longtest/longtest.c | 17 +--- tools/meson.build | 15 ---- tools/mpool/mblock/mpiotest.c | 14 +--- tools/mpool/mdc/mdc_tool.c | 38 ++------- tools/multicursor/multicursor.c | 18 +--- tools/pfx_probe/pfx_probe.c | 5 +- tools/pgd/pgd.c | 11 +-- tools/pscan/pscan.c | 20 +---- tools/ptree-overload/ptree-overload.c | 18 +--- tools/put_flush/put_flush.c | 5 +- tools/put_txget/put_txget.c | 5 +- tools/putbin/putbin.c | 19 +++-- tools/putgetdel/putgetdel.c | 104 +++++++----------------- tools/range_read/range_read.c | 19 +---- tools/simple_client/simple_client.c | 36 +------- tools/throttle/throttle.c | 95 ++++++---------------- tools/txn_thrash/txn_thrash.c | 5 +- tools/txput_flush/txput_flush.c | 5 +- tools/upsert/upsert.c | 20 +---- tools/waltest/waltest.c | 93 +++++++-------------- tools/wscan/wscan.c | 7 +- 45 files changed, 295 insertions(+), 731 deletions(-) create mode 100644 cli/include/hse/cli/output.h create mode 100644 cli/lib/output.c delete mode 100644 tools/cndump/fatal.c delete mode 100644 tools/cndump/fatal.h diff --git a/cli/include/hse/cli/output.h b/cli/include/hse/cli/output.h new file mode 100644 index 000000000..3ee107cd0 --- /dev/null +++ b/cli/include/hse/cli/output.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: Apache-2.0 OR MIT + * + * SPDX-FileCopyrightText: Copyright 2023 Micron Technology, Inc. + */ + +#include + +#include + +HSE_PRINTF(2, 3) void +error(hse_err_t err, const char *fmt, ...); + +#define errorx(_fmt, ...) error(0, (_fmt), ##__VA_ARGS__) + +HSE_PRINTF(2, 3) HSE_NORETURN void +fatal(hse_err_t err, const char *fmt, ...); + +#define fatalx(_fmt, ...) fatal(0, (_fmt), ##__VA_ARGS__) + +HSE_PRINTF(1, 2) HSE_NORETURN void +syntax(const char *fmt, ...); diff --git a/cli/lib/meson.build b/cli/lib/meson.build index f33c0b2d3..6fd698c08 100644 --- a/cli/lib/meson.build +++ b/cli/lib/meson.build @@ -3,6 +3,7 @@ # SPDX-FileCopyrightText: Copyright 2021 Micron Technology, Inc. cli_sources = files( + 'output.c', 'param.c', 'program.c', 'rest/api.c', diff --git a/cli/lib/output.c b/cli/lib/output.c new file mode 100644 index 000000000..05da11a23 --- /dev/null +++ b/cli/lib/output.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: Apache-2.0 OR MIT + * + * SPDX-FileCopyrightText: Copyright 2023 Micron Technology, Inc. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +static thread_local char error_buffer_tls[1024]; + +static void +eprint(const hse_err_t err, const char *fmt, va_list ap) +{ + int rc HSE_MAYBE_UNUSED; + + if (err) { + char buf[256]; + size_t needed_sz HSE_MAYBE_UNUSED; + + needed_sz = hse_strerror(err, buf, sizeof(buf)); + assert(needed_sz < sizeof(buf)); + + rc = snprintf( + error_buffer_tls, sizeof(error_buffer_tls), "%s: %s: %s\n", progname, fmt, buf); + } else { + rc = snprintf(error_buffer_tls, sizeof(error_buffer_tls), "%s: %s\n", progname, fmt); + } + assert(rc >= 0 && rc < sizeof(error_buffer_tls)); + + vfprintf(stderr, error_buffer_tls, ap); +} + +void +error(const hse_err_t err, const char * const fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + eprint(err, fmt, ap); + va_end(ap); +} + +void +fatal(const hse_err_t err, const char * const fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + eprint(err, fmt, ap); + va_end(ap); + + exit(1); +} + +void +syntax(const char * const fmt, ...) +{ + va_list ap; + char msg[256]; + + va_start(ap, fmt); + vsnprintf(msg, sizeof(msg), fmt, ap); + va_end(ap); + + error(0, "%s, use -h for help", msg); + exit(EX_USAGE); +} diff --git a/cli/meson.build b/cli/meson.build index 1a360b08a..2674cd579 100644 --- a/cli/meson.build +++ b/cli/meson.build @@ -24,6 +24,8 @@ hse_cli = static_library( ], dependencies: [ cjson_dep, + # TODO: Remove when the cli can depend on libhse-util + hse_internal_dep, hse_error_dep, libcurl_dep, rbtree_dep, diff --git a/tools/attack/attack.c b/tools/attack/attack.c index 71da8442d..c6bbc04b3 100644 --- a/tools/attack/attack.c +++ b/tools/attack/attack.c @@ -29,37 +29,10 @@ #include +#include #include #include -void HSE_PRINTF(2, 3) -fatal(hse_err_t err, char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - if (err) - fprintf(stderr, ": %ld\n", (long)err); - else - fprintf(stderr, "\n"); - va_end(ap); - exit(1); -} - -void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { diff --git a/tools/bnt/bnt.c b/tools/bnt/bnt.c index d68605ceb..92e31ed82 100644 --- a/tools/bnt/bnt.c +++ b/tools/bnt/bnt.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -350,18 +351,6 @@ humanize(u_long *nump, char **sufp) } } -__attribute__((format(printf, 1, 2))) void -syntax(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsnprintf(emsg, sizeof(emsg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, emsg); -} - uint64_t strtou64(const void *str, char **endp, u_int base) { diff --git a/tools/boundcur/boundcur.c b/tools/boundcur/boundcur.c index 07ce87a50..9e14a2ac2 100644 --- a/tools/boundcur/boundcur.c +++ b/tools/boundcur/boundcur.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -134,19 +135,6 @@ do_work(void *arg) rc = hse_kvs_cursor_destroy(c); } -void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { @@ -237,10 +225,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/capput/capput.c b/tools/capput/capput.c index 9e9a09aec..7f0262c34 100644 --- a/tools/capput/capput.c +++ b/tools/capput/capput.c @@ -46,6 +46,7 @@ #include +#include #include #include #include @@ -533,19 +534,6 @@ reader(void *arg) hse_kvdb_txn_free(targ->kvdb, txn); } -void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { @@ -681,10 +669,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/cn_metrics/cn_metrics.c b/tools/cn_metrics/cn_metrics.c index 80e470d00..1d23b8971 100644 --- a/tools/cn_metrics/cn_metrics.c +++ b/tools/cn_metrics/cn_metrics.c @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -48,19 +49,6 @@ usage(void) progname); } -void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - /* Big enough for s64 min/max, u64 max, etc */ #define BIGNUM_WIDTH_MAX 21 /* max width for signed 64-bit */ @@ -551,10 +539,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/cndump/cndb_dump.c b/tools/cndump/cndb_dump.c index 515583cb4..fcc869140 100644 --- a/tools/cndump/cndb_dump.c +++ b/tools/cndump/cndb_dump.c @@ -11,13 +11,13 @@ #include +#include #include #include #include "cndb_reader.h" #include "cndb_record.h" #include "commands.h" -#include "fatal.h" #include "globals.h" /* command line options for cndb sub-command */ @@ -103,11 +103,11 @@ cndb_cmd(int argc, char **argv) err = hse_init(0, NELEM(paramv), paramv); if (err) - fatal("hse_init", err); + fatal(err, "hse_init"); err = diag_kvdb_open(opts.home, 0, 0, &kvdb); if (err) - fatal("diag_kvdb_open", err); + fatal(err, "diag_kvdb_open"); cndb_iter_init(kvdb, &reader); cndb_rec_init(&rec); @@ -117,7 +117,7 @@ cndb_cmd(int argc, char **argv) err = diag_kvdb_close(kvdb); if (err) - fatal("diag_kvdb_close", err); + fatal(err, "diag_kvdb_close"); hse_fini(); } diff --git a/tools/cndump/cndb_reader.c b/tools/cndump/cndb_reader.c index 10b980ca0..fd5db9853 100644 --- a/tools/cndump/cndb_reader.c +++ b/tools/cndump/cndb_reader.c @@ -3,12 +3,12 @@ * SPDX-FileCopyrightText: Copyright 2022 Micron Technology, Inc. */ +#include #include #include #include "cndb_reader.h" #include "cndb_record.h" -#include "fatal.h" static void read_record(struct cndb_dump_reader *reader, struct cndb_rec *rec) @@ -23,7 +23,7 @@ read_record(struct cndb_dump_reader *reader, struct cndb_rec *rec) } if (err) - fatal("mpool_mdc_read", err); + fatal(err, "mpool_mdc_read"); if (reclen) { rec->type = omf_cnhdr_type(rec->buf); @@ -42,14 +42,14 @@ cndb_iter_init(struct hse_kvdb *kvdb, struct cndb_dump_reader *r) err = diag_kvdb_get_cndb(kvdb, &cndb); if (err) - fatal("diag_kvdb_get_cndb", err); + fatal(err, "diag_kvdb_get_cndb"); r->mdc = cndb_mdc_get(cndb); r->eof = false; err = mpool_mdc_rewind(r->mdc); if (err) - fatal("mpool_mdc_rewind", err); + fatal(err, "mpool_mdc_rewind"); } bool diff --git a/tools/cndump/cndb_record.c b/tools/cndump/cndb_record.c index 3ca5d7c09..7da6ea664 100644 --- a/tools/cndump/cndb_record.c +++ b/tools/cndump/cndb_record.c @@ -3,11 +3,11 @@ * SPDX-FileCopyrightText: Copyright 2022 Micron Technology, Inc. */ +#include #include #include "cndb/omf.h" #include "cndb_record.h" -#include "fatal.h" const char * cndb_rec_type_name(enum cndb_rec_type rtype) @@ -54,7 +54,7 @@ cndb_rec_resize(struct cndb_rec *rec, size_t reclen) p = realloc(rec->buf, newsz); if (!p) - fatal("realloc", merr(ENOMEM)); + fatal(merr(ENOMEM), "realloc"); rec->bufsz = newsz; rec->buf = p; @@ -69,7 +69,7 @@ cndb_rec_clone(struct cndb_rec *rec, struct cndb_rec *clone) clone->bufsz = rec->bufsz; clone->buf = malloc(rec->bufsz); if (!clone->buf) - fatal("malloc", merr(ENOMEM)); + fatal(merr(ENOMEM), "malloc"); memcpy(clone->buf, rec->buf, rec->bufsz); cndb_rec_parse(clone); } else { diff --git a/tools/cndump/cndump.c b/tools/cndump/cndump.c index 4c9d8f1dd..5e9ec776e 100644 --- a/tools/cndump/cndump.c +++ b/tools/cndump/cndump.c @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -17,7 +18,6 @@ #include "cndb/omf.h" #include "cndb_reader.h" #include "commands.h" -#include "fatal.h" #include "globals.h" /* globals */ diff --git a/tools/cndump/fatal.c b/tools/cndump/fatal.c deleted file mode 100644 index 19d680378..000000000 --- a/tools/cndump/fatal.c +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 OR MIT - * - * SPDX-FileCopyrightText: Copyright 2022 Micron Technology, Inc. - */ - -#include -#include -#include - -#include - -#include - -#include "fatal.h" -#include "globals.h" - -void -fatal(const char *who, merr_t err) -{ - char buf[256]; - - hse_strerror(err, buf, sizeof(buf)); - fprintf(stderr, "%s: %s: %s\n", progname, who, buf); - exit(EX_OSERR); -} - -void -syntax(const char *fmt, ...) -{ - va_list ap; - - fprintf(stderr, "%s: ", progname); - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - fprintf(stderr, " (use -h for help)\n"); - - exit(EX_USAGE); -} diff --git a/tools/cndump/fatal.h b/tools/cndump/fatal.h deleted file mode 100644 index 9606c3c83..000000000 --- a/tools/cndump/fatal.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 OR MIT - * - * SPDX-FileCopyrightText: Copyright 2022 Micron Technology, Inc. - */ - -#ifndef CNDUMP_FATAL_H -#define CNDUMP_FATAL_H - -#include -#include - -HSE_NORETURN void -fatal(const char *who, merr_t err); - -HSE_NORETURN void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...); - -#endif diff --git a/tools/cndump/kvset_dump.c b/tools/cndump/kvset_dump.c index 3c8275b8e..38bab13a7 100644 --- a/tools/cndump/kvset_dump.c +++ b/tools/cndump/kvset_dump.c @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -26,7 +27,6 @@ #include "cndb_reader.h" #include "cndb_record.h" #include "commands.h" -#include "fatal.h" #include "globals.h" bool dumping_mblock; @@ -182,7 +182,7 @@ fmt_data( if (bufsz < output_len) { void *p = realloc(buf, output_len); if (!p) - fatal("realloc", merr(ENOMEM)); + fatal(merr(ENOMEM), "realloc"); buf = *buf_ptr = p; bufsz = *bufsz_ptr = output_len; } @@ -518,7 +518,7 @@ bloom_dump(struct dump_mblock *mblk) cntv = calloc(bktmax, sizeof(*cntv)); if (!cntv) - fatal("calloc", merr(ENOMEM)); + fatal(merr(ENOMEM), "calloc"); cntmax = cntsum = cntempty = cntfull = 0; cntmin = UINT_MAX; @@ -774,7 +774,7 @@ get_props(struct mpool *mp, uint64_t mbid, struct mblock_props *props) err = mpool_mblock_props_get(mp, mbid, props); if (err) - fatal("mpool_mblock_props_get", err); + fatal(err, "mpool_mblock_props_get"); } static void @@ -789,7 +789,7 @@ read_mblock(struct mpool *mp, struct dump_mblock *mblk) data = aligned_alloc(PAGE_SIZE, ALIGN(wlen, PAGE_SIZE)); if (!data) - fatal("aligned_alloc", merr(errno)); + fatal(merr(errno), "aligned_alloc"); memset(data, 0xbe, wlen); @@ -798,7 +798,7 @@ read_mblock(struct mpool *mp, struct dump_mblock *mblk) err = mpool_mblock_read(mp, mblk->props.mpr_objid, &iov, 1, 0); if (err) - fatal("mpool_mblock_read", err); + fatal(err, "mpool_mblock_read"); mblk->data = data; } @@ -811,7 +811,7 @@ dkvset_read_props(struct mpool *mp, struct dump_kvset *kvset) kvset->kblkv = calloc(rec->kblkc, sizeof(kvset->kblkv[0])); kvset->vblkv = calloc(rec->vblkc, sizeof(kvset->vblkv[0])); if (!kvset->kblkv || !kvset->vblkv) - fatal("calloc", merr(ENOMEM)); + fatal(merr(ENOMEM), "calloc"); get_props(mp, rec->hblkid, &kvset->hblk.props); @@ -876,11 +876,11 @@ kvset_cmd(int argc, char **argv) err = hse_init(0, NELEM(paramv), paramv); if (err) - fatal("hse_init", err); + fatal(err, "hse_init"); err = diag_kvdb_open(opts.home, 0, 0, &kvdb); if (err) - fatal("diag_kvdb_open", err); + fatal(err, "diag_kvdb_open"); printf("# Kvset ID %lu\n", opts.kvset_id); @@ -895,7 +895,7 @@ kvset_cmd(int argc, char **argv) continue; if (found) - fatal("CDNB log has two kvsets with same ID", merr(EPROTO)); + fatal(merr(EPROTO), "CDNB log has two kvsets with same ID"); found = true; dkvset_init(&kvset, &rec); @@ -903,12 +903,12 @@ kvset_cmd(int argc, char **argv) } else if (rec.type == CNDB_TYPE_KVSET_DEL) { if (rec.rec.kvset_del.kvsetid == opts.kvset_id) - fatal("kvset no longer exists", merr(EINVAL)); + fatal(merr(EINVAL), "kvset no longer exists"); } } if (!found) - fatal("no such kvset", merr(EINVAL)); + fatal(merr(EINVAL), "no such kvset"); cndb_rec_fini(&rec); @@ -927,7 +927,7 @@ kvset_cmd(int argc, char **argv) err = diag_kvdb_close(kvdb); if (err) - fatal("diag_kvdb_close", err); + fatal(err, "diag_kvdb_close"); hse_fini(); } @@ -950,11 +950,11 @@ mblock_cmd(int argc, char **argv) err = hse_init(0, NELEM(paramv), paramv); if (err) - fatal("hse_init", err); + fatal(err, "hse_init"); err = diag_kvdb_open(opts.home, 0, 0, &kvdb); if (err) - fatal("diag_kvdb_open", err); + fatal(err, "diag_kvdb_open"); mp = ikvdb_mpool_get((struct ikvdb *)kvdb); @@ -966,7 +966,7 @@ mblock_cmd(int argc, char **argv) err = diag_kvdb_close(kvdb); if (err) - fatal("diag_kvdb_close", err); + fatal(err, "diag_kvdb_close"); hse_fini(); } diff --git a/tools/common.c b/tools/common.c index 42c689ed7..e9001ccc4 100644 --- a/tools/common.c +++ b/tools/common.c @@ -22,52 +22,6 @@ struct app_opts Opts; -static void -error(hse_err_t err, char *fmt, va_list ap) -{ - char user_msg[128]; - char err_msg[128]; - bool user_msg_empty, need_newline; - size_t off; - - off = 0; - - vsnprintf(user_msg, sizeof(user_msg), fmt, ap); - - if (err) { - off += hse_strerror(err, err_msg + off, sizeof(err_msg) - (ulong)off); - off += (size_t)snprintf(err_msg + off, sizeof(err_msg) - (ulong)off, " (0x%lx)", err); - } - - user_msg_empty = user_msg[0] == '\0'; - need_newline = off > 0 && err_msg[off - 1] != '\n'; - - fprintf( - stderr, "%s%s%s%s", user_msg, user_msg_empty ? "" : " ", err_msg, need_newline ? "\n" : ""); -} - -void -warn(hse_err_t err, char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - error(err, fmt, ap); - va_end(ap); -} - -void -fatal(hse_err_t err, char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - error(err, fmt, ap); - va_end(ap); - - exit(1); -} - static inline unsigned char atobin(char c) { diff --git a/tools/ctxn_validation/ctxn_validation.c b/tools/ctxn_validation/ctxn_validation.c index cae343683..f9b7d073b 100644 --- a/tools/ctxn_validation/ctxn_validation.c +++ b/tools/ctxn_validation/ctxn_validation.c @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -116,37 +117,6 @@ eprint(const char *fmt, ...) fprintf(stderr, "%s: %s", progname, msg); } -__attribute__((format(printf, 1, 2))) void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - -__attribute__((format(printf, 2, 3), __noreturn__)) void -fatal(uint64_t err, const char *fmt, ...) -{ - char msg[128], errbuf[300]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - if (err) { - hse_strerror(err, errbuf, sizeof(errbuf)); - fprintf(stderr, "%s: %s: %s\n", progname, msg, errbuf); - } - - exit(1); -} - void ctxn_validation_init(void) { @@ -1074,10 +1044,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/hsettp/hsettp.c b/tools/hsettp/hsettp.c index 75f9482c4..8a9f77134 100644 --- a/tools/hsettp/hsettp.c +++ b/tools/hsettp/hsettp.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -1645,19 +1646,6 @@ root_usage(FILE * const output) fprintf(output, "\nUse -hv to show additional infrequently used operations\n"); } -static void HSE_PRINTF(1, 2) -syntax(const char * const fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - int main(const int argc, char ** const argv) { diff --git a/tools/include/hse/tools/common.h b/tools/include/hse/tools/common.h index de7473b48..af3c3e0e3 100644 --- a/tools/include/hse/tools/common.h +++ b/tools/include/hse/tools/common.h @@ -18,16 +18,9 @@ #include -void -warn(hse_err_t err, char *fmt, ...) HSE_PRINTF(2, 3); -void -fatal(hse_err_t err, char *fmt, ...) HSE_PRINTF(2, 3); - /* * key/value formatting */ -char * -fmt(void *out, int max, const void *data, int len); size_t fmt_data(char *out, char *in); diff --git a/tools/kmt/kmt.c b/tools/kmt/kmt.c index 0c038bd33..9921747c5 100644 --- a/tools/kmt/kmt.c +++ b/tools/kmt/kmt.c @@ -165,6 +165,7 @@ #include #include +#include #include #include #include @@ -4007,19 +4008,6 @@ struct km_impl km_impl_mongo = { .vlenmax_max = 4ul << 20, }; -__attribute__((format(printf, 1, 2))) void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - ulong cvt_strtoul( #if __GNUC__ > 4 diff --git a/tools/ksync/ksync.c b/tools/ksync/ksync.c index ac7302313..5157243ed 100644 --- a/tools/ksync/ksync.c +++ b/tools/ksync/ksync.c @@ -16,6 +16,7 @@ #include +#include #include #include @@ -61,18 +62,6 @@ eprint(char *fmt, ...) va_end(ap); } -__attribute__((format(printf, 1, 2))) void -syntax(const char *fmt, ...) -{ - va_list ap; - - fprintf(stderr, "%s: ", progname); - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); -} - void stuff(void) { diff --git a/tools/kvs_helper.c b/tools/kvs_helper.c index 4e3278ee8..3186f8a9f 100644 --- a/tools/kvs_helper.c +++ b/tools/kvs_helper.c @@ -17,6 +17,8 @@ #include #include +#include + #include "kvs_helper.h" struct test { diff --git a/tools/kvt/kvt.c b/tools/kvt/kvt.c index fe3c42f7e..359d700b4 100644 --- a/tools/kvt/kvt.c +++ b/tools/kvt/kvt.c @@ -145,6 +145,7 @@ #include +#include #include #include @@ -558,18 +559,6 @@ humanize(u_long *nump, char **sufp) } } -__attribute__((format(printf, 1, 2))) void -syntax(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsnprintf(emsg, sizeof(emsg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, emsg); -} - uint64_t strtou64(const void *str, char **endp, u_int base) { diff --git a/tools/longtest/longtest.c b/tools/longtest/longtest.c index 78afe0b61..0e791e328 100644 --- a/tools/longtest/longtest.c +++ b/tools/longtest/longtest.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -147,8 +148,6 @@ /* == Section: Command Line Processing ================ */ -static void -syntax(const char *fmt, ...); static void usage(void); @@ -713,20 +712,6 @@ usage(void) "\n"); } -static void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); - exit(EX_USAGE); -} - /* get time of day as a count of micro seconds */ uint64_t gtod_usec(void) diff --git a/tools/meson.build b/tools/meson.build index 61ad4d233..0c13cbf0b 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -26,7 +26,6 @@ tools = { 'dependencies': [hse_internal_dep], 'sources': files( 'boundcur/boundcur.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -38,7 +37,6 @@ tools = { ], 'sources': files( 'capput/capput.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -47,7 +45,6 @@ tools = { 'dependencies': [hse_internal_dep], 'sources': files( 'cn_metrics/cn_metrics.c', - 'common.c', 'parm_groups.c' ), }, @@ -58,7 +55,6 @@ tools = { 'cndump/cndb_reader.c', 'cndump/cndb_record.c', 'cndump/cndump.c', - 'cndump/fatal.c', 'cndump/kvset_dump.c', ), }, @@ -193,7 +189,6 @@ tools = { ], 'sources': files( 'multicursor/multicursor.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -205,7 +200,6 @@ tools = { ], 'sources': files( 'pfx_probe/pfx_probe.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -236,7 +230,6 @@ tools = { ], 'sources': files( 'ptree-overload/ptree-overload.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -248,7 +241,6 @@ tools = { ], 'sources': files( 'put_flush/put_flush.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -260,7 +252,6 @@ tools = { ], 'sources': files( 'put_txget/put_txget.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -272,7 +263,6 @@ tools = { ], 'sources': files( 'putbin/putbin.c', - 'common.c', 'parm_groups.c' ), }, @@ -295,7 +285,6 @@ tools = { ], 'sources': files( 'range_read/range_read.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -325,7 +314,6 @@ tools = { ], 'sources': files( 'txn_thrash/txn_thrash.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -337,7 +325,6 @@ tools = { ], 'sources': files( 'txput_flush/txput_flush.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ) @@ -349,7 +336,6 @@ tools = { ], 'sources': files( 'upsert/upsert.c', - 'common.c', 'kvs_helper.c', 'parm_groups.c' ), @@ -372,7 +358,6 @@ tools = { ], 'sources': files( 'wscan/wscan.c', - 'common.c', 'parm_groups.c' ), }, diff --git a/tools/mpool/mblock/mpiotest.c b/tools/mpool/mblock/mpiotest.c index 2e69534f8..eabe412f8 100644 --- a/tools/mpool/mblock/mpiotest.c +++ b/tools/mpool/mblock/mpiotest.c @@ -32,6 +32,7 @@ #include +#include #include #include #include @@ -126,19 +127,6 @@ int debug; volatile sig_atomic_t sigalrm; volatile sig_atomic_t sigint; -void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - /* Error print. */ static void HSE_PRINTF(1, 2) diff --git a/tools/mpool/mdc/mdc_tool.c b/tools/mpool/mdc/mdc_tool.c index d4c32ff48..a676096a7 100644 --- a/tools/mpool/mdc/mdc_tool.c +++ b/tools/mpool/mdc/mdc_tool.c @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -31,29 +32,6 @@ */ static char buf[8192]; -void -fatal(char *who, hse_err_t err) -{ - char buf[ERROR_BUF_SIZE]; - - hse_strerror(err, buf, sizeof(buf)); - log_err("mdc_tool: %s: %s", who, buf); - exit(1); -} - -void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - int dump(char *buf, size_t sz) { @@ -74,11 +52,11 @@ eopen_mdc(struct mpool * const mp, const struct kvdb_meta * const meta, struct m err = mpool_mdc_open(mp, meta->km_cndb.oid1, meta->km_cndb.oid2, false, mdc); if (err) - fatal("mpool_mdc_open", err); + fatal(err, "mpool_mdc_open"); err = mpool_mdc_rewind(*mdc); if (err) - fatal("mpool_mdc_rewind", err); + fatal(err, "mpool_mdc_rewind"); } void @@ -162,25 +140,25 @@ main(int argc, char **argv) err = hse_init(config, 0, NULL); if (err) - fatal("hse_init", err); + fatal(err, "hse_init"); fp = 0; if (wpath) { fp = fopen(wpath, "w"); if (!fp) - fatal(wpath, errno); + fatal(errno, "%s", wpath); } err = kvdb_meta_deserialize(&meta, home); if (err) - fatal("kvdb_meta_deserialize", err); + fatal(err, "kvdb_meta_deserialize"); for (int i = HSE_MCLASS_BASE; i < HSE_MCLASS_CAPACITY; i++) strlcpy(params.mclass[i].path, meta.km_storage[i].path, sizeof(params.mclass[i].path)); err = mpool_open(home, ¶ms, O_RDWR, &mp); if (err) - fatal("mpool_open", err); + fatal(err, "mpool_open"); eopen_mdc(mp, &meta, &mdc); @@ -203,7 +181,7 @@ main(int argc, char **argv) fclose(fp); if (err) - fatal("mpool_mdc_read", err); + fatal(err, "mpool_mdc_read"); hse_fini(); diff --git a/tools/multicursor/multicursor.c b/tools/multicursor/multicursor.c index 5f15b1400..464a6eebf 100644 --- a/tools/multicursor/multicursor.c +++ b/tools/multicursor/multicursor.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -242,19 +243,6 @@ usage(void) progname); } -void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - int main(int argc, char **argv) { @@ -338,10 +326,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/pfx_probe/pfx_probe.c b/tools/pfx_probe/pfx_probe.c index 7cb30d2b2..a0a54c559 100644 --- a/tools/pfx_probe/pfx_probe.c +++ b/tools/pfx_probe/pfx_probe.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -390,10 +391,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/pgd/pgd.c b/tools/pgd/pgd.c index 6dc39d3cf..1e4bfdc87 100644 --- a/tools/pgd/pgd.c +++ b/tools/pgd/pgd.c @@ -28,6 +28,7 @@ #include +#include #include #include @@ -141,7 +142,7 @@ main(int argc, char **argv) usage(); if (argc - optind < 2) - fatal(0, "missing required params: kvdb and kvs"); + fatalx("missing required params: kvdb and kvs"); mpname = argv[optind++]; kvsname = argv[optind++]; @@ -151,10 +152,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); @@ -220,12 +221,12 @@ main(int argc, char **argv) if (err) break; if (!fnd) - warn(ENOENT, "cannot find key %s", key); + error(ENOENT, "cannot find key %s", key); else if (action == GET) show(kbuf, klen, gbuf, glen, 0); else if (glen != vlen || memcmp(vbuf, gbuf, vlen)) { fmt_pe(obuf, sizeof(gbuf), gbuf, glen); - warn(EIO, "wanted %d/%s, got %ld/%s", vlen, val, glen, obuf); + error(EIO, "wanted %d/%s, got %ld/%s", vlen, val, glen, obuf); } break; } diff --git a/tools/pscan/pscan.c b/tools/pscan/pscan.c index 8050666cb..de9c4165d 100644 --- a/tools/pscan/pscan.c +++ b/tools/pscan/pscan.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -58,19 +59,6 @@ struct shr { pthread_t tid; }; -void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { @@ -300,10 +288,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); @@ -473,7 +461,7 @@ main(int argc, char **argv) err = hse_kvdb_close(kvdb_h); if (err) - warn(err, "hse_kvdb_close"); + error(err, "hse_kvdb_close"); pg_destroy(pg); svec_reset(&hse_gparm); diff --git a/tools/ptree-overload/ptree-overload.c b/tools/ptree-overload/ptree-overload.c index c995e2e43..2228a542b 100644 --- a/tools/ptree-overload/ptree-overload.c +++ b/tools/ptree-overload/ptree-overload.c @@ -16,6 +16,7 @@ #include +#include #include #include @@ -71,19 +72,6 @@ dostuff(void *arg) killthreads = 1; } -void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { @@ -171,10 +159,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/put_flush/put_flush.c b/tools/put_flush/put_flush.c index 93205cb70..1fff17dec 100644 --- a/tools/put_flush/put_flush.c +++ b/tools/put_flush/put_flush.c @@ -19,6 +19,7 @@ #include #include +#include #include #include "kvs_helper.h" @@ -100,10 +101,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/put_txget/put_txget.c b/tools/put_txget/put_txget.c index e618367f3..b281ad98c 100644 --- a/tools/put_txget/put_txget.c +++ b/tools/put_txget/put_txget.c @@ -19,6 +19,7 @@ #include +#include #include #include "kvs_helper.h" @@ -96,10 +97,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/putbin/putbin.c b/tools/putbin/putbin.c index 3f70989c5..b5c4149ee 100644 --- a/tools/putbin/putbin.c +++ b/tools/putbin/putbin.c @@ -24,6 +24,7 @@ #include +#include #include #include @@ -319,13 +320,13 @@ main(int argc, char **argv) break; case '?': /* fallthru */ default: - fatal(0, "invalid option: -%c\nuse -h for help\n", c); + fatalx("invalid option: -%c\nuse -h for help\n", c); break; } } if (argc - optind < 2) - fatal(0, "missing required parameter\nuse -h for help"); + fatalx("missing required parameter\nuse -h for help"); mpname = argv[optind++]; kvname = argv[optind++]; @@ -334,10 +335,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); @@ -369,7 +370,7 @@ main(int argc, char **argv) info = calloc(tc, sizeof(*info)); if (!info) - fatal(0, "cannot alloc thread info"); + fatalx("cannot alloc thread info"); /* keys and values share the same data buffer, * which is modified to hold the sequence number; @@ -384,7 +385,7 @@ main(int argc, char **argv) buf = malloc(len); if (!buf) - fatal(0, "cannot alloc thread buffers"); + fatalx("cannot alloc thread buffers"); memcpy(buf, data, len); @@ -420,7 +421,7 @@ main(int argc, char **argv) rc = pthread_create(&ti->tid, 0, run, ti); if (rc) - warn(rc, "cannot create thread %d", c); + error(rc, "cannot create thread %d", c); else ti->joined = 0; } @@ -431,7 +432,7 @@ main(int argc, char **argv) continue; rc = pthread_join(ti->tid, 0); if (rc) - warn(rc, "cannot join tid[%d]=%ld: %d %s", c, ti->tid, rc, strerror(rc)); + error(rc, "cannot join tid[%d]=%ld: %d %s", c, ti->tid, rc, strerror(rc)); else ti->joined = 1; } @@ -444,7 +445,7 @@ main(int argc, char **argv) } rc = pthread_join(ti->tid, 0); if (rc) { - warn(rc, "repeated join tid[%d]=%ld: %d %s", c, ti->tid, rc, strerror(rc)); + error(rc, "repeated join tid[%d]=%ld: %d %s", c, ti->tid, rc, strerror(rc)); usleep(2000); } else ++c; diff --git a/tools/putgetdel/putgetdel.c b/tools/putgetdel/putgetdel.c index 359246d41..ca066e8f2 100644 --- a/tools/putgetdel/putgetdel.c +++ b/tools/putgetdel/putgetdel.c @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -107,54 +108,9 @@ struct thread_info { int pfxlen; }; -static void -syntax(const char *fmt, ...) HSE_PRINTF(1, 2); -static void -quit(const char *fmt, ...) HSE_PRINTF(1, 2); static void usage(void); -static void -quit(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - if (fmt && *fmt) { - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - fprintf(stderr, "%s: %s\n", progname, msg); - fflush(stderr); - } - exit(-1); -} - -static void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s\nUse -h for help.\n", progname, msg); - exit(EX_USAGE); -} - -static void -merr_quit_impl(const char *detail, hse_err_t err, const char *file, int line) -{ - char errbuf[128]; - - hse_strerror(err, errbuf, sizeof(errbuf)); - quit("%s:%d: %s: %s", file, line, detail, errbuf); -} - -#define merr_quit(_detail, _err) merr_quit_impl((_detail), (_err), REL_FILE(__FILE__), __LINE__) - void announce_header(void) { @@ -529,22 +485,20 @@ void bar_sync_init(uint count) { int rc; - char buf[64]; rc = pthread_barrier_init(&barrier, NULL, count); if (rc) - quit("Error: pthread_barrier_init: %s", strerror_r(rc, buf, sizeof(buf))); + fatal(rc, "pthread_barrier_init"); } void bar_sync(void) { int rc; - char buf[64]; rc = pthread_barrier_wait(&barrier); if (rc && rc != PTHREAD_BARRIER_SERIAL_THREAD) - quit("Error: pthread_barrier_wait: %s", strerror_r(rc, buf, sizeof(buf))); + fatal(rc, "pthread_barrier_wait"); } void @@ -568,10 +522,10 @@ test_start_phase(struct thread_info *ti, char *message) struct svec sv = { 0 }; rc = svec_append_pg(&sv, pg, PG_KVDB_OPEN, NULL); if (rc) - quit("svec_append_pg: rc %d", rc); + fatal(rc, "svec_append_pg"); err = hse_kvdb_open(opt.mpool, sv.strc, sv.strv, &kvdb); if (err) - merr_quit("hse_kvdb_open failed", err); + fatal(err, "hse_kvdb_open failed"); svec_reset(&sv); } else { kvdb = (void *)1; @@ -588,10 +542,10 @@ test_start_phase(struct thread_info *ti, char *message) struct svec sv = { 0 }; rc = svec_append_pg(&sv, pg, PG_KVS_OPEN, NULL); if (rc) - quit("svec_append_pg: rc %d", rc); + fatal(rc, "svec_append_pg"); err = hse_kvdb_kvs_open(kvdb, ti->kvs_name, sv.strc, sv.strv, &ti->kvs); if (err) - merr_quit("hse_kvdb_kvs_open failed", err); + fatal(err, "hse_kvdb_kvs_open failed"); svec_reset(&sv); } else { ti->kvs = (void *)1; @@ -613,7 +567,7 @@ test_end_phase(struct thread_info *ti, bool final) if (!opt.dryrun) { err = hse_kvdb_sync(kvdb, 0); if (err) - merr_quit("hse_kvdb_sync failed", err); + fatal(err, "hse_kvdb_sync failed"); } } @@ -623,7 +577,7 @@ test_end_phase(struct thread_info *ti, bool final) if (!opt.dryrun) { err = hse_kvdb_kvs_close(ti->kvs); if (err) - merr_quit("hse_kvdb_kvs_close failed", err); + fatal(err, "hse_kvdb_kvs_close failed"); } ti->kvs = 0; } @@ -636,7 +590,7 @@ test_end_phase(struct thread_info *ti, bool final) if (!opt.dryrun) { err = hse_kvdb_close(kvdb); if (err) - merr_quit("hse_kvdb_close failed", err); + fatal(err, "hse_kvdb_close failed"); } kvdb = 0; } @@ -651,7 +605,7 @@ fmt_string(char *str, int len, int max_len, char fill, char *fmt, uint64_t fmt_a int i; if (len > max_len) - quit("key or value too large: %u (limit is %u)", len, max_len); + fatalx("key or value too large: %u (limit is %u)", len, max_len); snprintf(str, len, fmt, fmt_arg1, fmt_arg2); i = strlen(str); @@ -761,7 +715,7 @@ test_put(struct thread_info *ti, uint salt) err = hse_kvs_put(ti->kvs, 0, NULL, ti->ref_key, ti->ref_klen, ti->ref_val, ti->ref_vlen); if (err) - merr_quit("kvdb_put failed", err); + fatal(err, "kvdb_put failed"); } test_end_phase(ti, false); @@ -783,7 +737,7 @@ test_delete(struct thread_info *ti) if (!err) goto done; - merr_quit("hse_kvs_prefix_delete failed", err); + fatal(err, "hse_kvs_prefix_delete failed"); } for (i = opt.kstart; i < last_key; i++) { @@ -798,7 +752,7 @@ test_delete(struct thread_info *ti) err = hse_kvs_delete(ti->kvs, 0, NULL, ti->ref_key, ti->ref_klen); if (err) - merr_quit("kvs_del failed", err); + fatal(err, "kvs_del failed"); } done: test_end_phase(ti, false); @@ -838,7 +792,7 @@ test_put_verify(struct thread_info *ti, uint salt) err = hse_kvs_get( ti->kvs, 0, NULL, ti->ref_key, ti->ref_klen, &found, get_val, VLEN_MAX, &get_vlen); if (err) - merr_quit("hse_kvs_get failed", err); + fatal(err, "hse_kvs_get failed"); if (!found) { add_error( @@ -907,7 +861,7 @@ test_delete_verify(struct thread_info *ti) err = hse_kvs_get( ti->kvs, 0, NULL, ti->ref_key, ti->ref_klen, &found, get_val, VLEN_MAX, &get_vlen); if (err) - merr_quit("hse_kvs_get failed", err); + fatal(err, "hse_kvs_get failed"); if (found) { add_error( @@ -947,7 +901,7 @@ thread_main(void *arg) test_end_phase(ti, true); if (errors >= opt.errcnt) - quit("Exiting, because %u error(s) were encountered\n", errors); + fatalx("Exiting, because %u error(s) were encountered\n", errors); announce("Successful"); @@ -973,7 +927,7 @@ main(int argc, char **argv) rc = pg_create(&pg, PG_HSE_GLOBAL, PG_KVDB_OPEN, PG_KVS_OPEN, NULL); if (rc) - quit("pg_create"); + fatal(rc, "pg_create"); options_default(&opt); options_parse(argc, argv, &opt); @@ -991,19 +945,19 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - quit("unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - quit("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: - quit("error processing parameter %s\n", argv[optind]); + fatalx("error processing parameter %s\n", argv[optind]); break; } rc = svec_append_pg(&hse_gparm, pg, PG_HSE_GLOBAL, NULL); if (rc) - quit("failed to parse hse-gparams"); + fatalx("failed to parse hse-gparams"); if (!opt.keys) syntax("number of keys must be > 0"); @@ -1018,7 +972,7 @@ main(int argc, char **argv) threads = calloc(opt.threads, sizeof(*threads)); if (!threads) - quit("unable to calloc %zu bytes for thread_info", opt.threads * sizeof(*threads)); + fatalx("unable to calloc %zu bytes for thread_info", opt.threads * sizeof(*threads)); bar_sync_init(opt.threads); @@ -1046,7 +1000,7 @@ main(int argc, char **argv) cp = strchr(ti->kvs_name, '/'); if (cp) { if (cp[1] == 0) - quit("prefix missing kvs: %s", ti->kvs_name); + fatalx("prefix missing kvs: %s", ti->kvs_name); *cp++ = 0; ti->pfx = ti->kvs_name; ti->pfxlen = strlen(ti->pfx); @@ -1058,7 +1012,7 @@ main(int argc, char **argv) } else { /* use kvs name and prefix from thread i % kvsc */ if (kvsc == 0) - quit("Invalid kvs name: %s", opt.kvs); + fatalx("Invalid kvs name: %s", opt.kvs); assert(i >= kvsc); ti->kvs_name = threads[i % kvsc].kvs_name; ti->pfx = threads[i % kvsc].pfx; @@ -1075,12 +1029,12 @@ main(int argc, char **argv) n = asprintf(&ti->kvs_name, cp, i); if (n <= 0) - quit("cannot format kvs name: '%s'", cp); + fatalx("cannot format kvs name: '%s'", cp); /* Ensure that no two threads are given the same kvs name. */ for (n = 0; n < i; n++) if (!strcmp(ti->kvs_name, threads[n].kvs_name)) - quit( + fatalx( "no two threads may work" " on the same kvs: %s", ti->kvs_name); @@ -1092,7 +1046,7 @@ main(int argc, char **argv) ti->get_val = malloc(VLEN_MAX); ti->ref_val = malloc(VLEN_MAX); if (!ti->ref_key || !ti->get_val || !ti->ref_val) - quit("Out of memory"); + fatalx("Out of memory"); } announce_header(); @@ -1100,7 +1054,7 @@ main(int argc, char **argv) /* Start HSE */ err = hse_init(opt.config, hse_gparm.strc, hse_gparm.strv); if (err) - quit("failed to initialize kvdb"); + fatalx("failed to initialize kvdb"); /* Start the threads */ for (i = 0, ti = threads; i < opt.threads; i++, ti++) { diff --git a/tools/range_read/range_read.c b/tools/range_read/range_read.c index 30176f7cd..bc44fda70 100644 --- a/tools/range_read/range_read.c +++ b/tools/range_read/range_read.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -329,20 +330,6 @@ print_stats() } } -/* Driver */ -void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { @@ -541,10 +528,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/simple_client/simple_client.c b/tools/simple_client/simple_client.c index c09577669..79dac8fd8 100644 --- a/tools/simple_client/simple_client.c +++ b/tools/simple_client/simple_client.c @@ -14,6 +14,7 @@ #include +#include #include #include @@ -23,41 +24,6 @@ uint kmax = 100; struct hse_kvdb *kvdb; struct hse_kvs *kvs; -void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...) -{ - char msg[2048]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - -void HSE_PRINTF(2, 3) -fatal(hse_err_t err, const char *fmt, ...) -{ - char msgbuf[1024]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msgbuf, sizeof(msgbuf) - 128, fmt, ap); - va_end(ap); - - if (err) { - size_t len = strlen(strcat(msgbuf, ": ")); - - hse_strerror(err, msgbuf + len, sizeof(msgbuf) - len); - } - - fprintf(stderr, "%s: %s\n", progname, msgbuf); - - hse_kvdb_close(kvdb); - exit(EX_SOFTWARE); -} - void usage(void) { diff --git a/tools/throttle/throttle.c b/tools/throttle/throttle.c index b96f6e31b..6699bf72d 100644 --- a/tools/throttle/throttle.c +++ b/tools/throttle/throttle.c @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -111,55 +112,9 @@ struct thread_info { uint64_t time; }; -static void -syntax(const char *fmt, ...); -static void -quit(const char *fmt, ...); static void usage(void); -static void -quit(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - if (fmt && *fmt) { - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - fprintf(stderr, "%s: %s\n", progname, msg); - fflush(stderr); - } - exit(-1); -} - -static void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s\nUse -h for help.\n", progname, msg); - exit(EX_USAGE); -} - -static void -_error_quit(const char *detail, hse_err_t err, const char *file, int line) -{ - char err_buf[300]; - - hse_strerror(err, err_buf, sizeof(err_buf)); - - quit("%s:%d: %s: %s", file, line, (detail && *detail) ? detail : "", err_buf); -} - -#define error_quit(detail, err) _error_quit(detail, err, REL_FILE(__FILE__), __LINE__) - void announce_header(void) { @@ -471,7 +426,7 @@ test_open_kvdb(void) rc = hse_kvdb_open(opt.mpool, db_oparm.strc, db_oparm.strv, &kvdb); if (rc) - error_quit("hse_kvdb_open failed", rc); + fatal(rc, "hse_kvdb_open failed"); assert(kvdb); } @@ -486,7 +441,7 @@ test_close_kvdb(void) rc = hse_kvdb_close(kvdb); if (rc) - error_quit("hse_kvdb_close failed", rc); + fatal(rc, "hse_kvdb_close failed"); kvdb = NULL; } @@ -501,7 +456,7 @@ test_open_kvs(char *kvs_name, struct hse_kvs **kvs) rc = hse_kvdb_kvs_open(kvdb, kvs_name, kv_oparm.strc, kv_oparm.strv, kvs); if (rc) - error_quit("hse_kvdb_kvs_open failed", rc); + fatal(rc, "hse_kvdb_kvs_open failed"); } void @@ -514,7 +469,7 @@ test_close_kvs(char *kvs_name, struct hse_kvs *kvs) rc = hse_kvdb_kvs_close(kvs); if (rc) - error_quit("hse_kvdb_kvs_close failed", rc); + fatal(rc, "hse_kvdb_kvs_close failed"); } void @@ -523,7 +478,7 @@ fmt_string(char *str, int len, int max_len, char fill, char *fmt, uint64_t fmt_a int i; if (len > max_len) - quit("key or value too large: %u (limit is %u)", len, max_len); + fatalx("key or value too large: %u (limit is %u)", len, max_len); snprintf(str, len, fmt, fmt_arg1, fmt_arg2); i = strlen(str); @@ -644,7 +599,7 @@ test_put_impl(struct thread_info *ti, uint salt, uint64_t time) kvs_h[idx], 0, NULL, (char *)ti->ref_key, ti->ref_klen, (char *)ti->ref_val, ti->ref_vlen); if (err) - error_quit("kvdb_put failed", err); + fatal(err, "kvdb_put failed"); ti->ops++; cnt++; @@ -700,7 +655,7 @@ thread_main(void *arg) test_put(ti, salt); if (errors >= opt.errcnt) - quit("Exiting, because %u error(s) were encountered\n", errors); + fatalx("Exiting, because %u error(s) were encountered\n", errors); announce("Successful"); @@ -735,7 +690,7 @@ extract_fields(char *str, uint max, char **fields, uint *out) } } else { if (count == 0) - quit("Invalid kvs name: %s", opt.kvs); + fatalx("Invalid kvs name: %s", opt.kvs); break; } count++; @@ -762,15 +717,15 @@ run_test(struct thread_info *threads, char *kvs, char *weight) extract_fields(kvs, 1024, kvs_names, &kvsc); if (!kvsc) - quit("Zero kvs"); + fatalx("Zero kvs"); if (kvsc > 1024) - quit("Too many kvses"); + fatalx("Too many kvses"); kvswtc = 0; extract_fields(weight, 1024, kvswt_param, &kvswtc); if (kvswtc && (kvsc != kvswtc)) - quit("Improper weights"); + fatalx("Improper weights"); for (i = 0; i < kvsc; i++) { if (!kvswtc) @@ -792,7 +747,7 @@ run_test(struct thread_info *threads, char *kvs, char *weight) ti->get_val = calloc(VLEN_MAX, VLEN_MAX); ti->ref_val = calloc(VLEN_MAX, VLEN_MAX); if (!ti->ref_key || !ti->get_val || !ti->ref_val) - quit("Out of memory"); + fatalx("Out of memory"); } announce_header(); @@ -879,7 +834,7 @@ main(int argc, char **argv) rc = pg_create(&pg, PG_HSE_GLOBAL, PG_KVDB_OPEN, PG_KVS_OPEN, NULL); if (rc) - quit("pg_create"); + fatalx("pg_create"); options_default(&opt); options_parse(argc, argv, &opt); @@ -899,13 +854,13 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - quit("unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - quit("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: - quit("error processing parameter %s\n", argv[optind]); + fatalx("error processing parameter %s\n", argv[optind]); break; } @@ -913,7 +868,7 @@ main(int argc, char **argv) rc = rc ?: svec_append_pg(&db_oparm, pg, PG_KVDB_OPEN, NULL); rc = rc ?: svec_append_pg(&kv_oparm, pg, PG_KVS_OPEN, NULL); if (rc) - quit("svec_apppend_pg failed: %d", rc); + fatalx("svec_apppend_pg failed: %d", rc); if (!opt.keys) syntax("number of keys must be > 0"); @@ -928,23 +883,23 @@ main(int argc, char **argv) threads = calloc(opt.threads, sizeof(*threads)); if (!threads) - quit("unable to calloc %zu bytes for thread_info", opt.threads * sizeof(*threads)); + fatalx("unable to calloc %zu bytes for thread_info", opt.threads * sizeof(*threads)); kvs_h = calloc(1024 * sizeof(*kvs_h), 1024 * sizeof(*kvs_h)); if (!kvs_h) - quit("Out of memory"); + fatalx("Out of memory"); kvs_names = malloc(1024 * sizeof(*kvs_names)); if (!kvs_names) - quit("Out of memory"); + fatalx("Out of memory"); kvswt_param = malloc(1024 * sizeof(*kvswt_param)); if (!kvswt_param) - quit("Out of memory"); + fatalx("Out of memory"); kvs_weight = malloc(1024 * sizeof(*kvs_weight)); if (!kvs_weight) - quit("Out of memory"); + fatalx("Out of memory"); gettimeofday(&tv_start, NULL); @@ -962,7 +917,7 @@ main(int argc, char **argv) err = hse_init(opt.config, hse_gparm.strc, hse_gparm.strv); if (err) - quit("failed to initialize kvdb"); + fatalx("failed to initialize kvdb"); time = get_time_ns(); @@ -983,7 +938,7 @@ main(int argc, char **argv) kvs = strdup(opt.kvs); weight = strdup(opt.weight); if (!kvs || !weight) - quit("Out of memory"); + fatalx("Out of memory"); runtime = get_time_ns(); run_test(threads, kvs, weight); diff --git a/tools/txn_thrash/txn_thrash.c b/tools/txn_thrash/txn_thrash.c index 97423649c..ac526b44d 100644 --- a/tools/txn_thrash/txn_thrash.c +++ b/tools/txn_thrash/txn_thrash.c @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -160,10 +161,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/txput_flush/txput_flush.c b/tools/txput_flush/txput_flush.c index 75a6dc8a7..6a751d8e8 100644 --- a/tools/txput_flush/txput_flush.c +++ b/tools/txput_flush/txput_flush.c @@ -19,6 +19,7 @@ #include +#include #include #include "kvs_helper.h" @@ -101,10 +102,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/upsert/upsert.c b/tools/upsert/upsert.c index 7947a097d..a25f516b5 100644 --- a/tools/upsert/upsert.c +++ b/tools/upsert/upsert.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -214,19 +215,6 @@ print_stats(void *arg) } } -void HSE_PRINTF(1, 2) -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help\n", progname, msg); -} - void usage(void) { @@ -320,7 +308,7 @@ main(int argc, char **argv) } if (argc - optind < 2) - fatal(0, "missing required parameter\nuse -h for help"); + fatalx("missing required parameter\nuse -h for help"); kvdbhome = argv[optind++]; kvsname = argv[optind++]; @@ -329,10 +317,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]); diff --git a/tools/waltest/waltest.c b/tools/waltest/waltest.c index e6294a03c..390e2a918 100644 --- a/tools/waltest/waltest.c +++ b/tools/waltest/waltest.c @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -121,45 +122,9 @@ struct thread_info { int pfxlen; }; -static void -syntax(const char *fmt, ...); -static void -quit(const char *fmt, ...); static void usage(void); -static void HSE_PRINTF(1, 2) -quit(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - if (fmt && *fmt) { - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - fprintf(stderr, "%s: %s\n", progname, msg); - fflush(stderr); - } -} - -static void -syntax(const char *fmt, ...) -{ - char msg[256]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - - fprintf(stderr, "%s: %s, use -h for help.\n", progname, msg); - exit(EX_USAGE); -} - -#define merr_quit(detail, err) \ - quit("%s:%d: %s: %ld", REL_FILE(__FILE__), __LINE__, (detail), (err)); - void announce_header(void) { @@ -585,11 +550,11 @@ test_kvdb_open(void) rc = svec_append_pg(&sv, pg, PG_KVDB_OPEN, NULL); if (rc) - quit("svec_append_pg: rc %d", (int)rc); + fatal(rc, "svec_append_pg"); rc = hse_kvdb_open(opt.kvdb, sv.strc, sv.strv, &kvdb); if (rc) - merr_quit("hse_kvdb_open failed", rc); + fatal(rc, "hse_kvdb_open failed"); svec_reset(&sv); } @@ -606,7 +571,7 @@ test_kvs_open(struct thread_info *ti, char *message) err = hse_kvdb_kvs_open(kvdb, ti->kvs_name, kvs_oparms.strc, kvs_oparms.strv, &ti->kvs); if (err) - merr_quit("hse_kvdb_kvs_open failed", err); + fatal(err, "hse_kvdb_kvs_open failed"); assert(ti->kvs); } @@ -632,7 +597,7 @@ test_start_phase(struct thread_info *ti, char *message) if (!opt.dryrun) { err = hse_kvdb_kvs_open(kvdb, ti->kvs_name, kvs_oparms.strc, kvs_oparms.strv, &ti->kvs); if (err) - merr_quit("hse_kvdb_kvs_open failed", err); + fatal(err, "hse_kvdb_kvs_open failed"); } else { ti->kvs = (void *)1; } @@ -651,7 +616,7 @@ fmt_string(char *str, int len, int max_len, char fill, char *fmt, uint64_t fmt_a int i; if (len > max_len) - quit("key or value too large: %u (limit is %u)", len, max_len); + fatalx("key or value too large: %u (limit is %u)", len, max_len); snprintf(str, len, fmt, fmt_arg1, fmt_arg2); i = strlen(str); @@ -776,7 +741,7 @@ test_put(struct thread_info *ti, uint salt, bool istxn) err = hse_kvs_put( ti->kvs, 0, txn, (char *)ti->ref_key, ti->ref_klen, (char *)ti->ref_val, ti->ref_vlen); if (err) - merr_quit("kvdb_put failed", err); + fatal(err, "kvdb_put failed"); atomic_inc(&put_cnt); @@ -785,7 +750,7 @@ test_put(struct thread_info *ti, uint salt, bool istxn) if (nkeys == 1) { txkey = calloc(1, ti->ref_klen); if (!txkey) - merr_quit("Tx calloc failed", merr(ENOMEM)); + fatal(merr(ENOMEM), "Tx calloc failed"); memcpy(txkey, (char *)ti->ref_key, ti->ref_klen); txkeyp = (uint *)txkey; } @@ -795,7 +760,7 @@ test_put(struct thread_info *ti, uint salt, bool istxn) err = hse_kvs_put( ti->kvs, 0, txn, (char *)txkey, ti->ref_klen, (char *)ti->ref_val, ti->ref_vlen); if (err) - merr_quit("kvdb_put failed", err); + fatal(err, "kvdb_put failed"); atomic_inc(&put_cnt); } @@ -838,11 +803,11 @@ test_delete(struct thread_info *ti, bool prefix, bool istxn) if (!prefix) { err = hse_kvs_delete(ti->kvs, 0, txn, (char *)ti->ref_key, ti->ref_klen); if (err) - merr_quit("kvs_del failed", err); + fatal(err, "kvs_del failed"); } else { err = hse_kvs_prefix_delete(ti->kvs, 0, txn, (char *)ti->ref_key, ti->ref_klen); if (err) - merr_quit("kvs_prefix_del failed", err); + fatal(err, "kvs_prefix_del failed"); } atomic_inc(&del_cnt); @@ -891,7 +856,7 @@ test_put_verify(struct thread_info *ti, uint salt, bool istxn) err = hse_kvs_get( ti->kvs, 0, NULL, ti->ref_key, ti->ref_klen, &found, get_val, VLEN_MAX, &get_vlen); if (err) - merr_quit("hse_kvs_get failed", err); + fatal(err, "hse_kvs_get failed"); if (!found) { add_error( @@ -934,7 +899,7 @@ test_put_verify(struct thread_info *ti, uint salt, bool istxn) if (nkeys == 1) { txkey = calloc(1, ti->ref_klen); if (!txkey) - merr_quit("Tx alloc failed", merr(ENOMEM)); + fatal(merr(ENOMEM), "Tx alloc failed"); memcpy(txkey, ti->ref_key, ti->ref_klen); txkeyp = (uint *)txkey; } @@ -946,7 +911,7 @@ test_put_verify(struct thread_info *ti, uint salt, bool istxn) ti->kvs, 0, NULL, txkey, ti->ref_klen, &found, get_val, VLEN_MAX, &get_vlen); if (err) { free(txkey); - merr_quit("hse_kvs_get failed", err); + fatal(err, "hse_kvs_get failed"); } if (!found && !found_err) @@ -1005,7 +970,7 @@ test_delete_verify(struct thread_info *ti) err = hse_kvs_get( ti->kvs, 0, NULL, ti->ref_key, ti->ref_klen, &found, get_val, VLEN_MAX, &get_vlen); if (err) - merr_quit("hse_kvs_get failed", err); + fatal(err, "hse_kvs_get failed"); if (found) { add_error( @@ -1074,7 +1039,7 @@ print_result(void) printf("waltest : No. of successful verified deletes %ld\n", atomic_read(&del_verify_cnt)); if (atomic_read(&errors) >= opt.errcnt) - quit("Exiting, because %lu error(s) were encountered\n", atomic_read(&errors)); + fatalx("Exiting, because %lu error(s) were encountered\n", atomic_read(&errors)); announce("Successful"); } @@ -1108,7 +1073,7 @@ waltest_run(int argc, char **argv) threads = calloc(opt.threads, sizeof(*threads)); if (!threads) - quit("unable to calloc %zu bytes for thread_info", opt.threads * sizeof(*threads)); + fatalx("unable to calloc %zu bytes for thread_info", opt.threads * sizeof(*threads)); /* Figure each thread's kvs name and kvs prefix. * Example input with 5 threads: @@ -1134,7 +1099,7 @@ waltest_run(int argc, char **argv) cp = strchr(ti->kvs_name, '/'); if (cp) { if (cp[1] == 0) - quit("prefix missing kvs: %s", ti->kvs_name); + fatalx("prefix missing kvs: %s", ti->kvs_name); *cp++ = 0; ti->pfx = ti->kvs_name; ti->pfxlen = strlen(ti->pfx); @@ -1146,7 +1111,7 @@ waltest_run(int argc, char **argv) } else { /* use kvs name and prefix from thread i % kvsc */ if (kvsc == 0) - quit("Invalid kvs name: %s", opt.kvs); + fatalx("Invalid kvs name: %s", opt.kvs); assert(i >= kvsc); ti->kvs_name = threads[i % kvsc].kvs_name; ti->pfx = threads[i % kvsc].pfx; @@ -1168,12 +1133,12 @@ waltest_run(int argc, char **argv) n = asprintf(&ti->kvs_name, cp, i); if (n <= 0) - quit("cannot format kvs name: '%s'", cp); + fatalx("cannot format kvs name: '%s'", cp); /* Ensure that no two threads are given the same kvs name. */ for (n = 0; !single_kvs && n < i; n++) if (!strcmp(ti->kvs_name, threads[n].kvs_name)) - quit( + fatalx( "no two threads may work" " on the same kvs: %s", ti->kvs_name); @@ -1185,7 +1150,7 @@ waltest_run(int argc, char **argv) ti->get_val = malloc(VLEN_MAX); ti->ref_val = malloc(VLEN_MAX); if (!ti->ref_key || !ti->get_val || !ti->ref_val) - quit("Out of memory"); + fatalx("Out of memory"); } /*open kvdb */ @@ -1293,11 +1258,11 @@ waltest_run(int argc, char **argv) int waltest_parse(int argc, char **argv) { - int rc; + merr_t rc; rc = pg_create(&pg, PG_KVDB_OPEN, PG_KVS_OPEN, NULL); if (rc) - quit("pg_create"); + fatal(rc, "pg_create"); options_default(&opt); options_parse(argc, argv, &opt); @@ -1311,11 +1276,11 @@ waltest_parse(int argc, char **argv) if (opt.do_txn) { rc = svec_append_pg(&kvs_oparms, pg, PG_KVS_OPEN, "transactions.enabled=true", NULL); if (rc) - quit("svec_append_pg failed: %d", rc); + fatal(rc, "svec_append_pg failed"); } else { rc = svec_append_pg(&kvs_oparms, pg, PG_KVS_OPEN, NULL); if (rc) - quit("svec_append_pg failed: %d", rc); + fatal(rc, "svec_append_pg failed"); } opt.kvdb = argv[optind++]; @@ -1325,15 +1290,15 @@ waltest_parse(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - quit("unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - quit("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: - quit("error processing parameter %s\n", argv[optind]); + fatalx("error processing parameter %s\n", argv[optind]); break; } diff --git a/tools/wscan/wscan.c b/tools/wscan/wscan.c index 5e9e9f06d..2d80f1112 100644 --- a/tools/wscan/wscan.c +++ b/tools/wscan/wscan.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -162,7 +163,7 @@ main(int argc, char **argv) usage(); if (argc - optind < 3) - fatal(0, "missing required parameters"); + fatalx("missing required parameters"); mpname = argv[optind++]; dsname = argv[optind++]; @@ -172,10 +173,10 @@ main(int argc, char **argv) switch (rc) { case 0: if (optind < argc) - fatal(0, "unknown parameter: %s", argv[optind]); + fatalx("unknown parameter: %s", argv[optind]); break; case EINVAL: - fatal(0, "missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); + fatalx("missing group name (e.g. %s) before parameter %s\n", PG_KVDB_OPEN, argv[optind]); break; default: fatal(rc, "error processing parameter %s\n", argv[optind]);