Skip to content

Commit c52cb43

Browse files
committed
Merge tag 'for-linus-4.5-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs
Pull 9p updates from Eric Van Hensbergen: "Sorry for the last minute pull request, there's was a change that didn't get pulled into for-next until two weeks ago and I wanted to give it some bake time. Summary: Rework and error handling fixes, primarily in the fscatch and fd transports" * tag 'for-linus-4.5-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs: fs/9p: use fscache mutex rather than spinlock 9p: trans_fd, bail out if recv fcall if missing 9p: trans_fd, read rework to use p9_parse_header net/9p: Add device name details on error
2 parents 00e3f5c + a333e4b commit c52cb43

File tree

2 files changed

+47
-43
lines changed

2 files changed

+47
-43
lines changed

net/9p/trans_fd.c

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ struct p9_poll_wait {
108108
* @unsent_req_list: accounting for requests that haven't been sent
109109
* @req: current request being processed (if any)
110110
* @tmp_buf: temporary buffer to read in header
111-
* @rsize: amount to read for current frame
112-
* @rpos: read position in current frame
113-
* @rbuf: current read buffer
111+
* @rc: temporary fcall for reading current frame
114112
* @wpos: write position for current frame
115113
* @wsize: amount of data to write for current frame
116114
* @wbuf: current write buffer
@@ -131,9 +129,7 @@ struct p9_conn {
131129
struct list_head unsent_req_list;
132130
struct p9_req_t *req;
133131
char tmp_buf[7];
134-
int rsize;
135-
int rpos;
136-
char *rbuf;
132+
struct p9_fcall rc;
137133
int wpos;
138134
int wsize;
139135
char *wbuf;
@@ -305,79 +301,87 @@ static void p9_read_work(struct work_struct *work)
305301
if (m->err < 0)
306302
return;
307303

308-
p9_debug(P9_DEBUG_TRANS, "start mux %p pos %d\n", m, m->rpos);
304+
p9_debug(P9_DEBUG_TRANS, "start mux %p pos %zd\n", m, m->rc.offset);
309305

310-
if (!m->rbuf) {
311-
m->rbuf = m->tmp_buf;
312-
m->rpos = 0;
313-
m->rsize = 7; /* start by reading header */
306+
if (!m->rc.sdata) {
307+
m->rc.sdata = m->tmp_buf;
308+
m->rc.offset = 0;
309+
m->rc.capacity = 7; /* start by reading header */
314310
}
315311

316312
clear_bit(Rpending, &m->wsched);
317-
p9_debug(P9_DEBUG_TRANS, "read mux %p pos %d size: %d = %d\n",
318-
m, m->rpos, m->rsize, m->rsize-m->rpos);
319-
err = p9_fd_read(m->client, m->rbuf + m->rpos,
320-
m->rsize - m->rpos);
313+
p9_debug(P9_DEBUG_TRANS, "read mux %p pos %zd size: %zd = %zd\n",
314+
m, m->rc.offset, m->rc.capacity,
315+
m->rc.capacity - m->rc.offset);
316+
err = p9_fd_read(m->client, m->rc.sdata + m->rc.offset,
317+
m->rc.capacity - m->rc.offset);
321318
p9_debug(P9_DEBUG_TRANS, "mux %p got %d bytes\n", m, err);
322-
if (err == -EAGAIN) {
319+
if (err == -EAGAIN)
323320
goto end_clear;
324-
}
325321

326322
if (err <= 0)
327323
goto error;
328324

329-
m->rpos += err;
325+
m->rc.offset += err;
330326

331-
if ((!m->req) && (m->rpos == m->rsize)) { /* header read in */
332-
u16 tag;
327+
/* header read in */
328+
if ((!m->req) && (m->rc.offset == m->rc.capacity)) {
333329
p9_debug(P9_DEBUG_TRANS, "got new header\n");
334330

335-
n = le32_to_cpu(*(__le32 *) m->rbuf); /* read packet size */
336-
if (n >= m->client->msize) {
331+
err = p9_parse_header(&m->rc, NULL, NULL, NULL, 0);
332+
if (err) {
333+
p9_debug(P9_DEBUG_ERROR,
334+
"error parsing header: %d\n", err);
335+
goto error;
336+
}
337+
338+
if (m->rc.size >= m->client->msize) {
337339
p9_debug(P9_DEBUG_ERROR,
338-
"requested packet size too big: %d\n", n);
340+
"requested packet size too big: %d\n",
341+
m->rc.size);
339342
err = -EIO;
340343
goto error;
341344
}
342345

343-
tag = le16_to_cpu(*(__le16 *) (m->rbuf+5)); /* read tag */
344346
p9_debug(P9_DEBUG_TRANS,
345-
"mux %p pkt: size: %d bytes tag: %d\n", m, n, tag);
347+
"mux %p pkt: size: %d bytes tag: %d\n",
348+
m, m->rc.size, m->rc.tag);
346349

347-
m->req = p9_tag_lookup(m->client, tag);
350+
m->req = p9_tag_lookup(m->client, m->rc.tag);
348351
if (!m->req || (m->req->status != REQ_STATUS_SENT)) {
349352
p9_debug(P9_DEBUG_ERROR, "Unexpected packet tag %d\n",
350-
tag);
353+
m->rc.tag);
351354
err = -EIO;
352355
goto error;
353356
}
354357

355358
if (m->req->rc == NULL) {
356-
m->req->rc = kmalloc(sizeof(struct p9_fcall) +
357-
m->client->msize, GFP_NOFS);
358-
if (!m->req->rc) {
359-
m->req = NULL;
360-
err = -ENOMEM;
361-
goto error;
362-
}
359+
p9_debug(P9_DEBUG_ERROR,
360+
"No recv fcall for tag %d (req %p), disconnecting!\n",
361+
m->rc.tag, m->req);
362+
m->req = NULL;
363+
err = -EIO;
364+
goto error;
363365
}
364-
m->rbuf = (char *)m->req->rc + sizeof(struct p9_fcall);
365-
memcpy(m->rbuf, m->tmp_buf, m->rsize);
366-
m->rsize = n;
366+
m->rc.sdata = (char *)m->req->rc + sizeof(struct p9_fcall);
367+
memcpy(m->rc.sdata, m->tmp_buf, m->rc.capacity);
368+
m->rc.capacity = m->rc.size;
367369
}
368370

369-
/* not an else because some packets (like clunk) have no payload */
370-
if ((m->req) && (m->rpos == m->rsize)) { /* packet is read in */
371+
/* packet is read in
372+
* not an else because some packets (like clunk) have no payload
373+
*/
374+
if ((m->req) && (m->rc.offset == m->rc.capacity)) {
371375
p9_debug(P9_DEBUG_TRANS, "got new packet\n");
372376
spin_lock(&m->client->lock);
373377
if (m->req->status != REQ_STATUS_ERROR)
374378
status = REQ_STATUS_RCVD;
375379
list_del(&m->req->req_list);
376380
spin_unlock(&m->client->lock);
377381
p9_client_cb(m->client, m->req, status);
378-
m->rbuf = NULL;
379-
m->rpos = 0;
380-
m->rsize = 0;
382+
m->rc.sdata = NULL;
383+
m->rc.offset = 0;
384+
m->rc.capacity = 0;
381385
m->req = NULL;
382386
}
383387

net/9p/trans_virtio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args)
658658
mutex_unlock(&virtio_9p_lock);
659659

660660
if (!found) {
661-
pr_err("no channels available\n");
661+
pr_err("no channels available for device %s\n", devname);
662662
return ret;
663663
}
664664

0 commit comments

Comments
 (0)