Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Apr 2012 09:14:17 +0000 (UTC)
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r233867 - in stable/8: share/man/man5 sys/fs/devfs
Message-ID:  <201204040914.q349EHlu094899@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mm
Date: Wed Apr  4 09:14:16 2012
New Revision: 233867
URL: http://svn.freebsd.org/changeset/base/233867

Log:
  MFC r232165, r232247 (partial), r232307:
  
  MFC r232165:
  Introduce the "ruleset=number" option for devfs(5) mounts.
  Add support for updating the devfs mount (currently only changing the
  ruleset number is supported).
  Check mnt_optnew with vfs_filteropt(9).
  
  This new option sets the specified ruleset number as the active ruleset
  of the new devfs mount and applies all its rules at mount time. If the
  specified ruleset doesn't exist, a new empty ruleset is created.
  
  MFC r232247 (partial):
  mdoc(7) type - start new sentences on new line
  
  MFC r232307:
  Add "export" to devfs_opts[] and return EOPNOTSUPP if called with it.
  Fixes mountd warnings.

Modified:
  stable/8/share/man/man5/devfs.5
  stable/8/sys/fs/devfs/devfs.h
  stable/8/sys/fs/devfs/devfs_rule.c
  stable/8/sys/fs/devfs/devfs_vfsops.c
Directory Properties:
  stable/8/share/man/man5/   (props changed)
  stable/8/sys/   (props changed)

Modified: stable/8/share/man/man5/devfs.5
==============================================================================
--- stable/8/share/man/man5/devfs.5	Wed Apr  4 08:47:36 2012	(r233866)
+++ stable/8/share/man/man5/devfs.5	Wed Apr  4 09:14:16 2012	(r233867)
@@ -38,7 +38,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 18, 2010
+.Dd February 9, 2012
 .Dt DEVFS 5
 .Os
 .Sh NAME
@@ -90,6 +90,30 @@ 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

Modified: stable/8/sys/fs/devfs/devfs.h
==============================================================================
--- stable/8/sys/fs/devfs/devfs.h	Wed Apr  4 08:47:36 2012	(r233866)
+++ stable/8/sys/fs/devfs/devfs.h	Wed Apr  4 09:14:16 2012	(r233867)
@@ -172,6 +172,8 @@ extern unsigned devfs_rule_depth;
 void devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de);
 void devfs_rules_cleanup (struct devfs_mount *dm);
 int devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td);
+void devfs_ruleset_set(devfs_rsnum rsnum, struct devfs_mount *dm);
+void devfs_ruleset_apply(struct devfs_mount *dm);
 int devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode,
     struct vnode **vpp);
 void devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de, int vp_locked);

Modified: stable/8/sys/fs/devfs/devfs_rule.c
==============================================================================
--- stable/8/sys/fs/devfs/devfs_rule.c	Wed Apr  4 08:47:36 2012	(r233866)
+++ stable/8/sys/fs/devfs/devfs_rule.c	Wed Apr  4 09:14:16 2012	(r233867)
@@ -771,3 +771,38 @@ devfs_rules_cleanup(struct devfs_mount *
 		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);
+}
+
+/*
+ * Apply the current active ruleset on a mount
+ */
+void
+devfs_ruleset_apply(struct devfs_mount *dm)
+{
+	struct devfs_ruleset *ds;
+
+	sx_assert(&dm->dm_lock, SX_XLOCKED);
+
+	sx_xlock(&sx_rules);
+	if (dm->dm_ruleset == 0) {
+		sx_xunlock(&sx_rules);
+		return;
+	}
+	ds = devfs_ruleset_bynum(dm->dm_ruleset);
+	if (ds != NULL)
+		devfs_ruleset_applydm(ds, dm);
+	sx_xunlock(&sx_rules);
+}

Modified: stable/8/sys/fs/devfs/devfs_vfsops.c
==============================================================================
--- stable/8/sys/fs/devfs/devfs_vfsops.c	Wed Apr  4 08:47:36 2012	(r233866)
+++ stable/8/sys/fs/devfs/devfs_vfsops.c	Wed Apr  4 09:14:16 2012	(r233867)
@@ -56,6 +56,10 @@ static vfs_unmount_t	devfs_unmount;
 static vfs_root_t	devfs_root;
 static vfs_statfs_t	devfs_statfs;
 
+static const char *devfs_opts[] = {
+	"from", "export", "ruleset", NULL
+};
+
 /*
  * Mount the filesystem
  */
@@ -65,15 +69,49 @@ devfs_mount(struct mount *mp)
 	int error;
 	struct devfs_mount *fmp;
 	struct vnode *rvp;
+	int rsnum;
 
 	if (devfs_unr == NULL)
 		devfs_unr = new_unrhdr(0, INT_MAX, NULL);
 
 	error = 0;
 
-	if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
+	if (mp->mnt_flag & MNT_ROOTFS)
 		return (EOPNOTSUPP);
 
+	rsnum = 0;
+
+	if (mp->mnt_optnew != NULL) {
+		if (vfs_filteropt(mp->mnt_optnew, devfs_opts))
+			return (EINVAL);
+
+		if (vfs_flagopt(mp->mnt_optnew, "export", NULL, 0))
+			return (EOPNOTSUPP);
+
+		if (vfs_getopt(mp->mnt_optnew, "ruleset", NULL, NULL) == 0 &&
+		    (vfs_scanopt(mp->mnt_optnew, "ruleset", "%d",
+		    &rsnum) != 1 || rsnum < 0 || rsnum > 65535))
+			error = EINVAL;
+	}
+
+	if (error) {
+		vfs_mount_error(mp, "%s", "invalid ruleset specification");
+		return (error);
+	}
+
+	if (mp->mnt_flag & MNT_UPDATE) {
+		if (rsnum != 0) {
+			fmp = mp->mnt_data;
+			if (fmp != NULL) {
+				sx_xlock(&fmp->dm_lock);
+				devfs_ruleset_set((devfs_rsnum)rsnum, fmp);
+				devfs_ruleset_apply(fmp);
+				sx_xunlock(&fmp->dm_lock);
+			}
+		}
+		return (0);
+	}
+
 	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 +139,12 @@ devfs_mount(struct mount *mp)
 		return (error);
 	}
 
+	if (rsnum != 0) {
+		sx_xlock(&fmp->dm_lock);
+		devfs_ruleset_set((devfs_rsnum)rsnum, fmp);
+		sx_xunlock(&fmp->dm_lock);
+	}
+
 	VOP_UNLOCK(rvp, 0);
 
 	vfs_mountedfrom(mp, "devfs");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204040914.q349EHlu094899>