sync: rename startup synchronization macros

parent 26891336
...@@ -1069,7 +1069,7 @@ static int do_start(void *data) ...@@ -1069,7 +1069,7 @@ static int do_start(void *data)
/* Don't leak the pinfd to the container. */ /* Don't leak the pinfd to the container. */
close_prot_errno_disarm(handler->pinfd); close_prot_errno_disarm(handler->pinfd);
ret = lxc_sync_wait_parent(handler, LXC_SYNC_STARTUP); ret = lxc_sync_wait_parent(handler, START_SYNC_STARTUP);
if (ret < 0) if (ret < 0)
goto out_warn_father; goto out_warn_father;
...@@ -1088,7 +1088,7 @@ static int do_start(void *data) ...@@ -1088,7 +1088,7 @@ static int do_start(void *data)
/* Tell the parent task it can begin to configure the container and wait /* Tell the parent task it can begin to configure the container and wait
* for it to finish. * for it to finish.
*/ */
ret = lxc_sync_barrier_parent(handler, LXC_SYNC_CONFIGURE); ret = lxc_sync_barrier_parent(handler, START_SYNC_CONFIGURE);
if (ret < 0) if (ret < 0)
goto out_error; goto out_error;
...@@ -1168,7 +1168,7 @@ static int do_start(void *data) ...@@ -1168,7 +1168,7 @@ static int do_start(void *data)
} }
/* Ask father to setup cgroups and wait for him to finish. */ /* Ask father to setup cgroups and wait for him to finish. */
ret = lxc_sync_barrier_parent(handler, LXC_SYNC_CGROUP); ret = lxc_sync_barrier_parent(handler, START_SYNC_CGROUP);
if (ret < 0) if (ret < 0)
goto out_error; goto out_error;
...@@ -1353,7 +1353,7 @@ static int do_start(void *data) ...@@ -1353,7 +1353,7 @@ static int do_start(void *data)
} }
} }
ret = lxc_sync_barrier_parent(handler, LXC_SYNC_CGROUP_LIMITS); ret = lxc_sync_barrier_parent(handler, START_SYNC_CGROUP_LIMITS);
if (ret < 0) if (ret < 0)
goto out_warn_father; goto out_warn_father;
...@@ -1447,7 +1447,7 @@ out_warn_father: ...@@ -1447,7 +1447,7 @@ out_warn_father:
* We want the parent to know something went wrong, so we return a * We want the parent to know something went wrong, so we return a
* special error code. * special error code.
*/ */
lxc_sync_wake_parent(handler, LXC_SYNC_ERROR); lxc_sync_wake_parent(handler, SYNC_ERROR);
out_error: out_error:
return -1; return -1;
...@@ -1790,11 +1790,11 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1790,11 +1790,11 @@ static int lxc_spawn(struct lxc_handler *handler)
} }
} }
ret = lxc_sync_wake_child(handler, LXC_SYNC_STARTUP); ret = lxc_sync_wake_child(handler, START_SYNC_STARTUP);
if (ret < 0) if (ret < 0)
goto out_delete_net; goto out_delete_net;
ret = lxc_sync_wait_child(handler, LXC_SYNC_CONFIGURE); ret = lxc_sync_wait_child(handler, START_SYNC_CONFIGURE);
if (ret < 0) if (ret < 0)
goto out_delete_net; goto out_delete_net;
...@@ -1862,9 +1862,9 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1862,9 +1862,9 @@ static int lxc_spawn(struct lxc_handler *handler)
} }
/* Tell the child to continue its initialization. We'll get /* Tell the child to continue its initialization. We'll get
* LXC_SYNC_CGROUP when it is ready for us to setup cgroups. * START_SYNC_CGROUP when it is ready for us to setup cgroups.
*/ */
ret = lxc_sync_barrier_child(handler, LXC_SYNC_POST_CONFIGURE); ret = lxc_sync_barrier_child(handler, START_SYNC_POST_CONFIGURE);
if (ret < 0) if (ret < 0)
goto out_delete_net; goto out_delete_net;
...@@ -1876,7 +1876,7 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1876,7 +1876,7 @@ static int lxc_spawn(struct lxc_handler *handler)
} }
} }
ret = lxc_sync_barrier_child(handler, LXC_SYNC_CGROUP_UNSHARE); ret = lxc_sync_barrier_child(handler, START_SYNC_CGROUP_UNSHARE);
if (ret < 0) if (ret < 0)
goto out_delete_net; goto out_delete_net;
...@@ -1937,11 +1937,11 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1937,11 +1937,11 @@ static int lxc_spawn(struct lxc_handler *handler)
/* Tell the child to complete its initialization and wait for it to exec /* Tell the child to complete its initialization and wait for it to exec
* or return an error. (The child will never return * or return an error. (The child will never return
* LXC_SYNC_READY_START+1. It will either close the sync pipe, causing * START_SYNC_READY_START+1. It will either close the sync pipe, causing
* lxc_sync_barrier_child to return success, or return a different * lxc_sync_barrier_child to return success, or return a different
* value, causing us to error out). * value, causing us to error out).
*/ */
ret = lxc_sync_barrier_child(handler, LXC_SYNC_READY_START); ret = lxc_sync_barrier_child(handler, START_SYNC_READY_START);
if (ret < 0) if (ret < 0)
goto out_delete_net; goto out_delete_net;
......
...@@ -32,7 +32,7 @@ int sync_wait(int fd, int sequence) ...@@ -32,7 +32,7 @@ int sync_wait(int fd, int sequence)
if ((size_t)ret != sizeof(sync)) if ((size_t)ret != sizeof(sync))
return log_error(-1, "Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync)); return log_error(-1, "Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync));
if (sync == LXC_SYNC_ERROR) if (sync == SYNC_ERROR)
return log_error(-1, "An error occurred in another process (expected sequence number %d)", sequence); return log_error(-1, "An error occurred in another process (expected sequence number %d)", sequence);
if (sync != sequence) if (sync != sequence)
...@@ -59,41 +59,69 @@ static int __sync_barrier(int fd, int sequence) ...@@ -59,41 +59,69 @@ static int __sync_barrier(int fd, int sequence)
return sync_wait(fd, sequence + 1); return sync_wait(fd, sequence + 1);
} }
static inline const char *start_sync_to_string(int state)
{
switch (state) {
case START_SYNC_STARTUP:
return "startup";
case START_SYNC_CONFIGURE:
return "configure";
case START_SYNC_POST_CONFIGURE:
return "post-configure";
case START_SYNC_CGROUP:
return "cgroup";
case START_SYNC_CGROUP_UNSHARE:
return "cgroup-unshare";
case START_SYNC_CGROUP_LIMITS:
return "cgroup-limits";
case START_SYNC_READY_START:
return "ready-start";
case START_SYNC_RESTART:
return "restart";
case START_SYNC_POST_RESTART:
return "post-restart";
case SYNC_ERROR:
return "error";
default:
return "invalid sync state";
}
}
int lxc_sync_barrier_parent(struct lxc_handler *handler, int sequence) int lxc_sync_barrier_parent(struct lxc_handler *handler, int sequence)
{ {
TRACE("Child waking parent with sequence %s and waiting for sequence %s", TRACE("Child waking parent with sequence %s and waiting for sequence %s",
sync_to_string(sequence), sync_to_string(sequence + 1)); start_sync_to_string(sequence), start_sync_to_string(sequence + 1));
return __sync_barrier(handler->sync_sock[0], sequence); return __sync_barrier(handler->sync_sock[0], sequence);
} }
int lxc_sync_barrier_child(struct lxc_handler *handler, int sequence) int lxc_sync_barrier_child(struct lxc_handler *handler, int sequence)
{ {
TRACE("Parent waking child with sequence %s and waiting with sequence %s", TRACE("Parent waking child with sequence %s and waiting with sequence %s",
sync_to_string(sequence), sync_to_string(sequence + 1)); start_sync_to_string(sequence), start_sync_to_string(sequence + 1));
return __sync_barrier(handler->sync_sock[1], sequence); return __sync_barrier(handler->sync_sock[1], sequence);
} }
int lxc_sync_wake_parent(struct lxc_handler *handler, int sequence) int lxc_sync_wake_parent(struct lxc_handler *handler, int sequence)
{ {
TRACE("Child waking parent with sequence %s", sync_to_string(sequence)); TRACE("Child waking parent with sequence %s", start_sync_to_string(sequence));
return sync_wake(handler->sync_sock[0], sequence); return sync_wake(handler->sync_sock[0], sequence);
} }
int lxc_sync_wait_parent(struct lxc_handler *handler, int sequence) int lxc_sync_wait_parent(struct lxc_handler *handler, int sequence)
{ {
TRACE("Parent waiting for child with sequence %s", sync_to_string(sequence)); TRACE("Parent waiting for child with sequence %s", start_sync_to_string(sequence));
return sync_wait(handler->sync_sock[0], sequence); return sync_wait(handler->sync_sock[0], sequence);
} }
int lxc_sync_wait_child(struct lxc_handler *handler, int sequence) int lxc_sync_wait_child(struct lxc_handler *handler, int sequence)
{ {
TRACE("Child waiting for parent with sequence %s", sync_to_string(sequence)); TRACE("Child waiting for parent with sequence %s", start_sync_to_string(sequence));
return sync_wait(handler->sync_sock[1], sequence); return sync_wait(handler->sync_sock[1], sequence);
} }
int lxc_sync_wake_child(struct lxc_handler *handler, int sequence) int lxc_sync_wake_child(struct lxc_handler *handler, int sequence)
{ {
TRACE("Child waking parent with sequence %s", sync_to_string(sequence)); TRACE("Child waking parent with sequence %s", start_sync_to_string(sequence));
return sync_wake(handler->sync_sock[1], sequence); return sync_wake(handler->sync_sock[1], sequence);
} }
......
...@@ -8,46 +8,18 @@ ...@@ -8,46 +8,18 @@
struct lxc_handler; struct lxc_handler;
enum { enum {
LXC_SYNC_STARTUP = 0, START_SYNC_STARTUP = 0,
LXC_SYNC_CONFIGURE = 1, START_SYNC_CONFIGURE = 1,
LXC_SYNC_POST_CONFIGURE = 2, START_SYNC_POST_CONFIGURE = 2,
LXC_SYNC_CGROUP = 3, START_SYNC_CGROUP = 3,
LXC_SYNC_CGROUP_UNSHARE = 4, START_SYNC_CGROUP_UNSHARE = 4,
LXC_SYNC_CGROUP_LIMITS = 5, START_SYNC_CGROUP_LIMITS = 5,
LXC_SYNC_READY_START = 6, START_SYNC_READY_START = 6,
LXC_SYNC_RESTART = 7, START_SYNC_RESTART = 7,
LXC_SYNC_POST_RESTART = 8, START_SYNC_POST_RESTART = 8,
LXC_SYNC_ERROR = -1 /* Used to report errors from another process */ SYNC_ERROR = -1 /* Used to report errors from another process */
}; };
static inline const char *sync_to_string(int state)
{
switch (state) {
case LXC_SYNC_STARTUP:
return "startup";
case LXC_SYNC_CONFIGURE:
return "configure";
case LXC_SYNC_POST_CONFIGURE:
return "post-configure";
case LXC_SYNC_CGROUP:
return "cgroup";
case LXC_SYNC_CGROUP_UNSHARE:
return "cgroup-unshare";
case LXC_SYNC_CGROUP_LIMITS:
return "cgroup-limits";
case LXC_SYNC_READY_START:
return "ready-start";
case LXC_SYNC_RESTART:
return "restart";
case LXC_SYNC_POST_RESTART:
return "post-restart";
case LXC_SYNC_ERROR:
return "error";
default:
return "invalid sync state";
}
}
__hidden extern int lxc_sync_init(struct lxc_handler *handler); __hidden extern int lxc_sync_init(struct lxc_handler *handler);
__hidden extern void lxc_sync_fini(struct lxc_handler *); __hidden extern void lxc_sync_fini(struct lxc_handler *);
__hidden extern void lxc_sync_fini_parent(struct lxc_handler *); __hidden extern void lxc_sync_fini_parent(struct lxc_handler *);
......
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