From e0cb71a82ff0939501a50dd2ff4c7afd94efe665 Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Mon, 2 Oct 2017 11:55:11 +0000 Subject: [PATCH 1/3] 8081 Compiler warnings in zdb illumos/illumos-gate@3f7978d02b206a6ebc5652c91aa9f42da6fbe00c https://github.com/illumos/illumos-gate/commit/3f7978d02b206a6ebc5652c91aa9f42da6fbe00c https://www.illumos.org/issues/8081 zdb(8) is full of minor problems that generate compiler warnings. On FreeBSD, which uses -WError, the only way to build it is to disable all compiler warnings. This makes it much harder to detect newly introduced bugs. We should cleanup all the warnings. Reviewed by: Matthew Ahrens Reviewed by: Prakash Surya Approved by: Richard Lowe Author: Alan Somers --- cmd/zdb/zdb.c | 128 +++++++++++++----------- cmd/zdb/zdb.h | 33 +++++++ cmd/zdb/zdb_il.c | 134 ++++++++++++++------------ cmd/ztest/ztest.c | 20 +++- lib/libzpool/common/sys/zfs_context.h | 3 +- uts/common/fs/zfs/arc.c | 6 +- uts/common/fs/zfs/dbuf.c | 3 +- uts/common/fs/zfs/spa.c | 3 +- uts/common/fs/zfs/sys/refcount.h | 2 +- uts/common/fs/zfs/sys/sa.h | 4 +- uts/common/fs/zfs/sys/spa.h | 2 +- uts/common/fs/zfs/sys/zil.h | 2 +- uts/common/fs/zfs/txg.c | 10 +- uts/common/fs/zfs/zfs_replay.c | 47 ++++++--- uts/common/fs/zfs/zvol.c | 10 +- 15 files changed, 258 insertions(+), 149 deletions(-) create mode 100644 cmd/zdb/zdb.h diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index bd2aa652df87..32c548d2bd12 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -66,6 +66,8 @@ #undef verify #include +#include "zdb.h" + #define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \ zio_compress_table[(idx)].ci_name : "UNKNOWN") #define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \ @@ -89,14 +91,13 @@ uint64_t zfs_arc_max, zfs_arc_meta_limit; int zfs_vdev_async_read_max_active; #endif -const char cmdname[] = "zdb"; +static const char cmdname[] = "zdb"; uint8_t dump_opt[256]; typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size); -extern void dump_intent_log(zilog_t *); uint64_t *zopt_object = NULL; -int zopt_objects = 0; +static unsigned zopt_objects = 0; libzfs_handle_t *g_zfs; uint64_t max_inflight = 1000; @@ -284,8 +285,8 @@ zdb_nicenum(uint64_t num, char *buf) nicenum(num, buf); } -const char histo_stars[] = "****************************************"; -const int histo_width = sizeof (histo_stars) - 1; +static const char histo_stars[] = "****************************************"; +static const uint64_t histo_width = sizeof (histo_stars) - 1; static void dump_histogram(const uint64_t *histo, int size, int offset) @@ -391,7 +392,7 @@ dump_unknown(objset_t *os, uint64_t object, void *data, size_t size) } /*ARGSUSED*/ -void +static void dump_uint8(objset_t *os, uint64_t object, void *data, size_t size) { } @@ -409,7 +410,7 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size) zap_cursor_t zc; zap_attribute_t attr; void *prop; - int i; + unsigned i; dump_zap_stats(os, object); (void) printf("\n"); @@ -567,7 +568,7 @@ dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size) zap_cursor_t zc; zap_attribute_t attr; uint16_t *layout_attrs; - int i; + unsigned i; dump_zap_stats(os, object); (void) printf("\n"); @@ -636,7 +637,7 @@ dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size) zap_cursor_fini(&zc); } -int +static int get_dtl_refcount(vdev_t *vd) { int refcount = 0; @@ -650,18 +651,18 @@ get_dtl_refcount(vdev_t *vd) return (0); } - for (int c = 0; c < vd->vdev_children; c++) + for (unsigned c = 0; c < vd->vdev_children; c++) refcount += get_dtl_refcount(vd->vdev_child[c]); return (refcount); } -int +static int get_metaslab_refcount(vdev_t *vd) { int refcount = 0; if (vd->vdev_top == vd && !vd->vdev_removing) { - for (int m = 0; m < vd->vdev_ms_count; m++) { + for (unsigned m = 0; m < vd->vdev_ms_count; m++) { space_map_t *sm = vd->vdev_ms[m]->ms_sm; if (sm != NULL && @@ -669,7 +670,7 @@ get_metaslab_refcount(vdev_t *vd) refcount++; } } - for (int c = 0; c < vd->vdev_children; c++) + for (unsigned c = 0; c < vd->vdev_children; c++) refcount += get_metaslab_refcount(vd->vdev_child[c]); return (refcount); @@ -701,7 +702,7 @@ static void dump_spacemap(objset_t *os, space_map_t *sm) { uint64_t alloc, offset, entry; - char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID", + const char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" }; if (sm == NULL) @@ -834,7 +835,7 @@ dump_metaslab_groups(spa_t *spa) metaslab_class_histogram_verify(mc); - for (int c = 0; c < rvd->vdev_children; c++) { + for (unsigned c = 0; c < rvd->vdev_children; c++) { vdev_t *tvd = rvd->vdev_child[c]; metaslab_group_t *mg = tvd->vdev_mg; @@ -913,7 +914,7 @@ dump_dde(const ddt_t *ddt, const ddt_entry_t *dde, uint64_t index) { const ddt_phys_t *ddp = dde->dde_phys; const ddt_key_t *ddk = &dde->dde_key; - char *types[4] = { "ditto", "single", "double", "triple" }; + const char *types[4] = { "ditto", "single", "double", "triple" }; char blkbuf[BP_SPRINTF_LEN]; blkptr_t blk; @@ -1004,8 +1005,11 @@ dump_ddt(ddt_t *ddt, enum ddt_type type, enum ddt_class class) static void dump_all_ddts(spa_t *spa) { - ddt_histogram_t ddh_total = { 0 }; - ddt_stat_t dds_total = { 0 }; + ddt_histogram_t ddh_total; + ddt_stat_t dds_total; + + bzero(&ddh_total, sizeof (ddh_total)); + bzero(&dds_total, sizeof (dds_total)); for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) { ddt_t *ddt = spa->spa_ddt[c]; @@ -1052,7 +1056,8 @@ dump_dtl(vdev_t *vd, int indent) { spa_t *spa = vd->vdev_spa; boolean_t required; - char *name[DTL_TYPES] = { "missing", "partial", "scrub", "outage" }; + const char *name[DTL_TYPES] = { "missing", "partial", "scrub", + "outage" }; char prefix[256]; spa_vdev_state_enter(spa, SCL_NONE); @@ -1080,7 +1085,7 @@ dump_dtl(vdev_t *vd, int indent) dump_spacemap(spa->spa_meta_objset, vd->vdev_dtl_sm); } - for (int c = 0; c < vd->vdev_children; c++) + for (unsigned c = 0; c < vd->vdev_children; c++) dump_dtl(vd->vdev_child[c], indent + 4); } @@ -1113,7 +1118,7 @@ dump_history(spa_t *spa) } while (len != 0); (void) printf("\nHistory:\n"); - for (int i = 0; i < num; i++) { + for (unsigned i = 0; i < num; i++) { uint64_t time, txg, ievent; char *cmd, *intstr; boolean_t printed = B_FALSE; @@ -1135,8 +1140,8 @@ dump_history(spa_t *spa) (void) snprintf(internalstr, sizeof (internalstr), - "[internal %s txg:%lld] %s", - zfs_history_event_names[ievent], txg, + "[internal %s txg:%ju] %s", + zfs_history_event_names[ievent], (uintmax_t)txg, intstr); cmd = internalstr; } @@ -1442,7 +1447,7 @@ dump_bptree_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) } static void -dump_bptree(objset_t *os, uint64_t obj, char *name) +dump_bptree(objset_t *os, uint64_t obj, const char *name) { char bytes[32]; bptree_phys_t *bt; @@ -1479,7 +1484,7 @@ dump_bpobj_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) } static void -dump_full_bpobj(bpobj_t *bpo, char *name, int indent) +dump_full_bpobj(bpobj_t *bpo, const char *name, int indent) { char bytes[32]; char comp[32]; @@ -1966,7 +1971,7 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header) dmu_buf_rele(db, FTAG); } -static char *objset_types[DMU_OST_NUMTYPES] = { +static const char *objset_types[DMU_OST_NUMTYPES] = { "NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" }; static void @@ -1978,10 +1983,11 @@ dump_dir(objset_t *os) char numbuf[32]; char blkbuf[BP_SPRINTF_LEN + 20]; char osname[ZFS_MAX_DATASET_NAME_LEN]; - char *type = "UNKNOWN"; + const char *type = "UNKNOWN"; int verbosity = dump_opt['d']; int print_header = 1; - int i, error; + unsigned i; + int error; dsl_pool_config_enter(dmu_objset_pool(os), FTAG); dmu_objset_fast_stat(os, &dds); @@ -2068,7 +2074,7 @@ dump_uberblock(uberblock_t *ub, const char *header, const char *footer) { time_t timestamp = ub->ub_timestamp; - (void) printf(header ? header : ""); + (void) printf("%s", header ? header : ""); (void) printf("\tmagic = %016llx\n", (u_longlong_t)ub->ub_magic); (void) printf("\tversion = %llu\n", (u_longlong_t)ub->ub_version); (void) printf("\ttxg = %llu\n", (u_longlong_t)ub->ub_txg); @@ -2080,7 +2086,7 @@ dump_uberblock(uberblock_t *ub, const char *header, const char *footer) snprintf_blkptr(blkbuf, sizeof (blkbuf), &ub->ub_rootbp); (void) printf("\trootbp = %s\n", blkbuf); } - (void) printf(footer ? footer : ""); + (void) printf("%s", footer ? footer : ""); } static void @@ -2423,7 +2429,7 @@ typedef struct zdb_blkstats { #define ZDB_OT_OTHER (DMU_OT_NUMTYPES + 2) #define ZDB_OT_TOTAL (DMU_OT_NUMTYPES + 3) -static char *zdb_ot_extname[] = { +static const char *zdb_ot_extname[] = { "deferred free", "dedup ditto", "other", @@ -2440,7 +2446,7 @@ typedef struct zdb_cb { uint64_t zcb_embedded_histogram[NUM_BP_EMBEDDED_TYPES] [BPE_PAYLOAD_SIZE]; uint64_t zcb_start; - uint64_t zcb_lastprint; + hrtime_t zcb_lastprint; uint64_t zcb_totalasize; uint64_t zcb_errors[256]; int zcb_readfails; @@ -2475,7 +2481,7 @@ zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp, * SPA_OLD_MAXBLOCKSIZE; larger blocks go into the last, * "other", bucket. */ - int idx = BP_GET_PSIZE(bp) >> SPA_MINBLOCKSHIFT; + unsigned idx = BP_GET_PSIZE(bp) >> SPA_MINBLOCKSHIFT; idx = MIN(idx, SPA_OLD_MAXBLOCKSIZE / SPA_MINBLOCKSIZE + 1); zb->zb_psize_histogram[idx]++; @@ -2677,10 +2683,11 @@ static metaslab_ops_t zdb_metaslab_ops = { static void zdb_ddt_leak_init(spa_t *spa, zdb_cb_t *zcb) { - ddt_bookmark_t ddb = { 0 }; + ddt_bookmark_t ddb; ddt_entry_t dde; int error; + bzero(&ddb, sizeof (ddb)); while ((error = ddt_walk(spa, &ddb, &dde)) == 0) { blkptr_t blk; ddt_phys_t *ddp = dde.dde_phys; @@ -2788,10 +2795,10 @@ zdb_leak_fini(spa_t *spa) { if (!dump_opt['L']) { vdev_t *rvd = spa->spa_root_vdev; - for (int c = 0; c < rvd->vdev_children; c++) { + for (unsigned c = 0; c < rvd->vdev_children; c++) { vdev_t *vd = rvd->vdev_child[c]; metaslab_group_t *mg = vd->vdev_mg; - for (int m = 0; m < vd->vdev_ms_count; m++) { + for (unsigned m = 0; m < vd->vdev_ms_count; m++) { metaslab_t *msp = vd->vdev_ms[m]; ASSERT3P(mg, ==, msp->ms_group); mutex_enter(&msp->ms_lock); @@ -2837,12 +2844,13 @@ count_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) static int dump_block_stats(spa_t *spa) { - zdb_cb_t zcb = { 0 }; + zdb_cb_t zcb; zdb_blkstats_t *zb, *tzb; uint64_t norm_alloc, norm_space, total_alloc, total_found; int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_HARD; boolean_t leaks = B_FALSE; + bzero(&zcb, sizeof (zcb)); (void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n", (dump_opt['c'] || !dump_opt['L']) ? "to verify " : "", (dump_opt['c'] == 1) ? "metadata " : "", @@ -2993,7 +3001,7 @@ dump_block_stats(spa_t *spa) for (t = 0; t <= ZDB_OT_TOTAL; t++) { char csize[32], lsize[32], psize[32], asize[32]; char avg[32], gang[32]; - char *typename; + const char *typename; if (t < DMU_OT_NUMTYPES) typename = dmu_ot[t].ot_name; @@ -3131,9 +3139,11 @@ dump_simulated_ddt(spa_t *spa) avl_tree_t t; void *cookie = NULL; zdb_ddt_entry_t *zdde; - ddt_histogram_t ddh_total = { 0 }; - ddt_stat_t dds_total = { 0 }; + ddt_histogram_t ddh_total; + ddt_stat_t dds_total; + bzero(&ddh_total, sizeof (ddh_total)); + bzero(&dds_total, sizeof (dds_total)); avl_create(&t, ddt_entry_compare, sizeof (zdb_ddt_entry_t), offsetof(zdb_ddt_entry_t, zdde_node)); @@ -3280,7 +3290,7 @@ dump_zpool(spa_t *spa) #define ZDB_FLAG_RAW 0x0040 #define ZDB_FLAG_PRINT_BLKPTR 0x0080 -int flagbits[256]; +static int flagbits[256]; static void zdb_print_blkptr(blkptr_t *bp, int flags) @@ -3321,10 +3331,11 @@ static void zdb_dump_block(char *label, void *buf, uint64_t size, int flags) { uint64_t *d = (uint64_t *)buf; - int nwords = size / sizeof (uint64_t); + unsigned nwords = size / sizeof (uint64_t); int do_bswap = !!(flags & ZDB_FLAG_BSWAP); - int i, j; - char *hdr, *c; + unsigned i, j; + const char *hdr; + char *c; if (do_bswap) @@ -3357,19 +3368,19 @@ zdb_dump_block(char *label, void *buf, uint64_t size, int flags) * RAID-Zs, you can specify either RAID-Z vdev with 0.0 or 0.1 . */ static vdev_t * -zdb_vdev_lookup(vdev_t *vdev, char *path) +zdb_vdev_lookup(vdev_t *vdev, const char *path) { char *s, *p, *q; - int i; + unsigned i; if (vdev == NULL) return (NULL); /* First, assume the x.x.x.x format */ - i = (int)strtoul(path, &s, 10); + i = strtoul(path, &s, 10); if (s == path || (s && *s != '.' && *s != '\0')) goto name; - if (i < 0 || i >= vdev->vdev_children) + if (i >= vdev->vdev_children) return (NULL); vdev = vdev->vdev_child[i]; @@ -3444,7 +3455,8 @@ zdb_read_block(char *thing, spa_t *spa) vdev_t *vd; abd_t *pabd; void *lbuf, *buf; - char *s, *p, *dup, *vdev, *flagstr; + const char *s, *vdev; + char *p, *dup, *flagstr; int i, error; dup = strdup(thing); @@ -3455,7 +3467,10 @@ zdb_read_block(char *thing, spa_t *spa) s = strtok(NULL, ":"); size = strtoull(s ? s : "", NULL, 16); s = strtok(NULL, ":"); - flagstr = s ? s : ""; + if (s) + flagstr = strdup(s); + else + flagstr = strdup(""); s = NULL; if (size == 0) @@ -3496,6 +3511,7 @@ zdb_read_block(char *thing, spa_t *spa) } } } + free(flagstr); vd = zdb_vdev_lookup(spa->spa_root_vdev, vdev); if (vd == NULL) { @@ -3632,11 +3648,12 @@ zdb_read_block(char *thing, spa_t *spa) static void zdb_embedded_block(char *thing) { - blkptr_t bp = { 0 }; + blkptr_t bp; unsigned long long *words = (void *)&bp; char buf[SPA_MAXBLOCKSIZE]; int err; + bzero(&bp, sizeof (bp)); err = sscanf(thing, "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx:" "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx", words + 0, words + 1, words + 2, words + 3, @@ -3681,8 +3698,9 @@ find_zpool(char **target, nvlist_t **configp, int dirc, char **dirv) char *sepp = NULL; char sep = '\0'; int count = 0; - importargs_t args = { 0 }; + importargs_t args; + bzero(&args, sizeof (args)); args.paths = dirc; args.path = dirv; args.can_be_active = B_TRUE; @@ -3742,7 +3760,7 @@ find_zpool(char **target, nvlist_t **configp, int dirc, char **dirv) int main(int argc, char **argv) { - int i, c; + int c; struct rlimit rl = { 1024, 1024 }; spa_t *spa = NULL; objset_t *os = NULL; @@ -4022,7 +4040,7 @@ main(int argc, char **argv) if (argc > 0) { zopt_objects = argc; zopt_object = calloc(zopt_objects, sizeof (uint64_t)); - for (i = 0; i < zopt_objects; i++) { + for (unsigned i = 0; i < zopt_objects; i++) { errno = 0; zopt_object[i] = strtoull(argv[i], NULL, 0); if (zopt_object[i] == 0 && errno != 0) @@ -4047,7 +4065,7 @@ main(int argc, char **argv) flagbits['p'] = ZDB_FLAG_PHYS; flagbits['r'] = ZDB_FLAG_RAW; - for (i = 0; i < argc; i++) + for (int i = 0; i < argc; i++) zdb_read_block(argv[i], spa); } diff --git a/cmd/zdb/zdb.h b/cmd/zdb/zdb.h new file mode 100644 index 000000000000..49579811efbb --- /dev/null +++ b/cmd/zdb/zdb.h @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2017 Spectra Logic Corp Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#ifndef _ZDB_H +#define _ZDB_H + +void dump_intent_log(zilog_t *); +extern uint8_t dump_opt[256]; + +#endif /* _ZDB_H */ diff --git a/cmd/zdb/zdb_il.c b/cmd/zdb/zdb_il.c index bc02b1b6709f..680179fc3b7b 100644 --- a/cmd/zdb/zdb_il.c +++ b/cmd/zdb/zdb_il.c @@ -43,9 +43,11 @@ #include #include +#include "zdb.h" + extern uint8_t dump_opt[256]; -static char prefix[4] = "\t\t\t"; +static char tab_prefix[4] = "\t\t\t"; static void print_log_bp(const blkptr_t *bp, const char *prefix) @@ -58,8 +60,9 @@ print_log_bp(const blkptr_t *bp, const char *prefix) /* ARGSUSED */ static void -zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr) +zil_prt_rec_create(zilog_t *zilog, int txtype, void *arg) { + lr_create_t *lr = arg; time_t crtime = lr->lr_crtime[0]; char *name, *link; lr_attr_t *lrattr; @@ -74,47 +77,53 @@ zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr) if (txtype == TX_SYMLINK) { link = name + strlen(name) + 1; - (void) printf("%s%s -> %s\n", prefix, name, link); + (void) printf("%s%s -> %s\n", tab_prefix, name, link); } else if (txtype != TX_MKXATTR) { - (void) printf("%s%s\n", prefix, name); + (void) printf("%s%s\n", tab_prefix, name); } - (void) printf("%s%s", prefix, ctime(&crtime)); - (void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix, + (void) printf("%s%s", tab_prefix, ctime(&crtime)); + (void) printf("%sdoid %llu, foid %llu, mode %llo\n", tab_prefix, (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_mode); - (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix, + (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", + tab_prefix, (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid, (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev); } /* ARGSUSED */ static void -zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr) +zil_prt_rec_remove(zilog_t *zilog, int txtype, void *arg) { - (void) printf("%sdoid %llu, name %s\n", prefix, + lr_remove_t *lr = arg; + + (void) printf("%sdoid %llu, name %s\n", tab_prefix, (u_longlong_t)lr->lr_doid, (char *)(lr + 1)); } /* ARGSUSED */ static void -zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr) +zil_prt_rec_link(zilog_t *zilog, int txtype, void *arg) { - (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix, + lr_link_t *lr = arg; + + (void) printf("%sdoid %llu, link_obj %llu, name %s\n", tab_prefix, (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj, (char *)(lr + 1)); } /* ARGSUSED */ static void -zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr) +zil_prt_rec_rename(zilog_t *zilog, int txtype, void *arg) { + lr_rename_t *lr = arg; char *snm = (char *)(lr + 1); char *tnm = snm + strlen(snm) + 1; - (void) printf("%ssdoid %llu, tdoid %llu\n", prefix, + (void) printf("%ssdoid %llu, tdoid %llu\n", tab_prefix, (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid); - (void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm); + (void) printf("%ssrc %s tgt %s\n", tab_prefix, snm, tnm); } /* ARGSUSED */ @@ -122,7 +131,7 @@ static int zil_prt_rec_write_cb(void *data, size_t len, void *unused) { char *cdata = data; - for (int i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { if (isprint(*cdata)) (void) printf("%c ", *cdata); else @@ -134,15 +143,16 @@ zil_prt_rec_write_cb(void *data, size_t len, void *unused) /* ARGSUSED */ static void -zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr) +zil_prt_rec_write(zilog_t *zilog, int txtype, void *arg) { + lr_write_t *lr = arg; abd_t *data; blkptr_t *bp = &lr->lr_blkptr; zbookmark_phys_t zb; int verbose = MAX(dump_opt['d'], dump_opt['i']); int error; - (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix, + (void) printf("%sfoid %llu, offset %llx, length %llx\n", tab_prefix, (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset, (u_longlong_t)lr->lr_length); @@ -150,20 +160,21 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr) return; if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) { - (void) printf("%shas blkptr, %s\n", prefix, + (void) printf("%shas blkptr, %s\n", tab_prefix, !BP_IS_HOLE(bp) && bp->blk_birth >= spa_first_txg(zilog->zl_spa) ? "will claim" : "won't claim"); - print_log_bp(bp, prefix); + print_log_bp(bp, tab_prefix); if (BP_IS_HOLE(bp)) { (void) printf("\t\t\tLSIZE 0x%llx\n", (u_longlong_t)BP_GET_LSIZE(bp)); - (void) printf("%s\n", prefix); + (void) printf("%s\n", tab_prefix); return; } if (bp->blk_birth < zilog->zl_header->zh_claim_txg) { - (void) printf("%s\n", prefix); + (void) printf("%s\n", + tab_prefix); return; } @@ -183,7 +194,7 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr) abd_copy_from_buf(data, lr + 1, lr->lr_length); } - (void) printf("%s", prefix); + (void) printf("%s", tab_prefix); (void) abd_iterate_func(data, 0, MIN(lr->lr_length, (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE)), zil_prt_rec_write_cb, NULL); @@ -195,52 +206,55 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr) /* ARGSUSED */ static void -zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr) +zil_prt_rec_truncate(zilog_t *zilog, int txtype, void *arg) { - (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix, + lr_truncate_t *lr = arg; + + (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", tab_prefix, (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset, (u_longlong_t)lr->lr_length); } /* ARGSUSED */ static void -zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr) +zil_prt_rec_setattr(zilog_t *zilog, int txtype, void *arg) { + lr_setattr_t *lr = arg; time_t atime = (time_t)lr->lr_atime[0]; time_t mtime = (time_t)lr->lr_mtime[0]; - (void) printf("%sfoid %llu, mask 0x%llx\n", prefix, + (void) printf("%sfoid %llu, mask 0x%llx\n", tab_prefix, (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask); if (lr->lr_mask & AT_MODE) { - (void) printf("%sAT_MODE %llo\n", prefix, + (void) printf("%sAT_MODE %llo\n", tab_prefix, (longlong_t)lr->lr_mode); } if (lr->lr_mask & AT_UID) { - (void) printf("%sAT_UID %llu\n", prefix, + (void) printf("%sAT_UID %llu\n", tab_prefix, (u_longlong_t)lr->lr_uid); } if (lr->lr_mask & AT_GID) { - (void) printf("%sAT_GID %llu\n", prefix, + (void) printf("%sAT_GID %llu\n", tab_prefix, (u_longlong_t)lr->lr_gid); } if (lr->lr_mask & AT_SIZE) { - (void) printf("%sAT_SIZE %llu\n", prefix, + (void) printf("%sAT_SIZE %llu\n", tab_prefix, (u_longlong_t)lr->lr_size); } if (lr->lr_mask & AT_ATIME) { - (void) printf("%sAT_ATIME %llu.%09llu %s", prefix, + (void) printf("%sAT_ATIME %llu.%09llu %s", tab_prefix, (u_longlong_t)lr->lr_atime[0], (u_longlong_t)lr->lr_atime[1], ctime(&atime)); } if (lr->lr_mask & AT_MTIME) { - (void) printf("%sAT_MTIME %llu.%09llu %s", prefix, + (void) printf("%sAT_MTIME %llu.%09llu %s", tab_prefix, (u_longlong_t)lr->lr_mtime[0], (u_longlong_t)lr->lr_mtime[1], ctime(&mtime)); @@ -249,41 +263,43 @@ zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr) /* ARGSUSED */ static void -zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr) +zil_prt_rec_acl(zilog_t *zilog, int txtype, void *arg) { - (void) printf("%sfoid %llu, aclcnt %llu\n", prefix, + lr_acl_t *lr = arg; + + (void) printf("%sfoid %llu, aclcnt %llu\n", tab_prefix, (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt); } -typedef void (*zil_prt_rec_func_t)(); +typedef void (*zil_prt_rec_func_t)(zilog_t *, int, void *); typedef struct zil_rec_info { zil_prt_rec_func_t zri_print; - char *zri_name; + const char *zri_name; uint64_t zri_count; } zil_rec_info_t; static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = { - { NULL, "Total " }, - { zil_prt_rec_create, "TX_CREATE " }, - { zil_prt_rec_create, "TX_MKDIR " }, - { zil_prt_rec_create, "TX_MKXATTR " }, - { zil_prt_rec_create, "TX_SYMLINK " }, - { zil_prt_rec_remove, "TX_REMOVE " }, - { zil_prt_rec_remove, "TX_RMDIR " }, - { zil_prt_rec_link, "TX_LINK " }, - { zil_prt_rec_rename, "TX_RENAME " }, - { zil_prt_rec_write, "TX_WRITE " }, - { zil_prt_rec_truncate, "TX_TRUNCATE " }, - { zil_prt_rec_setattr, "TX_SETATTR " }, - { zil_prt_rec_acl, "TX_ACL_V0 " }, - { zil_prt_rec_acl, "TX_ACL_ACL " }, - { zil_prt_rec_create, "TX_CREATE_ACL " }, - { zil_prt_rec_create, "TX_CREATE_ATTR " }, - { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " }, - { zil_prt_rec_create, "TX_MKDIR_ACL " }, - { zil_prt_rec_create, "TX_MKDIR_ATTR " }, - { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " }, - { zil_prt_rec_write, "TX_WRITE2 " }, + {.zri_print = NULL, .zri_name = "Total "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKXATTR "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_SYMLINK "}, + {.zri_print = zil_prt_rec_remove, .zri_name = "TX_REMOVE "}, + {.zri_print = zil_prt_rec_remove, .zri_name = "TX_RMDIR "}, + {.zri_print = zil_prt_rec_link, .zri_name = "TX_LINK "}, + {.zri_print = zil_prt_rec_rename, .zri_name = "TX_RENAME "}, + {.zri_print = zil_prt_rec_write, .zri_name = "TX_WRITE "}, + {.zri_print = zil_prt_rec_truncate, .zri_name = "TX_TRUNCATE "}, + {.zri_print = zil_prt_rec_setattr, .zri_name = "TX_SETATTR "}, + {.zri_print = zil_prt_rec_acl, .zri_name = "TX_ACL_V0 "}, + {.zri_print = zil_prt_rec_acl, .zri_name = "TX_ACL_ACL "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE_ACL "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE_ATTR "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE_ACL_ATTR "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR_ACL "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR_ATTR "}, + {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR_ACL_ATTR "}, + {.zri_print = zil_prt_rec_write, .zri_name = "TX_WRITE2 "}, }; /* ARGSUSED */ @@ -321,7 +337,7 @@ print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg) { char blkbuf[BP_SPRINTF_LEN + 10]; int verbose = MAX(dump_opt['d'], dump_opt['i']); - char *claim; + const char *claim; if (verbose <= 3) return (0); @@ -350,7 +366,7 @@ print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg) static void print_log_stats(int verbose) { - int i, w, p10; + unsigned i, w, p10; if (verbose > 3) (void) printf("\n"); diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index c187a0358aa9..55611e6ccc90 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -1420,8 +1420,10 @@ ztest_log_setattr(ztest_ds_t *zd, dmu_tx_t *tx, lr_setattr_t *lr) * ZIL replay ops */ static int -ztest_replay_create(ztest_ds_t *zd, lr_create_t *lr, boolean_t byteswap) +ztest_replay_create(void *arg1, void *arg2, boolean_t byteswap) { + ztest_ds_t *zd = arg1; + lr_create_t *lr = arg2; char *name = (void *)(lr + 1); /* name follows lr */ objset_t *os = zd->zd_os; ztest_block_tag_t *bbt; @@ -1504,8 +1506,10 @@ ztest_replay_create(ztest_ds_t *zd, lr_create_t *lr, boolean_t byteswap) } static int -ztest_replay_remove(ztest_ds_t *zd, lr_remove_t *lr, boolean_t byteswap) +ztest_replay_remove(void *arg1, void *arg2, boolean_t byteswap) { + ztest_ds_t *zd = arg1; + lr_remove_t *lr = arg2; char *name = (void *)(lr + 1); /* name follows lr */ objset_t *os = zd->zd_os; dmu_object_info_t doi; @@ -1555,8 +1559,10 @@ ztest_replay_remove(ztest_ds_t *zd, lr_remove_t *lr, boolean_t byteswap) } static int -ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap) +ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap) { + ztest_ds_t *zd = arg1; + lr_write_t *lr = arg2; objset_t *os = zd->zd_os; void *data = lr + 1; /* data follows lr */ uint64_t offset, length; @@ -1680,8 +1686,10 @@ ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap) } static int -ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap) +ztest_replay_truncate(void *arg1, void *arg2, boolean_t byteswap) { + ztest_ds_t *zd = arg1; + lr_truncate_t *lr = arg2; objset_t *os = zd->zd_os; dmu_tx_t *tx; uint64_t txg; @@ -1719,8 +1727,10 @@ ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap) } static int -ztest_replay_setattr(ztest_ds_t *zd, lr_setattr_t *lr, boolean_t byteswap) +ztest_replay_setattr(void *arg1, void *arg2, boolean_t byteswap) { + ztest_ds_t *zd = arg1; + lr_setattr_t *lr = arg2; objset_t *os = zd->zd_os; dmu_tx_t *tx; dmu_buf_t *db; diff --git a/lib/libzpool/common/sys/zfs_context.h b/lib/libzpool/common/sys/zfs_context.h index 2fb336fcf984..01c12b90a869 100644 --- a/lib/libzpool/common/sys/zfs_context.h +++ b/lib/libzpool/common/sys/zfs_context.h @@ -197,7 +197,8 @@ extern struct proc p0; #define PS_NONE -1 -extern kthread_t *zk_thread_create(void (*func)(), void *arg); +extern kthread_t *zk_thread_create(void (*func)(void*), void *arg, + uint64_t len); #define issig(why) (FALSE) #define ISSIG(thr, why) (FALSE) diff --git a/uts/common/fs/zfs/arc.c b/uts/common/fs/zfs/arc.c index 2ccfe8784284..e431c1f5bf5b 100644 --- a/uts/common/fs/zfs/arc.c +++ b/uts/common/fs/zfs/arc.c @@ -4087,8 +4087,9 @@ arc_kmem_reap_now(void) * This possible deadlock is avoided by always acquiring a hash lock * using mutex_tryenter() from arc_reclaim_thread(). */ +/* ARGSUSED */ static void -arc_reclaim_thread(void) +arc_reclaim_thread(void *unused) { hrtime_t growtime = 0; callb_cpr_t cpr; @@ -7022,8 +7023,9 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz) * This thread feeds the L2ARC at regular intervals. This is the beating * heart of the L2ARC. */ +/* ARGSUSED */ static void -l2arc_feed_thread(void) +l2arc_feed_thread(void *unused) { callb_cpr_t cpr; l2arc_dev_t *dev; diff --git a/uts/common/fs/zfs/dbuf.c b/uts/common/fs/zfs/dbuf.c index 5abe64e0510a..cf6b550c3ef6 100644 --- a/uts/common/fs/zfs/dbuf.c +++ b/uts/common/fs/zfs/dbuf.c @@ -495,8 +495,9 @@ dbuf_evict_one(void) * of the dbuf cache is at or below the maximum size. Once the dbuf is aged * out of the cache it is destroyed and becomes eligible for arc eviction. */ +/* ARGSUSED */ static void -dbuf_evict_thread(void) +dbuf_evict_thread(void *unused) { callb_cpr_t cpr; diff --git a/uts/common/fs/zfs/spa.c b/uts/common/fs/zfs/spa.c index 576ef1525c3a..e97aa59a4074 100644 --- a/uts/common/fs/zfs/spa.c +++ b/uts/common/fs/zfs/spa.c @@ -5865,8 +5865,9 @@ spa_async_autoexpand(spa_t *spa, vdev_t *vd) } static void -spa_async_thread(spa_t *spa) +spa_async_thread(void *arg) { + spa_t *spa = (spa_t *)arg; int tasks; ASSERT(spa->spa_sync_on); diff --git a/uts/common/fs/zfs/sys/refcount.h b/uts/common/fs/zfs/sys/refcount.h index 3f50cddb6f51..17cb8174d4ac 100644 --- a/uts/common/fs/zfs/sys/refcount.h +++ b/uts/common/fs/zfs/sys/refcount.h @@ -39,7 +39,7 @@ extern "C" { * particular object, use FTAG (which is a string) for the holder_tag. * Otherwise, use the object that holds the reference. */ -#define FTAG ((char *)__func__) +#define FTAG ((char *)(uintptr_t)__func__) #ifdef ZFS_DEBUG typedef struct reference { diff --git a/uts/common/fs/zfs/sys/sa.h b/uts/common/fs/zfs/sys/sa.h index a60eb3772cd4..fe2291c50c64 100644 --- a/uts/common/fs/zfs/sys/sa.h +++ b/uts/common/fs/zfs/sys/sa.h @@ -146,8 +146,8 @@ int sa_replace_all_by_template(sa_handle_t *, sa_bulk_attr_t *, int sa_replace_all_by_template_locked(sa_handle_t *, sa_bulk_attr_t *, int, dmu_tx_t *); boolean_t sa_enabled(objset_t *); -void sa_cache_init(); -void sa_cache_fini(); +void sa_cache_init(void); +void sa_cache_fini(void); int sa_set_sa_object(objset_t *, uint64_t); int sa_hdrsize(void *); void sa_handle_lock(sa_handle_t *); diff --git a/uts/common/fs/zfs/sys/spa.h b/uts/common/fs/zfs/sys/spa.h index 1d267c971e40..91925a8cf241 100644 --- a/uts/common/fs/zfs/sys/spa.h +++ b/uts/common/fs/zfs/sys/spa.h @@ -870,7 +870,7 @@ extern void vdev_cache_stat_fini(void); /* Initialization and termination */ extern void spa_init(int flags); extern void spa_fini(void); -extern void spa_boot_init(); +extern void spa_boot_init(void); /* properties */ extern int spa_prop_set(spa_t *spa, nvlist_t *nvp); diff --git a/uts/common/fs/zfs/sys/zil.h b/uts/common/fs/zfs/sys/zil.h index 2b0484ad5ef8..1f1298e8c627 100644 --- a/uts/common/fs/zfs/sys/zil.h +++ b/uts/common/fs/zfs/sys/zil.h @@ -389,7 +389,7 @@ typedef int zil_parse_blk_func_t(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t txg); typedef int zil_parse_lr_func_t(zilog_t *zilog, lr_t *lr, void *arg, uint64_t txg); -typedef int zil_replay_func_t(); +typedef int zil_replay_func_t(void *arg1, void *arg2, boolean_t byteswap); typedef int zil_get_data_t(void *arg, lr_write_t *lr, char *dbuf, struct lwb *lwb, zio_t *zio); diff --git a/uts/common/fs/zfs/txg.c b/uts/common/fs/zfs/txg.c index 4bca693ef29b..ec36f09b3886 100644 --- a/uts/common/fs/zfs/txg.c +++ b/uts/common/fs/zfs/txg.c @@ -106,8 +106,8 @@ * now transition to the syncing state. */ -static void txg_sync_thread(dsl_pool_t *dp); -static void txg_quiesce_thread(dsl_pool_t *dp); +static void txg_sync_thread(void *arg); +static void txg_quiesce_thread(void *arg); int zfs_txg_timeout = 5; /* max seconds worth of delta per txg */ @@ -445,8 +445,9 @@ txg_dispatch_callbacks(dsl_pool_t *dp, uint64_t txg) } static void -txg_sync_thread(dsl_pool_t *dp) +txg_sync_thread(void *arg) { + dsl_pool_t *dp = arg; spa_t *spa = dp->dp_spa; tx_state_t *tx = &dp->dp_tx; callb_cpr_t cpr; @@ -525,8 +526,9 @@ txg_sync_thread(dsl_pool_t *dp) } static void -txg_quiesce_thread(dsl_pool_t *dp) +txg_quiesce_thread(void *arg) { + dsl_pool_t *dp = arg; tx_state_t *tx = &dp->dp_tx; callb_cpr_t cpr; diff --git a/uts/common/fs/zfs/zfs_replay.c b/uts/common/fs/zfs/zfs_replay.c index c4223079d0d7..de8d9c10b616 100644 --- a/uts/common/fs/zfs/zfs_replay.c +++ b/uts/common/fs/zfs/zfs_replay.c @@ -69,7 +69,7 @@ zfs_init_vattr(vattr_t *vap, uint64_t mask, uint64_t mode, /* ARGSUSED */ static int -zfs_replay_error(zfsvfs_t *zfsvfs, lr_t *lr, boolean_t byteswap) +zfs_replay_error(void *arg1, void *arg2, boolean_t byteswap) { return (SET_ERROR(ENOTSUP)); } @@ -262,9 +262,10 @@ zfs_replay_swap_attrs(lr_attr_t *lrattr) * as option FUID information. */ static int -zfs_replay_create_acl(zfsvfs_t *zfsvfs, - lr_acl_create_t *lracl, boolean_t byteswap) +zfs_replay_create_acl(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_acl_create_t *lracl = arg2; char *name = NULL; /* location determined later */ lr_create_t *lr = (lr_create_t *)lracl; znode_t *dzp; @@ -403,8 +404,10 @@ zfs_replay_create_acl(zfsvfs_t *zfsvfs, } static int -zfs_replay_create(zfsvfs_t *zfsvfs, lr_create_t *lr, boolean_t byteswap) +zfs_replay_create(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_create_t *lr = arg2; char *name = NULL; /* location determined later */ char *link; /* symlink content follows name */ znode_t *dzp; @@ -528,8 +531,10 @@ zfs_replay_create(zfsvfs_t *zfsvfs, lr_create_t *lr, boolean_t byteswap) } static int -zfs_replay_remove(zfsvfs_t *zfsvfs, lr_remove_t *lr, boolean_t byteswap) +zfs_replay_remove(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_remove_t *lr = arg2; char *name = (char *)(lr + 1); /* name follows lr_remove_t */ znode_t *dzp; int error; @@ -561,8 +566,10 @@ zfs_replay_remove(zfsvfs_t *zfsvfs, lr_remove_t *lr, boolean_t byteswap) } static int -zfs_replay_link(zfsvfs_t *zfsvfs, lr_link_t *lr, boolean_t byteswap) +zfs_replay_link(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_link_t *lr = arg2; char *name = (char *)(lr + 1); /* name follows lr_link_t */ znode_t *dzp, *zp; int error; @@ -591,8 +598,10 @@ zfs_replay_link(zfsvfs_t *zfsvfs, lr_link_t *lr, boolean_t byteswap) } static int -zfs_replay_rename(zfsvfs_t *zfsvfs, lr_rename_t *lr, boolean_t byteswap) +zfs_replay_rename(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_rename_t *lr = arg2; char *sname = (char *)(lr + 1); /* sname and tname follow lr_rename_t */ char *tname = sname + strlen(sname) + 1; znode_t *sdzp, *tdzp; @@ -623,8 +632,10 @@ zfs_replay_rename(zfsvfs_t *zfsvfs, lr_rename_t *lr, boolean_t byteswap) } static int -zfs_replay_write(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap) +zfs_replay_write(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_write_t *lr = arg2; char *data = (char *)(lr + 1); /* data follows lr_write_t */ znode_t *zp; int error; @@ -689,8 +700,10 @@ zfs_replay_write(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap) * the file is grown. */ static int -zfs_replay_write2(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap) +zfs_replay_write2(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_write_t *lr = arg2; znode_t *zp; int error; uint64_t end; @@ -734,8 +747,10 @@ zfs_replay_write2(zfsvfs_t *zfsvfs, lr_write_t *lr, boolean_t byteswap) } static int -zfs_replay_truncate(zfsvfs_t *zfsvfs, lr_truncate_t *lr, boolean_t byteswap) +zfs_replay_truncate(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_truncate_t *lr = arg2; znode_t *zp; flock64_t fl; int error; @@ -761,8 +776,10 @@ zfs_replay_truncate(zfsvfs_t *zfsvfs, lr_truncate_t *lr, boolean_t byteswap) } static int -zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_setattr_t *lr, boolean_t byteswap) +zfs_replay_setattr(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_setattr_t *lr = arg2; znode_t *zp; xvattr_t xva; vattr_t *vap = &xva.xva_vattr; @@ -813,8 +830,10 @@ zfs_replay_setattr(zfsvfs_t *zfsvfs, lr_setattr_t *lr, boolean_t byteswap) } static int -zfs_replay_acl_v0(zfsvfs_t *zfsvfs, lr_acl_v0_t *lr, boolean_t byteswap) +zfs_replay_acl_v0(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_acl_v0_t *lr = arg2; ace_t *ace = (ace_t *)(lr + 1); /* ace array follows lr_acl_t */ vsecattr_t vsa; znode_t *zp; @@ -857,8 +876,10 @@ zfs_replay_acl_v0(zfsvfs_t *zfsvfs, lr_acl_v0_t *lr, boolean_t byteswap) * */ static int -zfs_replay_acl(zfsvfs_t *zfsvfs, lr_acl_t *lr, boolean_t byteswap) +zfs_replay_acl(void *arg1, void *arg2, boolean_t byteswap) { + zfsvfs_t *zfsvfs = arg1; + lr_acl_t *lr = arg2; ace_t *ace = (ace_t *)(lr + 1); vsecattr_t vsa; znode_t *zp; diff --git a/uts/common/fs/zfs/zvol.c b/uts/common/fs/zfs/zvol.c index 35b5b69efa04..1e0529964b93 100644 --- a/uts/common/fs/zfs/zvol.c +++ b/uts/common/fs/zfs/zvol.c @@ -374,8 +374,10 @@ zvol_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx) * implement DKIOCFREE/free-long-range. */ static int -zvol_replay_truncate(zvol_state_t *zv, lr_truncate_t *lr, boolean_t byteswap) +zvol_replay_truncate(void *arg1, void *arg2, boolean_t byteswap) { + zvol_state_t *zv = arg1; + lr_truncate_t *lr = arg2; uint64_t offset, length; if (byteswap) @@ -392,8 +394,10 @@ zvol_replay_truncate(zvol_state_t *zv, lr_truncate_t *lr, boolean_t byteswap) * after a system failure */ static int -zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap) +zvol_replay_write(void *arg1, void *arg2, boolean_t byteswap) { + zvol_state_t *zv = arg1; + lr_write_t *lr = arg2; objset_t *os = zv->zv_objset; char *data = (char *)(lr + 1); /* data follows lr_write_t */ uint64_t offset, length; @@ -430,7 +434,7 @@ zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap) /* ARGSUSED */ static int -zvol_replay_err(zvol_state_t *zv, lr_t *lr, boolean_t byteswap) +zvol_replay_err(void *arg1, void *arg2, boolean_t byteswap) { return (SET_ERROR(ENOTSUP)); } From fcf62a28091fff46b3fc89729b9eeedbf8974dda Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Thu, 26 Oct 2017 16:20:47 +0000 Subject: [PATCH 2/3] 640 number_to_scaled_string is duplicated in several commands illumos/illumos-gate@0a0551200ecbcd4f1b17560acaeeb7b6c8b0090e https://github.com/illumos/illumos-gate/commit/0a0551200ecbcd4f1b17560acaeeb7b6c8b0090e https://www.illumos.org/issues/640 du(1), df(1m), ls(1), and swap(1m) all include a copy (it appears literally copied) of the 'number_to_scaled_string' function in their source. This should be moved to a shared library and all 4 commands should use this instead. Reviewed by: Sebastian Wiedenroth Reviewed by: Robert Mustacchi Reviewed by: Yuri Pankov Approved by: Dan McDonald Author: Jason King --- cmd/zdb/zdb.c | 138 +++++++++++++++++++------- cmd/ztest/ztest.c | 21 ++-- lib/libcmdutils/common/nicenum.c | 130 ++++++++++++++++++++++++ lib/libzfs/common/libzfs_util.c | 38 +------ lib/libzpool/common/sys/zfs_context.h | 2 +- lib/libzpool/common/util.c | 47 ++------- 6 files changed, 256 insertions(+), 120 deletions(-) create mode 100644 lib/libcmdutils/common/nicenum.c diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 32c548d2bd12..3538a9734fc6 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -63,6 +63,7 @@ #include #include #include +#include #undef verify #include @@ -277,12 +278,12 @@ dump_history_offsets(objset_t *os, uint64_t object, void *data, size_t size) } static void -zdb_nicenum(uint64_t num, char *buf) +zdb_nicenum(uint64_t num, char *buf, size_t buflen) { if (dump_opt['P']) - (void) sprintf(buf, "%llu", (longlong_t)num); + (void) snprintf(buf, buflen, "%llu", (longlong_t)num); else - nicenum(num, buf); + nicenum(num, buf, sizeof (buf)); } static const char histo_stars[] = "****************************************"; @@ -459,12 +460,17 @@ dump_bpobj(objset_t *os, uint64_t object, void *data, size_t size) bpobj_phys_t *bpop = data; char bytes[32], comp[32], uncomp[32]; + /* make sure the output won't get truncated */ + CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ); + if (bpop == NULL) return; - zdb_nicenum(bpop->bpo_bytes, bytes); - zdb_nicenum(bpop->bpo_comp, comp); - zdb_nicenum(bpop->bpo_uncomp, uncomp); + zdb_nicenum(bpop->bpo_bytes, bytes, sizeof (bytes)); + zdb_nicenum(bpop->bpo_comp, comp, sizeof (comp)); + zdb_nicenum(bpop->bpo_uncomp, uncomp, sizeof (uncomp)); (void) printf("\t\tnum_blkptrs = %llu\n", (u_longlong_t)bpop->bpo_num_blkptrs); @@ -757,7 +763,10 @@ dump_metaslab_stats(metaslab_t *msp) avl_tree_t *t = &msp->ms_size_tree; int free_pct = range_tree_space(rt) * 100 / msp->ms_size; - zdb_nicenum(metaslab_block_maxsize(msp), maxbuf); + /* max sure nicenum has enough space */ + CTASSERT(sizeof (maxbuf) >= NN_NUMBUF_SZ); + + zdb_nicenum(metaslab_block_maxsize(msp), maxbuf, sizeof (maxbuf)); (void) printf("\t %25s %10lu %7s %6s %4s %4d%%\n", "segments", avl_numnodes(t), "maxsize", maxbuf, @@ -774,7 +783,8 @@ dump_metaslab(metaslab_t *msp) space_map_t *sm = msp->ms_sm; char freebuf[32]; - zdb_nicenum(msp->ms_size - space_map_allocated(sm), freebuf); + zdb_nicenum(msp->ms_size - space_map_allocated(sm), freebuf, + sizeof (freebuf)); (void) printf( "\tmetaslab %6llu offset %12llx spacemap %6llu free %5s\n", @@ -1334,6 +1344,9 @@ dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size) time_t crtime; char nice[32]; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (nice) >= NN_NUMBUF_SZ); + if (dd == NULL) return; @@ -1349,15 +1362,15 @@ dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size) (u_longlong_t)dd->dd_origin_obj); (void) printf("\t\tchild_dir_zapobj = %llu\n", (u_longlong_t)dd->dd_child_dir_zapobj); - zdb_nicenum(dd->dd_used_bytes, nice); + zdb_nicenum(dd->dd_used_bytes, nice, sizeof (nice)); (void) printf("\t\tused_bytes = %s\n", nice); - zdb_nicenum(dd->dd_compressed_bytes, nice); + zdb_nicenum(dd->dd_compressed_bytes, nice, sizeof (nice)); (void) printf("\t\tcompressed_bytes = %s\n", nice); - zdb_nicenum(dd->dd_uncompressed_bytes, nice); + zdb_nicenum(dd->dd_uncompressed_bytes, nice, sizeof (nice)); (void) printf("\t\tuncompressed_bytes = %s\n", nice); - zdb_nicenum(dd->dd_quota, nice); + zdb_nicenum(dd->dd_quota, nice, sizeof (nice)); (void) printf("\t\tquota = %s\n", nice); - zdb_nicenum(dd->dd_reserved, nice); + zdb_nicenum(dd->dd_reserved, nice, sizeof (nice)); (void) printf("\t\treserved = %s\n", nice); (void) printf("\t\tprops_zapobj = %llu\n", (u_longlong_t)dd->dd_props_zapobj); @@ -1367,7 +1380,8 @@ dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size) (u_longlong_t)dd->dd_flags); #define DO(which) \ - zdb_nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice); \ + zdb_nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice, \ + sizeof (nice)); \ (void) printf("\t\tused_breakdown[" #which "] = %s\n", nice) DO(HEAD); DO(SNAP); @@ -1386,15 +1400,22 @@ dump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size) char used[32], compressed[32], uncompressed[32], unique[32]; char blkbuf[BP_SPRINTF_LEN]; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (used) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (compressed) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (uncompressed) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (unique) >= NN_NUMBUF_SZ); + if (ds == NULL) return; ASSERT(size == sizeof (*ds)); crtime = ds->ds_creation_time; - zdb_nicenum(ds->ds_referenced_bytes, used); - zdb_nicenum(ds->ds_compressed_bytes, compressed); - zdb_nicenum(ds->ds_uncompressed_bytes, uncompressed); - zdb_nicenum(ds->ds_unique_bytes, unique); + zdb_nicenum(ds->ds_referenced_bytes, used, sizeof (used)); + zdb_nicenum(ds->ds_compressed_bytes, compressed, sizeof (compressed)); + zdb_nicenum(ds->ds_uncompressed_bytes, uncompressed, + sizeof (uncompressed)); + zdb_nicenum(ds->ds_unique_bytes, unique, sizeof (unique)); snprintf_blkptr(blkbuf, sizeof (blkbuf), &ds->ds_bp); (void) printf("\t\tdir_obj = %llu\n", @@ -1453,12 +1474,15 @@ dump_bptree(objset_t *os, uint64_t obj, const char *name) bptree_phys_t *bt; dmu_buf_t *db; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ); + if (dump_opt['d'] < 3) return; VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db)); bt = db->db_data; - zdb_nicenum(bt->bt_bytes, bytes); + zdb_nicenum(bt->bt_bytes, bytes, sizeof (bytes)); (void) printf("\n %s: %llu datasets, %s\n", name, (unsigned long long)(bt->bt_end - bt->bt_begin), bytes); dmu_buf_rele(db, FTAG); @@ -1490,13 +1514,18 @@ dump_full_bpobj(bpobj_t *bpo, const char *name, int indent) char comp[32]; char uncomp[32]; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ); + if (dump_opt['d'] < 3) return; - zdb_nicenum(bpo->bpo_phys->bpo_bytes, bytes); + zdb_nicenum(bpo->bpo_phys->bpo_bytes, bytes, sizeof (bytes)); if (bpo->bpo_havesubobj && bpo->bpo_phys->bpo_subobjs != 0) { - zdb_nicenum(bpo->bpo_phys->bpo_comp, comp); - zdb_nicenum(bpo->bpo_phys->bpo_uncomp, uncomp); + zdb_nicenum(bpo->bpo_phys->bpo_comp, comp, sizeof (comp)); + zdb_nicenum(bpo->bpo_phys->bpo_uncomp, uncomp, sizeof (uncomp)); (void) printf(" %*s: object %llu, %llu local blkptrs, " "%llu subobjs in object %llu, %s (%s/%s comp)\n", indent * 8, name, @@ -1550,6 +1579,11 @@ dump_deadlist(dsl_deadlist_t *dl) char comp[32]; char uncomp[32]; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ); + if (dump_opt['d'] < 3) return; @@ -1558,9 +1592,9 @@ dump_deadlist(dsl_deadlist_t *dl) return; } - zdb_nicenum(dl->dl_phys->dl_used, bytes); - zdb_nicenum(dl->dl_phys->dl_comp, comp); - zdb_nicenum(dl->dl_phys->dl_uncomp, uncomp); + zdb_nicenum(dl->dl_phys->dl_used, bytes, sizeof (bytes)); + zdb_nicenum(dl->dl_phys->dl_comp, comp, sizeof (comp)); + zdb_nicenum(dl->dl_phys->dl_uncomp, uncomp, sizeof (uncomp)); (void) printf("\n Deadlist: %s (%s/%s comp)\n", bytes, comp, uncomp); @@ -1863,6 +1897,13 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header) char aux[50]; int error; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (iblk) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (dblk) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (lsize) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (asize) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (bonus_size) >= NN_NUMBUF_SZ); + if (*print_header) { (void) printf("\n%10s %3s %5s %5s %5s %5s %6s %s\n", "Object", "lvl", "iblk", "dblk", "dsize", "lsize", @@ -1883,11 +1924,11 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header) } dmu_object_info_from_dnode(dn, &doi); - zdb_nicenum(doi.doi_metadata_block_size, iblk); - zdb_nicenum(doi.doi_data_block_size, dblk); - zdb_nicenum(doi.doi_max_offset, lsize); - zdb_nicenum(doi.doi_physical_blocks_512 << 9, asize); - zdb_nicenum(doi.doi_bonus_size, bonus_size); + zdb_nicenum(doi.doi_metadata_block_size, iblk, sizeof (iblk)); + zdb_nicenum(doi.doi_data_block_size, dblk, sizeof (dblk)); + zdb_nicenum(doi.doi_max_offset, lsize, sizeof (lsize)); + zdb_nicenum(doi.doi_physical_blocks_512 << 9, asize, sizeof (asize)); + zdb_nicenum(doi.doi_bonus_size, bonus_size, sizeof (bonus_size)); (void) sprintf(fill, "%6.2f", 100.0 * doi.doi_fill_count * doi.doi_data_block_size / (object == 0 ? DNODES_PER_BLOCK : 1) / doi.doi_max_offset); @@ -1950,6 +1991,8 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header) for (;;) { char segsize[32]; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (segsize) >= NN_NUMBUF_SZ); error = dnode_next_offset(dn, 0, &start, minlvl, blkfill, 0); if (error) @@ -1957,7 +2000,7 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header) end = start; error = dnode_next_offset(dn, DNODE_FIND_HOLE, &end, minlvl, blkfill, 0); - zdb_nicenum(end - start, segsize); + zdb_nicenum(end - start, segsize, sizeof (segsize)); (void) printf("\t\tsegment [%016llx, %016llx)" " size %5s\n", (u_longlong_t)start, (u_longlong_t)end, segsize); @@ -1989,6 +2032,9 @@ dump_dir(objset_t *os) unsigned i; int error; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (numbuf) >= NN_NUMBUF_SZ); + dsl_pool_config_enter(dmu_objset_pool(os), FTAG); dmu_objset_fast_stat(os, &dds); dsl_pool_config_exit(dmu_objset_pool(os), FTAG); @@ -2007,7 +2053,7 @@ dump_dir(objset_t *os) ASSERT3U(usedobjs, ==, BP_GET_FILL(os->os_rootbp)); - zdb_nicenum(refdbytes, numbuf); + zdb_nicenum(refdbytes, numbuf, sizeof (numbuf)); if (verbosity >= 4) { (void) snprintf(blkbuf, sizeof (blkbuf), ", rootbp "); @@ -2652,6 +2698,9 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, int sec_remaining = (zcb->zcb_totalasize - bytes) / 1024 / kb_per_sec; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (buf) >= NN_NUMBUF_SZ); + zfs_nicenum(bytes, buf, sizeof (buf)); (void) fprintf(stderr, "\r%5s completed (%4dMB/s) " @@ -3003,6 +3052,14 @@ dump_block_stats(spa_t *spa) char avg[32], gang[32]; const char *typename; + /* make sure nicenum has enough space */ + CTASSERT(sizeof (csize) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (lsize) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (psize) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (asize) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (avg) >= NN_NUMBUF_SZ); + CTASSERT(sizeof (gang) >= NN_NUMBUF_SZ); + if (t < DMU_OT_NUMTYPES) typename = dmu_ot[t].ot_name; else @@ -3036,12 +3093,17 @@ dump_block_stats(spa_t *spa) zcb.zcb_type[ZB_TOTAL][t].zb_asize) continue; - zdb_nicenum(zb->zb_count, csize); - zdb_nicenum(zb->zb_lsize, lsize); - zdb_nicenum(zb->zb_psize, psize); - zdb_nicenum(zb->zb_asize, asize); - zdb_nicenum(zb->zb_asize / zb->zb_count, avg); - zdb_nicenum(zb->zb_gangs, gang); + zdb_nicenum(zb->zb_count, csize, + sizeof (csize)); + zdb_nicenum(zb->zb_lsize, lsize, + sizeof (lsize)); + zdb_nicenum(zb->zb_psize, psize, + sizeof (psize)); + zdb_nicenum(zb->zb_asize, asize, + sizeof (asize)); + zdb_nicenum(zb->zb_asize / zb->zb_count, avg, + sizeof (avg)); + zdb_nicenum(zb->zb_gangs, gang, sizeof (gang)); (void) printf("%6s\t%5s\t%5s\t%5s\t%5s" "\t%5.2f\t%6.2f\t", diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index 55611e6ccc90..8afe98766d7d 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -24,6 +24,7 @@ * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2013 Steven Hartland. All rights reserved. * Copyright (c) 2014 Integros [integros.com] + * Copyright 2017 Joyent, Inc. */ /* @@ -123,6 +124,7 @@ #include #include #include +#include static int ztest_fd_data = -1; static int ztest_fd_rand = -1; @@ -554,12 +556,13 @@ usage(boolean_t requested) { const ztest_shared_opts_t *zo = &ztest_opts_defaults; - char nice_vdev_size[10]; - char nice_gang_bang[10]; + char nice_vdev_size[NN_NUMBUF_SZ]; + char nice_gang_bang[NN_NUMBUF_SZ]; FILE *fp = requested ? stdout : stderr; - nicenum(zo->zo_vdev_size, nice_vdev_size); - nicenum(zo->zo_metaslab_gang_bang, nice_gang_bang); + nicenum(zo->zo_vdev_size, nice_vdev_size, sizeof (nice_vdev_size)); + nicenum(zo->zo_metaslab_gang_bang, nice_gang_bang, + sizeof (nice_gang_bang)); (void) fprintf(fp, "Usage: %s\n" "\t[-v vdevs (default: %llu)]\n" @@ -3166,10 +3169,10 @@ ztest_vdev_LUN_growth(ztest_ds_t *zd, uint64_t id) old_class_space, new_class_space); if (ztest_opts.zo_verbose >= 5) { - char oldnumbuf[6], newnumbuf[6]; + char oldnumbuf[NN_NUMBUF_SZ], newnumbuf[NN_NUMBUF_SZ]; - nicenum(old_class_space, oldnumbuf); - nicenum(new_class_space, newnumbuf); + nicenum(old_class_space, oldnumbuf, sizeof (oldnumbuf)); + nicenum(new_class_space, newnumbuf, sizeof (newnumbuf)); (void) printf("%s grew from %s to %s\n", spa->spa_name, oldnumbuf, newnumbuf); } @@ -6207,7 +6210,7 @@ main(int argc, char **argv) ztest_info_t *zi; ztest_shared_callstate_t *zc; char timebuf[100]; - char numbuf[6]; + char numbuf[NN_NUMBUF_SZ]; spa_t *spa; char *cmd; boolean_t hasalt; @@ -6344,7 +6347,7 @@ main(int argc, char **argv) now = MIN(now, zs->zs_proc_stop); print_time(zs->zs_proc_stop - now, timebuf); - nicenum(zs->zs_space, numbuf); + nicenum(zs->zs_space, numbuf, sizeof (numbuf)); (void) printf("Pass %3d, %8s, %3llu ENOSPC, " "%4.1f%% of %5s used, %3.0f%% done, %8s to go\n", diff --git a/lib/libcmdutils/common/nicenum.c b/lib/libcmdutils/common/nicenum.c new file mode 100644 index 000000000000..8e3202f79270 --- /dev/null +++ b/lib/libcmdutils/common/nicenum.c @@ -0,0 +1,130 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2017 Jason king + */ + +#include +#include +#include +#include +#include "libcmdutils.h" + +/* The largest suffix that can fit, aka an exabyte (2^60 / 10^18) */ +#define INDEX_MAX (6) + +/* Verify INDEX_MAX fits */ +CTASSERT(INDEX_MAX * 10 < sizeof (uint64_t) * 8); + +void +nicenum_scale(uint64_t n, size_t units, char *buf, size_t buflen, + uint32_t flags) +{ + uint64_t divamt = 1024; + uint64_t divisor = 1; + int index = 0; + int rc = 0; + char u; + + if (units == 0) + units = 1; + + if (n > 0) { + n *= units; + if (n < units) + goto overflow; + } + + if (flags & NN_DIVISOR_1000) + divamt = 1000; + + /* + * This tries to find the suffix S(n) such that + * S(n) <= n < S(n+1), where S(n) = 2^(n*10) | 10^(3*n) + * (i.e. 1024/1000, 1,048,576/1,000,000, etc). Stop once S(n) + * is the largest prefix supported (i.e. don't bother computing + * and checking S(n+1). Since INDEX_MAX should be the largest + * suffix that fits (currently an exabyte), S(INDEX_MAX + 1) is + * never checked as it would overflow. + */ + while (index < INDEX_MAX) { + uint64_t newdiv = divisor * divamt; + + /* CTASSERT() guarantee these never trip */ + VERIFY3U(newdiv, >=, divamt); + VERIFY3U(newdiv, >=, divisor); + + if (n < newdiv) + break; + + divisor = newdiv; + index++; + } + + u = " KMGTPE"[index]; + + if (index == 0) { + rc = snprintf(buf, buflen, "%llu", n); + } else if (n % divisor == 0) { + /* + * If this is an even multiple of the base, always display + * without any decimal precision. + */ + rc = snprintf(buf, buflen, "%llu%c", n / divisor, u); + } else { + /* + * We want to choose a precision that reflects the best choice + * for fitting in 5 characters. This can get rather tricky + * when we have numbers that are very close to an order of + * magnitude. For example, when displaying 10239 (which is + * really 9.999K), we want only a single place of precision + * for 10.0K. We could develop some complex heuristics for + * this, but it's much easier just to try each combination + * in turn. + */ + int i; + for (i = 2; i >= 0; i--) { + if ((rc = snprintf(buf, buflen, "%.*f%c", i, + (double)n / divisor, u)) <= 5) + break; + } + } + + if (rc + 1 > buflen || rc < 0) + goto overflow; + + return; + +overflow: + /* prefer a more verbose message if possible */ + if (buflen > 10) + (void) strlcpy(buf, "", buflen); + else + (void) strlcpy(buf, "??", buflen); +} + +void +nicenum(uint64_t num, char *buf, size_t buflen) +{ + nicenum_scale(num, 1, buf, buflen, 0); +} diff --git a/lib/libzfs/common/libzfs_util.c b/lib/libzfs/common/libzfs_util.c index bcb48094f65a..aba044add5e0 100644 --- a/lib/libzfs/common/libzfs_util.c +++ b/lib/libzfs/common/libzfs_util.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -572,42 +573,7 @@ zfs_strdup(libzfs_handle_t *hdl, const char *str) void zfs_nicenum(uint64_t num, char *buf, size_t buflen) { - uint64_t n = num; - int index = 0; - char u; - - while (n >= 1024) { - n /= 1024; - index++; - } - - u = " KMGTPE"[index]; - - if (index == 0) { - (void) snprintf(buf, buflen, "%llu", n); - } else if ((num & ((1ULL << 10 * index) - 1)) == 0) { - /* - * If this is an even multiple of the base, always display - * without any decimal precision. - */ - (void) snprintf(buf, buflen, "%llu%c", n, u); - } else { - /* - * We want to choose a precision that reflects the best choice - * for fitting in 5 characters. This can get rather tricky when - * we have numbers that are very close to an order of magnitude. - * For example, when displaying 10239 (which is really 9.999K), - * we want only a single place of precision for 10.0K. We could - * develop some complex heuristics for this, but it's much - * easier just to try each combination in turn. - */ - int i; - for (i = 2; i >= 0; i--) { - if (snprintf(buf, buflen, "%.*f%c", i, - (double)num / (1ULL << 10 * index), u) <= 5) - break; - } - } + nicenum(num, buf, buflen); } void diff --git a/lib/libzpool/common/sys/zfs_context.h b/lib/libzpool/common/sys/zfs_context.h index 01c12b90a869..d8d1f8e9191f 100644 --- a/lib/libzpool/common/sys/zfs_context.h +++ b/lib/libzpool/common/sys/zfs_context.h @@ -542,7 +542,7 @@ extern void kernel_init(int); extern void kernel_fini(void); struct spa; -extern void nicenum(uint64_t num, char *buf); +extern void nicenum(uint64_t num, char *buf, size_t); extern void show_pool_stats(struct spa *); extern int set_global_var(char *arg); diff --git a/lib/libzpool/common/util.c b/lib/libzpool/common/util.c index e929aa564544..363940677c19 100644 --- a/lib/libzpool/common/util.c +++ b/lib/libzpool/common/util.c @@ -38,33 +38,6 @@ * Routines needed by more than one client of libzpool. */ -void -nicenum(uint64_t num, char *buf) -{ - uint64_t n = num; - int index = 0; - char u; - - while (n >= 1024) { - n = (n + (1024 / 2)) / 1024; /* Round up or down */ - index++; - } - - u = " KMGTPE"[index]; - - if (index == 0) { - (void) sprintf(buf, "%llu", (u_longlong_t)n); - } else if (n < 10 && (num & (num - 1)) != 0) { - (void) sprintf(buf, "%.2f%c", - (double)num / (1ULL << 10 * index), u); - } else if (n < 100 && (num & (num - 1)) != 0) { - (void) sprintf(buf, "%.1f%c", - (double)num / (1ULL << 10 * index), u); - } else { - (void) sprintf(buf, "%llu%c", (u_longlong_t)n, u); - } -} - static void show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent) { @@ -97,15 +70,17 @@ show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent) sec = MAX(1, vs->vs_timestamp / NANOSEC); - nicenum(vs->vs_alloc, used); - nicenum(vs->vs_space - vs->vs_alloc, avail); - nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops); - nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops); - nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes); - nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes); - nicenum(vs->vs_read_errors, rerr); - nicenum(vs->vs_write_errors, werr); - nicenum(vs->vs_checksum_errors, cerr); + nicenum(vs->vs_alloc, used, sizeof (used)); + nicenum(vs->vs_space - vs->vs_alloc, avail, sizeof (avail)); + nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops, sizeof (rops)); + nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops, sizeof (wops)); + nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes, + sizeof (rbytes)); + nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes, + sizeof (wbytes)); + nicenum(vs->vs_read_errors, rerr, sizeof (rerr)); + nicenum(vs->vs_write_errors, werr, sizeof (werr)); + nicenum(vs->vs_checksum_errors, cerr, sizeof (cerr)); (void) printf("%*s%s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n", indent, "", From ae99a88d67d0b4329f0bc3d0ff1041e6b2c8c57d Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Fri, 27 Oct 2017 11:26:36 +0000 Subject: [PATCH 3/3] follow up to r325013, add libcmdutils.h to the vendor area --- lib/libcmdutils/libcmdutils.h | 231 ++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 lib/libcmdutils/libcmdutils.h diff --git a/lib/libcmdutils/libcmdutils.h b/lib/libcmdutils/libcmdutils.h new file mode 100644 index 000000000000..5f9957b861ff --- /dev/null +++ b/lib/libcmdutils/libcmdutils.h @@ -0,0 +1,231 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +/* + * Copyright (c) 2013 RackTop Systems. + */ +/* + * Copyright 2017 Joyent, Inc. + */ + +/* + * Declarations for the functions in libcmdutils. + */ + +#ifndef _LIBCMDUTILS_H +#define _LIBCMDUTILS_H + +#if !defined(_LP64) && \ + !((_FILE_OFFSET_BITS == 64) || defined(_LARGEFILE64_SOURCE)) +#error "libcmdutils.h can only be used in a largefile compilation environment" +#endif + +/* + * This is a private header file. Applications should not directly include + * this file. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* extended system attribute support */ +#define _NOT_SATTR 0 +#define _RO_SATTR 1 +#define _RW_SATTR 2 + +#define MAXMAPSIZE (1024*1024*8) /* map at most 8MB */ +#define SMALLFILESIZE (32*1024) /* don't use mmap on little file */ + +/* Type used for a node containing a device id and inode number */ + +#if defined(_LP64) || (_FILE_OFFSET_BITS == 64) +typedef struct tree_node { + dev_t node_dev; + ino_t node_ino; + avl_node_t avl_link; +} tree_node_t; +#else +typedef struct tree_node { + dev_t node_dev; + ino64_t node_ino; + avl_node_t avl_link; +} tree_node_t; +#endif + + /* extended system attribute support */ + +/* Determine if a file is the name of an extended system attribute file */ +extern int sysattr_type(char *); + +/* Determine if the underlying file system supports system attributes */ +extern int sysattr_support(char *, int); + +/* Copies the content of the source file to the target file */ +#if defined(_LP64) || (_FILE_OFFSET_BITS == 64) +extern int writefile(int, int, char *, char *, char *, char *, + struct stat *, struct stat *); +#else +extern int writefile(int, int, char *, char *, char *, char *, + struct stat64 *, struct stat64 *); +#endif + +/* Gets file descriptors of the source and target attribute files */ +extern int get_attrdirs(int, int, char *, int *, int *); + +/* Move extended attribute and extended system attribute */ +extern int mv_xattrs(char *, char *, char *, int, int); + +/* Returns non default extended system attribute list */ +extern nvlist_t *sysattr_list(char *, int, char *); + + + + /* avltree */ + +/* + * Used to compare two nodes. We are attempting to match the 1st + * argument (node) against the 2nd argument (a node which + * is already in the search tree). + */ + +extern int tnode_compare(const void *, const void *); + +/* + * Used to add a single node (containing the input device id and + * inode number) to the specified search tree. The calling + * application must set the tree pointer to NULL before calling + * add_tnode() for the first time. + */ +#if defined(_LP64) || (_FILE_OFFSET_BITS == 64) +extern int add_tnode(avl_tree_t **, dev_t, ino_t); +#else +extern int add_tnode(avl_tree_t **, dev_t, ino64_t); +#endif + +/* + * Used to destroy a whole tree (all nodes) without rebalancing. + * The calling application is responsible for setting the tree + * pointer to NULL upon return. + */ +extern void destroy_tree(avl_tree_t *); + + + + /* user/group id helpers */ + +/* + * Used to get the next available user id in given range. + */ +extern int findnextuid(uid_t, uid_t, uid_t *); + +/* + * Used to get the next available group id in given range. + */ +extern int findnextgid(gid_t, gid_t, gid_t *); + + + + /* dynamic string utilities */ + +typedef struct custr custr_t; + +/* + * Allocate and free a "custr_t" dynamic string object. Returns 0 on success + * and -1 otherwise. + */ +extern int custr_alloc(custr_t **); +extern void custr_free(custr_t *); + +/* + * Allocate a "custr_t" dynamic string object that operates on a fixed external + * buffer. + */ +extern int custr_alloc_buf(custr_t **, void *, size_t); + +/* + * Append a single character, or a NUL-terminated string of characters, to a + * dynamic string. Returns 0 on success and -1 otherwise. The dynamic string + * will be unmodified if the function returns -1. + */ +extern int custr_appendc(custr_t *, char); +extern int custr_append(custr_t *, const char *); + +/* + * Append a format string and arguments as though the contents were being parsed + * through snprintf. Returns 0 on success and -1 otherwise. The dynamic string + * will be unmodified if the function returns -1. + */ +extern int custr_append_printf(custr_t *, const char *, ...); +extern int custr_append_vprintf(custr_t *, const char *, va_list); + +/* + * Determine the length in bytes, not including the NUL terminator, of the + * dynamic string. + */ +extern size_t custr_len(custr_t *); + +/* + * Clear the contents of a dynamic string. Does not free the underlying + * memory. + */ +extern void custr_reset(custr_t *); + +/* + * Retrieve a const pointer to a NUL-terminated string version of the contents + * of the dynamic string. Storage for this string should not be freed, and + * the pointer will be invalidated by any mutations to the dynamic string. + */ +extern const char *custr_cstr(custr_t *str); + +#define NN_DIVISOR_1000 (1U << 0) + +/* Minimum size for the output of nicenum, including NULL */ +#define NN_NUMBUF_SZ (6) + +void nicenum(uint64_t, char *, size_t); +void nicenum_scale(uint64_t, size_t, char *, size_t, uint32_t); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBCMDUTILS_H */