mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 19:04:45 +03:00
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:
committed by
Brian Behlendorf
parent
3cf2bfa570
commit
20232ecfaa
@@ -627,6 +627,15 @@ zfs_link_create(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we added a longname activate the SPA_FEATURE_LONGNAME.
|
||||
*/
|
||||
if (strlen(name) >= ZAP_MAXNAMELEN) {
|
||||
dsl_dataset_t *ds = dmu_objset_ds(zfsvfs->z_os);
|
||||
ds->ds_feature_activation[SPA_FEATURE_LONGNAME] =
|
||||
(void *)B_TRUE;
|
||||
}
|
||||
|
||||
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL,
|
||||
&dzp->z_id, sizeof (dzp->z_id));
|
||||
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
|
||||
|
||||
@@ -614,6 +614,14 @@ acl_type_changed_cb(void *arg, uint64_t newval)
|
||||
zfsvfs->z_acl_type = newval;
|
||||
}
|
||||
|
||||
static void
|
||||
longname_changed_cb(void *arg, uint64_t newval)
|
||||
{
|
||||
zfsvfs_t *zfsvfs = arg;
|
||||
|
||||
zfsvfs->z_longname = newval;
|
||||
}
|
||||
|
||||
static int
|
||||
zfs_register_callbacks(vfs_t *vfsp)
|
||||
{
|
||||
@@ -751,6 +759,8 @@ zfs_register_callbacks(vfs_t *vfsp)
|
||||
error = error ? error : dsl_prop_register(ds,
|
||||
zfs_prop_to_name(ZFS_PROP_ACLINHERIT), acl_inherit_changed_cb,
|
||||
zfsvfs);
|
||||
error = error ? error : dsl_prop_register(ds,
|
||||
zfs_prop_to_name(ZFS_PROP_LONGNAME), longname_changed_cb, zfsvfs);
|
||||
dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
|
||||
if (error)
|
||||
goto unregister;
|
||||
@@ -1489,7 +1499,8 @@ zfs_statfs(vfs_t *vfsp, struct statfs *statp)
|
||||
strlcpy(statp->f_mntonname, vfsp->mnt_stat.f_mntonname,
|
||||
sizeof (statp->f_mntonname));
|
||||
|
||||
statp->f_namemax = MAXNAMELEN - 1;
|
||||
statp->f_namemax =
|
||||
zfsvfs->z_longname ? (ZAP_MAXNAMELEN_NEW - 1) : (MAXNAMELEN - 1);
|
||||
|
||||
zfs_exit(zfsvfs, FTAG);
|
||||
return (0);
|
||||
|
||||
@@ -892,6 +892,14 @@ zfs_lookup(vnode_t *dvp, const char *nm, vnode_t **vpp,
|
||||
return (error);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
is_nametoolong(zfsvfs_t *zfsvfs, const char *name)
|
||||
{
|
||||
size_t dlen = strlen(name);
|
||||
return ((!zfsvfs->z_longname && dlen >= ZAP_MAXNAMELEN) ||
|
||||
dlen >= ZAP_MAXNAMELEN_NEW);
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to create a new entry in a directory. If the entry
|
||||
* already exists, truncate the file if permissible, else return
|
||||
@@ -937,6 +945,9 @@ zfs_create(znode_t *dzp, const char *name, vattr_t *vap, int excl, int mode,
|
||||
vnode_t *dvp = ZTOV(dzp);
|
||||
#endif
|
||||
|
||||
if (is_nametoolong(zfsvfs, name))
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
|
||||
/*
|
||||
* If we have an ephemeral id, ACL, or XVATTR then
|
||||
* make sure file system is at proper version
|
||||
@@ -1301,6 +1312,9 @@ zfs_mkdir(znode_t *dzp, const char *dirname, vattr_t *vap, znode_t **zpp,
|
||||
|
||||
ASSERT3U(vap->va_type, ==, VDIR);
|
||||
|
||||
if (is_nametoolong(zfsvfs, dirname))
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
|
||||
/*
|
||||
* If we have an ephemeral id, ACL, or XVATTR then
|
||||
* make sure file system is at proper version
|
||||
@@ -1616,7 +1630,7 @@ zfs_readdir(vnode_t *vp, zfs_uio_t *uio, cred_t *cr, int *eofp,
|
||||
os = zfsvfs->z_os;
|
||||
offset = zfs_uio_offset(uio);
|
||||
prefetch = zp->z_zn_prefetch;
|
||||
zap = zap_attribute_alloc();
|
||||
zap = zap_attribute_long_alloc();
|
||||
|
||||
/*
|
||||
* Initialize the iterator cursor.
|
||||
@@ -3294,6 +3308,9 @@ zfs_rename(znode_t *sdzp, const char *sname, znode_t *tdzp, const char *tname,
|
||||
int error;
|
||||
svp = tvp = NULL;
|
||||
|
||||
if (is_nametoolong(tdzp->z_zfsvfs, tname))
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
|
||||
if (rflags != 0 || wo_vap != NULL)
|
||||
return (SET_ERROR(EINVAL));
|
||||
|
||||
@@ -3358,6 +3375,9 @@ zfs_symlink(znode_t *dzp, const char *name, vattr_t *vap,
|
||||
|
||||
ASSERT3S(vap->va_type, ==, VLNK);
|
||||
|
||||
if (is_nametoolong(zfsvfs, name))
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
|
||||
if ((error = zfs_enter_verify_zp(zfsvfs, dzp, FTAG)) != 0)
|
||||
return (error);
|
||||
zilog = zfsvfs->z_log;
|
||||
@@ -3540,6 +3560,9 @@ zfs_link(znode_t *tdzp, znode_t *szp, const char *name, cred_t *cr,
|
||||
|
||||
ASSERT3S(ZTOV(tdzp)->v_type, ==, VDIR);
|
||||
|
||||
if (is_nametoolong(zfsvfs, name))
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
|
||||
if ((error = zfs_enter_verify_zp(zfsvfs, tdzp, FTAG)) != 0)
|
||||
return (error);
|
||||
zilog = zfsvfs->z_log;
|
||||
@@ -5996,7 +6019,8 @@ zfs_vptocnp(struct vop_vptocnp_args *ap)
|
||||
znode_t *dzp;
|
||||
size_t len;
|
||||
|
||||
error = zfs_znode_parent_and_name(zp, &dzp, name);
|
||||
error = zfs_znode_parent_and_name(zp, &dzp, name,
|
||||
sizeof (name));
|
||||
if (error == 0) {
|
||||
len = strlen(name);
|
||||
if (*ap->a_buflen < len)
|
||||
|
||||
@@ -1792,7 +1792,8 @@ zfs_znode_update_vfs(znode_t *zp)
|
||||
}
|
||||
|
||||
int
|
||||
zfs_znode_parent_and_name(znode_t *zp, znode_t **dzpp, char *buf)
|
||||
zfs_znode_parent_and_name(znode_t *zp, znode_t **dzpp, char *buf,
|
||||
uint64_t buflen)
|
||||
{
|
||||
zfsvfs_t *zfsvfs = zp->z_zfsvfs;
|
||||
uint64_t parent;
|
||||
@@ -1814,7 +1815,7 @@ zfs_znode_parent_and_name(znode_t *zp, znode_t **dzpp, char *buf)
|
||||
return (SET_ERROR(EINVAL));
|
||||
|
||||
err = zap_value_search(zfsvfs->z_os, parent, zp->z_id,
|
||||
ZFS_DIRENT_OBJ(-1ULL), buf);
|
||||
ZFS_DIRENT_OBJ(-1ULL), buf, buflen);
|
||||
if (err != 0)
|
||||
return (err);
|
||||
err = zfs_zget(zfsvfs, parent, dzpp);
|
||||
|
||||
Reference in New Issue
Block a user