[lxc-devel] [lxc/master] commands: remove mutex from state client list

brauner on Github lxc-bot at linuxcontainers.org
Mon Feb 26 10:52:11 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1235 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180226/df366622/attachment.bin>
-------------- next part --------------
From 328a3f0f8b34ca11f5b1b6c9bcb3e40a15303255 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 26 Feb 2018 11:43:42 +0100
Subject: [PATCH] commands: remove mutex from state client list

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 at ubuntu.com>
---
 src/lxc/commands.c       | 2 --
 src/lxc/commands_utils.c | 3 ---
 src/lxc/start.c          | 3 ---
 3 files changed, 8 deletions(-)

diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 3062ec11e..2246b0c4a 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -1149,7 +1149,6 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
 		return;
 	}
 
-	process_lock();
 	lxc_list_for_each_safe(cur, &handler->conf->state_clients, next) {
 		client = cur->elem;
 		if (client->clientfd != fd)
@@ -1165,7 +1164,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,
diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c
index 12b131707..3a96b42dd 100644
--- a/src/lxc/commands_utils.c
+++ b/src/lxc/commands_utils.c
@@ -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->conf->state_clients, tmplist);
-		process_unlock();
 	} else {
-		process_unlock();
 		free(newclient);
 		free(tmplist);
 		return state;
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 1279635d6..5438ebda0 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -390,7 +390,6 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
 	struct lxc_state_client *client;
 	struct lxc_msg msg = {.type = lxc_msg_state, .value = state};
 
-	process_lock();
 	if (state == THAWED)
 		handler->state = RUNNING;
 	else
@@ -400,7 +399,6 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
 
 	if (lxc_list_empty(&handler->conf->state_clients)) {
 		TRACE("No state clients registered");
-		process_unlock();
 		return 0;
 	}
 
@@ -437,7 +435,6 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
 		free(cur->elem);
 		free(cur);
 	}
-	process_unlock();
 
 	return 0;
 }


More information about the lxc-devel mailing list