Cette annexe fournit le code complet de chaque méthode du type de ressources SUNW.xfnts. Elle comprend le listing de xfnts.c contenant le code des sous-routines appelées par les méthodes de rappel. Programmes figurant dans cette annexe :
Ce fichier met en œuvre les sous-routines appelées par les méthodes SUNW.xfnts.
/* * Copyright (c) 1998-2004 by Sun Microsystems, Inc. * All rights reserved. * * xfnts.c - Common utilities for HA-XFS * * This utility has the methods for performing the validation, starting and * stopping the data service and the fault monitor. It also contains the method * to probe the health of the data service. The probe just returns either * success or failure. Action is taken based on this returned value in the * method found in the file xfnts_probe.c * */ #pragma ident “@(#)xfnts.c 1.47 01/01/18 SMI” #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <sys/wait.h> #include <netinet/in.h> #include <scha.h> #include <rgm/libdsdev.h> #include <errno.h> #include “xfnts.h” /* * The initial timeout allowed for the HAXFS data service to * be fully up and running. We will wait for 3 % (SVC_WAIT_PCT) * of the start_timeout time before probing the service. */ #define SVC_WAIT_PCT 3 /* * We need to use 95% of probe_timeout to connect to the port and the * remaining time is used to disconnect from port in the svc_probe function. */ #define SVC_CONNECT_TIMEOUT_PCT 95 /* * SVC_WAIT_TIME is used only during starting in svc_wait(). * In svc_wait() we need to be sure that the service is up * before returning, thus we need to call svc_probe() to * monitor the service. SVC_WAIT_TIME is the time between * such probes. */ #define SVC_WAIT_TIME 5 /* * This value will be used as disconnect timeout, if there is no * time left from the probe_timeout. */ #define SVC_DISCONNECT_TIMEOUT_SECONDS 2 /* * svc_validate(): * * Do HA-XFS specific validation of the resource configuration. * * svc_validate will check for the following * 1. Confdir_list extension property * 2. fontserver.cfg file * 3. xfs binary * 4. port_list property * 5. network resources * 6. other extension properties * * If any of the above validation fails then, Return > 0 otherwise return 0 for * success */ int svc_validate(scds_handle_t scds_handle) { char xfnts_conf[SCDS_ARRAY_SIZE]; scha_str_array_t *confdirs; scds_net_resource_list_t *snrlp; int rc; struct stat statbuf; scds_port_list_t *portlist; scha_err_t err; /* * Get the configuration directory for the XFS dataservice from the * confdir_list extension property. */ confdirs = scds_get_ext_confdir_list(scds_handle); /* Return an error if there is no confdir_list extension property */ if (confdirs == NULL || confdirs->array_cnt != 1) { scds_syslog(LOG_ERR, “Property Confdir_list is not set properly.”); return (1); /* Validation failure */ } /* * Construct the path to the configuration file from the extension * property confdir_list. Since HA-XFS has only one configuration * we will need to use the first entry of the confdir_list property. */ (void) sprintf(xfnts_conf, “%s/fontserver.cfg”, confdirs->str_array[0]); /* * Check to see if the HA-XFS configuration file is in the right place. * Try to access the HA-XFS configuration file and make sure the * permissions are set properly */ if (stat(xfnts_conf, &statbuf) != 0) { /* * suppress lint error because errno.h prototype * is missing void arg */ scds_syslog(LOG_ERR, “Failed to access file <%s> : <%s>”, xfnts_conf, strerror(errno)); /*lint !e746 */ return (1); } /* * Make sure that xfs binary exists and that the permissions * are correct. The XFS binary are assumed to be on the local * File system and not on the Global File System */ if (stat(“/usr/openwin/bin/xfs”, &statbuf) != 0) { scds_syslog(LOG_ERR, “Cannot access XFS binary : <%s> “, strerror(errno)); return (1); } /* HA-XFS will have only port */ err = scds_get_port_list(scds_handle, &portlist); if (err != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Could not access property Port_list: %s.”, scds_error_string(err)); return (1); /* Validation Failure */ } #ifdef TEST if (portlist->num_ports != 1) { scds_syslog(LOG_ERR, “Property Port_list must have only one value.”); scds_free_port_list(portlist); return (1); /* Validation Failure */ } #endif /* * Return an error if there is an error when trying to get the * available network address resources for this resource */ if ((err = scds_get_rs_hostnames(scds_handle, &snrlp)) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “No network address resource in resource group: %s.”, scds_error_string(err)); return (1); /* Validation Failure */ } /* Return an error if there are no network address resources */ if (snrlp == NULL || snrlp->num_netresources == 0) { scds_syslog(LOG_ERR, “No network address resource in resource group.”); rc = 1; goto finished; } /* Check to make sure other important extension props are set */ if (scds_get_ext_monitor_retry_count(scds_handle) <= 0) { scds_syslog(LOG_ERR, “Property Monitor_retry_count is not set.”); rc = 1; /* Validation Failure */ goto finished; } if (scds_get_ext_monitor_retry_interval(scds_handle) <= 0) { scds_syslog(LOG_ERR, “Property Monitor_retry_interval is not set.”); rc = 1; /* Validation Failure */ goto finished; } /* All validation checks were successful */ scds_syslog(LOG_INFO, “Successful validation.”); rc = 0; finished: scds_free_net_list(snrlp); scds_free_port_list(portlist); return (rc); /* return result of validation */ } /* * svc_start(): * * Start up the X font server * Return 0 on success, > 0 on failures. * * The XFS service will be started by running the command * /usr/openwin/bin/xfs -config <fontserver.cfg file> -port <port to listen> * XFS will be started under PMF. XFS will be started as a single instance * service. The PMF tag for the data service will be of the form * <resourcegroupname,resourcename,instance_number.svc>. In case of XFS, since * there will be only one instance the instance_number in the tag will be 0. */ int svc_start(scds_handle_t scds_handle) { char xfnts_conf[SCDS_ARRAY_SIZE]; char cmd[SCDS_ARRAY_SIZE]; scha_str_array_t *confdirs; scds_port_list_t *portlist; scha_err_t err; /* get the configuration directory from the confdir_list property */ confdirs = scds_get_ext_confdir_list(scds_handle); (void) sprintf(xfnts_conf, “%s/fontserver.cfg”, confdirs->str_array[0]); /* obtain the port to be used by XFS from the Port_list property */ err = scds_get_port_list(scds_handle, &portlist); if (err != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Could not access property Port_list.”); return (1); } /* * Construct the command to start HA-XFS. * NOTE: XFS daemon prints the following message while stopping the XFS * “/usr/openwin/bin/xfs notice: terminating” * In order to suppress the daemon message, * the output is redirected to /dev/null. */ (void) sprintf(cmd, “/usr/openwin/bin/xfs -config %s -port %d 2>/dev/null”, xfnts_conf, portlist->ports[0].port); /* * Start HA-XFS under PMF. Note that HA-XFS is started as a single * instance service. The last argument to the scds_pmf_start function * denotes the level of children to be monitored. A value of -1 for * this parameter means that all the children along with the original * process are to be monitored. */ scds_syslog(LOG_INFO, “Issuing a start request.”); err = scds_pmf_start(scds_handle, SCDS_PMF_TYPE_SVC, SCDS_PMF_SINGLE_INSTANCE, cmd, -1); if (err == SCHA_ERR_NOERR) { scds_syslog(LOG_INFO, “Start command completed successfully.”); } else { scds_syslog(LOG_ERR, “Failed to start HA-XFS “); } scds_free_port_list(portlist); return (err); /* return Success/failure status */ } /* * svc_stop(): * * Stop the XFS server * Return 0 on success, > 0 on failures. * * svc_stop will stop the server by calling the toolkit function: * scds_pmf_stop. */ int svc_stop(scds_handle_t scds_handle) { scha_err_t err; /* * The timeout value for the stop method to succeed is set in the * Stop_Timeout (system defined) property */ scds_syslog(LOG_ERR, “Issuing a stop request.”); err = scds_pmf_stop(scds_handle, SCDS_PMF_TYPE_SVC, SCDS_PMF_SINGLE_INSTANCE, SIGTERM, scds_get_rs_stop_timeout(scds_handle)); if (err != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to stop HA-XFS.”); return (1); } scds_syslog(LOG_INFO, “Successfully stopped HA-XFS.”); return (SCHA_ERR_NOERR); /* Successfully stopped */ } /* * svc_wait(): * * wait for the data service to start up fully and make sure it is running * healthy */ int svc_wait(scds_handle_t scds_handle) { int rc, svc_start_timeout, probe_timeout; scds_netaddr_list_t *netaddr; /* obtain the network resource to use for probing */ if (scds_get_netaddr_list(scds_handle, &netaddr)) { scds_syslog(LOG_ERR, “No network address resources found in resource group.”); return (1); } /* Return an error if there are no network resources */ if (netaddr == NULL || netaddr->num_netaddrs == 0) { scds_syslog(LOG_ERR, “No network address resource in resource group.”); return (1); } /* * Get the Start method timeout, port number on which to probe, * the Probe timeout value */ svc_start_timeout = scds_get_rs_start_timeout(scds_handle); probe_timeout = scds_get_ext_probe_timeout(scds_handle); /* * sleep for SVC_WAIT_PCT percentage of start_timeout time * before actually probing the dataservice. This is to allow * the dataservice to be fully up in order to reply to the * probe. NOTE: the value for SVC_WAIT_PCT could be different * for different data services. * Instead of calling sleep(), * call scds_svc_wait() so that if service fails too * many times, we give up and return early. */ if (scds_svc_wait(scds_handle, (svc_start_timeout * SVC_WAIT_PCT)/100) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Service failed to start.”); return (1); } do { /* * probe the data service on the IP address of the * network resource and the portname */ rc = svc_probe(scds_handle, netaddr->netaddrs[0].hostname, netaddr->netaddrs[0].port_proto.port, probe_timeout); if (rc == SCHA_ERR_NOERR) { /* Success. Free up resources and return */ scds_free_netaddr_list(netaddr); return (0); } /* * Dataservice is still trying to come up. Sleep for a while * before probing again. Instead of calling sleep(), * call scds_svc_wait() so that if service fails too * many times, we give up and return early. */ if (scds_svc_wait(scds_handle, SVC_WAIT_TIME) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Service failed to start.”); return (1); } /* We rely on RGM to timeout and terminate the program */ } while (1); } /* * This function starts the fault monitor for a HA-XFS resource. * This is done by starting the probe under PMF. The PMF tag * is derived as <RG-name,RS-name,instance_number.mon>. The restart option * of PMF is used but not the “infinite restart”. Instead * interval/retry_time is obtained from the RTR file. */ int mon_start(scds_handle_t scds_handle) { scha_err_t err; scds_syslog_debug(DBG_LEVEL_HIGH, “Calling MONITOR_START method for resource <%s>.”, scds_get_resource_name(scds_handle)); /* * The probe xfnts_probe is assumed to be available in the same * subdirectory where the other callback methods for the RT are * installed. The last parameter to scds_pmf_start denotes the * child monitor level. Since we are starting the probe under PMF * we need to monitor the probe process only and hence we are using * a value of 0. */ err = scds_pmf_start(scds_handle, SCDS_PMF_TYPE_MON, SCDS_PMF_SINGLE_INSTANCE, “xfnts_probe”, 0); if (err != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to start fault monitor.”); return (1); } scds_syslog(LOG_INFO, “Started the fault monitor.”); return (SCHA_ERR_NOERR); /* Successfully started Monitor */ } /* * This function stops the fault monitor for a HA-XFS resource. * This is done via PMF. The PMF tag for the fault monitor is * constructed based on <RG-name_RS-name,instance_number.mon>. */ int mon_stop(scds_handle_t scds_handle) { scha_err_t err; scds_syslog_debug(DBG_LEVEL_HIGH, “Calling scds_pmf_stop method”); err = scds_pmf_stop(scds_handle, SCDS_PMF_TYPE_MON, SCDS_PMF_SINGLE_INSTANCE, SIGKILL, scds_get_rs_monitor_stop_timeout(scds_handle)); if (err != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to stop fault monitor.”); return (1); } scds_syslog(LOG_INFO, “Stopped the fault monitor.”); return (SCHA_ERR_NOERR); /* Successfully stopped monitor */ } /* * svc_probe(): Do data service specific probing. Return a float value * between 0 (success) and 100(complete failure). * * The probe does a simple socket connection to the XFS server on the specified * port which is configured as the resource extension property (Port_list) and * pings the dataservice. If the probe fails to connect to the port, we return * a value of 100 indicating that there is a total failure. If the connection * goes through and the disconnect to the port fails, then a value of 50 is * returned indicating a partial failure. */ int svc_probe(scds_handle_t scds_handle, char *hostname, int port, int timeout) { int rc; hrtime_t t1, t2; int sock; char testcmd[2048]; int time_used, time_remaining; time_t connect_timeout; /* * probe the dataservice by doing a socket connection to the port * specified in the port_list property to the host that is * serving the XFS dataservice. If the XFS service which is configured * to listen on the specified port, replies to the connection, then * the probe is successful. Else we will wait for a time period set * in probe_timeout property before concluding that the probe failed. */ /* * Use the SVC_CONNECT_TIMEOUT_PCT percentage of timeout * to connect to the port */ connect_timeout = (SVC_CONNECT_TIMEOUT_PCT * timeout)/100; t1 = (hrtime_t)(gethrtime()/1E9); /* * the probe makes a connection to the specified hostname and port. * The connection is timed for 95% of the actual probe_timeout. */ rc = scds_fm_tcp_connect(scds_handle, &sock, hostname, port, connect_timeout); if (rc) { scds_syslog(LOG_ERR, “Failed to connect to port <%d> of resource <%s>.”, port, scds_get_resource_name(scds_handle)); /* this is a complete failure */ return (SCDS_PROBE_COMPLETE_FAILURE); } t2 = (hrtime_t)(gethrtime()/1E9); /* * Compute the actual time it took to connect. This should be less than * or equal to connect_timeout, the time allocated to connect. * If the connect uses all the time that is allocated for it, * then the remaining value from the probe_timeout that is passed to * this function will be used as disconnect timeout. Otherwise, the * the remaining time from the connect call will also be added to * the disconnect timeout. * */ time_used = (int)(t2 - t1); /* * Use the remaining time(timeout - time_took_to_connect) to disconnect */ time_remaining = timeout - (int)time_used; /* * If all the time is used up, use a small hardcoded timeout * to still try to disconnect. This will avoid the fd leak. */ if (time_remaining <= 0) { scds_syslog_debug(DBG_LEVEL_LOW, “svc_probe used entire timeout of “ “%d seconds during connect operation and exceeded the “ “timeout by %d seconds. Attempting disconnect with timeout” “ %d “, connect_timeout, abs(time_used), SVC_DISCONNECT_TIMEOUT_SECONDS); time_remaining = SVC_DISCONNECT_TIMEOUT_SECONDS; } /* * Return partial failure in case of disconnection failure. * Reason: The connect call is successful, which means * the application is alive. A disconnection failure * could happen due to a hung application or heavy load. * If it is the later case, don't declare the application * as dead by returning complete failure. Instead, declare * it as partial failure. If this situation persists, the * disconnect call will fail again and the application will be * restarted. */ rc = scds_fm_tcp_disconnect(scds_handle, sock, time_remaining); if (rc != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to disconnect to port %d of resource %s.”, port, scds_get_resource_name(scds_handle)); /* this is a partial failure */ return (SCDS_PROBE_COMPLETE_FAILURE/2); } t2 = (hrtime_t)(gethrtime()/1E9); time_used = (int)(t2 - t1); time_remaining = timeout - time_used; /* * If there is no time left, don't do the full test with * fsinfo. Return SCDS_PROBE_COMPLETE_FAILURE/2 * instead. This will make sure that if this timeout * persists, server will be restarted. */ if (time_remaining <= 0) { scds_syslog(LOG_ERR, “Probe timed out.”); return (SCDS_PROBE_COMPLETE_FAILURE/2); } /* * The connection and disconnection to port is successful, * Run the fsinfo command to perform a full check of * server health. * Redirect stdout, otherwise the output from fsinfo * ends up on the console. */ (void) sprintf(testcmd, “/usr/openwin/bin/fsinfo -server %s:%d > /dev/null”, hostname, port); scds_syslog_debug(DBG_LEVEL_HIGH, “Checking the server status with %s.”, testcmd); if (scds_timerun(scds_handle, testcmd, time_remaining, SIGKILL, &rc) != SCHA_ERR_NOERR || rc != 0) { scds_syslog(LOG_ERR, “Failed to check server status with command <%s>”, testcmd); return (SCDS_PROBE_COMPLETE_FAILURE/2); } return (0); } |
Cette méthode vérifie que la configuration de base du type de ressources est valide.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_monitor_check.c - méthode de contrôle du détecteur de HA-XFS */ #pragma ident “@(#)xfnts_monitor_check.c 1.11 01/01/18 SMI” #include <rgm/libdsdev.h> #include “xfnts.h” /* * Effectuez un simple contrôle de validation du service */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; int rc; /* Traitez les arguments passés au RGM et initialisez syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } rc = svc_validate(scds_handle); scds_syslog_debug(DBG_LEVEL_HIGH, “monitor_check method “ “was called and returned <%d>.”, rc); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); /* Retournez le résultat de la méthode de validation exécutée dans le cadre du contrôle du détecteur */ return (rc); } |
Cette méthode exécute la méthode xfnts_probe.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_monitor_start.c - Méthode de démarrage du détecteur de HA-XFS */ #pragma ident “@(#)xfnts_monitor_start.c 1.10 01/01/18 SMI” #include <rgm/libdsdev.h> #include “xfnts.h” /* * Cette méthode démarre le système de détection des pannes d’une ressource HA-XFS. * Cette action est réalisée en lançant la détection sous la fonction PMF. * La balise PMF est dérivée en tant que RG-name,RS-name.mon. L’option de redémarrage * de la fonction PMF est utilisée mais pas le “redémarrage illimité”. * interval/retry_time est obtenu à la place à partir du fichier RTR. */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; int rc; /* Traitez les arguments passés par le RGM et initialisez syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } rc = mon_start(scds_handle); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); /* Retournez le résultat de la méthode Démarrage_détecteur */ return (rc); } |
Cette méthode arrête la méthode xfnts_probe.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_monitor_stop.c - Méthode Arrêt du détecteur de HA-XFS */ #pragma ident “@(#)xfnts_monitor_stop.c 1.9 01/01/18 SMI” #include <rgm/libdsdev.h> #include “xfnts.h” /* * Cette méthode arrête le système de détection des pannes d’une ressource HA-XFS. * Cette action est réalisée via la fonction PMF. La balise PMF du système de détection * des pannes est créée sur le modèle RG-name_RS-name.mon. */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; int rc; /* Traitez les arguments passés par le RGM et initialisez syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } rc = mon_stop(scds_handle); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); /* Retournez le résultat de la méthode Arrêt du détecteur */ return (rc); } |
La méthode xfnts_probe contrôle la disponibilité de l'application et choisit de basculer ou de redémarrer le service de données. La méthode de rappel xfnts_monitor_start lance ce programme tandis que la méthode de rappel xfnts_monitor_stop l'arrête.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_probe.c - Probe for HA-XFS */ #pragma ident “@(#)xfnts_probe.c 1.26 01/01/18 SMI” #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <signal.h> #include <sys/time.h> #include <sys/socket.h> #include <strings.h> #include <rgm/libdsdev.h> #include “xfnts.h” /* * main(): * Boucle illimitée qui attend (sleep()s) pendant un laps de temps que le script * d’action de la fonction PMF interrompe sleep(). Une fois qu’il est interrompu * elle appelle la méthode de démarrage de HA-XFS pour le redémarrer. * */ int main(int argc, char *argv[]) { int timeout; int port, ip, probe_result; scds_handle_t scds_handle; hrtime_t ht1, ht2; unsigned long dt; scds_netaddr_list_t *netaddr; char *hostname; if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } /* Obtenez les adresses IP disponibles pour cette ressource */ if (scds_get_netaddr_list(scds_handle, &netaddr)) { scds_syslog(LOG_ERR, “No network address resource in resource group.”); scds_close(&scds_handle); return (1); } /* Retournez une erreur en l’absence de ressources réseau */ if (netaddr == NULL || netaddr->num_netaddrs == 0) { scds_syslog(LOG_ERR, “No network address resource in resource group.”); return (1); } /* * Définissez le délai d’attente des propriétés X. Cela signifie que chaque * itération de détection obtient un délai d’attente complet sur chaque ressource * réseau sans supprimer le délai d’attente entre toutes les ressources réseau * configurées pour cette ressource. */ timeout = scds_get_ext_probe_timeout(scds_handle); for (;;) { /* * Attendez que s’écoule l’intervalle_sonde_complet entre les * tentatives réussies. */ (void) scds_fm_sleep(scds_handle, scds_get_rs_thorough_probe_interval(scds_handle)); /* * À présent, détectez toutes les adresses IP utilisées. Itérez * 1. Toutes les ressources réseau utilisées. * 2. Toutes les adresses IP d’une ressource donnée. * Chaque adresse IP testée, * Calculez l’historique d’échec. */ probe_result = 0; /* * Itérez toutes les ressources pour obtenir chaque * adresse IP à utiliser pour appeler svc_probe() */ for (ip = 0; ip < netaddr->num_netaddrs; ip++) { /* * * Saisissez le nom d’hôte et le port * dont l’état doit être contrôlé. */ hostname = netaddr->netaddrs[ip].hostname; port = netaddr->netaddrs[ip].port_proto.port; /* * HA-XFS ne prend en charge qu’un port, par conséquent * obtenez la valeur du port à partir de la * première entrée dans l’ensemble des ports. */ ht1 = gethrtime(); /* Verrouillez le délai de démarrage de détection */ scds_syslog(LOG_INFO, “Probing the service on “ “port: %d.”, port); probe_result = svc_probe(scds_handle, hostname, port, timeout); /* *Mettez à jour l’historique de détection du service, * effectuez les actions requises si nécessaire. * Verrouillez le délai de fin de détection. */ ht2 = gethrtime(); /* Conversion en millisecondes */ dt = (ulong_t)((ht2 - ht1) / 1e6); /* * Calculez l’historique d’échec et effectuez les actions * requises le cas échéant */ (void) scds_fm_action(scds_handle, probe_result, (long)dt); } /* Chaque ressource réseau */ } /* Conserver la détection */ } |
Le RGM appelle la méthode Start sur un nœud du cluster lorsque le groupe de ressources contenant la ressource du service de données est connecté à ce nœud ou lorsque la ressource est activée. La méthode xfnts_start active le démon xfs sur ce nœud.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_svc_start.c - Méthode de démarrage de HA-XFS */ #pragma ident “@(#)xfnts_svc_start.c 1.13 01/01/18 SMI” #include <rgm/libdsdev.h> #include “xfnts.h” /* * Méthode de démarrage de HA-XFS. Effectue quelques contrôles sanitaires sur * les paramètres de ressource, puis démarre HA-XFS via la fonction PMF avec un * script d’action. */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; int rc; /* * Traitez tous les arguments qui nous ont été passés à partir du gestionnaire * RG et effectuez des actions d’initialisation pour syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } /* Validez l’initialisation et retournez en arrière en cas d’erreur */ rc = svc_validate(scds_handle); if (rc != 0) { scds_syslog(LOG_ERR, “Failed to validate configuration.”); return (rc); } /* Démarrez le service de données et retournez une erreur en cas d’erreur */ rc = svc_start(scds_handle); if (rc != 0) { goto finished; } /* Attendez que le service démarre complètement */ scds_syslog_debug(DBG_LEVEL_HIGH, “Calling svc_wait to verify that service has started.”); rc = svc_wait(scds_handle); scds_syslog_debug(DBG_LEVEL_HIGH, “Returned from svc_wait”); if (rc == 0) { scds_syslog(LOG_INFO, “Successfully started the service.”); } else { scds_syslog(LOG_ERR, “Failed to start the service.”); } finished: /* Libérez les ressources Environnement qui ont été allouées */ scds_close(&scds_handle); return (rc); } |
Le RGM appelle la méthode Stop sur un nœud du cluster lorsque le groupe de ressources contenant la ressource HA-XFS est déconnecté de ce nœud ou lorsque la ressource est désactivée. Cette méthode arrête le démon xfs sur ce nœud.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_svc_stop.c - Méthode d’arrêt de HA-XFS */ #pragma ident “@(#)xfnts_svc_stop.c 1.10 01/01/18 SMI” #include <rgm/libdsdev.h> #include “xfnts.h” /* * Arrête le processus HA-XFS via la fonction PMF */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; int rc; /* Traitez les arguments passés par le RGM et initialisez syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } rc = svc_stop(scds_handle); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); /* Retournez le résultat de la méthode arrêt_svc */ return (rc); } |
Le RGM appelle la méthode Update pour notifier à une ressource en cours d'exécution que ses propriétés ont été modifiées. Il appelle Update après l'exécution réussie d'une action administrative de paramétrage des propriétés d'une ressource ou de son groupe.
#pragma ident “@(#)xfnts_update.c 1.10 01/01/18 SMI” /* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droits réservés. * * xfnts_update.c - Update method for HA-XFS */ #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <rgm/libdsdev.h> /* * Certaines des propriétés de ressource peuvent avoir été mises à jour. Toutes * ces propriétés qu’il est possible de mettre à jour sont liées au système de * détection des pannes. Par conséquent, il suffit normalement de redémarrer * le détecteur. */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; scha_err_t result; /*Traitez les arguments passés par le RGM et initialisez syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } /* * Vérifiez si le système de détection des pannes fonctionne déjà et arrêtez-le * le cas échéant, puis redémarrez-le. Le second paramètre de scds_pmf_restart_fm() * identifie uniquement l’instance du système de détection des pannes qui doit être * redémarré. */ scds_syslog(LOG_INFO, “Restarting the fault monitor.”); result = scds_pmf_restart_fm(scds_handle, 0); if (result != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to restart fault monitor.”); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); return (1); } scds_syslog(LOG_INFO, “Completed successfully.”); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); return (0); } |
Cette méthode vérifie l'existence du répertoire spécifié par la propriété Confdir_list. Le RGM appelle cette méthode lorsque l'administrateur du cluster crée le service de données et met à jour ses propriétés. La méthode Monitor_check appelle cette méthode chaque fois que le système de détection des pannes bascule le service de données vers un nouveau nœud.
/* * Copyright (c) 1998-2003 par Sun Microsystems, Inc. * Tous droit réservés. * * xfnts_validate.c - Méthode de validation de HA-XFS */ #pragma ident “@(#)xfnts_validate.c 1.9 01/01/18 SMI” #include <rgm/libdsdev.h> #include “xfnts.h” /* * Vérifiez que toutes les propriétés ont été correctement définies. */ int main(int argc, char *argv[]) { scds_handle_t scds_handle; int rc; /* Traitez les arguments passés par le RGM et initialisez syslog */ if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) { scds_syslog(LOG_ERR, “Failed to initialize the handle.”); return (1); } rc = svc_validate(scds_handle); /* Libérez toute la mémoire allouée par scds_initialize */ scds_close(&scds_handle); /* Retournez le résultat de la méthode de validation */ return (rc); } |