History

switch file_open_root() to struct path

... and provide file_open_root_mnt(), using the root of given mount.

Al Viro committed 5 years ago

Commit ffb37ca1 parent 4f0ed9311 files · +29 −16Browse files

Unified · Split

11 files
  1. Documentation/filesystems/porting.rst +9 −0
  2. arch/um/drivers/mconsole_kern.c +1 −1
  3. fs/coredump.c +2 −2
  4. fs/fhandle.c +1 −1
  5. fs/internal.h +1 −1
  6. fs/kernel_read_file.c +1 −1
  7. fs/namei.c +3 −5
  8. fs/open.c +2 −2
  9. fs/proc/proc_sysctl.c +1 −1
  10. include/linux/fs.h +7 −1
  11. kernel/usermode_driver.c +1 −1
Documentation/filesystems/porting.rst+9−0
@@ -890,3 +890,12 @@ been called or returned with non -EIOCBQUEUED code. · 889 unmodified lines
890890
891891 mnt_want_write_file() can now only be paired with mnt_drop_write_file(),
892892 whereas previously it could be paired with mnt_drop_write() as well.
893+
894+---
895+
896+**mandatory**
897+
898+Calling conventions for file_open_root() changed; now it takes struct path *
899+instead of passing mount and dentry separately. For callers that used to
900+pass <mnt, mnt->mnt_root> pair (i.e. the root of given mount), a new helper
901+is provided - file_open_root_mnt(). In-tree users adjusted.
arch/um/drivers/mconsole_kern.c+1−1
@@ -140,7 +140,7 @@ void mconsole_proc(struct mc_request *req) · 139 unmodified lines
140140 mconsole_reply(req, "Proc not available", 1, 0);
141141 goto out;
142142 }
143− file = file_open_root(mnt->mnt_root, mnt, ptr, O_RDONLY, 0);
143+ file = file_open_root_mnt(mnt, ptr, O_RDONLY, 0);
144144 if (IS_ERR(file)) {
145145 mconsole_reply(req, "Failed to open file", 1, 0);
146146 printk(KERN_ERR "open /proc/%s: %ld\n", ptr, PTR_ERR(file));
fs/coredump.c+2−2
@@ -755,8 +755,8 @@ void do_coredump(const kernel_siginfo_t *siginfo) · 754 unmodified lines
755755 task_lock(&init_task);
756756 get_fs_root(init_task.fs, &root);
757757 task_unlock(&init_task);
758− cprm.file = file_open_root(root.dentry, root.mnt,
759− cn.corename, open_flags, 0600);
758+ cprm.file = file_open_root(&root, cn.corename,
759+ open_flags, 0600);
760760 path_put(&root);
761761 } else {
762762 cprm.file = filp_open(cn.corename, open_flags, 0600);
fs/fhandle.c+1−1
@@ -229,7 +229,7 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh, · 228 unmodified lines
229229 path_put(&path);
230230 return fd;
231231 }
232− file = file_open_root(path.dentry, path.mnt, "", open_flag, 0);
232+ file = file_open_root(&path, "", open_flag, 0);
233233 if (IS_ERR(file)) {
234234 put_unused_fd(fd);
235235 retval = PTR_ERR(file);
fs/internal.h+1−1
@@ -129,7 +129,7 @@ struct open_flags { · 128 unmodified lines
129129 };
130130 extern struct file *do_filp_open(int dfd, struct filename *pathname,
131131 const struct open_flags *op);
132−extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
132+extern struct file *do_file_open_root(const struct path *,
133133 const char *, const struct open_flags *);
134134 extern struct open_how build_open_how(int flags, umode_t mode);
135135 extern int build_open_flags(const struct open_how *how, struct open_flags *op);
fs/kernel_read_file.c+1−1
@@ -160,7 +160,7 @@ int kernel_read_file_from_path_initns(const char *path, loff_t offset, · 159 unmodified lines
160160 get_fs_root(init_task.fs, &root);
161161 task_unlock(&init_task);
162162
163− file = file_open_root(root.dentry, root.mnt, path, O_RDONLY, 0);
163+ file = file_open_root(&root, path, O_RDONLY, 0);
164164 path_put(&root);
165165 if (IS_ERR(file))
166166 return PTR_ERR(file);
fs/namei.c+3−5
@@ -3533,7 +3533,7 @@ struct file *do_filp_open(int dfd, struct filename *pathname, · 3532 unmodified lines
35333533 return filp;
35343534 }
35353535
3536−struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,
3536+struct file *do_file_open_root(const struct path *root,
35373537 const char *name, const struct open_flags *op)
35383538 {
35393539 struct nameidata nd;
@@ -3541,16 +3541,14 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, · 1 unmodified line
35413541 struct filename *filename;
35423542 int flags = op->lookup_flags | LOOKUP_ROOT;
35433543
3544− nd.root.mnt = mnt;
3545− nd.root.dentry = dentry;
3546−
3547− if (d_is_symlink(dentry) && op->intent & LOOKUP_OPEN)
3544+ if (d_is_symlink(root->dentry) && op->intent & LOOKUP_OPEN)
35483545 return ERR_PTR(-ELOOP);
35493546
35503547 filename = getname_kernel(name);
35513548 if (IS_ERR(filename))
35523549 return ERR_CAST(filename);
35533550
3551+ nd.root = *root;
35543552 set_nameidata(&nd, -1, filename);
35553553 file = path_openat(&nd, op, flags | LOOKUP_RCU);
35563554 if (unlikely(file == ERR_PTR(-ECHILD)))
fs/open.c+2−2
@@ -1156,7 +1156,7 @@ struct file *filp_open(const char *filename, int flags, umode_t mode) · 1155 unmodified lines
11561156 }
11571157 EXPORT_SYMBOL(filp_open);
11581158
1159−struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt,
1159+struct file *file_open_root(const struct path *root,
11601160 const char *filename, int flags, umode_t mode)
11611161 {
11621162 struct open_flags op;
@@ -1164,7 +1164,7 @@ struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt, · 1 unmodified line
11641164 int err = build_open_flags(&how, &op);
11651165 if (err)
11661166 return ERR_PTR(err);
1167− return do_file_open_root(dentry, mnt, filename, &op);
1167+ return do_file_open_root(root, filename, &op);
11681168 }
11691169 EXPORT_SYMBOL(file_open_root);
11701170
fs/proc/proc_sysctl.c+1−1
@@ -1806,7 +1806,7 @@ static int process_sysctl_arg(char *param, char *val, · 1805 unmodified lines
18061806 panic("%s: Failed to allocate path for %s\n", __func__, param);
18071807 strreplace(path, '.', '/');
18081808
1809− file = file_open_root((*proc_mnt)->mnt_root, *proc_mnt, path, O_WRONLY, 0);
1809+ file = file_open_root_mnt(*proc_mnt, path, O_WRONLY, 0);
18101810 if (IS_ERR(file)) {
18111811 err = PTR_ERR(file);
18121812 if (err == -ENOENT)
include/linux/fs.h+7−1
@@ -2632,8 +2632,14 @@ extern long do_sys_open(int dfd, const char __user *filename, int flags, · 2631 unmodified lines
26322632 umode_t mode);
26332633 extern struct file *file_open_name(struct filename *, int, umode_t);
26342634 extern struct file *filp_open(const char *, int, umode_t);
2635−extern struct file *file_open_root(struct dentry *, struct vfsmount *,
2635+extern struct file *file_open_root(const struct path *,
26362636 const char *, int, umode_t);
2637+static inline struct file *file_open_root_mnt(struct vfsmount *mnt,
2638+ const char *name, int flags, umode_t mode)
2639+{
2640+ return file_open_root(&(struct path){.mnt = mnt, .dentry = mnt->mnt_root},
2641+ name, flags, mode);
2642+}
26372643 extern struct file * dentry_open(const struct path *, int, const struct cred *);
26382644 extern struct file * open_with_fake_path(const struct path *, int,
26392645 struct inode*, const struct cred *);
kernel/usermode_driver.c+1−1
@@ -26,7 +26,7 @@ static struct vfsmount *blob_to_mnt(const void *data, size_t len, const char *na · 25 unmodified lines
2626 if (IS_ERR(mnt))
2727 return mnt;
2828
29− file = file_open_root(mnt->mnt_root, mnt, name, O_CREAT | O_WRONLY, 0700);
29+ file = file_open_root_mnt(mnt, name, O_CREAT | O_WRONLY, 0700);
3030 if (IS_ERR(file)) {
3131 mntput(mnt);
3232 return ERR_CAST(file);