4
0

openais-cfgtool.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2006 Red Hat Inc
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake <sdake@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 <errno.h>
  37. #include <signal.h>
  38. #include <unistd.h>
  39. #include <string.h>
  40. #include <sys/types.h>
  41. #include <sys/socket.h>
  42. #include <sys/select.h>
  43. #include <sys/un.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include "saAis.h"
  47. #include "cfg.h"
  48. static void ringstatusget_do (void)
  49. {
  50. SaAisErrorT result;
  51. openais_cfg_handle_t handle;
  52. unsigned int interface_count;
  53. char **interface_names;
  54. char **interface_status;
  55. unsigned int i;
  56. printf ("Printing ring status.\n");
  57. result = openais_cfg_initialize (&handle, NULL);
  58. if (result != SA_AIS_OK) {
  59. printf ("Could not initialize openais configuration API error %d\n", result);
  60. exit (1);
  61. }
  62. openais_cfg_ring_status_get (handle,
  63. &interface_names,
  64. &interface_status,
  65. &interface_count);
  66. for (i = 0; i < interface_count; i++) {
  67. printf ("RING ID %d\n", i);
  68. printf ("\tid\t= %s\n", interface_names[i]);
  69. printf ("\tstatus\t= %s\n", interface_status[i]);
  70. }
  71. openais_cfg_finalize (handle);
  72. }
  73. static void ringreenable_do (void)
  74. {
  75. SaAisErrorT result;
  76. openais_cfg_handle_t handle;
  77. printf ("Re-enabling all failed rings.\n");
  78. result = openais_cfg_initialize (&handle, NULL);
  79. if (result != SA_AIS_OK) {
  80. printf ("Could not initialize openais configuration API error %d\n", result);
  81. exit (1);
  82. }
  83. result = openais_cfg_ring_reenable (handle);
  84. if (result != SA_AIS_OK) {
  85. printf ("Could not reenable ring error %d\n", result);
  86. }
  87. openais_cfg_finalize (handle);
  88. }
  89. void usage_do (void)
  90. {
  91. printf ("openais-cfgtool [-s] [-r]\n\n");
  92. printf ("A tool for displaying and configuring active parameters within openais.\n");
  93. printf ("options:\n");
  94. printf ("\t-s\tDisplays the status of the current rings on this node.\n");
  95. printf ("\t-r\tReset redundant ring state cluster wide after a fault to\n");
  96. printf ("\t\tre-enable redundant ring operation.\n");
  97. }
  98. int main (int argc, char *argv[]) {
  99. const char *options = "sr";
  100. int opt;
  101. if (argc == 1) {
  102. usage_do ();
  103. }
  104. while ( (opt = getopt(argc, argv, options)) != -1 ) {
  105. switch (opt) {
  106. case 's':
  107. ringstatusget_do ();
  108. break;
  109. case 'r':
  110. ringreenable_do ();
  111. break;
  112. }
  113. }
  114. return (0);
  115. }