[CRIU] [PATCH 05/24] parasite: Prepare structures for daemon mode

Andrey Vagin avagin at openvz.org
Wed May 22 16:08:06 EDT 2013


From: Cyrill Gorcunov <gorcunov at openvz.org>

Parasite daemon mode might be considered as a series
of network messages sent from main crtools module to
parasite daemon which spins on a socket waiting for
command to handle.

Simple command handling session might look as

        crtools                     daemon
        |                           |                           |
        | ---> command message ---> |                           |
        |                           | ---> receive command ---> |
        |                           |           ....            |
        |                           |       handle command      |
        |                           |           ....            |
        |                           | <--- send ack       <---  |
        | <--- receive ack     <--- |                           |
        |                           |                           |
        v                           v                           v
      time

where, in case of multithread application [handle command] stage
includes waking up of children threads via futexes, wait until
handling complete and only then send ack back to ctrools module.

This patch brings in description of command message as

struct ctl_msg {
    unsigned int    id;     /* command recipient */
    unsigned int    cmd;    /* command itself */
    unsigned int    ack;    /* ack on command */
    int             err;    /* error code on reply */
};

For example, in case of dumpee being with pid 2 and acquiring
to handle PARASITE_CMD_DUMP_MISC, the command/ack series will look
as

    cmd-msg
    -------
    .id     = 2,
    .cmd    = PARASITE_CMD_DUMP_MISC,
    .ack    = 0,
    .err    = 0,

    ack-msg
    -------
    .id     = 2,
    .cmd    = PARASITE_CMD_DUMP_MISC,
    .ack    = PARASITE_CMD_DUMP_MISC,
    .err    = 0

in case if error happened in parasite, the @err field set accordingly.

For convenience ctl_msg_cmd()/ctl_msg_ack() macros are provided
for control message generations.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/parasite.h | 23 +++++++++++++++++++++++
 pie/parasite.c     |  9 +++++++++
 2 files changed, 32 insertions(+)

diff --git a/include/parasite.h b/include/parasite.h
index ba9da39..22148e2 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -18,8 +18,18 @@
 #define __head __used __section(.head.text)
 
 enum {
+	PARASITE_CMD_IDLE		= 0,
+	PARASITE_CMD_ACK,
+
 	PARASITE_CMD_INIT,
 	PARASITE_CMD_INIT_THREAD,
+
+	/*
+	 * These two must be greater than INITs.
+	 */
+	PARASITE_CMD_DAEMONIZE,
+	PARASITE_CMD_DAEMONIZED,
+
 	PARASITE_CMD_CFG_LOG,
 	PARASITE_CMD_FINI,
 	PARASITE_CMD_FINI_THREAD,
@@ -39,6 +49,19 @@ enum {
 	PARASITE_CMD_MAX,
 };
 
+struct ctl_msg {
+	unsigned int	id;			/* command recipient */
+	unsigned int	cmd;			/* command itself */
+	unsigned int	ack;			/* ack on command */
+	int		err;			/* error code on reply */
+};
+
+#define ctl_msg_cmd(_id, _cmd)		\
+	(struct ctl_msg){ .id = _id, .cmd = _cmd, }
+
+#define ctl_msg_ack(_id, _cmd, _err)	\
+	(struct ctl_msg){ .id = _id, .cmd = _cmd, .ack = _cmd, .err = _err, }
+
 struct parasite_init_args {
 	int			h_addr_len;
 	struct sockaddr_un	h_addr;
diff --git a/pie/parasite.c b/pie/parasite.c
index 28f126d..6f2328f 100644
--- a/pie/parasite.c
+++ b/pie/parasite.c
@@ -8,6 +8,7 @@
 
 #include "syscall.h"
 #include "parasite.h"
+#include "lock.h"
 #include "log.h"
 
 #include <string.h>
@@ -19,6 +20,11 @@ static int tsock = -1;
 static struct tid_state_s {
 	pid_t		real;
 	pid_t		tid;
+
+	futex_t		cmd;
+	futex_t		ack;
+	int		ret;
+
 	bool		use_sig_blocked;
 	k_rtsigset_t	sig_blocked;
 	void		*next;
@@ -239,6 +245,9 @@ static int init_thread(struct parasite_init_args *args)
 	tid_state[next_tid_state].tid = sys_gettid();
 	tid_state[next_tid_state].real = args->real;
 
+	futex_set(&tid_state[next_tid_state].cmd, PARASITE_CMD_IDLE);
+	futex_set(&tid_state[next_tid_state].ack, PARASITE_CMD_IDLE);
+
 	hash_thread_state(&tid_state[next_tid_state]);
 
 	next_tid_state++;
-- 
1.8.2



More information about the CRIU mailing list