Skip to content

Commit 59ebc33

Browse files
author
Andreas Gruenbacher
committed
gfs2: qd_check_sync cleanups
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 <[email protected]>
1 parent 2aedfe8 commit 59ebc33

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

fs/gfs2/quota.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,13 @@ static void bh_put(struct gfs2_quota_data *qd)
462462
mutex_unlock(&sdp->sd_quota_mutex);
463463
}
464464

465-
static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
466-
u64 *sync_gen)
465+
static bool qd_grab_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
466+
u64 sync_gen)
467467
{
468468
if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
469469
!test_bit(QDF_CHANGE, &qd->qd_flags) ||
470-
(sync_gen && (qd->qd_sync_gen >= *sync_gen)))
471-
return 0;
470+
qd->qd_sync_gen >= sync_gen)
471+
return false;
472472

473473
/*
474474
* 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,
478478
if (!qd->qd_change && test_and_clear_bit(QDF_CHANGE, &qd->qd_flags)) {
479479
slot_put(qd);
480480
qd_put(qd);
481-
return 0;
481+
return false;
482482
}
483483

484484
if (!lockref_get_not_dead(&qd->qd_lockref))
485-
return 0;
485+
return false;
486486

487487
list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
488488
set_bit(QDF_LOCKED, &qd->qd_flags);
489489
qd->qd_change_sync = qd->qd_change;
490490
slot_hold(qd);
491-
return 1;
491+
return true;
492+
}
493+
494+
static void qd_ungrab_sync(struct gfs2_quota_data *qd)
495+
{
496+
clear_bit(QDF_LOCKED, &qd->qd_flags);
497+
slot_put(qd);
498+
qd_put(qd);
492499
}
493500

494501
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)
504511
spin_lock(&qd_lock);
505512

506513
list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) {
507-
if (qd_check_sync(sdp, iter, &sdp->sd_quota_sync_gen)) {
514+
if (qd_grab_sync(sdp, iter, sdp->sd_quota_sync_gen)) {
508515
qd = iter;
509516
break;
510517
}
@@ -515,9 +522,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
515522
if (qd) {
516523
error = bh_get(qd);
517524
if (error) {
518-
clear_bit(QDF_LOCKED, &qd->qd_flags);
519-
slot_put(qd);
520-
qd_put(qd);
525+
qd_ungrab_sync(qd);
521526
return error;
522527
}
523528
}
@@ -1157,14 +1162,14 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
11571162
struct gfs2_quota_data *qda[2 * GFS2_MAXQUOTAS];
11581163
unsigned int count = 0;
11591164
u32 x;
1160-
int found;
11611165

11621166
if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
11631167
return;
11641168

11651169
for (x = 0; x < ip->i_qadata->qa_qd_num; x++) {
11661170
struct gfs2_quota_data *qd;
11671171
bool sync;
1172+
int error;
11681173

11691174
qd = ip->i_qadata->qa_qd[x];
11701175
sync = need_sync(qd);
@@ -1174,17 +1179,16 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
11741179
continue;
11751180

11761181
spin_lock(&qd_lock);
1177-
found = qd_check_sync(sdp, qd, NULL);
1182+
sync = qd_grab_sync(sdp, qd, U64_MAX);
11781183
spin_unlock(&qd_lock);
11791184

1180-
if (!found)
1185+
if (!sync)
11811186
continue;
11821187

11831188
gfs2_assert_warn(sdp, qd->qd_change_sync);
1184-
if (bh_get(qd)) {
1185-
clear_bit(QDF_LOCKED, &qd->qd_flags);
1186-
slot_put(qd);
1187-
qd_put(qd);
1189+
error = bh_get(qd);
1190+
if (error) {
1191+
qd_ungrab_sync(qd);
11881192
continue;
11891193
}
11901194

0 commit comments

Comments
 (0)