ctdb-tests: Fix some incorrect memory allocations
[obnox/samba/samba-obnox.git] / ctdb / tests / src / ctdb_takeover_tests.c
1 /* 
2    Tests for ctdb_takeover.c
3
4    Copyright (C) Martin Schwenke 2011
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "ctdbd_test.c"
21
22 /* This is lazy... but it is test code! */
23 #define CTDB_TEST_MAX_NODES 256
24 #define CTDB_TEST_MAX_IPS 1024
25
26 /* Format of each line is "IP pnn" - the separator has to be at least
27  * 1 space (not a tab or whatever - a space!).
28  */
29 static struct public_ip_list *
30 read_ctdb_public_ip_list(TALLOC_CTX *ctx)
31 {
32         char line[1024];
33         ctdb_sock_addr addr;
34         char *t;
35         int pnn;
36         struct public_ip_list *last = NULL;
37
38         struct public_ip_list *ret = NULL;
39
40         while (fgets(line, sizeof(line), stdin) != NULL) {
41                 
42                 if ((t = strchr(line, ' ')) != NULL) {
43                         /* Make line contain just the address */
44                         *t = '\0';
45                         /* Point to PNN or leading whitespace...  */
46                         t++;
47                         pnn = (int) strtol(t, (char **) NULL, 10);
48                 } else {
49                         /* Assume just an IP address, default to PNN -1 */
50                         if ((t = strchr(line, '\n')) != NULL) {
51                                 *t = '\0';
52                         }
53                         pnn = -1;
54                 }
55                
56                 if (parse_ip(line, NULL, 0, &addr)) {
57                         if (last == NULL) {
58                                 last = talloc(ctx, struct public_ip_list);
59                         } else {
60                                 last->next = talloc(ctx, struct public_ip_list);
61                                 last = last->next;
62                         }
63                         last->next = NULL;
64                         last->pnn = pnn;
65                         memcpy(&(last->addr), &addr, sizeof(addr));
66                         if (ret == NULL) {
67                                 ret = last;
68                         }
69                 } else {
70                         DEBUG(DEBUG_ERR, (__location__ " ERROR, bad address :%s\n", line));
71                 }
72         }
73                         
74         return ret;
75 }
76
77 static void print_ctdb_public_ip_list(struct public_ip_list * ips)
78 {
79         while (ips) {
80                 printf("%s %d\n", ctdb_addr_to_str(&(ips->addr)), ips->pnn);
81                 ips = ips->next;
82         }
83 }
84
85 /* Read some IPs from stdin, 1 per line, parse them and then print
86  * them back out. */
87 static void ctdb_test_read_ctdb_public_ip_list(void)
88 {
89         struct public_ip_list *l;
90
91         TALLOC_CTX *tmp_ctx = talloc_new(NULL);
92
93         l = read_ctdb_public_ip_list(tmp_ctx);
94
95         print_ctdb_public_ip_list(l);
96
97         talloc_free(tmp_ctx);
98 }
99
100 static uint32_t *get_tunable_values(TALLOC_CTX *tmp_ctx,
101                                     int numnodes,
102                                     const char *tunable);
103 static enum ctdb_runstate *get_runstate(TALLOC_CTX *tmp_ctx,
104                                         int numnodes);
105
106 /* Format of each line is "IP CURRENT_PNN ALLOWED_PNN,...".
107  */
108 static bool
109 read_ctdb_public_ip_info(TALLOC_CTX *ctx  ,
110                          int numnodes,
111                          struct public_ip_list ** all_ips,
112                          struct ctdb_public_ip_list_old *** known,
113                          struct ctdb_public_ip_list_old *** avail)
114 {
115         char line[1024];
116         ctdb_sock_addr addr;
117         char *t, *tok;
118         struct public_ip_list * ta;
119         int pnn, numips, curr, n, i;
120         struct ctdb_public_ip_list_old * a;
121
122         struct public_ip_list *last = NULL;
123         enum ctdb_runstate *runstate;
124
125         runstate = get_runstate(ctx, numnodes);
126
127         *known = talloc_array_size(ctx, sizeof(struct ctdb_public_ip_list_old *), CTDB_TEST_MAX_NODES);
128         memset(*known, 0,
129                sizeof(struct ctdb_public_ip_list_old *) * CTDB_TEST_MAX_NODES);
130
131         *avail = talloc_array_size(ctx, sizeof(struct ctdb_public_ip_list_old *),
132                                    CTDB_TEST_MAX_NODES);
133         memset(*avail, 0,
134                sizeof(struct ctdb_public_ip_list_old *) * CTDB_TEST_MAX_NODES);
135
136         numips = 0;
137         *all_ips = NULL;
138         while (fgets(line, sizeof(line), stdin) != NULL) {
139
140                 /* Get rid of pesky newline */
141                 if ((t = strchr(line, '\n')) != NULL) {
142                         *t = '\0';
143                 }
144
145                 /* Exit on an empty line */
146                 if (line[0] == '\0') {
147                         break;
148                 }
149
150                 /* Get the IP address */
151                 tok = strtok(line, " \t");
152                 if (tok == NULL) {
153                         DEBUG(DEBUG_ERR, (__location__ " WARNING, bad line ignored :%s\n", line));
154                         continue;
155                 }
156
157                 if (!parse_ip(tok, NULL, 0, &addr)) {
158                         DEBUG(DEBUG_ERR, (__location__ " ERROR, bad address :%s\n", tok));
159                         continue;
160                 }
161
162                 numips++;
163                 if (numips > CTDB_TEST_MAX_IPS) {
164                         DEBUG(DEBUG_ERR, ("ERROR: Exceeding CTDB_TEST_MAX_IPS: %d\n", CTDB_TEST_MAX_IPS));
165                         exit(1);
166                 }
167
168                 /* Get the PNN */
169                 pnn = -1;
170                 tok = strtok(NULL, " \t");
171                 if (tok != NULL) {
172                         pnn = (int) strtol(tok, (char **) NULL, 10);
173                 }
174
175                 /* Add address + pnn to all_ips */
176                 if (last == NULL) {
177                         last = talloc(ctx, struct public_ip_list);
178                 } else {
179                         last->next = talloc(ctx, struct public_ip_list);
180                         last = last->next;
181                 }
182                 last->next = NULL;
183                 last->pnn = pnn;
184                 memcpy(&(last->addr), &addr, sizeof(addr));
185                 if (*all_ips == NULL) {
186                         *all_ips = last;
187                 }
188
189                 tok = strtok(NULL, " \t#");
190                 if (tok == NULL) {
191                         continue;
192                 }
193
194                 /* Handle allowed nodes for addr */
195                 t = strtok(tok, ",");
196                 while (t != NULL) {
197                         n = (int) strtol(t, (char **) NULL, 10);
198                         if ((*known)[n] == NULL) {
199                                 /* Array size here has to be
200                                  * CTDB_TEST_MAX_IPS because total
201                                  * number of IPs isn't yet known */
202                                 (*known)[n] = talloc_size(ctx,
203                                                           offsetof(struct ctdb_public_ip_list_old, ips) +
204                                                           CTDB_TEST_MAX_IPS * sizeof(struct ctdb_public_ip));
205                                 (*known)[n]->num = 0;
206                         }
207                         curr = (*known)[n]->num;
208                         (*known)[n]->ips[curr].pnn = pnn;
209                         memcpy(&((*known)[n]->ips[curr].addr),
210                                &addr, sizeof(addr));
211                         (*known)[n]->num++;
212                         t = strtok(NULL, ",");
213                 }
214
215         }
216
217         /* Build list of all allowed IPs */
218         a = talloc_size(ctx,
219                         offsetof(struct ctdb_public_ip_list_old, ips) +
220                         numips * sizeof(struct ctdb_public_ip));
221         a->num = numips;
222         for (ta = *all_ips, i=0; ta != NULL && i < numips ; ta = ta->next, i++) {
223                 a->ips[i].pnn = ta->pnn;
224                 memcpy(&(a->ips[i].addr), &(ta->addr), sizeof(ta->addr));
225         }
226
227         /* Assign it to any nodes that don't have a list assigned */
228         for (n = 0; n < numnodes; n++) {
229                 if ((*known)[n] == NULL) {
230                         (*known)[n] = a;
231                 }
232                 if (runstate[n] == CTDB_RUNSTATE_RUNNING) {
233                         (*avail)[n] = (*known)[n];
234                 }
235         }
236
237         return true;
238 }
239
240 static void print_ctdb_available_ips(int numnodes,
241                                      struct ctdb_public_ip_list_old **avail)
242 {
243         int n, i;
244
245         for (n = 0; n < numnodes; n++) {
246                 if ((avail[n] != NULL) && (avail[n]->num > 0)) {
247                         printf("%d:", n);
248                         for (i = 0; i < avail[n]->num; i++) {
249                                 printf("%s%s",
250                                        (i == 0) ? " " : ", ",
251                                        ctdb_addr_to_str(&(avail[n]->ips[i].addr)));
252                         }
253                         printf("\n");
254                 }
255         }
256 }
257
258 static void ctdb_test_read_ctdb_public_ip_info(const char nodestates[])
259 {
260         int numnodes;
261         struct public_ip_list *l;
262         struct ctdb_public_ip_list_old **known;
263         struct ctdb_public_ip_list_old **avail;
264         char *tok, *ns;
265
266         TALLOC_CTX *tmp_ctx = talloc_new(NULL);
267
268         /* Avoid that const */
269         ns = talloc_strdup(tmp_ctx, nodestates);
270
271         numnodes = 0;
272         tok = strtok(ns, ",");
273         while (tok != NULL) {
274                 numnodes++;
275                 if (numnodes > CTDB_TEST_MAX_NODES) {
276                         DEBUG(DEBUG_ERR, ("ERROR: Exceeding CTDB_TEST_MAX_NODES: %d\n", CTDB_TEST_MAX_NODES));
277                         exit(1);
278                 }
279                 tok = strtok(NULL, ",");
280         }
281         
282         read_ctdb_public_ip_info(tmp_ctx, numnodes, &l, &known, &avail);
283
284         print_ctdb_public_ip_list(l);
285         print_ctdb_available_ips(numnodes, avail);
286
287         talloc_free(tmp_ctx);
288 }
289
290 /* Read 2 IPs from stdin, calculate the IP distance and print it. */
291 static void ctdb_test_ip_distance(void)
292 {
293         struct public_ip_list *l;
294         uint32_t distance;
295
296         TALLOC_CTX *tmp_ctx = talloc_new(NULL);
297
298         l = read_ctdb_public_ip_list(tmp_ctx);
299
300         if (l && l->next) {
301                 distance = ip_distance(&(l->addr), &(l->next->addr));
302                 printf ("%lu\n", (unsigned long) distance);
303         }
304
305         talloc_free(tmp_ctx);
306 }
307
308 /* Read some IPs from stdin, calculate the sum of the squares of the
309  * IP distances between the 1st argument and those read that are on
310  * the given node. The given IP must one of the ones in the list.  */
311 static void ctdb_test_ip_distance_2_sum(const char ip[], int pnn)
312 {
313         struct public_ip_list *l;
314         struct public_ip_list *t;
315         ctdb_sock_addr addr;
316         uint32_t distance;
317
318         TALLOC_CTX *tmp_ctx = talloc_new(NULL);
319
320         
321         l = read_ctdb_public_ip_list(tmp_ctx);
322
323         if (l && parse_ip(ip, NULL, 0, &addr)) {
324                 /* find the entry for the specified IP */
325                 for (t=l; t!=NULL; t=t->next) {
326                         if (ctdb_same_ip(&(t->addr), &addr)) {
327                                 break;
328                         }
329                 }
330
331                 if (t == NULL) {
332                         fprintf(stderr, "IP NOT PRESENT IN LIST");
333                         exit(1);
334                 }
335
336                 distance = ip_distance_2_sum(&(t->addr), l, pnn);
337                 printf ("%lu\n", (unsigned long) distance);
338         } else {
339                 fprintf(stderr, "BAD INPUT");
340                 exit(1);
341         }
342
343         talloc_free(tmp_ctx);
344 }
345
346 /* Read some IPs from stdin, calculate the sum of the squares of the
347  * IP distances between the first and the rest, and print it. */
348 static void ctdb_test_lcp2_imbalance(int pnn)
349 {
350         struct public_ip_list *l;
351         uint32_t imbalance;
352
353         TALLOC_CTX *tmp_ctx = talloc_new(NULL);
354
355         l = read_ctdb_public_ip_list(tmp_ctx);
356
357         imbalance = lcp2_imbalance(l, pnn);
358         printf ("%lu\n", (unsigned long) imbalance);
359
360         talloc_free(tmp_ctx);
361 }
362
363 static uint32_t *get_tunable_values(TALLOC_CTX *tmp_ctx,
364                                     int numnodes,
365                                     const char *tunable)
366 {
367         int i;
368         char *tok;
369         uint32_t *tvals = talloc_zero_array(tmp_ctx, uint32_t, numnodes);
370         char *t = getenv(tunable);
371
372         if (t) {
373                 if (strcmp(t, "1") == 0) {
374                         for (i=0; i<numnodes; i++) {
375                                 tvals[i] = 1;
376                         }
377                 } else {
378                         tok = strtok(t, ",");
379                         i = 0;
380                         while (tok != NULL) {
381                                 tvals[i] =
382                                         (uint32_t) strtol(tok, NULL, 0);
383                                 i++;
384                                 tok = strtok(NULL, ",");
385                         }
386                         if (i != numnodes) {
387                                 fprintf(stderr, "ERROR: Wrong number of values in %s\n", tunable);
388                                 exit(1);
389                         }
390                 }
391         }
392
393         return tvals;
394 }
395
396 static enum ctdb_runstate *get_runstate(TALLOC_CTX *tmp_ctx,
397                                         int numnodes)
398 {
399         int i;
400         uint32_t *tvals;
401         enum ctdb_runstate *runstate =
402                 talloc_zero_array(tmp_ctx, enum ctdb_runstate, numnodes);
403         char *t = getenv("CTDB_TEST_RUNSTATE");
404
405         if (t == NULL) {
406                 for (i=0; i<numnodes; i++) {
407                         runstate[i] = CTDB_RUNSTATE_RUNNING;
408                 }
409         } else {
410                 tvals = get_tunable_values(tmp_ctx, numnodes, "CTDB_TEST_RUNSTATE");
411                 for (i=0; i<numnodes; i++) {
412                         runstate[i] = (enum ctdb_runstate) tvals[i];
413                 }
414                 talloc_free(tvals);
415         }
416
417         return runstate;
418 }
419
420 /* Fake up enough CTDB state to be able to run the IP allocation
421  * algorithm.  Usually this sets up some standard state, sets the node
422  * states from the command-line and reads the current IP layout from
423  * stdin.
424  *
425  * However, if read_ips_for_multiple_nodes is true then each node's
426  * idea of the IP layout is read separately from stdin.  In this mode
427  * is doesn't make much sense to use read_ctdb_public_ip_info's
428  * optional ALLOWED_PNN,... list in the input, since each node is
429  * being handled separately anyway.  IPs for each node are separated
430  * by a blank line.  This mode is for testing weird behaviours where
431  * the IP layouts differs across nodes and we want to improve
432  * create_merged_ip_list(), so should only be used in tests of
433  * ipalloc().  Yes, it is a hack...  :-)
434  */
435 static void ctdb_test_init(const char nodestates[],
436                            struct ctdb_context **ctdb,
437                            struct ipalloc_state **ipalloc_state,
438                            bool read_ips_for_multiple_nodes)
439 {
440         struct ctdb_public_ip_list_old **known;
441         struct ctdb_public_ip_list_old **avail;
442         int i, numnodes;
443         uint32_t nodeflags[CTDB_TEST_MAX_NODES];
444         char *tok, *ns, *t;
445         struct ctdb_node_map_old *nodemap;
446         uint32_t *tval_noiptakeover;
447         uint32_t *tval_noiptakeoverondisabled;
448         struct public_ip_list *all_ips;
449
450         *ctdb = talloc_zero(NULL, struct ctdb_context);
451
452         /* Avoid that const */
453         ns = talloc_strdup(*ctdb, nodestates);
454
455         numnodes = 0;
456         tok = strtok(ns, ",");
457         while (tok != NULL) {
458                 nodeflags[numnodes] = (uint32_t) strtol(tok, NULL, 0);
459                 numnodes++;
460                 if (numnodes >= CTDB_TEST_MAX_NODES) {
461                         DEBUG(DEBUG_ERR, ("ERROR: Exceeding CTDB_TEST_MAX_NODES: %d\n", CTDB_TEST_MAX_NODES));
462                         exit(1);
463                 }
464                 tok = strtok(NULL, ",");
465         }
466         
467         /* Fake things up... */
468         (*ctdb)->num_nodes = numnodes;
469
470         /* Default to LCP2 */
471         (*ctdb)->tunable.lcp2_public_ip_assignment = 1;
472         (*ctdb)->tunable.deterministic_public_ips = 0;
473         (*ctdb)->tunable.disable_ip_failover = 0;
474         (*ctdb)->tunable.no_ip_failback = 0;
475
476         if ((t = getenv("CTDB_IP_ALGORITHM"))) {
477                 if (strcmp(t, "lcp2") == 0) {
478                         (*ctdb)->tunable.lcp2_public_ip_assignment = 1;
479                 } else if (strcmp(t, "nondet") == 0) {
480                         (*ctdb)->tunable.lcp2_public_ip_assignment = 0;
481                 } else if (strcmp(t, "det") == 0) {
482                         (*ctdb)->tunable.lcp2_public_ip_assignment = 0;
483                         (*ctdb)->tunable.deterministic_public_ips = 1;
484                 } else {
485                         fprintf(stderr, "ERROR: unknown IP algorithm %s\n", t);
486                         exit(1);
487                 }
488         }
489
490         tval_noiptakeover = get_tunable_values(*ctdb, numnodes,
491                                                "CTDB_SET_NoIPTakeover");
492         tval_noiptakeoverondisabled =
493                 get_tunable_values(*ctdb, numnodes,
494                                    "CTDB_SET_NoIPHostOnAllDisabled");
495
496         nodemap =  talloc_array(*ctdb, struct ctdb_node_map_old, numnodes);
497         nodemap->num = numnodes;
498
499         if (!read_ips_for_multiple_nodes) {
500                 read_ctdb_public_ip_info(*ctdb, numnodes,
501                                          &all_ips, &known, &avail);
502         }
503
504         (*ctdb)->nodes = talloc_array(*ctdb, struct ctdb_node *, numnodes); // FIXME: bogus size, overkill
505
506         *ipalloc_state = ipalloc_state_init(*ctdb, *ctdb);
507
508         for (i=0; i < numnodes; i++) {
509                 nodemap->nodes[i].pnn = i;
510                 nodemap->nodes[i].flags = nodeflags[i];
511                 /* nodemap->nodes[i].sockaddr is uninitialised */
512
513                 if (read_ips_for_multiple_nodes) {
514                         read_ctdb_public_ip_info(*ctdb, numnodes,
515                                                  &all_ips, &known, &avail);
516                 }
517
518                 (*ctdb)->nodes[i] = talloc(*ctdb, struct ctdb_node);
519                 (*ctdb)->nodes[i]->pnn = i;
520                 (*ctdb)->nodes[i]->flags = nodeflags[i];
521
522                 (*ipalloc_state)->available_public_ips[i] = avail[i];
523                 (*ipalloc_state)->known_public_ips[i] = known[i];
524         }
525
526         set_ipflags_internal(*ipalloc_state, nodemap,
527                              tval_noiptakeover,
528                              tval_noiptakeoverondisabled);
529
530         (*ipalloc_state)->all_ips = create_merged_ip_list(*ctdb,
531                                                           *ipalloc_state);
532
533         (*ipalloc_state)->force_rebalance_nodes = NULL;
534 }
535
536 /* IP layout is read from stdin. */
537 static void ctdb_test_lcp2_allocate_unassigned(const char nodestates[])
538 {
539         struct ctdb_context *ctdb;
540         struct ipalloc_state *ipalloc_state;
541
542         uint32_t *lcp2_imbalances;
543         bool *newly_healthy;
544
545         ctdb_test_init(nodestates, &ctdb, &ipalloc_state, false);
546
547         lcp2_init(ipalloc_state, &lcp2_imbalances, &newly_healthy);
548
549         lcp2_allocate_unassigned(ipalloc_state, lcp2_imbalances);
550
551         print_ctdb_public_ip_list(ipalloc_state->all_ips);
552
553         talloc_free(ctdb);
554 }
555
556 /* IP layout is read from stdin. */
557 static void ctdb_test_lcp2_failback(const char nodestates[])
558 {
559         struct ctdb_context *ctdb;
560         struct ipalloc_state *ipalloc_state;
561
562         uint32_t *lcp2_imbalances;
563         bool *newly_healthy;
564
565         ctdb_test_init(nodestates, &ctdb, &ipalloc_state, false);
566
567         lcp2_init(ipalloc_state, &lcp2_imbalances, &newly_healthy);
568
569         lcp2_failback(ipalloc_state, lcp2_imbalances, newly_healthy);
570
571         print_ctdb_public_ip_list(ipalloc_state->all_ips);
572
573         talloc_free(ctdb);
574 }
575
576 /* IP layout is read from stdin. */
577 static void ctdb_test_lcp2_failback_loop(const char nodestates[])
578 {
579         struct ctdb_context *ctdb;
580         struct ipalloc_state *ipalloc_state;
581
582         uint32_t *lcp2_imbalances;
583         bool *newly_healthy;
584
585         ctdb_test_init(nodestates, &ctdb, &ipalloc_state, false);
586
587         lcp2_init(ipalloc_state, &lcp2_imbalances, &newly_healthy);
588
589         lcp2_failback(ipalloc_state, lcp2_imbalances, newly_healthy);
590
591         print_ctdb_public_ip_list(ipalloc_state->all_ips);
592
593         talloc_free(ctdb);
594 }
595
596 /* IP layout is read from stdin.  See comment for ctdb_test_init() for
597  * explanation of read_ips_for_multiple_nodes.
598  */
599 static void ctdb_test_ipalloc(const char nodestates[],
600                               bool read_ips_for_multiple_nodes)
601 {
602         struct ctdb_context *ctdb;
603         struct ipalloc_state *ipalloc_state;
604
605         ctdb_test_init(nodestates, &ctdb, &ipalloc_state,
606                        read_ips_for_multiple_nodes);
607
608         ipalloc(ipalloc_state);
609
610         print_ctdb_public_ip_list(ipalloc_state->all_ips);
611
612         talloc_free(ctdb);
613 }
614
615 static void usage(void)
616 {
617         fprintf(stderr, "usage: ctdb_takeover_tests <op>\n");
618         exit(1);
619 }
620
621 int main(int argc, const char *argv[])
622 {
623         DEBUGLEVEL = DEBUG_DEBUG;
624         if (getenv("CTDB_TEST_LOGLEVEL")) {
625                 DEBUGLEVEL = atoi(getenv("CTDB_TEST_LOGLEVEL"));
626         }
627
628         if (argc < 2) {
629                 usage();
630         }
631
632         if (strcmp(argv[1], "ip_list") == 0) {
633                 ctdb_test_read_ctdb_public_ip_list();
634         } else if (argc == 3 && strcmp(argv[1], "ip_info") == 0) {
635                 ctdb_test_read_ctdb_public_ip_info(argv[2]);
636         } else if (strcmp(argv[1], "ip_distance") == 0) {
637                 ctdb_test_ip_distance();
638         } else if (argc == 4 && strcmp(argv[1], "ip_distance_2_sum") == 0) {
639                 ctdb_test_ip_distance_2_sum(argv[2], atoi(argv[3]));
640         } else if (argc >= 3 && strcmp(argv[1], "lcp2_imbalance") == 0) {
641                 ctdb_test_lcp2_imbalance(atoi(argv[2]));
642         } else if (argc == 3 && strcmp(argv[1], "lcp2_allocate_unassigned") == 0) {
643                 ctdb_test_lcp2_allocate_unassigned(argv[2]);
644         } else if (argc == 3 && strcmp(argv[1], "lcp2_failback") == 0) {
645                 ctdb_test_lcp2_failback(argv[2]);
646         } else if (argc == 3 && strcmp(argv[1], "lcp2_failback_loop") == 0) {
647                 ctdb_test_lcp2_failback_loop(argv[2]);
648         } else if (argc == 3 &&
649                    strcmp(argv[1], "ipalloc") == 0) {
650                 ctdb_test_ipalloc(argv[2], false);
651         } else if (argc == 4 &&
652                    strcmp(argv[1], "ipalloc") == 0 &&
653                    strcmp(argv[3], "multi") == 0) {
654                 ctdb_test_ipalloc(argv[2], true);
655         } else {
656                 usage();
657         }
658
659         return 0;
660 }