2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
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.
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>
38 struct gfs2_inum_range_host {
43 static int iget_test(struct inode *inode, void *opaque)
45 struct gfs2_inode *ip = GFS2_I(inode);
46 u64 *no_addr = opaque;
48 if (ip->i_no_addr == *no_addr)
54 static int iget_set(struct inode *inode, void *opaque)
56 struct gfs2_inode *ip = GFS2_I(inode);
57 u64 *no_addr = opaque;
59 inode->i_ino = (unsigned long)*no_addr;
60 ip->i_no_addr = *no_addr;
64 struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr)
66 unsigned long hash = (unsigned long)no_addr;
67 return ilookup5(sb, hash, iget_test, &no_addr);
70 static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
72 unsigned long hash = (unsigned long)no_addr;
73 return iget5_locked(sb, hash, iget_test, iget_set, &no_addr);
77 * GFS2 lookup code fills in vfs inode contents based on info obtained
78 * from directory entry inside gfs2_inode_lookup(). This has caused issues
79 * with NFS code path since its get_dentry routine doesn't have the relevant
80 * directory entry when gfs2_inode_lookup() is invoked. Part of the code
81 * segment inside gfs2_inode_lookup code needs to get moved around.
83 * Clears I_NEW as well.
86 void gfs2_set_iop(struct inode *inode)
88 struct gfs2_sbd *sdp = GFS2_SB(inode);
89 umode_t mode = inode->i_mode;
92 inode->i_op = &gfs2_file_iops;
93 if (gfs2_localflocks(sdp))
94 inode->i_fop = &gfs2_file_fops_nolock;
96 inode->i_fop = &gfs2_file_fops;
97 } else if (S_ISDIR(mode)) {
98 inode->i_op = &gfs2_dir_iops;
99 if (gfs2_localflocks(sdp))
100 inode->i_fop = &gfs2_dir_fops_nolock;
102 inode->i_fop = &gfs2_dir_fops;
103 } else if (S_ISLNK(mode)) {
104 inode->i_op = &gfs2_symlink_iops;
106 inode->i_op = &gfs2_file_iops;
107 init_special_inode(inode, inode->i_mode, inode->i_rdev);
110 unlock_new_inode(inode);
114 * gfs2_inode_lookup - Lookup an inode
115 * @sb: The super block
116 * @no_addr: The inode number
117 * @type: The type of the inode
119 * Returns: A VFS inode, or an error
122 struct inode *gfs2_inode_lookup(struct super_block *sb,
128 struct gfs2_inode *ip;
129 struct gfs2_glock *io_gl = NULL;
132 inode = gfs2_iget(sb, no_addr);
136 return ERR_PTR(-ENOBUFS);
138 if (inode->i_state & I_NEW) {
139 struct gfs2_sbd *sdp = GFS2_SB(inode);
140 ip->i_no_formal_ino = no_formal_ino;
142 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
145 ip->i_gl->gl_object = ip;
147 error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
151 set_bit(GIF_INVALID, &ip->i_flags);
152 error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
155 ip->i_iopen_gh.gh_gl->gl_object = ip;
157 gfs2_glock_put(io_gl);
160 if ((type == DT_UNKNOWN) && (no_formal_ino == 0))
163 inode->i_mode = DT2IF(type);
166 * We must read the inode in order to work out its type in
167 * this case. Note that this doesn't happen often as we normally
168 * know the type beforehand. This code path only occurs during
169 * unlinked inode recovery (where it is safe to do this glock,
170 * which is not true in the general case).
172 if (type == DT_UNKNOWN) {
173 struct gfs2_holder gh;
174 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
177 /* Inode is now uptodate */
178 gfs2_glock_dq_uninit(&gh);
187 gfs2_glock_dq(&ip->i_iopen_gh);
190 gfs2_glock_put(io_gl);
192 if (inode->i_state & I_NEW)
193 ip->i_gl->gl_object = NULL;
194 gfs2_glock_put(ip->i_gl);
196 if (inode->i_state & I_NEW)
200 return ERR_PTR(error);
203 struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
204 u64 *no_formal_ino, unsigned int blktype)
206 struct super_block *sb = sdp->sd_vfs;
207 struct gfs2_holder i_gh;
211 error = gfs2_glock_nq_num(sdp, no_addr, &gfs2_inode_glops,
212 LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
214 return ERR_PTR(error);
216 error = gfs2_check_blk_type(sdp, no_addr, blktype);
220 inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0);
224 error = gfs2_inode_refresh(GFS2_I(inode));
228 /* Pick up the works we bypass in gfs2_inode_lookup */
229 if (inode->i_state & I_NEW)
232 /* Two extra checks for NFS only */
235 if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)
239 if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
246 gfs2_glock_dq_uninit(&i_gh);
247 return error ? ERR_PTR(error) : inode;
253 static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
255 const struct gfs2_dinode *str = buf;
256 struct timespec atime;
259 if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr)))
261 ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino);
262 ip->i_inode.i_mode = be32_to_cpu(str->di_mode);
263 ip->i_inode.i_rdev = 0;
264 switch (ip->i_inode.i_mode & S_IFMT) {
267 ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major),
268 be32_to_cpu(str->di_minor));
272 ip->i_inode.i_uid = be32_to_cpu(str->di_uid);
273 ip->i_inode.i_gid = be32_to_cpu(str->di_gid);
275 * We will need to review setting the nlink count here in the
276 * light of the forthcoming ro bind mount work. This is a reminder
279 ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink);
280 i_size_write(&ip->i_inode, be64_to_cpu(str->di_size));
281 gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks));
282 atime.tv_sec = be64_to_cpu(str->di_atime);
283 atime.tv_nsec = be32_to_cpu(str->di_atime_nsec);
284 if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0)
285 ip->i_inode.i_atime = atime;
286 ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime);
287 ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec);
288 ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime);
289 ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec);
291 ip->i_goal = be64_to_cpu(str->di_goal_meta);
292 ip->i_generation = be64_to_cpu(str->di_generation);
294 ip->i_diskflags = be32_to_cpu(str->di_flags);
295 gfs2_set_inode_flags(&ip->i_inode);
296 height = be16_to_cpu(str->di_height);
297 if (unlikely(height > GFS2_MAX_META_HEIGHT))
299 ip->i_height = (u8)height;
301 depth = be16_to_cpu(str->di_depth);
302 if (unlikely(depth > GFS2_DIR_MAX_DEPTH))
304 ip->i_depth = (u8)depth;
305 ip->i_entries = be32_to_cpu(str->di_entries);
307 ip->i_eattr = be64_to_cpu(str->di_eattr);
308 if (S_ISREG(ip->i_inode.i_mode))
309 gfs2_set_aops(&ip->i_inode);
313 if (gfs2_consist_inode(ip))
314 gfs2_dinode_print(ip);
319 * gfs2_inode_refresh - Refresh the incore copy of the dinode
320 * @ip: The GFS2 inode
325 int gfs2_inode_refresh(struct gfs2_inode *ip)
327 struct buffer_head *dibh;
330 error = gfs2_meta_inode_buffer(ip, &dibh);
334 if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) {
339 error = gfs2_dinode_in(ip, dibh->b_data);
341 clear_bit(GIF_INVALID, &ip->i_flags);
346 int gfs2_dinode_dealloc(struct gfs2_inode *ip)
348 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
349 struct gfs2_alloc *al;
350 struct gfs2_rgrpd *rgd;
353 if (gfs2_get_inode_blocks(&ip->i_inode) != 1) {
354 if (gfs2_consist_inode(ip))
355 gfs2_dinode_print(ip);
359 al = gfs2_alloc_get(ip);
363 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
367 error = gfs2_rindex_hold(sdp, &al->al_ri_gh);
371 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
373 gfs2_consist_inode(ip);
375 goto out_rindex_relse;
378 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0,
381 goto out_rindex_relse;
383 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1);
387 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
388 set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags);
390 gfs2_free_di(rgd, ip);
395 gfs2_glock_dq_uninit(&al->al_rgd_gh);
397 gfs2_glock_dq_uninit(&al->al_ri_gh);
399 gfs2_quota_unhold(ip);
406 * gfs2_change_nlink - Change nlink count on inode
407 * @ip: The GFS2 inode
408 * @diff: The change in the nlink count required
412 int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
414 struct buffer_head *dibh;
418 BUG_ON(diff != 1 && diff != -1);
419 nlink = ip->i_inode.i_nlink + diff;
421 /* If we are reducing the nlink count, but the new value ends up being
422 bigger than the old one, we must have underflowed. */
423 if (diff < 0 && nlink > ip->i_inode.i_nlink) {
424 if (gfs2_consist_inode(ip))
425 gfs2_dinode_print(ip);
429 error = gfs2_meta_inode_buffer(ip, &dibh);
434 inc_nlink(&ip->i_inode);
436 drop_nlink(&ip->i_inode);
438 ip->i_inode.i_ctime = CURRENT_TIME;
440 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
441 gfs2_dinode_out(ip, dibh->b_data);
443 mark_inode_dirty(&ip->i_inode);
445 if (ip->i_inode.i_nlink == 0)
446 gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */
451 struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
455 gfs2_str2qstr(&qstr, name);
456 inode = gfs2_lookupi(dip, &qstr, 1);
457 /* gfs2_lookupi has inconsistent callers: vfs
458 * related routines expect NULL for no entry found,
459 * gfs2_lookup_simple callers expect ENOENT
460 * and do not check for NULL.
463 return ERR_PTR(-ENOENT);
470 * gfs2_lookupi - Look up a filename in a directory and return its inode
471 * @d_gh: An initialized holder for the directory glock
472 * @name: The name of the inode to look for
473 * @is_root: If 1, ignore the caller's permissions
474 * @i_gh: An uninitialized holder for the new inode glock
476 * This can be called via the VFS filldir function when NFS is doing
477 * a readdirplus and the inode which its intending to stat isn't
478 * already in cache. In this case we must not take the directory glock
479 * again, since the readdir call will have already taken that lock.
484 struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
487 struct super_block *sb = dir->i_sb;
488 struct gfs2_inode *dip = GFS2_I(dir);
489 struct gfs2_holder d_gh;
491 struct inode *inode = NULL;
494 if (!name->len || name->len > GFS2_FNAMESIZE)
495 return ERR_PTR(-ENAMETOOLONG);
497 if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
498 (name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
499 dir == sb->s_root->d_inode)) {
504 if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) {
505 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
507 return ERR_PTR(error);
512 error = gfs2_permission(dir, MAY_EXEC);
517 inode = gfs2_dir_search(dir, name);
519 error = PTR_ERR(inode);
522 gfs2_glock_dq_uninit(&d_gh);
523 if (error == -ENOENT)
525 return inode ? inode : ERR_PTR(error);
529 * create_ok - OK to create a new on-disk inode here?
530 * @dip: Directory in which dinode is to be created
531 * @name: Name of new dinode
537 static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
542 error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
546 /* Don't create entries in an unlinked directory */
547 if (!dip->i_inode.i_nlink)
550 error = gfs2_dir_check(&dip->i_inode, name, NULL);
561 if (dip->i_entries == (u32)-1)
563 if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1)
569 static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode,
570 unsigned int *uid, unsigned int *gid)
572 if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir &&
573 (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) {
576 else if (dip->i_inode.i_uid != current_fsuid())
578 *uid = dip->i_inode.i_uid;
580 *uid = current_fsuid();
582 if (dip->i_inode.i_mode & S_ISGID) {
585 *gid = dip->i_inode.i_gid;
587 *gid = current_fsgid();
590 static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
592 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
595 if (gfs2_alloc_get(dip) == NULL)
598 dip->i_alloc->al_requested = RES_DINODE;
599 error = gfs2_inplace_reserve(dip);
603 error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0);
607 error = gfs2_alloc_di(dip, no_addr, generation);
612 gfs2_inplace_release(dip);
619 * init_dinode - Fill in a new dinode structure
620 * @dip: the directory this inode is being created in
621 * @gl: The glock covering the new inode
622 * @inum: the inode number
623 * @mode: the file permissions
629 static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
630 const struct gfs2_inum_host *inum, unsigned int mode,
631 unsigned int uid, unsigned int gid,
632 const u64 *generation, dev_t dev, struct buffer_head **bhp)
634 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
635 struct gfs2_dinode *di;
636 struct buffer_head *dibh;
637 struct timespec tv = CURRENT_TIME;
639 dibh = gfs2_meta_new(gl, inum->no_addr);
640 gfs2_trans_add_bh(gl, dibh, 1);
641 gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI);
642 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
643 di = (struct gfs2_dinode *)dibh->b_data;
645 di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino);
646 di->di_num.no_addr = cpu_to_be64(inum->no_addr);
647 di->di_mode = cpu_to_be32(mode);
648 di->di_uid = cpu_to_be32(uid);
649 di->di_gid = cpu_to_be32(gid);
652 di->di_blocks = cpu_to_be64(1);
653 di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec);
654 di->di_major = cpu_to_be32(MAJOR(dev));
655 di->di_minor = cpu_to_be32(MINOR(dev));
656 di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr);
657 di->di_generation = cpu_to_be64(*generation);
661 if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) ||
662 gfs2_tune_get(sdp, gt_new_files_jdata))
663 di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA);
664 } else if (S_ISDIR(mode)) {
665 di->di_flags |= cpu_to_be32(dip->i_diskflags &
666 GFS2_DIF_INHERIT_JDATA);
670 di->di_payload_format = cpu_to_be32(S_ISDIR(mode) ? GFS2_FORMAT_DE : 0);
676 memset(&di->__pad4, 0, sizeof(di->__pad4));
678 di->di_atime_nsec = cpu_to_be32(tv.tv_nsec);
679 di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec);
680 di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec);
681 memset(&di->di_reserved, 0, sizeof(di->di_reserved));
683 set_buffer_uptodate(dibh);
688 static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
689 unsigned int mode, const struct gfs2_inum_host *inum,
690 const u64 *generation, dev_t dev, struct buffer_head **bhp)
692 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
693 unsigned int uid, gid;
696 munge_mode_uid_gid(dip, &mode, &uid, &gid);
697 if (!gfs2_alloc_get(dip))
700 error = gfs2_quota_lock(dip, uid, gid);
704 error = gfs2_quota_check(dip, uid, gid);
708 error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0);
712 init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, bhp);
713 gfs2_quota_change(dip, +1, uid, gid);
717 gfs2_quota_unlock(dip);
723 static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
724 struct gfs2_inode *ip)
726 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
727 struct gfs2_alloc *al;
729 struct buffer_head *dibh;
732 al = gfs2_alloc_get(dip);
736 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
740 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name);
741 if (alloc_required < 0)
742 goto fail_quota_locks;
743 if (alloc_required) {
744 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
746 goto fail_quota_locks;
748 al->al_requested = sdp->sd_max_dirres;
750 error = gfs2_inplace_reserve(dip);
752 goto fail_quota_locks;
754 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
755 al->al_rgd->rd_length +
757 RES_STATFS + RES_QUOTA, 0);
761 error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0);
763 goto fail_quota_locks;
766 error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode));
770 error = gfs2_meta_inode_buffer(ip, &dibh);
773 ip->i_inode.i_nlink = 1;
774 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
775 gfs2_dinode_out(ip, dibh->b_data);
783 if (dip->i_alloc->al_rgd)
784 gfs2_inplace_release(dip);
787 gfs2_quota_unlock(dip);
794 static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip)
801 err = security_inode_init_security(&ip->i_inode, &dip->i_inode,
802 &name, &value, &len);
805 if (err == -EOPNOTSUPP)
810 err = __gfs2_xattr_set(&ip->i_inode, name, value, len, 0,
811 GFS2_EATYPE_SECURITY);
819 * gfs2_createi - Create a new inode
820 * @ghs: An array of two holders
821 * @name: The name of the new file
822 * @mode: the permissions on the new inode
824 * @ghs[0] is an initialized holder for the directory
825 * @ghs[1] is the holder for the inode lock
827 * If the return value is not NULL, the glocks on both the directory and the new
828 * file are held. A transaction has been started and an inplace reservation
834 struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
835 unsigned int mode, dev_t dev)
837 struct inode *inode = NULL;
838 struct gfs2_inode *dip = ghs->gh_gl->gl_object;
839 struct inode *dir = &dip->i_inode;
840 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
841 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 };
844 struct buffer_head *bh = NULL;
846 if (!name->len || name->len > GFS2_FNAMESIZE)
847 return ERR_PTR(-ENAMETOOLONG);
849 gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs);
850 error = gfs2_glock_nq(ghs);
854 error = create_ok(dip, name, mode);
858 error = alloc_dinode(dip, &inum.no_addr, &generation);
861 inum.no_formal_ino = generation;
863 error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops,
864 LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
868 error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, &bh);
872 inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode), inum.no_addr,
877 error = gfs2_inode_refresh(GFS2_I(inode));
881 error = gfs2_acl_create(dip, inode);
885 error = gfs2_security_init(dip, GFS2_I(inode));
889 error = link_dinode(dip, name, GFS2_I(inode));
898 gfs2_glock_dq_uninit(ghs + 1);
899 if (inode && !IS_ERR(inode))
906 return ERR_PTR(error);
909 static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
911 struct inode *inode = &ip->i_inode;
912 struct buffer_head *dibh;
915 error = gfs2_meta_inode_buffer(ip, &dibh);
919 if ((attr->ia_valid & ATTR_SIZE) &&
920 attr->ia_size != i_size_read(inode)) {
921 error = vmtruncate(inode, attr->ia_size);
926 setattr_copy(inode, attr);
927 mark_inode_dirty(inode);
929 gfs2_assert_warn(GFS2_SB(inode), !error);
930 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
931 gfs2_dinode_out(ip, dibh->b_data);
937 * gfs2_setattr_simple -
941 * Called with a reference on the vnode.
946 int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
950 if (current->journal_info)
951 return __gfs2_setattr_simple(ip, attr);
953 error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0);
957 error = __gfs2_setattr_simple(ip, attr);
958 gfs2_trans_end(GFS2_SB(&ip->i_inode));
962 void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf)
964 struct gfs2_dinode *str = buf;
966 str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
967 str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI);
968 str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI);
969 str->di_num.no_addr = cpu_to_be64(ip->i_no_addr);
970 str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
971 str->di_mode = cpu_to_be32(ip->i_inode.i_mode);
972 str->di_uid = cpu_to_be32(ip->i_inode.i_uid);
973 str->di_gid = cpu_to_be32(ip->i_inode.i_gid);
974 str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink);
975 str->di_size = cpu_to_be64(i_size_read(&ip->i_inode));
976 str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
977 str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec);
978 str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec);
979 str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec);
981 str->di_goal_meta = cpu_to_be64(ip->i_goal);
982 str->di_goal_data = cpu_to_be64(ip->i_goal);
983 str->di_generation = cpu_to_be64(ip->i_generation);
985 str->di_flags = cpu_to_be32(ip->i_diskflags);
986 str->di_height = cpu_to_be16(ip->i_height);
987 str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) &&
988 !(ip->i_diskflags & GFS2_DIF_EXHASH) ?
990 str->di_depth = cpu_to_be16(ip->i_depth);
991 str->di_entries = cpu_to_be32(ip->i_entries);
993 str->di_eattr = cpu_to_be64(ip->i_eattr);
994 str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec);
995 str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec);
996 str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec);
999 void gfs2_dinode_print(const struct gfs2_inode *ip)
1001 printk(KERN_INFO " no_formal_ino = %llu\n",
1002 (unsigned long long)ip->i_no_formal_ino);
1003 printk(KERN_INFO " no_addr = %llu\n",
1004 (unsigned long long)ip->i_no_addr);
1005 printk(KERN_INFO " i_size = %llu\n",
1006 (unsigned long long)i_size_read(&ip->i_inode));
1007 printk(KERN_INFO " blocks = %llu\n",
1008 (unsigned long long)gfs2_get_inode_blocks(&ip->i_inode));
1009 printk(KERN_INFO " i_goal = %llu\n",
1010 (unsigned long long)ip->i_goal);
1011 printk(KERN_INFO " i_diskflags = 0x%.8X\n", ip->i_diskflags);
1012 printk(KERN_INFO " i_height = %u\n", ip->i_height);
1013 printk(KERN_INFO " i_depth = %u\n", ip->i_depth);
1014 printk(KERN_INFO " i_entries = %u\n", ip->i_entries);
1015 printk(KERN_INFO " i_eattr = %llu\n",
1016 (unsigned long long)ip->i_eattr);