@@ -206,12 +206,6 @@ static int demote_ok(const struct gfs2_glock *gl)
206206
207207 if (gl -> gl_state == LM_ST_UNLOCKED )
208208 return 0 ;
209- /*
210- * Note that demote_ok is used for the lru process of disposing of
211- * glocks. For this purpose, we don't care if the glock's holders
212- * have the HIF_MAY_DEMOTE flag set or not. If someone is using
213- * them, don't demote.
214- */
215209 if (!list_empty (& gl -> gl_holders ))
216210 return 0 ;
217211 if (glops -> go_demote_ok )
@@ -394,7 +388,7 @@ static void do_error(struct gfs2_glock *gl, const int ret)
394388 struct gfs2_holder * gh , * tmp ;
395389
396390 list_for_each_entry_safe (gh , tmp , & gl -> gl_holders , gh_list ) {
397- if (! test_bit (HIF_WAIT , & gh -> gh_iflags ))
391+ if (test_bit (HIF_HOLDER , & gh -> gh_iflags ))
398392 continue ;
399393 if (ret & LM_OUT_ERROR )
400394 gh -> gh_error = - EIO ;
@@ -408,45 +402,6 @@ static void do_error(struct gfs2_glock *gl, const int ret)
408402 }
409403}
410404
411- /**
412- * demote_incompat_holders - demote incompatible demoteable holders
413- * @gl: the glock we want to promote
414- * @current_gh: the newly promoted holder
415- *
416- * We're passing the newly promoted holder in @current_gh, but actually, any of
417- * the strong holders would do.
418- */
419- static void demote_incompat_holders (struct gfs2_glock * gl ,
420- struct gfs2_holder * current_gh )
421- {
422- struct gfs2_holder * gh , * tmp ;
423-
424- /*
425- * Demote incompatible holders before we make ourselves eligible.
426- * (This holder may or may not allow auto-demoting, but we don't want
427- * to demote the new holder before it's even granted.)
428- */
429- list_for_each_entry_safe (gh , tmp , & gl -> gl_holders , gh_list ) {
430- /*
431- * Since holders are at the front of the list, we stop when we
432- * find the first non-holder.
433- */
434- if (!test_bit (HIF_HOLDER , & gh -> gh_iflags ))
435- return ;
436- if (gh == current_gh )
437- continue ;
438- if (test_bit (HIF_MAY_DEMOTE , & gh -> gh_iflags ) &&
439- !may_grant (gl , current_gh , gh )) {
440- /*
441- * We should not recurse into do_promote because
442- * __gfs2_glock_dq only calls handle_callback,
443- * gfs2_glock_add_to_lru and __gfs2_glock_queue_work.
444- */
445- __gfs2_glock_dq (gh );
446- }
447- }
448- }
449-
450405/**
451406 * find_first_holder - find the first "holder" gh
452407 * @gl: the glock
@@ -465,26 +420,6 @@ static inline struct gfs2_holder *find_first_holder(const struct gfs2_glock *gl)
465420 return NULL ;
466421}
467422
468- /**
469- * find_first_strong_holder - find the first non-demoteable holder
470- * @gl: the glock
471- *
472- * Find the first holder that doesn't have the HIF_MAY_DEMOTE flag set.
473- */
474- static inline struct gfs2_holder *
475- find_first_strong_holder (struct gfs2_glock * gl )
476- {
477- struct gfs2_holder * gh ;
478-
479- list_for_each_entry (gh , & gl -> gl_holders , gh_list ) {
480- if (!test_bit (HIF_HOLDER , & gh -> gh_iflags ))
481- return NULL ;
482- if (!test_bit (HIF_MAY_DEMOTE , & gh -> gh_iflags ))
483- return gh ;
484- }
485- return NULL ;
486- }
487-
488423/*
489424 * gfs2_instantiate - Call the glops instantiate function
490425 * @gh: The glock holder
@@ -541,9 +476,8 @@ int gfs2_instantiate(struct gfs2_holder *gh)
541476static int do_promote (struct gfs2_glock * gl )
542477{
543478 struct gfs2_holder * gh , * current_gh ;
544- bool incompat_holders_demoted = false;
545479
546- current_gh = find_first_strong_holder (gl );
480+ current_gh = find_first_holder (gl );
547481 list_for_each_entry (gh , & gl -> gl_holders , gh_list ) {
548482 if (test_bit (HIF_HOLDER , & gh -> gh_iflags ))
549483 continue ;
@@ -562,11 +496,8 @@ static int do_promote(struct gfs2_glock *gl)
562496 set_bit (HIF_HOLDER , & gh -> gh_iflags );
563497 trace_gfs2_promote (gh );
564498 gfs2_holder_wake (gh );
565- if (!incompat_holders_demoted ) {
499+ if (!current_gh )
566500 current_gh = gh ;
567- demote_incompat_holders (gl , current_gh );
568- incompat_holders_demoted = true;
569- }
570501 }
571502 return 0 ;
572503}
@@ -1538,7 +1469,7 @@ __acquires(&gl->gl_lockref.lock)
15381469 if (test_bit (GLF_LOCK , & gl -> gl_flags )) {
15391470 struct gfs2_holder * current_gh ;
15401471
1541- current_gh = find_first_strong_holder (gl );
1472+ current_gh = find_first_holder (gl );
15421473 try_futile = !may_grant (gl , current_gh , gh );
15431474 }
15441475 if (test_bit (GLF_INVALIDATE_IN_PROGRESS , & gl -> gl_flags ))
@@ -1550,8 +1481,6 @@ __acquires(&gl->gl_lockref.lock)
15501481 continue ;
15511482 if (gh -> gh_gl -> gl_ops -> go_type == LM_TYPE_FLOCK )
15521483 continue ;
1553- if (test_bit (HIF_MAY_DEMOTE , & gh2 -> gh_iflags ))
1554- continue ;
15551484 if (!pid_is_meaningful (gh2 ))
15561485 continue ;
15571486 goto trap_recursive ;
@@ -1666,64 +1595,42 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16661595 int fast_path = 0 ;
16671596
16681597 /*
1669- * This while loop is similar to function demote_incompat_holders:
1670- * If the glock is due to be demoted (which may be from another node
1671- * or even if this holder is GL_NOCACHE), the weak holders are
1672- * demoted as well, allowing the glock to be demoted.
1598+ * If we're in the process of file system withdraw, we cannot just
1599+ * dequeue any glocks until our journal is recovered, lest we introduce
1600+ * file system corruption. We need two exceptions to this rule: We need
1601+ * to allow unlocking of nondisk glocks and the glock for our own
1602+ * journal that needs recovery.
16731603 */
1674- while (gh ) {
1675- /*
1676- * If we're in the process of file system withdraw, we cannot
1677- * just dequeue any glocks until our journal is recovered, lest
1678- * we introduce file system corruption. We need two exceptions
1679- * to this rule: We need to allow unlocking of nondisk glocks
1680- * and the glock for our own journal that needs recovery.
1681- */
1682- if (test_bit (SDF_WITHDRAW_RECOVERY , & sdp -> sd_flags ) &&
1683- glock_blocked_by_withdraw (gl ) &&
1684- gh -> gh_gl != sdp -> sd_jinode_gl ) {
1685- sdp -> sd_glock_dqs_held ++ ;
1686- spin_unlock (& gl -> gl_lockref .lock );
1687- might_sleep ();
1688- wait_on_bit (& sdp -> sd_flags , SDF_WITHDRAW_RECOVERY ,
1689- TASK_UNINTERRUPTIBLE );
1690- spin_lock (& gl -> gl_lockref .lock );
1691- }
1604+ if (test_bit (SDF_WITHDRAW_RECOVERY , & sdp -> sd_flags ) &&
1605+ glock_blocked_by_withdraw (gl ) &&
1606+ gh -> gh_gl != sdp -> sd_jinode_gl ) {
1607+ sdp -> sd_glock_dqs_held ++ ;
1608+ spin_unlock (& gl -> gl_lockref .lock );
1609+ might_sleep ();
1610+ wait_on_bit (& sdp -> sd_flags , SDF_WITHDRAW_RECOVERY ,
1611+ TASK_UNINTERRUPTIBLE );
1612+ spin_lock (& gl -> gl_lockref .lock );
1613+ }
16921614
1693- /*
1694- * This holder should not be cached, so mark it for demote.
1695- * Note: this should be done before the check for needs_demote
1696- * below.
1697- */
1698- if (gh -> gh_flags & GL_NOCACHE )
1699- handle_callback (gl , LM_ST_UNLOCKED , 0 , false);
1615+ /*
1616+ * This holder should not be cached, so mark it for demote.
1617+ * Note: this should be done before the check for needs_demote
1618+ * below.
1619+ */
1620+ if (gh -> gh_flags & GL_NOCACHE )
1621+ handle_callback (gl , LM_ST_UNLOCKED , 0 , false);
17001622
1701- list_del_init (& gh -> gh_list );
1702- clear_bit (HIF_HOLDER , & gh -> gh_iflags );
1703- trace_gfs2_glock_queue (gh , 0 );
1623+ list_del_init (& gh -> gh_list );
1624+ clear_bit (HIF_HOLDER , & gh -> gh_iflags );
1625+ trace_gfs2_glock_queue (gh , 0 );
17041626
1705- /*
1706- * If there hasn't been a demote request we are done.
1707- * (Let the remaining holders, if any, keep holding it.)
1708- */
1709- if (!needs_demote (gl )) {
1710- if (list_empty (& gl -> gl_holders ))
1711- fast_path = 1 ;
1712- break ;
1713- }
1714- /*
1715- * If we have another strong holder (we cannot auto-demote)
1716- * we are done. It keeps holding it until it is done.
1717- */
1718- if (find_first_strong_holder (gl ))
1719- break ;
1720-
1721- /*
1722- * If we have a weak holder at the head of the list, it
1723- * (and all others like it) must be auto-demoted. If there
1724- * are no more weak holders, we exit the while loop.
1725- */
1726- gh = find_first_holder (gl );
1627+ /*
1628+ * If there hasn't been a demote request we are done.
1629+ * (Let the remaining holders, if any, keep holding it.)
1630+ */
1631+ if (!needs_demote (gl )) {
1632+ if (list_empty (& gl -> gl_holders ))
1633+ fast_path = 1 ;
17271634 }
17281635
17291636 if (!test_bit (GLF_LFLUSH , & gl -> gl_flags ) && demote_ok (gl ))
@@ -1938,33 +1845,6 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
19381845 if (test_bit (GLF_REPLY_PENDING , & gl -> gl_flags ))
19391846 delay = gl -> gl_hold_time ;
19401847 }
1941- /*
1942- * Note 1: We cannot call demote_incompat_holders from handle_callback
1943- * or gfs2_set_demote due to recursion problems like: gfs2_glock_dq ->
1944- * handle_callback -> demote_incompat_holders -> gfs2_glock_dq
1945- * Plus, we only want to demote the holders if the request comes from
1946- * a remote cluster node because local holder conflicts are resolved
1947- * elsewhere.
1948- *
1949- * Note 2: if a remote node wants this glock in EX mode, lock_dlm will
1950- * request that we set our state to UNLOCKED. Here we mock up a holder
1951- * to make it look like someone wants the lock EX locally. Any SH
1952- * and DF requests should be able to share the lock without demoting.
1953- *
1954- * Note 3: We only want to demote the demoteable holders when there
1955- * are no more strong holders. The demoteable holders might as well
1956- * keep the glock until the last strong holder is done with it.
1957- */
1958- if (!find_first_strong_holder (gl )) {
1959- struct gfs2_holder mock_gh = {
1960- .gh_gl = gl ,
1961- .gh_state = (state == LM_ST_UNLOCKED ) ?
1962- LM_ST_EXCLUSIVE : state ,
1963- .gh_iflags = BIT (HIF_HOLDER )
1964- };
1965-
1966- demote_incompat_holders (gl , & mock_gh );
1967- }
19681848 handle_callback (gl , state , delay , true);
19691849 __gfs2_glock_queue_work (gl , delay );
19701850 spin_unlock (& gl -> gl_lockref .lock );
@@ -2356,8 +2236,6 @@ static const char *hflags2str(char *buf, u16 flags, unsigned long iflags)
23562236 * p ++ = 'H' ;
23572237 if (test_bit (HIF_WAIT , & iflags ))
23582238 * p ++ = 'W' ;
2359- if (test_bit (HIF_MAY_DEMOTE , & iflags ))
2360- * p ++ = 'D' ;
23612239 if (flags & GL_SKIP )
23622240 * p ++ = 's' ;
23632241 * p = 0 ;
0 commit comments