Permalink
Browse files

Flashcache init script - basic

  • Loading branch information...
1 parent 140990e commit 2ce099e8cd8adbc9798822bb6d0e835ffd2dde3f @boopathi boopathi committed Sep 22, 2012
Showing with 91 additions and 0 deletions.
  1. +91 −0 utils/flashcache
View
91 utils/flashcache 100644 → 100755
@@ -0,0 +1,91 @@
+#!/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
+
+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
+ /sbin/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 /var/lock/subsys/flashcache
+}
+
+stop() {
+ #unmount
+ /bin/umount $MOUNTPOINT
+ /sbin/sysctl -w dev.flashcache.$FLASHCACHE_NAME.fast_remove=0
+ echo "Flushing flashcache: Flushes to $BACKEND_DISK"
+ dmsetup remove $CACHEDEV_NAME
+ #unlock subsys
+ rm -f /var/lock/subsys/flashcache
+}
+
+status() {
+ [ -f /var/lock/subsys/flashcache ] && echo "Flashcache status: loaded" || echo "Flashcache status: NOT loaded";
+ exit 0
+}
+
+case $1 in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|status}"
+ exit 1
+esac
+
+exit 0

0 comments on commit 2ce099e

Please sign in to comment.