From 56c049a0032e667f1d3051b08cbc295a26f76d44 Mon Sep 17 00:00:00 2001 From: Rick Macklem Date: Thu, 26 Dec 2019 22:33:20 +0000 Subject: [PATCH] Fix mount_nfs to recognize the NFSv4 specific errors returned by nmount(2). When mount_nfs calls nmount(2), certain NFSv4 specific errors such as NFSERR_MINORVERMISMATCH can be returned. Without this patch, 10021 is reported as an unknown error. This is not particulcarily serious, but make it difficult for sysadmins to figure out why the mount attempt is failing. This patch uses nfsv4_errstr.h to convert 10021 and similar to error strings that can be printed out. A positive side effect of this patch is the removal of a reference to sys/nfsclient/nfs.h, which should no longer be used, since it is part of the old NFS client. This patch should only affect reporting of failed mount attempts and not the semantics of NFS mount attempts. --- sbin/mount_nfs/mount_nfs.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index 473370ee020..1c15f505d8e 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -61,7 +61,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include +#include #include @@ -155,7 +156,7 @@ main(int argc, char *argv[]) char *mntname, *p, *spec, *tmp; char mntpath[MAXPATHLEN], errmsg[255]; char hostname[MAXHOSTNAMELEN + 1], gssn[MAXHOSTNAMELEN + 50]; - const char *gssname; + const char *gssname, *nmount_errstr; iov = NULL; iovlen = 0; @@ -462,9 +463,14 @@ main(int argc, char *argv[]) build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1); build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); - if (nmount(iov, iovlen, 0)) - err(1, "nmount: %s%s%s", mntpath, errmsg[0] ? ", " : "", - errmsg); + if (nmount(iov, iovlen, 0)) { + nmount_errstr = nfsv4_geterrstr(errno); + if (mountmode == V4 && nmount_errstr != NULL) + errx(1, "nmount: %s, %s", mntpath, nmount_errstr); + else + err(1, "nmount: %s%s%s", mntpath, errmsg[0] ? ", " : "", + errmsg); + } exit(0); }