Utility to load and unload flashcache #83

Merged
merged 6 commits into from Sep 24, 2012
View
24 doc/flashcache-sa-guide.txt
@@ -147,6 +147,30 @@ Flashcache stats are also reported in
/proc/flashcache/<cache name>/flashcache_stats
for easier parseability.
+Using Flashcache sysVinit script (Redhat based systems):
+=======================================================
+Kindly note that, this sections only applies to the Redhat based systems. Use
+'utils/flashcache' from the repository as the sysvinit script.
+
+This script is to load, unload and get statistics of an existing flashcache
+writeback cache volume. It helps in loading the already created cachedev during
+system boot and removes the flashcache volume before system halt happens.
+
+This script is necessary, because, when a flashcache volume is not removed
+before the system halt, kernel panic occurs.
+
+Configuring the script using chkconfig:
+
+1. Copy 'utils/flashcache' from the repo to '/etc/init.d/flashcache'
+2. Make sure this file has execute permissions,
+ 'sudo chmod +x /etc/init.d/flashcache'.
+3. Edit this file and specify the values for the following variables
+ SSD_DISK, BACKEND_DISK, CACHEDEV_NAME, MOUNTPOINT, FLASHCACHE_NAME
+4. Modify the headers in the file if necessary.
+ By default, it starts in runlevel 3, with start-stop priority 90-10
+5. Register this file using chkconfig
+ 'chkconfig --add /etc/init.d/flashcache'
+
Cache Blocksize selection :
=========================
Cache blocksize selection is critical for good cache utilization and
View
104 utils/flashcache
@@ -0,0 +1,104 @@
+#!/bin/bash
+#
+# flashcache Init Script to manage cachedev loads
+#
+# chkconfig: 345 90 10
+# description: Flashcache Management
+
+# Flashcache options
+# modify this before using this init script
+
+SSD_DISK=
+BACKEND_DISK=
+CACHEDEV_NAME=
+MOUNTPOINT=
+FLASHCACHE_NAME=
+
+# Just a check, to validate the above params are set
+[ -n "$SSD_DISK" ] && exit 10
+[ -n "$BACKEND_DISK" ] && exit 11
+[ -n "$CACHEDEV_NAME" ] && exit 12
+[ -n "$MOUNTPOINT" ] && exit 13
+[ -n "$FLASHCACHE_NAME" ] && exit 14
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+#globals
+DMSETUP=`/usr/bin/which dmsetup`
+SERVICE=flashcache
+FLASHCACHE_LOAD=/sbin/flashcache_load
+SUBSYS_LOCK=/var/lock/subsys/$SERVICE
+
+RETVAL=0
+
+start() {
+ echo "Starting Flashcache..."
+ #Load the module
+ /sbin/modprobe flashcache
+ RETVAL=$?
+ if [ $RETVAL -ne 0 ]; then
+ echo "Module Load Error: flashcache. Exited with status - $RETVAL"
+ exit $RETVAL
+ fi
+ #flashcache_load the cachedev
+ $FLASHCACHE_LOAD $SSD_DISK $CACHEDEV_NAME
+ RETVAL=$?
+ if [ $RETVAl -ne 0 ]; then
+ echo "Failed: flashcache_load $SSD_DISK $CACHEDEV_NAME"
+ exit $RETVAL;
+ fi
+ #mount
+ if [ -L /dev/mapper/$CACHEDEV_NAME ]; then
+ /bin/mount /dev/mapper/$CACHEDEV_NAME $MOUNTPOINT
+ RETVAL=$?
+ if [ $RETVAL -ne 0 ]; then
+ echo "Mount Failed: /dev/mapper/$CACHEDEV_NAME to $MOUNTPOINT"
+ exit $RETVAL
+ fi
+ else
+ echo "Not Found: /dev/mapper/$CACHEDEV_NAME"
+ exit 1
+ fi
+ #lock subsys
+ touch $SUBSYS_LOCK
+}
+
+stop() {
+ #unmount
+ /bin/umount $MOUNTPOINT
+ #check for force flag
+ FLAG=0
+ [ "$1" == '--force' ] && FLAG=1
+ /sbin/sysctl -w dev.flashcache.$FLASHCACHE_NAME.fast_remove=$FLAG
+ echo "Flushing flashcache: Flushes to $BACKEND_DISK"
+ $DMSETUP remove $CACHEDEV_NAME
+ #unlock subsys
+ rm -f $SUBSYS_LOCK
+}
+
+status() {
+ [ -f $SUBSYS_LOCK ] && echo "Flashcache status: loaded" || echo "Flashcache status: NOT loaded";
+ $DMSETUP status $CACHEDEV_NAME
+ exit $?
+}
+
+case $1 in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
+ ;;
+ forcestop)
+ stop --force
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|status}"
+ exit 1
+esac
+
+exit 0