2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <sys/select.h>
50 void printSaClmNodeAddressT (SaClmNodeAddressT
*nodeAddress
) {
53 printf ("family=%d - address=", nodeAddress
->family
);
54 for (i
= 0; i
< nodeAddress
->length
; i
++) {
55 printf ("%c", nodeAddress
->value
[i
]);
59 void printSaNameT (SaNameT
*name
)
63 for (i
= 0; i
< name
->length
; i
++) {
64 printf ("%c", name
->value
[i
]);
68 void printSaClmClusterNodeT (char *description
, SaClmClusterNodeT
*clusterNode
) {
69 printf ("Node Information for %s\n", description
);
71 printf ("\tnode id is %x\n", (int)clusterNode
->nodeId
);
73 printf ("\tnode address is ");
74 printSaClmNodeAddressT (&clusterNode
->nodeAddress
);
77 printf ("\tNode name is ");
78 printSaNameT (&clusterNode
->nodeName
);
81 printf ("\tMember is %d\n", clusterNode
->member
);
83 printf ("\tTimestamp is %llx nanoseconds\n", (unsigned long long)clusterNode
->bootTimestamp
);
86 void NodeGetCallback (
87 SaInvocationT invocation
,
88 const SaClmClusterNodeT
*clusterNode
,
93 if (error
!= SA_AIS_OK
) {
94 printf ("Node for invocation %llu not found (%d)\n",
95 (unsigned long long)invocation
, error
);
97 sprintf (buf
, "NODEGETCALLBACK %llu\n", (unsigned long long)invocation
);
98 printSaClmClusterNodeT (buf
, (SaClmClusterNodeT
*)clusterNode
);
103 const SaClmClusterNotificationBufferT
*notificationBuffer
,
104 SaUint32T numberOfMembers
,
109 printf ("Track callback\n");
110 printf ("Calling track callback %p\n", notificationBuffer
);
111 for (i
= 0; i
< numberOfMembers
; i
++) {
112 switch (notificationBuffer
->notification
[i
].clusterChange
) {
113 case SA_CLM_NODE_NO_CHANGE
:
114 printf ("NODE STATE NO CHANGE.\n");
116 case SA_CLM_NODE_JOINED
:
117 printf ("NODE STATE JOINED.\n");
119 case SA_CLM_NODE_LEFT
:
120 printf ("NODE STATE LEFT.\n");
122 case SA_CLM_NODE_RECONFIGURED
:
123 printf ("NODE STATE RECONFIGURED.\n");
126 printSaClmClusterNodeT ("TRACKING",
127 ¬ificationBuffer
->notification
[i
].clusterNode
);
129 printf ("Done calling trackCallback\n");
132 SaClmCallbacksT callbacks
= {
133 .saClmClusterNodeGetCallback
= NodeGetCallback
,
134 .saClmClusterTrackCallback
= TrackCallback
137 SaVersionT version
= { 'B', 1, 1 };
139 void sigintr_handler (int signum
) {
146 SaSelectionObjectT select_fd
;
148 SaClmClusterNotificationT clusterNotification
[64];
149 SaClmClusterNotificationBufferT clusterNotificationBuffer
;
150 SaClmClusterNodeT clusterNode
;
153 clusterNotificationBuffer
.notification
= clusterNotification
;
154 clusterNotificationBuffer
.numberOfItems
= 64;
156 signal (SIGINT
, sigintr_handler
);
158 result
= saClmInitialize (&handle
, &callbacks
, &version
);
159 if (result
!= SA_AIS_OK
) {
160 printf ("Could not initialize Cluster Membership API instance error %d\n", result
);
164 result
= saClmClusterNodeGet (handle
, SA_CLM_LOCAL_NODE_ID
, SA_TIME_END
, &clusterNode
);
166 printf ("Result of saClmClusterNodeGet %d\n", result
);
168 printSaClmClusterNodeT ("saClmClusterNodeGet SA_CLM_LOCAL_NODE_ID result %d", &clusterNode
);
170 result
= saClmClusterNodeGetAsync (handle
, 55, SA_CLM_LOCAL_NODE_ID
);
171 printf ("result is %d\n", result
);
173 result
= saClmClusterNodeGetAsync (handle
, 60, 0x6201a8c0);
174 printf ("result is %d\n", result
);
176 result
= saClmClusterNodeGetAsync (handle
, 61, 0x6a01a8f0);
177 printf ("result is %d\n", result
);
179 result
= saClmClusterNodeGetAsync (handle
, 59, SA_CLM_LOCAL_NODE_ID
);
180 printf ("result is %d\n", result
);
182 result
= saClmClusterNodeGetAsync (handle
, 57, SA_CLM_LOCAL_NODE_ID
);
183 printf ("result is %d\n", result
);
185 result
= saClmClusterTrack (handle
, SA_TRACK_CURRENT
| SA_TRACK_CHANGES
,
186 &clusterNotificationBuffer
);
187 printf ("track result is %d\n", result
);
188 for (i
= 0; i
< clusterNotificationBuffer
.numberOfItems
; i
++) {
189 printSaClmClusterNodeT ("Results from SA_TRACK_CURRENT:",
190 &clusterNotificationBuffer
.notification
[i
].clusterNode
);
193 saClmSelectionObjectGet (handle
, &select_fd
);
195 printf ("select fd is %llu\n", (unsigned long long)select_fd
);
197 printf ("press the enter key to exit with track stop and finalize.\n");
199 FD_SET (select_fd
, &read_fds
);
200 FD_SET (STDIN_FILENO
, &read_fds
);
201 result
= select (select_fd
+ 1, &read_fds
, 0, 0, 0);
205 if (FD_ISSET (STDIN_FILENO
, &read_fds
)) {
208 printf ("done with select\n");
209 saClmDispatch (handle
, SA_DISPATCH_ALL
);
212 result
= saClmClusterTrackStop (handle
);
213 printf ("TrackStop result is %d (should be 1)\n", result
);
215 result
= saClmFinalize (handle
);
216 printf ("Finalize result is %d (should be 1)\n", result
);