2 * Copyright (c) 2006-2007 Red Hat, Inc.
6 * Author: Steven Dake <sdake@redhat.com>
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <sys/select.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
51 static void ringstatusget_do (void)
54 openais_cfg_handle_t handle
;
55 unsigned int interface_count
;
56 char **interface_names
;
57 char **interface_status
;
60 printf ("Printing ring status.\n");
61 result
= openais_cfg_initialize (&handle
, NULL
);
62 if (result
!= SA_AIS_OK
) {
63 printf ("Could not initialize openais configuration API error %d\n", result
);
67 openais_cfg_ring_status_get (handle
,
72 for (i
= 0; i
< interface_count
; i
++) {
73 printf ("RING ID %d\n", i
);
74 printf ("\tid\t= %s\n", interface_names
[i
]);
75 printf ("\tstatus\t= %s\n", interface_status
[i
]);
78 openais_cfg_finalize (handle
);
81 static void ringreenable_do (void)
84 openais_cfg_handle_t handle
;
86 printf ("Re-enabling all failed rings.\n");
87 result
= openais_cfg_initialize (&handle
, NULL
);
88 if (result
!= SA_AIS_OK
) {
89 printf ("Could not initialize openais configuration API error %d\n", result
);
93 result
= openais_cfg_ring_reenable (handle
);
94 if (result
!= SA_AIS_OK
) {
95 printf ("Could not reenable ring error %d\n", result
);
98 openais_cfg_finalize (handle
);
101 void service_load_do (char *service
, unsigned int version
)
104 openais_cfg_handle_t handle
;
106 printf ("Loading service '%s' version '%d'\n", service
, version
);
107 result
= openais_cfg_initialize (&handle
, NULL
);
108 if (result
!= SA_AIS_OK
) {
109 printf ("Could not initialize openais configuration API error %d\n", result
);
112 result
= openais_cfg_service_load (handle
, service
, version
);
113 if (result
!= SA_AIS_OK
) {
114 printf ("Could not load service (error = %d)\n", result
);
116 openais_cfg_finalize (handle
);
119 void service_unload_do (char *service
, unsigned int version
)
122 openais_cfg_handle_t handle
;
124 printf ("Unloading service '%s' version '%d'\n", service
, version
);
125 result
= openais_cfg_initialize (&handle
, NULL
);
126 if (result
!= SA_AIS_OK
) {
127 printf ("Could not initialize openais configuration API error %d\n", result
);
130 result
= openais_cfg_service_unload (handle
, service
, version
);
131 if (result
!= SA_AIS_OK
) {
132 printf ("Could not unload service (error = %d)\n", result
);
134 openais_cfg_finalize (handle
);
139 printf ("openais-cfgtool [-s] [-r] [-l] [-u] [service_name] [-v] [version]\n\n");
140 printf ("A tool for displaying and configuring active parameters within openais.\n");
141 printf ("options:\n");
142 printf ("\t-s\tDisplays the status of the current rings on this node.\n");
143 printf ("\t-r\tReset redundant ring state cluster wide after a fault to\n");
144 printf ("\t\tre-enable redundant ring operation.\n");
145 printf ("\t-l\tLoad a service identified by name.\n");
146 printf ("\t-u\tUnload a service identified by name.\n");
149 int main (int argc
, char *argv
[]) {
150 const char *options
= "srl:u:v:";
152 int service_load
= 0;
153 int service_unload
= 0;
155 unsigned int version
;
160 while ( (opt
= getopt(argc
, argv
, options
)) != -1 ) {
170 service
= strdup (optarg
);
174 service
= strdup (optarg
);
177 version
= atoi (optarg
);
182 service_load_do (service
, version
);
184 if (service_unload
) {
185 service_unload_do (service
, version
);