[6/6] unux: Make --external support --ext-unix-sk

Submitted by Pavel Emelianov on Sept. 20, 2016, 1:27 p.m.

Details

Message ID 57E1392E.4010803@virtuozzo.com
State Rejected
Series "Unify external resources in CLI"
Headers show

Commit Message

Pavel Emelianov Sept. 20, 2016, 1:27 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/crtools.c            |  5 +----
 criu/include/cr_options.h |  1 -
 criu/sk-unix.c            | 37 ++++++++++++-------------------------
 images/rpc.proto          |  2 +-
 4 files changed, 14 insertions(+), 31 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/crtools.c b/criu/crtools.c
index 53fce47..a0eecf3 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -58,7 +58,6 @@  void init_opts(void)
 
 	/* Default options */
 	opts.final_state = TASK_DEAD;
-	INIT_LIST_HEAD(&opts.ext_unixsk_ids);
 	INIT_LIST_HEAD(&opts.ext_mounts);
 	INIT_LIST_HEAD(&opts.inherit_fds);
 	INIT_LIST_HEAD(&opts.external);
@@ -832,14 +831,12 @@  usage:
 "                            tty[rdev:dev]\n"
 "                            file[mnt_id:inode]\n"
 "                            dev[maj:min]:VAL\n"
+"                            unix[ino]\n"
 "                        Formats of RES on restore:\n"
 "                            dev[VAL]:DEVPATH\n"
 "                            veth[IFNAME]:OUTNAME{@BRIDGE}\n"
 "\n"
 "* Special resources support:\n"
-"  -x|--" USK_EXT_PARAM " [inode,...]\n"
-"                        allow external unix connections (optional arguments\n"
-"                        are socketpair inode(s) that allow one-sided dump)\n"
 "     --" SK_EST_PARAM "  checkpoint/restore established TCP connections\n"
 "     --" SK_INFLIGHT_PARAM "   skip (ignore) in-flight TCP connections\n"
 "  -r|--root PATH        change the root filesystem (when run in mount namespace)\n"
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index 95dd878..8a9427b 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -60,7 +60,6 @@  struct cr_options {
 	};
 	bool			restore_sibling;
 	bool			ext_unix_sk;
-	struct list_head        ext_unixsk_ids;
 	bool			shell_job;
 	bool			handle_file_locks;
 	bool			tcp_established_ok;
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 99f0b08..e0ac2c5 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -27,6 +27,7 @@ 
 #include "plugin.h"
 #include "namespaces.h"
 #include "pstree.h"
+#include "external.h"
 #include "crtools.h"
 
 #include "protobuf.h"
@@ -95,11 +96,6 @@  struct unix_sk_listen_icon {
 	struct unix_sk_listen_icon	*next;
 };
 
-struct  unix_sk_exception {
-	struct list_head unix_sk_list;
-	ino_t unix_sk_ino;
-};
-
 #define SK_HASH_SIZE		32
 
 static struct unix_sk_listen_icon *unix_listen_icons[SK_HASH_SIZE];
@@ -166,18 +162,15 @@  static int can_dump_unix_sk(const struct unix_sk_desc *sk)
 
 static bool unix_sk_exception_lookup_id(ino_t ino)
 {
-	bool ret = false;
-	struct unix_sk_exception *sk;
-
-	list_for_each_entry(sk, &opts.ext_unixsk_ids, unix_sk_list) {
-		if (sk->unix_sk_ino == ino) {
-			pr_debug("Found ino %u in exception unix sk list\n", (unsigned int)ino);
-			ret = true;
-			break;
-		}
+	char id[20];
+
+	snprintf(id, sizeof(id), "unix[%lu]", ino);
+	if (external_lookup_id(id)) {
+		pr_debug("Found ino %u in exception unix sk list\n", (unsigned int)ino);
+		return true;
 	}
 
-	return ret;
+	return false;
 }
 
 static int write_unix_entry(struct unix_sk_desc *sk)
@@ -1448,17 +1441,11 @@  static int resolve_unix_peers(void *unused)
 
 int unix_sk_id_add(ino_t ino)
 {
-	struct unix_sk_exception *unix_sk;
+	char *e_str;
 
-	/* TODO: validate inode here? */
-
-	unix_sk = xmalloc(sizeof *unix_sk);
-	if (unix_sk == NULL)
-		return -1;
-	unix_sk->unix_sk_ino = ino;
-	list_add_tail(&unix_sk->unix_sk_list, &opts.ext_unixsk_ids);
-
-	return 0;
+	e_str = xmalloc(20);
+	snprintf(e_str, 20, "unix[%lu]", ino);
+	return add_external(e_str);
 }
 
 int unix_sk_ids_parse(char *optarg)
diff --git a/images/rpc.proto b/images/rpc.proto
index 0ae130c..7f72014 100644
--- a/images/rpc.proto
+++ b/images/rpc.proto
@@ -91,7 +91,7 @@  message criu_opts {
 	repeated string			skip_mnt	= 31;
 	repeated string			enable_fs	= 32;
 
-	repeated unix_sk                unix_sk_ino     = 33;
+	repeated unix_sk                unix_sk_ino     = 33; /* DEPRECATED, use external instead */
 
 	optional criu_cg_mode		manage_cgroups_mode = 34;
 	optional uint32			ghost_limit	= 35 [default = 0x100000];

Comments

Cyrill Gorcunov Sept. 20, 2016, 2:06 p.m.
On Tue, Sep 20, 2016 at 04:27:10PM +0300, Pavel Emelyanov wrote:
...
>  
>  int unix_sk_id_add(ino_t ino)
>  {
> -	struct unix_sk_exception *unix_sk;
> +	char *e_str;
>  
> -	/* TODO: validate inode here? */
> -
> -	unix_sk = xmalloc(sizeof *unix_sk);
> -	if (unix_sk == NULL)
> -		return -1;
> -	unix_sk->unix_sk_ino = ino;
> -	list_add_tail(&unix_sk->unix_sk_list, &opts.ext_unixsk_ids);
> -
> -	return 0;
> +	e_str = xmalloc(20);

	if (!e_str)
		return -ENOMEM;

> +	snprintf(e_str, 20, "unix[%lu]", ino);
> +	return add_external(e_str);
>  }