Skip to content

Commit ae84250

Browse files
author
Al Viro
committed
Merge branches 'work.path' and 'work.mount' into work.f_path
3 parents cdc59a6 + 1b25dea + a797652 commit ae84250

File tree

36 files changed

+655
-704
lines changed

36 files changed

+655
-704
lines changed

fs/bpf_fs_kfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ __bpf_kfunc void bpf_put_file(struct file *file)
7979
* pathname in *buf*, including the NUL termination character. On error, a
8080
* negative integer is returned.
8181
*/
82-
__bpf_kfunc int bpf_path_d_path(struct path *path, char *buf, size_t buf__sz)
82+
__bpf_kfunc int bpf_path_d_path(const struct path *path, char *buf, size_t buf__sz)
8383
{
8484
int len;
8585
char *ret;

fs/configfs/symlink.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,28 @@ static int create_link(struct config_item *parent_item,
114114
}
115115

116116

117-
static int get_target(const char *symname, struct path *path,
118-
struct config_item **target, struct super_block *sb)
117+
static int get_target(const char *symname, struct config_item **target,
118+
struct super_block *sb)
119119
{
120+
struct path path __free(path_put) = {};
120121
int ret;
121122

122-
ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path);
123-
if (!ret) {
124-
if (path->dentry->d_sb == sb) {
125-
*target = configfs_get_config_item(path->dentry);
126-
if (!*target) {
127-
ret = -ENOENT;
128-
path_put(path);
129-
}
130-
} else {
131-
ret = -EPERM;
132-
path_put(path);
133-
}
134-
}
135-
136-
return ret;
123+
ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &path);
124+
if (ret)
125+
return ret;
126+
if (path.dentry->d_sb != sb)
127+
return -EPERM;
128+
*target = configfs_get_config_item(path.dentry);
129+
if (!*target)
130+
return -ENOENT;
131+
return 0;
137132
}
138133

139134

140135
int configfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
141136
struct dentry *dentry, const char *symname)
142137
{
143138
int ret;
144-
struct path path;
145139
struct configfs_dirent *sd;
146140
struct config_item *parent_item;
147141
struct config_item *target_item = NULL;
@@ -188,7 +182,7 @@ int configfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
188182
* AV, a thoroughly annoyed bastard.
189183
*/
190184
inode_unlock(dir);
191-
ret = get_target(symname, &path, &target_item, dentry->d_sb);
185+
ret = get_target(symname, &target_item, dentry->d_sb);
192186
inode_lock(dir);
193187
if (ret)
194188
goto out_put;
@@ -210,7 +204,6 @@ int configfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
210204
}
211205

212206
config_item_put(target_item);
213-
path_put(&path);
214207

215208
out_put:
216209
config_item_put(parent_item);

fs/dcache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ struct check_mount {
13901390
unsigned int mounted;
13911391
};
13921392

1393+
/* locks: mount_locked_reader && dentry->d_lock */
13931394
static enum d_walk_ret path_check_mount(void *data, struct dentry *dentry)
13941395
{
13951396
struct check_mount *info = data;
@@ -1416,9 +1417,8 @@ int path_has_submounts(const struct path *parent)
14161417
{
14171418
struct check_mount data = { .mnt = parent->mnt, .mounted = 0 };
14181419

1419-
read_seqlock_excl(&mount_lock);
1420+
guard(mount_locked_reader)();
14201421
d_walk(parent->dentry, &data, path_check_mount);
1421-
read_sequnlock_excl(&mount_lock);
14221422

14231423
return data.mounted;
14241424
}

fs/ecryptfs/dentry.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ static int ecryptfs_d_revalidate(struct inode *dir, const struct qstr *name,
5959
return rc;
6060
}
6161

62-
struct kmem_cache *ecryptfs_dentry_info_cache;
63-
64-
static void ecryptfs_dentry_free_rcu(struct rcu_head *head)
65-
{
66-
kmem_cache_free(ecryptfs_dentry_info_cache,
67-
container_of(head, struct ecryptfs_dentry_info, rcu));
68-
}
69-
7062
/**
7163
* ecryptfs_d_release
7264
* @dentry: The ecryptfs dentry
@@ -75,11 +67,7 @@ static void ecryptfs_dentry_free_rcu(struct rcu_head *head)
7567
*/
7668
static void ecryptfs_d_release(struct dentry *dentry)
7769
{
78-
struct ecryptfs_dentry_info *p = dentry->d_fsdata;
79-
if (p) {
80-
path_put(&p->lower_path);
81-
call_rcu(&p->rcu, ecryptfs_dentry_free_rcu);
82-
}
70+
dput(dentry->d_fsdata);
8371
}
8472

8573
const struct dentry_operations ecryptfs_dops = {

fs/ecryptfs/ecryptfs_kernel.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,6 @@ struct ecryptfs_inode_info {
258258
struct ecryptfs_crypt_stat crypt_stat;
259259
};
260260

261-
/* dentry private data. Each dentry must keep track of a lower
262-
* vfsmount too. */
263-
struct ecryptfs_dentry_info {
264-
struct path lower_path;
265-
struct rcu_head rcu;
266-
};
267-
268261
/**
269262
* ecryptfs_global_auth_tok - A key used to encrypt all new files under the mountpoint
270263
* @flags: Status flags
@@ -348,6 +341,7 @@ struct ecryptfs_mount_crypt_stat {
348341
/* superblock private data. */
349342
struct ecryptfs_sb_info {
350343
struct super_block *wsi_sb;
344+
struct vfsmount *lower_mnt;
351345
struct ecryptfs_mount_crypt_stat mount_crypt_stat;
352346
};
353347

@@ -494,22 +488,25 @@ ecryptfs_set_superblock_lower(struct super_block *sb,
494488
}
495489

496490
static inline void
497-
ecryptfs_set_dentry_private(struct dentry *dentry,
498-
struct ecryptfs_dentry_info *dentry_info)
491+
ecryptfs_set_dentry_lower(struct dentry *dentry,
492+
struct dentry *lower_dentry)
499493
{
500-
dentry->d_fsdata = dentry_info;
494+
dentry->d_fsdata = lower_dentry;
501495
}
502496

503497
static inline struct dentry *
504498
ecryptfs_dentry_to_lower(struct dentry *dentry)
505499
{
506-
return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
500+
return dentry->d_fsdata;
507501
}
508502

509-
static inline const struct path *
510-
ecryptfs_dentry_to_lower_path(struct dentry *dentry)
503+
static inline struct path
504+
ecryptfs_lower_path(struct dentry *dentry)
511505
{
512-
return &((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path;
506+
return (struct path){
507+
.mnt = ecryptfs_superblock_to_private(dentry->d_sb)->lower_mnt,
508+
.dentry = ecryptfs_dentry_to_lower(dentry)
509+
};
513510
}
514511

515512
#define ecryptfs_printk(type, fmt, arg...) \
@@ -532,7 +529,6 @@ extern unsigned int ecryptfs_number_of_users;
532529

533530
extern struct kmem_cache *ecryptfs_auth_tok_list_item_cache;
534531
extern struct kmem_cache *ecryptfs_file_info_cache;
535-
extern struct kmem_cache *ecryptfs_dentry_info_cache;
536532
extern struct kmem_cache *ecryptfs_inode_info_cache;
537533
extern struct kmem_cache *ecryptfs_sb_info_cache;
538534
extern struct kmem_cache *ecryptfs_header_cache;
@@ -557,7 +553,6 @@ int ecryptfs_encrypt_and_encode_filename(
557553
size_t *encoded_name_size,
558554
struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
559555
const char *name, size_t name_size);
560-
struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry);
561556
void ecryptfs_dump_hex(char *data, int bytes);
562557
int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
563558
int sg_size);

fs/ecryptfs/file.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
3333
struct iov_iter *to)
3434
{
3535
ssize_t rc;
36-
const struct path *path;
3736
struct file *file = iocb->ki_filp;
3837

3938
rc = generic_file_read_iter(iocb, to);
4039
if (rc >= 0) {
41-
path = ecryptfs_dentry_to_lower_path(file->f_path.dentry);
42-
touch_atime(path);
40+
struct path path = ecryptfs_lower_path(file->f_path.dentry);
41+
touch_atime(&path);
4342
}
4443
return rc;
4544
}
@@ -59,12 +58,11 @@ static ssize_t ecryptfs_splice_read_update_atime(struct file *in, loff_t *ppos,
5958
size_t len, unsigned int flags)
6059
{
6160
ssize_t rc;
62-
const struct path *path;
6361

6462
rc = filemap_splice_read(in, ppos, pipe, len, flags);
6563
if (rc >= 0) {
66-
path = ecryptfs_dentry_to_lower_path(in->f_path.dentry);
67-
touch_atime(path);
64+
struct path path = ecryptfs_lower_path(in->f_path.dentry);
65+
touch_atime(&path);
6866
}
6967
return rc;
7068
}
@@ -283,6 +281,7 @@ static int ecryptfs_dir_open(struct inode *inode, struct file *file)
283281
* ecryptfs_lookup() */
284282
struct ecryptfs_file_info *file_info;
285283
struct file *lower_file;
284+
struct path path;
286285

287286
/* Released in ecryptfs_release or end of function if failure */
288287
file_info = kmem_cache_zalloc(ecryptfs_file_info_cache, GFP_KERNEL);
@@ -292,8 +291,8 @@ static int ecryptfs_dir_open(struct inode *inode, struct file *file)
292291
"Error attempting to allocate memory\n");
293292
return -ENOMEM;
294293
}
295-
lower_file = dentry_open(ecryptfs_dentry_to_lower_path(ecryptfs_dentry),
296-
file->f_flags, current_cred());
294+
path = ecryptfs_lower_path(ecryptfs_dentry);
295+
lower_file = dentry_open(&path, file->f_flags, current_cred());
297296
if (IS_ERR(lower_file)) {
298297
printk(KERN_ERR "%s: Error attempting to initialize "
299298
"the lower file for the dentry with name "

fs/ecryptfs/inode.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,15 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
327327
static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
328328
struct dentry *lower_dentry)
329329
{
330-
const struct path *path = ecryptfs_dentry_to_lower_path(dentry->d_parent);
330+
struct dentry *lower_parent = ecryptfs_dentry_to_lower(dentry->d_parent);
331331
struct inode *inode, *lower_inode;
332-
struct ecryptfs_dentry_info *dentry_info;
333332
int rc = 0;
334333

335-
dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
336-
if (!dentry_info) {
337-
dput(lower_dentry);
338-
return ERR_PTR(-ENOMEM);
339-
}
340-
341334
fsstack_copy_attr_atime(d_inode(dentry->d_parent),
342-
d_inode(path->dentry));
335+
d_inode(lower_parent));
343336
BUG_ON(!d_count(lower_dentry));
344337

345-
ecryptfs_set_dentry_private(dentry, dentry_info);
346-
dentry_info->lower_path.mnt = mntget(path->mnt);
347-
dentry_info->lower_path.dentry = lower_dentry;
338+
ecryptfs_set_dentry_lower(dentry, lower_dentry);
348339

349340
/*
350341
* negative dentry can go positive under us here - its parent is not
@@ -1022,10 +1013,10 @@ static int ecryptfs_getattr(struct mnt_idmap *idmap,
10221013
{
10231014
struct dentry *dentry = path->dentry;
10241015
struct kstat lower_stat;
1016+
struct path lower_path = ecryptfs_lower_path(dentry);
10251017
int rc;
10261018

1027-
rc = vfs_getattr_nosec(ecryptfs_dentry_to_lower_path(dentry),
1028-
&lower_stat, request_mask, flags);
1019+
rc = vfs_getattr_nosec(&lower_path, &lower_stat, request_mask, flags);
10291020
if (!rc) {
10301021
fsstack_copy_attr_all(d_inode(dentry),
10311022
ecryptfs_inode_to_lower(d_inode(dentry)));

fs/ecryptfs/main.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ static int ecryptfs_init_lower_file(struct dentry *dentry,
106106
struct file **lower_file)
107107
{
108108
const struct cred *cred = current_cred();
109-
const struct path *path = ecryptfs_dentry_to_lower_path(dentry);
109+
struct path path = ecryptfs_lower_path(dentry);
110110
int rc;
111111

112-
rc = ecryptfs_privileged_open(lower_file, path->dentry, path->mnt,
113-
cred);
112+
rc = ecryptfs_privileged_open(lower_file, path.dentry, path.mnt, cred);
114113
if (rc) {
115114
printk(KERN_ERR "Error opening lower file "
116115
"for lower_dentry [0x%p] and lower_mnt [0x%p]; "
117-
"rc = [%d]\n", path->dentry, path->mnt, rc);
116+
"rc = [%d]\n", path.dentry, path.mnt, rc);
118117
(*lower_file) = NULL;
119118
}
120119
return rc;
@@ -437,7 +436,6 @@ static int ecryptfs_get_tree(struct fs_context *fc)
437436
struct ecryptfs_fs_context *ctx = fc->fs_private;
438437
struct ecryptfs_sb_info *sbi = fc->s_fs_info;
439438
struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
440-
struct ecryptfs_dentry_info *root_info;
441439
const char *err = "Getting sb failed";
442440
struct inode *inode;
443441
struct path path;
@@ -543,14 +541,8 @@ static int ecryptfs_get_tree(struct fs_context *fc)
543541
goto out_free;
544542
}
545543

546-
rc = -ENOMEM;
547-
root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
548-
if (!root_info)
549-
goto out_free;
550-
551-
/* ->kill_sb() will take care of root_info */
552-
ecryptfs_set_dentry_private(s->s_root, root_info);
553-
root_info->lower_path = path;
544+
ecryptfs_set_dentry_lower(s->s_root, path.dentry);
545+
ecryptfs_superblock_to_private(s)->lower_mnt = path.mnt;
554546

555547
s->s_flags |= SB_ACTIVE;
556548
fc->root = dget(s->s_root);
@@ -580,6 +572,7 @@ static void ecryptfs_kill_block_super(struct super_block *sb)
580572
kill_anon_super(sb);
581573
if (!sb_info)
582574
return;
575+
mntput(sb_info->lower_mnt);
583576
ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat);
584577
kmem_cache_free(ecryptfs_sb_info_cache, sb_info);
585578
}
@@ -667,11 +660,6 @@ static struct ecryptfs_cache_info {
667660
.name = "ecryptfs_file_cache",
668661
.size = sizeof(struct ecryptfs_file_info),
669662
},
670-
{
671-
.cache = &ecryptfs_dentry_info_cache,
672-
.name = "ecryptfs_dentry_info_cache",
673-
.size = sizeof(struct ecryptfs_dentry_info),
674-
},
675663
{
676664
.cache = &ecryptfs_inode_info_cache,
677665
.name = "ecryptfs_inode_cache",

fs/file_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct backing_file {
5454

5555
#define backing_file(f) container_of(f, struct backing_file, file)
5656

57-
struct path *backing_file_user_path(const struct file *f)
57+
const struct path *backing_file_user_path(const struct file *f)
5858
{
5959
return &backing_file(f)->user_path;
6060
}

fs/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern int finish_clean_context(struct fs_context *fc);
5353
* namei.c
5454
*/
5555
extern int filename_lookup(int dfd, struct filename *name, unsigned flags,
56-
struct path *path, struct path *root);
56+
struct path *path, const struct path *root);
5757
int do_rmdir(int dfd, struct filename *name);
5858
int do_unlinkat(int dfd, struct filename *name);
5959
int may_linkat(struct mnt_idmap *idmap, const struct path *link);
@@ -84,9 +84,9 @@ void mnt_put_write_access_file(struct file *file);
8484
extern void dissolve_on_fput(struct vfsmount *);
8585
extern bool may_mount(void);
8686

87-
int path_mount(const char *dev_name, struct path *path,
87+
int path_mount(const char *dev_name, const struct path *path,
8888
const char *type_page, unsigned long flags, void *data_page);
89-
int path_umount(struct path *path, int flags);
89+
int path_umount(const struct path *path, int flags);
9090

9191
int show_path(struct seq_file *m, struct dentry *root);
9292

0 commit comments

Comments
 (0)