Initial commit
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
56
utils/open-cas-loader
Executable file
56
utils/open-cas-loader
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python2
|
||||
#
|
||||
# Copyright(c) 2012-2019 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
import subprocess
|
||||
import time
|
||||
import opencas
|
||||
import sys
|
||||
import os
|
||||
import syslog as sl
|
||||
|
||||
def wait_for_cas_ctrl():
|
||||
for i in range(30): # timeout 30s
|
||||
if os.path.exists('/dev/cas_ctrl'):
|
||||
return
|
||||
time.sleep(1)
|
||||
|
||||
try:
|
||||
subprocess.call(['/sbin/modprobe', 'cas_cache'])
|
||||
except:
|
||||
sl.syslog(sl.LOG_ERR, 'Unable to probe cas_cache module')
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
config = opencas.cas_config.from_file('/etc/opencas/opencas.conf',
|
||||
allow_incomplete=True)
|
||||
except Exception as e:
|
||||
sl.syslog(sl.LOG_ERR,
|
||||
'Unable to load opencas config. Reason: {0}'.format(str(e)))
|
||||
exit(1)
|
||||
|
||||
for cache in config.caches.values():
|
||||
if sys.argv[1] == os.path.realpath(cache.device):
|
||||
try:
|
||||
wait_for_cas_ctrl()
|
||||
opencas.start_cache(cache, True)
|
||||
except opencas.casadm.CasadmError as e:
|
||||
sl.syslog(sl.LOG_WARNING,
|
||||
'Unable to load cache {0} ({1}). Reason: {2}'
|
||||
.format(cache.cache_id, cache.device, e.result.stderr))
|
||||
exit(e.result.exit_code)
|
||||
exit(0)
|
||||
for core in cache.cores.values():
|
||||
if sys.argv[1] == os.path.realpath(core.device):
|
||||
try:
|
||||
wait_for_cas_ctrl()
|
||||
opencas.add_core(core, True)
|
||||
except opencas.casadm.CasadmError as e:
|
||||
sl.syslog(sl.LOG_WARNING,
|
||||
'Unable to attach core {0} from cache {1}. Reason: {2}'
|
||||
.format(core.device, cache.cache_id, e.result.stderr))
|
||||
exit(e.result.exit_code)
|
||||
exit(0)
|
||||
Reference in New Issue
Block a user