Skip to content

Commit c8758ad

Browse files
author
Andreas Gruenbacher
committed
gfs2: Invert the GLF_INITIAL flag
Invert the meaning of the GLF_INITIAL flag: right now, when GLF_INITIAL is set, a DLM lock exists and we have a valid identifier for it; when GLF_INITIAL is cleared, no DLM lock exists (yet). This is confusing. In addition, it makes more sense to highlight the exceptional case (i.e., no DLM lock exists yet) in glock dumps and trace points than to highlight the common case. To avoid confusion between the "old" and the "new" meaning of the flag, use 'a' instead of 'I' to represent the flag. For improved code consistency, check if the GLF_INITIAL flag is cleared to determine whether a DLM lock exists instead of checking if the lock identifier is non-zero. Document what the flag is used for. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent c8cf2d9 commit c8758ad

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

fs/gfs2/glock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,9 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
12371237

12381238
atomic_inc(&sdp->sd_glock_disposal);
12391239
gl->gl_node.next = NULL;
1240-
gl->gl_flags = glops->go_instantiate ? BIT(GLF_INSTANTIATE_NEEDED) : 0;
1240+
gl->gl_flags = BIT(GLF_INITIAL);
1241+
if (glops->go_instantiate)
1242+
gl->gl_flags |= BIT(GLF_INSTANTIATE_NEEDED);
12411243
gl->gl_name = name;
12421244
lockdep_set_subclass(&gl->gl_lockref.lock, glops->go_subclass);
12431245
gl->gl_lockref.count = 1;
@@ -2363,7 +2365,7 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23632365
if (test_bit(GLF_HAVE_REPLY, gflags))
23642366
*p++ = 'r';
23652367
if (test_bit(GLF_INITIAL, gflags))
2366-
*p++ = 'I';
2368+
*p++ = 'a';
23672369
if (test_bit(GLF_HAVE_FROZEN_REPLY, gflags))
23682370
*p++ = 'F';
23692371
if (!list_empty(&gl->gl_holders))

fs/gfs2/lock_dlm.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,21 @@ static void gdlm_ast(void *arg)
163163
BUG();
164164
}
165165

166-
set_bit(GLF_INITIAL, &gl->gl_flags);
166+
/*
167+
* The GLF_INITIAL flag is initially set for new glocks. Upon the
168+
* first successful new (non-conversion) request, we clear this flag to
169+
* indicate that a DLM lock exists and that gl->gl_lksb.sb_lkid is the
170+
* identifier to use for identifying it.
171+
*
172+
* Any failed initial requests do not create a DLM lock, so we ignore
173+
* the gl->gl_lksb.sb_lkid values that come with such requests.
174+
*/
175+
176+
clear_bit(GLF_INITIAL, &gl->gl_flags);
167177
gfs2_glock_complete(gl, ret);
168178
return;
169179
out:
170-
if (!test_bit(GLF_INITIAL, &gl->gl_flags))
180+
if (test_bit(GLF_INITIAL, &gl->gl_flags))
171181
gl->gl_lksb.sb_lkid = 0;
172182
gfs2_glock_complete(gl, ret);
173183
}
@@ -239,7 +249,7 @@ static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
239249
BUG();
240250
}
241251

242-
if (gl->gl_lksb.sb_lkid != 0) {
252+
if (!test_bit(GLF_INITIAL, &gl->gl_flags)) {
243253
lkf |= DLM_LKF_CONVERT;
244254
if (test_bit(GLF_BLOCKING, &gl->gl_flags))
245255
lkf |= DLM_LKF_QUECVT;
@@ -270,14 +280,14 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
270280
lkf = make_flags(gl, flags, req);
271281
gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
272282
gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
273-
if (gl->gl_lksb.sb_lkid) {
274-
gfs2_update_request_times(gl);
275-
} else {
283+
if (test_bit(GLF_INITIAL, &gl->gl_flags)) {
276284
memset(strname, ' ', GDLM_STRNAME_BYTES - 1);
277285
strname[GDLM_STRNAME_BYTES - 1] = '\0';
278286
gfs2_reverse_hex(strname + 7, gl->gl_name.ln_type);
279287
gfs2_reverse_hex(strname + 23, gl->gl_name.ln_number);
280288
gl->gl_dstamp = ktime_get_real();
289+
} else {
290+
gfs2_update_request_times(gl);
281291
}
282292
/*
283293
* Submit the actual lock request.
@@ -301,7 +311,7 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
301311

302312
BUG_ON(!__lockref_is_dead(&gl->gl_lockref));
303313

304-
if (gl->gl_lksb.sb_lkid == 0) {
314+
if (test_bit(GLF_INITIAL, &gl->gl_flags)) {
305315
gfs2_glock_free(gl);
306316
return;
307317
}

fs/gfs2/trace_gfs2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{(1UL << GLF_LFLUSH), "f" }, \
5555
{(1UL << GLF_INVALIDATE_IN_PROGRESS), "i" }, \
5656
{(1UL << GLF_HAVE_REPLY), "r" }, \
57-
{(1UL << GLF_INITIAL), "I" }, \
57+
{(1UL << GLF_INITIAL), "a" }, \
5858
{(1UL << GLF_HAVE_FROZEN_REPLY), "F" }, \
5959
{(1UL << GLF_LRU), "L" }, \
6060
{(1UL << GLF_OBJECT), "o" }, \

0 commit comments

Comments
 (0)