netfilter: xtables: constify args in compat copying functions
[safe/jmp/linux-2.6] / net / 9p / client.c
index 93f442a..8af95b2 100644 (file)
@@ -60,9 +60,9 @@ static struct p9_req_t *
 p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
 
 /**
- * v9fs_parse_options - parse mount options into session structure
- * @options: options string passed from mount
- * @v9ses: existing v9fs session information
+ * parse_options - parse mount options into client structure
+ * @opts: options string passed from mount
+ * @clnt: existing v9fs client information
  *
  * Return 0 upon success, -ERRNO upon failure
  */
@@ -117,9 +117,6 @@ static int parse_opts(char *opts, struct p9_client *clnt)
                }
        }
 
-       if (!clnt->trans_mod)
-               clnt->trans_mod = v9fs_get_default_trans();
-
        kfree(options);
        return ret;
 }
@@ -203,7 +200,6 @@ static struct p9_req_t *p9_tag_alloc(struct p9_client *c, u16 tag)
        p9pdu_reset(req->tc);
        p9pdu_reset(req->rc);
 
-       req->flush_tag = 0;
        req->tc->tag = tag-1;
        req->status = REQ_STATUS_ALLOC;
 
@@ -236,7 +232,7 @@ EXPORT_SYMBOL(p9_tag_lookup);
 
 /**
  * p9_tag_init - setup tags structure and contents
- * @tags: tags structure from the client struct
+ * @c:  v9fs client struct
  *
  * This initializes the tags structure for each client instance.
  *
@@ -262,7 +258,7 @@ error:
 
 /**
  * p9_tag_cleanup - cleans up tags structure and reclaims resources
- * @tags: tags structure from the client struct
+ * @c:  v9fs client struct
  *
  * This frees resources associated with the tags structure
  *
@@ -324,35 +320,9 @@ static void p9_free_req(struct p9_client *c, struct p9_req_t *r)
  */
 void p9_client_cb(struct p9_client *c, struct p9_req_t *req)
 {
-       struct p9_req_t *other_req;
-       unsigned long flags;
-
        P9_DPRINTK(P9_DEBUG_MUX, " tag %d\n", req->tc->tag);
-
-       if (req->status == REQ_STATUS_ERROR)
-               wake_up(req->wq);
-
-       if (req->flush_tag) {                   /* flush receive path */
-               P9_DPRINTK(P9_DEBUG_9P, "<<< RFLUSH %d\n", req->tc->tag);
-               spin_lock_irqsave(&c->lock, flags);
-               other_req = p9_tag_lookup(c, req->flush_tag);
-               if (other_req->status != REQ_STATUS_FLSH) /* stale flush */
-                       spin_unlock_irqrestore(&c->lock, flags);
-               else {
-                       other_req->status = REQ_STATUS_FLSHD;
-                       spin_unlock_irqrestore(&c->lock, flags);
-                       wake_up(other_req->wq);
-               }
-               p9_free_req(c, req);
-       } else {                                /* normal receive path */
-               P9_DPRINTK(P9_DEBUG_MUX, "normal: tag %d\n", req->tc->tag);
-               spin_lock_irqsave(&c->lock, flags);
-               if (req->status != REQ_STATUS_FLSHD)
-                       req->status = REQ_STATUS_RCVD;
-               spin_unlock_irqrestore(&c->lock, flags);
-               wake_up(req->wq);
-               P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag);
-       }
+       wake_up(req->wq);
+       P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag);
 }
 EXPORT_SYMBOL(p9_client_cb);
 
@@ -441,14 +411,9 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
                if (c->dotu)
                        err = -ecode;
 
-               if (!err) {
+               if (!err || !IS_ERR_VALUE(err))
                        err = p9_errstr2errno(ename, strlen(ename));
 
-                       /* string match failed */
-                       if (!err)
-                               err = -ESERVERFAULT;
-               }
-
                P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", -ecode, ename);
 
                kfree(ename);
@@ -460,8 +425,8 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
 
 /**
  * p9_client_flush - flush (cancel) a request
- * c: client state
- * req: request to cancel
+ * @c: client state
+ * @oldreq: request to cancel
  *
  * This sents a flush for a particular requests and links
  * the flush request to the original request.  The current
@@ -486,9 +451,15 @@ static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq)
        if (IS_ERR(req))
                return PTR_ERR(req);
 
-       req->flush_tag = oldtag;
 
-       /* we don't free anything here because RPC isn't complete */
+       /* if we haven't received a response for oldreq,
+          remove it from the list. */
+       spin_lock(&c->lock);
+       if (oldreq->status == REQ_STATUS_FLSH)
+               list_del(&oldreq->req_list);
+       spin_unlock(&c->lock);
+
+       p9_free_req(c, req);
        return 0;
 }
 
@@ -509,7 +480,6 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
        struct p9_req_t *req;
        unsigned long flags;
        int sigpending;
-       int flushed = 0;
 
        P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type);
 
@@ -546,42 +516,28 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
                goto reterr;
        }
 
-       /* if it was a flush we just transmitted, return our tag */
-       if (type == P9_TFLUSH)
-               return req;
-again:
        P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d\n", req->wq, tag);
        err = wait_event_interruptible(*req->wq,
                                                req->status >= REQ_STATUS_RCVD);
-       P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d returned %d (flushed=%d)\n",
-                                               req->wq, tag, err, flushed);
+       P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d returned %d\n",
+                                               req->wq, tag, err);
 
        if (req->status == REQ_STATUS_ERROR) {
                P9_DPRINTK(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err);
                err = req->t_err;
-       } else if (err == -ERESTARTSYS && flushed) {
-               P9_DPRINTK(P9_DEBUG_MUX, "flushed - going again\n");
-               goto again;
-       } else if (req->status == REQ_STATUS_FLSHD) {
-               P9_DPRINTK(P9_DEBUG_MUX, "flushed - erestartsys\n");
-               err = -ERESTARTSYS;
        }
 
-       if ((err == -ERESTARTSYS) && (c->status == Connected) && (!flushed)) {
+       if ((err == -ERESTARTSYS) && (c->status == Connected)) {
                P9_DPRINTK(P9_DEBUG_MUX, "flushing\n");
-               spin_lock_irqsave(&c->lock, flags);
-               if (req->status == REQ_STATUS_SENT)
-                       req->status = REQ_STATUS_FLSH;
-               spin_unlock_irqrestore(&c->lock, flags);
                sigpending = 1;
-               flushed = 1;
                clear_thread_flag(TIF_SIGPENDING);
 
-               if (c->trans_mod->cancel(c, req)) {
-                       err = p9_client_flush(c, req);
-                       if (err == 0)
-                               goto again;
-               }
+               if (c->trans_mod->cancel(c, req))
+                       p9_client_flush(c, req);
+
+               /* if we received the response anyway, don't signal error */
+               if (req->status == REQ_STATUS_RCVD)
+                       err = 0;
        }
 
        if (sigpending) {
@@ -626,11 +582,9 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt)
 
        memset(&fid->qid, 0, sizeof(struct p9_qid));
        fid->mode = -1;
-       fid->rdir_fpos = 0;
        fid->uid = current_fsuid();
        fid->clnt = clnt;
-       fid->aux = NULL;
-
+       fid->rdir = NULL;
        spin_lock_irqsave(&clnt->lock, flags);
        list_add(&fid->flist, &clnt->fidlist);
        spin_unlock_irqrestore(&clnt->lock, flags);
@@ -653,6 +607,7 @@ static void p9_fid_destroy(struct p9_fid *fid)
        spin_lock_irqsave(&clnt->lock, flags);
        list_del(&fid->flist);
        spin_unlock_irqrestore(&clnt->lock, flags);
+       kfree(fid->rdir);
        kfree(fid);
 }
 
@@ -725,6 +680,9 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
        if (err < 0)
                goto error;
 
+       if (!clnt->trans_mod)
+               clnt->trans_mod = v9fs_get_default_trans();
+
        if (clnt->trans_mod == NULL) {
                err = -EPROTONOSUPPORT;
                P9_DPRINTK(P9_DEBUG_ERROR,
@@ -1134,7 +1092,6 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
 
        if (data) {
                memmove(data, dataptr, count);
-               data += count;
        }
 
        if (udata) {
@@ -1228,9 +1185,9 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid)
 
        err = p9pdu_readf(req->rc, clnt->dotu, "wS", &ignored, ret);
        if (err) {
-               ret = ERR_PTR(err);
                p9pdu_dump(1, req->rc);
-               goto free_and_error;
+               p9_free_req(clnt, req);
+               goto error;
        }
 
        P9_DPRINTK(P9_DEBUG_9P,
@@ -1244,10 +1201,12 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid)
                ret->name, ret->uid, ret->gid, ret->muid, ret->extension,
                ret->n_uid, ret->n_gid, ret->n_muid);
 
-free_and_error:
        p9_free_req(clnt, req);
-error:
        return ret;
+
+error:
+       kfree(ret);
+       return ERR_PTR(err);
 }
 EXPORT_SYMBOL(p9_client_stat);