From admin@WBIw009.westbend.net  Sat Apr 26 17:19:37 2003
Return-Path: <admin@WBIw009.westbend.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 72D1D37B401; Sat, 26 Apr 2003 17:19:37 -0700 (PDT)
Received: from mail.westbend.net (ns1.westbend.net [216.47.253.3])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id A4C6043FAF; Sat, 26 Apr 2003 17:19:36 -0700 (PDT)
	(envelope-from admin@WBIw009.westbend.net)
Received: from WBIw009.westbend.net (wbiw009 [216.47.253.29])
	by mail.westbend.net (8.12.9/8.12.9) with ESMTP id h3R0JRdR087955;
	Sat, 26 Apr 2003 19:19:28 -0500 (CDT)
	(envelope-from admin@WBIw009.westbend.net)
Received: from WBIw009.westbend.net (localhost [127.0.0.1])
	by WBIw009.westbend.net (8.12.9/8.12.9) with ESMTP id h3R0JQkx000764;
	Sat, 26 Apr 2003 19:19:27 -0500 (CDT)
	(envelope-from admin@WBIw009.westbend.net)
Received: (from root@localhost)
	by WBIw009.westbend.net (8.12.9/8.12.9/Submit) id h3R0JPXU000763;
	Sat, 26 Apr 2003 19:19:26 -0500 (CDT)
Message-Id: <200304270019.h3R0JPXU000763@WBIw009.westbend.net>
Date: Sat, 26 Apr 2003 19:19:26 -0500 (CDT)
From: "Scot W. Hetzel" <hetzels@westbend.net>
Reply-To: "Scot W. Hetzel" <hetzels@westbend.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc: gordon@freebsd.org
Subject: RC_NG Script for creating Memory Disks
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         51451
>Category:       bin
>Synopsis:       RC_NG Script for creating Memory Disks
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 26 17:20:12 PDT 2003
>Closed-Date:    Sat Apr 26 18:48:40 PDT 2003
>Last-Modified:  Sat Apr 26 18:48:40 PDT 2003
>Originator:     Scot W. Hetzel
>Release:        FreeBSD 5.0-CURRENT
>Organization:
West Bend Internet
>Environment:
System: FreeBSD WBIw009.westbend.net 4.8-STABLE FreeBSD 4.8-STABLE #2: Tue Apr 22 02:28:52 CDT 2003 root@WBIw009.westbend.net:/usr/obj/usr/src/4x/sys/GENERIC-SMP i386

>Description:
	I didn't find a RC_NG script on current that would create and
	mount the Memory Disks (/dev/md?).

>How-To-Repeat:
	Try to have the system create/mount a Memory Disk as it is booting.

>Fix:
	The attached patch allows you to create them.  For example by placing
	the following into rc.conf, You can creat the vnode, swap, or malloc
	Memory Disks.

	    memorydisk_enable="YES"
	    memorydisk_list="test0 test1 test2"

	    memorydisk_test0_type="vnode"
	    memorydisk_test0_file="/usr/test/file"
	    memorydisk_test0_mount="/usr/test0"

	    memorydisk_test1_type="swap"
	    memorydisk_test1_size="4m"
	    memorydisk_test1_mount="/usr/test1"

	    memorydisk_test2_type="malloc"
	    memorydisk_test2_size="5m"
	    memorydisk_test2_mount="/usr/test2"

	Depending on the setting of memorydisk_<name>_type will determine
	which additional variables will need to be set (*_file, or *_size).

Index: etc/defaults/rc.conf
===================================================================
RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
retrieving revision 1.172
diff -u -r1.172 rc.conf
--- etc/defaults/rc.conf	16 Apr 2003 16:29:51 -0000	1.172
+++ etc/defaults/rc.conf	26 Apr 2003 23:41:46 -0000
@@ -48,6 +48,16 @@
 extra_netfs_types="NO"	# List of network extra filesystem types for delayed
 			# mount at startup (or NO).
 
+memorydisk_enable="NO"	# Enable Memory Disks
+memorydisk_list=""	# List of Memory Disks to create
+
+# for each named Memory Disk in mdfile_list, create an entry with these variables:
+#
+# memorydisk_<name>_type    - swap, malloc, vnode
+# memorydisk_<name>_file    - required by vnode only
+# memorydisk_<name>_size    - required by swap/malloc only
+# memorydisk_<name>_mount   - mount point for mdfile (optional?)
+
 ##############################################################
 ###  Network configuration sub-section  ######################
 ##############################################################
Index: etc/rc.d/Makefile
===================================================================
RCS file: /home/ncvs/src/etc/rc.d/Makefile,v
retrieving revision 1.15
diff -u -r1.15 Makefile
--- etc/rc.d/Makefile	24 Apr 2003 08:20:47 -0000	1.15
+++ etc/rc.d/Makefile	26 Apr 2003 23:16:55 -0000
@@ -8,7 +8,7 @@
 	cleartmp cron devd devdb devfs dhclient diskless dmesg dumpon fsck \
 	hostname inetd initdiskless initrandom ip6fw ipfilter ipfs ipfw ipmon \
 	ipnat ipsec ipxrouted isdnd jail kadmind kerberos keyserv kldxref \
-	ldconfig local localdaemons lomac lpd motd mountcritlocal mountcritremote \
+	ldconfig local localdaemons lomac lpd memorydisk motd mountcritlocal mountcritremote \
 	mountd moused mroute6d mrouted msgs named netif network1 network2 network3 \
 	network_ipv6 nfsclient nfsd nfslocking nfsserver nisdomain ntpd \
 	ntpdate othermta pccard pcvt ppp-user pppoed pwcheck quota random \
Index: etc/rc.d/memorydisk
===================================================================
RCS file: etc/rc.d/memorydisk
diff -N etc/rc.d/memorydisk
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ etc/rc.d/memorydisk	26 Apr 2003 23:45:15 -0000
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: memorydisk
+# REQUIRE: NETWORKING root mountcritlocal
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="memorydisk"
+rcvar=`set_rcvar`
+start_cmd="memorydisk_start"
+stop_cmd=":"
+
+memorydisk_start()
+{
+	for _md_name in ${memorydisk_list}
+	do
+		eval md_type=\"\$memorydisk_${_md_name}_type\"
+		eval md_file=\"\$memorydisk_${_md_name}_file\"
+		eval md_size=\"\$memorydisk_${_md_name}_size\"
+		eval md_mount=\"\$memorydisk_${_md_name}_mount\"
+
+		case "${md_type}" in
+			swap|malloc)
+				if [ -n "${md_size}" -a -c /dev/mdctl ]; then
+					mdev=`mdconfig -a -t ${md_type} -s ${md_size}`
+					[ -n "${md_mount}" ] && newfs -U /dev/${mdev}
+				fi
+				;;
+
+			vnode)
+				if [ -w "${md_file}" -a -c /dev/mdctl ]; then
+					mdev=`mdconfig -a -t vnode -f ${md_file}`
+				fi
+				;;
+			*)
+				;;
+		esac
+
+		[ -n "${md_mount}" -a -d ${md_mount} ] && mount /dev/${mdev} ${md_mount}
+	done
+}
+
+load_rc_config $name
+run_rc_command "$1"
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: dougb 
State-Changed-When: Sat Apr 26 18:04:54 PDT 2003 
State-Changed-Why:  

I was planning on adding a symlink to mdmfs as mount_mfs, which will 
allow you to put things like this in fstab: 

md                      /tmp            mfs rw,-s8m,noatime     2       2 

to accomplish something very similar to what you're proposing. Do you think 
that this would be adequate, or do you still feel that we should address this 
through rc? 



Responsible-Changed-From-To: freebsd-bugs->dougb 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Sat Apr 26 18:04:54 PDT 2003 
Responsible-Changed-Why:  

I'll handle the feedback. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51451 

From: "Scot W. Hetzel" <hetzels@westbend.net>
To: "Doug Barton" <dougb@FreeBSD.org>,
	<freebsd-gnats-submit@FreeBSD.org>
Cc:  
Subject: Re: bin/51451: RC_NG Script for creating Memory Disks
Date: Sat, 26 Apr 2003 20:31:04 -0500

 From: "Doug Barton" <dougb@FreeBSD.org>
 > I was planning on adding a symlink to mdmfs as mount_mfs, which will
 > allow you to put things like this in fstab:
 >
 > md                      /tmp            mfs rw,-s8m,noatime     2       2
 >
 > to accomplish something very similar to what you're proposing. Do you
 think
 > that this would be adequate, or do you still feel that we should address
 this
 > through rc?
 >
 That should be adequate, no rc script required.
 
 I noticed that the md, and mdconfig man pages are missing a reference to the
 mdmfs(8) man page.
 
 Scot
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: dougb 
State-Changed-When: Sat Apr 26 18:47:03 PDT 2003 
State-Changed-Why:  

Fabulous! I've already committed the mount_mfs link, and updated 
the man pages as you suggested. Thanks for catching that! 

If you decide that the mount_mfs stuff doesn't meet your needs, 
feel free to reply to this PR again and we can take another look. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51451 
>Unformatted:
