Skip to content

Commit b6900ce

Browse files
author
Andreas Gruenbacher
committed
gfs2: Simplify DLM_LKF_QUECVT use
The DLM_LKF_QUECVT flag needs to be set for "upward" lock conversions to ensure fairness, but setting it for "downward" lock conversions will lead to a failure. The flag is currently set based on the GLF_BLOCKING flag and it's not immediately obvious why this is correct. Simplify things by figuring out if a lock conversion is "upward" by looking at the before and after locking modes instead of relying on the GLF_BLOCKING flag. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 03ff378 commit b6900ce

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

fs/gfs2/lock_dlm.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,21 @@ static int make_mode(struct gfs2_sbd *sdp, const unsigned int lmstate)
224224
return -1;
225225
}
226226

227+
/* Taken from fs/dlm/lock.c. */
228+
229+
static bool middle_conversion(int cur, int req)
230+
{
231+
return (cur == DLM_LOCK_PR && req == DLM_LOCK_CW) ||
232+
(cur == DLM_LOCK_CW && req == DLM_LOCK_PR);
233+
}
234+
235+
static bool down_conversion(int cur, int req)
236+
{
237+
return !middle_conversion(cur, req) && req < cur;
238+
}
239+
227240
static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
228-
const int req)
241+
const int cur, const int req)
229242
{
230243
u32 lkf = 0;
231244

@@ -251,7 +264,14 @@ static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
251264

252265
if (!test_bit(GLF_INITIAL, &gl->gl_flags)) {
253266
lkf |= DLM_LKF_CONVERT;
254-
if (test_bit(GLF_BLOCKING, &gl->gl_flags))
267+
268+
/*
269+
* The DLM_LKF_QUECVT flag needs to be set for "first come,
270+
* first served" semantics, but it must only be set for
271+
* "upward" lock conversions or else DLM will reject the
272+
* request as invalid.
273+
*/
274+
if (!down_conversion(cur, req))
255275
lkf |= DLM_LKF_QUECVT;
256276
}
257277

@@ -271,13 +291,14 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
271291
unsigned int flags)
272292
{
273293
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
274-
int req;
294+
int cur, req;
275295
u32 lkf;
276296
char strname[GDLM_STRNAME_BYTES] = "";
277297
int error;
278298

299+
cur = make_mode(gl->gl_name.ln_sbd, gl->gl_state);
279300
req = make_mode(gl->gl_name.ln_sbd, req_state);
280-
lkf = make_flags(gl, flags, req);
301+
lkf = make_flags(gl, flags, cur, req);
281302
gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
282303
gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
283304
if (test_bit(GLF_INITIAL, &gl->gl_flags)) {

0 commit comments

Comments
 (0)