Sun Cluster 数据服务开发者指南(适用于 Solaris OS)

第 8 章 DSDL 资源类型实现样例

本章介绍使用 DSDL 实现的资源类型 SUNW.xfnts 的样例。 该数据服务是用 C 语言编写的。基础应用程序是 X Font Server,一种基于 TCP/IP 的服务。

本章内容包括:

X Font Server

X Font Server 是一种简单的基于 TCP/IP 的服务,它可以向其客户机提供字体文件。 客户机将连接该服务器,请求提供字体集,该服务器将从磁盘读取相应的字体文件并将它们提供给客户机。 X Font Server 守护程序包含一个服务器二进制文件 /usr/openwin/bin/xfs。 虽然通常从 inetd 启动该守护程序,但是,对于当前样例,假设已禁用 /etc/inetd.conf 文件中的相应项(例如,通过 fsadmin -d 命令),这样守护程序就在 Sun Cluster 的单一控制下。

X Font Server 配置文件

缺省情况下,X Font Server 从文件 /usr/openwin/lib/X11/fontserver.cfg 中读取其配置信息。 此文件中的目录项包含了守护程序可以提供的字体目录列表。 群集管理员可以将字体目录定位到全局文件系统中(以通过在系统上维护单个字体数据库副本来优化 X Font Server 在 Sun Cluster 中的使用)。 如果执行此操作,管理员必须编辑 fontserver.cfg 来反映该字体目录的新路径。

为了可以轻松地进行配置,管理员也可以将配置文件本身放置在全局文件系统中。 xfs 守护程序提供了命令行变量,以覆盖此文件的缺省内置位置。 SUNW.xfnts 资源类型使用以下命令启动受 Sun Cluster 控制的守护程序。


/usr/openwin/bin/xfs -config <location_of_cfg_file>/fontserver.cfg \
-port <portnumber>

SUNW.xfnts 资源类型实现中,您可以使用 Confdir_list 特性管理 fontserver.cfg 配置文件的位置。

TCP 端口号

xfs 服务器守护程序所侦听的 TCP 端口号通常是“fs”端口(其端口号在 /etc/services 文件中通常定义为 7100)。 然而,使用 xfs 命令行上的 -port 选项,系统管理员可以覆盖该缺省设置。 可以使用 SUNW.xfnts 资源类型中的 Port_list 特性设置缺省值,并支持在 xfs 命令行上使用 -port 选项。 在 RTR 文件中您需要将此特性的缺省值定义为 7100/tcp。 在 SUNW.xfnts Start 方法中,将 Port_list 传送到 xfs 命令行上的 -port 选项。 因此,不要求此资源类型的用户指定端口号(缺省端口为 7100/tcp),但是,如果需要,当配置资源类型时,通过为 Port_list 特性指定不同的值,可以指定其它端口。

命名惯例

您可以采用以下命名惯例来标识多个代码样例段。

SUNW.xfnts RTR 文件

本节介绍 SUNW.xfnts RTR 文件中的几个主要特性。 本节并未介绍该文件中每个特性的作用, 有关此方面的介绍,请参阅设置资源和资源类型特性

Confdir_list 扩展特性用来标识配置目录(或目录列表),如下所示。


{
        PROPERTY = Confdir_list;
        EXTENSION;
        STRINGARRAY;
        TUNABLE = AT_CREATION;
        DESCRIPTION = "The Configuration Directory Path(s)";
}

Confdir_list 特性未指定缺省值。 创建资源时,群集管理员必须指定一个目录。 因为可调性被限制为 AT_CREATION,因此创建以后无法更改此值。

Port_list 特性用来标识服务器守护程序所侦听的端口,如下所示。


{
        PROPERTY = Port_list;
        DEFAULT = 7100/tcp;
        TUNABLE = AT_CREATION;
}

因为该特性声明了一个缺省值,所以在创建资源时,群集管理员既可以选择指定一个新值,又可以接受该缺省值。 因为可调性被限制为 AT_CREATION,因此创建以后无法更改此值。

scds_initialize() 函数

DSDL 要求每个回叫方法在该方法的开头调用 scds_initialize(3HA) 函数。 此函数可执行以下操作:

使用 scds_close() 函数回收通过 scds_initialize() 分配的资源。

xfnts_start 方法

使含有数据服务资源的资源组在群集节点上联机时或启用该资源时,RGM 将对该节点调用 Start 方法。 在 SUNW.xfnts 资源类型样例中,xfnts_start 方法将激活该节点上的 xfs 守护程序。

xfnts_start 方法将在 PMF 控制下调用 scds_pmf_start() 启动该守护程序。 除了与故障监视器集成以外,PMF 还提供了自动的失败通知并重启的功能。


注意:

xfnts_start 中首先调用的是 scds_initialize(),该函数执行一些必要的内务处理功能(scds_initialize() 函数scds_initialize(3HA) 手册页中包含详细信息)。


在启动之前验证服务

在尝试启动 X Font Server 之前,xfnts_start 方法将调用 svc_validate() 验证是否已进行了适当的配置,以支持 xfs 守护程序(有关详细信息,请参阅xfnts_validate 方法),如下所示。


rc = svc_validate(scds_handle);
   if (rc != 0) {
      scds_syslog(LOG_ERR,
          "Failed to validate configuration.");
      return (rc);
   }

启动服务

xfnts_start 方法将调用 xfnts.c 中定义的 svc_start() 方法来启动 xfs 守护程序。 本节将介绍 svc_start ()

用来启动 xfs 守护程序的命令如下所示。


xfs -config config_directory/fontserver.cfg -port port_number

Confdir_list 扩展特性用来标识 config_directoryPort_list 系统特性用来标识 port_number。 群集管理员配置数据服务时,需要提供这些特性的具体值。

xfnts_start 方法将使用 scds_get_ext_confdir_list()scds_get_port_list() 函数将这些特性声明为字符串数组并获取管理员设置的值(在 scds_property_functions(3HA) 中进行介绍),如下所示。


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);
   }

请注意,confdirs 变量指向该数组的第一个元素 (0)。

xfnts_start 方法使用 sprintf 组成 xfs 命令行,如下所示。


/* Construct the command to start the xfs daemon. */
   (void) sprintf(cmd,
       "/usr/openwin/bin/xfs -config %s -port %d 2>/dev/null",
       xfnts_conf, portlist->ports[0].port);

请注意,输出将重定向到 dev/null,以抑制该守护程序生成的消息。

xfnts_start 方法将把 xfs 命令行传送到 scds_pmf_start(),以在 PMF 控制下启动该数据服务,如下所示。


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_pmf_start() 进行调用的内容。

在返回之前,svc_pmf_start() 将释放为 portlist 结构分配的内存,如下所示。


scds_free_port_list(portlist);
return (err);

svc_start() 返回

即使 svc_start() 成功地返回,基础应用程序也可能无法启动。 因此,svc_start() 必须探测应用程序以验证在返回成功消息前运行了此应用程序。 该探测程序还必须将应用程序可能无法立即可用这一点考虑在内,因为该程序需要一些时间来启动。 svc_start() 方法将调用在 xfnts.c 中定义的 svc_wait() 来检验应用程序是否正在运行,如下所示。


/* 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.");
   }

svc_wait() 函数将调用 scds_get_netaddr_list(3HA) 来获取探测应用程序时所需的网络地址资源,如下所示。


/* 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);
   }

然后 svc_wait() 将获取 start_timeoutstop_timeout 的值,如下所示。


svc_start_timeout = scds_get_rs_start_timeout(scds_handle)
   probe_timeout = scds_get_ext_probe_timeout(scds_handle)

考虑到该服务器启动可能花费的时间,svc_wait() 将调用 scds_svc_wait() 并传送等于 start_timeout 值的百分之三的超时值。 然后 svc_wait() 将调用 svc_probe() 来检验该应用程序是否已启动。 svc_probe() 方法用来建立指定端口上服务器的简单套接字连接。 如果无法连接该端口,svc_probe() 将返回值 100,该值表明操作完全失败。 如果连接成功但是断开连接操作失败,svc_probe() 将返回值 50。

svc_probe() 失败或部分失败时,svc_wait() 使用超时值 5 调用 scds_svc_wait()scds_svc_wait() 方法将探测频率限制为每五秒钟一次。 此方法也可用来计算尝试启动该服务的次数。 如果在资源的 Retry_interval 特性指定的时间内尝试次数超过资源的 Retry_count 特性的值,则 scds_svc_wait() 函数将返回失败。 在这种情况下,svc_start() 函数也返回失败。


#define    SVC_CONNECT_TIMEOUT_PCT    95
#define    SVC_WAIT_PCT       3
   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);
      }

       /* Call scds_svc_wait() so that if service fails too
      if (scds_svc_wait(scds_handle, SVC_WAIT_TIME)
         != SCHA_ERR_NOERR) {
         scds_syslog(LOG_ERR, "Service failed to start.");
         return (1);
      }

   /* Rely on RGM to timeout and terminate the program */
   } while (1);


注意:

退出前,xfnts_start 方法调用 scds_close() 来回收由 scds_initialize() 分配的资源。 有关详细信息,请参阅scds_initialize() 函数scds_close(3HA) 手册页。


xfnts_stop 方法

因为 xfnts_start 方法使用 scds_pmf_start() 在 PMF 控制下启动服务,所以 xfnts_stop 将使用 scds_pmf_stop() 停止该服务。


注意:

xfnts_stop 中首先调用的是 scds_initialize(),该函数可以执行一些必要的内务处理功能(scds_initialize() 函数scds_initialize(3HA) 手册页中包含了详细信息)。


xfnts_stop 方法将调用在 xfnts.c 中定义的 svc_stop() 方法,如下所示。


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_stop() 中调用 scds_pmf_stop() 函数的内容。


注意:

在退出之前,xfnts_stop 方法将调用 scds_close() 回收通过 scds_initialize() 分配的资源。 有关详细信息,请参阅scds_initialize() 函数scds_close(3HA) 手册页。


xfnts_monitor_start 方法

在节点上启动资源后,RGM 将对该节点调用 Monitor_start 方法,以启动故障监视器。 xfnts_monitor_start 方法将使用 scds_pmf_start() 在 PMF 的控制下启动监视器守护程序。


注意:

xfnts_monitor_start 中首先调用的是 scds_initialize(),该函数可以执行一些必要的内务处理功能(scds_initialize() 函数scds_initialize(3HA) 手册页中包含了详细信息)。


xfnts_monitor_start 方法将调用在 xfnts.c 中定义的 mon_start 方法,如下所示。


scds_syslog_debug(DBG_LEVEL_HIGH,
      "Calling Monitor_start method for resource <%s>.",
      scds_get_resource_name(scds_handle));

    /* Call scds_pmf_start and pass the name of the probe. */
   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 */
}

请注意以下关于在 svc_mon_start() 中调用 scds_pmf_start() 函数的内容。


注意:

在退出之前,xfnts_monitor_start 方法将调用 scds_close() 来回收通过 scds_initialize() 分配的资源。 有关详细信息,请参阅scds_initialize() 函数scds_close(3HA) 手册页。


xfnts_monitor_stop 方法

因为 xfnts_monitor_start 方法使用 scds_pmf_start() 在 PMF 的控制下启动监视器守护程序,所以 xfnts_monitor_stop 将使用 scds_pmf_stop() 停止该监视器守护程序。


注意:

xfnts_monitor_stop 中首先调用的是 scds_initialize(),该函数可以执行一些必要的内务处理功能(scds_initialize() 函数scds_initialize(3HA) 手册页中包含了详细信息)。


xfnts_monitor_stop() 方法将调用在 xfnts.c 中定义的 mon_stop 方法,如下所示。


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_mon_stop() 中调用 scds_pmf_stop() 函数的内容。


注意:

在退出之前,xfnts_monitor_stop 方法将调用 scds_close() 来回收通过 scds_initialize() 分配的资源。 有关详细信息,请参阅scds_initialize() 函数scds_close(3HA) 手册页。


xfnts_monitor_check 方法

每当故障监视器试图将含有资源的资源组故障切换到其它节点时,RGM 都将调用 Monitor_check 方法。 xfnts_monitor_check 方法将调用 svc_validate() 方法来检验是否已进行了适当的配置,以支持 xfs 守护程序(有关详细信息,请参阅xfnts_validate 方法)。 xfnts_monitor_check 的代码如下。


   /* 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);
}

SUNW.xfnts 故障监视器

在节点上启动资源后,RGM 并不直接调用 PROBE 方法,而是调用 Monitor_start 方法来启动监视器。 xfnts_monitor_start 方法将在 PMF 的控制下启动故障监视器。 xfnts_monitor_stop 方法用来停止该故障监视器。

SUNW.xfnts 故障监视器可以执行以下操作:

xfonts_probe 主循环

xfonts_probe 方法实现一个循环。 在实现该循环之前,xfonts_probe 将:

xfnts_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 */

svc_probe() 函数将实现探测程序逻辑。 从 svc_probe() 返回的值被传送到 scds_fm_action(),以决定是否重新启动应用程序、对资源组进行故障切换或不进行任何操作。

svc_probe() 函数

svc_probe() 函数将通过调用 scds_fm_tcp_connect() 建立指定端口的简单套接字连接。 如果连接失败,svc_probe() 将返回值 100,该值表明操作完全失败。 如果连接成功,但断开连接操作失败,svc_probe() 将返回值 50,该值表明操作部分失败。 如果连接和断开连接的操作都成功,svc_probe() 将返回值 0,该值表明操作成功。

svc_probe() 的代码如下。


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 data service by doing a socket connection to the port */
    * specified in the port_list property to the host that is
    * serving the XFS data service. 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);
}

完成操作后,svc_probe() 将返回表示成功的值 (0)、表示部分失败的值 (50) 或表示完全失败的值 (100)。 xfnts_probe 方法将把此值传送到 scds_fm_action()

确定故障监视器操作

xfnts_probe 方法将调用 scds_fm_action() 来确定要执行的操作。 scds_fm_action() 中的逻辑如下:

例如,假设该探测程序建立了 xfs 服务器的连接,但是断开连接操作失败。 这表明该服务器正在运行,但是可能处于挂起状态或恰好处于临时装入状态。 如果断开连接操作失败,将向 scds_fm_action() 发送表明部分失败的值 (50)。 此值虽然小于用来重启该数据服务的阈值,但是它将保留在失败历史记录中。

如果在下一次探测中,连接服务器再次失败,值 50 将被添加到由 scds_fm_action() 维护的失败历史记录中。 现在累积的失败值为 100,因此 scds_fm_action() 将重启该数据服务。

xfnts_validate 方法

创建资源时和通过管理操作更新资源的特性或资源所包含的组的特性时,RGM 将调用 Validate 方法。 在进行创建或更新之前,RGM 将调用 Validate,如果从任何节点上的方法返回失败出口代码都将导致创建或更新操作取消。

仅当通过管理操作更改资源或组特性时(而不是在 RGM 设置特性时或监视器设置资源特性 StatusStatus_msg 时),RGM 才调用 Validate


注意:

每当 PROBE 尝试将数据服务故障切换到新节点时,Monitor_check 方法也将明确调用 Validate 方法。


RGM 通过不同于传送到其它方法的变量的附加变量(包括所更新的特性和值)调用 Validate。 在 xfnts_validate 开头部分对 scds_initialize() 的调用可分析 RGM 传送到 xfnts_validate 的所有变量,并将信息存储在 scds_handle 参数中。 xfnts_validate 调用的子例行程序将使用这些信息。

xfnts_validate 方法将调用用来检验以下方面的 svc_validate()

在返回之前,svc_validate() 将释放所有分配的资源。


finished:
   scds_free_net_list(snrlp);
   scds_free_port_list(portlist);

   return (rc); /* return result of validation */


注意:

在退出之前,xfnts_validate 方法将调用 scds_close() 来回收通过 scds_initialize() 分配的资源。 有关详细信息,请参阅scds_initialize() 函数scds_close(3HA) 手册页。


xfnts_update 方法

RGM 将调用 Update 方法通知运行资源其特性已被更改。 唯一可以为 xfnts 数据服务更改的特性与故障监视器有关, 因此,每当更新特性时,xfnts_update 方法都将调用 scds_pmf_restart_fm() 来重启该故障监视器。


* 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.");


注意:

如果存在多个实例,scds_pmf_restart_fm() 的第二个参数将唯一标识要重启的故障监视器的实例。 样例中的值 0 表明该故障监视器只有一个实例。