Skip to content

Commit 603ba7e

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs pile #2 from Al Viro: "Next pile (and there'll be one or two more). The large piece in this one is getting rid of /proc/*/ns/* weirdness; among other things, it allows to (finally) make nameidata completely opaque outside of fs/namei.c, making for easier further cleanups in there" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: coda_venus_readdir(): use file_inode() fs/namei.c: fold link_path_walk() call into path_init() path_init(): don't bother with LOOKUP_PARENT in argument fs/namei.c: new helper (path_cleanup()) path_init(): store the "base" pointer to file in nameidata itself make default ->i_fop have ->open() fail with ENXIO make nameidata completely opaque outside of fs/namei.c kill proc_ns completely take the targets of /proc/*/ns/* symlinks to separate fs bury struct proc_ns in fs/proc copy address of proc_ns_ops into ns_common new helpers: ns_alloc_inum/ns_free_inum make proc_ns_operations work with struct ns_common * instead of void * switch the rest of proc_ns_operations to working with &...->ns netns: switch ->get()/->put()/->install()/->inum() to working with &net->ns make mntns ->get()/->put()/->install()/->inum() work with &mnt_ns->ns common object embedded into various struct ....ns
2 parents 31f48fc + 93fe74b commit 603ba7e

36 files changed

+416
-430
lines changed

arch/ia64/kernel/perfmon.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,22 +2145,12 @@ pfm_close(struct inode *inode, struct file *filp)
21452145
return 0;
21462146
}
21472147

2148-
static int
2149-
pfm_no_open(struct inode *irrelevant, struct file *dontcare)
2150-
{
2151-
DPRINT(("pfm_no_open called\n"));
2152-
return -ENXIO;
2153-
}
2154-
2155-
2156-
21572148
static const struct file_operations pfm_file_ops = {
21582149
.llseek = no_llseek,
21592150
.read = pfm_read,
21602151
.write = pfm_write,
21612152
.poll = pfm_poll,
21622153
.unlocked_ioctl = pfm_ioctl,
2163-
.open = pfm_no_open, /* special open code to disallow open via /proc */
21642154
.fasync = pfm_fasync,
21652155
.release = pfm_close,
21662156
.flush = pfm_flush

fs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ obj-y := open.o read_write.o file_table.o super.o \
1111
attr.o bad_inode.o file.o filesystems.o namespace.o \
1212
seq_file.o xattr.o libfs.o fs-writeback.o \
1313
pnode.o splice.o sync.o utimes.o \
14-
stack.o fs_struct.o statfs.o fs_pin.o
14+
stack.o fs_struct.o statfs.o fs_pin.o nsfs.o
1515

1616
ifeq ($(CONFIG_BLOCK),y)
1717
obj-y += buffer.o block_dev.o direct-io.o mpage.o

fs/coda/dir.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ static int coda_venus_readdir(struct file *coda_file, struct dir_context *ctx)
426426
struct coda_file_info *cfi;
427427
struct coda_inode_info *cii;
428428
struct file *host_file;
429-
struct dentry *de;
430429
struct venus_dirent *vdir;
431430
unsigned long vdir_size = offsetof(struct venus_dirent, d_name);
432431
unsigned int type;
@@ -438,8 +437,7 @@ static int coda_venus_readdir(struct file *coda_file, struct dir_context *ctx)
438437
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
439438
host_file = cfi->cfi_container;
440439

441-
de = coda_file->f_path.dentry;
442-
cii = ITOC(de->d_inode);
440+
cii = ITOC(file_inode(coda_file));
443441

444442
vdir = kmalloc(sizeof(*vdir), GFP_KERNEL);
445443
if (!vdir) return -ENOMEM;

fs/inode.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ int proc_nr_inodes(struct ctl_table *table, int write,
114114
}
115115
#endif
116116

117+
static int no_open(struct inode *inode, struct file *file)
118+
{
119+
return -ENXIO;
120+
}
121+
117122
/**
118123
* inode_init_always - perform inode structure intialisation
119124
* @sb: superblock inode belongs to
@@ -125,15 +130,15 @@ int proc_nr_inodes(struct ctl_table *table, int write,
125130
int inode_init_always(struct super_block *sb, struct inode *inode)
126131
{
127132
static const struct inode_operations empty_iops;
128-
static const struct file_operations empty_fops;
133+
static const struct file_operations no_open_fops = {.open = no_open};
129134
struct address_space *const mapping = &inode->i_data;
130135

131136
inode->i_sb = sb;
132137
inode->i_blkbits = sb->s_blocksize_bits;
133138
inode->i_flags = 0;
134139
atomic_set(&inode->i_count, 1);
135140
inode->i_op = &empty_iops;
136-
inode->i_fop = &empty_fops;
141+
inode->i_fop = &no_open_fops;
137142
inode->__i_nlink = 1;
138143
inode->i_opflags = 0;
139144
i_uid_write(inode, 0);
@@ -1798,7 +1803,7 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
17981803
} else if (S_ISFIFO(mode))
17991804
inode->i_fop = &pipefifo_fops;
18001805
else if (S_ISSOCK(mode))
1801-
inode->i_fop = &bad_sock_fops;
1806+
; /* leave it no_open_fops */
18021807
else
18031808
printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o) for"
18041809
" inode %s:%lu\n", mode, inode->i_sb->s_id,

fs/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,8 @@ extern const struct file_operations pipefifo_fops;
147147
*/
148148
extern void sb_pin_kill(struct super_block *sb);
149149
extern void mnt_pin_kill(struct mount *m);
150+
151+
/*
152+
* fs/nsfs.c
153+
*/
154+
extern struct dentry_operations ns_dentry_operations;

fs/mount.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include <linux/mount.h>
22
#include <linux/seq_file.h>
33
#include <linux/poll.h>
4+
#include <linux/ns_common.h>
45

56
struct mnt_namespace {
67
atomic_t count;
7-
unsigned int proc_inum;
8+
struct ns_common ns;
89
struct mount * root;
910
struct list_head list;
1011
struct user_namespace *user_ns;

fs/namei.c

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,19 @@ void path_put(const struct path *path)
487487
}
488488
EXPORT_SYMBOL(path_put);
489489

490+
struct nameidata {
491+
struct path path;
492+
struct qstr last;
493+
struct path root;
494+
struct inode *inode; /* path.dentry.d_inode */
495+
unsigned int flags;
496+
unsigned seq, m_seq;
497+
int last_type;
498+
unsigned depth;
499+
struct file *base;
500+
char *saved_names[MAX_NESTED_LINKS + 1];
501+
};
502+
490503
/*
491504
* Path walking has 2 modes, rcu-walk and ref-walk (see
492505
* Documentation/filesystems/path-lookup.txt). In situations when we can't
@@ -695,6 +708,18 @@ void nd_jump_link(struct nameidata *nd, struct path *path)
695708
nd->flags |= LOOKUP_JUMPED;
696709
}
697710

711+
void nd_set_link(struct nameidata *nd, char *path)
712+
{
713+
nd->saved_names[nd->depth] = path;
714+
}
715+
EXPORT_SYMBOL(nd_set_link);
716+
717+
char *nd_get_link(struct nameidata *nd)
718+
{
719+
return nd->saved_names[nd->depth];
720+
}
721+
EXPORT_SYMBOL(nd_get_link);
722+
698723
static inline void put_link(struct nameidata *nd, struct path *link, void *cookie)
699724
{
700725
struct inode *inode = link->dentry->d_inode;
@@ -1821,13 +1846,14 @@ static int link_path_walk(const char *name, struct nameidata *nd)
18211846
}
18221847

18231848
static int path_init(int dfd, const char *name, unsigned int flags,
1824-
struct nameidata *nd, struct file **fp)
1849+
struct nameidata *nd)
18251850
{
18261851
int retval = 0;
18271852

18281853
nd->last_type = LAST_ROOT; /* if there are only slashes... */
1829-
nd->flags = flags | LOOKUP_JUMPED;
1854+
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
18301855
nd->depth = 0;
1856+
nd->base = NULL;
18311857
if (flags & LOOKUP_ROOT) {
18321858
struct dentry *root = nd->root.dentry;
18331859
struct inode *inode = root->d_inode;
@@ -1847,7 +1873,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
18471873
} else {
18481874
path_get(&nd->path);
18491875
}
1850-
return 0;
1876+
goto done;
18511877
}
18521878

18531879
nd->root.mnt = NULL;
@@ -1897,7 +1923,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
18971923
nd->path = f.file->f_path;
18981924
if (flags & LOOKUP_RCU) {
18991925
if (f.flags & FDPUT_FPUT)
1900-
*fp = f.file;
1926+
nd->base = f.file;
19011927
nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
19021928
rcu_read_lock();
19031929
} else {
@@ -1908,13 +1934,26 @@ static int path_init(int dfd, const char *name, unsigned int flags,
19081934

19091935
nd->inode = nd->path.dentry->d_inode;
19101936
if (!(flags & LOOKUP_RCU))
1911-
return 0;
1937+
goto done;
19121938
if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq)))
1913-
return 0;
1939+
goto done;
19141940
if (!(nd->flags & LOOKUP_ROOT))
19151941
nd->root.mnt = NULL;
19161942
rcu_read_unlock();
19171943
return -ECHILD;
1944+
done:
1945+
current->total_link_count = 0;
1946+
return link_path_walk(name, nd);
1947+
}
1948+
1949+
static void path_cleanup(struct nameidata *nd)
1950+
{
1951+
if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) {
1952+
path_put(&nd->root);
1953+
nd->root.mnt = NULL;
1954+
}
1955+
if (unlikely(nd->base))
1956+
fput(nd->base);
19181957
}
19191958

19201959
static inline int lookup_last(struct nameidata *nd, struct path *path)
@@ -1930,7 +1969,6 @@ static inline int lookup_last(struct nameidata *nd, struct path *path)
19301969
static int path_lookupat(int dfd, const char *name,
19311970
unsigned int flags, struct nameidata *nd)
19321971
{
1933-
struct file *base = NULL;
19341972
struct path path;
19351973
int err;
19361974

@@ -1948,14 +1986,7 @@ static int path_lookupat(int dfd, const char *name,
19481986
* be handled by restarting a traditional ref-walk (which will always
19491987
* be able to complete).
19501988
*/
1951-
err = path_init(dfd, name, flags | LOOKUP_PARENT, nd, &base);
1952-
1953-
if (unlikely(err))
1954-
goto out;
1955-
1956-
current->total_link_count = 0;
1957-
err = link_path_walk(name, nd);
1958-
1989+
err = path_init(dfd, name, flags, nd);
19591990
if (!err && !(flags & LOOKUP_PARENT)) {
19601991
err = lookup_last(nd, &path);
19611992
while (err > 0) {
@@ -1983,14 +2014,7 @@ static int path_lookupat(int dfd, const char *name,
19832014
}
19842015
}
19852016

1986-
out:
1987-
if (base)
1988-
fput(base);
1989-
1990-
if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) {
1991-
path_put(&nd->root);
1992-
nd->root.mnt = NULL;
1993-
}
2017+
path_cleanup(nd);
19942018
return err;
19952019
}
19962020

@@ -2297,19 +2321,13 @@ mountpoint_last(struct nameidata *nd, struct path *path)
22972321
static int
22982322
path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags)
22992323
{
2300-
struct file *base = NULL;
23012324
struct nameidata nd;
23022325
int err;
23032326

2304-
err = path_init(dfd, name, flags | LOOKUP_PARENT, &nd, &base);
2327+
err = path_init(dfd, name, flags, &nd);
23052328
if (unlikely(err))
23062329
goto out;
23072330

2308-
current->total_link_count = 0;
2309-
err = link_path_walk(name, &nd);
2310-
if (err)
2311-
goto out;
2312-
23132331
err = mountpoint_last(&nd, path);
23142332
while (err > 0) {
23152333
void *cookie;
@@ -2325,12 +2343,7 @@ path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags
23252343
put_link(&nd, &link, cookie);
23262344
}
23272345
out:
2328-
if (base)
2329-
fput(base);
2330-
2331-
if (nd.root.mnt && !(nd.flags & LOOKUP_ROOT))
2332-
path_put(&nd.root);
2333-
2346+
path_cleanup(&nd);
23342347
return err;
23352348
}
23362349

@@ -3181,7 +3194,6 @@ static int do_tmpfile(int dfd, struct filename *pathname,
31813194
static struct file *path_openat(int dfd, struct filename *pathname,
31823195
struct nameidata *nd, const struct open_flags *op, int flags)
31833196
{
3184-
struct file *base = NULL;
31853197
struct file *file;
31863198
struct path path;
31873199
int opened = 0;
@@ -3198,12 +3210,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
31983210
goto out;
31993211
}
32003212

3201-
error = path_init(dfd, pathname->name, flags | LOOKUP_PARENT, nd, &base);
3202-
if (unlikely(error))
3203-
goto out;
3204-
3205-
current->total_link_count = 0;
3206-
error = link_path_walk(pathname->name, nd);
3213+
error = path_init(dfd, pathname->name, flags, nd);
32073214
if (unlikely(error))
32083215
goto out;
32093216

@@ -3229,10 +3236,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
32293236
put_link(nd, &link, cookie);
32303237
}
32313238
out:
3232-
if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
3233-
path_put(&nd->root);
3234-
if (base)
3235-
fput(base);
3239+
path_cleanup(nd);
32363240
if (!(opened & FILE_OPENED)) {
32373241
BUG_ON(!error);
32383242
put_filp(file);

0 commit comments

Comments
 (0)