nstool: Reverse parameters to nstool
Having the "subcommand" first is more conventional and will make it more natural for future extensions I have planned. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
4914fce77b
commit
2884ccd2e7
2 changed files with 28 additions and 28 deletions
|
@ -77,8 +77,8 @@ setup_pasta() {
|
||||||
|
|
||||||
layout_pasta
|
layout_pasta
|
||||||
|
|
||||||
context_run_bg unshare "unshare -rUnpf ${NSTOOL} ${STATESETUP}/ns.hold hold"
|
context_run_bg unshare "unshare -rUnpf ${NSTOOL} hold ${STATESETUP}/ns.hold"
|
||||||
__target_pid=$(${NSTOOL} ${STATESETUP}/ns.hold pid)
|
__target_pid=$(${NSTOOL} pid ${STATESETUP}/ns.hold)
|
||||||
|
|
||||||
context_setup_nsenter ns -U -n -p --preserve-credentials -t ${__target_pid}
|
context_setup_nsenter ns -U -n -p --preserve-credentials -t ${__target_pid}
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ setup_passt_in_ns() {
|
||||||
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
||||||
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
||||||
|
|
||||||
context_run_bg pasta "./pasta ${__opts} -t 10001,10002,10011,10012 -T 10003,10013 -u 10001,10002,10011,10012 -U 10003,10013 -P ${STATESETUP}/pasta.pid --config-net ${NSTOOL} ${STATESETUP}/ns.hold hold"
|
context_run_bg pasta "./pasta ${__opts} -t 10001,10002,10011,10012 -T 10003,10013 -u 10001,10002,10011,10012 -U 10003,10013 -P ${STATESETUP}/pasta.pid --config-net ${NSTOOL} hold ${STATESETUP}/ns.hold"
|
||||||
wait_for [ -f "${STATESETUP}/pasta.pid" ]
|
wait_for [ -f "${STATESETUP}/pasta.pid" ]
|
||||||
__ns_pid=$(${NSTOOL} ${STATESETUP}/ns.hold pid)
|
__ns_pid=$(${NSTOOL} pid ${STATESETUP}/ns.hold)
|
||||||
|
|
||||||
context_setup_nsenter qemu "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
context_setup_nsenter qemu "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
||||||
context_setup_nsenter ns "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
context_setup_nsenter ns "-t ${__ns_pid} -U -n -p --preserve-credentials"
|
||||||
|
@ -189,16 +189,16 @@ setup_two_guests() {
|
||||||
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_1.pcap"
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_1.pcap"
|
||||||
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
||||||
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
||||||
context_run_bg pasta_1 "./pasta ${__opts} --trace -l /tmp/pasta1.log -P ${STATESETUP}/pasta_1.pid -t 10001,10002 -T 10003,10004 -u 10001,10002 -U 10003,10004 --config-net ${NSTOOL} ${STATESETUP}/ns1.hold hold"
|
context_run_bg pasta_1 "./pasta ${__opts} --trace -l /tmp/pasta1.log -P ${STATESETUP}/pasta_1.pid -t 10001,10002 -T 10003,10004 -u 10001,10002 -U 10003,10004 --config-net ${NSTOOL} hold ${STATESETUP}/ns1.hold"
|
||||||
__ns1_pid=$(${NSTOOL} ${STATESETUP}/ns1.hold pid)
|
__ns1_pid=$(${NSTOOL} pid ${STATESETUP}/ns1.hold)
|
||||||
context_setup_nsenter passt_1 -U -n -p --preserve-credentials -t ${__ns1_pid}
|
context_setup_nsenter passt_1 -U -n -p --preserve-credentials -t ${__ns1_pid}
|
||||||
|
|
||||||
__opts=
|
__opts=
|
||||||
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_2.pcap"
|
[ ${PCAP} -eq 1 ] && __opts="${__opts} -p ${LOGDIR}/pasta_2.pcap"
|
||||||
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
[ ${DEBUG} -eq 1 ] && __opts="${__opts} -d"
|
||||||
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
[ ${TRACE} -eq 1 ] && __opts="${__opts} --trace"
|
||||||
context_run_bg pasta_2 "./pasta ${__opts} --trace -l /tmp/pasta2.log -P ${STATESETUP}/pasta_2.pid -t 10004,10005 -T 10003,10001 -u 10004,10005 -U 10003,10001 --config-net ${NSTOOL} ${STATESETUP}/ns2.hold hold"
|
context_run_bg pasta_2 "./pasta ${__opts} --trace -l /tmp/pasta2.log -P ${STATESETUP}/pasta_2.pid -t 10004,10005 -T 10003,10001 -u 10004,10005 -U 10003,10001 --config-net ${NSTOOL} hold ${STATESETUP}/ns2.hold"
|
||||||
__ns2_pid=$(${NSTOOL} ${STATESETUP}/ns2.hold pid)
|
__ns2_pid=$(${NSTOOL} pid ${STATESETUP}/ns2.hold)
|
||||||
context_setup_nsenter passt_2 -U -n -p --preserve-credentials -t ${__ns2_pid}
|
context_setup_nsenter passt_2 -U -n -p --preserve-credentials -t ${__ns2_pid}
|
||||||
|
|
||||||
context_setup_nsenter qemu_1 -U -n -p --preserve-credentials -t ${__ns1_pid}
|
context_setup_nsenter qemu_1 -U -n -p --preserve-credentials -t ${__ns1_pid}
|
||||||
|
@ -284,7 +284,7 @@ teardown_passt() {
|
||||||
|
|
||||||
# teardown_pasta() - Exit namespace, kill pasta process
|
# teardown_pasta() - Exit namespace, kill pasta process
|
||||||
teardown_pasta() {
|
teardown_pasta() {
|
||||||
${NSTOOL} "${STATESETUP}/ns.hold" stop
|
${NSTOOL} stop "${STATESETUP}/ns.hold"
|
||||||
context_wait unshare
|
context_wait unshare
|
||||||
|
|
||||||
teardown_context_watch ${PANE_HOST} host
|
teardown_context_watch ${PANE_HOST} host
|
||||||
|
@ -297,7 +297,7 @@ teardown_passt_in_ns() {
|
||||||
context_run ns kill $(cat "${STATESETUP}/qemu.pid")
|
context_run ns kill $(cat "${STATESETUP}/qemu.pid")
|
||||||
context_wait qemu
|
context_wait qemu
|
||||||
|
|
||||||
${NSTOOL} "${STATESETUP}/ns.hold" stop
|
${NSTOOL} stop "${STATESETUP}/ns.hold"
|
||||||
context_wait pasta
|
context_wait pasta
|
||||||
|
|
||||||
rm "${STATESETUP}/passt.pid" "${STATESETUP}/pasta.pid"
|
rm "${STATESETUP}/passt.pid" "${STATESETUP}/pasta.pid"
|
||||||
|
@ -310,8 +310,8 @@ teardown_passt_in_ns() {
|
||||||
|
|
||||||
# teardown_two_guests() - Exit namespaces, kill qemu processes, passt and pasta
|
# teardown_two_guests() - Exit namespaces, kill qemu processes, passt and pasta
|
||||||
teardown_two_guests() {
|
teardown_two_guests() {
|
||||||
__ns1_pid=$(${NSTOOL} "${STATESETUP}/ns1.hold" pid)
|
__ns1_pid=$(${NSTOOL} pid "${STATESETUP}/ns1.hold")
|
||||||
__ns2_pid=$(${NSTOOL} "${STATESETUP}/ns2.hold" pid)
|
__ns2_pid=$(${NSTOOL} pid "${STATESETUP}/ns2.hold")
|
||||||
nsenter -U -p --preserve-credentials -t ${__ns1_pid} kill $(cat "${STATESETUP}/qemu_1.pid")
|
nsenter -U -p --preserve-credentials -t ${__ns1_pid} kill $(cat "${STATESETUP}/qemu_1.pid")
|
||||||
nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/qemu_2.pid")
|
nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/qemu_2.pid")
|
||||||
context_wait qemu_1
|
context_wait qemu_1
|
||||||
|
@ -321,8 +321,8 @@ teardown_two_guests() {
|
||||||
nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/passt_2.pid")
|
nsenter -U -p --preserve-credentials -t ${__ns2_pid} kill $(cat "${STATESETUP}/passt_2.pid")
|
||||||
context_wait passt_1
|
context_wait passt_1
|
||||||
context_wait passt_2
|
context_wait passt_2
|
||||||
${NSTOOL} "${STATESETUP}/ns1.hold" stop
|
${NSTOOL} stop "${STATESETUP}/ns1.hold"
|
||||||
${NSTOOL} "${STATESETUP}/ns2.hold" stop
|
${NSTOOL} stop "${STATESETUP}/ns2.hold"
|
||||||
context_wait pasta_1
|
context_wait pasta_1
|
||||||
context_wait pasta_2
|
context_wait pasta_2
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
*
|
*
|
||||||
* Can run in 3 modes:
|
* Can run in 3 modes:
|
||||||
*
|
*
|
||||||
* nstool <path> hold
|
* nstool hold <path>
|
||||||
* Designed to be run inside a namespace, opens a Unix domain
|
* Designed to be run inside a namespace, opens a Unix domain
|
||||||
* control socket at <path> and waits until instructed to stop
|
* control socket at <path> and waits until instructed to stop
|
||||||
* with "nstool <path> stop"
|
* with "nstool stop <path>"
|
||||||
* nstool <path> pid
|
* nstool pid <path>
|
||||||
* Prints the PID of the nstool hold process with control
|
* Prints the PID of the nstool hold process with control socket
|
||||||
* socket <path>. This is given in the PID namespace where
|
* <path>. This is given in the PID namespace where nstool pid
|
||||||
* nstool pid is executed, not the one where nstool hold is
|
* is executed, not the one where nstool hold is running
|
||||||
* running
|
* nstool stop <path>
|
||||||
* nstool <path> stop
|
* Instruct the nstool hold with control socket at <path> to
|
||||||
* Instruct the nstool hold with control socket at <path> to exit.
|
* exit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
die("Usage: nstool <socket path> hold|pid\n");
|
die("Usage: nstool hold|pid|stop <socket path>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hold(int fd, const struct sockaddr_un *addr)
|
static void hold(int fd, const struct sockaddr_un *addr)
|
||||||
|
@ -119,18 +119,18 @@ int main(int argc, char *argv[])
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
sockname = argv[1];
|
sockname = argv[2];
|
||||||
strncpy(sockaddr.sun_path, sockname, UNIX_PATH_MAX);
|
strncpy(sockaddr.sun_path, sockname, UNIX_PATH_MAX);
|
||||||
|
|
||||||
fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX);
|
fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
die("socket(): %s\n", strerror(errno));
|
die("socket(): %s\n", strerror(errno));
|
||||||
|
|
||||||
if (strcmp(argv[2], "hold") == 0)
|
if (strcmp(argv[1], "hold") == 0)
|
||||||
hold(fd, &sockaddr);
|
hold(fd, &sockaddr);
|
||||||
else if (strcmp(argv[2], "pid") == 0)
|
else if (strcmp(argv[1], "pid") == 0)
|
||||||
pid(fd, &sockaddr);
|
pid(fd, &sockaddr);
|
||||||
else if (strcmp(argv[2], "stop") == 0)
|
else if (strcmp(argv[1], "stop") == 0)
|
||||||
stop(fd, &sockaddr);
|
stop(fd, &sockaddr);
|
||||||
else
|
else
|
||||||
usage();
|
usage();
|
||||||
|
|
Loading…
Reference in a new issue