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 <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #15921
This commit is contained in:
Sanjeev Bagewadi
2021-02-02 13:54:15 +00:00
committed by Brian Behlendorf
parent 141368a4b6
commit 3cf2bfa570
35 changed files with 513 additions and 365 deletions
+24 -16
View File
@@ -2621,35 +2621,39 @@ dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
{
dsl_dataset_t *ds = os->os_dsl_dataset;
zap_cursor_t cursor;
zap_attribute_t attr;
zap_attribute_t *attr;
ASSERT(dsl_pool_config_held(dmu_objset_pool(os)));
if (dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0)
return (SET_ERROR(ENOENT));
attr = zap_attribute_alloc();
zap_cursor_init_serialized(&cursor,
ds->ds_dir->dd_pool->dp_meta_objset,
dsl_dataset_phys(ds)->ds_snapnames_zapobj, *offp);
if (zap_cursor_retrieve(&cursor, &attr) != 0) {
if (zap_cursor_retrieve(&cursor, attr) != 0) {
zap_cursor_fini(&cursor);
zap_attribute_free(attr);
return (SET_ERROR(ENOENT));
}
if (strlen(attr.za_name) + 1 > namelen) {
if (strlen(attr->za_name) + 1 > namelen) {
zap_cursor_fini(&cursor);
zap_attribute_free(attr);
return (SET_ERROR(ENAMETOOLONG));
}
(void) strlcpy(name, attr.za_name, namelen);
(void) strlcpy(name, attr->za_name, namelen);
if (idp)
*idp = attr.za_first_integer;
*idp = attr->za_first_integer;
if (case_conflict)
*case_conflict = attr.za_normalization_conflict;
*case_conflict = attr->za_normalization_conflict;
zap_cursor_advance(&cursor);
*offp = zap_cursor_serialize(&cursor);
zap_cursor_fini(&cursor);
zap_attribute_free(attr);
return (0);
}
@@ -2666,33 +2670,37 @@ dmu_dir_list_next(objset_t *os, int namelen, char *name,
{
dsl_dir_t *dd = os->os_dsl_dataset->ds_dir;
zap_cursor_t cursor;
zap_attribute_t attr;
zap_attribute_t *attr;
/* there is no next dir on a snapshot! */
if (os->os_dsl_dataset->ds_object !=
dsl_dir_phys(dd)->dd_head_dataset_obj)
return (SET_ERROR(ENOENT));
attr = zap_attribute_alloc();
zap_cursor_init_serialized(&cursor,
dd->dd_pool->dp_meta_objset,
dsl_dir_phys(dd)->dd_child_dir_zapobj, *offp);
if (zap_cursor_retrieve(&cursor, &attr) != 0) {
if (zap_cursor_retrieve(&cursor, attr) != 0) {
zap_cursor_fini(&cursor);
zap_attribute_free(attr);
return (SET_ERROR(ENOENT));
}
if (strlen(attr.za_name) + 1 > namelen) {
if (strlen(attr->za_name) + 1 > namelen) {
zap_cursor_fini(&cursor);
zap_attribute_free(attr);
return (SET_ERROR(ENAMETOOLONG));
}
(void) strlcpy(name, attr.za_name, namelen);
(void) strlcpy(name, attr->za_name, namelen);
if (idp)
*idp = attr.za_first_integer;
*idp = attr->za_first_integer;
zap_cursor_advance(&cursor);
*offp = zap_cursor_serialize(&cursor);
zap_cursor_fini(&cursor);
zap_attribute_free(attr);
return (0);
}
@@ -2740,7 +2748,7 @@ dmu_objset_find_dp_impl(dmu_objset_find_ctx_t *dcp)
}
thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj;
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
attr = zap_attribute_alloc();
/*
* Iterate over all children.
@@ -2801,7 +2809,7 @@ dmu_objset_find_dp_impl(dmu_objset_find_ctx_t *dcp)
}
}
kmem_free(attr, sizeof (zap_attribute_t));
zap_attribute_free(attr);
if (err != 0) {
dsl_dir_rele(dd, FTAG);
@@ -2975,7 +2983,7 @@ dmu_objset_find_impl(spa_t *spa, const char *name,
}
thisobj = dsl_dir_phys(dd)->dd_head_dataset_obj;
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP);
attr = zap_attribute_alloc();
/*
* Iterate over all children.
@@ -3003,7 +3011,7 @@ dmu_objset_find_impl(spa_t *spa, const char *name,
if (err != 0) {
dsl_dir_rele(dd, FTAG);
dsl_pool_config_exit(dp, FTAG);
kmem_free(attr, sizeof (zap_attribute_t));
zap_attribute_free(attr);
return (err);
}
}
@@ -3041,7 +3049,7 @@ dmu_objset_find_impl(spa_t *spa, const char *name,
}
dsl_dir_rele(dd, FTAG);
kmem_free(attr, sizeof (zap_attribute_t));
zap_attribute_free(attr);
dsl_pool_config_exit(dp, FTAG);
if (err != 0)