[CFR][DEVFS] Add "ruleset" mount option

Martin Matuska mm at FreeBSD.org
Mon Feb 6 09:26:25 UTC 2012


The devfs(8) command supports configuring specific rulesets for devfs(5)
mounts.
However, it operates on already mounted devfs filesystems only and it is
impossible to configure a specific ruleset on mount-time.

The attached patch adds a "ruleset" mount option to devfs mounts.
The ruleset is automatically applied upon mount time. If the ruleset
doesn't exist, an empty ruleset with the given numer is created and
can be modified with devfs(8) later.

The patch is also available at:
http://people.freebsd.org/~mm/patches/devfs/devfs_mount_ruleset.patch

Please review and/or comment my attached patch.

-- 
Martin Matuska
FreeBSD committer
http://blog.vx.sk

-------------- next part --------------
Index: share/man/man5/devfs.5
===================================================================
--- share/man/man5/devfs.5	(revision 231065)
+++ share/man/man5/devfs.5	(working copy)
@@ -90,6 +90,29 @@ and
 .Pa 2 .
 .Xr fdescfs 5
 creates files for all open descriptors.
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl o Ar options
+Use the specified mount
+.Ar options ,
+as described in
+.Xr mount 8 .
+The following devfs file system-specific options are available:
+.Bl -tag -width indent
+.It Cm ruleset Ns No = Ns Ar ruleset
+Set ruleset number
+.Ar ruleset
+as the current ruleset for the mount-point and apply all its rules. If the
+ruleset number
+.Ar ruleset
+does not exist, an empty ruleset with the number
+.Ar ruleset
+is created. See
+.Xr devfs 8
+for more information on working with devfs rulesets.
+.El
+.El
 .Sh FILES
 .Bl -tag -width /dev/XXXX -compact
 .It Pa /dev
Index: sys/fs/devfs/devfs_rule.c
===================================================================
--- sys/fs/devfs/devfs_rule.c	(revision 231065)
+++ sys/fs/devfs/devfs_rule.c	(working copy)
@@ -771,3 +771,17 @@ devfs_rules_cleanup(struct devfs_mount *dm)
 		devfs_ruleset_reap(ds);
 	}
 }
+
+/*
+ * Make rsnum the active ruleset for dm (locked)
+ */
+void
+devfs_ruleset_set(devfs_rsnum rsnum, struct devfs_mount *dm)
+{
+
+	sx_assert(&dm->dm_lock, SX_XLOCKED);
+
+	sx_xlock(&sx_rules);
+	devfs_ruleset_use(rsnum, dm);
+	sx_xunlock(&sx_rules);
+}
Index: sys/fs/devfs/devfs_vfsops.c
===================================================================
--- sys/fs/devfs/devfs_vfsops.c	(revision 231065)
+++ sys/fs/devfs/devfs_vfsops.c	(working copy)
@@ -65,6 +65,7 @@ devfs_mount(struct mount *mp)
 	int error;
 	struct devfs_mount *fmp;
 	struct vnode *rvp;
+	devfs_rsnum rsnum;
 
 	if (devfs_unr == NULL)
 		devfs_unr = new_unrhdr(0, INT_MAX, NULL);
@@ -74,6 +75,18 @@ devfs_mount(struct mount *mp)
 	if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
 		return (EOPNOTSUPP);
 
+	rsnum = 0;
+
+	if (mp->mnt_optnew != NULL &&
+	    vfs_getopt(mp->mnt_optnew, "ruleset", NULL, NULL) == 0) {
+		if (vfs_scanopt(mp->mnt_optnew, "ruleset", "%d",
+		    &rsnum) != 1) {
+			vfs_mount_error(mp, "%s",
+			    "invalid ruleset specification");
+			return (EINVAL);
+		}
+	}
+
 	fmp = malloc(sizeof *fmp, M_DEVFS, M_WAITOK | M_ZERO);
 	fmp->dm_idx = alloc_unr(devfs_unr);
 	sx_init(&fmp->dm_lock, "devfsmount");
@@ -101,6 +114,12 @@ devfs_mount(struct mount *mp)
 		return (error);
 	}
 
+	if (rsnum != 0) {
+		sx_xlock(&fmp->dm_lock);
+		devfs_ruleset_set(rsnum, fmp);
+		sx_xunlock(&fmp->dm_lock);
+	}
+
 	VOP_UNLOCK(rvp, 0);
 
 	vfs_mountedfrom(mp, "devfs");
Index: sys/fs/devfs/devfs.h
===================================================================
--- sys/fs/devfs/devfs.h	(revision 231065)
+++ sys/fs/devfs/devfs.h	(working copy)
@@ -182,6 +182,7 @@ void	devfs_rules_apply(struct devfs_mount *, struc
 void	devfs_rules_cleanup(struct devfs_mount *);
 int	devfs_rules_ioctl(struct devfs_mount *, u_long, caddr_t,
 	    struct thread *);
+void	devfs_ruleset_set(devfs_rsnum rsnum, struct devfs_mount *dm);
 int	devfs_allocv(struct devfs_dirent *, struct mount *, int,
 	    struct vnode **);
 char	*devfs_fqpn(char *, struct devfs_mount *, struct devfs_dirent *,


More information about the freebsd-fs mailing list