Skip to content

Commit

Permalink
totemknet: retry knet_handle_new if it fails
Browse files Browse the repository at this point in the history
Retry knet_handle_new without privileged operations if it fails

knet_handle_new can fail with ENAMETOOLONG if its privileged operations
fail, which can happen if we're running as a user process or in an
unprivileged container.

This adds a cmap key 'allow_knet_handle_fallback' that defaults to no,
which is the current behavior of exiting with error if the knet_handle
can't be created with privileged operations. If the new cmap key is set
to 'yes' and the knet_handle creation fails, fallback to creating the
handle using unprivileged operations is tried.

Signed-off-by: Dan Streetman <ddstreet@canonical.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
  • Loading branch information
Dan Streetman authored and jfriesse committed Mar 18, 2021
1 parent 2d29f68 commit 4f171ea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions exec/cfg.c
Expand Up @@ -640,6 +640,7 @@ static void remove_ro_entries(icmap_map_t temp_map)
delete_and_notify_if_changed(temp_map, "totem.cluster_name");
delete_and_notify_if_changed(temp_map, "quorum.provider");
delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
delete_and_notify_if_changed(temp_map, "system.allow_knet_handle_fallback");
delete_and_notify_if_changed(temp_map, "system.sched_rr");
delete_and_notify_if_changed(temp_map, "system.priority");
delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
Expand Down
8 changes: 8 additions & 0 deletions exec/coroparse.c
Expand Up @@ -808,6 +808,14 @@ static int main_config_parser_cb(const char *path,
return (0);
}
}
if (strcmp(path, "system.allow_knet_handle_fallback") == 0) {
if ((strcmp(value, "yes") != 0) &&
(strcmp(value, "no") != 0)) {
*error_string = "Invalid system.allow_knet_handle_fallback";

return (0);
}
}
break;

case MAIN_CP_CB_DATA_STATE_INTERFACE:
Expand Down
22 changes: 19 additions & 3 deletions exec/totemknet.c
Expand Up @@ -1081,7 +1081,9 @@ int totemknet_initialize (
void *context))
{
struct totemknet_instance *instance;
char *tmp_str;
int8_t channel=0;
int allow_knet_handle_fallback=0;
int res;
int i;

Expand Down Expand Up @@ -1146,13 +1148,27 @@ int totemknet_initialize (
goto exit_error;
}

if (icmap_get_string("system.allow_knet_handle_fallback", &tmp_str) == CS_OK) {
if (strcmp(tmp_str, "yes") == 0) {
allow_knet_handle_fallback = 1;
}
free(tmp_str);
}

#if !defined(KNET_API_VER) || (KNET_API_VER == 1)
#if defined(KNET_API_VER) && (KNET_API_VER == 2)
instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, KNET_HANDLE_FLAG_PRIVILEGED);
#else
instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG);
#endif
#if KNET_API_VER == 2
instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, KNET_HANDLE_FLAG_PRIVILEGED);

if (allow_knet_handle_fallback && !instance->knet_handle && errno == ENAMETOOLONG) {
KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING, "knet_handle_new failed, trying unprivileged");
#if defined(KNET_API_VER) && (KNET_API_VER == 2)
instance->knet_handle = knet_handle_new(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, 0);
#else
instance->knet_handle = knet_handle_new_ex(instance->totem_config->node_id, instance->logpipes[1], KNET_LOG_DEBUG, 0);
#endif
}

if (!instance->knet_handle) {
KNET_LOGSYS_PERROR(errno, LOGSYS_LEVEL_CRIT, "knet_handle_new failed");
Expand Down
11 changes: 11 additions & 0 deletions man/corosync.conf.5
Expand Up @@ -801,6 +801,17 @@ Should be set to yes (default) if corosync should try to move itself to root
cgroup. This feature is available only for systems with cgroups with RT
sched enabled (Linux with CONFIG_RT_GROUP_SCHED kernel option).

.TP
allow_knet_handle_fallback
If knet handle creation fails using privileged operations, allow fallback to
creating knet handle using unprivileged operations. Defaults to no, meaning
if privileged knet handle creation fails, corosync will refuse to start.

The knet handle will always be created using privileged operations if possible,
setting this to yes only allows fallback to unprivileged operations. This fallback
may result in performance issues, but if running in an unprivileged environment,
e.g. as a normal user or in unprivileged container, this may be required.

.TP
state_dir
Existing directory where corosync should chdir into. Corosync stores
Expand Down

0 comments on commit 4f171ea

Please sign in to comment.