Skip to content

Commit ed82dc5

Browse files
Support for longnames for files/directories (Linux part)
This patch adds the ability for zfs to support file/dir name up to 1023 bytes. This number is chosen so we can support up to 255 4-byte characters. This new feature is represented by the new feature flag feature@longname. A new dataset property "longname" is also introduced to toggle longname support for each dataset individually. This property can be disabled, even if it contains longname files. In such case, new file cannot be created with longname but existing longname files can still be looked up. Note that, to my knowledge native Linux filesystems don't support name longer than 255 bytes. So there might be programs not able to work with longname. Note that NFS server may needs to use exportfs_get_name to reconnect dentries, and the buffer being passed is limit to NAME_MAX+1 (256). So NFS may not work when longname is enabled. Signed-off-by: Chunwei Chen <[email protected]>
1 parent d346792 commit ed82dc5

35 files changed

+1164
-402
lines changed

cmd/zdb/zdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ 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 *attrp = zap_attribute_alloc();
1120+
zap_attribute_t *attrp = zap_attribute_long_alloc();
11211121
void *prop;
11221122
unsigned i;
11231123

@@ -1365,7 +1365,7 @@ dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
13651365
{
13661366
(void) data, (void) size;
13671367
zap_cursor_t zc;
1368-
zap_attribute_t *attrp = zap_attribute_alloc();
1368+
zap_attribute_t *attrp = zap_attribute_long_alloc();
13691369
const char *typenames[] = {
13701370
/* 0 */ "not specified",
13711371
/* 1 */ "FIFO",

cmd/zhack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ 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 = zap_attribute_alloc();
206+
zap_attribute_t *za = zap_attribute_long_alloc();
207207

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

include/os/linux/zfs/sys/zfs_vfsops_os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct zfsvfs {
118118
boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */
119119
boolean_t z_draining; /* is true when drain is active */
120120
boolean_t z_drain_cancel; /* signal the unlinked drain to stop */
121+
boolean_t z_longname; /* Dataset supports long names */
121122
uint64_t z_version; /* ZPL version */
122123
uint64_t z_shares_dir; /* hidden shares dir */
123124
dataset_kstats_t z_kstat; /* fs kstats */

include/os/linux/zfs/sys/zfs_vnops_os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern int zfs_write_simple(znode_t *zp, const void *data, size_t len,
4444
loff_t pos, size_t *resid);
4545
extern int zfs_lookup(znode_t *dzp, char *nm, znode_t **zpp, int flags,
4646
cred_t *cr, int *direntflags, pathname_t *realpnp);
47+
extern int zfs_get_name(znode_t *dzp, char *name, znode_t *zp);
4748
extern int zfs_create(znode_t *dzp, char *name, vattr_t *vap, int excl,
4849
int mode, znode_t **zpp, cred_t *cr, int flag, vsecattr_t *vsecp,
4950
zidmap_t *mnt_ns);

include/sys/fs/zfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef enum dmu_objset_type {
8181
* All of these include the terminating NUL byte.
8282
*/
8383
#define ZAP_MAXNAMELEN 256
84+
#define ZAP_MAXNAMELEN_NEW 1024
8485
#define ZAP_MAXVALUELEN (1024 * 8)
8586
#define ZAP_OLDMAXVALUELEN 1024
8687
#define ZFS_MAX_DATASET_NAME_LEN 256
@@ -194,6 +195,7 @@ typedef enum {
194195
ZFS_PROP_PREFETCH,
195196
ZFS_PROP_VOLTHREADING,
196197
ZFS_PROP_DIRECT,
198+
ZFS_PROP_LONGNAME,
197199
ZFS_NUM_PROPS
198200
} zfs_prop_t;
199201

include/sys/zap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
315315
* match must be exact (ie, same as mask=-1ULL).
316316
*/
317317
int zap_value_search(objset_t *os, uint64_t zapobj,
318-
uint64_t value, uint64_t mask, char *name);
318+
uint64_t value, uint64_t mask, char *name, uint64_t namelen);
319319

320320
/*
321321
* Transfer all the entries from fromobj into intoobj. Only works on
@@ -387,6 +387,7 @@ void zap_fini(void);
387387
* Alloc and free zap_attribute_t.
388388
*/
389389
zap_attribute_t *zap_attribute_alloc(void);
390+
zap_attribute_t *zap_attribute_long_alloc(void);
390391
void zap_attribute_free(zap_attribute_t *attrp);
391392

392393
/*

include/sys/zfs_ioctl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ typedef enum drr_headertype {
124124
* default use of "zfs send" won't encounter the bug mentioned above.
125125
*/
126126
#define DMU_BACKUP_FEATURE_SWITCH_TO_LARGE_BLOCKS (1 << 27)
127-
/* flag #28 is reserved for a Nutanix feature */
127+
#define DMU_BACKUP_FEATURE_LONGNAME (1 << 28)
128128
/*
129129
* flag #29 is the last unused bit. It is reserved to indicate a to-be-designed
130130
* extension to the stream format which will accomodate more feature flags.
@@ -141,7 +141,7 @@ typedef enum drr_headertype {
141141
DMU_BACKUP_FEATURE_COMPRESSED | DMU_BACKUP_FEATURE_LARGE_DNODE | \
142142
DMU_BACKUP_FEATURE_RAW | DMU_BACKUP_FEATURE_HOLDS | \
143143
DMU_BACKUP_FEATURE_REDACTED | DMU_BACKUP_FEATURE_SWITCH_TO_LARGE_BLOCKS | \
144-
DMU_BACKUP_FEATURE_ZSTD)
144+
DMU_BACKUP_FEATURE_ZSTD | DMU_BACKUP_FEATURE_LONGNAME)
145145

146146
/* Are all features in the given flag word currently supported? */
147147
#define DMU_STREAM_SUPPORTED(x) (!((x) & ~DMU_BACKUP_FEATURE_MASK))

include/zfeature_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ typedef enum spa_feature {
8383
SPA_FEATURE_REDACTION_LIST_SPILL,
8484
SPA_FEATURE_RAIDZ_EXPANSION,
8585
SPA_FEATURE_FAST_DEDUP,
86+
SPA_FEATURE_LONGNAME,
8687
SPA_FEATURES
8788
} spa_feature_t;
8889

lib/libzfs/libzfs.abi

Lines changed: 297 additions & 356 deletions
Large diffs are not rendered by default.

module/os/freebsd/zfs/zfs_znode_os.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ zfs_znode_parent_and_name(znode_t *zp, znode_t **dzpp, char *buf)
18141814
return (SET_ERROR(EINVAL));
18151815

18161816
err = zap_value_search(zfsvfs->z_os, parent, zp->z_id,
1817-
ZFS_DIRENT_OBJ(-1ULL), buf);
1817+
ZFS_DIRENT_OBJ(-1ULL), buf, MAXNAMELEN);
18181818
if (err != 0)
18191819
return (err);
18201820
err = zfs_zget(zfsvfs, parent, dzpp);

0 commit comments

Comments
 (0)