3535#include <linux/rhashtable.h>
3636#include <linux/pid_namespace.h>
3737#include <linux/file.h>
38+ #include <linux/random.h>
3839
3940#include "gfs2.h"
4041#include "incore.h"
@@ -562,11 +563,11 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
562563 gl -> gl_tchange = jiffies ;
563564}
564565
565- static void gfs2_set_demote (struct gfs2_glock * gl )
566+ static void gfs2_set_demote (int nr , struct gfs2_glock * gl )
566567{
567568 struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
568569
569- set_bit (GLF_DEMOTE , & gl -> gl_flags );
570+ set_bit (nr , & gl -> gl_flags );
570571 smp_mb ();
571572 wake_up (& sdp -> sd_async_glock_wait );
572573}
@@ -958,37 +959,45 @@ static void gfs2_glock_poke(struct gfs2_glock *gl)
958959 gfs2_holder_uninit (& gh );
959960}
960961
961- static bool gfs2_try_evict (struct gfs2_glock * gl )
962+ static void gfs2_try_evict (struct gfs2_glock * gl )
962963{
963964 struct gfs2_inode * ip ;
964- bool evicted = false;
965965
966966 /*
967967 * 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.
971973 *
972974 * The remote node is likely still holding the corresponding inode
973975 * 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().)
975978 */
976979 spin_lock (& gl -> gl_lockref .lock );
977980 ip = gl -> gl_object ;
978981 if (ip && !igrab (& ip -> i_inode ))
979982 ip = NULL ;
980983 spin_unlock (& gl -> gl_lockref .lock );
981984 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 );
984993 d_prune_aliases (& ip -> i_inode );
985994 iput (& ip -> i_inode );
986995
987996 /* If the inode was evicted, gl->gl_object will now be NULL. */
988997 spin_lock (& gl -> gl_lockref .lock );
989998 ip = gl -> gl_object ;
990999 if (ip ) {
991- clear_bit (GIF_DEFERRED_DELETE , & ip -> i_flags );
1000+ clear_bit (GIF_DEFER_DELETE , & ip -> i_flags );
9921001 if (!igrab (& ip -> i_inode ))
9931002 ip = NULL ;
9941003 }
@@ -997,9 +1006,7 @@ static bool gfs2_try_evict(struct gfs2_glock *gl)
9971006 gfs2_glock_poke (ip -> i_gl );
9981007 iput (& ip -> i_inode );
9991008 }
1000- evicted = !ip ;
10011009 }
1002- return evicted ;
10031010}
10041011
10051012bool gfs2_queue_try_to_evict (struct gfs2_glock * gl )
@@ -1008,70 +1015,47 @@ bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
10081015
10091016 if (test_and_set_bit (GLF_TRY_TO_EVICT , & gl -> gl_flags ))
10101017 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 );
10131019}
10141020
1015- static bool gfs2_queue_verify_evict (struct gfs2_glock * gl )
1021+ bool gfs2_queue_verify_delete (struct gfs2_glock * gl , bool later )
10161022{
10171023 struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
1024+ unsigned long delay ;
10181025
1019- if (test_and_set_bit (GLF_VERIFY_EVICT , & gl -> gl_flags ))
1026+ if (test_and_set_bit (GLF_VERIFY_DELETE , & gl -> gl_flags ))
10201027 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 );
10231030}
10241031
10251032static void delete_work_func (struct work_struct * work )
10261033{
10271034 struct delayed_work * dwork = to_delayed_work (work );
10281035 struct gfs2_glock * gl = container_of (dwork , struct gfs2_glock , gl_delete );
10291036 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 );
10321038
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 ;
10591045
1060- if (test_and_clear_bit (GLF_VERIFY_EVICT , & gl -> gl_flags )) {
10611046 inode = gfs2_lookup_by_inum (sdp , no_addr , gl -> gl_no_formal_ino ,
10621047 GFS2_BLKST_UNLINKED );
10631048 if (IS_ERR (inode )) {
10641049 if (PTR_ERR (inode ) == - EAGAIN &&
10651050 !test_bit (SDF_KILL , & sdp -> sd_flags ) &&
1066- gfs2_queue_verify_evict (gl ))
1051+ gfs2_queue_verify_delete (gl , true ))
10671052 return ;
10681053 } else {
10691054 d_prune_aliases (inode );
10701055 iput (inode );
10711056 }
10721057 }
10731058
1074- out :
10751059 gfs2_glock_put (gl );
10761060}
10771061
@@ -1100,7 +1084,7 @@ static void glock_work_func(struct work_struct *work)
11001084
11011085 if (!delay ) {
11021086 clear_bit (GLF_PENDING_DEMOTE , & gl -> gl_flags );
1103- gfs2_set_demote (gl );
1087+ gfs2_set_demote (GLF_DEMOTE , gl );
11041088 }
11051089 }
11061090 run_queue (gl , 0 );
@@ -1442,10 +1426,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
14421426static void request_demote (struct gfs2_glock * gl , unsigned int state ,
14431427 unsigned long delay , bool remote )
14441428{
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 );
14491430 if (gl -> gl_demote_state == LM_ST_EXCLUSIVE ) {
14501431 gl -> gl_demote_state = state ;
14511432 gl -> gl_demote_time = jiffies ;
@@ -1635,12 +1616,6 @@ int gfs2_glock_poll(struct gfs2_holder *gh)
16351616 return test_bit (HIF_WAIT , & gh -> gh_iflags ) ? 0 : 1 ;
16361617}
16371618
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-
16441619static void __gfs2_glock_dq (struct gfs2_holder * gh )
16451620{
16461621 struct gfs2_glock * gl = gh -> gh_gl ;
@@ -1649,8 +1624,8 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16491624
16501625 /*
16511626 * 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.
16541629 */
16551630 if (gh -> gh_flags & GL_NOCACHE )
16561631 request_demote (gl , LM_ST_UNLOCKED , 0 , false);
@@ -1663,7 +1638,7 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16631638 * If there hasn't been a demote request we are done.
16641639 * (Let the remaining holders, if any, keep holding it.)
16651640 */
1666- if (!needs_demote (gl )) {
1641+ if (!glock_needs_demote (gl )) {
16671642 if (list_empty (& gl -> gl_holders ))
16681643 fast_path = 1 ;
16691644 }
@@ -2117,7 +2092,7 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
21172092void gfs2_cancel_delete_work (struct gfs2_glock * gl )
21182093{
21192094 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 );
21212096 if (cancel_delayed_work (& gl -> gl_delete ))
21222097 gfs2_glock_put (gl );
21232098}
@@ -2370,7 +2345,7 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23702345 * p ++ = 'N' ;
23712346 if (test_bit (GLF_TRY_TO_EVICT , gflags ))
23722347 * p ++ = 'e' ;
2373- if (test_bit (GLF_VERIFY_EVICT , gflags ))
2348+ if (test_bit (GLF_VERIFY_DELETE , gflags ))
23742349 * p ++ = 'E' ;
23752350 * p = 0 ;
23762351 return buf ;
0 commit comments