2828#define NFSD_FILE_HASH_SIZE (1 << NFSD_FILE_HASH_BITS)
2929#define NFSD_LAUNDRETTE_DELAY (2 * HZ)
3030
31- #define NFSD_FILE_SHUTDOWN (1 )
31+ #define NFSD_FILE_CACHE_UP (0 )
3232
3333/* We only care about NFSD_MAY_READ/WRITE for this cache */
3434#define NFSD_FILE_MAY_MASK (NFSD_MAY_READ|NFSD_MAY_WRITE)
@@ -59,17 +59,16 @@ static struct kmem_cache *nfsd_file_slab;
5959static struct kmem_cache * nfsd_file_mark_slab ;
6060static struct nfsd_fcache_bucket * nfsd_file_hashtbl ;
6161static struct list_lru nfsd_file_lru ;
62- static long nfsd_file_lru_flags ;
62+ static unsigned long nfsd_file_flags ;
6363static struct fsnotify_group * nfsd_file_fsnotify_group ;
6464static atomic_long_t nfsd_filecache_count ;
6565static struct delayed_work nfsd_filecache_laundrette ;
6666
6767static void
6868nfsd_file_schedule_laundrette (void )
6969{
70- long count = atomic_long_read (& nfsd_filecache_count );
71-
72- if (count == 0 || test_bit (NFSD_FILE_SHUTDOWN , & nfsd_file_lru_flags ))
70+ if ((atomic_long_read (& nfsd_filecache_count ) == 0 ) ||
71+ test_bit (NFSD_FILE_CACHE_UP , & nfsd_file_flags ) == 0 )
7372 return ;
7473
7574 queue_delayed_work (system_wq , & nfsd_filecache_laundrette ,
@@ -698,9 +697,8 @@ nfsd_file_cache_init(void)
698697 int ret = - ENOMEM ;
699698 unsigned int i ;
700699
701- clear_bit (NFSD_FILE_SHUTDOWN , & nfsd_file_lru_flags );
702-
703- if (nfsd_file_hashtbl )
700+ lockdep_assert_held (& nfsd_mutex );
701+ if (test_and_set_bit (NFSD_FILE_CACHE_UP , & nfsd_file_flags ) == 1 )
704702 return 0 ;
705703
706704 nfsd_filecache_wq = alloc_workqueue ("nfsd_filecache" , 0 , 0 );
@@ -786,18 +784,15 @@ nfsd_file_cache_init(void)
786784/*
787785 * Note this can deadlock with nfsd_file_lru_cb.
788786 */
789- void
790- nfsd_file_cache_purge (struct net * net )
787+ static void
788+ __nfsd_file_cache_purge (struct net * net )
791789{
792790 unsigned int i ;
793791 struct nfsd_file * nf ;
794792 struct hlist_node * next ;
795793 LIST_HEAD (dispose );
796794 bool del ;
797795
798- if (!nfsd_file_hashtbl )
799- return ;
800-
801796 for (i = 0 ; i < NFSD_FILE_HASH_SIZE ; i ++ ) {
802797 struct nfsd_fcache_bucket * nfb = & nfsd_file_hashtbl [i ];
803798
@@ -858,6 +853,19 @@ nfsd_file_cache_start_net(struct net *net)
858853 return nn -> fcache_disposal ? 0 : - ENOMEM ;
859854}
860855
856+ /**
857+ * nfsd_file_cache_purge - Remove all cache items associated with @net
858+ * @net: target net namespace
859+ *
860+ */
861+ void
862+ nfsd_file_cache_purge (struct net * net )
863+ {
864+ lockdep_assert_held (& nfsd_mutex );
865+ if (test_bit (NFSD_FILE_CACHE_UP , & nfsd_file_flags ) == 1 )
866+ __nfsd_file_cache_purge (net );
867+ }
868+
861869void
862870nfsd_file_cache_shutdown_net (struct net * net )
863871{
@@ -870,7 +878,9 @@ nfsd_file_cache_shutdown(void)
870878{
871879 int i ;
872880
873- set_bit (NFSD_FILE_SHUTDOWN , & nfsd_file_lru_flags );
881+ lockdep_assert_held (& nfsd_mutex );
882+ if (test_and_clear_bit (NFSD_FILE_CACHE_UP , & nfsd_file_flags ) == 0 )
883+ return ;
874884
875885 lease_unregister_notifier (& nfsd_file_lease_notifier );
876886 unregister_shrinker (& nfsd_file_shrinker );
@@ -879,7 +889,7 @@ nfsd_file_cache_shutdown(void)
879889 * calling nfsd_file_cache_purge
880890 */
881891 cancel_delayed_work_sync (& nfsd_filecache_laundrette );
882- nfsd_file_cache_purge (NULL );
892+ __nfsd_file_cache_purge (NULL );
883893 list_lru_destroy (& nfsd_file_lru );
884894 rcu_barrier ();
885895 fsnotify_put_group (nfsd_file_fsnotify_group );
@@ -1143,7 +1153,7 @@ static int nfsd_file_cache_stats_show(struct seq_file *m, void *v)
11431153 * don't end up racing with server shutdown
11441154 */
11451155 mutex_lock (& nfsd_mutex );
1146- if (nfsd_file_hashtbl ) {
1156+ if (test_bit ( NFSD_FILE_CACHE_UP , & nfsd_file_flags ) == 1 ) {
11471157 for (i = 0 ; i < NFSD_FILE_HASH_SIZE ; i ++ ) {
11481158 count += nfsd_file_hashtbl [i ].nfb_count ;
11491159 longest = max (longest , nfsd_file_hashtbl [i ].nfb_count );
0 commit comments