NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/54471: Allow the user to specify an fsid for umapfs



>Number:         54471
>Category:       kern
>Synopsis:       Allow the user to specify an fsid for umapfs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 15 21:55:00 +0000 2019
>Originator:     Konrad Schroder
>Release:        NetBSD-current 20190815
>Organization:
	University of Washington
>Environment:
System: NetBSD apu1c.bastion.coral.washington.edu 9.99.7 NetBSD 9.99.7 (APU1C_GENERIC) #13: Thu Aug 15 12:14:59 PDT 2019  root%backup.coral.washington.edu@localhost:/ovar/src-current/sys/arch/amd64/compile/obj/APU1C_GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
If a umapfs is being exported, it needs to have a consistent fsid across
reboots.  But currently umapfs assigns a random fsid on every mount.
>How-To-Repeat:
Export a umapfs, reboot the server.
>Fix:

Index: sbin/mount_umap/mount_umap.8
===================================================================
RCS file: /cvsroot/src/sbin/mount_umap/mount_umap.8,v
retrieving revision 1.19
diff -u -r1.19 mount_umap.8
--- sbin/mount_umap/mount_umap.8	11 Sep 2005 23:40:43 -0000	1.19
+++ sbin/mount_umap/mount_umap.8	15 Aug 2019 21:45:22 -0000
@@ -42,6 +42,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl o Ar options
+.Op Fl i Ar fsid
 .Fl g Ar gid-mapfile
 .Fl u Ar uid-mapfile
 .Ar target
@@ -70,6 +71,11 @@
 Use the group ID mapping specified in
 .Ar gid-mapfile .
 This flag is required.
+.It Fl i Ar fsid
+Use the specified
+.Ar fsid
+for the filesystem ID, rather than choosing one at random.
+This is useful if the filesystem is to be exported.
 .It Fl o
 Options are specified with a
 .Fl o
Index: sbin/mount_umap/mount_umap.c
===================================================================
RCS file: /cvsroot/src/sbin/mount_umap/mount_umap.c,v
retrieving revision 1.23
diff -u -r1.23 mount_umap.c
--- sbin/mount_umap/mount_umap.c	29 Aug 2011 14:35:03 -0000	1.23
+++ sbin/mount_umap/mount_umap.c	15 Aug 2019 21:45:22 -0000
@@ -104,18 +104,22 @@
 	long d1, d2;
 	u_long mapdata[MAPFILEENTRIES][2];
 	u_long gmapdata[GMAPFILEENTRIES][2];
+	u_long fsid;
 	int ch, count, gnentries, mntflags, nentries;
 	char *gmapfile, *mapfile, buf[20];
 	char source[MAXPATHLEN], target[MAXPATHLEN];
 	mntoptparse_t mp;
 
-	mntflags = 0;
+	fsid = mntflags = 0;
 	mapfile = gmapfile = NULL;
-	while ((ch = getopt(argc, argv, "g:o:u:")) != -1)
+	while ((ch = getopt(argc, argv, "g:i:o:u:")) != -1)
 		switch (ch) {
 		case 'g':
 			gmapfile = optarg;
 			break;
+		case 'i':
+			fsid = strtoul(optarg, NULL, 16);
+			break;
 		case 'o':
 			mp = getmntopts(optarg, mopts, &mntflags, 0);
 			if (mp == NULL)
@@ -246,7 +250,12 @@
 	args.mapdata = mapdata;
 	args.gnentries = gnentries;
 	args.gmapdata = gmapdata;
+	args.fsid = fsid;
 
+	printf("sizeof export_args30 = %d, sizeof layer_args = %d, sizeof umap_args = %d\n",
+		(int)sizeof(struct export_args30),
+		(int)sizeof(struct layer_args),
+		(int)sizeof(struct umap_args));
 	if (mount(MOUNT_UMAP, target, mntflags, &args, sizeof args) == -1)
 		err(1, "%s on %s", source, target);
 	if (mntflags & MNT_GETARGS) {
@@ -260,6 +269,6 @@
 usage(void)
 {
 	(void)fprintf(stderr,
-"usage: mount_umap [-o options] -g groupmap -u usermap target_fs mount_point\n");
+"usage: mount_umap [-o options] [-i fsid] -g groupmap -u usermap target_fs mount_point\n");
 	exit(1);
 }
Index: sys/miscfs/umapfs/umap.h
===================================================================
RCS file: /cvsroot/src/sys/miscfs/umapfs/umap.h,v
retrieving revision 1.17
diff -u -r1.17 umap.h
--- sys/miscfs/umapfs/umap.h	11 Apr 2017 07:51:37 -0000	1.17
+++ sys/miscfs/umapfs/umap.h	15 Aug 2019 21:45:22 -0000
@@ -51,6 +51,7 @@
 	int 		gnentries;	/* # of entries in group map array */
 	u_long 		(*mapdata)[2];	/* pointer to array of user mappings */
 	u_long 		(*gmapdata)[2];	/* pointer to array of group mappings */
+	u_long		fsid;		/* user-supplied per-fs ident */
 };
 
 #ifdef _KERNEL
@@ -94,11 +95,11 @@
 #define	MOUNTTOUMAPMOUNT(mp) ((struct umap_mount *)((mp)->mnt_data))
 #define	VTOUMAP(vp) ((struct umap_node *)(vp)->v_data)
 #define UMAPTOV(xp) ((xp)->umap_vnode)
-#ifdef UMAPFS_DIAGNOSTIC
+/* #ifdef UMAPFS_DIAGNOSTIC
 #define	UMAPVPTOLOWERVP(vp) layer_checkvp((vp), __FILE__, __LINE__)
-#else
+#else */
 #define	UMAPVPTOLOWERVP(vp) (VTOUMAP(vp)->umap_lowervp)
-#endif
+/* #endif */
 
 extern int (**umap_vnodeop_p)(void *);
 extern struct vfsops umapfs_vfsops;
Index: sys/miscfs/umapfs/umap_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/umapfs/umap_vfsops.c,v
retrieving revision 1.100
diff -u -r1.100 umap_vfsops.c
--- sys/miscfs/umapfs/umap_vfsops.c	20 Feb 2019 10:06:00 -0000	1.100
+++ sys/miscfs/umapfs/umap_vfsops.c	15 Aug 2019 21:45:22 -0000
@@ -51,6 +51,7 @@
 #include <sys/vnode.h>
 #include <sys/mount.h>
 #include <sys/namei.h>
+#include <sys/syslog.h>
 #include <sys/kauth.h>
 #include <sys/module.h>
 
@@ -79,11 +80,17 @@
 #ifdef UMAPFS_DIAGNOSTIC
 	int i;
 #endif
+	fsid_t tfsid;
 
 	if (args == NULL)
 		return EINVAL;
-	if (*data_len < sizeof *args)
+	if (*data_len < sizeof *args) {
+#ifdef UMAPFS_DIAGNOSTIC
+		printf("mount_umap: data len %d < args %d\n",
+			(int)*data_len, (int)(sizeof *args));
+#endif
 		return EINVAL;
+	}
 
 	if (mp->mnt_flag & MNT_GETARGS) {
 		amp = MOUNTTOUMAPMOUNT(mp);
@@ -190,7 +197,23 @@
 	 * Make sure the mount point's sufficiently initialized
 	 * that the node create call will work.
 	 */
-	vfs_getnewfsid(mp);
+	tfsid.__fsid_val[0] = (int32_t)args->fsid;
+	tfsid.__fsid_val[1] = makefstype(MOUNT_UMAP);
+	if (tfsid.__fsid_val[0] == 0) {
+		log(LOG_WARNING, "umapfs: fsid given as 0, ignoring\n");
+		vfs_getnewfsid(mp);
+	} else if (vfs_getvfs(&tfsid)) {
+		log(LOG_WARNING, "umapfs: fsid %x already mounted\n",
+			tfsid.__fsid_val[0]);
+		vfs_getnewfsid(mp);
+	} else {
+       		mp->mnt_stat.f_fsidx.__fsid_val[0] = tfsid.__fsid_val[0];
+       		mp->mnt_stat.f_fsidx.__fsid_val[1] = tfsid.__fsid_val[1];
+		mp->mnt_stat.f_fsid = tfsid.__fsid_val[0];
+	}
+	log(LOG_DEBUG, "umapfs: using fsid %x/%x\n",
+		mp->mnt_stat.f_fsidx.__fsid_val[0],
+		mp->mnt_stat.f_fsidx.__fsid_val[1]);
 	mp->mnt_lower = lowerrootvp->v_mount;
 
 	amp->umapm_size = sizeof(struct umap_node);



Home | Main Index | Thread Index | Old Index