mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
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@parallels.com> Acked-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
parent
1e694235b4
commit
0213d3ec64
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
26
crtools.c
26
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:
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
12
test/zdtm.sh
12
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user