]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
sync: rename startup synchronization macros
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 12:31:57 +0000 (13:31 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 12:36:25 +0000 (13:36 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/start.c
src/lxc/sync.c
src/lxc/sync.h

index 9370465c9fc7f201f7c0409c32463cc52b09dcdd..0397ab66ba8b0c74828f67f5aca25db597ba1e29 100644 (file)
@@ -1069,7 +1069,7 @@ static int do_start(void *data)
        /* Don't leak the pinfd to the container. */
        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)
                goto out_warn_father;
 
@@ -1088,7 +1088,7 @@ static int do_start(void *data)
        /* Tell the parent task it can begin to configure the container and wait
         * 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)
                goto out_error;
 
@@ -1168,7 +1168,7 @@ static int do_start(void *data)
        }
 
        /* 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)
                goto out_error;
 
@@ -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)
                goto out_warn_father;
 
@@ -1447,7 +1447,7 @@ out_warn_father:
         * We want the parent to know something went wrong, so we return a
         * special error code.
         */
-       lxc_sync_wake_parent(handler, LXC_SYNC_ERROR);
+       lxc_sync_wake_parent(handler, SYNC_ERROR);
 
 out_error:
        return -1;
@@ -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)
                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)
                goto out_delete_net;
 
@@ -1862,9 +1862,9 @@ static int lxc_spawn(struct lxc_handler *handler)
        }
 
        /* 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)
                goto out_delete_net;
 
@@ -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)
                goto out_delete_net;
 
@@ -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
         * 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
         * 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)
                goto out_delete_net;
 
index c9733967fdb08ea82a7cef099ab6cd876d662115..b9221d8d4df8258d7029ceb3a7c29f2033d8831e 100644 (file)
@@ -32,7 +32,7 @@ int sync_wait(int fd, int sequence)
        if ((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);
 
        if (sync != sequence)
@@ -59,41 +59,69 @@ static int __sync_barrier(int fd, int sequence)
        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)
 {
        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);
 }
 
 int lxc_sync_barrier_child(struct lxc_handler *handler, int sequence)
 {
        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);
 }
 
 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);
 }
 
 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);
 }
 
 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);
 }
 
 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);
 }
 
index 55ebfaca703be1b4f53d3c33268ef2c17f18c3b3..35a942b39b8ec3511edcccb7346665707785c7c3 100644 (file)
@@ -8,46 +8,18 @@
 struct lxc_handler;
 
 enum {
-       LXC_SYNC_STARTUP        = 0,
-       LXC_SYNC_CONFIGURE      = 1,
-       LXC_SYNC_POST_CONFIGURE = 2,
-       LXC_SYNC_CGROUP         = 3,
-       LXC_SYNC_CGROUP_UNSHARE = 4,
-       LXC_SYNC_CGROUP_LIMITS  = 5,
-       LXC_SYNC_READY_START    = 6,
-       LXC_SYNC_RESTART        = 7,
-       LXC_SYNC_POST_RESTART   = 8,
-       LXC_SYNC_ERROR          = -1 /* Used to report errors from another process */
+       START_SYNC_STARTUP              =  0,
+       START_SYNC_CONFIGURE            =  1,
+       START_SYNC_POST_CONFIGURE       =  2,
+       START_SYNC_CGROUP               =  3,
+       START_SYNC_CGROUP_UNSHARE       =  4,
+       START_SYNC_CGROUP_LIMITS        =  5,
+       START_SYNC_READY_START          =  6,
+       START_SYNC_RESTART              =  7,
+       START_SYNC_POST_RESTART         =  8,
+       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 void lxc_sync_fini(struct lxc_handler *);
 __hidden extern void lxc_sync_fini_parent(struct lxc_handler *);