You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
12 KiB

  1. From fa73e6b0d5f64eb8a6fd8a1706d7ec03293a943e Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= <flecaille@haproxy.com>
  3. Date: Thu, 13 Jul 2017 09:07:09 +0200
  4. Subject: [PATCH 01/18] BUG/MINOR: peers: peer synchronization issue (with
  5. several peers sections).
  6. When several stick-tables were configured with several peers sections,
  7. only a part of them could be synchronized: the ones attached to the last
  8. parsed 'peers' section. This was due to the fact that, at least, the peer I/O handler
  9. refered to the wrong peer section list, in fact always the same: the last one parsed.
  10. The fact that the global peer section list was named "struct peers *peers"
  11. lead to this issue. This variable name is dangerous ;).
  12. So this patch renames global 'peers' variable to 'cfg_peers' to ensure that
  13. no such wrong references are still in use, then all the functions wich used
  14. old 'peers' variable have been modified to refer to the correct peer list.
  15. Must be backported to 1.6 and 1.7.
  16. (cherry picked from commit ed2b4a6b793d062000518e51ed71e014c649c313)
  17. Signed-off-by: Willy Tarreau <w@1wt.eu>
  18. ---
  19. include/types/peers.h | 2 +-
  20. src/cfgparse.c | 18 +++++++++---------
  21. src/haproxy.c | 10 +++++-----
  22. src/peers.c | 40 ++++++++++++++++++++--------------------
  23. src/proxy.c | 6 +++---
  24. 5 files changed, 38 insertions(+), 38 deletions(-)
  25. diff --git a/include/types/peers.h b/include/types/peers.h
  26. index 105dffb0..a77a0942 100644
  27. --- a/include/types/peers.h
  28. +++ b/include/types/peers.h
  29. @@ -91,7 +91,7 @@ struct peers {
  30. };
  31. -extern struct peers *peers;
  32. +extern struct peers *cfg_peers;
  33. #endif /* _TYPES_PEERS_H */
  34. diff --git a/src/cfgparse.c b/src/cfgparse.c
  35. index 8c0906bf..1b53006b 100644
  36. --- a/src/cfgparse.c
  37. +++ b/src/cfgparse.c
  38. @@ -2124,7 +2124,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
  39. goto out;
  40. }
  41. - for (curpeers = peers; curpeers != NULL; curpeers = curpeers->next) {
  42. + for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) {
  43. /*
  44. * If there are two proxies with the same name only following
  45. * combinations are allowed:
  46. @@ -2142,8 +2142,8 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
  47. goto out;
  48. }
  49. - curpeers->next = peers;
  50. - peers = curpeers;
  51. + curpeers->next = cfg_peers;
  52. + cfg_peers = curpeers;
  53. curpeers->conf.file = strdup(file);
  54. curpeers->conf.line = linenum;
  55. curpeers->last_change = now.tv_sec;
  56. @@ -2223,7 +2223,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
  57. if (strcmp(newpeer->id, localpeer) == 0) {
  58. /* Current is local peer, it define a frontend */
  59. newpeer->local = 1;
  60. - peers->local = newpeer;
  61. + cfg_peers->local = newpeer;
  62. if (!curpeers->peers_fe) {
  63. if ((curpeers->peers_fe = calloc(1, sizeof(struct proxy))) == NULL) {
  64. @@ -8189,9 +8189,9 @@ int check_config_validity()
  65. }
  66. if (curproxy->table.peers.name) {
  67. - struct peers *curpeers = peers;
  68. + struct peers *curpeers;
  69. - for (curpeers = peers; curpeers; curpeers = curpeers->next) {
  70. + for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
  71. if (strcmp(curpeers->id, curproxy->table.peers.name) == 0) {
  72. free((void *)curproxy->table.peers.name);
  73. curproxy->table.peers.p = curpeers;
  74. @@ -9279,15 +9279,15 @@ out_uri_auth_compat:
  75. if (curproxy->table.peers.p)
  76. curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
  77. - if (peers) {
  78. - struct peers *curpeers = peers, **last;
  79. + if (cfg_peers) {
  80. + struct peers *curpeers = cfg_peers, **last;
  81. struct peer *p, *pb;
  82. /* Remove all peers sections which don't have a valid listener,
  83. * which are not used by any table, or which are bound to more
  84. * than one process.
  85. */
  86. - last = &peers;
  87. + last = &cfg_peers;
  88. while (*last) {
  89. curpeers = *last;
  90. diff --git a/src/haproxy.c b/src/haproxy.c
  91. index 6d09aed4..25cea0cd 100644
  92. --- a/src/haproxy.c
  93. +++ b/src/haproxy.c
  94. @@ -988,7 +988,7 @@ void init(int argc, char **argv)
  95. struct peers *pr;
  96. struct proxy *px;
  97. - for (pr = peers; pr; pr = pr->next)
  98. + for (pr = cfg_peers; pr; pr = pr->next)
  99. if (pr->peers_fe)
  100. break;
  101. @@ -1217,11 +1217,11 @@ void init(int argc, char **argv)
  102. if (global.stats_fe)
  103. global.maxsock += global.stats_fe->maxconn;
  104. - if (peers) {
  105. + if (cfg_peers) {
  106. /* peers also need to bypass global maxconn */
  107. - struct peers *p = peers;
  108. + struct peers *p = cfg_peers;
  109. - for (p = peers; p; p = p->next)
  110. + for (p = cfg_peers; p; p = p->next)
  111. if (p->peers_fe)
  112. global.maxsock += p->peers_fe->maxconn;
  113. }
  114. @@ -2067,7 +2067,7 @@ int main(int argc, char **argv)
  115. }
  116. /* we might have to unbind some peers sections from some processes */
  117. - for (curpeers = peers; curpeers; curpeers = curpeers->next) {
  118. + for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) {
  119. if (!curpeers->peers_fe)
  120. continue;
  121. diff --git a/src/peers.c b/src/peers.c
  122. index 543c84c1..5b8a287a 100644
  123. --- a/src/peers.c
  124. +++ b/src/peers.c
  125. @@ -171,7 +171,7 @@ enum {
  126. #define PEER_MINOR_VER 1
  127. #define PEER_DWNGRD_MINOR_VER 0
  128. -struct peers *peers = NULL;
  129. +struct peers *cfg_peers = NULL;
  130. static void peer_session_forceshutdown(struct appctx *appctx);
  131. /* This function encode an uint64 to 'dynamic' length format.
  132. @@ -727,19 +727,19 @@ switchstate:
  133. /* if current peer is local */
  134. if (curpeer->local) {
  135. /* if current host need resyncfrom local and no process assined */
  136. - if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMLOCAL &&
  137. - !(peers->flags & PEERS_F_RESYNC_ASSIGN)) {
  138. + if ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMLOCAL &&
  139. + !(curpeers->flags & PEERS_F_RESYNC_ASSIGN)) {
  140. /* assign local peer for a lesson, consider lesson already requested */
  141. curpeer->flags |= PEER_F_LEARN_ASSIGN;
  142. - peers->flags |= (PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
  143. + curpeers->flags |= (PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
  144. }
  145. }
  146. - else if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
  147. - !(peers->flags & PEERS_F_RESYNC_ASSIGN)) {
  148. + else if ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
  149. + !(curpeers->flags & PEERS_F_RESYNC_ASSIGN)) {
  150. /* assign peer for a lesson */
  151. curpeer->flags |= PEER_F_LEARN_ASSIGN;
  152. - peers->flags |= PEERS_F_RESYNC_ASSIGN;
  153. + curpeers->flags |= PEERS_F_RESYNC_ASSIGN;
  154. }
  155. @@ -807,7 +807,7 @@ switchstate:
  156. curpeer->statuscode = atoi(trash.str);
  157. /* Awake main task */
  158. - task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
  159. + task_wakeup(curpeers->sync_task, TASK_WOKEN_MSG);
  160. /* If status code is success */
  161. if (curpeer->statuscode == PEER_SESS_SC_SUCCESSCODE) {
  162. @@ -830,14 +830,14 @@ switchstate:
  163. curpeer->flags |= PEER_F_TEACH_PROCESS;
  164. }
  165. - else if ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
  166. - !(peers->flags & PEERS_F_RESYNC_ASSIGN)) {
  167. + else if ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FROMREMOTE &&
  168. + !(curpeers->flags & PEERS_F_RESYNC_ASSIGN)) {
  169. /* If peer is remote and resync from remote is needed,
  170. and no peer currently assigned */
  171. /* assign peer for a lesson */
  172. curpeer->flags |= PEER_F_LEARN_ASSIGN;
  173. - peers->flags |= PEERS_F_RESYNC_ASSIGN;
  174. + curpeers->flags |= PEERS_F_RESYNC_ASSIGN;
  175. }
  176. }
  177. @@ -950,8 +950,8 @@ switchstate:
  178. if (curpeer->flags & PEER_F_LEARN_ASSIGN) {
  179. curpeer->flags &= ~PEER_F_LEARN_ASSIGN;
  180. - peers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
  181. - peers->flags |= (PEERS_F_RESYNC_LOCAL|PEERS_F_RESYNC_REMOTE);
  182. + curpeers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
  183. + curpeers->flags |= (PEERS_F_RESYNC_LOCAL|PEERS_F_RESYNC_REMOTE);
  184. }
  185. curpeer->confirm++;
  186. }
  187. @@ -959,11 +959,11 @@ switchstate:
  188. if (curpeer->flags & PEER_F_LEARN_ASSIGN) {
  189. curpeer->flags &= ~PEER_F_LEARN_ASSIGN;
  190. - peers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
  191. + curpeers->flags &= ~(PEERS_F_RESYNC_ASSIGN|PEERS_F_RESYNC_PROCESS);
  192. curpeer->flags |= PEER_F_LEARN_NOTUP2DATE;
  193. - peers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(5000));
  194. - task_wakeup(peers->sync_task, TASK_WOKEN_MSG);
  195. + curpeers->resync_timeout = tick_add(now_ms, MS_TO_TICKS(5000));
  196. + task_wakeup(curpeers->sync_task, TASK_WOKEN_MSG);
  197. }
  198. curpeer->confirm++;
  199. }
  200. @@ -1334,8 +1334,8 @@ incomplete:
  201. /* Need to request a resync */
  202. if ((curpeer->flags & PEER_F_LEARN_ASSIGN) &&
  203. - (peers->flags & PEERS_F_RESYNC_ASSIGN) &&
  204. - !(peers->flags & PEERS_F_RESYNC_PROCESS)) {
  205. + (curpeers->flags & PEERS_F_RESYNC_ASSIGN) &&
  206. + !(curpeers->flags & PEERS_F_RESYNC_PROCESS)) {
  207. unsigned char msg[2];
  208. /* Current peer was elected to request a resync */
  209. @@ -1351,7 +1351,7 @@ incomplete:
  210. appctx->st0 = PEER_SESS_ST_END;
  211. goto switchstate;
  212. }
  213. - peers->flags |= PEERS_F_RESYNC_PROCESS;
  214. + curpeers->flags |= PEERS_F_RESYNC_PROCESS;
  215. }
  216. /* Nothing to read, now we start to write */
  217. @@ -1624,7 +1624,7 @@ incomplete:
  218. /* Current peer was elected to request a resync */
  219. msg[0] = PEER_MSG_CLASS_CONTROL;
  220. - msg[1] = ((peers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FINISHED) ? PEER_MSG_CTRL_RESYNCFINISHED : PEER_MSG_CTRL_RESYNCPARTIAL;
  221. + msg[1] = ((curpeers->flags & PEERS_RESYNC_STATEMASK) == PEERS_RESYNC_FINISHED) ? PEER_MSG_CTRL_RESYNCFINISHED : PEER_MSG_CTRL_RESYNCPARTIAL;
  222. /* process final lesson message */
  223. repl = bi_putblk(si_ic(si), (char *)msg, sizeof(msg));
  224. if (repl <= 0) {
  225. diff --git a/src/proxy.c b/src/proxy.c
  226. index 78120d9b..bedc7ae0 100644
  227. --- a/src/proxy.c
  228. +++ b/src/proxy.c
  229. @@ -1007,7 +1007,7 @@ void soft_stop(void)
  230. p = p->next;
  231. }
  232. - prs = peers;
  233. + prs = cfg_peers;
  234. while (prs) {
  235. if (prs->peers_fe)
  236. stop_proxy(prs->peers_fe);
  237. @@ -1142,7 +1142,7 @@ void pause_proxies(void)
  238. p = p->next;
  239. }
  240. - prs = peers;
  241. + prs = cfg_peers;
  242. while (prs) {
  243. if (prs->peers_fe)
  244. err |= !pause_proxy(prs->peers_fe);
  245. @@ -1176,7 +1176,7 @@ void resume_proxies(void)
  246. p = p->next;
  247. }
  248. - prs = peers;
  249. + prs = cfg_peers;
  250. while (prs) {
  251. if (prs->peers_fe)
  252. err |= !resume_proxy(prs->peers_fe);
  253. --
  254. 2.13.0