summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2019-07-31 17:31:33 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2019-07-31 17:49:43 +0530
commitb85561a4e8b6613a87a5f055a1365e2a97594de6 (patch)
tree22156b570af90cd7cacc67f0b7df7b2e649ad1df /daemon
parent85031ad48b011f5626cd0a287749abcaa145277b (diff)
downloadtargetcli-b85561a4e8b6613a87a5f055a1365e2a97594de6.tar.gz
targetcli: serialize multiple requests
Problem: ------- targetcli/rtslib cannot handle parallel requests at the moment. Read more about this at http://bit.ly/targetcli-parallel-requests-issue $ for i in {1..10}; do \ targetcli /backstores/fileio create ${i} /tmp/file${i} 10M& done Created fileio 1 with size 10485760 This _Backstore already exists in configFS This _Backstore already exists in configFS This _Backstore already exists in configFS This _Backstore already exists in configFS This _Backstore already exists in configFS Created fileio 6 with size 10485760 Created fileio 2 with size 10485760 This _Backstore already exists in configFS Created fileio 8 with size 10485760 Created fileio 9 with size 10485760 bails-out most of the time with above errors and sometimes even crashes. Solution: -------- Serialize/defend the parallel requests by simply taking a wait lock at targetcli level, so that only one request can be processed by targetcli at any given point in time. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'daemon')
-rwxr-xr-xdaemon/targetclid47
1 files changed, 0 insertions, 47 deletions
diff --git a/daemon/targetclid b/daemon/targetclid
index b909c6e..06ffbe8 100755
--- a/daemon/targetclid
+++ b/daemon/targetclid
@@ -44,8 +44,6 @@ class TargetCLI:
self.socket_path = '/var/run/targetclid.sock'
# pid file for defending on multiple daemon runs
self.pid_file = '/var/run/targetclid.pid'
- # lockfile for serializing multiple client requests
- self.lock_file = '/var/run/targetclid.lock'
self.NoSignal = True
@@ -85,16 +83,6 @@ class TargetCLI:
self.pfd.close()
sys.exit(1)
- try:
- self.lkfd = open(self.lock_file, 'w+');
- except IOError as e:
- self.display(
- self.render(
- "opening lockfile failed: %s" %str(e),
- 'red'))
- self.pfd.close()
- sys.exit(1)
-
# Keep track, for later use
self.con_stdout_ = self.con._stdout
self.con_stderr_ = self.con._stderr
@@ -104,9 +92,6 @@ class TargetCLI:
'''
destructor
'''
- if not self.lkfd.closed:
- self.lkfd.close()
-
if not self.pfd.closed:
self.pfd.close()
@@ -149,40 +134,10 @@ class TargetCLI:
self.pfd.close()
- def try_op_lock(self):
- '''
- acquire a blocking lock on lockfile, to serialize multiple client requests
- '''
- try:
- fcntl.flock(self.lkfd, fcntl.LOCK_EX) # wait here until ongoing request is finished
- except Exception, e:
- self.display(
- self.render(
- "taking lock on lockfile failed: %s" %str(e),
- 'red'))
- sys.exit(1)
-
-
- def release_op_lock(self):
- '''
- release blocking lock on lockfile, which can allow other requests process
- '''
- try:
- fcntl.flock(self.lkfd, fcntl.LOCK_UN) # allow other requests now
- except Exception, e:
- self.display(
- self.render(
- "unlock on lockfile failed: %s" %str(e),
- 'red'))
- sys.exit(1)
-
-
def client_thread(self, connection):
'''
Handle commands from client
'''
- self.try_op_lock()
-
still_listen = True
# Receive the data in small chunks and retransmit it
while still_listen:
@@ -212,8 +167,6 @@ class TargetCLI:
connection.sendall(var) # length of string
connection.sendall(output) # actual string
- self.release_op_lock()
-
def usage():
print("Usage: %s [--version|--help]" % sys.argv[0], file=err)