Skip to content

Commit 41d9884

Browse files
committed
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
2 parents 63345b4 + dae3794 commit 41d9884

File tree

18 files changed

+73
-137
lines changed

18 files changed

+73
-137
lines changed

arch/alpha/include/uapi/asm/fcntl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define O_SYNC (__O_SYNC|O_DSYNC)
3333

3434
#define O_PATH 040000000
35-
#define O_TMPFILE 0100000000
35+
#define __O_TMPFILE 0100000000
3636

3737
#define F_GETLK 7
3838
#define F_SETLK 8

arch/parisc/include/uapi/asm/fcntl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define O_INVISIBLE 004000000 /* invisible I/O, for DMAPI/XDSM */
2121

2222
#define O_PATH 020000000
23-
#define O_TMPFILE 040000000
23+
#define __O_TMPFILE 040000000
2424

2525
#define F_GETLK64 8
2626
#define F_SETLK64 9

arch/sparc/include/uapi/asm/fcntl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define O_SYNC (__O_SYNC|O_DSYNC)
3636

3737
#define O_PATH 0x1000000
38-
#define O_TMPFILE 0x2000000
38+
#define __O_TMPFILE 0x2000000
3939

4040
#define F_GETOWN 5 /* for sockets. */
4141
#define F_SETOWN 6 /* for sockets. */

fs/configfs/dir.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,19 +660,15 @@ static int create_default_group(struct config_group *parent_group,
660660
struct config_group *group)
661661
{
662662
int ret;
663-
struct qstr name;
664663
struct configfs_dirent *sd;
665664
/* We trust the caller holds a reference to parent */
666665
struct dentry *child, *parent = parent_group->cg_item.ci_dentry;
667666

668667
if (!group->cg_item.ci_name)
669668
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);
673669

674670
ret = -ENOMEM;
675-
child = d_alloc(parent, &name);
671+
child = d_alloc_name(parent, group->cg_item.ci_name);
676672
if (child) {
677673
d_add(child, NULL);
678674

@@ -1650,7 +1646,6 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
16501646
{
16511647
int err;
16521648
struct config_group *group = &subsys->su_group;
1653-
struct qstr name;
16541649
struct dentry *dentry;
16551650
struct dentry *root;
16561651
struct configfs_dirent *sd;
@@ -1667,12 +1662,8 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
16671662

16681663
mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT);
16691664

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-
16741665
err = -ENOMEM;
1675-
dentry = d_alloc(root, &name);
1666+
dentry = d_alloc_name(root, group->cg_item.ci_name);
16761667
if (dentry) {
16771668
d_add(dentry, NULL);
16781669

fs/efivarfs/inode.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,8 @@ static int efivarfs_unlink(struct inode *dir, struct dentry *dentry)
155155
return 0;
156156
};
157157

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-
170158
const struct inode_operations efivarfs_dir_inode_operations = {
171-
.lookup = efivarfs_lookup,
159+
.lookup = simple_lookup,
172160
.unlink = efivarfs_unlink,
173161
.create = efivarfs_create,
174162
};

fs/file_table.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,15 @@ static void __fput(struct file *file)
265265
mntput(mnt);
266266
}
267267

268-
static DEFINE_SPINLOCK(delayed_fput_lock);
269-
static LIST_HEAD(delayed_fput_list);
268+
static LLIST_HEAD(delayed_fput_list);
270269
static void delayed_fput(struct work_struct *unused)
271270
{
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));
280277
}
281278
}
282279

@@ -306,18 +303,22 @@ void fput(struct file *file)
306303
{
307304
if (atomic_long_dec_and_test(&file->f_count)) {
308305
struct task_struct *task = current;
309-
unsigned long flags;
310306

311307
file_sb_list_del(file);
312308
if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
313309
init_task_work(&file->f_u.fu_rcuhead, ____fput);
314310
if (!task_work_add(task, &file->f_u.fu_rcuhead, true))
315311
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+
*/
316318
}
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);
321322
}
322323
}
323324

fs/libfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, unsigned
6161

6262
if (dentry->d_name.len > NAME_MAX)
6363
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);
6566
d_add(dentry, NULL);
6667
return NULL;
6768
}

fs/namei.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2977,7 +2977,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
29772977

29782978
file->f_flags = op->open_flag;
29792979

2980-
if (unlikely(file->f_flags & O_TMPFILE)) {
2980+
if (unlikely(file->f_flags & __O_TMPFILE)) {
29812981
error = do_tmpfile(dfd, pathname, nd, flags, op, file, &opened);
29822982
goto out;
29832983
}

fs/open.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
840840
if (flags & __O_SYNC)
841841
flags |= O_DSYNC;
842842

843-
if (flags & O_TMPFILE) {
844-
if (!(flags & O_CREAT))
843+
if (flags & __O_TMPFILE) {
844+
if ((flags & O_TMPFILE_MASK) != O_TMPFILE)
845845
return -EINVAL;
846846
acc_mode = MAY_OPEN | ACC_MODE(flags);
847847
} else if (flags & O_PATH) {

include/linux/fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/stat.h>
1111
#include <linux/cache.h>
1212
#include <linux/list.h>
13+
#include <linux/llist.h>
1314
#include <linux/radix-tree.h>
1415
#include <linux/rbtree.h>
1516
#include <linux/init.h>
@@ -768,6 +769,7 @@ struct file {
768769
*/
769770
union {
770771
struct list_head fu_list;
772+
struct llist_node fu_llist;
771773
struct rcu_head fu_rcuhead;
772774
} f_u;
773775
struct path f_path;

include/linux/llist.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ static inline struct llist_node *llist_next(struct llist_node *node)
142142
return node->next;
143143
}
144144

145+
extern bool llist_add_batch(struct llist_node *new_first,
146+
struct llist_node *new_last,
147+
struct llist_head *head);
145148
/**
146149
* llist_add - add a new entry
147150
* @new: new entry to be added
@@ -151,18 +154,7 @@ static inline struct llist_node *llist_next(struct llist_node *node)
151154
*/
152155
static inline bool llist_add(struct llist_node *new, struct llist_head *head)
153156
{
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);
166158
}
167159

168160
/**
@@ -178,9 +170,6 @@ static inline struct llist_node *llist_del_all(struct llist_head *head)
178170
return xchg(&head->first, NULL);
179171
}
180172

181-
extern bool llist_add_batch(struct llist_node *new_first,
182-
struct llist_node *new_last,
183-
struct llist_head *head);
184173
extern struct llist_node *llist_del_first(struct llist_head *head);
185174

186175
#endif /* LLIST_H */

include/linux/sunrpc/rpc_pipe_fs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ extern ssize_t rpc_pipe_generic_upcall(struct file *, struct rpc_pipe_msg *,
7373
extern int rpc_queue_upcall(struct rpc_pipe *, struct rpc_pipe_msg *);
7474

7575
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 *);
7777
extern int rpc_remove_client_dir(struct dentry *);
7878

7979
struct cache_detail;
8080
extern struct dentry *rpc_create_cache_dir(struct dentry *,
81-
struct qstr *,
81+
const char *,
8282
umode_t umode,
8383
struct cache_detail *);
8484
extern void rpc_remove_cache_dir(struct dentry *);

include/uapi/asm-generic/fcntl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@
8484
#define O_PATH 010000000
8585
#endif
8686

87-
#ifndef O_TMPFILE
88-
#define O_TMPFILE 020000000
87+
#ifndef __O_TMPFILE
88+
#define __O_TMPFILE 020000000
8989
#endif
9090

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)
94+
9195
#ifndef O_NDELAY
9296
#define O_NDELAY O_NONBLOCK
9397
#endif

kernel/cgroup.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ static struct cgroup *task_cgroup_from_root(struct task_struct *task,
802802
*/
803803

804804
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);
806805
static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
807806
static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files,
808807
unsigned long subsys_mask);
@@ -2642,7 +2641,7 @@ static const struct inode_operations cgroup_file_inode_operations = {
26422641
};
26432642

26442643
static const struct inode_operations cgroup_dir_inode_operations = {
2645-
.lookup = cgroup_lookup,
2644+
.lookup = simple_lookup,
26462645
.mkdir = cgroup_mkdir,
26472646
.rmdir = cgroup_rmdir,
26482647
.rename = cgroup_rename,
@@ -2652,14 +2651,6 @@ static const struct inode_operations cgroup_dir_inode_operations = {
26522651
.removexattr = cgroup_removexattr,
26532652
};
26542653

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-
26632654
/*
26642655
* Check if a file is a control file
26652656
*/

lib/llist.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@
3939
bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
4040
struct llist_head *head)
4141
{
42-
struct llist_node *entry, *old_entry;
42+
struct llist_node *first;
4343

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);
5247

53-
return old_entry == NULL;
48+
return !first;
5449
}
5550
EXPORT_SYMBOL_GPL(llist_add_batch);
5651

net/sunrpc/cache.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,19 +1823,11 @@ int sunrpc_cache_register_pipefs(struct dentry *parent,
18231823
const char *name, umode_t umode,
18241824
struct cache_detail *cd)
18251825
{
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;
18391831
}
18401832
EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs);
18411833

net/sunrpc/clnt.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,25 @@ static struct dentry *rpc_setup_pipedir_sb(struct super_block *sb,
128128
{
129129
static uint32_t clntid;
130130
char name[15];
131-
struct qstr q = { .name = name };
132131
struct dentry *dir, *dentry;
133-
int error;
134132

135133
dir = rpc_d_lookup_sb(sb, dir_name);
136134
if (dir == NULL) {
137135
pr_info("RPC: pipefs directory doesn't exist: %s\n", dir_name);
138136
return dir;
139137
}
140138
for (;;) {
141-
q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
139+
snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
142140
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);
145142
if (!IS_ERR(dentry))
146143
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;
154150
}
155151
dput(dir);
156152
return dentry;

0 commit comments

Comments
 (0)