cpghum.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. * Copyright (c) 2015-2016 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield <ccaulfie@redhat.com>
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <signal.h>
  38. #include <unistd.h>
  39. #include <errno.h>
  40. #include <time.h>
  41. #include <limits.h>
  42. #include <sys/time.h>
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <sys/select.h>
  46. #include <sys/uio.h>
  47. #include <sys/un.h>
  48. #include <netinet/in.h>
  49. #include <arpa/inet.h>
  50. #include <pthread.h>
  51. #include <zlib.h>
  52. #include <libgen.h>
  53. #include <qb/qblog.h>
  54. #include <qb/qbutil.h>
  55. #include <corosync/corotypes.h>
  56. #include <corosync/cpg.h>
  57. static cpg_handle_t handle;
  58. static pthread_t thread;
  59. #ifndef timersub
  60. #define timersub(a, b, result) \
  61. do { \
  62. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  63. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  64. if ((result)->tv_usec < 0) { \
  65. --(result)->tv_sec; \
  66. (result)->tv_usec += 1000000; \
  67. } \
  68. } while (0)
  69. #endif /* timersub */
  70. static int alarm_notice;
  71. #define ONE_MEG 1048576
  72. #define DATASIZE (ONE_MEG*20)
  73. static char data[DATASIZE];
  74. static int send_counter = 0;
  75. static int do_syslog = 0;
  76. static int quiet = 0;
  77. static int report_rtt = 0;
  78. static int abort_on_error = 0;
  79. static unsigned int g_our_nodeid;
  80. static volatile int stopped;
  81. // stats
  82. static unsigned int length_errors=0;
  83. static unsigned int crc_errors=0;
  84. static unsigned int sequence_errors=0;
  85. static unsigned int packets_sent=0;
  86. static unsigned int packets_recvd=0;
  87. static unsigned int packets_recvd1=0; /* For flood intermediates */
  88. static unsigned int send_retries=0;
  89. static unsigned int send_fails=0;
  90. static unsigned long avg_rtt=0;
  91. static unsigned long max_rtt=0;
  92. static unsigned long min_rtt=LONG_MAX;
  93. struct cpghum_header {
  94. unsigned int counter;
  95. unsigned int crc;
  96. unsigned int size;
  97. struct timeval timestamp;
  98. };
  99. static void cpg_bm_confchg_fn (
  100. cpg_handle_t handle_in,
  101. const struct cpg_name *group_name,
  102. const struct cpg_address *member_list, size_t member_list_entries,
  103. const struct cpg_address *left_list, size_t left_list_entries,
  104. const struct cpg_address *joined_list, size_t joined_list_entries)
  105. {
  106. }
  107. static unsigned int g_recv_count;
  108. static unsigned int g_recv_length;
  109. static int g_recv_counter = 1;
  110. static int g_check_counter = 1;
  111. static void cpg_bm_deliver_fn (
  112. cpg_handle_t handle_in,
  113. const struct cpg_name *group_name,
  114. uint32_t nodeid,
  115. uint32_t pid,
  116. void *msg,
  117. size_t msg_len)
  118. {
  119. uLong crc=0;
  120. struct cpghum_header *header = (struct cpghum_header *)msg;
  121. uLong recv_crc = header->crc & 0xFFFFFFFF;
  122. unsigned int *dataint = (unsigned int *)((char*)msg + sizeof(struct cpghum_header));
  123. unsigned int datalen;
  124. packets_recvd++;
  125. packets_recvd1++;
  126. g_recv_length = msg_len;
  127. datalen = header->size - sizeof(struct cpghum_header);
  128. // Report RTT first in case abort_on_error is set
  129. if (nodeid == g_our_nodeid) {
  130. struct timeval tv1;
  131. struct timeval rtt;
  132. unsigned long rtt_usecs = rtt.tv_usec + rtt.tv_sec*1000000;
  133. gettimeofday (&tv1, NULL);
  134. timersub(&tv1, &header->timestamp, &rtt);
  135. rtt_usecs = rtt.tv_usec + rtt.tv_sec*1000000;
  136. if (rtt_usecs > max_rtt) {
  137. max_rtt = rtt_usecs;
  138. }
  139. if (rtt_usecs < min_rtt) {
  140. min_rtt = rtt_usecs;
  141. }
  142. avg_rtt = ((avg_rtt * g_recv_counter) + rtt_usecs) / (g_recv_counter+1);
  143. if (report_rtt) {
  144. fprintf(stderr, "%s: RTT %ld uS (min/avg/max): %ld/%ld/%ld\n", group_name->value, rtt_usecs, min_rtt, avg_rtt, max_rtt);
  145. if (do_syslog) {
  146. syslog(LOG_ERR, "%s: RTT %ld uS (min/avg/max): %ld/%ld/%ld\n", group_name->value, rtt_usecs, min_rtt, avg_rtt, max_rtt);
  147. }
  148. }
  149. }
  150. // Basic check, packets should all be the right size
  151. if (msg_len != header->size) {
  152. length_errors++;
  153. fprintf(stderr, "%s: message sizes don't match. got %zu, expected %u\n", group_name->value, msg_len, header->size);
  154. if (do_syslog) {
  155. syslog(LOG_ERR, "%s: message sizes don't match. got %zu, expected %u\n", group_name->value, msg_len, header->size);
  156. }
  157. if (abort_on_error) {
  158. exit(2);
  159. }
  160. }
  161. // Sequence counters are incrementing in step?
  162. if (g_check_counter && (header->counter != g_recv_counter)) {
  163. sequence_errors++;
  164. fprintf(stderr, "%s: counters don't match. got %d, expected %d\n", group_name->value, header->counter, g_recv_counter);
  165. if (do_syslog) {
  166. syslog(LOG_ERR, "%s: counters don't match. got %d, expected %d\n", group_name->value, header->counter, g_recv_counter);
  167. }
  168. if (abort_on_error) {
  169. exit(2);
  170. }
  171. // Catch up or we'll be printing errors for ever
  172. g_recv_counter = header->counter +1;
  173. }
  174. else {
  175. g_recv_counter++;
  176. }
  177. // Check crc
  178. crc = crc32(0, NULL, 0);
  179. crc = crc32(crc, (Bytef *)dataint, datalen) & 0xFFFFFFFF;
  180. if (crc != recv_crc) {
  181. crc_errors++;
  182. fprintf(stderr, "%s: CRCs don't match. got %lx, expected %lx\n", group_name->value, recv_crc, crc);
  183. if (do_syslog) {
  184. syslog(LOG_ERR, "%s: CRCs don't match. got %lx, expected %lx\n", group_name->value, recv_crc, crc);
  185. }
  186. if (abort_on_error) {
  187. exit(2);
  188. }
  189. }
  190. g_recv_count++;
  191. }
  192. static cpg_model_v1_data_t model1_data = {
  193. .cpg_deliver_fn = cpg_bm_deliver_fn,
  194. .cpg_confchg_fn = cpg_bm_confchg_fn,
  195. };
  196. static cpg_callbacks_t callbacks = {
  197. .cpg_deliver_fn = cpg_bm_deliver_fn,
  198. .cpg_confchg_fn = cpg_bm_confchg_fn
  199. };
  200. static struct cpg_name group_name = {
  201. .value = "cpghum",
  202. .length = 7
  203. };
  204. static void set_packet(int write_size, int counter)
  205. {
  206. struct cpghum_header *header = (struct cpghum_header *)data;
  207. int i;
  208. unsigned int *dataint = (unsigned int *)(data + sizeof(struct cpghum_header));
  209. unsigned int datalen = write_size - sizeof(struct cpghum_header);
  210. struct timeval tv1;
  211. uLong crc;
  212. header->counter = counter;
  213. for (i=0; i<(datalen/4); i++) {
  214. dataint[i] = rand();
  215. }
  216. crc = crc32(0, NULL, 0);
  217. header->crc = crc32(crc, (Bytef*)&dataint[0], datalen);
  218. header->size = write_size;
  219. gettimeofday (&tv1, NULL);
  220. memcpy(&header->timestamp, &tv1, sizeof(struct timeval));
  221. }
  222. static void cpg_flood (
  223. cpg_handle_t handle_in,
  224. int write_size)
  225. {
  226. struct timeval tv1, tv2, tv_elapsed;
  227. struct iovec iov;
  228. unsigned int res = CS_OK;
  229. alarm_notice = 0;
  230. iov.iov_base = data;
  231. iov.iov_len = write_size;
  232. alarm (10);
  233. packets_recvd1 = 0;
  234. gettimeofday (&tv1, NULL);
  235. do {
  236. /* Only increment the packet counter if it sucessfully sent */
  237. if (res != CS_ERR_TRY_AGAIN) {
  238. set_packet(write_size, send_counter++);
  239. }
  240. res = cpg_mcast_joined (handle_in, CPG_TYPE_AGREED, &iov, 1);
  241. if (res == CS_OK) {
  242. packets_sent++;
  243. }
  244. else {
  245. if (res == CS_ERR_TRY_AGAIN) {
  246. send_retries++;
  247. }
  248. else {
  249. send_fails++;
  250. }
  251. }
  252. } while (!stopped && alarm_notice == 0 && (res == CS_OK || res == CS_ERR_TRY_AGAIN));
  253. gettimeofday (&tv2, NULL);
  254. timersub (&tv2, &tv1, &tv_elapsed);
  255. if (!quiet) {
  256. printf ("%5d messages received ", packets_recvd1);
  257. printf ("%5d bytes per write ", write_size);
  258. printf ("%7.3f Seconds runtime ",
  259. (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  260. printf ("%9.3f TP/s ",
  261. ((float)packets_recvd1) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  262. printf ("%7.3f MB/s.\n",
  263. ((float)packets_recvd1) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
  264. }
  265. }
  266. static void cpg_test (
  267. cpg_handle_t handle_in,
  268. int write_size,
  269. int delay_time,
  270. int print_time)
  271. {
  272. struct timeval tv1, tv2, tv_elapsed;
  273. struct iovec iov;
  274. unsigned int res;
  275. alarm_notice = 0;
  276. iov.iov_base = data;
  277. iov.iov_len = write_size;
  278. g_recv_count = 0;
  279. alarm (print_time);
  280. do {
  281. send_counter++;
  282. resend:
  283. set_packet(write_size, send_counter);
  284. res = cpg_mcast_joined (handle_in, CPG_TYPE_AGREED, &iov, 1);
  285. if (res == CS_ERR_TRY_AGAIN) {
  286. usleep(10000);
  287. send_retries++;
  288. goto resend;
  289. }
  290. if (res != CS_OK) {
  291. fprintf(stderr, "send failed: %d\n", res);
  292. send_fails++;
  293. }
  294. else {
  295. packets_sent++;
  296. }
  297. usleep(delay_time*1000);
  298. } while (alarm_notice == 0 && (res == CS_OK || res == CS_ERR_TRY_AGAIN) && stopped == 0);
  299. gettimeofday (&tv2, NULL);
  300. timersub (&tv2, &tv1, &tv_elapsed);
  301. if (!quiet) {
  302. printf ("%s: %5d message%s received, ", group_name.value, g_recv_count, g_recv_count==1?"":"s");
  303. printf ("%5d bytes per write. ", write_size);
  304. printf ("RTT min/avg/max: %ld/%ld/%ld\n", min_rtt, avg_rtt, max_rtt);
  305. }
  306. }
  307. static void sigalrm_handler (int num)
  308. {
  309. alarm_notice = 1;
  310. }
  311. static void sigint_handler (int num)
  312. {
  313. stopped = 1;
  314. }
  315. static void* dispatch_thread (void *arg)
  316. {
  317. cpg_dispatch (handle, CS_DISPATCH_BLOCKING);
  318. return NULL;
  319. }
  320. static void usage(char *cmd)
  321. {
  322. fprintf(stderr, "%s [OPTIONS]\n", cmd);
  323. fprintf(stderr, "\n");
  324. fprintf(stderr, "%s sends CPG messages to all registered users of the CPG.\n", cmd);
  325. fprintf(stderr, "The messages have a sequence number and a CRC so that missing or\n");
  326. fprintf(stderr, "corrupted messages will be detected and reported.\n");
  327. fprintf(stderr, "\n");
  328. fprintf(stderr, "%s can also be asked to simply listen for (and check) packets\n", cmd);
  329. fprintf(stderr, "so that there is another node in the cluster connected to the CPG.\n");
  330. fprintf(stderr, "\n");
  331. fprintf(stderr, "Multiple copies, in different CPGs, can also be run on the same or\n");
  332. fprintf(stderr, "different nodes by using the -n option.\n");
  333. fprintf(stderr, "\n");
  334. fprintf(stderr, "%s can't handle more than 1 sender in the same CPG as it messes with the\n", cmd);
  335. fprintf(stderr, "sequence numbers.\n");
  336. fprintf(stderr, "\n");
  337. fprintf(stderr, " -w Write size in Kbytes, default 4\n");
  338. fprintf(stderr, " -W Write size in bytes, default 4096\n");
  339. fprintf(stderr, " -n CPG name to use, default 'cpghum'\n");
  340. fprintf(stderr, " -d Delay between sending packets (mS), default 1000\n");
  341. fprintf(stderr, " -r Number of repetitions, default 100\n");
  342. fprintf(stderr, " -p Delay between printing output(S), default 10s\n");
  343. fprintf(stderr, " -l Listen and check CRCs only, don't send (^C to quit)\n");
  344. fprintf(stderr, " -t Report Round Trip Times for each packet.\n");
  345. fprintf(stderr, " -m cpg_initialise() model. Default 1.\n");
  346. fprintf(stderr, " -s Also send errors to syslog (for daemon log correlation).\n");
  347. fprintf(stderr, " -f Flood test CPG (like cpgbench). -W defaults to 64 in this case.\n");
  348. fprintf(stderr, " -a Abort on crc/length/sequence error\n");
  349. fprintf(stderr, " -q Quiet. Don't print messages every 10 seconds (see also -p)\n");
  350. fprintf(stderr, " -qq Very quiet. Don't print stats at the end)\n");
  351. fprintf(stderr, "\n");
  352. fprintf(stderr, "%s exit code is 0 if no error happened, 1 on generic error and 2 on\n", cmd);
  353. fprintf(stderr, "send/crc/length/sequence error");
  354. fprintf(stderr, "\n");
  355. }
  356. int main (int argc, char *argv[]) {
  357. int i;
  358. unsigned int res;
  359. uint32_t maxsize;
  360. int opt;
  361. int bs;
  362. int write_size = 4096;
  363. int delay_time = 1000;
  364. int repetitions = 100;
  365. int print_time = 10;
  366. int have_size = 0;
  367. int listen_only = 0;
  368. int flood = 0;
  369. int model = 1;
  370. while ( (opt = getopt(argc, argv, "qlstafn:d:r:p:m:w:W:")) != -1 ) {
  371. switch (opt) {
  372. case 'w': // Write size in K
  373. bs = atoi(optarg);
  374. if (bs > 0) {
  375. write_size = bs*1024;
  376. have_size = 1;
  377. }
  378. break;
  379. case 'W': // Write size in bytes
  380. bs = atoi(optarg);
  381. if (bs > 0) {
  382. write_size = bs;
  383. have_size = 1;
  384. }
  385. break;
  386. case 'n':
  387. if (strlen(optarg) >= CPG_MAX_NAME_LENGTH) {
  388. fprintf(stderr, "CPG name too long\n");
  389. exit(1);
  390. }
  391. strcpy(group_name.value, optarg);
  392. group_name.length = strlen(group_name.value);
  393. break;
  394. case 't':
  395. report_rtt = 1;
  396. break;
  397. case 'f':
  398. flood = 1;
  399. g_check_counter = 0; /* packets can get 'lost' */
  400. break;
  401. case 'a':
  402. abort_on_error = 1;
  403. break;
  404. case 'd':
  405. delay_time = atoi(optarg);
  406. break;
  407. case 'r':
  408. repetitions = atoi(optarg);
  409. break;
  410. case 'p':
  411. print_time = atoi(optarg);
  412. break;
  413. case 'l':
  414. listen_only = 1;
  415. break;
  416. case 's':
  417. do_syslog = 1;
  418. break;
  419. case 'q':
  420. quiet++;
  421. break;
  422. case 'm':
  423. model = atoi(optarg);
  424. if (model < 0 || model > 1) {
  425. fprintf(stderr, "%s: Model must be 0-1\n", argv[0]);
  426. exit(1);
  427. }
  428. break;
  429. case '?':
  430. usage(basename(argv[0]));
  431. exit(1);
  432. }
  433. }
  434. if (!have_size && flood) {
  435. write_size = 64;
  436. }
  437. qb_log_init("cpghum", LOG_USER, LOG_EMERG);
  438. qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
  439. qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
  440. QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
  441. qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
  442. signal (SIGALRM, sigalrm_handler);
  443. signal (SIGINT, sigint_handler);
  444. switch (model) {
  445. case 0:
  446. res = cpg_initialize (&handle, &callbacks);
  447. break;
  448. case 1:
  449. res = cpg_model_initialize (&handle, CPG_MODEL_V1, (cpg_model_data_t *)&model1_data, NULL);
  450. break;
  451. default:
  452. res=999; // can't get here but it keeps the compiler happy
  453. break;
  454. }
  455. if (res != CS_OK) {
  456. printf ("cpg_initialize failed with result %d\n", res);
  457. exit (1);
  458. }
  459. cpg_local_get(handle, &g_our_nodeid);
  460. pthread_create (&thread, NULL, dispatch_thread, NULL);
  461. res = cpg_join (handle, &group_name);
  462. if (res != CS_OK) {
  463. printf ("cpg_join failed with result %d\n", res);
  464. exit (1);
  465. }
  466. if (listen_only) {
  467. int secs = 0;
  468. if (!quiet) {
  469. printf("-- Listening on CPG %s\n", group_name.value);
  470. printf("-- Ignore any starting \"counters don't match\" error while we catch up\n");
  471. }
  472. while (!stopped) {
  473. sleep(1);
  474. if (++secs > print_time && !quiet) {
  475. printf ("%s: %5d message%s received. %d bytes. RTT min/avg/max: %ld/%ld/%ld\n",
  476. group_name.value, g_recv_count, g_recv_count==1?"":"s", g_recv_length,
  477. min_rtt, avg_rtt, max_rtt);
  478. secs = 0;
  479. g_recv_count = 0;
  480. }
  481. }
  482. }
  483. else {
  484. cpg_max_atomic_msgsize_get (handle, &maxsize);
  485. if (write_size > maxsize) {
  486. fprintf(stderr, "INFO: packet size (%d) is larger than the maximum atomic size (%d), libcpg will fragment\n",
  487. write_size, maxsize);
  488. }
  489. if (flood) {
  490. for (i = 0; i < 10; i++) { /* number of repetitions - up to 50k */
  491. cpg_flood (handle, write_size);
  492. signal (SIGALRM, sigalrm_handler);
  493. write_size *= 5;
  494. if (write_size >= (ONE_MEG - 100)) {
  495. break;
  496. }
  497. }
  498. }
  499. else {
  500. for (i = 0; i < repetitions && !stopped; i++) {
  501. cpg_test (handle, write_size, delay_time, print_time);
  502. signal (SIGALRM, sigalrm_handler);
  503. }
  504. }
  505. }
  506. res = cpg_finalize (handle);
  507. if (res != CS_OK) {
  508. printf ("cpg_finalize failed with result %d\n", res);
  509. exit (1);
  510. }
  511. if (quiet < 2) {
  512. printf("\n");
  513. printf("Stats:\n");
  514. if (!listen_only) {
  515. printf(" packets sent: %d\n", packets_sent);
  516. printf(" send failures: %d\n", send_fails);
  517. printf(" send retries: %d\n", send_retries);
  518. }
  519. printf(" length errors: %d\n", length_errors);
  520. printf(" packets recvd: %d\n", packets_recvd);
  521. printf(" sequence errors: %d\n", sequence_errors);
  522. printf(" crc errors: %d\n", crc_errors);
  523. if (!listen_only) {
  524. printf(" min RTT: %ld\n", min_rtt);
  525. printf(" max RTT: %ld\n", max_rtt);
  526. printf(" avg RTT: %ld\n", avg_rtt);
  527. }
  528. printf("\n");
  529. }
  530. res = 0;
  531. if (send_fails > 0 || (have_size && length_errors > 0) || sequence_errors > 0 || crc_errors > 0) {
  532. res = 2;
  533. }
  534. return (res);
  535. }