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
+9
View File
@@ -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,
+12 -1
View File
@@ -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);
+26 -2
View File
@@ -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)
+3 -2
View File
@@ -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);
+9
View File
@@ -847,6 +847,15 @@ zfs_link_create(zfs_dirlock_t *dl, znode_t *zp, dmu_tx_t *tx, int flag)
return (error);
}
/*
* If we added a longname activate the SPA_FEATURE_LONGNAME.
*/
if (strlen(dl->dl_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,
+11 -1
View File
@@ -57,6 +57,7 @@
#include <sys/dmu_objset.h>
#include <sys/dsl_dir.h>
#include <sys/objlist.h>
#include <sys/zfeature.h>
#include <sys/zpl.h>
#include <linux/vfs_compat.h>
#include <linux/fs.h>
@@ -449,6 +450,12 @@ acl_inherit_changed_cb(void *arg, uint64_t newval)
((zfsvfs_t *)arg)->z_acl_inherit = newval;
}
static void
longname_changed_cb(void *arg, uint64_t newval)
{
((zfsvfs_t *)arg)->z_longname = newval;
}
static int
zfs_register_callbacks(vfs_t *vfsp)
{
@@ -509,6 +516,8 @@ zfs_register_callbacks(vfs_t *vfsp)
zfsvfs);
error = error ? error : dsl_prop_register(ds,
zfs_prop_to_name(ZFS_PROP_NBMAND), nbmand_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;
@@ -1140,7 +1149,8 @@ zfs_statvfs(struct inode *ip, struct kstatfs *statp)
statp->f_fsid.val[0] = (uint32_t)fsid;
statp->f_fsid.val[1] = (uint32_t)(fsid >> 32);
statp->f_type = ZFS_SUPER_MAGIC;
statp->f_namelen = MAXNAMELEN - 1;
statp->f_namelen =
zfsvfs->z_longname ? (ZAP_MAXNAMELEN_NEW - 1) : (MAXNAMELEN - 1);
/*
* We have all of 40 characters to stuff a string here.
+41 -1
View File
@@ -542,6 +542,46 @@ zfs_lookup(znode_t *zdp, char *nm, znode_t **zpp, int flags, cred_t *cr,
return (error);
}
/*
* Perform a linear search in directory for the name of specific inode.
* Note we don't pass in the buffer size of name because it's hardcoded to
* NAME_MAX+1(256) in Linux.
*
* IN: dzp - znode of directory to search.
* zp - znode of the target
*
* OUT: name - dentry name of the target
*
* RETURN: 0 on success, error code on failure.
*/
int
zfs_get_name(znode_t *dzp, char *name, znode_t *zp)
{
zfsvfs_t *zfsvfs = ZTOZSB(dzp);
int error = 0;
if ((error = zfs_enter_verify_zp(zfsvfs, dzp, FTAG)) != 0)
return (error);
if ((error = zfs_verify_zp(zp)) != 0) {
zfs_exit(zfsvfs, FTAG);
return (error);
}
/* ctldir should have got their name in zfs_vget */
if (dzp->z_is_ctldir || zp->z_is_ctldir) {
zfs_exit(zfsvfs, FTAG);
return (ENOENT);
}
/* buffer len is hardcoded to 256 in Linux kernel */
error = zap_value_search(zfsvfs->z_os, dzp->z_id, zp->z_id,
ZFS_DIRENT_OBJ(-1ULL), name, ZAP_MAXNAMELEN);
zfs_exit(zfsvfs, FTAG);
return (error);
}
/*
* Attempt to create a new entry in a directory. If the entry
* already exists, truncate the file if permissible, else return
@@ -1548,7 +1588,7 @@ zfs_readdir(struct inode *ip, struct dir_context *ctx, cred_t *cr)
os = zfsvfs->z_os;
offset = ctx->pos;
prefetch = zp->z_zn_prefetch;
zap = zap_attribute_alloc();
zap = zap_attribute_long_alloc();
/*
* Initialize the iterator cursor.
+31
View File
@@ -24,6 +24,7 @@
*/
#include <sys/file.h>
#include <sys/zfs_znode.h>
#include <sys/zfs_vnops.h>
#include <sys/zfs_ctldir.h>
@@ -102,6 +103,35 @@ zpl_fh_to_dentry(struct super_block *sb, struct fid *fh,
return (d_obtain_alias(ip));
}
/*
* In case the filesystem contains name longer than 255, we need to override
* the default get_name so we don't get buffer overflow. Unfortunately, since
* the buffer size is hardcoded in Linux, we will get ESTALE error in this
* case.
*/
static int
zpl_get_name(struct dentry *parent, char *name, struct dentry *child)
{
cred_t *cr = CRED();
fstrans_cookie_t cookie;
struct inode *dir = parent->d_inode;
struct inode *ip = child->d_inode;
int error;
if (!dir || !S_ISDIR(dir->i_mode))
return (-ENOTDIR);
crhold(cr);
cookie = spl_fstrans_mark();
spl_inode_lock_shared(dir);
error = -zfs_get_name(ITOZ(dir), name, ITOZ(ip));
spl_inode_unlock_shared(dir);
spl_fstrans_unmark(cookie);
crfree(cr);
return (error);
}
static struct dentry *
zpl_get_parent(struct dentry *child)
{
@@ -146,6 +176,7 @@ zpl_commit_metadata(struct inode *inode)
const struct export_operations zpl_export_operations = {
.encode_fh = zpl_encode_fh,
.fh_to_dentry = zpl_fh_to_dentry,
.get_name = zpl_get_name,
.get_parent = zpl_get_parent,
.commit_metadata = zpl_commit_metadata,
};
+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);
+12
View File
@@ -760,6 +760,18 @@ zpool_feature_init(void)
ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL,
sfeatures);
{
static const spa_feature_t longname_deps[] = {
SPA_FEATURE_EXTENSIBLE_DATASET,
SPA_FEATURE_NONE
};
zfeature_register(SPA_FEATURE_LONGNAME,
"org.zfsonlinux:longname", "longname",
"support filename up to 1024 bytes",
ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN,
longname_deps, sfeatures);
}
zfs_mod_list_supported_free(sfeatures);
}
+4
View File
@@ -772,6 +772,10 @@ zfs_prop_init(void)
ZFS_TYPE_VOLUME, "<date>", "SNAPSHOTS_CHANGED", B_FALSE, B_TRUE,
B_TRUE, NULL, sfeatures);
zprop_register_index(ZFS_PROP_LONGNAME, "longname", 0, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM, "on | off", "LONGNAME", boolean_table,
sfeatures);
zfs_mod_list_supported_free(sfeatures);
}
+17
View File
@@ -602,6 +602,13 @@ recv_begin_check_feature_flags_impl(uint64_t featureflags, spa_t *spa)
!spa_feature_is_enabled(spa, SPA_FEATURE_REDACTED_DATASETS))
return (SET_ERROR(ENOTSUP));
/*
* If the LONGNAME is not enabled on the target, fail that request.
*/
if ((featureflags & DMU_BACKUP_FEATURE_LONGNAME) &&
!spa_feature_is_enabled(spa, SPA_FEATURE_LONGNAME))
return (SET_ERROR(ENOTSUP));
return (0);
}
@@ -990,6 +997,16 @@ dmu_recv_begin_sync(void *arg, dmu_tx_t *tx)
dmu_buf_will_dirty(newds->ds_dbuf, tx);
dsl_dataset_phys(newds)->ds_flags |= DS_FLAG_INCONSISTENT;
/*
* Activate longname feature if received
*/
if (featureflags & DMU_BACKUP_FEATURE_LONGNAME &&
!dsl_dataset_feature_is_active(newds, SPA_FEATURE_LONGNAME)) {
dsl_dataset_activate_feature(newds->ds_object,
SPA_FEATURE_LONGNAME, (void *)B_TRUE, tx);
newds->ds_feature[SPA_FEATURE_LONGNAME] = (void *)B_TRUE;
}
/*
* If we actually created a non-clone, we need to create the objset
* in our new dataset. If this is a raw send we postpone this until
+4
View File
@@ -2011,6 +2011,10 @@ setup_featureflags(struct dmu_send_params *dspp, objset_t *os,
if (dsl_dataset_feature_is_active(to_ds, SPA_FEATURE_LARGE_DNODE)) {
*featureflags |= DMU_BACKUP_FEATURE_LARGE_DNODE;
}
if (dsl_dataset_feature_is_active(to_ds, SPA_FEATURE_LONGNAME)) {
*featureflags |= DMU_BACKUP_FEATURE_LONGNAME;
}
return (0);
}
+2 -1
View File
@@ -494,7 +494,8 @@ dsl_dataset_get_snapname(dsl_dataset_t *ds)
return (err);
headphys = headdbuf->db_data;
err = zap_value_search(dp->dp_meta_objset,
headphys->ds_snapnames_zapobj, ds->ds_object, 0, ds->ds_snapname);
headphys->ds_snapnames_zapobj, ds->ds_object, 0, ds->ds_snapname,
sizeof (ds->ds_snapname));
if (err != 0 && zfs_recover == B_TRUE) {
err = 0;
(void) snprintf(ds->ds_snapname, sizeof (ds->ds_snapname),
+2 -1
View File
@@ -239,7 +239,8 @@ dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,
err = zap_value_search(dp->dp_meta_objset,
dsl_dir_phys(dd->dd_parent)->
dd_child_dir_zapobj,
ddobj, 0, dd->dd_myname);
ddobj, 0, dd->dd_myname,
sizeof (dd->dd_myname));
}
if (err != 0)
goto errout;
+13 -7
View File
@@ -832,7 +832,12 @@ zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l,
static int
fzap_checkname(zap_name_t *zn)
{
if (zn->zn_key_orig_numints * zn->zn_key_intlen > ZAP_MAXNAMELEN)
uint32_t maxnamelen = zn->zn_normbuf_len;
uint64_t len = (uint64_t)zn->zn_key_orig_numints * zn->zn_key_intlen;
/* Only allow directory zap to have longname */
if (len > maxnamelen ||
(len > ZAP_MAXNAMELEN &&
zn->zn_zap->zap_dnode->dn_type != DMU_OT_DIRECTORY_CONTENTS))
return (SET_ERROR(ENAMETOOLONG));
return (0);
}
@@ -1102,7 +1107,7 @@ zap_create_link_dnsize(objset_t *os, dmu_object_type_t ot, uint64_t parent_obj,
int
zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
char *name)
char *name, uint64_t namelen)
{
zap_cursor_t zc;
int err;
@@ -1110,12 +1115,13 @@ zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
if (mask == 0)
mask = -1ULL;
zap_attribute_t *za = zap_attribute_alloc();
zap_attribute_t *za = zap_attribute_long_alloc();
for (zap_cursor_init(&zc, os, zapobj);
(err = zap_cursor_retrieve(&zc, za)) == 0;
zap_cursor_advance(&zc)) {
if ((za->za_first_integer & mask) == (value & mask)) {
(void) strlcpy(name, za->za_name, MAXNAMELEN);
if (strlcpy(name, za->za_name, namelen) >= namelen)
err = SET_ERROR(ENAMETOOLONG);
break;
}
}
@@ -1130,7 +1136,7 @@ zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx)
zap_cursor_t zc;
int err = 0;
zap_attribute_t *za = zap_attribute_alloc();
zap_attribute_t *za = zap_attribute_long_alloc();
for (zap_cursor_init(&zc, os, fromobj);
zap_cursor_retrieve(&zc, za) == 0;
(void) zap_cursor_advance(&zc)) {
@@ -1155,7 +1161,7 @@ zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
zap_cursor_t zc;
int err = 0;
zap_attribute_t *za = zap_attribute_alloc();
zap_attribute_t *za = zap_attribute_long_alloc();
for (zap_cursor_init(&zc, os, fromobj);
zap_cursor_retrieve(&zc, za) == 0;
(void) zap_cursor_advance(&zc)) {
@@ -1180,7 +1186,7 @@ zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
zap_cursor_t zc;
int err = 0;
zap_attribute_t *za = zap_attribute_alloc();
zap_attribute_t *za = zap_attribute_long_alloc();
for (zap_cursor_init(&zc, os, fromobj);
zap_cursor_retrieve(&zc, za) == 0;
(void) zap_cursor_advance(&zc)) {
+80 -24
View File
@@ -131,12 +131,12 @@ zap_hash(zap_name_t *zn)
}
static int
zap_normalize(zap_t *zap, const char *name, char *namenorm, int normflags)
zap_normalize(zap_t *zap, const char *name, char *namenorm, int normflags,
size_t outlen)
{
ASSERT(!(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY));
size_t inlen = strlen(name) + 1;
size_t outlen = ZAP_MAXNAMELEN;
int err = 0;
(void) u8_textprep_str((char *)name, &inlen, namenorm, &outlen,
@@ -149,23 +149,39 @@ zap_normalize(zap_t *zap, const char *name, char *namenorm, int normflags)
boolean_t
zap_match(zap_name_t *zn, const char *matchname)
{
boolean_t res = B_FALSE;
ASSERT(!(zap_getflags(zn->zn_zap) & ZAP_FLAG_UINT64_KEY));
if (zn->zn_matchtype & MT_NORMALIZE) {
char norm[ZAP_MAXNAMELEN];
size_t namelen = zn->zn_normbuf_len;
char normbuf[ZAP_MAXNAMELEN];
char *norm = normbuf;
/*
* Cannot allocate this on-stack as it exceed the stack-limit of
* 1024.
*/
if (namelen > ZAP_MAXNAMELEN)
norm = kmem_alloc(namelen, KM_SLEEP);
if (zap_normalize(zn->zn_zap, matchname, norm,
zn->zn_normflags) != 0)
return (B_FALSE);
return (strcmp(zn->zn_key_norm, norm) == 0);
zn->zn_normflags, namelen) != 0) {
res = B_FALSE;
} else {
res = (strcmp(zn->zn_key_norm, norm) == 0);
}
if (norm != normbuf)
kmem_free(norm, namelen);
} else {
return (strcmp(zn->zn_key_orig, matchname) == 0);
res = (strcmp(zn->zn_key_orig, matchname) == 0);
}
return (res);
}
static kmem_cache_t *zap_name_cache;
static kmem_cache_t *zap_attr_cache;
static kmem_cache_t *zap_name_long_cache;
static kmem_cache_t *zap_attr_long_cache;
void
zap_init(void)
@@ -177,6 +193,14 @@ zap_init(void)
zap_attr_cache = kmem_cache_create("zap_attr_cache",
sizeof (zap_attribute_t) + ZAP_MAXNAMELEN, 0, NULL,
NULL, NULL, NULL, NULL, 0);
zap_name_long_cache = kmem_cache_create("zap_name_long",
sizeof (zap_name_t) + ZAP_MAXNAMELEN_NEW, 0, NULL, NULL,
NULL, NULL, NULL, 0);
zap_attr_long_cache = kmem_cache_create("zap_attr_long_cache",
sizeof (zap_attribute_t) + ZAP_MAXNAMELEN_NEW, 0, NULL,
NULL, NULL, NULL, NULL, 0);
}
void
@@ -184,33 +208,47 @@ zap_fini(void)
{
kmem_cache_destroy(zap_name_cache);
kmem_cache_destroy(zap_attr_cache);
kmem_cache_destroy(zap_name_long_cache);
kmem_cache_destroy(zap_attr_long_cache);
}
static zap_name_t *
zap_name_alloc(zap_t *zap)
zap_name_alloc(zap_t *zap, boolean_t longname)
{
zap_name_t *zn = kmem_cache_alloc(zap_name_cache, KM_SLEEP);
kmem_cache_t *cache = longname ? zap_name_long_cache : zap_name_cache;
zap_name_t *zn = kmem_cache_alloc(cache, KM_SLEEP);
zn->zn_zap = zap;
zn->zn_normbuf_len = longname ? ZAP_MAXNAMELEN_NEW : ZAP_MAXNAMELEN;
return (zn);
}
void
zap_name_free(zap_name_t *zn)
{
kmem_cache_free(zap_name_cache, zn);
if (zn->zn_normbuf_len == ZAP_MAXNAMELEN) {
kmem_cache_free(zap_name_cache, zn);
} else {
ASSERT3U(zn->zn_normbuf_len, ==, ZAP_MAXNAMELEN_NEW);
kmem_cache_free(zap_name_long_cache, zn);
}
}
static int
zap_name_init_str(zap_name_t *zn, const char *key, matchtype_t mt)
{
zap_t *zap = zn->zn_zap;
size_t key_len = strlen(key) + 1;
/* Make sure zn is allocated for longname if key is long */
IMPLY(key_len > ZAP_MAXNAMELEN,
zn->zn_normbuf_len == ZAP_MAXNAMELEN_NEW);
zn->zn_key_intlen = sizeof (*key);
zn->zn_key_orig = key;
zn->zn_key_orig_numints = strlen(zn->zn_key_orig) + 1;
zn->zn_key_orig_numints = key_len;
zn->zn_matchtype = mt;
zn->zn_normflags = zap->zap_normflags;
zn->zn_normbuf_len = ZAP_MAXNAMELEN;
/*
* If we're dealing with a case sensitive lookup on a mixed or
@@ -226,7 +264,7 @@ zap_name_init_str(zap_name_t *zn, const char *key, matchtype_t mt)
* what the hash is computed from.
*/
if (zap_normalize(zap, key, zn->zn_normbuf,
zap->zap_normflags) != 0)
zap->zap_normflags, zn->zn_normbuf_len) != 0)
return (SET_ERROR(ENOTSUP));
zn->zn_key_norm = zn->zn_normbuf;
zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1;
@@ -245,7 +283,7 @@ zap_name_init_str(zap_name_t *zn, const char *key, matchtype_t mt)
* what the matching is based on. (Not the hash!)
*/
if (zap_normalize(zap, key, zn->zn_normbuf,
zn->zn_normflags) != 0)
zn->zn_normflags, zn->zn_normbuf_len) != 0)
return (SET_ERROR(ENOTSUP));
zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1;
}
@@ -256,7 +294,8 @@ zap_name_init_str(zap_name_t *zn, const char *key, matchtype_t mt)
zap_name_t *
zap_name_alloc_str(zap_t *zap, const char *key, matchtype_t mt)
{
zap_name_t *zn = zap_name_alloc(zap);
size_t key_len = strlen(key) + 1;
zap_name_t *zn = zap_name_alloc(zap, (key_len > ZAP_MAXNAMELEN));
if (zap_name_init_str(zn, key, mt) != 0) {
zap_name_free(zn);
return (NULL);
@@ -491,7 +530,7 @@ mzap_open(dmu_buf_t *db)
zfs_btree_create_custom(&zap->zap_m.zap_tree, mze_compare,
mze_find_in_buf, sizeof (mzap_ent_t), 512);
zap_name_t *zn = zap_name_alloc(zap);
zap_name_t *zn = zap_name_alloc(zap, B_FALSE);
for (uint16_t i = 0; i < zap->zap_m.zap_num_chunks; i++) {
mzap_ent_phys_t *mze =
&zap_m_phys(zap)->mz_chunk[i];
@@ -698,7 +737,7 @@ mzap_upgrade(zap_t **zapp, const void *tag, dmu_tx_t *tx, zap_flags_t flags)
fzap_upgrade(zap, tx, flags);
zap_name_t *zn = zap_name_alloc(zap);
zap_name_t *zn = zap_name_alloc(zap, B_FALSE);
for (int i = 0; i < nchunks; i++) {
mzap_ent_phys_t *mze = &mzp->mz_chunk[i];
if (mze->mze_name[0] == 0)
@@ -1625,21 +1664,38 @@ zap_remove_uint64_by_dnode(dnode_t *dn, const uint64_t *key, int key_numints,
}
static zap_attribute_t *
zap_attribute_alloc_impl(boolean_t longname)
{
zap_attribute_t *za;
za = kmem_cache_alloc((longname)? zap_attr_long_cache : zap_attr_cache,
KM_SLEEP);
za->za_name_len = (longname)? ZAP_MAXNAMELEN_NEW : ZAP_MAXNAMELEN;
return (za);
}
zap_attribute_t *
zap_attribute_alloc(void)
{
uint32_t len = ZAP_MAXNAMELEN;
zap_attribute_t *za;
return (zap_attribute_alloc_impl(B_FALSE));
}
za = kmem_cache_alloc(zap_attr_cache, KM_SLEEP);
za->za_name_len = len;
return (za);
zap_attribute_t *
zap_attribute_long_alloc(void)
{
return (zap_attribute_alloc_impl(B_TRUE));
}
void
zap_attribute_free(zap_attribute_t *za)
{
kmem_cache_free(zap_attr_cache, za);
if (za->za_name_len == ZAP_MAXNAMELEN) {
kmem_cache_free(zap_attr_cache, za);
} else {
ASSERT3U(za->za_name_len, ==, ZAP_MAXNAMELEN_NEW);
kmem_cache_free(zap_attr_long_cache, za);
}
}
/*
+35
View File
@@ -2594,6 +2594,41 @@ zfs_prop_set_special(const char *dsname, zprop_source_t source,
}
break;
}
case ZFS_PROP_LONGNAME:
{
zfsvfs_t *zfsvfs;
/*
* Ignore the checks if the property is being applied as part of
* 'zfs receive'. Because, we already check if the local pool
* has SPA_FEATURE_LONGNAME enabled in dmu_recv_begin_check().
*/
if (source == ZPROP_SRC_RECEIVED) {
cmn_err(CE_NOTE, "Skipping ZFS_PROP_LONGNAME checks "
"for dsname=%s\n", dsname);
err = -1;
break;
}
if ((err = zfsvfs_hold(dsname, FTAG, &zfsvfs, B_FALSE)) != 0) {
cmn_err(CE_WARN, "%s:%d Failed to hold for dsname=%s "
"err=%d\n", __FILE__, __LINE__, dsname, err);
break;
}
if (!spa_feature_is_enabled(zfsvfs->z_os->os_spa,
SPA_FEATURE_LONGNAME)) {
err = ENOTSUP;
} else {
/*
* Set err to -1 to force the zfs_set_prop_nvlist code
* down the default path to set the value in the nvlist.
*/
err = -1;
}
zfsvfs_rele(zfsvfs, FTAG);
break;
}
default:
err = -1;
}
+6 -2
View File
@@ -178,6 +178,7 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
dmu_buf_t *prevdb = NULL;
dmu_buf_t *sa_db = NULL;
char *path = buf + len - 1;
char *comp_buf;
int error;
*path = '\0';
@@ -193,9 +194,10 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
return (error);
}
comp_buf = kmem_alloc(ZAP_MAXNAMELEN_NEW + 2, KM_SLEEP);
for (;;) {
uint64_t pobj = 0;
char component[MAXNAMELEN + 2];
char *component = comp_buf;
size_t complen;
int is_xattrdir = 0;
@@ -219,7 +221,8 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
strcpy(component + 1, "<xattrdir>");
} else {
error = zap_value_search(osp, pobj, obj,
ZFS_DIRENT_OBJ(-1ULL), component + 1);
ZFS_DIRENT_OBJ(-1ULL), component + 1,
ZAP_MAXNAMELEN_NEW);
if (error != 0)
break;
}
@@ -250,6 +253,7 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
if (error == 0)
(void) memmove(buf, path, buf + len - path);
kmem_free(comp_buf, ZAP_MAXNAMELEN_NEW +2);
return (error);
}