[PATCH] FUSE: atomic create+open
[safe/jmp/linux-2.6] / fs / fuse / dev.c
index e4ada02..8f873e6 100644 (file)
@@ -103,20 +103,9 @@ static struct fuse_req *do_get_request(struct fuse_conn *fc)
        return req;
 }
 
+/* This can return NULL, but only in case it's interrupted by a SIGKILL */
 struct fuse_req *fuse_get_request(struct fuse_conn *fc)
 {
-       if (down_interruptible(&fc->outstanding_sem))
-               return NULL;
-       return do_get_request(fc);
-}
-
-/*
- * Non-interruptible version of the above function is for operations
- * which can't legally return -ERESTART{SYS,NOINTR}.  This can still
- * return NULL, but only in case the signal is SIGKILL.
- */
-struct fuse_req *fuse_get_request_nonint(struct fuse_conn *fc)
-{
        int intr;
        sigset_t oldset;
 
@@ -162,9 +151,9 @@ void fuse_release_background(struct fuse_req *req)
 /*
  * 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
- * occured during communication with userspace, or the device file was
- * closed.  It decreases the referece count for the request.  In case
- * of a background request the referece to the stored objects are
+ * 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
  *
@@ -195,6 +184,13 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
                   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) {
+               /* 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;
        }
        if (putback)
                fuse_putback_request(fc, req);
@@ -241,43 +237,20 @@ static void background_request(struct fuse_conn *fc, struct fuse_req *req)
                get_file(req->file);
 }
 
-static int request_wait_answer_nonint(struct fuse_req *req)
-{
-       int err;
-       sigset_t oldset;
-       block_sigs(&oldset);
-       err = wait_event_interruptible(req->waitq, req->finished);
-       restore_sigs(&oldset);
-       return err;
-}
-
 /* Called with fuse_lock held.  Releases, and then reacquires it. */
-static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req,
-                               int interruptible)
+static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
 {
-       int intr;
+       sigset_t oldset;
 
        spin_unlock(&fuse_lock);
-       if (interruptible)
-               intr = wait_event_interruptible(req->waitq, req->finished);
-       else
-               intr = request_wait_answer_nonint(req);
+       block_sigs(&oldset);
+       wait_event_interruptible(req->waitq, req->finished);
+       restore_sigs(&oldset);
        spin_lock(&fuse_lock);
-       if (intr && interruptible && req->sent) {
-               /* If request is already in userspace, only allow KILL
-                  signal to interrupt */
-               spin_unlock(&fuse_lock);
-               intr = request_wait_answer_nonint(req);
-               spin_lock(&fuse_lock);
-       }
-       if (!intr)
+       if (req->finished)
                return;
 
-       if (!interruptible || req->sent)
-               req->out.h.error = -EINTR;
-       else
-               req->out.h.error = -ERESTARTNOINTR;
-
+       req->out.h.error = -EINTR;
        req->interrupted = 1;
        if (req->locked) {
                /* This is uninterruptible sleep, because data is
@@ -330,8 +303,10 @@ static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
        wake_up(&fc->waitq);
 }
 
-static void request_send_wait(struct fuse_conn *fc, struct fuse_req *req,
-                             int interruptible)
+/*
+ * This can only be interrupted by a SIGKILL
+ */
+void request_send(struct fuse_conn *fc, struct fuse_req *req)
 {
        req->isreply = 1;
        spin_lock(&fuse_lock);
@@ -345,26 +320,11 @@ static void request_send_wait(struct fuse_conn *fc, struct fuse_req *req,
                   after request_end() */
                __fuse_get_request(req);
 
-               request_wait_answer(fc, req, interruptible);
+               request_wait_answer(fc, req);
        }
        spin_unlock(&fuse_lock);
 }
 
-void request_send(struct fuse_conn *fc, struct fuse_req *req)
-{
-       request_send_wait(fc, req, 1);
-}
-
-/*
- * Non-interruptible version of the above function is for operations
- * which can't legally return -ERESTART{SYS,NOINTR}.  This can still
- * be interrupted but only with SIGKILL.
- */
-void request_send_nonint(struct fuse_conn *fc, struct fuse_req *req)
-{
-       request_send_wait(fc, req, 0);
-}
-
 static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
 {
        spin_lock(&fuse_lock);