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.

Note, FreeBSD vfs layer imposes a limit of 255 name lengh, so even
though we add code to support it here, it won't actually work.

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-06-18 08:55:01 +00:00
committed by Brian Behlendorf
parent 3cf2bfa570
commit 20232ecfaa
41 changed files with 1239 additions and 406 deletions
+55 -1
View File
@@ -46,9 +46,29 @@ zpl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
pathname_t pn;
int zfs_flags = 0;
zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
dsl_dataset_t *ds = dmu_objset_ds(zfsvfs->z_os);
size_t dlen = dlen(dentry);
if (dlen(dentry) >= ZAP_MAXNAMELEN)
/*
* If z_longname is disabled, disallow create or rename of names
* longer than ZAP_MAXNAMELEN.
*
* This is needed in cases where longname was enabled first and some
* files/dirs with names > ZAP_MAXNAMELEN were created. And later
* longname was disabled. In such a case allow access to existing
* longnames. But disallow creation newer longnamed entities.
*/
if (!zfsvfs->z_longname && (dlen >= ZAP_MAXNAMELEN)) {
/*
* If this is for create or rename fail it.
*/
if (!dsl_dataset_feature_is_active(ds, SPA_FEATURE_LONGNAME) ||
(flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)))
return (ERR_PTR(-ENAMETOOLONG));
}
if (dlen >= ZAP_MAXNAMELEN_NEW) {
return (ERR_PTR(-ENAMETOOLONG));
}
crhold(cr);
cookie = spl_fstrans_mark();
@@ -131,6 +151,16 @@ zpl_vap_init(vattr_t *vap, struct inode *dir, umode_t mode, cred_t *cr,
}
}
static inline bool
is_nametoolong(struct dentry *dentry)
{
zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
size_t dlen = dlen(dentry);
return ((!zfsvfs->z_longname && dlen >= ZAP_MAXNAMELEN) ||
dlen >= ZAP_MAXNAMELEN_NEW);
}
static int
#ifdef HAVE_IOPS_CREATE_USERNS
zpl_create(struct user_namespace *user_ns, struct inode *dir,
@@ -151,6 +181,10 @@ zpl_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flag)
zidmap_t *user_ns = kcred->user_ns;
#endif
if (is_nametoolong(dentry)) {
return (-ENAMETOOLONG);
}
crhold(cr);
vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
zpl_vap_init(vap, dir, mode, cr, user_ns);
@@ -201,6 +235,10 @@ zpl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
zidmap_t *user_ns = kcred->user_ns;
#endif
if (is_nametoolong(dentry)) {
return (-ENAMETOOLONG);
}
/*
* We currently expect Linux to supply rdev=0 for all sockets
* and fifos, but we want to know if this behavior ever changes.
@@ -353,6 +391,10 @@ zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
zidmap_t *user_ns = kcred->user_ns;
#endif
if (is_nametoolong(dentry)) {
return (-ENAMETOOLONG);
}
crhold(cr);
vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
zpl_vap_init(vap, dir, mode | S_IFDIR, cr, user_ns);
@@ -568,6 +610,10 @@ zpl_rename2(struct inode *sdip, struct dentry *sdentry,
zidmap_t *user_ns = kcred->user_ns;
#endif
if (is_nametoolong(tdentry)) {
return (-ENAMETOOLONG);
}
crhold(cr);
if (rflags & RENAME_WHITEOUT) {
wo_vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
@@ -618,6 +664,10 @@ zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
zidmap_t *user_ns = kcred->user_ns;
#endif
if (is_nametoolong(dentry)) {
return (-ENAMETOOLONG);
}
crhold(cr);
vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
zpl_vap_init(vap, dir, S_IFLNK | S_IRWXUGO, cr, user_ns);
@@ -707,6 +757,10 @@ zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
int error;
fstrans_cookie_t cookie;
if (is_nametoolong(dentry)) {
return (-ENAMETOOLONG);
}
if (ip->i_nlink >= ZFS_LINK_MAX)
return (-EMLINK);