aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/quota.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/quota.c')
-rw-r--r--fs/gfs2/quota.c72
1 files changed, 41 insertions, 31 deletions
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 27b5cc7d688..a3bde91645c 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -494,11 +494,15 @@ static void qdsb_put(struct gfs2_quota_data *qd)
494int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid) 494int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
495{ 495{
496 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 496 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
497 struct gfs2_qadata *qa = ip->i_qadata; 497 struct gfs2_quota_data **qd;
498 struct gfs2_quota_data **qd = qa->qa_qd;
499 int error; 498 int error;
500 499
501 if (gfs2_assert_warn(sdp, !qa->qa_qd_num) || 500 if (ip->i_res == NULL)
501 gfs2_rs_alloc(ip);
502
503 qd = ip->i_res->rs_qa_qd;
504
505 if (gfs2_assert_warn(sdp, !ip->i_res->rs_qa_qd_num) ||
502 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) 506 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)))
503 return -EIO; 507 return -EIO;
504 508
@@ -508,20 +512,20 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
508 error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, qd); 512 error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, qd);
509 if (error) 513 if (error)
510 goto out; 514 goto out;
511 qa->qa_qd_num++; 515 ip->i_res->rs_qa_qd_num++;
512 qd++; 516 qd++;
513 517
514 error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, qd); 518 error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, qd);
515 if (error) 519 if (error)
516 goto out; 520 goto out;
517 qa->qa_qd_num++; 521 ip->i_res->rs_qa_qd_num++;
518 qd++; 522 qd++;
519 523
520 if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) { 524 if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) {
521 error = qdsb_get(sdp, QUOTA_USER, uid, qd); 525 error = qdsb_get(sdp, QUOTA_USER, uid, qd);
522 if (error) 526 if (error)
523 goto out; 527 goto out;
524 qa->qa_qd_num++; 528 ip->i_res->rs_qa_qd_num++;
525 qd++; 529 qd++;
526 } 530 }
527 531
@@ -529,7 +533,7 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
529 error = qdsb_get(sdp, QUOTA_GROUP, gid, qd); 533 error = qdsb_get(sdp, QUOTA_GROUP, gid, qd);
530 if (error) 534 if (error)
531 goto out; 535 goto out;
532 qa->qa_qd_num++; 536 ip->i_res->rs_qa_qd_num++;
533 qd++; 537 qd++;
534 } 538 }
535 539
@@ -542,16 +546,17 @@ out:
542void gfs2_quota_unhold(struct gfs2_inode *ip) 546void gfs2_quota_unhold(struct gfs2_inode *ip)
543{ 547{
544 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 548 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
545 struct gfs2_qadata *qa = ip->i_qadata;
546 unsigned int x; 549 unsigned int x;
547 550
551 if (ip->i_res == NULL)
552 return;
548 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); 553 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
549 554
550 for (x = 0; x < qa->qa_qd_num; x++) { 555 for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) {
551 qdsb_put(qa->qa_qd[x]); 556 qdsb_put(ip->i_res->rs_qa_qd[x]);
552 qa->qa_qd[x] = NULL; 557 ip->i_res->rs_qa_qd[x] = NULL;
553 } 558 }
554 qa->qa_qd_num = 0; 559 ip->i_res->rs_qa_qd_num = 0;
555} 560}
556 561
557static int sort_qd(const void *a, const void *b) 562static int sort_qd(const void *a, const void *b)
@@ -764,6 +769,10 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
764 unsigned int nalloc = 0, blocks; 769 unsigned int nalloc = 0, blocks;
765 int error; 770 int error;
766 771
772 error = gfs2_rs_alloc(ip);
773 if (error)
774 return error;
775
767 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), 776 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
768 &data_blocks, &ind_blocks); 777 &data_blocks, &ind_blocks);
769 778
@@ -915,7 +924,6 @@ fail:
915int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) 924int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
916{ 925{
917 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 926 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
918 struct gfs2_qadata *qa = ip->i_qadata;
919 struct gfs2_quota_data *qd; 927 struct gfs2_quota_data *qd;
920 unsigned int x; 928 unsigned int x;
921 int error = 0; 929 int error = 0;
@@ -928,15 +936,15 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
928 sdp->sd_args.ar_quota != GFS2_QUOTA_ON) 936 sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
929 return 0; 937 return 0;
930 938
931 sort(qa->qa_qd, qa->qa_qd_num, sizeof(struct gfs2_quota_data *), 939 sort(ip->i_res->rs_qa_qd, ip->i_res->rs_qa_qd_num,
932 sort_qd, NULL); 940 sizeof(struct gfs2_quota_data *), sort_qd, NULL);
933 941
934 for (x = 0; x < qa->qa_qd_num; x++) { 942 for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) {
935 int force = NO_FORCE; 943 int force = NO_FORCE;
936 qd = qa->qa_qd[x]; 944 qd = ip->i_res->rs_qa_qd[x];
937 if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags)) 945 if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags))
938 force = FORCE; 946 force = FORCE;
939 error = do_glock(qd, force, &qa->qa_qd_ghs[x]); 947 error = do_glock(qd, force, &ip->i_res->rs_qa_qd_ghs[x]);
940 if (error) 948 if (error)
941 break; 949 break;
942 } 950 }
@@ -945,7 +953,7 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
945 set_bit(GIF_QD_LOCKED, &ip->i_flags); 953 set_bit(GIF_QD_LOCKED, &ip->i_flags);
946 else { 954 else {
947 while (x--) 955 while (x--)
948 gfs2_glock_dq_uninit(&qa->qa_qd_ghs[x]); 956 gfs2_glock_dq_uninit(&ip->i_res->rs_qa_qd_ghs[x]);
949 gfs2_quota_unhold(ip); 957 gfs2_quota_unhold(ip);
950 } 958 }
951 959
@@ -990,7 +998,6 @@ static int need_sync(struct gfs2_quota_data *qd)
990 998
991void gfs2_quota_unlock(struct gfs2_inode *ip) 999void gfs2_quota_unlock(struct gfs2_inode *ip)
992{ 1000{
993 struct gfs2_qadata *qa = ip->i_qadata;
994 struct gfs2_quota_data *qda[4]; 1001 struct gfs2_quota_data *qda[4];
995 unsigned int count = 0; 1002 unsigned int count = 0;
996 unsigned int x; 1003 unsigned int x;
@@ -998,14 +1005,14 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
998 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) 1005 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
999 goto out; 1006 goto out;
1000 1007
1001 for (x = 0; x < qa->qa_qd_num; x++) { 1008 for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) {
1002 struct gfs2_quota_data *qd; 1009 struct gfs2_quota_data *qd;
1003 int sync; 1010 int sync;
1004 1011
1005 qd = qa->qa_qd[x]; 1012 qd = ip->i_res->rs_qa_qd[x];
1006 sync = need_sync(qd); 1013 sync = need_sync(qd);
1007 1014
1008 gfs2_glock_dq_uninit(&qa->qa_qd_ghs[x]); 1015 gfs2_glock_dq_uninit(&ip->i_res->rs_qa_qd_ghs[x]);
1009 1016
1010 if (sync && qd_trylock(qd)) 1017 if (sync && qd_trylock(qd))
1011 qda[count++] = qd; 1018 qda[count++] = qd;
@@ -1038,7 +1045,6 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
1038int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) 1045int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1039{ 1046{
1040 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1047 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1041 struct gfs2_qadata *qa = ip->i_qadata;
1042 struct gfs2_quota_data *qd; 1048 struct gfs2_quota_data *qd;
1043 s64 value; 1049 s64 value;
1044 unsigned int x; 1050 unsigned int x;
@@ -1050,8 +1056,8 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1050 if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON) 1056 if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
1051 return 0; 1057 return 0;
1052 1058
1053 for (x = 0; x < qa->qa_qd_num; x++) { 1059 for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) {
1054 qd = qa->qa_qd[x]; 1060 qd = ip->i_res->rs_qa_qd[x];
1055 1061
1056 if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || 1062 if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1057 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags)))) 1063 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))))
@@ -1089,7 +1095,6 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1089void gfs2_quota_change(struct gfs2_inode *ip, s64 change, 1095void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1090 u32 uid, u32 gid) 1096 u32 uid, u32 gid)
1091{ 1097{
1092 struct gfs2_qadata *qa = ip->i_qadata;
1093 struct gfs2_quota_data *qd; 1098 struct gfs2_quota_data *qd;
1094 unsigned int x; 1099 unsigned int x;
1095 1100
@@ -1098,8 +1103,8 @@ void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1098 if (ip->i_diskflags & GFS2_DIF_SYSTEM) 1103 if (ip->i_diskflags & GFS2_DIF_SYSTEM)
1099 return; 1104 return;
1100 1105
1101 for (x = 0; x < qa->qa_qd_num; x++) { 1106 for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) {
1102 qd = qa->qa_qd[x]; 1107 qd = ip->i_res->rs_qa_qd[x];
1103 1108
1104 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || 1109 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1105 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) { 1110 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) {
@@ -1549,10 +1554,14 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
1549 if (error) 1554 if (error)
1550 return error; 1555 return error;
1551 1556
1557 error = gfs2_rs_alloc(ip);
1558 if (error)
1559 goto out_put;
1560
1552 mutex_lock(&ip->i_inode.i_mutex); 1561 mutex_lock(&ip->i_inode.i_mutex);
1553 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, 0, &q_gh); 1562 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, 0, &q_gh);
1554 if (error) 1563 if (error)
1555 goto out_put; 1564 goto out_unlockput;
1556 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); 1565 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1557 if (error) 1566 if (error)
1558 goto out_q; 1567 goto out_q;
@@ -1609,8 +1618,9 @@ out_i:
1609 gfs2_glock_dq_uninit(&i_gh); 1618 gfs2_glock_dq_uninit(&i_gh);
1610out_q: 1619out_q:
1611 gfs2_glock_dq_uninit(&q_gh); 1620 gfs2_glock_dq_uninit(&q_gh);
1612out_put: 1621out_unlockput:
1613 mutex_unlock(&ip->i_inode.i_mutex); 1622 mutex_unlock(&ip->i_inode.i_mutex);
1623out_put:
1614 qd_put(qd); 1624 qd_put(qd);
1615 return error; 1625 return error;
1616} 1626}