]> err.no Git - linux-2.6/blobdiff - fs/fuse/dev.c
[PATCH] fuse: handle error INIT reply
[linux-2.6] / fs / fuse / dev.c
index e5bc3f8eebd06a092f2f88343995fc13c870fcf4..8244e89a8dd6e3fe1379b1c002ccd351c8a7c770 100644 (file)
@@ -148,22 +148,40 @@ void fuse_release_background(struct fuse_req *req)
        spin_unlock(&fuse_lock);
 }
 
+static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
+{
+       int i;
+       struct fuse_init_out *arg = &req->misc.init_out;
+
+       if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION)
+               fc->conn_error = 1;
+       else {
+               fc->minor = arg->minor;
+               fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
+       }
+
+       /* After INIT reply is received other requests can go
+          out.  So do (FUSE_MAX_OUTSTANDING - 1) number of
+          up()s on outstanding_sem.  The last up() is done in
+          fuse_putback_request() */
+       for (i = 1; i < FUSE_MAX_OUTSTANDING; i++)
+               up(&fc->outstanding_sem);
+}
+
 /*
  * This function is called when a request is finished.  Either a reply
  * has arrived or it was interrupted (and not yet sent) or some error
- * occurred during communication with userspace, or the device file was
- * closed.  It decreases the reference count for the request.  In case
- * of a background request the reference to the stored objects are
- * released.  The requester thread is woken up (if still waiting), and
- * finally the request is either freed or put on the unused_list
+ * occurred during communication with userspace, or the device file
+ * was closed.  In case of a background request the reference to the
+ * stored objects are released.  The requester thread is woken up (if
+ * still waiting), and finally the reference to the request is
+ * released
  *
  * Called with fuse_lock, unlocks it
  */
 static void request_end(struct fuse_conn *fc, struct fuse_req *req)
 {
-       int putback;
        req->finished = 1;
-       putback = atomic_dec_and_test(&req->count);
        spin_unlock(&fuse_lock);
        if (req->background) {
                down_read(&fc->sbput_sem);
@@ -172,30 +190,16 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
                up_read(&fc->sbput_sem);
        }
        wake_up(&req->waitq);
-       if (req->in.h.opcode == FUSE_INIT) {
-               int i;
-
-               if (req->misc.init_in_out.major != FUSE_KERNEL_VERSION)
-                       fc->conn_error = 1;
-
-               fc->minor = req->misc.init_in_out.minor;
-
-               /* After INIT reply is received other requests can go
-                  out.  So do (FUSE_MAX_OUTSTANDING - 1) number of
-                  up()s on outstanding_sem.  The last up() is done in
-                  fuse_putback_request() */
-               for (i = 1; i < FUSE_MAX_OUTSTANDING; i++)
-                       up(&fc->outstanding_sem);
-       } else if (req->in.h.opcode == FUSE_RELEASE && req->inode == NULL) {
+       if (req->in.h.opcode == FUSE_INIT)
+               process_init_reply(fc, req);
+       else if (req->in.h.opcode == FUSE_RELEASE && req->inode == NULL) {
                /* Special case for failed iget in CREATE */
                u64 nodeid = req->in.h.nodeid;
-               __fuse_get_request(req);
                fuse_reset_request(req);
                fuse_send_forget(fc, req, nodeid, 1);
-               putback = 0;
+               return;
        }
-       if (putback)
-               fuse_putback_request(fc, req);
+       fuse_put_request(fc, req);
 }
 
 /*
@@ -359,7 +363,7 @@ void fuse_send_init(struct fuse_conn *fc)
        /* This is called from fuse_read_super() so there's guaranteed
           to be a request available */
        struct fuse_req *req = do_get_request(fc);
-       struct fuse_init_in_out *arg = &req->misc.init_in_out;
+       struct fuse_init_in *arg = &req->misc.init_in;
        arg->major = FUSE_KERNEL_VERSION;
        arg->minor = FUSE_KERNEL_MINOR_VERSION;
        req->in.h.opcode = FUSE_INIT;
@@ -367,8 +371,12 @@ void fuse_send_init(struct fuse_conn *fc)
        req->in.args[0].size = sizeof(*arg);
        req->in.args[0].value = arg;
        req->out.numargs = 1;
-       req->out.args[0].size = sizeof(*arg);
-       req->out.args[0].value = arg;
+       /* Variable length arguement used for backward compatibility
+          with interface version < 7.5.  Rest of init_out is zeroed
+          by do_get_request(), so a short reply is not a problem */
+       req->out.argvar = 1;
+       req->out.args[0].size = sizeof(struct fuse_init_out);
+       req->out.args[0].value = &req->misc.init_out;
        request_send_background(fc, req);
 }
 
@@ -617,6 +625,7 @@ static ssize_t fuse_dev_readv(struct file *file, const struct iovec *iov,
        struct fuse_copy_state cs;
        unsigned reqsize;
 
+ restart:
        spin_lock(&fuse_lock);
        fc = file->private_data;
        err = -EPERM;
@@ -632,20 +641,25 @@ static ssize_t fuse_dev_readv(struct file *file, const struct iovec *iov,
 
        req = list_entry(fc->pending.next, struct fuse_req, list);
        list_del_init(&req->list);
-       spin_unlock(&fuse_lock);
 
        in = &req->in;
-       reqsize = req->in.h.len;
-       fuse_copy_init(&cs, 1, req, iov, nr_segs);
-       err = -EINVAL;
-       if (iov_length(iov, nr_segs) >= reqsize) {
-               err = fuse_copy_one(&cs, &in->h, sizeof(in->h));
-               if (!err)
-                       err = fuse_copy_args(&cs, in->numargs, in->argpages,
-                                            (struct fuse_arg *) in->args, 0);
+       reqsize = in->h.len;
+       /* If request is too large, reply with an error and restart the read */
+       if (iov_length(iov, nr_segs) < reqsize) {
+               req->out.h.error = -EIO;
+               /* SETXATTR is special, since it may contain too large data */
+               if (in->h.opcode == FUSE_SETXATTR)
+                       req->out.h.error = -E2BIG;
+               request_end(fc, req);
+               goto restart;
        }
+       spin_unlock(&fuse_lock);
+       fuse_copy_init(&cs, 1, req, iov, nr_segs);
+       err = fuse_copy_one(&cs, &in->h, sizeof(in->h));
+       if (!err)
+               err = fuse_copy_args(&cs, in->numargs, in->argpages,
+                                    (struct fuse_arg *) in->args, 0);
        fuse_copy_finish(&cs);
-
        spin_lock(&fuse_lock);
        req->locked = 0;
        if (!err && req->interrupted)
@@ -755,8 +769,10 @@ static ssize_t fuse_dev_writev(struct file *file, const struct iovec *iov,
 
        list_del_init(&req->list);
        if (req->interrupted) {
-               request_end(fc, req);
+               spin_unlock(&fuse_lock);
                fuse_copy_finish(&cs);
+               spin_lock(&fuse_lock);
+               request_end(fc, req);
                return -ENOENT;
        }
        req->out.h = oh;