Skip to contentSkip to conversation

mountd.nfs: Better error diagnostics for the mount command (take 3)

PATCH In review Steve Dickson 1 participant 4 messages Jun 3, 2010 – Jun 22, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mountd.nfs: Better error diagnostics for the mount command (take 3)

[I've incorporated the last few code review comments]

The following two patches add better error diagnostics when invalid option values are given and when the network protocol can not be determined.

Steve Dickson (2):
mount: silently fails when bad option values are given mount.nfs: silently fails when the network protocol is not found

 utils/mount/network.c   |   59 ++++++++++++++++++++++++++++++++++++----------
 utils/mount/nfsumount.c |    4 +--
 utils/mount/stropts.c   |   16 ++++++++----
 3 files changed, 58 insertions(+), 21 deletions(-)
#1 lore raw

PATCH 1/2 mount: silently fails when bad option values are given

mount.nfs should not only fail when an invalid option values are supplied (as it does), it should also print a diagnostic message identifying the problem

---
 utils/mount/network.c   |   29 +++++++++++++++++++++++++----
 utils/mount/nfsumount.c |    4 +---
 2 files changed, 26 insertions(+), 7 deletions(-)
utils/mount/network.c +25 -4
index c541257..b08ce80 100644
@@ -1211,7 +1211,10 @@ nfs_nfs_program(struct mount_options *options, unsigned long *program)
 			*program = tmp;
 			return 1;
 		}
+	/* FALLTHRU */
 	case PO_BAD_VALUE:
+		nfs_error(_("%s: invalid value for 'nfsprog=' option"),
+				progname);
 		return 0;
 	}
 
@@ -1249,11 +1252,14 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
 				*version = tmp;
 				return 1;
 			}
+		/* FALLTHRU */
+		case PO_BAD_VALUE:
+			nfs_error(_("%s: invalid value for 'vers=' option"),
+					progname);
 			return 0;
 		case PO_NOT_FOUND:
-			nfs_error(_("%s: option parsing error\n"),
+			nfs_error(_("%s: parsing error on 'vers=' option\n"),
 					progname);
-		case PO_BAD_VALUE:
 			return 0;
 		}
 	case 4: /* nfsvers */
@@ -1263,11 +1269,14 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
 				*version = tmp;
 				return 1;
 			}
+		/* FALLTHRU */
+		case PO_BAD_VALUE:
+			nfs_error(_("%s: invalid value for 'nfsvers=' option"),
+					progname);
 			return 0;
 		case PO_NOT_FOUND:
-			nfs_error(_("%s: option parsing error\n"),
+			nfs_error(_("%s: parsing error on 'nfsvers=' option\n"),
 					progname);
-		case PO_BAD_VALUE:
 			return 0;
 		}
 	}
@@ -1335,7 +1344,10 @@ nfs_nfs_port(struct mount_options *options, unsigned long *port)
 			*port = tmp;
 			return 1;
 		}
+	/* FALLTHRU */
 	case PO_BAD_VALUE:
+		nfs_error(_("%s: invalid value for 'port=' option"),
+				progname);
 		return 0;
 	}
 
@@ -1422,7 +1434,10 @@ nfs_mount_program(struct mount_options *options, unsigned long *program)
 			*program = tmp;
 			return 1;
 		}
+	/* FALLTHRU */
 	case PO_BAD_VALUE:
+		nfs_error(_("%s: invalid value for 'mountprog=' option"),
+				progname);
 		return 0;
 	}
 
@@ -1451,7 +1466,10 @@ nfs_mount_version(struct mount_options *options, unsigned long *version)
 			*version = tmp;
 			return 1;
 		}
+	/* FALLTHRU */
 	case PO_BAD_VALUE:
+		nfs_error(_("%s: invalid value for 'mountvers=' option"),
+				progname);
 		return 0;
 	}
 
@@ -1509,7 +1527,10 @@ nfs_mount_port(struct mount_options *options, unsigned long *port)
 			*port = tmp;
 			return 1;
 		}
+	/* FALLTHRU */
 	case PO_BAD_VALUE:
+		nfs_error(_("%s: invalid value for 'mountport=' option"),
+				progname);
 		return 0;
 	}
 
utils/mount/nfsumount.c +1 -3
index 9d798a2..1514340 100644
@@ -179,10 +179,8 @@ static int nfs_umount_do_umnt(struct mount_options *options,
 	struct pmap nfs_pmap, mnt_pmap;
 	sa_family_t family;
 
-	if (!nfs_options2pmap(options, &nfs_pmap, &mnt_pmap)) {
-		nfs_error(_("%s: bad mount options"), progname);
+	if (!nfs_options2pmap(options, &nfs_pmap, &mnt_pmap))
 		return EX_FAIL;
-	}
 
 	/* Skip UMNT call for vers=4 mounts */
 	if (nfs_pmap.pm_vers == 4)
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH 2/2 mount.nfs: silently fails when the network protocol is not found

In reply to Steve Dickson

mount.nfs should display some type of error diagnostics when the network protocol can not be determined.

---
 utils/mount/network.c |   30 +++++++++++++++++++++---------
 utils/mount/stropts.c |   16 +++++++++++-----
 2 files changed, 32 insertions(+), 14 deletions(-)
utils/mount/network.c +21 -9
index b08ce80..7c28869 100644
@@ -1312,6 +1312,8 @@ nfs_nfs_protocol(struct mount_options *options, unsigned long *protocol)
 		if (option != NULL) {
 			if (!nfs_get_proto(option, &family, protocol)) {
 				errno = EPROTONOSUPPORT;
+				nfs_error(_("%s: Failed to find '%s' protocol"), 
+					progname, option);
 				return 0;
 			}
 			return 1;
@@ -1401,8 +1403,13 @@ int nfs_nfs_proto_family(struct mount_options *options,
 	case 2: /* proto */
 		option = po_get(options, "proto");
 		if (option != NULL &&
-		    !nfs_get_proto(option, &tmp_family, &protocol))
-			goto out_err;
+		    !nfs_get_proto(option, &tmp_family, &protocol)) {
+
+			nfs_error(_("%s: Failed to find '%s' protocol"), 
+				progname, option);
+			errno = EPROTONOSUPPORT;
+			return 0;
+		}
 	}
 
 	if (!nfs_verify_family(tmp_family))
@@ -1495,6 +1502,8 @@ nfs_mount_protocol(struct mount_options *options, unsigned long *protocol)
 	option = po_get(options, "mountproto");
 	if (option != NULL) {
 		if (!nfs_get_proto(option, &family, protocol)) {
+			nfs_error(_("%s: Failed to find '%s' protocol"), 
+				progname, option);
 			errno = EPROTONOSUPPORT;
 			return 0;
 		}
@@ -1556,10 +1565,16 @@ int nfs_mount_proto_family(struct mount_options *options,
 
 	option = po_get(options, "mountproto");
 	if (option != NULL) {
-		if (!nfs_get_proto(option, &tmp_family, &protocol))
-			goto out_err;
-		if (!nfs_verify_family(tmp_family))
-			goto out_err;
+		if (!nfs_get_proto(option, &tmp_family, &protocol)) {
+			nfs_error(_("%s: Failed to find '%s' protocol"), 
+				progname, option);
+			errno = EPROTONOSUPPORT;
+			return 0;
+		}
+		if (!nfs_verify_family(tmp_family)) {
+			errno = EAFNOSUPPORT;
+			return 0;
+		}
 		*family = tmp_family;
 		return 1;
 	}
@@ -1571,9 +1586,6 @@ int nfs_mount_proto_family(struct mount_options *options,
 	 * NFS.
 	 */
 	return nfs_nfs_proto_family(options, family);
-out_err:
-	errno = EAFNOSUPPORT;
-	return 0;
 }
 
 /**
utils/mount/stropts.c +11 -5
index 98557d2..0241400 100644
@@ -538,7 +538,10 @@ nfs_rewrite_pmap_mount_options(struct mount_options *options)
 
 	if (!nfs_construct_new_options(options, nfs_saddr, &nfs_pmap,
 					mnt_saddr, &mnt_pmap)) {
-		errno = EINVAL;
+		if (rpc_createerr.cf_stat == RPC_UNKNOWNPROTO)
+			errno = EPROTONOSUPPORT;
+		else
+			errno = EINVAL;
 		return 0;
 	}
 
@@ -586,18 +589,21 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		errno = ENOMEM;
 		return result;
 	}
-
+	errno = 0;
 	if (!nfs_append_addr_option(sap, salen, options)) {
-		errno = EINVAL;
+		if (errno == 0)
+			errno = EINVAL;
 		goto out_fail;
 	}
 
 	if (!nfs_fix_mounthost_option(options, mi->hostname)) {
-		errno = EINVAL;
+		if (errno == 0)
+			errno = EINVAL;
 		goto out_fail;
 	}
 	if (!mi->fake && !nfs_verify_lock_option(options)) {
-		errno = EINVAL;
+		if (errno == 0)
+			errno = EINVAL;
 		goto out_fail;
 	}
 
Signature · 1 line
1.6.5.2
#3 lore raw
In reply to Steve Dickson
Quoted 15 lines · Steve Dickson

[I've incorporated the last few code review comments]

The following two patches add better error diagnostics when invalid option values are given and when the network protocol can not be determined.

Steve Dickson (2):
mount: silently fails when bad option values are given mount.nfs: silently fails when the network protocol is not found

 utils/mount/network.c   |   59 ++++++++++++++++++++++++++++++++++++----------
 utils/mount/nfsumount.c |    4 +--
 utils/mount/stropts.c   |   16 ++++++++----
 3 files changed, 58 insertions(+), 21 deletions(-)
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Committed...

steved.