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_set_iop - Sets inode operations
78 * @inode: The inode with correct i_mode filled in
80 * GFS2 lookup code fills in vfs inode contents based on info obtained
81 * from directory entry inside gfs2_inode_lookup().
84 static void gfs2_set_iop(struct inode
*inode
)
86 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
87 umode_t mode
= inode
->i_mode
;
90 inode
->i_op
= &gfs2_file_iops
;
91 if (gfs2_localflocks(sdp
))
92 inode
->i_fop
= &gfs2_file_fops_nolock
;
94 inode
->i_fop
= &gfs2_file_fops
;
95 } else if (S_ISDIR(mode
)) {
96 inode
->i_op
= &gfs2_dir_iops
;
97 if (gfs2_localflocks(sdp
))
98 inode
->i_fop
= &gfs2_dir_fops_nolock
;
100 inode
->i_fop
= &gfs2_dir_fops
;
101 } else if (S_ISLNK(mode
)) {
102 inode
->i_op
= &gfs2_symlink_iops
;
104 inode
->i_op
= &gfs2_file_iops
;
105 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
110 * gfs2_inode_lookup - Lookup an inode
111 * @sb: The super block
112 * @no_addr: The inode number
113 * @type: The type of the inode
115 * Returns: A VFS inode, or an error
118 struct inode
*gfs2_inode_lookup(struct super_block
*sb
, unsigned int type
,
119 u64 no_addr
, u64 no_formal_ino
)
122 struct gfs2_inode
*ip
;
123 struct gfs2_glock
*io_gl
= NULL
;
126 inode
= gfs2_iget(sb
, no_addr
);
130 return ERR_PTR(-ENOBUFS
);
132 if (inode
->i_state
& I_NEW
) {
133 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
134 ip
->i_no_formal_ino
= no_formal_ino
;
136 error
= gfs2_glock_get(sdp
, no_addr
, &gfs2_inode_glops
, CREATE
, &ip
->i_gl
);
139 ip
->i_gl
->gl_object
= ip
;
141 error
= gfs2_glock_get(sdp
, no_addr
, &gfs2_iopen_glops
, CREATE
, &io_gl
);
145 set_bit(GIF_INVALID
, &ip
->i_flags
);
146 error
= gfs2_glock_nq_init(io_gl
, LM_ST_SHARED
, GL_EXACT
, &ip
->i_iopen_gh
);
150 ip
->i_iopen_gh
.gh_gl
->gl_object
= ip
;
151 gfs2_glock_put(io_gl
);
154 if (type
== DT_UNKNOWN
) {
155 /* Inode glock must be locked already */
156 error
= gfs2_inode_refresh(GFS2_I(inode
));
160 inode
->i_mode
= DT2IF(type
);
164 unlock_new_inode(inode
);
170 ip
->i_iopen_gh
.gh_gl
->gl_object
= NULL
;
171 gfs2_glock_dq_uninit(&ip
->i_iopen_gh
);
174 gfs2_glock_put(io_gl
);
176 ip
->i_gl
->gl_object
= NULL
;
177 gfs2_glock_put(ip
->i_gl
);
180 return ERR_PTR(error
);
183 struct inode
*gfs2_lookup_by_inum(struct gfs2_sbd
*sdp
, u64 no_addr
,
184 u64
*no_formal_ino
, unsigned int blktype
)
186 struct super_block
*sb
= sdp
->sd_vfs
;
187 struct gfs2_holder i_gh
;
191 error
= gfs2_glock_nq_num(sdp
, no_addr
, &gfs2_inode_glops
,
192 LM_ST_SHARED
, LM_FLAG_ANY
, &i_gh
);
194 return ERR_PTR(error
);
196 error
= gfs2_check_blk_type(sdp
, no_addr
, blktype
);
200 inode
= gfs2_inode_lookup(sb
, DT_UNKNOWN
, no_addr
, 0);
204 /* Two extra checks for NFS only */
207 if (GFS2_I(inode
)->i_no_formal_ino
!= *no_formal_ino
)
211 if (GFS2_I(inode
)->i_diskflags
& GFS2_DIF_SYSTEM
)
218 gfs2_glock_dq_uninit(&i_gh
);
219 return error
? ERR_PTR(error
) : inode
;
225 static int gfs2_dinode_in(struct gfs2_inode
*ip
, const void *buf
)
227 const struct gfs2_dinode
*str
= buf
;
228 struct timespec atime
;
231 if (unlikely(ip
->i_no_addr
!= be64_to_cpu(str
->di_num
.no_addr
)))
233 ip
->i_no_formal_ino
= be64_to_cpu(str
->di_num
.no_formal_ino
);
234 ip
->i_inode
.i_mode
= be32_to_cpu(str
->di_mode
);
235 ip
->i_inode
.i_rdev
= 0;
236 switch (ip
->i_inode
.i_mode
& S_IFMT
) {
239 ip
->i_inode
.i_rdev
= MKDEV(be32_to_cpu(str
->di_major
),
240 be32_to_cpu(str
->di_minor
));
244 ip
->i_inode
.i_uid
= be32_to_cpu(str
->di_uid
);
245 ip
->i_inode
.i_gid
= be32_to_cpu(str
->di_gid
);
247 * We will need to review setting the nlink count here in the
248 * light of the forthcoming ro bind mount work. This is a reminder
251 ip
->i_inode
.i_nlink
= be32_to_cpu(str
->di_nlink
);
252 i_size_write(&ip
->i_inode
, be64_to_cpu(str
->di_size
));
253 gfs2_set_inode_blocks(&ip
->i_inode
, be64_to_cpu(str
->di_blocks
));
254 atime
.tv_sec
= be64_to_cpu(str
->di_atime
);
255 atime
.tv_nsec
= be32_to_cpu(str
->di_atime_nsec
);
256 if (timespec_compare(&ip
->i_inode
.i_atime
, &atime
) < 0)
257 ip
->i_inode
.i_atime
= atime
;
258 ip
->i_inode
.i_mtime
.tv_sec
= be64_to_cpu(str
->di_mtime
);
259 ip
->i_inode
.i_mtime
.tv_nsec
= be32_to_cpu(str
->di_mtime_nsec
);
260 ip
->i_inode
.i_ctime
.tv_sec
= be64_to_cpu(str
->di_ctime
);
261 ip
->i_inode
.i_ctime
.tv_nsec
= be32_to_cpu(str
->di_ctime_nsec
);
263 ip
->i_goal
= be64_to_cpu(str
->di_goal_meta
);
264 ip
->i_generation
= be64_to_cpu(str
->di_generation
);
266 ip
->i_diskflags
= be32_to_cpu(str
->di_flags
);
267 gfs2_set_inode_flags(&ip
->i_inode
);
268 height
= be16_to_cpu(str
->di_height
);
269 if (unlikely(height
> GFS2_MAX_META_HEIGHT
))
271 ip
->i_height
= (u8
)height
;
273 depth
= be16_to_cpu(str
->di_depth
);
274 if (unlikely(depth
> GFS2_DIR_MAX_DEPTH
))
276 ip
->i_depth
= (u8
)depth
;
277 ip
->i_entries
= be32_to_cpu(str
->di_entries
);
279 ip
->i_eattr
= be64_to_cpu(str
->di_eattr
);
280 if (S_ISREG(ip
->i_inode
.i_mode
))
281 gfs2_set_aops(&ip
->i_inode
);
285 if (gfs2_consist_inode(ip
))
286 gfs2_dinode_print(ip
);
291 * gfs2_inode_refresh - Refresh the incore copy of the dinode
292 * @ip: The GFS2 inode
297 int gfs2_inode_refresh(struct gfs2_inode
*ip
)
299 struct buffer_head
*dibh
;
302 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
306 if (gfs2_metatype_check(GFS2_SB(&ip
->i_inode
), dibh
, GFS2_METATYPE_DI
)) {
311 error
= gfs2_dinode_in(ip
, dibh
->b_data
);
313 clear_bit(GIF_INVALID
, &ip
->i_flags
);
318 int gfs2_dinode_dealloc(struct gfs2_inode
*ip
)
320 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
321 struct gfs2_alloc
*al
;
322 struct gfs2_rgrpd
*rgd
;
325 if (gfs2_get_inode_blocks(&ip
->i_inode
) != 1) {
326 if (gfs2_consist_inode(ip
))
327 gfs2_dinode_print(ip
);
331 al
= gfs2_alloc_get(ip
);
335 error
= gfs2_quota_hold(ip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
339 error
= gfs2_rindex_hold(sdp
, &al
->al_ri_gh
);
343 rgd
= gfs2_blk2rgrpd(sdp
, ip
->i_no_addr
);
345 gfs2_consist_inode(ip
);
347 goto out_rindex_relse
;
350 error
= gfs2_glock_nq_init(rgd
->rd_gl
, LM_ST_EXCLUSIVE
, 0,
353 goto out_rindex_relse
;
355 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
+ RES_QUOTA
, 1);
359 set_bit(GLF_DIRTY
, &ip
->i_gl
->gl_flags
);
360 set_bit(GLF_LFLUSH
, &ip
->i_gl
->gl_flags
);
362 gfs2_free_di(rgd
, ip
);
367 gfs2_glock_dq_uninit(&al
->al_rgd_gh
);
369 gfs2_glock_dq_uninit(&al
->al_ri_gh
);
371 gfs2_quota_unhold(ip
);
378 * gfs2_change_nlink - Change nlink count on inode
379 * @ip: The GFS2 inode
380 * @diff: The change in the nlink count required
384 int gfs2_change_nlink(struct gfs2_inode
*ip
, int diff
)
386 struct buffer_head
*dibh
;
390 BUG_ON(diff
!= 1 && diff
!= -1);
391 nlink
= ip
->i_inode
.i_nlink
+ diff
;
393 /* If we are reducing the nlink count, but the new value ends up being
394 bigger than the old one, we must have underflowed. */
395 if (diff
< 0 && nlink
> ip
->i_inode
.i_nlink
) {
396 if (gfs2_consist_inode(ip
))
397 gfs2_dinode_print(ip
);
401 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
406 inc_nlink(&ip
->i_inode
);
408 drop_nlink(&ip
->i_inode
);
410 ip
->i_inode
.i_ctime
= CURRENT_TIME
;
412 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
413 gfs2_dinode_out(ip
, dibh
->b_data
);
415 mark_inode_dirty(&ip
->i_inode
);
417 if (ip
->i_inode
.i_nlink
== 0)
418 gfs2_unlink_di(&ip
->i_inode
); /* mark inode unlinked */
423 struct inode
*gfs2_lookup_simple(struct inode
*dip
, const char *name
)
427 gfs2_str2qstr(&qstr
, name
);
428 inode
= gfs2_lookupi(dip
, &qstr
, 1);
429 /* gfs2_lookupi has inconsistent callers: vfs
430 * related routines expect NULL for no entry found,
431 * gfs2_lookup_simple callers expect ENOENT
432 * and do not check for NULL.
435 return ERR_PTR(-ENOENT
);
442 * gfs2_lookupi - Look up a filename in a directory and return its inode
443 * @d_gh: An initialized holder for the directory glock
444 * @name: The name of the inode to look for
445 * @is_root: If 1, ignore the caller's permissions
446 * @i_gh: An uninitialized holder for the new inode glock
448 * This can be called via the VFS filldir function when NFS is doing
449 * a readdirplus and the inode which its intending to stat isn't
450 * already in cache. In this case we must not take the directory glock
451 * again, since the readdir call will have already taken that lock.
456 struct inode
*gfs2_lookupi(struct inode
*dir
, const struct qstr
*name
,
459 struct super_block
*sb
= dir
->i_sb
;
460 struct gfs2_inode
*dip
= GFS2_I(dir
);
461 struct gfs2_holder d_gh
;
463 struct inode
*inode
= NULL
;
466 if (!name
->len
|| name
->len
> GFS2_FNAMESIZE
)
467 return ERR_PTR(-ENAMETOOLONG
);
469 if ((name
->len
== 1 && memcmp(name
->name
, ".", 1) == 0) ||
470 (name
->len
== 2 && memcmp(name
->name
, "..", 2) == 0 &&
471 dir
== sb
->s_root
->d_inode
)) {
476 if (gfs2_glock_is_locked_by_me(dip
->i_gl
) == NULL
) {
477 error
= gfs2_glock_nq_init(dip
->i_gl
, LM_ST_SHARED
, 0, &d_gh
);
479 return ERR_PTR(error
);
484 error
= gfs2_permission(dir
, MAY_EXEC
, 0);
489 inode
= gfs2_dir_search(dir
, name
);
491 error
= PTR_ERR(inode
);
494 gfs2_glock_dq_uninit(&d_gh
);
495 if (error
== -ENOENT
)
497 return inode
? inode
: ERR_PTR(error
);
501 * create_ok - OK to create a new on-disk inode here?
502 * @dip: Directory in which dinode is to be created
503 * @name: Name of new dinode
509 static int create_ok(struct gfs2_inode
*dip
, const struct qstr
*name
,
514 error
= gfs2_permission(&dip
->i_inode
, MAY_WRITE
| MAY_EXEC
, 0);
518 /* Don't create entries in an unlinked directory */
519 if (!dip
->i_inode
.i_nlink
)
522 error
= gfs2_dir_check(&dip
->i_inode
, name
, NULL
);
533 if (dip
->i_entries
== (u32
)-1)
535 if (S_ISDIR(mode
) && dip
->i_inode
.i_nlink
== (u32
)-1)
541 static void munge_mode_uid_gid(struct gfs2_inode
*dip
, unsigned int *mode
,
542 unsigned int *uid
, unsigned int *gid
)
544 if (GFS2_SB(&dip
->i_inode
)->sd_args
.ar_suiddir
&&
545 (dip
->i_inode
.i_mode
& S_ISUID
) && dip
->i_inode
.i_uid
) {
548 else if (dip
->i_inode
.i_uid
!= current_fsuid())
550 *uid
= dip
->i_inode
.i_uid
;
552 *uid
= current_fsuid();
554 if (dip
->i_inode
.i_mode
& S_ISGID
) {
557 *gid
= dip
->i_inode
.i_gid
;
559 *gid
= current_fsgid();
562 static int alloc_dinode(struct gfs2_inode
*dip
, u64
*no_addr
, u64
*generation
)
564 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
567 if (gfs2_alloc_get(dip
) == NULL
)
570 dip
->i_alloc
->al_requested
= RES_DINODE
;
571 error
= gfs2_inplace_reserve(dip
);
575 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
, 0);
579 error
= gfs2_alloc_di(dip
, no_addr
, generation
);
584 gfs2_inplace_release(dip
);
591 * init_dinode - Fill in a new dinode structure
592 * @dip: the directory this inode is being created in
593 * @gl: The glock covering the new inode
594 * @inum: the inode number
595 * @mode: the file permissions
601 static void init_dinode(struct gfs2_inode
*dip
, struct gfs2_glock
*gl
,
602 const struct gfs2_inum_host
*inum
, unsigned int mode
,
603 unsigned int uid
, unsigned int gid
,
604 const u64
*generation
, dev_t dev
, struct buffer_head
**bhp
)
606 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
607 struct gfs2_dinode
*di
;
608 struct buffer_head
*dibh
;
609 struct timespec tv
= CURRENT_TIME
;
611 dibh
= gfs2_meta_new(gl
, inum
->no_addr
);
612 gfs2_trans_add_bh(gl
, dibh
, 1);
613 gfs2_metatype_set(dibh
, GFS2_METATYPE_DI
, GFS2_FORMAT_DI
);
614 gfs2_buffer_clear_tail(dibh
, sizeof(struct gfs2_dinode
));
615 di
= (struct gfs2_dinode
*)dibh
->b_data
;
617 di
->di_num
.no_formal_ino
= cpu_to_be64(inum
->no_formal_ino
);
618 di
->di_num
.no_addr
= cpu_to_be64(inum
->no_addr
);
619 di
->di_mode
= cpu_to_be32(mode
);
620 di
->di_uid
= cpu_to_be32(uid
);
621 di
->di_gid
= cpu_to_be32(gid
);
624 di
->di_blocks
= cpu_to_be64(1);
625 di
->di_atime
= di
->di_mtime
= di
->di_ctime
= cpu_to_be64(tv
.tv_sec
);
626 di
->di_major
= cpu_to_be32(MAJOR(dev
));
627 di
->di_minor
= cpu_to_be32(MINOR(dev
));
628 di
->di_goal_meta
= di
->di_goal_data
= cpu_to_be64(inum
->no_addr
);
629 di
->di_generation
= cpu_to_be64(*generation
);
633 if ((dip
->i_diskflags
& GFS2_DIF_INHERIT_JDATA
) ||
634 gfs2_tune_get(sdp
, gt_new_files_jdata
))
635 di
->di_flags
|= cpu_to_be32(GFS2_DIF_JDATA
);
636 } else if (S_ISDIR(mode
)) {
637 di
->di_flags
|= cpu_to_be32(dip
->i_diskflags
&
638 GFS2_DIF_INHERIT_JDATA
);
642 di
->di_payload_format
= cpu_to_be32(S_ISDIR(mode
) ? GFS2_FORMAT_DE
: 0);
648 memset(&di
->__pad4
, 0, sizeof(di
->__pad4
));
650 di
->di_atime_nsec
= cpu_to_be32(tv
.tv_nsec
);
651 di
->di_mtime_nsec
= cpu_to_be32(tv
.tv_nsec
);
652 di
->di_ctime_nsec
= cpu_to_be32(tv
.tv_nsec
);
653 memset(&di
->di_reserved
, 0, sizeof(di
->di_reserved
));
655 set_buffer_uptodate(dibh
);
660 static int make_dinode(struct gfs2_inode
*dip
, struct gfs2_glock
*gl
,
661 unsigned int mode
, const struct gfs2_inum_host
*inum
,
662 const u64
*generation
, dev_t dev
, struct buffer_head
**bhp
)
664 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
665 unsigned int uid
, gid
;
668 munge_mode_uid_gid(dip
, &mode
, &uid
, &gid
);
669 if (!gfs2_alloc_get(dip
))
672 error
= gfs2_quota_lock(dip
, uid
, gid
);
676 error
= gfs2_quota_check(dip
, uid
, gid
);
680 error
= gfs2_trans_begin(sdp
, RES_DINODE
+ RES_QUOTA
, 0);
684 init_dinode(dip
, gl
, inum
, mode
, uid
, gid
, generation
, dev
, bhp
);
685 gfs2_quota_change(dip
, +1, uid
, gid
);
689 gfs2_quota_unlock(dip
);
695 static int link_dinode(struct gfs2_inode
*dip
, const struct qstr
*name
,
696 struct gfs2_inode
*ip
)
698 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
699 struct gfs2_alloc
*al
;
701 struct buffer_head
*dibh
;
704 al
= gfs2_alloc_get(dip
);
708 error
= gfs2_quota_lock(dip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
712 error
= alloc_required
= gfs2_diradd_alloc_required(&dip
->i_inode
, name
);
713 if (alloc_required
< 0)
714 goto fail_quota_locks
;
715 if (alloc_required
) {
716 error
= gfs2_quota_check(dip
, dip
->i_inode
.i_uid
, dip
->i_inode
.i_gid
);
718 goto fail_quota_locks
;
720 al
->al_requested
= sdp
->sd_max_dirres
;
722 error
= gfs2_inplace_reserve(dip
);
724 goto fail_quota_locks
;
726 error
= gfs2_trans_begin(sdp
, sdp
->sd_max_dirres
+
727 al
->al_rgd
->rd_length
+
729 RES_STATFS
+ RES_QUOTA
, 0);
733 error
= gfs2_trans_begin(sdp
, RES_LEAF
+ 2 * RES_DINODE
, 0);
735 goto fail_quota_locks
;
738 error
= gfs2_dir_add(&dip
->i_inode
, name
, ip
, IF2DT(ip
->i_inode
.i_mode
));
742 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
745 ip
->i_inode
.i_nlink
= 1;
746 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
747 gfs2_dinode_out(ip
, dibh
->b_data
);
755 if (dip
->i_alloc
->al_rgd
)
756 gfs2_inplace_release(dip
);
759 gfs2_quota_unlock(dip
);
766 static int gfs2_security_init(struct gfs2_inode
*dip
, struct gfs2_inode
*ip
)
773 err
= security_inode_init_security(&ip
->i_inode
, &dip
->i_inode
,
774 &name
, &value
, &len
);
777 if (err
== -EOPNOTSUPP
)
782 err
= __gfs2_xattr_set(&ip
->i_inode
, name
, value
, len
, 0,
783 GFS2_EATYPE_SECURITY
);
791 * gfs2_createi - Create a new inode
792 * @ghs: An array of two holders
793 * @name: The name of the new file
794 * @mode: the permissions on the new inode
796 * @ghs[0] is an initialized holder for the directory
797 * @ghs[1] is the holder for the inode lock
799 * If the return value is not NULL, the glocks on both the directory and the new
800 * file are held. A transaction has been started and an inplace reservation
806 struct inode
*gfs2_createi(struct gfs2_holder
*ghs
, const struct qstr
*name
,
807 unsigned int mode
, dev_t dev
)
809 struct inode
*inode
= NULL
;
810 struct gfs2_inode
*dip
= ghs
->gh_gl
->gl_object
;
811 struct inode
*dir
= &dip
->i_inode
;
812 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
813 struct gfs2_inum_host inum
= { .no_addr
= 0, .no_formal_ino
= 0 };
816 struct buffer_head
*bh
= NULL
;
818 if (!name
->len
|| name
->len
> GFS2_FNAMESIZE
)
819 return ERR_PTR(-ENAMETOOLONG
);
821 gfs2_holder_reinit(LM_ST_EXCLUSIVE
, 0, ghs
);
822 error
= gfs2_glock_nq(ghs
);
826 error
= create_ok(dip
, name
, mode
);
830 error
= alloc_dinode(dip
, &inum
.no_addr
, &generation
);
833 inum
.no_formal_ino
= generation
;
835 error
= gfs2_glock_nq_num(sdp
, inum
.no_addr
, &gfs2_inode_glops
,
836 LM_ST_EXCLUSIVE
, GL_SKIP
, ghs
+ 1);
840 error
= make_dinode(dip
, ghs
[1].gh_gl
, mode
, &inum
, &generation
, dev
, &bh
);
844 inode
= gfs2_inode_lookup(dir
->i_sb
, IF2DT(mode
), inum
.no_addr
,
849 error
= gfs2_inode_refresh(GFS2_I(inode
));
853 error
= gfs2_acl_create(dip
, inode
);
857 error
= gfs2_security_init(dip
, GFS2_I(inode
));
861 error
= link_dinode(dip
, name
, GFS2_I(inode
));
870 gfs2_glock_dq_uninit(ghs
+ 1);
871 if (inode
&& !IS_ERR(inode
))
878 return ERR_PTR(error
);
881 static int __gfs2_setattr_simple(struct gfs2_inode
*ip
, struct iattr
*attr
)
883 struct inode
*inode
= &ip
->i_inode
;
884 struct buffer_head
*dibh
;
887 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
891 setattr_copy(inode
, attr
);
892 mark_inode_dirty(inode
);
893 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
894 gfs2_dinode_out(ip
, dibh
->b_data
);
900 * gfs2_setattr_simple -
904 * Called with a reference on the vnode.
909 int gfs2_setattr_simple(struct gfs2_inode
*ip
, struct iattr
*attr
)
913 if (current
->journal_info
)
914 return __gfs2_setattr_simple(ip
, attr
);
916 error
= gfs2_trans_begin(GFS2_SB(&ip
->i_inode
), RES_DINODE
, 0);
920 error
= __gfs2_setattr_simple(ip
, attr
);
921 gfs2_trans_end(GFS2_SB(&ip
->i_inode
));
925 void gfs2_dinode_out(const struct gfs2_inode
*ip
, void *buf
)
927 struct gfs2_dinode
*str
= buf
;
929 str
->di_header
.mh_magic
= cpu_to_be32(GFS2_MAGIC
);
930 str
->di_header
.mh_type
= cpu_to_be32(GFS2_METATYPE_DI
);
931 str
->di_header
.mh_format
= cpu_to_be32(GFS2_FORMAT_DI
);
932 str
->di_num
.no_addr
= cpu_to_be64(ip
->i_no_addr
);
933 str
->di_num
.no_formal_ino
= cpu_to_be64(ip
->i_no_formal_ino
);
934 str
->di_mode
= cpu_to_be32(ip
->i_inode
.i_mode
);
935 str
->di_uid
= cpu_to_be32(ip
->i_inode
.i_uid
);
936 str
->di_gid
= cpu_to_be32(ip
->i_inode
.i_gid
);
937 str
->di_nlink
= cpu_to_be32(ip
->i_inode
.i_nlink
);
938 str
->di_size
= cpu_to_be64(i_size_read(&ip
->i_inode
));
939 str
->di_blocks
= cpu_to_be64(gfs2_get_inode_blocks(&ip
->i_inode
));
940 str
->di_atime
= cpu_to_be64(ip
->i_inode
.i_atime
.tv_sec
);
941 str
->di_mtime
= cpu_to_be64(ip
->i_inode
.i_mtime
.tv_sec
);
942 str
->di_ctime
= cpu_to_be64(ip
->i_inode
.i_ctime
.tv_sec
);
944 str
->di_goal_meta
= cpu_to_be64(ip
->i_goal
);
945 str
->di_goal_data
= cpu_to_be64(ip
->i_goal
);
946 str
->di_generation
= cpu_to_be64(ip
->i_generation
);
948 str
->di_flags
= cpu_to_be32(ip
->i_diskflags
);
949 str
->di_height
= cpu_to_be16(ip
->i_height
);
950 str
->di_payload_format
= cpu_to_be32(S_ISDIR(ip
->i_inode
.i_mode
) &&
951 !(ip
->i_diskflags
& GFS2_DIF_EXHASH
) ?
953 str
->di_depth
= cpu_to_be16(ip
->i_depth
);
954 str
->di_entries
= cpu_to_be32(ip
->i_entries
);
956 str
->di_eattr
= cpu_to_be64(ip
->i_eattr
);
957 str
->di_atime_nsec
= cpu_to_be32(ip
->i_inode
.i_atime
.tv_nsec
);
958 str
->di_mtime_nsec
= cpu_to_be32(ip
->i_inode
.i_mtime
.tv_nsec
);
959 str
->di_ctime_nsec
= cpu_to_be32(ip
->i_inode
.i_ctime
.tv_nsec
);
962 void gfs2_dinode_print(const struct gfs2_inode
*ip
)
964 printk(KERN_INFO
" no_formal_ino = %llu\n",
965 (unsigned long long)ip
->i_no_formal_ino
);
966 printk(KERN_INFO
" no_addr = %llu\n",
967 (unsigned long long)ip
->i_no_addr
);
968 printk(KERN_INFO
" i_size = %llu\n",
969 (unsigned long long)i_size_read(&ip
->i_inode
));
970 printk(KERN_INFO
" blocks = %llu\n",
971 (unsigned long long)gfs2_get_inode_blocks(&ip
->i_inode
));
972 printk(KERN_INFO
" i_goal = %llu\n",
973 (unsigned long long)ip
->i_goal
);
974 printk(KERN_INFO
" i_diskflags = 0x%.8X\n", ip
->i_diskflags
);
975 printk(KERN_INFO
" i_height = %u\n", ip
->i_height
);
976 printk(KERN_INFO
" i_depth = %u\n", ip
->i_depth
);
977 printk(KERN_INFO
" i_entries = %u\n", ip
->i_entries
);
978 printk(KERN_INFO
" i_eattr = %llu\n",
979 (unsigned long long)ip
->i_eattr
);