]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nfsd: nfsd_file cache entries should be per net namespace
authorTrond Myklebust <trondmy@gmail.com>
Mon, 2 Sep 2019 17:02:55 +0000 (13:02 -0400)
committerJ. Bruce Fields <bfields@redhat.com>
Tue, 10 Sep 2019 13:23:41 +0000 (09:23 -0400)
Ensure that we can safely clear out the file cache entries when the
nfs server is shut down on a container. Otherwise, the file cache
may end up pinning the mounts.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/export.c
fs/nfsd/filecache.c
fs/nfsd/filecache.h
fs/nfsd/nfssvc.c

index 052fac64b57819c38d50d6b7001ed206af094856..15422c951fd1603d1fbd56c0dcf5c0dba8dcfb91 100644 (file)
@@ -240,7 +240,7 @@ static void expkey_flush(void)
         * destroyed while we're in the middle of flushing.
         */
        mutex_lock(&nfsd_mutex);
-       nfsd_file_cache_purge();
+       nfsd_file_cache_purge(current->nsproxy->net_ns);
        mutex_unlock(&nfsd_mutex);
 }
 
index 2e1a972231e5f6310b4e54247a2688855b88bb17..da9e790a055ee0f2cefd86e0952cb3c0bd0be6ba 100644 (file)
@@ -16,6 +16,7 @@
 #include "vfs.h"
 #include "nfsd.h"
 #include "nfsfh.h"
+#include "netns.h"
 #include "filecache.h"
 #include "trace.h"
 
@@ -167,7 +168,8 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)
 }
 
 static struct nfsd_file *
-nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval)
+nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval,
+               struct net *net)
 {
        struct nfsd_file *nf;
 
@@ -177,6 +179,7 @@ nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval)
                INIT_LIST_HEAD(&nf->nf_lru);
                nf->nf_file = NULL;
                nf->nf_cred = get_current_cred();
+               nf->nf_net = net;
                nf->nf_flags = 0;
                nf->nf_inode = inode;
                nf->nf_hashval = hashval;
@@ -607,10 +610,11 @@ out_err:
  * Note this can deadlock with nfsd_file_lru_cb.
  */
 void
-nfsd_file_cache_purge(void)
+nfsd_file_cache_purge(struct net *net)
 {
        unsigned int            i;
        struct nfsd_file        *nf;
+       struct hlist_node       *next;
        LIST_HEAD(dispose);
        bool del;
 
@@ -618,10 +622,12 @@ nfsd_file_cache_purge(void)
                return;
 
        for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
-               spin_lock(&nfsd_file_hashtbl[i].nfb_lock);
-               while(!hlist_empty(&nfsd_file_hashtbl[i].nfb_head)) {
-                       nf = hlist_entry(nfsd_file_hashtbl[i].nfb_head.first,
-                                        struct nfsd_file, nf_node);
+               struct nfsd_fcache_bucket *nfb = &nfsd_file_hashtbl[i];
+
+               spin_lock(&nfb->nfb_lock);
+               hlist_for_each_entry_safe(nf, next, &nfb->nfb_head, nf_node) {
+                       if (net && nf->nf_net != net)
+                               continue;
                        del = nfsd_file_unhash_and_release_locked(nf, &dispose);
 
                        /*
@@ -630,7 +636,7 @@ nfsd_file_cache_purge(void)
                         */
                        WARN_ON_ONCE(!del);
                }
-               spin_unlock(&nfsd_file_hashtbl[i].nfb_lock);
+               spin_unlock(&nfb->nfb_lock);
                nfsd_file_dispose_list(&dispose);
        }
 }
@@ -649,7 +655,7 @@ nfsd_file_cache_shutdown(void)
         * calling nfsd_file_cache_purge
         */
        cancel_delayed_work_sync(&nfsd_filecache_laundrette);
-       nfsd_file_cache_purge();
+       nfsd_file_cache_purge(NULL);
        list_lru_destroy(&nfsd_file_lru);
        rcu_barrier();
        fsnotify_put_group(nfsd_file_fsnotify_group);
@@ -685,7 +691,7 @@ nfsd_match_cred(const struct cred *c1, const struct cred *c2)
 
 static struct nfsd_file *
 nfsd_file_find_locked(struct inode *inode, unsigned int may_flags,
-                       unsigned int hashval)
+                       unsigned int hashval, struct net *net)
 {
        struct nfsd_file *nf;
        unsigned char need = may_flags & NFSD_FILE_MAY_MASK;
@@ -696,6 +702,8 @@ nfsd_file_find_locked(struct inode *inode, unsigned int may_flags,
                        continue;
                if (nf->nf_inode != inode)
                        continue;
+               if (nf->nf_net != net)
+                       continue;
                if (!nfsd_match_cred(nf->nf_cred, current_cred()))
                        continue;
                if (nfsd_file_get(nf) != NULL)
@@ -738,6 +746,7 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
                  unsigned int may_flags, struct nfsd_file **pnf)
 {
        __be32  status;
+       struct net *net = SVC_NET(rqstp);
        struct nfsd_file *nf, *new;
        struct inode *inode;
        unsigned int hashval;
@@ -752,12 +761,12 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
        hashval = (unsigned int)hash_long(inode->i_ino, NFSD_FILE_HASH_BITS);
 retry:
        rcu_read_lock();
-       nf = nfsd_file_find_locked(inode, may_flags, hashval);
+       nf = nfsd_file_find_locked(inode, may_flags, hashval, net);
        rcu_read_unlock();
        if (nf)
                goto wait_for_construction;
 
-       new = nfsd_file_alloc(inode, may_flags, hashval);
+       new = nfsd_file_alloc(inode, may_flags, hashval, net);
        if (!new) {
                trace_nfsd_file_acquire(rqstp, hashval, inode, may_flags,
                                        NULL, nfserr_jukebox);
@@ -765,7 +774,7 @@ retry:
        }
 
        spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
-       nf = nfsd_file_find_locked(inode, may_flags, hashval);
+       nf = nfsd_file_find_locked(inode, may_flags, hashval, net);
        if (nf == NULL)
                goto open_file;
        spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
index 0c0c67166b87c7e60a3a17e0fcaeb0b916d2daec..851d9abf54c25a35638a7e63ba0350de9ea3664e 100644 (file)
@@ -34,6 +34,7 @@ struct nfsd_file {
        struct rcu_head         nf_rcu;
        struct file             *nf_file;
        const struct cred       *nf_cred;
+       struct net              *nf_net;
 #define NFSD_FILE_HASHED       (0)
 #define NFSD_FILE_PENDING      (1)
 #define NFSD_FILE_BREAK_READ   (2)
@@ -48,7 +49,7 @@ struct nfsd_file {
 };
 
 int nfsd_file_cache_init(void);
-void nfsd_file_cache_purge(void);
+void nfsd_file_cache_purge(struct net *);
 void nfsd_file_cache_shutdown(void);
 void nfsd_file_put(struct nfsd_file *nf);
 struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
index d02712ca2685215dfc05dc909e6553bdd41e2fb6..b944553c69276aabe9c8b17d58a86b5266a7446e 100644 (file)
@@ -387,6 +387,7 @@ static void nfsd_shutdown_net(struct net *net)
 {
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
+       nfsd_file_cache_purge(net);
        nfs4_state_shutdown_net(net);
        if (nn->lockd_up) {
                lockd_down(net);