Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- CACHEPARAMS="512 1 writethrough default 0"
- CACHEDEVICES="o=/dev/mapper/storage c=/dev/mapper/suse-cache"
- MAPPER="storagecached"
- if [ "$(id -u)" != "0" ] ; then
- echo "Must be run as root - exiting"
- exit
- fi
- if [ "$1" == "-u" ] ; then
- {
- for i in $CACHEDEVICES ; do
- if [ "`echo $i | grep \"^c=\"`" != "" ] ; then
- __CACHEDEV=${i:2}
- elif [ "`echo $i | grep \"^o=\"`" != "" ] ; then
- __ORIGINALDEV=${i:2}
- fi
- done
- echo \^ $MAPPER \| $__CACHEDEV \$
- dmsetup suspend $MAPPER
- dmsetup remove $MAPPER
- dmsetup remove `basename $__CACHEDEV`-blocks
- dmsetup remove `basename $__CACHEDEV`-metadata
- unset __ORIGINALDEV
- unset __CACHEDEV
- }
- else
- {
- for i in $CACHEDEVICES ; do
- if [ "`echo $i | grep \"^c=\"`" != "" ] ; then
- __CACHEDEV=${i:2}
- elif [ "`echo $i | grep \"^o=\"`" != "" ] ; then
- __ORIGINALDEV=${i:2}
- fi
- done
- if [ "$__CACHEDEV" == "" ] ; then
- echo -e "${C_LIGHT_RED}Devices list invalid${C_OFF}" ; exit ; fi
- if [ "$__ORIGINALDEV" == "" ] ; then
- echo -e "${C_LIGHT_RED}Devices list invalid${C_OFF}" ; exit ; fi
- if [ -e "$__CACHEDEV" ] ; then echo -n
- else
- echo -e "${C_LIGHT_RED}Devices list invalid${C_OFF}" ; exit ; fi
- if [ -e "$__ORIGINALDEV" ] ; then echo -n
- else
- echo -e "${C_LIGHT_RED}Devices list invalid${C_OFF}" ; exit ; fi
- __CACHEDEVSIZE="`blockdev --getsize64 \"$__CACHEDEV\"`"
- __CACHEMETASIZE="$(((4194304 + (16 * $__CACHEDEVSIZE / 262144))/512))"
- if [ "$__CACHEMETASIZE" == ""$(((4194303 + (16 * $__CACHEDEVSIZE / 262144))/512))"" ] ; then
- __CACHEMETASIZE="$(($__CACHEMETASIZE + 1))" ; fi
- __CACHEBLOCKSSIZE="$((($__CACHEDEVSIZE/512) - $__CACHEMETASIZE))"
- __ORIGINALDEVSIZE="`blockdev --getsz $__ORIGINALDEV`"
- echo \^ $__CACHEDEV \| $__CACHEMETASIZE \| $__CACHEBLOCKSSIZE \| $MAPPER \| $__ORIGINALDEVSIZE \| $__ORIGINALDEV \| $CACHEPARAMS \$
- echo dmsetup create `basename $__CACHEDEV`-metadata --table "0 $__CACHEMETASIZE linear /dev/mapper/suse-cache 0"
- echo dmsetup create `basename $__CACHEDEV`-blocks --table "0 $__CACHEBLOCKSSIZE linear /dev/mapper/suse-cache $__CACHEMETASIZE"
- echo dmsetup create $MAPPER --table "0 $__ORIGINALDEVSIZE cache /dev/mapper/`basename $__CACHEDEV`-metadata /dev/mapper/`basename $__CACHEDEV`-blocks $__ORIGINALDEV $CACHEPARAMS"
- echo dmsetup resume $MAPPER
- dmsetup create `basename $__CACHEDEV`-metadata --table "0 $__CACHEMETASIZE linear /dev/mapper/suse-cache 0"
- dmsetup create `basename $__CACHEDEV`-blocks --table "0 $__CACHEBLOCKSSIZE linear /dev/mapper/suse-cache $__CACHEMETASIZE"
- dmsetup create $MAPPER --table "0 $__ORIGINALDEVSIZE cache /dev/mapper/`basename $__CACHEDEV`-metadata /dev/mapper/`basename $__CACHEDEV`-blocks $__ORIGINALDEV $CACHEPARAMS"
- dmsetup resume $MAPPER
- unset __ORIGINALDEV
- unset __ORIGINALDEVSIZE
- unset __CACHEDEV
- unset __CACHEDEVSIZE
- unset __CACHEMETASIZE
- unset __CACHEBLOCKSSIZE
- }
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement