]> Pileus Git - ~andy/linux/blobdiff - fs/nfs/write.c
NFS: make 2 functions static
[~andy/linux] / fs / nfs / write.c
index 2beb1268bb1b582844ac802fefef60959a707862..50774991f8d56f845b1a79ced47f6e526557306d 100644 (file)
@@ -46,7 +46,6 @@
  * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de>
  */
 
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/mm.h>
@@ -98,11 +97,10 @@ struct nfs_write_data *nfs_commit_alloc(unsigned int pagecount)
        if (p) {
                memset(p, 0, sizeof(*p));
                INIT_LIST_HEAD(&p->pages);
-               if (pagecount < NFS_PAGEVEC_SIZE)
-                       p->pagevec = &p->page_array[0];
+               if (pagecount <= ARRAY_SIZE(p->page_array))
+                       p->pagevec = p->page_array;
                else {
-                       size_t size = ++pagecount * sizeof(struct page *);
-                       p->pagevec = kzalloc(size, GFP_NOFS);
+                       p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
                        if (!p->pagevec) {
                                mempool_free(p, nfs_commit_mempool);
                                p = NULL;
@@ -126,14 +124,11 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
        if (p) {
                memset(p, 0, sizeof(*p));
                INIT_LIST_HEAD(&p->pages);
-               if (pagecount < NFS_PAGEVEC_SIZE)
-                       p->pagevec = &p->page_array[0];
+               if (pagecount <= ARRAY_SIZE(p->page_array))
+                       p->pagevec = p->page_array;
                else {
-                       size_t size = ++pagecount * sizeof(struct page *);
-                       p->pagevec = kmalloc(size, GFP_NOFS);
-                       if (p->pagevec) {
-                               memset(p->pagevec, 0, size);
-                       } else {
+                       p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
+                       if (!p->pagevec) {
                                mempool_free(p, nfs_wdata_mempool);
                                p = NULL;
                        }
@@ -142,7 +137,7 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
        return p;
 }
 
-void nfs_writedata_free(struct nfs_write_data *p)
+static void nfs_writedata_free(struct nfs_write_data *p)
 {
        if (p && (p->pagevec != &p->page_array[0]))
                kfree(p->pagevec);
@@ -501,7 +496,7 @@ nfs_mark_request_dirty(struct nfs_page *req)
        nfs_list_add_request(req, &nfsi->dirty);
        nfsi->ndirty++;
        spin_unlock(&nfsi->req_lock);
-       inc_page_state(nr_dirty);
+       inc_zone_page_state(req->wb_page, NR_FILE_DIRTY);
        mark_inode_dirty(inode);
 }
 
@@ -529,7 +524,7 @@ nfs_mark_request_commit(struct nfs_page *req)
        nfs_list_add_request(req, &nfsi->commit);
        nfsi->ncommit++;
        spin_unlock(&nfsi->req_lock);
-       inc_page_state(nr_unstable);
+       inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
        mark_inode_dirty(inode);
 }
 #endif
@@ -539,8 +534,7 @@ nfs_mark_request_commit(struct nfs_page *req)
  *
  * Interruptible by signals only if mounted with intr flag.
  */
-static int
-nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, unsigned int npages)
+static int nfs_wait_on_requests_locked(struct inode *inode, unsigned long idx_start, unsigned int npages)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
        struct nfs_page *req;
@@ -553,7 +547,6 @@ nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, unsigned int
        else
                idx_end = idx_start + npages - 1;
 
-       spin_lock(&nfsi->req_lock);
        next = idx_start;
        while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_WRITEBACK)) {
                if (req->wb_index > idx_end)
@@ -566,15 +559,49 @@ nfs_wait_on_requests(struct inode *inode, unsigned long idx_start, unsigned int
                spin_unlock(&nfsi->req_lock);
                error = nfs_wait_on_request(req);
                nfs_release_request(req);
+               spin_lock(&nfsi->req_lock);
                if (error < 0)
                        return error;
-               spin_lock(&nfsi->req_lock);
                res++;
        }
-       spin_unlock(&nfsi->req_lock);
        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;
+       while(!list_empty(head)) {
+               req = nfs_list_entry(head->next);
+               nfs_list_remove_request(req);
+               nfs_inode_remove_request(req);
+               nfs_clear_page_writeback(req);
+       }
+}
+
+static void nfs_cancel_commit_list(struct list_head *head)
+{
+       struct nfs_page *req;
+
+       while(!list_empty(head)) {
+               req = nfs_list_entry(head->next);
+               nfs_list_remove_request(req);
+               nfs_inode_remove_request(req);
+               nfs_clear_page_writeback(req);
+               dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
+       }
+}
+
 /*
  * nfs_scan_dirty - Scan an inode for dirty requests
  * @inode: NFS inode to scan
@@ -594,7 +621,6 @@ nfs_scan_dirty(struct inode *inode, struct list_head *dst, unsigned long idx_sta
        if (nfsi->ndirty != 0) {
                res = nfs_scan_lock_dirty(nfsi, dst, idx_start, npages);
                nfsi->ndirty -= res;
-               sub_page_state(nr_dirty,res);
                if ((nfsi->ndirty == 0) != list_empty(&nfsi->dirty))
                        printk(KERN_ERR "NFS: desynchronized value of nfs_i.ndirty.\n");
        }
@@ -619,13 +645,18 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_st
        int res = 0;
 
        if (nfsi->ncommit != 0) {
-               res = nfs_scan_list(&nfsi->commit, dst, idx_start, npages);
+               res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages);
                nfsi->ncommit -= res;
                if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit))
                        printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n");
        }
        return res;
 }
+#else
+static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, unsigned long idx_start, unsigned int npages)
+{
+       return 0;
+}
 #endif
 
 static int nfs_wait_on_write_congestion(struct address_space *mapping, int intr)
@@ -1363,6 +1394,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
                nfs_list_remove_request(req);
                nfs_mark_request_commit(req);
                nfs_clear_page_writeback(req);
+               dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
        }
        return -ENOMEM;
 }
@@ -1374,7 +1406,6 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
 {
        struct nfs_write_data   *data = calldata;
        struct nfs_page         *req;
-       int res = 0;
 
         dprintk("NFS: %4d nfs_commit_done (status %d)\n",
                                 task->tk_pid, task->tk_status);
@@ -1386,6 +1417,7 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
        while (!list_empty(&data->pages)) {
                req = nfs_list_entry(data->pages.next);
                nfs_list_remove_request(req);
+               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,
@@ -1412,15 +1444,18 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
                nfs_mark_request_dirty(req);
        next:
                nfs_clear_page_writeback(req);
-               res++;
        }
-       sub_page_state(nr_unstable,res);
 }
 
 static const struct rpc_call_ops nfs_commit_ops = {
        .rpc_call_done = nfs_commit_done,
        .rpc_release = nfs_commit_release,
 };
+#else
+static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how)
+{
+       return 0;
+}
 #endif
 
 static int nfs_flush_inode(struct inode *inode, unsigned long idx_start,
@@ -1460,31 +1495,51 @@ int nfs_commit_inode(struct inode *inode, int how)
 }
 #endif
 
-int nfs_sync_inode(struct inode *inode, unsigned long idx_start,
-                 unsigned int npages, int how)
+int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
+               unsigned int npages, int how)
 {
+       struct nfs_inode *nfsi = NFS_I(inode);
+       LIST_HEAD(head);
        int nocommit = how & FLUSH_NOCOMMIT;
-       int wait = how & FLUSH_WAIT;
-       int error;
-
-       how &= ~(FLUSH_WAIT|FLUSH_NOCOMMIT);
+       int pages, ret;
 
+       how &= ~FLUSH_NOCOMMIT;
+       spin_lock(&nfsi->req_lock);
        do {
-               if (wait) {
-                       error = nfs_wait_on_requests(inode, idx_start, npages);
-                       if (error != 0)
-                               continue;
+               ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
+               if (ret != 0)
+                       continue;
+               pages = nfs_scan_dirty(inode, &head, idx_start, npages);
+               if (pages != 0) {
+                       spin_unlock(&nfsi->req_lock);
+                       if (how & FLUSH_INVALIDATE)
+                               nfs_cancel_dirty_list(&head);
+                       else
+                               ret = nfs_flush_list(inode, &head, pages, how);
+                       spin_lock(&nfsi->req_lock);
+                       continue;
                }
-               error = nfs_flush_inode(inode, idx_start, npages, how);
-               if (error != 0)
+               if (nocommit)
+                       break;
+               pages = nfs_scan_commit(inode, &head, idx_start, npages);
+               if (pages == 0)
+                       break;
+               if (how & FLUSH_INVALIDATE) {
+                       spin_unlock(&nfsi->req_lock);
+                       nfs_cancel_commit_list(&head);
+                       spin_lock(&nfsi->req_lock);
                        continue;
-               if (!nocommit)
-                       error = nfs_commit_inode(inode, how);
-       } while (error > 0);
-       return error;
+               }
+               pages += nfs_scan_commit(inode, &head, 0, 0);
+               spin_unlock(&nfsi->req_lock);
+               ret = nfs_commit_list(inode, &head, how);
+               spin_lock(&nfsi->req_lock);
+       } while (ret >= 0);
+       spin_unlock(&nfsi->req_lock);
+       return ret;
 }
 
-int nfs_init_writepagecache(void)
+int __init nfs_init_writepagecache(void)
 {
        nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
                                             sizeof(struct nfs_write_data),
@@ -1493,17 +1548,13 @@ int nfs_init_writepagecache(void)
        if (nfs_wdata_cachep == NULL)
                return -ENOMEM;
 
-       nfs_wdata_mempool = mempool_create(MIN_POOL_WRITE,
-                                          mempool_alloc_slab,
-                                          mempool_free_slab,
-                                          nfs_wdata_cachep);
+       nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE,
+                                                    nfs_wdata_cachep);
        if (nfs_wdata_mempool == NULL)
                return -ENOMEM;
 
-       nfs_commit_mempool = mempool_create(MIN_POOL_COMMIT,
-                                          mempool_alloc_slab,
-                                          mempool_free_slab,
-                                          nfs_wdata_cachep);
+       nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
+                                                     nfs_wdata_cachep);
        if (nfs_commit_mempool == NULL)
                return -ENOMEM;