aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hugetlbfs/inode.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 /fs/hugetlbfs/inode.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 'fs/hugetlbfs/inode.c')
-rw-r--r--fs/hugetlbfs/inode.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 0f5df73dbb73..12aca8ed605f 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -933,16 +933,11 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
933 if (!dentry) 933 if (!dentry)
934 goto out_shm_unlock; 934 goto out_shm_unlock;
935 935
936 error = -ENFILE;
937 file = get_empty_filp();
938 if (!file)
939 goto out_dentry;
940
941 error = -ENOSPC; 936 error = -ENOSPC;
942 inode = hugetlbfs_get_inode(root->d_sb, current->fsuid, 937 inode = hugetlbfs_get_inode(root->d_sb, current->fsuid,
943 current->fsgid, S_IFREG | S_IRWXUGO, 0); 938 current->fsgid, S_IFREG | S_IRWXUGO, 0);
944 if (!inode) 939 if (!inode)
945 goto out_file; 940 goto out_dentry;
946 941
947 error = -ENOMEM; 942 error = -ENOMEM;
948 if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT)) 943 if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
@@ -951,17 +946,18 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
951 d_instantiate(dentry, inode); 946 d_instantiate(dentry, inode);
952 inode->i_size = size; 947 inode->i_size = size;
953 inode->i_nlink = 0; 948 inode->i_nlink = 0;
954 file->f_path.mnt = mntget(hugetlbfs_vfsmount); 949
955 file->f_path.dentry = dentry; 950 error = -ENFILE;
956 file->f_mapping = inode->i_mapping; 951 file = alloc_file(hugetlbfs_vfsmount, dentry,
957 file->f_op = &hugetlbfs_file_operations; 952 FMODE_WRITE | FMODE_READ,
958 file->f_mode = FMODE_WRITE | FMODE_READ; 953 &hugetlbfs_file_operations);
954 if (!file)
955 goto out_inode;
956
959 return file; 957 return file;
960 958
961out_inode: 959out_inode:
962 iput(inode); 960 iput(inode);
963out_file:
964 put_filp(file);
965out_dentry: 961out_dentry:
966 dput(dentry); 962 dput(dentry);
967out_shm_unlock: 963out_shm_unlock: