All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: trond.myklebust@netapp.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 08/12] NSM: Avoid return code checking in NSM XDR encoder functions
Date: Wed, 17 Nov 2010 13:01:04 -0500	[thread overview]
Message-ID: <20101117180104.29429.36095.stgit@matisse.1015granger.net> (raw)
In-Reply-To: <20101117175317.29429.90956.stgit@matisse.1015granger.net>

Clean up.

The trend in the other XDR encoder functions is to BUG() when encoding
problems occur, since a problem is always due to a local coding error.
Then, instead of a status, zero is unconditionally returned.

Update the NSM XDR encoders to behave this way.

To finish the update, use the new-style ntohl() and htonl() macros,
and compute the buffer sizes using raw integers instead of sizeof().
This matches the conventions used in other XDR functions

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: J. Bruce Fields <bfields@redhat.com>
---

 fs/lockd/mon.c |   68 +++++++++++++++++++++-----------------------------------
 1 files changed, 25 insertions(+), 43 deletions(-)

diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index e0c9189..d812818 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -401,26 +401,22 @@ void nsm_release(struct nsm_handle *nsm)
  * Status Monitor wire protocol.
  */
 
-static int encode_nsm_string(struct xdr_stream *xdr, const char *string)
+static void encode_nsm_string(struct xdr_stream *xdr, const char *string)
 {
 	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;
+	BUG_ON(len > SM_MAXSTRLEN);
+	p = xdr_reserve_space(xdr, 4 + len);
 	xdr_encode_opaque(p, string, len);
-	return 0;
 }
 
 /*
  * "mon_name" specifies the host to be monitored.
  */
-static int encode_mon_name(struct xdr_stream *xdr, const struct nsm_args *argp)
+static void encode_mon_name(struct xdr_stream *xdr, const struct nsm_args *argp)
 {
-	return encode_nsm_string(xdr, argp->mon_name);
+	encode_nsm_string(xdr, argp->mon_name);
 }
 
 /*
@@ -429,35 +425,25 @@ static int encode_mon_name(struct xdr_stream *xdr, const struct nsm_args *argp)
  * (via the NLMPROC_SM_NOTIFY call) that the state of host "mon_name"
  * has changed.
  */
-static int encode_my_id(struct xdr_stream *xdr, const struct nsm_args *argp)
+static void encode_my_id(struct xdr_stream *xdr, const struct nsm_args *argp)
 {
-	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 0;
+	encode_nsm_string(xdr, utsname()->nodename);
+	p = xdr_reserve_space(xdr, 4 + 4 + 4);
+	*p++ = cpu_to_be32(argp->prog);
+	*p++ = cpu_to_be32(argp->vers);
+	*p = cpu_to_be32(argp->proc);
 }
 
 /*
  * The "mon_id" argument specifies the non-private arguments
  * of an NSMPROC_MON or NSMPROC_UNMON call.
  */
-static int encode_mon_id(struct xdr_stream *xdr, const struct nsm_args *argp)
+static void encode_mon_id(struct xdr_stream *xdr, const struct nsm_args *argp)
 {
-	int status;
-
-	status = encode_mon_name(xdr, argp);
-	if (unlikely(status != 0))
-		return status;
-	return encode_my_id(xdr, argp);
+	encode_mon_name(xdr, argp);
+	encode_my_id(xdr, argp);
 }
 
 /*
@@ -465,28 +451,23 @@ static int encode_mon_id(struct xdr_stream *xdr, const struct nsm_args *argp)
  * by the NSMPROC_MON call. This information will be supplied in the
  * NLMPROC_SM_NOTIFY call.
  */
-static int encode_priv(struct xdr_stream *xdr, const struct nsm_args *argp)
+static void 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;
 	xdr_encode_opaque_fixed(p, argp->priv->data, SM_PRIV_SIZE);
-	return 0;
 }
 
 static int xdr_enc_mon(struct rpc_rqst *req, __be32 *p,
 		       const struct nsm_args *argp)
 {
 	struct xdr_stream xdr;
-	int status;
 
 	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);
+	encode_mon_id(&xdr, argp);
+	encode_priv(&xdr, argp);
+	return 0;
 }
 
 static int xdr_enc_unmon(struct rpc_rqst *req, __be32 *p,
@@ -495,7 +476,8 @@ static int xdr_enc_unmon(struct rpc_rqst *req, __be32 *p,
 	struct xdr_stream xdr;
 
 	xdr_init_encode(&xdr, &req->rq_snd_buf, p);
-	return encode_mon_id(&xdr, argp);
+	encode_mon_id(&xdr, argp);
+	return 0;
 }
 
 static int xdr_dec_stat_res(struct rpc_rqst *rqstp, __be32 *p,
@@ -504,11 +486,11 @@ static int xdr_dec_stat_res(struct rpc_rqst *rqstp, __be32 *p,
 	struct xdr_stream xdr;
 
 	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
-	p = xdr_inline_decode(&xdr, 2 * sizeof(u32));
+	p = xdr_inline_decode(&xdr, 4 + 4);
 	if (unlikely(p == NULL))
 		return -EIO;
-	resp->status = ntohl(*p++);
-	resp->state = ntohl(*p);
+	resp->status = be32_to_cpup(p++);
+	resp->state = be32_to_cpup(p);
 
 	dprintk("lockd: xdr_dec_stat_res status %d state %d\n",
 			resp->status, resp->state);
@@ -521,10 +503,10 @@ static int xdr_dec_stat(struct rpc_rqst *rqstp, __be32 *p,
 	struct xdr_stream xdr;
 
 	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
-	p = xdr_inline_decode(&xdr, sizeof(u32));
+	p = xdr_inline_decode(&xdr, 4);
 	if (unlikely(p == NULL))
 		return -EIO;
-	resp->state = ntohl(*p);
+	resp->state = be32_to_cpup(p);
 
 	dprintk("lockd: xdr_dec_stat state %d\n", resp->state);
 	return 0;


  parent reply	other threads:[~2010-11-17 18:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17 17:59 [PATCH 00/12] Additional XDR clean-up Chuck Lever
2010-11-17 17:59 ` [PATCH 01/12] NFSD: Update XDR encoders in NFSv4 callback client Chuck Lever
     [not found]   ` <20101117175953.29429.43098.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2010-11-17 18:07     ` Benny Halevy
2010-11-17 18:37       ` Chuck Lever
2010-11-17 18:00 ` [PATCH 02/12] NFSD: Update XDR decoders " Chuck Lever
2010-11-17 18:00 ` [PATCH 03/12] NFS: Repair whitespace damage in NFS PROC macro Chuck Lever
2010-11-17 18:00 ` [PATCH 04/12] lockd: Move nlmdbg_cookie2a() to svclock.c Chuck Lever
2010-11-17 18:00 ` [PATCH 05/12] NFS: Fix hdrlen calculation in NFSv4's decode_read() Chuck Lever
2010-11-17 18:00 ` [PATCH 06/12] NFS: Simplify ->decode_dirent() calling sequence Chuck Lever
2010-11-17 18:00 ` [PATCH 07/12] NFS: Squelch compiler warning in decode_getdeviceinfo() Chuck Lever
2010-11-17 18:01 ` Chuck Lever [this message]
2010-11-17 18:01 ` [PATCH 09/12] NFS: Avoid return code checking in mount XDR encoder functions Chuck Lever
2010-11-17 18:01 ` [PATCH 10/12] SUNRPC: Avoid return code checking in rpcbind " Chuck Lever
2010-11-17 18:01 ` [PATCH 11/12] SUNRPC: New xdr_streams XDR encoder API Chuck Lever
2010-11-17 18:01 ` [PATCH 12/12] SUNRPC: New xdr_streams XDR decoder API 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=20101117180104.29429.36095.stgit@matisse.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@netapp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.