aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/inode.c
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2013-03-01 04:29:12 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2013-04-08 03:40:37 -0400
commit79ba74808df1132d9ddbf4e87304a4050e667e3e (patch)
tree0e5ddd568f03e4c9248321b9988d4a9e37c74400 /fs/gfs2/inode.c
parent28fb30275570e9397e551d6f8e3bfd78862ea79e (diff)
GFS2: Use gfs2_dinode_out() in the inode create path
Over the previous two patches relating to inode creation, the content of init_dinode() has been looking more and more like gfs2_dinode_out(). This is not an accident! This patch replaces the parts of init_dinode() which are duplicated in gfs2_dinode_out() with a call to that function. Mostly that is straightforward, but there is one issue which needed to be resolved relating to the link count. The link count has to be set to zero in a certain error handling code path, which lands up calling iput(). This is now done specifically in that code path allowing the link count to be set earlier and written into the on disk inode by gfs2_dinode_put() in the normal way. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/inode.c')
-rw-r--r--fs/gfs2/inode.c44
1 files changed, 9 insertions, 35 deletions
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index cb53b4ffc0d3..8833a4f264e3 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -446,46 +446,24 @@ static void gfs2_init_dir(struct buffer_head *dibh,
446 */ 446 */
447 447
448static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip, 448static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
449 const char *symname, struct buffer_head **bhp) 449 const char *symname)
450{ 450{
451 struct gfs2_dinode *di; 451 struct gfs2_dinode *di;
452 struct buffer_head *dibh; 452 struct buffer_head *dibh;
453 453
454 dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr); 454 dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr);
455 gfs2_trans_add_meta(ip->i_gl, dibh); 455 gfs2_trans_add_meta(ip->i_gl, dibh);
456 gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI);
457 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
458 di = (struct gfs2_dinode *)dibh->b_data; 456 di = (struct gfs2_dinode *)dibh->b_data;
457 gfs2_dinode_out(ip, di);
459 458
460 di->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
461 di->di_num.no_addr = cpu_to_be64(ip->i_no_addr);
462 di->di_mode = cpu_to_be32(ip->i_inode.i_mode);
463 di->di_uid = cpu_to_be32(i_uid_read(&ip->i_inode));
464 di->di_gid = cpu_to_be32(i_gid_read(&ip->i_inode));
465 di->di_nlink = 0;
466 di->di_size = cpu_to_be64(ip->i_inode.i_size);
467 di->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode));
468 di->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec);
469 di->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec);
470 di->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec);
471 di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev)); 459 di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev));
472 di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev)); 460 di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev));
473 di->di_goal_meta = di->di_goal_data = cpu_to_be64(ip->i_no_addr);
474 di->di_generation = cpu_to_be64(ip->i_generation);
475 di->di_flags = cpu_to_be32(ip->i_diskflags);
476 di->__pad1 = 0; 461 di->__pad1 = 0;
477 di->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) ? GFS2_FORMAT_DE : 0);
478 di->di_height = cpu_to_be16(ip->i_height);
479 di->__pad2 = 0; 462 di->__pad2 = 0;
480 di->__pad3 = 0; 463 di->__pad3 = 0;
481 di->di_depth = cpu_to_be16(ip->i_depth);
482 di->di_entries = cpu_to_be32(ip->i_entries);
483 memset(&di->__pad4, 0, sizeof(di->__pad4)); 464 memset(&di->__pad4, 0, sizeof(di->__pad4));
484 di->di_eattr = cpu_to_be64(ip->i_eattr);
485 di->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec);
486 di->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec);
487 di->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec);
488 memset(&di->di_reserved, 0, sizeof(di->di_reserved)); 465 memset(&di->di_reserved, 0, sizeof(di->di_reserved));
466 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
489 467
490 switch(ip->i_inode.i_mode & S_IFMT) { 468 switch(ip->i_inode.i_mode & S_IFMT) {
491 case S_IFDIR: 469 case S_IFDIR:
@@ -497,8 +475,7 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
497 } 475 }
498 476
499 set_buffer_uptodate(dibh); 477 set_buffer_uptodate(dibh);
500 478 brelse(dibh);
501 *bhp = dibh;
502} 479}
503 480
504static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, 481static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
@@ -532,9 +509,6 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
532 if (error) 509 if (error)
533 goto fail_end_trans; 510 goto fail_end_trans;
534 511
535 set_nlink(&ip->i_inode, S_ISDIR(ip->i_inode.i_mode) ? 2 : 1);
536 mark_inode_dirty(&ip->i_inode);
537
538fail_end_trans: 512fail_end_trans:
539 gfs2_trans_end(sdp); 513 gfs2_trans_end(sdp);
540fail_ipreserv: 514fail_ipreserv:
@@ -590,7 +564,6 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
590 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 564 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
591 struct gfs2_glock *io_gl; 565 struct gfs2_glock *io_gl;
592 int error; 566 int error;
593 struct buffer_head *bh = NULL;
594 u32 aflags = 0; 567 u32 aflags = 0;
595 int arq; 568 int arq;
596 569
@@ -634,6 +607,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
634 goto fail_free_inode; 607 goto fail_free_inode;
635 608
636 inode->i_mode = mode; 609 inode->i_mode = mode;
610 set_nlink(inode, S_ISDIR(mode) ? 2 : 1);
637 inode->i_rdev = dev; 611 inode->i_rdev = dev;
638 inode->i_size = size; 612 inode->i_size = size;
639 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 613 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
@@ -682,7 +656,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
682 if (error) 656 if (error)
683 goto fail_gunlock2; 657 goto fail_gunlock2;
684 658
685 init_dinode(dip, ip, symname, &bh); 659 init_dinode(dip, ip, symname);
686 gfs2_trans_end(sdp); 660 gfs2_trans_end(sdp);
687 661
688 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl); 662 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
@@ -710,7 +684,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
710 if (error) 684 if (error)
711 goto fail_gunlock3; 685 goto fail_gunlock3;
712 686
713 brelse(bh); 687 mark_inode_dirty(inode);
714 gfs2_glock_dq_uninit(ghs); 688 gfs2_glock_dq_uninit(ghs);
715 gfs2_glock_dq_uninit(ghs + 1); 689 gfs2_glock_dq_uninit(ghs + 1);
716 d_instantiate(dentry, inode); 690 d_instantiate(dentry, inode);
@@ -733,12 +707,12 @@ fail_free_inode:
733fail_gunlock: 707fail_gunlock:
734 gfs2_glock_dq_uninit(ghs); 708 gfs2_glock_dq_uninit(ghs);
735 if (inode && !IS_ERR(inode)) { 709 if (inode && !IS_ERR(inode)) {
710 clear_nlink(inode);
711 mark_inode_dirty(inode);
736 set_bit(GIF_ALLOC_FAILED, &GFS2_I(inode)->i_flags); 712 set_bit(GIF_ALLOC_FAILED, &GFS2_I(inode)->i_flags);
737 iput(inode); 713 iput(inode);
738 } 714 }
739fail: 715fail:
740 if (bh)
741 brelse(bh);
742 return error; 716 return error;
743} 717}
744 718