summaryrefslogtreecommitdiff
path: root/daemon
Commit message (Collapse)AuthorAgeFilesLines
* uds: set right permissions at bind() timePrasanna Kumar Kalever2020-05-291-0/+6
| | | | | | | | | | | | | | We fixed it earlier with commit 6e4f39357a90a914d11bac21cc2d2b52c07c213d but that fixes the issue when someone run the targetclid with systemd only. If we don't use targetclid.socket and want to run `targetclid` from command line, then socket.bind() will create the file with default permissions. Hence its good if we can guard the permissions right at the time of .bind() Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
* Use temp file objects for temporary storage areaPrasanna Kumar Kalever2020-04-031-13/+13
| | | | | | | | | | | | | | | | | | | | | | | happen to see yet another issue after we switch to stringIO/bytesIO: $ targetcli ls 'unicode' does not have the buffer interface After which I felt like dealing with StringIO/BytesIO is like a wild goose chase and we are after all attempting to deal with python incompatible apis. Technically speaking, the rtslib and configshell libraries are expecting a string IO stream, but then for python2 with ByteIO() we are passing a bytestream, and stringIO() is behaving a bit different in python2 than expected as explained in my previous patch. Lets simply switch to temporary file in the most secure manner possible, opening files in string mode will assure the compatibility across the platforms. At the end we wish to have a consistent behaviour across all python versions. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
* Fix StringIO/BytesIO stuck issuePrasanna Kumar Kalever2020-04-021-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We all know the way python3 handles strings is a bit different. $ python2 Python 2.7.16 (default, Apr 30 2019, 15:54:43) [GCC 9.0.1 20190312 (Red Hat 9.0.1-0.10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import io >>> s=io.BytesIO() >>> s.write('hello') 5L >>> s.getvalue() 'hello' >>> s=io.StringIO() >>> s.write('hello') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unicode argument expected, got 'str' >>> s.write(u'hello') 5L >>> s.getvalue() u'hello' >>> $ python3 Python 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import io >>> s=io.BytesIO() >>> s.write('hello') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: a bytes-like object is required, not 'str' >>> s.write(b'hello') 5 >>> s.getvalue() b'hello' >>> s=io.StringIO() >>> s.write('hello') 5 >>> s.getvalue() 'hello' >>> The way Python2 and Python3 handles String and Bytes IO is different. * In Python2 BytesIO() accepts text format syntax, and StringIO() expects unicodes * While in Python3 StringIO() accepts text format syntax, and BytesIO() expects bytes like objects I think the compatibility of using both the IO streams with python2 and python3 is compromised. Hence this patch, uses BytesIO() and StringIO() based on python version. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
* Fix targetclid daemon infinite stuckPrasanna Kumar Kalever2020-03-301-1/+1
| | | | | | | We need to open a byte IO stream because we are actually dealing with binary data in memory. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
* Use StringIO as a buffer instead of a fileMatt Coleman2019-11-071-8/+9
|
* daemon: load the prefs on every new connectionPrasanna Kumar Kalever2019-10-301-0/+3
| | | | | | | | | | | | | | | Problem: ------- Noticing inconsistency with prefs when switching between cli mode and daemon mode Solution: ------- Makesure to read/load the prefs on every new connection Thanks to 'Xiubo Li <xiubli@redhat.com>' for reporting the problem Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
* Do not print err msg when signal closes socket.Lee Duncan2019-10-101-1/+3
| | | | | | Before, we would get a "Bad File Descriptor" message when a signal causes closure of the socket while waiting on a socket message.
* Handle systemd socket activation, when present.Lee Duncan2019-10-101-29/+41
| | | | | Regular socket communications are fallen back to when no systemd socket is present.
* Close socket when receiving a signal to interrupt connection.Lee Duncan2019-10-101-0/+6
| | | | | | | This allows the main loop to get an exception in its wait loop when a signal arrives, rather than block forever. Before this, topping the daemon required sending a KILL signal or sending one last command, so that the loop could check the "received a signal" flag.
* Exit with success when getting a signal.Lee Duncan2019-10-101-1/+2
| | | | | Save the error exit for unknown exits. This makes systemd happier, since it stops us with a signal.
* Only return response to targetcli when bytes presentLee Duncan2019-10-101-3/+3
| | | | | There's no need to return a zero-length string. Before being fixed, this caused a hang when shutting down.
* Removed useless semicolons, as they're ignoredLee Duncan2019-10-101-2/+2
|
* Handle OSError correctly: use strerror to get stringLee Duncan2019-10-101-4/+4
|
* Handle Python 3.7 stricter binary vs. string rules.Lee Duncan2019-10-101-4/+4
| | | | | | | | We can no longer have python automatically convert binary to/from string data, so be explicit about it. Also, the TargetCLI __del__ method was testing for a non-existant attribute, so close our socket if open.
* Fix indention for targetclid when processing output.Lee Duncan2019-10-101-3/+3
| | | | | | The indentation was wrong, causing the daemon to only process the last block of outout, which would only show up with a lot of output.
* Fix a syntax error in some except clausesChristophe Vu-Brugier2019-08-011-1/+1
| | | | | | | "except Exception, e" triggers a syntax error on Python 3.7. The correct syntax is "except Exception as e". This patch fixes issue #142.
* targetcli: serialize multiple requestsPrasanna Kumar Kalever2019-07-311-47/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* targetclid: add daemonize component for targetcliPrasanna Kumar Kalever2019-06-111-0/+299
Problem: ------- Overall creation time of a block using targetcli is raising linearly as the block count increase. This is because of the recurring issue involving refresh(reload) at multiple objects/places, as the LIO's configfs is deeply nested. Earlier discussion of the problem statement with stats and graphs about delays: http://bit.ly/targetcli-create-delay Solution: -------- Introduce a daemon component for targetcli[d] which will retain state of Configshell object in memory, so that any new requests can directly use it, instead of loading the storageObjects/targetObjects again. Details about "how to use it ?": ------------------------------- $ systemctl start targetclid $ systemctl status targetclid ● targetclid.service - Targetcli daemon Loaded: loaded (/usr/lib/systemd/system/targetclid.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2019-04-10 12:19:51 IST; 2h 17min ago Main PID: 3950 (targetclid) Tasks: 3 (limit: 4915) CGroup: /system.slice/targetclid.service └─3950 /usr/bin/python /usr/bin/targetclid Apr 10 12:19:51 localhost.localdomain systemd[1]: Started Targetcli daemon. $ targetcli help Usage: /usr/bin/targetcli [--version|--help|CMD|--tcp] --version Print version --help Print this information CMD Run targetcli shell command and exit <nothing> Enter configuration shell --tcp CMD Pass targetcli command to targetclid --tcp <nothing> Enter multi-line command mode for targetclid See man page for more information. One line command usage: ---------------------- $ targetcli --tcp CMD Eg: $ targetcli --tcp pwd / Multiple line commands usage: ---------------------------- $ targetcli --tcp CMD1 CMD2 . . CMDN exit Eg: $ targetcli --tcp ^Tab / backstores/ iscsi/ loopback/ vhost/ xen-pvscsi/ cd clearconfig exit get help ls pwd refresh restoreconfig saveconfig set status pwd get global logfile get global auto_save_on_exit / saveconfig exit output follows: / logfile=/var/log/gluster-block/gluster-block-configshell.log auto_save_on_exit=false Configuration saved to /etc/target/saveconfig.json Stats with and without changes: ------------------------------ Running simple 'pwd' command after creating 1000 blocks on a node: Without this change: $ time targetcli pwd / real 0m8.963s user 0m7.775s sys 0m1.103s with daemonize changes: $ time targetcli --tcp "pwd" / real 0m0.126s user 0m0.099s sys 0m0.024s Thanks to Maurizio for hangingout with me for all the discussions involved. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>