]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/fuse/file.c
Pull acpi_bus_register_driver into release branch
[linux-2.6-omap-h63xx.git] / fs / fuse / file.c
index 296351615b0014a2f564dfa3d2fb1ce725e00f6f..fc342cf7c2cc7881dbfafa09097d6de52b34bdca 100644 (file)
@@ -1,6 +1,6 @@
 /*
   FUSE: Filesystem in Userspace
-  Copyright (C) 2001-2005  Miklos Szeredi <miklos@szeredi.hu>
+  Copyright (C) 2001-2006  Miklos Szeredi <miklos@szeredi.hu>
 
   This program can be distributed under the terms of the GNU GPL.
   See the file COPYING.
@@ -12,7 +12,7 @@
 #include <linux/slab.h>
 #include <linux/kernel.h>
 
-static struct file_operations fuse_direct_io_file_operations;
+static const struct file_operations fuse_direct_io_file_operations;
 
 static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
                          struct fuse_open_out *outargp)
@@ -22,9 +22,9 @@ static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
        struct fuse_req *req;
        int err;
 
-       req = fuse_get_request(fc);
-       if (!req)
-               return -EINTR;
+       req = fuse_get_req(fc);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
 
        memset(&inarg, 0, sizeof(inarg));
        inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
@@ -116,9 +116,14 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
 /* Special case for failed iget in CREATE */
 static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req)
 {
-       u64 nodeid = req->in.h.nodeid;
-       fuse_reset_request(req);
-       fuse_send_forget(fc, req, nodeid, 1);
+       /* If called from end_io_requests(), req has more than one
+          reference and fuse_reset_request() cannot work */
+       if (fc->connected) {
+               u64 nodeid = req->in.h.nodeid;
+               fuse_reset_request(req);
+               fuse_send_forget(fc, req, nodeid, 1);
+       } else
+               fuse_put_request(fc, req);
 }
 
 void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
@@ -179,9 +184,9 @@ static int fuse_flush(struct file *file)
        if (fc->no_flush)
                return 0;
 
-       req = fuse_get_request(fc);
-       if (!req)
-               return -EINTR;
+       req = fuse_get_req(fc);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
 
        memset(&inarg, 0, sizeof(inarg));
        inarg.fh = ff->fh;
@@ -218,9 +223,9 @@ int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
        if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir))
                return 0;
 
-       req = fuse_get_request(fc);
-       if (!req)
-               return -EINTR;
+       req = fuse_get_req(fc);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
 
        memset(&inarg, 0, sizeof(inarg));
        inarg.fh = ff->fh;
@@ -292,9 +297,9 @@ static int fuse_readpage(struct file *file, struct page *page)
        if (is_bad_inode(inode))
                goto out;
 
-       err = -EINTR;
-       req = fuse_get_request(fc);
-       if (!req)
+       req = fuse_get_req(fc);
+       err = PTR_ERR(req);
+       if (IS_ERR(req))
                goto out;
 
        req->out.page_zeroing = 1;
@@ -363,10 +368,10 @@ static int fuse_readpages_fill(void *_data, struct page *page)
             (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
             req->pages[req->num_pages - 1]->index + 1 != page->index)) {
                fuse_send_readpages(req, data->file, inode);
-               data->req = req = fuse_get_request(fc);
-               if (!req) {
+               data->req = req = fuse_get_req(fc);
+               if (IS_ERR(req)) {
                        unlock_page(page);
-                       return -EINTR;
+                       return PTR_ERR(req);
                }
        }
        req->pages[req->num_pages] = page;
@@ -387,13 +392,17 @@ static int fuse_readpages(struct file *file, struct address_space *mapping,
 
        data.file = file;
        data.inode = inode;
-       data.req = fuse_get_request(fc);
-       if (!data.req)
-               return -EINTR;
+       data.req = fuse_get_req(fc);
+       if (IS_ERR(data.req))
+               return PTR_ERR(data.req);
 
        err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data);
-       if (!err)
-               fuse_send_readpages(data.req, file, inode);
+       if (!err) {
+               if (data.req->num_pages)
+                       fuse_send_readpages(data.req, file, inode);
+               else
+                       fuse_put_request(fc, data.req);
+       }
        return err;
 }
 
@@ -446,9 +455,9 @@ static int fuse_commit_write(struct file *file, struct page *page,
        if (is_bad_inode(inode))
                return -EIO;
 
-       req = fuse_get_request(fc);
-       if (!req)
-               return -EINTR;
+       req = fuse_get_req(fc);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
 
        req->num_pages = 1;
        req->pages[0] = page;
@@ -523,9 +532,9 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
        if (is_bad_inode(inode))
                return -EIO;
 
-       req = fuse_get_request(fc);
-       if (!req)
-               return -EINTR;
+       req = fuse_get_req(fc);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
 
        while (count) {
                size_t nres;
@@ -556,8 +565,12 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
                buf += nres;
                if (nres != nbytes)
                        break;
-               if (count)
-                       fuse_reset_request(req);
+               if (count) {
+                       fuse_put_request(fc, req);
+                       req = fuse_get_req(fc);
+                       if (IS_ERR(req))
+                               break;
+               }
        }
        fuse_put_request(fc, req);
        if (res > 0) {
@@ -606,7 +619,7 @@ static int fuse_set_page_dirty(struct page *page)
        return 0;
 }
 
-static struct file_operations fuse_file_operations = {
+static const struct file_operations fuse_file_operations = {
        .llseek         = generic_file_llseek,
        .read           = generic_file_read,
        .write          = generic_file_write,
@@ -618,7 +631,7 @@ static struct file_operations fuse_file_operations = {
        .sendfile       = generic_file_sendfile,
 };
 
-static struct file_operations fuse_direct_io_file_operations = {
+static const struct file_operations fuse_direct_io_file_operations = {
        .llseek         = generic_file_llseek,
        .read           = fuse_direct_read,
        .write          = fuse_direct_write,