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