Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Dec 2010 15:37:08 GMT
From:      David Naylor <naylor.b.david@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   conf/153123: [rc] add gsched rc file to automatically insert gsched on top of storage device(s)
Message-ID:  <201012131537.oBDFb81e036379@red.freebsd.org>
Resent-Message-ID: <201012131540.oBDFe6UV070118@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         153123
>Category:       conf
>Synopsis:       [rc] add gsched rc file to automatically insert gsched on top of storage device(s)
>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:   Mon Dec 13 15:40:06 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     David Naylor
>Release:        FreeBSD-current
>Organization:
Private
>Environment:
FreeBSD dragon.dg 9.0-CURRENT FreeBSD 9.0-CURRENT #0: Tue Nov  9 22:34:47 SAST 2010     root@dragon.dg:/tmp/home/freebsd9/src/sys/DRAGON  amd64
>Description:
Add a gsched rc file to automatically insert gsched on top of a storage device(s).  The rc file inserts the scheduler on startup and removes the scheduler on shutdown.  It could also be integrated into devd.  

I have used this without incident with the following in my rc.conf:
gsched_enable="YES"
gsched_devs="ad4 ad8"

There are two issues when using the following for devd:
notify 100 {
	match "system"		"DEVFS";
	match "subsystem"	"CDEV";
	match "type"		"CREATE";
	match "cdev"		"(ad|ada|cd|da)[0-9]+";
	action "/etc/rc.d/gsched start $cdev";
};

1) a scheduler insert is attempted twice on startup (devd appears to run the script when it is first run)
2) using the above to insert a scheduler on a memory stick causes KDE (via hal, I assume) to loose the labels.  
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

#!/bin/sh
#
# $FreeBSD$
#
# Specify gsched_enable="YES" in /etc/rc.conf(.local) to activate scheduling on
# storage devices.  
# 
# gsched_devs is a space separated list of accepted devices.  `ALL' may be used 
# to indicate all storage devices.  
#
# gsched_flags_$dev specifies storage device specific flags (i.e. ``-a rr'' to
# use rr scheduling, see gsched(8) insert command).  

# TODO:
# - add gsched profiles, such as `desktop' for kern.geom.sched.rr tunables
# - add rejected list

# PROVIDE: gsched
# KEYWORD: nojail

. /etc/rc.subr

gsched_enable=${gsched_enable:-NO}

name="gsched"
rcvar=`set_rcvar`
command="/sbin/${name}"
start_cmd="gsched_start"
stop_cmd="gsched_stop"

gsched_filter() {
	local _gsched_devs _devs _devs_recon _kern_disks

	_kern_disks=`sysctl -n kern.disks`

	_devs=$*
	if [ -z "${_devs}" ]; then
		_devs=${_kern_disks}
	fi

	_gsched_devs=${gsched_devs}
	case ${_gsched_devs} in
		[aA][lL][lL])
			_gsched_devs=${_kern_disks}
			;;
	esac

	for _g in ${_devs}; do
		# Filter all devs that are part of gsched_devs
		case " ${_gsched_devs} " in
		    *\ ${_g}\ *)
			# Filter all devs that exist
			case " ${_kern_disks} " in
			    *\ ${_g}\ *)
				# ${_g} is part of ${gsched_dev} and it exists
				_devs_recon="${_devs_recon} ${_g}"
				;;
			esac
			;;
		esac
	done

	echo ${_devs_recon}
}

gsched_start()
{
	local _devs _g _gsched_flags

	# Make sure only accepted (and existing) devices are used
	#
	_devs=`gsched_filter $*`

	echo -n "Starting gsched devices:"

	for _g in ${_devs}; do
		echo -n " $_g"
		eval _gsched_flags=\$gsched_flags_${_g}
		${command} insert ${_gsched_flags} ${_g}
	done

	echo "."
}

gsched_stop() {
	local _devs _g

	# Make sure only accepted (and existing) devices are used
	#
	_devs=`gsched_filter $*`

	echo -n "Stopping gsched devices:"

	for _g in ${_devs}; do
		echo -n " $_g"
		${command} destroy ${_g}.sched.
	done

	echo "."
}

load_rc_config $name
run_rc_command $*


>Release-Note:
>Audit-Trail:
>Unformatted:



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