<p>Jan Friesse has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5858">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_corosync: Change thread stack size<br><br>In Corosync 2.x libraries were changed to use LibQB IPC.<br>Sadly LibQB IPC doesn't support copy-free access to received buffer, so<br>Corosync libraries were rewritten to use stack as buffer. Mostly the<br>needed stack size is quite small, but for all *_dispatch functions, 1MiB<br>is needed.<br><br>Asterisk function ast_pthread_create_background set stack size for new<br>thread to much smaller AST_BACKGROUND_STACKSIZE (~500KiB).<br><br>This results in Asterisk crash when running with Corosync 2.x.<br><br>Patch solves this issue by creating it's own version of<br>ast_pthread_create_background which sets stack size to much higher value<br>(actually it's AST_BACKGROUND_STACKSIZE + 3MiB).<br><br>Another problem may appear when "corosync show members" netconsole<br>command is executed. It is also executed in thread and also has only<br>500KiB stack size. Sadly it calls corosync_cfg_get_node_addrs which<br>again needs at least 1MiB stack.<br><br>Solution is to use HAVE_COROSYNC_CFG_STATE_TRACK as a discriminator<br>between Corosync 1.x and 2.x. If 1.x is found, nothing changes. If 2.x<br>is found, NodeID is displayed instead of IP address.<br><br>ASTERISK-25370 #close<br>Reported by: mdu113<br><br>Change-Id: Id95b0d21ab6e708e7d74ad8786c587211676fa08<br>---<br>M res/res_corosync.c<br>1 file changed, 24 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/5858/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_corosync.c b/res/res_corosync.c<br>index dbb8846..c865e20 100644<br>--- a/res/res_corosync.c<br>+++ b/res/res_corosync.c<br>@@ -79,6 +79,15 @@<br> struct ast_sockaddr addr;<br> };<br> <br>+/*! \brief Corosync ipc dispatch/request and reply size */<br>+#define COROSYNC_IPC_BUFFER_SIZE (8192 * 128)<br>+<br>+/*! \brief Version of pthread_create to ensure stack is large enough */<br>+#define corosync_pthread_create_background(a, b, c, d) \<br>+ ast_pthread_create_stack(a, b, c, d, \<br>+ (AST_BACKGROUND_STACKSIZE + (3 * COROSYNC_IPC_BUFFER_SIZE)), \<br>+ __FILE__, __FUNCTION__, __LINE__, #c)<br>+<br> static struct corosync_node *corosync_node_alloc(struct ast_event *event)<br> {<br> struct corosync_node *node;<br>@@ -810,19 +819,27 @@<br> for (i = 1, cs_err = cpg_iteration_next(cpg_iter, &cpg_desc);<br> cs_err == CS_OK;<br> cs_err = cpg_iteration_next(cpg_iter, &cpg_desc), i++) {<br>+#ifdef HAVE_COROSYNC_CFG_STATE_TRACK<br> corosync_cfg_node_address_t addrs[8];<br> int num_addrs = 0;<br> unsigned int j;<br>+#endif<br> <br>+ ast_cli(a->fd, "=== Node %u\n", i);<br>+ ast_cli(a->fd, "=== --> Group: %s\n", cpg_desc.group.value);<br>+<br>+#ifdef HAVE_COROSYNC_CFG_STATE_TRACK<br>+ /*<br>+ * Corosync 2.x cfg lib needs to allocate 1M on stack after calling<br>+ * corosync_cfg_get_node_addrs. netconsole thread has allocated only 0.5M<br>+ * resulting in crash.<br>+ */<br> cs_err = corosync_cfg_get_node_addrs(cfg_handle, cpg_desc.nodeid,<br> ARRAY_LEN(addrs), &num_addrs, addrs);<br> if (cs_err != CS_OK) {<br> ast_log(LOG_WARNING, "Failed to get node addresses\n");<br> continue;<br> }<br>-<br>- ast_cli(a->fd, "=== Node %u\n", i);<br>- ast_cli(a->fd, "=== --> Group: %s\n", cpg_desc.group.value);<br> <br> for (j = 0; j < num_addrs; j++) {<br> struct sockaddr *sa = (struct sockaddr *) addrs[j].address;<br>@@ -833,7 +850,9 @@<br> <br> ast_cli(a->fd, "=== --> Address %u: %s\n", j + 1, buf);<br> }<br>-<br>+#else<br>+ ast_cli(a->fd, "=== --> Nodeid: %"PRIu32"\n", cpg_desc.nodeid);<br>+#endif<br> }<br> <br> ast_cli(a->fd, "===\n"<br>@@ -1159,7 +1178,7 @@<br> goto failed;<br> }<br> <br>- if (ast_pthread_create_background(&dispatch_thread.id, NULL,<br>+ if (corosync_pthread_create_background(&dispatch_thread.id, NULL,<br> dispatch_thread_handler, NULL)) {<br> ast_log(LOG_ERROR, "Error starting CPG dispatch thread.\n");<br> goto failed;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5858">change 5858</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/5858"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id95b0d21ab6e708e7d74ad8786c587211676fa08 </div>
<div style="display:none"> Gerrit-Change-Number: 5858 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jan Friesse <jfriesse@redhat.com> </div>