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
);
76 struct gfs2_skip_data
{
81 static int iget_skip_test(struct inode
*inode
, void *opaque
)
83 struct gfs2_inode
*ip
= GFS2_I(inode
);
84 struct gfs2_skip_data
*data
= opaque
;
86 if (ip
->i_no_addr
== data
->no_addr
) {
87 if (inode
->i_state
& (I_FREEING
|I_CLEAR
|I_WILL_FREE
)){
96 static int iget_skip_set(struct inode
*inode
, void *opaque
)
98 struct gfs2_inode
*ip
= GFS2_I(inode
);
99 struct gfs2_skip_data
*data
= opaque
;
103 inode
->i_ino
= (unsigned long)(data
->no_addr
);
104 ip
->i_no_addr
= data
->no_addr
;
108 static struct inode
*gfs2_iget_skip(struct super_block
*sb
,
111 struct gfs2_skip_data data
;
112 unsigned long hash
= (unsigned long)no_addr
;
114 data
.no_addr
= no_addr
;
116 return iget5_locked(sb
, hash
, iget_skip_test
, iget_skip_set
, &data
);
120 * GFS2 lookup code fills in vfs inode contents based on info obtained
121 * from directory entry inside gfs2_inode_lookup(). This has caused issues
122 * with NFS code path since its get_dentry routine doesn't have the relevant
123 * directory entry when gfs2_inode_lookup() is invoked. Part of the code
124 * segment inside gfs2_inode_lookup code needs to get moved around.
126 * Clears I_NEW as well.
129 void gfs2_set_iop(struct inode
*inode
)
131 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
132 umode_t mode
= inode
->i_mode
;
135 inode
->i_op
= &gfs2_file_iops
;
136 if (gfs2_localflocks(sdp
))
137 inode
->i_fop
= &gfs2_file_fops_nolock
;
139 inode
->i_fop
= &gfs2_file_fops
;
140 } else if (S_ISDIR(mode
)) {
141 inode
->i_op
= &gfs2_dir_iops
;
142 if (gfs2_localflocks(sdp
))
143 inode
->i_fop
= &gfs2_dir_fops_nolock
;
145 inode
->i_fop
= &gfs2_dir_fops
;
146 } else if (S_ISLNK(mode
)) {
147 inode
->i_op
= &gfs2_symlink_iops
;
149 inode
->i_op
= &gfs2_file_iops
;
150 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
153 unlock_new_inode(inode
);
157 * gfs2_inode_lookup - Lookup an inode
158 * @sb: The super block
159 * @no_addr: The inode number
160 * @type: The type of the inode
161 * @skip_freeing: set this not return an inode if it is currently being freed.
163 * Returns: A VFS inode, or an error
166 struct inode
*gfs2_inode_lookup(struct super_block
*sb
,
169 u64 no_formal_ino
, int skip_freeing
)
172 struct gfs2_inode
*ip
;
173 struct gfs2_glock
*io_gl
;
177 inode
= gfs2_iget_skip(sb
, no_addr
);
179 inode
= gfs2_iget(sb
, no_addr
);
183 return ERR_PTR(-ENOBUFS
);
185 if (inode
->i_state
& I_NEW
) {
186 struct gfs2_sbd
*sdp
= GFS2_SB(inode
);
187 ip
->i_no_formal_ino
= no_formal_ino
;
189 error
= gfs2_glock_get(sdp
, no_addr
, &gfs2_inode_glops
, CREATE
, &ip
->i_gl
);
192 ip
->i_gl
->gl_object
= ip
;
194 error
= gfs2_glock_get(sdp
, no_addr
, &gfs2_iopen_glops
, CREATE
, &io_gl
);
198 set_bit(GIF_INVALID
, &ip
->i_flags
);
199 error
= gfs2_glock_nq_init(io_gl
, LM_ST_SHARED
, GL_EXACT
, &ip
->i_iopen_gh
);
202 ip
->i_iopen_gh
.gh_gl
->gl_object
= ip
;
204 gfs2_glock_put(io_gl
);
206 if ((type
== DT_UNKNOWN
) && (no_formal_ino
== 0))
209 inode
->i_mode
= DT2IF(type
);
212 * We must read the inode in order to work out its type in
213 * this case. Note that this doesn't happen often as we normally
214 * know the type beforehand. This code path only occurs during
215 * unlinked inode recovery (where it is safe to do this glock,
216 * which is not true in the general case).
218 if (type
== DT_UNKNOWN
) {
219 struct gfs2_holder gh
;
220 error
= gfs2_glock_nq_init(ip
->i_gl
, LM_ST_EXCLUSIVE
, 0, &gh
);
223 /* Inode is now uptodate */
224 gfs2_glock_dq_uninit(&gh
);
233 gfs2_glock_dq(&ip
->i_iopen_gh
);
235 gfs2_glock_put(io_gl
);
237 ip
->i_gl
->gl_object
= NULL
;
238 gfs2_glock_put(ip
->i_gl
);
241 return ERR_PTR(error
);
244 static int gfs2_dinode_in(struct gfs2_inode
*ip
, const void *buf
)
246 const struct gfs2_dinode
*str
= buf
;
247 struct timespec atime
;
250 if (unlikely(ip
->i_no_addr
!= be64_to_cpu(str
->di_num
.no_addr
)))
252 ip
->i_no_formal_ino
= be64_to_cpu(str
->di_num
.no_formal_ino
);
253 ip
->i_inode
.i_mode
= be32_to_cpu(str
->di_mode
);
254 ip
->i_inode
.i_rdev
= 0;
255 switch (ip
->i_inode
.i_mode
& S_IFMT
) {
258 ip
->i_inode
.i_rdev
= MKDEV(be32_to_cpu(str
->di_major
),
259 be32_to_cpu(str
->di_minor
));
263 ip
->i_inode
.i_uid
= be32_to_cpu(str
->di_uid
);
264 ip
->i_inode
.i_gid
= be32_to_cpu(str
->di_gid
);
266 * We will need to review setting the nlink count here in the
267 * light of the forthcoming ro bind mount work. This is a reminder
270 ip
->i_inode
.i_nlink
= be32_to_cpu(str
->di_nlink
);
271 ip
->i_disksize
= be64_to_cpu(str
->di_size
);
272 i_size_write(&ip
->i_inode
, ip
->i_disksize
);
273 gfs2_set_inode_blocks(&ip
->i_inode
, be64_to_cpu(str
->di_blocks
));
274 atime
.tv_sec
= be64_to_cpu(str
->di_atime
);
275 atime
.tv_nsec
= be32_to_cpu(str
->di_atime_nsec
);
276 if (timespec_compare(&ip
->i_inode
.i_atime
, &atime
) < 0)
277 ip
->i_inode
.i_atime
= atime
;
278 ip
->i_inode
.i_mtime
.tv_sec
= be64_to_cpu(str
->di_mtime
);
279 ip
->i_inode
.i_mtime
.tv_nsec
= be32_to_cpu(str
->di_mtime_nsec
);
280 ip
->i_inode
.i_ctime
.tv_sec
= be64_to_cpu(str
->di_ctime
);
281 ip
->i_inode
.i_ctime
.tv_nsec
= be32_to_cpu(str
->di_ctime_nsec
);
283 ip
->i_goal
= be64_to_cpu(str
->di_goal_meta
);
284 ip
->i_generation
= be64_to_cpu(str
->di_generation
);
286 ip
->i_diskflags
= be32_to_cpu(str
->di_flags
);
287 gfs2_set_inode_flags(&ip
->i_inode
);
288 height
= be16_to_cpu(str
->di_height
);
289 if (unlikely(height
> GFS2_MAX_META_HEIGHT
))
291 ip
->i_height
= (u8
)height
;
293 depth
= be16_to_cpu(str
->di_depth
);
294 if (unlikely(depth
> GFS2_DIR_MAX_DEPTH
))
296 ip
->i_depth
= (u8
)depth
;
297 ip
->i_entries
= be32_to_cpu(str
->di_entries
);
299 ip
->i_eattr
= be64_to_cpu(str
->di_eattr
);
300 if (S_ISREG(ip
->i_inode
.i_mode
))
301 gfs2_set_aops(&ip
->i_inode
);
305 if (gfs2_consist_inode(ip
))
306 gfs2_dinode_print(ip
);
311 * gfs2_inode_refresh - Refresh the incore copy of the dinode
312 * @ip: The GFS2 inode
317 int gfs2_inode_refresh(struct gfs2_inode
*ip
)
319 struct buffer_head
*dibh
;
322 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
326 if (gfs2_metatype_check(GFS2_SB(&ip
->i_inode
), dibh
, GFS2_METATYPE_DI
)) {
331 error
= gfs2_dinode_in(ip
, dibh
->b_data
);
333 clear_bit(GIF_INVALID
, &ip
->i_flags
);
338 int gfs2_dinode_dealloc(struct gfs2_inode
*ip
)
340 struct gfs2_sbd
*sdp
= GFS2_SB(&ip
->i_inode
);
341 struct gfs2_alloc
*al
;
342 struct gfs2_rgrpd
*rgd
;
345 if (gfs2_get_inode_blocks(&ip
->i_inode
) != 1) {
346 if (gfs2_consist_inode(ip
))
347 gfs2_dinode_print(ip
);
351 al
= gfs2_alloc_get(ip
);
355 error
= gfs2_quota_hold(ip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
359 error
= gfs2_rindex_hold(sdp
, &al
->al_ri_gh
);
363 rgd
= gfs2_blk2rgrpd(sdp
, ip
->i_no_addr
);
365 gfs2_consist_inode(ip
);
367 goto out_rindex_relse
;
370 error
= gfs2_glock_nq_init(rgd
->rd_gl
, LM_ST_EXCLUSIVE
, 0,
373 goto out_rindex_relse
;
375 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
+ RES_QUOTA
, 1);
379 set_bit(GLF_DIRTY
, &ip
->i_gl
->gl_flags
);
380 set_bit(GLF_LFLUSH
, &ip
->i_gl
->gl_flags
);
382 gfs2_free_di(rgd
, ip
);
387 gfs2_glock_dq_uninit(&al
->al_rgd_gh
);
389 gfs2_glock_dq_uninit(&al
->al_ri_gh
);
391 gfs2_quota_unhold(ip
);
398 * gfs2_change_nlink - Change nlink count on inode
399 * @ip: The GFS2 inode
400 * @diff: The change in the nlink count required
404 int gfs2_change_nlink(struct gfs2_inode
*ip
, int diff
)
406 struct buffer_head
*dibh
;
410 BUG_ON(diff
!= 1 && diff
!= -1);
411 nlink
= ip
->i_inode
.i_nlink
+ diff
;
413 /* If we are reducing the nlink count, but the new value ends up being
414 bigger than the old one, we must have underflowed. */
415 if (diff
< 0 && nlink
> ip
->i_inode
.i_nlink
) {
416 if (gfs2_consist_inode(ip
))
417 gfs2_dinode_print(ip
);
421 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
426 inc_nlink(&ip
->i_inode
);
428 drop_nlink(&ip
->i_inode
);
430 ip
->i_inode
.i_ctime
= CURRENT_TIME
;
432 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
433 gfs2_dinode_out(ip
, dibh
->b_data
);
435 mark_inode_dirty(&ip
->i_inode
);
437 if (ip
->i_inode
.i_nlink
== 0)
438 gfs2_unlink_di(&ip
->i_inode
); /* mark inode unlinked */
443 struct inode
*gfs2_lookup_simple(struct inode
*dip
, const char *name
)
447 gfs2_str2qstr(&qstr
, name
);
448 inode
= gfs2_lookupi(dip
, &qstr
, 1);
449 /* gfs2_lookupi has inconsistent callers: vfs
450 * related routines expect NULL for no entry found,
451 * gfs2_lookup_simple callers expect ENOENT
452 * and do not check for NULL.
455 return ERR_PTR(-ENOENT
);
462 * gfs2_lookupi - Look up a filename in a directory and return its inode
463 * @d_gh: An initialized holder for the directory glock
464 * @name: The name of the inode to look for
465 * @is_root: If 1, ignore the caller's permissions
466 * @i_gh: An uninitialized holder for the new inode glock
468 * This can be called via the VFS filldir function when NFS is doing
469 * a readdirplus and the inode which its intending to stat isn't
470 * already in cache. In this case we must not take the directory glock
471 * again, since the readdir call will have already taken that lock.
476 struct inode
*gfs2_lookupi(struct inode
*dir
, const struct qstr
*name
,
479 struct super_block
*sb
= dir
->i_sb
;
480 struct gfs2_inode
*dip
= GFS2_I(dir
);
481 struct gfs2_holder d_gh
;
483 struct inode
*inode
= NULL
;
486 if (!name
->len
|| name
->len
> GFS2_FNAMESIZE
)
487 return ERR_PTR(-ENAMETOOLONG
);
489 if ((name
->len
== 1 && memcmp(name
->name
, ".", 1) == 0) ||
490 (name
->len
== 2 && memcmp(name
->name
, "..", 2) == 0 &&
491 dir
== sb
->s_root
->d_inode
)) {
496 if (gfs2_glock_is_locked_by_me(dip
->i_gl
) == NULL
) {
497 error
= gfs2_glock_nq_init(dip
->i_gl
, LM_ST_SHARED
, 0, &d_gh
);
499 return ERR_PTR(error
);
504 error
= gfs2_permission(dir
, MAY_EXEC
);
509 inode
= gfs2_dir_search(dir
, name
);
511 error
= PTR_ERR(inode
);
514 gfs2_glock_dq_uninit(&d_gh
);
515 if (error
== -ENOENT
)
517 return inode
? inode
: ERR_PTR(error
);
521 * create_ok - OK to create a new on-disk inode here?
522 * @dip: Directory in which dinode is to be created
523 * @name: Name of new dinode
529 static int create_ok(struct gfs2_inode
*dip
, const struct qstr
*name
,
534 error
= gfs2_permission(&dip
->i_inode
, MAY_WRITE
| MAY_EXEC
);
538 /* Don't create entries in an unlinked directory */
539 if (!dip
->i_inode
.i_nlink
)
542 error
= gfs2_dir_check(&dip
->i_inode
, name
, NULL
);
553 if (dip
->i_entries
== (u32
)-1)
555 if (S_ISDIR(mode
) && dip
->i_inode
.i_nlink
== (u32
)-1)
561 static void munge_mode_uid_gid(struct gfs2_inode
*dip
, unsigned int *mode
,
562 unsigned int *uid
, unsigned int *gid
)
564 if (GFS2_SB(&dip
->i_inode
)->sd_args
.ar_suiddir
&&
565 (dip
->i_inode
.i_mode
& S_ISUID
) && dip
->i_inode
.i_uid
) {
568 else if (dip
->i_inode
.i_uid
!= current_fsuid())
570 *uid
= dip
->i_inode
.i_uid
;
572 *uid
= current_fsuid();
574 if (dip
->i_inode
.i_mode
& S_ISGID
) {
577 *gid
= dip
->i_inode
.i_gid
;
579 *gid
= current_fsgid();
582 static int alloc_dinode(struct gfs2_inode
*dip
, u64
*no_addr
, u64
*generation
)
584 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
587 if (gfs2_alloc_get(dip
) == NULL
)
590 dip
->i_alloc
->al_requested
= RES_DINODE
;
591 error
= gfs2_inplace_reserve(dip
);
595 error
= gfs2_trans_begin(sdp
, RES_RG_BIT
+ RES_STATFS
, 0);
599 error
= gfs2_alloc_di(dip
, no_addr
, generation
);
604 gfs2_inplace_release(dip
);
611 * init_dinode - Fill in a new dinode structure
612 * @dip: the directory this inode is being created in
613 * @gl: The glock covering the new inode
614 * @inum: the inode number
615 * @mode: the file permissions
621 static void init_dinode(struct gfs2_inode
*dip
, struct gfs2_glock
*gl
,
622 const struct gfs2_inum_host
*inum
, unsigned int mode
,
623 unsigned int uid
, unsigned int gid
,
624 const u64
*generation
, dev_t dev
, struct buffer_head
**bhp
)
626 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
627 struct gfs2_dinode
*di
;
628 struct buffer_head
*dibh
;
629 struct timespec tv
= CURRENT_TIME
;
631 dibh
= gfs2_meta_new(gl
, inum
->no_addr
);
632 gfs2_trans_add_bh(gl
, dibh
, 1);
633 gfs2_metatype_set(dibh
, GFS2_METATYPE_DI
, GFS2_FORMAT_DI
);
634 gfs2_buffer_clear_tail(dibh
, sizeof(struct gfs2_dinode
));
635 di
= (struct gfs2_dinode
*)dibh
->b_data
;
637 di
->di_num
.no_formal_ino
= cpu_to_be64(inum
->no_formal_ino
);
638 di
->di_num
.no_addr
= cpu_to_be64(inum
->no_addr
);
639 di
->di_mode
= cpu_to_be32(mode
);
640 di
->di_uid
= cpu_to_be32(uid
);
641 di
->di_gid
= cpu_to_be32(gid
);
644 di
->di_blocks
= cpu_to_be64(1);
645 di
->di_atime
= di
->di_mtime
= di
->di_ctime
= cpu_to_be64(tv
.tv_sec
);
646 di
->di_major
= cpu_to_be32(MAJOR(dev
));
647 di
->di_minor
= cpu_to_be32(MINOR(dev
));
648 di
->di_goal_meta
= di
->di_goal_data
= cpu_to_be64(inum
->no_addr
);
649 di
->di_generation
= cpu_to_be64(*generation
);
653 if ((dip
->i_diskflags
& GFS2_DIF_INHERIT_JDATA
) ||
654 gfs2_tune_get(sdp
, gt_new_files_jdata
))
655 di
->di_flags
|= cpu_to_be32(GFS2_DIF_JDATA
);
656 } else if (S_ISDIR(mode
)) {
657 di
->di_flags
|= cpu_to_be32(dip
->i_diskflags
&
658 GFS2_DIF_INHERIT_JDATA
);
662 di
->di_payload_format
= cpu_to_be32(S_ISDIR(mode
) ? GFS2_FORMAT_DE
: 0);
668 memset(&di
->__pad4
, 0, sizeof(di
->__pad4
));
670 di
->di_atime_nsec
= cpu_to_be32(tv
.tv_nsec
);
671 di
->di_mtime_nsec
= cpu_to_be32(tv
.tv_nsec
);
672 di
->di_ctime_nsec
= cpu_to_be32(tv
.tv_nsec
);
673 memset(&di
->di_reserved
, 0, sizeof(di
->di_reserved
));
675 set_buffer_uptodate(dibh
);
680 static int make_dinode(struct gfs2_inode
*dip
, struct gfs2_glock
*gl
,
681 unsigned int mode
, const struct gfs2_inum_host
*inum
,
682 const u64
*generation
, dev_t dev
, struct buffer_head
**bhp
)
684 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
685 unsigned int uid
, gid
;
688 munge_mode_uid_gid(dip
, &mode
, &uid
, &gid
);
689 if (!gfs2_alloc_get(dip
))
692 error
= gfs2_quota_lock(dip
, uid
, gid
);
696 error
= gfs2_quota_check(dip
, uid
, gid
);
700 error
= gfs2_trans_begin(sdp
, RES_DINODE
+ RES_QUOTA
, 0);
704 init_dinode(dip
, gl
, inum
, mode
, uid
, gid
, generation
, dev
, bhp
);
705 gfs2_quota_change(dip
, +1, uid
, gid
);
709 gfs2_quota_unlock(dip
);
715 static int link_dinode(struct gfs2_inode
*dip
, const struct qstr
*name
,
716 struct gfs2_inode
*ip
)
718 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
719 struct gfs2_alloc
*al
;
721 struct buffer_head
*dibh
;
724 al
= gfs2_alloc_get(dip
);
728 error
= gfs2_quota_lock(dip
, NO_QUOTA_CHANGE
, NO_QUOTA_CHANGE
);
732 error
= alloc_required
= gfs2_diradd_alloc_required(&dip
->i_inode
, name
);
733 if (alloc_required
< 0)
734 goto fail_quota_locks
;
735 if (alloc_required
) {
736 error
= gfs2_quota_check(dip
, dip
->i_inode
.i_uid
, dip
->i_inode
.i_gid
);
738 goto fail_quota_locks
;
740 al
->al_requested
= sdp
->sd_max_dirres
;
742 error
= gfs2_inplace_reserve(dip
);
744 goto fail_quota_locks
;
746 error
= gfs2_trans_begin(sdp
, sdp
->sd_max_dirres
+
747 al
->al_rgd
->rd_length
+
749 RES_STATFS
+ RES_QUOTA
, 0);
753 error
= gfs2_trans_begin(sdp
, RES_LEAF
+ 2 * RES_DINODE
, 0);
755 goto fail_quota_locks
;
758 error
= gfs2_dir_add(&dip
->i_inode
, name
, ip
, IF2DT(ip
->i_inode
.i_mode
));
762 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
765 ip
->i_inode
.i_nlink
= 1;
766 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
767 gfs2_dinode_out(ip
, dibh
->b_data
);
775 if (dip
->i_alloc
->al_rgd
)
776 gfs2_inplace_release(dip
);
779 gfs2_quota_unlock(dip
);
786 static int gfs2_security_init(struct gfs2_inode
*dip
, struct gfs2_inode
*ip
)
793 err
= security_inode_init_security(&ip
->i_inode
, &dip
->i_inode
,
794 &name
, &value
, &len
);
797 if (err
== -EOPNOTSUPP
)
802 err
= __gfs2_xattr_set(&ip
->i_inode
, name
, value
, len
, 0,
803 GFS2_EATYPE_SECURITY
);
811 * gfs2_createi - Create a new inode
812 * @ghs: An array of two holders
813 * @name: The name of the new file
814 * @mode: the permissions on the new inode
816 * @ghs[0] is an initialized holder for the directory
817 * @ghs[1] is the holder for the inode lock
819 * If the return value is not NULL, the glocks on both the directory and the new
820 * file are held. A transaction has been started and an inplace reservation
826 struct inode
*gfs2_createi(struct gfs2_holder
*ghs
, const struct qstr
*name
,
827 unsigned int mode
, dev_t dev
)
829 struct inode
*inode
= NULL
;
830 struct gfs2_inode
*dip
= ghs
->gh_gl
->gl_object
;
831 struct inode
*dir
= &dip
->i_inode
;
832 struct gfs2_sbd
*sdp
= GFS2_SB(&dip
->i_inode
);
833 struct gfs2_inum_host inum
= { .no_addr
= 0, .no_formal_ino
= 0 };
836 struct buffer_head
*bh
= NULL
;
838 if (!name
->len
|| name
->len
> GFS2_FNAMESIZE
)
839 return ERR_PTR(-ENAMETOOLONG
);
841 gfs2_holder_reinit(LM_ST_EXCLUSIVE
, 0, ghs
);
842 error
= gfs2_glock_nq(ghs
);
846 error
= create_ok(dip
, name
, mode
);
850 error
= alloc_dinode(dip
, &inum
.no_addr
, &generation
);
853 inum
.no_formal_ino
= generation
;
855 error
= gfs2_glock_nq_num(sdp
, inum
.no_addr
, &gfs2_inode_glops
,
856 LM_ST_EXCLUSIVE
, GL_SKIP
, ghs
+ 1);
860 error
= make_dinode(dip
, ghs
[1].gh_gl
, mode
, &inum
, &generation
, dev
, &bh
);
864 inode
= gfs2_inode_lookup(dir
->i_sb
, IF2DT(mode
), inum
.no_addr
,
865 inum
.no_formal_ino
, 0);
869 error
= gfs2_inode_refresh(GFS2_I(inode
));
873 error
= gfs2_acl_create(dip
, inode
);
877 error
= gfs2_security_init(dip
, GFS2_I(inode
));
881 error
= link_dinode(dip
, name
, GFS2_I(inode
));
890 gfs2_glock_dq_uninit(ghs
+ 1);
891 if (inode
&& !IS_ERR(inode
))
898 return ERR_PTR(error
);
901 static int __gfs2_setattr_simple(struct gfs2_inode
*ip
, struct iattr
*attr
)
903 struct buffer_head
*dibh
;
906 error
= gfs2_meta_inode_buffer(ip
, &dibh
);
908 error
= inode_setattr(&ip
->i_inode
, attr
);
909 gfs2_assert_warn(GFS2_SB(&ip
->i_inode
), !error
);
910 gfs2_trans_add_bh(ip
->i_gl
, dibh
, 1);
911 gfs2_dinode_out(ip
, dibh
->b_data
);
918 * gfs2_setattr_simple -
922 * Called with a reference on the vnode.
927 int gfs2_setattr_simple(struct gfs2_inode
*ip
, struct iattr
*attr
)
931 if (current
->journal_info
)
932 return __gfs2_setattr_simple(ip
, attr
);
934 error
= gfs2_trans_begin(GFS2_SB(&ip
->i_inode
), RES_DINODE
, 0);
938 error
= __gfs2_setattr_simple(ip
, attr
);
939 gfs2_trans_end(GFS2_SB(&ip
->i_inode
));
943 void gfs2_dinode_out(const struct gfs2_inode
*ip
, void *buf
)
945 struct gfs2_dinode
*str
= buf
;
947 str
->di_header
.mh_magic
= cpu_to_be32(GFS2_MAGIC
);
948 str
->di_header
.mh_type
= cpu_to_be32(GFS2_METATYPE_DI
);
949 str
->di_header
.mh_format
= cpu_to_be32(GFS2_FORMAT_DI
);
950 str
->di_num
.no_addr
= cpu_to_be64(ip
->i_no_addr
);
951 str
->di_num
.no_formal_ino
= cpu_to_be64(ip
->i_no_formal_ino
);
952 str
->di_mode
= cpu_to_be32(ip
->i_inode
.i_mode
);
953 str
->di_uid
= cpu_to_be32(ip
->i_inode
.i_uid
);
954 str
->di_gid
= cpu_to_be32(ip
->i_inode
.i_gid
);
955 str
->di_nlink
= cpu_to_be32(ip
->i_inode
.i_nlink
);
956 str
->di_size
= cpu_to_be64(ip
->i_disksize
);
957 str
->di_blocks
= cpu_to_be64(gfs2_get_inode_blocks(&ip
->i_inode
));
958 str
->di_atime
= cpu_to_be64(ip
->i_inode
.i_atime
.tv_sec
);
959 str
->di_mtime
= cpu_to_be64(ip
->i_inode
.i_mtime
.tv_sec
);
960 str
->di_ctime
= cpu_to_be64(ip
->i_inode
.i_ctime
.tv_sec
);
962 str
->di_goal_meta
= cpu_to_be64(ip
->i_goal
);
963 str
->di_goal_data
= cpu_to_be64(ip
->i_goal
);
964 str
->di_generation
= cpu_to_be64(ip
->i_generation
);
966 str
->di_flags
= cpu_to_be32(ip
->i_diskflags
);
967 str
->di_height
= cpu_to_be16(ip
->i_height
);
968 str
->di_payload_format
= cpu_to_be32(S_ISDIR(ip
->i_inode
.i_mode
) &&
969 !(ip
->i_diskflags
& GFS2_DIF_EXHASH
) ?
971 str
->di_depth
= cpu_to_be16(ip
->i_depth
);
972 str
->di_entries
= cpu_to_be32(ip
->i_entries
);
974 str
->di_eattr
= cpu_to_be64(ip
->i_eattr
);
975 str
->di_atime_nsec
= cpu_to_be32(ip
->i_inode
.i_atime
.tv_nsec
);
976 str
->di_mtime_nsec
= cpu_to_be32(ip
->i_inode
.i_mtime
.tv_nsec
);
977 str
->di_ctime_nsec
= cpu_to_be32(ip
->i_inode
.i_ctime
.tv_nsec
);
980 void gfs2_dinode_print(const struct gfs2_inode
*ip
)
982 printk(KERN_INFO
" no_formal_ino = %llu\n",
983 (unsigned long long)ip
->i_no_formal_ino
);
984 printk(KERN_INFO
" no_addr = %llu\n",
985 (unsigned long long)ip
->i_no_addr
);
986 printk(KERN_INFO
" i_disksize = %llu\n",
987 (unsigned long long)ip
->i_disksize
);
988 printk(KERN_INFO
" blocks = %llu\n",
989 (unsigned long long)gfs2_get_inode_blocks(&ip
->i_inode
));
990 printk(KERN_INFO
" i_goal = %llu\n",
991 (unsigned long long)ip
->i_goal
);
992 printk(KERN_INFO
" i_diskflags = 0x%.8X\n", ip
->i_diskflags
);
993 printk(KERN_INFO
" i_height = %u\n", ip
->i_height
);
994 printk(KERN_INFO
" i_depth = %u\n", ip
->i_depth
);
995 printk(KERN_INFO
" i_entries = %u\n", ip
->i_entries
);
996 printk(KERN_INFO
" i_eattr = %llu\n",
997 (unsigned long long)ip
->i_eattr
);