]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands: remove mutex from state client list
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 26 Feb 2018 10:43:42 +0000 (11:43 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 23 Aug 2018 20:33:22 +0000 (22:33 +0200)
I was thinking about the locking here yesterday and it dawned on me that we
actually don't need this at all:
- possible contention between traversing list to send states to state clients
  and adding new state clients to the list:
  It is the command handler that adds new state clients to the state client
  list. The command handler and the code that actually sends out the container
  states run in the same process so there's not contention and thus no locking
  needed.
- adding state clients to the list from multiple threads:
  The command handler itself is single-threaded so only one thread's request can
  be served at the same time so no locking is needed.
- sending out the state to state clients via the command handler itself:
  The state client also adds and removes state clients from the state client
  list so there's no locking needed.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c
src/lxc/commands_utils.c
src/lxc/start.c

index 302fc40122fc443e877a7a9f8a319f9cd5397248..5eb2f76f5de118b28ce61a866df77c0e9148c3ed 100644 (file)
@@ -1014,7 +1014,6 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
                return;
        }
 
-       process_lock();
        lxc_list_for_each_safe(cur, &handler->state_clients, next) {
                client = cur->elem;
                if (client->clientfd != fd)
@@ -1030,7 +1029,6 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
                 */
                break;
        }
-       process_unlock();
 }
 
 static int lxc_cmd_handler(int fd, uint32_t events, void *data,
index bcce07b1b7b6079260ee9b384060622ab829fd0a..7f2b66139bac18b94ccd1ef6f061d24629f90a14 100644 (file)
@@ -211,14 +211,11 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
                return -ENOMEM;
        }
 
-       process_lock();
        state = handler->state;
        if (states[state] != 1) {
                lxc_list_add_elem(tmplist, newclient);
                lxc_list_add_tail(&handler->state_clients, tmplist);
-               process_unlock();
        } else {
-               process_unlock();
                free(newclient);
                free(tmplist);
                return state;
index 8313d25ce06716611b16a0b5203806b4c4355178..93a51e811faff928a444fa1b121a4c8f871add93 100644 (file)
@@ -382,7 +382,6 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
        struct state_client *client;
        struct lxc_msg msg = {.type = lxc_msg_state, .value = state};
 
-       process_lock();
        if (state == THAWED)
                handler->state = RUNNING;
        else
@@ -392,7 +391,6 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
 
        if (lxc_list_empty(&handler->state_clients)) {
                TRACE("No state clients registered");
-               process_unlock();
                return 0;
        }
 
@@ -429,7 +427,6 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
                free(cur->elem);
                free(cur);
        }
-       process_unlock();
 
        return 0;
 }