@@ -607,14 +607,19 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
607607 if (gh && (ret & LM_OUT_CANCELED ))
608608 gfs2_holder_wake (gh );
609609 if (gh && !test_bit (GLF_DEMOTE_IN_PROGRESS , & gl -> gl_flags )) {
610- /* move to back of queue and try next entry */
611610 if (ret & LM_OUT_CANCELED ) {
612- list_move_tail (& gh -> gh_list , & gl -> gl_holders );
611+ list_del_init (& gh -> gh_list );
612+ trace_gfs2_glock_queue (gh , 0 );
613+ gl -> gl_target = gl -> gl_state ;
613614 gh = find_first_waiter (gl );
614- gl -> gl_target = gh -> gh_state ;
615- if (do_promote (gl ))
616- goto out ;
617- goto retry ;
615+ if (gh ) {
616+ gl -> gl_target = gh -> gh_state ;
617+ if (do_promote (gl ))
618+ goto out ;
619+ do_xmote (gl , gh , gl -> gl_target );
620+ return ;
621+ }
622+ goto out ;
618623 }
619624 /* Some error or failed "try lock" - report it */
620625 if ((ret & LM_OUT_ERROR ) ||
@@ -627,7 +632,6 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
627632 switch (state ) {
628633 /* Unlocked due to conversion deadlock, try again */
629634 case LM_ST_UNLOCKED :
630- retry :
631635 do_xmote (gl , gh , gl -> gl_target );
632636 break ;
633637 /* Conversion fails, unlock and try again */
@@ -661,7 +665,8 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
661665 do_promote (gl );
662666 }
663667out :
664- clear_bit (GLF_LOCK , & gl -> gl_flags );
668+ if (!test_bit (GLF_CANCELING , & gl -> gl_flags ))
669+ clear_bit (GLF_LOCK , & gl -> gl_flags );
665670}
666671
667672static bool is_system_glock (struct gfs2_glock * gl )
@@ -807,6 +812,7 @@ __acquires(&gl->gl_lockref.lock)
807812 }
808813
809814 if (ls -> ls_ops -> lm_lock ) {
815+ set_bit (GLF_PENDING_REPLY , & gl -> gl_flags );
810816 spin_unlock (& gl -> gl_lockref .lock );
811817 ret = ls -> ls_ops -> lm_lock (gl , target , lck_flags );
812818 spin_lock (& gl -> gl_lockref .lock );
@@ -825,6 +831,7 @@ __acquires(&gl->gl_lockref.lock)
825831 /* The operation will be completed asynchronously. */
826832 return ;
827833 }
834+ clear_bit (GLF_PENDING_REPLY , & gl -> gl_flags );
828835 }
829836
830837 /* Complete the operation now. */
@@ -843,12 +850,13 @@ static void run_queue(struct gfs2_glock *gl, const int nonblock)
843850__releases (& gl - > gl_lockref .lock )
844851__acquires (& gl - > gl_lockref .lock )
845852{
846- struct gfs2_holder * gh = NULL ;
853+ struct gfs2_holder * gh ;
847854
848855 if (test_bit (GLF_LOCK , & gl -> gl_flags ))
849856 return ;
850857 set_bit (GLF_LOCK , & gl -> gl_flags );
851858
859+ /* While a demote is in progress, the GLF_LOCK flag must be set. */
852860 GLOCK_BUG_ON (gl , test_bit (GLF_DEMOTE_IN_PROGRESS , & gl -> gl_flags ));
853861
854862 if (test_bit (GLF_DEMOTE , & gl -> gl_flags ) &&
@@ -860,18 +868,22 @@ __acquires(&gl->gl_lockref.lock)
860868 set_bit (GLF_DEMOTE_IN_PROGRESS , & gl -> gl_flags );
861869 GLOCK_BUG_ON (gl , gl -> gl_demote_state == LM_ST_EXCLUSIVE );
862870 gl -> gl_target = gl -> gl_demote_state ;
871+ do_xmote (gl , NULL , gl -> gl_target );
872+ return ;
863873 } else {
864874 if (test_bit (GLF_DEMOTE , & gl -> gl_flags ))
865875 gfs2_demote_wake (gl );
866876 if (do_promote (gl ))
867877 goto out_unlock ;
868878 gh = find_first_waiter (gl );
879+ if (!gh )
880+ goto out_unlock ;
869881 gl -> gl_target = gh -> gh_state ;
870882 if (!(gh -> gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB )))
871883 do_error (gl , 0 ); /* Fail queued try locks */
884+ do_xmote (gl , gh , gl -> gl_target );
885+ return ;
872886 }
873- do_xmote (gl , gh , gl -> gl_target );
874- return ;
875887
876888out_sched :
877889 clear_bit (GLF_LOCK , & gl -> gl_flags );
@@ -898,12 +910,8 @@ void glock_set_object(struct gfs2_glock *gl, void *object)
898910 prev_object = gl -> gl_object ;
899911 gl -> gl_object = object ;
900912 spin_unlock (& gl -> gl_lockref .lock );
901- if (gfs2_assert_warn (gl -> gl_name .ln_sbd , prev_object == NULL )) {
902- pr_warn ("glock=%u/%llx\n" ,
903- gl -> gl_name .ln_type ,
904- (unsigned long long )gl -> gl_name .ln_number );
913+ if (gfs2_assert_warn (gl -> gl_name .ln_sbd , prev_object == NULL ))
905914 gfs2_dump_glock (NULL , gl , true);
906- }
907915}
908916
909917/**
@@ -919,12 +927,8 @@ void glock_clear_object(struct gfs2_glock *gl, void *object)
919927 prev_object = gl -> gl_object ;
920928 gl -> gl_object = NULL ;
921929 spin_unlock (& gl -> gl_lockref .lock );
922- if (gfs2_assert_warn (gl -> gl_name .ln_sbd , prev_object == object )) {
923- pr_warn ("glock=%u/%llx\n" ,
924- gl -> gl_name .ln_type ,
925- (unsigned long long )gl -> gl_name .ln_number );
930+ if (gfs2_assert_warn (gl -> gl_name .ln_sbd , prev_object == object ))
926931 gfs2_dump_glock (NULL , gl , true);
927- }
928932}
929933
930934void gfs2_inode_remember_delete (struct gfs2_glock * gl , u64 generation )
@@ -959,6 +963,25 @@ static void gfs2_glock_poke(struct gfs2_glock *gl)
959963 gfs2_holder_uninit (& gh );
960964}
961965
966+ static struct gfs2_inode * gfs2_grab_existing_inode (struct gfs2_glock * gl )
967+ {
968+ struct gfs2_inode * ip ;
969+
970+ spin_lock (& gl -> gl_lockref .lock );
971+ ip = gl -> gl_object ;
972+ if (ip && !igrab (& ip -> i_inode ))
973+ ip = NULL ;
974+ spin_unlock (& gl -> gl_lockref .lock );
975+ if (ip ) {
976+ wait_on_inode (& ip -> i_inode );
977+ if (is_bad_inode (& ip -> i_inode )) {
978+ iput (& ip -> i_inode );
979+ ip = NULL ;
980+ }
981+ }
982+ return ip ;
983+ }
984+
962985static void gfs2_try_evict (struct gfs2_glock * gl )
963986{
964987 struct gfs2_inode * ip ;
@@ -976,32 +999,15 @@ static void gfs2_try_evict(struct gfs2_glock *gl)
976999 * happened below. (Verification is triggered by the call to
9771000 * gfs2_queue_verify_delete() in gfs2_evict_inode().)
9781001 */
979- spin_lock (& gl -> gl_lockref .lock );
980- ip = gl -> gl_object ;
981- if (ip && !igrab (& ip -> i_inode ))
982- ip = NULL ;
983- spin_unlock (& gl -> gl_lockref .lock );
984- if (ip ) {
985- wait_on_inode (& ip -> i_inode );
986- if (is_bad_inode (& ip -> i_inode )) {
987- iput (& ip -> i_inode );
988- ip = NULL ;
989- }
990- }
1002+ ip = gfs2_grab_existing_inode (gl );
9911003 if (ip ) {
992- set_bit (GIF_DEFER_DELETE , & ip -> i_flags );
1004+ set_bit (GLF_DEFER_DELETE , & gl -> gl_flags );
9931005 d_prune_aliases (& ip -> i_inode );
9941006 iput (& ip -> i_inode );
1007+ clear_bit (GLF_DEFER_DELETE , & gl -> gl_flags );
9951008
9961009 /* If the inode was evicted, gl->gl_object will now be NULL. */
997- spin_lock (& gl -> gl_lockref .lock );
998- ip = gl -> gl_object ;
999- if (ip ) {
1000- clear_bit (GIF_DEFER_DELETE , & ip -> i_flags );
1001- if (!igrab (& ip -> i_inode ))
1002- ip = NULL ;
1003- }
1004- spin_unlock (& gl -> gl_lockref .lock );
1010+ ip = gfs2_grab_existing_inode (gl );
10051011 if (ip ) {
10061012 gfs2_glock_poke (ip -> i_gl );
10071013 iput (& ip -> i_inode );
@@ -1462,9 +1468,7 @@ static inline bool pid_is_meaningful(const struct gfs2_holder *gh)
14621468{
14631469 if (!(gh -> gh_flags & GL_NOPID ))
14641470 return true;
1465- if (gh -> gh_state == LM_ST_UNLOCKED )
1466- return true;
1467- return false;
1471+ return !test_bit (HIF_HOLDER , & gh -> gh_iflags );
14681472}
14691473
14701474/**
@@ -1483,7 +1487,6 @@ __acquires(&gl->gl_lockref.lock)
14831487{
14841488 struct gfs2_glock * gl = gh -> gh_gl ;
14851489 struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
1486- struct list_head * insert_pt = NULL ;
14871490 struct gfs2_holder * gh2 ;
14881491 int try_futile = 0 ;
14891492
@@ -1519,21 +1522,11 @@ __acquires(&gl->gl_lockref.lock)
15191522 gfs2_holder_wake (gh );
15201523 return ;
15211524 }
1522- if (test_bit (HIF_HOLDER , & gh2 -> gh_iflags ))
1523- continue ;
15241525 }
15251526 trace_gfs2_glock_queue (gh , 1 );
15261527 gfs2_glstats_inc (gl , GFS2_LKS_QCOUNT );
15271528 gfs2_sbstats_inc (gl , GFS2_LKS_QCOUNT );
1528- if (likely (insert_pt == NULL )) {
1529- list_add_tail (& gh -> gh_list , & gl -> gl_holders );
1530- return ;
1531- }
1532- list_add_tail (& gh -> gh_list , insert_pt );
1533- spin_unlock (& gl -> gl_lockref .lock );
1534- if (sdp -> sd_lockstruct .ls_ops -> lm_cancel )
1535- sdp -> sd_lockstruct .ls_ops -> lm_cancel (gl );
1536- spin_lock (& gl -> gl_lockref .lock );
1529+ list_add_tail (& gh -> gh_list , & gl -> gl_holders );
15371530 return ;
15381531
15391532trap_recursive :
@@ -1673,11 +1666,19 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
16731666 }
16741667
16751668 if (list_is_first (& gh -> gh_list , & gl -> gl_holders ) &&
1676- !test_bit (HIF_HOLDER , & gh -> gh_iflags )) {
1669+ !test_bit (HIF_HOLDER , & gh -> gh_iflags ) &&
1670+ test_bit (GLF_LOCK , & gl -> gl_flags ) &&
1671+ !test_bit (GLF_DEMOTE_IN_PROGRESS , & gl -> gl_flags ) &&
1672+ !test_bit (GLF_CANCELING , & gl -> gl_flags )) {
1673+ set_bit (GLF_CANCELING , & gl -> gl_flags );
16771674 spin_unlock (& gl -> gl_lockref .lock );
16781675 gl -> gl_name .ln_sbd -> sd_lockstruct .ls_ops -> lm_cancel (gl );
16791676 wait_on_bit (& gh -> gh_iflags , HIF_WAIT , TASK_UNINTERRUPTIBLE );
16801677 spin_lock (& gl -> gl_lockref .lock );
1678+ clear_bit (GLF_CANCELING , & gl -> gl_flags );
1679+ clear_bit (GLF_LOCK , & gl -> gl_flags );
1680+ if (!gfs2_holder_queued (gh ))
1681+ goto out ;
16811682 }
16821683
16831684 /*
@@ -1923,6 +1924,7 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
19231924 struct lm_lockstruct * ls = & gl -> gl_name .ln_sbd -> sd_lockstruct ;
19241925
19251926 spin_lock (& gl -> gl_lockref .lock );
1927+ clear_bit (GLF_PENDING_REPLY , & gl -> gl_flags );
19261928 gl -> gl_reply = ret ;
19271929
19281930 if (unlikely (test_bit (DFL_BLOCK_LOCKS , & ls -> ls_recover_flags ))) {
@@ -2323,6 +2325,8 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23232325 * p ++ = 'f' ;
23242326 if (test_bit (GLF_INVALIDATE_IN_PROGRESS , gflags ))
23252327 * p ++ = 'i' ;
2328+ if (test_bit (GLF_PENDING_REPLY , gflags ))
2329+ * p ++ = 'R' ;
23262330 if (test_bit (GLF_HAVE_REPLY , gflags ))
23272331 * p ++ = 'r' ;
23282332 if (test_bit (GLF_INITIAL , gflags ))
@@ -2347,6 +2351,10 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23472351 * p ++ = 'e' ;
23482352 if (test_bit (GLF_VERIFY_DELETE , gflags ))
23492353 * p ++ = 'E' ;
2354+ if (test_bit (GLF_DEFER_DELETE , gflags ))
2355+ * p ++ = 's' ;
2356+ if (test_bit (GLF_CANCELING , gflags ))
2357+ * p ++ = 'C' ;
23502358 * p = 0 ;
23512359 return buf ;
23522360}
0 commit comments