1 /*
2    protocol tests - common functions
3 
4    Copyright (C) Amitay Isaacs  2015-2017
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 "replace.h"
21 #include "system/network.h"
22 
23 #include <assert.h>
24 
25 #include "protocol/protocol_api.h"
26 
27 #include "tests/src/protocol_common_basic.h"
28 #include "tests/src/protocol_common.h"
29 
fill_tdb_data_nonnull(TALLOC_CTX * mem_ctx,TDB_DATA * p)30 void fill_tdb_data_nonnull(TALLOC_CTX *mem_ctx, TDB_DATA *p)
31 {
32 	p->dsize = rand_int(1024) + 1;
33 	p->dptr = talloc_array(mem_ctx, uint8_t, p->dsize);
34 	assert(p->dptr != NULL);
35 	fill_buffer(p->dptr, p->dsize);
36 }
37 
fill_tdb_data(TALLOC_CTX * mem_ctx,TDB_DATA * p)38 void fill_tdb_data(TALLOC_CTX *mem_ctx, TDB_DATA *p)
39 {
40 	if (rand_int(5) == 0) {
41 		p->dsize = 0;
42 		p->dptr = NULL;
43 	} else {
44 		fill_tdb_data_nonnull(mem_ctx, p);
45 	}
46 }
47 
verify_tdb_data(TDB_DATA * p1,TDB_DATA * p2)48 void verify_tdb_data(TDB_DATA *p1, TDB_DATA *p2)
49 {
50 	assert(p1->dsize == p2->dsize);
51 	verify_buffer(p1->dptr, p2->dptr, p1->dsize);
52 }
53 
fill_ctdb_tdb_data(TALLOC_CTX * mem_ctx,TDB_DATA * p)54 void fill_ctdb_tdb_data(TALLOC_CTX *mem_ctx, TDB_DATA *p)
55 {
56 	fill_tdb_data(mem_ctx, p);
57 }
58 
verify_ctdb_tdb_data(TDB_DATA * p1,TDB_DATA * p2)59 void verify_ctdb_tdb_data(TDB_DATA *p1, TDB_DATA *p2)
60 {
61 	verify_tdb_data(p1, p2);
62 }
63 
fill_ctdb_tdb_datan(TALLOC_CTX * mem_ctx,TDB_DATA * p)64 void fill_ctdb_tdb_datan(TALLOC_CTX *mem_ctx, TDB_DATA *p)
65 {
66 	fill_tdb_data(mem_ctx, p);
67 }
68 
verify_ctdb_tdb_datan(TDB_DATA * p1,TDB_DATA * p2)69 void verify_ctdb_tdb_datan(TDB_DATA *p1, TDB_DATA *p2)
70 {
71 	verify_tdb_data(p1, p2);
72 }
73 
fill_ctdb_latency_counter(struct ctdb_latency_counter * p)74 void fill_ctdb_latency_counter(struct ctdb_latency_counter *p)
75 {
76 	p->num = rand32i();
77 	p->min = rand_double();
78 	p->max = rand_double();
79 	p->total = rand_double();
80 }
81 
verify_ctdb_latency_counter(struct ctdb_latency_counter * p1,struct ctdb_latency_counter * p2)82 void verify_ctdb_latency_counter(struct ctdb_latency_counter *p1,
83 				 struct ctdb_latency_counter *p2)
84 {
85 	assert(p1->num == p2->num);
86 	assert(p1->min == p2->min);
87 	assert(p1->max == p2->max);
88 	assert(p1->total == p2->total);
89 }
90 
fill_ctdb_statistics(TALLOC_CTX * mem_ctx,struct ctdb_statistics * p)91 void fill_ctdb_statistics(TALLOC_CTX *mem_ctx, struct ctdb_statistics *p)
92 {
93 	int i;
94 
95 	p->num_clients = rand32();
96 	p->frozen = rand32();
97 	p->recovering = rand32();
98 	p->client_packets_sent = rand32();
99 	p->client_packets_recv = rand32();
100 	p->node_packets_sent = rand32();
101 	p->node_packets_recv = rand32();
102 	p->keepalive_packets_sent = rand32();
103 	p->keepalive_packets_recv = rand32();
104 
105 	p->node.req_call = rand32();
106 	p->node.reply_call = rand32();
107 	p->node.req_dmaster = rand32();
108 	p->node.reply_dmaster = rand32();
109 	p->node.reply_error = rand32();
110 	p->node.req_message = rand32();
111 	p->node.req_control = rand32();
112 	p->node.reply_control = rand32();
113 
114 	p->client.req_call = rand32();
115 	p->client.req_message = rand32();
116 	p->client.req_control = rand32();
117 
118 	p->timeouts.call = rand32();
119 	p->timeouts.control = rand32();
120 	p->timeouts.traverse = rand32();
121 
122 	fill_ctdb_latency_counter(&p->reclock.ctdbd);
123 	fill_ctdb_latency_counter(&p->reclock.recd);
124 
125 	p->locks.num_calls = rand32();
126 	p->locks.num_current = rand32();
127 	p->locks.num_pending = rand32();
128 	p->locks.num_failed = rand32();
129 	fill_ctdb_latency_counter(&p->locks.latency);
130 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
131 		p->locks.buckets[i] = rand32();
132 	}
133 
134 	p->total_calls = rand32();
135 	p->pending_calls = rand32();
136 	p->childwrite_calls = rand32();
137 	p->pending_childwrite_calls = rand32();
138 	p->memory_used = rand32();
139 	p->__last_counter = rand32();
140 	p->max_hop_count = rand32();
141 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
142 		p->hop_count_bucket[i] = rand32();
143 	}
144 	fill_ctdb_latency_counter(&p->call_latency);
145 	fill_ctdb_latency_counter(&p->childwrite_latency);
146 	p->num_recoveries = rand32();
147 	fill_ctdb_timeval(&p->statistics_start_time);
148 	fill_ctdb_timeval(&p->statistics_current_time);
149 	p->total_ro_delegations = rand32();
150 	p->total_ro_revokes = rand32();
151 }
152 
verify_ctdb_statistics(struct ctdb_statistics * p1,struct ctdb_statistics * p2)153 void verify_ctdb_statistics(struct ctdb_statistics *p1,
154 			    struct ctdb_statistics *p2)
155 {
156 	int i;
157 
158 	assert(p1->num_clients == p2->num_clients);
159 	assert(p1->frozen == p2->frozen);
160 	assert(p1->recovering == p2->recovering);
161 	assert(p1->client_packets_sent == p2->client_packets_sent);
162 	assert(p1->client_packets_recv == p2->client_packets_recv);
163 	assert(p1->node_packets_sent == p2->node_packets_sent);
164 	assert(p1->node_packets_recv == p2->node_packets_recv);
165 	assert(p1->keepalive_packets_sent == p2->keepalive_packets_sent);
166 	assert(p1->keepalive_packets_recv == p2->keepalive_packets_recv);
167 
168 	assert(p1->node.req_call == p2->node.req_call);
169 	assert(p1->node.reply_call == p2->node.reply_call);
170 	assert(p1->node.req_dmaster == p2->node.req_dmaster);
171 	assert(p1->node.reply_dmaster == p2->node.reply_dmaster);
172 	assert(p1->node.reply_error == p2->node.reply_error);
173 	assert(p1->node.req_message == p2->node.req_message);
174 	assert(p1->node.req_control == p2->node.req_control);
175 	assert(p1->node.reply_control == p2->node.reply_control);
176 
177 	assert(p1->client.req_call == p2->client.req_call);
178 	assert(p1->client.req_message == p2->client.req_message);
179 	assert(p1->client.req_control == p2->client.req_control);
180 
181 	assert(p1->timeouts.call == p2->timeouts.call);
182 	assert(p1->timeouts.control == p2->timeouts.control);
183 	assert(p1->timeouts.traverse == p2->timeouts.traverse);
184 
185 	verify_ctdb_latency_counter(&p1->reclock.ctdbd, &p2->reclock.ctdbd);
186 	verify_ctdb_latency_counter(&p1->reclock.recd, &p2->reclock.recd);
187 
188 	assert(p1->locks.num_calls == p2->locks.num_calls);
189 	assert(p1->locks.num_current == p2->locks.num_current);
190 	assert(p1->locks.num_pending == p2->locks.num_pending);
191 	assert(p1->locks.num_failed == p2->locks.num_failed);
192 	verify_ctdb_latency_counter(&p1->locks.latency, &p2->locks.latency);
193 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
194 		assert(p1->locks.buckets[i] == p2->locks.buckets[i]);
195 	}
196 
197 	assert(p1->total_calls == p2->total_calls);
198 	assert(p1->pending_calls == p2->pending_calls);
199 	assert(p1->childwrite_calls == p2->childwrite_calls);
200 	assert(p1->pending_childwrite_calls == p2->pending_childwrite_calls);
201 	assert(p1->memory_used == p2->memory_used);
202 	assert(p1->__last_counter == p2->__last_counter);
203 	assert(p1->max_hop_count == p2->max_hop_count);
204 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
205 		assert(p1->hop_count_bucket[i] == p2->hop_count_bucket[i]);
206 	}
207 	verify_ctdb_latency_counter(&p1->call_latency, &p2->call_latency);
208 	verify_ctdb_latency_counter(&p1->childwrite_latency,
209 				    &p2->childwrite_latency);
210 	assert(p1->num_recoveries == p2->num_recoveries);
211 	verify_ctdb_timeval(&p1->statistics_start_time,
212 			    &p2->statistics_start_time);
213 	verify_ctdb_timeval(&p1->statistics_current_time,
214 			    &p2->statistics_current_time);
215 	assert(p1->total_ro_delegations == p2->total_ro_delegations);
216 	assert(p1->total_ro_revokes == p2->total_ro_revokes);
217 }
218 
fill_ctdb_vnn_map(TALLOC_CTX * mem_ctx,struct ctdb_vnn_map * p)219 void fill_ctdb_vnn_map(TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *p)
220 {
221 	unsigned int i;
222 
223 	p->generation = rand32();
224 	p->size = rand_int(20);
225 	if (p->size > 0) {
226 		p->map = talloc_array(mem_ctx, uint32_t, p->size);
227 		assert(p->map != NULL);
228 
229 		for (i=0; i<p->size; i++) {
230 			p->map[i] = rand32();
231 		}
232 	} else {
233 		p->map = NULL;
234 	}
235 }
236 
verify_ctdb_vnn_map(struct ctdb_vnn_map * p1,struct ctdb_vnn_map * p2)237 void verify_ctdb_vnn_map(struct ctdb_vnn_map *p1, struct ctdb_vnn_map *p2)
238 {
239 	unsigned int i;
240 
241 	assert(p1->generation == p2->generation);
242 	assert(p1->size == p2->size);
243 	for (i=0; i<p1->size; i++) {
244 		assert(p1->map[i] == p2->map[i]);
245 	}
246 }
247 
fill_ctdb_dbid(TALLOC_CTX * mem_ctx,struct ctdb_dbid * p)248 void fill_ctdb_dbid(TALLOC_CTX *mem_ctx, struct ctdb_dbid *p)
249 {
250 	p->db_id = rand32();
251 	p->flags = rand8();
252 }
253 
verify_ctdb_dbid(struct ctdb_dbid * p1,struct ctdb_dbid * p2)254 void verify_ctdb_dbid(struct ctdb_dbid *p1, struct ctdb_dbid *p2)
255 {
256 	assert(p1->db_id == p2->db_id);
257 	assert(p1->flags == p2->flags);
258 }
259 
fill_ctdb_dbid_map(TALLOC_CTX * mem_ctx,struct ctdb_dbid_map * p)260 void fill_ctdb_dbid_map(TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *p)
261 {
262 	unsigned int i;
263 
264 	p->num = rand_int(40);
265 	if (p->num > 0) {
266 		p->dbs = talloc_zero_array(mem_ctx, struct ctdb_dbid, p->num);
267 		assert(p->dbs != NULL);
268 		for (i=0; i<p->num; i++) {
269 			fill_ctdb_dbid(mem_ctx, &p->dbs[i]);
270 		}
271 	} else {
272 		p->dbs = NULL;
273 	}
274 }
275 
verify_ctdb_dbid_map(struct ctdb_dbid_map * p1,struct ctdb_dbid_map * p2)276 void verify_ctdb_dbid_map(struct ctdb_dbid_map *p1, struct ctdb_dbid_map *p2)
277 {
278 	unsigned int i;
279 
280 	assert(p1->num == p2->num);
281 	for (i=0; i<p1->num; i++) {
282 		verify_ctdb_dbid(&p1->dbs[i], &p2->dbs[i]);
283 	}
284 }
285 
fill_ctdb_pulldb(TALLOC_CTX * mem_ctx,struct ctdb_pulldb * p)286 void fill_ctdb_pulldb(TALLOC_CTX *mem_ctx, struct ctdb_pulldb *p)
287 {
288 	p->db_id = rand32();
289 	p->lmaster = rand32();
290 }
291 
verify_ctdb_pulldb(struct ctdb_pulldb * p1,struct ctdb_pulldb * p2)292 void verify_ctdb_pulldb(struct ctdb_pulldb *p1, struct ctdb_pulldb *p2)
293 {
294 	assert(p1->db_id == p2->db_id);
295 	assert(p1->lmaster == p2->lmaster);
296 }
297 
fill_ctdb_pulldb_ext(TALLOC_CTX * mem_ctx,struct ctdb_pulldb_ext * p)298 void fill_ctdb_pulldb_ext(TALLOC_CTX *mem_ctx, struct ctdb_pulldb_ext *p)
299 {
300 	p->db_id = rand32();
301 	p->lmaster = rand32();
302 	p->srvid = rand64();
303 }
304 
verify_ctdb_pulldb_ext(struct ctdb_pulldb_ext * p1,struct ctdb_pulldb_ext * p2)305 void verify_ctdb_pulldb_ext(struct ctdb_pulldb_ext *p1,
306 			    struct ctdb_pulldb_ext *p2)
307 {
308 	assert(p1->db_id == p2->db_id);
309 	assert(p1->lmaster == p2->lmaster);
310 	assert(p1->srvid == p2->srvid);
311 }
312 
fill_ctdb_db_vacuum(TALLOC_CTX * mem_ctx,struct ctdb_db_vacuum * p)313 void fill_ctdb_db_vacuum(TALLOC_CTX *mem_ctx, struct ctdb_db_vacuum *p)
314 {
315 	fill_ctdb_uint32(&p->db_id);
316 	fill_ctdb_bool(&p->full_vacuum_run);
317 }
318 
verify_ctdb_db_vacuum(struct ctdb_db_vacuum * p1,struct ctdb_db_vacuum * p2)319 void verify_ctdb_db_vacuum(struct ctdb_db_vacuum *p1,
320 			    struct ctdb_db_vacuum *p2)
321 {
322 	verify_ctdb_uint32(&p1->db_id, &p2->db_id);
323 	verify_ctdb_bool(&p1->full_vacuum_run, &p2->full_vacuum_run);
324 }
325 
fill_ctdb_ltdb_header(struct ctdb_ltdb_header * p)326 void fill_ctdb_ltdb_header(struct ctdb_ltdb_header *p)
327 {
328 	p->rsn = rand64();
329 	p->dmaster = rand32();
330 	p->reserved1 = rand32();
331 	p->flags = rand32();
332 }
333 
verify_ctdb_ltdb_header(struct ctdb_ltdb_header * p1,struct ctdb_ltdb_header * p2)334 void verify_ctdb_ltdb_header(struct ctdb_ltdb_header *p1,
335 			     struct ctdb_ltdb_header *p2)
336 {
337 	assert(p1->rsn == p2->rsn);
338 	assert(p1->dmaster == p2->dmaster);
339 	assert(p1->reserved1 == p2->reserved1);
340 	assert(p1->flags == p2->flags);
341 }
342 
fill_ctdb_rec_data(TALLOC_CTX * mem_ctx,struct ctdb_rec_data * p)343 void fill_ctdb_rec_data(TALLOC_CTX *mem_ctx, struct ctdb_rec_data *p)
344 {
345 	p->reqid = rand32();
346 	if (p->reqid % 5 == 0) {
347 		p->header = talloc(mem_ctx, struct ctdb_ltdb_header);
348 		assert(p->header != NULL);
349 		fill_ctdb_ltdb_header(p->header);
350 	} else {
351 		p->header = NULL;
352 	}
353 	fill_tdb_data_nonnull(mem_ctx, &p->key);
354 	fill_tdb_data(mem_ctx, &p->data);
355 }
356 
verify_ctdb_rec_data(struct ctdb_rec_data * p1,struct ctdb_rec_data * p2)357 void verify_ctdb_rec_data(struct ctdb_rec_data *p1, struct ctdb_rec_data *p2)
358 {
359 	struct ctdb_ltdb_header header;
360 
361 	assert(p1->reqid == p2->reqid);
362 	if (p1->header != NULL) {
363 		assert(ctdb_ltdb_header_extract(&p2->data, &header) == 0);
364 		verify_ctdb_ltdb_header(p1->header, &header);
365 	}
366 	verify_tdb_data(&p1->key, &p2->key);
367 	verify_tdb_data(&p1->data, &p2->data);
368 }
369 
fill_ctdb_rec_buffer(TALLOC_CTX * mem_ctx,struct ctdb_rec_buffer * p)370 void fill_ctdb_rec_buffer(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *p)
371 {
372 	struct ctdb_rec_data rec;
373 	int ret, i;
374 	int count;
375 
376 	p->db_id = rand32();
377 	p->count = 0;
378 	p->buf = NULL;
379 	p->buflen = 0;
380 
381 	count = rand_int(100);
382 	if (count > 0) {
383 		for (i=0; i<count; i++) {
384 			fill_ctdb_rec_data(mem_ctx, &rec);
385 			ret = ctdb_rec_buffer_add(mem_ctx, p, rec.reqid,
386 						  rec.header,
387 						  rec.key, rec.data);
388 			assert(ret == 0);
389 		}
390 	}
391 }
392 
verify_ctdb_rec_buffer(struct ctdb_rec_buffer * p1,struct ctdb_rec_buffer * p2)393 void verify_ctdb_rec_buffer(struct ctdb_rec_buffer *p1,
394 			    struct ctdb_rec_buffer *p2)
395 {
396 	assert(p1->db_id == p2->db_id);
397 	assert(p1->count == p2->count);
398 	assert(p1->buflen == p2->buflen);
399 	verify_buffer(p1->buf, p2->buf, p1->buflen);
400 }
401 
fill_ctdb_traverse_start(TALLOC_CTX * mem_ctx,struct ctdb_traverse_start * p)402 void fill_ctdb_traverse_start(TALLOC_CTX *mem_ctx,
403 			      struct ctdb_traverse_start *p)
404 {
405 	p->db_id = rand32();
406 	p->reqid = rand32();
407 	p->srvid = rand64();
408 }
409 
verify_ctdb_traverse_start(struct ctdb_traverse_start * p1,struct ctdb_traverse_start * p2)410 void verify_ctdb_traverse_start(struct ctdb_traverse_start *p1,
411 				struct ctdb_traverse_start *p2)
412 {
413 	assert(p1->db_id == p2->db_id);
414 	assert(p1->reqid == p2->reqid);
415 	assert(p1->srvid == p2->srvid);
416 }
417 
fill_ctdb_traverse_all(TALLOC_CTX * mem_ctx,struct ctdb_traverse_all * p)418 void fill_ctdb_traverse_all(TALLOC_CTX *mem_ctx,
419 			    struct ctdb_traverse_all *p)
420 {
421 	p->db_id = rand32();
422 	p->reqid = rand32();
423 	p->pnn = rand32();
424 	p->client_reqid = rand32();
425 	p->srvid = rand64();
426 }
427 
verify_ctdb_traverse_all(struct ctdb_traverse_all * p1,struct ctdb_traverse_all * p2)428 void verify_ctdb_traverse_all(struct ctdb_traverse_all *p1,
429 			      struct ctdb_traverse_all *p2)
430 {
431 	assert(p1->db_id == p2->db_id);
432 	assert(p1->reqid == p2->reqid);
433 	assert(p1->pnn == p2->pnn);
434 	assert(p1->client_reqid == p2->client_reqid);
435 	assert(p1->srvid == p2->srvid);
436 }
437 
fill_ctdb_traverse_start_ext(TALLOC_CTX * mem_ctx,struct ctdb_traverse_start_ext * p)438 void fill_ctdb_traverse_start_ext(TALLOC_CTX *mem_ctx,
439 				  struct ctdb_traverse_start_ext *p)
440 {
441 	p->db_id = rand32();
442 	p->reqid = rand32();
443 	p->srvid = rand64();
444 	p->withemptyrecords = rand_int(2);
445 }
446 
verify_ctdb_traverse_start_ext(struct ctdb_traverse_start_ext * p1,struct ctdb_traverse_start_ext * p2)447 void verify_ctdb_traverse_start_ext(struct ctdb_traverse_start_ext *p1,
448 				    struct ctdb_traverse_start_ext *p2)
449 {
450 	assert(p1->db_id == p2->db_id);
451 	assert(p1->reqid == p2->reqid);
452 	assert(p1->srvid == p2->srvid);
453 	assert(p1->withemptyrecords == p2->withemptyrecords);
454 }
455 
fill_ctdb_traverse_all_ext(TALLOC_CTX * mem_ctx,struct ctdb_traverse_all_ext * p)456 void fill_ctdb_traverse_all_ext(TALLOC_CTX *mem_ctx,
457 				struct ctdb_traverse_all_ext *p)
458 {
459 	p->db_id = rand32();
460 	p->reqid = rand32();
461 	p->pnn = rand32();
462 	p->client_reqid = rand32();
463 	p->srvid = rand64();
464 	p->withemptyrecords = rand_int(2);
465 }
466 
verify_ctdb_traverse_all_ext(struct ctdb_traverse_all_ext * p1,struct ctdb_traverse_all_ext * p2)467 void verify_ctdb_traverse_all_ext(struct ctdb_traverse_all_ext *p1,
468 				  struct ctdb_traverse_all_ext *p2)
469 {
470 	assert(p1->db_id == p2->db_id);
471 	assert(p1->reqid == p2->reqid);
472 	assert(p1->pnn == p2->pnn);
473 	assert(p1->client_reqid == p2->client_reqid);
474 	assert(p1->srvid == p2->srvid);
475 	assert(p1->withemptyrecords == p2->withemptyrecords);
476 }
477 
fill_ctdb_sock_addr(TALLOC_CTX * mem_ctx,ctdb_sock_addr * p)478 void fill_ctdb_sock_addr(TALLOC_CTX *mem_ctx, ctdb_sock_addr *p)
479 {
480 	if (rand_int(2) == 0) {
481 		p->ip.sin_family = AF_INET;
482 		p->ip.sin_port = rand_int(65535);
483 		fill_buffer(&p->ip.sin_addr, sizeof(struct in_addr));
484 	} else {
485 		p->ip6.sin6_family = AF_INET6;
486 		p->ip6.sin6_port = rand_int(65535);
487 		fill_buffer(&p->ip6.sin6_addr, sizeof(struct in6_addr));
488 	}
489 }
490 
verify_ctdb_sock_addr(ctdb_sock_addr * p1,ctdb_sock_addr * p2)491 void verify_ctdb_sock_addr(ctdb_sock_addr *p1, ctdb_sock_addr *p2)
492 {
493 	assert(p1->sa.sa_family == p2->sa.sa_family);
494 	if (p1->sa.sa_family == AF_INET) {
495 		assert(p1->ip.sin_port == p2->ip.sin_port);
496 		verify_buffer(&p1->ip.sin_addr, &p2->ip.sin_addr,
497 				   sizeof(struct in_addr));
498 	} else {
499 		assert(p1->ip6.sin6_port == p2->ip6.sin6_port);
500 		verify_buffer(&p1->ip6.sin6_addr, &p2->ip6.sin6_addr,
501 				   sizeof(struct in6_addr));
502 	}
503 }
504 
fill_ctdb_connection(TALLOC_CTX * mem_ctx,struct ctdb_connection * p)505 void fill_ctdb_connection(TALLOC_CTX *mem_ctx, struct ctdb_connection *p)
506 {
507 	fill_ctdb_sock_addr(mem_ctx, &p->src);
508 	fill_ctdb_sock_addr(mem_ctx, &p->dst);
509 }
510 
verify_ctdb_connection(struct ctdb_connection * p1,struct ctdb_connection * p2)511 void verify_ctdb_connection(struct ctdb_connection *p1,
512 			    struct ctdb_connection *p2)
513 {
514 	verify_ctdb_sock_addr(&p1->src, &p2->src);
515 	verify_ctdb_sock_addr(&p1->dst, &p2->dst);
516 }
517 
fill_ctdb_connection_list(TALLOC_CTX * mem_ctx,struct ctdb_connection_list * p)518 void fill_ctdb_connection_list(TALLOC_CTX *mem_ctx,
519 			       struct ctdb_connection_list *p)
520 {
521 	uint32_t i;
522 
523 	p->num = rand_int(1000);
524 	if (p->num > 0) {
525 		p->conn = talloc_array(mem_ctx, struct ctdb_connection, p->num);
526 		assert(p->conn != NULL);
527 		for (i=0; i<p->num; i++) {
528 			fill_ctdb_connection(mem_ctx, &p->conn[i]);
529 		}
530 	} else {
531 		p->conn = NULL;
532 	}
533 }
534 
verify_ctdb_connection_list(struct ctdb_connection_list * p1,struct ctdb_connection_list * p2)535 void verify_ctdb_connection_list(struct ctdb_connection_list *p1,
536 				 struct ctdb_connection_list *p2)
537 {
538 	uint32_t i;
539 
540 	assert(p1->num == p2->num);
541 	for (i=0; i<p1->num; i++) {
542 		verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
543 	}
544 }
545 
fill_ctdb_tunable(TALLOC_CTX * mem_ctx,struct ctdb_tunable * p)546 void fill_ctdb_tunable(TALLOC_CTX *mem_ctx, struct ctdb_tunable *p)
547 {
548 	fill_ctdb_string(mem_ctx, &p->name);
549 	p->value = rand32();
550 }
551 
verify_ctdb_tunable(struct ctdb_tunable * p1,struct ctdb_tunable * p2)552 void verify_ctdb_tunable(struct ctdb_tunable *p1, struct ctdb_tunable *p2)
553 {
554 	verify_ctdb_string(&p1->name, &p2->name);
555 	assert(p1->value == p2->value);
556 }
557 
fill_ctdb_node_flag_change(TALLOC_CTX * mem_ctx,struct ctdb_node_flag_change * p)558 void fill_ctdb_node_flag_change(TALLOC_CTX *mem_ctx,
559 				struct ctdb_node_flag_change *p)
560 {
561 	p->pnn = rand32();
562 	p->new_flags = rand32();
563 	p->old_flags = rand32();
564 }
565 
verify_ctdb_node_flag_change(struct ctdb_node_flag_change * p1,struct ctdb_node_flag_change * p2)566 void verify_ctdb_node_flag_change(struct ctdb_node_flag_change *p1,
567 				  struct ctdb_node_flag_change *p2)
568 {
569 	assert(p1->pnn == p2->pnn);
570 	assert(p1->new_flags == p2->new_flags);
571 	assert(p1->old_flags == p2->old_flags);
572 }
573 
fill_ctdb_var_list(TALLOC_CTX * mem_ctx,struct ctdb_var_list * p)574 void fill_ctdb_var_list(TALLOC_CTX *mem_ctx, struct ctdb_var_list *p)
575 {
576 	int i;
577 
578 	p->count = rand_int(100) + 1;
579 	p->var = talloc_array(mem_ctx, const char *, p->count);
580 	for (i=0; i<p->count; i++) {
581 		fill_ctdb_string(p->var, &p->var[i]);
582 	}
583 }
584 
verify_ctdb_var_list(struct ctdb_var_list * p1,struct ctdb_var_list * p2)585 void verify_ctdb_var_list(struct ctdb_var_list *p1, struct ctdb_var_list *p2)
586 {
587 	int i;
588 
589 	assert(p1->count == p2->count);
590 	for (i=0; i<p1->count; i++) {
591 		verify_ctdb_string(&p1->var[i], &p2->var[i]);
592 	}
593 }
594 
fill_ctdb_tunable_list(TALLOC_CTX * mem_ctx,struct ctdb_tunable_list * p)595 void fill_ctdb_tunable_list(TALLOC_CTX *mem_ctx, struct ctdb_tunable_list *p)
596 {
597 	p->max_redirect_count = rand32();
598 	p->seqnum_interval = rand32();
599 	p->control_timeout = rand32();
600 	p->traverse_timeout = rand32();
601 	p->keepalive_interval = rand32();
602 	p->keepalive_limit = rand32();
603 	p->recover_timeout = rand32();
604 	p->recover_interval = rand32();
605 	p->election_timeout = rand32();
606 	p->takeover_timeout = rand32();
607 	p->monitor_interval = rand32();
608 	p->tickle_update_interval = rand32();
609 	p->script_timeout = rand32();
610 	p->monitor_timeout_count = rand32();
611 	p->script_unhealthy_on_timeout = rand32();
612 	p->recovery_grace_period = rand32();
613 	p->recovery_ban_period = rand32();
614 	p->database_hash_size = rand32();
615 	p->database_max_dead = rand32();
616 	p->rerecovery_timeout = rand32();
617 	p->enable_bans = rand32();
618 	p->deterministic_public_ips = rand32();
619 	p->reclock_ping_period = rand32();
620 	p->no_ip_failback = rand32();
621 	p->disable_ip_failover = rand32();
622 	p->verbose_memory_names = rand32();
623 	p->recd_ping_timeout = rand32();
624 	p->recd_ping_failcount = rand32();
625 	p->log_latency_ms = rand32();
626 	p->reclock_latency_ms = rand32();
627 	p->recovery_drop_all_ips = rand32();
628 	p->verify_recovery_lock = rand32();
629 	p->vacuum_interval = rand32();
630 	p->vacuum_max_run_time = rand32();
631 	p->repack_limit = rand32();
632 	p->vacuum_limit = rand32();
633 	p->max_queue_depth_drop_msg = rand32();
634 	p->allow_unhealthy_db_read = rand32();
635 	p->stat_history_interval = rand32();
636 	p->deferred_attach_timeout = rand32();
637 	p->vacuum_fast_path_count = rand32();
638 	p->lcp2_public_ip_assignment = rand32();
639 	p->allow_client_db_attach = rand32();
640 	p->recover_pdb_by_seqnum = rand32();
641 	p->deferred_rebalance_on_node_add = rand32();
642 	p->fetch_collapse = rand32();
643 	p->hopcount_make_sticky = rand32();
644 	p->sticky_duration = rand32();
645 	p->sticky_pindown = rand32();
646 	p->no_ip_takeover = rand32();
647 	p->db_record_count_warn = rand32();
648 	p->db_record_size_warn = rand32();
649 	p->db_size_warn = rand32();
650 	p->pulldb_preallocation_size = rand32();
651 	p->no_ip_host_on_all_disabled = rand32();
652 	p->samba3_hack = rand32();
653 	p->mutex_enabled = rand32();
654 	p->lock_processes_per_db = rand32();
655 	p->rec_buffer_size_limit = rand32();
656 	p->queue_buffer_size = rand32();
657 	p->ip_alloc_algorithm = rand32();
658 	p->allow_mixed_versions = rand32();
659 }
660 
verify_ctdb_tunable_list(struct ctdb_tunable_list * p1,struct ctdb_tunable_list * p2)661 void verify_ctdb_tunable_list(struct ctdb_tunable_list *p1,
662 			      struct ctdb_tunable_list *p2)
663 {
664 	assert(p1->max_redirect_count == p2->max_redirect_count);
665 	assert(p1->seqnum_interval == p2->seqnum_interval);
666 	assert(p1->control_timeout == p2->control_timeout);
667 	assert(p1->traverse_timeout == p2->traverse_timeout);
668 	assert(p1->keepalive_interval == p2->keepalive_interval);
669 	assert(p1->keepalive_limit == p2->keepalive_limit);
670 	assert(p1->recover_timeout == p2->recover_timeout);
671 	assert(p1->recover_interval == p2->recover_interval);
672 	assert(p1->election_timeout == p2->election_timeout);
673 	assert(p1->takeover_timeout == p2->takeover_timeout);
674 	assert(p1->monitor_interval == p2->monitor_interval);
675 	assert(p1->tickle_update_interval == p2->tickle_update_interval);
676 	assert(p1->script_timeout == p2->script_timeout);
677 	assert(p1->monitor_timeout_count == p2->monitor_timeout_count);
678 	assert(p1->script_unhealthy_on_timeout == p2->script_unhealthy_on_timeout);
679 	assert(p1->recovery_grace_period == p2->recovery_grace_period);
680 	assert(p1->recovery_ban_period == p2->recovery_ban_period);
681 	assert(p1->database_hash_size == p2->database_hash_size);
682 	assert(p1->database_max_dead == p2->database_max_dead);
683 	assert(p1->rerecovery_timeout == p2->rerecovery_timeout);
684 	assert(p1->enable_bans == p2->enable_bans);
685 	assert(p1->deterministic_public_ips == p2->deterministic_public_ips);
686 	assert(p1->reclock_ping_period == p2->reclock_ping_period);
687 	assert(p1->no_ip_failback == p2->no_ip_failback);
688 	assert(p1->disable_ip_failover == p2->disable_ip_failover);
689 	assert(p1->verbose_memory_names == p2->verbose_memory_names);
690 	assert(p1->recd_ping_timeout == p2->recd_ping_timeout);
691 	assert(p1->recd_ping_failcount == p2->recd_ping_failcount);
692 	assert(p1->log_latency_ms == p2->log_latency_ms);
693 	assert(p1->reclock_latency_ms == p2->reclock_latency_ms);
694 	assert(p1->recovery_drop_all_ips == p2->recovery_drop_all_ips);
695 	assert(p1->verify_recovery_lock == p2->verify_recovery_lock);
696 	assert(p1->vacuum_interval == p2->vacuum_interval);
697 	assert(p1->vacuum_max_run_time == p2->vacuum_max_run_time);
698 	assert(p1->repack_limit == p2->repack_limit);
699 	assert(p1->vacuum_limit == p2->vacuum_limit);
700 	assert(p1->max_queue_depth_drop_msg == p2->max_queue_depth_drop_msg);
701 	assert(p1->allow_unhealthy_db_read == p2->allow_unhealthy_db_read);
702 	assert(p1->stat_history_interval == p2->stat_history_interval);
703 	assert(p1->deferred_attach_timeout == p2->deferred_attach_timeout);
704 	assert(p1->vacuum_fast_path_count == p2->vacuum_fast_path_count);
705 	assert(p1->lcp2_public_ip_assignment == p2->lcp2_public_ip_assignment);
706 	assert(p1->allow_client_db_attach == p2->allow_client_db_attach);
707 	assert(p1->recover_pdb_by_seqnum == p2->recover_pdb_by_seqnum);
708 	assert(p1->deferred_rebalance_on_node_add == p2->deferred_rebalance_on_node_add);
709 	assert(p1->fetch_collapse == p2->fetch_collapse);
710 	assert(p1->hopcount_make_sticky == p2->hopcount_make_sticky);
711 	assert(p1->sticky_duration == p2->sticky_duration);
712 	assert(p1->sticky_pindown == p2->sticky_pindown);
713 	assert(p1->no_ip_takeover == p2->no_ip_takeover);
714 	assert(p1->db_record_count_warn == p2->db_record_count_warn);
715 	assert(p1->db_record_size_warn == p2->db_record_size_warn);
716 	assert(p1->db_size_warn == p2->db_size_warn);
717 	assert(p1->pulldb_preallocation_size == p2->pulldb_preallocation_size);
718 	assert(p1->no_ip_host_on_all_disabled == p2->no_ip_host_on_all_disabled);
719 	assert(p1->samba3_hack == p2->samba3_hack);
720 	assert(p1->mutex_enabled == p2->mutex_enabled);
721 	assert(p1->lock_processes_per_db == p2->lock_processes_per_db);
722 	assert(p1->rec_buffer_size_limit == p2->rec_buffer_size_limit);
723 	assert(p1->queue_buffer_size == p2->queue_buffer_size);
724 	assert(p1->ip_alloc_algorithm == p2->ip_alloc_algorithm);
725 	assert(p1->allow_mixed_versions == p2->allow_mixed_versions);
726 }
727 
fill_ctdb_tickle_list(TALLOC_CTX * mem_ctx,struct ctdb_tickle_list * p)728 void fill_ctdb_tickle_list(TALLOC_CTX *mem_ctx, struct ctdb_tickle_list *p)
729 {
730 	unsigned int i;
731 
732 	fill_ctdb_sock_addr(mem_ctx, &p->addr);
733 	p->num = rand_int(1000);
734 	if (p->num > 0) {
735 		p->conn = talloc_array(mem_ctx, struct ctdb_connection, p->num);
736 		assert(p->conn != NULL);
737 		for (i=0; i<p->num; i++) {
738 			fill_ctdb_connection(mem_ctx, &p->conn[i]);
739 		}
740 	} else {
741 		p->conn = NULL;
742 	}
743 }
744 
verify_ctdb_tickle_list(struct ctdb_tickle_list * p1,struct ctdb_tickle_list * p2)745 void verify_ctdb_tickle_list(struct ctdb_tickle_list *p1,
746 			     struct ctdb_tickle_list *p2)
747 {
748 	unsigned int i;
749 
750 	verify_ctdb_sock_addr(&p1->addr, &p2->addr);
751 	assert(p1->num == p2->num);
752 	for (i=0; i<p1->num; i++) {
753 		verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
754 	}
755 }
756 
fill_ctdb_addr_info(TALLOC_CTX * mem_ctx,struct ctdb_addr_info * p)757 void fill_ctdb_addr_info(TALLOC_CTX *mem_ctx, struct ctdb_addr_info *p)
758 {
759 	fill_ctdb_sock_addr(mem_ctx, &p->addr);
760 	p->mask = rand_int(33);
761 	if (rand_int(2) == 0) {
762 		p->iface = NULL;
763 	} else {
764 		fill_ctdb_string(mem_ctx, &p->iface);
765 	}
766 }
767 
verify_ctdb_addr_info(struct ctdb_addr_info * p1,struct ctdb_addr_info * p2)768 void verify_ctdb_addr_info(struct ctdb_addr_info *p1,
769 			   struct ctdb_addr_info *p2)
770 {
771 	verify_ctdb_sock_addr(&p1->addr, &p2->addr);
772 	assert(p1->mask == p2->mask);
773 	verify_ctdb_string(&p1->iface, &p2->iface);
774 }
775 
fill_ctdb_transdb(TALLOC_CTX * mem_ctx,struct ctdb_transdb * p)776 void fill_ctdb_transdb(TALLOC_CTX *mem_ctx, struct ctdb_transdb *p)
777 {
778 	p->db_id = rand32();
779 	p->tid = rand32();
780 }
781 
verify_ctdb_transdb(struct ctdb_transdb * p1,struct ctdb_transdb * p2)782 void verify_ctdb_transdb(struct ctdb_transdb *p1, struct ctdb_transdb *p2)
783 {
784 	assert(p1->db_id == p2->db_id);
785 	assert(p1->tid == p2->tid);
786 }
787 
fill_ctdb_uptime(TALLOC_CTX * mem_ctx,struct ctdb_uptime * p)788 void fill_ctdb_uptime(TALLOC_CTX *mem_ctx, struct ctdb_uptime *p)
789 {
790 	fill_ctdb_timeval(&p->current_time);
791 	fill_ctdb_timeval(&p->ctdbd_start_time);
792 	fill_ctdb_timeval(&p->last_recovery_started);
793 	fill_ctdb_timeval(&p->last_recovery_finished);
794 }
795 
verify_ctdb_uptime(struct ctdb_uptime * p1,struct ctdb_uptime * p2)796 void verify_ctdb_uptime(struct ctdb_uptime *p1, struct ctdb_uptime *p2)
797 {
798 	verify_ctdb_timeval(&p1->current_time, &p2->current_time);
799 	verify_ctdb_timeval(&p1->ctdbd_start_time, &p2->ctdbd_start_time);
800 	verify_ctdb_timeval(&p1->last_recovery_started,
801 			    &p2->last_recovery_started);
802 	verify_ctdb_timeval(&p1->last_recovery_finished,
803 			    &p2->last_recovery_finished);
804 }
805 
fill_ctdb_public_ip(TALLOC_CTX * mem_ctx,struct ctdb_public_ip * p)806 void fill_ctdb_public_ip(TALLOC_CTX *mem_ctx, struct ctdb_public_ip *p)
807 {
808 	p->pnn = rand32();
809 	fill_ctdb_sock_addr(mem_ctx, &p->addr);
810 }
811 
verify_ctdb_public_ip(struct ctdb_public_ip * p1,struct ctdb_public_ip * p2)812 void verify_ctdb_public_ip(struct ctdb_public_ip *p1,
813 			   struct ctdb_public_ip *p2)
814 {
815 	assert(p1->pnn == p2->pnn);
816 	verify_ctdb_sock_addr(&p1->addr, &p2->addr);
817 }
818 
fill_ctdb_public_ip_list(TALLOC_CTX * mem_ctx,struct ctdb_public_ip_list * p)819 void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx,
820 			      struct ctdb_public_ip_list *p)
821 {
822 	unsigned int i;
823 
824 	p->num = rand_int(32);
825 	if (p->num > 0) {
826 		p->ip = talloc_array(mem_ctx, struct ctdb_public_ip, p->num);
827 		assert(p->ip != NULL);
828 		for (i=0; i<p->num; i++) {
829 			fill_ctdb_public_ip(mem_ctx, &p->ip[i]);
830 		}
831 	} else {
832 		p->ip = NULL;
833 	}
834 }
835 
verify_ctdb_public_ip_list(struct ctdb_public_ip_list * p1,struct ctdb_public_ip_list * p2)836 void verify_ctdb_public_ip_list(struct ctdb_public_ip_list *p1,
837 				struct ctdb_public_ip_list *p2)
838 {
839 	unsigned int i;
840 
841 	assert(p1->num == p2->num);
842 	for (i=0; i<p1->num; i++) {
843 		verify_ctdb_public_ip(&p1->ip[i], &p2->ip[i]);
844 	}
845 }
846 
fill_ctdb_node_and_flags(TALLOC_CTX * mem_ctx,struct ctdb_node_and_flags * p)847 void fill_ctdb_node_and_flags(TALLOC_CTX *mem_ctx,
848 			      struct ctdb_node_and_flags *p)
849 {
850 	p->pnn = rand32();
851 	p->flags = rand32();
852 	fill_ctdb_sock_addr(mem_ctx, &p->addr);
853 }
854 
verify_ctdb_node_and_flags(struct ctdb_node_and_flags * p1,struct ctdb_node_and_flags * p2)855 void verify_ctdb_node_and_flags(struct ctdb_node_and_flags *p1,
856 				struct ctdb_node_and_flags *p2)
857 {
858 	assert(p1->pnn == p2->pnn);
859 	assert(p1->flags == p2->flags);
860 	verify_ctdb_sock_addr(&p1->addr, &p2->addr);
861 }
862 
fill_ctdb_node_map(TALLOC_CTX * mem_ctx,struct ctdb_node_map * p)863 void fill_ctdb_node_map(TALLOC_CTX *mem_ctx, struct ctdb_node_map *p)
864 {
865 	unsigned int i;
866 
867 	p->num = rand_int(32);
868 	if (p->num > 0) {
869 		p->node = talloc_array(mem_ctx, struct ctdb_node_and_flags,
870 				       p->num);
871 		assert(p->node != NULL);
872 		for (i=0; i<p->num; i++) {
873 			fill_ctdb_node_and_flags(mem_ctx, &p->node[i]);
874 		}
875 	} else {
876 		p->node = NULL;
877 	}
878 }
879 
verify_ctdb_node_map(struct ctdb_node_map * p1,struct ctdb_node_map * p2)880 void verify_ctdb_node_map(struct ctdb_node_map *p1, struct ctdb_node_map *p2)
881 {
882 	unsigned int i;
883 
884 	assert(p1->num == p2->num);
885 	for (i=0; i<p1->num; i++) {
886 		verify_ctdb_node_and_flags(&p1->node[i], &p2->node[i]);
887 	}
888 }
889 
fill_ctdb_script(TALLOC_CTX * mem_ctx,struct ctdb_script * p)890 void fill_ctdb_script(TALLOC_CTX *mem_ctx, struct ctdb_script *p)
891 {
892 	fill_string(p->name, MAX_SCRIPT_NAME+1);
893 	fill_ctdb_timeval(&p->start);
894 	fill_ctdb_timeval(&p->finished);
895 	p->status = rand32i();
896 	fill_string(p->output, MAX_SCRIPT_OUTPUT+1);
897 }
898 
verify_ctdb_script(struct ctdb_script * p1,struct ctdb_script * p2)899 void verify_ctdb_script(struct ctdb_script *p1, struct ctdb_script *p2)
900 {
901 	verify_string(p1->name, p2->name);
902 	verify_ctdb_timeval(&p1->start, &p2->start);
903 	verify_ctdb_timeval(&p1->finished, &p2->finished);
904 	assert(p1->status == p2->status);
905 	verify_string(p1->output, p2->output);
906 }
907 
fill_ctdb_script_list(TALLOC_CTX * mem_ctx,struct ctdb_script_list * p)908 void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p)
909 {
910 	unsigned int i;
911 
912 	p->num_scripts = rand_int(32);
913 	if (p->num_scripts > 0) {
914 		p->script = talloc_zero_array(mem_ctx, struct ctdb_script,
915 					      p->num_scripts);
916 		assert(p->script != NULL);
917 		for (i=0; i<p->num_scripts; i++) {
918 			fill_ctdb_script(mem_ctx, &p->script[i]);
919 		}
920 	} else {
921 		p->script = NULL;
922 	}
923 }
924 
verify_ctdb_script_list(struct ctdb_script_list * p1,struct ctdb_script_list * p2)925 void verify_ctdb_script_list(struct ctdb_script_list *p1,
926 			     struct ctdb_script_list *p2)
927 {
928 	unsigned int i;
929 
930 	assert(p1->num_scripts == p2->num_scripts);
931 	for (i=0; i<p1->num_scripts; i++) {
932 		verify_ctdb_script(&p1->script[i], &p2->script[i]);
933 	}
934 }
935 
fill_ctdb_ban_state(TALLOC_CTX * mem_ctx,struct ctdb_ban_state * p)936 void fill_ctdb_ban_state(TALLOC_CTX *mem_ctx, struct ctdb_ban_state *p)
937 {
938 	p->pnn = rand32();
939 	p->time = rand32();
940 }
941 
verify_ctdb_ban_state(struct ctdb_ban_state * p1,struct ctdb_ban_state * p2)942 void verify_ctdb_ban_state(struct ctdb_ban_state *p1,
943 			   struct ctdb_ban_state *p2)
944 {
945 	assert(p1->pnn == p2->pnn);
946 	assert(p1->time == p2->time);
947 }
948 
fill_ctdb_notify_data(TALLOC_CTX * mem_ctx,struct ctdb_notify_data * p)949 void fill_ctdb_notify_data(TALLOC_CTX *mem_ctx, struct ctdb_notify_data *p)
950 {
951 	p->srvid = rand64();
952 	fill_tdb_data(mem_ctx, &p->data);
953 }
954 
verify_ctdb_notify_data(struct ctdb_notify_data * p1,struct ctdb_notify_data * p2)955 void verify_ctdb_notify_data(struct ctdb_notify_data *p1,
956 			     struct ctdb_notify_data *p2)
957 {
958 	assert(p1->srvid == p2->srvid);
959 	verify_tdb_data(&p1->data, &p2->data);
960 }
961 
fill_ctdb_iface(TALLOC_CTX * mem_ctx,struct ctdb_iface * p)962 void fill_ctdb_iface(TALLOC_CTX *mem_ctx, struct ctdb_iface *p)
963 {
964 	fill_string(p->name, CTDB_IFACE_SIZE+2);
965 	p->link_state = rand16();
966 	p->references = rand32();
967 }
968 
verify_ctdb_iface(struct ctdb_iface * p1,struct ctdb_iface * p2)969 void verify_ctdb_iface(struct ctdb_iface *p1, struct ctdb_iface *p2)
970 {
971 	verify_string(p1->name, p2->name);
972 	assert(p1->link_state == p2->link_state);
973 	assert(p1->references == p2->references);
974 }
975 
fill_ctdb_iface_list(TALLOC_CTX * mem_ctx,struct ctdb_iface_list * p)976 void fill_ctdb_iface_list(TALLOC_CTX *mem_ctx, struct ctdb_iface_list *p)
977 {
978 	unsigned int i;
979 
980 	p->num = rand_int(32);
981 	if (p->num > 0) {
982 		p->iface = talloc_array(mem_ctx, struct ctdb_iface, p->num);
983 		assert(p->iface != NULL);
984 		for (i=0; i<p->num; i++) {
985 			fill_ctdb_iface(mem_ctx, &p->iface[i]);
986 		}
987 	} else {
988 		p->iface = NULL;
989 	}
990 }
991 
verify_ctdb_iface_list(struct ctdb_iface_list * p1,struct ctdb_iface_list * p2)992 void verify_ctdb_iface_list(struct ctdb_iface_list *p1,
993 			    struct ctdb_iface_list *p2)
994 {
995 	unsigned int i;
996 
997 	assert(p1->num == p2->num);
998 	for (i=0; i<p1->num; i++) {
999 		verify_ctdb_iface(&p1->iface[i], &p2->iface[i]);
1000 	}
1001 }
1002 
fill_ctdb_public_ip_info(TALLOC_CTX * mem_ctx,struct ctdb_public_ip_info * p)1003 void fill_ctdb_public_ip_info(TALLOC_CTX *mem_ctx,
1004 			      struct ctdb_public_ip_info *p)
1005 {
1006 	fill_ctdb_public_ip(mem_ctx, &p->ip);
1007 	p->active_idx = rand_int(32) + 1;
1008 	p->ifaces = talloc(mem_ctx, struct ctdb_iface_list);
1009 	assert(p->ifaces != NULL);
1010 	fill_ctdb_iface_list(mem_ctx, p->ifaces);
1011 }
1012 
verify_ctdb_public_ip_info(struct ctdb_public_ip_info * p1,struct ctdb_public_ip_info * p2)1013 void verify_ctdb_public_ip_info(struct ctdb_public_ip_info *p1,
1014 				struct ctdb_public_ip_info *p2)
1015 {
1016 	verify_ctdb_public_ip(&p1->ip, &p2->ip);
1017 	assert(p1->active_idx == p2->active_idx);
1018 	verify_ctdb_iface_list(p1->ifaces, p2->ifaces);
1019 }
1020 
fill_ctdb_statistics_list(TALLOC_CTX * mem_ctx,struct ctdb_statistics_list * p)1021 void fill_ctdb_statistics_list(TALLOC_CTX *mem_ctx,
1022 			       struct ctdb_statistics_list *p)
1023 {
1024 	int i;
1025 
1026 	p->num = rand_int(10);
1027 	if (p->num > 0) {
1028 		p->stats = talloc_zero_array(mem_ctx, struct ctdb_statistics,
1029 					     p->num);
1030 		assert(p->stats != NULL);
1031 
1032 		for (i=0; i<p->num; i++) {
1033 			fill_ctdb_statistics(mem_ctx, &p->stats[i]);
1034 		}
1035 	} else {
1036 		p->stats = NULL;
1037 	}
1038 }
1039 
verify_ctdb_statistics_list(struct ctdb_statistics_list * p1,struct ctdb_statistics_list * p2)1040 void verify_ctdb_statistics_list(struct ctdb_statistics_list *p1,
1041 				 struct ctdb_statistics_list *p2)
1042 {
1043 	int i;
1044 
1045 	assert(p1->num == p2->num);
1046 	for (i=0; i<p1->num; i++) {
1047 		verify_ctdb_statistics(&p1->stats[i], &p2->stats[i]);
1048 	}
1049 }
1050 
fill_ctdb_key_data(TALLOC_CTX * mem_ctx,struct ctdb_key_data * p)1051 void fill_ctdb_key_data(TALLOC_CTX *mem_ctx, struct ctdb_key_data *p)
1052 {
1053 	p->db_id = rand32();
1054 	fill_ctdb_ltdb_header(&p->header);
1055 	fill_tdb_data_nonnull(mem_ctx, &p->key);
1056 }
1057 
verify_ctdb_key_data(struct ctdb_key_data * p1,struct ctdb_key_data * p2)1058 void verify_ctdb_key_data(struct ctdb_key_data *p1, struct ctdb_key_data *p2)
1059 {
1060 	assert(p1->db_id == p2->db_id);
1061 	verify_ctdb_ltdb_header(&p1->header, &p2->header);
1062 	verify_tdb_data(&p1->key, &p2->key);
1063 }
1064 
fill_ctdb_db_statistics(TALLOC_CTX * mem_ctx,struct ctdb_db_statistics * p)1065 void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx,
1066 			     struct ctdb_db_statistics *p)
1067 {
1068 	unsigned int i;
1069 
1070 	p->locks.num_calls = rand32();
1071 	p->locks.num_current = rand32();
1072 	p->locks.num_pending = rand32();
1073 	p->locks.num_failed = rand32();
1074 	fill_ctdb_latency_counter(&p->locks.latency);
1075 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1076 		p->locks.buckets[i] = rand32();
1077 	}
1078 
1079 	fill_ctdb_latency_counter(&p->vacuum.latency);
1080 
1081 	p->db_ro_delegations = rand32();
1082 	p->db_ro_revokes = rand32();
1083 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1084 		p->hop_count_bucket[i] = rand32();
1085 	}
1086 
1087 	p->num_hot_keys = MAX_HOT_KEYS;
1088 	for (i=0; i<p->num_hot_keys; i++) {
1089 		p->hot_keys[i].count = rand32();
1090 		fill_tdb_data(mem_ctx, &p->hot_keys[i].key);
1091 	}
1092 }
1093 
verify_ctdb_db_statistics(struct ctdb_db_statistics * p1,struct ctdb_db_statistics * p2)1094 void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1,
1095 			       struct ctdb_db_statistics *p2)
1096 {
1097 	unsigned int i;
1098 
1099 	assert(p1->locks.num_calls == p2->locks.num_calls);
1100 	assert(p1->locks.num_current == p2->locks.num_current);
1101 	assert(p1->locks.num_pending == p2->locks.num_pending);
1102 	assert(p1->locks.num_failed == p2->locks.num_failed);
1103 	verify_ctdb_latency_counter(&p1->locks.latency, &p2->locks.latency);
1104 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1105 		assert(p1->locks.buckets[i] == p2->locks.buckets[i]);
1106 	}
1107 
1108 	verify_ctdb_latency_counter(&p1->vacuum.latency, &p2->vacuum.latency);
1109 
1110 	assert(p1->db_ro_delegations == p2->db_ro_delegations);
1111 	assert(p1->db_ro_revokes == p2->db_ro_revokes);
1112 	for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1113 		assert(p1->hop_count_bucket[i] == p2->hop_count_bucket[i]);
1114 	}
1115 
1116 	assert(p1->num_hot_keys == p2->num_hot_keys);
1117 	for (i=0; i<p1->num_hot_keys; i++) {
1118 		assert(p1->hot_keys[i].count == p2->hot_keys[i].count);
1119 		verify_tdb_data(&p1->hot_keys[i].key, &p2->hot_keys[i].key);
1120 	}
1121 }
1122 
fill_ctdb_pid_srvid(TALLOC_CTX * mem_ctx,struct ctdb_pid_srvid * p)1123 void fill_ctdb_pid_srvid(TALLOC_CTX *mem_ctx, struct ctdb_pid_srvid *p)
1124 {
1125 	p->pid = rand32();
1126 	p->srvid = rand64();
1127 }
1128 
verify_ctdb_pid_srvid(struct ctdb_pid_srvid * p1,struct ctdb_pid_srvid * p2)1129 void verify_ctdb_pid_srvid(struct ctdb_pid_srvid *p1,
1130 			   struct ctdb_pid_srvid *p2)
1131 {
1132 	assert(p1->pid == p2->pid);
1133 	assert(p1->srvid == p2->srvid);
1134 }
1135 
fill_ctdb_election_message(TALLOC_CTX * mem_ctx,struct ctdb_election_message * p)1136 void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
1137 				struct ctdb_election_message *p)
1138 {
1139 	p->num_connected = rand_int(32);
1140 	fill_ctdb_timeval(&p->priority_time);
1141 	p->pnn = rand_int(32);
1142 	p->node_flags = rand32();
1143 }
1144 
verify_ctdb_election_message(struct ctdb_election_message * p1,struct ctdb_election_message * p2)1145 void verify_ctdb_election_message(struct ctdb_election_message *p1,
1146 				  struct ctdb_election_message *p2)
1147 {
1148 	assert(p1->num_connected == p2->num_connected);
1149 	verify_ctdb_timeval(&p1->priority_time, &p2->priority_time);
1150 	assert(p1->pnn == p2->pnn);
1151 	assert(p1->node_flags == p2->node_flags);
1152 }
1153 
fill_ctdb_srvid_message(TALLOC_CTX * mem_ctx,struct ctdb_srvid_message * p)1154 void fill_ctdb_srvid_message(TALLOC_CTX *mem_ctx,
1155 			     struct ctdb_srvid_message *p)
1156 {
1157 	p->pnn = rand_int(32);
1158 	p->srvid = rand64();
1159 }
1160 
verify_ctdb_srvid_message(struct ctdb_srvid_message * p1,struct ctdb_srvid_message * p2)1161 void verify_ctdb_srvid_message(struct ctdb_srvid_message *p1,
1162 			       struct ctdb_srvid_message *p2)
1163 {
1164 	assert(p1->pnn == p2->pnn);
1165 	assert(p1->srvid == p2->srvid);
1166 }
1167 
fill_ctdb_disable_message(TALLOC_CTX * mem_ctx,struct ctdb_disable_message * p)1168 void fill_ctdb_disable_message(TALLOC_CTX *mem_ctx,
1169 			       struct ctdb_disable_message *p)
1170 {
1171 	p->pnn = rand_int(32);
1172 	p->srvid = rand64();
1173 	p->timeout = rand32();
1174 }
1175 
verify_ctdb_disable_message(struct ctdb_disable_message * p1,struct ctdb_disable_message * p2)1176 void verify_ctdb_disable_message(struct ctdb_disable_message *p1,
1177 				 struct ctdb_disable_message *p2)
1178 {
1179 	assert(p1->pnn == p2->pnn);
1180 	assert(p1->srvid == p2->srvid);
1181 	assert(p1->timeout == p2->timeout);
1182 }
1183 
fill_ctdb_server_id(struct ctdb_server_id * p)1184 void fill_ctdb_server_id(struct ctdb_server_id *p)
1185 {
1186 	p->pid = rand64();
1187 	p->task_id = rand32();
1188 	p->vnn = rand_int(32);
1189 	p->unique_id = rand64();
1190 }
1191 
verify_ctdb_server_id(struct ctdb_server_id * p1,struct ctdb_server_id * p2)1192 void verify_ctdb_server_id(struct ctdb_server_id *p1,
1193 			   struct ctdb_server_id *p2)
1194 {
1195 	assert(p1->pid == p2->pid);
1196 	assert(p1->task_id == p2->task_id);
1197 	assert(p1->vnn == p2->vnn);
1198 	assert(p1->unique_id == p2->unique_id);
1199 }
1200 
fill_ctdb_g_lock(struct ctdb_g_lock * p)1201 void fill_ctdb_g_lock(struct ctdb_g_lock *p)
1202 {
1203 	p->type = rand_int(2);
1204 	fill_ctdb_server_id(&p->sid);
1205 }
1206 
verify_ctdb_g_lock(struct ctdb_g_lock * p1,struct ctdb_g_lock * p2)1207 void verify_ctdb_g_lock(struct ctdb_g_lock *p1, struct ctdb_g_lock *p2)
1208 {
1209 	assert(p1->type == p2->type);
1210 	verify_ctdb_server_id(&p1->sid, &p2->sid);
1211 }
1212 
fill_ctdb_g_lock_list(TALLOC_CTX * mem_ctx,struct ctdb_g_lock_list * p)1213 void fill_ctdb_g_lock_list(TALLOC_CTX *mem_ctx, struct ctdb_g_lock_list *p)
1214 {
1215 	unsigned int i;
1216 
1217 	p->num = rand_int(20) + 1;
1218 	p->lock = talloc_zero_array(mem_ctx, struct ctdb_g_lock, p->num);
1219 	assert(p->lock != NULL);
1220 	for (i=0; i<p->num; i++) {
1221 		fill_ctdb_g_lock(&p->lock[i]);
1222 	}
1223 }
1224 
verify_ctdb_g_lock_list(struct ctdb_g_lock_list * p1,struct ctdb_g_lock_list * p2)1225 void verify_ctdb_g_lock_list(struct ctdb_g_lock_list *p1,
1226 			     struct ctdb_g_lock_list *p2)
1227 {
1228 	unsigned int i;
1229 
1230 	assert(p1->num == p2->num);
1231 	for (i=0; i<p1->num; i++) {
1232 		verify_ctdb_g_lock(&p1->lock[i], &p2->lock[i]);
1233 	}
1234 }
1235 
fill_sock_packet_header(struct sock_packet_header * p)1236 void fill_sock_packet_header(struct sock_packet_header *p)
1237 {
1238 	p->length = rand32();
1239 	p->reqid = rand32();
1240 }
1241 
verify_sock_packet_header(struct sock_packet_header * p1,struct sock_packet_header * p2)1242 void verify_sock_packet_header(struct sock_packet_header *p1,
1243 			       struct sock_packet_header *p2)
1244 {
1245 	assert(p1->length == p2->length);
1246 	assert(p1->reqid == p2->reqid);
1247 }
1248