Sun Cluster Data Services Developer's Guide for Solaris OS

Validate Method

The purpose of the Validate callback method of a resource type implementation is to check that the proposed resource settings (as specified by the proposed property settings on the resource) are acceptable to the resource type.

The Validate method of a resource type implementation is called by the Resource Group Manager (RGM) under one of the following two conditions:

These two scenarios can be distinguished by the presence of the command-line option -c (create) or -u (update) that is passed to the Validate method of the resource.

The Validate method is called on each node of a set of nodes or in each zone, where the set of nodes or zones is defined by the value of the resource type property Init_nodes. If Init_nodes is set to RG_PRIMARIES, Validate is called on each node or zone that can host (be a primary of) the resource group that contains the resource. If Init_nodes is set to RT_INSTALLED_NODES, Validate is called on each node or zone where the resource type software is installed, typically all nodes or zones in the cluster.

The default value of Init_nodes is RG_PRIMARIES (see the rt_reg(4) man page). At the point the Validate method is called, the RGM has not yet created the resource (in the case of creation callback) or has not yet applied the updated values of the properties that are being updated (in the case of update callback).


Note –

If you are using local file systems that are managed by the HAStoragePlus resource type, you use the scds_hasp_check() function to check the state of that resource type. This information is obtained from the state (online or otherwise) of all SUNW.HAStoragePlus resources on which the resource depends by using the Resource_dependencies or Resource_dependencies_weak system properties that are defined for the resource. See the scds_hasp_check(3HA) man page for a complete list of status codes that are returned by the scds_hasp_check() function.


The DSDL function scds_initialize() handles these situations in the following manner:

Suppose the function that implements the validation of a resource's properties is called svc_validate(), which uses the scds_get_name() family of functions to look at the property to be validated. Assuming that an acceptable resource setting is represented by a 0 return code from this function, the Validate method of the resource type can thus be represented by the following code fragment:

int
main(int argc, char *argv[])
{
   scds_handle_t handle;
   int rc;

   if (scds_initialize(&handle, argc, argv)!= SCHA_ERR_NOERR) {
   return (1);   /* Initialization Error */
   }
   rc = svc_validate(handle);
   scds_close(&handle);
   return (rc);
}

The validation function should also log the reason why the validation of the resource failed. However, by leaving out that detail (Chapter 8, Sample DSDL Resource Type Implementation contains a more realistic treatment of a validation function), you can implement a simpler example svc_validate() function, as follows:

int
svc_validate(scds_handle_t handle)
{
   scha_str_array_t *confdirs;
   struct stat    statbuf;
   confdirs = scds_get_confdir_list(handle);
   if (stat(confdirs->str_array[0], &statbuf) == -1) {
   return (1);   /* Invalid resource property setting */
   }
   return (0);   /* Acceptable setting */
}

Thus, you must concern yourself with only the implementation of the svc_validate() function.