Skip to content

Commit 3cf2bfa

Browse files
sanjeevbagewadinutanixbehlendorf
authored andcommitted
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
1 parent 141368a commit 3cf2bfa

35 files changed

+513
-365
lines changed

cmd/zdb/zdb.c

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,61 +1117,62 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
11171117
{
11181118
(void) data, (void) size;
11191119
zap_cursor_t zc;
1120-
zap_attribute_t attr;
1120+
zap_attribute_t *attrp = zap_attribute_alloc();
11211121
void *prop;
11221122
unsigned i;
11231123

11241124
dump_zap_stats(os, object);
11251125
(void) printf("\n");
11261126

11271127
for (zap_cursor_init(&zc, os, object);
1128-
zap_cursor_retrieve(&zc, &attr) == 0;
1128+
zap_cursor_retrieve(&zc, attrp) == 0;
11291129
zap_cursor_advance(&zc)) {
11301130
boolean_t key64 =
11311131
!!(zap_getflags(zc.zc_zap) & ZAP_FLAG_UINT64_KEY);
11321132

11331133
if (key64)
11341134
(void) printf("\t\t0x%010lx = ",
1135-
*(uint64_t *)attr.za_name);
1135+
*(uint64_t *)attrp->za_name);
11361136
else
1137-
(void) printf("\t\t%s = ", attr.za_name);
1137+
(void) printf("\t\t%s = ", attrp->za_name);
11381138

1139-
if (attr.za_num_integers == 0) {
1139+
if (attrp->za_num_integers == 0) {
11401140
(void) printf("\n");
11411141
continue;
11421142
}
1143-
prop = umem_zalloc(attr.za_num_integers *
1144-
attr.za_integer_length, UMEM_NOFAIL);
1143+
prop = umem_zalloc(attrp->za_num_integers *
1144+
attrp->za_integer_length, UMEM_NOFAIL);
11451145

11461146
if (key64)
11471147
(void) zap_lookup_uint64(os, object,
1148-
(const uint64_t *)attr.za_name, 1,
1149-
attr.za_integer_length, attr.za_num_integers,
1148+
(const uint64_t *)attrp->za_name, 1,
1149+
attrp->za_integer_length, attrp->za_num_integers,
11501150
prop);
11511151
else
1152-
(void) zap_lookup(os, object, attr.za_name,
1153-
attr.za_integer_length, attr.za_num_integers,
1152+
(void) zap_lookup(os, object, attrp->za_name,
1153+
attrp->za_integer_length, attrp->za_num_integers,
11541154
prop);
11551155

1156-
if (attr.za_integer_length == 1 && !key64) {
1157-
if (strcmp(attr.za_name,
1156+
if (attrp->za_integer_length == 1 && !key64) {
1157+
if (strcmp(attrp->za_name,
11581158
DSL_CRYPTO_KEY_MASTER_KEY) == 0 ||
1159-
strcmp(attr.za_name,
1159+
strcmp(attrp->za_name,
11601160
DSL_CRYPTO_KEY_HMAC_KEY) == 0 ||
1161-
strcmp(attr.za_name, DSL_CRYPTO_KEY_IV) == 0 ||
1162-
strcmp(attr.za_name, DSL_CRYPTO_KEY_MAC) == 0 ||
1163-
strcmp(attr.za_name, DMU_POOL_CHECKSUM_SALT) == 0) {
1161+
strcmp(attrp->za_name, DSL_CRYPTO_KEY_IV) == 0 ||
1162+
strcmp(attrp->za_name, DSL_CRYPTO_KEY_MAC) == 0 ||
1163+
strcmp(attrp->za_name,
1164+
DMU_POOL_CHECKSUM_SALT) == 0) {
11641165
uint8_t *u8 = prop;
11651166

1166-
for (i = 0; i < attr.za_num_integers; i++) {
1167+
for (i = 0; i < attrp->za_num_integers; i++) {
11671168
(void) printf("%02x", u8[i]);
11681169
}
11691170
} else {
11701171
(void) printf("%s", (char *)prop);
11711172
}
11721173
} else {
1173-
for (i = 0; i < attr.za_num_integers; i++) {
1174-
switch (attr.za_integer_length) {
1174+
for (i = 0; i < attrp->za_num_integers; i++) {
1175+
switch (attrp->za_integer_length) {
11751176
case 1:
11761177
(void) printf("%u ",
11771178
((uint8_t *)prop)[i]);
@@ -1192,9 +1193,11 @@ dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
11921193
}
11931194
}
11941195
(void) printf("\n");
1195-
umem_free(prop, attr.za_num_integers * attr.za_integer_length);
1196+
umem_free(prop,
1197+
attrp->za_num_integers * attrp->za_integer_length);
11961198
}
11971199
zap_cursor_fini(&zc);
1200+
zap_attribute_free(attrp);
11981201
}
11991202

12001203
static void
@@ -1295,72 +1298,74 @@ dump_sa_attrs(objset_t *os, uint64_t object, void *data, size_t size)
12951298
{
12961299
(void) data, (void) size;
12971300
zap_cursor_t zc;
1298-
zap_attribute_t attr;
1301+
zap_attribute_t *attrp = zap_attribute_alloc();
12991302

13001303
dump_zap_stats(os, object);
13011304
(void) printf("\n");
13021305

13031306
for (zap_cursor_init(&zc, os, object);
1304-
zap_cursor_retrieve(&zc, &attr) == 0;
1307+
zap_cursor_retrieve(&zc, attrp) == 0;
13051308
zap_cursor_advance(&zc)) {
1306-
(void) printf("\t\t%s = ", attr.za_name);
1307-
if (attr.za_num_integers == 0) {
1309+
(void) printf("\t\t%s = ", attrp->za_name);
1310+
if (attrp->za_num_integers == 0) {
13081311
(void) printf("\n");
13091312
continue;
13101313
}
13111314
(void) printf(" %llx : [%d:%d:%d]\n",
1312-
(u_longlong_t)attr.za_first_integer,
1313-
(int)ATTR_LENGTH(attr.za_first_integer),
1314-
(int)ATTR_BSWAP(attr.za_first_integer),
1315-
(int)ATTR_NUM(attr.za_first_integer));
1315+
(u_longlong_t)attrp->za_first_integer,
1316+
(int)ATTR_LENGTH(attrp->za_first_integer),
1317+
(int)ATTR_BSWAP(attrp->za_first_integer),
1318+
(int)ATTR_NUM(attrp->za_first_integer));
13161319
}
13171320
zap_cursor_fini(&zc);
1321+
zap_attribute_free(attrp);
13181322
}
13191323

13201324
static void
13211325
dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size)
13221326
{
13231327
(void) data, (void) size;
13241328
zap_cursor_t zc;
1325-
zap_attribute_t attr;
1329+
zap_attribute_t *attrp = zap_attribute_alloc();
13261330
uint16_t *layout_attrs;
13271331
unsigned i;
13281332

13291333
dump_zap_stats(os, object);
13301334
(void) printf("\n");
13311335

13321336
for (zap_cursor_init(&zc, os, object);
1333-
zap_cursor_retrieve(&zc, &attr) == 0;
1337+
zap_cursor_retrieve(&zc, attrp) == 0;
13341338
zap_cursor_advance(&zc)) {
1335-
(void) printf("\t\t%s = [", attr.za_name);
1336-
if (attr.za_num_integers == 0) {
1339+
(void) printf("\t\t%s = [", attrp->za_name);
1340+
if (attrp->za_num_integers == 0) {
13371341
(void) printf("\n");
13381342
continue;
13391343
}
13401344

1341-
VERIFY(attr.za_integer_length == 2);
1342-
layout_attrs = umem_zalloc(attr.za_num_integers *
1343-
attr.za_integer_length, UMEM_NOFAIL);
1345+
VERIFY(attrp->za_integer_length == 2);
1346+
layout_attrs = umem_zalloc(attrp->za_num_integers *
1347+
attrp->za_integer_length, UMEM_NOFAIL);
13441348

1345-
VERIFY(zap_lookup(os, object, attr.za_name,
1346-
attr.za_integer_length,
1347-
attr.za_num_integers, layout_attrs) == 0);
1349+
VERIFY(zap_lookup(os, object, attrp->za_name,
1350+
attrp->za_integer_length,
1351+
attrp->za_num_integers, layout_attrs) == 0);
13481352

1349-
for (i = 0; i != attr.za_num_integers; i++)
1353+
for (i = 0; i != attrp->za_num_integers; i++)
13501354
(void) printf(" %d ", (int)layout_attrs[i]);
13511355
(void) printf("]\n");
13521356
umem_free(layout_attrs,
1353-
attr.za_num_integers * attr.za_integer_length);
1357+
attrp->za_num_integers * attrp->za_integer_length);
13541358
}
13551359
zap_cursor_fini(&zc);
1360+
zap_attribute_free(attrp);
13561361
}
13571362

13581363
static void
13591364
dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
13601365
{
13611366
(void) data, (void) size;
13621367
zap_cursor_t zc;
1363-
zap_attribute_t attr;
1368+
zap_attribute_t *attrp = zap_attribute_alloc();
13641369
const char *typenames[] = {
13651370
/* 0 */ "not specified",
13661371
/* 1 */ "FIFO",
@@ -1384,13 +1389,14 @@ dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
13841389
(void) printf("\n");
13851390

13861391
for (zap_cursor_init(&zc, os, object);
1387-
zap_cursor_retrieve(&zc, &attr) == 0;
1392+
zap_cursor_retrieve(&zc, attrp) == 0;
13881393
zap_cursor_advance(&zc)) {
13891394
(void) printf("\t\t%s = %lld (type: %s)\n",
1390-
attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
1391-
typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
1395+
attrp->za_name, ZFS_DIRENT_OBJ(attrp->za_first_integer),
1396+
typenames[ZFS_DIRENT_TYPE(attrp->za_first_integer)]);
13921397
}
13931398
zap_cursor_fini(&zc);
1399+
zap_attribute_free(attrp);
13941400
}
13951401

13961402
static int
@@ -2155,23 +2161,25 @@ dump_brt(spa_t *spa)
21552161
continue;
21562162

21572163
zap_cursor_t zc;
2158-
zap_attribute_t za;
2164+
zap_attribute_t *za = zap_attribute_alloc();
21592165
for (zap_cursor_init(&zc, brt->brt_mos, brtvd->bv_mos_entries);
2160-
zap_cursor_retrieve(&zc, &za) == 0;
2166+
zap_cursor_retrieve(&zc, za) == 0;
21612167
zap_cursor_advance(&zc)) {
21622168
uint64_t refcnt;
21632169
VERIFY0(zap_lookup_uint64(brt->brt_mos,
21642170
brtvd->bv_mos_entries,
2165-
(const uint64_t *)za.za_name, 1,
2166-
za.za_integer_length, za.za_num_integers, &refcnt));
2171+
(const uint64_t *)za->za_name, 1,
2172+
za->za_integer_length, za->za_num_integers,
2173+
&refcnt));
21672174

2168-
uint64_t offset = *(const uint64_t *)za.za_name;
2175+
uint64_t offset = *(const uint64_t *)za->za_name;
21692176

21702177
snprintf(dva, sizeof (dva), "%" PRIu64 ":%llx", vdevid,
21712178
(u_longlong_t)offset);
21722179
printf("%-16s %-10llu\n", dva, (u_longlong_t)refcnt);
21732180
}
21742181
zap_cursor_fini(&zc);
2182+
zap_attribute_free(za);
21752183
}
21762184
}
21772185

@@ -2953,28 +2961,30 @@ static void
29532961
dump_bookmarks(objset_t *os, int verbosity)
29542962
{
29552963
zap_cursor_t zc;
2956-
zap_attribute_t attr;
2964+
zap_attribute_t *attrp;
29572965
dsl_dataset_t *ds = dmu_objset_ds(os);
29582966
dsl_pool_t *dp = spa_get_dsl(os->os_spa);
29592967
objset_t *mos = os->os_spa->spa_meta_objset;
29602968
if (verbosity < 4)
29612969
return;
2970+
attrp = zap_attribute_alloc();
29622971
dsl_pool_config_enter(dp, FTAG);
29632972

29642973
for (zap_cursor_init(&zc, mos, ds->ds_bookmarks_obj);
2965-
zap_cursor_retrieve(&zc, &attr) == 0;
2974+
zap_cursor_retrieve(&zc, attrp) == 0;
29662975
zap_cursor_advance(&zc)) {
29672976
char osname[ZFS_MAX_DATASET_NAME_LEN];
29682977
char buf[ZFS_MAX_DATASET_NAME_LEN];
29692978
int len;
29702979
dmu_objset_name(os, osname);
29712980
len = snprintf(buf, sizeof (buf), "%s#%s", osname,
2972-
attr.za_name);
2981+
attrp->za_name);
29732982
VERIFY3S(len, <, ZFS_MAX_DATASET_NAME_LEN);
29742983
(void) dump_bookmark(dp, buf, verbosity >= 5, verbosity >= 6);
29752984
}
29762985
zap_cursor_fini(&zc);
29772986
dsl_pool_config_exit(dp, FTAG);
2987+
zap_attribute_free(attrp);
29782988
}
29792989

29802990
static void
@@ -6857,18 +6867,19 @@ iterate_deleted_livelists(spa_t *spa, ll_iter_t func, void *arg)
68576867
ASSERT0(err);
68586868

68596869
zap_cursor_t zc;
6860-
zap_attribute_t attr;
6870+
zap_attribute_t *attrp = zap_attribute_alloc();
68616871
dsl_deadlist_t ll;
68626872
/* NULL out os prior to dsl_deadlist_open in case it's garbage */
68636873
ll.dl_os = NULL;
68646874
for (zap_cursor_init(&zc, mos, zap_obj);
6865-
zap_cursor_retrieve(&zc, &attr) == 0;
6875+
zap_cursor_retrieve(&zc, attrp) == 0;
68666876
(void) zap_cursor_advance(&zc)) {
6867-
dsl_deadlist_open(&ll, mos, attr.za_first_integer);
6877+
dsl_deadlist_open(&ll, mos, attrp->za_first_integer);
68686878
func(&ll, arg);
68696879
dsl_deadlist_close(&ll);
68706880
}
68716881
zap_cursor_fini(&zc);
6882+
zap_attribute_free(attrp);
68726883
}
68736884

68746885
static int
@@ -8082,13 +8093,14 @@ static void
80828093
errorlog_count_refd(objset_t *mos, uint64_t errlog)
80838094
{
80848095
zap_cursor_t zc;
8085-
zap_attribute_t za;
8096+
zap_attribute_t *za = zap_attribute_alloc();
80868097
for (zap_cursor_init(&zc, mos, errlog);
8087-
zap_cursor_retrieve(&zc, &za) == 0;
8098+
zap_cursor_retrieve(&zc, za) == 0;
80888099
zap_cursor_advance(&zc)) {
8089-
mos_obj_refd(za.za_first_integer);
8100+
mos_obj_refd(za->za_first_integer);
80908101
}
80918102
zap_cursor_fini(&zc);
8103+
zap_attribute_free(za);
80928104
}
80938105

80948106
static int

cmd/zhack.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,26 +203,27 @@ static void
203203
dump_obj(objset_t *os, uint64_t obj, const char *name)
204204
{
205205
zap_cursor_t zc;
206-
zap_attribute_t za;
206+
zap_attribute_t *za = zap_attribute_alloc();
207207

208208
(void) printf("%s_obj:\n", name);
209209

210210
for (zap_cursor_init(&zc, os, obj);
211-
zap_cursor_retrieve(&zc, &za) == 0;
211+
zap_cursor_retrieve(&zc, za) == 0;
212212
zap_cursor_advance(&zc)) {
213-
if (za.za_integer_length == 8) {
214-
ASSERT(za.za_num_integers == 1);
213+
if (za->za_integer_length == 8) {
214+
ASSERT(za->za_num_integers == 1);
215215
(void) printf("\t%s = %llu\n",
216-
za.za_name, (u_longlong_t)za.za_first_integer);
216+
za->za_name, (u_longlong_t)za->za_first_integer);
217217
} else {
218-
ASSERT(za.za_integer_length == 1);
218+
ASSERT(za->za_integer_length == 1);
219219
char val[1024];
220-
VERIFY(zap_lookup(os, obj, za.za_name,
220+
VERIFY(zap_lookup(os, obj, za->za_name,
221221
1, sizeof (val), val) == 0);
222-
(void) printf("\t%s = %s\n", za.za_name, val);
222+
(void) printf("\t%s = %s\n", za->za_name, val);
223223
}
224224
}
225225
zap_cursor_fini(&zc);
226+
zap_attribute_free(za);
226227
}
227228

228229
static void

include/sys/zap.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,19 @@ typedef struct {
376376
boolean_t za_normalization_conflict;
377377
uint64_t za_num_integers;
378378
uint64_t za_first_integer; /* no sign extension for <8byte ints */
379-
char za_name[ZAP_MAXNAMELEN];
379+
uint32_t za_name_len;
380+
char za_name[];
380381
} zap_attribute_t;
381382

383+
void zap_init(void);
384+
void zap_fini(void);
385+
386+
/*
387+
* Alloc and free zap_attribute_t.
388+
*/
389+
zap_attribute_t *zap_attribute_alloc(void);
390+
void zap_attribute_free(zap_attribute_t *attrp);
391+
382392
/*
383393
* The interface for listing all the attributes of a zapobj can be
384394
* thought of as cursor moving down a list of the attributes one by

include/sys/zap_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ typedef struct zap_name {
191191
uint64_t zn_hash;
192192
matchtype_t zn_matchtype;
193193
int zn_normflags;
194-
char zn_normbuf[ZAP_MAXNAMELEN];
194+
int zn_normbuf_len;
195+
char zn_normbuf[];
195196
} zap_name_t;
196197

197198
#define zap_f zap_u.zap_fat

0 commit comments

Comments
 (0)