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 struct gfs2_skip_data
{
49 static int iget_test(struct inode
*inode
, void *opaque
)
51 struct gfs2_inode
*ip
= GFS2_I(inode
);
52 struct gfs2_skip_data
*data
= opaque
;
54 if (ip
->i_no_addr
== data
->no_addr
) {
55 if (data
->non_block
&&
56 inode
->i_state
& (I_FREEING
|I_CLEAR
|I_WILL_FREE
)) {
65 static int iget_set(struct inode
*inode
, void *opaque
)
67 struct gfs2_inode
*ip
= GFS2_I(inode
);
68 struct gfs2_skip_data
*data
= opaque
;
72 inode
->i_ino
= (unsigned long)(data
->no_addr
);
73 ip
->i_no_addr
= data
->no_addr
;
77 struct inode
*gfs2_ilookup(struct super_block
*sb
, u64 no_addr
)
79 unsigned long hash
= (unsigned long)no_addr
;
80 struct gfs2_skip_data data
;
82 data
.no_addr
= no_addr
;
85 return ilookup5(sb
, hash
, iget_test
, &data
);
88 static struct inode
*gfs2_iget(struct super_block
*sb
, u64 no_addr
,
91 struct gfs2_skip_data data
;
92 unsigned long hash
= (unsigned long)no_addr
;
94 data
.no_addr
= no_addr
;
96 data
.non_block
= non_block
;
97 return iget5_locked(sb
, hash
, iget_test
, iget_set
, &data
);
101 * gfs2_set_iop - Sets inode operations
102 * @inode: The inode with correct i_mode filled in
104 * GFS2 lookup code fills in vfs inode contents based on info obtained
105 * from directory entry inside gfs2_inode_lookup().
108 static void gfs2_set_iop(struct inode
*inode
)
110 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
111 umode_t mode
= inode
->i_mode
;
114 inode
->i_op
= &gfs2_file_iops
;
115 if (gfs2_localflocks(sdp
))
116 inode
->i_fop
= &gfs2_file_fops_nolock
;
118 inode
->i_fop
= &gfs2_file_fops
;
119 } else if (S_ISDIR(mode
)) {
120 inode
->i_op
= &gfs2_dir_iops
;
121 if (gfs2_localflocks(sdp
))
122 inode
->i_fop
= &gfs2_dir_fops_nolock
;
124 inode
->i_fop
= &gfs2_dir_fops
;
125 } else if (S_ISLNK(mode
)) {
126 inode
->i_op
= &gfs2_symlink_iops
;
128 inode
->i_op
= &gfs2_file_iops
;
129 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
134 * gfs2_inode_lookup - Lookup an inode
135 * @sb: The super block
136 * @no_addr: The inode number
137 * @type: The type of the inode
138 * non_block: Can we block on inodes that are being freed?
140 * Returns: A VFS inode, or an error
143 struct inode
*gfs2_inode_lookup(struct super_block
*sb
, unsigned int type
,
144 u64 no_addr
, u64 no_formal_ino
, int non_block
)
147 struct gfs2_inode
*ip
;
148 struct gfs2_glock
*io_gl
= NULL
;
151 inode
= gfs2_iget(sb
, no_addr
, non_block
);
155 return ERR_PTR(-ENOBUFS
);
157 if (inode
->i_state
& I_NEW
) {
158 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
159 ip
->i_no_formal_ino
= no_formal_ino
;
161 error
= gfs2_glock_get(sdp
, no_addr
, &gfs2_inode_glops
, CREATE
, &ip
->i_gl
);
164 ip
->i_gl
->gl_object
= ip
;
166 error
= gfs2_glock_get(sdp
, no_addr
, &gfs2_iopen_glops
, CREATE
, &io_gl
);
170 set_bit(GIF_INVALID
, &ip
->i_flags
);
171 error
= gfs2_glock_nq_init(io_gl
, LM_ST_SHARED
, GL_EXACT
, &ip
->i_iopen_gh
);
175 ip
->i_iopen_gh
.gh_gl
->gl_object
= ip
;
176 gfs2_glock_put(io_gl
);
179 if (type
== DT_UNKNOWN
) {
180 /* Inode glock must be locked already */
181 error
= gfs2_inode_refresh(GFS2_I(inode
));
185 inode
->i_mode
= DT2IF(type
);
189 unlock_new_inode(inode
);
195 ip
->i_iopen_gh
.gh_gl
->gl_object
= NULL
;
196 gfs2_glock_dq_uninit(&ip
->i_iopen_gh
);
199 gfs2_glock_put(io_gl
);
201 ip
->i_gl
->gl_object
= NULL
;
202 gfs2_glock_put(ip
->i_gl
);
205 return ERR_PTR(error
);
208 struct inode
*gfs2_lookup_by_inum(struct gfs2_sbd
*sdp
, u64 no_addr
,
209 u64
*no_formal_ino
, unsigned int blktype
)
211 struct super_block
*sb
= sdp
->sd_vfs
;
212 struct gfs2_holder i_gh
;
213 struct inode
*inode
= NULL
;
216 /* Must not read in block until block type is verified */
217 error
= gfs2_glock_nq_num(sdp
, no_addr
, &gfs2_inode_glops
,
218 LM_ST_EXCLUSIVE
, GL_SKIP
, &i_gh
);
220 return ERR_PTR(error
);
222 error
= gfs2_check_blk_type(sdp
, no_addr
, blktype
);
226 inode
= gfs2_inode_lookup(sb
, DT_UNKNOWN
, no_addr
, 0, 1);
230 /* Two extra checks for NFS only */
233 if (GFS2_I(inode
)->i_no_formal_ino
!= *no_formal_ino
)
237 if (GFS2_I(inode
)->i_diskflags
& GFS2_DIF_SYSTEM
)
244 gfs2_glock_dq_uninit(&i_gh
);
245 return error
? ERR_PTR(error
) : inode
;
251 static int gfs2_dinode_in(struct gfs2_inode
*ip
, const void *buf
)
253 const struct gfs2_dinode
*str
= buf
;
254 struct timespec atime
;
257 if (unlikely(ip
->i_no_addr
!= be64_to_cpu(str
->di_num
.no_addr
)))
259 ip
->i_no_formal_ino
= be64_to_cpu(str
->di_num
.no_formal_ino
);
260 ip
->i_inode
.i_mode
= be32_to_cpu(str
->di_mode
);
261 ip
->i_inode
.i_rdev
= 0;
262 switch (ip
->i_inode
.i_mode
& S_IFMT
) {
265 ip
->i_inode
.i_rdev
= MKDEV(be32_to_cpu(str
->di_major
),
266 be32_to_cpu(str
->di_minor
));
270 ip
->i_inode
.i_uid
= be32_to_cpu(str
->di_uid
);
271 ip
->i_inode
.i_gid
= be32_to_cpu(str
->di_gid
);
273 * We will need to review setting the nlink count here in the
274 * light of the forthcoming ro bind mount work. This is a reminder
277 ip
->i_inode
.i_nlink
= be32_to_cpu(str
->di_nlink
);
278 i_size_write(&ip
->i_inode
, be64_to_cpu(str
->di_size
));
279 gfs2_set_inode_blocks(&ip
->i_inode
, be64_to_cpu(str
->di_blocks
));
280 atime
.tv_sec
= be64_to_cpu(str
->di_atime
);
281 atime
.tv_nsec
= be32_to_cpu(str
->di_atime_nsec
);
282 if (timespec_compare(&ip
->i_inode
.i_atime
, &atime
) < 0)
283 ip
->i_inode
.i_atime
= atime
;
284 ip
->i_inode
.i_mtime
.tv_sec
= be64_to_cpu(str
->di_mtime
);
285 ip
->i_inode
.i_mtime
.tv_nsec
= be32_to_cpu(str
->di_mtime_nsec
);
286 ip
->i_inode
.i_ctime
.tv_sec
= be64_to_cpu(str
->di_ctime
);
287 ip
->i_inode
.i_ctime
.tv_nsec
= be32_to_cpu(str
->di_ctime_nsec
);
289 ip
->i_goal
= be64_to_cpu(str
->di_goal_meta
);
290 ip
->i_generation
= be64_to_cpu(str
->di_generation
);
292 ip
->i_diskflags
= be32_to_cpu(str
->di_flags
);
293 gfs2_set_inode_flags(&ip
->i_inode
);
294 height
= be16_to_cpu(str
->di_height
);
295 if (unlikely(height
> GFS2_MAX_META_HEIGHT
))
297 ip
->i_height
= (u8
)height
;
299 depth
= be16_to_cpu(str
->di_depth
);
300 if (unlikely(depth
> GFS2_DIR_MAX_DEPTH
))
302 ip
->i_depth
= (u8
)depth
;
303 ip
->i_entries
= be32_to_cpu(str
->di_entries
);
305 ip
->i_eattr
= be64_to_cpu(str
->di_eattr
);
306 if (S_ISREG(ip
->i_inode
.i_mode
))
307 gfs2_set_aops(&ip
->i_inode
);
311 if (gfs2_consist_inode(ip
))
312 gfs2_dinode_print(ip
);
317 * gfs2_inode_refresh - Refresh the incore copy of the dinode
318 * @ip: The GFS2 inode
323 int gfs2_inode_refresh(struct gfs2_inode
*ip
)
325 struct buffer_head
*dibh
;
328 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
332 if (gfs2_metatype_check(GFS2_SB(&ip
->i_inode
), dibh
, GFS2_METATYPE_DI
)) {
337 error
= gfs2_dinode_in(ip
, dibh
->b_data
);
339 clear_bit(GIF_INVALID
, &ip
->i_flags
);
344 int gfs2_dinode_dealloc(struct gfs2_inode
*ip
)
346 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
347 struct gfs2_alloc
*al
;
348 struct gfs2_rgrpd
*rgd
;
351 if (gfs2_get_inode_blocks(&ip
->i_inode
) != 1) {
352 if (gfs2_consist_inode(ip
))
353 gfs2_dinode_print(ip
);
357 al
= gfs2_alloc_get(ip
);
361 error
= gfs2_quota_hold(ip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
365 error
= gfs2_rindex_hold(sdp
, &al
->al_ri_gh
);
369 rgd
= gfs2_blk2rgrpd(sdp
, ip
->i_no_addr
);
371 gfs2_consist_inode(ip
);
373 goto out_rindex_relse
;
376 error
= gfs2_glock_nq_init(rgd
->rd_gl
, LM_ST_EXCLUSIVE
, 0,
379 goto out_rindex_relse
;
381 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
+ RES_QUOTA
, 1);
385 set_bit(GLF_DIRTY
, &ip
->i_gl
->gl_flags
);
386 set_bit(GLF_LFLUSH
, &ip
->i_gl
->gl_flags
);
388 gfs2_free_di(rgd
, ip
);
393 gfs2_glock_dq_uninit(&al
->al_rgd_gh
);
395 gfs2_glock_dq_uninit(&al
->al_ri_gh
);
397 gfs2_quota_unhold(ip
);
404 * gfs2_change_nlink - Change nlink count on inode
405 * @ip: The GFS2 inode
406 * @diff: The change in the nlink count required
410 int gfs2_change_nlink(struct gfs2_inode
*ip
, int diff
)
412 struct buffer_head
*dibh
;
416 BUG_ON(diff
!= 1 && diff
!= -1);
417 nlink
= ip
->i_inode
.i_nlink
+ diff
;
419 /* If we are reducing the nlink count, but the new value ends up being
420 bigger than the old one, we must have underflowed. */
421 if (diff
< 0 && nlink
> ip
->i_inode
.i_nlink
) {
422 if (gfs2_consist_inode(ip
))
423 gfs2_dinode_print(ip
);
427 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
432 inc_nlink(&ip
->i_inode
);
434 drop_nlink(&ip
->i_inode
);
436 ip
->i_inode
.i_ctime
= CURRENT_TIME
;
438 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
439 gfs2_dinode_out(ip
, dibh
->b_data
);
441 mark_inode_dirty(&ip
->i_inode
);
443 if (ip
->i_inode
.i_nlink
== 0)
444 gfs2_unlink_di(&ip
->i_inode
); /* mark inode unlinked */
449 struct inode
*gfs2_lookup_simple(struct inode
*dip
, const char *name
)
453 gfs2_str2qstr(&qstr
, name
);
454 inode
= gfs2_lookupi(dip
, &qstr
, 1);
455 /* gfs2_lookupi has inconsistent callers: vfs
456 * related routines expect NULL for no entry found,
457 * gfs2_lookup_simple callers expect ENOENT
458 * and do not check for NULL.
461 return ERR_PTR(-ENOENT
);
468 * gfs2_lookupi - Look up a filename in a directory and return its inode
469 * @d_gh: An initialized holder for the directory glock
470 * @name: The name of the inode to look for
471 * @is_root: If 1, ignore the caller's permissions
472 * @i_gh: An uninitialized holder for the new inode glock
474 * This can be called via the VFS filldir function when NFS is doing
475 * a readdirplus and the inode which its intending to stat isn't
476 * already in cache. In this case we must not take the directory glock
477 * again, since the readdir call will have already taken that lock.
482 struct inode
*gfs2_lookupi(struct inode
*dir
, const struct qstr
*name
,
485 struct super_block
*sb
= dir
->i_sb
;
486 struct gfs2_inode
*dip
= GFS2_I(dir
);
487 struct gfs2_holder d_gh
;
489 struct inode
*inode
= NULL
;
492 if (!name
->len
|| name
->len
> GFS2_FNAMESIZE
)
493 return ERR_PTR(-ENAMETOOLONG
);
495 if ((name
->len
== 1 && memcmp(name
->name
, ".", 1) == 0) ||
496 (name
->len
== 2 && memcmp(name
->name
, "..", 2) == 0 &&
497 dir
== sb
->s_root
->d_inode
)) {
502 if (gfs2_glock_is_locked_by_me(dip
->i_gl
) == NULL
) {
503 error
= gfs2_glock_nq_init(dip
->i_gl
, LM_ST_SHARED
, 0, &d_gh
);
505 return ERR_PTR(error
);
510 error
= gfs2_permission(dir
, MAY_EXEC
, 0);
515 inode
= gfs2_dir_search(dir
, name
);
517 error
= PTR_ERR(inode
);
520 gfs2_glock_dq_uninit(&d_gh
);
521 if (error
== -ENOENT
)
523 return inode
? inode
: ERR_PTR(error
);
527 * create_ok - OK to create a new on-disk inode here?
528 * @dip: Directory in which dinode is to be created
529 * @name: Name of new dinode
535 static int create_ok(struct gfs2_inode
*dip
, const struct qstr
*name
,
540 error
= gfs2_permission(&dip
->i_inode
, MAY_WRITE
| MAY_EXEC
, 0);
544 /* Don't create entries in an unlinked directory */
545 if (!dip
->i_inode
.i_nlink
)
548 error
= gfs2_dir_check(&dip
->i_inode
, name
, NULL
);
559 if (dip
->i_entries
== (u32
)-1)
561 if (S_ISDIR(mode
) && dip
->i_inode
.i_nlink
== (u32
)-1)
567 static void munge_mode_uid_gid(struct gfs2_inode
*dip
, unsigned int *mode
,
568 unsigned int *uid
, unsigned int *gid
)
570 if (GFS2_SB(&dip
->i_inode
)->sd_args
.ar_suiddir
&&
571 (dip
->i_inode
.i_mode
& S_ISUID
) && dip
->i_inode
.i_uid
) {
574 else if (dip
->i_inode
.i_uid
!= current_fsuid())
576 *uid
= dip
->i_inode
.i_uid
;
578 *uid
= current_fsuid();
580 if (dip
->i_inode
.i_mode
& S_ISGID
) {
583 *gid
= dip
->i_inode
.i_gid
;
585 *gid
= current_fsgid();
588 static int alloc_dinode(struct gfs2_inode
*dip
, u64
*no_addr
, u64
*generation
)
590 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
593 if (gfs2_alloc_get(dip
) == NULL
)
596 dip
->i_alloc
->al_requested
= RES_DINODE
;
597 error
= gfs2_inplace_reserve(dip
);
601 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
, 0);
605 error
= gfs2_alloc_di(dip
, no_addr
, generation
);
610 gfs2_inplace_release(dip
);
617 * init_dinode - Fill in a new dinode structure
618 * @dip: the directory this inode is being created in
619 * @gl: The glock covering the new inode
620 * @inum: the inode number
621 * @mode: the file permissions
627 static void init_dinode(struct gfs2_inode
*dip
, struct gfs2_glock
*gl
,
628 const struct gfs2_inum_host
*inum
, unsigned int mode
,
629 unsigned int uid
, unsigned int gid
,
630 const u64
*generation
, dev_t dev
, struct buffer_head
**bhp
)
632 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
633 struct gfs2_dinode
*di
;
634 struct buffer_head
*dibh
;
635 struct timespec tv
= CURRENT_TIME
;
637 dibh
= gfs2_meta_new(gl
, inum
->no_addr
);
638 gfs2_trans_add_bh(gl
, dibh
, 1);
639 gfs2_metatype_set(dibh
, GFS2_METATYPE_DI
, GFS2_FORMAT_DI
);
640 gfs2_buffer_clear_tail(dibh
, sizeof(struct gfs2_dinode
));
641 di
= (struct gfs2_dinode
*)dibh
->b_data
;
643 di
->di_num
.no_formal_ino
= cpu_to_be64(inum
->no_formal_ino
);
644 di
->di_num
.no_addr
= cpu_to_be64(inum
->no_addr
);
645 di
->di_mode
= cpu_to_be32(mode
);
646 di
->di_uid
= cpu_to_be32(uid
);
647 di
->di_gid
= cpu_to_be32(gid
);
650 di
->di_blocks
= cpu_to_be64(1);
651 di
->di_atime
= di
->di_mtime
= di
->di_ctime
= cpu_to_be64(tv
.tv_sec
);
652 di
->di_major
= cpu_to_be32(MAJOR(dev
));
653 di
->di_minor
= cpu_to_be32(MINOR(dev
));
654 di
->di_goal_meta
= di
->di_goal_data
= cpu_to_be64(inum
->no_addr
);
655 di
->di_generation
= cpu_to_be64(*generation
);
659 if ((dip
->i_diskflags
& GFS2_DIF_INHERIT_JDATA
) ||
660 gfs2_tune_get(sdp
, gt_new_files_jdata
))
661 di
->di_flags
|= cpu_to_be32(GFS2_DIF_JDATA
);
662 } else if (S_ISDIR(mode
)) {
663 di
->di_flags
|= cpu_to_be32(dip
->i_diskflags
&
664 GFS2_DIF_INHERIT_JDATA
);
668 di
->di_payload_format
= cpu_to_be32(S_ISDIR(mode
) ? GFS2_FORMAT_DE
: 0);
674 memset(&di
->__pad4
, 0, sizeof(di
->__pad4
));
676 di
->di_atime_nsec
= cpu_to_be32(tv
.tv_nsec
);
677 di
->di_mtime_nsec
= cpu_to_be32(tv
.tv_nsec
);
678 di
->di_ctime_nsec
= cpu_to_be32(tv
.tv_nsec
);
679 memset(&di
->di_reserved
, 0, sizeof(di
->di_reserved
));
681 set_buffer_uptodate(dibh
);
686 static int make_dinode(struct gfs2_inode
*dip
, struct gfs2_glock
*gl
,
687 unsigned int mode
, const struct gfs2_inum_host
*inum
,
688 const u64
*generation
, dev_t dev
, struct buffer_head
**bhp
)
690 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
691 unsigned int uid
, gid
;
694 munge_mode_uid_gid(dip
, &mode
, &uid
, &gid
);
695 if (!gfs2_alloc_get(dip
))
698 error
= gfs2_quota_lock(dip
, uid
, gid
);
702 error
= gfs2_quota_check(dip
, uid
, gid
);
706 error
= gfs2_trans_begin(sdp
, RES_DINODE
+ RES_QUOTA
, 0);
710 init_dinode(dip
, gl
, inum
, mode
, uid
, gid
, generation
, dev
, bhp
);
711 gfs2_quota_change(dip
, +1, uid
, gid
);
715 gfs2_quota_unlock(dip
);
721 static int link_dinode(struct gfs2_inode
*dip
, const struct qstr
*name
,
722 struct gfs2_inode
*ip
)
724 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
725 struct gfs2_alloc
*al
;
727 struct buffer_head
*dibh
;
730 al
= gfs2_alloc_get(dip
);
734 error
= gfs2_quota_lock(dip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
738 error
= alloc_required
= gfs2_diradd_alloc_required(&dip
->i_inode
, name
);
739 if (alloc_required
< 0)
740 goto fail_quota_locks
;
741 if (alloc_required
) {
742 error
= gfs2_quota_check(dip
, dip
->i_inode
.i_uid
, dip
->i_inode
.i_gid
);
744 goto fail_quota_locks
;
746 al
->al_requested
= sdp
->sd_max_dirres
;
748 error
= gfs2_inplace_reserve(dip
);
750 goto fail_quota_locks
;
752 error
= gfs2_trans_begin(sdp
, sdp
->sd_max_dirres
+
753 al
->al_rgd
->rd_length
+
755 RES_STATFS
+ RES_QUOTA
, 0);
759 error
= gfs2_trans_begin(sdp
, RES_LEAF
+ 2 * RES_DINODE
, 0);
761 goto fail_quota_locks
;
764 error
= gfs2_dir_add(&dip
->i_inode
, name
, ip
, IF2DT(ip
->i_inode
.i_mode
));
768 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
771 ip
->i_inode
.i_nlink
= 1;
772 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
773 gfs2_dinode_out(ip
, dibh
->b_data
);
781 if (dip
->i_alloc
->al_rgd
)
782 gfs2_inplace_release(dip
);
785 gfs2_quota_unlock(dip
);
792 static int gfs2_security_init(struct gfs2_inode
*dip
, struct gfs2_inode
*ip
,
793 const struct qstr
*qstr
)
800 err
= security_inode_init_security(&ip
->i_inode
, &dip
->i_inode
, qstr
,
801 &name
, &value
, &len
);
804 if (err
== -EOPNOTSUPP
)
809 err
= __gfs2_xattr_set(&ip
->i_inode
, name
, value
, len
, 0,
810 GFS2_EATYPE_SECURITY
);
818 * gfs2_createi - Create a new inode
819 * @ghs: An array of two holders
820 * @name: The name of the new file
821 * @mode: the permissions on the new inode
823 * @ghs[0] is an initialized holder for the directory
824 * @ghs[1] is the holder for the inode lock
826 * If the return value is not NULL, the glocks on both the directory and the new
827 * file are held. A transaction has been started and an inplace reservation
833 struct inode
*gfs2_createi(struct gfs2_holder
*ghs
, const struct qstr
*name
,
834 unsigned int mode
, dev_t dev
)
836 struct inode
*inode
= NULL
;
837 struct gfs2_inode
*dip
= ghs
->gh_gl
->gl_object
;
838 struct inode
*dir
= &dip
->i_inode
;
839 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
840 struct gfs2_inum_host inum
= { .no_addr
= 0, .no_formal_ino
= 0 };
843 struct buffer_head
*bh
= NULL
;
845 if (!name
->len
|| name
->len
> GFS2_FNAMESIZE
)
846 return ERR_PTR(-ENAMETOOLONG
);
848 gfs2_holder_reinit(LM_ST_EXCLUSIVE
, 0, ghs
);
849 error
= gfs2_glock_nq(ghs
);
853 error
= create_ok(dip
, name
, mode
);
857 error
= alloc_dinode(dip
, &inum
.no_addr
, &generation
);
860 inum
.no_formal_ino
= generation
;
862 error
= gfs2_glock_nq_num(sdp
, inum
.no_addr
, &gfs2_inode_glops
,
863 LM_ST_EXCLUSIVE
, GL_SKIP
, ghs
+ 1);
867 error
= make_dinode(dip
, ghs
[1].gh_gl
, mode
, &inum
, &generation
, dev
, &bh
);
871 inode
= gfs2_inode_lookup(dir
->i_sb
, IF2DT(mode
), inum
.no_addr
,
872 inum
.no_formal_ino
, 0);
876 error
= gfs2_inode_refresh(GFS2_I(inode
));
880 error
= gfs2_acl_create(dip
, inode
);
884 error
= gfs2_security_init(dip
, GFS2_I(inode
), name
);
888 error
= link_dinode(dip
, name
, GFS2_I(inode
));
897 gfs2_glock_dq_uninit(ghs
+ 1);
898 if (inode
&& !IS_ERR(inode
))
905 return ERR_PTR(error
);
908 static int __gfs2_setattr_simple(struct gfs2_inode
*ip
, struct iattr
*attr
)
910 struct inode
*inode
= &ip
->i_inode
;
911 struct buffer_head
*dibh
;
914 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
918 setattr_copy(inode
, attr
);
919 mark_inode_dirty(inode
);
920 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
921 gfs2_dinode_out(ip
, dibh
->b_data
);
927 * gfs2_setattr_simple -
931 * Called with a reference on the vnode.
936 int gfs2_setattr_simple(struct gfs2_inode
*ip
, struct iattr
*attr
)
940 if (current
->journal_info
)
941 return __gfs2_setattr_simple(ip
, attr
);
943 error
= gfs2_trans_begin(GFS2_SB(&ip
->i_inode
), RES_DINODE
, 0);
947 error
= __gfs2_setattr_simple(ip
, attr
);
948 gfs2_trans_end(GFS2_SB(&ip
->i_inode
));
952 void gfs2_dinode_out(const struct gfs2_inode
*ip
, void *buf
)
954 struct gfs2_dinode
*str
= buf
;
956 str
->di_header
.mh_magic
= cpu_to_be32(GFS2_MAGIC
);
957 str
->di_header
.mh_type
= cpu_to_be32(GFS2_METATYPE_DI
);
958 str
->di_header
.mh_format
= cpu_to_be32(GFS2_FORMAT_DI
);
959 str
->di_num
.no_addr
= cpu_to_be64(ip
->i_no_addr
);
960 str
->di_num
.no_formal_ino
= cpu_to_be64(ip
->i_no_formal_ino
);
961 str
->di_mode
= cpu_to_be32(ip
->i_inode
.i_mode
);
962 str
->di_uid
= cpu_to_be32(ip
->i_inode
.i_uid
);
963 str
->di_gid
= cpu_to_be32(ip
->i_inode
.i_gid
);
964 str
->di_nlink
= cpu_to_be32(ip
->i_inode
.i_nlink
);
965 str
->di_size
= cpu_to_be64(i_size_read(&ip
->i_inode
));
966 str
->di_blocks
= cpu_to_be64(gfs2_get_inode_blocks(&ip
->i_inode
));
967 str
->di_atime
= cpu_to_be64(ip
->i_inode
.i_atime
.tv_sec
);
968 str
->di_mtime
= cpu_to_be64(ip
->i_inode
.i_mtime
.tv_sec
);
969 str
->di_ctime
= cpu_to_be64(ip
->i_inode
.i_ctime
.tv_sec
);
971 str
->di_goal_meta
= cpu_to_be64(ip
->i_goal
);
972 str
->di_goal_data
= cpu_to_be64(ip
->i_goal
);
973 str
->di_generation
= cpu_to_be64(ip
->i_generation
);
975 str
->di_flags
= cpu_to_be32(ip
->i_diskflags
);
976 str
->di_height
= cpu_to_be16(ip
->i_height
);
977 str
->di_payload_format
= cpu_to_be32(S_ISDIR(ip
->i_inode
.i_mode
) &&
978 !(ip
->i_diskflags
& GFS2_DIF_EXHASH
) ?
980 str
->di_depth
= cpu_to_be16(ip
->i_depth
);
981 str
->di_entries
= cpu_to_be32(ip
->i_entries
);
983 str
->di_eattr
= cpu_to_be64(ip
->i_eattr
);
984 str
->di_atime_nsec
= cpu_to_be32(ip
->i_inode
.i_atime
.tv_nsec
);
985 str
->di_mtime_nsec
= cpu_to_be32(ip
->i_inode
.i_mtime
.tv_nsec
);
986 str
->di_ctime_nsec
= cpu_to_be32(ip
->i_inode
.i_ctime
.tv_nsec
);
989 void gfs2_dinode_print(const struct gfs2_inode
*ip
)
991 printk(KERN_INFO
" no_formal_ino = %llu\n",
992 (unsigned long long)ip
->i_no_formal_ino
);
993 printk(KERN_INFO
" no_addr = %llu\n",
994 (unsigned long long)ip
->i_no_addr
);
995 printk(KERN_INFO
" i_size = %llu\n",
996 (unsigned long long)i_size_read(&ip
->i_inode
));
997 printk(KERN_INFO
" blocks = %llu\n",
998 (unsigned long long)gfs2_get_inode_blocks(&ip
->i_inode
));
999 printk(KERN_INFO
" i_goal = %llu\n",
1000 (unsigned long long)ip
->i_goal
);
1001 printk(KERN_INFO
" i_diskflags = 0x%.8X\n", ip
->i_diskflags
);
1002 printk(KERN_INFO
" i_height = %u\n", ip
->i_height
);
1003 printk(KERN_INFO
" i_depth = %u\n", ip
->i_depth
);
1004 printk(KERN_INFO
" i_entries = %u\n", ip
->i_entries
);
1005 printk(KERN_INFO
" i_eattr = %llu\n",
1006 (unsigned long long)ip
->i_eattr
);