Skip to content

Commit 947867a

Browse files
Dominique Martinetericvh
authored andcommitted
9p: trans_fd, read rework to use p9_parse_header
Most of the changes here are no-op and just renaming to use a fcall struct, needed for p9_parse_header It fixes the unaligned memory access to read the tag and defers to common functions for part of the protocol knowledge (although header length is still hard-coded...) Reported-By: Rob Landley <rob@landley.net> Signed-Off-By: Dominique Martinet <dominique.martinet@cea.fr> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
1 parent c7c72c5 commit 947867a

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

net/9p/trans_fd.c

Lines changed: 40 additions & 35 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,49 +301,56 @@ 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) {
337333
p9_debug(P9_DEBUG_ERROR,
338-
"requested packet size too big: %d\n", n);
334+
"error parsing header: %d\n", err);
335+
goto error;
336+
}
337+
338+
if (m->rc.size >= m->client->msize) {
339+
p9_debug(P9_DEBUG_ERROR,
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
}
@@ -361,23 +364,25 @@ static void p9_read_work(struct work_struct *work)
361364
goto error;
362365
}
363366
}
364-
m->rbuf = (char *)m->req->rc + sizeof(struct p9_fcall);
365-
memcpy(m->rbuf, m->tmp_buf, m->rsize);
366-
m->rsize = n;
367+
m->rc.sdata = (char *)m->req->rc + sizeof(struct p9_fcall);
368+
memcpy(m->rc.sdata, m->tmp_buf, m->rc.capacity);
369+
m->rc.capacity = m->rc.size;
367370
}
368371

369-
/* not an else because some packets (like clunk) have no payload */
370-
if ((m->req) && (m->rpos == m->rsize)) { /* packet is read in */
372+
/* packet is read in
373+
* not an else because some packets (like clunk) have no payload
374+
*/
375+
if ((m->req) && (m->rc.offset == m->rc.capacity)) {
371376
p9_debug(P9_DEBUG_TRANS, "got new packet\n");
372377
spin_lock(&m->client->lock);
373378
if (m->req->status != REQ_STATUS_ERROR)
374379
status = REQ_STATUS_RCVD;
375380
list_del(&m->req->req_list);
376381
spin_unlock(&m->client->lock);
377382
p9_client_cb(m->client, m->req, status);
378-
m->rbuf = NULL;
379-
m->rpos = 0;
380-
m->rsize = 0;
383+
m->rc.sdata = NULL;
384+
m->rc.offset = 0;
385+
m->rc.capacity = 0;
381386
m->req = NULL;
382387
}
383388

0 commit comments

Comments
 (0)