sun.com | docs.sun.com | How To Buy | My Sun | Worldwide Sites |  |

| Previous Contents Index Next
## Retrieving Information About Any Node The `cmm_member_getinfo()` and `cmm_potential_getinfo()` functions retrieve information about a specified node as explained in Identifying the Properties of a Node. The node must be identified by the nodeid argument . These functions return the `cmm_member_t` structure. For more information, see Using the `cmm_member_t` Structure for Information About Member Nodes. If the `cmm_member_getinfo()` function returns the `CMM_ESRCH` error, the node has the `CMM_OUT_OF_CLUSTER` membership role. This error information can also be obtained by using the `cmm_potential_getinfo()` function. For further information about return values, see Return Values of the CMM API. For more information about these functions, see the `cmm_member_getinfo`(3CMM) and `cmm_potential_getinfo`(3CMM) man pages. The following code example demonstrates how to retrieve information about the current node by using the `cmm_member_getinfo()` function: Example 5-4 Retrieving Information About the Current Node Using the `cmm_member_getinfo()` Function
    #include <cmm.h>
    #include <stdio.h>
    #include <stdlib.h>         /* for exit() */
    #include "common.h"

    /*******************************************************************/
    void main(void)
    {
        cmm_error_t  res;
        cmm_nodeid_t currnode;
        cmm_member_t currnode_info;

        /* get the current node id */
        if ((res = cmm_node_getid(&currnode))==CMM_OK)
            printf("Current node id is: %d\n", currnode);
        else {
            printf("Error getting id of local node: %s\n",
                cmm_strerror(res));
            exit(1) ;
        }
        /* get the current node info */
        res = cmm_member_getinfo(currnode, &currnode_info);
        switch(res) {
        case CMM_OK:
            printf("Current node is in cluster\n");
            break;
        case CMM_ESRCH:
            printf("Current node is *NOT* in any cluster\n");
            break;
        default:
            printf("Error getting info on local node: %s\n",
                cmm_strerror(res));
            break;
        }
    }
The following code sample demonstrates how to retrieve information about a specific node by using the `cmm_member_getinfo()` function: Example 5-5 Retrieving Information About a Specific Node in the Cluster Using the `cmm_member_getinfo()` Function
    #include <cmm.h>
    #include <stdio.h>
    #include <sys/types.h>       /* for boolean_t */
    #include <stdlib.h>          /* for exit(), atoi() */
    #include "common.h"

    /**************************************************************/
    int get_id(cmm_nodeid_t *P_NodeId)
    {
        int          success;
        char         str_node[10];
        boolean_t    go_on = B_TRUE;

        while (go_on == B_TRUE) {
            printf("Enter the node id
            of the node you want information about [0 for abort]: ");
            success = (scanf("%9s", str_node) != 0);
            if (success) {
                *P_NodeId = atoi(str_node);
                if (*P_NodeId >= 0)
                    go_on = FALSE;
            }
        }
        return (*P_NodeId==0)?B_FALSE:B_TRUE;
    }

    /**************************************************************/
    void main(void)
    {
        cmm_error_t  res;
        cmm_nodeid_t onenode;
        cmm_member_t onenode_info;

        if (!get_id(&onenode))
        {
            printf("abort\n");
            exit(0);
        }

        /* get the node info */
        res = cmm_member_getinfo(onenode, &onenode_info);
        switch(res) {
        case CMM_OK:
            printf("node %d is in cluster\n", onenode);
            break;

        case CMM_ESRCH:
            printf("node %d is *NOT* in cluster\n", onenode);
            res = cmm_potential_getinfo(onenode, &onenode_info);
            if (res==CMM_OK)
                printf("node %d is member of the cluster\n",onenode);
            else
            if (res==CMM_ESRCH)
                printf("node %d is *NOT* member of the cluster\n",
                                    onenode);
            else printf("Error getting info on node %d: %s",
                            onenode,cmm_strerror(res));
            break;

        default:
            printf("Error getting info on node %d: %s\n",
                onenode,
                cmm_strerror(res));
            break;
        }
    }
Previous Contents Index Next

Copyright 1994-2004 Sun Microsystems