Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 8251e3b

Browse files
Andreas Gruenbachergregkh
authored andcommitted
gfs2: qd_check_sync cleanups
[ Upstream commit 59ebc33 ] 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]> Stable-dep-of: 4b4b637 ("gfs2: Revert "ignore negated quota changes"") Signed-off-by: Sasha Levin <[email protected]>
1 parent e51c5af commit 8251e3b

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
@@ -446,13 +446,13 @@ static void bh_put(struct gfs2_quota_data *qd)
446446
mutex_unlock(&sdp->sd_quota_mutex);
447447
}
448448

449-
static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
450-
u64 *sync_gen)
449+
static bool qd_grab_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
450+
u64 sync_gen)
451451
{
452452
if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
453453
!test_bit(QDF_CHANGE, &qd->qd_flags) ||
454-
(sync_gen && (qd->qd_sync_gen >= *sync_gen)))
455-
return 0;
454+
qd->qd_sync_gen >= sync_gen)
455+
return false;
456456

457457
/*
458458
* If qd_change is 0 it means a pending quota change was negated.
@@ -462,17 +462,24 @@ static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
462462
if (!qd->qd_change && test_and_clear_bit(QDF_CHANGE, &qd->qd_flags)) {
463463
slot_put(qd);
464464
qd_put(qd);
465-
return 0;
465+
return false;
466466
}
467467

468468
if (!lockref_get_not_dead(&qd->qd_lockref))
469-
return 0;
469+
return false;
470470

471471
list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
472472
set_bit(QDF_LOCKED, &qd->qd_flags);
473473
qd->qd_change_sync = qd->qd_change;
474474
slot_hold(qd);
475-
return 1;
475+
return true;
476+
}
477+
478+
static void qd_ungrab_sync(struct gfs2_quota_data *qd)
479+
{
480+
clear_bit(QDF_LOCKED, &qd->qd_flags);
481+
slot_put(qd);
482+
qd_put(qd);
476483
}
477484

478485
static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
@@ -488,7 +495,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
488495
spin_lock(&qd_lock);
489496

490497
list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) {
491-
if (qd_check_sync(sdp, iter, &sdp->sd_quota_sync_gen)) {
498+
if (qd_grab_sync(sdp, iter, sdp->sd_quota_sync_gen)) {
492499
qd = iter;
493500
break;
494501
}
@@ -499,9 +506,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
499506
if (qd) {
500507
error = bh_get(qd);
501508
if (error) {
502-
clear_bit(QDF_LOCKED, &qd->qd_flags);
503-
slot_put(qd);
504-
qd_put(qd);
509+
qd_ungrab_sync(qd);
505510
return error;
506511
}
507512
}
@@ -1139,14 +1144,14 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
11391144
struct gfs2_quota_data *qda[2 * GFS2_MAXQUOTAS];
11401145
unsigned int count = 0;
11411146
u32 x;
1142-
int found;
11431147

11441148
if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
11451149
return;
11461150

11471151
for (x = 0; x < ip->i_qadata->qa_qd_num; x++) {
11481152
struct gfs2_quota_data *qd;
11491153
bool sync;
1154+
int error;
11501155

11511156
qd = ip->i_qadata->qa_qd[x];
11521157
sync = need_sync(qd);
@@ -1156,17 +1161,16 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
11561161
continue;
11571162

11581163
spin_lock(&qd_lock);
1159-
found = qd_check_sync(sdp, qd, NULL);
1164+
sync = qd_grab_sync(sdp, qd, U64_MAX);
11601165
spin_unlock(&qd_lock);
11611166

1162-
if (!found)
1167+
if (!sync)
11631168
continue;
11641169

11651170
gfs2_assert_warn(sdp, qd->qd_change_sync);
1166-
if (bh_get(qd)) {
1167-
clear_bit(QDF_LOCKED, &qd->qd_flags);
1168-
slot_put(qd);
1169-
qd_put(qd);
1171+
error = bh_get(qd);
1172+
if (error) {
1173+
qd_ungrab_sync(qd);
11701174
continue;
11711175
}
11721176

0 commit comments

Comments
 (0)