]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] v9fs: fix handling of malformed 9P messages
authorEric Van Hensbergen <ericvh@gmail.com>
Fri, 9 Sep 2005 20:04:28 +0000 (13:04 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 9 Sep 2005 20:57:58 +0000 (13:57 -0700)
This patch attempts to do a better job of cleaning up after detecting errors
on the transport.  This should also improve error reporting on broken
connections to servers.

Signed-off-by: Latchesar Ionkov <lucho@ionkov.net>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/9p/error.h
fs/9p/mux.c
fs/9p/mux.h
fs/9p/trans_sock.c

index 2eb5927d589ed5b4a08bc5155162581938ef387d..78f89acf7c9affa0552ea442b75e8be06787bfc3 100644 (file)
@@ -47,6 +47,7 @@ static struct errormap errmap[] = {
        {"Operation not permitted", EPERM},
        {"wstat prohibited", EPERM},
        {"No such file or directory", ENOENT},
+       {"directory entry not found", ENOENT},
        {"file not found", ENOENT},
        {"Interrupted system call", EINTR},
        {"Input/output error", EIO},
index 0854bef58c166edce9da5d946cd8eb5acd8f3970..8835b576f7445c98eae41c69c9afde4f21d91b3a 100644 (file)
@@ -162,18 +162,21 @@ static int v9fs_recv(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req)
        dprintk(DEBUG_MUX, "waiting for response: %d\n", req->tcall->tag);
        ret = wait_event_interruptible(v9ses->read_wait,
                       ((v9ses->transport->status != Connected) ||
-                       (req->rcall != 0) || dprintcond(v9ses, req)));
+                       (req->rcall != 0) || (req->err < 0) ||
+                       dprintcond(v9ses, req)));
 
        dprintk(DEBUG_MUX, "got it: rcall %p\n", req->rcall);
+
+       spin_lock(&v9ses->muxlock);
+       list_del(&req->next);
+       spin_unlock(&v9ses->muxlock);
+
+       if (req->err < 0)
+               return req->err;
+
        if (v9ses->transport->status == Disconnected)
                return -ECONNRESET;
 
-       if (ret == 0) {
-               spin_lock(&v9ses->muxlock);
-               list_del(&req->next);
-               spin_unlock(&v9ses->muxlock);
-       }
-
        return ret;
 }
 
@@ -245,6 +248,9 @@ v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall,
        if (!v9ses)
                return -EINVAL;
 
+       if (!v9ses->transport || v9ses->transport->status != Connected)
+               return -EIO;
+
        if (rcall)
                *rcall = NULL;
 
@@ -257,6 +263,7 @@ v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall,
        tcall->tag = tid;
 
        req.tcall = tcall;
+       req.err = 0;
        req.rcall = NULL;
 
        ret = v9fs_send(v9ses, &req);
@@ -371,16 +378,21 @@ static int v9fs_recvproc(void *data)
                }
 
                err = read_message(v9ses, rcall, v9ses->maxdata + V9FS_IOHDRSZ);
-               if (err < 0) {
-                       kfree(rcall);
-                       break;
-               }
                spin_lock(&v9ses->muxlock);
-               list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) {
-                       if (rreq->tcall->tag == rcall->tag) {
-                               req = rreq;
-                               req->rcall = rcall;
-                               break;
+               if (err < 0) {
+                       list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) {
+                               rreq->err = err;
+                       }
+                       if(err != -ERESTARTSYS)
+                               eprintk(KERN_ERR,
+                                       "Transport error while reading message %d\n", err);
+               } else {
+                       list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) {
+                               if (rreq->tcall->tag == rcall->tag) {
+                                       req = rreq;
+                                       req->rcall = rcall;
+                                       break;
+                               }
                        }
                }
 
@@ -399,9 +411,10 @@ static int v9fs_recvproc(void *data)
                spin_unlock(&v9ses->muxlock);
 
                if (!req) {
-                       dprintk(DEBUG_ERROR,
-                               "unexpected response: id %d tag %d\n",
-                               rcall->id, rcall->tag);
+                       if (err >= 0)
+                               dprintk(DEBUG_ERROR,
+                                       "unexpected response: id %d tag %d\n",
+                                       rcall->id, rcall->tag);
 
                        kfree(rcall);
                }
@@ -410,6 +423,8 @@ static int v9fs_recvproc(void *data)
                set_current_state(TASK_INTERRUPTIBLE);
        }
 
+       v9ses->transport->close(v9ses->transport);
+
        /* Inform all pending processes about the failure */
        wake_up_all(&v9ses->read_wait);
 
index 82ce793af1b57402cff569415c454eb404e6367b..4994cb10badfef1498931d85928a5fb140960e7b 100644 (file)
@@ -28,6 +28,7 @@
 struct v9fs_rpcreq {
        struct v9fs_fcall *tcall;
        struct v9fs_fcall *rcall;
+       int err;        /* error code if response failed */
 
        /* XXX - could we put scatter/gather buffers here? */
 
index 081d1c84780301e80883bb9994beaa4e2579914b..01e26f0013aced186efe40992d34996999ded2da 100644 (file)
@@ -254,7 +254,12 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name,
 
 static void v9fs_sock_close(struct v9fs_transport *trans)
 {
-       struct v9fs_trans_sock *ts = trans ? trans->priv : NULL;
+       struct v9fs_trans_sock *ts;
+
+       if (!trans)
+               return;
+
+       ts = trans->priv;
 
        if ((ts) && (ts->s)) {
                dprintk(DEBUG_TRANS, "closing the socket %p\n", ts->s);
@@ -264,7 +269,10 @@ static void v9fs_sock_close(struct v9fs_transport *trans)
                dprintk(DEBUG_TRANS, "socket closed\n");
        }
 
-       kfree(ts);
+       if (ts)
+               kfree(ts);
+
+       trans->priv = NULL;
 }
 
 struct v9fs_transport v9fs_trans_tcp = {