]> Pileus Git - ~andy/linux/blobdiff - net/sunrpc/cache.c
Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[~andy/linux] / net / sunrpc / cache.c
index 9afa4393c21728cb5c0cbd675b6c25966fe99175..25d58e766014bf751ba404cac60893b2cfc5ecf9 100644 (file)
@@ -196,9 +196,9 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_update);
 
 static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
 {
-       if (!cd->cache_upcall)
-               return -EINVAL;
-       return cd->cache_upcall(cd, h);
+       if (cd->cache_upcall)
+               return cd->cache_upcall(cd, h);
+       return sunrpc_cache_pipe_upcall(cd, h);
 }
 
 static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h)
@@ -670,13 +670,13 @@ static void cache_revisit_request(struct cache_head *item)
 {
        struct cache_deferred_req *dreq;
        struct list_head pending;
-       struct hlist_node *lp, *tmp;
+       struct hlist_node *tmp;
        int hash = DFR_HASH(item);
 
        INIT_LIST_HEAD(&pending);
        spin_lock(&cache_defer_lock);
 
-       hlist_for_each_entry_safe(dreq, lp, tmp, &cache_defer_hash[hash], hash)
+       hlist_for_each_entry_safe(dreq, tmp, &cache_defer_hash[hash], hash)
                if (dreq->item == item) {
                        __unhash_deferred_req(dreq);
                        list_add(&dreq->recent, &pending);
@@ -750,12 +750,24 @@ struct cache_reader {
        int                     offset; /* if non-0, we have a refcnt on next request */
 };
 
+static int cache_request(struct cache_detail *detail,
+                              struct cache_request *crq)
+{
+       char *bp = crq->buf;
+       int len = PAGE_SIZE;
+
+       detail->cache_request(detail, crq->item, &bp, &len);
+       if (len < 0)
+               return -EAGAIN;
+       return PAGE_SIZE - len;
+}
+
 static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
                          loff_t *ppos, struct cache_detail *cd)
 {
        struct cache_reader *rp = filp->private_data;
        struct cache_request *rq;
-       struct inode *inode = filp->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(filp);
        int err;
 
        if (count == 0)
@@ -784,6 +796,13 @@ static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
                rq->readers++;
        spin_unlock(&queue_lock);
 
+       if (rq->len == 0) {
+               err = cache_request(cd, rq);
+               if (err < 0)
+                       goto out;
+               rq->len = err;
+       }
+
        if (rp->offset == 0 && !test_bit(CACHE_PENDING, &rq->item->flags)) {
                err = -EAGAIN;
                spin_lock(&queue_lock);
@@ -886,7 +905,7 @@ static ssize_t cache_write(struct file *filp, const char __user *buf,
                           struct cache_detail *cd)
 {
        struct address_space *mapping = filp->f_mapping;
-       struct inode *inode = filp->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(filp);
        ssize_t ret = -EINVAL;
 
        if (!cd->cache_parse)
@@ -1140,17 +1159,14 @@ static bool cache_listeners_exist(struct cache_detail *detail)
  *
  * Each request is at most one page long.
  */
-int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
-               void (*cache_request)(struct cache_detail *,
-                                     struct cache_head *,
-                                     char **,
-                                     int *))
+int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
 {
 
        char *buf;
        struct cache_request *crq;
-       char *bp;
-       int len;
+
+       if (!detail->cache_request)
+               return -EINVAL;
 
        if (!cache_listeners_exist(detail)) {
                warn_no_listener(detail);
@@ -1167,19 +1183,10 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
                return -EAGAIN;
        }
 
-       bp = buf; len = PAGE_SIZE;
-
-       cache_request(detail, h, &bp, &len);
-
-       if (len < 0) {
-               kfree(buf);
-               kfree(crq);
-               return -EAGAIN;
-       }
        crq->q.reader = 0;
        crq->item = cache_get(h);
        crq->buf = buf;
-       crq->len = PAGE_SIZE - len;
+       crq->len = 0;
        crq->readers = 0;
        spin_lock(&queue_lock);
        list_add_tail(&crq->q.list, &detail->queue);
@@ -1454,7 +1461,7 @@ static ssize_t write_flush(struct file *file, const char __user *buf,
 static ssize_t cache_read_procfs(struct file *filp, char __user *buf,
                                 size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
+       struct cache_detail *cd = PDE(file_inode(filp))->data;
 
        return cache_read(filp, buf, count, ppos, cd);
 }
@@ -1462,14 +1469,14 @@ static ssize_t cache_read_procfs(struct file *filp, char __user *buf,
 static ssize_t cache_write_procfs(struct file *filp, const char __user *buf,
                                  size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
+       struct cache_detail *cd = PDE(file_inode(filp))->data;
 
        return cache_write(filp, buf, count, ppos, cd);
 }
 
 static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
 {
-       struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
+       struct cache_detail *cd = PDE(file_inode(filp))->data;
 
        return cache_poll(filp, wait, cd);
 }
@@ -1477,7 +1484,7 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
 static long cache_ioctl_procfs(struct file *filp,
                               unsigned int cmd, unsigned long arg)
 {
-       struct inode *inode = filp->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(filp);
        struct cache_detail *cd = PDE(inode)->data;
 
        return cache_ioctl(inode, filp, cmd, arg, cd);
@@ -1546,7 +1553,7 @@ static int release_flush_procfs(struct inode *inode, struct file *filp)
 static ssize_t read_flush_procfs(struct file *filp, char __user *buf,
                            size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
+       struct cache_detail *cd = PDE(file_inode(filp))->data;
 
        return read_flush(filp, buf, count, ppos, cd);
 }
@@ -1555,7 +1562,7 @@ static ssize_t write_flush_procfs(struct file *filp,
                                  const char __user *buf,
                                  size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
+       struct cache_detail *cd = PDE(file_inode(filp))->data;
 
        return write_flush(filp, buf, count, ppos, cd);
 }
@@ -1605,7 +1612,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
        if (p == NULL)
                goto out_nomem;
 
-       if (cd->cache_upcall || cd->cache_parse) {
+       if (cd->cache_request || cd->cache_parse) {
                p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
                                     cd->u.procfs.proc_ent,
                                     &cache_file_operations_procfs, cd);
@@ -1614,7 +1621,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
                        goto out_nomem;
        }
        if (cd->cache_show) {
-               p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
+               p = proc_create_data("content", S_IFREG|S_IRUSR,
                                cd->u.procfs.proc_ent,
                                &content_file_operations_procfs, cd);
                cd->u.procfs.content_ent = p;
@@ -1686,7 +1693,7 @@ EXPORT_SYMBOL_GPL(cache_destroy_net);
 static ssize_t cache_read_pipefs(struct file *filp, char __user *buf,
                                 size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
+       struct cache_detail *cd = RPC_I(file_inode(filp))->private;
 
        return cache_read(filp, buf, count, ppos, cd);
 }
@@ -1694,14 +1701,14 @@ static ssize_t cache_read_pipefs(struct file *filp, char __user *buf,
 static ssize_t cache_write_pipefs(struct file *filp, const char __user *buf,
                                  size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
+       struct cache_detail *cd = RPC_I(file_inode(filp))->private;
 
        return cache_write(filp, buf, count, ppos, cd);
 }
 
 static unsigned int cache_poll_pipefs(struct file *filp, poll_table *wait)
 {
-       struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
+       struct cache_detail *cd = RPC_I(file_inode(filp))->private;
 
        return cache_poll(filp, wait, cd);
 }
@@ -1709,7 +1716,7 @@ static unsigned int cache_poll_pipefs(struct file *filp, poll_table *wait)
 static long cache_ioctl_pipefs(struct file *filp,
                              unsigned int cmd, unsigned long arg)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = file_inode(filp);
        struct cache_detail *cd = RPC_I(inode)->private;
 
        return cache_ioctl(inode, filp, cmd, arg, cd);
@@ -1778,7 +1785,7 @@ static int release_flush_pipefs(struct inode *inode, struct file *filp)
 static ssize_t read_flush_pipefs(struct file *filp, char __user *buf,
                            size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
+       struct cache_detail *cd = RPC_I(file_inode(filp))->private;
 
        return read_flush(filp, buf, count, ppos, cd);
 }
@@ -1787,7 +1794,7 @@ static ssize_t write_flush_pipefs(struct file *filp,
                                  const char __user *buf,
                                  size_t count, loff_t *ppos)
 {
-       struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
+       struct cache_detail *cd = RPC_I(file_inode(filp))->private;
 
        return write_flush(filp, buf, count, ppos, cd);
 }