Cleanup XDR parsing for LAYOUTGET, GETDEVICEINFO
Subsystems (2)
PATCH 1/1 Cleanup XDR parsing for LAYOUTGET, GETDEVICEINFO
changes LAYOUTGET and GETDEVICEINFO XDR parsing to:
- not use vmap, which doesn't work on incoherent archs
- use xdr_stream parsing for all xdr
--- fs/nfs/nfs4filelayout.c | 53 +++++++++++-- fs/nfs/nfs4filelayoutdev.c | 180 ++++++++++++++++++++++++++++++-------------- fs/nfs/nfs4proc.c | 9 +-- fs/nfs/nfs4xdr.c | 30 +++++--- fs/nfs/pnfs.c | 39 ++++++++++ fs/nfs/pnfs.h | 1 - include/linux/nfs_xdr.h | 6 +- 7 files changed, 232 insertions(+), 86 deletions(-)
fs/nfs/nfs4filelayout.c +44 -9
@@ -441,12 +441,33 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo,struct nfs4_layoutget_res *lgr, struct nfs4_deviceid *id) { - uint32_t *p = (uint32_t *)lgr->layout.buf; + struct xdr_stream stream; +struct xdr_buf buf = { + .pages = lgr->layoutp->pages, + .page_len = lgr->layoutp->len, + .buflen = lgr->layoutp->len, + .len = lgr->layoutp->len, + }; +struct page *scratch; +__be32 *p;uint32_t nfl_util;int i;dprintk ("%s: set_layout_map Begin\n" , __func__); + scratch =alloc_page (GFP_KERNEL ); +if (!scratch) +return -ENOMEM ; + +xdr_init_decode (&stream, &buf,NULL ); +xdr_set_scratch_buffer (&stream,page_address (scratch),PAGE_SIZE ); + +/* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8), +* num_fh (4) */ + p =xdr_inline_decode (&stream,NFS4_DEVICEID4_SIZE +20 ); +if (unlikely (!p)) + goto out_err; +memcpy (id, p,sizeof (*id)); p +=XDR_QUADLEN (NFS4_DEVICEID4_SIZE );print_deviceid (id);
@@ -468,32 +489,46 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo, __func__, nfl_util, fl->num_fh, fl->first_stripe_index, fl->pattern_offset); +if (!fl->num_fh) + goto out_err; + fl->fh_array =kzalloc (fl->num_fh *sizeof (struct nfs_fh *),GFP_KERNEL );if (!fl->fh_array) -return -ENOMEM ; + goto out_err;for (i =0 ; i < fl->num_fh; i++) {/* Do we want to use a mempool here? */ fl->fh_array[i] =kmalloc (sizeof (struct nfs_fh ),GFP_KERNEL ); -if (!fl->fh_array[i]) { -filelayout_free_fh_array (fl); -return -ENOMEM ; - } +if (!fl->fh_array[i]) + goto out_err_free; + + p =xdr_inline_decode (&stream,4 ); +if (unlikely (!p)) + goto out_err_free; fl->fh_array[i]->size =be32_to_cpup (p++);if (sizeof (struct nfs_fh ) < fl->fh_array[i]->size) {printk (KERN_ERR "Too big fh %d received %d\n" , i, fl->fh_array[i]->size); -filelayout_free_fh_array (fl); -return -EIO ; + goto out_err_free; } + + p =xdr_inline_decode (&stream, fl->fh_array[i]->size); +if (unlikely (!p)) + goto out_err_free;memcpy (fl->fh_array[i]->data, p, fl->fh_array[i]->size); - p +=XDR_QUADLEN (fl->fh_array[i]->size);dprintk ("DEBUG: %s: fh len %d\n" , __func__, fl->fh_array[i]->size); } +__free_page (scratch);return 0 ; + +out_err_free: +filelayout_free_fh_array (fl); +out_err: +__free_page (scratch); +return -EIO ; } static struct pnfs_layout_segment *
fs/nfs/nfs4filelayoutdev.c +124 -56
273 lines not on this page · raw message
fs/nfs/nfs4proc.c +1 -8
@@ -5460,8 +5460,6 @@ static void nfs4_layoutget_release(void *calldata)struct nfs4_layoutget *lgp = calldata;dprintk ("--> %s\n" , __func__); -if (lgp->res.layout.buf !=NULL ) -free_page ((unsigned long ) lgp->res.layout.buf);put_nfs_open_context (lgp->args.ctx);kfree (calldata);dprintk ("<-- %s\n" , __func__);
@@ -5493,12 +5491,7 @@ int nfs4_proc_layoutget(struct nfs4_layoutget *lgp)dprintk ("--> %s\n" , __func__); - lgp->res.layout.buf = (void *)__get_free_page (GFP_NOFS ); -if (lgp->res.layout.buf ==NULL ) { -nfs4_layoutget_release (lgp); -return -ENOMEM ; - } - + lgp->res.layoutp = &lgp->args.layout; lgp->res.seq_res.sr_slot =NULL ; task =rpc_run_task (&task_setup_data);if (IS_ERR (task))
fs/nfs/nfs4xdr.c +20 -10
@@ -2604,6 +2604,10 @@ static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,encode_sequence (xdr, &args->seq_args, &hdr);encode_putfh (xdr,NFS_FH (args->inode), &hdr);encode_layoutget (xdr, args, &hdr); + +xdr_inline_pages (&req->rq_rcv_buf, hdr.replen <<2 , + args->layout.pages,0 , args->layout.pglen); + encode_nops(&hdr); }#endif /* CONFIG_NFS_V4_1 */
@@ -4952,6 +4956,9 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,__be32 *p;int status;u32 layout_count; +struct xdr_buf *rcvbuf = &req->rq_rcv_buf; +struct kvec *iov = rcvbuf->head; +u32 hdrlen, recvd; status =decode_op_hdr (xdr,OP_LAYOUTGET );if (status)
@@ -4968,17 +4975,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,return -EINVAL ; } - p =xdr_inline_decode (xdr,24 ); + p =xdr_inline_decode (xdr,28 );if (unlikely (!p)) goto out_overflow; p =xdr_decode_hyper (p, &res->range.offset); p =xdr_decode_hyper (p, &res->range.length); res->range.iomode =be32_to_cpup (p++); res->type =be32_to_cpup (p++); - - status =decode_opaque_inline (xdr, &res->layout.len, (char **)&p); -if (unlikely (status)) -return status; + res->layoutp->len =be32_to_cpup (p); dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n", __func__,
@@ -4986,12 +4990,18 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, (unsigned long )res->range.length, res->range.iomode, res->type, - res->layout.len); + res->layoutp->len); + + hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; + recvd = req->rq_rcv_buf.len - hdrlen; +if (res->layoutp->len > recvd) { +dprintk ("NFS: server cheating in layoutget reply: " +"layout len %u > recvd %u\n" , + res->layoutp->len, recvd); +return -EINVAL ; + } -/* nfs4_proc_layoutget allocated a single page */ -if (res->layout.len >PAGE_SIZE ) -return -ENOMEM ; -memcpy (res->layout.buf, p, res->layout.len); +xdr_read_pages (xdr, res->layoutp->len);if (layout_count >1 ) {/* We only handle a length one array at the moment. Any
fs/nfs/pnfs.c +39 -0
@@ -471,6 +471,9 @@ send_layoutget(struct pnfs_layout_hdr *lo,struct nfs_server *server =NFS_SERVER (ino);struct nfs4_layoutget *lgp;struct pnfs_layout_segment *lseg =NULL ; +struct page **pages =NULL ; +int i; +u32 max_resp_sz, max_pages;dprintk ("--> %s\n" , __func__);
@@ -478,6 +481,21 @@ send_layoutget(struct pnfs_layout_hdr *lo, lgp =kzalloc (sizeof (*lgp),GFP_KERNEL );if (lgp ==NULL )return NULL ; + +/* allocate pages for xdr post processing */ + max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; + max_pages = max_resp_sz >>PAGE_SHIFT ; + + pages =kzalloc (max_pages *sizeof (struct page *),GFP_KERNEL ); +if (!pages) + goto out_err_free; + +for (i =0 ; i < max_pages; i++) { + pages[i] =alloc_page (GFP_KERNEL ); +if (!pages[i]) + goto out_err_free; + } + lgp->args.minlength =NFS4_MAX_UINT64 ; lgp->args.maxcount =PNFS_LAYOUT_MAXSIZE ; lgp->args.range.iomode = iomode;
@@ -486,6 +504,8 @@ send_layoutget(struct pnfs_layout_hdr *lo, lgp->args.type = server->pnfs_curr_ld->id; lgp->args.inode = ino; lgp->args.ctx =get_nfs_open_context (ctx); + lgp->args.layout.pages = pages; + lgp->args.layout.pglen = max_pages *PAGE_SIZE ; lgp->lsegpp = &lseg;/* Synchronously retrieve layout information from server and
@@ -496,7 +516,26 @@ send_layoutget(struct pnfs_layout_hdr *lo,/* remember that LAYOUTGET failed and suspend trying */ set_bit (lo_fail_bit (iomode), &lo->plh_flags); } + +/* free xdr pages */ +for (i =0 ; i < max_pages; i++) +__free_page (pages[i]); +kfree (pages); +return lseg; + +out_err_free: +/* free any allocated xdr pages, lgp as it's not used */ +if (pages) { +for (i =0 ; i < max_pages; i++) { +if (!pages[i]) +break ; +__free_page (pages[i]); + } +kfree (pages); + } +kfree (lgp); +return NULL ; }bool pnfs_roc (struct inode *ino)
fs/nfs/pnfs.h +0 -1
@@ -100,7 +100,6 @@ struct pnfs_device {unsigned int layout_type;unsigned int mincount;struct page **pages; -void *area;unsigned int pgbase;unsigned int pglen; };
include/linux/nfs_xdr.h +4 -2
@@ -190,8 +190,9 @@ struct nfs4_get_lease_time_res {#define PNFS_LAYOUT_MAXSIZE 4096struct nfs4_layoutdriver_data { +struct page **pages; +__u32 pglen;__u32 len; -void *buf; };struct pnfs_layout_range {
@@ -209,6 +210,7 @@ struct nfs4_layoutget_args {struct nfs_open_context *ctx;struct nfs4_sequence_args seq_args;nfs4_stateid stateid; +struct nfs4_layoutdriver_data layout; };struct nfs4_layoutget_res {
@@ -216,8 +218,8 @@ struct nfs4_layoutget_res {struct pnfs_layout_range range;__u32 type;nfs4_stateid stateid; -struct nfs4_layoutdriver_data layout;struct nfs4_sequence_res seq_res; +struct nfs4_layoutdriver_data *layoutp; };struct nfs4_layoutget {
Signature · 1 line
1.7.4.1
Quoted 59 lines · Weston Andros Adamson
fs/nfs/nfs4filelayoutdev.c +19
-10@@ -261,7 +261,7 @@ out:* Currently only support ipv4, and one multi-path address. */ static struct nfs4_pnfs_ds * -decode_and_add_ds (__be32 **pp,struct inode *inode) +decode_and_add_ds (struct xdr_stream *streamp,struct inode *inode) {struct nfs4_pnfs_ds *ds =NULL ;char *buf;@@ -269,25 +269,34 @@ decode_and_add_ds(__be32 **pp, struct inode *inode)u32 ip_addr, port;int nlen, rlen, i;int tmp[2 ]; -__be32 *r_netid, *r_addr, *p = *pp; +__be32 *p;/* r_netid */ + p =xdr_inline_decode (streamp,4 ); +if (unlikely (!p)) + goto out_err; nlen =be32_to_cpup (p++); - r_netid = p; - p +=XDR_QUADLEN (nlen); -/* r_addr */ - rlen =be32_to_cpup (p++); - r_addr = p; - p +=XDR_QUADLEN (rlen); - *pp = p; + p =xdr_inline_decode (streamp, nlen); +if (unlikely (!p)) + goto out_err;/* Check that netid is "tcp" */ -if (nlen !=3 ||memcmp ((char *)r_netid,"tcp" ,3 )) { +if (nlen !=3 ||memcmp ((char *)p,"tcp" ,3 )) {dprintk ("%s: ERROR: non ipv4 TCP r_netid\n" , __func__); goto out_err; } +/* r_addr */ + p =xdr_inline_decode (streamp,4 ); +if (unlikely (!p)) + goto out_err; + rlen =be32_to_cpup (p); + + p =xdr_inline_decode (streamp, rlen); +if (unlikely (!p)) + goto out_err; +/* ipv6 length plus port is legal */ if (rlen >INET6_ADDRSTRLEN +8 ) { dprintk("%s: Invalid address, length %d\n", __func__,@@ -295,8 +304,10 @@ decode_and_add_ds(__be32 **pp, struct inode *inode) goto out_err;
fs/nfs/nfs4filelayoutdev.c decode_and_add_ds(__be32 **pp, struct inode *inode) · line 313
Quoted 10 lines
fs/nfs/nfs4filelayoutdev.c +3
-1} buf =kmalloc (rlen +1 ,GFP_KERNEL ); +if (unlikely (!buf)) + goto out_err; buf[rlen] ='\0' ; -memcpy (buf, r_addr, rlen); +memcpy (buf, p, rlen);/* replace the port dots with dashes for the in4_pton() delimiter*/ for (i =0 ; i <2 ; i++) {
I had a small conflict with this last hunk due to an existing patch in the nfs-for-2.6.39 branch, but I think I've fixed it up correctly.
Please check the nfs-for-2.6.39 branch on
git://git.linux-nfs.org/projects/trondmy/nfs-2.6.git
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Looks good to me.
-dros
sd
Quoted 86 lines · Trond Myklebust
Quoted 59 lines · Weston Andros Adamson
fs/nfs/nfs4filelayoutdev.c +0
-0@@ -261,7 +261,7 @@ out:* Currently only support ipv4, and one multi-path address. */ static struct
nfs4_pnfs_ds*fs/nfs/nfs4filelayoutdev.c +1
-1-decode_and_add_ds(__be32 **pp, struct inode *inode) +decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode){ struct nfs4_pnfs_ds *ds = NULL; char *buf;fs/nfs/nfs4filelayoutdev.c +18
-9@@ -269,25 +269,34 @@ decode_and_add_ds(__be32 **pp, struct inode *inode)u32 ip_addr, port;int nlen, rlen, i;int tmp[2 ]; -__be32 *r_netid, *r_addr, *p = *pp; +__be32 *p;/* r_netid */ + p =xdr_inline_decode (streamp,4 ); +if (unlikely (!p)) + goto out_err; nlen =be32_to_cpup (p++); - r_netid = p; - p +=XDR_QUADLEN (nlen); -/* r_addr */ - rlen =be32_to_cpup (p++); - r_addr = p; - p +=XDR_QUADLEN (rlen); - *pp = p; + p =xdr_inline_decode (streamp, nlen); +if (unlikely (!p)) + goto out_err;/* Check that netid is "tcp" */ -if (nlen !=3 ||memcmp ((char *)r_netid,"tcp" ,3 )) { +if (nlen !=3 ||memcmp ((char *)p,"tcp" ,3 )) {dprintk ("%s: ERROR: non ipv4 TCP r_netid\n" , __func__); goto out_err; } +/* r_addr */ + p =xdr_inline_decode (streamp,4 ); +if (unlikely (!p)) + goto out_err; + rlen =be32_to_cpup (p); + + p =xdr_inline_decode (streamp, rlen); +if (unlikely (!p)) + goto out_err; +/* ipv6 length plus port is legal */ if (rlen >INET6_ADDRSTRLEN +8 ) { dprintk("%s: Invalid address, length %d\n", __func__,@@ -295,8 +304,10 @@ decode_and_add_ds(__be32 **pp, struct inode *inode) goto out_err;fs/nfs/nfs4filelayoutdev.c decode_and_add_ds(__be32 **pp, struct inode *inode) · line 313
Quoted 10 lines
fs/nfs/nfs4filelayoutdev.c +3
-1} buf =kmalloc (rlen +1 ,GFP_KERNEL ); +if (unlikely (!buf)) + goto out_err; buf[rlen] ='\0' ; -memcpy (buf, r_addr, rlen); +memcpy (buf, p, rlen);/* replace the port dots with dashes for the in4_pton() delimiter*/ for (i =0 ; i <2 ; i++) {I had a small conflict with this last hunk due to an existing patch in the nfs-for-2.6.39 branch, but I think I've fixed it up correctly.
Please check the nfs-for-2.6.39 branch on
git://git.linux-nfs.org/projects/trondmy/nfs-2.6.gitSignature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com