Merge branch 'for-3.18/core' of git://git.kernel.dk/linux-block
[firefly-linux-kernel-4.4.55.git] / fs / nfs / file.c
index 3b42cb86218e4c2caeb60d19d87c75000e71fd0a..2ab6f00dba5bd63cc8e958165c1a5bdf9443840f 100644 (file)
@@ -36,6 +36,7 @@
 #include "internal.h"
 #include "iostat.h"
 #include "fscache.h"
+#include "pnfs.h"
 
 #include "nfstrace.h"
 
@@ -327,6 +328,12 @@ static int nfs_want_read_modify_write(struct file *file, struct page *page,
        unsigned int offset = pos & (PAGE_CACHE_SIZE - 1);
        unsigned int end = offset + len;
 
+       if (pnfs_ld_read_whole_page(file->f_mapping->host)) {
+               if (!PageUptodate(page))
+                       return 1;
+               return 0;
+       }
+
        if ((file->f_mode & FMODE_READ) &&      /* open for read? */
            !PageUptodate(page) &&              /* Uptodate? */
            !PagePrivate(page) &&               /* i/o request already? */
@@ -468,17 +475,26 @@ static int nfs_release_page(struct page *page, gfp_t gfp)
 
        dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
 
-       /* Only do I/O if gfp is a superset of GFP_KERNEL, and we're not
-        * doing this memory reclaim for a fs-related allocation.
+       /* Always try to initiate a 'commit' if relevant, but only
+        * wait for it if __GFP_WAIT is set.  Even then, only wait 1
+        * second and only if the 'bdi' is not congested.
+        * Waiting indefinitely can cause deadlocks when the NFS
+        * server is on this machine, when a new TCP connection is
+        * needed and in other rare cases.  There is no particular
+        * need to wait extensively here.  A short wait has the
+        * benefit that someone else can worry about the freezer.
         */
-       if (mapping && (gfp & GFP_KERNEL) == GFP_KERNEL &&
-           !(current->flags & PF_FSTRANS)) {
-               int how = FLUSH_SYNC;
-
-               /* Don't let kswapd deadlock waiting for OOM RPC calls */
-               if (current_is_kswapd())
-                       how = 0;
-               nfs_commit_inode(mapping->host, how);
+       if (mapping) {
+               struct nfs_server *nfss = NFS_SERVER(mapping->host);
+               nfs_commit_inode(mapping->host, 0);
+               if ((gfp & __GFP_WAIT) &&
+                   !bdi_write_congested(&nfss->backing_dev_info)) {
+                       wait_on_page_bit_killable_timeout(page, PG_private,
+                                                         HZ);
+                       if (PagePrivate(page))
+                               set_bdi_congested(&nfss->backing_dev_info,
+                                                 BLK_RW_ASYNC);
+               }
        }
        /* If PagePrivate() is set, then the page is not freeable */
        if (PagePrivate(page))
@@ -539,13 +555,25 @@ static int nfs_launder_page(struct page *page)
 static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
                                                sector_t *span)
 {
+       int ret;
+       struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host);
+
        *span = sis->pages;
-       return xs_swapper(NFS_CLIENT(file->f_mapping->host)->cl_xprt, 1);
+
+       rcu_read_lock();
+       ret = xs_swapper(rcu_dereference(clnt->cl_xprt), 1);
+       rcu_read_unlock();
+
+       return ret;
 }
 
 static void nfs_swap_deactivate(struct file *file)
 {
-       xs_swapper(NFS_CLIENT(file->f_mapping->host)->cl_xprt, 0);
+       struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host);
+
+       rcu_read_lock();
+       xs_swapper(rcu_dereference(clnt->cl_xprt), 0);
+       rcu_read_unlock();
 }
 #endif
 
@@ -891,17 +919,6 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
 }
 EXPORT_SYMBOL_GPL(nfs_flock);
 
-/*
- * There is no protocol support for leases, so we have no way to implement
- * them correctly in the face of opens by other clients.
- */
-int nfs_setlease(struct file *file, long arg, struct file_lock **fl)
-{
-       dprintk("NFS: setlease(%pD2, arg=%ld)\n", file, arg);
-       return -EINVAL;
-}
-EXPORT_SYMBOL_GPL(nfs_setlease);
-
 const struct file_operations nfs_file_operations = {
        .llseek         = nfs_file_llseek,
        .read           = new_sync_read,
@@ -918,6 +935,6 @@ const struct file_operations nfs_file_operations = {
        .splice_read    = nfs_file_splice_read,
        .splice_write   = iter_file_splice_write,
        .check_flags    = nfs_check_flags,
-       .setlease       = nfs_setlease,
+       .setlease       = simple_nosetlease,
 };
 EXPORT_SYMBOL_GPL(nfs_file_operations);