@@ -125,12 +125,11 @@ static void gfs2_glock_dealloc(struct rcu_head *rcu)
125125{
126126 struct gfs2_glock * gl = container_of (rcu , struct gfs2_glock , gl_rcu );
127127
128- if (gl -> gl_ops -> go_flags & GLOF_ASPACE ) {
128+ kfree (gl -> gl_lksb .sb_lvbptr );
129+ if (gl -> gl_ops -> go_flags & GLOF_ASPACE )
129130 kmem_cache_free (gfs2_glock_aspace_cachep , gl );
130- } else {
131- kfree (gl -> gl_lksb .sb_lvbptr );
131+ else
132132 kmem_cache_free (gfs2_glock_cachep , gl );
133- }
134133}
135134
136135/**
@@ -465,6 +464,15 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
465464 gl -> gl_tchange = jiffies ;
466465}
467466
467+ static void gfs2_set_demote (struct gfs2_glock * gl )
468+ {
469+ struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
470+
471+ set_bit (GLF_DEMOTE , & gl -> gl_flags );
472+ smp_mb ();
473+ wake_up (& sdp -> sd_async_glock_wait );
474+ }
475+
468476static void gfs2_demote_wake (struct gfs2_glock * gl )
469477{
470478 gl -> gl_demote_state = LM_ST_EXCLUSIVE ;
@@ -757,20 +765,127 @@ __acquires(&gl->gl_lockref.lock)
757765 return ;
758766}
759767
768+ void gfs2_inode_remember_delete (struct gfs2_glock * gl , u64 generation )
769+ {
770+ struct gfs2_inode_lvb * ri = (void * )gl -> gl_lksb .sb_lvbptr ;
771+
772+ if (ri -> ri_magic == 0 )
773+ ri -> ri_magic = cpu_to_be32 (GFS2_MAGIC );
774+ if (ri -> ri_magic == cpu_to_be32 (GFS2_MAGIC ))
775+ ri -> ri_generation_deleted = cpu_to_be64 (generation );
776+ }
777+
778+ bool gfs2_inode_already_deleted (struct gfs2_glock * gl , u64 generation )
779+ {
780+ struct gfs2_inode_lvb * ri = (void * )gl -> gl_lksb .sb_lvbptr ;
781+
782+ if (ri -> ri_magic != cpu_to_be32 (GFS2_MAGIC ))
783+ return false;
784+ return generation <= be64_to_cpu (ri -> ri_generation_deleted );
785+ }
786+
787+ static void gfs2_glock_poke (struct gfs2_glock * gl )
788+ {
789+ int flags = LM_FLAG_TRY_1CB | LM_FLAG_ANY | GL_SKIP ;
790+ struct gfs2_holder gh ;
791+ int error ;
792+
793+ error = gfs2_glock_nq_init (gl , LM_ST_SHARED , flags , & gh );
794+ if (!error )
795+ gfs2_glock_dq (& gh );
796+ }
797+
798+ static bool gfs2_try_evict (struct gfs2_glock * gl )
799+ {
800+ struct gfs2_inode * ip ;
801+ bool evicted = false;
802+
803+ /*
804+ * If there is contention on the iopen glock and we have an inode, try
805+ * to grab and release the inode so that it can be evicted. This will
806+ * allow the remote node to go ahead and delete the inode without us
807+ * having to do it, which will avoid rgrp glock thrashing.
808+ *
809+ * The remote node is likely still holding the corresponding inode
810+ * glock, so it will run before we get to verify that the delete has
811+ * happened below.
812+ */
813+ spin_lock (& gl -> gl_lockref .lock );
814+ ip = gl -> gl_object ;
815+ if (ip && !igrab (& ip -> i_inode ))
816+ ip = NULL ;
817+ spin_unlock (& gl -> gl_lockref .lock );
818+ if (ip ) {
819+ struct gfs2_glock * inode_gl = NULL ;
820+
821+ gl -> gl_no_formal_ino = ip -> i_no_formal_ino ;
822+ set_bit (GIF_DEFERRED_DELETE , & ip -> i_flags );
823+ d_prune_aliases (& ip -> i_inode );
824+ iput (& ip -> i_inode );
825+
826+ /* If the inode was evicted, gl->gl_object will now be NULL. */
827+ spin_lock (& gl -> gl_lockref .lock );
828+ ip = gl -> gl_object ;
829+ if (ip ) {
830+ inode_gl = ip -> i_gl ;
831+ lockref_get (& inode_gl -> gl_lockref );
832+ clear_bit (GIF_DEFERRED_DELETE , & ip -> i_flags );
833+ }
834+ spin_unlock (& gl -> gl_lockref .lock );
835+ if (inode_gl ) {
836+ gfs2_glock_poke (inode_gl );
837+ gfs2_glock_put (inode_gl );
838+ }
839+ evicted = !ip ;
840+ }
841+ return evicted ;
842+ }
843+
760844static void delete_work_func (struct work_struct * work )
761845{
762- struct gfs2_glock * gl = container_of (work , struct gfs2_glock , gl_delete );
846+ struct delayed_work * dwork = to_delayed_work (work );
847+ struct gfs2_glock * gl = container_of (dwork , struct gfs2_glock , gl_delete );
763848 struct gfs2_sbd * sdp = gl -> gl_name .ln_sbd ;
764849 struct inode * inode ;
765850 u64 no_addr = gl -> gl_name .ln_number ;
766851
852+ spin_lock (& gl -> gl_lockref .lock );
853+ clear_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
854+ spin_unlock (& gl -> gl_lockref .lock );
855+
767856 /* If someone's using this glock to create a new dinode, the block must
768857 have been freed by another node, then re-used, in which case our
769858 iopen callback is too late after the fact. Ignore it. */
770859 if (test_bit (GLF_INODE_CREATING , & gl -> gl_flags ))
771860 goto out ;
772861
773- inode = gfs2_lookup_by_inum (sdp , no_addr , NULL , GFS2_BLKST_UNLINKED );
862+ if (test_bit (GLF_DEMOTE , & gl -> gl_flags )) {
863+ /*
864+ * If we can evict the inode, give the remote node trying to
865+ * delete the inode some time before verifying that the delete
866+ * has happened. Otherwise, if we cause contention on the inode glock
867+ * immediately, the remote node will think that we still have
868+ * the inode in use, and so it will give up waiting.
869+ *
870+ * If we can't evict the inode, signal to the remote node that
871+ * the inode is still in use. We'll later try to delete the
872+ * inode locally in gfs2_evict_inode.
873+ *
874+ * FIXME: We only need to verify that the remote node has
875+ * deleted the inode because nodes before this remote delete
876+ * rework won't cooperate. At a later time, when we no longer
877+ * care about compatibility with such nodes, we can skip this
878+ * step entirely.
879+ */
880+ if (gfs2_try_evict (gl )) {
881+ if (gfs2_queue_delete_work (gl , 5 * HZ ))
882+ return ;
883+ }
884+ goto out ;
885+ }
886+
887+ inode = gfs2_lookup_by_inum (sdp , no_addr , gl -> gl_no_formal_ino ,
888+ GFS2_BLKST_UNLINKED );
774889 if (!IS_ERR_OR_NULL (inode )) {
775890 d_prune_aliases (inode );
776891 iput (inode );
@@ -801,7 +916,7 @@ static void glock_work_func(struct work_struct *work)
801916
802917 if (!delay ) {
803918 clear_bit (GLF_PENDING_DEMOTE , & gl -> gl_flags );
804- set_bit ( GLF_DEMOTE , & gl -> gl_flags );
919+ gfs2_set_demote ( gl );
805920 }
806921 }
807922 run_queue (gl , 0 );
@@ -932,7 +1047,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
9321047 gl -> gl_object = NULL ;
9331048 gl -> gl_hold_time = GL_GLOCK_DFT_HOLD ;
9341049 INIT_DELAYED_WORK (& gl -> gl_work , glock_work_func );
935- INIT_WORK (& gl -> gl_delete , delete_work_func );
1050+ INIT_DELAYED_WORK (& gl -> gl_delete , delete_work_func );
9361051
9371052 mapping = gfs2_glock2aspace (gl );
9381053 if (mapping ) {
@@ -1146,9 +1261,10 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
11461261static void handle_callback (struct gfs2_glock * gl , unsigned int state ,
11471262 unsigned long delay , bool remote )
11481263{
1149- int bit = delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE ;
1150-
1151- set_bit (bit , & gl -> gl_flags );
1264+ if (delay )
1265+ set_bit (GLF_PENDING_DEMOTE , & gl -> gl_flags );
1266+ else
1267+ gfs2_set_demote (gl );
11521268 if (gl -> gl_demote_state == LM_ST_EXCLUSIVE ) {
11531269 gl -> gl_demote_state = state ;
11541270 gl -> gl_demote_time = jiffies ;
@@ -1755,6 +1871,44 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
17551871 rhashtable_walk_exit (& iter );
17561872}
17571873
1874+ bool gfs2_queue_delete_work (struct gfs2_glock * gl , unsigned long delay )
1875+ {
1876+ bool queued ;
1877+
1878+ spin_lock (& gl -> gl_lockref .lock );
1879+ queued = queue_delayed_work (gfs2_delete_workqueue ,
1880+ & gl -> gl_delete , delay );
1881+ if (queued )
1882+ set_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
1883+ spin_unlock (& gl -> gl_lockref .lock );
1884+ return queued ;
1885+ }
1886+
1887+ void gfs2_cancel_delete_work (struct gfs2_glock * gl )
1888+ {
1889+ if (cancel_delayed_work_sync (& gl -> gl_delete )) {
1890+ clear_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
1891+ gfs2_glock_put (gl );
1892+ }
1893+ }
1894+
1895+ bool gfs2_delete_work_queued (const struct gfs2_glock * gl )
1896+ {
1897+ return test_bit (GLF_PENDING_DELETE , & gl -> gl_flags );
1898+ }
1899+
1900+ static void flush_delete_work (struct gfs2_glock * gl )
1901+ {
1902+ flush_delayed_work (& gl -> gl_delete );
1903+ gfs2_glock_queue_work (gl , 0 );
1904+ }
1905+
1906+ void gfs2_flush_delete_work (struct gfs2_sbd * sdp )
1907+ {
1908+ glock_hash_walk (flush_delete_work , sdp );
1909+ flush_workqueue (gfs2_delete_workqueue );
1910+ }
1911+
17581912/**
17591913 * thaw_glock - thaw out a glock which has an unprocessed reply waiting
17601914 * @gl: The glock to thaw
0 commit comments