Skip to content

Commit dbc9d2b

Browse files
committed
btrfs: use struct qstr for subvolume ioctl helpers
We pass name and length of subvolumes separately to the related functions, while this can be a struct qstr which is otherwise used for dentry interfaces. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 987f437 commit dbc9d2b

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

fs/btrfs/ioctl.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -894,22 +894,21 @@ static inline int btrfs_may_create(struct mnt_idmap *idmap,
894894
*/
895895
static noinline int btrfs_mksubvol(const struct path *parent,
896896
struct mnt_idmap *idmap,
897-
const char *name, int namelen,
898-
struct btrfs_root *snap_src,
897+
struct qstr *qname, struct btrfs_root *snap_src,
899898
bool readonly,
900899
struct btrfs_qgroup_inherit *inherit)
901900
{
902901
struct inode *dir = d_inode(parent->dentry);
903902
struct btrfs_fs_info *fs_info = inode_to_fs_info(dir);
904903
struct dentry *dentry;
905-
struct fscrypt_str name_str = FSTR_INIT((char *)name, namelen);
904+
struct fscrypt_str name_str = FSTR_INIT((char *)qname->name, qname->len);
906905
int ret;
907906

908907
ret = down_write_killable_nested(&dir->i_rwsem, I_MUTEX_PARENT);
909908
if (ret == -EINTR)
910909
return ret;
911910

912-
dentry = lookup_one(idmap, &QSTR_LEN(name, namelen), parent->dentry);
911+
dentry = lookup_one(idmap, qname, parent->dentry);
913912
ret = PTR_ERR(dentry);
914913
if (IS_ERR(dentry))
915914
goto out_unlock;
@@ -949,7 +948,7 @@ static noinline int btrfs_mksubvol(const struct path *parent,
949948

950949
static noinline int btrfs_mksnapshot(const struct path *parent,
951950
struct mnt_idmap *idmap,
952-
const char *name, int namelen,
951+
struct qstr *qname,
953952
struct btrfs_root *root,
954953
bool readonly,
955954
struct btrfs_qgroup_inherit *inherit)
@@ -976,8 +975,8 @@ static noinline int btrfs_mksnapshot(const struct path *parent,
976975

977976
btrfs_wait_ordered_extents(root, U64_MAX, NULL);
978977

979-
ret = btrfs_mksubvol(parent, idmap, name, namelen,
980-
root, readonly, inherit);
978+
ret = btrfs_mksubvol(parent, idmap, qname, root, readonly, inherit);
979+
981980
atomic_dec(&root->snapshot_force_cow);
982981
out:
983982
btrfs_drew_read_unlock(&root->snapshot_lock);
@@ -1187,8 +1186,8 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
11871186
bool readonly,
11881187
struct btrfs_qgroup_inherit *inherit)
11891188
{
1190-
int namelen;
11911189
int ret = 0;
1190+
struct qstr qname = QSTR_INIT(name, strlen(name));
11921191

11931192
if (!S_ISDIR(file_inode(file)->i_mode))
11941193
return -ENOTDIR;
@@ -1197,21 +1196,20 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
11971196
if (ret)
11981197
goto out;
11991198

1200-
namelen = strlen(name);
12011199
if (strchr(name, '/')) {
12021200
ret = -EINVAL;
12031201
goto out_drop_write;
12041202
}
12051203

1206-
if (name[0] == '.' &&
1207-
(namelen == 1 || (name[1] == '.' && namelen == 2))) {
1204+
if (qname.name[0] == '.' &&
1205+
(qname.len == 1 || (qname.name[1] == '.' && qname.len == 2))) {
12081206
ret = -EEXIST;
12091207
goto out_drop_write;
12101208
}
12111209

12121210
if (subvol) {
1213-
ret = btrfs_mksubvol(&file->f_path, idmap, name,
1214-
namelen, NULL, readonly, inherit);
1211+
ret = btrfs_mksubvol(&file->f_path, idmap, &qname, NULL,
1212+
readonly, inherit);
12151213
} else {
12161214
CLASS(fd, src)(fd);
12171215
struct inode *src_inode;
@@ -1241,8 +1239,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
12411239
*/
12421240
ret = -EINVAL;
12431241
} else {
1244-
ret = btrfs_mksnapshot(&file->f_path, idmap,
1245-
name, namelen,
1242+
ret = btrfs_mksnapshot(&file->f_path, idmap, &qname,
12461243
BTRFS_I(src_inode)->root,
12471244
readonly, inherit);
12481245
}

0 commit comments

Comments
 (0)