本附錄列出 SUNW.xfnts 資源類型中每個方法的完整程式碼。它包含 xfnts.c 的清單,該清單包含回呼方法呼叫的子常式程式碼。本附錄中的程式碼清單如下所示。
該檔案實施 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);
}
|
此方法確認基本資源類型配置有效。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_monitor_check.c - Monitor Check method for HA-XFS
*/
#pragma ident “@(#)xfnts_monitor_check.c 1.11 01/01/18
SMI”
#include <rgm/libdsdev.h>
#include “xfnts.h”
/*
* just make a simple validate check on the service
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
int rc;
/* Process the arguments passed by RGM and initialize 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);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of validate method run as part of monitor check */
return (rc);
}
|
此方法啟動 xfnts_probe 方法。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_monitor_start.c - Monitor Start method for HA-XFS
*/
#pragma ident “@(#)xfnts_monitor_start.c 1.10 01/01/18
SMI”
#include <rgm/libdsdev.h>
#include “xfnts.h”
/*
* This method 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.mon. The restart option of PMF
* is used but not the “infinite restart”. Instead
* interval/retry_time is obtained from the RTR file.
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
int rc;
/* Process arguments passed by RGM and initialize 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);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of monitor_start method */
return (rc);
}
|
此方法停止 xfnts_probe 方法。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_monitor_stop.c - Monitor Stop method for HA-XFS
*/
#pragma ident “@(#)xfnts_monitor_stop.c 1.9 01/01/18 SMI”
#include <rgm/libdsdev.h>
#include “xfnts.h”
/*
* This method 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.mon.
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
int rc;
/* Process arguments passed by RGM and initialize 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);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of monitor stop method */
return (rc);
}
|
xfnts_probe 方法檢查應用程式的可用性,並決定是故障轉移資料服務還是重新啟動資料服務。xfnts_monitor_start 回呼方法啟動該程式,而 xfnts_monitor_stop 回呼方法停止該程式。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* 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():
* Just an infinite loop which sleep()s for sometime, waiting for
* the PMF action script to interrupt the sleep(). When interrupted
* It calls the start method for HA-XFS to restart it.
*
*/
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);
}
/* Get the ip addresses available for this resource */
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);
}
/* 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);
}
/*
* Set the timeout from the X props. This means that each probe
* iteration will get a full timeout on each network resource
* without chopping up the timeout between all of the network
* resources configured for this resource.
*/
timeout = scds_get_ext_probe_timeout(scds_handle);
for (;;) {
/*
* sleep for a duration of thorough_probe_interval between
* successive probes.
*/
(void) scds_fm_sleep(scds_handle,
scds_get_rs_thorough_probe_interval(scds_handle));
/*
* Now probe all ipaddress we use. Loop over
* 1. All net resources we use.
* 2. All ipaddresses in a given resource.
* For each of the ipaddress that is probed,
* compute the failure history.
*/
probe_result = 0;
/*
* Iterate through the all resources to get each
* IP address to use for calling svc_probe()
*/
for (ip = 0; ip < netaddr->num_netaddrs; ip++) {
/*
* Grab the hostname and port on which the
* health has to be monitored.
*/
hostname = netaddr->netaddrs[ip].hostname;
port = netaddr->netaddrs[ip].port_proto.port;
/*
* HA-XFS supports only one port and
* hence obtain the port value from the
* first entry in the array of ports.
*/
ht1 = gethrtime(); /* Latch probe start time */
scds_syslog(LOG_INFO, “Probing the service on “
“port: %d.”, port);
probe_result =
svc_probe(scds_handle, hostname, port, timeout);
/*
* Update service probe history,
* take action if necessary.
* Latch probe end time.
*/
ht2 = gethrtime();
/* Convert to milliseconds */
dt = (ulong_t)((ht2 - ht1) / 1e6);
/*
* Compute failure history and take
* action if needed
*/
(void) scds_fm_action(scds_handle,
probe_result, (long)dt);
} /* Each net resource */
} /* Keep probing forever */
}
|
當包含資料服務資源的資源群組在某叢集節點上線時或當啟用資源時,RGM 將在此叢集節點上呼叫 Start 方法。xfnts_start 方法在該節點上啟動 xfs 常駐程式。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_svc_start.c - Start method for HA-XFS
*/
#pragma ident “@(#)xfnts_svc_start.c 1.13 01/01/18 SMI”
#include <rgm/libdsdev.h>
#include “xfnts.h”
/*
* The start method for HA-XFS. Does some sanity checks on
* the resource settings then starts the HA-XFS under PMF with
* an action script.
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
int rc;
/*
* Process all the arguments that have been passed to us from RGM
* and do some initialization for syslog
*/
if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR)
{
scds_syslog(LOG_ERR, “Failed to initialize the handle.”);
return (1);
}
/* Validate the configuration and if there is an error return back */
rc = svc_validate(scds_handle);
if (rc != 0) {
scds_syslog(LOG_ERR,
“Failed to validate configuration.”);
return (rc);
}
/* Start the data service, if it fails return with an error */
rc = svc_start(scds_handle);
if (rc != 0) {
goto finished;
}
/* Wait for the service to start up fully */
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:
/* Free up the Environment resources that were allocated */
scds_close(&scds_handle);
return (rc);
}
|
當在某個叢集節點上使包含 HS-XFS 資源的資源群組離線時或當停用資源時,RGM 將在該叢集節點上呼叫 Stop 方法。此方法在該節點上停止 xfs 常駐程式。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_svc_stop.c - Stop method for HA-XFS
*/
#pragma ident “@(#)xfnts_svc_stop.c 1.10 01/01/18 SMI”
#include <rgm/libdsdev.h>
#include “xfnts.h”
/*
* Stops the HA-XFS process using PMF
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
int rc;
/* Process the arguments passed by RGM and initialize 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);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of svc_stop method */
return (rc);
}
|
RGM 呼叫 Update 方法以通知正在執行的資源其特性已變更。在管理動作成功地設定了資源或資源群組的特性之後,RGM 將呼叫 Update。
#pragma ident “@(#)xfnts_update.c 1.10 01/01/18 SMI”
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_update.c - Update method for HA-XFS
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <rgm/libdsdev.h>
/*
* Some of the resource properties might have been updated. All such
* updatable properties are related to the fault monitor. Hence, just
* restarting the monitor should be enough.
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
scha_err_t result;
/* Process the arguments passed by RGM and initialize syslog */
if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR)
{
scds_syslog(LOG_ERR, “Failed to initialize the handle.”);
return (1);
}
/*
* check if the Fault monitor is already running and if so stop and
* restart it. The second parameter to scds_pmf_restart_fm() uniquely
* identifies the instance of the fault monitor that needs to be
* restarted.
*/
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.”);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
return (1);
}
scds_syslog(LOG_INFO,
“Completed successfully.”);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
return (0);
}
|
此方法驗證 Confdir_list 特性指向的目錄是否存在。建立資料服務時和叢集管理員更新資料服務特性時,RGM 將呼叫此方法。每當故障監視器將資料服務故障轉移至新節點時,Monitor_check 方法即會呼叫此方法。
/*
* Copyright (c) 1998-2004 by Sun Microsystems, Inc.
* All rights reserved.
*
* xfnts_validate.c - validate method for HA-XFS
*/
#pragma ident “@(#)xfnts_validate.c 1.9 01/01/18 SMI”
#include <rgm/libdsdev.h>
#include “xfnts.h”
/*
* Check to make sure that the properties have been set properly.
*/
int
main(int argc, char *argv[])
{
scds_handle_t scds_handle;
int rc;
/* Process arguments passed by RGM and initialize 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);
/* Free up all the memory allocated by scds_initialize */
scds_close(&scds_handle);
/* Return the result of validate method */
return (rc);
}
|