35
35
#include <linux/rhashtable.h>
36
36
#include <linux/pid_namespace.h>
37
37
#include <linux/file.h>
38
+ #include <linux/random.h>
38
39
39
40
#include "gfs2.h"
40
41
#include "incore.h"
@@ -562,11 +563,11 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
562
563
gl -> gl_tchange = jiffies ;
563
564
}
564
565
565
- static void gfs2_set_demote (struct gfs2_glock * gl )
566
+ static void gfs2_set_demote (int nr , struct gfs2_glock * gl )
566
567
{
567
568
struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
568
569
569
- set_bit (GLF_DEMOTE , & gl -> gl_flags );
570
+ set_bit (nr , & gl -> gl_flags );
570
571
smp_mb ();
571
572
wake_up (& sdp -> sd_async_glock_wait );
572
573
}
@@ -958,37 +959,45 @@ static void gfs2_glock_poke(struct gfs2_glock *gl)
958
959
gfs2_holder_uninit (& gh );
959
960
}
960
961
961
- static bool gfs2_try_evict (struct gfs2_glock * gl )
962
+ static void gfs2_try_evict (struct gfs2_glock * gl )
962
963
{
963
964
struct gfs2_inode * ip ;
964
- bool evicted = false;
965
965
966
966
/*
967
967
* If there is contention on the iopen glock and we have an inode, try
968
- * to grab and release the inode so that it can be evicted. This will
969
- * allow the remote node to go ahead and delete the inode without us
970
- * having to do it, which will avoid rgrp glock thrashing.
968
+ * to grab and release the inode so that it can be evicted. The
969
+ * GIF_DEFER_DELETE flag indicates to gfs2_evict_inode() that the inode
970
+ * should not be deleted locally. This will allow the remote node to
971
+ * go ahead and delete the inode without us having to do it, which will
972
+ * avoid rgrp glock thrashing.
971
973
*
972
974
* The remote node is likely still holding the corresponding inode
973
975
* glock, so it will run before we get to verify that the delete has
974
- * happened below.
976
+ * happened below. (Verification is triggered by the call to
977
+ * gfs2_queue_verify_delete() in gfs2_evict_inode().)
975
978
*/
976
979
spin_lock (& gl -> gl_lockref .lock );
977
980
ip = gl -> gl_object ;
978
981
if (ip && !igrab (& ip -> i_inode ))
979
982
ip = NULL ;
980
983
spin_unlock (& gl -> gl_lockref .lock );
981
984
if (ip ) {
982
- gl -> gl_no_formal_ino = ip -> i_no_formal_ino ;
983
- set_bit (GIF_DEFERRED_DELETE , & ip -> i_flags );
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
+ }
991
+ if (ip ) {
992
+ set_bit (GIF_DEFER_DELETE , & ip -> i_flags );
984
993
d_prune_aliases (& ip -> i_inode );
985
994
iput (& ip -> i_inode );
986
995
987
996
/* If the inode was evicted, gl->gl_object will now be NULL. */
988
997
spin_lock (& gl -> gl_lockref .lock );
989
998
ip = gl -> gl_object ;
990
999
if (ip ) {
991
- clear_bit (GIF_DEFERRED_DELETE , & ip -> i_flags );
1000
+ clear_bit (GIF_DEFER_DELETE , & ip -> i_flags );
992
1001
if (!igrab (& ip -> i_inode ))
993
1002
ip = NULL ;
994
1003
}
@@ -997,9 +1006,7 @@ static bool gfs2_try_evict(struct gfs2_glock *gl)
997
1006
gfs2_glock_poke (ip -> i_gl );
998
1007
iput (& ip -> i_inode );
999
1008
}
1000
- evicted = !ip ;
1001
1009
}
1002
- return evicted ;
1003
1010
}
1004
1011
1005
1012
bool gfs2_queue_try_to_evict (struct gfs2_glock * gl )
@@ -1008,70 +1015,47 @@ bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
1008
1015
1009
1016
if (test_and_set_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags ))
1010
1017
return false;
1011
- return queue_delayed_work (sdp -> sd_delete_wq ,
1012
- & gl -> gl_delete , 0 );
1018
+ return !mod_delayed_work (sdp -> sd_delete_wq , & gl -> gl_delete , 0 );
1013
1019
}
1014
1020
1015
- static bool gfs2_queue_verify_evict (struct gfs2_glock * gl )
1021
+ bool gfs2_queue_verify_delete (struct gfs2_glock * gl , bool later )
1016
1022
{
1017
1023
struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
1024
+ unsigned long delay ;
1018
1025
1019
- if (test_and_set_bit (GLF_VERIFY_EVICT , & gl -> gl_flags ))
1026
+ if (test_and_set_bit (GLF_VERIFY_DELETE , & gl -> gl_flags ))
1020
1027
return false;
1021
- return queue_delayed_work ( sdp -> sd_delete_wq ,
1022
- & gl -> gl_delete , 5 * HZ );
1028
+ delay = later ? HZ + get_random_long () % ( HZ * 9 ) : 0 ;
1029
+ return queue_delayed_work ( sdp -> sd_delete_wq , & gl -> gl_delete , delay );
1023
1030
}
1024
1031
1025
1032
static void delete_work_func (struct work_struct * work )
1026
1033
{
1027
1034
struct delayed_work * dwork = to_delayed_work (work );
1028
1035
struct gfs2_glock * gl = container_of (dwork , struct gfs2_glock , gl_delete );
1029
1036
struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
1030
- struct inode * inode ;
1031
- u64 no_addr = gl -> gl_name .ln_number ;
1037
+ bool verify_delete = test_and_clear_bit (GLF_VERIFY_DELETE , & gl -> gl_flags );
1032
1038
1033
- if (test_and_clear_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags )) {
1034
- /*
1035
- * If we can evict the inode, give the remote node trying to
1036
- * delete the inode some time before verifying that the delete
1037
- * has happened. Otherwise, if we cause contention on the inode glock
1038
- * immediately, the remote node will think that we still have
1039
- * the inode in use, and so it will give up waiting.
1040
- *
1041
- * If we can't evict the inode, signal to the remote node that
1042
- * the inode is still in use. We'll later try to delete the
1043
- * inode locally in gfs2_evict_inode.
1044
- *
1045
- * FIXME: We only need to verify that the remote node has
1046
- * deleted the inode because nodes before this remote delete
1047
- * rework won't cooperate. At a later time, when we no longer
1048
- * care about compatibility with such nodes, we can skip this
1049
- * step entirely.
1050
- */
1051
- if (gfs2_try_evict (gl )) {
1052
- if (test_bit (SDF_KILL , & sdp -> sd_flags ))
1053
- goto out ;
1054
- if (gfs2_queue_verify_evict (gl ))
1055
- return ;
1056
- }
1057
- goto out ;
1058
- }
1039
+ if (test_and_clear_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags ))
1040
+ gfs2_try_evict (gl );
1041
+
1042
+ if (verify_delete ) {
1043
+ u64 no_addr = gl -> gl_name .ln_number ;
1044
+ struct inode * inode ;
1059
1045
1060
- if (test_and_clear_bit (GLF_VERIFY_EVICT , & gl -> gl_flags )) {
1061
1046
inode = gfs2_lookup_by_inum (sdp , no_addr , gl -> gl_no_formal_ino ,
1062
1047
GFS2_BLKST_UNLINKED );
1063
1048
if (IS_ERR (inode )) {
1064
1049
if (PTR_ERR (inode ) == - EAGAIN &&
1065
1050
!test_bit (SDF_KILL , & sdp -> sd_flags ) &&
1066
- gfs2_queue_verify_evict (gl ))
1051
+ gfs2_queue_verify_delete (gl , true ))
1067
1052
return ;
1068
1053
} else {
1069
1054
d_prune_aliases (inode );
1070
1055
iput (inode );
1071
1056
}
1072
1057
}
1073
1058
1074
- out :
1075
1059
gfs2_glock_put (gl );
1076
1060
}
1077
1061
@@ -1100,7 +1084,7 @@ static void glock_work_func(struct work_struct *work)
1100
1084
1101
1085
if (!delay ) {
1102
1086
clear_bit (GLF_PENDING_DEMOTE , & gl -> gl_flags );
1103
- gfs2_set_demote (gl );
1087
+ gfs2_set_demote (GLF_DEMOTE , gl );
1104
1088
}
1105
1089
}
1106
1090
run_queue (gl , 0 );
@@ -1442,10 +1426,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
1442
1426
static void request_demote (struct gfs2_glock * gl , unsigned int state ,
1443
1427
unsigned long delay , bool remote )
1444
1428
{
1445
- if (delay )
1446
- set_bit (GLF_PENDING_DEMOTE , & gl -> gl_flags );
1447
- else
1448
- gfs2_set_demote (gl );
1429
+ gfs2_set_demote (delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE , gl );
1449
1430
if (gl -> gl_demote_state == LM_ST_EXCLUSIVE ) {
1450
1431
gl -> gl_demote_state = state ;
1451
1432
gl -> gl_demote_time = jiffies ;
@@ -1635,12 +1616,6 @@ int gfs2_glock_poll(struct gfs2_holder *gh)
1635
1616
return test_bit (HIF_WAIT , & gh -> gh_iflags ) ? 0 : 1 ;
1636
1617
}
1637
1618
1638
- static inline bool needs_demote (struct gfs2_glock * gl )
1639
- {
1640
- return (test_bit (GLF_DEMOTE , & gl -> gl_flags ) ||
1641
- test_bit (GLF_PENDING_DEMOTE , & gl -> gl_flags ));
1642
- }
1643
-
1644
1619
static void __gfs2_glock_dq (struct gfs2_holder * gh )
1645
1620
{
1646
1621
struct gfs2_glock * gl = gh -> gh_gl ;
@@ -1649,8 +1624,8 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
1649
1624
1650
1625
/*
1651
1626
* This holder should not be cached, so mark it for demote.
1652
- * Note: this should be done before the check for needs_demote
1653
- * below.
1627
+ * Note: this should be done before the glock_needs_demote
1628
+ * check below.
1654
1629
*/
1655
1630
if (gh -> gh_flags & GL_NOCACHE )
1656
1631
request_demote (gl , LM_ST_UNLOCKED , 0 , false);
@@ -1663,7 +1638,7 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
1663
1638
* If there hasn't been a demote request we are done.
1664
1639
* (Let the remaining holders, if any, keep holding it.)
1665
1640
*/
1666
- if (!needs_demote (gl )) {
1641
+ if (!glock_needs_demote (gl )) {
1667
1642
if (list_empty (& gl -> gl_holders ))
1668
1643
fast_path = 1 ;
1669
1644
}
@@ -2117,7 +2092,7 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
2117
2092
void gfs2_cancel_delete_work (struct gfs2_glock * gl )
2118
2093
{
2119
2094
clear_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags );
2120
- clear_bit (GLF_VERIFY_EVICT , & gl -> gl_flags );
2095
+ clear_bit (GLF_VERIFY_DELETE , & gl -> gl_flags );
2121
2096
if (cancel_delayed_work (& gl -> gl_delete ))
2122
2097
gfs2_glock_put (gl );
2123
2098
}
@@ -2370,7 +2345,7 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
2370
2345
* p ++ = 'N' ;
2371
2346
if (test_bit (GLF_TRY_TO_EVICT , gflags ))
2372
2347
* p ++ = 'e' ;
2373
- if (test_bit (GLF_VERIFY_EVICT , gflags ))
2348
+ if (test_bit (GLF_VERIFY_DELETE , gflags ))
2374
2349
* p ++ = 'E' ;
2375
2350
* p = 0 ;
2376
2351
return buf ;
0 commit comments