Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Device Failure Handling and other minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: sanoj <sunnikrishnan@stec-inc.com>
  • Loading branch information
sanoj-stec committed Apr 12, 2013
1 parent 35a2b18 commit d88c2bc
Showing 1 changed file with 66 additions and 12 deletions.
78 changes: 66 additions & 12 deletions CLI/eio_cli
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,84 @@ SUBSYSTEM!="block", GOTO="EIO_EOF"
EnhanceIO device so ignore it.
GOTO="EIO_EOF"
#=================== EIO_CACHE =======================
# If we just found the cache device and the source already \
exists then we can setup
LABEL="EIO_CACHE"
TEST!="/dev/enhanceio/<cache_name>", \
PROGRAM="/bin/mkdir -p /dev/enhanceio/<cache_name>"
PROGRAM="/bin/sh -c 'echo $kernel > /dev/enhanceio/<cache_name>/.ssd_name'"
TEST=="/proc/enhanceio/<cache_name>", \
RUN+="/sbin/eio_cli notify -a add -s /dev/$kernel -c <cache_name>", \
GOTO="EIO_EOF"
TEST=="/dev/enhanceio/<cache_name>/.disk_name", GOTO="EIO_SETUP"
GOTO="EIO_EOF"
#=================== EIO_SOURCE =======================
# If we just found the source device and the cache already \
exists then we can setup
LABEL="EIO_SOURCE"
TEST=="/dev/enhanceio/<cache_name>/.eio_delete", GOTO="EIO_SOURCE_DELETE"
TEST!="/dev/enhanceio/<cache_name>", PROGRAM="/bin/mkdir -p \
/dev/enhanceio/<cache_name>"
PROGRAM="/bin/sh -c 'echo $kernel > /dev/enhanceio/<cache_name>/.disk_name'"
PROGRAM="/bin/sh -c 'echo $major $minor > \
/dev/enhanceio/<cache_name>/.disk_mjr_mnr'"
PROGRAM="/bin/sh -c 'echo $links > \
/dev/enhanceio/<cache_name>/.srclinks'"
TEST=="/proc/enhanceio/<cache_name>",\
PROGRAM="/bin/grep 'state\s*failed' /proc/enhanceio/<cache_name>/config", \
PROGRAM="/bin/grep 'no_source_dev\s*1' /proc/enhanceio/<cache_name>/errors", \
RUN+="/sbin/eio_admin notify -a add -d /dev/$kernel -c <cache_name>", NAME="", \
GOTO="EIO_EOF"
TEST!="/proc/enhanceio/<cache_name>", \
TEST!="/dev/enhanceio/<cache_name>/.eio_delete", ACTION!="change", NAME=""
TEST=="/dev/enhanceio/<cache_name>/.ssd_name", GOTO="EIO_SETUP"
PROGRAM="/bin/sh -c 'blockdev --setro $kernel'"
GOTO="EIO_EOF"
#=================== EIO_SOURCE_DELETE =======================
LABEL="EIO_SOURCE_DELETE"
PROGRAM="/bin/sh -c 'cat /dev/enhanceio/<cache_name>/.disk_name'", \
ENV{disk_name}="%c"
TEST=="/dev/enhanceio/<cache_name>/.disk_name", ENV{disk_name}=="?*", \
NAME="$env{disk_name}"
PROGRAM="/bin/unlink /dev/enhanceio/<cache_name>/.disk_name"
PROGRAM="/bin/unlink /dev/enhanceio/<cache_name>/.disk_mjr_mnr"
GOTO="EIO_EOF"
#=================== EIO_SETUP =======================
LABEL="EIO_SETUP"
PROGRAM="/bin/sh -c 'cat /dev/enhanceio/<cache_name>/.ssd_name'", \
ENV{ssd_name}="%c"
PROGRAM="/bin/sh -c 'cat /dev/enhanceio/<cache_name>/.disk_name'", \
ENV{disk_name}="%c"
TEST!="/proc/enhanceio/<cache_name>", \
TEST!="/dev/enhanceio/<cache_name>/.skip_enable", \
RUN+="/bin/sh -c '/bin/mknod /dev/$env{disk_name} b \
`/bin/cat /dev/enhanceio/<cache_name>/.disk_mjr_mnr`'"
TEST!="/proc/enhanceio/<cache_name>", \
RUN+="/bin/sh -c ' for i in `cat /dev/enhanceio/<cache_name>/.srclinks`; \
do rm -f /dev/$$i; ln -f -s /dev/$env{disk_name} /dev/$$i; done'"
TEST!="/proc/enhanceio/<cache_name>", RUN+="/sbin/eio_cli \
enable -d /dev/$env{disk_name} -s /dev/$env{ssd_name} -m <mode> \
-b <block_size> -c <cache_name>"
-b <block_size> -p <policy> -c <cache_name>"
LABEL="EIO_EOF"
"""
Expand Down Expand Up @@ -249,6 +294,11 @@ class Cache_rec(Structure):
print "Block Size : " + str(self.blksize)
print "Associativity : " + str(self.assoc)

if os.path.exists("/proc/enhanceio/" + self.name):
cmd = "cat /proc/enhanceio/" + self.name + "/config" + " | grep state"
status = run_cmd(cmd)
print "State : " + status.output.split()[1]

pass


Expand Down Expand Up @@ -337,10 +387,9 @@ class Cache_rec(Structure):
if self.get_cache_info() == SUCCESS:
if mode != 0:
self.mode = mode
elif policy != 0:
if policy != 0:
self.policy = policy

self.print_info()
if self.do_eio_ioctl(EIO_IOC_EDIT) == SUCCESS:
self.create_rules()
print 'Cache edited Successfully'
Expand All @@ -361,14 +410,16 @@ class Cache_rec(Structure):
cache_match_expr = make_udev_match_expr(self.ssd_name, self.name)
print cache_match_expr
modes = {3:"wt", 1:"wb", 2:"ro",0:"N/A"}
policies = {3:"rand", 1:"fifo", 2:"lru", 0:"N/A"}

try:
udev_rule = udev_template.replace("<cache_name>",\
self.name).replace("<source_match_expr>",\
source_match_expr).replace("<cache_match_expr>",\
cache_match_expr).replace("<mode>",\
modes[self.mode]).replace("<block_size>",\
str(self.blksize))
str(self.blksize)).replace("<policy>",\
policies[self.policy])

# write rule file
rule_file_path = "/etc/udev/rules.d/94-enhanceio-" + \
Expand All @@ -388,12 +439,16 @@ class Cache_rec(Structure):
print "No cache exists with the name " + self.name
return FAILURE

run_cmd("/bin/touch /dev/enhanceio/" + self.name + "/.eio_delete")

if self.do_eio_ioctl(EIO_IOC_DELETE) == SUCCESS:
if self.delete_rules() == SUCCESS:
return SUCCESS
else:
print 'Cache deletion failed (dmesg can provide you more info)'

run_cmd("/bin/rm -f /dev/enhanceio/" + self.name + "/.eio_delete")

return FAILURE


Expand All @@ -407,7 +462,7 @@ class Cache_rec(Structure):
return SUCCESS
except Exception as e:
print "Unable to delete rule file" + \
"(please emove it manually)"
"(please remove it manually)"
print e
return FAILURE

Expand All @@ -429,8 +484,8 @@ class Dev_info:
def get_device_size_info(self,name):
fd = open(name,"r")

status = run_cmd("blockdev --getsize "+ name);
self.dev_size = int(status.output.split()[0]) * 512
status = run_cmd("blockdev --getsize64 "+ name);
self.dev_size = int(status.output.split()[0])

status = run_cmd("blockdev --getss "+ name);
self.dev_sect_size = int(status.output.split()[0])
Expand Down Expand Up @@ -462,7 +517,7 @@ def create_parser():
about currently create caches')

#clean
parser_clean = parser.add_parser('clean', help='clean the drity blocks \
parser_clean = parser.add_parser('clean', help='clean the dirty blocks \
in the cache (Applicable only to writeback caches)')
parser_clean.add_argument("-c", action="store", dest="cache",required=True)

Expand Down Expand Up @@ -501,14 +556,14 @@ def create_parser():
parser_enable.add_argument("-c", action="store", dest="cache", required=True)

#notify
parser_notify = parser.add_parser('notify_ssd_add')
parser_notify = parser.add_parser('notify')
parser_notify.add_argument("-s", action="store", dest="ssd",\
help="name of the ssd device")
parser_notify.add_argument("-a", action="store", dest="action",\
help="add/remove/reboot")
parser_notify.add_argument("-d", action="store", dest="hdd",\
required=True,\
help="name of the source device")
parser_notify.add_argument("-c", action="store", dest="cache", required=True)

#sanity
parser_sanity = parser.add_parser('sanity')
Expand Down Expand Up @@ -575,7 +630,6 @@ def main():

elif sys.argv[1] == "notify":
# This command will be fired by udev rule on SSD/Source addition

if args.action == "reboot":
cache = Cache_rec(name = "dummy")
cache.do_eio_ioctl(EIO_IOC_ENABLE)
Expand Down

0 comments on commit d88c2bc

Please sign in to comment.