Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Longname: files/directories name upto 1023 bytes #15921

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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_long_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_long_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_long_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
1 change: 1 addition & 0 deletions include/os/linux/zfs/sys/zfs_vfsops_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct zfsvfs {
boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */
boolean_t z_draining; /* is true when drain is active */
boolean_t z_drain_cancel; /* signal the unlinked drain to stop */
boolean_t z_longname; /* Dataset supports long names */
uint64_t z_version; /* ZPL version */
uint64_t z_shares_dir; /* hidden shares dir */
dataset_kstats_t z_kstat; /* fs kstats */
Expand Down
1 change: 1 addition & 0 deletions include/os/linux/zfs/sys/zfs_vnops_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern int zfs_write_simple(znode_t *zp, const void *data, size_t len,
loff_t pos, size_t *resid);
extern int zfs_lookup(znode_t *dzp, char *nm, znode_t **zpp, int flags,
cred_t *cr, int *direntflags, pathname_t *realpnp);
extern int zfs_get_name(znode_t *dzp, char *name, znode_t *zp);
extern int zfs_create(znode_t *dzp, char *name, vattr_t *vap, int excl,
int mode, znode_t **zpp, cred_t *cr, int flag, vsecattr_t *vsecp,
zidmap_t *mnt_ns);
Expand Down
2 changes: 2 additions & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef enum dmu_objset_type {
* All of these include the terminating NUL byte.
*/
#define ZAP_MAXNAMELEN 256
#define ZAP_MAXNAMELEN_NEW 1024
#define ZAP_MAXVALUELEN (1024 * 8)
#define ZAP_OLDMAXVALUELEN 1024
#define ZFS_MAX_DATASET_NAME_LEN 256
Expand Down Expand Up @@ -193,6 +194,7 @@ typedef enum {
ZFS_PROP_SNAPSHOTS_CHANGED,
ZFS_PROP_PREFETCH,
ZFS_PROP_VOLTHREADING,
ZFS_PROP_LONGNAME,
ZFS_NUM_PROPS
} zfs_prop_t;

Expand Down
15 changes: 13 additions & 2 deletions include/sys/zap.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
* match must be exact (ie, same as mask=-1ULL).
*/
int zap_value_search(objset_t *os, uint64_t zapobj,
uint64_t value, uint64_t mask, char *name);
uint64_t value, uint64_t mask, char *name, uint64_t namelen);

/*
* Transfer all the entries from fromobj into intoobj. Only works on
Expand Down Expand Up @@ -367,9 +367,20 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, this represents total length of the field. Just couple days ago looking recently on ZAP code I've found that its iterator code can not properly report binary names, since this structure includes neither length nor number of integers for the name, unlike value. I am thinking if it would be good to fix while you are here and changing the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amotin Right, this represent the buffer len for za_name.
Regarding your issue, can you elaborate a bit. Is there any command or api affect by this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuxoko There may be other examples, but I particularly hit that dump_zap() in zdb is unable to handle DDT and BRT ZAPs.

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);
zap_attribute_t *zap_attribute_long_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