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

| Previous Contents Index Next
### The `cmm_member_setqualif()` Function The code provided by Example A-6 performs a switchover by disqualifying the master node by using the `cmm_member_setqualif()` function. Example A-6 The `smpl_cmm_member_setqualif.c` Program
    /**********************************************************
    * Copyright (c) 2002 by Sun Microsystems, Inc.
    * All rights reserved.
    *
    *
    * ident  "@(#)smpl_cmm_member_setqualif.c 1.2     01/12/14 SMI"
    *************************************************************************/

    #include <stdio.h>
    #include <unistd.h>

    #include <cmm.h>

    /*
     * get master ID
     * test if we are on master
     * dequalify ourself
     *
     */

    int main(int argc , char ** argv) {
      cmm_error_t  cmm_diag;
      cmm_nodeid_t CurrentNodeid;
      cmm_member_t MasterNodeInfo;
      cmm_member_t ViceMasterNodeInfo;

      cmm_diag = cmm_node_getid(&CurrentNodeid);
      if (cmm_diag != CMM_OK) {
        fprintf(stderr,"An error occured during cmm_node_getid() call \n");
        fprintf(stderr,"Details: %s\n",cmm_strerror(cmm_diag));
        exit(1);
      }

      printf("My id is %d\n",CurrentNodeid);

      /*get master/vice master id*/
      cmm_diag = cmm_master_getinfo(&MasterNodeInfo);
      if (cmm_diag != CMM_OK) {
        fprintf(stderr,"An error occured during
        cmm_master_getinfocall, CR=%d\n",cmm_diag);
        fprintf(stderr,"Details: %s\n",cmm_strerror(cmm_diag));
        exit(1);
      }

      cmm_diag = cmm_vicemaster_getinfo(&ViceMasterNodeInfo);
      if (cmm_diag != CMM_OK) {
        fprintf(stderr,"An error occured during
        cmm_master_getinfocall, CR=%d\n",cmm_diag);
        fprintf(stderr,"Details: %s\n",cmm_strerror(cmm_diag));
        exit(1);
      }

      printf("master node id is %d\n",MasterNodeInfo.nodeid);
      printf("vice-master node id is %d\n",ViceMasterNodeInfo.nodeid);

      /*the role could be verified by cmm_member_ismaster()*/
      if (CurrentNodeid == MasterNodeInfo.nodeid) {
        printf("We are the master of the cluster, launch the SO\n");
      } else {
        printf("We are not master, operation will be cancelled\n");
        exit(1);
      }

      /*disqualify the master*/
      cmm_diag =
       cmm_member_setqualif(CurrentNodeid,CMM_DISQUALIFIED_MEMBER);
      if (cmm_diag != CMM_OK) {
        fprintf(stderr,"An error occured during
        cmm_member_setqualif, CR=%d\n",cmm_diag);
        fprintf(stderr,"Details: %s\n",cmm_strerror(cmm_diag));
        exit(1);
      }

      /*the switch over is running*/
      /* ... */

      /* the master (ex master) is now disqualified                        */
      /* We need to be on the new master to be allowed to qualify a node   */
      /* on the new master we should run this command to                   */
      /* qualify the ex-master to make it the vice-master of the cluster   */
      /*                                                                   */
      /* cmm_diag =
      /*  cmm_member_setqualif(CurrentNodeid,CMM_QUALIFIED_MEMBER); */
      /*  if (cmm_diag != CMM_OK) {                                        */
      /*      fprintf(stderr,"An error occured during
      cmm_member_setqualif, CR=%d\n",cmm_diag);                            */
      /*      exit(1);                                                     */
      /*  }                                                                */

      exit(0);

    }
Previous Contents Index Next

Copyright 1994-2004 Sun Microsystems