aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/inode.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-08-01 06:40:02 -0400
committerNeilBrown <neilb@suse.de>2012-08-01 06:40:02 -0400
commitbb181e2e48f8c85db08c9cb015cbba9618dbf05c (patch)
tree191bc24dd97bcb174535cc217af082f16da3b43d /fs/gfs2/inode.c
parentd57368afe63b3b7b45ce6c2b8c5276417935be2f (diff)
parentc039c332f23e794deb6d6f37b9f07ff3b27fb2cf (diff)
Merge commit 'c039c332f23e794deb6d6f37b9f07ff3b27fb2cf' into md
Pull in pre-requisites for adding raid10 support to dm-raid.
Diffstat (limited to 'fs/gfs2/inode.c')
-rw-r--r--fs/gfs2/inode.c101
1 files changed, 51 insertions, 50 deletions
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index a9ba2444e077..4ce22e547308 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -521,12 +521,13 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
521 int error; 521 int error;
522 522
523 munge_mode_uid_gid(dip, &mode, &uid, &gid); 523 munge_mode_uid_gid(dip, &mode, &uid, &gid);
524 if (!gfs2_qadata_get(dip)) 524 error = gfs2_rindex_update(sdp);
525 return -ENOMEM; 525 if (error)
526 return error;
526 527
527 error = gfs2_quota_lock(dip, uid, gid); 528 error = gfs2_quota_lock(dip, uid, gid);
528 if (error) 529 if (error)
529 goto out; 530 return error;
530 531
531 error = gfs2_quota_check(dip, uid, gid); 532 error = gfs2_quota_check(dip, uid, gid);
532 if (error) 533 if (error)
@@ -542,8 +543,6 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
542 543
543out_quota: 544out_quota:
544 gfs2_quota_unlock(dip); 545 gfs2_quota_unlock(dip);
545out:
546 gfs2_qadata_put(dip);
547 return error; 546 return error;
548} 547}
549 548
@@ -551,14 +550,13 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
551 struct gfs2_inode *ip) 550 struct gfs2_inode *ip)
552{ 551{
553 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 552 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
554 struct gfs2_qadata *qa;
555 int alloc_required; 553 int alloc_required;
556 struct buffer_head *dibh; 554 struct buffer_head *dibh;
557 int error; 555 int error;
558 556
559 qa = gfs2_qadata_get(dip); 557 error = gfs2_rindex_update(sdp);
560 if (!qa) 558 if (error)
561 return -ENOMEM; 559 return error;
562 560
563 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); 561 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
564 if (error) 562 if (error)
@@ -605,13 +603,13 @@ fail_end_trans:
605 gfs2_trans_end(sdp); 603 gfs2_trans_end(sdp);
606 604
607fail_ipreserv: 605fail_ipreserv:
608 gfs2_inplace_release(dip); 606 if (alloc_required)
607 gfs2_inplace_release(dip);
609 608
610fail_quota_locks: 609fail_quota_locks:
611 gfs2_quota_unlock(dip); 610 gfs2_quota_unlock(dip);
612 611
613fail: 612fail:
614 gfs2_qadata_put(dip);
615 return error; 613 return error;
616} 614}
617 615
@@ -657,7 +655,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
657 const struct qstr *name = &dentry->d_name; 655 const struct qstr *name = &dentry->d_name;
658 struct gfs2_holder ghs[2]; 656 struct gfs2_holder ghs[2];
659 struct inode *inode = NULL; 657 struct inode *inode = NULL;
660 struct gfs2_inode *dip = GFS2_I(dir); 658 struct gfs2_inode *dip = GFS2_I(dir), *ip;
661 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 659 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
662 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; 660 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 };
663 int error; 661 int error;
@@ -667,6 +665,15 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
667 if (!name->len || name->len > GFS2_FNAMESIZE) 665 if (!name->len || name->len > GFS2_FNAMESIZE)
668 return -ENAMETOOLONG; 666 return -ENAMETOOLONG;
669 667
668 /* We need a reservation to allocate the new dinode block. The
669 directory ip temporarily points to the reservation, but this is
670 being done to get a set of contiguous blocks for the new dinode.
671 Since this is a create, we don't have a sizehint yet, so it will
672 have to use the minimum reservation size. */
673 error = gfs2_rs_alloc(dip);
674 if (error)
675 return error;
676
670 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 677 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
671 if (error) 678 if (error)
672 goto fail; 679 goto fail;
@@ -700,19 +707,29 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
700 if (IS_ERR(inode)) 707 if (IS_ERR(inode))
701 goto fail_gunlock2; 708 goto fail_gunlock2;
702 709
703 error = gfs2_inode_refresh(GFS2_I(inode)); 710 ip = GFS2_I(inode);
711 error = gfs2_inode_refresh(ip);
704 if (error) 712 if (error)
705 goto fail_gunlock2; 713 goto fail_gunlock2;
706 714
715 /* The newly created inode needs a reservation so it can allocate
716 xattrs. At the same time, we want new blocks allocated to the new
717 dinode to be as contiguous as possible. Since we allocated the
718 dinode block under the directory's reservation, we transfer
719 ownership of that reservation to the new inode. The directory
720 doesn't need a reservation unless it needs a new allocation. */
721 ip->i_res = dip->i_res;
722 dip->i_res = NULL;
723
707 error = gfs2_acl_create(dip, inode); 724 error = gfs2_acl_create(dip, inode);
708 if (error) 725 if (error)
709 goto fail_gunlock2; 726 goto fail_gunlock2;
710 727
711 error = gfs2_security_init(dip, GFS2_I(inode), name); 728 error = gfs2_security_init(dip, ip, name);
712 if (error) 729 if (error)
713 goto fail_gunlock2; 730 goto fail_gunlock2;
714 731
715 error = link_dinode(dip, name, GFS2_I(inode)); 732 error = link_dinode(dip, name, ip);
716 if (error) 733 if (error)
717 goto fail_gunlock2; 734 goto fail_gunlock2;
718 735
@@ -722,10 +739,9 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
722 gfs2_trans_end(sdp); 739 gfs2_trans_end(sdp);
723 /* Check if we reserved space in the rgrp. Function link_dinode may 740 /* Check if we reserved space in the rgrp. Function link_dinode may
724 not, depending on whether alloc is required. */ 741 not, depending on whether alloc is required. */
725 if (dip->i_res) 742 if (gfs2_mb_reserved(dip))
726 gfs2_inplace_release(dip); 743 gfs2_inplace_release(dip);
727 gfs2_quota_unlock(dip); 744 gfs2_quota_unlock(dip);
728 gfs2_qadata_put(dip);
729 mark_inode_dirty(inode); 745 mark_inode_dirty(inode);
730 gfs2_glock_dq_uninit_m(2, ghs); 746 gfs2_glock_dq_uninit_m(2, ghs);
731 d_instantiate(dentry, inode); 747 d_instantiate(dentry, inode);
@@ -740,6 +756,7 @@ fail_gunlock:
740 iput(inode); 756 iput(inode);
741 } 757 }
742fail: 758fail:
759 gfs2_rs_delete(dip);
743 if (bh) 760 if (bh)
744 brelse(bh); 761 brelse(bh);
745 return error; 762 return error;
@@ -755,11 +772,8 @@ fail:
755 */ 772 */
756 773
757static int gfs2_create(struct inode *dir, struct dentry *dentry, 774static int gfs2_create(struct inode *dir, struct dentry *dentry,
758 umode_t mode, struct nameidata *nd) 775 umode_t mode, bool excl)
759{ 776{
760 int excl = 0;
761 if (nd && (nd->flags & LOOKUP_EXCL))
762 excl = 1;
763 return gfs2_create_inode(dir, dentry, S_IFREG | mode, 0, NULL, 0, excl); 777 return gfs2_create_inode(dir, dentry, S_IFREG | mode, 0, NULL, 0, excl);
764} 778}
765 779
@@ -775,7 +789,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
775 */ 789 */
776 790
777static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, 791static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
778 struct nameidata *nd) 792 unsigned int flags)
779{ 793{
780 struct inode *inode = gfs2_lookupi(dir, &dentry->d_name, 0); 794 struct inode *inode = gfs2_lookupi(dir, &dentry->d_name, 0);
781 if (inode && !IS_ERR(inode)) { 795 if (inode && !IS_ERR(inode)) {
@@ -819,6 +833,10 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
819 if (S_ISDIR(inode->i_mode)) 833 if (S_ISDIR(inode->i_mode))
820 return -EPERM; 834 return -EPERM;
821 835
836 error = gfs2_rs_alloc(dip);
837 if (error)
838 return error;
839
822 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 840 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
823 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); 841 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
824 842
@@ -870,16 +888,9 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
870 error = 0; 888 error = 0;
871 889
872 if (alloc_required) { 890 if (alloc_required) {
873 struct gfs2_qadata *qa = gfs2_qadata_get(dip);
874
875 if (!qa) {
876 error = -ENOMEM;
877 goto out_gunlock;
878 }
879
880 error = gfs2_quota_lock_check(dip); 891 error = gfs2_quota_lock_check(dip);
881 if (error) 892 if (error)
882 goto out_alloc; 893 goto out_gunlock;
883 894
884 error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres); 895 error = gfs2_inplace_reserve(dip, sdp->sd_max_dirres);
885 if (error) 896 if (error)
@@ -922,9 +933,6 @@ out_ipres:
922out_gunlock_q: 933out_gunlock_q:
923 if (alloc_required) 934 if (alloc_required)
924 gfs2_quota_unlock(dip); 935 gfs2_quota_unlock(dip);
925out_alloc:
926 if (alloc_required)
927 gfs2_qadata_put(dip);
928out_gunlock: 936out_gunlock:
929 gfs2_glock_dq(ghs + 1); 937 gfs2_glock_dq(ghs + 1);
930out_child: 938out_child:
@@ -1234,6 +1242,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1234 if (error) 1242 if (error)
1235 return error; 1243 return error;
1236 1244
1245 error = gfs2_rs_alloc(ndip);
1246 if (error)
1247 return error;
1248
1237 if (odip != ndip) { 1249 if (odip != ndip) {
1238 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 1250 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
1239 0, &r_gh); 1251 0, &r_gh);
@@ -1357,16 +1369,9 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1357 goto out_gunlock; 1369 goto out_gunlock;
1358 1370
1359 if (alloc_required) { 1371 if (alloc_required) {
1360 struct gfs2_qadata *qa = gfs2_qadata_get(ndip);
1361
1362 if (!qa) {
1363 error = -ENOMEM;
1364 goto out_gunlock;
1365 }
1366
1367 error = gfs2_quota_lock_check(ndip); 1372 error = gfs2_quota_lock_check(ndip);
1368 if (error) 1373 if (error)
1369 goto out_alloc; 1374 goto out_gunlock;
1370 1375
1371 error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres); 1376 error = gfs2_inplace_reserve(ndip, sdp->sd_max_dirres);
1372 if (error) 1377 if (error)
@@ -1427,9 +1432,6 @@ out_ipreserv:
1427out_gunlock_q: 1432out_gunlock_q:
1428 if (alloc_required) 1433 if (alloc_required)
1429 gfs2_quota_unlock(ndip); 1434 gfs2_quota_unlock(ndip);
1430out_alloc:
1431 if (alloc_required)
1432 gfs2_qadata_put(ndip);
1433out_gunlock: 1435out_gunlock:
1434 while (x--) { 1436 while (x--) {
1435 gfs2_glock_dq(ghs + x); 1437 gfs2_glock_dq(ghs + x);
@@ -1590,12 +1592,9 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
1590 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) 1592 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
1591 ogid = ngid = NO_QUOTA_CHANGE; 1593 ogid = ngid = NO_QUOTA_CHANGE;
1592 1594
1593 if (!gfs2_qadata_get(ip))
1594 return -ENOMEM;
1595
1596 error = gfs2_quota_lock(ip, nuid, ngid); 1595 error = gfs2_quota_lock(ip, nuid, ngid);
1597 if (error) 1596 if (error)
1598 goto out_alloc; 1597 return error;
1599 1598
1600 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { 1599 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
1601 error = gfs2_quota_check(ip, nuid, ngid); 1600 error = gfs2_quota_check(ip, nuid, ngid);
@@ -1621,8 +1620,6 @@ out_end_trans:
1621 gfs2_trans_end(sdp); 1620 gfs2_trans_end(sdp);
1622out_gunlock_q: 1621out_gunlock_q:
1623 gfs2_quota_unlock(ip); 1622 gfs2_quota_unlock(ip);
1624out_alloc:
1625 gfs2_qadata_put(ip);
1626 return error; 1623 return error;
1627} 1624}
1628 1625
@@ -1644,6 +1641,10 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1644 struct gfs2_holder i_gh; 1641 struct gfs2_holder i_gh;
1645 int error; 1642 int error;
1646 1643
1644 error = gfs2_rs_alloc(ip);
1645 if (error)
1646 return error;
1647
1647 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); 1648 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1648 if (error) 1649 if (error)
1649 return error; 1650 return error;