Skip to contentSkip to conversation

mountd.nfs: Better error diagnostics for the mount command

PATCH In review Steve Dickson 2 participants 8 messages Jun 2, 2010 – Jun 3, 2010 1 message not in the archive

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

cover mountd.nfs: Better error diagnostics for the mount command

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

Steve Dickson (2):
mount.nfs: silently fails with bad version arguments mount.nfs: silently fails when the network protocol is not found

 utils/mount/network.c |   21 +++++++++++++++++++--
 utils/mount/stropts.c |   16 +++++++++++-----
 2 files changed, 30 insertions(+), 7 deletions(-)
#1 lore raw

PATCH 1/2 mount.nfs: silently fails with bad version arguments

mount.nfs should not only fail when an invalid protocol option is used (as it does), it should also print a diagnostic identifying the problem.

---
 utils/mount/network.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
utils/mount/network.c +4 -0
index c541257..de1014d 100644
@@ -1254,6 +1254,8 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
 			nfs_error(_("%s: option parsing error\n"),
 					progname);
 		case PO_BAD_VALUE:
+			nfs_error(_("%s: invalid value for 'vers=' option"),
+					progname);
 			return 0;
 		}
 	case 4: /* nfsvers */
@@ -1268,6 +1270,8 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
 			nfs_error(_("%s: option parsing error\n"),
 					progname);
 		case PO_BAD_VALUE:
+			nfs_error(_("%s: invalid value for 'nfsvers=' option"),
+					progname);
 			return 0;
 		}
 	}
Signature · 1 line
1.6.6.1
#2 lore raw

Re: [PATCH 1/2] mount.nfs: silently fails with bad version arguments

Quoted 14 lines · Steve Dickson

mount.nfs should not only fail when an invalid protocol option is used (as it does), it should also print a diagnostic identifying the problem.

---
  utils/mount/network.c |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
utils/mount/network.c +0 -0
index c541257..de1014d 100644

utils/mount/network.c nfs_nfs_version(struct mount_options *options, unsigned long *version) · line 1255

Quoted 2 lines
utils/mount/network.c +0 -0
@@ -1254,6 +1254,8 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
  			nfs_error(_("%s: option parsing error\n"),
  					progname);

Watch out for case fall-through. You need to add:

			return 0;

here.

utils/mount/network.c nfs_nfs_version(struct mount_options *options, unsigned long *version) · line 1271

Quoted 9 lines
utils/mount/network.c +2 -0
  		case PO_BAD_VALUE:
+			nfs_error(_("%s: invalid value for 'vers=' option"),
+					progname);
  			return 0;
  		}
  	case 4: /* nfsvers */
@@ -1268,6 +1270,8 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
  			nfs_error(_("%s: option parsing error\n"),
  					progname);

Case fall-through here as well.

utils/mount/network.c nfs_nfs_version(struct mount_options *options, unsigned long *version) · line 1274

Quoted 3 lines
utils/mount/network.c +2 -0
  		case PO_BAD_VALUE:
+			nfs_error(_("%s: invalid value for 'nfsvers=' option"),
+					progname);

Why wouldn't you also print a diagnostic if a numeric value was used, but the value was out of range?

And, what about similar cases in nfs_nfs_port(), nfs_nfs_program(), nfs_mount_program(), nfs_mount_version(), and nfs_mount_port() ?

Quoted 3 lines
utils/mount/network.c +0 -0
  			return 0;
  		}
  	}
#3 lore raw

Re: [PATCH 1/2] mount.nfs: silently fails with bad version arguments

Quoted 21 lines · Chuck Lever
Quoted 14 lines · Steve Dickson

mount.nfs should not only fail when an invalid protocol option is used (as it does), it should also print a diagnostic identifying the problem.

---
  utils/mount/network.c |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
utils/mount/network.c +0 -0
index c541257..de1014d 100644

utils/mount/network.c nfs_nfs_version(struct mount_options *options, · line 1256

Quoted 3 lines
utils/mount/network.c +0 -0
@@ -1254,6 +1254,8 @@ nfs_nfs_version(struct mount_options *options,
 unsigned long *version)
              nfs_error(_("%s: option parsing error\n"),
                      progname);

Watch out for case fall-through. You need to add:

Quoted 3 lines
            return 0;

here.

Ah I didn't see that... good catch...

Quoted 14 lines

utils/mount/network.c nfs_nfs_version(struct mount_options *options, · line 1272

Quoted 11 lines
utils/mount/network.c +2 -0
          case PO_BAD_VALUE:
+            nfs_error(_("%s: invalid value for 'vers=' option"),
+                    progname);
              return 0;
          }
      case 4: /* nfsvers */
utils/mount/network.c +0 -0
@@ -1268,6 +1270,8 @@ nfs_nfs_version(struct mount_options *options,
 unsigned long *version)
              nfs_error(_("%s: option parsing error\n"),
                      progname);

Case fall-through here as well.

Quoted 6 lines

utils/mount/network.c nfs_nfs_version(struct mount_options *options, unsigned long *version) · line 1274

Quoted 3 lines
utils/mount/network.c +2 -0
          case PO_BAD_VALUE:
+            nfs_error(_("%s: invalid value for 'nfsvers=' option"),
+                    progname);

Why wouldn't you also print a diagnostic if a numeric value was used, but the value was out of range?

It did not appear there was any guarantee that &tmp would have been filled with anything useful, especially with something like nfsvers=v3 is given.

Quoted 3 lines

And, what about similar cases in nfs_nfs_port(), nfs_nfs_program(), nfs_mount_program(), nfs_mount_version(), and nfs_mount_port() ?

I was just looking at the version and protocol options and I really didn't want to make things too verbose. Meaning we don't need to be printing two or three messages for one error...

But I do see the need of going back and taking a good hard look at all the diagnostics that do (and do not) come out of the mount command in error conditions... since it appears the diagnostics messages are a bit light at times..

steved.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Re: [PATCH 1/2] mount.nfs: silently fails with bad version arguments

Quoted 52 lines · Steve Dickson
Quoted 21 lines · Chuck Lever
Quoted 14 lines · Steve Dickson

mount.nfs should not only fail when an invalid protocol option is used (as it does), it should also print a diagnostic identifying the problem.

---
  utils/mount/network.c |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
utils/mount/network.c +0 -0
index c541257..de1014d 100644

utils/mount/network.c nfs_nfs_version(struct mount_options *options, · line 1256

Quoted 3 lines
utils/mount/network.c +0 -0
@@ -1254,6 +1254,8 @@ nfs_nfs_version(struct mount_options *options,
 unsigned long *version)
              nfs_error(_("%s: option parsing error\n"),
                      progname);

Watch out for case fall-through. You need to add:

Quoted 3 lines
            return 0;

here.

Ah I didn't see that... good catch...

Quoted 14 lines

utils/mount/network.c nfs_nfs_version(struct mount_options *options, · line 1272

Quoted 11 lines
utils/mount/network.c +2 -0
          case PO_BAD_VALUE:
+            nfs_error(_("%s: invalid value for 'vers=' option"),
+                    progname);
              return 0;
          }
      case 4: /* nfsvers */
utils/mount/network.c +0 -0
@@ -1268,6 +1270,8 @@ nfs_nfs_version(struct mount_options *options,
 unsigned long *version)
              nfs_error(_("%s: option parsing error\n"),
                      progname);

Case fall-through here as well.

Quoted 6 lines

utils/mount/network.c nfs_nfs_version(struct mount_options *options, unsigned long *version) · line 1274

Quoted 3 lines
utils/mount/network.c +2 -0
          case PO_BAD_VALUE:
+            nfs_error(_("%s: invalid value for 'nfsvers=' option"),
+                    progname);

Why wouldn't you also print a diagnostic if a numeric value was used, but the value was out of range?

It did not appear there was any guarantee that &tmp would have been filled with anything useful, especially with something like nfsvers=v3 is given.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

And, what about similar cases in nfs_nfs_port(), nfs_nfs_program(), nfs_mount_program(), nfs_mount_version(), and nfs_mount_port() ?

I was just looking at the version and protocol options and I really didn't want to make things too verbose. Meaning we don't need to be printing two or three messages for one error...

On second thought... it turns out making this work is not too bad..

steved.

#6 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 |   17 +++++++++++++++--
 utils/mount/stropts.c |   16 +++++++++++-----
 2 files changed, 26 insertions(+), 7 deletions(-)
utils/mount/network.c +15 -2
index de1014d..74f9cb2 100644
@@ -1307,6 +1307,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;
@@ -1393,8 +1395,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))
+		    !nfs_get_proto(option, &tmp_family, &protocol)) {
+
+			nfs_error(_("%s: Failed to find '%s' protocol"), 
+				progname, option);
+			errno = EPROTONOSUPPORT;
 			goto out_err;
+		}
 	}
 
 	if (!nfs_verify_family(tmp_family))
@@ -1482,6 +1489,8 @@ nfs_mount_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;
@@ -1539,8 +1548,12 @@ 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))
+		if (!nfs_get_proto(option, &tmp_family, &protocol)) {
+			nfs_error(_("%s: Failed to find '%s' protocol"), 
+				progname, option);
+			errno = EPROTONOSUPPORT;
 			goto out_err;
+		}
 		if (!nfs_verify_family(tmp_family))
 			goto out_err;
 		*family = tmp_family;
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.6.1
#7 lore raw

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

Quoted 23 lines · Steve Dickson

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

---
  utils/mount/network.c |   17 +++++++++++++++--
  utils/mount/stropts.c |   16 +++++++++++-----
  2 files changed, 26 insertions(+), 7 deletions(-)
utils/mount/network.c +2 -0
index de1014d..74f9cb2 100644
@@ -1307,6 +1307,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;

utils/mount/network.c int nfs_nfs_proto_family(struct mount_options *options, · line 1403

Quoted 10 lines
utils/mount/network.c +5 -1
@@ -1393,8 +1395,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))
+		    !nfs_get_proto(option,&tmp_family,&protocol)) {
+
+			nfs_error(_("%s: Failed to find '%s' protocol"),
+				progname, option);
+			errno = EPROTONOSUPPORT;
  			goto out_err;

Code at the out_err label will clobber the errno value you just set here.

Quoted 32 lines
utils/mount/network.c +8 -1
+		}
  	}
 
  	if (!nfs_verify_family(tmp_family))
@@ -1482,6 +1489,8 @@ nfs_mount_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;
@@ -1539,8 +1548,12 @@ 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))
+		if (!nfs_get_proto(option,&tmp_family,&protocol)) {
+			nfs_error(_("%s: Failed to find '%s' protocol"),
+				progname, option);
+			errno = EPROTONOSUPPORT;
  			goto out_err;
+		}
  		if (!nfs_verify_family(tmp_family))
  			goto out_err;
  		*family = tmp_family;
utils/mount/stropts.c +0 -0
index 98557d2..0241400 100644

utils/mount/stropts.c nfs_rewrite_pmap_mount_options(struct mount_options *options) · line 544

Quoted 8 lines
utils/mount/stropts.c +4 -1
@@ -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;

It would be more clear if specific errnos were set in nfs_construct_new_options() or the functions it calls.

utils/mount/stropts.c static int nfs_do_mount_v3v2(struct nfsmount_info *mi, · line 595

Quoted 13 lines
utils/mount/stropts.c +3 -2
  		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;

It might be more clear if nfs_append_addr_option() set the right errno.
Likewise for nfs_fix_mounthost_option() and nfs_verify_lock_option().

Quoted 16 lines
utils/mount/stropts.c +4 -2
  		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;
  	}
 
#8 lore raw

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

Quoted 30 lines · Chuck Lever
Quoted 29 lines · Steve Dickson

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

---
  utils/mount/network.c |   17 +++++++++++++++--
  utils/mount/stropts.c |   16 +++++++++++-----
  2 files changed, 26 insertions(+), 7 deletions(-)
utils/mount/network.c +2 -0
index de1014d..74f9cb2 100644
@@ -1307,6 +1307,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;
utils/mount/network.c +0 -1
@@ -1393,8 +1395,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))
Quoted 8 lines

utils/mount/network.c int nfs_nfs_proto_family(struct mount_options *options, · line 1403

Quoted 6 lines
utils/mount/network.c +5 -0
+            !nfs_get_proto(option,&tmp_family,&protocol)) {
+
+            nfs_error(_("%s: Failed to find '%s' protocol"),
+                progname, option);
+            errno = EPROTONOSUPPORT;
              goto out_err;

Code at the out_err label will clobber the errno value you just set here.

Right...

Quoted 37 lines
Quoted 37 lines
utils/mount/network.c +1 -0
+        }
      }
 

if (!nfs_verify_family(tmp_family))

utils/mount/network.c +2 -0
@@ -1482,6 +1489,8 @@ nfs_mount_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;
utils/mount/network.c +5 -1
@@ -1539,8 +1548,12 @@ 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))
+        if (!nfs_get_proto(option,&tmp_family,&protocol)) {
+            nfs_error(_("%s: Failed to find '%s' protocol"),
+                progname, option);
+            errno = EPROTONOSUPPORT;
              goto out_err;
+        }
          if (!nfs_verify_family(tmp_family))
              goto out_err;
          *family = tmp_family;
utils/mount/stropts.c +0 -0
index 98557d2..0241400 100644
@@ -538,7 +538,10 @@ nfs_rewrite_pmap_mount_options(struct
 mount_options *options)
 
Quoted 10 lines

utils/mount/stropts.c nfs_rewrite_pmap_mount_options(struct mount_options *options) · line 544

Quoted 7 lines
utils/mount/stropts.c +4 -1
      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;

It would be more clear if specific errnos were set in nfs_construct_new_options() or the functions it calls.

Not sure I agree with that simple if statement not be clear... I think it pretty straightforward as to what is happening..

Quoted 4 lines
Quoted 4 lines
utils/mount/stropts.c +0 -0
          return 0;
      }
Quoted 14 lines

utils/mount/stropts.c static int nfs_do_mount_v3v2(struct · line 596

Quoted 11 lines
utils/mount/stropts.c +3 -2
@@ -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;

It might be more clear if nfs_append_addr_option() set the right errno.
Likewise for nfs_fix_mounthost_option() and nfs_verify_lock_option().

Again the concept is pretty simple.. if errno is not set, then set it..

steved.