NFS: Clean up nfs_scan_dirty()
[powerpc.git] / fs / nfs / write.c
index 883dd4a..dbc89fa 100644 (file)
@@ -79,8 +79,7 @@ static struct nfs_page * nfs_update_request(struct nfs_open_context*,
                                            unsigned int, unsigned int);
 static int nfs_wait_on_write_congestion(struct address_space *, int);
 static int nfs_wait_on_requests(struct inode *, unsigned long, unsigned int);
-static int nfs_flush_inode(struct inode *inode, unsigned long idx_start,
-                          unsigned int npages, int how);
+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;
 static const struct rpc_call_ops nfs_commit_ops;
@@ -102,13 +101,19 @@ struct nfs_write_data *nfs_commit_alloc(void)
        return p;
 }
 
-void nfs_commit_free(struct nfs_write_data *p)
+void nfs_commit_rcu_free(struct rcu_head *head)
 {
+       struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu);
        if (p && (p->pagevec != &p->page_array[0]))
                kfree(p->pagevec);
        mempool_free(p, nfs_commit_mempool);
 }
 
+void nfs_commit_free(struct nfs_write_data *wdata)
+{
+       call_rcu_bh(&wdata->task.u.tk_rcu, nfs_commit_rcu_free);
+}
+
 struct nfs_write_data *nfs_writedata_alloc(size_t len)
 {
        unsigned int pagecount = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -131,13 +136,19 @@ struct nfs_write_data *nfs_writedata_alloc(size_t len)
        return p;
 }
 
-static void nfs_writedata_free(struct nfs_write_data *p)
+static void nfs_writedata_rcu_free(struct rcu_head *head)
 {
+       struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu);
        if (p && (p->pagevec != &p->page_array[0]))
                kfree(p->pagevec);
        mempool_free(p, nfs_wdata_mempool);
 }
 
+static void nfs_writedata_free(struct nfs_write_data *wdata)
+{
+       call_rcu_bh(&wdata->task.u.tk_rcu, nfs_writedata_rcu_free);
+}
+
 void nfs_writedata_release(void *wdata)
 {
        nfs_writedata_free(wdata);
@@ -258,7 +269,7 @@ static int nfs_writepage_sync(struct nfs_open_context *ctx, struct inode *inode,
 io_error:
        nfs_end_data_update(inode);
        end_page_writeback(page);
-       nfs_writedata_free(wdata);
+       nfs_writedata_release(wdata);
        return written ? written : result;
 }
 
@@ -340,7 +351,7 @@ do_it:
        if (!IS_SYNC(inode) && inode_referenced) {
                err = nfs_writepage_async(ctx, inode, page, 0, offset);
                if (!wbc->for_writepages)
-                       nfs_flush_inode(inode, 0, 0, wb_priority(wbc));
+                       nfs_flush_mapping(page->mapping, wbc, wb_priority(wbc));
        } else {
                err = nfs_writepage_sync(ctx, inode, page, 0,
                                                offset, priority);
@@ -379,21 +390,18 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
                        return 0;
                nfs_wait_on_write_congestion(mapping, 0);
        }
-       err = nfs_flush_inode(inode, 0, 0, wb_priority(wbc));
+       err = nfs_flush_mapping(mapping, wbc, wb_priority(wbc));
        if (err < 0)
                goto out;
        nfs_add_stats(inode, NFSIOS_WRITEPAGES, err);
-       wbc->nr_to_write -= 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) {
-               wbc->nr_to_write -= err;
+       if (err > 0)
                err = 0;
-       }
 out:
        clear_bit(BDI_write_congested, &bdi->state);
        wake_up_all(&nfs_write_congestion);
@@ -597,31 +605,6 @@ static void nfs_cancel_commit_list(struct list_head *head)
        }
 }
 
-/*
- * nfs_scan_dirty - Scan an inode for dirty requests
- * @inode: NFS inode to scan
- * @dst: destination list
- * @idx_start: lower bound of page->index to scan.
- * @npages: idx_start + npages sets the upper bound to scan.
- *
- * Moves requests from the inode's dirty page list.
- * The requests are *not* checked to ensure that they form a contiguous set.
- */
-static int
-nfs_scan_dirty(struct inode *inode, struct list_head *dst, unsigned long idx_start, unsigned int npages)
-{
-       struct nfs_inode *nfsi = NFS_I(inode);
-       int res = 0;
-
-       if (nfsi->ndirty != 0) {
-               res = nfs_scan_lock_dirty(nfsi, dst, idx_start, npages);
-               nfsi->ndirty -= res;
-               if ((nfsi->ndirty == 0) != list_empty(&nfsi->dirty))
-                       printk(KERN_ERR "NFS: desynchronized value of nfs_i.ndirty.\n");
-       }
-       return res;
-}
-
 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
 /*
  * nfs_scan_commit - Scan an inode for commit requests
@@ -979,9 +962,7 @@ static void nfs_execute_write(struct nfs_write_data *data)
        sigset_t oldset;
 
        rpc_clnt_sigmask(clnt, &oldset);
-       lock_kernel();
        rpc_execute(&data->task);
-       unlock_kernel();
        rpc_clnt_sigunmask(clnt, &oldset);
 }
 
@@ -1043,7 +1024,7 @@ out_bad:
        while (!list_empty(&list)) {
                data = list_entry(list.next, struct nfs_write_data, pages);
                list_del(&data->pages);
-               nfs_writedata_free(data);
+               nfs_writedata_release(data);
        }
        nfs_mark_request_dirty(req);
        nfs_clear_page_writeback(req);
@@ -1459,18 +1440,17 @@ static inline int nfs_commit_list(struct inode *inode, struct list_head *head, i
 }
 #endif
 
-static int nfs_flush_inode(struct inode *inode, unsigned long idx_start,
-                          unsigned int npages, int how)
+static long nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how)
 {
-       struct nfs_inode *nfsi = NFS_I(inode);
+       struct nfs_inode *nfsi = NFS_I(mapping->host);
        LIST_HEAD(head);
-       int res;
+       long res;
 
        spin_lock(&nfsi->req_lock);
-       res = nfs_scan_dirty(inode, &head, idx_start, npages);
+       res = nfs_scan_dirty(mapping, wbc, &head);
        spin_unlock(&nfsi->req_lock);
        if (res) {
-               int error = nfs_flush_list(inode, &head, res, how);
+               int error = nfs_flush_list(mapping->host, &head, res, how);
                if (error < 0)
                        return error;
        }
@@ -1496,13 +1476,21 @@ int nfs_commit_inode(struct inode *inode, int how)
 }
 #endif
 
-int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
+long nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
                unsigned int npages, int how)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
+       struct address_space *mapping = inode->i_mapping;
+       struct writeback_control wbc = {
+               .bdi = mapping->backing_dev_info,
+               .sync_mode = WB_SYNC_ALL,
+               .nr_to_write = LONG_MAX,
+               .range_start = ((loff_t)idx_start) << PAGE_CACHE_SHIFT,
+               .range_end = ((loff_t)(idx_start + npages - 1)) << PAGE_CACHE_SHIFT,
+       };
        LIST_HEAD(head);
        int nocommit = how & FLUSH_NOCOMMIT;
-       int pages, ret;
+       long pages, ret;
 
        how &= ~FLUSH_NOCOMMIT;
        spin_lock(&nfsi->req_lock);
@@ -1510,12 +1498,13 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
                ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
                if (ret != 0)
                        continue;
-               pages = nfs_scan_dirty(inode, &head, idx_start, npages);
+               pages = nfs_scan_dirty(mapping, &wbc, &head);
                if (pages != 0) {
                        spin_unlock(&nfsi->req_lock);
-                       if (how & FLUSH_INVALIDATE)
+                       if (how & FLUSH_INVALIDATE) {
                                nfs_cancel_dirty_list(&head);
-                       else
+                               ret = pages;
+                       } else
                                ret = nfs_flush_list(inode, &head, pages, how);
                        spin_lock(&nfsi->req_lock);
                        continue;
@@ -1528,6 +1517,7 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
                if (how & FLUSH_INVALIDATE) {
                        spin_unlock(&nfsi->req_lock);
                        nfs_cancel_commit_list(&head);
+                       ret = pages;
                        spin_lock(&nfsi->req_lock);
                        continue;
                }