From nobody@FreeBSD.org  Tue Jun  6 21:53:54 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D04CA16D29A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 Jun 2006 21:45:13 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B510B43D55
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 Jun 2006 21:45:11 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k56LjBE9072577
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 6 Jun 2006 21:45:11 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k56LjBiB072576;
	Tue, 6 Jun 2006 21:45:11 GMT
	(envelope-from nobody)
Message-Id: <200606062145.k56LjBiB072576@www.freebsd.org>
Date: Tue, 6 Jun 2006 21:45:11 GMT
From: Olli Hauer <ohauer@gmx.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] /etc/rc.d/ramdisk + ramdisk-own replacement
X-Send-Pr-Version: www-2.3

>Number:         98603
>Category:       conf
>Synopsis:       [PATCH] /etc/rc.d/ramdisk + ramdisk-own replacement
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    flz
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 06 22:00:34 GMT 2006
>Closed-Date:    Mon Sep 25 22:59:40 GMT 2006
>Last-Modified:  Mon Sep 25 22:59:40 GMT 2006
>Originator:     Olli Hauer
>Release:        FreeBSD 6.1-RELEASE i386
>Organization:
>Environment:
>Description:
Replacement for the following scripts:
- /etc/rc.d/ramdisk
- /etc/rc.d/ramdisk-own


I see the old scripts as workaround for md's in fstab, but there is no
dockumentation inside (I think only a handful people use them as they are).

The replacement covers both scripts in one with fault tolerance and give
example how to use it (extra paramter help). 
It also has the feature to create directorys before the owner or permissions 
are set, this is handy for example cvs-lock directoy or other things.


>How-To-Repeat:

>Fix:
--- ramdisk.orig	Mon Jun  5 20:05:09 2006
+++ ramdisk.sh	Tue Jun  6 23:09:40 2006
@@ -36,31 +36,110 @@
 name="ramdisk"
 stop_cmd="ramdisk_stop"
 start_cmd="ramdisk_start"
+help_cmd=ramdisk_help
+extra_commands="help"
 
 ramdisk_start()
 {
-	for unit in $ramdisk_units; do
+	for unit in ${ramdisk_units}; do
+		if [ -c /dev/md${unit} ]; then
+			echo "${0}: md${unit} exists, skipping"
+			continue
+		fi
+
 		eval mdoptions=\$ramdisk_${unit}_config
-		if [ "$mdoptions" = "${mdoptions##-t}" ]; then
-			echo "Type not specified for md$unit"
+
+		if [ "${mdoptions}" = "${mdoptions##-t}" ]; then
+			echo "Type not specified for md${unit}"
 			continue
 		fi
+
 		eval fsoptions=\$ramdisk_${unit}_newfs
+		eval owner=\$ramdisk_${unit}_owner
+		eval perms=\$ramdisk_${unit}_perms
+		eval mount=\$ramdisk_${unit}_mount
+		eval mdirs=\$ramdisk_${unit}_mkdir
+
+		echo "Configuring ramdisk /dev/md${unit}"
+
+		[ "X${mount}" != "X" ] && mkdir -p ${mount} > /dev/null 2>&1
+
+		mdconfig -a ${mdoptions} -u ${unit}
+		newfs ${fsoptions} /dev/md${unit}
+
+
+		[ "X${mount}" != "X" ] && mount /dev/md${unit} ${mount} 
+		[ "X${mdirs}" != "X" ] && for DIR in ${mdirs}; do mkdir -p ${mount}/${DIR}; done 
+		[ "X${owner}" != "X" ] && chown -R ${owner} ${mount}
+		[ "X${perms}" != "X" ] && chmod -R ${perms} ${mount} 
+
+		echo "---------------------------------------"
+		echo "unit     : ${unit}"
+		echo "mdoptions: ${mdoptions}"
+		echo "fsoptions: ${fsoptions}"
+		echo "owner    : ${owner}"
+		echo "perms    : ${perms}"
+		echo "mount    : ${mount}"
+		[ "X${mdirs}" != "X" ] && for DIR in ${mdirs}; do echo "mkdir    : ${mount}/${DIR}" ; done 
+		echo "---------------------------------------"
+		/bin/df -hi ${mount}
+		echo "---------------------------------------"
 
-		mdconfig -a $mdoptions -u $unit
-		newfs $fsoptions /dev/md$unit
 	done
 }
 
 ramdisk_stop()
 {
-	for unit in $ramdisk_units
-	do
-		if [ -c /dev/md$unit ]; then
-			umount -f /dev/md$unit > /dev/null 2>&1
-			mdconfig -d -u $unit
+	for unit in ${ramdisk_units}; do
+		if [ -c /dev/md${unit} ]; then
+			eval mount=\$ramdisk_${unit}_mount
+			[ "X${mount}" != "X" ]   && umount -f ${mount} > /dev/null 2>&1
+
+			umount -f /dev/md${unit} 	> /dev/null 2>&1
+			mdconfig -d -u ${unit}
+			echo Recovered ramdisk /dev/md${unit}
 		fi
 	done
+}
+
+
+ramdisk_help()
+{
+cat << _EOF
+
+#=======================================
+#  config sample in rc.conf
+#   see man mdconfig(8)
+#=======================================
+
+	ramdisk_enable="YES"'
+	ramdisk_units="10 11"
+
+	# -- ramdisk unit 10 configuration --
+
+	# 1: allocate from RAM (malloc)
+	ramdisk_10_config="-t malloc -s 128m"
+	
+	# 2: mountpoint
+	ramdisk_10_mount="/data/ncvs/CVSTMP"
+	
+	# 3: crate this folders inside the ramdisk
+	ramdisk_10_mkdir="tmp lock/Prj1 lock/Prj2"
+	
+	# 4: owner:group
+	ramdisk_10_owner="ncvs:ncvs"
+	
+	# 5: permissions
+	ramdisk_10_perms="1755"
+
+
+	# -- ramdisk unit 11 configuration --
+
+	# 1: allocate from swap 
+	ramdisk_11_config="-t swap -s 128m"
+	...
+
+_EOF
 }
 
 load_rc_config $name
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Jun 29 00:24:01 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98603 
State-Changed-From-To: open->feedback 
State-Changed-By: flz 
State-Changed-When: Thu Jun 29 10:08:37 UTC 2006 
State-Changed-Why:  
I have some concerns about your patch: 
x ramdisk{,-own} scripts have been superseded by mdconfig{,2} in HEAD 
x you're using some commands which are not available soon enough like 
chown, chmod, ...; that was the only reason why there were two scripts 
in a first place 
x you're adding a help command, such things goes either in rc.conf(5) 
or in /etc/defaults/rc.conf 
x you're printing debug stuff inconditionnally, see debug/info 
subroutines in rc.subr 

Anyway, please test mdconfig scripts, I'm going to remove those ramdisk 
scripts from HEAD in a couple of minutes. 


Responsible-Changed-From-To: freebsd-rc->flz 
Responsible-Changed-By: flz 
Responsible-Changed-When: Thu Jun 29 10:08:37 UTC 2006 
Responsible-Changed-Why:  
Grab this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98603 
State-Changed-From-To: feedback->closed 
State-Changed-By: flz 
State-Changed-When: Mon Sep 25 22:57:41 UTC 2006 
State-Changed-Why:  
Feedback timeout. I'm willing to re-open the PR if submitter think there 
are still unresolved problems with the new scripts. 

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