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.
Modified files:
Index: src/sbin/mount_umap/mount_umap.8
diff -u src/sbin/mount_umap/mount_umap.8:1.19 src/sbin/mount_umap/mount_umap.8:1.20
--- src/sbin/mount_umap/mount_umap.8:1.19 Sun Sep 11 23:40:43 2005
+++ src/sbin/mount_umap/mount_umap.8 Tue Aug 20 20:18:54 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: mount_umap.8,v 1.19 2005/09/11 23:40:43 wiz Exp $
+.\" $NetBSD: mount_umap.8,v 1.20 2019/08/20 20:18:54 perseant Exp $
.\"
.\" Copyright (c) 1992, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -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 @@ The options are as follows:
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: src/sbin/mount_umap/mount_umap.c
diff -u src/sbin/mount_umap/mount_umap.c:1.23 src/sbin/mount_umap/mount_umap.c:1.24
--- src/sbin/mount_umap/mount_umap.c:1.23 Mon Aug 29 14:35:03 2011
+++ src/sbin/mount_umap/mount_umap.c Tue Aug 20 20:18:54 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_umap.c,v 1.23 2011/08/29 14:35:03 joerg Exp $ */
+/* $NetBSD: mount_umap.c,v 1.24 2019/08/20 20:18:54 perseant Exp $ */
/*
* Copyright (c) 1992, 1993, 1994
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19
#if 0
static char sccsid[] = "@(#)mount_umap.c 8.5 (Berkeley) 4/26/95";
#else
-__RCSID("$NetBSD: mount_umap.c,v 1.23 2011/08/29 14:35:03 joerg Exp $");
+__RCSID("$NetBSD: mount_umap.c,v 1.24 2019/08/20 20:18:54 perseant Exp $");
#endif
#endif /* not lint */
@@ -104,18 +104,22 @@ mount_umap(int argc, char *argv[])
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 @@ mount_umap(int argc, char *argv[])
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 @@ static void
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: src/sys/miscfs/umapfs/umap.h
diff -u src/sys/miscfs/umapfs/umap.h:1.17 src/sys/miscfs/umapfs/umap.h:1.18
--- src/sys/miscfs/umapfs/umap.h:1.17 Tue Apr 11 07:51:37 2017
+++ src/sys/miscfs/umapfs/umap.h Tue Aug 20 20:18:54 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: umap.h,v 1.17 2017/04/11 07:51:37 hannken Exp $ */
+/* $NetBSD: umap.h,v 1.18 2019/08/20 20:18:54 perseant Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -51,6 +51,7 @@ struct umap_args {
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 @@ void umap_mapids(struct mount *v_mount,
#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: src/sys/miscfs/umapfs/umap_vfsops.c
diff -u src/sys/miscfs/umapfs/umap_vfsops.c:1.100 src/sys/miscfs/umapfs/umap_vfsops.c:1.101
--- src/sys/miscfs/umapfs/umap_vfsops.c:1.100 Wed Feb 20 10:06:00 2019
+++ src/sys/miscfs/umapfs/umap_vfsops.c Tue Aug 20 20:18:54 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: umap_vfsops.c,v 1.100 2019/02/20 10:06:00 hannken Exp $ */
+/* $NetBSD: umap_vfsops.c,v 1.101 2019/08/20 20:18:54 perseant Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.100 2019/02/20 10:06:00 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.101 2019/08/20 20:18:54 perseant Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: umap_vfsops.
#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 @@ umapfs_mount(struct mount *mp, const cha
#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 @@ umapfs_mount(struct mount *mp, const cha
* 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);