bsdacct: fix uid/gid misreporting
[safe/jmp/linux-2.6] / fs / nfs / write.c
index ce72882..d171696 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/file.h>
 #include <linux/writeback.h>
 #include <linux/swap.h>
+#include <linux/migrate.h>
 
 #include <linux/sunrpc/clnt.h>
 #include <linux/nfs_fs.h>
@@ -26,6 +27,7 @@
 #include "internal.h"
 #include "iostat.h"
 #include "nfs4_fs.h"
+#include "fscache.h"
 
 #define NFSDBG_FACILITY                NFSDBG_PAGECACHE
 
@@ -87,17 +89,15 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
        return p;
 }
 
-static void nfs_writedata_free(struct nfs_write_data *p)
+void nfs_writedata_free(struct nfs_write_data *p)
 {
        if (p && (p->pagevec != &p->page_array[0]))
                kfree(p->pagevec);
        mempool_free(p, nfs_wdata_mempool);
 }
 
-void nfs_writedata_release(void *data)
+static void nfs_writedata_release(struct nfs_write_data *wdata)
 {
-       struct nfs_write_data *wdata = data;
-
        put_nfs_open_context(wdata->args.context);
        nfs_writedata_free(wdata);
 }
@@ -178,7 +178,7 @@ static int wb_priority(struct writeback_control *wbc)
 {
        if (wbc->for_reclaim)
                return FLUSH_HIGHPRI | FLUSH_STABLE;
-       if (wbc->for_kupdate)
+       if (wbc->for_kupdate || wbc->for_background)
                return FLUSH_LOWPRI;
        return 0;
 }
@@ -202,8 +202,10 @@ static int nfs_set_page_writeback(struct page *page)
                struct nfs_server *nfss = NFS_SERVER(inode);
 
                if (atomic_long_inc_return(&nfss->writeback) >
-                               NFS_CONGESTION_ON_THRESH)
-                       set_bdi_congested(&nfss->backing_dev_info, WRITE);
+                               NFS_CONGESTION_ON_THRESH) {
+                       set_bdi_congested(&nfss->backing_dev_info,
+                                               BLK_RW_ASYNC);
+               }
        }
        return ret;
 }
@@ -215,27 +217,20 @@ static void nfs_end_page_writeback(struct page *page)
 
        end_page_writeback(page);
        if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
-               clear_bdi_congested(&nfss->backing_dev_info, WRITE);
+               clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC);
 }
 
-/*
- * Find an associated nfs write request, and prepare to flush it out
- * May return an error if the user signalled nfs_wait_on_request().
- */
-static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
-                               struct page *page)
+static struct nfs_page *nfs_find_and_lock_request(struct page *page)
 {
        struct inode *inode = page->mapping->host;
        struct nfs_page *req;
        int ret;
 
        spin_lock(&inode->i_lock);
-       for(;;) {
+       for (;;) {
                req = nfs_page_find_request_locked(page);
-               if (req == NULL) {
-                       spin_unlock(&inode->i_lock);
-                       return 0;
-               }
+               if (req == NULL)
+                       break;
                if (nfs_set_page_tag_locked(req))
                        break;
                /* Note: If we hold the page lock, as is the case in nfs_writepage,
@@ -247,23 +242,40 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
                ret = nfs_wait_on_request(req);
                nfs_release_request(req);
                if (ret != 0)
-                       return ret;
+                       return ERR_PTR(ret);
                spin_lock(&inode->i_lock);
        }
-       if (test_bit(PG_CLEAN, &req->wb_flags)) {
-               spin_unlock(&inode->i_lock);
-               BUG();
-       }
-       if (nfs_set_page_writeback(page) != 0) {
-               spin_unlock(&inode->i_lock);
-               BUG();
-       }
        spin_unlock(&inode->i_lock);
+       return req;
+}
+
+/*
+ * Find an associated nfs write request, and prepare to flush it out
+ * May return an error if the user signalled nfs_wait_on_request().
+ */
+static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
+                               struct page *page)
+{
+       struct nfs_page *req;
+       int ret = 0;
+
+       req = nfs_find_and_lock_request(page);
+       if (!req)
+               goto out;
+       ret = PTR_ERR(req);
+       if (IS_ERR(req))
+               goto out;
+
+       ret = nfs_set_page_writeback(page);
+       BUG_ON(ret != 0);
+       BUG_ON(test_bit(PG_CLEAN, &req->wb_flags));
+
        if (!nfs_pageio_add_request(pgio, req)) {
                nfs_redirty_request(req);
-               return pgio->pg_error;
+               ret = pgio->pg_error;
        }
-       return 0;
+out:
+       return ret;
 }
 
 static int nfs_do_writepage(struct page *page, struct writeback_control *wbc, struct nfs_pageio_descriptor *pgio)
@@ -762,7 +774,7 @@ int nfs_updatepage(struct file *file, struct page *page,
         */
        if (nfs_write_pageuptodate(page, inode) &&
                        inode->i_flock == NULL &&
-                       !(file->f_flags & O_SYNC)) {
+                       !(file->f_flags & O_DSYNC)) {
                count = max(count + offset, nfs_page_length(page));
                offset = 0;
        }
@@ -1204,7 +1216,7 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
                                 */
                                argp->stable = NFS_FILE_SYNC;
                        }
-                       nfs4_restart_rpc(task, server->nfs_client);
+                       nfs_restart_rpc(task, server->nfs_client);
                        return -EAGAIN;
                }
                if (time_before(complain, jiffies)) {
@@ -1216,7 +1228,6 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
                /* Can't do anything about it except throw an error. */
                task->tk_status = -EIO;
        }
-       nfs4_sequence_free_slot(server->nfs_client, &data->res.seq_res);
        return 0;
 }
 
@@ -1478,7 +1489,6 @@ static int nfs_write_mapping(struct address_space *mapping, int how)
                .nr_to_write = LONG_MAX,
                .range_start = 0,
                .range_end = LLONG_MAX,
-               .for_writepages = 1,
        };
 
        return __nfs_write_mapping(mapping, &wbc, how);
@@ -1580,6 +1590,42 @@ int nfs_wb_page(struct inode *inode, struct page* page)
        return nfs_wb_page_priority(inode, page, FLUSH_STABLE);
 }
 
+#ifdef CONFIG_MIGRATION
+int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
+               struct page *page)
+{
+       struct nfs_page *req;
+       int ret;
+
+       if (PageFsCache(page))
+               nfs_fscache_release_page(page, GFP_KERNEL);
+
+       req = nfs_find_and_lock_request(page);
+       ret = PTR_ERR(req);
+       if (IS_ERR(req))
+               goto out;
+
+       ret = migrate_page(mapping, newpage, page);
+       if (!req)
+               goto out;
+       if (ret)
+               goto out_unlock;
+       page_cache_get(newpage);
+       spin_lock(&mapping->host->i_lock);
+       req->wb_page = newpage;
+       SetPagePrivate(newpage);
+       set_page_private(newpage, (unsigned long)req);
+       ClearPagePrivate(page);
+       set_page_private(page, 0);
+       spin_unlock(&mapping->host->i_lock);
+       page_cache_release(page);
+out_unlock:
+       nfs_clear_page_tag_locked(req);
+out:
+       return ret;
+}
+#endif
+
 int __init nfs_init_writepagecache(void)
 {
        nfs_wdata_cachep = kmem_cache_create("nfs_write_data",