summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurizio Lombardi <mlombard@redhat.com>2019-10-31 17:35:35 +0100
committerGitHub <noreply@github.com>2019-10-31 17:35:35 +0100
commit67f75e6d7c7639cdc8fa9b5f4f6f41adcb90ed61 (patch)
tree5c0f97679676a452728a63913b999aa69aa15578
parent6e3146fa514042938549d7b0f17724a7aa759e17 (diff)
parent47e981a9c81ad03d8f0509ebf2fd4917ea2215d7 (diff)
downloadtargetcli-67f75e6d7c7639cdc8fa9b5f4f6f41adcb90ed61.tar.gz
Merge pull request #153 from pkalever/improve-daemon-exp
Improve user experience with daemonized appoach
-rwxr-xr-xdaemon/targetclid3
-rwxr-xr-xscripts/targetcli28
-rw-r--r--systemd/targetclid.service2
-rw-r--r--systemd/targetclid.socket2
-rw-r--r--targetcli.88
-rw-r--r--targetclid.886
6 files changed, 121 insertions, 8 deletions
diff --git a/daemon/targetclid b/daemon/targetclid
index 156a25c..fb472dc 100755
--- a/daemon/targetclid
+++ b/daemon/targetclid
@@ -142,6 +142,9 @@ class TargetCLI:
'''
Handle commands from client
'''
+ # load the prefs
+ self.shell.prefs.load()
+
still_listen = True
# Receive the data in small chunks and retransmit it
while still_listen:
diff --git a/scripts/targetcli b/scripts/targetcli
index cb97b2b..49355e3 100755
--- a/scripts/targetcli
+++ b/scripts/targetcli
@@ -67,13 +67,14 @@ class TargetCLI(ConfigShell):
}
def usage():
- print("Usage: %s [--version|--help|CMD|--tcp]" % sys.argv[0], file=err)
+ print("Usage: %s [--version|--help|CMD|--tcp|--disable-daemon]" % sys.argv[0], file=err)
print(" --version\t\tPrint version", file=err)
print(" --help\t\tPrint this information", file=err)
print(" CMD\t\t\tRun targetcli shell command and exit", file=err)
print(" <nothing>\t\tEnter configuration shell", file=err)
print(" --tcp CMD\t\tPass targetcli command to targetclid", file=err)
print(" --tcp <nothing>\tEnter multi-line command mode for targetclid", file=err)
+ print(" --disable-daemon\tTurn-off the global auto use daemon flag", file=err)
print("See man page for more information.", file=err)
sys.exit(-1)
@@ -133,6 +134,11 @@ def call_daemon(shell, req):
sock.connect(socket_path)
except socket.error as err:
shell.con.display(shell.con.render_text(err, 'red'))
+ shell.con.display(
+ shell.con.render_text("Currently auto_use_daemon is true, "
+ "hence please make sure targetclid daemon is running ...\n"
+ "(or)\nIncase if you wish to turn auto_use_daemon to false "
+ "then run '#targetcli --disable-daemon'", 'red'))
sys.exit(1)
try:
@@ -157,7 +163,7 @@ def call_daemon(shell, req):
sock.close()
sys.exit(0)
-def get_arguments():
+def get_arguments(shell):
readline.set_completer(completer)
readline.set_completer_delims('')
@@ -174,7 +180,13 @@ def get_arguments():
command = " ".join(sys.argv[argstart:])
else:
inputs = []
+ shell.con.display("targetcli shell version %s\n"
+ "Entering targetcli batch mode for daemonized approach.\n"
+ "Enter multiple commands separated by newline and "
+ "type 'exit' to run them all in one go.\n"
+ % targetcli_version)
while True:
+ shell.con.raw_write("/> ")
command = six.moves.input()
if command.lower() == "exit":
break
@@ -212,13 +224,16 @@ def main():
if shell.prefs['auto_use_daemon']:
use_daemon = True
+ disable_daemon=False
if len(sys.argv) > 1:
usage_version(sys.argv[1])
if sys.argv[1] in ("tcp", "--tcp", "-t"):
use_daemon = True
+ elif sys.argv[1] in ("disable-daemon", "--disable-daemon"):
+ disable_daemon=True
- if use_daemon:
- call_daemon(shell, get_arguments().encode())
+ if use_daemon and not disable_daemon:
+ call_daemon(shell, get_arguments(shell).encode())
# does not return
try:
@@ -232,7 +247,10 @@ def main():
if len(sys.argv) > 1:
try:
- shell.run_cmdline(" ".join(sys.argv[1:]))
+ if disable_daemon:
+ shell.run_cmdline('set global auto_use_daemon=false')
+ else:
+ shell.run_cmdline(" ".join(sys.argv[1:]))
except Exception as e:
print(str(e), file=sys.stderr)
sys.exit(1)
diff --git a/systemd/targetclid.service b/systemd/targetclid.service
index c337e3b..dd1b54c 100644
--- a/systemd/targetclid.service
+++ b/systemd/targetclid.service
@@ -1,6 +1,6 @@
[Unit]
Description=Targetcli daemon
-Documentation=man:targetcli(8)
+Documentation=man:targetclid(8)
After=network.target
[Service]
diff --git a/systemd/targetclid.socket b/systemd/targetclid.socket
index 079f0c7..4730fce 100644
--- a/systemd/targetclid.socket
+++ b/systemd/targetclid.socket
@@ -1,6 +1,6 @@
[Unit]
Description=targetclid socket
-Documentation=man:targetcli(8)
+Documentation=man:targetclid(8)
[Socket]
ListenStream=/var/run/targetclid.sock
diff --git a/targetcli.8 b/targetcli.8
index 61f4b64..a73f785 100644
--- a/targetcli.8
+++ b/targetcli.8
@@ -10,6 +10,11 @@ administrator to assign local storage resources backed by either
files, volumes, local SCSI devices, or ramdisk, and export them to
remote systems via network fabrics, such as iSCSI or FCoE.
.P
+There is a daemon component for targetcli, which will greatly improve
+the overall execution time taken by targetcli commands at scale. For
+more details about switching to daemonized mode refer to targetclid(8)
+man page.
+.P
The configuration layout is tree-based, similar to a filesystem, and
is navigated in a similar manner.
.SH USAGE
@@ -458,8 +463,9 @@ the userid and password for full-feature phase for this ACL.
.B /etc/target/backup/*
.SH ENVIRONMENT
.SS TARGETCLI_HOME
-If set, this variable points to a directory that should be used instead of ~/.targetctl
+If set, this variable points to a directory that should be used instead of ~/.targetcli
.SH SEE ALSO
+.BR targetclid (8),
.BR targetctl (8),
.BR tcmu-runner (8)
.SH AUTHOR
diff --git a/targetclid.8 b/targetclid.8
new file mode 100644
index 0000000..a2518b4
--- /dev/null
+++ b/targetclid.8
@@ -0,0 +1,86 @@
+.TH targetclid 8
+.SH NAME
+.B targetclid
+\- daemon component for targetcli
+.SH DESCRIPTION
+.B targetclid
+is the daemon component of targetcli, which will help retain state of various
+configfs object in memory, hence any new request/command can directly use the
+in memory objects instead of reconstructing them by parsing through the entire
+configfs files again and again for each and every single command. This will
+greatly improve the overall execution time taken by targetcli commands at scale.
+
+.SH USAGE
+.B targetclid [cmd]
+.br
+.B "--help"
+for additional usage information.
+.br
+.B "--version"
+for version information.
+.SH QUICKSTART & EXAMPLES
+.TP
+To start using the daemon, one need to enable targetclid socket,
+.br
+$ systemctl enable targetclid.socket
+.TP
+If you would like to use the daemonized approach as default method then,
+.br
+$ targetcli set global auto_use_daemon=true
+.br
+$ targetcli ls
+.TP
+You can use batch mode for sending multiple commands in one go,
+.br
+$ targetcli <hit-enter>
+.br
+targetcli shell version 2.1.50
+.br
+Entering targetcli batch mode for daemonized approach.
+.br
+Enter multiple commands separated by newline and type 'exit' to run them all in one go.
+.br
+/> ls
+.br
+/> pwd
+.br
+/> get global loglevel_file
+.br
+/> exit
+.br
+.TP
+You can set preference to stop using daemonized mode even when the daemon is not running,
+.br
+$ targetcli --disable-daemon
+.TP
+If you want to selectively run commands through daemon while default mode is cli (auto_use_daemon=false), you can use,
+.br
+$ targetcli --tcp ls
+.br
+For batch mode,
+.br
+$ targetcli --tcp <hit-enter>
+.P
+.SH FILES
+.B /etc/target/saveconfig.json
+.br
+.B /etc/target/backup/*
+.br
+.B /var/run/targetclid.sock
+.br
+.B /var/run/targetclid.pid
+.SH ENVIRONMENT
+.SS TARGETCLI_HOME
+If set, this variable points to a directory that should be used instead of ~/.targetcli
+.SH SEE ALSO
+.BR targetcli (8),
+.BR targetctl (8),
+.BR tcmu-runner (8)
+.SH AUTHOR
+Written by Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
+.br
+Man page written by Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
+.SH REPORTING BUGS
+Report bugs via <targetcli-fb-devel@lists.fedorahosted.org>
+.br
+or <https://github.com/open-iscsi/targetcli-fb/issues>