Commit 41d9884c44237cd66e2bdbc412028b29196b344c

Authored by Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull more vfs stuff from Al Viro:
 "O_TMPFILE ABI changes, Oleg's fput() series, misc cleanups, including
  making simple_lookup() usable for filesystems with non-NULL s_d_op,
  which allows us to get rid of quite a bit of ugliness"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  sunrpc: now we can just set ->s_d_op
  cgroup: we can use simple_lookup() now
  efivarfs: we can use simple_lookup() now
  make simple_lookup() usable for filesystems that set ->s_d_op
  configfs: don't open-code d_alloc_name()
  __rpc_lookup_create_exclusive: pass string instead of qstr
  rpc_create_*_dir: don't bother with qstr
  llist: llist_add() can use llist_add_batch()
  llist: fix/simplify llist_add() and llist_add_batch()
  fput: turn "list_head delayed_fput_list" into llist_head
  fs/file_table.c:fput(): add comment
  Safer ABI for O_TMPFILE

Showing 18 changed files Side-by-side Diff

arch/alpha/include/uapi/asm/fcntl.h
... ... @@ -32,7 +32,7 @@
32 32 #define O_SYNC (__O_SYNC|O_DSYNC)
33 33  
34 34 #define O_PATH 040000000
35   -#define O_TMPFILE 0100000000
  35 +#define __O_TMPFILE 0100000000
36 36  
37 37 #define F_GETLK 7
38 38 #define F_SETLK 8
arch/parisc/include/uapi/asm/fcntl.h
... ... @@ -20,7 +20,7 @@
20 20 #define O_INVISIBLE 004000000 /* invisible I/O, for DMAPI/XDSM */
21 21  
22 22 #define O_PATH 020000000
23   -#define O_TMPFILE 040000000
  23 +#define __O_TMPFILE 040000000
24 24  
25 25 #define F_GETLK64 8
26 26 #define F_SETLK64 9
arch/sparc/include/uapi/asm/fcntl.h
... ... @@ -35,7 +35,7 @@
35 35 #define O_SYNC (__O_SYNC|O_DSYNC)
36 36  
37 37 #define O_PATH 0x1000000
38   -#define O_TMPFILE 0x2000000
  38 +#define __O_TMPFILE 0x2000000
39 39  
40 40 #define F_GETOWN 5 /* for sockets. */
41 41 #define F_SETOWN 6 /* for sockets. */
... ... @@ -660,19 +660,15 @@
660 660 struct config_group *group)
661 661 {
662 662 int ret;
663   - struct qstr name;
664 663 struct configfs_dirent *sd;
665 664 /* We trust the caller holds a reference to parent */
666 665 struct dentry *child, *parent = parent_group->cg_item.ci_dentry;
667 666  
668 667 if (!group->cg_item.ci_name)
669 668 group->cg_item.ci_name = group->cg_item.ci_namebuf;
670   - name.name = group->cg_item.ci_name;
671   - name.len = strlen(name.name);
672   - name.hash = full_name_hash(name.name, name.len);
673 669  
674 670 ret = -ENOMEM;
675   - child = d_alloc(parent, &name);
  671 + child = d_alloc_name(parent, group->cg_item.ci_name);
676 672 if (child) {
677 673 d_add(child, NULL);
678 674  
... ... @@ -1650,7 +1646,6 @@
1650 1646 {
1651 1647 int err;
1652 1648 struct config_group *group = &subsys->su_group;
1653   - struct qstr name;
1654 1649 struct dentry *dentry;
1655 1650 struct dentry *root;
1656 1651 struct configfs_dirent *sd;
1657 1652  
... ... @@ -1667,12 +1662,8 @@
1667 1662  
1668 1663 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT);
1669 1664  
1670   - name.name = group->cg_item.ci_name;
1671   - name.len = strlen(name.name);
1672   - name.hash = full_name_hash(name.name, name.len);
1673   -
1674 1665 err = -ENOMEM;
1675   - dentry = d_alloc(root, &name);
  1666 + dentry = d_alloc_name(root, group->cg_item.ci_name);
1676 1667 if (dentry) {
1677 1668 d_add(dentry, NULL);
1678 1669  
... ... @@ -155,20 +155,8 @@
155 155 return 0;
156 156 };
157 157  
158   -/*
159   - * Handle negative dentry.
160   - */
161   -static struct dentry *efivarfs_lookup(struct inode *dir, struct dentry *dentry,
162   - unsigned int flags)
163   -{
164   - if (dentry->d_name.len > NAME_MAX)
165   - return ERR_PTR(-ENAMETOOLONG);
166   - d_add(dentry, NULL);
167   - return NULL;
168   -}
169   -
170 158 const struct inode_operations efivarfs_dir_inode_operations = {
171   - .lookup = efivarfs_lookup,
  159 + .lookup = simple_lookup,
172 160 .unlink = efivarfs_unlink,
173 161 .create = efivarfs_create,
174 162 };
... ... @@ -265,18 +265,15 @@
265 265 mntput(mnt);
266 266 }
267 267  
268   -static DEFINE_SPINLOCK(delayed_fput_lock);
269   -static LIST_HEAD(delayed_fput_list);
  268 +static LLIST_HEAD(delayed_fput_list);
270 269 static void delayed_fput(struct work_struct *unused)
271 270 {
272   - LIST_HEAD(head);
273   - spin_lock_irq(&delayed_fput_lock);
274   - list_splice_init(&delayed_fput_list, &head);
275   - spin_unlock_irq(&delayed_fput_lock);
276   - while (!list_empty(&head)) {
277   - struct file *f = list_first_entry(&head, struct file, f_u.fu_list);
278   - list_del_init(&f->f_u.fu_list);
279   - __fput(f);
  271 + struct llist_node *node = llist_del_all(&delayed_fput_list);
  272 + struct llist_node *next;
  273 +
  274 + for (; node; node = next) {
  275 + next = llist_next(node);
  276 + __fput(llist_entry(node, struct file, f_u.fu_llist));
280 277 }
281 278 }
282 279  
283 280  
284 281  
... ... @@ -306,18 +303,22 @@
306 303 {
307 304 if (atomic_long_dec_and_test(&file->f_count)) {
308 305 struct task_struct *task = current;
309   - unsigned long flags;
310 306  
311 307 file_sb_list_del(file);
312 308 if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
313 309 init_task_work(&file->f_u.fu_rcuhead, ____fput);
314 310 if (!task_work_add(task, &file->f_u.fu_rcuhead, true))
315 311 return;
  312 + /*
  313 + * After this task has run exit_task_work(),
  314 + * task_work_add() will fail. free_ipc_ns()->
  315 + * shm_destroy() can do this. Fall through to delayed
  316 + * fput to avoid leaking *file.
  317 + */
316 318 }
317   - spin_lock_irqsave(&delayed_fput_lock, flags);
318   - list_add(&file->f_u.fu_list, &delayed_fput_list);
319   - schedule_work(&delayed_fput_work);
320   - spin_unlock_irqrestore(&delayed_fput_lock, flags);
  319 +
  320 + if (llist_add(&file->f_u.fu_llist, &delayed_fput_list))
  321 + schedule_work(&delayed_fput_work);
321 322 }
322 323 }
323 324  
... ... @@ -61,7 +61,8 @@
61 61  
62 62 if (dentry->d_name.len > NAME_MAX)
63 63 return ERR_PTR(-ENAMETOOLONG);
64   - d_set_d_op(dentry, &simple_dentry_operations);
  64 + if (!dentry->d_sb->s_d_op)
  65 + d_set_d_op(dentry, &simple_dentry_operations);
65 66 d_add(dentry, NULL);
66 67 return NULL;
67 68 }
... ... @@ -2977,7 +2977,7 @@
2977 2977  
2978 2978 file->f_flags = op->open_flag;
2979 2979  
2980   - if (unlikely(file->f_flags & O_TMPFILE)) {
  2980 + if (unlikely(file->f_flags & __O_TMPFILE)) {
2981 2981 error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened);
2982 2982 goto out;
2983 2983 }
... ... @@ -840,8 +840,8 @@
840 840 if (flags & __O_SYNC)
841 841 flags |= O_DSYNC;
842 842  
843   - if (flags & O_TMPFILE) {
844   - if (!(flags & O_CREAT))
  843 + if (flags & __O_TMPFILE) {
  844 + if ((flags & O_TMPFILE_MASK) != O_TMPFILE)
845 845 return -EINVAL;
846 846 acc_mode = MAY_OPEN | ACC_MODE(flags);
847 847 } else if (flags & O_PATH) {
... ... @@ -10,6 +10,7 @@
10 10 #include <linux/stat.h>
11 11 #include <linux/cache.h>
12 12 #include <linux/list.h>
  13 +#include <linux/llist.h>
13 14 #include <linux/radix-tree.h>
14 15 #include <linux/rbtree.h>
15 16 #include <linux/init.h>
... ... @@ -768,6 +769,7 @@
768 769 */
769 770 union {
770 771 struct list_head fu_list;
  772 + struct llist_node fu_llist;
771 773 struct rcu_head fu_rcuhead;
772 774 } f_u;
773 775 struct path f_path;
include/linux/llist.h
... ... @@ -142,6 +142,9 @@
142 142 return node->next;
143 143 }
144 144  
  145 +extern bool llist_add_batch(struct llist_node *new_first,
  146 + struct llist_node *new_last,
  147 + struct llist_head *head);
145 148 /**
146 149 * llist_add - add a new entry
147 150 * @new: new entry to be added
... ... @@ -151,18 +154,7 @@
151 154 */
152 155 static inline bool llist_add(struct llist_node *new, struct llist_head *head)
153 156 {
154   - struct llist_node *entry, *old_entry;
155   -
156   - entry = head->first;
157   - for (;;) {
158   - old_entry = entry;
159   - new->next = entry;
160   - entry = cmpxchg(&head->first, old_entry, new);
161   - if (entry == old_entry)
162   - break;
163   - }
164   -
165   - return old_entry == NULL;
  157 + return llist_add_batch(new, new, head);
166 158 }
167 159  
168 160 /**
... ... @@ -178,9 +170,6 @@
178 170 return xchg(&head->first, NULL);
179 171 }
180 172  
181   -extern bool llist_add_batch(struct llist_node *new_first,
182   - struct llist_node *new_last,
183   - struct llist_head *head);
184 173 extern struct llist_node *llist_del_first(struct llist_head *head);
185 174  
186 175 #endif /* LLIST_H */
include/linux/sunrpc/rpc_pipe_fs.h
... ... @@ -73,12 +73,12 @@
73 73 extern int rpc_queue_upcall(struct rpc_pipe *, struct rpc_pipe_msg *);
74 74  
75 75 struct rpc_clnt;
76   -extern struct dentry *rpc_create_client_dir(struct dentry *, struct qstr *, struct rpc_clnt *);
  76 +extern struct dentry *rpc_create_client_dir(struct dentry *, const char *, struct rpc_clnt *);
77 77 extern int rpc_remove_client_dir(struct dentry *);
78 78  
79 79 struct cache_detail;
80 80 extern struct dentry *rpc_create_cache_dir(struct dentry *,
81   - struct qstr *,
  81 + const char *,
82 82 umode_t umode,
83 83 struct cache_detail *);
84 84 extern void rpc_remove_cache_dir(struct dentry *);
include/uapi/asm-generic/fcntl.h
... ... @@ -84,9 +84,13 @@
84 84 #define O_PATH 010000000
85 85 #endif
86 86  
87   -#ifndef O_TMPFILE
88   -#define O_TMPFILE 020000000
  87 +#ifndef __O_TMPFILE
  88 +#define __O_TMPFILE 020000000
89 89 #endif
  90 +
  91 +/* a horrid kludge trying to make sure that this will fail on old kernels */
  92 +#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY | O_RDWR)
  93 +#define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT | O_ACCMODE)
90 94  
91 95 #ifndef O_NDELAY
92 96 #define O_NDELAY O_NONBLOCK
... ... @@ -802,7 +802,6 @@
802 802 */
803 803  
804 804 static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
805   -static struct dentry *cgroup_lookup(struct inode *, struct dentry *, unsigned int);
806 805 static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
807 806 static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files,
808 807 unsigned long subsys_mask);
... ... @@ -2642,7 +2641,7 @@
2642 2641 };
2643 2642  
2644 2643 static const struct inode_operations cgroup_dir_inode_operations = {
2645   - .lookup = cgroup_lookup,
  2644 + .lookup = simple_lookup,
2646 2645 .mkdir = cgroup_mkdir,
2647 2646 .rmdir = cgroup_rmdir,
2648 2647 .rename = cgroup_rename,
... ... @@ -2651,14 +2650,6 @@
2651 2650 .listxattr = cgroup_listxattr,
2652 2651 .removexattr = cgroup_removexattr,
2653 2652 };
2654   -
2655   -static struct dentry *cgroup_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
2656   -{
2657   - if (dentry->d_name.len > NAME_MAX)
2658   - return ERR_PTR(-ENAMETOOLONG);
2659   - d_add(dentry, NULL);
2660   - return NULL;
2661   -}
2662 2653  
2663 2654 /*
2664 2655 * Check if a file is a control file
... ... @@ -39,18 +39,13 @@
39 39 bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
40 40 struct llist_head *head)
41 41 {
42   - struct llist_node *entry, *old_entry;
  42 + struct llist_node *first;
43 43  
44   - entry = head->first;
45   - for (;;) {
46   - old_entry = entry;
47   - new_last->next = entry;
48   - entry = cmpxchg(&head->first, old_entry, new_first);
49   - if (entry == old_entry)
50   - break;
51   - }
  44 + do {
  45 + new_last->next = first = ACCESS_ONCE(head->first);
  46 + } while (cmpxchg(&head->first, first, new_first) != first);
52 47  
53   - return old_entry == NULL;
  48 + return !first;
54 49 }
55 50 EXPORT_SYMBOL_GPL(llist_add_batch);
56 51  
... ... @@ -1823,19 +1823,11 @@
1823 1823 const char *name, umode_t umode,
1824 1824 struct cache_detail *cd)
1825 1825 {
1826   - struct qstr q;
1827   - struct dentry *dir;
1828   - int ret = 0;
1829   -
1830   - q.name = name;
1831   - q.len = strlen(name);
1832   - q.hash = full_name_hash(q.name, q.len);
1833   - dir = rpc_create_cache_dir(parent, &q, umode, cd);
1834   - if (!IS_ERR(dir))
1835   - cd->u.pipefs.dir = dir;
1836   - else
1837   - ret = PTR_ERR(dir);
1838   - return ret;
  1826 + struct dentry *dir = rpc_create_cache_dir(parent, name, umode, cd);
  1827 + if (IS_ERR(dir))
  1828 + return PTR_ERR(dir);
  1829 + cd->u.pipefs.dir = dir;
  1830 + return 0;
1839 1831 }
1840 1832 EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs);
1841 1833  
... ... @@ -128,9 +128,7 @@
128 128 {
129 129 static uint32_t clntid;
130 130 char name[15];
131   - struct qstr q = { .name = name };
132 131 struct dentry *dir, *dentry;
133   - int error;
134 132  
135 133 dir = rpc_d_lookup_sb(sb, dir_name);
136 134 if (dir == NULL) {
137 135  
138 136  
... ... @@ -138,19 +136,17 @@
138 136 return dir;
139 137 }
140 138 for (;;) {
141   - q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
  139 + snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
142 140 name[sizeof(name) - 1] = '\0';
143   - q.hash = full_name_hash(q.name, q.len);
144   - dentry = rpc_create_client_dir(dir, &q, clnt);
  141 + dentry = rpc_create_client_dir(dir, name, clnt);
145 142 if (!IS_ERR(dentry))
146 143 break;
147   - error = PTR_ERR(dentry);
148   - if (error != -EEXIST) {
149   - printk(KERN_INFO "RPC: Couldn't create pipefs entry"
150   - " %s/%s, error %d\n",
151   - dir_name, name, error);
152   - break;
153   - }
  144 + if (dentry == ERR_PTR(-EEXIST))
  145 + continue;
  146 + printk(KERN_INFO "RPC: Couldn't create pipefs entry"
  147 + " %s/%s, error %ld\n",
  148 + dir_name, name, PTR_ERR(dentry));
  149 + break;
154 150 }
155 151 dput(dir);
156 152 return dentry;
net/sunrpc/rpc_pipe.c
... ... @@ -673,13 +673,12 @@
673 673 }
674 674  
675 675 static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent,
676   - struct qstr *name)
  676 + const char *name)
677 677 {
678   - struct dentry *dentry;
679   -
680   - dentry = d_lookup(parent, name);
  678 + struct qstr q = QSTR_INIT(name, strlen(name));
  679 + struct dentry *dentry = d_hash_and_lookup(parent, &q);
681 680 if (!dentry) {
682   - dentry = d_alloc(parent, name);
  681 + dentry = d_alloc(parent, &q);
683 682 if (!dentry)
684 683 return ERR_PTR(-ENOMEM);
685 684 }
... ... @@ -704,8 +703,7 @@
704 703 for (i = start; i < eof; i++) {
705 704 name.name = files[i].name;
706 705 name.len = strlen(files[i].name);
707   - name.hash = full_name_hash(name.name, name.len);
708   - dentry = d_lookup(parent, &name);
  706 + dentry = d_hash_and_lookup(parent, &name);
709 707  
710 708 if (dentry == NULL)
711 709 continue;
... ... @@ -747,12 +745,7 @@
747 745  
748 746 mutex_lock(&dir->i_mutex);
749 747 for (i = start; i < eof; i++) {
750   - struct qstr q;
751   -
752   - q.name = files[i].name;
753   - q.len = strlen(files[i].name);
754   - q.hash = full_name_hash(q.name, q.len);
755   - dentry = __rpc_lookup_create_exclusive(parent, &q);
  748 + dentry = __rpc_lookup_create_exclusive(parent, files[i].name);
756 749 err = PTR_ERR(dentry);
757 750 if (IS_ERR(dentry))
758 751 goto out_bad;
... ... @@ -785,7 +778,7 @@
785 778 }
786 779  
787 780 static struct dentry *rpc_mkdir_populate(struct dentry *parent,
788   - struct qstr *name, umode_t mode, void *private,
  781 + const char *name, umode_t mode, void *private,
789 782 int (*populate)(struct dentry *, void *), void *args_populate)
790 783 {
791 784 struct dentry *dentry;
... ... @@ -856,7 +849,6 @@
856 849 struct dentry *dentry;
857 850 struct inode *dir = parent->d_inode;
858 851 umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR;
859   - struct qstr q;
860 852 int err;
861 853  
862 854 if (pipe->ops->upcall == NULL)
863 855  
... ... @@ -864,12 +856,8 @@
864 856 if (pipe->ops->downcall == NULL)
865 857 umode &= ~S_IWUGO;
866 858  
867   - q.name = name;
868   - q.len = strlen(name);
869   - q.hash = full_name_hash(q.name, q.len),
870   -
871 859 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
872   - dentry = __rpc_lookup_create_exclusive(parent, &q);
  860 + dentry = __rpc_lookup_create_exclusive(parent, name);
873 861 if (IS_ERR(dentry))
874 862 goto out;
875 863 err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops,
... ... @@ -940,8 +928,8 @@
940 928  
941 929 /**
942 930 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
943   - * @dentry: dentry from the rpc_pipefs root to the new directory
944   - * @name: &struct qstr for the name
  931 + * @dentry: the parent of new directory
  932 + * @name: the name of new directory
945 933 * @rpc_client: rpc client to associate with this directory
946 934 *
947 935 * This creates a directory at the given @path associated with
... ... @@ -950,7 +938,7 @@
950 938 * later be created using rpc_mkpipe().
951 939 */
952 940 struct dentry *rpc_create_client_dir(struct dentry *dentry,
953   - struct qstr *name,
  941 + const char *name,
954 942 struct rpc_clnt *rpc_client)
955 943 {
956 944 return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL,
... ... @@ -996,7 +984,7 @@
996 984 rpc_depopulate(dentry, cache_pipefs_files, 0, 3);
997 985 }
998 986  
999   -struct dentry *rpc_create_cache_dir(struct dentry *parent, struct qstr *name,
  987 +struct dentry *rpc_create_cache_dir(struct dentry *parent, const char *name,
1000 988 umode_t umode, struct cache_detail *cd)
1001 989 {
1002 990 return rpc_mkdir_populate(parent, name, umode, NULL,
... ... @@ -1076,9 +1064,7 @@
1076 1064 const unsigned char *dir_name)
1077 1065 {
1078 1066 struct qstr dir = QSTR_INIT(dir_name, strlen(dir_name));
1079   -
1080   - dir.hash = full_name_hash(dir.name, dir.len);
1081   - return d_lookup(sb->s_root, &dir);
  1067 + return d_hash_and_lookup(sb->s_root, &dir);
1082 1068 }
1083 1069 EXPORT_SYMBOL_GPL(rpc_d_lookup_sb);
1084 1070