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

Changed files
+73 -137
arch
alpha
include
uapi
asm
parisc
include
uapi
asm
sparc
include
uapi
asm
fs
include
linux
uapi
asm-generic
kernel
lib
net
+1 -1
arch/alpha/include/uapi/asm/fcntl.h
··· 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
+1 -1
arch/parisc/include/uapi/asm/fcntl.h
··· 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
+1 -1
arch/sparc/include/uapi/asm/fcntl.h
··· 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. */
+2 -11
fs/configfs/dir.c
··· 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 ··· 1646 1650 { 1647 1651 int err; 1648 1652 struct config_group *group = &subsys->su_group; 1649 - struct qstr name; 1650 1653 struct dentry *dentry; 1651 1654 struct dentry *root; 1652 1655 struct configfs_dirent *sd; ··· 1662 1667 1663 1668 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT); 1664 1669 1665 - name.name = group->cg_item.ci_name; 1666 - name.len = strlen(name.name); 1667 - name.hash = full_name_hash(name.name, name.len); 1668 - 1669 1670 err = -ENOMEM; 1670 - dentry = d_alloc(root, &name); 1671 + dentry = d_alloc_name(root, group->cg_item.ci_name); 1671 1672 if (dentry) { 1672 1673 d_add(dentry, NULL); 1673 1674
+1 -13
fs/efivarfs/inode.c
··· 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 };
+16 -15
fs/file_table.c
··· 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 ··· 303 306 { 304 307 if (atomic_long_dec_and_test(&file->f_count)) { 305 308 struct task_struct *task = current; 306 - unsigned long flags; 307 309 308 310 file_sb_list_del(file); 309 311 if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) { 310 312 init_task_work(&file->f_u.fu_rcuhead, ____fput); 311 313 if (!task_work_add(task, &file->f_u.fu_rcuhead, true)) 312 314 return; 315 + /* 316 + * After this task has run exit_task_work(), 317 + * task_work_add() will fail. free_ipc_ns()-> 318 + * shm_destroy() can do this. Fall through to delayed 319 + * fput to avoid leaking *file. 320 + */ 313 321 } 314 - spin_lock_irqsave(&delayed_fput_lock, flags); 315 - list_add(&file->f_u.fu_list, &delayed_fput_list); 316 - schedule_work(&delayed_fput_work); 317 - spin_unlock_irqrestore(&delayed_fput_lock, flags); 322 + 323 + if (llist_add(&file->f_u.fu_llist, &delayed_fput_list)) 324 + schedule_work(&delayed_fput_work); 318 325 } 319 326 } 320 327
+2 -1
fs/libfs.c
··· 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 }
+1 -1
fs/namei.c
··· 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 }
+2 -2
fs/open.c
··· 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) {
+2
include/linux/fs.h
··· 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> ··· 769 768 */ 770 769 union { 771 770 struct list_head fu_list; 771 + struct llist_node fu_llist; 772 772 struct rcu_head fu_rcuhead; 773 773 } f_u; 774 774 struct path f_path;
+4 -15
include/linux/llist.h
··· 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 ··· 154 151 */ 155 152 static inline bool llist_add(struct llist_node *new, struct llist_head *head) 156 153 { 157 - struct llist_node *entry, *old_entry; 158 - 159 - entry = head->first; 160 - for (;;) { 161 - old_entry = entry; 162 - new->next = entry; 163 - entry = cmpxchg(&head->first, old_entry, new); 164 - if (entry == old_entry) 165 - break; 166 - } 167 - 168 - return old_entry == NULL; 154 + return llist_add_batch(new, new, head); 169 155 } 170 156 171 157 /** ··· 170 178 return xchg(&head->first, NULL); 171 179 } 172 180 173 - extern bool llist_add_batch(struct llist_node *new_first, 174 - struct llist_node *new_last, 175 - struct llist_head *head); 176 181 extern struct llist_node *llist_del_first(struct llist_head *head); 177 182 178 183 #endif /* LLIST_H */
+2 -2
include/linux/sunrpc/rpc_pipe_fs.h
··· 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 *);
+6 -2
include/uapi/asm-generic/fcntl.h
··· 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
+1 -10
kernel/cgroup.c
··· 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); ··· 2641 2642 }; 2642 2643 2643 2644 static const struct inode_operations cgroup_dir_inode_operations = { 2644 - .lookup = cgroup_lookup, 2645 + .lookup = simple_lookup, 2645 2646 .mkdir = cgroup_mkdir, 2646 2647 .rmdir = cgroup_rmdir, 2647 2648 .rename = cgroup_rename, ··· 2650 2651 .listxattr = cgroup_listxattr, 2651 2652 .removexattr = cgroup_removexattr, 2652 2653 }; 2653 - 2654 - static struct dentry *cgroup_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) 2655 - { 2656 - if (dentry->d_name.len > NAME_MAX) 2657 - return ERR_PTR(-ENAMETOOLONG); 2658 - d_add(dentry, NULL); 2659 - return NULL; 2660 - } 2661 2654 2662 2655 /* 2663 2656 * Check if a file is a control file
+5 -10
lib/llist.c
··· 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
+5 -13
net/sunrpc/cache.c
··· 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
+8 -12
net/sunrpc/clnt.c
··· 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) { ··· 136 138 return dir; 137 139 } 138 140 for (;;) { 139 - q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); 141 + snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); 140 142 name[sizeof(name) - 1] = '\0'; 141 - q.hash = full_name_hash(q.name, q.len); 142 - dentry = rpc_create_client_dir(dir, &q, clnt); 143 + dentry = rpc_create_client_dir(dir, name, clnt); 143 144 if (!IS_ERR(dentry)) 144 145 break; 145 - error = PTR_ERR(dentry); 146 - if (error != -EEXIST) { 147 - printk(KERN_INFO "RPC: Couldn't create pipefs entry" 148 - " %s/%s, error %d\n", 149 - dir_name, name, error); 150 - break; 151 - } 146 + if (dentry == ERR_PTR(-EEXIST)) 147 + continue; 148 + printk(KERN_INFO "RPC: Couldn't create pipefs entry" 149 + " %s/%s, error %ld\n", 150 + dir_name, name, PTR_ERR(dentry)); 151 + break; 152 152 } 153 153 dput(dir); 154 154 return dentry;
+13 -27
net/sunrpc/rpc_pipe.c
··· 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 } ··· 703 704 for (i = start; i < eof; i++) { 704 705 name.name = files[i].name; 705 706 name.len = strlen(files[i].name); 706 - name.hash = full_name_hash(name.name, name.len); 707 - dentry = d_lookup(parent, &name); 707 + dentry = d_hash_and_lookup(parent, &name); 708 708 709 709 if (dentry == NULL) 710 710 continue; ··· 745 747 746 748 mutex_lock(&dir->i_mutex); 747 749 for (i = start; i < eof; i++) { 748 - struct qstr q; 749 - 750 - q.name = files[i].name; 751 - q.len = strlen(files[i].name); 752 - q.hash = full_name_hash(q.name, q.len); 753 - dentry = __rpc_lookup_create_exclusive(parent, &q); 750 + dentry = __rpc_lookup_create_exclusive(parent, files[i].name); 754 751 err = PTR_ERR(dentry); 755 752 if (IS_ERR(dentry)) 756 753 goto out_bad; ··· 778 785 } 779 786 780 787 static struct dentry *rpc_mkdir_populate(struct dentry *parent, 781 - struct qstr *name, umode_t mode, void *private, 788 + const char *name, umode_t mode, void *private, 782 789 int (*populate)(struct dentry *, void *), void *args_populate) 783 790 { 784 791 struct dentry *dentry; ··· 849 856 struct dentry *dentry; 850 857 struct inode *dir = parent->d_inode; 851 858 umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR; 852 - struct qstr q; 853 859 int err; 854 860 855 861 if (pipe->ops->upcall == NULL) ··· 856 864 if (pipe->ops->downcall == NULL) 857 865 umode &= ~S_IWUGO; 858 866 859 - q.name = name; 860 - q.len = strlen(name); 861 - q.hash = full_name_hash(q.name, q.len), 862 - 863 867 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); 864 - dentry = __rpc_lookup_create_exclusive(parent, &q); 868 + dentry = __rpc_lookup_create_exclusive(parent, name); 865 869 if (IS_ERR(dentry)) 866 870 goto out; 867 871 err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops, ··· 928 940 929 941 /** 930 942 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs 931 - * @dentry: dentry from the rpc_pipefs root to the new directory 932 - * @name: &struct qstr for the name 943 + * @dentry: the parent of new directory 944 + * @name: the name of new directory 933 945 * @rpc_client: rpc client to associate with this directory 934 946 * 935 947 * This creates a directory at the given @path associated with ··· 938 950 * later be created using rpc_mkpipe(). 939 951 */ 940 952 struct dentry *rpc_create_client_dir(struct dentry *dentry, 941 - struct qstr *name, 953 + const char *name, 942 954 struct rpc_clnt *rpc_client) 943 955 { 944 956 return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL, ··· 984 996 rpc_depopulate(dentry, cache_pipefs_files, 0, 3); 985 997 } 986 998 987 - struct dentry *rpc_create_cache_dir(struct dentry *parent, struct qstr *name, 999 + struct dentry *rpc_create_cache_dir(struct dentry *parent, const char *name, 988 1000 umode_t umode, struct cache_detail *cd) 989 1001 { 990 1002 return rpc_mkdir_populate(parent, name, umode, NULL, ··· 1064 1076 const unsigned char *dir_name) 1065 1077 { 1066 1078 struct qstr dir = QSTR_INIT(dir_name, strlen(dir_name)); 1067 - 1068 - dir.hash = full_name_hash(dir.name, dir.len); 1069 - return d_lookup(sb->s_root, &dir); 1079 + return d_hash_and_lookup(sb->s_root, &dir); 1070 1080 } 1071 1081 EXPORT_SYMBOL_GPL(rpc_d_lookup_sb); 1072 1082