@@ -67,7 +67,6 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state,
67
67
68
68
static struct dentry * gfs2_root ;
69
69
static struct workqueue_struct * glock_workqueue ;
70
- struct workqueue_struct * gfs2_delete_workqueue ;
71
70
static LIST_HEAD (lru_list );
72
71
static atomic_t lru_count = ATOMIC_INIT (0 );
73
72
static DEFINE_SPINLOCK (lru_lock );
@@ -274,9 +273,8 @@ static void __gfs2_glock_put(struct gfs2_glock *gl)
274
273
struct address_space * mapping = gfs2_glock2aspace (gl );
275
274
276
275
lockref_mark_dead (& gl -> gl_lockref );
277
-
278
- gfs2_glock_remove_from_lru (gl );
279
276
spin_unlock (& gl -> gl_lockref .lock );
277
+ gfs2_glock_remove_from_lru (gl );
280
278
GLOCK_BUG_ON (gl , !list_empty (& gl -> gl_holders ));
281
279
if (mapping ) {
282
280
truncate_inode_pages_final (mapping );
@@ -883,6 +881,7 @@ void glock_set_object(struct gfs2_glock *gl, void *object)
883
881
/**
884
882
* glock_clear_object - clear the gl_object field of a glock
885
883
* @gl: the glock
884
+ * @object: object the glock currently points at
886
885
*/
887
886
void glock_clear_object (struct gfs2_glock * gl , void * object )
888
887
{
@@ -892,8 +891,7 @@ void glock_clear_object(struct gfs2_glock *gl, void *object)
892
891
prev_object = gl -> gl_object ;
893
892
gl -> gl_object = NULL ;
894
893
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 )) {
897
895
pr_warn ("glock=%u/%llx\n" ,
898
896
gl -> gl_name .ln_type ,
899
897
(unsigned long long )gl -> gl_name .ln_number );
@@ -977,6 +975,26 @@ static bool gfs2_try_evict(struct gfs2_glock *gl)
977
975
return evicted ;
978
976
}
979
977
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
+
980
998
static void delete_work_func (struct work_struct * work )
981
999
{
982
1000
struct delayed_work * dwork = to_delayed_work (work );
@@ -985,11 +1003,7 @@ static void delete_work_func(struct work_struct *work)
985
1003
struct inode * inode ;
986
1004
u64 no_addr = gl -> gl_name .ln_number ;
987
1005
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 )) {
993
1007
/*
994
1008
* If we can evict the inode, give the remote node trying to
995
1009
* delete the inode some time before verifying that the delete
@@ -1008,22 +1022,28 @@ static void delete_work_func(struct work_struct *work)
1008
1022
* step entirely.
1009
1023
*/
1010
1024
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 ))
1012
1028
return ;
1013
1029
}
1014
1030
goto out ;
1015
1031
}
1016
1032
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 ))
1022
1040
return ;
1023
- } else {
1024
- d_prune_aliases (inode );
1025
- iput (inode );
1041
+ } else {
1042
+ d_prune_aliases (inode );
1043
+ iput (inode );
1044
+ }
1026
1045
}
1046
+
1027
1047
out :
1028
1048
gfs2_glock_put (gl );
1029
1049
}
@@ -1985,26 +2005,26 @@ __acquires(&lru_lock)
1985
2005
1986
2006
static long gfs2_scan_glock_lru (int nr )
1987
2007
{
1988
- struct gfs2_glock * gl ;
1989
- LIST_HEAD (skipped );
2008
+ struct gfs2_glock * gl , * next ;
1990
2009
LIST_HEAD (dispose );
1991
2010
long freed = 0 ;
1992
2011
1993
2012
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 ;
1997
2016
/* Test for being demotable */
1998
2017
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 );
2003
2026
}
2004
-
2005
- list_move (& gl -> gl_lru , & skipped );
2006
2027
}
2007
- list_splice (& skipped , & lru_list );
2008
2028
if (!list_empty (& dispose ))
2009
2029
gfs2_dispose_glock_lru (& dispose );
2010
2030
spin_unlock (& lru_lock );
@@ -2063,37 +2083,21 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
2063
2083
rhashtable_walk_exit (& iter );
2064
2084
}
2065
2085
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
-
2079
2086
void gfs2_cancel_delete_work (struct gfs2_glock * gl )
2080
2087
{
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 ))
2083
2091
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 );
2090
2092
}
2091
2093
2092
2094
static void flush_delete_work (struct gfs2_glock * gl )
2093
2095
{
2094
2096
if (gl -> gl_name .ln_type == LM_TYPE_IOPEN ) {
2097
+ struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
2098
+
2095
2099
if (cancel_delayed_work (& gl -> gl_delete )) {
2096
- queue_delayed_work (gfs2_delete_workqueue ,
2100
+ queue_delayed_work (sdp -> sd_delete_wq ,
2097
2101
& gl -> gl_delete , 0 );
2098
2102
}
2099
2103
}
@@ -2102,7 +2106,7 @@ static void flush_delete_work(struct gfs2_glock *gl)
2102
2106
void gfs2_flush_delete_work (struct gfs2_sbd * sdp )
2103
2107
{
2104
2108
glock_hash_walk (flush_delete_work , sdp );
2105
- flush_workqueue (gfs2_delete_workqueue );
2109
+ flush_workqueue (sdp -> sd_delete_wq );
2106
2110
}
2107
2111
2108
2112
/**
@@ -2308,14 +2312,16 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
2308
2312
* p ++ = 'o' ;
2309
2313
if (test_bit (GLF_BLOCKING , gflags ))
2310
2314
* p ++ = 'b' ;
2311
- if (test_bit (GLF_PENDING_DELETE , gflags ))
2312
- * p ++ = 'P' ;
2313
2315
if (test_bit (GLF_FREEING , gflags ))
2314
2316
* p ++ = 'x' ;
2315
2317
if (test_bit (GLF_INSTANTIATE_NEEDED , gflags ))
2316
2318
* p ++ = 'n' ;
2317
2319
if (test_bit (GLF_INSTANTIATE_IN_PROG , gflags ))
2318
2320
* 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' ;
2319
2325
* p = 0 ;
2320
2326
return buf ;
2321
2327
}
@@ -2465,18 +2471,9 @@ int __init gfs2_glock_init(void)
2465
2471
rhashtable_destroy (& gl_hash_table );
2466
2472
return - ENOMEM ;
2467
2473
}
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
- }
2476
2474
2477
2475
ret = register_shrinker (& glock_shrinker , "gfs2-glock" );
2478
2476
if (ret ) {
2479
- destroy_workqueue (gfs2_delete_workqueue );
2480
2477
destroy_workqueue (glock_workqueue );
2481
2478
rhashtable_destroy (& gl_hash_table );
2482
2479
return ret ;
@@ -2493,7 +2490,6 @@ void gfs2_glock_exit(void)
2493
2490
unregister_shrinker (& glock_shrinker );
2494
2491
rhashtable_destroy (& gl_hash_table );
2495
2492
destroy_workqueue (glock_workqueue );
2496
- destroy_workqueue (gfs2_delete_workqueue );
2497
2493
}
2498
2494
2499
2495
static void gfs2_glock_iter_next (struct gfs2_glock_iter * gi , loff_t n )
0 commit comments