9p/net: add zero copy support
Subsystems (3)
PATCH 1/1 9p/net: add zero copy support
Adds support for scatterlists for the transports. If the transport indicates that it can handle scatterlists (P9_TRANS_SG in the flags field), it should check the sg field in the p9_fcall structs. If sg field is non-NULL, the transport should write/read the 9P message into the memory pointed by the scatterlist.
The protocol and client code prepares the transmitting/receiving buffers so the data is directly written from/read to the user data buffer.
Signed-off-by Latchesar Ionkov <[email protected]>
--- include/net/9p/9p.h | 20 ++- include/net/9p/client.h | 24 ++ include/net/9p/transport.h | 11 + net/9p/client.c | 512 ++++++++++++++++++++++++++++++++++---------- net/9p/protocol.c | 56 ++++-- net/9p/protocol.h | 3 + net/9p/trans_fd.c | 20 +- net/9p/util.c | 2 +- 8 files changed, 502 insertions(+), 146 deletions(-)
include/net/9p/9p.h +17 -3
@@ -27,6 +27,8 @@#ifndef NET_9P_H #define NET_9P_H +#include <linux/scatterlist.h> +/** * enum p9_debug_flags - bits for mount time debug parameter * @P9_DEBUG_ERROR: more verbose error messages including original error string
@@ -304,6 +306,8 @@ enum p9_qid_t {/* ample room for Twrite/Rread header */ #define P9_IOHDRSZ 24 +#define P9_TWRITE_HDRSZ 23 +#define P9_RREAD_HDRSZ 11/* Room for readdir header */ #define P9_READDIRHDRSZ 24
@@ -633,9 +637,12 @@ struct p9_rwstat {* @size: prefixed length of the structure * @id: protocol operating identifier of type &p9_msg_t * @tag: transaction id of the request -* @offset: used by marshalling routines to track currentposition in buffer +* @offset: used by marshalling routines to track current position in buffer * @capacity: used by marshalling routines to track total capacity -* @sdata: payload +* @sgcount: number of entries in the scatterlist array +* @sg: array of scatterlist structs that describe the payload. The first +* entry in the array is always mapped and pointer to it is stored in &buf +* @buf: payload (whole if sg is NULL, otherwise the first entry). * * &p9_fcall represents the structure for all 9P RPC * transactions. Requests are packaged into fcalls, and reponses
@@ -645,14 +652,21 @@ struct p9_rwstat {*/ struct p9_fcall { +/* 9P message header data */ u32 size;u8 id;u16 tag; +/* data related to marshalling */ size_t offset;size_t capacity; -uint8_t *sdata; +/* buffer description */ +int sgcount; +struct scatterlist *sg; +uint8_t *buf; + +struct list_head fclist; };struct p9_idpool ;
include/net/9p/client.h +24 -0
@@ -95,6 +95,8 @@ enum p9_req_status_t {* @wq: wait_queue for the client to block on for this request * @tc: the request fcall structure * @rc: the response fcall structure +* @tb: the request buffer +* @rb: the response buffer * @aux: transport specific data (provided for trans_fd migration) * @req_list: link for higher level objects to chain requests *
@@ -110,6 +112,7 @@ enum p9_req_status_t {*/ struct p9_req_t { +u16 tag;int status;int t_err;wait_queue_head_t *wq;
@@ -134,6 +137,12 @@ struct p9_req_t {* @tagpool - transaction id accounting for session * @reqs - 2D array of requests * @max_tag - current maximum tag id allocated +* @sblist - list of small pdu +* @sbcount - number of elements in sblist +* @lblist - list of large (->msize) pdu +* @lbcount - number of elements in lblist +* @sgblist - list of scatterlist pdu +* @sgbcount - number of elements in sgblist * * The client structure is used to keep track of various per-client * state that has been instantiated.
@@ -146,12 +155,20 @@ struct p9_req_t {* Each row is 256 requests and we'll support up to 256 rows for * a total of 64k concurrent requests per session. * +* The client structure keeps track of two classes of 9P message buffers: +* - large buffers (lblist, lbcount) that can hold up to &msize bytes +* messages. +* - small buffers (sblist, sbcount) that can hold up to P9_SMALL_SIZE +* byte header + scatterlist for up to &msize/PAGE_SIZE+2 pages. +* There are up to P9_MAX_BUFS messages kept in the lists. +* * Bugs: duplicated data and potentially unnecessary elements. */ struct p9_client {spinlock_t lock;/* protect client structure */ int msize; +int maxsgcount;unsigned char proto_version;struct p9_trans_module *trans_mod;enum p9_trans_status status;
@@ -164,6 +181,11 @@ struct p9_client {struct p9_idpool *tagpool;struct p9_req_t *reqs[P9_ROW_MAXTAG ];int max_tag; + +struct list_head sblist; +int sbcount; +struct list_head lblist; +int lbcount; };/**
@@ -257,6 +279,8 @@ void p9_client_cb(struct p9_client *c, struct p9_req_t *req);int p9_parse_header (struct p9_fcall *,int32_t *,int8_t *,int16_t *,int );int p9stat_read (char *,int ,struct p9_wstat *,int );void p9stat_free (struct p9_wstat *); +struct p9_fcall *p9_fcall_alloc (struct p9_client *c,int size); +void p9_fcall_free (struct p9_client *c,struct p9_fcall *fc);int p9_is_proto_dotu (struct p9_client *clnt);int p9_is_proto_dotl (struct p9_client *clnt);
include/net/9p/transport.h +11 -0
@@ -43,11 +43,16 @@* BUGS: the transport module list isn't protected. */ +enum { +P9_TRANS_SG =1 ,/* support for scatterlists */ +}; +struct p9_trans_module {struct list_head list;char *name;/* name of transport */ int maxsize;/* max message size of transport */ int def;/* this transport should be default */ +int flags;/* P9_TRANS_* flags */ struct module *owner;int (*create)(struct p9_client *,const char *,char *);void (*close) (struct p9_client *);
@@ -60,4 +65,10 @@ void v9fs_unregister_trans(struct p9_trans_module *m);struct p9_trans_module *v9fs_get_trans_by_name (const substring_t *name);struct p9_trans_module *v9fs_get_default_trans (void );void v9fs_put_trans (struct p9_trans_module *m); + +static int inline p9_trans_sg_support (struct p9_trans_module *ts) +{ +return ts->flags &P9_TRANS_SG ; +} +#endif /* NET_9P_TRANSPORT_H */
net/9p/client.c +399 -113
828 lines not on this page · raw message
net/9p/protocol.c +37 -19
117 lines not on this page · raw message
net/9p/protocol.h +3 -0
@@ -32,3 +32,6 @@ int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type);int p9pdu_finalize (struct p9_fcall *pdu);void p9pdu_dump (int ,struct p9_fcall *);void p9pdu_reset (struct p9_fcall *pdu); +int p9pdu_prepare_sg (struct p9_fcall *pdu,int32_t hdrsz,int32_t count, +int rw,const void __user *data); +void p9pdu_free_sg (struct p9_fcall *pdu);
net/9p/trans_fd.c +10 -10
@@ -347,16 +347,15 @@ static void p9_read_work(struct work_struct *work) goto error; } -if (m->req->rc ==NULL ) { - m->req->rc =kmalloc (sizeof (struct p9_fcall ) + - m->client->msize,GFP_KERNEL ); -if (!m->req->rc) { - m->req =NULL ; - err = -ENOMEM ; - goto error; - } +/* trans_fd doesn't support scatterlists, rc can't e non-NULL */ +BUG_ON (m->req->rc !=NULL ); + m->req->rc =p9_fcall_alloc (m->client, n); +if (!m->req->rc) { + m->req =NULL ; + err = -ENOMEM ; + goto error; } - m->rbuf = (char *)m->req->rc +sizeof (struct p9_fcall ); + m->rbuf = (char *)m->req->rc->buf;memcpy (m->rbuf, m->tmp_buf, m->rsize); m->rsize = n; }
@@ -364,6 +363,7 @@ static void p9_read_work(struct work_struct *work)/* not an else because some packets (like clunk) have no payload */ if ((m->req) && (m->rpos == m->rsize)) {/* packet is read in */ P9_DPRINTK (P9_DEBUG_TRANS ,"got new packet\n" ); + m->req->rc->size = m->rsize;spin_lock (&m->client->lock);if (m->req->status !=REQ_STATUS_ERROR ) m->req->status =REQ_STATUS_RCVD ;
@@ -462,7 +462,7 @@ static void p9_write_work(struct work_struct *work)P9_DPRINTK (P9_DEBUG_TRANS ,"move req %p\n" , req);list_move_tail (&req->req_list, &m->req_list); - m->wbuf = req->tc->sdata; + m->wbuf = req->tc->buf; m->wsize = req->tc->size; m->wpos =0 ;spin_unlock (&m->client->lock);
net/9p/util.c +1 -1
@@ -66,7 +66,7 @@ struct p9_idpool *p9_idpool_create(void)EXPORT_SYMBOL (p9_idpool_create);/** -* p9_idpool_destroy - create a new per-connection id pool +* p9_idpool_destroy - destroy the per-connection id pool * @p: idpool to destory */