Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
snajpa committed Dec 4, 2024
1 parent 5e834df commit 4f09ecc
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -5190,25 +5190,28 @@ zfs_check_attrname(const char *name)
}

static char *
zfs_attrname_maybe_rename(char *name)
zfs_dup_attrname_maybe_rename(const char *name)
{
char *ret = name;
char *ret;
size_t len = strlen(name);

if (zfs_xattr_compat)
return (ret);

if (ZFS_XA_NS_PREFIX_FORBIDDEN(name)) {
ret = kmem_alloc(strlen(name) + 6, KM_SLEEP);
snprintf(ret, strlen(name), "user.%s", name);
ret = kmem_alloc(len + 6, KM_SLEEP);
snprintf(ret, len + 5, "user.%s", name);
}

ret = kmem_alloc(len + 1, KM_SLEEP);
memcpy(ret, name, len);
return (ret);
}

static void
zfs_attrname_maybe_free(char *name, char *orig)
zfs_dup_attrname_free(char *name, const char *orig)
{
if (name != orig)
kmem_free(name, strlen(name));
kmem_free(name, strlen(name));
}

/*
Expand Down Expand Up @@ -5413,16 +5416,16 @@ zfs_getextattr(struct vop_getextattr_args *ap)
if (error != 0)
return (SET_ERROR(error));

maybe_renamed = zfs_attrname_maybe_rename(origname);
maybe_renamed = zfs_dup_attrname_maybe_rename(origname);

error = zfs_check_attrname(maybe_renamed);
if (error != 0) {
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}

if ((error = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0) {
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}
error = ENOENT;
Expand All @@ -5442,7 +5445,7 @@ zfs_getextattr(struct vop_getextattr_args *ap)
zfs_exit(zfsvfs, FTAG);
if (error == ENOENT)
error = SET_ERROR(ENOATTR);
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}

Expand Down Expand Up @@ -5564,14 +5567,14 @@ zfs_deleteextattr(struct vop_deleteextattr_args *ap)
if (error != 0)
return (SET_ERROR(error));

maybe_renamed = zfs_attrname_maybe_rename(origname);
maybe_renamed = zfs_dup_attrname_maybe_rename(origname);
error = zfs_check_attrname(maybe_renamed);
if (error != 0) {
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}
if ((error = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0) {
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}
rw_enter(&zp->z_xattr_lock, RW_WRITER);
Expand All @@ -5591,7 +5594,7 @@ zfs_deleteextattr(struct vop_deleteextattr_args *ap)
zfs_exit(zfsvfs, FTAG);
if (error == ENOENT)
error = SET_ERROR(ENOATTR);
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}

Expand Down Expand Up @@ -5761,15 +5764,15 @@ zfs_setextattr(struct vop_setextattr_args *ap)
if (error != 0)
return (SET_ERROR(error));

maybe_renamed = zfs_attrname_maybe_rename(origname);
maybe_renamed = zfs_dup_attrname_maybe_rename(origname);
error = zfs_check_attrname(maybe_renamed);
if (error != 0) {
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}

if ((error = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0) {
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}
rw_enter(&zp->z_xattr_lock, RW_WRITER);
Expand All @@ -5778,7 +5781,7 @@ zfs_setextattr(struct vop_setextattr_args *ap)

rw_exit(&zp->z_xattr_lock);
zfs_exit(zfsvfs, FTAG);
zfs_attrname_maybe_free(maybe_renamed, origname);
zfs_dup_attrname_free(maybe_renamed, origname);
return (error);
}

Expand Down

0 comments on commit 4f09ecc

Please sign in to comment.