2d06576
commit 99defadcebf3bf892871f5541bfe762685faccbd
2d06576
Author: Steve Dickson <steved@redhat.com>
2d06576
Date:   Wed May 9 13:14:26 2007 -0400
2d06576
2d06576
    When nfs4 mount fail because the exported directory does
2d06576
    not exist, the mount command claims the local mount point
2d06576
    does not exist which is wrong. This patch fixes that problem
2d06576
    as well as  makes the v4 mount failures look like v3/v2 failures.
2d06576
    
2d06576
    Signed-off-by: Steve Dickson <steved@redhat.com>
2d06576
2d06576
--- nfs-utils-1.0.12/utils/mount/mount.c.orig	2007-05-09 14:06:23.574929000 -0400
2d06576
+++ nfs-utils-1.0.12/utils/mount/mount.c	2007-05-09 14:07:34.368247000 -0400
2d06576
@@ -348,22 +348,49 @@
2d06576
 	return 0;
2d06576
 }
2d06576
 
2d06576
-static void mount_error(char *node)
2d06576
+static void mount_error(char *mntpnt, char *node)
2d06576
 {
2d06576
 	switch(errno) {
2d06576
 		case ENOTDIR:
2d06576
-			fprintf(stderr, "%s: mount point %s is not a directory\n", progname, node);
2d06576
+			fprintf(stderr, "%s: mount point %s is not a directory\n", 
2d06576
+				progname, mntpnt);
2d06576
 			break;
2d06576
 		case EBUSY:
2d06576
-			fprintf(stderr, "%s: %s is already mounted or busy\n", progname, node);
2d06576
+			fprintf(stderr, "%s: %s is already mounted or busy\n", 
2d06576
+				progname, mntpnt);
2d06576
 			break;
2d06576
 		case ENOENT:
2d06576
-			fprintf(stderr, "%s: mount point %s does not exist\n", progname, node);
2d06576
+			if (node) {
2d06576
+				fprintf(stderr, "%s: %s failed, reason given by server: %s\n",
2d06576
+					progname, node, strerror(errno));
2d06576
+			} else
2d06576
+				fprintf(stderr, "%s: mount point %s does not exist\n", 
2d06576
+					progname, mntpnt);
2d06576
 			break;
2d06576
 		default:
2d06576
 			fprintf(stderr, "%s: %s\n", progname, strerror(errno));
2d06576
 	}
2d06576
 }
2d06576
+static int chk_mountpoint(mount_point)
2d06576
+{
2d06576
+	struct stat sb;
2d06576
+
2d06576
+	if (stat(mount_point, &sb) < 0){
2d06576
+		mount_error(mount_point, NULL);
2d06576
+		return 1;
2d06576
+	}
2d06576
+	if (S_ISDIR(sb.st_mode) == 0){
2d06576
+		errno = ENOTDIR;
2d06576
+		mount_error(mount_point, NULL);
2d06576
+		return 1;
2d06576
+	}
2d06576
+	if (access(mount_point, X_OK) < 0) {
2d06576
+		mount_error(mount_point, NULL);
2d06576
+		return 1;
2d06576
+	}
2d06576
+
2d06576
+	return 0;
2d06576
+}
2d06576
 #define NFS_MOUNT_VERS_DEFAULT 3
2d06576
 
2d06576
 int main(int argc, char *argv[])
2d06576
@@ -493,6 +520,9 @@
2d06576
 		}
2d06576
 	}
2d06576
 
2d06576
+	if (chk_mountpoint(mount_point))
2d06576
+		exit(EX_FAIL);
2d06576
+
2d06576
 	if (nfs_mount_vers == 4) {
2d06576
 		mnt_err = nfs4mount(spec, mount_point, &flags, 
2d06576
 			&extra_opts, &mount_opts, 0);
2d06576
@@ -512,7 +542,7 @@
2d06576
 				flags, mount_opts);
2d06576
 
2d06576
 		if (mnt_err) {
2d06576
-			mount_error(mount_point);
2d06576
+			mount_error(mount_point, spec);
2d06576
 			exit(EX_FAIL);
2d06576
 		}
2d06576
 	}