Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[powerpc.git] / fs / nfs / write.c
index 594eb16..febdade 100644 (file)
@@ -1,47 +1,7 @@
 /*
  * linux/fs/nfs/write.c
  *
- * Writing file data over NFS.
- *
- * We do it like this: When a (user) process wishes to write data to an
- * NFS file, a write request is allocated that contains the RPC task data
- * plus some info on the page to be written, and added to the inode's
- * write chain. If the process writes past the end of the page, an async
- * RPC call to write the page is scheduled immediately; otherwise, the call
- * is delayed for a few seconds.
- *
- * Just like readahead, no async I/O is performed if wsize < PAGE_SIZE.
- *
- * Write requests are kept on the inode's writeback list. Each entry in
- * that list references the page (portion) to be written. When the
- * cache timeout has expired, the RPC task is woken up, and tries to
- * lock the page. As soon as it manages to do so, the request is moved
- * from the writeback list to the writelock list.
- *
- * Note: we must make sure never to confuse the inode passed in the
- * write_page request with the one in page->inode. As far as I understand
- * it, these are different when doing a swap-out.
- *
- * To understand everything that goes on here and in the NFS read code,
- * one should be aware that a page is locked in exactly one of the following
- * cases:
- *
- *  -  A write request is in progress.
- *  -  A user process is in generic_file_write/nfs_update_page
- *  -  A user process is in generic_file_read
- *
- * Also note that because of the way pages are invalidated in
- * nfs_revalidate_inode, the following assertions hold:
- *
- *  -  If a page is dirty, there will be no read requests (a page will
- *     not be re-read unless invalidated by nfs_revalidate_inode).
- *  -  If the page is not uptodate, there will be no pending write
- *     requests, and no process will be in nfs_update_page.
- *
- * FIXME: Interaction with the vmscan routines is not optimal yet.
- * Either vmscan must be made nfs-savvy, or we need a different page
- * reclaim concept that supports something like FS-independent
- * buffer_heads with a b_ops-> field.
+ * Write file data over NFS.
  *
  * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de>
  */
@@ -79,7 +39,6 @@ static struct nfs_page * nfs_update_request(struct nfs_open_context*,
                                            unsigned int, unsigned int);
 static void nfs_mark_request_dirty(struct nfs_page *req);
 static int nfs_wait_on_write_congestion(struct address_space *, int);
-static int nfs_wait_on_requests(struct inode *, unsigned long, unsigned int);
 static long nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how);
 static const struct rpc_call_ops nfs_write_partial_ops;
 static const struct rpc_call_ops nfs_write_full_ops;
@@ -194,6 +153,13 @@ static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int c
        i_size_write(inode, end);
 }
 
+/* A writeback failed: mark the page as bad, and invalidate the page cache */
+static void nfs_set_pageerror(struct page *page)
+{
+       SetPageError(page);
+       nfs_zap_mapping(page->mapping->host, page->mapping);
+}
+
 /* We can set the PG_uptodate flag if we see that a write request
  * covers the full page.
  */
@@ -323,7 +289,7 @@ static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc
                err = 0;
 out:
        if (!wbc->for_writepages)
-               nfs_flush_mapping(page->mapping, wbc, wb_priority(wbc));
+               nfs_flush_mapping(page->mapping, wbc, FLUSH_STABLE|wb_priority(wbc));
        return err;
 }
 
@@ -360,14 +326,7 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
        if (err < 0)
                goto out;
        nfs_add_stats(inode, NFSIOS_WRITEPAGES, err);
-       if (!wbc->nonblocking && wbc->sync_mode == WB_SYNC_ALL) {
-               err = nfs_wait_on_requests(inode, 0, 0);
-               if (err < 0)
-                       goto out;
-       }
-       err = nfs_commit_inode(inode, wb_priority(wbc));
-       if (err > 0)
-               err = 0;
+       err = 0;
 out:
        clear_bit(BDI_write_congested, &bdi->state);
        wake_up_all(&nfs_write_congestion);
@@ -516,17 +475,6 @@ static int nfs_wait_on_requests_locked(struct inode *inode, unsigned long idx_st
        return res;
 }
 
-static int nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, unsigned int npages)
-{
-       struct nfs_inode *nfsi = NFS_I(inode);
-       int ret;
-
-       spin_lock(&nfsi->req_lock);
-       ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
-       spin_unlock(&nfsi->req_lock);
-       return ret;
-}
-
 static void nfs_cancel_dirty_list(struct list_head *head)
 {
        struct nfs_page *req;
@@ -754,8 +702,8 @@ int nfs_updatepage(struct file *file, struct page *page,
        nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
 
        dprintk("NFS:      nfs_updatepage(%s/%s %d@%Ld)\n",
-               file->f_dentry->d_parent->d_name.name,
-               file->f_dentry->d_name.name, count,
+               file->f_path.dentry->d_parent->d_name.name,
+               file->f_path.dentry->d_name.name, count,
                (long long)(page_offset(page) +offset));
 
        /* If we're not using byte range locks, and we know the page
@@ -773,7 +721,7 @@ int nfs_updatepage(struct file *file, struct page *page,
         dprintk("NFS:      nfs_updatepage returns %d (isize %Ld)\n",
                        status, (long long)i_size_read(inode));
        if (status < 0)
-               ClearPageUptodate(page);
+               nfs_set_pageerror(page);
        return status;
 }
 
@@ -852,7 +800,8 @@ static void nfs_write_rpcsetup(struct nfs_page *req,
        data->task.tk_priority = flush_task_priority(how);
        data->task.tk_cookie = (unsigned long)inode;
 
-       dprintk("NFS: %4d initiated write call (req %s/%Ld, %u bytes @ offset %Lu)\n",
+       dprintk("NFS: %5u initiated write call "
+               "(req %s/%Ld, %u bytes @ offset %Lu)\n",
                data->task.tk_pid,
                inode->i_sb->s_id,
                (long long)NFS_FILEID(inode),
@@ -1034,8 +983,7 @@ static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
                return;
 
        if (task->tk_status < 0) {
-               ClearPageUptodate(page);
-               SetPageError(page);
+               nfs_set_pageerror(page);
                req->wb_context->error = task->tk_status;
                dprintk(", error = %d\n", task->tk_status);
        } else {
@@ -1092,8 +1040,7 @@ static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
                        (long long)req_offset(req));
 
                if (task->tk_status < 0) {
-                       ClearPageUptodate(page);
-                       SetPageError(page);
+                       nfs_set_pageerror(page);
                        req->wb_context->error = task->tk_status;
                        end_page_writeback(page);
                        nfs_inode_remove_request(req);
@@ -1134,7 +1081,7 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
        struct nfs_writeres     *resp = &data->res;
        int status;
 
-       dprintk("NFS: %4d nfs_writeback_done (status %d)\n",
+       dprintk("NFS: %5u nfs_writeback_done (status %d)\n",
                task->tk_pid, task->tk_status);
 
        /*
@@ -1250,7 +1197,7 @@ static void nfs_commit_rpcsetup(struct list_head *head,
        data->task.tk_priority = flush_task_priority(how);
        data->task.tk_cookie = (unsigned long)inode;
        
-       dprintk("NFS: %4d initiated commit call\n", data->task.tk_pid);
+       dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
 }
 
 /*
@@ -1291,7 +1238,7 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
        struct nfs_write_data   *data = calldata;
        struct nfs_page         *req;
 
-        dprintk("NFS: %4d nfs_commit_done (status %d)\n",
+        dprintk("NFS: %5u nfs_commit_done (status %d)\n",
                                 task->tk_pid, task->tk_status);
 
        /* Call the NFS version-specific code */
@@ -1516,6 +1463,8 @@ int nfs_wb_page_priority(struct inode *inode, struct page *page, int how)
                if (ret < 0)
                        goto out;
        }
+       if (!PagePrivate(page))
+               return 0;
        ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
        if (ret >= 0)
                return 0;