Skip to content

Commit 7da4d6e

Browse files
author
Andreas Gruenbacher
committed
gfs2: Fix and clean up function do_qc
Function do_qc() is supposed to be conceptually simple: it alters the current in-memory and on-disk quota change values for a given uid/gid by a given delta. If the on-disk record isn't defined yet, a new record is created. If the on-disk record exists and the resulting change value is zero, there no longer is a need for that record and so the record is deleted. On top of that, some reference counting is involved when creating and deleting records. Currently, instead of doing the above, do_qc() alters the on-disk value and then it sets the in-memory value to the on-disk value. This is incorrect when the on-disk value differs from the in-memory value. The two values are allowed to differ when quota changes are synced to the global quota file. Fix by changing both values by the same amount. In addition, do_qc() currently gets confused when the delta value is 0. It isn't supposed to be called that way, but that assumption isn't mentioned and it makes the code harder to read. Make the code more explicit. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent ec4b520 commit 7da4d6e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

fs/gfs2/quota.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -702,32 +702,40 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change)
702702
mutex_lock(&sdp->sd_quota_mutex);
703703
gfs2_trans_add_meta(ip->i_gl, qd->qd_bh);
704704

705-
if (!test_bit(QDF_CHANGE, &qd->qd_flags)) {
706-
qc->qc_change = 0;
707-
qc->qc_flags = 0;
708-
if (qd->qd_id.type == USRQUOTA)
709-
qc->qc_flags = cpu_to_be32(GFS2_QCF_USER);
710-
qc->qc_id = cpu_to_be32(from_kqid(&init_user_ns, qd->qd_id));
711-
}
705+
/*
706+
* The QDF_CHANGE flag indicates that the slot in the quota change file
707+
* is used. Here, we use the value of qc->qc_change when the slot is
708+
* used, and we assume a value of 0 otherwise.
709+
*/
712710

713-
x = be64_to_cpu(qc->qc_change) + change;
714-
qc->qc_change = cpu_to_be64(x);
711+
x = 0;
712+
if (test_bit(QDF_CHANGE, &qd->qd_flags))
713+
x = be64_to_cpu(qc->qc_change);
714+
x += change;
715715

716716
spin_lock(&qd_lock);
717-
qd->qd_change = x;
717+
qd->qd_change += change;
718718
spin_unlock(&qd_lock);
719719

720-
if (!x) {
721-
gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags));
720+
if (!x && test_bit(QDF_CHANGE, &qd->qd_flags)) {
721+
/* The slot in the quota change file becomes unused. */
722722
clear_bit(QDF_CHANGE, &qd->qd_flags);
723723
qc->qc_flags = 0;
724724
qc->qc_id = 0;
725725
slot_put(qd);
726726
qd_put(qd);
727-
} else if (!test_and_set_bit(QDF_CHANGE, &qd->qd_flags)) {
727+
} else if (x && !test_bit(QDF_CHANGE, &qd->qd_flags)) {
728+
/* The slot in the quota change file becomes used. */
729+
set_bit(QDF_CHANGE, &qd->qd_flags);
728730
qd_hold(qd);
729731
slot_hold(qd);
732+
733+
qc->qc_flags = 0;
734+
if (qd->qd_id.type == USRQUOTA)
735+
qc->qc_flags = cpu_to_be32(GFS2_QCF_USER);
736+
qc->qc_id = cpu_to_be32(from_kqid(&init_user_ns, qd->qd_id));
730737
}
738+
qc->qc_change = cpu_to_be64(x);
731739

732740
if (change < 0) /* Reset quiet flag if we freed some blocks */
733741
clear_bit(QDF_QMSG_QUIET, &qd->qd_flags);

0 commit comments

Comments
 (0)