All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Gmeiner <christian.gmeiner@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/4] nfs: factor out generic reply error handling
Date: Mon,  1 Oct 2018 11:46:44 +0200	[thread overview]
Message-ID: <20181001094646.11539-2-christian.gmeiner@gmail.com> (raw)
In-Reply-To: <20181001094646.11539-1-christian.gmeiner@gmail.com>

From: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>
---
 net/nfs.c | 93 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 51 insertions(+), 42 deletions(-)

diff --git a/net/nfs.c b/net/nfs.c
index 81c08de626..d3de9b8c38 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -440,6 +440,54 @@ static void nfs_send(void)
 Handlers for the reply from server
 **************************************************************************/
 
+static int rpc_handle_error(struct rpc_t *rpc_pkt)
+{
+	if (rpc_pkt->u.reply.rstatus  ||
+	    rpc_pkt->u.reply.verifier ||
+	    rpc_pkt->u.reply.astatus  ||
+	    rpc_pkt->u.reply.data[0]) {
+		switch (ntohl(rpc_pkt->u.reply.astatus)) {
+		case NFS_RPC_SUCCESS: /* Not an error */
+			break;
+		case NFS_RPC_PROG_MISMATCH: {
+			/* Remote can't support NFS version */
+			const int min = ntohl(rpc_pkt->u.reply.data[0]);
+			const int max = ntohl(rpc_pkt->u.reply.data[1]);
+
+			if (max < NFS_V2 || max > NFS_V3 || min > NFS_V3) {
+				puts("*** ERROR: NFS version not supported");
+				debug(": Requested: V%d, accepted: min V%d - max V%d\n",
+				      choosen_nfs_version,
+				      ntohl(rpc_pkt->u.reply.data[0]),
+				      ntohl(rpc_pkt->u.reply.data[1]));
+				puts("\n");
+				choosen_nfs_version = NFS_UNKOWN;
+				break;
+			}
+
+			debug("*** Warning: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n",
+					choosen_nfs_version,
+					ntohl(rpc_pkt->u.reply.data[0]),
+					ntohl(rpc_pkt->u.reply.data[1]));
+			debug("Will retry with NFSv%d\n", min);
+			choosen_nfs_version = min;
+			return -NFS_RPC_PROG_MISMATCH;
+		}
+		case NFS_RPC_PROG_UNAVAIL:
+		case NFS_RPC_PROC_UNAVAIL:
+		case NFS_RPC_GARBAGE_ARGS:
+		case NFS_RPC_SYSTEM_ERR:
+		default: /* Unknown error on 'accept state' flag */
+			debug("*** ERROR: accept state error (%d)\n",
+			      ntohl(rpc_pkt->u.reply.astatus));
+			break;
+		}
+		return -1;
+	}
+
+	return 0;
+}
+
 static int rpc_lookup_reply(int prog, uchar *pkt, unsigned len)
 {
 	struct rpc_t rpc_pkt;
@@ -533,48 +581,9 @@ static int nfs_lookup_reply(uchar *pkt, unsigned len)
 	else if (ntohl(rpc_pkt.u.reply.id) < rpc_id)
 		return -NFS_RPC_DROP;
 
-	if (rpc_pkt.u.reply.rstatus  ||
-	    rpc_pkt.u.reply.verifier ||
-	    rpc_pkt.u.reply.astatus  ||
-	    rpc_pkt.u.reply.data[0]) {
-		switch (ntohl(rpc_pkt.u.reply.astatus)) {
-		case NFS_RPC_SUCCESS: /* Not an error */
-			break;
-		case NFS_RPC_PROG_MISMATCH: {
-			/* Remote can't support NFS version */
-			const int min = ntohl(rpc_pkt.u.reply.data[0]);
-			const int max = ntohl(rpc_pkt.u.reply.data[1]);
-
-			if (max < NFS_V2 || max > NFS_V3 || min > NFS_V3) {
-				puts("*** ERROR: NFS version not supported");
-				debug(": Requested: V%d, accepted: min V%d - max V%d\n",
-				      choosen_nfs_version,
-				      ntohl(rpc_pkt.u.reply.data[0]),
-				      ntohl(rpc_pkt.u.reply.data[1]));
-				puts("\n");
-				choosen_nfs_version = NFS_UNKOWN;
-				break;
-			}
-
-			debug("*** Warning: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n",
-					choosen_nfs_version,
-					ntohl(rpc_pkt.u.reply.data[0]),
-					ntohl(rpc_pkt.u.reply.data[1]));
-			debug("Will retry with NFSv%d\n", min);
-			choosen_nfs_version = min;
-			return -NFS_RPC_PROG_MISMATCH;
-		}
-		case NFS_RPC_PROG_UNAVAIL:
-		case NFS_RPC_PROC_UNAVAIL:
-		case NFS_RPC_GARBAGE_ARGS:
-		case NFS_RPC_SYSTEM_ERR:
-		default: /* Unknown error on 'accept state' flag */
-			debug("*** ERROR: accept state error (%d)\n",
-			      ntohl(rpc_pkt.u.reply.astatus));
-			break;
-		}
-		return -1;
-	}
+	int ret =  rpc_handle_error(&rpc_pkt);
+	if (ret)
+		return ret;
 
 	if (choosen_nfs_version == NFS_V2) {
 		memcpy(filefh, rpc_pkt.u.reply.data + 1, NFS_FHSIZE);
-- 
2.17.1

  reply	other threads:[~2018-10-01  9:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01  9:46 [U-Boot] [PATCH 1/4] nfs: convert supported_nfs_versions bitfield to an enum Christian Gmeiner
2018-10-01  9:46 ` Christian Gmeiner [this message]
2018-10-01  9:46 ` [U-Boot] [PATCH 3/4] nfs: handle rpc errors for mount calls Christian Gmeiner
2018-10-01  9:46 ` [U-Boot] [PATCH 4/4] net: add NFSv1 support Christian Gmeiner
2018-10-01 13:08 ` [U-Boot] [PATCH 1/4] nfs: convert supported_nfs_versions bitfield to an enum Wolfgang Denk
2018-10-01 13:56   ` Christian Gmeiner
2018-10-22 18:53     ` Joe Hershberger
2018-10-22 19:39       ` Simon Goldschmidt
2018-10-29 20:05         ` Joe Hershberger
2018-10-29 22:13           ` Tom Rini
2018-10-30  8:46           ` Wolfgang Denk
2018-10-30  8:53             ` Simon Goldschmidt

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=20181001094646.11539-2-christian.gmeiner@gmail.com \
    --to=christian.gmeiner@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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.