GFS2: Move gfs2_refresh_inode() and friends into glops.c
[deliverable/linux.git] / fs / gfs2 / inode.c
1 /*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/posix_acl.h>
16 #include <linux/sort.h>
17 #include <linux/gfs2_ondisk.h>
18 #include <linux/crc32.h>
19 #include <linux/security.h>
20 #include <linux/time.h>
21
22 #include "gfs2.h"
23 #include "incore.h"
24 #include "acl.h"
25 #include "bmap.h"
26 #include "dir.h"
27 #include "xattr.h"
28 #include "glock.h"
29 #include "glops.h"
30 #include "inode.h"
31 #include "log.h"
32 #include "meta_io.h"
33 #include "quota.h"
34 #include "rgrp.h"
35 #include "trans.h"
36 #include "util.h"
37
38 struct gfs2_skip_data {
39 u64 no_addr;
40 int skipped;
41 int non_block;
42 };
43
44 static 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
60 static 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
72 struct 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
83 static 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
103 static 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
138 struct 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
189 fail_refresh:
190 ip->i_iopen_gh.gh_gl->gl_object = NULL;
191 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
192 fail_iopen:
193 if (io_gl)
194 gfs2_glock_put(io_gl);
195 fail_put:
196 ip->i_gl->gl_object = NULL;
197 gfs2_glock_put(ip->i_gl);
198 fail:
199 iget_failed(inode);
200 return ERR_PTR(error);
201 }
202
203 struct 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
238 fail:
239 gfs2_glock_dq_uninit(&i_gh);
240 return error ? ERR_PTR(error) : inode;
241 fail_iput:
242 iput(inode);
243 goto fail;
244 }
245
246
247 struct 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
280 struct 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);
316 out:
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
333 static 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
365 static 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
386 static 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
407 out_ipreserv:
408 gfs2_inplace_release(dip);
409 out:
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
425 static 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
484 static 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
512 out_quota:
513 gfs2_quota_unlock(dip);
514 out:
515 gfs2_alloc_put(dip);
516 return error;
517 }
518
519 static 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
575 fail_end_trans:
576 gfs2_trans_end(sdp);
577
578 fail_ipreserv:
579 if (dip->i_alloc->al_rgd)
580 gfs2_inplace_release(dip);
581
582 fail_quota_locks:
583 gfs2_quota_unlock(dip);
584
585 fail:
586 gfs2_alloc_put(dip);
587 return error;
588 }
589
590 static 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
631 struct 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
694 fail_gunlock2:
695 gfs2_glock_dq_uninit(ghs + 1);
696 if (inode && !IS_ERR(inode))
697 iput(inode);
698 fail_gunlock:
699 gfs2_glock_dq(ghs);
700 fail:
701 if (bh)
702 brelse(bh);
703 return ERR_PTR(error);
704 }
705
706 static 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
734 int 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
750 void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
751 {
752 struct gfs2_dinode *str = buf;
753
754 str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
755 str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI);
756 str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI);
757 str->di_num.no_addr = cpu_to_be64(ip->i_no_addr);
758 str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
759 str->di_mode = cpu_to_be32(ip->i_inode.i_mode);
760 str->di_uid = cpu_to_be32(ip->i_inode.i_uid);
761 str->di_gid = cpu_to_be32(ip->i_inode.i_gid);
762 str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink);
763 str->di_size = cpu_to_be64(i_size_read(&ip->i_inode));
764 str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
765 str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec);
766 str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec);
767 str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec);
768
769 str->di_goal_meta = cpu_to_be64(ip->i_goal);
770 str->di_goal_data = cpu_to_be64(ip->i_goal);
771 str->di_generation = cpu_to_be64(ip->i_generation);
772
773 str->di_flags = cpu_to_be32(ip->i_diskflags);
774 str->di_height = cpu_to_be16(ip->i_height);
775 str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) &&
776 !(ip->i_diskflags & GFS2_DIF_EXHASH) ?
777 GFS2_FORMAT_DE : 0);
778 str->di_depth = cpu_to_be16(ip->i_depth);
779 str->di_entries = cpu_to_be32(ip->i_entries);
780
781 str->di_eattr = cpu_to_be64(ip->i_eattr);
782 str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec);
783 str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec);
784 str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec);
785 }
This page took 0.046356 seconds and 5 git commands to generate.