File: flashcache

package info (click to toggle)
flashcache 3.1.3%2Bgit20150701-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,116 kB
  • ctags: 1,310
  • sloc: ansic: 9,797; sh: 403; perl: 329; makefile: 201
file content (104 lines) | stat: -rwxr-xr-x 2,140 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#
# flashcache	Init Script to manage cachedev loads
#
# chkconfig: 345 9 98
# 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
[ -z "$SSD_DISK" ] && exit 10
[ -z "$BACKEND_DISK" ] && exit 11
[ -z "$CACHEDEV_NAME" ] && exit 12
[ -z "$MOUNTPOINT" ] && exit 13
[ -z "$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