Skip to content

Commit

Permalink
Allocate zap_attribute_t from kmem instead of stack
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Chunwei Chen <[email protected]>
  • Loading branch information
sanjeevbagewadinutanix authored and davidchenntnx committed Feb 20, 2024
1 parent af4da5c commit ba0595c
Show file tree
Hide file tree
Showing 35 changed files with 507 additions and 360 deletions.
121 changes: 66 additions & 55 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,44 +1086,45 @@ 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;

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;
}
prop = umem_zalloc(attr.za_num_integers *
attr.za_integer_length, UMEM_NOFAIL);
(void) zap_lookup(os, object, attr.za_name,
attr.za_integer_length, attr.za_num_integers, prop);
if (attr.za_integer_length == 1) {
if (strcmp(attr.za_name,
prop = umem_zalloc(attrp->za_num_integers *
attrp->za_integer_length, UMEM_NOFAIL);
(void) zap_lookup(os, object, attrp->za_name,
attrp->za_integer_length, attrp->za_num_integers, prop);
if (attrp->za_integer_length == 1) {
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 2:
(void) printf("%u ",
((uint16_t *)prop)[i]);
Expand All @@ -1140,9 +1141,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
Expand Down Expand Up @@ -1243,72 +1246,74 @@ 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
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;

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;
}

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
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",
Expand All @@ -1332,13 +1337,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
Expand Down Expand Up @@ -2048,18 +2054,19 @@ 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 offset = *(uint64_t *)za.za_name;
uint64_t refcnt = za.za_first_integer;
uint64_t offset = *(uint64_t *)za->za_name;
uint64_t refcnt = za->za_first_integer;

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);
}
}

Expand Down Expand Up @@ -2841,28 +2848,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
Expand Down Expand Up @@ -6636,18 +6645,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
Expand Down Expand Up @@ -7862,13 +7872,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
Expand Down
17 changes: 9 additions & 8 deletions cmd/zhack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion include/sys/zap.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,19 @@ typedef struct {
boolean_t za_normalization_conflict;
uint64_t za_num_integers;
uint64_t za_first_integer; /* no sign extension for <8byte ints */
char za_name[ZAP_MAXNAMELEN];
uint32_t za_name_len;
char za_name[];
} zap_attribute_t;

void zap_init(void);
void zap_fini(void);

/*
* Alloc and free zap_attribute_t.
*/
zap_attribute_t *zap_attribute_alloc(void);
void zap_attribute_free(zap_attribute_t *attrp);

/*
* The interface for listing all the attributes of a zapobj can be
* thought of as cursor moving down a list of the attributes one by
Expand Down
3 changes: 2 additions & 1 deletion include/sys/zap_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ typedef struct zap_name {
uint64_t zn_hash;
matchtype_t zn_matchtype;
int zn_normflags;
char zn_normbuf[ZAP_MAXNAMELEN];
int zn_normbuf_len;
char zn_normbuf[];
} zap_name_t;

#define zap_f zap_u.zap_fat
Expand Down
Loading

0 comments on commit ba0595c

Please sign in to comment.