Skip to contentSkip to conversation

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

PATCH In review Amit Gud 3 participants 4 messages Jun 12, 2006 – Jun 13, 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 - take2

AG

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

Adds the support functions needed for mount and umount. This functionality will someday be available in the form of shared mount library.

---

support/include/conn.h +42 -0
diff -uprN nfs-utils-1.0.8/support/include/conn.h nfs-utils-1.0.8-ag/support/include/conn.h
@@ -0,0 +1,42 @@
+/* 
+ * conn.h -- Connection routines for NFS mount / umount code.
+ *
+ * 2006-06-06 Amit Gud <[email protected]>
+ * - Moved code snippets here from util-linux/mount
+ */
+
+#ifndef _CONN_H
+#define _CONN_H
+
+#ifdef HAVE_RPCSVC_NFS_PROT_H
+#include <rpcsvc/nfs_prot.h>
+#else
+#include <linux/nfs.h>
+#define nfsstat nfs_stat
+#endif
+
+#include <rpc/pmap_prot.h>
+#include <rpc/clnt.h>
+
+#define MNT_SENDBUFSIZE ((u_int)2048)
+#define MNT_RECVBUFSIZE ((u_int)1024)
+
+typedef struct {
+	char **hostname;
+	struct sockaddr_in saddr;
+	struct pmap pmap;
+} clnt_addr_t;
+
+/* RPC call timeout values */
+static const struct timeval TIMEOUT = { 20, 0 };
+static const struct timeval RETRY_TIMEOUT = { 3, 0 };
+
+int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int);
+u_long nfsvers_to_mnt(const u_long);
+u_long mntvers_to_nfs(const u_long);
+int get_socket(struct sockaddr_in *, u_int, int);
+CLIENT * mnt_openclnt(clnt_addr_t *, int *);
+void mnt_closeclnt(CLIENT *, int);
+
+#endif /* _CONN_H */
+
support/include/fstab.h +24 -0
diff -uprN nfs-utils-1.0.8/support/include/fstab.h nfs-utils-1.0.8-ag/support/include/fstab.h
@@ -0,0 +1,24 @@
+#ifndef _NFS_FSTAB_H
+#define _NFS_FSTAB_H
+
+#include "nfs_mntent.h"
+
+int mtab_is_writable(void);
+int mtab_does_not_exist(void);
+
+struct mntentchn {
+	struct mntentchn *nxt, *prev;
+	nfs_mntent_t m;
+};
+
+struct mntentchn *mtab_head (void);
+struct mntentchn *getmntoptfile (const char *file);
+struct mntentchn *getmntdirbackward (const char *dir, struct mntentchn *mc);
+struct mntentchn *getmntdevbackward (const char *dev, struct mntentchn *mc);
+
+void lock_mtab (void);
+void unlock_mtab (void);
+void update_mtab (const char *special, nfs_mntent_t *with);
+
+#endif /* _NFS_FSTAB_H */
+
support/include/Makefile.am +5 -0
diff -uprN nfs-utils-1.0.8/support/include/Makefile.am nfs-utils-1.0.8-ag/support/include/Makefile.am
@@ -3,9 +3,13 @@
 SUBDIRS = nfs rpcsvc sys
 
 noinst_HEADERS = \
+	conn.h \
 	exportfs.h \
+	fstab.h \
 	ha-callout.h \
 	misc.h \
+	nfs_mntent.h \
+	nfs_paths.h \
 	nfslib.h \
 	rpcdispatch.h \
 	rpcmisc.h \
@@ -15,6 +19,7 @@ noinst_HEADERS = \
 	xio.h \
 	xlog.h \
 	xmalloc.h \
+	xcommon.h \
 	ypupdate.h
 
 MAINTAINERCLEANFILES = Makefile.in
support/include/nfs_mntent.h +34 -0
diff -uprN nfs-utils-1.0.8/support/include/nfs_mntent.h nfs-utils-1.0.8-ag/support/include/nfs_mntent.h
@@ -0,0 +1,34 @@
+/*
+ * 2006-06-08 Amit Gud <[email protected]>
+ * - Moved code snippets here from util-linux/mount/my_mntent.h
+ */
+
+#ifndef _NFS_MNTENT_H
+#define _NFS_MNTENT_H
+
+typedef struct nfs_mntent_s {
+	const char *mnt_fsname;
+	const char *mnt_dir;
+	const char *mnt_type;
+	const char *mnt_opts;
+	int mnt_freq;
+	int mnt_passno;
+} nfs_mntent_t;
+
+#define ERR_MAX 5
+
+typedef struct mntFILEstruct {
+	FILE *mntent_fp;
+	char *mntent_file;
+	int mntent_lineno;
+	int mntent_errs;
+	int mntent_softerrs;
+} mntFILE;
+
+mntFILE *nfs_setmntent (const char *file, char *mode);
+void nfs_endmntent (mntFILE *mfp);
+int nfs_addmntent (mntFILE *mfp, nfs_mntent_t *mnt);
+struct nfs_mntent *my_getmntent (mntFILE *mfp);
+nfs_mntent_t *nfs_getmntent (mntFILE *mfp);
+
+#endif /* _NFS_MNTENT_H */
support/include/nfs_paths.h +11 -0
diff -uprN nfs-utils-1.0.8/support/include/nfs_paths.h nfs-utils-1.0.8-ag/support/include/nfs_paths.h
@@ -0,0 +1,11 @@
+#ifndef _NFS_PATHS_H
+#define _NFS_PATHS_H
+
+#ifndef _PATH_MOUNTED
+#define _PATH_MOUNTED "/etc/fstab"
+#endif
+#define MOUNTED_LOCK	_PATH_MOUNTED "~"
+#define MOUNTED_TEMP	_PATH_MOUNTED ".tmp"
+
+#endif /* _NFS_PATHS_H */
+
support/include/nls.h +27 -0
diff -uprN nfs-utils-1.0.8/support/include/nls.h nfs-utils-1.0.8-ag/support/include/nls.h
@@ -0,0 +1,27 @@
+/* 
+ * 2006-06-08 Amit Gud <[email protected]>
+ * - Copied to nfs-utils/support/include from util-linux/mount
+ */
+
+#ifndef LOCALEDIR
+#define LOCALEDIR "/usr/share/locale"
+#endif
+
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+# ifdef gettext_noop
+#  define N_(String) gettext_noop (String)
+# else
+#  define N_(String) (String)
+# endif
+#else
+# undef bindtextdomain
+# define bindtextdomain(Domain, Directory) /* empty */
+# undef textdomain
+# define textdomain(Domain) /* empty */
+# define _(Text) (Text)
+# define N_(Text) (Text)
+#endif
+
+
support/include/xcommon.h +48 -0

48 lines not on this page · raw message

support/include/xmalloc.h +1 -16
diff -uprN nfs-utils-1.0.8/support/include/xmalloc.h nfs-utils-1.0.8-ag/support/include/xmalloc.h
@@ -1,16 +1 @@
-/*
- * xmalloc	Module for memory allocation. Drop in your
- *		debugging malloc module if you feel like it.
- *
- * Copyright (C) 1995 Olaf Kirch <[email protected]>
- */
-
-#ifndef XMALLOC_H
-#define XMALLOC_H
-
-void	*xmalloc(size_t size);
-void	*xrealloc(void *ptr, size_t size);
-char	*xstrdup(const char *s);
-void	xfree(void *ptr);
-
-#endif /* XMALLOC_H */
+#include "xcommon.h"
support/nfs/conn.c +211 -0

211 lines not on this page · raw message

support/nfs/fstab.c +487 -0

487 lines not on this page · raw message

support/nfs/Makefile.am +2 -2
diff -uprN nfs-utils-1.0.8/support/nfs/Makefile.am nfs-utils-1.0.8-ag/support/nfs/Makefile.am
@@ -2,9 +2,9 @@
 
 noinst_LIBRARIES = libnfs.a
 libnfs_a_SOURCES = exports.c rmtab.c xio.c rpcmisc.c rpcdispatch.c \
-		   xlog.c xmalloc.c wildmat.c nfssvc.c nfsclient.c \
+		   xlog.c xcommon.c wildmat.c nfssvc.c nfsclient.c \
 		   nfsexport.c getfh.c nfsctl.c lockdsvc.c \
-		   svc_socket.c cacheio.c closeall.c
+		   svc_socket.c cacheio.c closeall.c conn.c fstab.c nfs_mntent.c
 
 MAINTAINERCLEANFILES = Makefile.in
 
support/nfs/nfs_mntent.c +226 -0

226 lines not on this page · raw message

support/nfs/xcommon.c +185 -0

185 lines not on this page · raw message

support/nfs/xmalloc.c +0 -50

50 lines not on this page · raw message

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

#1 lore raw

Hi Amit,

I see that the mtab locking here has the patches that should make it work properly (at least I believe that is the case) but if that same fix is not implemented in the util-linux code base then the problem will persist.

Perhaps Adrian Bunk should be involved in this since he will ultimately need to update util-linux as well?

Ian

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

#2 lore raw

Re: [PATCH 2 / 2] Move NFS mount code from util-linux tonfs-utils - take2

Quoted 10 lines · Ian Kent

Hi Amit,

I see that the mtab locking here has the patches that should make it work properly (at least I believe that is the case) but if that same fix is not implemented in the util-linux code base then the problem will persist.

Perhaps Adrian Bunk should be involved in this since he will ultimately need to update util-linux as well?

util-linux already uses this locking protocol (which is included in the patches), in fact that code is duplicated now in nfs-utils. But theres code like the samba client (mount.cifs), that doesn't follow this and have implemented some different mechanism.

AG

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



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

Re: [PATCH 2 / 2] Move NFS mount code from util-linux tonfs-utils - take2

Quoted 8 lines · Amit Gud
Quoted 7 lines · Ian Kent

Hi Amit,

I see that the mtab locking here has the patches that should make it work properly (at least I believe that is the case) but if that same fix is not implemented in the util-linux code base then the problem will persist.

Quoted 8 lines
Quoted 3 lines

Perhaps Adrian Bunk should be involved in this since he will ultimately need to update util-linux as well?

util-linux already uses this locking protocol (which is included in the patches), in fact that code is duplicated now in nfs-utils. But theres code like the samba client (mount.cifs), that doesn't follow this and have implemented some different mechanism.

My point is that the code in util-linux does not do the locking properly and if it is not fixed then the locking here isn't worth anything.

Ian

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