Skip to contentSkip to conversation

Move NFS mount code from util-linux to nfs-utils

PATCH In review Amit Gud 2 participants 2 messages Jun 8, 2006 – Jun 9, 2006

Subsystems (2)
lore
Share & tools
lore

Amit Gud

author
#0 lore raw

PATCH 1/1 Move NFS mount code from util-linux to nfs-utils

AG

Signature · 2 lines
May the source be with you.
http://www.cis.ksu.edu/~gud

Adds the mount directory and the code to mount and umount the NFS file system.

---

utils/Makefile.am +1 -0
diff -uprN nfs-utils-1.0.8/utils/Makefile.am nfs-utils-1.0.8-ag/utils/Makefile.am
@@ -17,6 +17,7 @@ endif
 SUBDIRS = \
 	exportfs \
 	lockd \
+	mount \
 	mountd \
 	nfsd \
 	nfsstat \
utils/mount/Makefile.am +41 -0

41 lines not on this page · raw message

utils/mount/mount.c +357 -0

357 lines not on this page · raw message

utils/mount/mount_constants.h +74 -0

74 lines not on this page · raw message

utils/mount/mount.nfs.man +87 -0

87 lines not on this page · raw message

utils/mount/nfs4mount.c +450 -0

450 lines not on this page · raw message

utils/mount/nfs4_mount.h +85 -0

85 lines not on this page · raw message

utils/mount/nfsmount.c +1245 -0

1,245 lines not on this page · raw message

utils/mount/nfs_mount.h +82 -0

82 lines not on this page · raw message

utils/mount/nfsmount.h +328 -0

328 lines not on this page · raw message

utils/mount/nfsmount.x +336 -0

244 lines not on this page · raw message

utils/mount/nfsmount_xdr.c +329 -0

329 lines not on this page · raw message

utils/mount/nfsumount.c +386 -0

386 lines not on this page · raw message

utils/mount/umount.nfs.man +76 -0

76 lines not on this page · raw message

configure.in +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 11 lines · On Thursday June 8, [email protected] wrote:

Adds the mount directory and the code to mount and umount the NFS file system.

---
diff -uprN nfs-utils-1.0.8/utils/mount/mount.c nfs-utils-1.0.8-ag/utils/mount/mount.c

utils/mount/mount.c line 42

Quoted 6 lines
utils/mount/mount.c +6 -0
+
+extern int nfsumount(int, char **);
+extern int nfs4mount(const char *, const char *, int *, char **,
+		char **, int);
+extern int nfsmount(const char *, const char *, int *, char **,
+		char **, int *, int);

Any chance of these going in an include file? I really like the same include file to be included both where the function is defined and where it is used, so there is a some real checking of signature consistency going on.

Quoted 5 lines
utils/mount/mount.c +5 -0
+int add_mtab(char *fsname, char *mount_point, char *fstype, int flags, char *opts, int freq, int passno)
+{
+	struct mntent ment;
+	int fd;
+	FILE *mtab;

utils/mount/mount.c line 158

Quoted 10 lines
utils/mount/mount.c +10 -0
+
+	ment.mnt_fsname = fsname;
+	ment.mnt_dir = mount_point;
+	ment.mnt_type = fstype;
+	ment.mnt_opts = fix_opts_string(flags, opts);
+	ment.mnt_freq = 0;
+	ment.mnt_passno= 0;
+
+	if ((fd = open(MTAB_FILE"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1)	{
+		fprintf(stderr, "Can't get "MOUNTED"~ lock file");

I think you mean "MTAB_FILE"~

But in the next patch, it is _PATH_MOUNTED.
A bit of consistence here would be a good thing!

Quoted 6 lines
utils/mount/mount.c +6 -0
+		return 1;
+	}
+        close(fd);
+
+        if ((mtab = setmntent(MTAB_FILE, "a+")) == NULL) {
+		fprintf(stderr, "Can't open " MTAB_FILE);

utils/mount/mount.c line 202

Quoted 10 lines
utils/mount/mount.c +9 -0
+		return 1;
+	}
 
+
+void mount_usage()
+{
+	printf("usage: %s remotetarget dir [-rvnh] [-t version] [-o nfsoptions]\n", progname);
+	printf("options:\n\t-r\t\tmount readonly\n");
+	printf("\t-v\t\tverbose\n");
+	printf("\t-n\t\tno mtab updation\n");

I don't think 'updation' is a word :-)
Maybe: -n Do not update /etc/mtab

utils/mount/mount.c line 211

Quoted 10 lines
utils/mount/mount.c +8 -0
+	printf("\t-h\t\tprint this help\n");
+	printf("\tversion\t\tnfs4 - NFS version 4, nfs - older NFS version supported\n");
+	printf("\tnfsoptions\tRefer mount.nfs(8) or nfs(5)\n\n");
+}
 
 
+
+	spec = canonicalize(argv[1]);
+	mount_point = canonicalize(argv[2]);
+

I'm certain you don't want to 'canonicalize' "spec" as it is not a local path name. I'm not convinced that you want to canonicalize mount_point, but I cannot immediately see any harm in it.

utils/mount/mount.c line 342

Quoted 9 lines
utils/mount/mount.c +9 -0
+
+	parse_opts(mount_opts, &flags, &extra_opts);
+
+	if (!strcmp(progname, "mount.nfs4") || nfs_mount_vers == 4) {
+		nfs_mount_vers = 4;
+		mnt_err = nfs4mount(spec, mount_point, &flags, &extra_opts, &mount_opts, 0);
+	}
+
+	/* fall back to v3 if v4 didn't work */

Nope. Falling back to v2 if v3 didn't work and no explicit version was given is OK, Falling back to v3 if v4 doesn't work is definitely not ok because
1- we only use v4 if an explicit version is asked for
2- v4 is very different, and has different path names for places on
the server.

utils/mount/mount.c line 353

Quoted 11 lines
utils/mount/mount.c +11 -0
+	if (mnt_err && errno != EBUSY && errno != ENOENT) {
+		nfs_mount_vers = 3;
+		mnt_err = nfsmount(spec, mount_point, &flags, &extra_opts, &mount_opts, &nfs_mount_vers, 0);
+	}
+
+	if (!mnt_err) {
+		do_mount_syscall(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs", flags, mount_opts);
+		if(!nomtab)
+			add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
+				 flags, extra_opts, 0, 0);
+	}

I think I would prefer to have two completely separate branches here, one for v4, one for v2/3 (But if you really really don't like that idea, I might listen).

Quoted 21 lines

diff -uprN nfs-utils-1.0.8/utils/mount/mount_constants.h nfs-utils-1.0.8-ag/utils/mount/mount_constants.h

utils/mount/mount_constants.h +17 -0
@@ -0,0 +1,74 @@
+#ifndef _NFS_MOUNT_CONSTANTS_H
+#define _NFS_MOUNT_CONSTANTS_H
+
+#ifndef MS_RDONLY
+#define MS_RDONLY	 1	/* Mount read-only */
+#endif
+#ifndef MS_NOSUID
+#define MS_NOSUID	 2	/* Ignore suid and sgid bits */
+#endif
+#ifndef MS_NODEV
+#define MS_NODEV	 4	/* Disallow access to device special files */
+#endif
+#ifndef MS_NOEXEC
+#define MS_NOEXEC	 8	/* Disallow program execution */
+#endif
+#ifndef MS_SYNCHRONOUS
+#define MS_SYNCHRONOUS	16	/* Writes are synced at once */

utils/mount/mount_constants.h line 27

Quoted 10 lines
utils/mount/mount_constants.h +10 -0
+#endif
+#ifndef MS_REMOUNT
+#define MS_REMOUNT	32	/* Alter flags of a mounted FS */
+#endif
+#ifndef MS_MANDLOCK
+#define MS_MANDLOCK	64	/* Allow mandatory locks on an FS */
+#endif
+#ifndef MS_DIRSYNC
+#define MS_DIRSYNC	128	/* Directory modifications are synchronous */
+#endif

Do we really need all of this? Is there any system at all that we want to support that doesn't have these in <sys/mount.h> ??

Quoted 12 lines

diff -uprN nfs-utils-1.0.8/utils/mount/mount.nfs.man nfs-utils-1.0.8-ag/utils/mount/mount.nfs.man

utils/mount/mount.nfs.man +8 -0
@@ -0,0 +1,87 @@
+.\"@(#)mount.nfs.8"
+.TH MOUNT.NFS 8 "5 Jun 2006"
+.SH NAME
+mount.nfs, mount.nfs4 \- mount a Network File System
+.SH SYNOPSIS
+.BI "mount.nfs" " remotetarget dir" " [\-rvnh ] [\-t " version "] [\-o " options "]
+.SH DESCRIPTION
+.BR mount.nfs

utils/mount/mount.nfs.man line 18

Quoted 10 lines
utils/mount/mount.nfs.man +10 -0
+is a part of 
+.BR nfs (5)
+utilities package, which provides NFS client functionality.
+
+.BR mount.nfs 
+is meant to be used by the
+.BR mount (8)
+command for mounting NFS shares. This subcommand, however, can also be used as a standalone command with limited functionality.
+
+.BR mount.nfs 
                ^^^ 4 ??

utils/mount/mount.nfs.man line 21

Quoted 3 lines
utils/mount/mount.nfs.man +3 -0
+is used for mounting NFSv4 file system, while 
+.BR mount.nfs 
+is used to mount NFS file systems with older versions.

v2 or v3 filesystems.
Saying "older versions" is, I think, the wrong emphasis. They are simply different versions.

Quoted 6 lines
utils/mount/mount.nfs.man +6 -0
+.I remotetarget 
+is a server share usually in the form of 
+.BR servername:/path/to/share.
+.I dir 
+is the directory on which the file system is to be mounted.
+

utils/mount/mount.nfs.man line 37

Quoted 10 lines
utils/mount/mount.nfs.man +10 -0
+.SH OPTIONS
+.TP
+.BI "\-r"
+Mount file system readonly.
+.TP
+.BI "\-v"
+Be verbose.
+.TP
+.BI "\-n"
+Make no updation to mtab. By default, an entry is created in 
           ^^^^^^^^

There's that word again :-)

Quoted 6 lines
utils/mount/mount.nfs.man +6 -0
+.I /etc/mtab 
+for every mounted file system. Use this option to skip making an entry.
+.TP
+.BI "\-h"
+Print help message.
+.TP

utils/mount/mount.nfs.man line 53

Quoted 10 lines
utils/mount/mount.nfs.man +10 -0
+.BI "version"
+Specify NFS file system version. Either
+.BR nfs4 
+or 
+.BR nfs.
+By default 
+.BR mount.nfs4 
+takes version 4, and 
+.BR mount.nfs 
+takes any supported older version.

This implied that
mount.nfs4 -t nfs
will use a v3 or v2 mount, but that code doesn't do that. I would say something like:
If the command is "mount.nfs4" or the filesystem type is nfs4, then version4 is used, else version 3 or 2 is used.

utils/mount/mount.nfs.man line 56

Quoted 3 lines
utils/mount/mount.nfs.man +3 -0
+.TP
+.BI "nfsoptions"
+Refer 

Refer to

utils/mount/mount.nfs.man line 63

Quoted 7 lines
utils/mount/mount.nfs.man +7 -0
+.BR nfs(5)
+or
+.BR mount(8) 
+manual pages.
+
+.SH NOTE
+For further information please refer 

to

Quoted 26 lines
utils/mount/mount.nfs.man +4 -0
+.BR nfs (5)
+and
+.BR mount (8)
+manual pages.

diff -uprN nfs-utils-1.0.8/utils/mount/nfs4mount.c nfs-utils-1.0.8-ag/utils/mount/nfs4mount.c

utils/mount/nfs4mount.c +16 -0
@@ -0,0 +1,450 @@
+/*
+ * nfs4mount.c -- Linux NFS mount
+ * Copyright (C) 2002 Trond Myklebust <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Note: this file based on the original nfsmount.c
+ *

utils/mount/nfs4mount.c line 26

Quoted 10 lines
utils/mount/nfs4mount.c +10 -0
+ * 2006-06-06 Amit Gud <[email protected]>
+ * - Moved to nfs-utils/utils/mount from util-linux/mount.
+ */
+
+#include <linux/posix_types.h>
+#include <asm/posix_types.h>
+#undef __FD_CLR
+#undef __FD_SET
+#undef __FD_ISSET
+#undef __FD_ZERO

Is it possible to avoid including anything from 'linux' or 'asm' ?? It is generally considered to be bad form.

utils/mount/nfsmount.h line 4

Quoted 8 lines

diff -uprN nfs-utils-1.0.8/utils/mount/nfsmount.h nfs-utils-1.0.8-ag/utils/mount/nfsmount.h

utils/mount/nfsmount.h +4 -0
@@ -0,0 +1,328 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */

Please do not post this file. It was generated using rpcgen :-)

utils/mount/umount.nfs.man

Quoted 5 lines

diff -uprN nfs-utils-1.0.8/utils/mount/umount.nfs.man nfs-utils-1.0.8-ag/utils/mount/umount.nfs.man

utils/mount/umount.nfs.man +2 -0
+.BI "\-n"
+Make no updation to mtab. By default, an entry is created in 

and again....

I haven't looked closely at the core mount/umount code, but it seemed reasonable and I assume it works...

If you'd like to send me a revised patch, it can probably get included in the next nfs-utils.... though it occurs to me that it might be good to have a
--without-mount
option to configure for distros that don't want to start using the new-improved approach just yet.

NeilBrown

_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs