NFS: Remove the redundant 'dirty' and 'commit' lists from nfs_inode
[linux-2.6-block.git] / fs / nfs / write.c
index 5d44b8bd107093c72ac5d0aa50f23a20025ec609..9ef9ec746bfb9715659e33ffd44c25f6c71a79df 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/backing-dev.h>
 
 #include <asm/uaccess.h>
-#include <linux/smp_lock.h>
 
 #include "delegation.h"
 #include "internal.h"
@@ -59,7 +58,7 @@ struct nfs_write_data *nfs_commit_alloc(void)
        return p;
 }
 
-void nfs_commit_rcu_free(struct rcu_head *head)
+static 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]))
@@ -118,7 +117,7 @@ static struct nfs_page *nfs_page_find_request_locked(struct page *page)
        if (PagePrivate(page)) {
                req = (struct nfs_page *)page_private(page);
                if (req != NULL)
-                       atomic_inc(&req->wb_count);
+                       kref_get(&req->wb_kref);
        }
        return req;
 }
@@ -169,7 +168,7 @@ static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int
        if (count != nfs_page_length(page))
                return;
        if (count != PAGE_CACHE_SIZE)
-               memclear_highpage_flush(page, count, PAGE_CACHE_SIZE - count);
+               zero_user_page(page, count, PAGE_CACHE_SIZE - count, KM_USER0);
        SetPageUptodate(page);
 }
 
@@ -192,8 +191,6 @@ static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
        }
        /* Update file length */
        nfs_grow_file(page, offset, count);
-       /* Set the PG_uptodate flag? */
-       nfs_mark_uptodate(page, offset, count);
        nfs_unlock_request(req);
        return 0;
 }
@@ -225,7 +222,7 @@ static int nfs_set_page_writeback(struct page *page)
                struct inode *inode = page->mapping->host;
                struct nfs_server *nfss = NFS_SERVER(inode);
 
-               if (atomic_inc_return(&nfss->writeback) >
+               if (atomic_long_inc_return(&nfss->writeback) >
                                NFS_CONGESTION_ON_THRESH)
                        set_bdi_congested(&nfss->backing_dev_info, WRITE);
        }
@@ -238,7 +235,7 @@ static void nfs_end_page_writeback(struct page *page)
        struct nfs_server *nfss = NFS_SERVER(inode);
 
        end_page_writeback(page);
-       if (atomic_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH) {
+       if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH) {
                clear_bdi_congested(&nfss->backing_dev_info, WRITE);
                congestion_end(WRITE);
        }
@@ -274,8 +271,6 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
                 *       request as dirty (in which case we don't care).
                 */
                spin_unlock(req_lock);
-               /* Prevent deadlock! */
-               nfs_pageio_complete(pgio);
                ret = nfs_wait_on_request(req);
                nfs_release_request(req);
                if (ret != 0)
@@ -294,7 +289,7 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
                BUG();
        }
        radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
-                       NFS_PAGE_TAG_WRITEBACK);
+                       NFS_PAGE_TAG_LOCKED);
        ret = test_bit(PG_NEED_FLUSH, &req->wb_flags);
        spin_unlock(req_lock);
        nfs_pageio_add_request(pgio, req);
@@ -322,6 +317,8 @@ static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc
                pgio = &mypgio;
        }
 
+       nfs_pageio_cond_complete(pgio, page->index);
+
        err = nfs_page_async_flush(pgio, page);
        if (err <= 0)
                goto out;
@@ -330,6 +327,8 @@ static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc
        if (!offset)
                goto out;
 
+       nfs_pageio_cond_complete(pgio, page->index);
+
        ctx = nfs_find_open_context(inode, NULL, FMODE_WRITE);
        if (ctx == NULL) {
                err = -EBADF;
@@ -399,7 +398,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
        if (PageDirty(req->wb_page))
                set_bit(PG_NEED_FLUSH, &req->wb_flags);
        nfsi->npages++;
-       atomic_inc(&req->wb_count);
+       kref_get(&req->wb_kref);
        return 0;
 }
 
@@ -408,7 +407,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
  */
 static void nfs_inode_remove_request(struct nfs_page *req)
 {
-       struct inode *inode = req->wb_context->dentry->d_inode;
+       struct inode *inode = req->wb_context->path.dentry->d_inode;
        struct nfs_inode *nfsi = NFS_I(inode);
 
        BUG_ON (!NFS_WBACK_BUSY(req));
@@ -456,13 +455,15 @@ nfs_dirty_request(struct nfs_page *req)
 static void
 nfs_mark_request_commit(struct nfs_page *req)
 {
-       struct inode *inode = req->wb_context->dentry->d_inode;
+       struct inode *inode = req->wb_context->path.dentry->d_inode;
        struct nfs_inode *nfsi = NFS_I(inode);
 
        spin_lock(&nfsi->req_lock);
-       nfs_list_add_request(req, &nfsi->commit);
        nfsi->ncommit++;
        set_bit(PG_NEED_COMMIT, &(req)->wb_flags);
+       radix_tree_tag_set(&nfsi->nfs_page_tree,
+                       req->wb_index,
+                       NFS_PAGE_TAG_COMMIT);
        spin_unlock(&nfsi->req_lock);
        inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
        __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
@@ -525,14 +526,14 @@ static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, u
                idx_end = idx_start + npages - 1;
 
        next = idx_start;
-       while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_WRITEBACK)) {
+       while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_LOCKED)) {
                if (req->wb_index > idx_end)
                        break;
 
                next = req->wb_index + 1;
                BUG_ON(!NFS_WBACK_BUSY(req));
 
-               atomic_inc(&req->wb_count);
+               kref_get(&req->wb_kref);
                spin_unlock(&nfsi->req_lock);
                error = nfs_wait_on_request(req);
                nfs_release_request(req);
@@ -576,10 +577,9 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, u
        int res = 0;
 
        if (nfsi->ncommit != 0) {
-               res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages);
+               res = nfs_scan_list(nfsi, dst, idx_start, npages,
+                               NFS_PAGE_TAG_COMMIT);
                nfsi->ncommit -= res;
-               if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit))
-                       printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n");
        }
        return res;
 }
@@ -750,12 +750,17 @@ int nfs_updatepage(struct file *file, struct page *page,
 static void nfs_writepage_release(struct nfs_page *req)
 {
 
-       if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) {
+       if (PageError(req->wb_page)) {
+               nfs_end_page_writeback(req->wb_page);
+               nfs_inode_remove_request(req);
+       } else if (!nfs_reschedule_unstable_write(req)) {
+               /* Set the PG_uptodate flag */
+               nfs_mark_uptodate(req->wb_page, req->wb_pgbase, req->wb_bytes);
                nfs_end_page_writeback(req->wb_page);
                nfs_inode_remove_request(req);
        } else
                nfs_end_page_writeback(req->wb_page);
-       nfs_clear_page_writeback(req);
+       nfs_clear_page_tag_locked(req);
 }
 
 static inline int flush_task_priority(int how)
@@ -785,7 +790,7 @@ static void nfs_write_rpcsetup(struct nfs_page *req,
         * NB: take care not to mess about with data->commit et al. */
 
        data->req = req;
-       data->inode = inode = req->wb_context->dentry->d_inode;
+       data->inode = inode = req->wb_context->path.dentry->d_inode;
        data->cred = req->wb_context->cred;
 
        data->args.fh     = NFS_FH(inode);
@@ -884,7 +889,7 @@ out_bad:
        }
        nfs_redirty_request(req);
        nfs_end_page_writeback(req->wb_page);
-       nfs_clear_page_writeback(req);
+       nfs_clear_page_tag_locked(req);
        return -ENOMEM;
 }
 
@@ -923,11 +928,11 @@ static int nfs_flush_one(struct inode *inode, struct list_head *head, unsigned i
        return 0;
  out_bad:
        while (!list_empty(head)) {
-               struct nfs_page *req = nfs_list_entry(head->next);
+               req = nfs_list_entry(head->next);
                nfs_list_remove_request(req);
                nfs_redirty_request(req);
                nfs_end_page_writeback(req->wb_page);
-               nfs_clear_page_writeback(req);
+               nfs_clear_page_tag_locked(req);
        }
        return -ENOMEM;
 }
@@ -953,8 +958,8 @@ static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
        struct page             *page = req->wb_page;
 
        dprintk("NFS: write (%s/%Ld %d@%Ld)",
-               req->wb_context->dentry->d_inode->i_sb->s_id,
-               (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
+               req->wb_context->path.dentry->d_inode->i_sb->s_id,
+               (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
                req->wb_bytes,
                (long long)req_offset(req));
 
@@ -1019,8 +1024,8 @@ static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
                page = req->wb_page;
 
                dprintk("NFS: write (%s/%Ld %d@%Ld)",
-                       req->wb_context->dentry->d_inode->i_sb->s_id,
-                       (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
+                       req->wb_context->path.dentry->d_inode->i_sb->s_id,
+                       (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
                        req->wb_bytes,
                        (long long)req_offset(req));
 
@@ -1038,12 +1043,14 @@ static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
                        dprintk(" marked for commit\n");
                        goto next;
                }
+               /* Set the PG_uptodate flag? */
+               nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
                dprintk(" OK\n");
 remove_request:
                nfs_end_page_writeback(page);
                nfs_inode_remove_request(req);
        next:
-               nfs_clear_page_writeback(req);
+               nfs_clear_page_tag_locked(req);
        }
 }
 
@@ -1156,7 +1163,7 @@ static void nfs_commit_rpcsetup(struct list_head *head,
 
        list_splice_init(head, &data->pages);
        first = nfs_list_entry(data->pages.next);
-       inode = first->wb_context->dentry->d_inode;
+       inode = first->wb_context->path.dentry->d_inode;
 
        data->inode       = inode;
        data->cred        = first->wb_context->cred;
@@ -1206,7 +1213,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
                nfs_list_remove_request(req);
                nfs_mark_request_commit(req);
                dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
-               nfs_clear_page_writeback(req);
+               nfs_clear_page_tag_locked(req);
        }
        return -ENOMEM;
 }
@@ -1233,8 +1240,8 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
                dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
 
                dprintk("NFS: commit (%s/%Ld %d@%Ld)",
-                       req->wb_context->dentry->d_inode->i_sb->s_id,
-                       (long long)NFS_FILEID(req->wb_context->dentry->d_inode),
+                       req->wb_context->path.dentry->d_inode->i_sb->s_id,
+                       (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
                        req->wb_bytes,
                        (long long)req_offset(req));
                if (task->tk_status < 0) {
@@ -1248,6 +1255,9 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
                 * returned by the server against all stored verfs. */
                if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) {
                        /* We have a match */
+                       /* Set the PG_uptodate flag */
+                       nfs_mark_uptodate(req->wb_page, req->wb_pgbase,
+                                       req->wb_bytes);
                        nfs_inode_remove_request(req);
                        dprintk(" OK\n");
                        goto next;
@@ -1256,7 +1266,7 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
                dprintk(" mismatch\n");
                nfs_redirty_request(req);
        next:
-               nfs_clear_page_writeback(req);
+               nfs_clear_page_tag_locked(req);
        }
 }