Commit ac845bd1 authored by Pavel Emelyanov's avatar Pavel Emelyanov

cr: Obsolete the --namespaces option

It's no longer required to use this option -- two currently
supported cases (tasks on host and tasks in containers) can
be detected automatically. Keep this option for future.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a46831ae
...@@ -1326,7 +1326,6 @@ static int collect_pstree(pid_t pid, const struct cr_options *opts) ...@@ -1326,7 +1326,6 @@ static int collect_pstree(pid_t pid, const struct cr_options *opts)
* Some tasks could have been reparented to * Some tasks could have been reparented to
* namespaces' reaper. Check this. * namespaces' reaper. Check this.
*/ */
if (opts->namespaces_flags & CLONE_NEWPID)
if (check_subtree(root_item)) if (check_subtree(root_item))
goto try_again; goto try_again;
...@@ -1522,7 +1521,7 @@ static int dump_zombies() ...@@ -1522,7 +1521,7 @@ static int dump_zombies()
{ {
struct pstree_item *item; struct pstree_item *item;
int oldfd, ret = -1; int oldfd, ret = -1;
int pidns = opts.namespaces_flags & CLONE_NEWPID; int pidns = current_ns_mask & CLONE_NEWPID;
if (pidns) { if (pidns) {
oldfd = set_proc_fd(pidns_proc); oldfd = set_proc_fd(pidns_proc);
...@@ -1614,7 +1613,7 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1614,7 +1613,7 @@ static int dump_one_task(struct pstree_item *item)
goto err; goto err;
} }
if (opts.namespaces_flags & CLONE_NEWPID && root_item == item) { if (current_ns_mask & CLONE_NEWPID && root_item == item) {
pidns_proc = parasite_get_proc_fd_seized(parasite_ctl); pidns_proc = parasite_get_proc_fd_seized(parasite_ctl);
if (pidns_proc < 0) { if (pidns_proc < 0) {
pr_err("Can't get proc fd (pid: %d)\n", pid); pr_err("Can't get proc fd (pid: %d)\n", pid);
...@@ -1751,15 +1750,15 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts) ...@@ -1751,15 +1750,15 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
if (cpu_init()) if (cpu_init())
goto err; goto err;
if (network_lock())
goto err;
if (write_img_inventory()) if (write_img_inventory())
goto err; goto err;
if (collect_pstree(pid, opts)) if (collect_pstree(pid, opts))
goto err; goto err;
if (network_lock())
goto err;
if (collect_file_locks(opts)) if (collect_file_locks(opts))
goto err; goto err;
...@@ -1775,7 +1774,7 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts) ...@@ -1775,7 +1774,7 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
* If netns isn't dumped, crtools will fail only * If netns isn't dumped, crtools will fail only
* if an unsupported socket will be really dumped. * if an unsupported socket will be really dumped.
*/ */
if ((opts->namespaces_flags & CLONE_NEWNET) && ret) if ((current_ns_mask & CLONE_NEWNET) && ret)
goto err; goto err;
ret = -1; ret = -1;
...@@ -1798,8 +1797,8 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts) ...@@ -1798,8 +1797,8 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
if (dump_pstree(root_item)) if (dump_pstree(root_item))
goto err; goto err;
if (opts->namespaces_flags) if (current_ns_mask)
if (dump_namespaces(&root_item->pid, opts->namespaces_flags) < 0) if (dump_namespaces(&root_item->pid, current_ns_mask) < 0)
goto err; goto err;
ret = cr_dump_shmem(); ret = cr_dump_shmem();
......
...@@ -1162,21 +1162,21 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts) ...@@ -1162,21 +1162,21 @@ static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
*/ */
if (init->pid.virt == INIT_PID) { if (init->pid.virt == INIT_PID) {
if (!(opts->namespaces_flags & CLONE_NEWPID)) { if (!(current_ns_mask & CLONE_NEWPID)) {
pr_err("This process tree can only be restored " pr_err("This process tree can only be restored "
"in a new pid namespace.\n" "in a new pid namespace.\n"
"crtools should be re-executed with the " "crtools should be re-executed with the "
"\"--namespace pid\" option.\n"); "\"--namespace pid\" option.\n");
return -1; return -1;
} }
} else if (opts->namespaces_flags & CLONE_NEWPID) { } else if (current_ns_mask & CLONE_NEWPID) {
pr_err("Can't restore pid namespace without the process init\n"); pr_err("Can't restore pid namespace without the process init\n");
return -1; return -1;
} }
futex_set(&task_entries->nr_in_progress, stage_participants(CR_STATE_FORKING)); futex_set(&task_entries->nr_in_progress, stage_participants(CR_STATE_FORKING));
ret = fork_with_pid(init, opts->namespaces_flags); ret = fork_with_pid(init, current_ns_mask);
if (ret < 0) if (ret < 0)
return -1; return -1;
...@@ -1211,7 +1211,7 @@ out: ...@@ -1211,7 +1211,7 @@ out:
struct pstree_item *pi; struct pstree_item *pi;
pr_err("Someone can't be restored\n"); pr_err("Someone can't be restored\n");
if (opts->namespaces_flags & CLONE_NEWPID) { if (current_ns_mask & CLONE_NEWPID) {
/* Kill init */ /* Kill init */
if (root_item->pid.real > 0) if (root_item->pid.real > 0)
kill(root_item->pid.real, SIGKILL); kill(root_item->pid.real, SIGKILL);
......
...@@ -32,15 +32,15 @@ static int parse_ns_string(const char *ptr) ...@@ -32,15 +32,15 @@ static int parse_ns_string(const char *ptr)
if (ptr[3] != ',' && ptr[3] != '\0') if (ptr[3] != ',' && ptr[3] != '\0')
goto bad_ns; goto bad_ns;
if (!strncmp(ptr, "uts", 3)) if (!strncmp(ptr, "uts", 3))
opts.namespaces_flags |= CLONE_NEWUTS; opts.rst_namespaces_flags |= CLONE_NEWUTS;
else if (!strncmp(ptr, "ipc", 3)) else if (!strncmp(ptr, "ipc", 3))
opts.namespaces_flags |= CLONE_NEWIPC; opts.rst_namespaces_flags |= CLONE_NEWIPC;
else if (!strncmp(ptr, "mnt", 3)) else if (!strncmp(ptr, "mnt", 3))
opts.namespaces_flags |= CLONE_NEWNS; opts.rst_namespaces_flags |= CLONE_NEWNS;
else if (!strncmp(ptr, "pid", 3)) else if (!strncmp(ptr, "pid", 3))
opts.namespaces_flags |= CLONE_NEWPID; opts.rst_namespaces_flags |= CLONE_NEWPID;
else if (!strncmp(ptr, "net", 3)) else if (!strncmp(ptr, "net", 3))
opts.namespaces_flags |= CLONE_NEWNET; opts.rst_namespaces_flags |= CLONE_NEWNET;
else else
goto bad_ns; goto bad_ns;
ptr += 4; ptr += 4;
......
...@@ -103,7 +103,7 @@ struct cr_options { ...@@ -103,7 +103,7 @@ struct cr_options {
bool tcp_established_ok; bool tcp_established_ok;
bool evasive_devices; bool evasive_devices;
bool link_remap_ok; bool link_remap_ok;
unsigned int namespaces_flags; unsigned int rst_namespaces_flags;
bool log_file_per_pid; bool log_file_per_pid;
char *output; char *output;
char *root; char *root;
......
...@@ -229,7 +229,7 @@ int dump_namespaces(struct pid *ns_pid, unsigned int ns_flags) ...@@ -229,7 +229,7 @@ int dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
pr_info("Dumping %d(%d)'s namespaces\n", ns_pid->virt, ns_pid->real); pr_info("Dumping %d(%d)'s namespaces\n", ns_pid->virt, ns_pid->real);
if ((opts.namespaces_flags & CLONE_NEWPID) && ns_pid->virt != 1) { if ((ns_flags & CLONE_NEWPID) && ns_pid->virt != 1) {
pr_err("Can't dump a pid namespace without the process init\n"); pr_err("Can't dump a pid namespace without the process init\n");
return -1; return -1;
} }
......
...@@ -382,7 +382,7 @@ int network_lock(void) ...@@ -382,7 +382,7 @@ int network_lock(void)
pr_info("Lock network\n"); pr_info("Lock network\n");
/* Each connection will be locked on dump */ /* Each connection will be locked on dump */
if (!(opts.namespaces_flags & CLONE_NEWNET)) if (!(current_ns_mask & CLONE_NEWNET))
return 0; return 0;
return run_scripts("network-lock"); return run_scripts("network-lock");
...@@ -392,7 +392,7 @@ void network_unlock(void) ...@@ -392,7 +392,7 @@ void network_unlock(void)
{ {
pr_info("Unlock network\n"); pr_info("Unlock network\n");
if (!(opts.namespaces_flags & CLONE_NEWNET)) { if (!(current_ns_mask & CLONE_NEWNET)) {
cpt_unlock_tcp_connections(); cpt_unlock_tcp_connections();
rst_unlock_tcp_connections(); rst_unlock_tcp_connections();
......
...@@ -298,7 +298,7 @@ static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads) ...@@ -298,7 +298,7 @@ static int parasite_init(struct parasite_ctl *ctl, pid_t pid, int nr_threads)
if (sock == -1) { if (sock == -1) {
int rst = -1; int rst = -1;
if (opts.namespaces_flags & CLONE_NEWNET) { if (current_ns_mask & CLONE_NEWNET) {
pr_info("Switching to %d's net for tsock creation\n", pid); pr_info("Switching to %d's net for tsock creation\n", pid);
if (switch_ns(pid, &net_ns_desc, &rst)) if (switch_ns(pid, &net_ns_desc, &rst))
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "sk-inet.h" #include "sk-inet.h"
#include "netfilter.h" #include "netfilter.h"
#include "image.h" #include "image.h"
#include "namespaces.h"
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/tcp-stream.pb-c.h" #include "protobuf/tcp-stream.pb-c.h"
...@@ -103,7 +104,7 @@ static int tcp_repair_establised(int fd, struct inet_sk_desc *sk) ...@@ -103,7 +104,7 @@ static int tcp_repair_establised(int fd, struct inet_sk_desc *sk)
goto err1; goto err1;
} }
if (!(opts.namespaces_flags & CLONE_NEWNET)) { if (!(current_ns_mask & CLONE_NEWNET)) {
ret = nf_lock_connection(sk); ret = nf_lock_connection(sk);
if (ret < 0) if (ret < 0)
goto err2; goto err2;
...@@ -122,7 +123,7 @@ static int tcp_repair_establised(int fd, struct inet_sk_desc *sk) ...@@ -122,7 +123,7 @@ static int tcp_repair_establised(int fd, struct inet_sk_desc *sk)
return 0; return 0;
err3: err3:
if (!(opts.namespaces_flags & CLONE_NEWNET)) if (!(current_ns_mask & CLONE_NEWNET))
nf_unlock_connection(sk); nf_unlock_connection(sk);
err2: err2:
close(sk->rfd); close(sk->rfd);
......
...@@ -425,7 +425,7 @@ int collect_sockets(int pid) ...@@ -425,7 +425,7 @@ int collect_sockets(int pid)
} r; } r;
} req; } req;
if (opts.namespaces_flags & CLONE_NEWNET) { if (current_ns_mask & CLONE_NEWNET) {
pr_info("Switching to %d's net for collecting sockets\n", pid); pr_info("Switching to %d's net for collecting sockets\n", pid);
if (switch_ns(pid, &net_ns_desc, &rst)) if (switch_ns(pid, &net_ns_desc, &rst))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment