From owner-freebsd-bugs@FreeBSD.ORG Tue Jun 6 22:16:32 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6A20716CC9C for ; Tue, 6 Jun 2006 22:00:37 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5141743D45 for ; Tue, 6 Jun 2006 22:00:35 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k56M0ZST060707 for ; Tue, 6 Jun 2006 22:00:35 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k56M0ZiG060704; Tue, 6 Jun 2006 22:00:35 GMT (envelope-from gnats) Resent-Date: Tue, 6 Jun 2006 22:00:35 GMT Resent-Message-Id: <200606062200.k56M0ZiG060704@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Olli Hauer Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D04CA16D29A for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: conf/98603: [PATCH] /etc/rc.d/ramdisk + ramdisk-own replacement X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jun 2006 22:16:34 -0000 >Number: 98603 >Category: conf >Synopsis: [PATCH] /etc/rc.d/ramdisk + ramdisk-own replacement >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Jun 06 22:00:34 GMT 2006 >Closed-Date: >Last-Modified: >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: >Unformatted: