NetBSD Problem Report #54471

From root@hhhh.org  Thu Aug 15 21:53:41 2019
Return-Path: <root@hhhh.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id ED9BA7A176
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 15 Aug 2019 21:53:40 +0000 (UTC)
Message-Id: <20190815215321.BA7D31B864@photomat.hhhh.org>
Date: Thu, 15 Aug 2019 14:53:21 -0700 (PDT)
From: perseant@netbsd.org
Reply-To: perseant@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: Allow the user to specify an fsid for umapfs
X-Send-Pr-Version: 3.95

>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:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 15 21:55:00 +0000 2019
>Closed-Date:    Tue Aug 20 20:20:24 +0000 2019
>Last-Modified:  Tue Aug 20 20:35: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:/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);

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: perseant@NetBSD.org
State-Changed-When: Tue, 20 Aug 2019 20:20:24 +0000
State-Changed-Why:
Applied patch.


From: "Konrad Schroder" <perseant@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54471 CVS commit: src
Date: Tue, 20 Aug 2019 20:18:54 +0000

 Module Name:	src
 Committed By:	perseant
 Date:		Tue Aug 20 20:18:54 UTC 2019

 Modified Files:
 	src/sbin/mount_umap: mount_umap.8 mount_umap.c
 	src/sys/miscfs/umapfs: umap.h umap_vfsops.c

 Log Message:
 Allow the user to specify the filesystem ID for umapfs at mount time,
 allowing a consistent filesystem ID across reboots.  Closes PR #54471.


 To generate a diff of this commit:
 cvs rdiff -u -r1.19 -r1.20 src/sbin/mount_umap/mount_umap.8
 cvs rdiff -u -r1.23 -r1.24 src/sbin/mount_umap/mount_umap.c
 cvs rdiff -u -r1.17 -r1.18 src/sys/miscfs/umapfs/umap.h
 cvs rdiff -u -r1.100 -r1.101 src/sys/miscfs/umapfs/umap_vfsops.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.