@@ -233,19 +233,18 @@ static void put_quota_format(struct quota_format_type *fmt)
233
233
* All dquots are placed to the end of inuse_list when first created, and this
234
234
* list is used for invalidate operation, which must look at every dquot.
235
235
*
236
- * When the last reference of a dquot will be dropped, the dquot will be
237
- * added to releasing_dquots. We'd then queue work item which would call
236
+ * When the last reference of a dquot is dropped, the dquot is added to
237
+ * releasing_dquots. We'll then queue work item which will call
238
238
* synchronize_srcu() and after that perform the final cleanup of all the
239
- * dquots on the list. Both releasing_dquots and free_dquots use the
240
- * dq_free list_head in the dquot struct. When a dquot is removed from
241
- * releasing_dquots, a reference count is always subtracted, and if
242
- * dq_count == 0 at that point, the dquot will be added to the free_dquots.
239
+ * dquots on the list. Each cleaned up dquot is moved to free_dquots list.
240
+ * Both releasing_dquots and free_dquots use the dq_free list_head in the dquot
241
+ * struct.
243
242
*
244
- * Unused dquots (dq_count == 0) are added to the free_dquots list when freed,
245
- * and this list is searched whenever we need an available dquot. Dquots are
246
- * removed from the list as soon as they are used again, and
247
- * dqstats.free_dquots gives the number of dquots on the list. When
248
- * dquot is invalidated it's completely released from memory.
243
+ * Unused and cleaned up dquots are in the free_dquots list and this list is
244
+ * searched whenever we need an available dquot. Dquots are removed from the
245
+ * list as soon as they are used again and dqstats.free_dquots gives the number
246
+ * of dquots on the list. When dquot is invalidated it's completely released
247
+ * from memory.
249
248
*
250
249
* Dirty dquots are added to the dqi_dirty_list of quota_info when mark
251
250
* dirtied, and this list is searched when writing dirty dquots back to
@@ -321,15 +320,18 @@ static inline void put_dquot_last(struct dquot *dquot)
321
320
static inline void put_releasing_dquots (struct dquot * dquot )
322
321
{
323
322
list_add_tail (& dquot -> dq_free , & releasing_dquots );
323
+ set_bit (DQ_RELEASING_B , & dquot -> dq_flags );
324
324
}
325
325
326
326
static inline void remove_free_dquot (struct dquot * dquot )
327
327
{
328
328
if (list_empty (& dquot -> dq_free ))
329
329
return ;
330
330
list_del_init (& dquot -> dq_free );
331
- if (!atomic_read ( & dquot -> dq_count ))
331
+ if (!test_bit ( DQ_RELEASING_B , & dquot -> dq_flags ))
332
332
dqstats_dec (DQST_FREE_DQUOTS );
333
+ else
334
+ clear_bit (DQ_RELEASING_B , & dquot -> dq_flags );
333
335
}
334
336
335
337
static inline void put_inuse (struct dquot * dquot )
@@ -581,12 +583,6 @@ static void invalidate_dquots(struct super_block *sb, int type)
581
583
continue ;
582
584
/* Wait for dquot users */
583
585
if (atomic_read (& dquot -> dq_count )) {
584
- /* dquot in releasing_dquots, flush and retry */
585
- if (!list_empty (& dquot -> dq_free )) {
586
- spin_unlock (& dq_list_lock );
587
- goto restart ;
588
- }
589
-
590
586
atomic_inc (& dquot -> dq_count );
591
587
spin_unlock (& dq_list_lock );
592
588
/*
@@ -605,6 +601,15 @@ static void invalidate_dquots(struct super_block *sb, int type)
605
601
* restart. */
606
602
goto restart ;
607
603
}
604
+ /*
605
+ * The last user already dropped its reference but dquot didn't
606
+ * get fully cleaned up yet. Restart the scan which flushes the
607
+ * work cleaning up released dquots.
608
+ */
609
+ if (test_bit (DQ_RELEASING_B , & dquot -> dq_flags )) {
610
+ spin_unlock (& dq_list_lock );
611
+ goto restart ;
612
+ }
608
613
/*
609
614
* Quota now has no users and it has been written on last
610
615
* dqput()
@@ -696,6 +701,13 @@ int dquot_writeback_dquots(struct super_block *sb, int type)
696
701
dq_dirty );
697
702
698
703
WARN_ON (!dquot_active (dquot ));
704
+ /* If the dquot is releasing we should not touch it */
705
+ if (test_bit (DQ_RELEASING_B , & dquot -> dq_flags )) {
706
+ spin_unlock (& dq_list_lock );
707
+ flush_delayed_work (& quota_release_work );
708
+ spin_lock (& dq_list_lock );
709
+ continue ;
710
+ }
699
711
700
712
/* Now we have active dquot from which someone is
701
713
* holding reference so we can safely just increase
@@ -809,18 +821,18 @@ static void quota_release_workfn(struct work_struct *work)
809
821
/* Exchange the list head to avoid livelock. */
810
822
list_replace_init (& releasing_dquots , & rls_head );
811
823
spin_unlock (& dq_list_lock );
824
+ synchronize_srcu (& dquot_srcu );
812
825
813
826
restart :
814
- synchronize_srcu (& dquot_srcu );
815
827
spin_lock (& dq_list_lock );
816
828
while (!list_empty (& rls_head )) {
817
829
dquot = list_first_entry (& rls_head , struct dquot , dq_free );
818
- /* Dquot got used again? */
819
- if ( atomic_read ( & dquot -> dq_count ) > 1 ) {
820
- remove_free_dquot ( dquot );
821
- atomic_dec ( & dquot -> dq_count );
822
- continue ;
823
- }
830
+ WARN_ON_ONCE ( atomic_read ( & dquot -> dq_count ));
831
+ /*
832
+ * Note that DQ_RELEASING_B protects us from racing with
833
+ * invalidate_dquots() calls so we are safe to work with the
834
+ * dquot even after we drop dq_list_lock.
835
+ */
824
836
if (dquot_dirty (dquot )) {
825
837
spin_unlock (& dq_list_lock );
826
838
/* Commit dquot before releasing */
@@ -834,7 +846,6 @@ static void quota_release_workfn(struct work_struct *work)
834
846
}
835
847
/* Dquot is inactive and clean, now move it to free list */
836
848
remove_free_dquot (dquot );
837
- atomic_dec (& dquot -> dq_count );
838
849
put_dquot_last (dquot );
839
850
}
840
851
spin_unlock (& dq_list_lock );
@@ -875,6 +886,7 @@ void dqput(struct dquot *dquot)
875
886
BUG_ON (!list_empty (& dquot -> dq_free ));
876
887
#endif
877
888
put_releasing_dquots (dquot );
889
+ atomic_dec (& dquot -> dq_count );
878
890
spin_unlock (& dq_list_lock );
879
891
queue_delayed_work (system_unbound_wq , & quota_release_work , 1 );
880
892
}
@@ -963,7 +975,7 @@ struct dquot *dqget(struct super_block *sb, struct kqid qid)
963
975
dqstats_inc (DQST_LOOKUPS );
964
976
}
965
977
/* Wait for dq_lock - after this we know that either dquot_release() is
966
- * already finished or it will be canceled due to dq_count > 1 test */
978
+ * already finished or it will be canceled due to dq_count > 0 test */
967
979
wait_on_dquot (dquot );
968
980
/* Read the dquot / allocate space in quota file */
969
981
if (!dquot_active (dquot )) {
0 commit comments