commands: don't lock atomic operations

We're dealing with an integer (lxc_state_t which is an enum). Any POSIX implementation makes those operations atomic so there's not need in locking this. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent e1ff30a9
...@@ -841,44 +841,35 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath, ...@@ -841,44 +841,35 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath,
}, },
}; };
/* Lock the whole lxc_cmd_add_state_client_callback() call to ensure
* that lxc_set_state() doesn't cause us to miss a state.
*/
process_lock();
/* Check if already in requested state. */ /* Check if already in requested state. */
state = lxc_getstate(name, lxcpath); state = lxc_getstate(name, lxcpath);
if (state < 0) { if (state < 0) {
process_unlock();
TRACE("%s - Failed to retrieve state of container", strerror(errno)); TRACE("%s - Failed to retrieve state of container", strerror(errno));
return -1; return -1;
} else if (states[state]) { } else if (states[state]) {
process_unlock();
TRACE("Container is %s state", lxc_state2str(state)); TRACE("Container is %s state", lxc_state2str(state));
return state; return state;
} }
if ((state == STARTING) && !states[RUNNING] && !states[STOPPING] && !states[STOPPED]) { if ((state == STARTING) && !states[RUNNING] && !states[STOPPING] && !states[STOPPED]) {
process_unlock();
TRACE("Container is in %s state and caller requested to be " TRACE("Container is in %s state and caller requested to be "
"informed about a previous state", lxc_state2str(state)); "informed about a previous state", lxc_state2str(state));
return state; return state;
} else if ((state == RUNNING) && !states[STOPPING] && !states[STOPPED]) { } else if ((state == RUNNING) && !states[STOPPING] && !states[STOPPED]) {
process_unlock();
TRACE("Container is in %s state and caller requested to be " TRACE("Container is in %s state and caller requested to be "
"informed about a previous state", lxc_state2str(state)); "informed about a previous state", lxc_state2str(state));
return state; return state;
} else if ((state == STOPPING) && !states[STOPPED]) { } else if ((state == STOPPING) && !states[STOPPED]) {
process_unlock();
TRACE("Container is in %s state and caller requested to be " TRACE("Container is in %s state and caller requested to be "
"informed about a previous state", lxc_state2str(state)); "informed about a previous state", lxc_state2str(state));
return state; return state;
} else if ((state == STOPPED) || (state == ABORTING)) { } else if ((state == STOPPED) || (state == ABORTING)) {
process_unlock();
TRACE("Container is in %s state and caller requested to be " TRACE("Container is in %s state and caller requested to be "
"informed about a previous state", lxc_state2str(state)); "informed about a previous state", lxc_state2str(state));
return state; return state;
} }
process_lock();
ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL); ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
process_unlock(); process_unlock();
if (ret < 0) { if (ret < 0) {
......
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