diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/configfs/dir.c | 5 | ||||
-rw-r--r-- | fs/file_table.c | 60 | ||||
-rw-r--r-- | fs/hugetlbfs/inode.c | 22 |
3 files changed, 72 insertions, 15 deletions
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index 2f436d4f1d6d..50ed691098bc 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c | |||
@@ -142,7 +142,7 @@ static int init_dir(struct inode * inode) | |||
142 | return 0; | 142 | return 0; |
143 | } | 143 | } |
144 | 144 | ||
145 | static int init_file(struct inode * inode) | 145 | static int configfs_init_file(struct inode * inode) |
146 | { | 146 | { |
147 | inode->i_size = PAGE_SIZE; | 147 | inode->i_size = PAGE_SIZE; |
148 | inode->i_fop = &configfs_file_operations; | 148 | inode->i_fop = &configfs_file_operations; |
@@ -283,7 +283,8 @@ static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * den | |||
283 | 283 | ||
284 | dentry->d_fsdata = configfs_get(sd); | 284 | dentry->d_fsdata = configfs_get(sd); |
285 | sd->s_dentry = dentry; | 285 | sd->s_dentry = dentry; |
286 | error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG, init_file); | 286 | error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG, |
287 | configfs_init_file); | ||
287 | if (error) { | 288 | if (error) { |
288 | configfs_put(sd); | 289 | configfs_put(sd); |
289 | return error; | 290 | return error; |
diff --git a/fs/file_table.c b/fs/file_table.c index ce3f39a4798a..3176fefc92e1 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -137,6 +137,66 @@ fail: | |||
137 | 137 | ||
138 | EXPORT_SYMBOL(get_empty_filp); | 138 | EXPORT_SYMBOL(get_empty_filp); |
139 | 139 | ||
140 | /** | ||
141 | * alloc_file - allocate and initialize a 'struct file' | ||
142 | * @mnt: the vfsmount on which the file will reside | ||
143 | * @dentry: the dentry representing the new file | ||
144 | * @mode: the mode with which the new file will be opened | ||
145 | * @fop: the 'struct file_operations' for the new file | ||
146 | * | ||
147 | * Use this instead of get_empty_filp() to get a new | ||
148 | * 'struct file'. Do so because of the same initialization | ||
149 | * pitfalls reasons listed for init_file(). This is a | ||
150 | * preferred interface to using init_file(). | ||
151 | * | ||
152 | * If all the callers of init_file() are eliminated, its | ||
153 | * code should be moved into this function. | ||
154 | */ | ||
155 | struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry, | ||
156 | mode_t mode, const struct file_operations *fop) | ||
157 | { | ||
158 | struct file *file; | ||
159 | struct path; | ||
160 | |||
161 | file = get_empty_filp(); | ||
162 | if (!file) | ||
163 | return NULL; | ||
164 | |||
165 | init_file(file, mnt, dentry, mode, fop); | ||
166 | return file; | ||
167 | } | ||
168 | EXPORT_SYMBOL(alloc_file); | ||
169 | |||
170 | /** | ||
171 | * init_file - initialize a 'struct file' | ||
172 | * @file: the already allocated 'struct file' to initialized | ||
173 | * @mnt: the vfsmount on which the file resides | ||
174 | * @dentry: the dentry representing this file | ||
175 | * @mode: the mode the file is opened with | ||
176 | * @fop: the 'struct file_operations' for this file | ||
177 | * | ||
178 | * Use this instead of setting the members directly. Doing so | ||
179 | * avoids making mistakes like forgetting the mntget() or | ||
180 | * forgetting to take a write on the mnt. | ||
181 | * | ||
182 | * Note: This is a crappy interface. It is here to make | ||
183 | * merging with the existing users of get_empty_filp() | ||
184 | * who have complex failure logic easier. All users | ||
185 | * of this should be moving to alloc_file(). | ||
186 | */ | ||
187 | int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry, | ||
188 | mode_t mode, const struct file_operations *fop) | ||
189 | { | ||
190 | int error = 0; | ||
191 | file->f_path.dentry = dentry; | ||
192 | file->f_path.mnt = mntget(mnt); | ||
193 | file->f_mapping = dentry->d_inode->i_mapping; | ||
194 | file->f_mode = mode; | ||
195 | file->f_op = fop; | ||
196 | return error; | ||
197 | } | ||
198 | EXPORT_SYMBOL(init_file); | ||
199 | |||
140 | void fastcall fput(struct file *file) | 200 | void fastcall fput(struct file *file) |
141 | { | 201 | { |
142 | if (atomic_dec_and_test(&file->f_count)) | 202 | if (atomic_dec_and_test(&file->f_count)) |
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 | ||
961 | out_inode: | 959 | out_inode: |
962 | iput(inode); | 960 | iput(inode); |
963 | out_file: | ||
964 | put_filp(file); | ||
965 | out_dentry: | 961 | out_dentry: |
966 | dput(dentry); | 962 | dput(dentry); |
967 | out_shm_unlock: | 963 | out_shm_unlock: |