aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
authorDave Hansen <haveblue@us.ibm.com>2007-10-17 02:31:13 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:43:04 -0400
commitce8d2cdf3d2b73e346c82e6f0a46da331df6364c (patch)
treebf3597f2d4f57d6e30a7703d7fce0dbf8c757962 /net/socket.c
parent348366b963e4e1462c8354827a9cb910aa865bf2 (diff)
r/o bind mounts: filesystem helpers for custom 'struct file's
Why do we need r/o bind mounts? This feature allows a read-only view into a read-write filesystem. In the process of doing that, it also provides infrastructure for keeping track of the number of writers to any given mount. This has a number of uses. It allows chroots to have parts of filesystems writable. It will be useful for containers in the future because users may have root inside a container, but should not be allowed to write to somefilesystems. This also replaces patches that vserver has had out of the tree for several years. It allows security enhancement by making sure that parts of your filesystem read-only (such as when you don't trust your FTP server), when you don't want to have entire new filesystems mounted, or when you want atime selectively updated. I've been using the following script to test that the feature is working as desired. It takes a directory and makes a regular bind and a r/o bind mount of it. It then performs some normal filesystem operations on the three directories, including ones that are expected to fail, like creating a file on the r/o mount. This patch: Some filesystems forego the vfs and may_open() and create their own 'struct file's. This patch creates a couple of helper functions which can be used by these filesystems, and will provide a unified place which the r/o bind mount code may patch. Also, rename an existing, static-scope init_file() to a less generic name. Signed-off-by: Dave Hansen <haveblue@us.ibm.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/net/socket.c b/net/socket.c
index 3cd96fe8191d..540013ea8620 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -364,26 +364,26 @@ static int sock_alloc_fd(struct file **filep)
364 364
365static int sock_attach_fd(struct socket *sock, struct file *file) 365static int sock_attach_fd(struct socket *sock, struct file *file)
366{ 366{
367 struct dentry *dentry;
367 struct qstr name = { .name = "" }; 368 struct qstr name = { .name = "" };
368 369
369 file->f_path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name); 370 dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name);
370 if (unlikely(!file->f_path.dentry)) 371 if (unlikely(!dentry))
371 return -ENOMEM; 372 return -ENOMEM;
372 373
373 file->f_path.dentry->d_op = &sockfs_dentry_operations; 374 dentry->d_op = &sockfs_dentry_operations;
374 /* 375 /*
375 * We dont want to push this dentry into global dentry hash table. 376 * We dont want to push this dentry into global dentry hash table.
376 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED 377 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED
377 * This permits a working /proc/$pid/fd/XXX on sockets 378 * This permits a working /proc/$pid/fd/XXX on sockets
378 */ 379 */
379 file->f_path.dentry->d_flags &= ~DCACHE_UNHASHED; 380 dentry->d_flags &= ~DCACHE_UNHASHED;
380 d_instantiate(file->f_path.dentry, SOCK_INODE(sock)); 381 d_instantiate(dentry, SOCK_INODE(sock));
381 file->f_path.mnt = mntget(sock_mnt);
382 file->f_mapping = file->f_path.dentry->d_inode->i_mapping;
383 382
384 sock->file = file; 383 sock->file = file;
385 file->f_op = SOCK_INODE(sock)->i_fop = &socket_file_ops; 384 init_file(file, sock_mnt, dentry, FMODE_READ | FMODE_WRITE,
386 file->f_mode = FMODE_READ | FMODE_WRITE; 385 &socket_file_ops);
386 SOCK_INODE(sock)->i_fop = &socket_file_ops;
387 file->f_flags = O_RDWR; 387 file->f_flags = O_RDWR;
388 file->f_pos = 0; 388 file->f_pos = 0;
389 file->private_data = sock; 389 file->private_data = sock;