diff options
author | Steven Whitehouse <swhiteho@redhat.com> | 2011-05-09 09:06:38 -0400 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2011-05-09 11:45:14 -0400 |
commit | 194c011fc4650d0dd1eecbc35bc26045108aca51 (patch) | |
tree | 1cb7769ab3df703336d17cc0835fc4a2132f51e6 /fs/gfs2/ops_inode.c | |
parent | d4b2cf1b0566eebfe39a6d70e9e4b5fa01ddaace (diff) |
GFS2: Move most of the remaining inode.c into ops_inode.c
This is in preparation to remove inode.c and rename ops_inode.c
to inode.c. Also most of the functions which were left in inode.c
relate to the creation and lookup of inodes. I'm intending to work
on consolidating some of that code, and its easier when its all in
one place.
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/ops_inode.c')
-rw-r--r-- | fs/gfs2/ops_inode.c | 711 |
1 files changed, 711 insertions, 0 deletions
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 2607c2c6de2b..a783a7a8c0ca 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/gfs2_ondisk.h> | 18 | #include <linux/gfs2_ondisk.h> |
19 | #include <linux/crc32.h> | 19 | #include <linux/crc32.h> |
20 | #include <linux/fiemap.h> | 20 | #include <linux/fiemap.h> |
21 | #include <linux/security.h> | ||
21 | #include <asm/uaccess.h> | 22 | #include <asm/uaccess.h> |
22 | 23 | ||
23 | #include "gfs2.h" | 24 | #include "gfs2.h" |
@@ -34,8 +35,676 @@ | |||
34 | #include "trans.h" | 35 | #include "trans.h" |
35 | #include "util.h" | 36 | #include "util.h" |
36 | #include "super.h" | 37 | #include "super.h" |
38 | #include "glops.h" | ||
39 | |||
40 | struct gfs2_skip_data { | ||
41 | u64 no_addr; | ||
42 | int skipped; | ||
43 | int non_block; | ||
44 | }; | ||
45 | |||
46 | static int iget_test(struct inode *inode, void *opaque) | ||
47 | { | ||
48 | struct gfs2_inode *ip = GFS2_I(inode); | ||
49 | struct gfs2_skip_data *data = opaque; | ||
50 | |||
51 | if (ip->i_no_addr == data->no_addr) { | ||
52 | if (data->non_block && | ||
53 | inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | ||
54 | data->skipped = 1; | ||
55 | return 0; | ||
56 | } | ||
57 | return 1; | ||
58 | } | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int iget_set(struct inode *inode, void *opaque) | ||
63 | { | ||
64 | struct gfs2_inode *ip = GFS2_I(inode); | ||
65 | struct gfs2_skip_data *data = opaque; | ||
66 | |||
67 | if (data->skipped) | ||
68 | return -ENOENT; | ||
69 | inode->i_ino = (unsigned long)(data->no_addr); | ||
70 | ip->i_no_addr = data->no_addr; | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr, int non_block) | ||
75 | { | ||
76 | unsigned long hash = (unsigned long)no_addr; | ||
77 | struct gfs2_skip_data data; | ||
78 | |||
79 | data.no_addr = no_addr; | ||
80 | data.skipped = 0; | ||
81 | data.non_block = non_block; | ||
82 | return ilookup5(sb, hash, iget_test, &data); | ||
83 | } | ||
84 | |||
85 | static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr, | ||
86 | int non_block) | ||
87 | { | ||
88 | struct gfs2_skip_data data; | ||
89 | unsigned long hash = (unsigned long)no_addr; | ||
90 | |||
91 | data.no_addr = no_addr; | ||
92 | data.skipped = 0; | ||
93 | data.non_block = non_block; | ||
94 | return iget5_locked(sb, hash, iget_test, iget_set, &data); | ||
95 | } | ||
37 | 96 | ||
38 | /** | 97 | /** |
98 | * gfs2_set_iop - Sets inode operations | ||
99 | * @inode: The inode with correct i_mode filled in | ||
100 | * | ||
101 | * GFS2 lookup code fills in vfs inode contents based on info obtained | ||
102 | * from directory entry inside gfs2_inode_lookup(). | ||
103 | */ | ||
104 | |||
105 | static void gfs2_set_iop(struct inode *inode) | ||
106 | { | ||
107 | struct gfs2_sbd *sdp = GFS2_SB(inode); | ||
108 | umode_t mode = inode->i_mode; | ||
109 | |||
110 | if (S_ISREG(mode)) { | ||
111 | inode->i_op = &gfs2_file_iops; | ||
112 | if (gfs2_localflocks(sdp)) | ||
113 | inode->i_fop = &gfs2_file_fops_nolock; | ||
114 | else | ||
115 | inode->i_fop = &gfs2_file_fops; | ||
116 | } else if (S_ISDIR(mode)) { | ||
117 | inode->i_op = &gfs2_dir_iops; | ||
118 | if (gfs2_localflocks(sdp)) | ||
119 | inode->i_fop = &gfs2_dir_fops_nolock; | ||
120 | else | ||
121 | inode->i_fop = &gfs2_dir_fops; | ||
122 | } else if (S_ISLNK(mode)) { | ||
123 | inode->i_op = &gfs2_symlink_iops; | ||
124 | } else { | ||
125 | inode->i_op = &gfs2_file_iops; | ||
126 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * gfs2_inode_lookup - Lookup an inode | ||
132 | * @sb: The super block | ||
133 | * @no_addr: The inode number | ||
134 | * @type: The type of the inode | ||
135 | * non_block: Can we block on inodes that are being freed? | ||
136 | * | ||
137 | * Returns: A VFS inode, or an error | ||
138 | */ | ||
139 | |||
140 | struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type, | ||
141 | u64 no_addr, u64 no_formal_ino, int non_block) | ||
142 | { | ||
143 | struct inode *inode; | ||
144 | struct gfs2_inode *ip; | ||
145 | struct gfs2_glock *io_gl = NULL; | ||
146 | int error; | ||
147 | |||
148 | inode = gfs2_iget(sb, no_addr, non_block); | ||
149 | ip = GFS2_I(inode); | ||
150 | |||
151 | if (!inode) | ||
152 | return ERR_PTR(-ENOBUFS); | ||
153 | |||
154 | if (inode->i_state & I_NEW) { | ||
155 | struct gfs2_sbd *sdp = GFS2_SB(inode); | ||
156 | ip->i_no_formal_ino = no_formal_ino; | ||
157 | |||
158 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); | ||
159 | if (unlikely(error)) | ||
160 | goto fail; | ||
161 | ip->i_gl->gl_object = ip; | ||
162 | |||
163 | error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); | ||
164 | if (unlikely(error)) | ||
165 | goto fail_put; | ||
166 | |||
167 | set_bit(GIF_INVALID, &ip->i_flags); | ||
168 | error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); | ||
169 | if (unlikely(error)) | ||
170 | goto fail_iopen; | ||
171 | |||
172 | ip->i_iopen_gh.gh_gl->gl_object = ip; | ||
173 | gfs2_glock_put(io_gl); | ||
174 | io_gl = NULL; | ||
175 | |||
176 | if (type == DT_UNKNOWN) { | ||
177 | /* Inode glock must be locked already */ | ||
178 | error = gfs2_inode_refresh(GFS2_I(inode)); | ||
179 | if (error) | ||
180 | goto fail_refresh; | ||
181 | } else { | ||
182 | inode->i_mode = DT2IF(type); | ||
183 | } | ||
184 | |||
185 | gfs2_set_iop(inode); | ||
186 | unlock_new_inode(inode); | ||
187 | } | ||
188 | |||
189 | return inode; | ||
190 | |||
191 | fail_refresh: | ||
192 | ip->i_iopen_gh.gh_gl->gl_object = NULL; | ||
193 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); | ||
194 | fail_iopen: | ||
195 | if (io_gl) | ||
196 | gfs2_glock_put(io_gl); | ||
197 | fail_put: | ||
198 | ip->i_gl->gl_object = NULL; | ||
199 | gfs2_glock_put(ip->i_gl); | ||
200 | fail: | ||
201 | iget_failed(inode); | ||
202 | return ERR_PTR(error); | ||
203 | } | ||
204 | |||
205 | struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr, | ||
206 | u64 *no_formal_ino, unsigned int blktype) | ||
207 | { | ||
208 | struct super_block *sb = sdp->sd_vfs; | ||
209 | struct gfs2_holder i_gh; | ||
210 | struct inode *inode = NULL; | ||
211 | int error; | ||
212 | |||
213 | /* Must not read in block until block type is verified */ | ||
214 | error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops, | ||
215 | LM_ST_EXCLUSIVE, GL_SKIP, &i_gh); | ||
216 | if (error) | ||
217 | return ERR_PTR(error); | ||
218 | |||
219 | error = gfs2_check_blk_type(sdp, no_addr, blktype); | ||
220 | if (error) | ||
221 | goto fail; | ||
222 | |||
223 | inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0, 1); | ||
224 | if (IS_ERR(inode)) | ||
225 | goto fail; | ||
226 | |||
227 | /* Two extra checks for NFS only */ | ||
228 | if (no_formal_ino) { | ||
229 | error = -ESTALE; | ||
230 | if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino) | ||
231 | goto fail_iput; | ||
232 | |||
233 | error = -EIO; | ||
234 | if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM) | ||
235 | goto fail_iput; | ||
236 | |||
237 | error = 0; | ||
238 | } | ||
239 | |||
240 | fail: | ||
241 | gfs2_glock_dq_uninit(&i_gh); | ||
242 | return error ? ERR_PTR(error) : inode; | ||
243 | fail_iput: | ||
244 | iput(inode); | ||
245 | goto fail; | ||
246 | } | ||
247 | |||
248 | |||
249 | struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) | ||
250 | { | ||
251 | struct qstr qstr; | ||
252 | struct inode *inode; | ||
253 | gfs2_str2qstr(&qstr, name); | ||
254 | inode = gfs2_lookupi(dip, &qstr, 1); | ||
255 | /* gfs2_lookupi has inconsistent callers: vfs | ||
256 | * related routines expect NULL for no entry found, | ||
257 | * gfs2_lookup_simple callers expect ENOENT | ||
258 | * and do not check for NULL. | ||
259 | */ | ||
260 | if (inode == NULL) | ||
261 | return ERR_PTR(-ENOENT); | ||
262 | else | ||
263 | return inode; | ||
264 | } | ||
265 | |||
266 | |||
267 | /** | ||
268 | * gfs2_lookupi - Look up a filename in a directory and return its inode | ||
269 | * @d_gh: An initialized holder for the directory glock | ||
270 | * @name: The name of the inode to look for | ||
271 | * @is_root: If 1, ignore the caller's permissions | ||
272 | * @i_gh: An uninitialized holder for the new inode glock | ||
273 | * | ||
274 | * This can be called via the VFS filldir function when NFS is doing | ||
275 | * a readdirplus and the inode which its intending to stat isn't | ||
276 | * already in cache. In this case we must not take the directory glock | ||
277 | * again, since the readdir call will have already taken that lock. | ||
278 | * | ||
279 | * Returns: errno | ||
280 | */ | ||
281 | |||
282 | struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, | ||
283 | int is_root) | ||
284 | { | ||
285 | struct super_block *sb = dir->i_sb; | ||
286 | struct gfs2_inode *dip = GFS2_I(dir); | ||
287 | struct gfs2_holder d_gh; | ||
288 | int error = 0; | ||
289 | struct inode *inode = NULL; | ||
290 | int unlock = 0; | ||
291 | |||
292 | if (!name->len || name->len > GFS2_FNAMESIZE) | ||
293 | return ERR_PTR(-ENAMETOOLONG); | ||
294 | |||
295 | if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || | ||
296 | (name->len == 2 && memcmp(name->name, "..", 2) == 0 && | ||
297 | dir == sb->s_root->d_inode)) { | ||
298 | igrab(dir); | ||
299 | return dir; | ||
300 | } | ||
301 | |||
302 | if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) { | ||
303 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); | ||
304 | if (error) | ||
305 | return ERR_PTR(error); | ||
306 | unlock = 1; | ||
307 | } | ||
308 | |||
309 | if (!is_root) { | ||
310 | error = gfs2_permission(dir, MAY_EXEC, 0); | ||
311 | if (error) | ||
312 | goto out; | ||
313 | } | ||
314 | |||
315 | inode = gfs2_dir_search(dir, name); | ||
316 | if (IS_ERR(inode)) | ||
317 | error = PTR_ERR(inode); | ||
318 | out: | ||
319 | if (unlock) | ||
320 | gfs2_glock_dq_uninit(&d_gh); | ||
321 | if (error == -ENOENT) | ||
322 | return NULL; | ||
323 | return inode ? inode : ERR_PTR(error); | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * create_ok - OK to create a new on-disk inode here? | ||
328 | * @dip: Directory in which dinode is to be created | ||
329 | * @name: Name of new dinode | ||
330 | * @mode: | ||
331 | * | ||
332 | * Returns: errno | ||
333 | */ | ||
334 | |||
335 | static int create_ok(struct gfs2_inode *dip, const struct qstr *name, | ||
336 | unsigned int mode) | ||
337 | { | ||
338 | int error; | ||
339 | |||
340 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, 0); | ||
341 | if (error) | ||
342 | return error; | ||
343 | |||
344 | /* Don't create entries in an unlinked directory */ | ||
345 | if (!dip->i_inode.i_nlink) | ||
346 | return -ENOENT; | ||
347 | |||
348 | error = gfs2_dir_check(&dip->i_inode, name, NULL); | ||
349 | switch (error) { | ||
350 | case -ENOENT: | ||
351 | error = 0; | ||
352 | break; | ||
353 | case 0: | ||
354 | return -EEXIST; | ||
355 | default: | ||
356 | return error; | ||
357 | } | ||
358 | |||
359 | if (dip->i_entries == (u32)-1) | ||
360 | return -EFBIG; | ||
361 | if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1) | ||
362 | return -EMLINK; | ||
363 | |||
364 | return 0; | ||
365 | } | ||
366 | |||
367 | static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, | ||
368 | unsigned int *uid, unsigned int *gid) | ||
369 | { | ||
370 | if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir && | ||
371 | (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) { | ||
372 | if (S_ISDIR(*mode)) | ||
373 | *mode |= S_ISUID; | ||
374 | else if (dip->i_inode.i_uid != current_fsuid()) | ||
375 | *mode &= ~07111; | ||
376 | *uid = dip->i_inode.i_uid; | ||
377 | } else | ||
378 | *uid = current_fsuid(); | ||
379 | |||
380 | if (dip->i_inode.i_mode & S_ISGID) { | ||
381 | if (S_ISDIR(*mode)) | ||
382 | *mode |= S_ISGID; | ||
383 | *gid = dip->i_inode.i_gid; | ||
384 | } else | ||
385 | *gid = current_fsgid(); | ||
386 | } | ||
387 | |||
388 | static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation) | ||
389 | { | ||
390 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | ||
391 | int error; | ||
392 | |||
393 | if (gfs2_alloc_get(dip) == NULL) | ||
394 | return -ENOMEM; | ||
395 | |||
396 | dip->i_alloc->al_requested = RES_DINODE; | ||
397 | error = gfs2_inplace_reserve(dip); | ||
398 | if (error) | ||
399 | goto out; | ||
400 | |||
401 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0); | ||
402 | if (error) | ||
403 | goto out_ipreserv; | ||
404 | |||
405 | error = gfs2_alloc_di(dip, no_addr, generation); | ||
406 | |||
407 | gfs2_trans_end(sdp); | ||
408 | |||
409 | out_ipreserv: | ||
410 | gfs2_inplace_release(dip); | ||
411 | out: | ||
412 | gfs2_alloc_put(dip); | ||
413 | return error; | ||
414 | } | ||
415 | |||
416 | /** | ||
417 | * init_dinode - Fill in a new dinode structure | ||
418 | * @dip: the directory this inode is being created in | ||
419 | * @gl: The glock covering the new inode | ||
420 | * @inum: the inode number | ||
421 | * @mode: the file permissions | ||
422 | * @uid: | ||
423 | * @gid: | ||
424 | * | ||
425 | */ | ||
426 | |||
427 | static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, | ||
428 | const struct gfs2_inum_host *inum, unsigned int mode, | ||
429 | unsigned int uid, unsigned int gid, | ||
430 | const u64 *generation, dev_t dev, struct buffer_head **bhp) | ||
431 | { | ||
432 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | ||
433 | struct gfs2_dinode *di; | ||
434 | struct buffer_head *dibh; | ||
435 | struct timespec tv = CURRENT_TIME; | ||
436 | |||
437 | dibh = gfs2_meta_new(gl, inum->no_addr); | ||
438 | gfs2_trans_add_bh(gl, dibh, 1); | ||
439 | gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); | ||
440 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); | ||
441 | di = (struct gfs2_dinode *)dibh->b_data; | ||
442 | |||
443 | di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino); | ||
444 | di->di_num.no_addr = cpu_to_be64(inum->no_addr); | ||
445 | di->di_mode = cpu_to_be32(mode); | ||
446 | di->di_uid = cpu_to_be32(uid); | ||
447 | di->di_gid = cpu_to_be32(gid); | ||
448 | di->di_nlink = 0; | ||
449 | di->di_size = 0; | ||
450 | di->di_blocks = cpu_to_be64(1); | ||
451 | di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec); | ||
452 | di->di_major = cpu_to_be32(MAJOR(dev)); | ||
453 | di->di_minor = cpu_to_be32(MINOR(dev)); | ||
454 | di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr); | ||
455 | di->di_generation = cpu_to_be64(*generation); | ||
456 | di->di_flags = 0; | ||
457 | |||
458 | if (S_ISREG(mode)) { | ||
459 | if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) || | ||
460 | gfs2_tune_get(sdp, gt_new_files_jdata)) | ||
461 | di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA); | ||
462 | } else if (S_ISDIR(mode)) { | ||
463 | di->di_flags |= cpu_to_be32(dip->i_diskflags & | ||
464 | GFS2_DIF_INHERIT_JDATA); | ||
465 | } | ||
466 | |||
467 | di->__pad1 = 0; | ||
468 | di->di_payload_format = cpu_to_be32(S_ISDIR(mode) ? GFS2_FORMAT_DE : 0); | ||
469 | di->di_height = 0; | ||
470 | di->__pad2 = 0; | ||
471 | di->__pad3 = 0; | ||
472 | di->di_depth = 0; | ||
473 | di->di_entries = 0; | ||
474 | memset(&di->__pad4, 0, sizeof(di->__pad4)); | ||
475 | di->di_eattr = 0; | ||
476 | di->di_atime_nsec = cpu_to_be32(tv.tv_nsec); | ||
477 | di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec); | ||
478 | di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec); | ||
479 | memset(&di->di_reserved, 0, sizeof(di->di_reserved)); | ||
480 | |||
481 | set_buffer_uptodate(dibh); | ||
482 | |||
483 | *bhp = dibh; | ||
484 | } | ||
485 | |||
486 | static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, | ||
487 | unsigned int mode, const struct gfs2_inum_host *inum, | ||
488 | const u64 *generation, dev_t dev, struct buffer_head **bhp) | ||
489 | { | ||
490 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | ||
491 | unsigned int uid, gid; | ||
492 | int error; | ||
493 | |||
494 | munge_mode_uid_gid(dip, &mode, &uid, &gid); | ||
495 | if (!gfs2_alloc_get(dip)) | ||
496 | return -ENOMEM; | ||
497 | |||
498 | error = gfs2_quota_lock(dip, uid, gid); | ||
499 | if (error) | ||
500 | goto out; | ||
501 | |||
502 | error = gfs2_quota_check(dip, uid, gid); | ||
503 | if (error) | ||
504 | goto out_quota; | ||
505 | |||
506 | error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0); | ||
507 | if (error) | ||
508 | goto out_quota; | ||
509 | |||
510 | init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, bhp); | ||
511 | gfs2_quota_change(dip, +1, uid, gid); | ||
512 | gfs2_trans_end(sdp); | ||
513 | |||
514 | out_quota: | ||
515 | gfs2_quota_unlock(dip); | ||
516 | out: | ||
517 | gfs2_alloc_put(dip); | ||
518 | return error; | ||
519 | } | ||
520 | |||
521 | static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, | ||
522 | struct gfs2_inode *ip) | ||
523 | { | ||
524 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | ||
525 | struct gfs2_alloc *al; | ||
526 | int alloc_required; | ||
527 | struct buffer_head *dibh; | ||
528 | int error; | ||
529 | |||
530 | al = gfs2_alloc_get(dip); | ||
531 | if (!al) | ||
532 | return -ENOMEM; | ||
533 | |||
534 | error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); | ||
535 | if (error) | ||
536 | goto fail; | ||
537 | |||
538 | error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); | ||
539 | if (alloc_required < 0) | ||
540 | goto fail_quota_locks; | ||
541 | if (alloc_required) { | ||
542 | error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); | ||
543 | if (error) | ||
544 | goto fail_quota_locks; | ||
545 | |||
546 | al->al_requested = sdp->sd_max_dirres; | ||
547 | |||
548 | error = gfs2_inplace_reserve(dip); | ||
549 | if (error) | ||
550 | goto fail_quota_locks; | ||
551 | |||
552 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | ||
553 | al->al_rgd->rd_length + | ||
554 | 2 * RES_DINODE + | ||
555 | RES_STATFS + RES_QUOTA, 0); | ||
556 | if (error) | ||
557 | goto fail_ipreserv; | ||
558 | } else { | ||
559 | error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0); | ||
560 | if (error) | ||
561 | goto fail_quota_locks; | ||
562 | } | ||
563 | |||
564 | error = gfs2_dir_add(&dip->i_inode, name, ip); | ||
565 | if (error) | ||
566 | goto fail_end_trans; | ||
567 | |||
568 | error = gfs2_meta_inode_buffer(ip, &dibh); | ||
569 | if (error) | ||
570 | goto fail_end_trans; | ||
571 | ip->i_inode.i_nlink = 1; | ||
572 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | ||
573 | gfs2_dinode_out(ip, dibh->b_data); | ||
574 | brelse(dibh); | ||
575 | return 0; | ||
576 | |||
577 | fail_end_trans: | ||
578 | gfs2_trans_end(sdp); | ||
579 | |||
580 | fail_ipreserv: | ||
581 | if (dip->i_alloc->al_rgd) | ||
582 | gfs2_inplace_release(dip); | ||
583 | |||
584 | fail_quota_locks: | ||
585 | gfs2_quota_unlock(dip); | ||
586 | |||
587 | fail: | ||
588 | gfs2_alloc_put(dip); | ||
589 | return error; | ||
590 | } | ||
591 | |||
592 | static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip, | ||
593 | const struct qstr *qstr) | ||
594 | { | ||
595 | int err; | ||
596 | size_t len; | ||
597 | void *value; | ||
598 | char *name; | ||
599 | |||
600 | err = security_inode_init_security(&ip->i_inode, &dip->i_inode, qstr, | ||
601 | &name, &value, &len); | ||
602 | |||
603 | if (err) { | ||
604 | if (err == -EOPNOTSUPP) | ||
605 | return 0; | ||
606 | return err; | ||
607 | } | ||
608 | |||
609 | err = __gfs2_xattr_set(&ip->i_inode, name, value, len, 0, | ||
610 | GFS2_EATYPE_SECURITY); | ||
611 | kfree(value); | ||
612 | kfree(name); | ||
613 | |||
614 | return err; | ||
615 | } | ||
616 | |||
617 | /** | ||
618 | * gfs2_createi - Create a new inode | ||
619 | * @ghs: An array of two holders | ||
620 | * @name: The name of the new file | ||
621 | * @mode: the permissions on the new inode | ||
622 | * | ||
623 | * @ghs[0] is an initialized holder for the directory | ||
624 | * @ghs[1] is the holder for the inode lock | ||
625 | * | ||
626 | * If the return value is not NULL, the glocks on both the directory and the new | ||
627 | * file are held. A transaction has been started and an inplace reservation | ||
628 | * is held, as well. | ||
629 | * | ||
630 | * Returns: An inode | ||
631 | */ | ||
632 | |||
633 | struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, | ||
634 | unsigned int mode, dev_t dev) | ||
635 | { | ||
636 | struct inode *inode = NULL; | ||
637 | struct gfs2_inode *dip = ghs->gh_gl->gl_object; | ||
638 | struct inode *dir = &dip->i_inode; | ||
639 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | ||
640 | struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; | ||
641 | int error; | ||
642 | u64 generation; | ||
643 | struct buffer_head *bh = NULL; | ||
644 | |||
645 | if (!name->len || name->len > GFS2_FNAMESIZE) | ||
646 | return ERR_PTR(-ENAMETOOLONG); | ||
647 | |||
648 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); | ||
649 | error = gfs2_glock_nq(ghs); | ||
650 | if (error) | ||
651 | goto fail; | ||
652 | |||
653 | error = create_ok(dip, name, mode); | ||
654 | if (error) | ||
655 | goto fail_gunlock; | ||
656 | |||
657 | error = alloc_dinode(dip, &inum.no_addr, &generation); | ||
658 | if (error) | ||
659 | goto fail_gunlock; | ||
660 | inum.no_formal_ino = generation; | ||
661 | |||
662 | error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops, | ||
663 | LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); | ||
664 | if (error) | ||
665 | goto fail_gunlock; | ||
666 | |||
667 | error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, &bh); | ||
668 | if (error) | ||
669 | goto fail_gunlock2; | ||
670 | |||
671 | inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode), inum.no_addr, | ||
672 | inum.no_formal_ino, 0); | ||
673 | if (IS_ERR(inode)) | ||
674 | goto fail_gunlock2; | ||
675 | |||
676 | error = gfs2_inode_refresh(GFS2_I(inode)); | ||
677 | if (error) | ||
678 | goto fail_gunlock2; | ||
679 | |||
680 | error = gfs2_acl_create(dip, inode); | ||
681 | if (error) | ||
682 | goto fail_gunlock2; | ||
683 | |||
684 | error = gfs2_security_init(dip, GFS2_I(inode), name); | ||
685 | if (error) | ||
686 | goto fail_gunlock2; | ||
687 | |||
688 | error = link_dinode(dip, name, GFS2_I(inode)); | ||
689 | if (error) | ||
690 | goto fail_gunlock2; | ||
691 | |||
692 | if (bh) | ||
693 | brelse(bh); | ||
694 | return inode; | ||
695 | |||
696 | fail_gunlock2: | ||
697 | gfs2_glock_dq_uninit(ghs + 1); | ||
698 | if (inode && !IS_ERR(inode)) | ||
699 | iput(inode); | ||
700 | fail_gunlock: | ||
701 | gfs2_glock_dq(ghs); | ||
702 | fail: | ||
703 | if (bh) | ||
704 | brelse(bh); | ||
705 | return ERR_PTR(error); | ||
706 | } | ||
707 | /** | ||
39 | * gfs2_create - Create a file | 708 | * gfs2_create - Create a file |
40 | * @dir: The directory in which to create the file | 709 | * @dir: The directory in which to create the file |
41 | * @dentry: The dentry of the new file | 710 | * @dentry: The dentry of the new file |
@@ -1000,6 +1669,48 @@ int gfs2_permission(struct inode *inode, int mask, unsigned int flags) | |||
1000 | return error; | 1669 | return error; |
1001 | } | 1670 | } |
1002 | 1671 | ||
1672 | static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) | ||
1673 | { | ||
1674 | struct inode *inode = &ip->i_inode; | ||
1675 | struct buffer_head *dibh; | ||
1676 | int error; | ||
1677 | |||
1678 | error = gfs2_meta_inode_buffer(ip, &dibh); | ||
1679 | if (error) | ||
1680 | return error; | ||
1681 | |||
1682 | setattr_copy(inode, attr); | ||
1683 | mark_inode_dirty(inode); | ||
1684 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | ||
1685 | gfs2_dinode_out(ip, dibh->b_data); | ||
1686 | brelse(dibh); | ||
1687 | return 0; | ||
1688 | } | ||
1689 | |||
1690 | /** | ||
1691 | * gfs2_setattr_simple - | ||
1692 | * @ip: | ||
1693 | * @attr: | ||
1694 | * | ||
1695 | * Returns: errno | ||
1696 | */ | ||
1697 | |||
1698 | int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) | ||
1699 | { | ||
1700 | int error; | ||
1701 | |||
1702 | if (current->journal_info) | ||
1703 | return __gfs2_setattr_simple(ip, attr); | ||
1704 | |||
1705 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0); | ||
1706 | if (error) | ||
1707 | return error; | ||
1708 | |||
1709 | error = __gfs2_setattr_simple(ip, attr); | ||
1710 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); | ||
1711 | return error; | ||
1712 | } | ||
1713 | |||
1003 | static int setattr_chown(struct inode *inode, struct iattr *attr) | 1714 | static int setattr_chown(struct inode *inode, struct iattr *attr) |
1004 | { | 1715 | { |
1005 | struct gfs2_inode *ip = GFS2_I(inode); | 1716 | struct gfs2_inode *ip = GFS2_I(inode); |