diff options
author | Sanjeev Bagewadi <[email protected]> | 2021-02-02 13:54:15 +0000 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2024-10-01 13:39:08 -0700 |
commit | 3cf2bfa57008af7f0690f73491d7f9b4ac4ed65a (patch) | |
tree | b92ca0e4bcf693c3b6f6df68c1995dcc4dfe5e63 /cmd | |
parent | 141368a4b6da039cefb745f6219d15b71e38326c (diff) |
Allocate zap_attribute_t from kmem instead of stack
This patch is preparatory work for long name feature. It changes all
users of zap_attribute_t to allocate it from kmem instead of stack. It
also make zap_attribute_t and zap_name_t structure variable length.
Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Chunwei Chen <[email protected]>
Closes #15921
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zdb/zdb.c | 130 | ||||
-rw-r--r-- | cmd/zhack.c | 17 |
2 files changed, 80 insertions, 67 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 8e3b6972a..83f79ad65 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -1117,7 +1117,7 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size) { (void) data, (void) size; zap_cursor_t zc; - zap_attribute_t attr; + zap_attribute_t *attrp = zap_attribute_alloc(); void *prop; unsigned i; @@ -1125,53 +1125,54 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size) (void) printf("\n"); for (zap_cursor_init(&zc, os, object); - zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_retrieve(&zc, attrp) == 0; zap_cursor_advance(&zc)) { boolean_t key64 = !!(zap_getflags(zc.zc_zap) & ZAP_FLAG_UINT64_KEY); if (key64) (void) printf("\t\t0x%010lx = ", - *(uint64_t *)attr.za_name); + *(uint64_t *)attrp->za_name); else - (void) printf("\t\t%s = ", attr.za_name); + (void) printf("\t\t%s = ", attrp->za_name); - if (attr.za_num_integers == 0) { + if (attrp->za_num_integers == 0) { (void) printf("\n"); continue; } - prop = umem_zalloc(attr.za_num_integers * - attr.za_integer_length, UMEM_NOFAIL); + prop = umem_zalloc(attrp->za_num_integers * + attrp->za_integer_length, UMEM_NOFAIL); if (key64) (void) zap_lookup_uint64(os, object, - (const uint64_t *)attr.za_name, 1, - attr.za_integer_length, attr.za_num_integers, + (const uint64_t *)attrp->za_name, 1, + attrp->za_integer_length, attrp->za_num_integers, prop); else - (void) zap_lookup(os, object, attr.za_name, - attr.za_integer_length, attr.za_num_integers, + (void) zap_lookup(os, object, attrp->za_name, + attrp->za_integer_length, attrp->za_num_integers, prop); - if (attr.za_integer_length == 1 && !key64) { - if (strcmp(attr.za_name, + if (attrp->za_integer_length == 1 && !key64) { + if (strcmp(attrp->za_name, DSL_CRYPTO_KEY_MASTER_KEY) == 0 || - strcmp(attr.za_name, + strcmp(attrp->za_name, DSL_CRYPTO_KEY_HMAC_KEY) == 0 || - strcmp(attr.za_name, DSL_CRYPTO_KEY_IV) == 0 || - strcmp(attr.za_name, DSL_CRYPTO_KEY_MAC) == 0 || - strcmp(attr.za_name, DMU_POOL_CHECKSUM_SALT) == 0) { + strcmp(attrp->za_name, DSL_CRYPTO_KEY_IV) == 0 || + strcmp(attrp->za_name, DSL_CRYPTO_KEY_MAC) == 0 || + strcmp(attrp->za_name, + DMU_POOL_CHECKSUM_SALT) == 0) { uint8_t *u8 = prop; - for (i = 0; i < attr.za_num_integers; i++) { + for (i = 0; i < attrp->za_num_integers; i++) { (void) printf("%02x", u8[i]); } } else { (void) printf("%s", (char *)prop); } } else { - for (i = 0; i < attr.za_num_integers; i++) { - switch (attr.za_integer_length) { + for (i = 0; i < attrp->za_num_integers; i++) { + switch (attrp->za_integer_length) { case 1: (void) printf("%u ", ((uint8_t *)prop)[i]); @@ -1192,9 +1193,11 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size) } } (void) printf("\n"); - umem_free(prop, attr.za_num_integers * attr.za_integer_length); + umem_free(prop, + attrp->za_num_integers * attrp->za_integer_length); } zap_cursor_fini(&zc); + zap_attribute_free(attrp); } static void @@ -1295,26 +1298,27 @@ dump_sa_attrs(objset_t *os, uint64_t object, void *data, size_t size) { (void) data, (void) size; zap_cursor_t zc; - zap_attribute_t attr; + zap_attribute_t *attrp = zap_attribute_alloc(); dump_zap_stats(os, object); (void) printf("\n"); for (zap_cursor_init(&zc, os, object); - zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_retrieve(&zc, attrp) == 0; zap_cursor_advance(&zc)) { - (void) printf("\t\t%s = ", attr.za_name); - if (attr.za_num_integers == 0) { + (void) printf("\t\t%s = ", attrp->za_name); + if (attrp->za_num_integers == 0) { (void) printf("\n"); continue; } (void) printf(" %llx : [%d:%d:%d]\n", - (u_longlong_t)attr.za_first_integer, - (int)ATTR_LENGTH(attr.za_first_integer), - (int)ATTR_BSWAP(attr.za_first_integer), - (int)ATTR_NUM(attr.za_first_integer)); + (u_longlong_t)attrp->za_first_integer, + (int)ATTR_LENGTH(attrp->za_first_integer), + (int)ATTR_BSWAP(attrp->za_first_integer), + (int)ATTR_NUM(attrp->za_first_integer)); } zap_cursor_fini(&zc); + zap_attribute_free(attrp); } static void @@ -1322,7 +1326,7 @@ dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size) { (void) data, (void) size; zap_cursor_t zc; - zap_attribute_t attr; + zap_attribute_t *attrp = zap_attribute_alloc(); uint16_t *layout_attrs; unsigned i; @@ -1330,29 +1334,30 @@ dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size) (void) printf("\n"); for (zap_cursor_init(&zc, os, object); - zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_retrieve(&zc, attrp) == 0; zap_cursor_advance(&zc)) { - (void) printf("\t\t%s = [", attr.za_name); - if (attr.za_num_integers == 0) { + (void) printf("\t\t%s = [", attrp->za_name); + if (attrp->za_num_integers == 0) { (void) printf("\n"); continue; } - VERIFY(attr.za_integer_length == 2); - layout_attrs = umem_zalloc(attr.za_num_integers * - attr.za_integer_length, UMEM_NOFAIL); + VERIFY(attrp->za_integer_length == 2); + layout_attrs = umem_zalloc(attrp->za_num_integers * + attrp->za_integer_length, UMEM_NOFAIL); - VERIFY(zap_lookup(os, object, attr.za_name, - attr.za_integer_length, - attr.za_num_integers, layout_attrs) == 0); + VERIFY(zap_lookup(os, object, attrp->za_name, + attrp->za_integer_length, + attrp->za_num_integers, layout_attrs) == 0); - for (i = 0; i != attr.za_num_integers; i++) + for (i = 0; i != attrp->za_num_integers; i++) (void) printf(" %d ", (int)layout_attrs[i]); (void) printf("]\n"); umem_free(layout_attrs, - attr.za_num_integers * attr.za_integer_length); + attrp->za_num_integers * attrp->za_integer_length); } zap_cursor_fini(&zc); + zap_attribute_free(attrp); } static void @@ -1360,7 +1365,7 @@ dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size) { (void) data, (void) size; zap_cursor_t zc; - zap_attribute_t attr; + zap_attribute_t *attrp = zap_attribute_alloc(); const char *typenames[] = { /* 0 */ "not specified", /* 1 */ "FIFO", @@ -1384,13 +1389,14 @@ dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size) (void) printf("\n"); for (zap_cursor_init(&zc, os, object); - zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_retrieve(&zc, attrp) == 0; zap_cursor_advance(&zc)) { (void) printf("\t\t%s = %lld (type: %s)\n", - attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer), - typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]); + attrp->za_name, ZFS_DIRENT_OBJ(attrp->za_first_integer), + typenames[ZFS_DIRENT_TYPE(attrp->za_first_integer)]); } zap_cursor_fini(&zc); + zap_attribute_free(attrp); } static int @@ -2155,23 +2161,25 @@ dump_brt(spa_t *spa) continue; zap_cursor_t zc; - zap_attribute_t za; + zap_attribute_t *za = zap_attribute_alloc(); for (zap_cursor_init(&zc, brt->brt_mos, brtvd->bv_mos_entries); - zap_cursor_retrieve(&zc, &za) == 0; + zap_cursor_retrieve(&zc, za) == 0; zap_cursor_advance(&zc)) { uint64_t refcnt; VERIFY0(zap_lookup_uint64(brt->brt_mos, brtvd->bv_mos_entries, - (const uint64_t *)za.za_name, 1, - za.za_integer_length, za.za_num_integers, &refcnt)); + (const uint64_t *)za->za_name, 1, + za->za_integer_length, za->za_num_integers, + &refcnt)); - uint64_t offset = *(const uint64_t *)za.za_name; + uint64_t offset = *(const uint64_t *)za->za_name; snprintf(dva, sizeof (dva), "%" PRIu64 ":%llx", vdevid, (u_longlong_t)offset); printf("%-16s %-10llu\n", dva, (u_longlong_t)refcnt); } zap_cursor_fini(&zc); + zap_attribute_free(za); } } @@ -2953,28 +2961,30 @@ static void dump_bookmarks(objset_t *os, int verbosity) { zap_cursor_t zc; - zap_attribute_t attr; + zap_attribute_t *attrp; dsl_dataset_t *ds = dmu_objset_ds(os); dsl_pool_t *dp = spa_get_dsl(os->os_spa); objset_t *mos = os->os_spa->spa_meta_objset; if (verbosity < 4) return; + attrp = zap_attribute_alloc(); dsl_pool_config_enter(dp, FTAG); for (zap_cursor_init(&zc, mos, ds->ds_bookmarks_obj); - zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_retrieve(&zc, attrp) == 0; zap_cursor_advance(&zc)) { char osname[ZFS_MAX_DATASET_NAME_LEN]; char buf[ZFS_MAX_DATASET_NAME_LEN]; int len; dmu_objset_name(os, osname); len = snprintf(buf, sizeof (buf), "%s#%s", osname, - attr.za_name); + attrp->za_name); VERIFY3S(len, <, ZFS_MAX_DATASET_NAME_LEN); (void) dump_bookmark(dp, buf, verbosity >= 5, verbosity >= 6); } zap_cursor_fini(&zc); dsl_pool_config_exit(dp, FTAG); + zap_attribute_free(attrp); } static void @@ -6857,18 +6867,19 @@ iterate_deleted_livelists(spa_t *spa, ll_iter_t func, void *arg) ASSERT0(err); zap_cursor_t zc; - zap_attribute_t attr; + zap_attribute_t *attrp = zap_attribute_alloc(); dsl_deadlist_t ll; /* NULL out os prior to dsl_deadlist_open in case it's garbage */ ll.dl_os = NULL; for (zap_cursor_init(&zc, mos, zap_obj); - zap_cursor_retrieve(&zc, &attr) == 0; + zap_cursor_retrieve(&zc, attrp) == 0; (void) zap_cursor_advance(&zc)) { - dsl_deadlist_open(&ll, mos, attr.za_first_integer); + dsl_deadlist_open(&ll, mos, attrp->za_first_integer); func(&ll, arg); dsl_deadlist_close(&ll); } zap_cursor_fini(&zc); + zap_attribute_free(attrp); } static int @@ -8082,13 +8093,14 @@ static void errorlog_count_refd(objset_t *mos, uint64_t errlog) { zap_cursor_t zc; - zap_attribute_t za; + zap_attribute_t *za = zap_attribute_alloc(); for (zap_cursor_init(&zc, mos, errlog); - zap_cursor_retrieve(&zc, &za) == 0; + zap_cursor_retrieve(&zc, za) == 0; zap_cursor_advance(&zc)) { - mos_obj_refd(za.za_first_integer); + mos_obj_refd(za->za_first_integer); } zap_cursor_fini(&zc); + zap_attribute_free(za); } static int diff --git a/cmd/zhack.c b/cmd/zhack.c index f15a6ece5..77284b895 100644 --- a/cmd/zhack.c +++ b/cmd/zhack.c @@ -203,26 +203,27 @@ static void dump_obj(objset_t *os, uint64_t obj, const char *name) { zap_cursor_t zc; - zap_attribute_t za; + zap_attribute_t *za = zap_attribute_alloc(); (void) printf("%s_obj:\n", name); for (zap_cursor_init(&zc, os, obj); - zap_cursor_retrieve(&zc, &za) == 0; + zap_cursor_retrieve(&zc, za) == 0; zap_cursor_advance(&zc)) { - if (za.za_integer_length == 8) { - ASSERT(za.za_num_integers == 1); + if (za->za_integer_length == 8) { + ASSERT(za->za_num_integers == 1); (void) printf("\t%s = %llu\n", - za.za_name, (u_longlong_t)za.za_first_integer); + za->za_name, (u_longlong_t)za->za_first_integer); } else { - ASSERT(za.za_integer_length == 1); + ASSERT(za->za_integer_length == 1); char val[1024]; - VERIFY(zap_lookup(os, obj, za.za_name, + VERIFY(zap_lookup(os, obj, za->za_name, 1, sizeof (val), val) == 0); - (void) printf("\t%s = %s\n", za.za_name, val); + (void) printf("\t%s = %s\n", za->za_name, val); } } zap_cursor_fini(&zc); + zap_attribute_free(za); } static void |