@@ -67,7 +67,6 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state,
6767
6868static struct dentry * gfs2_root ;
6969static struct workqueue_struct * glock_workqueue ;
70- struct workqueue_struct * gfs2_delete_workqueue ;
7170static LIST_HEAD (lru_list );
7271static atomic_t lru_count = ATOMIC_INIT (0 );
7372static DEFINE_SPINLOCK (lru_lock );
@@ -274,9 +273,8 @@ static void __gfs2_glock_put(struct gfs2_glock *gl)
274273 struct address_space * mapping = gfs2_glock2aspace (gl );
275274
276275 lockref_mark_dead (& gl -> gl_lockref );
277-
278- gfs2_glock_remove_from_lru (gl );
279276 spin_unlock (& gl -> gl_lockref .lock );
277+ gfs2_glock_remove_from_lru (gl );
280278 GLOCK_BUG_ON (gl , !list_empty (& gl -> gl_holders ));
281279 if (mapping ) {
282280 truncate_inode_pages_final (mapping );
@@ -883,6 +881,7 @@ void glock_set_object(struct gfs2_glock *gl, void *object)
883881/**
884882 * glock_clear_object - clear the gl_object field of a glock
885883 * @gl: the glock
884+ * @object: object the glock currently points at
886885 */
887886void glock_clear_object (struct gfs2_glock * gl , void * object )
888887{
@@ -892,8 +891,7 @@ void glock_clear_object(struct gfs2_glock *gl, void *object)
892891 prev_object = gl -> gl_object ;
893892 gl -> gl_object = NULL ;
894893 spin_unlock (& gl -> gl_lockref .lock );
895- if (gfs2_assert_warn (gl -> gl_name .ln_sbd ,
896- prev_object == object || prev_object == NULL )) {
894+ if (gfs2_assert_warn (gl -> gl_name .ln_sbd , prev_object == object )) {
897895 pr_warn ("glock=%u/%llx\n" ,
898896 gl -> gl_name .ln_type ,
899897 (unsigned long long )gl -> gl_name .ln_number );
@@ -977,6 +975,26 @@ static bool gfs2_try_evict(struct gfs2_glock *gl)
977975 return evicted ;
978976}
979977
978+ bool gfs2_queue_try_to_evict (struct gfs2_glock * gl )
979+ {
980+ struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
981+
982+ if (test_and_set_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags ))
983+ return false;
984+ return queue_delayed_work (sdp -> sd_delete_wq ,
985+ & gl -> gl_delete , 0 );
986+ }
987+
988+ static bool gfs2_queue_verify_evict (struct gfs2_glock * gl )
989+ {
990+ struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
991+
992+ if (test_and_set_bit (GLF_VERIFY_EVICT , & gl -> gl_flags ))
993+ return false;
994+ return queue_delayed_work (sdp -> sd_delete_wq ,
995+ & gl -> gl_delete , 5 * HZ );
996+ }
997+
980998static void delete_work_func (struct work_struct * work )
981999{
9821000 struct delayed_work * dwork = to_delayed_work (work );
@@ -985,11 +1003,7 @@ static void delete_work_func(struct work_struct *work)
9851003 struct inode * inode ;
9861004 u64 no_addr = gl -> gl_name .ln_number ;
9871005
988- spin_lock (& gl -> gl_lockref .lock );
989- clear_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
990- spin_unlock (& gl -> gl_lockref .lock );
991-
992- if (test_bit (GLF_DEMOTE , & gl -> gl_flags )) {
1006+ if (test_and_clear_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags )) {
9931007 /*
9941008 * If we can evict the inode, give the remote node trying to
9951009 * delete the inode some time before verifying that the delete
@@ -1008,22 +1022,28 @@ static void delete_work_func(struct work_struct *work)
10081022 * step entirely.
10091023 */
10101024 if (gfs2_try_evict (gl )) {
1011- if (gfs2_queue_delete_work (gl , 5 * HZ ))
1025+ if (test_bit (SDF_DEACTIVATING , & sdp -> sd_flags ))
1026+ goto out ;
1027+ if (gfs2_queue_verify_evict (gl ))
10121028 return ;
10131029 }
10141030 goto out ;
10151031 }
10161032
1017- inode = gfs2_lookup_by_inum (sdp , no_addr , gl -> gl_no_formal_ino ,
1018- GFS2_BLKST_UNLINKED );
1019- if (IS_ERR (inode )) {
1020- if (PTR_ERR (inode ) == - EAGAIN &&
1021- (gfs2_queue_delete_work (gl , 5 * HZ )))
1033+ if (test_and_clear_bit (GLF_VERIFY_EVICT , & gl -> gl_flags )) {
1034+ inode = gfs2_lookup_by_inum (sdp , no_addr , gl -> gl_no_formal_ino ,
1035+ GFS2_BLKST_UNLINKED );
1036+ if (IS_ERR (inode )) {
1037+ if (PTR_ERR (inode ) == - EAGAIN &&
1038+ !test_bit (SDF_DEACTIVATING , & sdp -> sd_flags ) &&
1039+ gfs2_queue_verify_evict (gl ))
10221040 return ;
1023- } else {
1024- d_prune_aliases (inode );
1025- iput (inode );
1041+ } else {
1042+ d_prune_aliases (inode );
1043+ iput (inode );
1044+ }
10261045 }
1046+
10271047out :
10281048 gfs2_glock_put (gl );
10291049}
@@ -1985,26 +2005,26 @@ __acquires(&lru_lock)
19852005
19862006static long gfs2_scan_glock_lru (int nr )
19872007{
1988- struct gfs2_glock * gl ;
1989- LIST_HEAD (skipped );
2008+ struct gfs2_glock * gl , * next ;
19902009 LIST_HEAD (dispose );
19912010 long freed = 0 ;
19922011
19932012 spin_lock (& lru_lock );
1994- while (( nr -- >= 0 ) && ! list_empty ( & lru_list ) ) {
1995- gl = list_first_entry ( & lru_list , struct gfs2_glock , gl_lru );
1996-
2013+ list_for_each_entry_safe ( gl , next , & lru_list , gl_lru ) {
2014+ if ( nr -- <= 0 )
2015+ break ;
19972016 /* Test for being demotable */
19982017 if (!test_bit (GLF_LOCK , & gl -> gl_flags )) {
1999- list_move (& gl -> gl_lru , & dispose );
2000- atomic_dec (& lru_count );
2001- freed ++ ;
2002- continue ;
2018+ if (!spin_trylock (& gl -> gl_lockref .lock ))
2019+ continue ;
2020+ if (!gl -> gl_lockref .count ) {
2021+ list_move (& gl -> gl_lru , & dispose );
2022+ atomic_dec (& lru_count );
2023+ freed ++ ;
2024+ }
2025+ spin_unlock (& gl -> gl_lockref .lock );
20032026 }
2004-
2005- list_move (& gl -> gl_lru , & skipped );
20062027 }
2007- list_splice (& skipped , & lru_list );
20082028 if (!list_empty (& dispose ))
20092029 gfs2_dispose_glock_lru (& dispose );
20102030 spin_unlock (& lru_lock );
@@ -2063,37 +2083,21 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
20632083 rhashtable_walk_exit (& iter );
20642084}
20652085
2066- bool gfs2_queue_delete_work (struct gfs2_glock * gl , unsigned long delay )
2067- {
2068- bool queued ;
2069-
2070- spin_lock (& gl -> gl_lockref .lock );
2071- queued = queue_delayed_work (gfs2_delete_workqueue ,
2072- & gl -> gl_delete , delay );
2073- if (queued )
2074- set_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
2075- spin_unlock (& gl -> gl_lockref .lock );
2076- return queued ;
2077- }
2078-
20792086void gfs2_cancel_delete_work (struct gfs2_glock * gl )
20802087{
2081- if (cancel_delayed_work (& gl -> gl_delete )) {
2082- clear_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
2088+ clear_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags );
2089+ clear_bit (GLF_VERIFY_EVICT , & gl -> gl_flags );
2090+ if (cancel_delayed_work (& gl -> gl_delete ))
20832091 gfs2_glock_put (gl );
2084- }
2085- }
2086-
2087- bool gfs2_delete_work_queued (const struct gfs2_glock * gl )
2088- {
2089- return test_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
20902092}
20912093
20922094static void flush_delete_work (struct gfs2_glock * gl )
20932095{
20942096 if (gl -> gl_name .ln_type == LM_TYPE_IOPEN ) {
2097+ struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
2098+
20952099 if (cancel_delayed_work (& gl -> gl_delete )) {
2096- queue_delayed_work (gfs2_delete_workqueue ,
2100+ queue_delayed_work (sdp -> sd_delete_wq ,
20972101 & gl -> gl_delete , 0 );
20982102 }
20992103 }
@@ -2102,7 +2106,7 @@ static void flush_delete_work(struct gfs2_glock *gl)
21022106void gfs2_flush_delete_work (struct gfs2_sbd * sdp )
21032107{
21042108 glock_hash_walk (flush_delete_work , sdp );
2105- flush_workqueue (gfs2_delete_workqueue );
2109+ flush_workqueue (sdp -> sd_delete_wq );
21062110}
21072111
21082112/**
@@ -2308,14 +2312,16 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23082312 * p ++ = 'o' ;
23092313 if (test_bit (GLF_BLOCKING , gflags ))
23102314 * p ++ = 'b' ;
2311- if (test_bit (GLF_PENDING_DELETE , gflags ))
2312- * p ++ = 'P' ;
23132315 if (test_bit (GLF_FREEING , gflags ))
23142316 * p ++ = 'x' ;
23152317 if (test_bit (GLF_INSTANTIATE_NEEDED , gflags ))
23162318 * p ++ = 'n' ;
23172319 if (test_bit (GLF_INSTANTIATE_IN_PROG , gflags ))
23182320 * p ++ = 'N' ;
2321+ if (test_bit (GLF_TRY_TO_EVICT , gflags ))
2322+ * p ++ = 'e' ;
2323+ if (test_bit (GLF_VERIFY_EVICT , gflags ))
2324+ * p ++ = 'E' ;
23192325 * p = 0 ;
23202326 return buf ;
23212327}
@@ -2465,18 +2471,9 @@ int __init gfs2_glock_init(void)
24652471 rhashtable_destroy (& gl_hash_table );
24662472 return - ENOMEM ;
24672473 }
2468- gfs2_delete_workqueue = alloc_workqueue ("delete_workqueue" ,
2469- WQ_MEM_RECLAIM | WQ_FREEZABLE ,
2470- 0 );
2471- if (!gfs2_delete_workqueue ) {
2472- destroy_workqueue (glock_workqueue );
2473- rhashtable_destroy (& gl_hash_table );
2474- return - ENOMEM ;
2475- }
24762474
24772475 ret = register_shrinker (& glock_shrinker , "gfs2-glock" );
24782476 if (ret ) {
2479- destroy_workqueue (gfs2_delete_workqueue );
24802477 destroy_workqueue (glock_workqueue );
24812478 rhashtable_destroy (& gl_hash_table );
24822479 return ret ;
@@ -2493,7 +2490,6 @@ void gfs2_glock_exit(void)
24932490 unregister_shrinker (& glock_shrinker );
24942491 rhashtable_destroy (& gl_hash_table );
24952492 destroy_workqueue (glock_workqueue );
2496- destroy_workqueue (gfs2_delete_workqueue );
24972493}
24982494
24992495static void gfs2_glock_iter_next (struct gfs2_glock_iter * gi , loff_t n )
0 commit comments