From 5b30c0a120c3cc5fc08f9ea5f14fc9f7f442ace3 Mon Sep 17 00:00:00 2001 From: Hans Feldt Date: Wed, 17 May 2006 07:22:43 +0000 Subject: [PATCH] Introduction of SA Forum information model for AMF as specified in SAI-Overview-B.02.01.pdf. Other AMF changes as specified in SAI-AIS-AMF-B.02.01. Summary: - SA Forum B.02 Information model for AMF - groups.conf renamed to amf.conf - amf.conf syntax changed heavily to follow SA Forum specs. - AMF works when daemon. - linux lists removed from AMF - component cmd environment variables support - component argv support - multi value csi attributes git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1026 fd59a12c-fef9-0310-b244-a6a79926bd2f --- Makefile | 2 +- QUICKSTART | 4 +- conf/amf.conf | 133 ++ conf/groups.conf | 239 --- exec/aisparser.c | 31 +- exec/aispoll.c | 6 +- exec/amf.c | 3429 ++++++++-------------------------------- exec/amfconfig.c | 1195 ++++++++------ exec/amfconfig.h | 439 +++-- exec/mainconfig.h | 2 - exec/util.c | 50 + exec/util.h | 5 +- include/ipc_amf.h | 8 +- lib/amf.c | 28 +- man/openais.conf.5 | 6 +- man/openais_overview.8 | 2 +- test/clc_cli_script | 21 +- test/testamf1.c | 16 +- 18 files changed, 1980 insertions(+), 3636 deletions(-) create mode 100644 conf/amf.conf delete mode 100644 conf/groups.conf diff --git a/Makefile b/Makefile index 7287b521..f411c5e7 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ install: install -m 755 exec/aisexec $(SBINDIR) install -m 755 exec/keygen $(SBINDIR)/ais-keygen install -m 755 conf/openais.conf $(ETCDIR) - install -m 755 conf/groups.conf $(ETCDIR) + install -m 755 conf/amf.conf $(ETCDIR) install -m 644 include/saAis.h $(INCLUDEDIR) install -m 644 include/saAmf.h $(INCLUDEDIR) diff --git a/QUICKSTART b/QUICKSTART index 9ead42ea..45c8340c 100644 --- a/QUICKSTART +++ b/QUICKSTART @@ -94,7 +94,7 @@ a message count. Until the man page is done you'll have to check the code and th totem spec for the function and usage of the timeouts. -The directory conf contains the file groups.conf which specifies the failover +The directory conf contains the file amf.conf which specifies the failover groups, service units, components, and policies to be used by the AMF. The configuration file matches the testamf1-6 programs in the test directory and can be copied directly. @@ -212,7 +212,7 @@ su to ais user The test/testamf{1-6} implement three seperate service units (SU). SU #1 consists of testamf1, testamf2. SU #2 consists of testamf3, testamf4. SU #3 consists of testamf5, testamf6. The active and backup directives -in groups.conf define how many SU's become active and how many +in amf.conf define how many SU's become active and how many become standby in the service group (SG). To test the openais AMF, run testamf3 and testamf4 on one node. Both diff --git a/conf/amf.conf b/conf/amf.conf new file mode 100644 index 00000000..1137c83b --- /dev/null +++ b/conf/amf.conf @@ -0,0 +1,133 @@ +# AMF Test configuration file +# - Times in milliseconds +# - clccli_path can be set on any level from application and down and will be +# added to the CLI commands if they are not already specified with an absolute +# path (begins with /). + +safAmfCluster = test_cluster { + saAmfClusterStartupTimeout=10000 + safAmfNode = seasc0036 { + saAmfNodeSuFailOverProb=2000 + saAmfNodeSuFailoverMax=2 + } + safApp = test_app1 { + clccli_path=/tmp/ais/test + safSg = raid { + saAmfSGRedundancyModel=nplusm + saAmfSGNumPrefActiveSUs=1 + saAmfSGMaxActiveSIsperSUs=2 + saAmfSGNumPrefStandbySUs=1 + saAmfSGMaxStandbySIsperSUs=2 + saAmfSGCompRestartProb=100000 + saAmfSGCompRestartMax=3 + saAmfSGSuRestartProb=20000 + saAmfSGSuRestartMax=6 + saAmfSGAutoAdjustProb=5000 + safSu = SU_1 { + saAmfSUNumComponents=1 + safComp = comp_a_in_su_1 { + saAmfCompCategory=sa_aware + saAmfCompCapability=x_active_or_y_standby + saAmfCompNumMaxActiveCsi=1 + saAmfCompNumMaxStandbyCsi=1 + saAmfCompDefaultClcCliTimeout = 500 + saAmfCompDefaultCallbackTimeOut = 500 + saAmfCompInstantiateCmd = /tmp/ais/test/clc_cli_script + saAmfCompInstantiateCmdArgv= instantiate /tmp/ais/test/testamf1 + saAmfCompTerminateCmd = /tmp/ais/test/clc_cli_script + saAmfCompTerminateCmdArgv = terminate + saAmfCompCleanupCmd = /tmp/ais/test/clc_cli_script + saAmfCompCleanupCmdArgv = cleanup + saAmfCompCsTypes { + for_comp_a_x + for_comp_a_y + } + saAmfCompCmdEnv { + var1=val1 + var2=val2 + } + saAmfCompRecoveryOnError=component_restart + safHealthcheckKey = key1 { + saAmfHealthcheckPeriod = 3000 + saAmfHealthcheckMaxDuration = 350 + } + } + } + safSu = SU_2 { + saAmfSUNumComponents=1 + safComp = comp_a_in_su_2 { + saAmfCompCategory=sa_aware + saAmfCompCapability=x_active_or_y_standby + saAmfCompNumMaxActiveCsi=1 + saAmfCompNumMaxStandbyCsi=1 + saAmfCompDefaultClcCliTimeout = 500 + saAmfCompDefaultCallbackTimeOut = 500 + saAmfCompInstantiateCmd = /tmp/ais/test/clc_cli_script + saAmfCompInstantiateCmdArgv= instantiate + saAmfCompTerminateCmd = /tmp/ais/test/clc_cli_script + saAmfCompTerminateCmdArgv = terminate + saAmfCompCleanupCmd = /tmp/ais/test/clc_cli_script + saAmfCompCleanupCmdArgv = cleanup + saAmfCompCsTypes { + for_comp_a_x + for_comp_a_y + } + saAmfCompCmdEnv { + COMP_BINARY_PATH=/tmp/ais/test + COMP_BINARY_NAME=testamf1 + } + saAmfCompRecoveryOnError=component_restart + safHealthcheckKey = key1 { + saAmfHealthcheckPeriod = 3000 + saAmfHealthcheckMaxDuration = 350 + } + safHealthcheckKey = key2 { + saAmfHealthcheckPeriod = 3000 + saAmfHealthcheckMaxDuration = 350 + } + } + } + } + safSi = SI_1 { + saAmfSINumCSIs=2 + safCsi = csi_ax_in_si_1 { + saAmfCSTypeName=for_comp_a_x + } + safCsi = csi_ay_in_si_1 { + saAmfCSTypeName = for_comp_a_y + saAmfCsiDependencies { + saAmfCSIDependency = csi_ax_in_si_1 + } + safCSIAttr = attr1 { + val1 + val2 + } + safCSIAttr = good_health_limit { + 10 + } + } + safRankedSu = SU_1 { + saAmfRank = 1 + } + safRankedSu = SU_2 { + saAmfRank = 2 + } + } + safSi = SI_2 { + saAmfSINumCSIs=1 + safCsi = csi_b_in_si_2 { + saAmfCSTypeName=for_comp_a_x + } + safDepend = SI_1 { + saAmfToleranceTime=10000 + } + } + safCSType = for_comp_a_y { + safAmfCSAttrName = attr1 + safAmfCSAttrName = good_health_limit + } + safCSType = for_comp_a_x { + } + } +} + diff --git a/conf/groups.conf b/conf/groups.conf deleted file mode 100644 index d37e4940..00000000 --- a/conf/groups.conf +++ /dev/null @@ -1,239 +0,0 @@ -# Test configuration file - -group { - name=raid - model=nplusm - preferred-active-units=2 - maximum-active-instances=2 - preferred-standby-units=2 - maximum-standby-instances=4 - clccli_path=/tmp/trunktest/test - binary_path=/tmp/trunktest/test - component_restart_probation=100000 - component_restart_max=4 - unit_restart_probation=200000 - unit_restart_max=6 - - unit { - name=SU_1 - component { - name=comp_a_in_su_1 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_a_x - } - csi_type_name { - name=for_comp_a_y - } - } - component { - name=comp_b_in_su_1 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_b - } - } - } - unit { - name=SU_2 - component { - name=comp_a_in_su_2 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_a_x - } - csi_type_name { - name=for_comp_a_y - } - } - component { - name=comp_b_in_su_2 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_b - } - } - } - unit { - name=SU_3 - component { - name=comp_a_in_su_3 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_a_x - } - csi_type_name { - name=for_comp_a_y - } - } - component { - name=comp_b_in_su_3 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_b - } - } - } - unit { - name=SU_4 - component { - name=comp_a_in_su_4 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_a_x - } - csi_type_name { - name=for_comp_a_y - } - } - component { - name=comp_b_in_su_4 - comptype=sa_aware - bn=testamf1 - instantiate=clc_cli_script - terminate=clc_cli_script - cleanup=clc_cli_script - csi_type_name { - name=for_comp_b - } - } - } - - serviceinstance { - name = SI_1 - csi_descriptor { - csi_name=csi_ax_in_si_1 - type_name=for_comp_a_x - name_value { - name=good_health_limit - value=0 - } - name_value { - name=ax_attr2 - value=ax1_val2 - } - } - csi_descriptor { - csi_name=csi_ay_in_si_1 - type_name=for_comp_a_y - name_value { - name=ay_attr1 - value=ay1_val1 - } - name_value { - name=ay_attr2 - value=ay1_val2 - } - } - csi_descriptor { - csi_name=csi_b_in_si_1 - type_name=for_comp_b - name_value { - name=good_health_limit - value=0 - } - name_value { - name=b_attr2 - value=b1_val2 - } - } - } - serviceinstance { - name = SI_2 - - csi_descriptor { - csi_name=csi_ax_in_si_2 - type_name=for_comp_a_x - name_value { - name=good_health_limit - value=10 - } - name_value { - name=ax_attr2 - value=ax2_val2 - } - } - csi_descriptor { - csi_name=csi_b_in_si_2 - type_name=for_comp_b - name_value { - name=good_health_limit - value=0 - } - name_value { - name=b_attr2 - value=b2_val2 - } - } - csi_descriptor { - csi_name=csi_ay_in_si_2 - type_name=for_comp_a_y - name_value { - name=ay_attr1 - value=ay2_val1 - } - name_value { - name=ay_attr2 - value=ay2_val2 - } - } - } -# serviceinstance { -# name = sibb -# } -# serviceinstance { -# name = sicc -# } -# serviceinstance { -# name = sidd -# } -# serviceinstance { -# name = side -# } -# serviceinstance { -# name = sidf -# } -} -healthcheck { - key = key1 - period = 500 - maximum_duration = 550 -} -healthcheck { - key = key2 - period = 2000 - maximum_duration = 250 -} -healthcheck { - key = key3 - period = 3000 - maximum_duration = 350 -} diff --git a/exec/aisparser.c b/exec/aisparser.c index 454dce59..4aa7663c 100644 --- a/exec/aisparser.c +++ b/exec/aisparser.c @@ -49,6 +49,7 @@ #include "objdb.h" #include "config.h" #include "mempool.h" +#include "util.h" static int read_config_file_into_objdb( struct objdb_iface_ver0 *objdb, @@ -66,7 +67,7 @@ static int aisparser_readconfig (struct objdb_iface_ver0 *objdb, char **error_st } -char *remove_whitespace(char *string) +static char *remove_whitespace(char *string) { char *start = string+strspn(string, " \t"); char *end = start+(strlen(start))-1; @@ -79,34 +80,6 @@ char *remove_whitespace(char *string) return start; } -char *strstr_rs (const char *haystack, const char *needle) -{ - char *end_address; - char *new_needle; - - new_needle = (char *)mempool_strdup (needle); - new_needle[strlen(new_needle) - 1] = '\0'; - - end_address = strstr (haystack, new_needle); - if (end_address) { - end_address += strlen (new_needle); - end_address = strstr (end_address, needle + strlen (new_needle)); - } - if (end_address) { - end_address += 1; /* skip past { or = */ - do { - if (*end_address == '\t' || *end_address == ' ') { - end_address++; - } else { - break; - } - } while (*end_address != '\0'); - } - - mempool_free (new_needle); - return (end_address); -} - static int parse_section(FILE *fp, struct objdb_iface_ver0 *objdb, unsigned int parent_handle, diff --git a/exec/aispoll.c b/exec/aispoll.c index dfade13b..0a8ac5a5 100644 --- a/exec/aispoll.c +++ b/exec/aispoll.c @@ -295,13 +295,13 @@ int poll_timer_add ( goto error_exit; } - timerlist_add_future (&poll_instance->timerlist, - timer_fn, data, msec_in_future, timer_handle_out); - if (timer_handle_out == 0) { res = -ENOENT; } + timerlist_add_future (&poll_instance->timerlist, + timer_fn, data, msec_in_future, timer_handle_out); + hdb_handle_put (&poll_instance_database, handle); error_exit: return (res); diff --git a/exec/amf.c b/exec/amf.c index af9e6dd3..34862285 100644 --- a/exec/amf.c +++ b/exec/amf.c @@ -1,9 +1,13 @@ /* * Copyright (c) 2002-2006 MontaVista Software, Inc. + * Author: Steven Dake (sdake@mvista.com) + * + * Copyright (c) 2006 Ericsson AB. + * Author: Hans Feldt + * Description: Introduced AMF B.02 information model * * All rights reserved. * - * Author: Steven Dake (sdake@mvista.com) * * This software licensed under BSD license, the text of which follows: * @@ -54,7 +58,6 @@ #include "../include/ipc_gen.h" #include "../include/ipc_amf.h" #include "../include/list.h" -#include "../include/queue.h" #include "../lcr/lcr_comp.h" #include "totempg.h" #include "aispoll.h" @@ -84,10 +87,10 @@ struct invocation { int active; }; -struct invocation *invocation_entries = 0; +static struct invocation *invocation_entries = 0; -int invocation_entries_size = 0; -int waiting = 0; +static int invocation_entries_size = 0; +static int waiting = 0; enum amf_response_interfaces { AMF_RESPONSE_HEALTHCHECKCALLBACK = 1, @@ -110,23 +113,6 @@ struct component_terminate_callback_data { struct amf_comp *comp; }; -struct healthcheck_active { - SaAmfHealthcheckKeyT key; - SaAmfHealthcheckInvocationT invocationType; - SaAmfRecommendedRecoveryT recommendedRecovery; - struct amf_comp *comp; - struct amf_healthcheck *healthcheck; - poll_timer_handle timer_healthcheck_duration; - poll_timer_handle timer_healthcheck_period; - struct list_head list; - int active; -}; - -static char *presencestate_ntoa (SaAmfPresenceStateT state); -static char *operationalstate_ntoa (SaAmfOperationalStateT state); -static char *hastate_ntoa (SaAmfHAStateT state); -static char *readinessstate_ntoa (int state); - static void amf_confchg_fn ( enum totem_configuration_type configuration_type, struct totem_ip_address *member_list, int member_list_entries, @@ -158,7 +144,7 @@ static void message_handler_req_lib_amf_hastateget (void *conn, void *message); static void message_handler_req_lib_amf_csiquiescingcomplete (void *conn, void *msg); -static void message_handler_req_lib_amf_protectiongrouptrackstart (void *conn, void *msg); +static void message_handler_req_lib_amf_protectiongrouptrack (void *conn, void *msg); static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg); @@ -188,35 +174,77 @@ static void message_handler_req_exec_amf_administrative_state_group_set ( void *message, struct totem_ip_address *source); -void presence_state_comp_set ( +static void presence_state_comp_set ( struct amf_comp *comp, SaAmfPresenceStateT presence_state); -void operational_state_comp_set ( +static void operational_state_comp_set ( struct amf_comp *comp, SaAmfOperationalStateT operational_state); -void operational_state_unit_set ( - struct amf_unit *unit, +static void operational_state_unit_set ( + struct amf_su *unit, SaAmfOperationalStateT operational_state); -int clc_instantiate_all (void); -int clc_instantiate (struct amf_comp *comp); -int clc_terminate (struct amf_comp *comp); - -int clc_cli_instantiate (struct amf_comp *comp); -int clc_instantiate_callback (struct amf_comp *comp); -int clc_csi_set_callback (struct amf_comp *comp); -int clc_cli_terminate (struct amf_comp *comp); -int clc_terminate_callback (struct amf_comp *comp); -int clc_csi_remove_callback (struct amf_comp *comp); -int clc_cli_cleanup (struct amf_comp *comp); -int clc_cli_cleanup_local (struct amf_comp *comp); -void healthcheck_activate (struct healthcheck_active *healthcheck_active); -void healthcheck_deactivate (struct healthcheck_active *healthcheck_active); -void comp_healthcheck_activate (struct amf_comp *comp); -void comp_healthcheck_deactivate (struct amf_comp *comp); +static void assign_sis (struct amf_sg *group); +static void clc_instantiate_all (void *data); +static int clc_instantiate (struct amf_comp *comp); +#if 0 +static int clc_terminate (struct amf_comp *comp); +#endif +static int clc_cli_instantiate (struct amf_comp *comp); +static int clc_instantiate_callback (struct amf_comp *comp); +static int clc_csi_set_callback (struct amf_comp *comp); +static int clc_cli_terminate (struct amf_comp *comp); +static int clc_terminate_callback (struct amf_comp *comp); +static int clc_csi_remove_callback (struct amf_comp *comp); +static int clc_cli_cleanup (struct amf_comp *comp); +static int clc_cli_cleanup_local (struct amf_comp *comp); +static void healthcheck_activate (struct amf_healthcheck *healthcheck_active); +static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active); +static void comp_healthcheck_activate (struct amf_comp *comp); +static void comp_healthcheck_deactivate (struct amf_comp *comp); static void escalation_policy_restart (struct amf_comp *comp); +static void amf_dump(void); + +static char *presence_state_text[] = { + "unknown", + "uninstantiated", + "instantiating", + "instantiated", + "terminating", + "restarting", + "instantion_failed", + "terminiation_failed" +}; + +static char *oper_state_text[] = { + "Unknown", + "enabled", + "disabled" +}; + +static char *admin_state_text[] = { + "Unknown", + "unlocked", + "locked", + "locked_instantiation", + "shutting_down" +}; + +static char *readiness_state_text[] = { + "Unknown", + "out of service", + "in service", +}; + +static char *ha_state_text[] = { + "Unknown", + "active", + "standby", + "quiesced", + "quiescing", +}; struct libamf_ci_trackentry { int active; @@ -246,31 +274,31 @@ struct clc_interface { /* * Life cycle functions */ -struct clc_interface clc_interface_sa_aware = { +static struct clc_interface clc_interface_sa_aware = { clc_cli_instantiate, clc_terminate_callback, clc_cli_cleanup }; -struct clc_interface clc_interface_proxied_pre = { +static struct clc_interface clc_interface_proxied_pre = { clc_instantiate_callback, clc_terminate_callback, clc_cli_cleanup }; -struct clc_interface clc_interface_proxied_non_pre = { +static struct clc_interface clc_interface_proxied_non_pre = { clc_csi_set_callback, clc_csi_remove_callback, clc_cli_cleanup_local }; -struct clc_interface clc_interface_non_proxied_non_saware = { +static struct clc_interface clc_interface_non_proxied_non_saware = { clc_cli_instantiate, clc_cli_terminate, clc_cli_cleanup_local }; -struct clc_interface *clc_interfaces[4] = { +static struct clc_interface *clc_interfaces[4] = { &clc_interface_sa_aware, &clc_interface_proxied_pre, &clc_interface_proxied_non_pre, @@ -337,9 +365,9 @@ static struct openais_lib_handler amf_lib_service[] = .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED }, { /* 9 */ - .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstart, - .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstart), - .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART, + .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrack, + .response_size = sizeof (struct res_lib_amf_protectiongrouptrack), + .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK, .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED }, { /* 10 */ @@ -386,32 +414,34 @@ static struct openais_exec_handler amf_exec_service[] = { } }; -void amf_dump(void); /* * Exports the interface for the service */ -struct openais_service_handler amf_service_handler = { +static struct openais_service_handler amf_service_handler = { .name = (unsigned char *)"openais availability management framework B.01.01", - .id = AMF_SERVICE, - .private_data_size = sizeof (struct amf_pd), - .lib_init_fn = amf_lib_init_fn, - .lib_exit_fn = amf_lib_exit_fn, - .lib_service = amf_lib_service, - .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler), - .exec_init_fn = amf_exec_init_fn, - .exec_service = amf_exec_service, - .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler), + .id = AMF_SERVICE, + .private_data_size = sizeof (struct amf_pd), + .lib_init_fn = amf_lib_init_fn, + .lib_exit_fn = amf_lib_exit_fn, + .lib_service = amf_lib_service, + .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler), + .exec_init_fn = amf_exec_init_fn, + .exec_service = amf_exec_service, + .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler), .confchg_fn = amf_confchg_fn, - .exec_dump_fn = amf_dump + .exec_dump_fn = amf_dump }; -struct openais_service_handler *amf_get_handler_ver0 (void); +static struct amf_node *this_amf_node; +static struct amf_cluster amf_cluster; -struct openais_service_handler_iface_ver0 amf_service_handler_iface = { +static struct openais_service_handler *amf_get_handler_ver0 (void); + +static struct openais_service_handler_iface_ver0 amf_service_handler_iface = { .openais_get_service_handler_ver0 = amf_get_handler_ver0 }; -struct lcr_iface openais_amf_ver0[1] = { +static struct lcr_iface openais_amf_ver0[1] = { { .name = "openais_amf", .version = 0, @@ -425,12 +455,12 @@ struct lcr_iface openais_amf_ver0[1] = { } }; -struct lcr_comp amf_comp_ver0 = { +static struct lcr_comp amf_comp_ver0 = { .iface_count = 1, .ifaces = openais_amf_ver0 }; -struct openais_service_handler *amf_get_handler_ver0 (void) +static struct openais_service_handler *amf_get_handler_ver0 (void) { return (&amf_service_handler); } @@ -453,7 +483,7 @@ struct clc_command_run_data { void (*completion_callback) (void *context); }; -int invocation_create ( +static int invocation_create ( int interface, void *data) { @@ -487,7 +517,7 @@ int invocation_create ( return (loc); } -int invocation_get_and_destroy (int invocation, int *interface, +static int invocation_get_and_destroy (int invocation, int *interface, void **data) { if (invocation > invocation_entries_size) { @@ -504,7 +534,7 @@ int invocation_get_and_destroy (int invocation, int *interface, return (0); } -void invocation_destroy_by_data (void *data) +static void invocation_destroy_by_data (void *data) { int i; @@ -517,26 +547,23 @@ void invocation_destroy_by_data (void *data) } } - -void *clc_command_run (void *context) +static void *clc_command_run (void *context) { - struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context; + struct clc_command_run_data *clc_command_run_data = + (struct clc_command_run_data *)context; pid_t pid; int res; char *argv[10]; char *envp[10]; int status; - char cmd[1024]; - char env_comp_binary_name[1024]; - char env_comp_binary_path[1024]; + char path[PATH_MAX]; + char *cmd = 0; + char *comp_argv = 0; char env_comp_name[1024]; - char *binary_to_run = NULL; - char *binary_path = NULL; - char *clc_cli_interface = NULL; + int i; - sleep (1); + ENTER_VOID(); - dprintf ("clc_command_run()\n"); pid = fork(); if (pid == -1) { @@ -556,82 +583,80 @@ void *clc_command_run (void *context) switch (clc_command_run_data->type) { case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE: - binary_to_run = clc_command_run_data->comp->instantiate_cmd; - clc_cli_interface = "CLC_CLI_INTERFACE=instantiate"; + cmd = clc_command_run_data->comp->saAmfCompInstantiateCmd; + comp_argv = clc_command_run_data->comp->saAmfCompInstantiateCmdArgv; break; case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE: - binary_to_run = clc_command_run_data->comp->terminate_cmd; - clc_cli_interface = "CLC_CLI_INTERFACE=terminate"; + cmd = clc_command_run_data->comp->saAmfCompTerminateCmd; + comp_argv = clc_command_run_data->comp->saAmfCompTerminateCmdArgv; break; case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP: - binary_to_run = clc_command_run_data->comp->cleanup_cmd; - clc_cli_interface = "CLC_CLI_INTERFACE=cleanup"; + cmd = clc_command_run_data->comp->saAmfCompCleanupCmd; + comp_argv = clc_command_run_data->comp->saAmfCompCleanupCmdArgv; break; default: assert (0 != 1); break; } - if (strlen (clc_command_run_data->comp->clccli_path)) { - sprintf (cmd, "%s/%s", - clc_command_run_data->comp->clccli_path, - binary_to_run); - } else - if (strlen (clc_command_run_data->comp->unit->clccli_path)) { - sprintf (cmd, "%s/%s", - clc_command_run_data->comp->unit->clccli_path, - binary_to_run); - } else { - sprintf (cmd, "%s/%s", - clc_command_run_data->comp->unit->amf_group->clccli_path, - binary_to_run); - } - - if (strlen (clc_command_run_data->comp->binary_path)) { - binary_path = clc_command_run_data->comp->binary_path; - } else - if (strlen (clc_command_run_data->comp->unit->binary_path)) { - binary_path = clc_command_run_data->comp->unit->binary_path; - } else { - binary_path = clc_command_run_data->comp->unit->amf_group->binary_path; + /* If command is not an absolute path, search for paths in parent objects */ + if (cmd[0] != '/') { + if (strlen (clc_command_run_data->comp->clccli_path)) { + sprintf (path, "%s/%s", + clc_command_run_data->comp->clccli_path, cmd); + } else if (strlen (clc_command_run_data->comp->su->clccli_path)) { + sprintf (path, "%s/%s", + clc_command_run_data->comp->su->clccli_path, cmd); + } else if (strlen (clc_command_run_data->comp->su->sg->clccli_path)) { + sprintf (path, "%s/%s", + clc_command_run_data->comp->su->sg->clccli_path, cmd); + } else if (strlen (clc_command_run_data->comp->su->sg->application->clccli_path)) { + sprintf (path, "%s/%s", + clc_command_run_data->comp->su->sg->application->clccli_path, cmd); + } + cmd = path; } argv[0] = cmd; - argv[1] = '\0'; - - envp[0] = cmd; - envp[1] = clc_cli_interface; - envp[2] = env_comp_binary_name; - envp[3] = env_comp_binary_path; - envp[4] = env_comp_name; - envp[5] = '\0'; - - sprintf (env_comp_binary_name, "COMP_BINARY_NAME=%s", - clc_command_run_data->comp->binary_name); - - sprintf (env_comp_binary_path, "COMP_BINARY_PATH=%s", - binary_path); + { + /* make a proper argv array */ + i = 1; + char *ptrptr; + char *arg = strtok_r(comp_argv, " ", &ptrptr); + while (arg) { + argv[i] = arg; + arg = strtok_r(NULL, " ", & ptrptr); + i++; + } + } + argv[i] = NULL; + envp[0] = env_comp_name; strcpy (env_comp_name, "SA_AMF_COMPONENT_NAME="); - strncat (env_comp_name, (char *)clc_command_run_data->comp->name.value, clc_command_run_data->comp->name.length); - if (cmd[0] == '\0') { - return (0); + for (i = 1; clc_command_run_data->comp->saAmfCompCmdEnv && + clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; i++) { + envp[i] = clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; } + envp[i] = NULL; + dprintf ("running command '%s' with environment:\n", cmd); - dprintf ("0 %s\n", envp[0]); - dprintf ("1 %s\n", envp[1]); - dprintf ("2 %s\n", envp[2]); - dprintf ("3 %s\n", envp[3]); - dprintf ("4 %s\n", envp[4]); + for (i = 0; envp[i] != NULL; i++) { + dprintf (" %s\n", envp[i]); + } + dprintf (" and argv:\n", cmd); + for (i = 0; argv[i] != NULL; i++) { + dprintf (" %s\n", argv[i]); + } res = execve (cmd, argv, envp); if (res == -1) { - dprintf ("Couldn't exec process %d=%s\n", errno, strerror (errno)); + log_printf (LOG_LEVEL_ERROR, "Couldn't exec program %s (%s)\n", + cmd, strerror (errno)); } assert (res != -1); return (0); @@ -674,10 +699,11 @@ struct req_exec_amf_comp_restart { /* * Instantiate possible operations */ -int clc_cli_instantiate (struct amf_comp *comp) +static int clc_cli_instantiate (struct amf_comp *comp) { int res; pthread_t thread; + pthread_attr_t thread_attr; /* thread attribute */ struct clc_command_run_data *clc_command_run_data; @@ -687,19 +713,23 @@ int clc_cli_instantiate (struct amf_comp *comp) clc_command_run_data->comp = comp; clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE; clc_command_run_data->completion_callback = NULL; - res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data); - pthread_detach (thread); + pthread_attr_init (&thread_attr); + pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED); + res = pthread_create (&thread, &thread_attr, clc_command_run, (void *)clc_command_run_data); + if (res != 0) { + log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res); + } // TODO error code from pthread_create return (res); } -int clc_instantiate_callback (struct amf_comp *comp) +static int clc_instantiate_callback (struct amf_comp *comp) { ENTER("comp %s\n", getSaNameT (&comp->name)); return (0); } -int clc_csi_set_callback (struct amf_comp *comp) +static int clc_csi_set_callback (struct amf_comp *comp) { ENTER("comp %s\n", getSaNameT (&comp->name)); return (0); @@ -708,27 +738,28 @@ int clc_csi_set_callback (struct amf_comp *comp) /* * Terminate possible operations */ -int clc_cli_terminate (struct amf_comp *comp) +static int clc_cli_terminate (struct amf_comp *comp) { ENTER("comp %s\n", getSaNameT (&comp->name)); return (0); } -int clc_terminate_callback (struct amf_comp *comp) + +static int clc_terminate_callback (struct amf_comp *comp) { struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback; struct component_terminate_callback_data *component_terminate_callback_data; ENTER("comp %s\n", getSaNameT (&comp->name)); - if (comp->presence_state != SA_AMF_PRESENCE_INSTANTIATED) { + if (comp->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) { dprintf ("component terminated but not instantiated %s - %d\n", - getSaNameT (&comp->name), comp->presence_state); + getSaNameT (&comp->name), comp->saAmfCompPresenceState); assert (0); return (0); } dprintf ("component name terminating %s\n", getSaNameT (&comp->name)); - dprintf ("component presence state %d\n", comp->presence_state); + dprintf ("component presence state %d\n", comp->saAmfCompPresenceState); res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK; res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback); @@ -758,7 +789,7 @@ int clc_terminate_callback (struct amf_comp *comp) return (0); } -int clc_csi_remove_callback (struct amf_comp *comp) +static int clc_csi_remove_callback (struct amf_comp *comp) { dprintf ("clc_tcsi_remove_callback\n"); return (0); @@ -767,7 +798,7 @@ int clc_csi_remove_callback (struct amf_comp *comp) /* * This reinstantiates the cleaned up component */ -void clc_cleanup_completion_callback (void *context) { +static void clc_cleanup_completion_callback (void *context) { struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context; escalation_policy_restart (clc_command_run_data->comp); @@ -776,10 +807,11 @@ void clc_cleanup_completion_callback (void *context) { /* * Cleanup possible operations */ -int clc_cli_cleanup (struct amf_comp *comp) +static int clc_cli_cleanup (struct amf_comp *comp) { int res; pthread_t thread; + pthread_attr_t thread_attr; /* thread attribute */ struct clc_command_run_data *clc_command_run_data; @@ -789,20 +821,23 @@ int clc_cli_cleanup (struct amf_comp *comp) clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP; clc_command_run_data->completion_callback = clc_cleanup_completion_callback; - res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data); - pthread_detach (thread); + pthread_attr_init (&thread_attr); + pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED); + res = pthread_create (&thread, &thread_attr, clc_command_run, (void *)clc_command_run_data); + if (res != 0) { + log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res); + } // TODO error code from pthread_create return (res); - return (0); } -int clc_cli_cleanup_local (struct amf_comp *comp) +static int clc_cli_cleanup_local (struct amf_comp *comp) { dprintf ("clc_cli_cleanup_local\n"); return (0); } -int clc_instantiate (struct amf_comp *comp) +static int clc_instantiate (struct amf_comp *comp) { int res; @@ -813,7 +848,8 @@ int clc_instantiate (struct amf_comp *comp) return (res); } -int clc_terminate (struct amf_comp *comp) +#if 0 +static int clc_terminate (struct amf_comp *comp) { int res; @@ -825,8 +861,9 @@ int clc_terminate (struct amf_comp *comp) res = clc_interfaces[comp->comptype]->terminate (comp); return (0); } +#endif -int clc_cleanup (struct amf_comp *comp) +static int clc_cleanup (struct amf_comp *comp) { int res; @@ -847,6 +884,15 @@ static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb) unsigned int object_service_handle; int enabled = 0; char *value; + char hostname[HOST_NAME_MAX + 1]; + struct amf_node *node; + struct amf_application *app; + struct amf_sg *sg; + struct amf_su *su; + struct amf_comp *comp; + struct amf_si *si; + struct amf_csi *csi; + int i; log_init ("AMF"); @@ -873,15 +919,76 @@ static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb) } } - if (enabled) { - res = openais_amf_config_read (&error_string); - if (res == -1) { - log_printf (LOG_LEVEL_ERROR, error_string); - return res; - } - - clc_instantiate_all (); + if (!enabled) { + return 0; } + + if (gethostname (hostname, sizeof(hostname)) == -1) { + log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno); + return -1; + } + + res = amf_config_read (&amf_cluster, &error_string); + if (res == -1) { + log_printf (LOG_LEVEL_ERROR, error_string); + return res; + } + + dprintf("Cluster: %s", getSaNameT(&amf_cluster.name)); + dprintf(" timeout: %d ms\n", amf_cluster.saAmfClusterStartupTimeout); + dprintf(" admin state: %s\n", admin_state_text[amf_cluster.saAmfClusterAdminState]); + for (node = amf_cluster.node_head; node != NULL; node = node->next) { + dprintf(" Node: %s\n", getSaNameT (&node->name)); + dprintf(" su_fail_over_prob: %u\n", node->saAmfNodeSuFailOverProb); + dprintf(" su_fail_over_max: %u\n", node->saAmfNodeSuFailoverMax); + dprintf(" auto repair: %u\n", node->saAmfNodeAutoRepair); + + /* look for this node */ + if (strcmp(hostname, getSaNameT (&node->name)) == 0) { + this_amf_node = node; + } + } + for (app = amf_cluster.application_head; app != NULL; app = app->next) { + dprintf(" Application: %s\n", getSaNameT(&app->name)); + dprintf(" num_sg: %d\n", app->saAmfApplicationCurrNumSG); + for (sg = app->sg_head; sg != NULL; sg = sg->next) { + dprintf(" SG: %s\n", getSaNameT(&sg->name)); + dprintf(" red model: %u\n", sg->saAmfSGRedundancyModel); + dprintf(" auto adjust: %u\n", sg->saAmfSGAutoAdjust); + for (su = sg->su_head; su != NULL; su = su->next) { + dprintf(" SU: %s\n", getSaNameT(&su->name)); + dprintf(" rank: %u\n", su->saAmfSURank); + for (comp = su->comp_head; comp != NULL; comp = comp->next) { + dprintf(" Comp: %s\n", getSaNameT(&comp->name)); + dprintf(" category: %u\n", comp->saAmfCompCategory); + dprintf(" env vars:"); + i = 0; + while (comp->saAmfCompCmdEnv && comp->saAmfCompCmdEnv[i]) { + dprintf(" %s", comp->saAmfCompCmdEnv[i]); + i++; + } + } + } + } + for (si = app->si_head; si != NULL; si = si->next) { + dprintf(" SI: %s\n", getSaNameT(&si->name)); + for (csi = si->csi_head; csi != NULL; csi = csi->next) { + dprintf(" CSI: %s\n", getSaNameT(&csi->name)); + } + } + } + + if (this_amf_node != NULL) { + /* wait a while before instantiating SUs as the AMF spec. says. */ + poll_timer_add(aisexec_poll_handle, + amf_cluster.saAmfClusterStartupTimeout, + NULL, + clc_instantiate_all, + &amf_cluster.timeout_handle); + } else { + log_printf (LOG_LEVEL_INFO, "This CLM node (%s) is not configured as an AMF node, disabling...", hostname); + } + return (0); } static void amf_confchg_fn ( @@ -891,7 +998,6 @@ static void amf_confchg_fn ( struct totem_ip_address *joined_list, int joined_list_entries, struct memb_ring_id *ring_id) { - #ifdef COMPILE_OUT int i; @@ -923,7 +1029,7 @@ static void amf_confchg_fn ( #endif } -int amf_lib_exit_fn (void *conn) +static int amf_lib_exit_fn (void *conn) { struct amf_comp *comp; struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn); @@ -934,18 +1040,9 @@ int amf_lib_exit_fn (void *conn) if (comp) { comp->conn = 0; - - dprintf ("setting in exit fn to uninst for comp %p\n", comp); - presence_state_comp_set ( - comp, - SA_AMF_PRESENCE_UNINSTANTIATED); - - operational_state_comp_set ( - comp, - SA_AMF_OPERATIONAL_DISABLED); - - comp_healthcheck_deactivate (comp); + dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name)); } + return (0); } @@ -969,8 +1066,8 @@ static void amf_synchronize (void *message, struct in_addr source_addr) getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName)); /* Find Component */ - component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName); - amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName); + component = amf_find_comp (&amf_cluster, &req_exec_amf_componentregister->req_lib_amf_componentregister.compName); + amfProxyComponent = amf_find_comp (&amf_cluster, &req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName); /* If this processor is component owner */ if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) { @@ -1016,7 +1113,7 @@ static void amf_synchronize (void *message, struct in_addr source_addr) } #endif -DECLARE_LIST_INIT (library_notification_send_listhead); +static DECLARE_LIST_INIT (library_notification_send_listhead); // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle; @@ -1270,8 +1367,8 @@ static void TODO_COMP_RESTART_THISISADEADPLACEHOLDER (struct amf_comp *comp) #endif #define INVOCATION_DONT_COMPARE 0xFFFFFFFFULL - -struct healthcheck_active *find_healthcheck_active ( +#if 0 +static struct healthcheck_active *find_healthcheck_active ( struct amf_comp *comp, SaAmfHealthcheckKeyT *key, SaAmfHealthcheckInvocationT invocation) @@ -1280,8 +1377,8 @@ struct healthcheck_active *find_healthcheck_active ( struct healthcheck_active *ret_healthcheck_active = 0; struct healthcheck_active *healthcheck_active; - for (list = comp->healthcheck_list.next; - list != &comp->healthcheck_list; + for (list = comp->healthcheck_head.next; + list != &comp->healthcheck_head; list = list->next) { healthcheck_active = list_entry (list, @@ -1299,49 +1396,40 @@ struct healthcheck_active *find_healthcheck_active ( } return (ret_healthcheck_active); } +#endif -void comp_healthcheck_activate ( - struct amf_comp *comp) +static void comp_healthcheck_activate (struct amf_comp *comp) { - struct list_head *key_list; - struct healthcheck_active *healthcheck_active; + struct amf_healthcheck *healthcheck; - for (key_list = comp->healthcheck_list.next; - key_list != &comp->healthcheck_list; - key_list = key_list->next) { + for (healthcheck = comp->healthcheck_head; + healthcheck != NULL; + healthcheck = healthcheck->next) { - healthcheck_active = list_entry (key_list, - struct healthcheck_active, list); - - if (healthcheck_active->active == 0) { - healthcheck_activate (healthcheck_active); + if (healthcheck->active == 0) { + healthcheck_activate (healthcheck); } } } -void comp_healthcheck_deactivate ( +static void comp_healthcheck_deactivate ( struct amf_comp *comp) { - struct list_head *list; - struct list_head *next; - struct healthcheck_active *healthcheck_active; + struct amf_healthcheck *healthcheck; log_printf (LOG_LEVEL_NOTICE, "ZZZ comp_healthcheck_deactivate %s\n", getSaNameT (&comp->name)); - for (list = comp->healthcheck_list.next, next = list->next; - list != &comp->healthcheck_list; - list = next, next = list->next) { + for (healthcheck = comp->healthcheck_head; + healthcheck != NULL; + healthcheck = healthcheck->next) { - healthcheck_active = list_entry (list, - struct healthcheck_active, list); - - dprintf ("healthcheck deactivating %p\n", healthcheck_active); - healthcheck_deactivate (healthcheck_active); + dprintf ("healthcheck deactivating %p\n", healthcheck); + healthcheck_deactivate (healthcheck); } } -void presence_state_comp_set ( +static void presence_state_comp_set ( struct amf_comp *comp, SaAmfPresenceStateT presence_state) { @@ -1363,30 +1451,30 @@ void presence_state_comp_set ( &iovec, 1, TOTEMPG_AGREED) == 0); } -void readiness_state_comp_set (struct amf_comp *comp) +static void readiness_state_comp_set (struct amf_comp *comp) { dprintf ("inputs to readiness_state_comp_set\n"); dprintf ("\tunit readiness state %s\n", - readinessstate_ntoa (comp->unit->readiness_state)); + readiness_state_text[comp->su->saAmfSUReadinessState]); dprintf ("\tcomp operational state %s\n", - operationalstate_ntoa (comp->unit->readiness_state)); + oper_state_text[comp->su->saAmfSUReadinessState]); /* * Set component readiness state appropriately * if unit in service and component is enabled, it is in service * otherwise it is out of service page 37 */ - if (comp->unit->readiness_state == SA_AMF_READINESS_IN_SERVICE && - comp->operational_state == SA_AMF_OPERATIONAL_ENABLED) { - comp->readiness_state = SA_AMF_READINESS_IN_SERVICE; + if (comp->su->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE && + comp->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) { + comp->saAmfCompReadinessState = SA_AMF_READINESS_IN_SERVICE; } else { - comp->readiness_state = SA_AMF_READINESS_OUT_OF_SERVICE; + comp->saAmfCompReadinessState = SA_AMF_READINESS_OUT_OF_SERVICE; } dprintf ("readiness_state_comp_set (%s)\n", - operationalstate_ntoa (comp->operational_state)); + oper_state_text[comp->saAmfCompOperState]); } -void operational_state_comp_set (struct amf_comp *comp, SaAmfOperationalStateT operational_state) +static void operational_state_comp_set (struct amf_comp *comp, SaAmfOperationalStateT oper_state) { struct req_exec_amf_operational_state_comp_set req_exec_amf_operational_state_comp_set; struct iovec iovec; @@ -1395,7 +1483,7 @@ void operational_state_comp_set (struct amf_comp *comp, SaAmfOperationalStateT o req_exec_amf_operational_state_comp_set.header.id = SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET); - req_exec_amf_operational_state_comp_set.operational_state = operational_state; + req_exec_amf_operational_state_comp_set.operational_state = oper_state; memcpy (&req_exec_amf_operational_state_comp_set.name, &comp->name, sizeof (SaNameT)); @@ -1407,131 +1495,98 @@ void operational_state_comp_set (struct amf_comp *comp, SaAmfOperationalStateT o &iovec, 1, TOTEMPG_AGREED) == 0); } -void csi_comp_set_callback ( +static void csi_comp_set_callback ( struct amf_comp *comp, struct amf_csi *csi, struct amf_pg *pg) { - struct list_head *name_value_list; - struct res_lib_amf_csisetcallback* res_lib_amf_csisetcallback; + struct res_lib_amf_csisetcallback* res_lib_amf_csisetcallback; void* p; - struct csi_set_callback_data *csi_set_callback_data; - struct amf_csi_name_value *name_value; - - - - size_t char_legnth_of_csi_attrs=0; + struct amf_csi_attribute *attribute; + size_t char_length_of_csi_attrs=0; size_t num_of_csi_attrs=0; + int i; + dprintf("\t Assigning CSI %s to component\n", getSaNameT (&csi->name)); - for (name_value_list = csi->name_value_head.next; - name_value_list != &csi->name_value_head; - name_value_list = name_value_list->next) { - num_of_csi_attrs++; - name_value = list_entry (name_value_list, struct amf_csi_name_value, csi_name_list); - dprintf("\t\tname = %s, value = %s\n", name_value->name, name_value->value); - char_legnth_of_csi_attrs += strlen(name_value->name); - char_legnth_of_csi_attrs += strlen(name_value->value); - char_legnth_of_csi_attrs += 2; + for (attribute = csi->attributes_head; + attribute != NULL; + attribute = attribute->next) { + for (i = 0; attribute->value[i] != NULL; i++) { + num_of_csi_attrs++; + char_length_of_csi_attrs += strlen(attribute->name); + char_length_of_csi_attrs += strlen(attribute->value[i]); + char_length_of_csi_attrs += 2; + } } p = malloc(sizeof(struct res_lib_amf_csisetcallback)+ - char_legnth_of_csi_attrs); - + char_length_of_csi_attrs); assert(p); res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback*)p; - - - - /* Address of the buffer containing the Csi name value pair */ char* csi_attribute_buf = res_lib_amf_csisetcallback->csi_attr_buf; - + /* Byteoffset start at the zero byte */ + unsigned int byte_offset = 0; + for (attribute = csi->attributes_head; + attribute != NULL; + attribute = attribute->next) { + for (i = 0; attribute->value[i] != NULL; i++) { + strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->name); + byte_offset += strlen(attribute->name) + 1; + strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->value[i]); + byte_offset += strlen(attribute->value[i]) + 1; + } + } - /* Byteoffset start att the zero byte */ - unsigned int byte_offset = 0; + res_lib_amf_csisetcallback->number = num_of_csi_attrs; + res_lib_amf_csisetcallback->csiFlags = SA_AMF_CSI_ADD_ONE; - for (name_value_list = csi->name_value_head.next; - name_value_list != &csi->name_value_head; - name_value_list = name_value_list->next) { - - name_value = list_entry (name_value_list, struct amf_csi_name_value, csi_name_list); - - strcpy(&csi_attribute_buf[byte_offset], - (char*)name_value->name); - - byte_offset += strlen(name_value->name) + 1; - - strcpy(&csi_attribute_buf[byte_offset], - (char*)name_value->value); - - byte_offset += strlen(name_value->value) + 1; - } - - res_lib_amf_csisetcallback->number = num_of_csi_attrs; - - - res_lib_amf_csisetcallback->csiFlags = SA_AMF_CSI_ADD_ONE; - - switch (comp->unit->requested_ha_state) { - case SA_AMF_HA_ACTIVE: - { + switch (comp->su->requested_ha_state) { + case SA_AMF_HA_ACTIVE: { res_lib_amf_csisetcallback->csiStateDescriptor.activeDescriptor.activeCompName.length = 0; res_lib_amf_csisetcallback->csiStateDescriptor.activeDescriptor.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN; break; } - case SA_AMF_HA_STANDBY: - { - + case SA_AMF_HA_STANDBY: { res_lib_amf_csisetcallback->csiStateDescriptor.standbyDescriptor.activeCompName.length = 0; res_lib_amf_csisetcallback->csiStateDescriptor.standbyDescriptor.standbyRank = 1; - - break; } - case SA_AMF_HA_QUIESCED: - { + case SA_AMF_HA_QUIESCED: { /*TODO*/ break; } - case SA_AMF_HA_QUIESCING: - { + case SA_AMF_HA_QUIESCING: { /*TODO*/ break; } - default: - { + default: { assert(SA_AMF_HA_ACTIVE||SA_AMF_HA_STANDBY||SA_AMF_HA_QUIESCING||SA_AMF_HA_QUIESCED); break; } - - } - + } - res_lib_amf_csisetcallback->header.id = - MESSAGE_RES_AMF_CSISETCALLBACK; - - res_lib_amf_csisetcallback->header.size = - sizeof (struct res_lib_amf_csisetcallback)+ - char_legnth_of_csi_attrs; - - res_lib_amf_csisetcallback->header.error = SA_AIS_OK; - + res_lib_amf_csisetcallback->header.id = MESSAGE_RES_AMF_CSISETCALLBACK; + res_lib_amf_csisetcallback->header.size = + sizeof (struct res_lib_amf_csisetcallback)+ + char_length_of_csi_attrs; + res_lib_amf_csisetcallback->header.error = SA_AIS_OK; memcpy (&res_lib_amf_csisetcallback->compName, - &comp->name, sizeof (SaNameT)); + &comp->name, sizeof (SaNameT)); memcpy (&res_lib_amf_csisetcallback->csiName, - &csi->name, sizeof (SaNameT)); + &csi->name, sizeof (SaNameT)); - res_lib_amf_csisetcallback->haState = comp->unit->requested_ha_state; + res_lib_amf_csisetcallback->haState = comp->su->requested_ha_state; csi_set_callback_data = malloc (sizeof (struct csi_set_callback_data)); assert (csi_set_callback_data); // TODO failure here of malloc @@ -1539,24 +1594,20 @@ void csi_comp_set_callback ( csi_set_callback_data->csi = csi; csi_set_callback_data->pg = pg; - res_lib_amf_csisetcallback->invocation = invocation_create ( AMF_RESPONSE_CSISETCALLBACK, csi_set_callback_data); - openais_conn_send_response ( openais_conn_partner_get (comp->conn), res_lib_amf_csisetcallback, res_lib_amf_csisetcallback->header.size); - - free(p); } - -void pg_create (struct amf_si *si, struct amf_pg **pg_out) +#if 0 +static void pg_create (struct amf_si *si, struct amf_pg **pg_out) { struct amf_pg *pg; // struct amf_pg_comp *pg_comp; @@ -1568,72 +1619,55 @@ void pg_create (struct amf_si *si, struct amf_pg **pg_out) list_add (&pg->pg_list, &si->pg_head); *pg_out = pg; } -void csi_unit_set_callback (struct amf_unit *unit, struct amf_si *si) +#endif +static void csi_unit_set_callback (struct amf_su *unit, struct amf_si *si) { - struct list_head *complist; - struct list_head *csilist; - struct list_head *typenamelist; struct amf_csi *csi; struct amf_pg *pg = NULL; struct amf_comp *comp; - struct amf_comp_csi_type_name *type_name; + SaNameT *cs_type; + int i; // pg_create (csi_in->si, &pg); // TODO remove si from csi data structure - dprintf ("assigning SI %s to SU %s for components:\n", - getSaNameT (&si->name), - getSaNameT (&unit->name)); - /* ** for each component in SU, find a CSI in the SI with the same type */ - for (complist = unit->comp_head.next; - complist != &unit->comp_head; - complist = complist->next) { - - comp = list_entry (complist, struct amf_comp, comp_list); + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { dprintf ("\t%s\n", getSaNameT (&comp->name)); int no_of_csi_types = 0; - for (typenamelist = comp->csi_type_name_head.next; - typenamelist != &comp->csi_type_name_head; - typenamelist = typenamelist->next) { - - type_name = list_entry (typenamelist, struct amf_comp_csi_type_name, list); + for (i = 0; comp->saAmfCompCsTypes[i]; i++) { + cs_type = comp->saAmfCompCsTypes[i]; no_of_csi_types++; int no_of_assignments = 0; - for (csilist = si->csi_head.next; - csilist != &si->csi_head; - csilist = csilist->next) { - - csi = list_entry (csilist, struct amf_csi, csi_list); - - if (!memcmp(csi->type_name.value, type_name->name.value, type_name->name.length)) { + for (csi = si->csi_head; csi != NULL; csi = csi->next) { + if (!memcmp(csi->saAmfCSTypeName.value, cs_type->value, cs_type->length)) { csi_comp_set_callback (comp, csi, pg); no_of_assignments++; } } if (no_of_assignments == 0) { - dprintf ("\t No CSIs of type %s configured?!!\n", - getSaNameT (&type_name->name)); + log_printf (LOG_WARNING, "\t No CSIs of type %s configured?!!\n", + getSaNameT (cs_type)); } } if (no_of_csi_types == 0) { - dprintf ("\t No CSI types configured for %s ?!!\n", + log_printf (LOG_LEVEL_ERROR, "\t No CS types configured for comp %s ?!!\n", getSaNameT (&comp->name)); } } } - -void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi) +#if 0 +static void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi) { struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback; struct csi_remove_callback_data *csi_remove_callback_data; - printf ("\t%s\n", + dprintf ("\t%s\n", getSaNameT (&comp->name)); res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK; @@ -1663,228 +1697,108 @@ void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi) sizeof (struct res_lib_amf_csiremovecallback)); } +#endif +static void assign_sis_timeout_fn(void *data) +{ + struct amf_application *app; + struct amf_sg *group; -extern struct list_head amf_groupHead; + dprintf("2nd Cluster start timer expired, assigning SIs\n"); -int clc_instantiate_all (void) { - struct list_head *list_group; - struct amf_group *group; - struct list_head *list_unit; - struct amf_unit *unit; - struct list_head *list_comp; + for (app = amf_cluster.application_head; app != NULL; app = app->next) { + for (group = app->sg_head; group != NULL; group = group->next) { + assign_sis(group); + } + } +} + +static void clc_instantiate_all (void *data) +{ + struct amf_application *app; + struct amf_sg *group; + struct amf_su *unit; struct amf_comp *comp; - for (list_group = amf_groupHead.next; - list_group != &amf_groupHead; - list_group = list_group->next) { + dprintf("1st Cluster start timer expired, instantiating SUs\n"); - group = list_entry (list_group, - struct amf_group, group_list); - - for (list_unit = group->unit_head.next; - list_unit != &group->unit_head; - list_unit = list_unit->next) { - - unit = list_entry (list_unit, - struct amf_unit, unit_list); - - for (list_comp = unit->comp_head.next; - list_comp != &unit->comp_head; - list_comp = list_comp->next) { - - comp = list_entry (list_comp, - struct amf_comp, comp_list); - - if (strlen ((char *)comp->instantiate_cmd)) { - - clc_instantiate (comp); + for (app = amf_cluster.application_head; app != NULL; app = app->next) { + for (group = app->sg_head; group != NULL; group = group->next) { + for (unit = group->su_head; unit != NULL; unit = unit->next) { + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { + if (strlen ((char *)comp->saAmfCompInstantiateCmd)) { + clc_instantiate (comp); + } } } } } - return (0); + + /* wait a while before assigning SIs as the AMF spec. says. */ + poll_timer_add(aisexec_poll_handle, + amf_cluster.saAmfClusterStartupTimeout, + NULL, + assign_sis_timeout_fn, + &amf_cluster.timeout_handle); } -void comp_terminate (struct amf_comp *comp) +#if 0 +static void comp_terminate (struct amf_comp *comp) { clc_terminate (comp); } -void unit_terminate (struct amf_unit *unit) +static void unit_terminate (struct amf_su *unit) { - struct list_head *list_comp; struct amf_comp *comp; - for (list_comp = unit->comp_head.next; - list_comp != &unit->comp_head; - list_comp = list_comp->next) { - - comp = list_entry (list_comp, struct amf_comp, comp_list); - + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { clc_terminate (comp); } - -} - -void comp_cleanup (struct amf_comp *comp) -{ - clc_cleanup (comp); -} - -void unit_cleanup (struct amf_unit *unit) -{ - struct list_head *list_comp; - struct amf_comp *comp; - - for (list_comp = unit->comp_head.next; - list_comp != &unit->comp_head; - list_comp = list_comp->next) { - - comp = list_entry (list_comp, struct amf_comp, comp_list); - - clc_cleanup (comp); - } - -} - -void comp_restart (struct amf_comp *comp) -{ - presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING); -} - -void unit_restart (struct amf_unit *unit) -{ - struct list_head *list_comp; - struct amf_comp *comp; - - for (list_comp = unit->comp_head.next; - list_comp != &unit->comp_head; - list_comp = list_comp->next) { - - comp = list_entry (list_comp, struct amf_comp, comp_list); - presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING); - } -} - -void clc_unit_instantiate (struct amf_unit *unit) -{ - struct list_head *list_comp; - struct amf_comp *comp; - - dprintf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n"); - for (list_comp = unit->comp_head.next; - list_comp != &unit->comp_head; - list_comp = list_comp->next) { - - comp = list_entry (list_comp, struct amf_comp, comp_list); - - clc_instantiate (comp); - } -} - -void csi_unit_remove_callbacks (struct amf_unit *unit) -{ - struct list_head *list_si; - struct list_head *list_csi; - struct list_head *list_comp; - struct amf_si *si; - struct amf_csi *csi; - struct amf_comp *comp; - - for (list_si = unit->si_head.next; - list_si != &unit->si_head; - list_si = list_si->next) { - - si = list_entry (list_si, struct amf_si, unit_list); - - for (list_csi = si->csi_head.next; - list_csi != &si->csi_head; - list_csi = list_csi->next) { - - csi = list_entry (list_csi, struct amf_csi, csi_list); - - for (list_comp = csi->unit->comp_head.next; - list_comp != &csi->unit->comp_head; - list_comp = list_comp->next) { - - comp = list_entry (list_comp, struct amf_comp, comp_list); - } - } - } -} -// THIS MIGHT BE GOOD FOR SOMEPTHING ELSE -#ifdef COMPILE_OUT -void csi_unit_remove_callbacks (struct amf_unit *unit) -{ - struct list_head *list_comp; - struct list_head *list_si; - struct list_head *list_csi; - struct list_head *list_pg; - struct list_head *list_pg_comp; - struct amf_comp *comp; - struct amf_csi *csi; - struct amf_si *si; - struct amf_pg *pg; - struct amf_pg_comp *pg_comp; - - for (list_si = unit->si_head.next; - list_si != &unit->si_head; - list_si = list_si->next) { - - si = list_entry (list_si, struct amf_si, unit_list); - - for (list_pg = si->pg_head.next; - list_pg != &si->pg_head; - list_pg = list_pg->next) { - - pg = list_entry (list_pg, struct amf_pg, pg_list); - printf ("pg %x\n", pg); - - for (list_pg_comp = pg->pg_comp_head.next; - list_pg_comp != &pg->pg_comp_head; - list_pg_comp = list_pg_comp->next) { - - pg_comp = list_entry (list_pg_comp, - struct amf_pg_comp, list); - printf ("pg_comp %x\n", pg_comp); - printf ("remove component callback\n"); - csi_comp_remove_callback ( - pg_comp->comp, - pg_comp->csi); - } - } - } } #endif -char csi_number = 0; -void csi_unit_create (struct amf_unit *unit, struct amf_si *si, - struct amf_csi **csi_out) +static void comp_cleanup (struct amf_comp *comp) { - struct amf_csi *csi; - - dprintf ("creating csi for si %p unit %p\n", si, unit); - si->csi_count += 1; - csi = malloc (sizeof (struct amf_csi)); - list_init (&csi->csi_list); - list_add (&csi->csi_list, &si->csi_head); - list_add (&si->unit_list, &unit->si_head); - csi->si = si; - csi->unit = unit; - csi->pg_set = 0; - - sprintf ((char *)csi->name.value, "CSI %d", csi_number); - csi->name.length = strlen ((char *)csi->name.value); - - csi_number += 1; - *csi_out = csi; + clc_cleanup (comp); } -void ha_state_unit_set (struct amf_unit *unit, struct amf_si *si, +static void unit_cleanup (struct amf_su *unit) +{ + struct amf_comp *comp; + + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { + clc_cleanup (comp); + } +} + +static void comp_restart (struct amf_comp *comp) +{ + presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING); +} +#if 0 +static void unit_restart (struct amf_su *unit) +{ + struct amf_comp *comp; + + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { + presence_state_comp_set (comp, SA_AMF_PRESENCE_RESTARTING); + } +} +static void clc_unit_instantiate (struct amf_su *unit) +{ + struct amf_comp *comp; + + dprintf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n"); + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { + clc_instantiate (comp); + } +} +#endif +static void ha_state_unit_set (struct amf_su *unit, struct amf_si *si, SaAmfHAStateT ha_state) { dprintf ("Assigning SI %s to SU %s with hastate %s\n", - getSaNameT (&si->name), getSaNameT (&unit->name), hastate_ntoa (ha_state)); + getSaNameT (&si->name), getSaNameT (&unit->name), ha_state_text[ha_state]); unit->requested_ha_state = ha_state; @@ -1892,57 +1806,39 @@ void ha_state_unit_set (struct amf_unit *unit, struct amf_si *si, } -int unit_inservice_count (struct amf_group *group) +static int unit_inservice_count (struct amf_sg *group) { - struct list_head *list; - struct amf_unit *unit; + struct amf_su *unit; int answer = 0; - for (list = group->unit_head.next; - list != &group->unit_head; - list = list->next) { - - unit = list_entry (list, - struct amf_unit, unit_list); - - if (unit->readiness_state == SA_AMF_READINESS_IN_SERVICE) { + for (unit = group->su_head; unit != NULL; unit = unit->next) { + if (unit->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE) { answer += 1; } } return (answer); } - -int comp_inservice_count (struct amf_unit *unit) +#if 0 +static int comp_inservice_count (struct amf_su *unit) { - struct list_head *list; struct amf_comp *comp; int answer = 0; - for (list = unit->comp_head.next; - list != &unit->comp_head; - list = list->next) { - - comp = list_entry (list, struct amf_comp, comp_list); - if (comp->readiness_state == SA_AMF_READINESS_IN_SERVICE) { + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { + if (comp->saAmfCompReadinessState == SA_AMF_READINESS_IN_SERVICE) { answer += 1; } } return (answer); } +#endif - -int si_count (struct amf_group *group) +static int si_count (struct amf_sg *group) { - struct list_head *list_si; struct amf_si *si; int answer = 0; - for (list_si = group->si_head.next; - list_si != &group->si_head; - list_si = list_si->next) { - - si = list_entry (list_si, struct amf_si, si_list); - + for (si = group->application->si_head; si != NULL; si = si->next) { answer += 1; } return (answer); @@ -1960,54 +1856,46 @@ static inline int div_round (int a, int b) } -void assign_nm_active (struct amf_group *group, int su_units_assign) +static void assign_nm_active (struct amf_sg *group, int su_units_assign) { - struct amf_unit *unit; + struct amf_su *unit; struct amf_si *si; - struct list_head *list_si; - struct list_head *list_unit; int assigned = 0; int assign_per_su = 0; int total_assigned = 0; assign_per_su = si_count (group); assign_per_su = div_round (assign_per_su, su_units_assign); - if (assign_per_su > group->maximum_active_instances) { - assign_per_su = group->maximum_active_instances; + if (assign_per_su > group->saAmfSGMaxActiveSIsperSUs) { + assign_per_su = group->saAmfSGMaxActiveSIsperSUs; } - list_si = group->si_head.next; - list_unit = group->unit_head.next; - while (list_unit != &group->unit_head) { - unit = list_entry (list_unit, - struct amf_unit, unit_list); - - if (unit->readiness_state != SA_AMF_READINESS_IN_SERVICE) { - list_unit = list_unit->next; + si = group->application->si_head; + unit = group->su_head; + while (unit != NULL) { + if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE) { + unit = unit->next; continue; /* Not in service */ } assigned = 0; - while (list_si != &group->si_head && + while (si != NULL && assigned < assign_per_su && total_assigned < si_count (group)) { - si = list_entry (list_si, struct amf_si, si_list); assigned += 1; total_assigned += 1; ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE); - list_si = list_si->next; + si = si->next; } - list_unit = list_unit->next; + unit = unit->next; } } -void assign_nm_standby (struct amf_group *group, int units_assign_standby) +static void assign_nm_standby (struct amf_sg *group, int units_assign_standby) { - struct amf_unit *unit; + struct amf_su *unit; struct amf_si *si; - struct list_head *list_si; - struct list_head *list_unit; int assigned = 0; int assign_per_su = 0; @@ -2016,76 +1904,55 @@ void assign_nm_standby (struct amf_group *group, int units_assign_standby) } assign_per_su = si_count (group); assign_per_su = div_round (assign_per_su, units_assign_standby); - if (assign_per_su > group->maximum_standby_instances) { - assign_per_su = group->maximum_standby_instances; + if (assign_per_su > group->saAmfSGMaxStandbySIsperSUs) { + assign_per_su = group->saAmfSGMaxStandbySIsperSUs; } - list_si = group->si_head.next; - list_unit = group->unit_head.next; - while (list_unit != &group->unit_head) { - unit = list_entry (list_unit, - struct amf_unit, unit_list); - - if (unit->readiness_state != SA_AMF_READINESS_IN_SERVICE || + si = group->application->si_head; + unit = group->su_head; + while (unit != NULL) { + if (unit->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE || unit->requested_ha_state == SA_AMF_HA_ACTIVE) { - list_unit = list_unit->next; + unit = unit->next; continue; /* Not available for assignment */ } assigned = 0; - while (list_si != &group->si_head && assigned < assign_per_su) { - si = list_entry (list_si, struct amf_si, si_list); + while (si != NULL && assigned < assign_per_su) { assigned += 1; ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY); - list_si = list_si->next; + si = si->next; } - list_unit = list_unit->next; + unit = unit->next; } } - -void assign_nm_spare (struct amf_group *group) +#if 0 +static void assign_nm_spare (struct amf_sg *group) { - struct amf_unit *unit; - struct list_head *list; + struct amf_su *unit; - for (list = group->unit_head.next; - list != &group->unit_head; - list = list->next) { - - unit = list_entry (list, - struct amf_unit, unit_list); - - if (unit->readiness_state == SA_AMF_READINESS_IN_SERVICE && + for (unit = group->su_head; unit != NULL; unit = unit->next) { + if (unit->saAmfSUReadinessState == SA_AMF_READINESS_IN_SERVICE && (unit->requested_ha_state != SA_AMF_HA_ACTIVE && unit->requested_ha_state != SA_AMF_HA_STANDBY)) { - printf ("Assigning to SU %s with SPARE\n", + dprintf ("Assigning to SU %s with SPARE\n", getSaNameT (&unit->name)); - } } } - -void clear_requested_ha_state (struct amf_group *group) +#endif +static void clear_requested_ha_state (struct amf_sg *group) { - struct list_head *list; - struct amf_unit *unit; + struct amf_su *unit; - for (list = group->unit_head.next; - list != &group->unit_head; - list = list->next) { - - unit = list_entry (list, - struct amf_unit, unit_list); - - unit->requested_ha_state = 0; + for (unit = group->su_head; unit != NULL; unit = unit->next) { + unit->requested_ha_state = SA_AMF_HA_QUIESCED; } - - csi_number = 0; } -void assign_sis (struct amf_group *group) +static void assign_sis (struct amf_sg *group) { int active_sus_needed; int standby_sus_needed; @@ -2105,22 +1972,22 @@ void assign_sis (struct amf_group *group) inservice_count = (float)unit_inservice_count (group); active_sus_needed = div_round (si_count(group), - group->maximum_active_instances); + group->saAmfSGMaxActiveSIsperSUs); standby_sus_needed = div_round (si_count(group), - group->maximum_standby_instances); + group->saAmfSGMaxStandbySIsperSUs); - units_for_active = inservice_count - group->preferred_standby_units; + units_for_active = inservice_count - group->saAmfSGNumPrefStandbySUs; if (units_for_active < 0) { units_for_active = 0; } - units_for_standby = inservice_count - group->preferred_active_units; + units_for_standby = inservice_count - group->saAmfSGNumPrefActiveSUs; if (units_for_standby < 0) { units_for_standby = 0; } - ii_spare = inservice_count - group->preferred_active_units - group->preferred_standby_units; + ii_spare = inservice_count - group->saAmfSGNumPrefActiveSUs - group->saAmfSGNumPrefStandbySUs; if (ii_spare < 0) { ii_spare = 0; } @@ -2147,30 +2014,30 @@ void assign_sis (struct amf_group *group) } su_spare_assign = 0; } else - if ((group->maximum_standby_instances * units_for_standby) <= si_count (group)) { + if ((group->saAmfSGMaxStandbySIsperSUs * units_for_standby) <= si_count (group)) { dprintf ("IV: full assignment with reduction of active service units\n"); su_active_assign = inservice_count - standby_sus_needed; su_standby_assign = standby_sus_needed; su_spare_assign = 0; } else - if ((group->maximum_active_instances * units_for_active) <= si_count (group)) { + if ((group->saAmfSGMaxActiveSIsperSUs * units_for_active) <= si_count (group)) { dprintf ("III: full assignment with reduction of standby service units\n"); - su_active_assign = group->preferred_active_units; + su_active_assign = group->saAmfSGNumPrefActiveSUs; su_standby_assign = units_for_standby; su_spare_assign = 0; } else if (ii_spare == 0) { dprintf ("II: full assignment with spare reduction\n"); - su_active_assign = group->preferred_active_units; - su_standby_assign = group->preferred_standby_units; + su_active_assign = group->saAmfSGNumPrefActiveSUs; + su_standby_assign = group->saAmfSGNumPrefStandbySUs; su_spare_assign = 0; } else { dprintf ("I: full assignment with spares\n"); - su_active_assign = group->preferred_active_units; - su_standby_assign = group->preferred_standby_units; + su_active_assign = group->saAmfSGNumPrefActiveSUs; + su_standby_assign = group->saAmfSGNumPrefStandbySUs; su_spare_assign = ii_spare; } @@ -2180,25 +2047,48 @@ void assign_sis (struct amf_group *group) assign_nm_standby (group, su_standby_assign); } -void readiness_state_unit_set (struct amf_unit *unit, SaAmfReadinessStateT readiness_state) +static int all_sus_in_sg_ready(struct amf_sg *sg) { - dprintf ("Assigning unit %s readiness state %s\n", - getSaNameT (&unit->name), readinessstate_ntoa (readiness_state)); + struct amf_su *su; + struct amf_comp *comp; + int ready = 1; - unit->readiness_state = readiness_state; - assign_sis (unit->amf_group); + for (su = sg->su_head; su != NULL; su = su->next) { + for (comp = su->comp_head; comp != NULL; comp = comp->next) { + if (su->saAmfSUReadinessState != SA_AMF_READINESS_IN_SERVICE) { + ready = 0; + } + } + } + + return ready; } -void presence_state_unit_set (struct amf_unit *unit, SaAmfPresenceStateT presence_state) +static void readiness_state_unit_set (struct amf_su *unit, SaAmfReadinessStateT readiness_state) +{ + dprintf ("Assigning unit %s readiness state %s\n", + getSaNameT (&unit->name), readiness_state_text[readiness_state]); + + unit->saAmfSUReadinessState = readiness_state; + + if (all_sus_in_sg_ready(unit->sg)){ + assign_sis (unit->sg); + if (amf_cluster.timeout_handle) { + poll_timer_delete (aisexec_poll_handle, amf_cluster.timeout_handle); + } + } +} + +static void presence_state_unit_set (struct amf_su *unit, SaAmfPresenceStateT presence_state) { dprintf ("Setting service unit presence state %s\n", - presencestate_ntoa (presence_state)); + presence_state_text[presence_state]); } static void escalation_policy_restart (struct amf_comp *comp) { - dprintf ("escalation_policy_restart %d\n", comp->unit->escalation_level); + dprintf ("escalation_policy_restart %d\n", comp->su->escalation_level); dprintf ("escalation policy restart uninsint %p\n", comp); presence_state_comp_set ( comp, @@ -2208,7 +2098,7 @@ static void escalation_policy_restart (struct amf_comp *comp) comp, SA_AMF_OPERATIONAL_DISABLED); - switch (comp->unit->escalation_level) { + switch (comp->su->escalation_level) { case ESCALATION_LEVEL_NO_ESCALATION: comp_restart (comp); @@ -2232,35 +2122,35 @@ static void escalation_policy_cleanup (struct amf_comp *comp) // escalation_timer_start (comp); - switch (comp->unit->escalation_level) { + switch (comp->su->escalation_level) { case ESCALATION_LEVEL_NO_ESCALATION: - comp->unit->restart_count += 1; - if (comp->unit->restart_count >= comp->unit->amf_group->component_restart_max) { - comp->unit->escalation_level = ESCALATION_LEVEL_ONE; + comp->su->saAmfSURestartCount += 1; + if (comp->su->saAmfSURestartCount >= comp->su->sg->saAmfSGCompRestartMax) { + comp->su->escalation_level = ESCALATION_LEVEL_ONE; escalation_policy_cleanup (comp); - comp->unit->restart_count = 0; + comp->su->saAmfSURestartCount = 0; return; } - printf ("Escalation level 0 - restart component\n"); - printf ("Cleaning up and restarting component.\n"); + dprintf ("Escalation level 0 - restart component\n"); + dprintf ("Cleaning up and restarting component.\n"); comp_cleanup (comp); break; case ESCALATION_LEVEL_ONE: - comp->unit->restart_count += 1; - if (comp->unit->restart_count >= comp->unit->amf_group->unit_restart_max) { - comp->unit->escalation_level = ESCALATION_LEVEL_TWO; + comp->su->saAmfSURestartCount += 1; + if (comp->su->saAmfSURestartCount >= comp->su->sg->saAmfSGSuRestartMax) { + comp->su->escalation_level = ESCALATION_LEVEL_TWO; escalation_policy_cleanup (comp); return; } - printf ("Escalation level 1 - restart unit\n"); - printf ("Cleaning up and restarting unit.\n"); - unit_cleanup (comp->unit); + dprintf ("Escalation level 1 - restart unit\n"); + dprintf ("Cleaning up and restarting unit.\n"); + unit_cleanup (comp->su); break; case ESCALATION_LEVEL_TWO: - printf ("Escalation level TWO\n"); - unit_cleanup (comp->unit); + dprintf ("Escalation level TWO\n"); + unit_cleanup (comp->su); // unit_terminate_failover (comp); break; @@ -2273,15 +2163,14 @@ static void escalation_policy_cleanup (struct amf_comp *comp) static void timer_function_healthcheck_timeout ( void *data) { - struct healthcheck_active *healthcheck_active = - (struct healthcheck_active *)data; + struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)data; - printf ("timeout occured on healthcheck for component %s.\n", - getSaNameT (&healthcheck_active->comp->name)); - escalation_policy_cleanup (healthcheck_active->comp); + dprintf ("timeout occured on healthcheck for component %s.\n", + getSaNameT (&healthcheck->comp->name)); + escalation_policy_cleanup (healthcheck->comp); } -void healthcheck_activate (struct healthcheck_active *healthcheck_active) +static void healthcheck_activate (struct amf_healthcheck *healthcheck_active) { struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback; @@ -2305,7 +2194,7 @@ void healthcheck_activate (struct healthcheck_active *healthcheck_active) sizeof (SaNameT)); memcpy (&res_lib_amf_healthcheckcallback.key, - &healthcheck_active->key, + &healthcheck_active->safHealthcheckKey, sizeof (SaAmfHealthcheckKeyT)); openais_conn_send_response ( @@ -2314,29 +2203,28 @@ void healthcheck_activate (struct healthcheck_active *healthcheck_active) sizeof (struct res_lib_amf_healthcheckcallback)); poll_timer_delete (aisexec_poll_handle, - healthcheck_active->timer_healthcheck_duration); + healthcheck_active->timer_handle_duration); poll_timer_add (aisexec_poll_handle, - healthcheck_active->healthcheck->maximum_duration, + healthcheck_active->saAmfHealthcheckMaxDuration, (void *)healthcheck_active, timer_function_healthcheck_timeout, - &healthcheck_active->timer_healthcheck_duration); + &healthcheck_active->timer_handle_duration); } -void healthcheck_deactivate (struct healthcheck_active *healthcheck_active) +static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active) { - log_printf (LOG_LEVEL_NOTICE, "ZZZ deactivating healthcheck for component %s\n", - getSaNameT (&healthcheck_active->comp->name)); + log_printf (LOG_LEVEL_NOTICE, + "ZZZ deactivating healthcheck for component %s\n", + getSaNameT (&healthcheck_active->comp->name)); poll_timer_delete (aisexec_poll_handle, - healthcheck_active->timer_healthcheck_period); + healthcheck_active->timer_handle_period); poll_timer_delete (aisexec_poll_handle, - healthcheck_active->timer_healthcheck_duration); + healthcheck_active->timer_handle_duration); invocation_destroy_by_data ((void *)healthcheck_active); - - list_del (&healthcheck_active->list); - free (healthcheck_active); + healthcheck_active->active = 0; } @@ -2346,71 +2234,18 @@ static void timer_function_healthcheck_next ( healthcheck_activate (data); } -void healthcheck_unit_deactivate ( - struct amf_unit *unit) +static void operational_state_unit_set ( + struct amf_su *unit, + SaAmfOperationalStateT oper_state) { - struct list_head *list; - struct list_head *key_list; - struct healthcheck_active *healthcheck_active; - struct amf_comp *comp; - - for (list = unit->comp_head.next; - list != &unit->comp_head; - list = list->next) { - - comp = list_entry (list, struct amf_comp, comp_list); - - for (key_list = comp->healthcheck_list.next; - key_list != &comp->healthcheck_list; - key_list = key_list->next) { - - healthcheck_active = list_entry (key_list, - struct healthcheck_active, list); - - healthcheck_deactivate (healthcheck_active); - } - } -} - - -void healthcheck_unit_activate ( - struct amf_unit *unit) -{ - struct list_head *list; - struct list_head *key_list; - struct healthcheck_active *healthcheck_active; - struct amf_comp *comp; - - for (list = unit->comp_head.next; - list != &unit->comp_head; - list = list->next) { - - comp = list_entry (list, struct amf_comp, comp_list); - - for (key_list = comp->healthcheck_list.next; - key_list != &comp->healthcheck_list; - key_list = key_list->next) { - - healthcheck_active = list_entry (key_list, - struct healthcheck_active, list); - - healthcheck_activate (healthcheck_active); - } - } -} - -void operational_state_unit_set ( - struct amf_unit *unit, - SaAmfOperationalStateT operational_state) -{ - if (operational_state == unit->operational_state) { + if (oper_state == unit->saAmfSUOperState) { dprintf ("Not assigning service unit new operational state - same state\n"); return; } - unit->operational_state = operational_state; + unit->saAmfSUOperState = oper_state; dprintf ("Service unit operational state set to %s\n", - operationalstate_ntoa (operational_state)); - if (operational_state == SA_AMF_OPERATIONAL_ENABLED) { + oper_state_text[oper_state]); + if (oper_state == SA_AMF_OPERATIONAL_ENABLED) { readiness_state_unit_set (unit, SA_AMF_READINESS_IN_SERVICE); /* @@ -2418,7 +2253,7 @@ void operational_state_unit_set ( */ // TODO healthcheck_unit_activate (unit); } else - if (operational_state == SA_AMF_OPERATIONAL_DISABLED) { + if (oper_state == SA_AMF_OPERATIONAL_DISABLED) { readiness_state_unit_set (unit, SA_AMF_READINESS_OUT_OF_SERVICE); // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY); @@ -2436,34 +2271,28 @@ static void message_handler_req_exec_amf_operational_state_comp_set ( (struct req_exec_amf_operational_state_comp_set *)message; struct amf_comp *comp; struct amf_comp *comp_compare; - struct list_head *list; int all_set = 1; - comp = find_comp (&req_exec_amf_operational_state_comp_set->name); - comp->operational_state = req_exec_amf_operational_state_comp_set->operational_state; + comp = amf_find_comp (&amf_cluster, &req_exec_amf_operational_state_comp_set->name); + comp->saAmfCompOperState = req_exec_amf_operational_state_comp_set->operational_state; dprintf ("Setting component %s operational state to %s\n", getSaNameT (&comp->name), - operationalstate_ntoa (comp->operational_state)); + oper_state_text[comp->saAmfCompOperState]); /* * If all operational states are ENABLED, then SU should be ENABLED */ - for (list = comp->unit->comp_head.next; - list != &comp->unit->comp_head; - list = list->next) { - - comp_compare = list_entry (list, - struct amf_comp, comp_list); - if (comp_compare->operational_state != SA_AMF_OPERATIONAL_ENABLED) { + for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp_compare->next) { + if (comp_compare->saAmfCompOperState != SA_AMF_OPERATIONAL_ENABLED) { all_set = 0; break; } } if (all_set) { - operational_state_unit_set (comp->unit, + operational_state_unit_set (comp->su, SA_AMF_OPERATIONAL_ENABLED); } else { - operational_state_unit_set (comp->unit, + operational_state_unit_set (comp->su, SA_AMF_OPERATIONAL_DISABLED); } readiness_state_comp_set (comp); @@ -2477,11 +2306,13 @@ static void message_handler_req_exec_amf_presence_state_comp_set ( (struct req_exec_amf_presence_state_comp_set *)message; struct amf_comp *comp; struct amf_comp *comp_compare; - struct list_head *list; int all_set = 1; - comp = find_comp (&req_exec_amf_presence_state_comp_set->name); - if (req_exec_amf_presence_state_comp_set->presence_state == comp->presence_state) { + ENTER_VOID(); + + comp = amf_find_comp (&amf_cluster, &req_exec_amf_presence_state_comp_set->name); + assert(comp); + if (req_exec_amf_presence_state_comp_set->presence_state == comp->saAmfCompPresenceState) { dprintf ("duplicate presence state set, not setting presence state\n"); return; } @@ -2494,21 +2325,21 @@ static void message_handler_req_exec_amf_presence_state_comp_set ( * The restarting state can only be entered from the uninstantiated state */ if (req_exec_amf_presence_state_comp_set->presence_state == SA_AMF_PRESENCE_RESTARTING && - comp->presence_state != SA_AMF_PRESENCE_UNINSTANTIATED) { + comp->saAmfCompPresenceState != SA_AMF_PRESENCE_UNINSTANTIATED) { dprintf ("restart presence state set even though not in terminating state\n"); return; } - comp->presence_state = req_exec_amf_presence_state_comp_set->presence_state; - if (comp->presence_state == SA_AMF_PRESENCE_RESTARTING) { + comp->saAmfCompPresenceState = req_exec_amf_presence_state_comp_set->presence_state; + if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) { dprintf ("SET TO RESTARTING instantiating now\n"); clc_instantiate (comp); } dprintf ("Setting component %s presence state %s\n", getSaNameT (&comp->name), - presencestate_ntoa (comp->presence_state)); + presence_state_text[comp->saAmfCompPresenceState]); /* * Restart components that are requested to enter the restarting presence state @@ -2517,20 +2348,15 @@ static void message_handler_req_exec_amf_presence_state_comp_set ( /* * If all comp presence states are INSTANTIATED, then SU should be instantated */ - for (list = comp->unit->comp_head.next; - list != &comp->unit->comp_head; - list = list->next) { - - comp_compare = list_entry (list, - struct amf_comp, comp_list); - if (comp_compare->presence_state != SA_AMF_PRESENCE_INSTANTIATED) { + for (comp_compare = comp->su->comp_head; comp_compare != NULL; comp_compare = comp->next) { + if (comp_compare->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) { all_set = 0; break; } } if (all_set) { - presence_state_unit_set (comp->unit, + presence_state_unit_set (comp->su, SA_AMF_PRESENCE_INSTANTIATED); } } @@ -2575,7 +2401,7 @@ static void message_handler_req_lib_amf_componentregister ( struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn); SaAisErrorT error = SA_AIS_ERR_NOT_EXIST; - comp = find_comp (&req_lib_amf_componentregister->compName); + comp = amf_find_comp (&amf_cluster, &req_lib_amf_componentregister->compName); if (comp) { presence_state_comp_set (comp, SA_AMF_PRESENCE_INSTANTIATED); @@ -2616,7 +2442,7 @@ static void message_handler_req_lib_amf_componentunregister ( req_lib_amf_componentunregister, sizeof (struct req_lib_amf_componentunregister)); - component = find_comp (&req_lib_amf_componentunregister->compName); + component = amf_find_comp (&amf_cluster, &req_lib_amf_componentunregister->compName); if (component && component->registered && component->local) { // component->probableCause = SA_AMF_NOT_RESPONDING; } @@ -2646,20 +2472,19 @@ static void message_handler_req_lib_amf_healthcheckstart ( (struct req_lib_amf_healthcheckstart *)msg; struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart; struct amf_healthcheck *healthcheck; - struct healthcheck_active *healthcheck_active; struct amf_comp *comp; SaAisErrorT error = SA_AIS_OK; -printf ("healthcheck start\n"); -fflush (stdout); - healthcheck = find_healthcheck (&req_lib_amf_healthcheckstart->healthcheckKey); - if (healthcheck == 0) { + ENTER(); + + comp = amf_find_comp (&amf_cluster, &req_lib_amf_healthcheckstart->compName); + if (comp == 0) { error = SA_AIS_ERR_NOT_EXIST; goto error_exit; } - comp = find_comp (&req_lib_amf_healthcheckstart->compName); - if (comp == 0) { + healthcheck = amf_find_healthcheck (comp, &req_lib_amf_healthcheckstart->healthcheckKey); + if (healthcheck == 0) { error = SA_AIS_ERR_NOT_EXIST; goto error_exit; } @@ -2667,51 +2492,24 @@ fflush (stdout); /* * Determine if this healthcheck is already active */ - healthcheck_active = find_healthcheck_active ( - comp, - &req_lib_amf_healthcheckstart->healthcheckKey, - req_lib_amf_healthcheckstart->invocationType); - if (healthcheck_active) { + if (healthcheck->active) { error = SA_AIS_ERR_EXIST; goto error_exit; } - healthcheck_active = malloc (sizeof (struct healthcheck_active)); - if (healthcheck_active == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - /* - * Make new instance of healthcheck key + * Initialise */ - list_init (&healthcheck_active->list); - memcpy (&healthcheck_active->key, - &req_lib_amf_healthcheckstart->healthcheckKey, - sizeof (SaAmfHealthcheckKeyT)); - healthcheck_active->comp = comp; - healthcheck_active->invocationType = req_lib_amf_healthcheckstart->invocationType; - healthcheck_active->healthcheck = healthcheck; - healthcheck_active->timer_healthcheck_duration = 0; - healthcheck_active->timer_healthcheck_period = 0; - healthcheck_active->active = 0; + healthcheck->invocationType = req_lib_amf_healthcheckstart->invocationType; + healthcheck->timer_handle_duration = 0; + healthcheck->timer_handle_period = 0; + healthcheck->active = 0; - list_add_tail (&healthcheck_active->list, &comp->healthcheck_list); - - if (comp->conn != 0) { -printf ("Activating healthcheck for the first time %p\n", healthcheck_active); - healthcheck_activate (healthcheck_active); + if (comp->conn == NULL) { + comp->conn = conn; } -#ifdef TODO -do we want to do healtchecking only when full su has registered or also of non-fully registered sus - if (comp->unit->operational_state == SA_AMF_OPERATIONAL_ENABLED) { - /* - * Start healthcheck now - */ - healthcheck_unit_activate (comp->unit); - } -#endif + healthcheck_activate (healthcheck); error_exit: res_lib_amf_healthcheckstart.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART; @@ -2735,32 +2533,31 @@ static void message_handler_req_lib_amf_healthcheckstop ( struct req_lib_amf_healthcheckstop *req_lib_amf_healthcheckstop = (struct req_lib_amf_healthcheckstop *)msg; struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop; - struct healthcheck_active *healthcheck_active; + struct amf_healthcheck *healthcheck; struct amf_comp *comp; SaAisErrorT error = SA_AIS_OK; - printf ("healthcheck stop\n"); - comp = find_comp (&req_lib_amf_healthcheckstop->compName); + dprintf ("healthcheck stop\n"); + comp = amf_find_comp (&amf_cluster, &req_lib_amf_healthcheckstop->compName); if (comp == 0) { error = SA_AIS_ERR_NOT_EXIST; goto error_exit; } - healthcheck_active = find_healthcheck_active ( + healthcheck = amf_find_healthcheck ( comp, - &req_lib_amf_healthcheckstop->healthcheckKey, - INVOCATION_DONT_COMPARE); + &req_lib_amf_healthcheckstop->healthcheckKey); - printf ("active %p\n", healthcheck_active); - if (healthcheck_active == 0) { + dprintf ("active %p\n", healthcheck); + if (healthcheck == 0) { error = SA_AIS_ERR_NOT_EXIST; goto error_exit; } - healthcheck_deactivate (healthcheck_active); + healthcheck_deactivate (healthcheck); error_exit: - printf ("healthcheck stop\n"); + dprintf ("healthcheck stop\n"); res_lib_amf_healthcheckstop.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP; res_lib_amf_healthcheckstop.header.size = sizeof (struct res_lib_amf_healthcheckstop); res_lib_amf_healthcheckstop.header.error = error; @@ -2797,22 +2594,22 @@ static void message_handler_req_lib_amf_hastateget ( #endif } -static void message_handler_req_lib_amf_protectiongrouptrackstart ( +static void message_handler_req_lib_amf_protectiongrouptrack ( void *conn, void *msg) { #ifdef COMPILE_OUT - struct req_lib_amf_protectiongrouptrackstart *req_lib_amf_protectiongrouptrackstart = (struct req_lib_amf_protectiongrouptrackstart *)message; - struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart; + struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message; + struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack; struct libamf_ci_trackentry *track = 0; int i; struct saAmfProtectionGroup *amfProtectionGroup; - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstart()\n"); + log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n"); - amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrackstart->csiName); + amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName); if (amfProtectionGroup) { - log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrackstart->csiName)); + log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName)); for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) { if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) { track = &conn_info->ais_ci.u.libamf_ci.tracks[i]; @@ -2826,10 +2623,10 @@ static void message_handler_req_lib_amf_protectiongrouptrackstart ( } track->active = 1; - track->trackFlags = req_lib_amf_protectiongrouptrackstart->trackFlags; - track->notificationBufferAddress = req_lib_amf_protectiongrouptrackstart->notificationBufferAddress; + track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags; + track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress; memcpy (&track->csiName, - &req_lib_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT)); + &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT)); conn_info->ais_ci.u.libamf_ci.trackActive += 1; @@ -2842,18 +2639,18 @@ static void message_handler_req_lib_amf_protectiongrouptrackstart ( log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n"); } - res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART; - res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart); - res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST; + res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK; + res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack); + res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST; if (amfProtectionGroup) { - res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK; + res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK; } - openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstart, - sizeof (struct res_lib_amf_protectiongrouptrackstart)); + openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack, + sizeof (struct res_lib_amf_protectiongrouptrack)); if (amfProtectionGroup && - req_lib_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) { + req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) { protectiongroup_notification_send (conn_info, track->notificationBufferAddress, @@ -2927,10 +2724,10 @@ static void message_handler_req_lib_amf_componenterrorreport ( ENTER(); log_printf (LOG_LEVEL_NOTICE, "Handle : message_handler_req_lib_amf_componenterrorreport()\n"); -printf ("ERROR REPORT\n"); - comp = find_comp (&req_lib_amf_componenterrorreport->erroneousComponent); + dprintf ("ERROR REPORT\n"); + comp = amf_find_comp (&amf_cluster, &req_lib_amf_componenterrorreport->erroneousComponent); if (comp) { -printf ("escalation policy terminate\n"); + dprintf ("escalation policy terminate\n"); escalation_policy_cleanup (comp); error = SA_AIS_OK; } @@ -2975,14 +2772,15 @@ static void message_handler_req_lib_amf_componenterrorclear ( } -void pg_comp_create ( +#if 0 +static void pg_comp_create ( struct amf_pg *pg, struct amf_csi *csi, struct amf_comp *comp) { struct amf_pg_comp *pg_comp; - printf ("creating component for pg\n"); + dprintf ("creating component for pg\n"); pg_comp = malloc (sizeof (struct amf_pg_comp)); assert (pg_comp); pg_comp->comp = comp; @@ -2990,7 +2788,7 @@ void pg_comp_create ( list_init (&pg_comp->list); list_add_tail (&pg_comp->list, &pg->pg_comp_head); } - +#endif static void message_handler_req_lib_amf_response (void *conn, void *msg) { struct req_lib_amf_response *req_lib_amf_response = (struct req_lib_amf_response *)msg; @@ -2998,7 +2796,7 @@ static void message_handler_req_lib_amf_response (void *conn, void *msg) struct csi_set_callback_data *csi_set_callback_data; struct csi_remove_callback_data *csi_remove_callback_data; struct component_terminate_callback_data *component_terminate_callback_data; - struct healthcheck_active *healthcheck_active; + struct amf_healthcheck *healthcheck_active; int interface; int res; void *data; @@ -3010,33 +2808,32 @@ static void message_handler_req_lib_amf_response (void *conn, void *msg) &interface, &data); if (res == -1) { - printf ("invocation not found\n"); + dprintf ("invocation not found\n"); error = SA_AIS_ERR_NOT_EXIST; goto error_exit; } switch (interface) { case AMF_RESPONSE_HEALTHCHECKCALLBACK: - healthcheck_active = (struct healthcheck_active *)data; + dprintf ("healtcheck callback executed from library.\n"); + healthcheck_active = (struct amf_healthcheck*)data; poll_timer_delete (aisexec_poll_handle, - healthcheck_active->timer_healthcheck_duration); + healthcheck_active->timer_handle_duration); - healthcheck_active->timer_healthcheck_duration = 0; + healthcheck_active->timer_handle_duration = 0; poll_timer_add (aisexec_poll_handle, - healthcheck_active->healthcheck->period, + healthcheck_active->saAmfHealthcheckPeriod, (void *)healthcheck_active, timer_function_healthcheck_next, - &healthcheck_active->timer_healthcheck_period); + &healthcheck_active->timer_handle_period); break; case AMF_RESPONSE_CSISETCALLBACK: csi_set_callback_data = (struct csi_set_callback_data *)data; - dprintf ("csi callback executed from library.\n"); - csi_set_callback_data->comp->ha_state = - csi_set_callback_data->comp->unit->requested_ha_state; + dprintf ("csi set callback executed from library.\n"); // list_add (&csi_set_callback_data->comp-> /* pg_comp_create ( @@ -3052,8 +2849,8 @@ static void message_handler_req_lib_amf_response (void *conn, void *msg) csi_remove_callback_data = (struct csi_remove_callback_data *)data; dprintf ("response from removing the CSI\n"); // AAAA - list_del (&csi_remove_callback_data->csi->si->unit_list); - list_del (&csi_remove_callback_data->csi->csi_list); +// list_del (&csi_remove_callback_data->csi->si->su_list); +// list_del (&csi_remove_callback_data->csi->si_csi_list); free (csi_remove_callback_data); break; @@ -3083,1936 +2880,102 @@ error_exit: LEAVE_VOID(); } - -#ifdef COMPILE_OUT -/* - * Executive Message Implementation - */ -static void message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required) +static void amf_dump_comp (struct amf_comp *comp ,void *data) { -#ifdef COMPILE_OUT - struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message; - struct res_lib_amf_componentregister res_lib_amf_componentregister; - struct amf_comp *component; - struct amf_comp *amfProxyComponent; - SaAisErrorT error; - - log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n", - getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName)); - - /* - * Determine if proxy isn't registered - */ - error = SA_AIS_OK; - component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName); - amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName); - - /* - * If a node is joining menber ship ,Component States Synchronize - */ - if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) { - amf_synchronize (message, source_addr); - return; - } - - /* - * If component not in configuration files, return error - */ - if (component == 0) { - error = SA_ERR_NOT_EXIST; - } - - /* - * If proxy doesn't exist and isn't registered, return error - */ - if ((amfProxyComponent == 0 && - req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) || - (amfProxyComponent && amfProxyComponent->registered == 0)) { - - error = SA_ERR_NOT_EXIST; - } - - /* - * If component already registered, return error - */ - if (error == SA_AIS_OK) { - if (component->registered) { - error = SA_ERR_EXIST; - } - } - - /* - * Finally register component and setup links for proxy if - * proxy present - */ - if (error == SA_AIS_OK) { - component->local = 0; - component->registered = 1; - component->conn_info = req_exec_amf_componentregister->source.conn_info; - component->source_addr = source_addr; -// component->currentReadinessState = SA_AMF_OUT_OF_SERVICE; -// component->newReadinessState = SA_AMF_OUT_OF_SERVICE; - component->currentHAState = 0; - component->newHAState = 0; - component->probableCause = 0; - component->enabledUnlockedState = 0; - component->disabledUnlockedState = 0; - component->healthcheck_outstanding = 0; - - if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) { - component->saAmfProxyComponent = amfProxyComponent; - } - } - - /* - * If this node originated the request to the cluster, respond back - * to the AMF library - */ - if (message_source_is_local(&req_exec_amf_componentregister->source)) { - if (error == SA_AIS_OK) { - component->local = 1; - req_exec_amf_componentregister->source.conn_info->component = component; - } - - log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n", - req_exec_amf_componentregister->source.conn_info->fd); - - res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister); - res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER; - res_lib_amf_componentregister.header.error = error; - - openais_conn_send_response (req_exec_amf_componentregister->source.conn_info, - &res_lib_amf_componentregister, - sizeof (struct res_lib_amf_componentregister)); - } - - /* - * If no error on registration, determine if we should enter new state - */ - if (error == SA_AIS_OK) { - dsm (component); - } - -#endif -} - -static void message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required) -{ - struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message; - struct res_lib_amf_componentunregister res_lib_amf_componentunregister; - struct amf_comp *component; - struct amf_comp *amfProxyComponent; - SaAisErrorT error; - - log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n", - getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName)); - - component = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName); - amfProxyComponent = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName); - - /* - * Check for proxy and component not existing in system - */ - error = SA_AIS_OK; - if (component == 0) { - error = SA_ERR_NOT_EXIST; - } - if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) { - if (amfProxyComponent) { - if (amfProxyComponent->registered == 0) { - error = SA_ERR_NOT_EXIST; - } - } else { - error = SA_ERR_NOT_EXIST; - } - } - - /* - * If there is a proxycompname, make sure it is the proxy - * of compName - */ - if (error == SA_AIS_OK && amfProxyComponent) { - if (component->saAmfProxyComponent != amfProxyComponent) { - error = SA_ERR_BAD_OPERATION; - } - } - - /* - * Finally unregister the component - */ - if (error == SA_AIS_OK) { - component->registered = 0; -// dsmEnabledUnlockedTransitionDisabledUnlocked (component); - } - - /* - * If this node originated the request to the cluster, respond back - * to the AMF library - */ - if (message_source_is_local (&req_exec_amf_componentunregister->source)) { - log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n", - req_exec_amf_componentunregister->source.conn_info->fd); - - res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister); - res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER; - res_lib_amf_componentunregister.header.error = error; - - openais_conn_send_response (req_exec_amf_componentunregister->source.conn_info, - &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister)); - } - - return; -} - -static void message_handler_req_exec_amf_componenterrorreport (void *message, struct in_addr source_addr, int endian_conversion_required) -{ - struct req_exec_amf_componenterrorreport *req_exec_amf_componenterrorreport = (struct req_exec_amf_componenterrorreport *)message; - struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport; - struct amf_comp *comp; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_NOTICE, "Executive: ErrorReport for %s\n", - getSaNameT (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent)); - - comp = find_comp (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent); - if (comp == 0) { - error = SA_AIS_ERR_NOT_EXIST; - } - - /* - * If this node originated the request to the cluster, respond back - * to the AMF library - */ - if (message_source_is_local (&req_exec_amf_componenterrorreport->source)) { - log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n", - req_exec_amf_componenterrorreport->source.conn_info->fd); - if (comp) { - } - - res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport); - res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT; - res_lib_amf_componenterrorreport.header.error = error; - - openais_conn_send_response (req_exec_amf_componenterrorreport->source.conn_info, - &res_lib_amf_componenterrorreport, sizeof (struct res_lib_amf_componenterrorreport)); - } - - return (0); -} - -static void message_handler_req_exec_amf_componenterrorclear (void *message, struct in_addr source_addr, int endian_conversion_required) -{ - struct req_exec_amf_componenterrorclear *req_exec_amf_componenterrorclear = (struct req_exec_amf_componenterrorclear *)message; - struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear; - struct amf_comp *component; - SaAisErrorT error = SA_ERR_BAD_OPERATION; - -#ifdef COMPILE_OUT - log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n", - getSaNameT (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName)); - - component = find_comp (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName); - if (component && component->registered) { - /* - * Mark component in service if its a AMF service - * connected to this aisexec - */ - if (component->probableCause) { - component->probableCause = 0; - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - dsm (component); - } - error = SA_AIS_OK; - } - - /* - * If this node originated the request to the cluster, respond back - * to the AMF library - */ - if (message_source_is_local (&req_exec_amf_componenterrorclear->source)) { - log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n", - req_exec_amf_componenterrorclear->source.conn_info->fd); - - res_lib_amf_componenterrorclear.header.size = sizeof (struct res_lib_amf_componenterrorclear); - res_lib_amf_componenterrorclear.header.id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR; - res_lib_amf_componenterrorclear.header.error = error; - - openais_conn_send_response (req_exec_amf_componenterrorclear->source.conn_info, - &res_lib_amf_componenterrorclear, sizeof (struct res_lib_amf_componenterrorclear)); - } - -#endif - return (0); -} -#endif -#ifdef COMPILE_OUT -static void grow_amf_track_table (struct conn_info *conn_info, int growby) -{ - struct libamf_ci_trackentry *tracks; - int newsize; - int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries; - - - newsize = growby + currsize; - - if (newsize > currsize) { - tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks, - (newsize) * sizeof (struct libamf_ci_trackentry)); - if (tracks == 0) { -#ifdef DEBUG - printf ("grow_amf_track_table: out of memory, woops\n"); -#endif -// TODO - exit (1); - } - memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry)); - conn_info->ais_ci.u.libamf_ci.trackEntries = newsize; - conn_info->ais_ci.u.libamf_ci.tracks = tracks; - } -} - - -static void component_unregister ( - struct amf_comp *component) -{ - struct req_exec_amf_componentunregister req_exec_amf_componentunregister; - struct iovec iovec; - - /* - * This only works on local components - */ - if (component == 0 || component->local != 1) { - return; - } - log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n", - getSaNameT (&component->name)); - - component->probableCause = SA_AMF_NOT_RESPONDING; - - req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister); - req_exec_amf_componentunregister.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER); - - req_exec_amf_componentunregister.source.conn_info = 0; - req_exec_amf_componentunregister.source.in_addr.s_addr = 0; - - memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister, - 0, sizeof (struct req_lib_amf_componentunregister)); - memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName, - &component->name, - sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_amf_componentunregister; - iovec.iov_len = sizeof (req_exec_amf_componentunregister); - - assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); -} - -static void component_register ( - struct amf_comp *component) -{ - struct req_exec_amf_componentregister req_exec_amf_componentregister; - struct iovec iovec; - - /* - * This only works on local components - */ - if (component == 0 || component->local != 1) { - return; - } - log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n", - getSaNameT (&component->name)); - - req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister); - req_exec_amf_componentregister.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER); - - req_exec_amf_componentregister.source.conn_info = 0; - req_exec_amf_componentregister.source.in_addr.s_addr = 0; - req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState; - req_exec_amf_componentregister.newReadinessState = component->newReadinessState; - req_exec_amf_componentregister.currentHAState = component->currentHAState; - req_exec_amf_componentregister.newHAState = component->newHAState; - - memset (&req_exec_amf_componentregister.req_lib_amf_componentregister, - 0, sizeof (struct req_lib_amf_componentregister)); - memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName, - &component->name, - sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_amf_componentregister; - iovec.iov_len = sizeof (req_exec_amf_componentregister); - - assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); -} - -/*** -This should be used for a partition I think -**/ -void enumerate_components ( - void (*function)(struct amf_comp *, void *data), - void *data) -{ - struct list_head *AmfGroupList; - struct list_head *AmfUnitList; - struct list_head *AmfComponentList; - - struct saAmfGroup *saAmfGroup; - struct saAmfUnit *AmfUnit; - struct amf_comp *AmfComponent; - - - /* - * Search all groups - */ - for (AmfGroupList = saAmfGroupHead.next; - AmfGroupList != &saAmfGroupHead; - AmfGroupList = AmfGroupList->next) { - - saAmfGroup = list_entry (AmfGroupList, - struct saAmfGroup, saAmfGroupList); - - /* - * Search all units - */ - for (AmfUnitList = saAmfGroup->saAmfUnitHead.next; - AmfUnitList != &saAmfGroup->saAmfUnitHead; - AmfUnitList = AmfUnitList->next) { - - AmfUnit = list_entry (AmfUnitList, - struct saAmfUnit, saAmfUnitList); - - /* - * Search all components - */ - for (AmfComponentList = AmfUnit->amf_compHead.next; - AmfComponentList != &AmfUnit->amf_compHead; - AmfComponentList = AmfComponentList->next) { - - AmfComponent = list_entry (AmfComponentList, - struct amf_comp, amf_compList); - - function (AmfComponent, data); - } - } - } -} - -void ha_state_api_set (struct amf_comp *component, SaAmfHAStateT haState) -{ - struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback; - memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback)); - - log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n"); - - if (component->local != 1) { - return; - } - if (component->probableCause == SA_AMF_NOT_RESPONDING) { - return; - } - /* - * this should be an assertion - */ - if (component->conn_info->state != CONN_STATE_ACTIVE || - component->conn_info->service != AMF_SERVICE) { - return; - } - - res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK; - res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback); - res_lib_amf_csisetcallback.header.error = SA_AIS_OK; - - if (res_lib_amf_csisetcallback.invocation == -1) { - printf ("TODO set callback\n"); - } - memcpy (&res_lib_amf_csisetcallback.compName, - &component->name, sizeof (SaNameT)); - memcpy (&res_lib_amf_csisetcallback.csiName, - &component->saAmfProtectionGroup->name, sizeof (SaNameT)); - res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES; - res_lib_amf_csisetcallback.haState = haState; - // TODO set activeCompName to correct component name - memcpy (&res_lib_amf_csisetcallback.activeCompName, - &component->name, sizeof (SaNameT)); - res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN; - - component->newHAState = haState; - - openais_conn_send_response (component->conn_info->conn_info_partner, - &res_lib_amf_csisetcallback, - sizeof (struct res_lib_amf_csisetcallback)); -} - -static void ha_state_group_set ( - struct amf_comp *component, - SaAmfHAStateT haState) -{ - struct req_exec_amf_hastateset req_exec_amf_hastateset; - struct iovec iovec; - - req_exec_amf_hastateset.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_HASTATESET); - req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset); - memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT)); - req_exec_amf_hastateset.haState = haState; - - log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name)); - log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState); - - iovec.iov_base = (char *)&req_exec_amf_hastateset; - iovec.iov_len = sizeof (req_exec_amf_hastateset); - - assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0); -} - -void readiness_state_api_set (struct amf_comp *component, - SaAmfReadinessStateT readinessState) -{ - struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback; - memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback)); - - /* - * If component is local, don't request service from API - */ - if (component->local != 1) { - return; - } - if (component->probableCause == SA_AMF_NOT_RESPONDING) { - return; - } - - /* - * this should be an assertion - */ - if (component->conn_info->state != CONN_STATE_ACTIVE || - component->conn_info->service != AMF_SERVICE) { - - return; - } - - res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK; - res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback); - res_lib_amf_readinessstatesetcallback.header.error = SA_AIS_OK; - res_lib_amf_readinessstatesetcallback.invocation = - req_lib_amf_invocation_create ( - MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK, - comp); - if (res_lib_amf_readinessstatesetcallback.invocation == -1) { - printf ("TODO readiness set callback\n"); - } - memcpy (&res_lib_amf_readinessstatesetcallback.compName, - &component->name, sizeof (SaNameT)); - res_lib_amf_readinessstatesetcallback.readinessState = readinessState; - component->newReadinessState = readinessState; - - log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState); - - openais_conn_send_response (component->conn_info->conn_info_partner, - &res_lib_amf_readinessstatesetcallback, - sizeof (struct res_lib_amf_readinessstatesetcallback)); -} - -static void readiness_state_group_set ( - struct amf_comp *component, - SaAmfReadinessStateT readinessState) -{ - struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset; - struct iovec iovec; - - req_exec_amf_readinessstateset.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_READINESSSTATESET); - req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset); - memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT)); - req_exec_amf_readinessstateset.readinessState = readinessState; - - log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n", - getSaNameT (&component->name)); - log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState); - - iovec.iov_base = (char *)&req_exec_amf_readinessstateset; - iovec.iov_len = sizeof (req_exec_amf_readinessstateset); - - assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); -} - -static void dsmDisabledUnlockedRegisteredOrErrorCancel ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - int serviceUnitEnabled; - - log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n", - getSaNameT (&component->name)); - - unit = component->saAmfUnit; - for (serviceUnitEnabled = 1, list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, - struct amf_comp, amf_compList); - - if (component->registered == 0 || - component->probableCause) { - log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n"); - serviceUnitEnabled = 0; - break; - } - } - if (serviceUnitEnabled == 1) { - log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n"); - component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED; - component->disabledUnlockedState = -1; // SHOULD BE INVALID - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - dsm (component); - } -} - -static void dsmDisabledUnlockedFailedComponent ( - struct amf_comp *component) -{ - log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n", - getSaNameT (&component->name)); - switch (component->enabledUnlockedState) { - case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED: - case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED: - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED; - if (component->probableCause == SA_AMF_NOT_RESPONDING) { - readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE); - } else { - readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE); - } - break; - - case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED: - case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED: - case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED: - case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED: - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED; - if (component->probableCause == SA_AMF_NOT_RESPONDING) { - ha_state_group_set (component, SA_AMF_QUIESCED); - } else { - ha_state_api_set (component, SA_AMF_QUIESCED); - } - poll_timer_delete (aisexec_poll_handle, - component->timer_healthcheck); - component->timer_healthcheck = 0; - break; - - default: - log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState); - break; - } -} - -static void dsmDisabledUnlockedFailed ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - - unit = component->saAmfUnit; - - for (list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - dsmDisabledUnlockedFailedComponent (component); - } - return; -} - -static void dsmDisabledUnlockedQuiescedRequested ( - struct amf_comp *component) -{ - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED; - dsm (component); -} - -static void dsmDisabledUnlockedQuiescedCompleted ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - int serviceUnitQuiesced; - - unit = component->saAmfUnit; - for (serviceUnitQuiesced = 1, list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - - if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) { - if (component->currentHAState != SA_AMF_QUIESCED) { - log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n"); - serviceUnitQuiesced = 0; - break; - } - } - } - if (serviceUnitQuiesced == 1) { - log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n"); - for (list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - - log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n", - getSaNameT (&component->name)); - - if ( component->probableCause == SA_AMF_NOT_RESPONDING ) { - readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE); - } else { - readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE); - } - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED; - } - } -} - -static void dsmDisabledUnlockedOutOfServiceRequested ( - struct amf_comp *component) -{ - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED; - dsm (component); -} - -static void dsmDisabledUnlockedOutOfServiceCompleted ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - int serviceUnitOutOfService; - struct saAmfGroup *group = 0; - struct list_head *comp_list = 0; - struct list_head *unit_list = 0; - int serviceUnitInStandby = 0; - int activeServiceUnits = 0; - - /* - * Once all components of a service unit are out of service, - * activate another service unit in standby - */ - log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name)); - - /* - * Determine if all components have responded to going out of service - */ - - unit = component->saAmfUnit; - for (serviceUnitOutOfService = 1, list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - - if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) { - if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) { - log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n"); - serviceUnitOutOfService = 0; - break; - } - } - - if ( component->registered == 0 ) { - protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED); - } - - } - - group = unit->saAmfGroup; - activeServiceUnits = activeServiceUnitsCount(group); - if (activeServiceUnits>=group->saAmfActiveUnitsDesired) { - return; - } - - if (serviceUnitOutOfService == 1) { - log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n"); - /* - * Search all units - */ - for (unit_list = group->saAmfUnitHead.next; - unit_list != &group->saAmfUnitHead; - unit_list = unit_list->next) { - - unit = list_entry (unit_list, - struct saAmfUnit, saAmfUnitList); - - log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name)); - /* - * Search all components - */ - for (serviceUnitInStandby = 1, - comp_list = unit->amf_compHead.next; - comp_list != &unit->amf_compHead; - comp_list = comp_list->next) { - - component = list_entry (comp_list, - struct amf_comp, amf_compList); - - if (component->currentHAState != SA_AMF_STANDBY) { - serviceUnitInStandby = 0; - break; /* for iteration of service unit components */ - } - } - if (serviceUnitInStandby) { - break; /* for iteration of service group's service units */ - } - } - - /* - * All components in service unit are standby, activate standby service unit - */ - if (serviceUnitInStandby) { - log_printf (LOG_LEVEL_DEBUG, "unit in standby\n"); - for (list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, - struct amf_comp, amf_compList); - - ha_state_api_set (component, SA_AMF_ACTIVE); - } - } else { - log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n"); - } - } -} - -static void dsmEnabledUnlockedInitial ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - - unit = component->saAmfUnit; - for (list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - - readiness_state_api_set (component, SA_AMF_IN_SERVICE); - log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n", - getSaNameT (&component->name)); - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED; - } -} - -static void dsmEnabledUnlockedInServiceRequested ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - int in_service; - - log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name)); - - unit = component->saAmfUnit; - for (in_service = 1, list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - - if (component->currentReadinessState != SA_AMF_IN_SERVICE) { - log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n"); - in_service = 0; - break; - } - } - if (in_service) { - log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n"); - - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED; - dsm (component); - } -} - -static void dsmEnabledUnlockedInServiceCompleted ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - SaAmfHAStateT newHaState; - int activeServiceUnits; - - log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name)); - - unit = component->saAmfUnit; - for (list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, - struct amf_comp, amf_compList); - - log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n"); - - /* - * Count number of active service units - */ - activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup); - if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) { - - newHaState = SA_AMF_ACTIVE; - log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name)); - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED; - } else { - newHaState = SA_AMF_STANDBY; - log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name)); - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED; - } - ha_state_api_set (component, newHaState); - } -} - -static void dsmEnabledUnlockedActiveRequested ( - struct amf_comp *component) -{ - if (component->local == 1) { - log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer1\n"); - poll_timer_add (aisexec_poll_handle, - component->healthcheckInterval, - (void *)component->conn_info, - timer_function_libamf_healthcheck, - &component->timer_healthcheck); - } - - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED; -} - -static void dsmEnabledUnlockedStandbyRequested ( - struct amf_comp *component) -{ - if (component->local == 1) { - - log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer2\n"); - - poll_timer_add (aisexec_poll_handle, - component->healthcheckInterval, - (void *)component->conn_info, - timer_function_libamf_healthcheck, - &component->timer_healthcheck); - } - - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED; -} - -static void dsmEnabledUnlockedTransitionDisabledUnlocked ( - struct amf_comp *component) -{ - struct saAmfUnit *unit; - struct list_head *list; - - unit = component->saAmfUnit; - for (list = unit->amf_compHead.next; - list != &unit->amf_compHead; - list = list->next) { - - component = list_entry (list, struct amf_comp, amf_compList); - - log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n", - getSaNameT (&component->name)); - - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED; - } - - component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED; - dsm (component); -} - -static void dsmSynchronizeStaus ( - struct amf_comp *component) -{ - enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED; - struct saAmfUnit *unit; - struct saAmfGroup *group; - struct list_head *list; - int activeServiceUnits; - - if (component->currentReadinessState == component->newReadinessState) { - - if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - - } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED; - unit_status = AMF_ENABLED_UNLOCKED; - - } else if (component->currentReadinessState == SA_AMF_QUIESCED) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - } - - } else { - if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - - } else if (component->newReadinessState == SA_AMF_IN_SERVICE) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED; - unit_status = AMF_ENABLED_UNLOCKED; - } else { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - } - } - - if (component->currentHAState == component->newHAState) { - - if (component->currentHAState == SA_AMF_ACTIVE) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED; - unit_status = AMF_ENABLED_UNLOCKED; - - } else if (component->currentHAState == SA_AMF_STANDBY) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED; - unit_status = AMF_ENABLED_UNLOCKED; - - } else { - /* depend on readiness status */ - } - - } else { - if (component->newHAState == SA_AMF_ACTIVE) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED; - unit_status = AMF_ENABLED_UNLOCKED; - - } else if (component->newHAState == SA_AMF_STANDBY) { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED; - unit_status = AMF_ENABLED_UNLOCKED; - - } else { - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - } - } - - /* Syncronize Operational AdministrativeState */ - component->saAmfUnit->operationalAdministrativeState = unit_status; - - unit = component->saAmfUnit; - group = unit->saAmfGroup; - - for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) { - activeServiceUnits = activeServiceUnitsCount(group); - if (activeServiceUnits <= group->saAmfActiveUnitsDesired) { - break; - } - if (component->currentHAState != SA_AMF_ACTIVE) { - continue; - } - ha_state_api_set (component, SA_AMF_STANDBY); - } - - return; -} - - -static void dsmEnabledUnlocked ( - struct amf_comp *component) -{ - switch (component->enabledUnlockedState) { - case AMF_ENABLED_UNLOCKED_INITIAL: - dsmEnabledUnlockedInitial (component); - break; - case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED: - dsmEnabledUnlockedInServiceRequested (component); - break; - case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED: - dsmEnabledUnlockedInServiceCompleted (component); - break; - case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED: - dsmEnabledUnlockedActiveRequested (component); - break; - case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED: - /* noop - operational state */ - break; - case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED: - dsmEnabledUnlockedStandbyRequested (component); - break; - case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED: - /* noop - operational state */ - break; - - default: - log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n"); - } -} - -static void dsmDisabledUnlocked ( - struct amf_comp *component) -{ - log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n", - getSaNameT (&component->name), - component->disabledUnlockedState); - - switch (component->disabledUnlockedState) { - case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL: - dsmDisabledUnlockedRegisteredOrErrorCancel (component); - break; - - case AMF_DISABLED_UNLOCKED_FAILED: - dsmDisabledUnlockedFailed (component); - break; - - case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED: - dsmDisabledUnlockedQuiescedRequested (component); - break; - - case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED: - dsmDisabledUnlockedQuiescedCompleted (component); - break; - - case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED: - dsmDisabledUnlockedOutOfServiceRequested (component); - break; - - case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED: - dsmDisabledUnlockedOutOfServiceCompleted (component); - break; - - default: - log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState); - } -} - -static void dsm ( - struct amf_comp *component) -{ - log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name)); - - switch (component->saAmfUnit->operationalAdministrativeState) { - case AMF_DISABLED_UNLOCKED: - dsmDisabledUnlocked (component); - break; - case AMF_ENABLED_UNLOCKED: - dsmEnabledUnlocked (component); - break; -/* - AMF_DISABLED_LOCKED, - AMF_ENABLED_STOPPING -*/ - default: - log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n"); - } -} - - -void error_report ( - struct amf_comp *component, - SaAmfProbableCauseT probableCause) -{ - struct req_exec_amf_componenterrorreport req_exec_amf_componenterrorreport; - struct iovec iovec; - - req_exec_amf_componenterrorreport.header.size = sizeof (struct req_exec_amf_componenterrorreport); - req_exec_amf_componenterrorreport.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_ERRORREPORT); - - req_exec_amf_componenterrorreport.source.conn_info = 0; - req_exec_amf_componenterrorreport.source.in_addr.s_addr = 0; - memcpy (&req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.erroneousComponent, - &component->name, - sizeof (SaNameT)); - req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.errorDescriptor.probableCause = probableCause; - - iovec.iov_base = (char *)&req_exec_amf_componenterrorreport; - iovec.iov_len = sizeof (req_exec_amf_componenterrorreport); - - assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 2, TOTEMPG_AGREED) == 0); -} - -int healthcheck_instance = 0; - -struct saAmfProtectionGroup *protectiongroup_find ( - SaNameT *csiName) -{ - struct list_head *AmfGroupList; - struct list_head *AmfProtectionGroupList; - - struct saAmfGroup *saAmfGroup; - struct saAmfProtectionGroup *AmfProtectionGroup; - - /* - * Search all groups - */ - for (AmfGroupList = saAmfGroupHead.next; - AmfGroupList != &saAmfGroupHead; - AmfGroupList = AmfGroupList->next) { - - saAmfGroup = list_entry (AmfGroupList, - struct saAmfGroup, saAmfGroupList); - - /* - * Search all protection groups - */ - for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next; - AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead; - AmfProtectionGroupList = AmfProtectionGroupList->next) { - - AmfProtectionGroup = list_entry (AmfProtectionGroupList, - struct saAmfProtectionGroup, saAmfProtectionGroupList); - - if (name_match (csiName, &AmfProtectionGroup->name)) { - return (AmfProtectionGroup); - } - } - } - return (0); -} - -struct amf_comp *component_in_protectiongroup_find ( - SaNameT *csiName, - SaNameT *compName) -{ - - struct list_head *AmfGroupList = 0; - struct list_head *AmfProtectionGroupList = 0; - struct list_head *AmfComponentList = 0; - - struct saAmfGroup *saAmfGroup = 0; - struct saAmfProtectionGroup *AmfProtectionGroup = 0; - struct amf_comp *AmfComponent = 0; - int found = 0; - - /* - * Search all groups - */ - for (AmfGroupList = saAmfGroupHead.next; - AmfGroupList != &saAmfGroupHead; - AmfGroupList = AmfGroupList->next) { - - saAmfGroup = list_entry (AmfGroupList, - struct saAmfGroup, saAmfGroupList); - - /* - * Search all protection groups - */ - for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next; - AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead; - AmfProtectionGroupList = AmfProtectionGroupList->next) { - - AmfProtectionGroup = list_entry (AmfProtectionGroupList, - struct saAmfProtectionGroup, saAmfProtectionGroupList); - - if (name_match (csiName, &AmfProtectionGroup->name)) { - /* - * Search all components - */ - for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next; - AmfComponentList != &AmfProtectionGroup->saAmfMembersHead; - AmfComponentList = AmfComponentList->next) { - - AmfComponent = list_entry (AmfComponentList, - struct amf_comp, saAmfProtectionGroupList); - - if (name_match (compName, &AmfComponent->name)) { - found = 1; - } - } - } - } - } - - if (found) { - return (AmfComponent); - } else { - return (0); - } -} - -/* - * The response handler for readiness state set callback - */ -static void response_handler_readinessstatesetcallback (struct conn_info *conn_info, - struct req_lib_amf_response *req_lib_amf_response) -{ - - if (req_lib_amf_response->error == SA_AIS_OK && conn_info->component) { - - log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n", - getSaNameT (&conn_info->component->name)); - readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState); - } -} - -/* - * iterate service unit components - * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state - */ -static void response_handler_csisetcallback (struct conn_info *conn_info, - struct req_lib_amf_response *req_lib_amf_response) -{ - - if (req_lib_amf_response->error == SA_AIS_OK && conn_info->component) { - ha_state_group_set (conn_info->component, conn_info->component->newHAState); - } -} - - - -void amf_confchg_njoin (struct amf_comp *component ,void *data) -{ - if (component->source_addr.s_addr != this_ip->sin_addr.s_addr) { - return; - } - - component_register (component); - return; -} - -void amf_confchg_nleave (struct amf_comp *component ,void *data) -{ - struct in_addr *source_addr = (struct in_addr *)data; - struct saAmfUnit *unit; - struct list_head *list; - struct amf_comp *leave_component = NULL; - enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED; - - if (component->source_addr.s_addr != source_addr->s_addr) { - return; - } - - if (!component->registered) { - return; - } - - log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name))); - - /* Component status Initialize */ - unit = component->saAmfUnit; - - for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) { - - component = list_entry (list, - struct amf_comp, amf_compList); - - if (component->source_addr.s_addr != source_addr->s_addr) { - disablestate = AMF_DISABLED_UNLOCKED_FAILED; - continue; - } - - component->registered = 0; - component->local = 0; - component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL; - component->newReadinessState = SA_AMF_OUT_OF_SERVICE; - component->currentReadinessState = SA_AMF_OUT_OF_SERVICE; - component->newHAState = SA_AMF_QUIESCED; - component->currentHAState = SA_AMF_QUIESCED; - component->source_addr.s_addr = 0; - leave_component = component; - } - - if (leave_component == NULL) { - return; - } - - leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED; - leave_component->disabledUnlockedState = disablestate; - - dsm (leave_component); - leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL; - - return; -} - - -/* - * If receiving this message from another cluster node, another cluster node - * has selected a readiness state for a component connected to _that_ cluster - * node. That cluster node API has verified the readiness state, so its time to let - * the rest of the cluster nodes know about the readiness state change. - */ -static void message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required) -{ - struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message; - struct amf_comp *component; - - component = find_comp (&req_exec_amf_readinessstateset->compName); - if (component) { - log_printf (LOG_LEVEL_FROM_GMI, - "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n", - getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState); - - component->currentReadinessState = req_exec_amf_readinessstateset->readinessState; - component->newReadinessState = component->currentReadinessState; - dsm (component); - } - - return (0); -} - -/* - * If receiving this message from another cluster node, another cluster node - * has selected a ha state for a component connected to _that_ cluster - * node. That cluster node API has verified the ha state, so its time to let - * the rest of the cluster nodes know about the HA state change. - */ -static void message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required) -{ - struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message; - struct amf_comp *component; - SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE; - - component = find_comp (&req_exec_amf_hastateset->compName); - if (!component) { - return (0); - } - - log_printf (LOG_LEVEL_FROM_GMI, - "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n", - getSaNameT (&component->name), req_exec_amf_hastateset->haState); - - if ( component->currentHAState == 0 ) { - if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE - || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) { - changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED; - } - } else { - if (component->currentHAState == req_exec_amf_hastateset->haState) { - changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE; - } - } - - component->currentHAState = req_exec_amf_hastateset->haState; - component->newHAState = component->currentHAState; - dsm (component); - - if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) { - protectiongroup_notifications_send (component, changeToComponent); - } - - return (0); -} - - - -static void message_handler_req_lib_amf_readinessstateget (struct conn_info *conn_info, void *message) -{ - struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message; - struct req_exec_amf_componentregister req_exec_amf_componentregister; - struct iovec iovec; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n"); - - req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister); - req_exec_amf_componentregister.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER); - - message_source_set (&req_exec_amf_componentregister.source, conn_info); - - memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister, - req_lib_amf_componentregister, - sizeof (struct req_lib_amf_componentregister)); - - iovec.iov_base = (char *)&req_exec_amf_componentregister; - iovec.iov_len = sizeof (req_exec_amf_componentregister); - - assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); - return (0); -} - -static void message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message) -{ - struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message; - struct req_exec_amf_componentunregister req_exec_amf_componentunregister; - struct iovec iovec; - struct saAmfComponent *component; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n"); - - req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister); - req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER; - - message_source_set (&req_exec_amf_componentunregister.source, conn_info); - - memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister, - req_lib_amf_componentunregister, - sizeof (struct req_lib_amf_componentunregister)); - - component = findComponent (&req_lib_amf_componentunregister->compName); - if (component && component->registered && component->local) { - component->probableCause = SA_AMF_NOT_RESPONDING; - } - iovec.iov_base = (char *)&req_exec_amf_componentunregister; - iovec.iov_len = sizeof (req_exec_amf_componentunregister); - - assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); - return (0); -} - -static void message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message) -{ - struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message; ->>>>>>> .r872 - struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget; - struct amf_comp *component; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_readinessstateget()\n"); - - res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET; - res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget); - res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST; - - component = find_comp (&req_lib_amf_readinessstateget->compName); - log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component); - if (component) { - memcpy (&res_lib_amf_readinessstateget.readinessState, - &component->currentReadinessState, sizeof (SaAmfReadinessStateT)); - res_lib_amf_readinessstateget.header.error = SA_AIS_OK; - } - openais_conn_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget)); - return (0); -} - - -static void message_handler_req_lib_amf_stoppingcomplete (struct conn_info *conn_info_notused, - void *message) -{ - struct req_lib_amf_stoppingcomplete *req_lib_amf_stoppingcomplete = (struct req_lib_amf_stoppingcomplete *)message; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n"); - - amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName); - if (amfProtectionGroup) { - log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName)); - for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) { - if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) { - track = &conn_info->ais_ci.u.libamf_ci.tracks[i]; - break; - } - } - - if (track == 0) { - grow_amf_track_table (conn_info, 1); - track = &conn_info->ais_ci.u.libamf_ci.tracks[i]; - } - - track->active = 1; - track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags; - track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress; - memcpy (&track->csiName, - &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT)); - - conn_info->ais_ci.u.libamf_ci.trackActive += 1; - - list_add (&conn_info->conn_list, &library_notification_send_listhead); - - /* - * If SA_TRACK_CURRENT is specified, write out all current connections - */ - } else { - log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n"); - } - - res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART; - res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart); - res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST; - - if (amfProtectionGroup) { - res_lib_amf_protectiongrouptrackstart.header.error = SA_AIS_OK; - } - openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart, - sizeof (struct res_lib_amf_protectiongrouptrackstart)); - - if (amfProtectionGroup && - req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) { - - protectiongroup_notification_send (conn_info, - track->notificationBufferAddress, - amfProtectionGroup, - 0, - 0, - SA_TRACK_CHANGES_ONLY); - - track->trackFlags &= ~SA_TRACK_CURRENT; - } - return (0); -} - -static void message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message) -{ - struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message; - struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop; - struct libamf_ci_trackentry *track = 0; - int i; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n"); - - for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) { - if (name_match (&req_amf_protectiongrouptrackstop->csiName, - &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) { - - track = &conn_info->ais_ci.u.libamf_ci.tracks[i]; - } - } - - if (track) { - log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName)); - memset (track, 0, sizeof (struct libamf_ci_trackentry)); - conn_info->ais_ci.u.libamf_ci.trackActive -= 1; - if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) { - list_del (&conn_info->conn_list); - } - } - - res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP; - res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop); - res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST; - - if (track) { - res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK; - } - openais_conn_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop, - sizeof (struct res_lib_amf_protectiongrouptrackstop)); - - return (0); -} - -static void message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message) -{ - struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message; - struct req_exec_amf_errorreport req_exec_amf_errorreport; - - struct iovec iovec; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n"); - - req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport); - req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT; - - message_source_set (&req_exec_amf_errorreport.source, conn_info); - - memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport, - req_lib_amf_errorreport, - sizeof (struct req_lib_amf_errorreport)); - - iovec.iov_base = (char *)&req_exec_amf_errorreport; - iovec.iov_len = sizeof (req_exec_amf_errorreport); - - assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); - - return (0); -} - -static void message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message) -{ - struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message; - struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall; - - struct iovec iovec; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n"); - - req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall); - req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL; - - message_source_set (&req_exec_amf_errorcancelall.source, conn_info); - - memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall, - req_lib_amf_errorcancelall, - sizeof (struct req_lib_amf_errorcancelall)); - - iovec.iov_base = (char *)&req_exec_amf_errorcancelall; - iovec.iov_len = sizeof (req_exec_amf_errorcancelall); - - assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0); - - return (0); -} - -static void message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused, - void *message) -{ - struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message; - struct conn_info *inv_conn_info = NULL; ->>>>>>> .r872 - int interface; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_stoppingcomplete()\n"); - - req_lib_amf_invocation_get_and_destroy (req_lib_amf_stoppingcomplete->invocation, - &interface, &inv_conn_info); - - inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState; - - readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING); - - protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE); - - return (0); -} - -void response_handler_healthcheckcallback (struct conn_info *conn_info, - struct req_lib_amf_response *req_lib_amf_response) { - - if (req_lib_amf_response->error == SA_AIS_OK) { - log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n"); - conn_info->component->healthcheck_outstanding = 0; - } -} - -static void message_handler_req_lib_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message) -{ - struct req_lib_amf_componentcapabilitymodelget *req_lib_amf_componentcapabilitymodelget = (struct req_lib_amf_componentcapabilitymodelget *)message; - struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget; - struct amf_comp *component; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentcapabilitymodelget()\n"); - - memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget)); - log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_lib_amf_componentcapabilitymodelget->compName)); - component = find_comp (&req_lib_amf_componentcapabilitymodelget->compName); - if (component && component->registered) { - memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel, - &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT)); - } else { - error = SA_ERR_NOT_EXIST; - } - - res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget); - res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET; - res_lib_amf_componentcapabilitymodelget.header.error = error; - openais_conn_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget, - sizeof (struct res_lib_amf_componentcapabilitymodelget)); - - return (0); -} - -static char disabled_unlocked_state_text[6][64] = { - "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL", - "AMF_DISABLED_UNLOCKED_FAILED", - "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED", - "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED", - "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED", - "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED" -}; - -static char *disabledunlockedstate_ntoa (int state) -{ - static char str[64]; - - if (state >= 0 && state < 6) { - sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state); - }else{ - sprintf (str, "Unknown(%d)", state); - } - - return (str); -} - -static char enabled_unlocked_state_text[7][64] = { - "AMF_ENABLED_UNLOCKED_INITIAL", - "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED", - "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED", - "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED", - "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED", - "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED", - "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED" -}; - -static char *enabledunlockedstate_ntoa (int state) -{ - static char str[64]; - if (state >= 0 && state < 7) { - sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state); - }else{ - sprintf (str, "Unknown(%d)", state); - } - return (str); -} - -#endif -static char presence_state_text[8][32] = { - "unknown", - "uninstantiated", - "instantiating", - "instantiated", - "terminating", - "restarting", - "instantion_failed", - "terminiation_failed" -}; - -static char *presencestate_ntoa (SaAmfPresenceStateT state) -{ - static char str[32]; - - if (state > 0 && state < 9) { - sprintf (str, "%s(%d)", presence_state_text[state], state); - }else{ - sprintf (str, "Unknown(%d)", state); - } - return (str); -} -static char operational_state_text[4][64] = { - "Unknown", - "enabled", - "disabled" -}; - -static char *operationalstate_ntoa (SaAmfOperationalStateT state) -{ - static char str[32]; - - if (state > 0 && state < 3) { - sprintf (str, "%s(%d)", operational_state_text[state], state); - }else{ - sprintf (str, "Unknown(%d)", state); - } - return (str); -} - -static char readiness_state_text[4][32] = { - "Unknown", - "out of service", - "in service", - "quiesced", -}; - -static char *readinessstate_ntoa (int state) -{ - static char str[32]; - - if (state > 0 && state < 4) { - sprintf (str, "%s(%d)", readiness_state_text[state], state); - }else{ - sprintf (str, "Unknown(%d)", state); - } - return (str); -} - -static char ha_state_text[4][32] = { - "Unknown", - "active", - "standby", - "quiesced", -}; - -static char *hastate_ntoa (SaAmfHAStateT state) -{ - - static char str[32]; - - if (state > 0 && state < 4) { - sprintf (str, "%s(%d)", ha_state_text[state], state); - }else{ - sprintf (str, "Unknown(%d)", state); - } - return (str); -} - -static void amf_dump_comp (struct amf_comp *component ,void *data) -{ - char name[64]; +#if 0 int level = LOG_LEVEL_NOTICE; data = NULL; - struct list_head* type_name_list; - struct amf_comp_csi_type_name* type_name; + struct list_head* cs_types; + struct amf_cs_type* cs_type; log_printf (level, "----------------\n" ); - log_printf (level, "registered = %d\n" ,component->registered); - log_printf (level, "local = %d\n" ,component->local ); - log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr)); - memset (name, 0 , sizeof(name)); - memcpy (name, component->name.value, component->name.length); - log_printf (level, "name = %s\n" ,name ); -#if 1 - log_printf (level, "csi type names\n"); - for (type_name_list = component->csi_type_name_head.next; - type_name_list != &component->csi_type_name_head; - type_name_list = type_name_list->next) { + log_printf (level, "source_addr = %s\n", + inet_ntoa (comp->source_addr)); + log_printf (level, "unit = %s\n", + comp->su->name.value); + log_printf (level, "name = %s\n", comp->name.value); + log_printf (level, "cs types\n"); + for (cs_types = comp->cs_types.next; + cs_types != &comp->cs_types; + cs_types = cs_types->next) { + cs_type = list_entry (cs_types, struct amf_cs_type, comp_cs_type_list); + log_printf (level, " name = %s\n" , cs_type->attr_name.value); + } - type_name = list_entry (type_name_list, - struct amf_comp_csi_type_name, list); - - log_printf (level, " name = %s\n" , type_name->name); - } -#endif -#if COMPILE_OUT - /* - * TODO Change to correct state syntax and implement new ...state_ntoa - */ - log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState)); - log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState)); - log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState)); - log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState)); - log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState)); - log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState)); - log_printf (level, "probableCause = %d\n" ,component->probableCause ); + log_printf (level, "category = %u\n", comp->category); + log_printf (level, "capability = %u\n", comp->capability); + log_printf (level, "num_max_active_csi = %u\n", + comp->num_max_active_csi); + log_printf (level, "num_max_standby_csi = %u\n", + comp->num_max_standby_csi); + log_printf (level, "default_clc_cli_timeout = %u\n", + comp->default_clc_cli_timeout); + log_printf (level, "default_callback_timeout = %u\n", + comp->default_callback_timeout); + log_printf (level, "oper state = %s\n", + oper_state_text[comp->saAmfCompOperState]); + log_printf (level, "readiness state = %s\n", + readiness_state_text[comp->saAmfCompReadinessState]); + log_printf (level, "presence state = %s\n", + presence_state_text[comp->saAmfCompPresenceState]); + log_printf (level, "restart_count = %u\n", + comp->restart_count); #endif } -void enumerate_components ( +static void enumerate_components ( void (*function)(struct amf_comp *, void *data), void *data) { + #if 0 struct list_head *AmfGroupList; struct list_head *AmfUnitList; struct list_head *AmfComponentList; - struct amf_group *saAmfGroup; - struct amf_unit *AmfUnit; + struct amf_sg *saAmfGroup; + struct amf_su *AmfUnit; struct amf_comp *AmfComponent; /* * Search all groups */ - for (AmfGroupList = amf_groupHead.next; - AmfGroupList != &amf_groupHead; + for (AmfGroupList = amf_sg_head.next; + AmfGroupList != &amf_sg_head; AmfGroupList = AmfGroupList->next) { saAmfGroup = list_entry (AmfGroupList, - struct amf_group, group_list); + struct amf_sg, application_sg_list); /* * Search all units */ - for (AmfUnitList = saAmfGroup->unit_head.next; - AmfUnitList != &saAmfGroup->unit_head; + for (AmfUnitList = saAmfGroup->su_head.next; + AmfUnitList != &saAmfGroup->su_head; AmfUnitList = AmfUnitList->next) { AmfUnit = list_entry (AmfUnitList, - struct amf_unit, unit_list); + struct amf_su, sg_su_list); /* * Search all components */ - for (AmfComponentList = AmfUnit->comp_head.next; + for (AmfComponentList = AmfUnit->comp_head.next; AmfComponentList != &AmfUnit->comp_head; AmfComponentList = AmfComponentList->next) { AmfComponent = list_entry (AmfComponentList, - struct amf_comp, comp_list); + struct amf_comp, su_comp_list); function (AmfComponent, data); } } } + #endif } -void amf_dump ( ) +static void amf_dump ( ) { enumerate_components (amf_dump_comp, NULL); - fflush (stderr); - - return; } diff --git a/exec/amfconfig.c b/exec/amfconfig.c index 7d5e7d60..724e0d28 100644 --- a/exec/amfconfig.c +++ b/exec/amfconfig.c @@ -1,10 +1,13 @@ /* * Copyright (c) 2002-2005 MontaVista Software, Inc. + * Author: Steven Dake (sdake@mvista.com) + * + * Copyright (c) 2006 Ericsson AB. + * Author: Hans Feldt + * Description: Reworked to match AMF B.02 information model * * All rights reserved. * - * Author: Steven Dake (sdake@mvista.com) - * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without @@ -35,10 +38,6 @@ #include #include #include -#include -#include -#include -#include #include "../include/saAis.h" #include "../include/saAmf.h" @@ -46,24 +45,27 @@ #include "../include/list.h" #include "util.h" #include "amfconfig.h" -#include "mempool.h" #include "totem.h" - -DECLARE_LIST_INIT (amf_groupHead); -DECLARE_LIST_INIT (amf_healthcheck_head); - -static char error_string_response[512]; +#include "print.h" typedef enum { AMF_HEAD, - AMF_GROUP, - AMF_UNIT, - AMF_COMPONENT, - AMF_COMPONENT_CSI_TYPE_NAMES, - AMF_SERVICEINSTANCE, - AMF_SERVICEINSTANCE_CSIDESCRIPTOR, - AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE, - AMF_HEALTHCHECK + AMF_APPLICATION, + AMF_CLUSTER, + AMF_NODE, + AMF_SG, + AMF_SU, + AMF_COMP, + AMF_COMP_ENV_VAR, + AMF_COMP_CS_TYPE, + AMF_SI, + AMF_SI_RANKED_SU, + AMF_SI_DEPENDENCY, + AMF_CSI, + AMF_CSI_ATTRIBUTE, + AMF_HEALTHCHECK, + AMF_CSI_DEPENDENCIES, + AMF_CS_TYPE, } amf_parse_t; typedef enum { @@ -75,87 +77,64 @@ typedef enum { MAIN_EVENT } main_parse_t; -void setSaNameT (SaNameT *name, char *str) { - strncpy ((char *)name->value, str, SA_MAX_NAME_LENGTH); - if (strlen ((char *)name->value) > SA_MAX_NAME_LENGTH) { - name->length = SA_MAX_NAME_LENGTH; - } else { - name->length = strlen (str); - } -} +#ifndef OPENAIS_CLUSTER_STARTUP_TIMEOUT +#define OPENAIS_CLUSTER_STARTUP_TIMEOUT 5000 +#endif -int SaNameTisEqual (SaNameT *str1, char *str2) { - if (str1->length == strlen (str2)) { - return ((strncmp ((char *)str1->value, (char *)str2, - str1->length)) == 0); - } else { - return 0; - } -} - -struct amf_healthcheck *find_healthcheck (SaAmfHealthcheckKeyT *key) +struct amf_healthcheck *amf_find_healthcheck (struct amf_comp *comp, SaAmfHealthcheckKeyT *key) { struct amf_healthcheck *healthcheck; struct amf_healthcheck *ret_healthcheck = 0; - struct list_head *list; - for (list = amf_healthcheck_head.next; - list != &amf_healthcheck_head; - list = list->next) { + for (healthcheck = comp->healthcheck_head; + healthcheck != NULL; + healthcheck = healthcheck->next) { - healthcheck = list_entry (list, - struct amf_healthcheck, list); - - if (memcmp (key, &healthcheck->key, sizeof (SaAmfHealthcheckKeyT)) == 0) { + if (memcmp (key, &healthcheck->safHealthcheckKey, sizeof (SaAmfHealthcheckKeyT)) == 0) { ret_healthcheck = healthcheck; break; } } + return (ret_healthcheck); } -struct amf_comp *find_comp (SaNameT *name) +struct amf_comp *amf_find_comp (struct amf_cluster *cluster, SaNameT *name) { - struct list_head *list_group = 0; - struct list_head *list_unit = 0; - struct list_head *AmfComponentList = 0; + struct amf_application *app; + struct amf_sg *group; + struct amf_su *unit; + struct amf_comp *comp; - struct amf_group *amf_group = 0; - struct amf_unit *amf_unit = 0; - struct amf_comp *AmfComponent = 0; + for (app = cluster->application_head; app != NULL; app = app->next) { + for (group = app->sg_head; group != NULL; group = group->next) { + for (unit = group->su_head; unit != NULL; unit = unit->next) { + for (comp = unit->comp_head; comp != NULL; comp = comp->next) { + if (name_match (name, &comp->name)) { + return comp; + } + } + } + } + } + + return (0); +} + +struct amf_su *amf_find_unit (struct amf_cluster *cluster, SaNameT *name) +{ + struct amf_application *app; + struct amf_sg *group; + struct amf_su *unit = 0; int found = 0; - /* - * Search all groups - */ - for (list_group = amf_groupHead.next; - list_group != &amf_groupHead && found == 0; - list_group = list_group->next) { - - amf_group = list_entry (list_group, - struct amf_group, group_list); - - /* - * Search all units - */ - for (list_unit = amf_group->unit_head.next; - list_unit != &amf_group->unit_head && found == 0; - list_unit = list_unit->next) { - - amf_unit = list_entry (list_unit, - struct amf_unit, unit_list); - - /* - * Search all components - */ - for (AmfComponentList = amf_unit->comp_head.next; - AmfComponentList != &amf_unit->comp_head && found == 0; - AmfComponentList = AmfComponentList->next) { - - AmfComponent = list_entry (AmfComponentList, - struct amf_comp, comp_list); - - if (name_match (name, &AmfComponent->name)) { + for (app = cluster->application_head; + app != NULL && found == 0; app = app->next) { + for (group = app->sg_head; + group != NULL && found == 0; group = group->next) { + for (unit = group->su_head; + unit != NULL && found == 0; unit = unit->next) { + if (name_match (name, &unit->name)) { found = 1; } } @@ -163,118 +142,194 @@ struct amf_comp *find_comp (SaNameT *name) } if (found) { - return (AmfComponent); + return (unit); } else { return (0); } } -struct amf_unit *find_unit (SaNameT *name) +static int init_category (struct amf_comp *comp, char *loc) { - struct list_head *list_group = 0; - struct list_head *list_unit = 0; - - struct amf_group *amf_group = 0; - struct amf_unit *amf_unit = 0; - int found = 0; - - /* - * Search all groups - */ - for (list_group = amf_groupHead.next; - list_group != &amf_groupHead && found == 0; - list_group = list_group->next) { - - amf_group = list_entry (list_group, - struct amf_group, group_list); - - /* - * Search all units - */ - for (list_unit = amf_group->unit_head.next; - list_unit != &amf_group->unit_head && found == 0; - list_unit = list_unit->next) { - - amf_unit = list_entry (list_unit, - struct amf_unit, unit_list); - - if (name_match (name, &amf_unit->name)) { - found = 1; - } - } - } - - if (found) { - return (amf_unit); + if (strcmp (loc, "sa_aware") == 0) { + comp->saAmfCompCategory = SA_AMF_COMP_SA_AWARE; + } else if (strcmp (loc, "proxy") == 0) { + comp->saAmfCompCategory = SA_AMF_COMP_PROXY; + } else if (strcmp (loc, "proxied") == 0) { + comp->saAmfCompCategory = SA_AMF_COMP_PROXIED; + } else if (strcmp (loc, "local") == 0) { + comp->saAmfCompCategory = SA_AMF_COMP_LOCAL; + } else { + return -1; + } + + return 0; +} + +static int init_capability (struct amf_comp *comp, char *loc) +{ + if (strcmp (loc, "x_active_and_y_standby") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_AND_Y_STANDBY; + } else if (strcmp (loc, "x_active_or_y_standby") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_OR_Y_STANDBY; + } else if (strcmp (loc, "one_active_or_y_standby") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_Y_STANDBY; + } else if (strcmp (loc, "one_active_or_one_standby") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_ONE_STANDBY; + } else if (strcmp (loc, "x_active") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE; + } else if (strcmp (loc, "1_active") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_1_ACTIVE; + } else if (strcmp (loc, "non_preinstantiable") == 0) { + comp->saAmfCompCapability = SA_AMF_COMP_NON_PRE_INSTANTIABLE; } else { - return (0); + return -1; + } + + return 0; +} + +static int init_recovery_on_error (struct amf_comp *comp, char *loc) +{ + if (strcmp (loc, "component_restart") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_RESTART; + } else if (strcmp (loc, "component_failover") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_FAILOVER; + } else if (strcmp (loc, "node_switchover") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_NODE_SWITCHOVER; + } else if (strcmp (loc, "node_failover") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILOVER; + } else if (strcmp (loc, "node_failfast") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILFAST; + } else if (strcmp (loc, "application_restart") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_APPLICATION_RESTART; + } else if (strcmp (loc, "cluster_reset") == 0) { + comp->saAmfCompRecoveryOnError = SA_AMF_CLUSTER_RESET; + } else { + return -1; + } + + return 0; +} + +static struct amf_comp *new_comp(struct amf_su *su) +{ + struct amf_comp *comp = calloc (1, sizeof (struct amf_comp)); + + if (comp == NULL) { + openais_exit_error(AIS_DONE_OUT_OF_MEMORY); + } + comp->next = su->comp_head; + su->comp_head = comp; + comp->su = su; + comp->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED; + comp->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED; + comp->saAmfCompNumMaxInstantiateWithoutDelay = 2; + comp->saAmfCompNumMaxAmStartAttempt = 2; + comp->saAmfCompNumMaxAmStopAttempt = 2; + + return comp; +} + +static void post_init_comp(struct amf_comp *comp) +{ + if (comp->saAmfCompInstantiateTimeout == 0) { + comp->saAmfCompInstantiateTimeout = comp->saAmfCompDefaultClcCliTimeout; + } + if (comp->saAmfCompTerminateTimeout == 0) { + comp->saAmfCompTerminateTimeout = comp->saAmfCompDefaultClcCliTimeout; + } + if (comp->saAmfCompCleanupTimeout == 0) { + comp->saAmfCompCleanupTimeout = comp->saAmfCompDefaultClcCliTimeout; + } + if (comp->saAmfCompAmStartTimeout == 0) { + comp->saAmfCompAmStartTimeout = comp->saAmfCompDefaultClcCliTimeout; + } + if (comp->saAmfCompAmStopTimeout == 0) { + comp->saAmfCompAmStopTimeout = comp->saAmfCompDefaultClcCliTimeout; + } + if (comp->saAmfCompTerminateCallbackTimeout == 0) { + comp->saAmfCompTerminateCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut; + } + if (comp->saAmfCompCSISetCallbackTimeout == 0) { + comp->saAmfCompCSISetCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut; + } + if (comp->saAmfCompCSIRmvCallbackTimeout == 0) { + comp->saAmfCompCSIRmvCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut; } } -static char *strstr_rs (const char *haystack, const char *needle) +static char *trim_str(char *str) { - char *end_address; - char *new_needle; - - new_needle = (char *)mempool_strdup (needle); - new_needle[strlen(new_needle) - 1] = '\0'; - - end_address = strstr (haystack, new_needle); - if (end_address) { - end_address += strlen (new_needle); - end_address = strstr (end_address, needle + strlen (new_needle)); - } - if (end_address) { - end_address += 1; /* skip past { or = */ - do { - if (*end_address == '\t' || *end_address == ' ') { - end_address++; - } else { - break; - } - } while (*end_address != '\0'); + char *s = str + strlen (str) - 1; + while (*s == '\t' || *s == ' ' || *s == '{') { + *s = '\0'; + s--; } - mempool_free (new_needle); - return (end_address); + return str; } - -extern int openais_amf_config_read (char **error_string) +static char *rm_beginning_ws(char *str) { - char line[255]; + char *s = str + strlen (str) - 1; + while (*s == '\t' || *s == ' ') { + *s = '\0'; + s--; + } + s = str; + while (*s == '\t' || *s == ' ') { + s++; + } + return s; +} + +int amf_config_read (struct amf_cluster *cluster, char **error_string) +{ + char buf[1024]; + char *line; FILE *fp; char *filename; amf_parse_t current_parse = AMF_HEAD; int line_number = 0; char *loc; int i; - - struct amf_group *amf_group = 0; - struct amf_unit *amf_unit = 0; - struct amf_comp *amf_comp = 0; - struct amf_si *amf_si = 0; - struct amf_healthcheck *amf_healthcheck = 0; - struct amf_comp_csi_type_name *csi_type_name = 0; - struct amf_csi *amf_csi = 0; - struct amf_csi_name_value *csi_name_value = NULL; + struct amf_application *app = 0; + struct amf_node *node = 0; + struct amf_sg *sg = 0; + struct amf_su *su = 0; + struct amf_comp *comp = 0; + struct amf_si *si = 0; + struct amf_si_ranked_su *si_ranked_su = 0; + struct amf_si_dependency *si_dependency = 0; + struct amf_healthcheck *healthcheck = 0; + struct amf_csi *csi = 0; + struct amf_csi_attribute *attribute = 0; + SaStringT env_var; + int comp_env_var_cnt = 0; + int comp_cs_type_cnt = 0; + int csi_attr_cnt = 0; + int csi_dependencies_cnt = 0; + char *error_reason = NULL; + char *value; filename = getenv("OPENAIS_AMF_CONFIG_FILE"); - if (!filename) - filename = "/etc/ais/groups.conf"; + if (!filename) { + filename = "/etc/ais/amf.conf"; + } fp = fopen (filename, "r"); - if (fp == 0) { - sprintf (error_string_response, - "Can't read %s file reason = (%s).\n", - filename, strerror (errno)); - *error_string = error_string_response; + sprintf (buf, "Can't read %s file reason = (%s).\n", + filename, strerror (errno)); + *error_string = buf; return (-1); } - while (fgets (line, 255, fp)) { + cluster->saAmfClusterStartupTimeout = -1; + + while (fgets (buf, 255, fp)) { line_number += 1; + line = buf; line[strlen(line) - 1] = '\0'; /* * Clear out comments and empty lines @@ -294,339 +349,557 @@ extern int openais_amf_config_read (char **error_string) } } + /* Trim whitespace from beginning of string */ + line = rm_beginning_ws(line); + error_reason = line; + error_reason = NULL; switch (current_parse) { case AMF_HEAD: - if (strstr_rs (line, "group{")) { - amf_group = (struct amf_group *)mempool_malloc (sizeof (struct amf_group)); - memset (amf_group, 0, sizeof (struct amf_group)); - list_init (&amf_group->group_list); - list_init (&amf_group->unit_head); - list_init (&amf_group->si_head); - list_add (&amf_group->group_list, &amf_groupHead); - memset (amf_group->clccli_path, 0, sizeof (&amf_unit->clccli_path)); - memset (amf_group->binary_path, 0, sizeof (&amf_unit->binary_path)); - current_parse = AMF_GROUP; - } else - if (strstr_rs (line, "healthcheck{")) { - amf_healthcheck = (struct amf_healthcheck *)mempool_malloc (sizeof (struct amf_healthcheck)); - memset (amf_healthcheck, 0, sizeof (struct amf_healthcheck)); - list_init (&amf_healthcheck->list); - list_add_tail (&amf_healthcheck->list, - &amf_healthcheck_head); - current_parse = AMF_HEALTHCHECK; + if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) { + setSaNameT (&cluster->name, trim_str (loc)); + current_parse = AMF_CLUSTER; } else { goto parse_error; } break; - case AMF_GROUP: - if ((loc = strstr_rs (line, "name=")) != 0) { - setSaNameT (&amf_group->name, loc); - } else - if ((loc = strstr_rs (line, "model=")) != 0) { - if (strcmp (loc, "2n") == 0) { - amf_group->model = SA_AMF_2N_REDUNDANCY_MODEL; - } else - if (strcmp (loc, "nplusm") == 0) { - amf_group->model = SA_AMF_NPM_REDUNDANCY_MODEL; - } else - if (strcmp (loc, "nway") == 0) { - printf ("nway redundancy model not supported.\n"); - goto parse_error; - } else - if (strcmp (loc, "nwayactive") == 0) { - printf ("nway active redundancy model not supported.\n"); - goto parse_error; - } else - if (strcmp (loc, "noredundancy") == 0) { - amf_group->model = SA_AMF_NO_REDUNDANCY_MODEL; - } else { + case AMF_CLUSTER: + if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) { + setSaNameT (&cluster->saAmfClusterClmCluster, loc); + } else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) { + cluster->saAmfClusterStartupTimeout = atol(loc); + } else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) { + node = calloc (1, sizeof (struct amf_node)); + node->next = cluster->node_head; + cluster->node_head = node; + node->saAmfNodeAutoRepair = SA_TRUE; + node->cluster = cluster; + node->saAmfNodeSuFailOverProb = -1; + node->saAmfNodeSuFailoverMax = ~0; + setSaNameT (&node->name, trim_str (loc)); + current_parse = AMF_NODE; + } else if ((loc = strstr_rs (line, "safApp=")) != 0) { + app = calloc (1, sizeof (struct amf_application)); + app->next = cluster->application_head; + cluster->application_head = app; + app->cluster = cluster; + setSaNameT (&app->name, trim_str (loc)); + current_parse = AMF_APPLICATION; + } else if (strstr_rs (line, "}")) { + if (cluster->saAmfClusterStartupTimeout == -1) { + error_reason = "saAmfClusterStartupTimeout missing"; goto parse_error; } - } else - if ((loc = strstr_rs (line, "preferred-active-units=")) != 0) { - amf_group->preferred_active_units = atoi (loc); - } else - if ((loc = strstr_rs (line, "preferred-standby-units=")) != 0) { - amf_group->preferred_standby_units = atoi (loc); - } else - if ((loc = strstr_rs (line, "maximum-active-instances=")) != 0) { - amf_group->maximum_active_instances = atoi (loc); - } else - if ((loc = strstr_rs (line, "maximum-standby-instances=")) != 0) { - amf_group->maximum_standby_instances = atoi (loc); - } else - if ((loc = strstr_rs (line, "clccli_path=")) != 0) { - strcpy (amf_group->clccli_path, loc); - } else - if ((loc = strstr_rs (line, "binary_path=")) != 0) { - strcpy (amf_group->binary_path, loc); - } else - if ((loc = strstr_rs (line, "component_restart_probation=")) != 0) { - amf_group->component_restart_probation = atoi (loc); - printf ("restart probation %d\n", amf_group->component_restart_probation); - } else - if ((loc = strstr_rs (line, "component_restart_max=")) != 0) { - amf_group->component_restart_max = atoi (loc); - printf ("restart max %d\n", amf_group->component_restart_max); - } else - if ((loc = strstr_rs (line, "unit_restart_probation=")) != 0) { - amf_group->unit_restart_probation = atoi (loc); - printf ("unit restart probation %d\n", amf_group->unit_restart_probation); - } else - if ((loc = strstr_rs (line, "unit_restart_max=")) != 0) { - amf_group->unit_restart_max = atoi (loc); - printf ("unit restart max %d\n", amf_group->unit_restart_max); - } else - - if (strstr_rs (line, "unit{")) { - amf_unit = (struct amf_unit *)mempool_malloc (sizeof (struct amf_unit)); - memset (amf_unit, 0, sizeof (struct amf_unit)); - amf_unit->amf_group = amf_group; - - amf_unit->operational_state = SA_AMF_OPERATIONAL_DISABLED; - amf_unit->presence_state = SA_AMF_PRESENCE_UNINSTANTIATED; - list_init (&amf_unit->comp_head); - list_init (&amf_unit->si_head); - amf_unit->escalation_level = ESCALATION_LEVEL_NO_ESCALATION; - amf_unit->restart_count = 0; - list_add_tail (&amf_unit->unit_list, &amf_group->unit_head); - memset (amf_unit->clccli_path, 0, sizeof (&amf_unit->clccli_path)); - memset (amf_unit->binary_path, 0, sizeof (&amf_unit->binary_path)); - current_parse = AMF_UNIT; - } else - if (strstr_rs (line, "serviceinstance{")) { - amf_si = (struct amf_si *)mempool_malloc (sizeof (struct amf_si)); - memset (amf_si, 0, sizeof (struct amf_si)); - list_init (&amf_si->csi_head); - list_init (&amf_si->unit_list); - list_init (&amf_si->pg_head); - list_add_tail (&amf_si->si_list, &amf_group->si_head); - amf_si->group = amf_group; - current_parse = AMF_SERVICEINSTANCE; - } else - if (strstr_rs (line, "}")) { + /* spec: set to default value if zero */ + if (cluster->saAmfClusterStartupTimeout == 0) { + cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT; + } current_parse = AMF_HEAD; } else { goto parse_error; } break; - case AMF_UNIT: - if ((loc = strstr_rs (line, "name=")) != 0) { - setSaNameT (&amf_unit->name, loc); - } else - if ((loc = strstr_rs (line, "component{")) != 0) { - amf_comp = (struct amf_comp *)mempool_malloc (sizeof (struct amf_comp)); - memset (amf_comp, 0, sizeof (struct amf_comp)); - amf_comp->unit = amf_unit; - amf_comp->operational_state = SA_AMF_OPERATIONAL_DISABLED; - amf_comp->presence_state = SA_AMF_PRESENCE_UNINSTANTIATED; - - list_init (&amf_comp->comp_list); - list_init (&amf_comp->healthcheck_list); - list_init (&amf_comp->csi_type_name_head); - list_add_tail (&amf_comp->comp_list, &amf_unit->comp_head); - - memset (amf_comp->clccli_path, 0, sizeof (&amf_comp->clccli_path)); - memset (amf_comp->binary_path, 0, sizeof (&amf_unit->binary_path)); - memset (amf_comp->binary_name, 0, sizeof (&amf_comp->binary_name)); - - current_parse = AMF_COMPONENT; - } else - if ((loc = strstr_rs (line, "clccli_path=")) != 0) { - strcpy (amf_unit->clccli_path, loc); - } else - if ((loc = strstr_rs (line, "binary_path=")) != 0) { - strcpy (amf_unit->binary_path, loc); - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_GROUP; - } else { - goto parse_error; - } - break; - - case AMF_COMPONENT: - if ((loc = strstr_rs (line, "name=")) != 0) { - setSaNameT (&amf_comp->name, loc); - } else -#ifdef COMPILE_OUT - if ((loc = strstr_rs (line, "model=")) != 0) { - if (strcmp (loc, "x_active_and_y_standby") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_AND_Y_STANDBY; - } else - if (strcmp (loc, "x_active_or_y_standby") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_OR_Y_STANDBY; - } else - if (strcmp (loc, "1_active_or_y_standby") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_Y_STANDBY; - } else - if (strcmp (loc, "1_active_or_1_standby") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_1_STANDBY; - } else - if (strcmp (loc, "x_active") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE; - } else - if (strcmp (loc, "1_active") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE; - } else - if (strcmp (loc, "no_active") == 0) { - amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_NO_ACTIVE; + case AMF_NODE: + if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb")) != 0) { + node->saAmfNodeSuFailOverProb = atol(loc); + } else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax")) != 0) { + node->saAmfNodeSuFailoverMax = atol(loc); + } else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) { + if (strcmp (loc, "true") == 0) { + node->saAmfNodeAutoRepair = SA_TRUE; + } else if (strcmp (loc, "false") == 0) { + node->saAmfNodeAutoRepair = SA_FALSE; } else { goto parse_error; } - } else -#endif - if ((loc = strstr_rs(line, "comptype=")) != 0) { - if (strstr (line, "sa_aware")) { - amf_comp->comptype = clc_component_sa_aware; - } else - if (strstr (line, "proxied_pre")) { - amf_comp->comptype = clc_component_proxied_pre; - } else - if (strstr (line, "proxied_non_pre")) { - amf_comp->comptype = clc_component_proxied_non_pre; - } else - if (strstr (line, "non_proxied_non_sa_aware")) { - amf_comp->comptype = clc_component_proxied_non_pre; + } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) { + if (strcmp (loc, "true") == 0) { + node->saAmfNodeRebootOnTerminationFailure = SA_TRUE; + } else if (strcmp (loc, "false") == 0) { + node->saAmfNodeRebootOnTerminationFailure = SA_FALSE; } else { goto parse_error; } - } else - if ((loc = strstr_rs(line, "instantiate=")) != 0) { - strcpy (amf_comp->instantiate_cmd, loc); - } else - if ((loc = strstr_rs(line, "terminate=")) != 0) { - strcpy (amf_comp->terminate_cmd, loc); - } else - if ((loc = strstr_rs(line, "cleanup=")) != 0) { - strcpy (amf_comp->cleanup_cmd, loc); - } else - if ((loc = strstr_rs(line, "am_start=")) != 0) { - strcpy (amf_comp->am_start_cmd, loc); - } else - if ((loc = strstr_rs(line, "am_stop=")) != 0) { - strcpy (amf_comp->am_stop_cmd, loc); - } else + } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) { + if (strcmp (loc, "true") == 0) { + node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE; + } else if (strcmp (loc, "false") == 0) { + node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE; + } else { + goto parse_error; + } + } else if (strstr_rs (line, "}")) { + if (node->saAmfNodeSuFailOverProb == -1) { + error_reason = "saAmfNodeSuFailOverProb missing"; + goto parse_error; + } + if (node->saAmfNodeSuFailoverMax == ~0) { + error_reason = "saAmfNodeSuFailoverMax missing"; + goto parse_error; + } + current_parse = AMF_CLUSTER; + } else { + goto parse_error; + } + break; + + case AMF_APPLICATION: if ((loc = strstr_rs (line, "clccli_path=")) != 0) { - strcpy (amf_comp->clccli_path, loc); - } else - if ((loc = strstr_rs (line, "binary_path=")) != 0) { - strcpy (amf_comp->binary_path, loc); - } else - if ((loc = strstr_rs (line, "bn=")) != 0) { - strcpy (amf_comp->binary_name, loc); - } else - if ((loc = strstr_rs (line, "csi_type_name{")) != 0) { - csi_type_name = - (struct amf_comp_csi_type_name*)mempool_malloc (sizeof(struct amf_comp_csi_type_name)); - - list_init(&csi_type_name->list); - list_add_tail (&csi_type_name->list, &amf_comp->csi_type_name_head); - - current_parse = AMF_COMPONENT_CSI_TYPE_NAMES; - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_UNIT; + strcpy (app->clccli_path, loc); + } else if ((loc = strstr_rs (line, "safSg=")) != 0) { + sg = calloc (1, sizeof (struct amf_sg)); + sg->next = app->sg_head; + app->sg_head = sg; + sg->saAmfSGNumPrefActiveSUs = 1; + sg->saAmfSGNumPrefStandbySUs = 1; + sg->saAmfSGCompRestartProb = -1; + sg->saAmfSGCompRestartMax = ~0; + sg->saAmfSGSuRestartProb = -1; + sg->saAmfSGSuRestartMax = ~0; + sg->saAmfSGAutoAdjustProb = -1; + sg->saAmfSGAutoRepair = SA_TRUE; + sg->application = app; + current_parse = AMF_SG; + setSaNameT (&sg->name, trim_str (loc)); + } else if ((loc = strstr_rs (line, "safSi=")) != 0) { + si = calloc (1, sizeof (struct amf_si)); + si->next = app->si_head; + app->si_head = si; + si->application = app; + si->saAmfSIPrefActiveAssignments = 1; + si->saAmfSIPrefStandbyAssignments = 1; + setSaNameT (&si->name, trim_str (loc)); + current_parse = AMF_SI; + } else if ((loc = strstr_rs (line, "safCSType=")) != 0) { + current_parse = AMF_CS_TYPE; + } else if (strstr_rs (line, "}")) { + current_parse = AMF_CLUSTER; } else { goto parse_error; } break; - case AMF_COMPONENT_CSI_TYPE_NAMES: - if ((loc = strstr_rs (line, "name=")) != 0) { - setSaNameT(&csi_type_name->name, loc); - } else - if ((loc = strstr_rs (line, "csi_type_name{")) != 0) { - csi_type_name = - (struct amf_comp_csi_type_name*)mempool_malloc (sizeof(struct amf_comp_csi_type_name)); - - list_init(&csi_type_name->list); - list_add_tail (&csi_type_name->list, &amf_comp->csi_type_name_head); - - current_parse = AMF_COMPONENT_CSI_TYPE_NAMES; - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_COMPONENT; - } else { - goto parse_error; - } - break; - case AMF_SERVICEINSTANCE: - if ((loc = strstr_rs (line, "name=")) != 0) { - setSaNameT (&amf_si->name, loc); - } else - if ((loc = strstr_rs (line, "csi_descriptor{")) != 0) { - amf_csi = (struct amf_csi*)mempool_malloc (sizeof(struct amf_csi)); - - list_init(&amf_csi->csi_list); - list_init(&amf_csi->name_value_head); - list_add_tail (&amf_csi->csi_list, &amf_si->csi_head); - - current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR; - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_GROUP; + case AMF_SG: + if ((loc = strstr_rs (line, "clccli_path=")) != 0) { + strcpy (sg->clccli_path, loc); + } else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) { + if (strcmp (loc, "2n") == 0) { + sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL; + } else if (strcmp (loc, "nplusm") == 0) { + sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL; + } else if (strcmp (loc, "nway") == 0) { + error_reason = "nway redundancy model not supported"; + goto parse_error; + } else if (strcmp (loc, "nwayactive") == 0) { + error_reason = "nway active redundancy model not supported"; + goto parse_error; + } else if (strcmp (loc, "noredundancy") == 0) { + sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL; + } else { + goto parse_error; + } + } else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) { + sg->saAmfSGNumPrefActiveSUs = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) { + sg->saAmfSGNumPrefStandbySUs = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) { + sg->saAmfSGMaxActiveSIsperSUs = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) { + sg->saAmfSGMaxStandbySIsperSUs = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) { + sg->saAmfSGCompRestartProb = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) { + sg->saAmfSGCompRestartMax = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) { + sg->saAmfSGSuRestartProb = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) { + sg->saAmfSGSuRestartMax = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) { + sg->saAmfSGAutoAdjustProb = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) { + sg->saAmfSGAutoRepair = atoi (loc); + } else if ((loc = strstr_rs (line, "safSu=")) != 0) { + su = calloc (1, sizeof (struct amf_su)); + su->next = sg->su_head; + sg->su_head = su; + su->sg = sg; + su->saAmfSUOperState = SA_AMF_OPERATIONAL_DISABLED; + su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED; + su->escalation_level = ESCALATION_LEVEL_NO_ESCALATION; + su->saAmfSUFailover = 1; + setSaNameT (&su->name, trim_str (loc)); + current_parse = AMF_SU; + } else if (strstr_rs (line, "}")) { + if (sg->saAmfSGRedundancyModel == 0) { + error_reason = "saAmfSGRedundancyModel missing"; + goto parse_error; + } + if (sg->saAmfSGCompRestartProb == -1) { + error_reason = "saAmfSGCompRestartProb missing"; + goto parse_error; + } + if (sg->saAmfSGCompRestartMax == ~0) { + error_reason = "saAmfSGCompRestartMax missing"; + goto parse_error; + } + if (sg->saAmfSGSuRestartProb == -1) { + error_reason = "saAmfSGSuRestartProb missing"; + goto parse_error; + } + if (sg->saAmfSGSuRestartMax == ~0) { + error_reason = "saAmfSGSuRestartMax missing"; + goto parse_error; + } + if (sg->saAmfSGAutoAdjustProb == -1) { + error_reason = "saAmfSGAutoAdjustProb missing"; + goto parse_error; + } + if (sg->saAmfSGAutoRepair > 1) { + error_reason = "saAmfSGAutoRepair erroneous"; + goto parse_error; + } + current_parse = AMF_APPLICATION; } else { goto parse_error; } break; - case AMF_SERVICEINSTANCE_CSIDESCRIPTOR: - if ((loc = strstr_rs (line, "csi_name=")) != 0) { - setSaNameT (&amf_csi->name, loc); - } else - if ((loc = strstr_rs (line, "type_name=")) != 0) { - setSaNameT (&amf_csi->type_name, loc); - } else - if ((loc = strstr_rs (line, "name_value{")) != 0) { - csi_name_value = (struct amf_csi_name_value*)mempool_malloc (sizeof(struct amf_csi_name_value)); - list_init(&csi_name_value->csi_name_list); - list_add_tail (&csi_name_value->csi_name_list, &amf_csi->name_value_head); + case AMF_SU: + if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) { + su->saAmfSUNumComponents = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) { + su->saAmfSUIsExternal = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) { + su->saAmfSUFailover = atoi (loc); + } else if ((loc = strstr_rs (line, "clccli_path=")) != 0) { + strcpy (su->clccli_path, loc); + } else if ((loc = strstr_rs (line, "safComp=")) != 0) { + comp = new_comp (su); + comp_env_var_cnt = 0; + comp_cs_type_cnt = 0; + setSaNameT (&comp->name, trim_str (loc)); + current_parse = AMF_COMP; + } else if (strstr_rs (line, "}")) { + if (su->saAmfSUNumComponents == 0) { + error_reason = "saAmfSUNumComponents missing"; + goto parse_error; + } + if (su->saAmfSUIsExternal > 1) { + error_reason = "saAmfSUIsExternal erroneous"; + goto parse_error; + } + if (su->saAmfSUFailover > 1) { + error_reason = "saAmfSUFailover erroneous"; + goto parse_error; + } + current_parse = AMF_SG; + } else { + goto parse_error; + } + break; - current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE; - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_SERVICEINSTANCE; - } else { - goto parse_error; - } - break; - case AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE: - if ((loc = strstr_rs (line, "name=")) != 0) { - strcpy(csi_name_value->name, loc); - } else - if ((loc = strstr_rs (line, "value=")) != 0) { - strcpy(csi_name_value->value, loc); - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR; - } else { - goto parse_error; - } - break; + case AMF_COMP: + if ((loc = strstr_rs (line, "clccli_path=")) != 0) { + strcpy (comp->clccli_path, loc); + } else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) { + current_parse = AMF_COMP_CS_TYPE; + } else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) { + if (init_category(comp, loc) != 0) { + error_reason = "unknown category"; + goto parse_error; + } + } else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) { + if (init_capability(comp, loc) != 0) { + error_reason = "unknown capability model"; + goto parse_error; + } + } else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) { + comp->saAmfCompNumMaxActiveCsi = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) { + comp->saAmfCompNumMaxStandbyCsi = atol (loc); + } else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) { + current_parse = AMF_COMP_ENV_VAR; + } else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) { + comp->saAmfCompDefaultClcCliTimeout = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) { + comp->saAmfCompDefaultCallbackTimeOut = atol (loc); + } else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) { + comp->saAmfCompInstantiateCmdArgv = malloc (strlen(loc) + 1); + strcpy (comp->saAmfCompInstantiateCmdArgv, loc); + } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) { + comp->saAmfCompInstantiateCmd = malloc (strlen(loc) + 1); + strcpy (comp->saAmfCompInstantiateCmd, loc); + } else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) { + comp->saAmfCompInstantiateTimeout = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) { + comp->saAmfCompInstantiationLevel = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) { + comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) { + comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) { + comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc); + } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) { + comp->saAmfCompTerminateCmdArgv = malloc (strlen(loc) + 1); + strcpy (comp->saAmfCompTerminateCmdArgv, loc); + } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) { + comp->saAmfCompTerminateCmd = malloc (strlen(loc) + 1); + strcpy (comp->saAmfCompTerminateCmd, loc); + } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) { + comp->saAmfCompTerminateTimeout = atol (loc); + } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) { + comp->saAmfCompCleanupCmdArgv = malloc (strlen(loc) + 1); + strcpy (comp->saAmfCompCleanupCmdArgv, loc); + } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) { + comp->saAmfCompCleanupCmd = malloc (strlen(loc) + 1); + strcpy (comp->saAmfCompCleanupCmd, loc); + } else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) { + comp->saAmfCompCleanupTimeout = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) { + comp->saAmfCompTerminateCallbackTimeout = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) { + comp->saAmfCompCSISetCallbackTimeout = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) { + comp->saAmfCompQuiescingCompleteTimeout = atol (loc); + } else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) { + comp->saAmfCompCSIRmvCallbackTimeout = atol (loc); + } else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) { + if (init_recovery_on_error (comp, loc) != 0) { + error_reason = "bad value"; + goto parse_error; + } + } else if ((loc = strstr_rs (line, "saAmfCompDisableRestart")) != 0) { + if (strcmp (loc, "false") == 0) { + comp->saAmfCompDisableRestart = SA_FALSE; + } else if (strcmp (loc, "true") == 0) { + comp->saAmfCompDisableRestart = SA_TRUE; + } else { + error_reason = "bad value"; + goto parse_error; + } + } else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) { + setSaNameT (&comp->saAmfCompProxyCsi, loc); + } else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) { + healthcheck = calloc (1, sizeof (struct amf_healthcheck)); + healthcheck->next = comp->healthcheck_head; + comp->healthcheck_head = healthcheck; + healthcheck->comp = comp; + strcpy (healthcheck->safHealthcheckKey.key, trim_str (loc)); + healthcheck->safHealthcheckKey.keyLen = strlen (loc); + current_parse = AMF_HEALTHCHECK; + } else if (strstr_rs (line, "}")) { + if (comp->saAmfCompCategory == 0) { + error_reason = "category missing"; + goto parse_error; + } + if (comp->saAmfCompCapability == 0) { + error_reason = "capability model missing"; + goto parse_error; + } + if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) { + comp->comptype = clc_component_sa_aware; + } else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) { + if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) { + comp->comptype = clc_component_proxied_non_pre; + } else { + comp->comptype = clc_component_proxied_pre; + } + } else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) { + comp->comptype = clc_component_non_proxied_non_sa_aware; + } + if (comp->saAmfCompNumMaxActiveCsi == 0) { + error_reason = "saAmfCompNumMaxActiveCsi missing"; + goto parse_error; + } + if (comp->saAmfCompNumMaxStandbyCsi == 0) { + error_reason = "saAmfCompNumMaxStandbyCsi missing"; + goto parse_error; + } + if (comp->saAmfCompDefaultClcCliTimeout == 0) { + error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous"; + goto parse_error; + } + if (comp->saAmfCompDefaultCallbackTimeOut == 0) { + error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous"; + goto parse_error; + } + if (comp->saAmfCompRecoveryOnError == 0) { + error_reason = "saAmfCompRecoveryOnError missing"; + goto parse_error; + } + post_init_comp (comp); + current_parse = AMF_SU; + } else { + error_reason = line; + goto parse_error; + } + break; + + case AMF_COMP_CS_TYPE: + if (strstr_rs (line, "}")) { + current_parse = AMF_COMP; + } else { + comp_cs_type_cnt++; + comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes, + (comp_cs_type_cnt + 1) * sizeof(SaNameT)); + comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL; + comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = malloc (sizeof(SaNameT)); + setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line); + } + break; + + case AMF_COMP_ENV_VAR: + if (strstr_rs (line, "}")) { + current_parse = AMF_COMP; + } else if ((loc = strchr (line, '=')) != 0) { + comp_env_var_cnt++; + comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv, + (comp_env_var_cnt + 1) * sizeof(SaStringT)); + comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL; + env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = malloc (strlen (line + 1)); + strcpy (env_var, line); + } else { + goto parse_error; + } + break; case AMF_HEALTHCHECK: - if ((loc = strstr_rs (line, "key=")) != 0) { - strcpy ((char *)amf_healthcheck->key.key, loc); - amf_healthcheck->key.keyLen = strlen (loc); - } else - if ((loc = strstr_rs (line, "period=")) != 0) { - amf_healthcheck->period = atoi (loc); - } else - if ((loc = strstr_rs (line, "maximum_duration=")) != 0) { - amf_healthcheck->maximum_duration = atoi (loc); - } else - if (strstr_rs (line, "}")) { - current_parse = AMF_HEAD; + if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) { + healthcheck->saAmfHealthcheckPeriod = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) { + healthcheck->saAmfHealthcheckMaxDuration = atoi (loc); + } else if (strstr_rs (line, "}")) { + current_parse = AMF_COMP; } else { goto parse_error; } break; - + + case AMF_SI: + if ((loc = strstr_rs (line, "safRankedSu=")) != 0) { + si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su)); + si_ranked_su->si_next = si->ranked_sus; + si->ranked_sus = si_ranked_su; + si_ranked_su->si = si; + setSaNameT (&si_ranked_su->name, trim_str (loc)); + current_parse = AMF_SI_RANKED_SU; + } else if ((loc = strstr_rs (line, "safDepend=")) != 0) { + si_dependency = calloc (1, sizeof(struct amf_si_dependency)); + si_dependency->next = si->depends_on; + si->depends_on = si_dependency; + setSaNameT (&si_dependency->name, trim_str (loc)); + current_parse = AMF_SI_DEPENDENCY; + } else if ((loc = strstr_rs (line, "safCsi=")) != 0) { + csi = calloc (1, sizeof(struct amf_csi)); + csi->next = si->csi_head; + si->csi_head = csi; + csi->si = si; + setSaNameT (&csi->name, trim_str (loc)); + current_parse = AMF_CSI; + } else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG{")) != 0) { + setSaNameT (&si->saAmfSIProtectedbySG, loc); + } else if ((loc = strstr_rs (line, "saAmfSIRank{")) != 0) { + si->saAmfSIRank = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) { + si->saAmfSINumCSIs = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) { + si->saAmfSIPrefActiveAssignments = atoi (loc); + } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) { + si->saAmfSIPrefStandbyAssignments = atoi (loc); + } else if (strstr_rs (line, "}")) { + if (si->saAmfSINumCSIs == 0) { + error_reason = "saAmfSINumCSIs missing"; + goto parse_error; + } + current_parse = AMF_APPLICATION; + } else { + goto parse_error; + } + break; + + case AMF_SI_RANKED_SU: + if ((loc = strstr_rs (line, "saAmfRank=")) != 0) { + si_ranked_su->saAmfRank = atoi (loc); + } else if (strstr_rs (line, "}")) { + current_parse = AMF_SI; + } else { + goto parse_error; + } + break; + + case AMF_SI_DEPENDENCY: + if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) { + si_dependency->saAmfToleranceTime = atoi (loc); + } else if (strstr_rs (line, "}")) { + current_parse = AMF_SI; + } else { + goto parse_error; + } + break; + + case AMF_CSI: + if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) { + setSaNameT (&csi->saAmfCSTypeName, loc); + } else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) { + attribute = calloc (1, sizeof(struct amf_csi_attribute)); + attribute->next = csi->attributes_head; + csi->attributes_head = attribute; + attribute->name = malloc (strlen (loc) + 1); + strcpy (attribute->name, trim_str (loc)); + csi_attr_cnt = 1; + current_parse = AMF_CSI_ATTRIBUTE; + } else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) { + csi_dependencies_cnt = 0; + current_parse = AMF_CSI_DEPENDENCIES; + } else if (strstr_rs (line, "}")) { + if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) { + error_reason = "saAmfCSTypeName missing"; + goto parse_error; + } + current_parse = AMF_SI; + } else { + goto parse_error; + } + break; + + case AMF_CSI_DEPENDENCIES: + if (strstr_rs (line, "}")) { + current_parse = AMF_CSI; + } else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) { + csi_dependencies_cnt++; + csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies, + (csi_dependencies_cnt + 1) * sizeof(SaNameT)); + csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL; + csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] = malloc (sizeof(SaNameT)); + setSaNameT (csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc); + } else { + goto parse_error; + } + break; + + case AMF_CSI_ATTRIBUTE: + if ((loc = strstr_rs (line, "}")) != 0) { + current_parse = AMF_CSI; + } else { + value = rm_beginning_ws (line); + attribute->value = realloc (attribute->value, + sizeof (SaStringT) * csi_attr_cnt + 1); + attribute->value[csi_attr_cnt - 1] = malloc (strlen (value) + 1); + strcpy (attribute->value[csi_attr_cnt - 1], value); + attribute->value[csi_attr_cnt] = NULL; + csi_attr_cnt++; + } + break; + + case AMF_CS_TYPE: + if ((loc = strstr_rs (line, "}")) != 0) { + current_parse = AMF_APPLICATION; + } + break; + default: - printf ("Invalid state\n"); + error_reason = "Invalid state\n"; goto parse_error; break; } @@ -636,9 +909,9 @@ extern int openais_amf_config_read (char **error_string) return (0); parse_error: - sprintf (error_string_response, - "parse error at %s: %d.\n", filename, line_number); - *error_string = error_string_response; + sprintf (buf, "parse error at %s: %d: %s\n", + filename, line_number, error_reason); + *error_string = buf; fclose (fp); return (-1); } diff --git a/exec/amfconfig.h b/exec/amfconfig.h index d6ad6120..cc9b8d51 100644 --- a/exec/amfconfig.h +++ b/exec/amfconfig.h @@ -1,10 +1,12 @@ /* * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * * Author: Steven Dake (sdake@mvista.com) * + * Copyright (c) 2006 Ericsson AB. + * Author: Hans Feldt + * Description: Reworked to match AMF B.02 information model + * + * All rights reserved. * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without @@ -31,7 +33,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ -#include + +#include #include "../include/saAis.h" #include "../include/saAmf.h" #include "../include/list.h" @@ -40,13 +43,6 @@ #ifndef AMFCONFIG_H_DEFINED #define AMFCONFIG_H_DEFINED -struct amf_healthcheck { - SaAmfHealthcheckKeyT key; - SaTimeT period; - SaTimeT maximum_duration; - struct amf_comp *comp; - struct list_head list; -}; enum escalation_levels { ESCALATION_LEVEL_NO_ESCALATION = 1, /* execute component restart */ @@ -55,92 +51,6 @@ enum escalation_levels { ESCALATION_LEVEL_THREE = 4 /* escalate to node failover */ }; -struct amf_unit { - SaNameT name; - struct list_head comp_head; - struct list_head unit_list; - struct amf_group *amf_group; - struct list_head si_head; - int si_count; - SaAmfPresenceStateT presence_state; - SaAmfOperationalStateT operational_state; - SaAmfReadinessStateT readiness_state; - SaAmfHAStateT assigned_ha_state; - SaAmfHAStateT requested_ha_state; - - char clccli_path[1024]; - char binary_path[1024]; - - poll_timer_handle restart_timer; - int restart_count; - enum escalation_levels escalation_level; -}; - -struct amf_csi_name_value { - struct list_head csi_name_list; - char name[128]; - char value[128]; -}; - -struct amf_si; -struct amf_csi { - SaNameT name; - SaNameT type_name; - struct amf_unit *unit; - struct list_head csi_list; - struct list_head unit_head; - struct list_head name_value_head; - struct amf_si *si; - int pg_set; -}; - -struct amf_si { - SaNameT name; - int csi_count; - struct list_head si_list; - struct amf_group *group; - struct list_head csi_head; - struct list_head pg_head; - struct list_head unit_list; - SaAmfAdminStateT administrative_state; - SaAmfOperationalStateT operational_state; -}; - -struct amf_pg { - SaNameT name; - struct amf_comp *comp; - struct list_head pg_list; - struct list_head pg_comp_head; -}; - -struct amf_pg_comp { - struct amf_comp *comp; - struct amf_csi *csi; - struct list_head list; -}; - -struct amf_group { - SaNameT name; - saAmfRedundancyModelT model; - SaUint32T preferred_active_units; - SaUint32T preferred_standby_units; - SaUint32T maximum_active_instances; - SaUint32T maximum_standby_instances; - SaAmfAdminStateT administrative_state; - struct list_head group_list; - struct list_head unit_head; - struct list_head si_head; - - char clccli_path[1024]; - char binary_path[1024]; - - unsigned int component_restart_probation; - unsigned int component_restart_max; - - unsigned int unit_restart_probation; - unsigned int unit_restart_max; -}; - enum clc_component_types { clc_component_sa_aware = 0, /* sa aware */ clc_component_proxied_pre = 1, /* proxied, pre-instantiable */ @@ -148,52 +58,321 @@ enum clc_component_types { clc_component_non_proxied_non_sa_aware = 3 /* non-proxied, non sa aware */ }; +struct amf_si_assignment; +struct amf_csi_assignment; +struct amf_healthcheck; + +struct amf_cluster { + /* Configuration Attributes */ + SaNameT name; + int saAmfClusterStartupTimeout; + SaNameT saAmfClusterClmCluster; + + /* Runtime Attributes */ + SaAmfAdminStateT saAmfClusterAdminState; + + /* Relations */ + struct amf_node *node_head; + struct amf_application *application_head; + + /* Implementation */ + poll_timer_handle timeout_handle; +}; + +struct amf_node { + /* Configuration Attributes */ + SaNameT name; + SaNameT saAmfNodeClmNode; + int saAmfNodeSuFailOverProb; + SaUint32T saAmfNodeSuFailoverMax; + SaBoolT saAmfNodeAutoRepair; + SaBoolT saAmfNodeRebootOnInstantiationFailure; + SaBoolT saAmfNodeRebootOnTerminationFailure; + + /* Runtime Attributes */ + SaAmfAdminStateT saAmfNodeAdminState; + SaAmfOperationalStateT saAmfNodeOperState; + + /* Relations */ + struct amf_cluster *cluster; + + /* Implementation */ + struct amf_node *next; +}; + +struct amf_application { + /* Configuration Attributes */ + SaNameT name; + + /* Runtime Attributes */ + SaAmfAdminStateT saAmfApplicationAdminState; + SaUint32T saAmfApplicationCurrNumSG; + + /* Relations */ + struct amf_cluster *cluster; + struct amf_sg *sg_head; + struct amf_si *si_head; + + /* Implementation */ + char clccli_path[PATH_MAX]; + char binary_path[PATH_MAX]; + struct amf_application *next; +}; + +struct amf_sg { + /* Configuration Attributes */ + SaNameT name; + saAmfRedundancyModelT saAmfSGRedundancyModel; + SaBoolT saAmfSGAutoAdjust; + SaUint32T saAmfSGNumPrefActiveSUs; + SaUint32T saAmfSGNumPrefStandbySUs; + SaUint32T saAmfSGNumPrefInserviceSUs; + SaUint32T saAmfSGNumPrefAssignedSUs; + SaUint32T saAmfSGMaxActiveSIsperSUs; + SaUint32T saAmfSGMaxStandbySIsperSUs; + SaTimeT saAmfSGCompRestartProb; + SaUint32T saAmfSGCompRestartMax; + SaTimeT saAmfSGSuRestartProb; + SaUint32T saAmfSGSuRestartMax; + SaTimeT saAmfSGAutoAdjustProb; + SaBoolT saAmfSGAutoRepair; + + /* Runtime Attributes */ + SaAmfAdminStateT saAmfSGAdminState; + SaUint32T saAmfSGNumCurrAssignedSUs; + SaUint32T saAmfSGNumCurrNonInstantiatedSpareSUs; + SaUint32T saAmfSGNumCurrInstantiatedSpareSUs; + + /* Relations */ + struct amf_application *application; + struct amf_su *su_head; + + /* Implementation */ + char clccli_path[PATH_MAX]; + char binary_path[PATH_MAX]; + struct amf_sg *next; +}; + +struct amf_su { + /* Configuration Attributes */ + SaNameT name; + SaUint32T saAmfSURank; + SaUint32T saAmfSUNumComponents; + SaBoolT saAmfSUIsExternal; + SaBoolT saAmfSUFailover; + + /* Runtime Attributes */ + SaBoolT saAmfSUPreInstantiable; + SaAmfOperationalStateT saAmfSUOperState; + SaAmfAdminStateT saAmfSUAdminState; + SaAmfReadinessStateT saAmfSUReadinessState; + SaAmfPresenceStateT saAmfSUPresenceState; + SaNameT saAmfSUAssignedSIs; + SaNameT saAmfSUHostedByNode; + SaUint32T saAmfSUNumCurrActiveSIs; + SaUint32T saAmfSUNumCurrStandbySIs; + SaUint32T saAmfSURestartCount; + + /* Relations */ + struct amf_sg *sg; + struct amf_comp *comp_head; + struct amf_si_assignment *assigned_sis; + + /* Implementation */ + char clccli_path[PATH_MAX]; + char binary_path[PATH_MAX]; + SaUint32T su_failover_cnt; /* missing in SAF specs? */ + enum escalation_levels escalation_level; + SaAmfHAStateT requested_ha_state; + struct amf_su *next; +}; + struct amf_comp { - int registered; - int local; - void *conn; + /* Configuration Attributes */ SaNameT name; - struct in_addr source_addr; + SaNameT **saAmfCompCsTypes; + saAmfCompCategoryT saAmfCompCategory; + saAmfCompCapabilityModelT saAmfCompCapability; + SaUint32T saAmfCompNumMaxActiveCsi; + SaUint32T saAmfCompNumMaxStandbyCsi; + SaStringT *saAmfCompCmdEnv; + int saAmfCompDefaultClcCliTimeout; + int saAmfCompDefaultCallbackTimeOut; + SaStringT saAmfCompInstantiateCmd; + SaStringT saAmfCompInstantiateCmdArgv; + int saAmfCompInstantiateTimeout; + SaUint32T saAmfCompInstantiationLevel; + SaUint32T saAmfCompNumMaxInstantiateWithoutDelay; + SaUint32T saAmfCompNumMaxInstantiateWithDelay; + int saAmfCompDelayBetweenInstantiateAttempts; + SaStringT saAmfCompTerminateCmd; + int saAmfCompTerminateTimeout; + SaStringT saAmfCompTerminateCmdArgv; + SaStringT saAmfCompCleanupCmd; + int saAmfCompCleanupTimeout; + SaStringT saAmfCompCleanupCmdArgv; + SaStringT saAmfCompAmStartCmd; + int saAmfCompAmStartTimeout; + SaStringT saAmfCompAmStartCmdArgv; + SaUint32T saAmfCompNumMaxAmStartAttempt; + SaStringT saAmfCompAmStopCmd; + int saAmfCompAmStopTimeout; + SaStringT saAmfCompAmStopCmdArgv; + SaUint32T saAmfCompNumMaxAmStopAttempt; + int saAmfCompTerminateCallbackTimeout; + int saAmfCompCSISetCallbackTimeout; + int saAmfCompQuiescingCompleteTimeout; + int saAmfCompCSIRmvCallbackTimeout; + SaAmfRecommendedRecoveryT saAmfCompRecoveryOnError; + SaBoolT saAmfCompDisableRestart; + SaNameT saAmfCompProxyCsi; + + /* Runtime Attributes */ + SaAmfOperationalStateT saAmfCompOperState; + SaAmfReadinessStateT saAmfCompReadinessState; + SaAmfPresenceStateT saAmfCompPresenceState; + SaUint32T saAmfCompRestartCount; + SaUint32T saAmfCompNumCurrActiveCsi; + SaUint32T saAmfCompNumCurrStandbyCsi; + SaNameT saAmfCompAssignedCsi; + SaNameT saAmfCompCurrProxyName; + SaNameT saAmfCompCurrProxiedNames; + + /* Relations */ struct amf_comp *proxy_comp; - struct amf_unit *unit; - struct amf_pg *pg; - struct amf_csi *csi; - - struct list_head comp_list; - struct list_head healthcheck_list; - struct list_head csi_type_name_head; + struct amf_su *su; + struct amf_csi_assignment *assigned_csis; + /* Implementation */ + char clccli_path[PATH_MAX]; + char binary_path[PATH_MAX]; + struct amf_comp *next; + void *conn; enum clc_component_types comptype; - - char clccli_path[1024]; - char binary_path[1024]; - char binary_name[1024]; - - char instantiate_cmd[1024]; - char terminate_cmd[1024]; - char cleanup_cmd[1024]; - char am_start_cmd[1024]; - char am_stop_cmd[1024]; - - SaAmfOperationalStateT operational_state; - SaAmfReadinessStateT readiness_state; - SaAmfHAStateT ha_state; - SaAmfPresenceStateT presence_state; + struct amf_healthcheck *healthcheck_head; }; -struct amf_comp_csi_type_name { - struct list_head list; +struct amf_healthcheck { + /* Configuration Attributes */ + SaAmfHealthcheckKeyT safHealthcheckKey; + int saAmfHealthcheckMaxDuration; + int saAmfHealthcheckPeriod; + + /* Relations */ + struct amf_comp *comp; + + /* Implementation */ + struct amf_healthcheck *next; + SaAmfHealthcheckInvocationT invocationType; + poll_timer_handle timer_handle_duration; + poll_timer_handle timer_handle_period; + int active; +}; + +struct amf_si { + /* Configuration Attributes */ SaNameT name; + SaNameT saAmfSIProtectedbySG; + SaUint32T saAmfSIRank; + SaUint32T saAmfSINumCSIs; + SaUint32T saAmfSIPrefActiveAssignments; + SaUint32T saAmfSIPrefStandbyAssignments; + + /* Runtime Attributes */ + SaAmfAdminStateT saAmfSIAdminState; + SaAmfAssignmentStateT saAmfSIAssignmentState; + SaUint32T saAmfSINumCurrActiveAssignments; + SaUint32T saAmfSINumICurrStandbyAssignments; + + /* Relations */ + struct amf_application *application; + struct amf_sg *protects_sg; + struct amf_csi *csi_head; + struct amf_si_assignment *si_assignments; + struct amf_si_dependency *depends_on; + struct amf_si_ranked_su *ranked_sus; + + /* Implementation */ + struct amf_si *next; }; -extern struct list_head amf_group_head; +struct amf_si_ranked_su { + /* Configuration Attributes */ + SaNameT name; + SaUint32T saAmfRank; -extern struct amf_comp *find_comp (SaNameT *name); + /* Relations */ + struct amf_si *si; + struct amf_su *su; -extern struct amf_unit *find_unit (SaNameT *name); + /* Implementation */ + struct amf_si_ranked_su *su_next; + struct amf_si_ranked_su *si_next; +}; -extern struct amf_healthcheck *find_healthcheck (SaAmfHealthcheckKeyT *key); +struct amf_si_dependency { + /* Configuration Attributes */ + SaNameT name; + int saAmfToleranceTime; -extern int openais_amf_config_read (char **error_string); + /* Relations */ + + /* Implementation */ + struct amf_si_dependency *next; +}; + +struct amf_si_assignment { + /* Runtime Attributes */ + SaNameT name; + SaAmfHAStateT saAmfSISUHAState; + + /* Relations */ + + /* Implementation */ +}; + +struct amf_csi { + /* Configuration Attributes */ + SaNameT name; + SaNameT saAmfCSTypeName; + SaNameT **saAmfCSIDependencies; + + /* Relations */ + struct amf_si *si; + struct amf_csi_assignment *csi_assignments; + struct amf_csi_attribute *attributes_head; + + /* Implementation */ + struct amf_csi *next; + int pg_set; +}; + +struct amf_csi_attribute { + /* Configuration Attributes */ + SaStringT name; + SaStringT *value; + + /* Implementation */ + struct amf_csi_attribute *next; +}; + +struct amf_csi_assignment { + /* Runtime Attributes */ + SaNameT name; + SaAmfHAStateT saAmfCSICompHASate; + + /* Relations */ + struct amf_csi *csi; + struct amf_comp *comp; + + /* Implementation */ + struct amf_csi_assignment *comp_next; + struct amf_csi_assignment *csi_next; +}; + +extern struct amf_comp *amf_find_comp (struct amf_cluster *cluster, SaNameT *name); +extern struct amf_su *amf_find_unit (struct amf_cluster *cluster, SaNameT *name); +extern struct amf_healthcheck *amf_find_healthcheck (struct amf_comp *comp, SaAmfHealthcheckKeyT *key); +extern int amf_config_read (struct amf_cluster *cluster, char **error_string); #endif /* AMFCONFIG_H_DEFINED */ diff --git a/exec/mainconfig.h b/exec/mainconfig.h index 9e67c2e9..83cb477f 100644 --- a/exec/mainconfig.h +++ b/exec/mainconfig.h @@ -75,8 +75,6 @@ struct main_config { struct logger_config *logger; }; -extern char *strstr_rs (const char *haystack, const char *needle); - extern int openais_main_config_read ( struct objdb_iface_ver0 *objdb, char **error_string, diff --git a/exec/util.c b/exec/util.c index eb0fc578..db095c97 100644 --- a/exec/util.c +++ b/exec/util.c @@ -84,6 +84,7 @@ void openais_exit_error (enum e_ais_done err) char *getSaNameT (SaNameT *name) { +#if 0 static char ret_name[300]; memset (ret_name, 0, sizeof (ret_name)); @@ -94,4 +95,53 @@ char *getSaNameT (SaNameT *name) memcpy (ret_name, name->value, name->length); } return (ret_name); +#endif + return name->value; } + +char *strstr_rs (const char *haystack, const char *needle) +{ + char *end_address; + char *new_needle; + + new_needle = (char *)strdup (needle); + new_needle[strlen (new_needle) - 1] = '\0'; + + end_address = strstr (haystack, new_needle); + if (end_address) { + end_address += strlen (new_needle); + end_address = strstr (end_address, needle + strlen (new_needle)); + } + if (end_address) { + end_address += 1; /* skip past { or = */ + do { + if (*end_address == '\t' || *end_address == ' ') { + end_address++; + } else { + break; + } + } while (*end_address != '\0'); + } + + free (new_needle); + return (end_address); +} + +void setSaNameT (SaNameT *name, char *str) { + strncpy ((char *)name->value, str, SA_MAX_NAME_LENGTH); + if (strlen ((char *)name->value) > SA_MAX_NAME_LENGTH) { + name->length = SA_MAX_NAME_LENGTH; + } else { + name->length = strlen (str); + } +} + +int SaNameTisEqual (SaNameT *str1, char *str2) { + if (str1->length == strlen (str2)) { + return ((strncmp ((char *)str1->value, (char *)str2, + str1->length)) == 0); + } else { + return 0; + } +} + diff --git a/exec/util.h b/exec/util.h index 8e08ab69..ff79c708 100644 --- a/exec/util.h +++ b/exec/util.h @@ -62,9 +62,12 @@ enum e_ais_done { AIS_DONE_DYNAMICLOAD = -12, AIS_DONE_OBJDB = -13, AIS_DONE_INIT_SERVICES = -14, + AIS_DONE_OUT_OF_MEMORY = -15, }; void openais_exit_error (enum e_ais_done err); - extern char *getSaNameT (SaNameT *name); +extern char *strstr_rs (const char *haystack, const char *needle); +extern void setSaNameT (SaNameT *name, char *str); +extern int SaNameTisEqual (SaNameT *str1, char *str2); #endif /* UTIL_H_DEFINED */ diff --git a/include/ipc_amf.h b/include/ipc_amf.h index 29a74347..d334c4d1 100644 --- a/include/ipc_amf.h +++ b/include/ipc_amf.h @@ -49,7 +49,7 @@ enum req_lib_amf_types { MESSAGE_REQ_AMF_HEALTHCHECKSTOP = 6, MESSAGE_REQ_AMF_HASTATEGET = 7, MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE = 8, - MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTART = 9, + MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK = 9, MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP = 10, MESSAGE_REQ_AMF_COMPONENTERRORREPORT = 11, MESSAGE_REQ_AMF_COMPONENTERRORCLEAR = 12, @@ -66,7 +66,7 @@ enum res_lib_amf_types { MESSAGE_RES_AMF_HEALTHCHECKSTOP = 6, MESSAGE_RES_AMF_HASTATEGET = 7, MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE = 8, - MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART = 9, + MESSAGE_RES_AMF_PROTECTIONGROUPTRACK = 9, MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP = 10, MESSAGE_RES_AMF_COMPONENTERRORREPORT = 11, MESSAGE_RES_AMF_COMPONENTERRORCLEAR = 12, @@ -176,14 +176,14 @@ struct res_lib_amf_csiquiescingcomplete { struct res_header header; }; -struct req_lib_amf_protectiongrouptrackstart { +struct req_lib_amf_protectiongrouptrack { struct req_header header; SaNameT csiName; SaUint8T trackFlags; SaAmfProtectionGroupNotificationT *notificationBufferAddress; }; -struct res_lib_amf_protectiongrouptrackstart { +struct res_lib_amf_protectiongrouptrack { struct res_header header; }; diff --git a/lib/amf.c b/lib/amf.c index ca45bd77..3c6ec9b4 100644 --- a/lib/amf.c +++ b/lib/amf.c @@ -328,10 +328,10 @@ saAmfDispatch ( int i; for (i=0; iresponse_mutex); error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_protectiongrouptrackstart, - sizeof (struct req_lib_amf_protectiongrouptrackstart), - &res_lib_amf_protectiongrouptrackstart, - sizeof (struct res_lib_amf_protectiongrouptrackstart)); + &req_lib_amf_protectiongrouptrack, + sizeof (struct req_lib_amf_protectiongrouptrack), + &res_lib_amf_protectiongrouptrack, + sizeof (struct res_lib_amf_protectiongrouptrack)); pthread_mutex_unlock (&amfInstance->response_mutex); saHandleInstancePut (&amfHandleDatabase, amfHandle); - return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstart.header.error : error); + return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrack.header.error : error); } SaAisErrorT diff --git a/man/openais.conf.5 b/man/openais.conf.5 index 176cb78e..63b77cd9 100644 --- a/man/openais.conf.5 +++ b/man/openais.conf.5 @@ -438,7 +438,7 @@ directive, there is one configuration option which is optional: .TP mode This can either contain the value enabled or disabled. When enabled, AMF will -instantiate the service groups specified in the /etc/ais/groups.conf file. +start the applications specified in the /etc/ais/amf.conf file. The default is disabled. .SH "FILES" @@ -446,8 +446,8 @@ The default is disabled. /etc/ais/openais.conf The openais executive configuration file. .TP -/etc/ais/groups.conf -The openais AMF service groups configuration file. +/etc/ais/amf.conf +The openais AMF configuration file. .SH "SEE ALSO" .BR openais_overview (8), README.amf diff --git a/man/openais_overview.8 b/man/openais_overview.8 index aa3d6125..0d4fabbb 100644 --- a/man/openais_overview.8 +++ b/man/openais_overview.8 @@ -215,7 +215,7 @@ OPENAIS_AMF_CONFIG_FILE This specifies the fully qualified path to the openais Availability Management Framework configuration file. -The default is /etc/ais/groups.conf. +The default is /etc/ais/amf.conf. .TP OPENAIS_DEFAULT_CONFIG_IFACE diff --git a/test/clc_cli_script b/test/clc_cli_script index 86a14e19..b1ea37a2 100755 --- a/test/clc_cli_script +++ b/test/clc_cli_script @@ -33,7 +33,8 @@ # It may be modified to do any action desired. instantiate() { - ./openais-instantiate $COMP_BINARY_PATH/$COMP_BINARY_NAME + echo clc_cli_script instantiating component $SA_AMF_COMPONENT_NAME $1 + ./openais-instantiate $1 RETVAL=$? return $RETVAL } @@ -62,13 +63,22 @@ cleanup() { return $RETVAL } -case "$CLC_CLI_INTERFACE" in +usage() { + echo $"Usage: $0 {instantiate|terminate|cleanup}" +} + +case "$1" in instantiate) - instantiate + if [ $# -gt 1 ]; then + instantiate $2 + else + instantiate $COMP_BINARY_PATH/$COMP_BINARY_NAME + exit 1 + fi ;; terminate) - terminiate + terminate ;; cleanup) @@ -76,9 +86,8 @@ case "$CLC_CLI_INTERFACE" in ;; *) - echo $"Usage: $0 {instantiate|terminate}" + usage exit 1 esac - exit 0 diff --git a/test/testamf1.c b/test/testamf1.c index bb6d4b8b..1fd5bea6 100644 --- a/test/testamf1.c +++ b/test/testamf1.c @@ -156,15 +156,16 @@ void CSISetCallback ( printf ("' for component "); printSaNameT ((SaNameT *)compName); printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); + printf (" requested to enter hastate SA_AMF_ACTIVE for CSI %s\n", + csiDescriptor->csiName.value); res = saAmfResponse (handle, invocation, SA_AIS_OK); int i; TR(TRU, csiDescriptor->csiAttr.number); for(i=0; icsiAttr.number; i++) { - if( strcmp(csiDescriptor->csiAttr.attr[i].attrName, "good_health_limit") == 0){ - good_health = strcmp(csiDescriptor->csiAttr.attr[i].attrValue, "0") ? 0 : 1; - good_health_limit = atoi(csiDescriptor->csiAttr.attr[i].attrValue); + if( strcmp((char*)csiDescriptor->csiAttr.attr[i].attrName, "good_health_limit") == 0){ + good_health = strcmp((char*)csiDescriptor->csiAttr.attr[i].attrValue, "0") ? 0 : 1; + good_health_limit = atoi((char*)csiDescriptor->csiAttr.attr[i].attrValue); } @@ -188,13 +189,14 @@ void CSISetCallback ( printf ("' for component "); printSaNameT ((SaNameT *)compName); printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); + printf (" requested to enter hastate SA_AMF_STANDBY for CSI %s\n", + csiDescriptor->csiName.value); res = saAmfResponse (handle, invocation, SA_AIS_OK); TR(TRU,csiDescriptor->csiAttr.number); for(i=0; icsiAttr.number; i++) { - if(!strcmp(csiDescriptor->csiAttr.attr[i].attrName, "good_health") && - !strcmp(csiDescriptor->csiAttr.attr[i].attrValue, "true")){ + if(!strcmp((char*)csiDescriptor->csiAttr.attr[i].attrName, "good_health") && + !strcmp((char*)csiDescriptor->csiAttr.attr[i].attrValue, "true")){ good_health = 1; } TR(TRS,csiDescriptor->csiAttr.attr[i].attrName);