Linux NFS development
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH 03/27] NSM: Add xdr_stream-based XDR encoders
Date: Wed, 10 Dec 2008 16:15:52 -0500	[thread overview]
Message-ID: <20081210211552.GJ1212@fieldses.org> (raw)
In-Reply-To: <6EDE5D9B-9D02-436D-9BD8-4E4BB10E17E8@oracle.com>

On Wed, Dec 10, 2008 at 03:54:43PM -0500, Chuck Lever wrote:
> On Dec 10, 2008, at Dec 10, 2008, 3:35 PM, J. Bruce Fields wrote:
>> On Fri, Dec 05, 2008 at 07:02:15PM -0500, Chuck Lever wrote:
>>> Introduce xdr_stream-based XDR encoder functions.  These are more
>>> careful about preventing RPC buffer overflows.
>>
>> Looks fine, thanks; applied, with a superficial patch reorganization:
>> for once this is a patch I think is too small.
>>
>> My two rules of thumb:
>>
>> 	- Callers for new code should be added at the same time as the
>> 	  new code.
>>
>> 	  (Otherwise it's not possible to judge the single patch on its
>> 	  own, because you don't know whether the new (temporarily dead)
>> 	  code is correct until you see it called.)
>>
>> 	- When replacing code, I'd rather see the new code added in the
>> 	  same patch that removes the old code.
>>
>> 	  (Again, it's easier to judge the single patch on its own if
>> 	  you see the side-by-side old-to-new comparison.)
>
> OK... FYI, I broke it up this way because often when we do both in the  
> same patch, the diff is nearly impossible to read.
>
> The kernel patch rules I'm familiar with require that each patch should 
> not break the build or kernel operation, and should be as atomic as 
> possible.
>
>> Neither rule is an absolute.
>>
>> In this case I think squashing the following four patches gives a
>> reasonable result; I've applied the below (literally just the
>> composition of the four patches) instead of 3--7.
>
> This looks OK at first glance.
>
> In general making this kind of alteration means I can't do an automated 
> merge when I sync up with 2.6.29.  I will have to check over these 
> changes carefully to see that what I sent you is exactly what was 
> applied, and delete them each separately.
>
> This is an important reason I prefer to make this kind of change myself 
> and resend the patches -- it's one more insulator against operator 
> mistakes and bugs in our tools.  I wish there were a better way to handle 
> this case, but such are the tools we have been provided.

Hm.  Since the end result is exactly the same, this should be
mechanically verifiable, but yeah, I'm not sure which (if any) git tool
will do that in one go.

--b.

>
>> (If we were to split this up more finely, I'd consider doing encoders
>> separately from decoders, and/or SM_MON separately from SM_UNMON.)
>>
>> --b.
>>
>> commit fc88c50d16bbc43ab6a90107acbf45a0654d57ee
>> Author: Chuck Lever <chuck.lever@oracle.com>
>> Date:   Fri Dec 5 19:02:15 2008 -0500
>>
>>    NSM: move to xdr_stream-based XDR encoders and decoders
>>
>>    Introduce xdr_stream-based XDR encoder and decoder functions, which 
>> are
>>    more careful about preventing RPC buffer overflows.
>>
>>    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
>>    Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
>>
>> diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
>> index 0fc9836..81e1cc1 100644
>> --- a/fs/lockd/mon.c
>> +++ b/fs/lockd/mon.c
>> @@ -193,21 +193,26 @@ nsm_create(void)
>>  * Status Monitor wire protocol.
>>  */
>>
>> -static __be32 *xdr_encode_nsm_string(__be32 *p, char *string)
>> +static int encode_nsm_string(struct xdr_stream *xdr, const char  
>> *string)
>> {
>> -	size_t len = strlen(string);
>> -
>> -	if (len > SM_MAXSTRLEN)
>> -		len = SM_MAXSTRLEN;
>> -	return xdr_encode_opaque(p, string, len);
>> +	const u32 len = strlen(string);
>> +	__be32 *p;
>> +
>> +	if (unlikely(len > SM_MAXSTRLEN))
>> +		return -EIO;
>> +	p = xdr_reserve_space(xdr, sizeof(u32) + len);
>> +	if (unlikely(p == NULL))
>> +		return -EIO;
>> +	xdr_encode_opaque(p, string, len);
>> +	return 0;
>> }
>>
>> /*
>>  * "mon_name" specifies the host to be monitored.
>>  */
>> -static __be32 *xdr_encode_mon_name(__be32 *p, struct nsm_args *argp)
>> +static int encode_mon_name(struct xdr_stream *xdr, const struct  
>> nsm_args *argp)
>> {
>> -	return xdr_encode_nsm_string(p, argp->mon_name);
>> +	return encode_nsm_string(xdr, argp->mon_name);
>> }
>>
>> /*
>> @@ -216,30 +221,35 @@ static __be32 *xdr_encode_mon_name(__be32 *p,  
>> struct nsm_args *argp)
>>  * (via the NLMPROC_SM_NOTIFY call) that the state of host "mon_name"
>>  * has changed.
>>  */
>> -static __be32 *xdr_encode_my_id(__be32 *p, struct nsm_args *argp)
>> +static int encode_my_id(struct xdr_stream *xdr, const struct nsm_args 
>> *argp)
>> {
>> -	p = xdr_encode_nsm_string(p, utsname()->nodename);
>> -	if (!p)
>> -		return ERR_PTR(-EIO);
>> -
>> +	int status;
>> +	__be32 *p;
>> +
>> +	status = encode_nsm_string(xdr, utsname()->nodename);
>> +	if (unlikely(status != 0))
>> +		return status;
>> +	p = xdr_reserve_space(xdr, 3 * sizeof(u32));
>> +	if (unlikely(p == NULL))
>> +		return -EIO;
>> 	*p++ = htonl(argp->prog);
>> 	*p++ = htonl(argp->vers);
>> 	*p++ = htonl(argp->proc);
>> -
>> -	return p;
>> +	return 0;
>> }
>>
>> /*
>>  * The "mon_id" argument specifies the non-private arguments
>>  * of an NSMPROC_MON or NSMPROC_UNMON call.
>>  */
>> -static __be32 *xdr_encode_mon_id(__be32 *p, struct nsm_args *argp)
>> +static int encode_mon_id(struct xdr_stream *xdr, const struct  
>> nsm_args *argp)
>> {
>> -	p = xdr_encode_mon_name(p, argp);
>> -	if (!p)
>> -		return ERR_PTR(-EIO);
>> +	int status;
>>
>> -	return xdr_encode_my_id(p, argp);
>> +	status = encode_mon_name(xdr, argp);
>> +	if (unlikely(status != 0))
>> +		return status;
>> +	return encode_my_id(xdr, argp);
>> }
>>
>> /*
>> @@ -250,55 +260,71 @@ static __be32 *xdr_encode_mon_id(__be32 *p,  
>> struct nsm_args *argp)
>>  * Linux provides the raw IP address of the monitored host,
>>  * left in network byte order.
>>  */
>> -static __be32 *xdr_encode_priv(__be32 *p, struct nsm_args *argp)
>> +static int encode_priv(struct xdr_stream *xdr, const struct nsm_args 
>> *argp)
>> {
>> +	__be32 *p;
>> +
>> +	p = xdr_reserve_space(xdr, SM_PRIV_SIZE);
>> +	if (unlikely(p == NULL))
>> +		return -EIO;
>> 	*p++ = argp->addr;
>> 	*p++ = 0;
>> 	*p++ = 0;
>> 	*p++ = 0;
>> -
>> -	return p;
>> +	return 0;
>> }
>>
>> -static int
>> -xdr_encode_mon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args  
>> *argp)
>> +static int xdr_enc_mon(struct rpc_rqst *req, __be32 *p,
>> +		       const struct nsm_args *argp)
>> {
>> -	p = xdr_encode_mon_id(p, argp);
>> -	if (IS_ERR(p))
>> -		return PTR_ERR(p);
>> -
>> -	p = xdr_encode_priv(p, argp);
>> -	if (IS_ERR(p))
>> -		return PTR_ERR(p);
>> +	struct xdr_stream xdr;
>> +	int status;
>>
>> -	rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
>> -	return 0;
>> +	xdr_init_encode(&xdr, &req->rq_snd_buf, p);
>> +	status = encode_mon_id(&xdr, argp);
>> +	if (unlikely(status))
>> +		return status;
>> +	return encode_priv(&xdr, argp);
>> }
>>
>> -static int
>> -xdr_encode_unmon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args  
>> *argp)
>> +static int xdr_enc_unmon(struct rpc_rqst *req, __be32 *p,
>> +			 const struct nsm_args *argp)
>> {
>> -	p = xdr_encode_mon_id(p, argp);
>> -	if (IS_ERR(p))
>> -		return PTR_ERR(p);
>> -	rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
>> -	return 0;
>> +	struct xdr_stream xdr;
>> +
>> +	xdr_init_encode(&xdr, &req->rq_snd_buf, p);
>> +	return encode_mon_id(&xdr, argp);
>> }
>>
>> -static int
>> -xdr_decode_stat_res(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res 
>> *resp)
>> +static int xdr_dec_stat_res(struct rpc_rqst *rqstp, __be32 *p,
>> +			    struct nsm_res *resp)
>> {
>> +	struct xdr_stream xdr;
>> +
>> +	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
>> +	p = xdr_inline_decode(&xdr, 2 * sizeof(u32));
>> +	if (unlikely(p == NULL))
>> +		return -EIO;
>> 	resp->status = ntohl(*p++);
>> -	resp->state = ntohl(*p++);
>> -	dprintk("nsm: xdr_decode_stat_res status %d state %d\n",
>> +	resp->state = ntohl(*p);
>> +
>> +	dprintk("lockd: xdr_dec_stat_res status %d state %d\n",
>> 			resp->status, resp->state);
>> 	return 0;
>> }
>>
>> -static int
>> -xdr_decode_stat(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res  
>> *resp)
>> +static int xdr_dec_stat(struct rpc_rqst *rqstp, __be32 *p,
>> +			struct nsm_res *resp)
>> {
>> -	resp->state = ntohl(*p++);
>> +	struct xdr_stream xdr;
>> +
>> +	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
>> +	p = xdr_inline_decode(&xdr, sizeof(u32));
>> +	if (unlikely(p == NULL))
>> +		return -EIO;
>> +	resp->state = ntohl(*p);
>> +
>> +	dprintk("lockd: xdr_dec_stat state %d\n", resp->state);
>> 	return 0;
>> }
>>
>> @@ -314,8 +340,8 @@ xdr_decode_stat(struct rpc_rqst *rqstp, __be32 *p, 
>> struct nsm_res *resp)
>> static struct rpc_procinfo	nsm_procedures[] = {
>> [NSMPROC_MON] = {
>> 		.p_proc		= NSMPROC_MON,
>> -		.p_encode	= (kxdrproc_t) xdr_encode_mon,
>> -		.p_decode	= (kxdrproc_t) xdr_decode_stat_res,
>> +		.p_encode	= (kxdrproc_t)xdr_enc_mon,
>> +		.p_decode	= (kxdrproc_t)xdr_dec_stat_res,
>> 		.p_arglen	= SM_mon_sz,
>> 		.p_replen	= SM_monres_sz,
>> 		.p_statidx	= NSMPROC_MON,
>> @@ -323,8 +349,8 @@ static struct rpc_procinfo	nsm_procedures[] = {
>> 	},
>> [NSMPROC_UNMON] = {
>> 		.p_proc		= NSMPROC_UNMON,
>> -		.p_encode	= (kxdrproc_t) xdr_encode_unmon,
>> -		.p_decode	= (kxdrproc_t) xdr_decode_stat,
>> +		.p_encode	= (kxdrproc_t)xdr_enc_unmon,
>> +		.p_decode	= (kxdrproc_t)xdr_dec_stat,
>> 		.p_arglen	= SM_mon_id_sz,
>> 		.p_replen	= SM_unmonres_sz,
>> 		.p_statidx	= NSMPROC_UNMON,
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-nfs"  
>> in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> -- 
> Chuck Lever
> chuck[dot]lever[at]oracle[dot]com
>
>
>
>

  reply	other threads:[~2008-12-10 21:15 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-06  0:01 [PATCH 00/27] Remaining IPv6 NSM patches for 2.6.29 Chuck Lever
     [not found] ` <20081205235557.24075.12511.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-06  0:01   ` [PATCH 01/27] NSM: Move NSM-related XDR data structures to lockd's xdr.h Chuck Lever
2008-12-06  0:02   ` [PATCH 02/27] NSM: Move NSM program and procedure numbers to fs/lockd/mon.c Chuck Lever
     [not found]     ` <20081206000206.24075.32502.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 20:09       ` J. Bruce Fields
2008-12-06  0:02   ` [PATCH 03/27] NSM: Add xdr_stream-based XDR encoders Chuck Lever
     [not found]     ` <20081206000214.24075.58074.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 20:35       ` J. Bruce Fields
2008-12-10 20:36         ` J. Bruce Fields
2008-12-10 20:54         ` Chuck Lever
2008-12-10 21:15           ` J. Bruce Fields [this message]
2008-12-06  0:02   ` [PATCH 04/27] " Chuck Lever
2008-12-06  0:02   ` [PATCH 05/27] NSM: Switch over to the new-style XDR functions Chuck Lever
2008-12-06  0:02   ` [PATCH 06/27] NSM: Remove unused old-style " Chuck Lever
2008-12-06  0:02   ` [PATCH 07/27] NSM: Move nsm_find() to fs/lockd/mon.c Chuck Lever
     [not found]     ` <20081206000244.24075.75258.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 20:58       ` J. Bruce Fields
2008-12-10 21:08         ` Chuck Lever
2008-12-06  0:02   ` [PATCH 08/27] NSM: Add dprintk() calls in nsm_find and nsm_release Chuck Lever
     [not found]     ` <20081206000252.24075.51827.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 21:05       ` J. Bruce Fields
2008-12-10 21:10         ` Chuck Lever
2008-12-10 21:14           ` J. Bruce Fields
2008-12-06  0:03   ` [PATCH 09/27] NSM: Remove NULL pointer check from nsm_find() Chuck Lever
2008-12-06  0:03   ` [PATCH 10/27] NSM: Remove !nsm check from nsm_release() Chuck Lever
     [not found]     ` <20081206000308.24075.73629.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 21:11       ` J. Bruce Fields
2008-12-06  0:03   ` [PATCH 11/27] NSM: Generate NSMPROC_MON's "priv" argument when nsm_handle is created Chuck Lever
2008-12-06  0:03   ` [PATCH 12/27] NSM: Encode the new "priv" cookie for NSMPROC_MON requests Chuck Lever
2008-12-06  0:03   ` [PATCH 13/27] NLM: Change nlm_host_rebooted() to take a single nlm_reboot argument Chuck Lever
2008-12-06  0:03   ` [PATCH 14/27] NLM: Decode "priv" argument of NLMPROC_SM_NOTIFY as an opaque Chuck Lever
     [not found]     ` <20081206000338.24075.50442.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 22:29       ` J. Bruce Fields
2008-12-06  0:03   ` [PATCH 15/27] NSM: Add nsm_lookup() function Chuck Lever
     [not found]     ` <20081206000346.24075.23426.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 22:58       ` J. Bruce Fields
2008-12-06  0:03   ` [PATCH 16/27] NLM: Call nsm_reboot_lookup() instead of nsm_find() Chuck Lever
2008-12-06  0:04   ` [PATCH 17/27] NLM: Remove "create" argument from nsm_find() Chuck Lever
     [not found]     ` <20081206000401.24075.77127.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 23:00       ` J. Bruce Fields
2008-12-06  0:04   ` [PATCH 18/27] NSM: Refactor nsm_handle creation into a helper function Chuck Lever
     [not found]     ` <20081206000409.24075.37859.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 23:28       ` J. Bruce Fields
2008-12-11 17:09         ` Chuck Lever
2008-12-11 18:53           ` J. Bruce Fields
2008-12-06  0:04   ` [PATCH 19/27] NSM: More clean up of nsm_get_handle() Chuck Lever
2008-12-06  0:04   ` [PATCH 20/27] NSM: Replace IP address as our nlm_reboot lookup key Chuck Lever
     [not found]     ` <20081206000424.24075.72384.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-10 23:43       ` J. Bruce Fields
2008-12-11 16:20         ` Chuck Lever
2008-12-06  0:04   ` [PATCH 21/27] NSM: Remove include/linux/lockd/sm_inter.h Chuck Lever
2008-12-06  0:04   ` [PATCH 22/27] NSM: Move nsm_addr() to fs/lockd/mon.c Chuck Lever
2008-12-06  0:04   ` [PATCH 23/27] NSM: Move nsm_use_hostnames to mon.c Chuck Lever
2008-12-06  0:04   ` [PATCH 24/27] NSM: Move nsm_create() Chuck Lever
2008-12-06  0:05   ` [PATCH 25/27] NLM: nlm_privileged_requester() doesn't recognize mapped loopback address Chuck Lever
2008-12-06  0:05   ` [PATCH 26/27] NLM: Rewrite IPv4 privileged requester's check Chuck Lever
2008-12-06  0:05   ` [PATCH 27/27] lockd: Enable NLM use of AF_INET6 Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081210211552.GJ1212@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox