[CRIU] [crtools-bot] namespaces: parametrized namespace option introduced

Cyrill Gorcunov gorcunov at openvz.org
Tue Jan 31 13:32:22 EST 2012


The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit 0213d3ec6413dfb4bf64133df0c195c04d242d46
Author: Stanislav Kinsbursky <skinsbursky at parallels.com>
Date:   Tue Jan 31 22:28:22 2012 +0400

    namespaces: parametrized namespace option introduced
    
    v2: strlen() check removed from parse_ns_string()
    
    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>
    Acked-by: Pavel Emelyanov <xemul at parallels.com>
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c            |    4 ++--
 cr-restore.c         |    8 +-------
 crtools.c            |   26 ++++++++++++++++++++++++--
 include/crtools.h    |    2 +-
 include/namespaces.h |    2 +-
 namespaces.c         |    6 +++---
 test/zdtm.sh         |   12 ++++++------
 7 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 8a76987..4e75bae 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 cf76e97..28532b2 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1371,7 +1371,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)) {
@@ -1402,12 +1401,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 faabf18..e61dc9d 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;
@@ -252,6 +253,26 @@ err:
 	return NULL;
 }
 
+static int parse_ns_string(const char *ptr, unsigned int *flags)
+{
+	const char *end = ptr + strlen(ptr);
+
+	do {
+		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;
@@ -260,7 +281,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);
 
@@ -307,7 +328,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 43e7dc3..583bd7a 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 0e34ebe..63568f1 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -30,7 +30,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
@@ -72,15 +72,15 @@ if [ $# -eq 0 ]; then
 	for t in $TEST_LIST; do
 		run_test $t "" || exit 1
 	done
-	for t in $NS_TEST_LIST; do
-		run_test $t "-n" || exit 1
+	for t in $UTS_TEST_LIST; do
+		run_test $t "-n uts" || exit 1
 	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" && exit 0
+	if echo "$UTS_TEST_LIST" | fgrep -q "$1" ; then
+		run_test "$ZP/$1" "-n uts" && exit 0
 	else
 		run_test "$ZP/$1" && exit 0
 	fi


More information about the CRIU mailing list