From: Andreas Gruenbacher <agruenba@redhat.com>
To: gfs2@lists.linux.dev
Cc: Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH 04/13] gfs2: qd_check_sync cleanups
Date: Tue, 18 Jun 2024 18:05:08 +0200 [thread overview]
Message-ID: <20240618160517.901589-5-agruenba@redhat.com> (raw)
In-Reply-To: <20240618160517.901589-1-agruenba@redhat.com>
Rename qd_check_sync() to qd_grab_sync() and make it return a bool.
Turn the sync_gen pointer into a regular u64 and pass in U64_MAX instead
of a NULL pointer when sync generation checking isn't needed.
Introduce a new qd_ungrab_sync() helper for undoing the effects of
qd_grab_sync() if the subsequent bh_get() on the qd object fails.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/quota.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index e0840b412d28..bbd66adaec3d 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -462,13 +462,13 @@ static void bh_put(struct gfs2_quota_data *qd)
mutex_unlock(&sdp->sd_quota_mutex);
}
-static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
- u64 *sync_gen)
+static bool qd_grab_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
+ u64 sync_gen)
{
if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
!test_bit(QDF_CHANGE, &qd->qd_flags) ||
- (sync_gen && (qd->qd_sync_gen >= *sync_gen)))
- return 0;
+ qd->qd_sync_gen >= sync_gen)
+ return false;
/*
* If qd_change is 0 it means a pending quota change was negated.
@@ -478,17 +478,24 @@ static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
if (!qd->qd_change && test_and_clear_bit(QDF_CHANGE, &qd->qd_flags)) {
slot_put(qd);
qd_put(qd);
- return 0;
+ return false;
}
if (!lockref_get_not_dead(&qd->qd_lockref))
- return 0;
+ return false;
list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
set_bit(QDF_LOCKED, &qd->qd_flags);
qd->qd_change_sync = qd->qd_change;
slot_hold(qd);
- return 1;
+ return true;
+}
+
+static void qd_ungrab_sync(struct gfs2_quota_data *qd)
+{
+ clear_bit(QDF_LOCKED, &qd->qd_flags);
+ slot_put(qd);
+ qd_put(qd);
}
static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
@@ -504,7 +511,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
spin_lock(&qd_lock);
list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) {
- if (qd_check_sync(sdp, iter, &sdp->sd_quota_sync_gen)) {
+ if (qd_grab_sync(sdp, iter, sdp->sd_quota_sync_gen)) {
qd = iter;
break;
}
@@ -515,9 +522,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
if (qd) {
error = bh_get(qd);
if (error) {
- clear_bit(QDF_LOCKED, &qd->qd_flags);
- slot_put(qd);
- qd_put(qd);
+ qd_ungrab_sync(qd);
return error;
}
}
@@ -1157,7 +1162,6 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
struct gfs2_quota_data *qda[2 * GFS2_MAXQUOTAS];
unsigned int count = 0;
u32 x;
- int found;
if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
return;
@@ -1165,6 +1169,7 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
for (x = 0; x < ip->i_qadata->qa_qd_num; x++) {
struct gfs2_quota_data *qd;
bool sync;
+ int error;
qd = ip->i_qadata->qa_qd[x];
sync = need_sync(qd);
@@ -1174,17 +1179,16 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
continue;
spin_lock(&qd_lock);
- found = qd_check_sync(sdp, qd, NULL);
+ sync = qd_grab_sync(sdp, qd, U64_MAX);
spin_unlock(&qd_lock);
- if (!found)
+ if (!sync)
continue;
gfs2_assert_warn(sdp, qd->qd_change_sync);
- if (bh_get(qd)) {
- clear_bit(QDF_LOCKED, &qd->qd_flags);
- slot_put(qd);
- qd_put(qd);
+ error = bh_get(qd);
+ if (error) {
+ qd_ungrab_sync(qd);
continue;
}
--
2.45.1
next prev parent reply other threads:[~2024-06-18 16:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 16:05 [PATCH 00/13] gfs2: quota changes Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 01/13] gfs2: Minor gfs2_quota_init error path cleanup Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 02/13] gfs2: Check quota consistency on mount Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 03/13] gfs2: Revert "introduce qd_bh_get_or_undo" Andreas Gruenbacher
2024-06-18 16:05 ` Andreas Gruenbacher [this message]
2024-06-18 16:05 ` [PATCH 05/13] gfs2: Revert "ignore negated quota changes" Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 06/13] gfs2: Revert "Add quota_change type" Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 07/13] gfs2: Fix and clean up function do_qc Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 08/13] gfs2: quota need_sync cleanup Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 09/13] gfs2: Fold qd_fish into gfs2_quota_sync Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 10/13] gfs2: Add some missing quota locking Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 11/13] gfs2: Get rid of some unnecessary " Andreas Gruenbacher
2024-06-20 14:22 ` Alexander Aring
2024-06-20 14:45 ` Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 12/13] gfs2: Be more careful with the quota sync generation Andreas Gruenbacher
2024-06-18 16:05 ` [PATCH 13/13] gfs2: Revert "check for no eligible quota changes" Andreas Gruenbacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240618160517.901589-5-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).