[CRIU] [PATCH v2 2/3] namespaces: parametrized namespace option
introduced
Kinsbursky Stanislav
skinsbursky at openvz.org
Mon Jan 30 10:46:13 EST 2012
From: Stanislav Kinsbursky <skinsbursky at parallels.com>
Now '-n' option must be followed by namespaces tags, separated by commas.
Currently, only "uts" namespace is supported.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at parallels.com>
---
cr-dump.c | 4 ++--
cr-restore.c | 8 +-------
crtools.c | 28 ++++++++++++++++++++++++++--
include/crtools.h | 2 +-
include/namespaces.h | 2 +-
namespaces.c | 6 +++---
test/zdtm.sh | 12 ++++++------
7 files changed, 40 insertions(+), 22 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index dbae3d6..78d4b9b 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1329,8 +1329,8 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts)
if (collect_pstree(pid, &pstree_list))
goto err;
- if (opts->with_namespaces) {
- ret = dump_namespaces(pid);
+ if (opts->namespaces_flags) {
+ ret = dump_namespaces(pid, opts->namespaces_flags);
if (ret < 0)
goto err;
}
diff --git a/cr-restore.c b/cr-restore.c
index 4c94936..220611a 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1375,7 +1375,6 @@ static int restore_root_task(int fd, struct cr_options *opts)
struct pstree_entry e;
int ret, i;
struct sigaction act, old_act;
- unsigned long ns_clone_flags;
ret = read(fd, &e, sizeof(e));
if (ret != sizeof(e)) {
@@ -1406,12 +1405,7 @@ static int restore_root_task(int fd, struct cr_options *opts)
* this later.
*/
- if (opts->with_namespaces)
- ns_clone_flags = CLONE_NEWUTS;
- else
- ns_clone_flags = 0;
-
- ret = fork_with_pid(e.pid, ns_clone_flags);
+ ret = fork_with_pid(e.pid, opts->namespaces_flags);
if (ret < 0)
return -1;
diff --git a/crtools.c b/crtools.c
index cde561b..615c886 100644
--- a/crtools.c
+++ b/crtools.c
@@ -18,6 +18,7 @@
#include "util.h"
#include "log.h"
#include "sockets.h"
+#include "syscall.h"
static struct cr_options opts;
struct page_entry zero_page_entry;
@@ -233,6 +234,28 @@ void close_cr_fdset(struct cr_fdset **cr_fdset)
*cr_fdset = NULL;
}
+static int parse_ns_string(const char *ptr, unsigned int *flags)
+{
+ const char *end = ptr + strlen(ptr);
+
+ do {
+ if (strlen(ptr) < 3)
+ goto bad_ns;
+ if (ptr[3] != ',' && ptr[3] != '\0')
+ goto bad_ns;
+ if (!strncmp(ptr, "uts", 3))
+ opts.namespaces_flags |= CLONE_NEWUTS;
+ else
+ goto bad_ns;
+ ptr += 4;
+ } while (ptr < end);
+ return 0;
+
+bad_ns:
+ pr_err("Unknown namespace '%s'\n", ptr);
+ return -1;
+}
+
int main(int argc, char *argv[])
{
pid_t pid = 0;
@@ -241,7 +264,7 @@ int main(int argc, char *argv[])
int action = -1;
int log_inited = 0;
- static const char short_opts[] = "df:p:t:hcD:o:n";
+ static const char short_opts[] = "df:p:t:hcD:o:n:";
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
@@ -288,7 +311,8 @@ int main(int argc, char *argv[])
log_inited = 1;
break;
case 'n':
- opts.with_namespaces = true;
+ if (parse_ns_string(optarg, &opts.namespaces_flags))
+ return -1;
break;
case 'h':
default:
diff --git a/include/crtools.h b/include/crtools.h
index dd66e67..0a9f7ef 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -53,7 +53,7 @@ struct cr_options {
bool leader_only;
bool show_pages_content;
bool restore_detach;
- bool with_namespaces;
+ unsigned int namespaces_flags;
};
/* file descriptors template */
diff --git a/include/namespaces.h b/include/namespaces.h
index f7bd0fa..9e0c04f 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -1,6 +1,6 @@
#ifndef __CR_NS_H__
#define __CR_NS_H__
-int dump_namespaces(int pid);
+int dump_namespaces(int pid, unsigned int ns_flags);
int prepare_namespace(int pid, unsigned long clone_flags);
int try_show_namespaces(int pid);
int switch_ns(int pid, int type, char *ns);
diff --git a/namespaces.c b/namespaces.c
index 7aa6f6c..ecca8b2 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -26,7 +26,7 @@ out:
return ret;
}
-static int do_dump_namespaces(int ns_pid)
+static int do_dump_namespaces(int ns_pid, unsigned int ns_flags)
{
struct cr_fdset *fdset;
int ret;
@@ -42,7 +42,7 @@ static int do_dump_namespaces(int ns_pid)
}
-int dump_namespaces(int ns_pid)
+int dump_namespaces(int ns_pid, unsigned int ns_flags)
{
int pid, ret, status;
@@ -66,7 +66,7 @@ int dump_namespaces(int ns_pid)
}
if (pid == 0) {
- ret = do_dump_namespaces(ns_pid);
+ ret = do_dump_namespaces(ns_pid, ns_flags);
exit(ret);
}
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 597f4da..7e60fa4 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -31,7 +31,7 @@ $ZP/static/caps00
$ZP/static/cmdlinenv00
$ZP/static/socket_listen"
-NS_TEST_LIST="\
+UTS_TEST_LIST="\
$ZP/static/utsname"
CRTOOLS=`pwd`/`dirname $0`/../crtools
@@ -87,15 +87,15 @@ if [ $# -eq 0 ]; then
for t in $TEST_LIST; do
run_test $t "" || case_error $t
done
- for t in $NS_TEST_LIST; do
- run_test $t "-n" || case_error $t
+ for t in $UTS_TEST_LIST; do
+ run_test $t "-n uts" || case_error $t
done
elif [ "$1" == "-l" ]; then
echo $TEST_LIST | sed -e "s#$ZP/##g" -e 's/ /\n/g'
- echo $NS_TEST_LIST | sed -e "s#$ZP/##g" -e 's/ /\n/g'
+ echo $UTS_TEST_LIST | sed -e "s#$ZP/##g" -e 's/ /\n/g'
else
- if echo "$NS_TEST_LIST" | fgrep -q "$1" ; then
- run_test "$ZP/$1" "-n" || case_error "$ZP/$1"
+ if echo "$UTS_TEST_LIST" | fgrep -q "$1" ; then
+ run_test "$ZP/$1" "-n uts" || case_error "$ZP/$1"
else
run_test "$ZP/$1" || case_error "$ZP/$1"
fi
More information about the CRIU
mailing list