diff --git a/corosync/Doxyfile b/Doxyfile similarity index 100% rename from corosync/Doxyfile rename to Doxyfile diff --git a/corosync/LICENSE b/LICENSE similarity index 100% rename from corosync/LICENSE rename to LICENSE diff --git a/corosync/Makefile b/Makefile similarity index 100% rename from corosync/Makefile rename to Makefile diff --git a/corosync/Makefile.inc b/Makefile.inc similarity index 100% rename from corosync/Makefile.inc rename to Makefile.inc diff --git a/corosync/Makefile.samples b/Makefile.samples similarity index 100% rename from corosync/Makefile.samples rename to Makefile.samples diff --git a/corosync/README.devmap b/README.devmap similarity index 100% rename from corosync/README.devmap rename to README.devmap diff --git a/corosync/README.recovery b/README.recovery similarity index 100% rename from corosync/README.recovery rename to README.recovery diff --git a/corosync/SECURITY b/SECURITY similarity index 100% rename from corosync/SECURITY rename to SECURITY diff --git a/corosync/TODO b/TODO similarity index 100% rename from corosync/TODO rename to TODO diff --git a/corosync/conf/corosync.conf b/conf/corosync.conf similarity index 100% rename from corosync/conf/corosync.conf rename to conf/corosync.conf diff --git a/corosync/exec/Makefile b/exec/Makefile similarity index 100% rename from corosync/exec/Makefile rename to exec/Makefile diff --git a/corosync/exec/apidef.c b/exec/apidef.c similarity index 100% rename from corosync/exec/apidef.c rename to exec/apidef.c diff --git a/corosync/exec/apidef.h b/exec/apidef.h similarity index 100% rename from corosync/exec/apidef.h rename to exec/apidef.h diff --git a/corosync/exec/config.h b/exec/config.h similarity index 100% rename from corosync/exec/config.h rename to exec/config.h diff --git a/corosync/exec/coroparse.c b/exec/coroparse.c similarity index 100% rename from corosync/exec/coroparse.c rename to exec/coroparse.c diff --git a/corosync/exec/coropoll.c b/exec/coropoll.c similarity index 100% rename from corosync/exec/coropoll.c rename to exec/coropoll.c diff --git a/corosync/exec/coropoll.h b/exec/coropoll.h similarity index 100% rename from corosync/exec/coropoll.h rename to exec/coropoll.h diff --git a/corosync/exec/crypto.c b/exec/crypto.c similarity index 100% rename from corosync/exec/crypto.c rename to exec/crypto.c diff --git a/corosync/exec/crypto.h b/exec/crypto.h similarity index 100% rename from corosync/exec/crypto.h rename to exec/crypto.h diff --git a/corosync/exec/flow.c b/exec/flow.c similarity index 100% rename from corosync/exec/flow.c rename to exec/flow.c diff --git a/corosync/exec/flow.h b/exec/flow.h similarity index 100% rename from corosync/exec/flow.h rename to exec/flow.h diff --git a/corosync/exec/ipc.c b/exec/ipc.c similarity index 100% rename from corosync/exec/ipc.c rename to exec/ipc.c diff --git a/corosync/exec/ipc.h b/exec/ipc.h similarity index 100% rename from corosync/exec/ipc.h rename to exec/ipc.h diff --git a/corosync/exec/logsys.c b/exec/logsys.c similarity index 100% rename from corosync/exec/logsys.c rename to exec/logsys.c diff --git a/corosync/exec/logsys.h b/exec/logsys.h similarity index 100% rename from corosync/exec/logsys.h rename to exec/logsys.h diff --git a/corosync/exec/main.c b/exec/main.c similarity index 100% rename from corosync/exec/main.c rename to exec/main.c diff --git a/corosync/exec/main.h b/exec/main.h similarity index 100% rename from corosync/exec/main.h rename to exec/main.h diff --git a/corosync/exec/mainconfig.c b/exec/mainconfig.c similarity index 100% rename from corosync/exec/mainconfig.c rename to exec/mainconfig.c diff --git a/corosync/exec/mainconfig.h b/exec/mainconfig.h similarity index 100% rename from corosync/exec/mainconfig.h rename to exec/mainconfig.h diff --git a/corosync/exec/mempool.c b/exec/mempool.c similarity index 100% rename from corosync/exec/mempool.c rename to exec/mempool.c diff --git a/corosync/exec/mempool.h b/exec/mempool.h similarity index 100% rename from corosync/exec/mempool.h rename to exec/mempool.h diff --git a/corosync/exec/objdb.c b/exec/objdb.c similarity index 100% rename from corosync/exec/objdb.c rename to exec/objdb.c diff --git a/corosync/exec/objdb.h b/exec/objdb.h similarity index 100% rename from corosync/exec/objdb.h rename to exec/objdb.h diff --git a/corosync/exec/service.c b/exec/service.c similarity index 100% rename from corosync/exec/service.c rename to exec/service.c diff --git a/corosync/exec/service.h b/exec/service.h similarity index 100% rename from corosync/exec/service.h rename to exec/service.h diff --git a/corosync/exec/sync.c b/exec/sync.c similarity index 100% rename from corosync/exec/sync.c rename to exec/sync.c diff --git a/corosync/exec/sync.h b/exec/sync.h similarity index 100% rename from corosync/exec/sync.h rename to exec/sync.h diff --git a/corosync/exec/timer.c b/exec/timer.c similarity index 100% rename from corosync/exec/timer.c rename to exec/timer.c diff --git a/corosync/exec/timer.h b/exec/timer.h similarity index 100% rename from corosync/exec/timer.h rename to exec/timer.h diff --git a/corosync/exec/tlist.h b/exec/tlist.h similarity index 100% rename from corosync/exec/tlist.h rename to exec/tlist.h diff --git a/corosync/exec/totem.h b/exec/totem.h similarity index 100% rename from corosync/exec/totem.h rename to exec/totem.h diff --git a/corosync/exec/totemconfig.c b/exec/totemconfig.c similarity index 100% rename from corosync/exec/totemconfig.c rename to exec/totemconfig.c diff --git a/corosync/exec/totemconfig.h b/exec/totemconfig.h similarity index 100% rename from corosync/exec/totemconfig.h rename to exec/totemconfig.h diff --git a/corosync/exec/totemip.c b/exec/totemip.c similarity index 100% rename from corosync/exec/totemip.c rename to exec/totemip.c diff --git a/corosync/exec/totemip.h b/exec/totemip.h similarity index 100% rename from corosync/exec/totemip.h rename to exec/totemip.h diff --git a/corosync/exec/totemmrp.c b/exec/totemmrp.c similarity index 100% rename from corosync/exec/totemmrp.c rename to exec/totemmrp.c diff --git a/corosync/exec/totemmrp.h b/exec/totemmrp.h similarity index 100% rename from corosync/exec/totemmrp.h rename to exec/totemmrp.h diff --git a/corosync/exec/totemnet.c b/exec/totemnet.c similarity index 100% rename from corosync/exec/totemnet.c rename to exec/totemnet.c diff --git a/corosync/exec/totemnet.h b/exec/totemnet.h similarity index 100% rename from corosync/exec/totemnet.h rename to exec/totemnet.h diff --git a/corosync/exec/totempg.c b/exec/totempg.c similarity index 100% rename from corosync/exec/totempg.c rename to exec/totempg.c diff --git a/corosync/exec/totempg.h b/exec/totempg.h similarity index 100% rename from corosync/exec/totempg.h rename to exec/totempg.h diff --git a/corosync/exec/totemrrp.c b/exec/totemrrp.c similarity index 100% rename from corosync/exec/totemrrp.c rename to exec/totemrrp.c diff --git a/corosync/exec/totemrrp.h b/exec/totemrrp.h similarity index 100% rename from corosync/exec/totemrrp.h rename to exec/totemrrp.h diff --git a/corosync/exec/totemsrp.c b/exec/totemsrp.c similarity index 100% rename from corosync/exec/totemsrp.c rename to exec/totemsrp.c diff --git a/corosync/exec/totemsrp.h b/exec/totemsrp.h similarity index 100% rename from corosync/exec/totemsrp.h rename to exec/totemsrp.h diff --git a/corosync/exec/util.c b/exec/util.c similarity index 100% rename from corosync/exec/util.c rename to exec/util.c diff --git a/corosync/exec/util.h b/exec/util.h similarity index 100% rename from corosync/exec/util.h rename to exec/util.h diff --git a/corosync/exec/version.h b/exec/version.h similarity index 100% rename from corosync/exec/version.h rename to exec/version.h diff --git a/corosync/exec/vsf.h b/exec/vsf.h similarity index 100% rename from corosync/exec/vsf.h rename to exec/vsf.h diff --git a/corosync/exec/vsf_ykd.c b/exec/vsf_ykd.c similarity index 100% rename from corosync/exec/vsf_ykd.c rename to exec/vsf_ykd.c diff --git a/corosync/exec/wthread.c b/exec/wthread.c similarity index 100% rename from corosync/exec/wthread.c rename to exec/wthread.c diff --git a/corosync/exec/wthread.h b/exec/wthread.h similarity index 100% rename from corosync/exec/wthread.h rename to exec/wthread.h diff --git a/corosync/include/ais_util.h b/include/ais_util.h similarity index 100% rename from corosync/include/ais_util.h rename to include/ais_util.h diff --git a/corosync/include/cfg.h b/include/cfg.h similarity index 100% rename from corosync/include/cfg.h rename to include/cfg.h diff --git a/corosync/include/confdb.h b/include/confdb.h similarity index 100% rename from corosync/include/confdb.h rename to include/confdb.h diff --git a/corosync/include/coroapi.h b/include/coroapi.h similarity index 100% rename from corosync/include/coroapi.h rename to include/coroapi.h diff --git a/corosync/include/cpg.h b/include/cpg.h similarity index 100% rename from corosync/include/cpg.h rename to include/cpg.h diff --git a/corosync/include/evs.h b/include/evs.h similarity index 100% rename from corosync/include/evs.h rename to include/evs.h diff --git a/corosync/include/hdb.h b/include/hdb.h similarity index 100% rename from corosync/include/hdb.h rename to include/hdb.h diff --git a/corosync/include/ipc_cfg.h b/include/ipc_cfg.h similarity index 100% rename from corosync/include/ipc_cfg.h rename to include/ipc_cfg.h diff --git a/corosync/include/ipc_confdb.h b/include/ipc_confdb.h similarity index 100% rename from corosync/include/ipc_confdb.h rename to include/ipc_confdb.h diff --git a/corosync/include/ipc_cpg.h b/include/ipc_cpg.h similarity index 100% rename from corosync/include/ipc_cpg.h rename to include/ipc_cpg.h diff --git a/corosync/include/ipc_evs.h b/include/ipc_evs.h similarity index 100% rename from corosync/include/ipc_evs.h rename to include/ipc_evs.h diff --git a/corosync/include/ipc_gen.h b/include/ipc_gen.h similarity index 100% rename from corosync/include/ipc_gen.h rename to include/ipc_gen.h diff --git a/corosync/include/jhash.h b/include/jhash.h similarity index 100% rename from corosync/include/jhash.h rename to include/jhash.h diff --git a/corosync/include/list.h b/include/list.h similarity index 100% rename from corosync/include/list.h rename to include/list.h diff --git a/corosync/include/mar_cpg.h b/include/mar_cpg.h similarity index 100% rename from corosync/include/mar_cpg.h rename to include/mar_cpg.h diff --git a/corosync/include/mar_gen.h b/include/mar_gen.h similarity index 100% rename from corosync/include/mar_gen.h rename to include/mar_gen.h diff --git a/corosync/include/queue.h b/include/queue.h similarity index 100% rename from corosync/include/queue.h rename to include/queue.h diff --git a/corosync/include/rmd.h b/include/rmd.h similarity index 100% rename from corosync/include/rmd.h rename to include/rmd.h diff --git a/corosync/include/saAis.h b/include/saAis.h similarity index 100% rename from corosync/include/saAis.h rename to include/saAis.h diff --git a/corosync/include/sq.h b/include/sq.h similarity index 100% rename from corosync/include/sq.h rename to include/sq.h diff --git a/corosync/include/swab.h b/include/swab.h similarity index 100% rename from corosync/include/swab.h rename to include/swab.h diff --git a/corosync/init/README b/init/README similarity index 100% rename from corosync/init/README rename to init/README diff --git a/corosync/init/generic b/init/generic similarity index 100% rename from corosync/init/generic rename to init/generic diff --git a/corosync/init/mvlcge b/init/mvlcge similarity index 100% rename from corosync/init/mvlcge rename to init/mvlcge diff --git a/corosync/init/redhat b/init/redhat similarity index 100% rename from corosync/init/redhat rename to init/redhat diff --git a/corosync/lcr/Makefile b/lcr/Makefile similarity index 100% rename from corosync/lcr/Makefile rename to lcr/Makefile diff --git a/corosync/lcr/README.lcr b/lcr/README.lcr similarity index 100% rename from corosync/lcr/README.lcr rename to lcr/README.lcr diff --git a/corosync/lcr/lcr_ckpt.h b/lcr/lcr_ckpt.h similarity index 100% rename from corosync/lcr/lcr_ckpt.h rename to lcr/lcr_ckpt.h diff --git a/corosync/lcr/lcr_comp.h b/lcr/lcr_comp.h similarity index 100% rename from corosync/lcr/lcr_comp.h rename to lcr/lcr_comp.h diff --git a/corosync/lcr/lcr_ifact.c b/lcr/lcr_ifact.c similarity index 100% rename from corosync/lcr/lcr_ifact.c rename to lcr/lcr_ifact.c diff --git a/corosync/lcr/lcr_ifact.h b/lcr/lcr_ifact.h similarity index 100% rename from corosync/lcr/lcr_ifact.h rename to lcr/lcr_ifact.h diff --git a/corosync/lcr/libtest_a.c b/lcr/libtest_a.c similarity index 100% rename from corosync/lcr/libtest_a.c rename to lcr/libtest_a.c diff --git a/corosync/lcr/libtest_b.c b/lcr/libtest_b.c similarity index 100% rename from corosync/lcr/libtest_b.c rename to lcr/libtest_b.c diff --git a/corosync/lcr/test.c b/lcr/test.c similarity index 100% rename from corosync/lcr/test.c rename to lcr/test.c diff --git a/corosync/lcr/uic.c b/lcr/uic.c similarity index 100% rename from corosync/lcr/uic.c rename to lcr/uic.c diff --git a/corosync/lcr/uis.c b/lcr/uis.c similarity index 100% rename from corosync/lcr/uis.c rename to lcr/uis.c diff --git a/corosync/lib/Makefile b/lib/Makefile similarity index 100% rename from corosync/lib/Makefile rename to lib/Makefile diff --git a/corosync/lib/cfg.c b/lib/cfg.c similarity index 100% rename from corosync/lib/cfg.c rename to lib/cfg.c diff --git a/corosync/lib/confdb.c b/lib/confdb.c similarity index 100% rename from corosync/lib/confdb.c rename to lib/confdb.c diff --git a/corosync/lib/cpg.c b/lib/cpg.c similarity index 100% rename from corosync/lib/cpg.c rename to lib/cpg.c diff --git a/corosync/lib/evs.c b/lib/evs.c similarity index 100% rename from corosync/lib/evs.c rename to lib/evs.c diff --git a/corosync/lib/libcfg.versions b/lib/libcfg.versions similarity index 100% rename from corosync/lib/libcfg.versions rename to lib/libcfg.versions diff --git a/corosync/lib/libconfdb.versions b/lib/libconfdb.versions similarity index 100% rename from corosync/lib/libconfdb.versions rename to lib/libconfdb.versions diff --git a/corosync/lib/libcoroutil.versions b/lib/libcoroutil.versions similarity index 100% rename from corosync/lib/libcoroutil.versions rename to lib/libcoroutil.versions diff --git a/corosync/lib/libcpg.versions b/lib/libcpg.versions similarity index 100% rename from corosync/lib/libcpg.versions rename to lib/libcpg.versions diff --git a/corosync/lib/libevs.versions b/lib/libevs.versions similarity index 100% rename from corosync/lib/libevs.versions rename to lib/libevs.versions diff --git a/corosync/lib/sa-confdb.c b/lib/sa-confdb.c similarity index 100% rename from corosync/lib/sa-confdb.c rename to lib/sa-confdb.c diff --git a/corosync/lib/sa-confdb.h b/lib/sa-confdb.h similarity index 100% rename from corosync/lib/sa-confdb.h rename to lib/sa-confdb.h diff --git a/corosync/lib/util.c b/lib/util.c similarity index 100% rename from corosync/lib/util.c rename to lib/util.c diff --git a/corosync/lib/util.h b/lib/util.h similarity index 100% rename from corosync/lib/util.h rename to lib/util.h diff --git a/corosync/loc b/loc similarity index 100% rename from corosync/loc rename to loc diff --git a/corosync/man/Makefile b/man/Makefile similarity index 100% rename from corosync/man/Makefile rename to man/Makefile diff --git a/corosync/man/amf.conf.5 b/man/amf.conf.5 similarity index 100% rename from corosync/man/amf.conf.5 rename to man/amf.conf.5 diff --git a/corosync/man/confdb_dispatch.3 b/man/confdb_dispatch.3 similarity index 100% rename from corosync/man/confdb_dispatch.3 rename to man/confdb_dispatch.3 diff --git a/corosync/man/confdb_fd_get.3 b/man/confdb_fd_get.3 similarity index 100% rename from corosync/man/confdb_fd_get.3 rename to man/confdb_fd_get.3 diff --git a/corosync/man/confdb_finalize.3 b/man/confdb_finalize.3 similarity index 100% rename from corosync/man/confdb_finalize.3 rename to man/confdb_finalize.3 diff --git a/corosync/man/confdb_initialize.3 b/man/confdb_initialize.3 similarity index 100% rename from corosync/man/confdb_initialize.3 rename to man/confdb_initialize.3 diff --git a/corosync/man/confdb_key_create.3 b/man/confdb_key_create.3 similarity index 100% rename from corosync/man/confdb_key_create.3 rename to man/confdb_key_create.3 diff --git a/corosync/man/confdb_key_delete.3 b/man/confdb_key_delete.3 similarity index 100% rename from corosync/man/confdb_key_delete.3 rename to man/confdb_key_delete.3 diff --git a/corosync/man/confdb_key_iter.3 b/man/confdb_key_iter.3 similarity index 100% rename from corosync/man/confdb_key_iter.3 rename to man/confdb_key_iter.3 diff --git a/corosync/man/confdb_key_replace.3 b/man/confdb_key_replace.3 similarity index 100% rename from corosync/man/confdb_key_replace.3 rename to man/confdb_key_replace.3 diff --git a/corosync/man/confdb_object_create.3 b/man/confdb_object_create.3 similarity index 100% rename from corosync/man/confdb_object_create.3 rename to man/confdb_object_create.3 diff --git a/corosync/man/confdb_object_destroy.3 b/man/confdb_object_destroy.3 similarity index 100% rename from corosync/man/confdb_object_destroy.3 rename to man/confdb_object_destroy.3 diff --git a/corosync/man/confdb_object_find.3 b/man/confdb_object_find.3 similarity index 100% rename from corosync/man/confdb_object_find.3 rename to man/confdb_object_find.3 diff --git a/corosync/man/confdb_object_iter.3 b/man/confdb_object_iter.3 similarity index 100% rename from corosync/man/confdb_object_iter.3 rename to man/confdb_object_iter.3 diff --git a/corosync/man/confdb_object_parent_get.3 b/man/confdb_object_parent_get.3 similarity index 100% rename from corosync/man/confdb_object_parent_get.3 rename to man/confdb_object_parent_get.3 diff --git a/corosync/man/confdb_overview.8 b/man/confdb_overview.8 similarity index 100% rename from corosync/man/confdb_overview.8 rename to man/confdb_overview.8 diff --git a/corosync/man/corosync-objctl.8 b/man/corosync-objctl.8 similarity index 100% rename from corosync/man/corosync-objctl.8 rename to man/corosync-objctl.8 diff --git a/corosync/man/cpg_context_get.3 b/man/cpg_context_get.3 similarity index 100% rename from corosync/man/cpg_context_get.3 rename to man/cpg_context_get.3 diff --git a/corosync/man/cpg_context_set.3 b/man/cpg_context_set.3 similarity index 100% rename from corosync/man/cpg_context_set.3 rename to man/cpg_context_set.3 diff --git a/corosync/man/cpg_dispatch.3 b/man/cpg_dispatch.3 similarity index 100% rename from corosync/man/cpg_dispatch.3 rename to man/cpg_dispatch.3 diff --git a/corosync/man/cpg_fd_get.3 b/man/cpg_fd_get.3 similarity index 100% rename from corosync/man/cpg_fd_get.3 rename to man/cpg_fd_get.3 diff --git a/corosync/man/cpg_finalize.3 b/man/cpg_finalize.3 similarity index 100% rename from corosync/man/cpg_finalize.3 rename to man/cpg_finalize.3 diff --git a/corosync/man/cpg_initialize.3 b/man/cpg_initialize.3 similarity index 100% rename from corosync/man/cpg_initialize.3 rename to man/cpg_initialize.3 diff --git a/corosync/man/cpg_join.3 b/man/cpg_join.3 similarity index 100% rename from corosync/man/cpg_join.3 rename to man/cpg_join.3 diff --git a/corosync/man/cpg_leave.3 b/man/cpg_leave.3 similarity index 100% rename from corosync/man/cpg_leave.3 rename to man/cpg_leave.3 diff --git a/corosync/man/cpg_local_get.3 b/man/cpg_local_get.3 similarity index 100% rename from corosync/man/cpg_local_get.3 rename to man/cpg_local_get.3 diff --git a/corosync/man/cpg_mcast_joined.3 b/man/cpg_mcast_joined.3 similarity index 100% rename from corosync/man/cpg_mcast_joined.3 rename to man/cpg_mcast_joined.3 diff --git a/corosync/man/cpg_membership_get.3 b/man/cpg_membership_get.3 similarity index 100% rename from corosync/man/cpg_membership_get.3 rename to man/cpg_membership_get.3 diff --git a/corosync/man/cpg_overview.8 b/man/cpg_overview.8 similarity index 100% rename from corosync/man/cpg_overview.8 rename to man/cpg_overview.8 diff --git a/corosync/man/evs_dispatch.3 b/man/evs_dispatch.3 similarity index 100% rename from corosync/man/evs_dispatch.3 rename to man/evs_dispatch.3 diff --git a/corosync/man/evs_fd_get.3 b/man/evs_fd_get.3 similarity index 100% rename from corosync/man/evs_fd_get.3 rename to man/evs_fd_get.3 diff --git a/corosync/man/evs_finalize.3 b/man/evs_finalize.3 similarity index 100% rename from corosync/man/evs_finalize.3 rename to man/evs_finalize.3 diff --git a/corosync/man/evs_initialize.3 b/man/evs_initialize.3 similarity index 100% rename from corosync/man/evs_initialize.3 rename to man/evs_initialize.3 diff --git a/corosync/man/evs_join.3 b/man/evs_join.3 similarity index 100% rename from corosync/man/evs_join.3 rename to man/evs_join.3 diff --git a/corosync/man/evs_leave.3 b/man/evs_leave.3 similarity index 100% rename from corosync/man/evs_leave.3 rename to man/evs_leave.3 diff --git a/corosync/man/evs_mcast_groups.3 b/man/evs_mcast_groups.3 similarity index 100% rename from corosync/man/evs_mcast_groups.3 rename to man/evs_mcast_groups.3 diff --git a/corosync/man/evs_mcast_joined.3 b/man/evs_mcast_joined.3 similarity index 100% rename from corosync/man/evs_mcast_joined.3 rename to man/evs_mcast_joined.3 diff --git a/corosync/man/evs_membership_get.3 b/man/evs_membership_get.3 similarity index 100% rename from corosync/man/evs_membership_get.3 rename to man/evs_membership_get.3 diff --git a/corosync/man/evs_overview.8 b/man/evs_overview.8 similarity index 100% rename from corosync/man/evs_overview.8 rename to man/evs_overview.8 diff --git a/corosync/man/index.html b/man/index.html similarity index 100% rename from corosync/man/index.html rename to man/index.html diff --git a/corosync/man/logsys_overview.8 b/man/logsys_overview.8 similarity index 100% rename from corosync/man/logsys_overview.8 rename to man/logsys_overview.8 diff --git a/corosync/man/openais.conf.5 b/man/openais.conf.5 similarity index 100% rename from corosync/man/openais.conf.5 rename to man/openais.conf.5 diff --git a/corosync/man/openais_overview.8 b/man/openais_overview.8 similarity index 100% rename from corosync/man/openais_overview.8 rename to man/openais_overview.8 diff --git a/openais/LICENSE b/openais/LICENSE deleted file mode 100644 index 1a34f5ec..00000000 --- a/openais/LICENSE +++ /dev/null @@ -1,61 +0,0 @@ -*** -All cryptographic software in this package is subject to the following legal -notice: -This package includes publicly available encryption source code which, -together with object code resulting from the compiling of publicly -available source code, may be exported from the United States under License -Exception TSU prsuant to 15 C.F.R Section 740.13(e). -*** ------------------------------------------------------------------------------ -The following license applies to every file in this package except for -the files exec/crypto.c and exec/crypto.h. The license for these files is -described later in this document. Some files are contributed by other authors -and hence not copyright MontaVista Software. In this case, the license is -still as follows: ------------------------------------------------------------------------------ - -Copyright (c) 2002-2004 MontaVista Software, Inc. - -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 -modification, are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -- Neither the name of the MontaVista Software, Inc. nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -The openais project uses software from the LibTomCrypt project -www.libtomcrypt.org. This software is contained the files exec/crypto.c and -exec/crypto.h. The following license applies to the files exec/crypto.c and -exec/crytpo.h: ------------------------------------------------------------------------------ -LibTomCrypt is public domain. As should all quality software be. - -All of the software was either written by or donated to Tom St Denis for the -purposes of this project. The only exception is the SAFER.C source which has -no known license status (assumed copyrighted) which is why SAFER,C is shipped -as disabled. - -Tom St Denis - - diff --git a/openais/Makefile b/openais/Makefile deleted file mode 100644 index 587e6360..00000000 --- a/openais/Makefile +++ /dev/null @@ -1,168 +0,0 @@ -# Copyright (c) 2002-2006 MontaVista Software, Inc. -# Copyright (c) 2006 Red Hat, Inc. -# -# 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 -# modification, are permitted provided that the following conditions are met: -# -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# - Neither the name of the MontaVista Software, Inc. nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -builddir:=$(CURDIR)/ -ifneq ($(O),) -# cleanup the path (make it absolute) -builddir:=$(abspath $(O))/ -ifeq ($(builddir),) -builddir:=$(O) -$(warning your abspath function is not working) -$(warning > setting builddir to $(builddir)) -endif -endif - -THIS_MAKEFILE:=$(realpath $(lastword $(MAKEFILE_LIST))) - -ifeq ($(THIS_MAKEFILE),) -srcdir:=$(CURDIR)/ -$(warning your realpath function is not working) -$(warning > setting srcdir to $(srcdir)) -else -srcdir:=$(dir $(THIS_MAKEFILE)) -endif - -include $(srcdir)Makefile.inc - -INCLUDEDIR=$(PREFIX)/include/openais -MANDIR=$(PREFIX)/share/man -ETCDIR=/etc -ARCH=$(shell uname -p) - -ifeq (,$(findstring 64,$(ARCH))) -LIBDIR=$(PREFIX)/lib/openais -else -LIBDIR=$(PREFIX)/lib64/openais -endif -ifeq (s390,$(ARCH)) -LIBDIR=$(PREFIX)/lib/openais -endif -ifeq (s390x,$(ARCH)) -LIBDIR=$(PREFIX)/lib64/openais -endif -ifeq (ia64,$(ARCH)) -LIBDIR=$(PREFIX)/lib/openais -endif - -SUBDIRS:=$(builddir)lcr $(builddir)lib $(builddir)exec $(builddir)test -sub_make = srcdir=$(srcdir) builddir=$(builddir) subdir=$(1)/ $(MAKE) -I$(srcdir)$(1) -f $(srcdir)$(1)/Makefile $(2) - -all: $(SUBDIRS) - @(cd $(builddir)lib; echo ==== `pwd` ===; $(call sub_make,lib,all)); - @(cd $(builddir)services; echo ==== `pwd` ===; $(call sub_make,services,all)); - @(cd $(builddir)test; echo ==== `pwd` ===; $(call sub_make,test,all)); - -# subdirs are not phony -.PHONY: all clean install doxygen - -$(builddir): - mkdir -p $@ - -$(SUBDIRS): - mkdir -p $@ - -help: - @echo - @echo "Requirements: GCC, LD, and a Linux 2.4/2.6 kernel." - @echo "Tested on:" - @echo " Debian Sarge(i386), Redhat 9(i386), Fedora Core 2 (i386), Fedora Core" - @echo " 4, 5 (i386,x86_64), SOLARIS, MontaVista Carrier Grade Edition 3.1(i386, x86_64," - @echo " classic ppc, ppc970, xscale) and buildroot/uclibc(ppc e500/603e)" - @echo - @echo Targets: - @echo " all - build all targets" - @echo " install - install openais onto your system" - @echo " clean - remove generated files" - @echo " doxygen - doxygen html docs" - @echo - @echo "Options: (* - default)" - @echo " OPENAIS [DEBUG/RELEASE*] - Enable/Disable debug symbols" - @echo " DESTDIR [directory] - Install prefix." - @echo " O [directory] - Locate all output files in \"dir\"." - @echo " BUILD_DYNAMIC [1*/0] - Enable/disable dynamic loading of service handler modules" - @echo " OPENAIS_PROFILE [1/0*] - Enable profiling" - @echo - - -clean: - (cd $(builddir)lib; echo ==== `pwd` ===; $(call sub_make,lib,clean)); - (cd $(builddir)services; echo ==== `pwd` ===; $(call sub_make,services,clean)); - (cd $(builddir)test; echo ==== `pwd` ===; $(call sub_make,test,clean)); - rm -rf $(builddir)doc/api - -AIS_LIBS = SaAmf SaClm SaCkpt SaEvt SaLck SaMsg - -AIS_HEADERS = saAis.h saAmf.h saClm.h saCkpt.h saEvt.h saEvt.h saLck.h \ - saMsg.h - -install: all - mkdir -p $(DESTDIR)$(INCLUDEDIR) - mkdir -p $(DESTDIR)$(LIBDIR) - mkdir -p $(DESTDIR)$(LCRSODIR) - mkdir -p $(DESTDIR)$(ETCDIR)/ais - mkdir -p $(DESTDIR)$(MANDIR)/man3 - mkdir -p $(DESTDIR)$(MANDIR)/man5 - mkdir -p $(DESTDIR)$(MANDIR)/man8 - mkdir -p $(DESTDIR)$(ETCDIR)/ld.so.conf.d - - for aLib in $(AIS_LIBS); do \ - ( cd $(builddir) ; \ - ln -sf lib$$aLib.so.2.0.0 lib/lib$$aLib.so; \ - ln -sf lib$$aLib.so.2.0.0 lib/lib$$aLib.so.2; \ - $(CP) -a lib/lib$$aLib.so $(DESTDIR)$(LIBDIR); \ - $(CP) -a lib/lib$$aLib.so.2 $(DESTDIR)$(LIBDIR); \ - install -m 755 lib/lib$$aLib.so.2.* $(DESTDIR)$(LIBDIR); \ - if [ "xYES" = "x$(STATICLIBS)" ]; then \ - install -m 755 lib/lib$$aLib.a $(DESTDIR)$(LIBDIR); \ - if [ ${OPENAIS_COMPAT} = "DARWIN" ]; then \ - ranlib $(DESTDIR)$(LIBDIR)/lib$$aLib.a; \ - fi \ - fi \ - ) \ - done - - echo $(LIBDIR) > "$(DESTDIR)$(ETCDIR)/ld.so.conf.d/openais-$(ARCH).conf" - - install -m 755 $(builddir)services/*lcrso $(DESTDIR)$(LCRSODIR) - - if [ ! -f $(DESTDIR)$(ETCDIR)/ais/openais.conf ] ; then \ - install -m 644 $(srcdir)conf/openais.conf $(DESTDIR)$(ETCDIR)/ais ; \ - fi - if [ ! -f $(DESTDIR)$(ETCDIR)/ais/amf.conf ] ; then \ - install -m 644 $(srcdir)conf/amf.conf $(DESTDIR)$(ETCDIR)/ais ; \ - fi - - for aHeader in $(AIS_HEADERS); do \ - install -m 644 $(srcdir)include/$$aHeader $(DESTDIR)$(INCLUDEDIR); \ - done - -doxygen: - mkdir -p doc/api && doxygen diff --git a/openais/Makefile.inc b/openais/Makefile.inc deleted file mode 100644 index 928ea887..00000000 --- a/openais/Makefile.inc +++ /dev/null @@ -1,113 +0,0 @@ -# Common options -PREFIX=/usr -DESTDIR= -LCRSODIR=$(PREFIX)/libexec/lcrso - -# Do not modify below this line - -# Basic OS detection -# -UNAME=$(shell uname) -CP=cp - -ifeq "$(UNAME)" "Linux" - OPENAIS_COMPAT=LINUX -endif -ifeq "$(UNAME)" "Darwin" - OPENAIS_COMPAT=DARWIN - CP=rsync -endif -ifneq "" "$(findstring BSD,$(UNAME))" - OPENAIS_COMPAT=BSD -endif -ifeq "$(UNAME)" "SunOS" - OPENAIS_COMPAT=SOLARIS - # Note that CC must be set to gcc compiled to link with gnu-ld -endif -ifndef OPENAIS_COMPAT - $(error "OPENAIS_COMPAT cannot be detected, it must be manually defined") -endif - -# BUILD_DYNAMIC can be defined to 1 to build for dynamic loading of service -# handler modules. If the developer intends to debug, building without -# dynamic modules should provide an easier route. -ifndef BUILD_DYNAMIC - BUILD_DYNAMIC=1 -endif - -# OPENAIS_BUILD can be defined as RELEASE or DEBUG -# -ifndef OPENAIS_BUILD - OPENAIS_BUILD=RELEASE -endif - -# OPENAIS_PROFILE - -# default CFLAGS, LDFLAGS -# -CFLAGS = -DCOROSYNC_EXTERNAL_ENGINE -LDFLAGS = -DYFLAGS = - -# Adding the TS_CLASS flag enables not being scheduled RR -#CFLAGS += -DTS_CLASS - -# build CFLAGS, LDFLAGS -# -ifeq (${OPENAIS_BUILD}, RELEASE) - CFLAGS += -O3 -Wall -# -Wstrict-aliasing=2 TODO sameday fix all of these -ifndef OPENAIS_PROFILE - CFLAGS += -fomit-frame-pointer -endif - LDFLAGS += -endif -ifeq (${OPENAIS_BUILD}, DEBUG) - CFLAGS += -O0 -g -Wall -DDEBUG - LDFLAGS += -g - ifeq (${OPENAIS_COMPAT}, SOLARIS) - CFLAGS += -Werror -DTS_CLASS - endif -endif -ifeq (${OPENAIS_BUILD}, COVERAGE) - CFLAGS += -O0 -g -ftest-coverage -fprofile-arcs - LDFLAGS += -g -ftest-coverage -fprofile-arcs - BUILD_DYNAMIC=0 -endif - -ifdef OPENAIS_PROFILE - CFLAGS += -pg - LDFLAGS += -pg -endif - -# platform specific CFLAGS, LDFLAGS -# -ifeq (${OPENAIS_COMPAT}, LINUX) - override CFLAGS += -DOPENAIS_LINUX - override LDFLAGS += -ldl -lpthread - override DYFLAGS += -rdynamic -endif -ifeq (${OPENAIS_COMPAT}, BSD) - override CFLAGS += -DOPENAIS_BSD - override LDFLAGS += -pthread - override DYFLAGS += -export-dynamic -endif -ifeq (${OPENAIS_COMPAT}, DARWIN) - override CFLAGS += -DOPENAIS_DARWIN - override LDFLAGS += -lpthread -endif -ifeq (${OPENAIS_COMPAT}, SOLARIS) - override CFLAGS += -DOPENAIS_SOLARIS -D_REENTRANT - override LDFLAGS += -lpthread - # See http://sources.redhat.com/ml/bug-gnu-utils/2000-07/msg00168.html - override LDFLAGS += -Wl,--export-dynamic -Wl,-rpath-link=/usr/lib -ifeq ($(shell uname -r), 5.10) - override CFLAGS += -DHAVE_GETPEERUCRED -DHAVE_SCANDIR -DHAVE_ALPHASORT -endif -ifeq ($(shell uname -r), 5.11) - override CFLAGS += -DHAVE_GETPEERUCRED -DHAVE_SCANDIR -DHAVE_ALPHASORT -endif -endif - -VPATH:=. $(srcdir) $(srcdir)$(subdir) - diff --git a/openais/README.amf b/openais/README.amf deleted file mode 100644 index 29934849..00000000 --- a/openais/README.amf +++ /dev/null @@ -1,536 +0,0 @@ -AMF B.02.01 Implementation --------------------------- -The implementation of AMF in openais is directed by the specification -SAI-AIS-AMF-B.02.01, see http://www.saforum.org/specification/. - -What does AMF do? ------------------ -The AMF has many major duties: - * issue instantiate, terminate, and cleanup operations for components - * assignment of component service instances to components - * executing of recovery and repair actions on fault reports delivered - by components (fault detection is a responsibility of all entities - in the system) - -An AMF user has to provide instantiate and cleanup commands and a -configuration file besides from the binaries that represents the actual -components. - -To start a component, AMF executes the instantiate command which starts -processes that are part of the component. AMF can stop the component -abruptly by running the cleaup command. - -An service unit (SU) contains multiple components and represents a -"useable service" and is configured to execute on an AMF node. The AMF node -is mapped in the configuration to a CLM node which is "an operating system -instance". An SU is the smallest part that can be instantiated in a redundant -manner and can therefore be viewed as the unit of redundancy. - -A service group (SG) contains multiple SUs. The SG is the unit that implements -high availability by managing its contained service units. An SG can be -configured to execute different redundancy policies. - -An application contains multiple SGs and multiple service instances (SIs). - -An SI represents the workload for an SU. An SI consists of one or more -component service instances (CSIs). - -A CSI represents the workload of a component. The CSI is configured to include -a list of name value pairs through which the user can express the workload. - -The AMF specification defines several types of components. The AMF -specification is exceedingly clear about which CLC operations occur for which -component types. - -If a component is not sa-aware, the only level of high availability that -can be applied to the application is through execution of the CLC interfaces. - -A special component, called a proxy component, can be used to present an -SA-aware component to AMF to manage a non-SA-aware component. This would be -useful, for example, to implement a healthcheck operation which runs some -operation of the unmodified application service. - -Components that are SA-aware have been written specifically to the AMF -interfaces. These components provide the most support for high availability -for application developers. - -When an SA-aware component has been instantiated it has to register within a -certain time. After a successful registration, AMF assigns workload to the -component by making callbacks once the service unit is available to take service. -There will be one callback for each CSI-assignment. Each CSI-assignment has -a HA state associated which indicates how the component shall act. -The HA state can be ACTIVE, STANDBY, QUIESCED or QUIESCING. - -The number of CSIs assigned to a component and the setting of their HA state -is determined by AMF. In the configuration the operator specifies the preferred -assignment of workload to the defined SUs. The configuration specifies also -limits for how much work each SU can execute. If not the preferred distribution -of workload can be met due to problems in the cluster a reduction process with -6 levels of reduction will be executed by AMF. The purpose of the reduction -procedure is to come as close as possible to the preferred configuration without -violating any limits for how much workload an SU can handle. The reduction -procedure continues until there are no SUs in-service in the SG. - -AMF supports fault detection through a healthcheck API. The user -specifies in the configuration file healthcheck keys and timing parameters. -This configuration is then used by the application developer to register -a healthcheck operation in the AMF. The healthcheck operation can be started -or stopped. Once started, the AMF will periodically send a request to the -component to determine its level of health. Optionally, AMF can be configured to -instead expect the component to report its health periodically. -The AMF reacts to negative healthchecks or failed healthchecks by executing -a recovery policy. - -The AMF specification also includes an API for reporting errors with a -recommended recovery action. AMF will not take a weaker recovery action than -what is recommended but may take a stronger action based on the recovery -escalation policy. - -There is a recovery escalation policy for the recomendations: -- component restart -- component failover - -When AMF receives a recommendation to restart a component, the recovery policy -attempts to restart the component first. When the component is restarted and -fail a certain number of times within a timeout period, the entire service unit -is restarted. When the SU has been restarted a certain number of times within -a certain timeout period, the SU is failed over to a standby SU. If AMF fails -over too many service units out of the same node in a given time period as a -consequence of error reports with either component restart or component -failover recommended recovery actions, the AMF escalates the recovery to an -entire node fail-over. - -What is currently implemented ? -------------------------------- - -SA-aware components can be instantiated and assigned load according to the -configuration specified in amf.conf. Other types of components are currently -not supported. The processes of instantiation and assignment of workload are -both simplified compared to the requirements in the AMF specification. - -Service units represented by their components can be configured to execute -on different nodes. AMF supports initial start of the cluster as well as adding -of a node to the cluster after the initial start. AMF also supports that a node -leave the cluster by failing over the workload to standby service units. - -Healthchecks are implemented as specified with only a few details missing. - -The error report API is implemented but AMF ignores the recommendation of -recovery action instead it will always try to recover by 'component restart'. - -The error escalation mechanism up to SU failover is also implemented as -specified with a few simplifications. - -Only redundancy model N+M is (partly) implemented. - -You can find a detailed list of what is NOT implemented later in the README. - -How to configure AMF --------------------- -The AMF specification doesn't specify a configuration file format. It does -however, describe many configuration options, which are specified formally in -SAI-Overview-B.02.01 chapter 4.5 - 4.11. The Overview can also be retrieved -from http://www.saforum.org/specification/. - -An implementation specific feature of openais is to implement the configuration -options in a file called amf.conf. There is a man page in the /man directory -which describes the syntax of amf.conf and what configuration options which -are currently supported. - -The example programs --------------------- -First the openais example programs should be installed. When compiling openais -in the exec directory a file called openais-instantiate is created. Copy this -file to a test directory of your own: - -mkdir /tmp/aisexample - -exec# cp openais-instantiate /tmp/aisexample - -Copy also the script which implements the instantiate, terminate and clean-up -operations to your test directory: - -exec# cp ../test/clc_cli_script /tmp/aisexample/clc_cli_script - -Set execute permissions for the clc_cli_script - -exec# chmod +x /tmp/aisexample/clc_cli_script - -Copy the binary to be used for all components: -exec# cp ../test/testamf1 /tmp/aisexample/testamf1 - -Copy the amf example configuration files from the openais/conf directory to -your test directory. - -exec# cp ../conf/*amf_example.conf /tmp/aisexample - -set environment variables to the names of the configuration files: - -setenv OPENAIS_AMF_CONFIG_FILE /tmp/aisexample/amf_example.conf -setenv OPENAIS_MAIN_CONFIG_FILE /tmp/aisexample/openais_amf_example.conf - -You have to specify the host on which you would like to execute the AMF example. -Open the file 'amf_example.conf' and replace the line: - -saAmfNodeClmNode=p01 - -in the following section in the cluster configuration: - - safAmfNode = AMF1 { - saAmfNodeSuFailOverProb=2000 - saAmfNodeSuFailoverMax=2 - saAmfNodeClmNode=p01 - } - -p01 shall be replaced with the name of your host. - -(You can obtain the name of your host by typing the command 'hostname' in a -shell.) - -Modify the following rows of 'openais_amf_example.conf' so that they match your -user and group: - -aisexec { - user: nisse - group: users -} - -(One way to obtain your user and group is to type the command 'id' in a shell.) - -Start aisexec by command: -./aisexec - -aisexec will be run in the background. -Once aisexec is run using the example configuration file, 2 service units -will be instantiated. The testamf1 C code will be used for both component A -and component B of both SUs. The testamf1 program determines its -component name at start time from the saAmfComponentNameGet() api call. -The result is that 4 processes will be started by AMF. - -Each testamf1 process will first try to register a bad component name and -there after register the name returned from saAmfComponentNameGet(). -The testamf1 will be assigned CSIs after they execute a -saAmfComponentRegister() API call. Note that a successful registration causes -the state of the component and service units to be set to INSTANTIATED as -required by the AMF specification. The service instances and their names are -defined within the configuration file. - -The component of type saAmfCSTypeName = B, which have the active HA state, -in this case, safComp=B,safSu=SERVICE_X_1,safSg=RAID,safApp=APP-1, -reports an error via saAmfErrorReport() after exactly 10 healthchecks. -The healthcheck period is configured to 1 second so one error report is sent -every 10th second. -This results in openais calling the cleanup handler, which for -an sa-aware component, is the CLC_CLI_CLEANUP command. This causes the cleanup -operation of the clc_cli_script to be run. This cleanup command then reads the -pid of the process that was stored to /var/run ( or /tmp) at startup of the -testamf1 program. It then executes a kill -9 on the PID. Custom cleanup -operations can be executed by modifying the clc_cli_script script program. - -After this is done 2 times (configurable) the entire service -unit is terminated and restarted due to the error escalation mechanism. Once -this happens 3 times (also configurable), the code escalates to level 2 and a -failover of the SU takes place. After this testamf1 makes no more error -reports and nothing will happen until some problem is recognized (like the -process of one of the components stops executing). - -The states of the cluster and its contained entities can be obtained by issuing -the following command in the shell: - -pkill -USR2 ais - -Some notes: ------------ -In the example, testamf1 is sending an error report at the 10th helthcheck. -This is actually controlled by the safCSIAttr = good_health_limit in -file amf_example.conf and can be changed as you like. - -The file openais_amf_example.conf specifies logging to stderr. - -If you would like to follow more closely the execution of the AMF in openais, -debug printouts can be enabled. - -example: -logging { - fileline: off - to_stderr: yes - to_file: no - logfile: /tmp/openais.log - debug: off - timestamp: on - logger { - ident: AMF - debug: on - tags: enter|leave|trace1|trace2|trace3|trace4|trace6 - } - -Setting 'debug: on' generally gives many printouts all other parts of openais. - -Run the example on a cluster with 2 nodes ------------------------------------------ - -It is easy to run the example on more than one node. -Modify the file openais_amf_example.conf: - -<1> -Replace the following line: - bindnetaddr: 127.0.0.0 - -bindnetaddr specifies the address which the openais Executive should bind to. -This address should always end in zero. If the local interface traffic -should be routed over is 192.168.5.92, set bindnetaddr to 192.168.5.0. - -Modify amf_example.conf like this: -<1> -Remove the comment character '#' from the following lines: -# safAmfNode = AMF2 { -# saAmfNodeSuFailOverProb=2000 -# saAmfNodeSuFailoverMax=2 -# saAmfNodeClmNode=p02 -# } -and replace p02 with the name of your second machine. -<2> -Locate the following two lines: - saAmfSUHostedByNode=AMF1 -# saAmfSUHostedByNode=AMF2 - -Replace them with: - -# saAmfSUHostedByNode=AMF1 - saAmfSUHostedByNode=AMF2 - -Feedback --------- -Any feed-back is appreciated. - -Keep in mind only parts of the functionality is implemented. Reports of bugs or -behaviour not compliant with the AMF specification within the implemented part -is greatly appreciated :-). - -What is currently NOT implemented ? ------------------------------------ -The following list specifies all chapters of the AMF specification which -currently is NOT fully implemented. The deviations from the specification are -described shortly except in those cases when none of the requirements in the -chapter is implemented. - -Chapter: Deviation: ---------- ---------- -3.3.1.2 Administrative State Not supported (always UNLOCKED). -3.3.1.4 Readiness State State STOPPING is not supported. -3.3.1.5 Service Unit’s HA State ... State QUIESCING is not supported. -3.3.2.2 Operational State AMF does not detect errors in the - following cases: - • A command used by the Availability - Management Framework to control the - component life cycle returned an - error or did not return in time. - • The component fails to respond in - time to an Availability Management - Framework's callback. - • The component responds to an - Availability Management Framework's - state change callback - (SaAmfCSISetCallbackT) with an error. - • If the component is SA-aware, and it - does not register with the - Availability Management Framework - within the preconfigured time-period - after its instantiation. - • If the component is SA-aware, and it - unexpectedly unregisters with the - Availability Management Framework. - • The component terminates unexpectedly. - • When a fail-over recovery operation - performed at the level of the service - unit or the node containing the - service unit triggers an abrupt - termination of the component. -3.3.2.3 Readiness State State STOPPING is not supported. -3.3.2.4 Component’s HA State per ... State QUIESCING is not supported. -3.3.3.1 Administrative State Not supported (always UNLOCKED). -3.3.5 Service Group States Administrative state is not supported - (always UNLOCKED). -3.3.6.1 Administrative State Not supported (always UNLOCKED). -3.3.6.2 Operational State None of the rules for transition between states are implemented. -3.3.7 Application States Administrative state is not supported (always UNLOCKED). -3.3.8 Cluster States Administrative state is not supported (always UNLOCKED). -3.5.1 Combined States for Pre-Inst.... Only Administrative state = UNLOCKED is supported. -3.5.2 Combined States for Non-Pre-I... Not supported. -3.6 Component Capability Model Configuration of capability model is - ignored. AMF expects all components to - be capable to be x_active_or_y_standby. -3.7.2 2N Redundancy Model Not supported. -3.7.3.1 Basics Spare service units can not be handled - properly. -3.7.3.3 Configuration • Ordered list of service units for a - service group: Not supported - (the order is unpredictable). - • Ordered list of SIs: Neither ranking - nor dependencies among SIs are - supported. SIs are assigned to SUs in - any order. - • Auto-adjust option: Not supported. - Auto-adjust is never done. -3.7.3.5.1 Handling of a Node Failure.. Not supported. -3.7.3.6 An Example of Auto-adjust Not supported. -3.7.4 N-Way Redundancy Model Not supported. -3.7.5 N-Way Active Redundancy Model Not supported. -3.7.6 No Redundancy Model Not supported. -3.7.7 The Effect of Administrative... Not supported. -3.9 Dependencies Among SIs, Compone.. Not supported. -3.11 Component Monitoring • External Active Monitoring: - Not supported. -3.12.1.1 Error Detection AMF does not support that a component - reports an error for another component. -3.12.1.2 Restart • AMF does not support terminating of - components by the terminate call-back - or the TERMINATE command. - • AMF does not consider component - instantiation-level at restart. - • The configuration option - disableRestart is not supported. -3.12.1.3 Recovery • Component or Service Unit Fail-Over: - • Component fail-over is not - implemented - • Only SU fail-over is implemented and - the only way to trig that case is by - error escalation. - • Node Switch-Over: Not implemented - • Node Fail-Over: Not implemented - • Node Fail-Fast: Not implemented - • The configuration option - recoveryOnFailure is not handled, - i.e. is never evaluated. - -3.12.1.4 Repair • The configuration attribute for - automatic repair is not evaluated. - • The administrative operation - SA_AMF_ADMIN_REPAIRED is not - implemented. - • Repair after component fail-over - is not implemented. - • Node leave while performing - automatic repair of that node, - is not implemented. - • Service unit failover recovery: - Is implemented except that an attempt - to repair is always done (confi- - guration attribute is not evaluated). - • Repair after Node Switch-Over, - Fail-Over or Fail-Fast - is not implemented. -3.12.1.5 Recovery Escalation The recommended recovery action is not - evaluated at the reception of an error - report. -3.12.2.1 Recommended Recovery Action The recommended recovery action is - never evaluated. Recovery action - SA_AMF_COMPONENT_RESTART is always - assumed. -3.12.2.2 Escalations of Levels 1 and 2 Is implemented with the following exception: - • The configuration attribute - component_restart_max is compared to - the restart counter of the component - that has reported the error instead of - against the sum of all restart - counters of all components within - the SU. -3.12.2.3 Escalation of Level 3 Not implemented -4.2 CLC-CLI's Environment Variables Translation of non-printable Unicode - characters is not supported. -4.4 INSTANTIATE Command • AMF does not evaluate the exit code of - the INSTANTIATE command as described - in the specification. - • AMF does not supervise that an - SA-aware component registers itself, - within the time limit configured. - As a consequence, none of the recovery - actions described are implemented. -4.5 TERMINATE Command Not supported. -4.6 CLEANUP Command AMF does not evaluate the exit code of - the CLEANUP command and thus does not - implement any recovery action. -4.7 AM_START Command Not supported. -4.8 AM_STOP Command Not supported. -5 Proxied Component Management Not implemented. -7 Administrative API Not implemented -8 Basic Operational Scenarios Not implemented. -9 Alarms and Notifications Not implemented. - -Appendix A: Implementation of CLC .. CLC-interfaces are partly implemented - for SA-aware components. - The terminate operation, - saAmfComponentTerminateCallback(), - is never called. - No CLC-interfaces are implemented for - any other type of component. - -Appendix B: API functions in Unre.... AMF does not verify that the rules - described are fulfilled. - - - -Which functions of the AMF API is currently NOT implemented ? -------------------------------------------------------------- - -Function Deviation --------- --------- -saAmfComponentUnregister() Is implemented in the library - but not in aisexec. - -saAmfPmStart() Is implemented in the library - but not in aisexec. - -saAmfPmStop() Is implemented in the library - but not in aisexec. - -saAmfHealthcheckStart() This function takes a parameter - of type SaAmfRecommendedRecoveryT. - The value of this parameter is - supposed to specify what kind of - recovery AMF should execute if - the component fails a health - check. AMF does not read the - value of this parameter but - instead always tries to recover - the component by a component - restart. - -void (*SaAmfCSIRemoveCallbackT)() AMF will never make a call-back - to this function. -void -(*SaAmfComponentTerminateCallbackT)() AMF will never make a call-back - to this function. -void -(*SaAmfProxiedComponentInstantiateCallbackT)() AMF will never make a call-back - to this function. -void -(*SaAmfProxiedComponentCleanupCallbackT)() AMF will never make a call-back - to this function. -saAmfProtectionGroupTrack() Is implemented in the library - but not in aisexec. - -saAmfProtectionGroupTrackStop() Is implemented in the library - but not in aisexec. - -void (*SaAmfProtectionGroupTrackCallbackT)() AMF will never make a call-back - to this function. - -saAmfProtectionGroupNotificationFree() Not implemented. - -saAmfComponentErrorReport() This function takes a parameter - of type SaAmfRecommendedRecoveryT. - The value of this parameter is - supposed to specify what kind of - recovery AMF should execute if - the component fails a health - check. AMF does not read the - value of this parameter but - instead always tries to recover - the component by a component - restart. - -saAmfComponentErrorClear() Is implemented in the library - but not in aisexec. - - diff --git a/openais/conf/amf.conf b/openais/conf/amf.conf deleted file mode 100644 index 37bc3830..00000000 --- a/openais/conf/amf.conf +++ /dev/null @@ -1,197 +0,0 @@ -# AMF Example configuration file, please read README.amf -# - 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 /). -# WL - WorkLoad - -safAmfCluster = TEST_CLUSTER { - saAmfClusterStartupTimeout=3000 - safAmfNode = AMF1 { - saAmfNodeSuFailOverProb=2000 - saAmfNodeSuFailoverMax=2 - saAmfNodeClmNode=balance - } -# safAmfNode = AMF2 { -# saAmfNodeSuFailOverProb=2000 -# saAmfNodeSuFailoverMax=2 -# saAmfNodeClmNode=p02 -# } - safApp = APP-1 { - safSg = RAID { - saAmfSGRedundancyModel=nplusm - saAmfSGNumPrefActiveSUs=1 - saAmfSGMaxActiveSIsperSUs=2 - saAmfSGNumPrefStandbySUs=1 - saAmfSGMaxStandbySIsperSUs=2 - saAmfSGCompRestartProb=100000 - saAmfSGCompRestartMax=2 - saAmfSGSuRestartProb=20000 - saAmfSGSuRestartMax=3 - saAmfSGAutoAdjustProb=5000 - safSu = SERVICE_X_1 { - saAmfSUHostedByNode=AMF1 - saAmfSUNumComponents=1 - safComp = A { - saAmfCompCategory=sa_aware - saAmfCompCapability=x_active_or_y_standby - saAmfCompNumMaxActiveCsi=1 - saAmfCompNumMaxStandbyCsi=1 - saAmfCompDefaultClcCliTimeout = 5000 - saAmfCompDefaultCallbackTimeOut = 5000 - saAmfCompInstantiateCmd = /tmp/aisexample/clc_cli_script - saAmfCompInstantiateCmdArgv= instantiate /tmp/aisexample/testamf1 - saAmfCompTerminateCmd = /tmp/aisexample/clc_cli_script - saAmfCompTerminateCmdArgv = terminate - saAmfCompCleanupCmd = /tmp/aisexample/clc_cli_script - saAmfCompCleanupCmdArgv = cleanup - saAmfCompCsTypes { - A - } - saAmfCompCmdEnv { - var1=val1 - var2=val2 - } - saAmfCompRecoveryOnError=component_restart - safHealthcheckKey = key1 { - saAmfHealthcheckPeriod = 100 - saAmfHealthcheckMaxDuration = 350 - } - } - safComp = B { - saAmfCompCategory=sa_aware - saAmfCompCapability=x_active_or_y_standby - saAmfCompNumMaxActiveCsi=1 - saAmfCompNumMaxStandbyCsi=1 - saAmfCompDefaultClcCliTimeout = 5000 - saAmfCompDefaultCallbackTimeOut = 5000 - saAmfCompInstantiateCmd = /tmp/aisexample/clc_cli_script - saAmfCompInstantiateCmdArgv= instantiate /tmp/aisexample/testamf1 - saAmfCompTerminateCmd = /tmp/aisexample/clc_cli_script - saAmfCompTerminateCmdArgv = terminate - saAmfCompCleanupCmd = /tmp/aisexample/clc_cli_script - saAmfCompCleanupCmdArgv = cleanup - saAmfCompCsTypes { - B - } - saAmfCompCmdEnv { - var1=val1 - var2=val2 - } - saAmfCompRecoveryOnError=component_restart - safHealthcheckKey = key1 { - saAmfHealthcheckPeriod = 100 - saAmfHealthcheckMaxDuration = 350 - } - } - } - safSu = SERVICE_X_2 { - clccli_path=/tmp/aisexample - saAmfSUHostedByNode=AMF1 -# saAmfSUHostedByNode=AMF2 - saAmfSUNumComponents=1 - safComp = A { - saAmfCompCategory=sa_aware - saAmfCompCapability=x_active_or_y_standby - saAmfCompNumMaxActiveCsi=1 - saAmfCompNumMaxStandbyCsi=1 - saAmfCompDefaultClcCliTimeout = 5000 - saAmfCompDefaultCallbackTimeOut = 5000 - saAmfCompInstantiateCmd = clc_cli_script - saAmfCompInstantiateCmdArgv= instantiate - saAmfCompTerminateCmd = clc_cli_script - saAmfCompTerminateCmdArgv = terminate - saAmfCompCleanupCmd = clc_cli_script - saAmfCompCleanupCmdArgv = cleanup - saAmfCompCsTypes { - A - } - saAmfCompCmdEnv { - COMP_BINARY_PATH=/tmp/aisexample - COMP_BINARY_NAME=testamf1 - var1=val1 - var2=val2 - } - saAmfCompRecoveryOnError=component_restart - safHealthcheckKey = amfInvoked { - saAmfHealthcheckPeriod = 100 - saAmfHealthcheckMaxDuration = 350 - } - safHealthcheckKey = compInvoked { - saAmfHealthcheckPeriod = 100 - saAmfHealthcheckMaxDuration = 350 - } - } - safComp = B { - saAmfCompCategory=sa_aware - saAmfCompCapability=x_active_or_y_standby - saAmfCompNumMaxActiveCsi=1 - saAmfCompNumMaxStandbyCsi=1 - saAmfCompDefaultClcCliTimeout = 500 - saAmfCompDefaultCallbackTimeOut = 500 - saAmfCompInstantiateCmd = /tmp/aisexample/clc_cli_script - saAmfCompInstantiateCmdArgv= instantiate /tmp/aisexample/testamf1 - saAmfCompTerminateCmd = /tmp/aisexample/clc_cli_script - saAmfCompTerminateCmdArgv = terminate - saAmfCompCleanupCmd = /tmp/aisexample/clc_cli_script - saAmfCompCleanupCmdArgv = cleanup - saAmfCompCsTypes { - B - } - saAmfCompCmdEnv { - var1=val1 - var2=val2 - } - saAmfCompRecoveryOnError=component_restart - safHealthcheckKey = amfInvoked { - saAmfHealthcheckPeriod = 100 - saAmfHealthcheckMaxDuration = 350 - } - safHealthcheckKey = compInvoked { - saAmfHealthcheckPeriod = 100 - saAmfHealthcheckMaxDuration = 350 - } - } - } - } - safSi = WL1 { - saAmfSINumCSIs=2 - safCsi = WL1-1 { - saAmfCSTypeName = A - } - safCsi = WL1-2 { - saAmfCSTypeName = B - safCSIAttr = attr1 { - val1 - val2 - } - safCSIAttr = good_health_limit { - 10 - } - } - } - safSi = WL2 { - saAmfSINumCSIs=2 - safCsi = WL2-1 { - saAmfCSTypeName = A - } - safCsi = WL2-2 { - saAmfCSTypeName = B - safCSIAttr = attr1 { - val1 - val2 - } - safCSIAttr = good_health_limit { - 10 - } - } - } - safCSType = A { - safAmfCSAttrName = attr1 - safAmfCSAttrName = good_health_limit - } - safCSType = B { - } - } -} - diff --git a/openais/conf/openais.conf b/openais/conf/openais.conf deleted file mode 100644 index ec70472e..00000000 --- a/openais/conf/openais.conf +++ /dev/null @@ -1,31 +0,0 @@ -# Please read the openais.conf.5 manual page -totem { - version: 2 - secauth: off - threads: 0 - interface { - ringnumber: 0 - bindnetaddr: 192.168.1.1 - mcastaddr: 226.94.1.1 - mcastport: 5405 - } -} - -logging { - fileline: off - to_stderr: yes - to_file: yes - to_syslog: yes - logfile: /tmp/openais.log - debug: off - timestamp: on - logger { - ident: AMF - debug: off - tags: enter|leave|trace1|trace2|trace3|trace4|trace6 - } -} - -amf { - mode: disabled -} diff --git a/openais/include/ipc_amf.h b/openais/include/ipc_amf.h deleted file mode 100644 index fdf80f95..00000000 --- a/openais/include/ipc_amf.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef AIS_IPC_AMF_H_DEFINED -#define AIS_IPC_AMF_H_DEFINED - -#include -#include "ipc_gen.h" -#include "saAis.h" -#include "saAmf.h" - -enum req_lib_amf_types { - MESSAGE_REQ_AMF_COMPONENTREGISTER = 0, - MESSAGE_REQ_AMF_COMPONENTUNREGISTER = 1, - MESSAGE_REQ_AMF_PMSTART = 2, - MESSAGE_REQ_AMF_PMSTOP = 3, - MESSAGE_REQ_AMF_HEALTHCHECKSTART = 4, - MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM = 5, - MESSAGE_REQ_AMF_HEALTHCHECKSTOP = 6, - MESSAGE_REQ_AMF_HASTATEGET = 7, - MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE = 8, - MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK = 9, - MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP = 10, - MESSAGE_REQ_AMF_COMPONENTERRORREPORT = 11, - MESSAGE_REQ_AMF_COMPONENTERRORCLEAR = 12, - MESSAGE_REQ_AMF_RESPONSE = 13 -}; - -enum res_lib_amf_types { - MESSAGE_RES_AMF_COMPONENTREGISTER = 0, - MESSAGE_RES_AMF_COMPONENTUNREGISTER = 1, - MESSAGE_RES_AMF_PMSTART = 2, - MESSAGE_RES_AMF_PMSTOP = 3, - MESSAGE_RES_AMF_HEALTHCHECKSTART = 4, - MESSAGE_RES_AMF_HEALTHCHECKCONFIRM = 5, - MESSAGE_RES_AMF_HEALTHCHECKSTOP = 6, - MESSAGE_RES_AMF_HASTATEGET = 7, - MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE = 8, - MESSAGE_RES_AMF_PROTECTIONGROUPTRACK = 9, - MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP = 10, - MESSAGE_RES_AMF_COMPONENTERRORREPORT = 11, - MESSAGE_RES_AMF_COMPONENTERRORCLEAR = 12, - MESSAGE_RES_AMF_RESPONSE = 13, - MESSAGE_RES_AMF_CSISETCALLBACK = 14, - MESSAGE_RES_AMF_HEALTHCHECKCALLBACK = 15, - MESSAGE_RES_AMF_CSIREMOVECALLBACK = 16, - MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK = 17, -}; - -struct req_lib_amf_componentregister { - mar_req_header_t header; - SaNameT compName; - SaNameT proxyCompName; -} __attribute__((packed)); - -struct res_lib_amf_componentregister { - mar_res_header_t header; -}; - -struct req_lib_amf_componentunregister { - mar_req_header_t header; - SaNameT compName; - SaNameT proxyCompName; -}; - -struct res_lib_amf_componentunregister { - mar_res_header_t header; -}; - -struct req_lib_amf_pmstart { - mar_req_header_t header; - SaNameT compName; - SaUint64T processId; - SaInt32T descendentsTreeDepth; - SaAmfPmErrorsT pmErrors; - SaAmfRecommendedRecoveryT recommendedRecovery; -}; - -struct res_lib_amf_pmstart { - mar_res_header_t header; -}; - -struct req_lib_amf_pmstop { - mar_req_header_t header; - SaNameT compName; - SaAmfPmStopQualifierT stopQualifier; - SaUint64T processId; - SaAmfPmErrorsT pmErrors; -}; - -struct res_lib_amf_pmstop { - mar_res_header_t header; -}; - -struct req_lib_amf_healthcheckstart { - mar_req_header_t header; - SaNameT compName; - SaAmfHealthcheckKeyT healthcheckKey; - SaAmfHealthcheckInvocationT invocationType; - SaAmfRecommendedRecoveryT recommendedRecovery; -}; - -struct res_lib_amf_healthcheckstart { - mar_res_header_t header; -}; - -struct req_lib_amf_healthcheckconfirm { - mar_req_header_t header; - SaNameT compName; - SaAmfHealthcheckKeyT healthcheckKey; - SaAisErrorT healthcheckResult; -}; - -struct res_lib_amf_healthcheckconfirm { - mar_res_header_t header; -}; - -struct req_lib_amf_healthcheckstop { - mar_req_header_t header; - SaNameT compName; - SaAmfHealthcheckKeyT healthcheckKey; -}; - -struct res_lib_amf_healthcheckstop { - mar_res_header_t header; -}; - -struct req_lib_amf_hastateget { - mar_req_header_t header; - SaNameT compName; - SaNameT csiName; -}; - -struct res_lib_amf_hastateget { - mar_res_header_t header; - SaAmfHAStateT haState; -}; - -struct req_lib_amf_csiquiescingcomplete { - mar_req_header_t header; - SaInvocationT invocation; - SaAisErrorT error; -}; - -struct res_lib_amf_csiquiescingcomplete { - mar_res_header_t header; -}; - -struct req_lib_amf_protectiongrouptrack { - mar_req_header_t header; - SaNameT csiName; - SaUint8T trackFlags; - SaAmfProtectionGroupNotificationBufferT *notificationBufferAddress; -}; - -struct res_lib_amf_protectiongrouptrack { - mar_res_header_t header; -}; - - -struct req_lib_amf_protectiongrouptrackstop { - mar_req_header_t header; - SaNameT csiName; -}; - -struct res_lib_amf_protectiongrouptrackstop { - mar_res_header_t header; -}; - -struct req_lib_amf_componenterrorreport { - mar_req_header_t header; - SaNameT reportingComponent; - SaNameT erroneousComponent; - SaTimeT errorDetectionTime; - SaAmfRecommendedRecoveryT recommendedRecovery; - SaNtfIdentifierT ntfIdentifier; -}; - -struct res_lib_amf_componenterrorreport { - mar_res_header_t header; -}; - -struct req_lib_amf_componenterrorclear { - mar_req_header_t header; - SaNameT compName; -}; - -struct res_lib_amf_componenterrorclear { - mar_res_header_t header; -}; - -struct req_lib_amf_response { - mar_req_header_t header; - SaInvocationT invocation; - SaAisErrorT error; -}; - -struct res_lib_amf_response { - mar_res_header_t header; -}; -struct res_lib_amf_healthcheckcallback { - mar_res_header_t header; - SaInvocationT invocation; - SaNameT compName; - SaAmfHealthcheckKeyT key; -}; - -#ifdef COMPILE_OUT - -struct res_lib_amf_componentterminatecallback { - mar_res_header_t header; - SaInvocationT invocation; - SaNameT compName; -}; - - -#endif - -/* struct res_lib_amf_csisetcallback { */ -/* mar_res_header_t header; */ -/* SaInvocationT invocation; */ -/* SaNameT compName; */ -/* SaAmfHAStateT haState; */ -/* SaAmfCSIDescriptorT csiDescriptor; */ -/* }; */ - -struct res_lib_amf_csisetcallback { - mar_res_header_t header; - SaInvocationT invocation; - SaNameT compName; - SaAmfHAStateT haState; - SaAmfCSIFlagsT csiFlags; - SaNameT csiName; - SaAmfCSIStateDescriptorT csiStateDescriptor; - SaUint32T number; - char csi_attr_buf[1]; /* Actual length will be calculated */ -}; - -struct res_lib_amf_csiremovecallback { - mar_res_header_t header; - SaInvocationT invocation; - SaNameT compName; - SaNameT csiName; - SaAmfCSIFlagsT csiFlags; -}; - -struct res_lib_amf_componentterminatecallback { - mar_res_header_t header; - SaInvocationT invocation; - SaNameT compName; -}; - - -#ifdef COMPILE_OUT -struct res_lib_amf_protectiongrouptrackcallback { - mar_res_header_t header; - SaNameT csiName; - SaAmfProtectionGroupNotificationT *notificationBufferAddress; - SaUint32T numberOfItems; - SaUint32T numberOfMembers; - SaUint32T error; - SaAmfProtectionGroupNotificationT notificationBuffer[0]; -}; - -typedef enum { - SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_AND_Y_STANDBY = 1, - SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_OR_Y_STANDBY = 2, - SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_Y_STANDBY = 3, - SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_1_STANDBY = 4, - SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE = 5, - SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE = 6, - SA_AMF_COMPONENT_CAPABILITY_NO_ACTIVE = 7 -} SaAmfComponentCapabilityModelT; - -#endif - -#endif /* AIS_IPC_AMF_H_DEFINED */ diff --git a/openais/include/ipc_ckpt.h b/openais/include/ipc_ckpt.h deleted file mode 100644 index 4c03385d..00000000 --- a/openais/include/ipc_ckpt.h +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Copyright (c) 2006 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef IPC_CKPT_H_DEFINED -#define IPC_CKPT_H_DEFINED - -#include "saAis.h" -#include "saCkpt.h" -#include -#include "mar_ckpt.h" - -enum req_lib_ckpt_checkpoint_types { - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN = 0, - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTCLOSE = 1, - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK = 2, - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET = 3, - MESSAGE_REQ_CKPT_ACTIVEREPLICASET = 4, - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET = 5, - MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE = 6, - MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE = 7, - MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET = 8, - MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE = 9, - MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE = 10, - MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD = 11, - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE = 12, - MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC = 13, - MESSAGE_REQ_CKPT_SECTIONITERATIONINITIALIZE = 14, - MESSAGE_REQ_CKPT_SECTIONITERATIONFINALIZE = 15, - MESSAGE_REQ_CKPT_SECTIONITERATIONNEXT = 16 -}; - -enum res_lib_ckpt_checkpoint_types { - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN = 0, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC = 1, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE = 2, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK = 3, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET = 4, - MESSAGE_RES_CKPT_ACTIVEREPLICASET = 5, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET = 6, - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE = 7, - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE = 8, - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET = 9, - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE = 10, - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE = 11, - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD = 12, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE = 13, - MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC = 14, - MESSAGE_RES_CKPT_SECTIONITERATIONINITIALIZE = 15, - MESSAGE_RES_CKPT_SECTIONITERATIONFINALIZE = 16, - MESSAGE_RES_CKPT_SECTIONITERATIONNEXT = 17 -}; - -struct req_lib_ckpt_checkpointopen { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8))); - int checkpoint_creation_attributes_set __attribute__((aligned(8))); - mar_ckpt_checkpoint_open_flags_t checkpoint_open_flags __attribute__((aligned(8))); - mar_ckpt_checkpoint_handle_t checkpoint_handle __attribute__((aligned(8))); - SaAisErrorT fail_with_error __attribute__((aligned(8))); - mar_invocation_t invocation __attribute__((aligned(8))); - mar_uint32_t async_call __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointopen { - mar_res_header_t header __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointopenasync { - mar_res_header_t header __attribute__((aligned(8))); - mar_ckpt_checkpoint_handle_t checkpoint_handle __attribute__((aligned(8))); - mar_invocation_t invocation __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_checkpointclose { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointclose { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_checkpointunlink { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointunlink { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_checkpointretentiondurationset { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_time_t retention_duration __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointretentiondurationset { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_activereplicaset { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_activereplicaset { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_checkpointstatusget { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointstatusget { - mar_res_header_t header __attribute__((aligned(8))); - mar_ckpt_checkpoint_descriptor_t checkpoint_descriptor __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectioncreate { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); - mar_uint32_t initial_data_size __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectioncreate { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectiondelete { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectiondelete { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectionexpirationtimeset { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectionexpirationtimeset { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectioniterationinitialize { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_ckpt_sections_chosen_t sections_chosen __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectioniterationinitialize { - mar_res_header_t header __attribute__((aligned(8))); - unsigned int iteration_handle __attribute__((aligned(8))); - mar_size_t max_section_id_size; -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectioniterationfinalize { - mar_req_header_t header __attribute__((aligned(8))); - unsigned int iteration_handle __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectioniterationfinalize { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectioniterationnext { - mar_req_header_t header __attribute__((aligned(8))); - unsigned int iteration_handle __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectioniterationnext { - mar_res_header_t header __attribute__((aligned(8))); - mar_ckpt_section_descriptor_t section_descriptor __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectionwrite { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_offset_t data_offset __attribute__((aligned(8))); - mar_offset_t data_size __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectionwrite { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectionoverwrite { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_uint32_t data_size __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectionoverwrite { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_sectionread { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_offset_t data_offset __attribute__((aligned(8))); - mar_offset_t data_size __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_sectionread { - mar_res_header_t header __attribute__((aligned(8))); - mar_size_t data_read __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_checkpointsynchronize { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointsynchronize { - mar_res_header_t header __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct req_lib_ckpt_checkpointsynchronizeasync { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_invocation_t invocation __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -struct res_lib_ckpt_checkpointsynchronizeasync { - mar_res_header_t header __attribute__((aligned(8))); - mar_invocation_t invocation __attribute__((aligned(8))); -} __attribute__((aligned(8))); - -#endif /* IPC_CKPT_H_DEFINED */ diff --git a/openais/include/ipc_clm.h b/openais/include/ipc_clm.h deleted file mode 100644 index 1305b0b9..00000000 --- a/openais/include/ipc_clm.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef IPC_CLM_H_DEFINED -#define IPC_CLM_H_DEFINED - -#include -#include -#include "saAis.h" -#include "saClm.h" -#include "mar_clm.h" - -enum req_clm_types { - MESSAGE_REQ_CLM_TRACKSTART = 0, - MESSAGE_REQ_CLM_TRACKSTOP = 1, - MESSAGE_REQ_CLM_NODEGET = 2, - MESSAGE_REQ_CLM_NODEGETASYNC = 3 -}; - -enum res_clm_types { - MESSAGE_RES_CLM_TRACKCALLBACK = 0, - MESSAGE_RES_CLM_TRACKSTART = 1, - MESSAGE_RES_CLM_TRACKSTOP = 2, - MESSAGE_RES_CLM_NODEGET = 3, - MESSAGE_RES_CLM_NODEGETASYNC = 4, - MESSAGE_RES_CLM_NODEGETCALLBACK = 5 -}; - -struct req_lib_clm_clustertrack { - mar_req_header_t header __attribute__((aligned(8))); - unsigned char track_flags __attribute__((aligned(8))); - int return_in_callback __attribute__((aligned(8))); -}; - -struct res_lib_clm_clustertrack { - mar_res_header_t header __attribute__((aligned(8))); - unsigned long long view __attribute__((aligned(8))); - unsigned int number_of_items __attribute__((aligned(8))); - mar_clm_cluster_notification_t notification[PROCESSOR_COUNT_MAX] __attribute__((aligned(8))); -}; - -struct req_lib_clm_trackstop { - mar_req_header_t header __attribute__((aligned(8))); - unsigned long long data_read __attribute__((aligned(8))); - SaAisErrorT error __attribute__((aligned(8))); -}; - -struct res_lib_clm_trackstop { - mar_res_header_t header __attribute__((aligned(8))); -}; - -struct req_lib_clm_nodeget { - mar_req_header_t header __attribute__((aligned(8))); - unsigned long long invocation __attribute__((aligned(8))); - unsigned int node_id __attribute__((aligned(8))); -}; - -struct res_clm_nodeget { - mar_res_header_t header __attribute__((aligned(8))); - unsigned long long invocation __attribute__((aligned(8))); - mar_clm_cluster_node_t cluster_node __attribute__((aligned(8))); - int valid __attribute__((aligned(8))); -}; - -struct req_lib_clm_nodegetasync { - mar_req_header_t header __attribute__((aligned(8))); - unsigned long long invocation __attribute__((aligned(8))); - unsigned int node_id __attribute__((aligned(8))); -}; - -struct res_clm_nodegetasync { - mar_res_header_t header __attribute__((aligned(8))); -}; - -struct res_clm_nodegetcallback { - mar_res_header_t header __attribute__((aligned(8))); - SaInvocationT invocation __attribute__((aligned(8))); - mar_clm_cluster_node_t cluster_node __attribute__((aligned(8))); -}; - -#endif /* IPC_CLM_H_DEFINED */ diff --git a/openais/include/ipc_evt.h b/openais/include/ipc_evt.h deleted file mode 100644 index 985c686c..00000000 --- a/openais/include/ipc_evt.h +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (c) 2004-2005 Mark Haverkamp - * Copyright (c) 2004-2005 Open Source Development Lab - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the Open Source Developement Lab nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef IPC_EVT_H_DEFINED -#define IPC_EVT_H_DEFINED - -#include -#include -#include "saAis.h" -#include "saEvt.h" -#include "saClm.h" -#include "mar_evt.h" - -enum req_evt_types { - MESSAGE_REQ_EVT_OPEN_CHANNEL = 0, - MESSAGE_REQ_EVT_OPEN_CHANNEL_ASYNC = 1, - MESSAGE_REQ_EVT_CLOSE_CHANNEL = 2, - MESSAGE_REQ_EVT_UNLINK_CHANNEL = 3, - MESSAGE_REQ_EVT_SUBSCRIBE = 4, - MESSAGE_REQ_EVT_UNSUBSCRIBE = 5, - MESSAGE_REQ_EVT_PUBLISH = 6, - MESSAGE_REQ_EVT_CLEAR_RETENTIONTIME = 7, - MESSAGE_REQ_EVT_EVENT_DATA = 8 -}; - -enum res_evt_types { - MESSAGE_RES_EVT_OPEN_CHANNEL = 0, - MESSAGE_RES_EVT_CLOSE_CHANNEL = 1, - MESSAGE_RES_EVT_UNLINK_CHANNEL = 2, - MESSAGE_RES_EVT_SUBSCRIBE = 3, - MESSAGE_RES_EVT_UNSUBSCRIBE = 4, - MESSAGE_RES_EVT_PUBLISH = 5, - MESSAGE_RES_EVT_CLEAR_RETENTIONTIME = 6, - MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK = 7, - MESSAGE_RES_EVT_EVENT_DATA = 8, - MESSAGE_RES_EVT_AVAILABLE = 9 -}; - -/* - * MESSAGE_REQ_EVT_OPEN_CHANNEL - * MESSAGE_REQ_EVT_OPEN_CHANNEL_ASYNC - * - * ico_head Request head - * ico_open_flag: Channel open flags - * ico_channel_name: Name of channel to open - * ico_c_handle: Local lib channel handle (used in returned event data) - * ico_timeout: Used only by open - * ico_invocation: Used only by async open - * - */ -struct req_evt_channel_open { - mar_req_header_t ico_head __attribute__((aligned(8))); - mar_uint8_t ico_open_flag __attribute__((aligned(8))); - mar_name_t ico_channel_name __attribute__((aligned(8))); - mar_evtchannelhandle_t ico_c_handle __attribute__((aligned(8))); - mar_time_t ico_timeout __attribute__((aligned(8))); - mar_invocation_t ico_invocation __attribute__((aligned(8))); -}; - -/* - * MESSAGE_RES_EVT_OPEN_CHANNEL - * - * Used by both the blocing and non-blocking - * versions. Only the error code in the header is used by the async - * open. The channel handle will be returnd via the channel open - * callback. - * - * - * ico_head: Results head - * ico_error: Request results - * ico_channel_handle: Server side channel handle (used in channel ops) - * - */ -struct res_evt_channel_open { - - mar_res_header_t ico_head __attribute__((aligned(8))); - mar_uint32_t ico_channel_handle __attribute__((aligned(8)));/* svr chan handle */ - -}; - -/* - * MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK - * - * ica_head: Results head. - * ica_c_handle: Lib size channel handle. So we can look - * up the new open channel info from the callback. - * ica_channel_handle: Server side handle. - * ica_invocation: Supplied by the user in the open call. Passed to - * the callback so the user can assocate the callback - * to the particular open. - */ -struct res_evt_open_chan_async { - mar_res_header_t ica_head __attribute__((aligned(8))); - mar_evtchannelhandle_t ica_c_handle __attribute__((aligned(8))); - mar_uint32_t ica_channel_handle __attribute__((aligned(8))); - mar_invocation_t ica_invocation __attribute__((aligned(8))); - -}; - - -/* - * MESSAGE_REQ_EVT_CLOSE_CHANNEL - * - * icc_head: Request head - * icc_channel_handle: Server handle of channel to close - * - */ -struct req_evt_channel_close { - mar_req_header_t icc_head __attribute__((aligned(8))); - mar_uint32_t icc_channel_handle __attribute__((aligned(8))); -}; - -/* - * MESSAGE_RES_EVT_CLOSE_CHANNEL - * - * icc_head: Results head - * - */ -struct res_evt_channel_close { - mar_res_header_t icc_head __attribute__((aligned(8))); -}; - -/* - * MESSAGE_REQ_EVT_UNLINK_CHANNEL - * - * iuc_head: Request head - * iuc_channel_name: Name of channel to unlink - * - */ -struct req_evt_channel_unlink { - mar_req_header_t iuc_head __attribute__((aligned(8))); - mar_name_t iuc_channel_name __attribute__((aligned(8))); -}; - -/* - * MESSAGE_RES_EVT_UNLINK_CHANNEL - * - * iuc_head: Results head - * - */ -struct res_evt_channel_unlink { - mar_res_header_t iuc_head __attribute__((aligned(8))); -}; - -/* - * MESSAGE_REQ_EVT_SUBSCRIBE - * - * ics_head: Request head - * ics_channel_handle: Server handle of channel - * ics_sub_id: Subscription ID - * ics_filter_size: Size of supplied filter data - * ics_filter_count: Number of filters supplied - * ics_filter_data: Filter data - * - */ -struct req_evt_event_subscribe { - mar_req_header_t ics_head __attribute__((aligned(8))); - mar_uint32_t ics_channel_handle __attribute__((aligned(8))); - mar_evtsubscriptionid_t ics_sub_id __attribute__((aligned(8))); - mar_uint32_t ics_filter_size __attribute__((aligned(8))); - mar_uint32_t ics_filter_count __attribute__((aligned(8))); - mar_uint8_t ics_filter_data[0] __attribute__((aligned(8))); - -}; - -/* - * MESSAGE_RES_EVT_SUBSCRIBE - * - * ics_head: Result head - * ics_error: Request results - * - */ -struct res_evt_event_subscribe { - mar_res_header_t ics_head __attribute__((aligned(8))); -}; - -/* - * MESSAGE_REQ_EVT_UNSUBSCRIBE - * - * icu_head: Request head - * icu_channel_handle: Server handle of channel - * icu_sub_id: Subscription ID - * - */ -struct req_evt_event_unsubscribe { - mar_req_header_t icu_head __attribute__((aligned(8))); - mar_uint32_t icu_channel_handle __attribute__((aligned(8))); - mar_evtsubscriptionid_t icu_sub_id __attribute__((aligned(8))); -}; - - -/* - * MESSAGE_RES_EVT_UNSUBSCRIBE - * - * icu_head: Results head - * icu_error: request result - * - */ -struct res_evt_event_unsubscribe { - mar_res_header_t icu_head __attribute__((aligned(8))); - -}; - -/* - * MESSAGE_REQ_EVT_EVENT_DATA - * MESSAGE_RES_EVT_AVAILABLE - * - * evd_head: Request Head - */ -struct res_evt_event_data { - mar_res_header_t evd_head __attribute__((aligned(8))); -}; - -/* - * MESSAGE_REQ_EVT_PUBLISH (1) - * MESSAGE_RES_EVT_EVENT_DATA (2) - * MESSAGE_REQ_EXEC_EVT_EVENTDATA (3) - * MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA (4) - * - * led_head: Request/Results head - * led_addr: address of node (4 only) - * led_receive_time: Time that the message was received (4 only) - * led_svr_channel_handle: Server channel handle (1 only) - * led_lib_channel_handle: Lib channel handle (2 only) - * led_chan_name: Channel name (3 and 4 only) - * led_chan_unlink_id: directs delivery to unlinked channels. - * led_event_id: Event ID (2, 3 and 4 only) - * led_msg_id: message ID (2, 3 and 4 only) - * led_sub_id: Subscription ID (2 only) - * led_publisher_node_id: Node ID of event publisher - * led_publisher_name: Node name of event publisher - * led_retention_time: Event retention time - * led_publish_time: Publication time of the event - * led_priority: Event priority - * led_user_data_offset: Offset to user data - * led_user_data_size: Size of user data - * led_patterns_number: Number of patterns in the event - * led_body: Pattern and user data - */ -struct lib_event_data { - mar_res_header_t led_head __attribute__((aligned(8))); - mar_uint32_t led_nodeid __attribute__((aligned(8))); - mar_time_t led_receive_time __attribute__((aligned(8))); - mar_uint32_t led_svr_channel_handle __attribute__((aligned(8))); - mar_evtchannelhandle_t led_lib_channel_handle __attribute__((aligned(8))); - mar_name_t led_chan_name __attribute__((aligned(8))); - mar_uint64_t led_chan_unlink_id __attribute__((aligned(8))); - mar_evteventid_t led_event_id __attribute__((aligned(8))); - mar_uint64_t led_msg_id __attribute__((aligned(8))); - mar_evtsubscriptionid_t led_sub_id __attribute__((aligned(8))); - mar_uint32_t led_publisher_node_id __attribute__((aligned(8))); - mar_name_t led_publisher_name __attribute__((aligned(8))); - mar_time_t led_retention_time __attribute__((aligned(8))); - mar_time_t led_publish_time __attribute__((aligned(8))); - mar_evteventpriority_t led_priority __attribute__((aligned(8))); - mar_uint32_t led_user_data_offset __attribute__((aligned(8))); - mar_uint32_t led_user_data_size __attribute__((aligned(8))); - mar_uint32_t led_patterns_number __attribute__((aligned(8))); - mar_uint8_t led_body[0] __attribute__((aligned(8))); -}; - -/* - * MESSAGE_RES_EVT_PUBLISH - * - * iep_head: Result head - * iep_error: Request results - * iep_event_id: Event ID of published message - * - */ -struct res_evt_event_publish { - mar_res_header_t iep_head __attribute__((aligned(8))); - mar_evteventid_t iep_event_id __attribute__((aligned(8))); -}; - -/* - * MESSAGE_REQ_EVT_CLEAR_RETENTIONTIME - * - * Request message: - * - * iec_head: Request head - * iec_event_id: ID of event to clear - * iec_channel_handle: Server handle of associate channel - * - */ -struct req_evt_event_clear_retentiontime { - - mar_req_header_t iec_head __attribute__((aligned(8))); - mar_evteventid_t iec_event_id __attribute__((aligned(8))); - mar_uint32_t iec_channel_handle __attribute__((aligned(8))); - -}; - -/* - * MESSAGE_RES_EVT_CLEAR_RETENTIONTIME - * - * iec_head: Results head - * iec_error: Request result - * - */ -struct res_evt_event_clear_retentiontime { - mar_res_header_t iec_head __attribute__((aligned(8))); -}; - -#endif /* AIS_EVT_H_DEFINED */ diff --git a/openais/include/ipc_lck.h b/openais/include/ipc_lck.h deleted file mode 100644 index b3f68613..00000000 --- a/openais/include/ipc_lck.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef IPC_LCK_H_DEFINED -#define IPC_LCK_H_DEFINED - -#include "saAis.h" -#include "saLck.h" -#include -#include - -enum req_lib_lck_resource_types { - MESSAGE_REQ_LCK_RESOURCEOPEN = 0, - MESSAGE_REQ_LCK_RESOURCEOPENASYNC = 1, - MESSAGE_REQ_LCK_RESOURCECLOSE = 2, - MESSAGE_REQ_LCK_RESOURCELOCK = 3, - MESSAGE_REQ_LCK_RESOURCELOCKASYNC = 4, - MESSAGE_REQ_LCK_RESOURCEUNLOCK = 5, - MESSAGE_REQ_LCK_RESOURCEUNLOCKASYNC = 6, - MESSAGE_REQ_LCK_LOCKPURGE = 7, -}; - -enum res_lib_lck_resource_types { - MESSAGE_RES_LCK_RESOURCEOPEN = 0, - MESSAGE_RES_LCK_RESOURCEOPENASYNC = 1, - MESSAGE_RES_LCK_RESOURCECLOSE = 2, - MESSAGE_RES_LCK_RESOURCELOCK = 3, - MESSAGE_RES_LCK_RESOURCELOCKASYNC = 4, - MESSAGE_RES_LCK_RESOURCEUNLOCK = 5, - MESSAGE_RES_LCK_RESOURCEUNLOCKASYNC = 6, - MESSAGE_RES_LCK_LOCKPURGE = 7, - MESSAGE_RES_LCK_LOCKWAITERCALLBACK = 8 -}; - -struct req_lib_lck_resourceopen { - mar_req_header_t header; - SaInvocationT invocation; - mar_name_t lockResourceName; - SaLckResourceOpenFlagsT resourceOpenFlags; - SaLckResourceHandleT resourceHandle; - SaTimeT timeout; - int async_call; -}; - -struct res_lib_lck_resourceopen { - mar_res_header_t header; - SaLckResourceHandleT resourceHandle; - mar_message_source_t source; -}; - -struct res_lib_lck_resourceopenasync { - mar_res_header_t header; - SaInvocationT invocation; - SaLckResourceHandleT resourceHandle; - mar_message_source_t source; -}; - -struct req_lib_lck_resourceclose { - mar_req_header_t header; - mar_name_t lockResourceName; - SaLckResourceHandleT resourceHandle; -}; - -struct res_lib_lck_resourceclose { - mar_res_header_t header; -}; - -struct req_lib_lck_resourcelock { - mar_req_header_t header; - mar_name_t lockResourceName; - SaInvocationT invocation; - SaLckLockModeT lockMode; - SaLckLockFlagsT lockFlags; - SaLckWaiterSignalT waiterSignal; - SaTimeT timeout; - SaLckLockIdT lockId; - int async_call; - mar_message_source_t source; - SaLckResourceHandleT resourceHandle; -}; - -static inline void swab_req_lib_lck_resourcelock ( - struct req_lib_lck_resourcelock *to_swab) -{ - swab_mar_req_header_t (&to_swab->header); - swab_mar_name_t (&to_swab->lockResourceName); - to_swab->invocation = swab64 (to_swab->invocation); - to_swab->lockMode = swab64 (to_swab->lockMode); - to_swab->lockFlags = swab32 (to_swab->lockFlags); - to_swab->waiterSignal = swab64 (to_swab->waiterSignal); - to_swab->timeout = swab64 (to_swab->timeout); - to_swab->lockId = swab64 (to_swab->lockId); - to_swab->async_call = swab32 (to_swab->async_call); - swab_mar_message_source_t (&to_swab->source); - to_swab->resourceHandle = swab64 (to_swab->resourceHandle); -} - -struct res_lib_lck_resourcelock { - mar_res_header_t header; - SaLckLockStatusT lockStatus; - void *resource_lock; -}; - -struct res_lib_lck_resourcelockasync { - mar_res_header_t header; - SaLckLockStatusT lockStatus; - SaLckLockIdT lockId; - void *resource_lock; - SaInvocationT invocation; - SaLckResourceHandleT resourceHandle; -}; - -struct req_lib_lck_resourceunlock { - mar_req_header_t header; - mar_name_t lockResourceName; - SaLckLockIdT lockId; - SaInvocationT invocation; - SaTimeT timeout; - int async_call; - void *resource_lock; -}; - -struct res_lib_lck_resourceunlock { - mar_res_header_t header; -}; - -struct res_lib_lck_resourceunlockasync { - mar_res_header_t header; - SaInvocationT invocation; - SaLckLockIdT lockId; -}; - -struct req_lib_lck_lockpurge { - mar_req_header_t header; - mar_name_t lockResourceName; -}; - -static inline void swab_req_lib_lck_lockpurge ( - struct req_lib_lck_lockpurge *to_swab) -{ - swab_mar_req_header_t (&to_swab->header); - swab_mar_name_t (&to_swab->lockResourceName); -} - -struct res_lib_lck_lockpurge { - mar_res_header_t header; -}; - -struct res_lib_lck_lockwaitercallback { - mar_res_header_t header; - SaLckWaiterSignalT waiter_signal; - SaLckLockIdT lock_id; - SaLckLockModeT mode_held; - SaLckLockModeT mode_requested; -}; - -#endif /* IPC_LCK_H_DEFINED */ diff --git a/openais/include/ipc_msg.h b/openais/include/ipc_msg.h deleted file mode 100644 index 8ee75d20..00000000 --- a/openais/include/ipc_msg.h +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef IPC_MSG_H_DEFINED -#define IPC_MSG_H_DEFINED - -#include "saAis.h" -#include "saMsg.h" - -#include - -enum req_lib_msg_queue_types { - MESSAGE_REQ_MSG_QUEUEOPEN = 0, - MESSAGE_REQ_MSG_QUEUEOPENASYNC = 1, - MESSAGE_REQ_MSG_QUEUECLOSE = 2, - MESSAGE_REQ_MSG_QUEUESTATUSGET = 3, - MESSAGE_REQ_MSG_QUEUEUNLINK = 4, - MESSAGE_REQ_MSG_QUEUEGROUPCREATE = 5, - MESSAGE_REQ_MSG_QUEUEGROUPINSERT = 6, - MESSAGE_REQ_MSG_QUEUEGROUPREMOVE = 7, - MESSAGE_REQ_MSG_QUEUEGROUPDELETE = 8, - MESSAGE_REQ_MSG_QUEUEGROUPTRACK = 9, - MESSAGE_REQ_MSG_QUEUEGROUPTRACKSTOP = 10, - MESSAGE_REQ_MSG_MESSAGESEND = 11, - MESSAGE_REQ_MSG_MESSAGESENDASYNC = 12, - MESSAGE_REQ_MSG_MESSAGEGET = 13, - MESSAGE_REQ_MSG_MESSAGECANCEL = 14, - MESSAGE_REQ_MSG_MESSAGESENDRECEIVE = 15, - MESSAGE_REQ_MSG_MESSAGEREPLY = 16, - MESSAGE_REQ_MSG_MESSAGEREPLYASYNC = 17 -}; - -enum res_lib_msg_queue_types { - MESSAGE_RES_MSG_QUEUEOPEN = 0, - MESSAGE_RES_MSG_QUEUEOPENASYNC = 1, - MESSAGE_RES_MSG_QUEUECLOSE = 2, - MESSAGE_RES_MSG_QUEUESTATUSGET = 3, - MESSAGE_RES_MSG_QUEUEUNLINK = 4, - MESSAGE_RES_MSG_QUEUEGROUPCREATE = 5, - MESSAGE_RES_MSG_QUEUEGROUPINSERT = 6, - MESSAGE_RES_MSG_QUEUEGROUPREMOVE = 7, - MESSAGE_RES_MSG_QUEUEGROUPDELETE = 8, - MESSAGE_RES_MSG_QUEUEGROUPTRACK = 9, - MESSAGE_RES_MSG_QUEUEGROUPTRACKSTOP = 10, - MESSAGE_RES_MSG_MESSAGESEND = 11, - MESSAGE_RES_MSG_MESSAGESENDASYNC = 12, - MESSAGE_RES_MSG_MESSAGEGET = 13, - MESSAGE_RES_MSG_MESSAGECANCEL = 14, - MESSAGE_RES_MSG_MESSAGESENDRECEIVE = 15, - MESSAGE_RES_MSG_MESSAGEREPLY = 16, - MESSAGE_RES_MSG_MESSAGEREPLYASYNC = 17 -}; - -struct req_lib_msg_queueopen { - mar_req_header_t header; - SaInvocationT invocation; - SaNameT queueName; - SaMsgQueueCreationAttributesT creationAttributes; - int creationAttributesSet; - SaMsgQueueOpenFlagsT openFlags; - SaMsgQueueHandleT queueHandle; - SaTimeT timeout; - int async_call; -}; - -struct res_lib_msg_queueopen { - mar_res_header_t header; - mar_message_source_t source; - SaMsgQueueHandleT queueHandle; -}; - -struct res_lib_msg_queueopenasync { - mar_res_header_t header; - mar_message_source_t source; - SaInvocationT invocation; - SaMsgQueueHandleT queueHandle; -}; - -struct req_lib_msg_queueclose { - mar_req_header_t header; - SaNameT queueName; - SaMsgQueueHandleT queueHandle; -}; - -struct res_lib_msg_queueclose { - mar_res_header_t header; -}; - -struct req_lib_msg_queuestatusget { - mar_req_header_t header; - SaNameT queueName; -}; - -struct res_lib_msg_queuestatusget { - mar_res_header_t header; - SaMsgQueueStatusT queueStatus; -}; - -struct req_lib_msg_queueunlink { - mar_req_header_t header; - SaNameT queueName; -}; - -struct res_lib_msg_queueunlink { - mar_res_header_t header; -}; - -struct req_lib_msg_queuegroupcreate { - mar_req_header_t header; - SaNameT queueGroupName; - SaMsgQueueGroupPolicyT queueGroupPolicy; -}; - -struct res_lib_msg_queuegroupcreate { - mar_res_header_t header; -}; - -struct req_lib_msg_queuegroupinsert { - mar_req_header_t header; - SaNameT queueGroupName; - SaNameT queueName; -}; - -struct res_lib_msg_queuegroupinsert { - mar_res_header_t header; -}; - -struct req_lib_msg_queuegroupremove { - mar_req_header_t header; - SaNameT queueGroupName; - SaNameT queueName; -}; - -struct res_lib_msg_queuegroupremove { - mar_res_header_t header; -}; - -struct req_lib_msg_queuegroupdelete { - mar_req_header_t header; - SaNameT queueGroupName; -}; - -struct res_lib_msg_queuegroupdelete { - mar_res_header_t header; -}; - -struct req_lib_msg_queuegrouptrack { - mar_req_header_t header; - SaNameT queueGroupName; - SaUint8T trackFlags; - SaUint8T bufferFlag; -}; - -struct res_lib_msg_queuegrouptrack { - mar_res_header_t header; - SaNameT queueGroupName; - SaUint32T numberOfMembers; - SaMsgQueueGroupNotificationBufferT notificationBuffer; -}; - -struct req_lib_msg_queuegrouptrackstop { - mar_req_header_t header; - SaNameT queueGroupName; -}; - -struct res_lib_msg_queuegrouptrackstop { - mar_res_header_t header; -}; - -struct req_lib_msg_messagesend { - mar_req_header_t header; - SaInvocationT invocation; - SaNameT destination; - SaMsgMessageT message; - SaTimeT timeout; - SaMsgAckFlagsT ackFlags; - int async_call; -}; - -struct res_lib_msg_messagesend { - mar_res_header_t header; - mar_message_source_t source; -}; - -struct res_lib_msg_messagesendasync { - mar_res_header_t header; - mar_message_source_t source; - SaInvocationT invocation; -}; - -struct req_lib_msg_messageget { - mar_req_header_t header; - SaNameT queueName; - SaTimeT timeout; -}; - -struct res_lib_msg_messageget { - mar_res_header_t header; - mar_message_source_t source; - SaTimeT sendTime; - SaMsgSenderIdT senderId; - SaMsgMessageT message; -}; - -struct req_lib_msg_messagecancel { - mar_req_header_t header; - SaNameT queueName; -}; - -struct res_lib_msg_messagecancel { - mar_res_header_t header; -}; - -struct req_lib_msg_messagesendreceive { - mar_req_header_t header; - SaNameT destination; - SaTimeT timeout; - SaNameT queueName; - SaMsgMessageT sendMessage; -}; - -struct res_lib_msg_messagesendreceive { - mar_res_header_t header; - SaTimeT replySendTime; - SaMsgMessageT receiveMessage; -}; - -struct req_lib_msg_messagereply { - mar_req_header_t header; - SaInvocationT invocation; - SaNameT queueName; - SaNameT senderId; - SaMsgMessageT replyMessage; - SaTimeT timeout; - SaMsgAckFlagsT ackFlags; - int async_call; -}; - -struct res_lib_msg_messagereply { - mar_res_header_t header; -}; - -struct res_lib_msg_messagereplyasync { - mar_res_header_t header; -}; - -#endif /* IPC_MSG_H_DEFINED */ diff --git a/openais/include/mar_ckpt.h b/openais/include/mar_ckpt.h deleted file mode 100644 index 6406df46..00000000 --- a/openais/include/mar_ckpt.h +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (C) 2006 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef AIS_MAR_CKPT_H_DEFINED -#define AIS_MAR_CKPT_H_DEFINED - -#include -#include "saAis.h" -#include "saCkpt.h" - -typedef mar_uint64_t mar_ckpt_checkpoint_handle_t; - -static inline void swab_mar_ckpt_checkpoint_handle_t ( - mar_ckpt_checkpoint_handle_t *to_swab) -{ - swab_mar_uint64_t (to_swab); -} - -typedef mar_uint32_t mar_ckpt_checkpoint_creation_flags_t; - -static inline void swab_mar_ckpt_checkpoint_creation_flags_t ( - mar_ckpt_checkpoint_creation_flags_t *to_swab) -{ - swab_mar_uint32_t (to_swab); -} - -/* - * Marshalling the SaCkptCheckpointCreationAttributesT data structure - */ -typedef struct { - mar_ckpt_checkpoint_creation_flags_t creation_flags __attribute__((aligned(8))); - mar_size_t checkpoint_size __attribute__((aligned(8))); - mar_time_t retention_duration __attribute__((aligned(8))); - mar_uint32_t max_sections __attribute__((aligned(8))); - mar_size_t max_section_size __attribute__((aligned(8))); - mar_size_t max_section_id_size __attribute__((aligned(8))); -} mar_ckpt_checkpoint_creation_attributes_t; - -static inline void swab_mar_ckpt_checkpoint_creation_attributes_t ( - mar_ckpt_checkpoint_creation_attributes_t *to_swab) -{ - swab_mar_ckpt_checkpoint_creation_flags_t (&to_swab->creation_flags); - swab_mar_size_t (&to_swab->checkpoint_size); - swab_mar_time_t (&to_swab->retention_duration); - swab_mar_uint32_t (&to_swab->max_sections); - swab_mar_size_t (&to_swab->max_section_size); - swab_mar_size_t (&to_swab->max_section_id_size); -} - -static inline void marshall_from_mar_ckpt_checkpoint_creation_attributes_t ( - SaCkptCheckpointCreationAttributesT *dest, - mar_ckpt_checkpoint_creation_attributes_t *src) -{ - dest->creationFlags = src->creation_flags; - dest->checkpointSize = src->checkpoint_size; - dest->retentionDuration = src->retention_duration; - dest->maxSections = src->max_sections; - dest->maxSectionSize = src->max_section_size; - dest->maxSectionIdSize = src->max_section_id_size; -} - -static inline void marshall_to_mar_ckpt_checkpoint_creation_attributes_t ( - mar_ckpt_checkpoint_creation_attributes_t *dest, - SaCkptCheckpointCreationAttributesT *src) -{ - memset (dest, 0, sizeof (mar_ckpt_checkpoint_creation_attributes_t)); - dest->creation_flags = src->creationFlags; - dest->checkpoint_size = src->checkpointSize; - dest->retention_duration = src->retentionDuration; - dest->max_sections = src->maxSections; - dest->max_section_size = src->maxSectionSize; - dest->max_section_id_size = src->maxSectionIdSize; -} - -#define MAR_CKPT_CHECKPOINT_READ 0x1 -#define MAR_CKPT_CHECKPOINT_WRITE 0x2 -#define MAR_CKPT_CHECKPOINT_CREATE 0x4 - -typedef mar_uint32_t mar_ckpt_checkpoint_open_flags_t; - -static inline void swab_mar_ckpt_checkpoint_open_flags_t (mar_ckpt_checkpoint_open_flags_t *to_swab) -{ - swab_mar_uint32_t (to_swab); -} - -#define MAR_CKPT_DEFAULT_SECTION_ID { 0, 0 } -#define MAR_CKPT_GENERATED_SECTION_ID { 0, 0 } - -/* - * Marshalling the SaCkptSectionIdT data structure - */ -typedef struct { - mar_uint16_t id_len __attribute__((aligned(8))); - mar_uint8_t *id __attribute__((aligned(8))); -} mar_ckpt_section_id_t; - -static inline void swab_mar_ckpt_section_id_t (mar_ckpt_section_id_t *to_swab) -{ - swab_mar_uint16_t (&to_swab->id_len); -} - -static inline void marshall_from_mar_ckpt_section_id_t ( - SaCkptSectionIdT *dest, - mar_ckpt_section_id_t *src) -{ - dest->idLen = src->id_len; - dest->id = src->id; -} - -static inline void marshall_to_mar_ckpt_section_id_t ( - mar_ckpt_section_id_t *dest, - SaCkptSectionIdT *src) -{ - memset (dest, 0, sizeof (mar_ckpt_section_id_t)); - dest->id_len = src->idLen; - dest->id = src->id; -} - -/* - * Marshalling the SaCkptSectionCreationAttributesT data structure - */ -typedef struct { - mar_ckpt_section_id_t *section_id __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); -} mar_ckpt_section_creation_attributes_t; - -static inline void swab_mar_ckpt_section_creation_attributes_t ( - mar_ckpt_section_creation_attributes_t *to_swab) -{ - swab_mar_ckpt_section_id_t (to_swab->section_id); - swab_mar_time_t (&to_swab->expiration_time); -} - -static inline void marshall_from_mar_ckpt_section_creation_attributes_t ( - SaCkptSectionCreationAttributesT *dest, - mar_ckpt_section_creation_attributes_t *src) -{ - marshall_from_mar_ckpt_section_id_t (dest->sectionId, src->section_id); - dest->expirationTime = src->expiration_time; -} - -static inline void marshall_to_mar_ckpt_section_creation_attributes_t ( - mar_ckpt_section_creation_attributes_t *dest, - SaCkptSectionCreationAttributesT *src) -{ - memset (dest, 0, sizeof (mar_ckpt_section_creation_attributes_t)); - marshall_to_mar_ckpt_section_id_t (dest->section_id, src->sectionId); - dest->expiration_time = src->expirationTime; -} - -typedef mar_uint32_t mar_ckpt_section_state_t; -#define MAR_CKPT_SECTION_VALID 1 -#define MAR_CKPT_SECTION_CORRUPTED 2 - -static inline void swab_mar_ckpt_section_state_t ( - mar_ckpt_section_state_t *to_swab) -{ - swab_mar_uint32_t (to_swab); -} - -/* - * Marshalling the SaCkptSectionDescriptorT data structure - */ -typedef struct { - mar_ckpt_section_id_t section_id __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); - mar_size_t section_size __attribute__((aligned(8))); - mar_ckpt_section_state_t section_state __attribute__((aligned(8))); - mar_time_t last_update __attribute__((aligned(8))); -} mar_ckpt_section_descriptor_t; - -static inline void swab_mar_ckpt_section_descriptor_t ( - mar_ckpt_section_descriptor_t *to_swab) -{ - swab_mar_ckpt_section_id_t (&to_swab->section_id); - swab_mar_time_t (&to_swab->expiration_time); - swab_mar_size_t (&to_swab->section_size); - swab_mar_ckpt_section_state_t (&to_swab->section_state); - swab_mar_time_t (&to_swab->last_update); -} -static inline void marshall_from_mar_ckpt_section_descriptor_t ( - SaCkptSectionDescriptorT *dest, - mar_ckpt_section_descriptor_t *src) -{ - marshall_from_mar_ckpt_section_id_t (&dest->sectionId, &src->section_id); - dest->expirationTime = src->expiration_time; - dest->sectionSize = src->section_size; - dest->sectionState = src->section_state; - dest->lastUpdate = src->last_update; -} - -static inline void marshall_to_mar_ckpt_section_descriptor_t ( - mar_ckpt_section_descriptor_t *dest, - SaCkptSectionDescriptorT *src) -{ - memset (dest, 0, sizeof (mar_ckpt_section_descriptor_t)); - marshall_to_mar_ckpt_section_id_t (&dest->section_id, &src->sectionId); - dest->expiration_time = src->expirationTime; - dest->section_size = src->sectionSize; - dest->section_state = src->sectionState; - dest->last_update = src->lastUpdate; -} - -typedef enum { - MAR_CKPT_SECTIONS_FOREVER = 1, - MAR_CKPT_SECTIONS_LEQ_EXPIRATION_TIME = 2, - MAR_CKPT_SECTIONS_GEQ_EXPIRATION_TIME = 3, - MAR_CKPT_SECTIONS_CORRUPTED = 4, - MAR_CKPT_SECTIONS_ANY = 5 -} mar_ckpt_sections_chosen_t; - -typedef mar_uint64_t mar_offset_t; - -static inline void swab_mar_offset_t ( - mar_offset_t *to_swab) -{ - swab_mar_uint64_t (to_swab); -} - -/* - * Marshalling the SaCkptIOVectorElementT (not needed) - */ -typedef struct { - mar_ckpt_section_id_t section_id __attribute__((aligned(8))); - void *data_buffer __attribute__((aligned(8))); - mar_size_t data_size __attribute__((aligned(8))); - mar_offset_t data_offset __attribute__((aligned(8))); - mar_size_t read_size __attribute__((aligned(8))); -} mar_ckpt_io_vector_element_t; - -/* - * Marshalling the SaCkptCheckpointDescriptorT - */ -typedef struct { - mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8))); - mar_uint32_t number_of_sections __attribute__((aligned(8))); - mar_uint32_t memory_used __attribute__((aligned(8))); -} mar_ckpt_checkpoint_descriptor_t; - -static inline void marshall_from_mar_ckpt_checkpoint_descriptor_t ( - SaCkptCheckpointDescriptorT *dest, - mar_ckpt_checkpoint_descriptor_t *src) -{ - marshall_from_mar_ckpt_checkpoint_creation_attributes_t ( - &dest->checkpointCreationAttributes, - &src->checkpoint_creation_attributes); - dest->numberOfSections = src->number_of_sections; - dest->memoryUsed = src->memory_used; -} - -static inline void marshall_to_mar_ckpt_checkpoint_descriptor_t ( - mar_ckpt_checkpoint_descriptor_t *dest, - SaCkptCheckpointDescriptorT *src) -{ - memset (dest, 0, sizeof (mar_ckpt_checkpoint_descriptor_t)); - marshall_to_mar_ckpt_checkpoint_creation_attributes_t ( - &dest->checkpoint_creation_attributes, - &src->checkpointCreationAttributes); - dest->number_of_sections = src->numberOfSections; - dest->memory_used = src->memoryUsed; -} - -#endif /* AIS_MAR_CKPT_H_DEFINED */ diff --git a/openais/include/mar_clm.h b/openais/include/mar_clm.h deleted file mode 100644 index 6c4ce901..00000000 --- a/openais/include/mar_clm.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 2006 Red Hat, Inc. - * Copyright (C) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef AIS_MAR_CLM_H_DEFINED -#define AIS_MAR_CLM_H_DEFINED - -#include -#include "saAis.h" -#include "saClm.h" -#include - -#define MAR_CLM_MAX_ADDRESS_LENGTH 64 - -typedef enum { - MAR_CLM_AF_INET = 1, - MAR_CLM_AF_INET6 = 2 -} mar_clm_node_address_family_t; - -/* - * Marshalling the SaClmNodeAdressT data structure - */ -typedef struct { - unsigned short length __attribute__((aligned(8))); - mar_clm_node_address_family_t family __attribute__((aligned(8))); - unsigned char value[MAR_CLM_MAX_ADDRESS_LENGTH] __attribute__((aligned(8))); -} mar_clm_node_address_t; - -static inline void swab_mar_clm_node_address_t(mar_clm_node_address_t *to_swab) -{ - swab_mar_uint16_t (&to_swab->length); - swab_mar_uint32_t (&to_swab->family); -} - -static inline void marshall_from_mar_clm_node_address_t ( - SaClmNodeAddressT *dest, - mar_clm_node_address_t *src) -{ - dest->family = src->family; - dest->length = src->length; - memcpy (dest->value, src->value, SA_CLM_MAX_ADDRESS_LENGTH); -} - -static inline void marshall_to_mar_clm_node_address_t ( - mar_clm_node_address_t *dest, - SaClmNodeAddressT *src) -{ - dest->family = src->family; - dest->length = src->length; - memcpy (dest->value, src->value, SA_CLM_MAX_ADDRESS_LENGTH); -} - -/* - * Marshalling the SaClmClusterNodeT data structure - */ -typedef struct { - mar_uint32_t node_id __attribute__((aligned(8))); - mar_clm_node_address_t node_address __attribute__((aligned(8))); - mar_name_t node_name __attribute__((aligned(8))); - mar_uint32_t member __attribute__((aligned(8))); - mar_uint64_t boot_timestamp __attribute__((aligned(8))); - mar_uint64_t initial_view_number __attribute__((aligned(8))); -} mar_clm_cluster_node_t; - -static inline void swab_mar_clm_cluster_node_t(mar_clm_cluster_node_t *to_swab) -{ - swab_mar_uint32_t (&to_swab->node_id); - swab_mar_uint32_t (&to_swab->member); - swab_mar_clm_node_address_t (&to_swab->node_address); - swab_mar_name_t (&to_swab->node_name); - swab_mar_uint64_t (&to_swab->boot_timestamp); - swab_mar_uint64_t (&to_swab->initial_view_number); -} - -static inline void marshall_to_mar_clm_cluster_node_t ( - mar_clm_cluster_node_t *dest, - SaClmClusterNodeT *src) -{ - dest->node_id = src->nodeId; - marshall_to_mar_clm_node_address_t (&dest->node_address, - &src->nodeAddress); - marshall_to_mar_name_t (&dest->node_name, &src->nodeName); - dest->member = src->member; - dest->boot_timestamp = src->bootTimestamp; - dest->initial_view_number = src->initialViewNumber; -} - -static inline void marshall_from_mar_clm_cluster_node_t ( - SaClmClusterNodeT *dest, - mar_clm_cluster_node_t *src) -{ - dest->nodeId = src->node_id; - marshall_from_mar_clm_node_address_t (&dest->nodeAddress, - &src->node_address); - marshall_from_mar_name_t (&dest->nodeName, &src->node_name); - dest->member = src->member; - dest->bootTimestamp = src->boot_timestamp; - dest->initialViewNumber = src->initial_view_number; -} - -typedef enum { - MAR_NODE_NO_CHANGE = 1, - MAR_NODE_JOINED = 2, - MAR_NODE_LEFT = 3, - MAR_NODE_RECONFIGURED = 4 -} mar_clm_cluster_change_t; - -/* - * Marshalling the SaClmClusterNotificationT data structure - */ -typedef struct { - mar_clm_cluster_node_t cluster_node __attribute__((aligned(8))); - mar_clm_cluster_change_t cluster_change __attribute__((aligned(8))); -} mar_clm_cluster_notification_t; - -static inline void marshall_to_mar_clm_cluster_notification_t ( - mar_clm_cluster_notification_t *dest, - SaClmClusterNotificationT *src) -{ - marshall_to_mar_clm_cluster_node_t (&dest->cluster_node, - &src->clusterNode); - dest->cluster_change = src->clusterChange; -} - -static inline void marshall_from_mar_clm_cluster_notification_t ( - SaClmClusterNotificationT *dest, - mar_clm_cluster_notification_t *src) -{ - marshall_from_mar_clm_cluster_node_t (&dest->clusterNode, - &src->cluster_node); - dest->clusterChange = src->cluster_change; -} - -typedef struct { - unsigned long long view_number __attribute__((aligned(8))); - unsigned int number_of_items __attribute__((aligned(8))); - unsigned long long notification __attribute__((aligned(8))); -} mar_clm_cluster_notification_buffer_t; - -static inline void marshall_to_mar_cluster_notification_buffer_t ( - mar_clm_cluster_notification_buffer_t *dest, - SaClmClusterNotificationBufferT *src) -{ - dest->view_number = src->viewNumber; - dest->number_of_items = src->numberOfItems; - memcpy (&dest->notification, &src->notification, - sizeof (SaClmClusterNotificationBufferT *)); -} - -static inline void marshall_from_mar_cluster_notification_buffer_t ( - SaClmClusterNotificationBufferT *dest, - mar_clm_cluster_notification_buffer_t *src) -{ - dest->viewNumber = src->view_number; - dest->numberOfItems = src->number_of_items; - memcpy (&dest->notification, &src->notification, - sizeof (SaClmClusterNotificationBufferT *)); -} - -#endif /* AIS_MAR_CLM_H_DEFINED */ diff --git a/openais/include/mar_evt.h b/openais/include/mar_evt.h deleted file mode 100644 index f1825182..00000000 --- a/openais/include/mar_evt.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2004-2005 Mark Haverkamp - * Copyright (c) 2004-2005 Open Source Development Lab - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the Open Source Developement Lab nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef MAR_EVT_H_DEFINED -#define MAR_EVT_H_DEFINED - -#include - -typedef mar_uint64_t mar_evtchannelhandle_t; - -typedef mar_uint64_t mar_evtsubscriptionid_t; - -typedef mar_uint8_t mar_evteventpriority_t; - -typedef mar_uint64_t mar_evteventid_t; - -typedef mar_uint8_t mar_evtchannelopenflags_t; - -typedef struct { - mar_size_t allocated_size __attribute__((aligned(8))); - mar_size_t pattern_size __attribute__((aligned(8))); - mar_uint8_t *pattern __attribute__((aligned(8))); -} mar_evt_event_pattern_t; - - -typedef struct { - mar_size_t allocated_number __attribute__((aligned(8))); - mar_size_t patterns_number __attribute__((aligned(8))); - mar_evt_event_pattern_t *patterns __attribute__((aligned(8))); -} mar_evt_event_pattern_array_t; - -typedef enum { - MAR_EVT_PREFIX_FILTER = 1, - MAR_EVT_SUFFIX_FILTER = 2, - MAR_EVT_EXACT_FILTER = 3, - MAR_EVT_PASS_ALL_FILTER = 4 -} mar_evt_event_filter_type_t; - -typedef struct { - mar_evt_event_filter_type_t filter_type __attribute__((aligned(8))); - mar_evt_event_pattern_t filter __attribute__((aligned(8))); -} mar_evt_event_filter_t; - -typedef struct { - mar_size_t filters_number __attribute__((aligned(8))); - mar_evt_event_filter_t *filters __attribute__((aligned(8))); -} mar_evt_event_filter_array_t; - -#endif /* MAR_EVT_H_DEFINED */ diff --git a/openais/include/saAis.h b/openais/include/saAis.h deleted file mode 100644 index 5670557e..00000000 --- a/openais/include/saAis.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef AIS_TYPES_H_DEFINED -#define AIS_TYPES_H_DEFINED - -/** - * @defgroup saf Service Availability Forum Application Interface Specification - */ - -typedef enum { - SA_FALSE = 0, - SA_TRUE = 1 -} SaBoolT; - -#ifndef OPENAIS_SOLARIS -#include -#else -#include -#endif - -typedef int8_t SaInt8T; -typedef int16_t SaInt16T; -typedef int32_t SaInt32T; -typedef int64_t SaInt64T; - -typedef uint8_t SaUint8T; -typedef uint16_t SaUint16T; -typedef uint32_t SaUint32T; -typedef uint64_t SaUint64T; - -typedef float SaFloatT; -typedef double SaDoubleT; -typedef char * SaStringT; -typedef SaInt64T SaTimeT; - -#define SA_TIME_END ((SaTimeT)0x7FFFFFFFFFFFFFFFULL) -#define SA_TIME_BEGIN 0x0ULL -#define SA_TIME_UNKNOWN 0x8000000000000000ULL - -#define SA_TIME_ONE_MICROSECOND 1000ULL -#define SA_TIME_ONE_MILLISECOND 1000000ULL -#define SA_TIME_ONE_SECOND 1000000000ULL -#define SA_TIME_ONE_MINUTE 60000000000ULL -#define SA_TIME_ONE_HOUR 3600000000000ULL -#define SA_TIME_ONE_DAY 86400000000000ULL -#define SA_TIME_MAX SA_TIME_END - -#define SA_MAX_NAME_LENGTH 256 - -typedef struct { - SaUint16T length; - SaUint8T value[SA_MAX_NAME_LENGTH]; -} SaNameT; - -typedef struct { - char releaseCode; - unsigned char majorVersion; - unsigned char minorVersion; -} SaVersionT; - -typedef SaUint64T SaNtfIdentifierT; - -#define SA_TRACK_CURRENT 0x01 -#define SA_TRACK_CHANGES 0x02 -#define SA_TRACK_CHANGES_ONLY 0x04 - -typedef enum { - SA_DISPATCH_ONE = 1, - SA_DISPATCH_ALL = 2, - SA_DISPATCH_BLOCKING = 3 -} SaDispatchFlagsT; - -typedef enum { - SA_AIS_OK = 1, - SA_AIS_ERR_LIBRARY = 2, - SA_AIS_ERR_VERSION = 3, - SA_AIS_ERR_INIT = 4, - SA_AIS_ERR_TIMEOUT = 5, - SA_AIS_ERR_TRY_AGAIN = 6, - SA_AIS_ERR_INVALID_PARAM = 7, - SA_AIS_ERR_NO_MEMORY = 8, - SA_AIS_ERR_BAD_HANDLE = 9, - SA_AIS_ERR_BUSY = 10, - SA_AIS_ERR_ACCESS = 11, - SA_AIS_ERR_NOT_EXIST = 12, - SA_AIS_ERR_NAME_TOO_LONG = 13, - SA_AIS_ERR_EXIST = 14, - SA_AIS_ERR_NO_SPACE = 15, - SA_AIS_ERR_INTERRUPT = 16, - SA_AIS_ERR_NAME_NOT_FOUND = 17, - SA_AIS_ERR_NO_RESOURCES = 18, - SA_AIS_ERR_NOT_SUPPORTED = 19, - SA_AIS_ERR_BAD_OPERATION = 20, - SA_AIS_ERR_FAILED_OPERATION = 21, - SA_AIS_ERR_MESSAGE_ERROR = 22, - SA_AIS_ERR_QUEUE_FULL = 23, - SA_AIS_ERR_QUEUE_NOT_AVAILABLE = 24, - SA_AIS_ERR_BAD_FLAGS = 25, - SA_AIS_ERR_TOO_BIG = 26, - SA_AIS_ERR_NO_SECTIONS = 27 -} SaAisErrorT; - -typedef union { - SaInt64T int64Value; - SaUint64T uint64Value; - SaTimeT timeValue; - SaFloatT floatValue; - SaDoubleT doubleValue; -} SaLimitValueT; - -typedef SaUint64T SaSelectionObjectT; - -typedef SaUint64T SaInvocationT; - -typedef SaUint64T SaSizeT; - -#define SA_HANDLE_INVALID 0x0ULL - -#endif /* AIS_TYPES_H_DEFINED */ diff --git a/openais/include/saAmf.h b/openais/include/saAmf.h deleted file mode 100644 index 3c2306a5..00000000 --- a/openais/include/saAmf.h +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef AIS_AMF_H_DEFINED -#define AIS_AMF_H_DEFINED - -#include "saAis.h" - -typedef SaUint64T SaAmfHandleT; - -#define SA_AMF_PM_ZERO_EXIT 0x1 -#define SA_AMF_PM_NON_ZERO_EXIT 0x2 -#define SA_AMF_PM_ABNORMAL_END 0x4 -#define SA_AMF_PM_ALL_ERRORS (SA_AMF_PM_ZERO_EXIT | SA_AMF_PM_NON_ZERO_EXIT | SA_AMF_PM_ABNORMAL_END) - -typedef SaUint32T SaAmfPmErrorsT; - -typedef enum { - SA_AMF_PM_PROC = 1, - SA_AMF_PM_PROC_AND_DESCENDENTS = 2, - SA_AMF_PM_ALL_PROCESSES =3 -} SaAmfPmStopQualifierT; - -typedef enum { - SA_AMF_HEALTHCHECK_AMF_INVOKED = 1, - SA_AMF_HEALTHCHECK_COMPONENT_INVOKED =2 -} SaAmfHealthcheckInvocationT; - -#define SA_AMF_HEALTHCHECK_KEY_MAX 32 -typedef struct { - SaUint8T key[SA_AMF_HEALTHCHECK_KEY_MAX]; - SaUint16T keyLen; -} SaAmfHealthcheckKeyT; - -typedef enum { - SA_AMF_HA_ACTIVE = 1, - SA_AMF_HA_STANDBY = 2, - SA_AMF_HA_QUIESCED = 3, - SA_AMF_HA_QUIESCING = 4 -} SaAmfHAStateT; - -typedef enum { - SA_AMF_READINESS_OUT_OF_SERVICE = 1, - SA_AMF_READINESS_IN_SERVICE = 2, - SA_AMF_READINESS_STOPPING = 3 -} SaAmfReadinessStateT; - -typedef enum { - SA_AMF_PRESENCE_UNINSTANTIATED = 1, - SA_AMF_PRESENCE_INSTANTIATING = 2, - SA_AMF_PRESENCE_INSTANTIATED = 3, - SA_AMF_PRESENCE_TERMINATING = 4, - SA_AMF_PRESENCE_RESTARTING = 5, - SA_AMF_PRESENCE_INSTANTIATION_FAILED = 6, - SA_AMF_PRESENCE_TERMINATION_FAILED = 7 -} SaAmfPresenceStateT; - -typedef enum { - SA_AMF_OPERATIONAL_ENABLED = 1, - SA_AMF_OPERATIONAL_DISABLED = 2 -} SaAmfOperationalStateT; - -typedef enum { - SA_AMF_ADMIN_UNLOCKED = 1, - SA_AMF_ADMIN_LOCKED = 2, - SA_AMF_ADMIN_LOCKED_INSTANTIATION = 3, - SA_AMF_ADMIN_SHUTTING_DOWN = 4 -} SaAmfAdminStateT; - -typedef enum { - SA_AMF_ASSIGNMENT_UNASSIGNED = 1, - SA_AMF_ASSIGNMENT_FULLY_ASSIGNED = 2, - SA_AMF_ASSIGNMENT_PARTIALLY_ASSIGNED = 3 -} SaAmfAssignmentStateT; - -typedef enum { - SA_AMF_PROXY_STATUS_UNPROXIED = 1, - SA_AMF_PROXY_STATUS_PROXIED = 2 -} SaAmfProxyStatusT; - -typedef enum { - SA_AMF_READINESS_STATE = 1, - SA_AMF_HA_STATE = 2, - SA_AMF_PRESENCE_STATE = 3, - SA_AMF_OP_STATE = 4, - SA_AMF_ADMIN_STATE = 5, - SA_AMF_ASSIGNMENT_STATE = 6, - SA_AMF_PROXY_STATUS = 7 -} SaAmfStateT; - -#define SA_AMF_CSI_ADD_ONE 0x1 -#define SA_AMF_CSI_TARGET_ONE 0x2 -#define SA_AMF_CSI_TARGET_ALL 0x4 - -typedef SaUint32T SaAmfCSIFlagsT; - - -typedef enum { - SA_AMF_CSI_NEW_ASSIGN = 1, - SA_AMF_CSI_QUIESCED = 2, - SA_AMF_CSI_NOT_QUIESCED = 3, - SA_AMF_CSI_STILL_ACTIVE = 4, -} SaAmfCSITransitionDescriptorT; - -typedef struct { - SaAmfCSITransitionDescriptorT transitionDescriptor; - SaNameT activeCompName; -} SaAmfCSIActiveDescriptorT; - -typedef struct { - SaNameT activeCompName; - SaUint32T standbyRank; -} SaAmfCSIStandbyDescriptorT; - -typedef union { - SaAmfCSIActiveDescriptorT activeDescriptor; - SaAmfCSIStandbyDescriptorT standbyDescriptor; -} SaAmfCSIStateDescriptorT; - -typedef struct { - SaUint8T *attrName; - SaUint8T *attrValue; - -} SaAmfCSIAttributeT; - -typedef struct { - SaAmfCSIAttributeT *attr; - SaUint32T number; -} SaAmfCSIAttributeListT; - -typedef struct { - SaAmfCSIFlagsT csiFlags; - SaNameT csiName; - SaAmfCSIStateDescriptorT csiStateDescriptor; - SaAmfCSIAttributeListT csiAttr; -} SaAmfCSIDescriptorT; - -typedef struct { - SaNameT compName; - SaAmfHAStateT haState; - SaUint32T rank; -} SaAmfProtectionGroupMemberT; - - -typedef enum { - SA_AMF_PROTECTION_GROUP_NO_CHANGE = 1, - SA_AMF_PROTECTION_GROUP_ADDED = 2, - SA_AMF_PROTECTION_GROUP_REMOVED = 3, - SA_AMF_PROTECTION_GROUP_STATE_CHANGE = 4 -} SaAmfProtectionGroupChangesT; - - -typedef struct { - SaAmfProtectionGroupMemberT member; - SaAmfProtectionGroupChangesT change; -} SaAmfProtectionGroupNotificationT; - -typedef struct { - SaUint32T numberOfItems; - SaAmfProtectionGroupNotificationT *notification; -} SaAmfProtectionGroupNotificationBufferT; - -typedef enum { - SA_AMF_NO_RECOMMENDATION = 1, - SA_AMF_COMPONENT_RESTART = 2, - SA_AMF_COMPONENT_FAILOVER = 3, - SA_AMF_NODE_SWITCHOVER = 4, - SA_AMF_NODE_FAILOVER = 5, - SA_AMF_NODE_FAILFAST = 6, - SA_AMF_CLUSTER_RESET = 7, - SA_AMF_APPLICATION_RESTART = 8 -} SaAmfRecommendedRecoveryT; - -#define SA_AMF_COMP_SA_AWARE 0x0001 -#define SA_AMF_COMP_PROXY 0x0002 -#define SA_AMF_COMP_PROXIED 0x0004 -#define SA_AMF_COMP_LOCAL 0x0008 -typedef SaUint32T saAmfCompCategoryT; - -typedef enum { - SA_AMF_2N_REDUNDANCY_MODEL = 1, - SA_AMF_NPM_REDUNDANCY_MODEL = 2, - SA_AMF_N_WAY_REDUNDANCY_MODEL = 3, - SA_AMF_N_WAY_ACTIVE_REDUNDACY_MODEL = 4, - SA_AMF_NO_REDUNDANCY_MODEL= 5 -} saAmfRedundancyModelT; - -typedef enum { - SA_AMF_COMP_X_ACTIVE_AND_Y_STANDBY = 1, - SA_AMF_COMP_X_ACTIVE_OR_Y_STANDBY = 2, - SA_AMF_COMP_ONE_ACTIVE_OR_Y_STANDBY = 3, - SA_AMF_COMP_ONE_ACTIVE_OR_ONE_STANDBY = 4, - SA_AMF_COMP_X_ACTIVE = 5, - SA_AMF_COMP_1_ACTIVE = 6, - SA_AMF_COMP_NON_PRE_INSTANTIABLE = 7 -} saAmfCompCapabilityModelT; - -typedef enum { - SA_AMF_NODE_NAME = 1, - SA_AMF_SI_NAME = 2 -} SaAmfAdditionalInfoIdT; - -typedef void (*SaAmfHealthcheckCallbackT) ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckKeyT *healthcheckKey); - -typedef void (*SaAmfComponentTerminateCallbackT) ( - SaInvocationT invocation, - const SaNameT *compName); - -typedef void (*SaAmfCSISetCallbackT) ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor); - -typedef void (*SaAmfCSIRemoveCallbackT) ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - SaAmfCSIFlagsT csiFlags); - -typedef void (*SaAmfExternalComponentInstantiateCallbackT) ( - SaInvocationT invocation, - const SaNameT *proxiedCompName); - -typedef void (*SaAmfExternalComponentCleanupCallbackT) ( - SaInvocationT invocation, - const SaNameT *proxiedCompName); - -typedef void (*SaAmfProtectionGroupTrackCallbackT) ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationBufferT *notificationBuffer, - SaUint32T numberOfMembers, - SaAisErrorT error); - -typedef struct { - SaAmfHealthcheckCallbackT - saAmfHealthcheckCallback; - SaAmfComponentTerminateCallbackT - saAmfComponentTerminateCallback; - SaAmfCSISetCallbackT - saAmfCSISetCallback; - SaAmfCSIRemoveCallbackT - saAmfCSIRemoveCallback; - SaAmfProtectionGroupTrackCallbackT - saAmfProtectionGroupTrackCallback; - SaAmfExternalComponentInstantiateCallbackT - saAmfExternalComponentInstantiateCallback; - SaAmfExternalComponentCleanupCallbackT - saAmfExternalComponentCleanupCallback; -} SaAmfCallbacksT; - -/* - * Interfaces - */ -#ifdef __cplusplus -extern "C" { -#endif - -SaAisErrorT -saAmfInitialize ( - SaAmfHandleT *amfHandle, - const SaAmfCallbacksT *amfCallbacks, - SaVersionT *version); - -SaAisErrorT -saAmfSelectionObjectGet ( - SaAmfHandleT amfHandle, - SaSelectionObjectT *selectionObject); - -SaAisErrorT -saAmfDispatch ( - SaAmfHandleT amfHandle, - SaDispatchFlagsT dispatchFlags); - -SaAisErrorT -saAmfFinalize ( - SaAmfHandleT amfHandle); - -SaAisErrorT -saAmfComponentRegister ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaNameT *proxyCompName); - -SaAisErrorT -saAmfComponentUnregister ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaNameT *proxyCompName); - -SaAisErrorT -saAmfComponentNameGet ( - SaAmfHandleT amfHandle, - SaNameT *compName); - -SaAisErrorT -saAmfPmStart ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - SaUint64T processId, - SaInt32T descendentsTreeDepth, - SaAmfPmErrorsT pmErrors, - SaAmfRecommendedRecoveryT recommendedRecovery); - -SaAisErrorT -saAmfPmStop ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - SaAmfPmStopQualifierT stopQualifier, - SaInt64T processId, - SaAmfPmErrorsT pmErrors); - -SaAisErrorT -saAmfHealthcheckStart ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaAmfHealthcheckKeyT *healthcheckKey, - SaAmfHealthcheckInvocationT invocationType, - SaAmfRecommendedRecoveryT recommendedRecovery); - -SaAisErrorT -saAmfHealthcheckConfirm ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaAmfHealthcheckKeyT *healthcheckKey, - SaAisErrorT healthcheckResult); - -SaAisErrorT -saAmfHealthcheckStop ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaAmfHealthcheckKeyT *healthcheckKey); - -SaAisErrorT -saAmfHAStateGet ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaNameT *csiName, - SaAmfHAStateT *haState); - - -SaAisErrorT -saAmfCSIQuiescingComplete( - SaAmfHandleT amfHandle, - SaInvocationT invocation, - SaAisErrorT error); - -SaAisErrorT -saAmfProtectionGroupTrack ( - SaAmfHandleT amfHandle, - const SaNameT *csiName, - SaUint8T trackFlags, - SaAmfProtectionGroupNotificationBufferT *notificationBuffer); - -SaAisErrorT -saAmfProtectionGroupTrackStop ( - SaAmfHandleT amfHandle, - const SaNameT *csiName); - -SaAisErrorT -saAmfComponentErrorReport ( - SaAmfHandleT amfHandle, - const SaNameT *erroneousComponent, - SaTimeT errorDetectionTime, - SaAmfRecommendedRecoveryT recommendedRecovery, - SaNtfIdentifierT ntfIdentifier); - -SaAisErrorT -saAmfComponentErrorClear ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - SaNtfIdentifierT ntfIdentifier); - - -SaAisErrorT -saAmfResponse ( - SaAmfHandleT amfHandle, - SaInvocationT invocation, - SaAisErrorT error); - -#ifdef __cplusplus -} -#endif - -#endif /* AIS_AMF_H_DEFINED */ diff --git a/openais/include/saCkpt.h b/openais/include/saCkpt.h deleted file mode 100644 index b8132185..00000000 --- a/openais/include/saCkpt.h +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SACKPT_H_DEFINED -#define SACKPT_H_DEFINED - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef SaUint64T SaCkptHandleT; - -typedef SaUint64T SaCkptCheckpointHandleT; - -typedef SaUint64T SaCkptSectionIterationHandleT; - -#define SA_CKPT_WR_ALL_REPLICAS 0x01 -#define SA_CKPT_WR_ACTIVE_REPLICA 0x2 -#define SA_CKPT_WR_ACTIVE_REPLICA_WEAK 0x4 -#define SA_CKPT_CHECKPOINT_COLLOCATED 0x8 - -typedef SaUint32T SaCkptCheckpointCreationFlagsT; - -typedef struct { - SaCkptCheckpointCreationFlagsT creationFlags; - SaSizeT checkpointSize; - SaTimeT retentionDuration; - SaUint32T maxSections; - SaSizeT maxSectionSize; - SaSizeT maxSectionIdSize; -} SaCkptCheckpointCreationAttributesT; - -#define SA_CKPT_CHECKPOINT_READ 0x1 -#define SA_CKPT_CHECKPOINT_WRITE 0x2 -#define SA_CKPT_CHECKPOINT_CREATE 0x4 - -typedef SaUint32T SaCkptCheckpointOpenFlagsT; - -#define SA_CKPT_DEFAULT_SECTION_ID { 0, 0 } -#define SA_CKPT_GENERATED_SECTION_ID { 0, 0 } - -typedef struct { - SaUint16T idLen; - SaUint8T *id; -} SaCkptSectionIdT; - -typedef struct { - SaCkptSectionIdT *sectionId; - SaTimeT expirationTime; -} SaCkptSectionCreationAttributesT; - -typedef enum { - SA_CKPT_SECTION_VALID = 1, - SA_CKPT_SECTION_CORRUPTED = 2 -} SaCkptSectionStateT; - -typedef struct { - SaCkptSectionIdT sectionId; - SaTimeT expirationTime; - SaSizeT sectionSize; - SaCkptSectionStateT sectionState; - SaTimeT lastUpdate; -} SaCkptSectionDescriptorT; - -typedef enum { - SA_CKPT_SECTIONS_FOREVER = 1, - SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME = 2, - SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME = 3, - SA_CKPT_SECTIONS_CORRUPTED = 4, - SA_CKPT_SECTIONS_ANY = 5 -} SaCkptSectionsChosenT; - -typedef SaUint64T SaOffsetT; - -typedef struct { - SaCkptSectionIdT sectionId; - void *dataBuffer; - SaSizeT dataSize; - SaOffsetT dataOffset; - SaSizeT readSize; -} SaCkptIOVectorElementT; - -typedef struct { - SaCkptCheckpointCreationAttributesT checkpointCreationAttributes; - SaUint32T numberOfSections; - SaUint32T memoryUsed; -} SaCkptCheckpointDescriptorT; - -typedef void (*SaCkptCheckpointOpenCallbackT) ( - SaInvocationT invocation, - const SaCkptCheckpointHandleT checkpointHandle, - SaAisErrorT error); - -typedef void (*SaCkptCheckpointSynchronizeCallbackT) ( - SaInvocationT invocation, - SaAisErrorT error); - -typedef struct { - SaCkptCheckpointOpenCallbackT saCkptCheckpointOpenCallback; - SaCkptCheckpointSynchronizeCallbackT saCkptCheckpointSynchronizeCallback; -} SaCkptCallbacksT; - - -SaAisErrorT -saCkptInitialize ( - SaCkptHandleT *ckptHandle, - const SaCkptCallbacksT *callbacks, - SaVersionT *version); - -SaAisErrorT -saCkptSelectionObjectGet ( - SaCkptHandleT ckptHandle, - SaSelectionObjectT *selectionObject); - -SaAisErrorT -saCkptDispatch ( - SaCkptHandleT ckptHandle, - SaDispatchFlagsT dispatchFlags); - -SaAisErrorT -saCkptFinalize ( - SaCkptHandleT ckptHandle); - -SaAisErrorT -saCkptCheckpointOpen ( - SaCkptHandleT ckptHandle, - const SaNameT *checkpointName, - const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes, - SaCkptCheckpointOpenFlagsT checkpointOpenFlags, - SaTimeT timeout, - SaCkptCheckpointHandleT *checkpointHandle); - -SaAisErrorT -saCkptCheckpointOpenAsync ( - SaCkptHandleT ckptHandle, - SaInvocationT invocation, - const SaNameT *checkpointName, - const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes, - SaCkptCheckpointOpenFlagsT checkpointOpenFlags); - -SaAisErrorT -saCkptCheckpointClose ( - SaCkptCheckpointHandleT checkpointHandle); - -SaAisErrorT -saCkptCheckpointUnlink ( - SaCkptHandleT ckptHandle, - const SaNameT *checkpointName); - -SaAisErrorT -saCkptCheckpointRetentionDurationSet ( - SaCkptCheckpointHandleT checkpointHandle, - SaTimeT retentionDuration); - -SaAisErrorT -saCkptActiveReplicaSet ( - const SaCkptCheckpointHandleT checkpointHandle); - -SaAisErrorT -saCkptCheckpointStatusGet ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptCheckpointDescriptorT *checkpointStatus); - -SaAisErrorT -saCkptSectionCreate ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptSectionCreationAttributesT *sectionCreationAttributes, - const void *initialData, - SaUint32T initialDataSize); - - -SaAisErrorT -saCkptSectionDelete ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptSectionIdT *sectionId); - -SaAisErrorT -saCkptSectionExpirationTimeSet ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptSectionIdT *sectionId, - SaTimeT expirationTime); - -SaAisErrorT -saCkptSectionIterationInitialize ( - const SaCkptCheckpointHandleT checkpointHandle, - SaCkptSectionsChosenT sectionsChosen, - SaTimeT expirationTime, - SaCkptSectionIterationHandleT *sectionIterationHandle); - -SaAisErrorT -saCkptSectionIterationNext ( - SaCkptSectionIterationHandleT sectionIterationHandle, - SaCkptSectionDescriptorT *sectionDescriptor); - -SaAisErrorT -saCkptSectionIterationFinalize ( - SaCkptSectionIterationHandleT sectionIterationHandle); - -SaAisErrorT -saCkptCheckpointWrite ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptIOVectorElementT *ioVector, - SaUint32T numberOfElements, - SaUint32T *erroneousVectorIndex); - -SaAisErrorT -saCkptSectionOverwrite ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptSectionIdT *secitonId, - const void *dataBuffer, - SaSizeT dataSize); - -SaAisErrorT -saCkptCheckpointRead ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptIOVectorElementT *ioVector, - SaUint32T numberOfElements, - SaUint32T *erroneousVectorIndex); - -SaAisErrorT -saCkptCheckpointSynchronize ( - SaCkptCheckpointHandleT checkpointHandle, - SaTimeT timeout); - -SaAisErrorT -saCkptCheckpointSynchronizeAsync ( - SaCkptCheckpointHandleT checkpointHandle, - SaInvocationT invocation); - -#ifdef __cplusplus -} -#endif - -#endif /* SACKPT_H_DEFINED */ diff --git a/openais/include/saClm.h b/openais/include/saClm.h deleted file mode 100644 index 57dfaeb3..00000000 --- a/openais/include/saClm.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "saAis.h" - -#ifndef AIS_CLM_H_DEFINED -#define AIS_CLM_H_DEFINED - -typedef SaUint64T SaClmHandleT; - -typedef SaUint32T SaClmNodeIdT; - -#define SA_CLM_LOCAL_NODE_ID 0xffffffff - -#define SA_CLM_MAX_ADDRESS_LENGTH 64 - -typedef enum { - SA_CLM_AF_INET = 1, - SA_CLM_AF_INET6 = 2 -} SaClmNodeAddressFamilyT; - -typedef struct { - SaClmNodeAddressFamilyT family; - SaUint16T length; - SaUint8T value[SA_CLM_MAX_ADDRESS_LENGTH]; -} SaClmNodeAddressT; - -typedef struct { - SaClmNodeIdT nodeId; - SaClmNodeAddressT nodeAddress; - SaNameT nodeName; - SaBoolT member; - SaTimeT bootTimestamp; - SaUint64T initialViewNumber; -} SaClmClusterNodeT; - -typedef enum { - SA_CLM_NODE_NO_CHANGE = 1, - SA_CLM_NODE_JOINED = 2, - SA_CLM_NODE_LEFT = 3, - SA_CLM_NODE_RECONFIGURED = 4 -} SaClmClusterChangesT; - -typedef struct { - SaClmClusterNodeT clusterNode; - SaClmClusterChangesT clusterChange; -} SaClmClusterNotificationT; - -typedef struct { - SaUint64T viewNumber; - SaUint32T numberOfItems; - SaClmClusterNotificationT *notification; -} SaClmClusterNotificationBufferT; - -typedef void (*SaClmClusterNodeGetCallbackT)( - SaInvocationT invocation, - const SaClmClusterNodeT *clusterNode, - SaAisErrorT error); - -typedef void (*SaClmClusterTrackCallbackT) ( - const SaClmClusterNotificationBufferT *notificationBuffer, - SaUint32T numberOfMembers, - SaAisErrorT error); - -typedef struct { - SaClmClusterNodeGetCallbackT saClmClusterNodeGetCallback; - SaClmClusterTrackCallbackT saClmClusterTrackCallback; -} SaClmCallbacksT; - -#ifdef __cplusplus -extern "C" { -#endif - -SaAisErrorT -saClmInitialize ( - SaClmHandleT *clmHandle, - const SaClmCallbacksT *clmCallbacks, - SaVersionT *version); - - -SaAisErrorT -saClmSelectionObjectGet ( - SaClmHandleT clmHandle, - SaSelectionObjectT *selectionObject); - -SaAisErrorT -saClmDispatch ( - SaClmHandleT clmHandle, - SaDispatchFlagsT dispatchFlags); - -SaAisErrorT -saClmFinalize ( - SaClmHandleT clmHandle); - -SaAisErrorT -saClmClusterTrack ( - SaClmHandleT clmHandle, - SaUint8T trackFlags, - SaClmClusterNotificationBufferT *notificationBuffer); - -SaAisErrorT -saClmClusterTrackStop ( - SaClmHandleT clmHandle); - -SaAisErrorT -saClmClusterNodeGet ( - SaClmHandleT clmHandle, - SaClmNodeIdT nodeId, - SaTimeT timeout, - SaClmClusterNodeT *clusterNode); - -SaAisErrorT -saClmClusterNodeGetAsync ( - SaClmHandleT clmHandle, - SaInvocationT invocation, - SaClmNodeIdT nodeId); - -#ifdef __cplusplus -} -#endif - -#endif /* AIS_CLM_H_DEFINED */ - - diff --git a/openais/include/saEvt.h b/openais/include/saEvt.h deleted file mode 100644 index adb38adf..00000000 --- a/openais/include/saEvt.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2004-2005 Mark Haverkamp - * Copyright (c) 2004-2005 Open Source Development Lab - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the Open Source Developement Lab nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "saAis.h" - -#ifndef AIS_EVT_H_DEFINED -#define AIS_EVT_H_DEFINED - -typedef SaUint64T SaEvtHandleT; -typedef SaUint64T SaEvtEventHandleT; -typedef SaUint64T SaEvtChannelHandleT; -typedef SaUint32T SaEvtSubscriptionIdT; - - -typedef void -(*SaEvtEventDeliverCallbackT)( - SaEvtSubscriptionIdT subscriptionId, - const SaEvtEventHandleT eventHandle, - const SaSizeT eventDataSize -); - -typedef void -(*SaEvtChannelOpenCallbackT)( - SaInvocationT invocation, - SaEvtChannelHandleT channelHandle, - SaAisErrorT error -); - -typedef struct{ - SaEvtChannelOpenCallbackT saEvtChannelOpenCallback; - SaEvtEventDeliverCallbackT saEvtEventDeliverCallback; -} SaEvtCallbacksT; - -#define SA_EVT_CHANNEL_PUBLISHER 0X1 -#define SA_EVT_CHANNEL_SUBSCRIBER 0X2 -#define SA_EVT_CHANNEL_CREATE 0X4 -typedef SaUint8T SaEvtChannelOpenFlagsT; - -typedef struct { - SaSizeT allocatedSize; - SaSizeT patternSize; - SaUint8T *pattern; -} SaEvtEventPatternT; - - -#define SA_EVT_HIGHEST_PRIORITY 0 -#define SA_EVT_LOWEST_PRIORITY 3 - -/* - * Event ID values from 0 to 1000 are have special meanings - * and aren't used for regular events. - */ - -/* - * Event ID for an allocated but not yet published event. - */ -#define SA_EVT_EVENTID_NONE 0 - -/* - * Event ID for a "lost event". - */ -#define SA_EVT_EVENTID_LOST 1 - -/* - * Pattern to indicate a "lost event" message. - */ -#define SA_EVT_LOST_EVENT "SA_EVT_LOST_EVENT_PATTERN" - -/* - * Size of the biggest data attachment to an event. - */ -#define SA_EVT_DATA_MAX_LEN (64 * 1024) - -typedef struct { - SaSizeT allocatedNumber; - SaSizeT patternsNumber; - SaEvtEventPatternT *patterns; -} SaEvtEventPatternArrayT; - -typedef SaUint8T SaEvtEventPriorityT; -typedef SaUint64T SaEvtEventIdT; - -typedef enum { - SA_EVT_PREFIX_FILTER = 1, - SA_EVT_SUFFIX_FILTER = 2, - SA_EVT_EXACT_FILTER = 3, - SA_EVT_PASS_ALL_FILTER = 4 -} SaEvtEventFilterTypeT; - -typedef struct { - SaEvtEventFilterTypeT filterType; - SaEvtEventPatternT filter; -} SaEvtEventFilterT; - -typedef struct { - SaSizeT filtersNumber; - SaEvtEventFilterT *filters; -} SaEvtEventFilterArrayT; - - -#ifdef __cplusplus -extern "C" { -#endif - -SaAisErrorT -saEvtInitialize( - SaEvtHandleT *evtHandle, - const SaEvtCallbacksT *callbacks, - SaVersionT *version); - -SaAisErrorT -saEvtSelectionObjectGet( - SaEvtHandleT evtHandle, - SaSelectionObjectT *selectionObject); - -SaAisErrorT -saEvtDispatch( - SaEvtHandleT evtHandle, - SaDispatchFlagsT dispatchFlags); - -SaAisErrorT -saEvtFinalize( - SaEvtHandleT evtHandle); - -SaAisErrorT -saEvtChannelOpen( - SaEvtHandleT evtHandle, - const SaNameT *channelName, - SaEvtChannelOpenFlagsT channelOpenFlags, - SaTimeT timeout, - SaEvtChannelHandleT *channelHandle); - -SaAisErrorT -saEvtChannelOpenAsync( - SaEvtHandleT evtHandle, - SaInvocationT invocation, - const SaNameT *channelName, - SaEvtChannelOpenFlagsT channelOpenFlags); - -SaAisErrorT -saEvtChannelClose( - SaEvtChannelHandleT channelHandle); - -SaAisErrorT -saEvtChannelUnlink( - SaEvtHandleT evtHandle, - const SaNameT *channelName); - -SaAisErrorT -saEvtEventAllocate( - SaEvtChannelHandleT channelHandle, - SaEvtEventHandleT *eventHandle); - -SaAisErrorT -saEvtEventFree( - SaEvtEventHandleT eventHandle); - -SaAisErrorT -saEvtEventAttributesSet( - SaEvtEventHandleT eventHandle, - const SaEvtEventPatternArrayT *patternArray, - SaEvtEventPriorityT priority, - SaTimeT retentionTime, - const SaNameT *publisherName); - -SaAisErrorT -saEvtEventAttributesGet( - SaEvtEventHandleT eventHandle, - SaEvtEventPatternArrayT *patternArray, - SaEvtEventPriorityT *priority, - SaTimeT *retentionTime, - SaNameT *publisherName, - SaTimeT *publishTime, - SaEvtEventIdT *eventId); - -SaAisErrorT -saEvtEventDataGet( - SaEvtEventHandleT eventHandle, - void *eventData, - SaSizeT *eventDataSize); - -SaAisErrorT -saEvtEventPublish( - SaEvtEventHandleT eventHandle, - const void *eventData, - SaSizeT eventDataSize, - SaEvtEventIdT *eventId); - -SaAisErrorT -saEvtEventSubscribe( - SaEvtChannelHandleT channelHandle, - const SaEvtEventFilterArrayT *filters, - SaEvtSubscriptionIdT subscriptionId); - -SaAisErrorT -saEvtEventUnsubscribe( - SaEvtChannelHandleT channelHandle, - SaEvtSubscriptionIdT subscriptionId); - -SaAisErrorT -saEvtEventRetentionTimeClear( - SaEvtChannelHandleT channelHandle, - SaEvtEventIdT eventId); - -#ifdef __cplusplus -} -#endif -#endif /* AIS_EVT_H_DEFINED */ diff --git a/openais/include/saLck.h b/openais/include/saLck.h deleted file mode 100644 index cfc90dab..00000000 --- a/openais/include/saLck.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SALCK_H_DEFINED -#define SALCK_H_DEFINED - -#ifdef __cplusplus -extern "C" { -#endif - -typedef SaUint64T SaLckHandleT; - -typedef SaUint64T SaLckLockIdT; - -typedef SaUint64T SaLckResourceHandleT; - -#define SA_LCK_LOCK_NO_QUEUE 0x1 -#define SA_LCK_LOCK_ORPHAN 0x2 - -typedef SaUint32T SaLckLockFlagsT; - -#define SA_LCK_RESOURCE_CREATE 0x1 - -typedef SaUint32T SaLckResourceOpenFlagsT; - -typedef enum { - SA_LCK_LOCK_GRANTED = 1, - SA_LCK_LOCK_DEADLOCK = 2, - SA_LCK_LOCK_NOT_QUEUED = 3, - SA_LCK_LOCK_ORPHANED = 4, - SA_LCK_LOCK_NO_MORE = 5, - SA_LCK_LOCK_DUPLICATE_EX = 6 -} SaLckLockStatusT; - -typedef enum { - SA_LCK_PR_LOCK_MODE = 1, - SA_LCK_EX_LOCK_MODE = 2 -} SaLckLockModeT; - -#define SA_LCK_OPT_ORPHAN_LOCKS 0x1 -#define SA_LCK_OPT_DEADLOCK_DETECTION 0x2 - -typedef SaUint32T SaLckOptionsT; - -typedef SaUint64T SaLckWaiterSignalT; - -typedef void (*SaLckResourceOpenCallbackT) ( - SaInvocationT invocation, - SaLckResourceHandleT lockResourceHandle, - SaAisErrorT error); - -typedef void (*SaLckLockGrantcallbackT) ( - SaInvocationT invocation, - SaLckLockStatusT lockStatus, - SaAisErrorT error); - -typedef void (*SaLckLockWaiterCallbackT) ( - SaLckWaiterSignalT waiterSignal, - SaLckLockIdT lockId, - SaLckLockModeT modeHeld, - SaLckLockModeT modeRequested); - -typedef void (*SaLckResourceUnlockCallbackT) ( - SaInvocationT invocation, - SaAisErrorT error); - -typedef struct { - SaLckResourceOpenCallbackT saLckResourceOpenCallback; - SaLckLockGrantcallbackT saLckLockGrantCallback; - SaLckLockWaiterCallbackT saLckLockWaiterCallback; - SaLckResourceUnlockCallbackT saLckResourceUnlockCallback; -} SaLckCallbacksT; - -SaAisErrorT -saLckInitialize ( - SaLckHandleT *lckHandle, - const SaLckCallbacksT *lckCallbacks, - SaVersionT *version); - -SaAisErrorT -saLckSelectionObjectGet ( - SaLckHandleT lckHandle, - SaSelectionObjectT *selectionObject); - -SaAisErrorT -saLckOptionCheck ( - SaLckHandleT lckHandle, - SaLckOptionsT *lckOptions); - -SaAisErrorT -saLckDispatch ( - SaLckHandleT lckHandle, - SaDispatchFlagsT dispatchFlags); - -SaAisErrorT -saLckFinalize ( - SaLckHandleT lckHandle); - -SaAisErrorT -saLckResourceOpen ( - SaLckHandleT lckHandle, - const SaNameT *lockResourceName, - SaLckResourceOpenFlagsT resourceFlags, - SaTimeT timeout, - SaLckResourceHandleT *lockResourceHandle); - -SaAisErrorT -saLckResourceOpenAsync ( - SaLckHandleT lckHandle, - SaInvocationT invocation, - const SaNameT *lockResourceName, - SaLckResourceOpenFlagsT resourceFlags); - -SaAisErrorT -saLckResourceClose ( - SaLckResourceHandleT lockResourceHandle); - -SaAisErrorT -saLckResourceLock ( - SaLckResourceHandleT lockResourceHandle, - SaLckLockIdT *lockId, - SaLckLockModeT lockMode, - SaLckLockFlagsT lockFlags, - SaLckWaiterSignalT waiterSignal, - SaTimeT timeout, - SaLckLockStatusT *lockStatus); - -SaAisErrorT -saLckResourceLockAsync ( - SaLckResourceHandleT lockResourceHandle, - SaInvocationT invocation, - SaLckLockIdT *lockId, - SaLckLockModeT lockMode, - SaLckLockFlagsT lockFlags, - SaLckWaiterSignalT waiterSignal); - -SaAisErrorT -saLckResourceUnlock ( - SaLckLockIdT lockId, - SaTimeT timeout); - -SaAisErrorT -saLckResourceUnlockAsync ( - SaInvocationT invocation, - SaLckLockIdT lockId); - -SaAisErrorT -saLckLockPurge ( - SaLckResourceHandleT lockResourceHandle); - -#endif /* SALCK_H_DEFINED */ diff --git a/openais/include/saMsg.h b/openais/include/saMsg.h deleted file mode 100644 index abf0ce42..00000000 --- a/openais/include/saMsg.h +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SAMSG_H_DEFINED -#define SAMSG_H_DEFINED - -#ifdef __cplusplus -extern "C" { -#endif - -typedef SaUint64T SaMsgHandleT; - -typedef SaUint64T SaMsgQueueHandleT; - -typedef SaUint64T SaMsgSenderIdT; - -#define SA_MSG_MESSAGE_DELIVERED_ACK 0x1 - -typedef SaUint32T SaMsgAckFlagsT; - -#define SA_MSG_QUEUE_PERSISTENT 0x1 - -typedef SaUint32T SaMsgQueueCreationFlagsT; - -#define SA_MSG_MESSAGE_HIGHEST_PRIORITY 0 -#define SA_MSG_MESSAGE_LOWEST_PRIORITY 3 - -typedef struct { - SaMsgQueueCreationFlagsT creationFlags; - SaSizeT size[SA_MSG_MESSAGE_LOWEST_PRIORITY + 1]; - SaTimeT retentionTime; -} SaMsgQueueCreationAttributesT; - -typedef enum { - SA_MSG_QUEUE_GROUP_ROUND_ROBIN = 1, - SA_MSG_QUEUE_GROUP_LOCAL_ROUND_ROBIN = 2, - SA_MSG_QUEUE_GROUP_LOCAL_BEST_QUEUE = 3, - SA_MSG_QUEUE_GROUP_BROADCAST = 4 -} SaMsgQueueGroupPolicyT; - -#define SA_MSG_QUEUE_CREATE 0x1 -#define SA_MSG_QUEUE_RECEIVE_CALLBACK 0x2 -#define SA_MSG_QUEUE_EMPTY 0x4 - -typedef SaUint32T SaMsgQueueOpenFlagsT; - -typedef struct { - SaSizeT queueSize; - SaSizeT queueUsed; - SaUint32T numberOfMessages; -} SaMsgQueueUsageT; - -typedef struct { - SaMsgQueueCreationFlagsT creationFlags; - SaTimeT retentionTime; - SaTimeT closeTime; - SaMsgQueueUsageT saMsgQueueUsage[SA_MSG_MESSAGE_LOWEST_PRIORITY + 1]; -} SaMsgQueueStatusT; - -typedef enum { - SA_MSG_QUEUE_GROUP_NO_CHANGE = 1, - SA_MSG_QUEUE_GROUP_ADDED = 2, - SA_MSG_QUEUE_GROUP_REMOVED = 3, - SA_MSG_QUEUE_GROUP_STATE_CHANGED = 4 -} SaMsgQueueGroupChangesT; - -typedef struct { - SaNameT queueName; -} SaMsgQueueGroupMemberT; - -typedef struct { - SaMsgQueueGroupMemberT member; - SaMsgQueueGroupChangesT change; -} SaMsgQueueGroupNotificationT; - -typedef struct { - SaUint32T numberOfItems; - SaMsgQueueGroupNotificationT *notification; - SaMsgQueueGroupPolicyT queueGroupPolicy; -} SaMsgQueueGroupNotificationBufferT; - -typedef struct { - SaUint32T type; - SaUint32T version; - SaSizeT size; - SaNameT *senderName; - void *data; - SaUint8T priority; -} SaMsgMessageT; - -typedef void (*SaMsgQueueOpenCallbackT) ( - SaInvocationT invocation, - SaMsgQueueHandleT queueHandle, - SaAisErrorT error); - -typedef void (*SaMsgQueueGroupTrackCallbackT) ( - const SaNameT *queueGroupName, - const SaMsgQueueGroupNotificationBufferT *notificationBuffer, - SaUint32T numberOfMembers, - SaAisErrorT error); - -typedef void (*SaMsgMessageDeliveredCallbackT) ( - SaInvocationT invocation, - SaAisErrorT error); - -typedef void (*SaMsgMessageReceivedCallbackT) ( - SaMsgQueueHandleT queueHandle); - -typedef struct { - SaMsgQueueOpenCallbackT saMsgQueueOpenCallback; - SaMsgQueueGroupTrackCallbackT saMsgQueueGroupTrackCallback; - SaMsgMessageDeliveredCallbackT saMsgMessageDeliveredCallback; - SaMsgMessageReceivedCallbackT saMsgMessageReceivedCallback; -} SaMsgCallbacksT; - -typedef enum { - SA_MSG_QUEUE_CAPACITY_REACHED = 1, - SA_MSG_QUEUE_CAPACITY_AVAILABLE = 2, - SA_MSG_QUEUE_GROUP_CAPACITY_REACHED = 3, - SA_MSG_QUEUE_GROUP_CAPACITY_AVAILABLE = 4 -} SaMsgMessageCapacityStatusT; - -typedef struct { - SaSizeT capacityReached[SA_MSG_MESSAGE_LOWEST_PRIORITY + 1]; - SaSizeT capacityAvailable[SA_MSG_MESSAGE_LOWEST_PRIORITY + 1]; -} SaMsgQueueThresholdsT; - -typedef enum { - SA_MSG_DEST_CAPACITY_STATUS = 1 -} SaMsgStateT; - -typedef enum { - SA_MSG_MAX_PRIORITY_AREA_SIZE_ID = 1, - SA_MSG_MAX_QUEUE_SIZE_ID = 2, - SA_MSG_MAX_NUM_QUEUES_ID = 3, - SA_MSG_MAX_NUM_QUEUE_GROUPS_ID = 4, - SA_MSG_MAX_NUM_QUEUES_PER_GROUP_ID = 5, - SA_MSG_MAX_MESSAGE_SIZE_ID = 6, - SA_MSG_MAX_REPLY_SIZE_ID = 7 -} SaMsgLimitIdT; - -SaAisErrorT -saMsgInitialize ( - SaMsgHandleT *msgHandle, - const SaMsgCallbacksT *msgCallbacks, - SaVersionT *version); - -SaAisErrorT -saMsgSelectionObjectGet ( - SaMsgHandleT msgHandle, - SaSelectionObjectT *selectionObject); - -SaAisErrorT -saMsgDispatch ( - SaMsgHandleT msgHandle, - SaDispatchFlagsT dispatchFlags); - -SaAisErrorT -saMsgFinalize ( - SaMsgHandleT msgHandle); - -SaAisErrorT -saMsgQueueOpen ( - SaMsgHandleT msgHandle, - const SaNameT *queueName, - const SaMsgQueueCreationAttributesT *creationAttributes, - SaMsgQueueOpenFlagsT openFlags, - SaTimeT timeout, - SaMsgQueueHandleT *queueHandle); - -SaAisErrorT -saMsgQueueOpenAsync ( - SaMsgHandleT msgHandle, - SaInvocationT invocation, - const SaNameT *queueName, - const SaMsgQueueCreationAttributesT *creationAttributes, - SaMsgQueueOpenFlagsT openFlags); - -SaAisErrorT -saMsgQueueClose ( - SaMsgQueueHandleT msgHandle); - -SaAisErrorT -saMsgQueueStatusGet ( - SaMsgHandleT msgHandle, - const SaNameT *queueName, - SaMsgQueueStatusT *queueStatus); - -SaAisErrorT -saMsgQueueRetentionTimeSet ( - SaMsgQueueHandleT queueHandle, - SaTimeT *retentionTime); - -SaAisErrorT -saMsgQueueUnlink ( - SaMsgQueueHandleT msgHandle, - const SaNameT *queueName); - -SaAisErrorT -saMsgQueueGroupCreate ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - SaMsgQueueGroupPolicyT queueGroupPolicy); - -SaAisErrorT -saMsgQueueGroupInsert ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - const SaNameT *queueName); - -SaAisErrorT -saMsgQueueGroupRemove ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - const SaNameT *queueName); - -SaAisErrorT -saMsgQueueGroupDelete ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName); - -SaAisErrorT -saMsgQueueGroupTrack ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - SaUint8T trackFlags, - SaMsgQueueGroupNotificationBufferT *notificationBuffer); - -SaAisErrorT -saMsgQueueGroupTrackStop ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName); - -SaAisErrorT -saMsgQueueGroupNotificationFree ( - SaMsgHandleT msgHandle, - SaMsgQueueGroupNotificationT *notification); - -SaAisErrorT -saMsgMessageSend ( - SaMsgHandleT msgHandle, - const SaNameT *destination, - const SaMsgMessageT *message, - SaTimeT timeout); - -SaAisErrorT -saMsgMessageSendAsync ( - SaMsgHandleT msgHandle, - SaInvocationT invocation, - const SaNameT *destination, - const SaMsgMessageT *message, - SaMsgAckFlagsT ackFlags); - -SaAisErrorT -saMsgMessageGet ( - SaMsgQueueHandleT queueHandle, - SaMsgMessageT *message, - SaTimeT *sendTIme, - SaMsgSenderIdT *senderId, - SaTimeT timeout); - -SaAisErrorT -saMsgMessageDataFree ( - SaMsgHandleT msgHandle, - void *data); - -SaAisErrorT -saMsgMessageCancel ( - SaMsgQueueHandleT queueHandle); - -SaAisErrorT -saMsgMessageSendReceive ( - SaMsgHandleT msgHandle, - const SaNameT *destination, - const SaMsgMessageT *sendMessage, - SaMsgMessageT *receiveMessage, - SaTimeT *replySendTime, - SaTimeT timeout); - -SaAisErrorT -saMsgMessageReply ( - SaMsgHandleT msgHandle, - const SaMsgMessageT *replyMessage, - const SaMsgSenderIdT *senderId, - SaTimeT timeout); - -SaAisErrorT -saMsgMessageReplyAsync ( - SaMsgHandleT msgHandle, - SaInvocationT invocation, - const SaMsgMessageT *replyMessage, - const SaMsgSenderIdT *senderId, - SaMsgAckFlagsT ackFlags); - -SaAisErrorT -saMsgQueueCapacityThresholdSet ( - SaMsgQueueHandleT queueHandle, - const SaMsgQueueThresholdsT *thresholds); - -SaAisErrorT -saMsgQueueCapacityThresholdGet ( - SaMsgQueueHandleT queueHandle, - SaMsgQueueThresholdsT *thresholds); - -SaAisErrorT -saMsgMetadataSizeGet ( - SaMsgHandleT msgHandle, - SaUint32T *metadataSize); - -SaAisErrorT -saMsgLimitGet ( - SaMsgHandleT msgHandle, - SaMsgLimitIdT limitId, - SaLimitValueT *limitValue); - -#endif /* SAMSG_H_DEFINED */ diff --git a/openais/lib/Makefile b/openais/lib/Makefile deleted file mode 100644 index de555316..00000000 --- a/openais/lib/Makefile +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright (c) 2002-2005 MontaVista Software, Inc. -# Copyright (c) 2006-2008 Red Hat, Inc. -# -# 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 -# modification, are permitted provided that the following conditions are met: -# -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# - Neither the name of the MontaVista Software, Inc. nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -# Include configuration -# -srcdir ?= $(CURDIR)/../ - -include $(srcdir)Makefile.inc - - -override CFLAGS += -I$(srcdir)include -override LDFLAGS += -L./ - -all: libSaClm.a libSaClm.so.2.0.0 \ - libSaCkpt.a libSaCkpt.so.2.0.0 \ - libSaEvt.a libSaEvt.so.2.0.0 \ - libSaMsg.a libSaMsg.so.2.0.0 \ - libSaLck.a libSaLck.so.2.0.0 - -libcoroutil.a: util.o - $(AR) -rc libcoroutil.a util.o - -ifeq (${OPENAIS_COMPAT}, DARWIN) - -DARWIN_OPTS=-dynamiclib -bind_at_load -current_version 2.0.0 -compatibility_version 2.0.0 - -libSaClm.so.2.0.0: util.o clm.o - $(CC) $(DARWIN_OPTS) util.o clm.o -o $@ - -libSaCkpt.so.2.0.0: util.o ckpt.o - $(CC) $(LDFLAGS) $(DARWIN_OPTS) util.o ckpt.o -o $@ - -libSaEvt.so.2.0.0: util.o evt.o sa-evt.o - $(CC) $(LDFLAGS) $(DARWIN_OPTS) util.o evt.o - -libSaMsg.so.2.0.0: util.o msg.o - $(CC) $(DARWIN_OPTS) util.o msg.o -o $@ - -libSaLck.so.2.0.0: util.o lck.o - $(CC) $(DARWIN_OPTS) util.o lck.o -o $@ - -else - -libSaClm.so.2.0.0: util.o clm.o - $(CC) -shared -Wl,-soname,libclm.so.2,-version-script=libSaClm.versions util.o clm.o -o $@ - -libSaCkpt.so.2.0.0: util.o ckpt.o - $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaCkpt.so.2,-version-script=libSaCkpt.versions util.o ckpt.o -o $@ - -libSaEvt.so.2.0.0: util.o evt.o - $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaEvt.so.2,-version-script=libSaEvt.versions util.o evt.o - -libSaMsg.so.2.0.0: util.o msg.o - $(CC) -shared -Wl,-soname,libmsg.so.2,-version-script=libSaMsg.versions util.o msg.o -o $@ - -libSaLck.so.2.0.0: util.o lck.o - $(CC) -shared -Wl,-soname,libSaLck.so.2,-version-script=libSaLck.versions util.o lck.o -o $@ - -endif - -libSaCkpt.a: util.o ckpt.o - $(AR) -rc libSaCkpt.a util.o ckpt.o - -libSaClm.a: util.o clm.o - $(AR) -rc libSaClm.a util.o clm.o - -libSaEvt.a: util.o evt.o - $(AR) -rc libSaEvt.a util.o evt.o - -libSaMsg.a: util.o msg.o - $(AR) -rc libSaMsg.a util.o msg.o - -libSaLck.a: util.o lck.o - $(AR) -rc libSaLck.a util.o lck.o - -clean: - rm -f *.o libSa*.so.* libSa*.a *.da *.bb *.bbg - -# -fPIC rules required for all libraries -%.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $< - -depend: - makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(LIBAIS_SRC) > /dev/null 2>&1 diff --git a/openais/lib/amf.c b/openais/lib/amf.c deleted file mode 100644 index cf2d6fe6..00000000 --- a/openais/lib/amf.c +++ /dev/null @@ -1,1062 +0,0 @@ - -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -struct res_overlay { - mar_res_header_t header __attribute__((aligned(8))); - char data[4096]; -}; - -/* - * Data structure for instance data - */ -struct amfInstance { - int response_fd; - int dispatch_fd; - SaAmfCallbacksT callbacks; - SaNameT compName; - int compRegistered; - int finalize; - pthread_mutex_t response_mutex; - pthread_mutex_t dispatch_mutex; -}; - -static void amfHandleInstanceDestructor (void *); - -/* - * All instances in one database - */ -static struct saHandleDatabase amfHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = amfHandleInstanceDestructor -}; - -/* - * Versions supported - */ -static SaVersionT amfVersionsSupported[] = { - { 'B', 1, 1 } -}; - -static struct saVersionDatabase amfVersionDatabase = { - sizeof (amfVersionsSupported) / sizeof (SaVersionT), - amfVersionsSupported -}; - -/* - * Implementation - */ - -void amfHandleInstanceDestructor (void *instance) -{ - struct amfInstance *amfInstance = instance; - - pthread_mutex_destroy (&amfInstance->response_mutex); - pthread_mutex_destroy (&amfInstance->dispatch_mutex); -} - -SaAisErrorT -saAmfInitialize ( - SaAmfHandleT *amfHandle, - const SaAmfCallbacksT *amfCallbacks, - SaVersionT *version) -{ - struct amfInstance *amfInstance; - SaAisErrorT error = SA_AIS_OK; - - error = saVersionVerify (&amfVersionDatabase, (SaVersionT *)version); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleCreate (&amfHandleDatabase, sizeof (struct amfInstance), amfHandle); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleInstanceGet (&amfHandleDatabase, *amfHandle, (void *)&amfInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - amfInstance->response_fd = -1; - - amfInstance->dispatch_fd = -1; - - error = saServiceConnect (&amfInstance->response_fd, - &amfInstance->dispatch_fd, AMF_SERVICE); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - memcpy (&amfInstance->callbacks, amfCallbacks, sizeof (SaAmfCallbacksT)); - - pthread_mutex_init (&amfInstance->response_mutex, NULL); - - pthread_mutex_init (&amfInstance->dispatch_mutex, NULL); - - saHandleInstancePut (&amfHandleDatabase, *amfHandle); - - return (SA_AIS_OK); - -error_put_destroy: - saHandleInstancePut (&amfHandleDatabase, *amfHandle); -error_destroy: - saHandleDestroy (&amfHandleDatabase, *amfHandle); -error_no_destroy: - return (error); -} - -SaAisErrorT -saAmfSelectionObjectGet ( - SaAmfHandleT amfHandle, - SaSelectionObjectT *selectionObject) -{ - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - *selectionObject = amfInstance->dispatch_fd; - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - return (SA_AIS_OK); -} - - -SaAisErrorT -saAmfDispatch ( - SaAmfHandleT amfHandle, - SaDispatchFlagsT dispatchFlags) -{ - struct pollfd ufds; - int timeout = -1; - SaAisErrorT error; - int cont = 1; /* always continue do loop except when set to 0 */ - int dispatch_avail; - struct amfInstance *amfInstance; - struct res_lib_amf_csisetcallback *res_lib_amf_csisetcallback; - - struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback; - struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback; - struct res_lib_amf_componentterminatecallback *res_lib_amf_componentterminatecallback; - SaAmfCallbacksT callbacks; - struct res_overlay dispatch_data; - - if (dispatchFlags != SA_DISPATCH_ONE && - dispatchFlags != SA_DISPATCH_ALL && - dispatchFlags != SA_DISPATCH_BLOCKING) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* - * Timeout instantly for SA_DISPATCH_ALL - */ - if (dispatchFlags == SA_DISPATCH_ALL) { - timeout = 0; - } - - do { - /* - * Read data directly from socket - */ - ufds.fd = amfInstance->dispatch_fd; - ufds.events = POLLIN; - ufds.revents = 0; - - error = saPollRetry (&ufds, 1, timeout); - if (error != SA_AIS_OK) { - goto error_put; - } - - pthread_mutex_lock (&amfInstance->dispatch_mutex); - - /* - * Handle has been finalized in another thread - */ - if (amfInstance->finalize == 1) { - error = SA_AIS_OK; - goto error_unlock; - } - - if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_unlock; - } - - dispatch_avail = ufds.revents & POLLIN; - if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) { - pthread_mutex_unlock (&amfInstance->dispatch_mutex); - break; /* exit do while cont is 1 loop */ - } else - if (dispatch_avail == 0) { - pthread_mutex_unlock (&amfInstance->dispatch_mutex); - continue; /* next poll */ - } - - if (ufds.revents & POLLIN) { - /* - * Queue empty, read response from socket - */ - error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.header, - sizeof (mar_res_header_t)); - - if (error != SA_AIS_OK) { - - goto error_unlock; - } - if (dispatch_data.header.size > sizeof (mar_res_header_t)) { - - error = saRecvRetry (amfInstance->dispatch_fd, &dispatch_data.data, - dispatch_data.header.size - sizeof (mar_res_header_t)); - - if (error != SA_AIS_OK) { - - goto error_unlock; - } - } - } else { - pthread_mutex_unlock (&amfInstance->dispatch_mutex); - - continue; - } - - /* - * Make copy of callbacks, message data, unlock instance, and call callback - * A risk of this dispatch method is that the callback routines may - * operate at the same time that amfFinalize has been called in another thread. - */ - - memcpy (&callbacks, &amfInstance->callbacks, sizeof (SaAmfCallbacksT)); - pthread_mutex_unlock (&amfInstance->dispatch_mutex); - - /* - * Dispatch incoming response - */ - - switch (dispatch_data.header.id) { - - case MESSAGE_RES_AMF_HEALTHCHECKCALLBACK: - res_lib_amf_healthcheckcallback = (struct res_lib_amf_healthcheckcallback *)&dispatch_data; - - callbacks.saAmfHealthcheckCallback ( - res_lib_amf_healthcheckcallback->invocation, - &res_lib_amf_healthcheckcallback->compName, - &res_lib_amf_healthcheckcallback->key); - break; - - case MESSAGE_RES_AMF_CSISETCALLBACK: - { - SaAmfCSIDescriptorT csi_descriptor; - SaAmfCSIAttributeT *csi_attribute_array; - char *attr_buf; - int i; - - res_lib_amf_csisetcallback = (struct res_lib_amf_csisetcallback *)&dispatch_data; - - - csi_descriptor.csiFlags = res_lib_amf_csisetcallback->csiFlags; - memcpy(&csi_descriptor.csiName, &res_lib_amf_csisetcallback->csiName, - sizeof(SaNameT)); - csi_descriptor.csiStateDescriptor = res_lib_amf_csisetcallback->csiStateDescriptor; - csi_descriptor.csiAttr.number = res_lib_amf_csisetcallback->number; - - csi_attribute_array = malloc (sizeof (SaAmfCSIAttributeT) * - csi_descriptor.csiAttr.number); - - if (csi_attribute_array == 0) { - return SA_AIS_ERR_LIBRARY; - } - csi_descriptor.csiAttr.attr = csi_attribute_array; - - attr_buf = res_lib_amf_csisetcallback->csi_attr_buf; - - for (i = 0; i < csi_descriptor.csiAttr.number; i++) { - csi_attribute_array[i].attrName = (SaUint8T*)attr_buf; - - attr_buf += strlen(attr_buf) + 1; - csi_attribute_array[i].attrValue = (SaUint8T*)attr_buf; - - attr_buf += strlen(attr_buf) + 1; - } - - callbacks.saAmfCSISetCallback ( - res_lib_amf_csisetcallback->invocation, - &res_lib_amf_csisetcallback->compName, - res_lib_amf_csisetcallback->haState, - &csi_descriptor); - - if (csi_attribute_array != NULL) { - free(csi_attribute_array); - } - break; - } - case MESSAGE_RES_AMF_CSIREMOVECALLBACK: - res_lib_amf_csiremovecallback = (struct res_lib_amf_csiremovecallback *)&dispatch_data; - callbacks.saAmfCSIRemoveCallback ( - res_lib_amf_csiremovecallback->invocation, - &res_lib_amf_csiremovecallback->compName, - &res_lib_amf_csiremovecallback->csiName, - res_lib_amf_csiremovecallback->csiFlags); - break; - - case MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK: - res_lib_amf_componentterminatecallback = (struct res_lib_amf_componentterminatecallback *)&dispatch_data; - callbacks.saAmfComponentTerminateCallback ( - res_lib_amf_componentterminatecallback->invocation, - &res_lib_amf_componentterminatecallback->compName); - break; - -#ifdef COMPILE_OUT - case MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK: - res_lib_amf_protectiongrouptrackcallback = (struct res_lib_amf_protectiongrouptrackcallback *)&dispatch_data; - memcpy (res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress, - res_lib_amf_protectiongrouptrackcallback->notificationBuffer, - res_lib_amf_protectiongrouptrackcallback->numberOfItems * sizeof (SaAmfProtectionGroupNotificationT)); - callbacks.saAmfProtectionGroupTrackCallback( - &res_lib_amf_protectiongrouptrackcallback->csiName, - res_lib_amf_protectiongrouptrackcallback->notificationBufferAddress, - res_lib_amf_protectiongrouptrackcallback->numberOfItems, - res_lib_amf_protectiongrouptrackcallback->numberOfMembers, - res_lib_amf_protectiongrouptrackcallback->error); -#endif - break; - default: - error = SA_AIS_ERR_LIBRARY; - goto error_put; - break; - } - - /* - * Determine if more messages should be processed - */ - switch (dispatchFlags) { - case SA_DISPATCH_ONE: - cont = 0; - break; - case SA_DISPATCH_ALL: - break; - case SA_DISPATCH_BLOCKING: - break; - } - } while (cont); - -error_unlock: - pthread_mutex_unlock (&amfInstance->dispatch_mutex); -error_put: - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error); -} - -SaAisErrorT -saAmfFinalize ( - SaAmfHandleT amfHandle) -{ - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&amfInstance->dispatch_mutex); - - pthread_mutex_lock (&amfInstance->response_mutex); - - /* - * Another thread has already started finalizing - */ - if (amfInstance->finalize) { - pthread_mutex_unlock (&amfInstance->response_mutex); - pthread_mutex_unlock (&amfInstance->dispatch_mutex); - saHandleInstancePut (&amfHandleDatabase, amfHandle); - return (SA_AIS_ERR_BAD_HANDLE); - } - - amfInstance->finalize = 1; - - pthread_mutex_unlock (&amfInstance->response_mutex); - - pthread_mutex_unlock (&amfInstance->dispatch_mutex); - - saHandleDestroy (&amfHandleDatabase, amfHandle); - - if (amfInstance->response_fd != -1) { - shutdown (amfInstance->response_fd, 0); - close (amfInstance->response_fd); - } - if (amfInstance->dispatch_fd != -1) { - shutdown (amfInstance->dispatch_fd, 0); - close (amfInstance->dispatch_fd); - } - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error); -} - -SaAisErrorT -saAmfComponentRegister ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaNameT *proxyCompName) -{ - struct amfInstance *amfInstance; - SaAisErrorT error; - struct req_lib_amf_componentregister req_lib_amf_componentregister; - struct res_lib_amf_componentregister res_lib_amf_componentregister; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_componentregister.header.size = sizeof (struct req_lib_amf_componentregister); - req_lib_amf_componentregister.header.id = MESSAGE_REQ_AMF_COMPONENTREGISTER; - memcpy (&req_lib_amf_componentregister.compName, compName, - sizeof (SaNameT)); - if (proxyCompName) { - memcpy (&req_lib_amf_componentregister.proxyCompName, - proxyCompName, sizeof (SaNameT)); - } else { - memset (&req_lib_amf_componentregister.proxyCompName, 0, - sizeof (SaNameT)); - } - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_componentregister, - sizeof (struct req_lib_amf_componentregister), - &res_lib_amf_componentregister, - sizeof (struct res_lib_amf_componentregister)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - if (res_lib_amf_componentregister.header.error == SA_AIS_OK) { - amfInstance->compRegistered = 1; - memcpy (&amfInstance->compName, compName, sizeof (SaNameT)); - } - return (error == SA_AIS_OK ? res_lib_amf_componentregister.header.error : error); -} - -SaAisErrorT -saAmfComponentUnregister ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaNameT *proxyCompName) -{ - struct req_lib_amf_componentunregister req_lib_amf_componentunregister; - struct res_lib_amf_componentunregister res_lib_amf_componentunregister; - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_componentunregister.header.size = sizeof (struct req_lib_amf_componentunregister); - req_lib_amf_componentunregister.header.id = MESSAGE_REQ_AMF_COMPONENTUNREGISTER; - memcpy (&req_lib_amf_componentunregister.compName, compName, - sizeof (SaNameT)); - if (proxyCompName) { - memcpy (&req_lib_amf_componentunregister.proxyCompName, - proxyCompName, sizeof (SaNameT)); - } else { - memset (&req_lib_amf_componentunregister.proxyCompName, 0, - sizeof (SaNameT)); - } - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_componentunregister, - sizeof (struct req_lib_amf_componentunregister), - &res_lib_amf_componentunregister, - sizeof (struct res_lib_amf_componentunregister)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_componentunregister.header.error : error); -} - -SaAisErrorT -saAmfComponentNameGet ( - SaAmfHandleT amfHandle, - SaNameT *compName) -{ - struct amfInstance *amfInstance; - SaAisErrorT error; - char *env_value; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = SA_AIS_OK; - - env_value = getenv ("SA_AMF_COMPONENT_NAME"); - if (env_value == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - strncpy ((char *)compName->value, env_value, SA_MAX_NAME_LENGTH-1); - compName->value[SA_MAX_NAME_LENGTH-1] = '\0'; - compName->length = strlen (env_value); - -error_exit: - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error); -} - -SaAisErrorT -saAmfPmStart ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - SaUint64T processId, - SaInt32T descendentsTreeDepth, - SaAmfPmErrorsT pmErrors, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct req_lib_amf_pmstart req_lib_amf_pmstart; - struct res_lib_amf_pmstart res_lib_amf_pmstart; - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_pmstart.header.size = sizeof (struct req_lib_amf_pmstart); - req_lib_amf_pmstart.header.id = MESSAGE_REQ_AMF_PMSTART; - memcpy (&req_lib_amf_pmstart.compName, compName, - sizeof (SaNameT)); - req_lib_amf_pmstart.processId = processId; - req_lib_amf_pmstart.descendentsTreeDepth = descendentsTreeDepth; - req_lib_amf_pmstart.pmErrors = pmErrors; - req_lib_amf_pmstart.recommendedRecovery = recommendedRecovery; - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_pmstart, - sizeof (struct req_lib_amf_pmstart), - &res_lib_amf_pmstart, - sizeof (struct res_lib_amf_pmstart)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_pmstart.header.error : error); -} - -SaAisErrorT -saAmfPmStop ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - SaAmfPmStopQualifierT stopQualifier, - SaInt64T processId, - SaAmfPmErrorsT pmErrors) -{ - struct req_lib_amf_pmstop req_lib_amf_pmstop; - struct res_lib_amf_pmstop res_lib_amf_pmstop; - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_pmstop.header.size = sizeof (struct req_lib_amf_pmstop); - req_lib_amf_pmstop.header.id = MESSAGE_REQ_AMF_PMSTOP; - memcpy (&req_lib_amf_pmstop.compName, compName, sizeof (SaNameT)); - req_lib_amf_pmstop.stopQualifier = stopQualifier; - req_lib_amf_pmstop.processId = processId; - req_lib_amf_pmstop.pmErrors = pmErrors; - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_pmstop, - sizeof (struct req_lib_amf_pmstop), - &res_lib_amf_pmstop, - sizeof (struct res_lib_amf_pmstop)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_pmstop.header.error : error); - return (SA_AIS_OK); -} - -SaAisErrorT -saAmfHealthcheckStart ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaAmfHealthcheckKeyT *healthcheckKey, - SaAmfHealthcheckInvocationT invocationType, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct req_lib_amf_healthcheckstart req_lib_amf_healthcheckstart; - struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart; - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_healthcheckstart.header.size = sizeof (struct req_lib_amf_healthcheckstart); - req_lib_amf_healthcheckstart.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTART; - memcpy (&req_lib_amf_healthcheckstart.compName, compName, - sizeof (SaNameT)); - memcpy (&req_lib_amf_healthcheckstart.healthcheckKey, - healthcheckKey, sizeof (SaAmfHealthcheckKeyT)); - req_lib_amf_healthcheckstart.invocationType = invocationType; - req_lib_amf_healthcheckstart.recommendedRecovery = recommendedRecovery; - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_healthcheckstart, - sizeof (struct req_lib_amf_healthcheckstart), - &res_lib_amf_healthcheckstart, - sizeof (struct res_lib_amf_healthcheckstart)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_healthcheckstart.header.error : error); -} - -SaAisErrorT -saAmfHealthcheckConfirm ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaAmfHealthcheckKeyT *healthcheckKey, - SaAisErrorT healthcheckResult) -{ - struct req_lib_amf_healthcheckconfirm req_lib_amf_healthcheckconfirm; - struct res_lib_amf_healthcheckconfirm res_lib_amf_healthcheckconfirm; - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_healthcheckconfirm.header.size = sizeof (struct req_lib_amf_healthcheckconfirm); - req_lib_amf_healthcheckconfirm.header.id = MESSAGE_REQ_AMF_HEALTHCHECKCONFIRM; - memcpy (&req_lib_amf_healthcheckconfirm.compName, compName, - sizeof (SaNameT)); - memcpy (&req_lib_amf_healthcheckconfirm.healthcheckKey, - healthcheckKey, sizeof (SaAmfHealthcheckKeyT)); - req_lib_amf_healthcheckconfirm.healthcheckResult = healthcheckResult; - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_healthcheckconfirm, - sizeof (struct req_lib_amf_healthcheckconfirm), - &res_lib_amf_healthcheckconfirm, - sizeof (struct res_lib_amf_healthcheckconfirm)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_healthcheckconfirm.header.error : error); -} - -SaAisErrorT -saAmfHealthcheckStop ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaAmfHealthcheckKeyT *healthcheckKey) -{ - struct req_lib_amf_healthcheckstop req_lib_amf_healthcheckstop; - struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop; - struct amfInstance *amfInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_healthcheckstop.header.size = sizeof (struct req_lib_amf_healthcheckstop); - req_lib_amf_healthcheckstop.header.id = MESSAGE_REQ_AMF_HEALTHCHECKSTOP; - memcpy (&req_lib_amf_healthcheckstop.compName, compName, - sizeof (SaNameT)); - memcpy (&req_lib_amf_healthcheckstop.healthcheckKey, - healthcheckKey, sizeof (SaAmfHealthcheckKeyT)); - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_healthcheckstop, - sizeof (struct req_lib_amf_healthcheckstop), - &res_lib_amf_healthcheckstop, - sizeof (struct res_lib_amf_healthcheckstop)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_healthcheckstop.header.error : error); -} - - -SaAisErrorT -saAmfHAStateGet ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - const SaNameT *csiName, - SaAmfHAStateT *haState) -{ - struct amfInstance *amfInstance; - struct req_lib_amf_hastateget req_lib_amf_hastateget; - struct res_lib_amf_hastateget res_lib_amf_hastateget; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&amfInstance->response_mutex); - - req_lib_amf_hastateget.header.id = MESSAGE_REQ_AMF_HASTATEGET; - req_lib_amf_hastateget.header.size = sizeof (struct req_lib_amf_hastateget); - memcpy (&req_lib_amf_hastateget.compName, compName, sizeof (SaNameT)); - memcpy (&req_lib_amf_hastateget.csiName, csiName, sizeof (SaNameT)); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_hastateget, sizeof (struct req_lib_amf_hastateget), - &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - if (res_lib_amf_hastateget.header.error == SA_AIS_OK) { - memcpy (haState, &res_lib_amf_hastateget.haState, - sizeof (SaAmfHAStateT)); - } - return (error == SA_AIS_OK ? res_lib_amf_hastateget.header.error : error); -} - -SaAisErrorT -saAmfCSIQuiescingComplete ( - SaAmfHandleT amfHandle, - SaInvocationT invocation, - SaAisErrorT error) -{ - struct req_lib_amf_csiquiescingcomplete req_lib_amf_csiquiescingcomplete; - struct res_lib_amf_csiquiescingcomplete res_lib_amf_csiquiescingcomplete; - struct amfInstance *amfInstance; - SaAisErrorT errorResult; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_csiquiescingcomplete.header.size = sizeof (struct req_lib_amf_csiquiescingcomplete); - req_lib_amf_csiquiescingcomplete.header.id = MESSAGE_REQ_AMF_CSIQUIESCINGCOMPLETE; - req_lib_amf_csiquiescingcomplete.invocation = invocation; - req_lib_amf_csiquiescingcomplete.error = error; - - pthread_mutex_lock (&amfInstance->response_mutex); - - errorResult = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_csiquiescingcomplete, - sizeof (struct req_lib_amf_csiquiescingcomplete), - &res_lib_amf_csiquiescingcomplete, - sizeof (struct res_lib_amf_csiquiescingcomplete)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (errorResult == SA_AIS_OK ? res_lib_amf_csiquiescingcomplete.header.error : errorResult); -} - -SaAisErrorT -saAmfProtectionGroupTrack ( - SaAmfHandleT amfHandle, - const SaNameT *csiName, - SaUint8T trackFlags, - SaAmfProtectionGroupNotificationBufferT *notificationBuffer) -{ - struct amfInstance *amfInstance; - struct req_lib_amf_protectiongrouptrack req_lib_amf_protectiongrouptrack; - struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack; - SaAisErrorT error; - - req_lib_amf_protectiongrouptrack.header.size = sizeof (struct req_lib_amf_protectiongrouptrack); - req_lib_amf_protectiongrouptrack.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACK; - memcpy (&req_lib_amf_protectiongrouptrack.csiName, csiName, - sizeof (SaNameT)); - req_lib_amf_protectiongrouptrack.trackFlags = trackFlags; - req_lib_amf_protectiongrouptrack.notificationBufferAddress = (SaAmfProtectionGroupNotificationBufferT *)notificationBuffer; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &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_protectiongrouptrack.header.error : error); -} - -SaAisErrorT -saAmfProtectionGroupTrackStop ( - SaAmfHandleT amfHandle, - const SaNameT *csiName) -{ - struct amfInstance *amfInstance; - struct req_lib_amf_protectiongrouptrackstop req_lib_amf_protectiongrouptrackstop; - struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct req_lib_amf_protectiongrouptrackstop); - req_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_REQ_AMF_PROTECTIONGROUPTRACKSTOP; - memcpy (&req_lib_amf_protectiongrouptrackstop.csiName, csiName, sizeof (SaNameT)); - - pthread_mutex_lock (&amfInstance->response_mutex); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_protectiongrouptrackstop, - sizeof (struct req_lib_amf_protectiongrouptrackstop), - &res_lib_amf_protectiongrouptrackstop, - sizeof (struct res_lib_amf_protectiongrouptrackstop)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_protectiongrouptrackstop.header.error : error); -} - -SaAisErrorT -saAmfComponentErrorReport ( - SaAmfHandleT amfHandle, - const SaNameT *erroneousComponent, - SaTimeT errorDetectionTime, - SaAmfRecommendedRecoveryT recommendedRecovery, - SaNtfIdentifierT ntfIdentifier) -{ - struct amfInstance *amfInstance; - struct req_lib_amf_componenterrorreport req_lib_amf_componenterrorreport; - struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_componenterrorreport.header.id = MESSAGE_REQ_AMF_COMPONENTERRORREPORT; - req_lib_amf_componenterrorreport.header.size = sizeof (struct req_lib_amf_componenterrorreport); - memcpy (&req_lib_amf_componenterrorreport.erroneousComponent, erroneousComponent, - sizeof (SaNameT)); - req_lib_amf_componenterrorreport.errorDetectionTime = errorDetectionTime; - req_lib_amf_componenterrorreport.recommendedRecovery = recommendedRecovery; - DPRINT (("start error report\n")); - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_componenterrorreport, - sizeof (struct req_lib_amf_componenterrorreport), - &res_lib_amf_componenterrorreport, - sizeof (struct res_lib_amf_componenterrorreport)); - DPRINT (("end error report\n")); - - error = res_lib_amf_componenterrorreport.header.error; - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_componenterrorreport.header.error : error); -} - -SaAisErrorT -saAmfComponentErrorClear ( - SaAmfHandleT amfHandle, - const SaNameT *compName, - SaNtfIdentifierT ntfIdentifier) -{ - struct amfInstance *amfInstance; - struct req_lib_amf_componenterrorclear req_lib_amf_componenterrorclear; - struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear; - SaAisErrorT error; - - error = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_amf_componenterrorclear.header.id = MESSAGE_REQ_AMF_COMPONENTERRORCLEAR; - req_lib_amf_componenterrorclear.header.size = sizeof (struct req_lib_amf_componenterrorclear); - memcpy (&req_lib_amf_componenterrorclear.compName, compName, sizeof (SaNameT)); - - error = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_componenterrorclear, - sizeof (struct req_lib_amf_componenterrorclear), - &res_lib_amf_componenterrorclear, - sizeof (struct res_lib_amf_componenterrorclear)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (error == SA_AIS_OK ? res_lib_amf_componenterrorclear.header.error : error); -} - -SaAisErrorT -saAmfResponse ( - SaAmfHandleT amfHandle, - SaInvocationT invocation, - SaAisErrorT error) -{ - struct amfInstance *amfInstance; - struct req_lib_amf_response req_lib_amf_response; - struct res_lib_amf_response res_lib_amf_response; - SaAisErrorT errorResult; - - errorResult = saHandleInstanceGet (&amfHandleDatabase, amfHandle, - (void *)&amfInstance); - if (errorResult != SA_AIS_OK) { - return (errorResult); - } - - req_lib_amf_response.header.id = MESSAGE_REQ_AMF_RESPONSE; - req_lib_amf_response.header.size = sizeof (struct req_lib_amf_response); - req_lib_amf_response.invocation = invocation; - req_lib_amf_response.error = error; - - pthread_mutex_lock (&amfInstance->response_mutex); - - errorResult = saSendReceiveReply (amfInstance->response_fd, - &req_lib_amf_response, sizeof (struct req_lib_amf_response), - &res_lib_amf_response, sizeof (struct res_lib_amf_response)); - - pthread_mutex_unlock (&amfInstance->response_mutex); - - saHandleInstancePut (&amfHandleDatabase, amfHandle); - - return (errorResult == SA_AIS_OK ? res_lib_amf_response.header.error : errorResult); -} diff --git a/openais/lib/ckpt.c b/openais/lib/ckpt.c deleted file mode 100644 index 7bdf12c4..00000000 --- a/openais/lib/ckpt.c +++ /dev/null @@ -1,1878 +0,0 @@ -/* - * Copyright (c) 2002-2004 MontaVista Software, Inc. - * Copyright (c) 2006 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../include/saAis.h" -#include -#include -#include -#include "../include/saCkpt.h" -#include "../include/ipc_ckpt.h" -#include "../include/mar_ckpt.h" - -#include - -struct message_overlay { - mar_res_header_t header __attribute__((aligned(8))); - char data[4096]; -}; - -/* - * Data structure for instance data - */ -struct ckptInstance { - int response_fd; - int dispatch_fd; - SaCkptCallbacksT callbacks; - int finalize; - SaCkptHandleT ckptHandle; - pthread_mutex_t response_mutex; - pthread_mutex_t dispatch_mutex; - struct list_head checkpoint_list; -}; - -struct ckptCheckpointInstance { - int response_fd; - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT checkpointHandle; - SaCkptCheckpointOpenFlagsT checkpointOpenFlags; - SaNameT checkpointName; - unsigned int checkpointId; - pthread_mutex_t response_mutex; - struct list_head list; - struct list_head section_iteration_list_head; -}; - -struct ckptSectionIterationInstance { - int response_fd; - SaCkptSectionIterationHandleT sectionIterationHandle; - SaNameT checkpointName; - SaSizeT maxSectionIdSize; - struct list_head sectionIdListHead; - pthread_mutex_t response_mutex; - unsigned int executive_iteration_handle; - struct list_head list; -}; - -void ckptHandleInstanceDestructor (void *instance); -void checkpointHandleInstanceDestructor (void *instance); -void ckptSectionIterationHandleInstanceDestructor (void *instance); - -/* - * All CKPT instances in this database - */ -static struct saHandleDatabase ckptHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = ckptHandleInstanceDestructor -}; - -/* - * All Checkpoint instances in this database - */ -static struct saHandleDatabase checkpointHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = checkpointHandleInstanceDestructor -}; - -/* - * All section iterators in this database - */ -static struct saHandleDatabase ckptSectionIterationHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = ckptSectionIterationHandleInstanceDestructor -}; - -/* - * Versions supported - */ -static SaVersionT ckptVersionsSupported[] = { - { 'B', 1, 1 } -}; - -static struct saVersionDatabase ckptVersionDatabase = { - sizeof (ckptVersionsSupported) / sizeof (SaVersionT), - ckptVersionsSupported -}; - -struct iteratorSectionIdListEntry { - struct list_head list; - unsigned char data[0]; -}; - - -/* - * Implementation - */ -void ckptHandleInstanceDestructor (void *instance) -{ - struct ckptInstance *ckptInstance = instance; - - pthread_mutex_destroy (&ckptInstance->response_mutex); - pthread_mutex_destroy (&ckptInstance->dispatch_mutex); -} - -void checkpointHandleInstanceDestructor (void *instance) -{ - struct ckptCheckpointInstance *checkpointInstance = instance; - - pthread_mutex_destroy (&checkpointInstance->response_mutex); -} - -void ckptSectionIterationHandleInstanceDestructor (void *instance) -{ - struct ckptSectionIterationInstance *iterationInstance = instance; - - pthread_mutex_destroy (&iterationInstance->response_mutex); -} - -static void ckptSectionIterationInstanceFinalize (struct ckptSectionIterationInstance *ckptSectionIterationInstance) -{ - struct iteratorSectionIdListEntry *iteratorSectionIdListEntry; - struct list_head *sectionIdIterationList; - struct list_head *sectionIdIterationListNext; - /* - * iterate list of section ids for this iterator to free the allocated memory - * be careful to cache next pointer because free removes memory from use - */ - for (sectionIdIterationList = ckptSectionIterationInstance->sectionIdListHead.next, - sectionIdIterationListNext = sectionIdIterationList->next; - sectionIdIterationList != &ckptSectionIterationInstance->sectionIdListHead; - sectionIdIterationList = sectionIdIterationListNext, - sectionIdIterationListNext = sectionIdIterationList->next) { - - iteratorSectionIdListEntry = list_entry (sectionIdIterationList, - struct iteratorSectionIdListEntry, list); - - free (iteratorSectionIdListEntry); - } - - list_del (&ckptSectionIterationInstance->list); - - saHandleDestroy (&ckptSectionIterationHandleDatabase, - ckptSectionIterationInstance->sectionIterationHandle); -} - -static void ckptCheckpointInstanceFinalize (struct ckptCheckpointInstance *ckptCheckpointInstance) -{ - struct ckptSectionIterationInstance *sectionIterationInstance; - struct list_head *sectionIterationList; - struct list_head *sectionIterationListNext; - - for (sectionIterationList = ckptCheckpointInstance->section_iteration_list_head.next, - sectionIterationListNext = sectionIterationList->next; - sectionIterationList != &ckptCheckpointInstance->section_iteration_list_head; - sectionIterationList = sectionIterationListNext, - sectionIterationListNext = sectionIterationList->next) { - - sectionIterationInstance = list_entry (sectionIterationList, - struct ckptSectionIterationInstance, list); - - ckptSectionIterationInstanceFinalize (sectionIterationInstance); - } - - list_del (&ckptCheckpointInstance->list); - - saHandleDestroy (&checkpointHandleDatabase, ckptCheckpointInstance->checkpointHandle); -} - -static void ckptInstanceFinalize (struct ckptInstance *ckptInstance) -{ - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct list_head *checkpointInstanceList; - struct list_head *checkpointInstanceListNext; - - for (checkpointInstanceList = ckptInstance->checkpoint_list.next, - checkpointInstanceListNext = checkpointInstanceList->next; - checkpointInstanceList != &ckptInstance->checkpoint_list; - checkpointInstanceList = checkpointInstanceListNext, - checkpointInstanceListNext = checkpointInstanceList->next) { - - ckptCheckpointInstance = list_entry (checkpointInstanceList, - struct ckptCheckpointInstance, list); - - ckptCheckpointInstanceFinalize (ckptCheckpointInstance); - } - - saHandleDestroy (&ckptHandleDatabase, ckptInstance->ckptHandle); -} - -/** - * @defgroup saCkpt SAF AIS Checkpoint API - * @ingroup saf - * - * @{ - */ - -SaAisErrorT -saCkptInitialize ( - SaCkptHandleT *ckptHandle, - const SaCkptCallbacksT *callbacks, - SaVersionT *version) -{ - struct ckptInstance *ckptInstance; - SaAisErrorT error = SA_AIS_OK; - - if (ckptHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saVersionVerify (&ckptVersionDatabase, version); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleCreate (&ckptHandleDatabase, sizeof (struct ckptInstance), - ckptHandle); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleInstanceGet (&ckptHandleDatabase, *ckptHandle, - (void *)&ckptInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - ckptInstance->response_fd = -1; - - error = saServiceConnect (&ckptInstance->response_fd, - &ckptInstance->dispatch_fd, CKPT_SERVICE); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - if (callbacks) { - memcpy (&ckptInstance->callbacks, callbacks, sizeof (SaCkptCallbacksT)); - } else { - memset (&ckptInstance->callbacks, 0, sizeof (SaCkptCallbacksT)); - } - - list_init (&ckptInstance->checkpoint_list); - - ckptInstance->ckptHandle = *ckptHandle; - - pthread_mutex_init (&ckptInstance->response_mutex, NULL); - - saHandleInstancePut (&ckptHandleDatabase, *ckptHandle); - - return (SA_AIS_OK); - -error_put_destroy: - saHandleInstancePut (&ckptHandleDatabase, *ckptHandle); -error_destroy: - saHandleDestroy (&ckptHandleDatabase, *ckptHandle); -error_no_destroy: - return (error); -} - -SaAisErrorT -saCkptSelectionObjectGet ( - const SaCkptHandleT ckptHandle, - SaSelectionObjectT *selectionObject) -{ - struct ckptInstance *ckptInstance; - SaAisErrorT error; - - if (selectionObject == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance); - if (error != SA_AIS_OK) { - return (error); - } - - *selectionObject = ckptInstance->dispatch_fd; - - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); - - return (SA_AIS_OK); -} - -SaAisErrorT -saCkptDispatch ( - const SaCkptHandleT ckptHandle, - SaDispatchFlagsT dispatchFlags) -{ - struct pollfd ufds; - int poll_fd; - int timeout = 1; - SaCkptCallbacksT callbacks; - SaAisErrorT error; - int dispatch_avail; - struct ckptInstance *ckptInstance; - int cont = 1; /* always continue do loop except when set to 0 */ - struct message_overlay dispatch_data; - struct res_lib_ckpt_checkpointopenasync *res_lib_ckpt_checkpointopenasync; - struct res_lib_ckpt_checkpointsynchronizeasync *res_lib_ckpt_checkpointsynchronizeasync; - struct ckptCheckpointInstance *ckptCheckpointInstance; - - if (dispatchFlags != SA_DISPATCH_ONE && - dispatchFlags != SA_DISPATCH_ALL && - dispatchFlags != SA_DISPATCH_BLOCKING) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, - (void *)&ckptInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Timeout instantly for SA_DISPATCH_ALL - */ - if (dispatchFlags == SA_DISPATCH_ALL) { - timeout = 0; - } - - do { - /* - * Read data directly from socket - */ - poll_fd = ckptInstance->dispatch_fd; - ufds.fd = poll_fd; - ufds.events = POLLIN; - ufds.revents = 0; - - error = saPollRetry(&ufds, 1, timeout); - if (error != SA_AIS_OK) { - goto error_put; - } - pthread_mutex_lock(&ckptInstance->dispatch_mutex); - - if (ckptInstance->finalize == 1) { - error = SA_AIS_OK; - goto error_unlock; - } - - if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_unlock; - } - - dispatch_avail = (ufds.revents & POLLIN); - - if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) { - pthread_mutex_unlock(&ckptInstance->dispatch_mutex); - break; /* exit do while cont is 1 loop */ - } else - if (dispatch_avail == 0) { - pthread_mutex_unlock(&ckptInstance->dispatch_mutex); - continue; - } - - memset(&dispatch_data,0, sizeof(struct message_overlay)); - error = saRecvRetry (ckptInstance->dispatch_fd, &dispatch_data.header, sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - if (dispatch_data.header.size > sizeof (mar_res_header_t)) { - error = saRecvRetry (ckptInstance->dispatch_fd, &dispatch_data.data, - dispatch_data.header.size - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - } - - /* - * Make copy of callbacks, message data, unlock instance, - * and call callback. A risk of this dispatch method is that - * the callback routines may operate at the same time that - * CkptFinalize has been called in another thread. - */ - memcpy(&callbacks,&ckptInstance->callbacks, sizeof(ckptInstance->callbacks)); - pthread_mutex_unlock(&ckptInstance->dispatch_mutex); - /* - * Dispatch incoming response - */ - switch (dispatch_data.header.id) { - case MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC: - if (callbacks.saCkptCheckpointOpenCallback == NULL) { - continue; - } - res_lib_ckpt_checkpointopenasync = (struct res_lib_ckpt_checkpointopenasync *) &dispatch_data; - - /* - * This instance get/listadd/put required so that close - * later has the proper list of checkpoints - */ - if (res_lib_ckpt_checkpointopenasync->header.error == SA_AIS_OK) { - error = saHandleInstanceGet (&checkpointHandleDatabase, - res_lib_ckpt_checkpointopenasync->checkpoint_handle, - (void *)&ckptCheckpointInstance); - - assert (error == SA_AIS_OK); /* should only be valid handles here */ - ckptCheckpointInstance->checkpointId = - res_lib_ckpt_checkpointopenasync->ckpt_id; - - /* - * open succeeded without error - */ - list_init (&ckptCheckpointInstance->list); - list_init (&ckptCheckpointInstance->section_iteration_list_head); - list_add (&ckptCheckpointInstance->list, - &ckptInstance->checkpoint_list); - - callbacks.saCkptCheckpointOpenCallback( - res_lib_ckpt_checkpointopenasync->invocation, - res_lib_ckpt_checkpointopenasync->checkpoint_handle, - res_lib_ckpt_checkpointopenasync->header.error); - saHandleInstancePut (&checkpointHandleDatabase, - res_lib_ckpt_checkpointopenasync->checkpoint_handle); - } else { - /* - * open failed with error - */ - callbacks.saCkptCheckpointOpenCallback( - res_lib_ckpt_checkpointopenasync->invocation, - -1, - res_lib_ckpt_checkpointopenasync->header.error); - } - break; - - case MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC: - if (callbacks.saCkptCheckpointSynchronizeCallback == NULL) { - continue; - } - - res_lib_ckpt_checkpointsynchronizeasync = (struct res_lib_ckpt_checkpointsynchronizeasync *) &dispatch_data; - - callbacks.saCkptCheckpointSynchronizeCallback( - res_lib_ckpt_checkpointsynchronizeasync->invocation, - res_lib_ckpt_checkpointsynchronizeasync->header.error); - break; - default: - break; - } - /* - * Determine if more messages should be processed - */ - switch (dispatchFlags) { - case SA_DISPATCH_ONE: - cont = 0; - break; - case SA_DISPATCH_ALL: - break; - case SA_DISPATCH_BLOCKING: - break; - } - } while (cont); -error_unlock: - pthread_mutex_unlock(&ckptInstance->dispatch_mutex); -error_put: - saHandleInstancePut(&ckptHandleDatabase, ckptHandle); -error_exit: - return (error); -} - -SaAisErrorT -saCkptFinalize ( - const SaCkptHandleT ckptHandle) -{ - struct ckptInstance *ckptInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, - (void *)&ckptInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&ckptInstance->response_mutex); - - /* - * Another thread has already started finalizing - */ - if (ckptInstance->finalize) { - pthread_mutex_unlock (&ckptInstance->response_mutex); - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); - return (SA_AIS_ERR_BAD_HANDLE); - } - - ckptInstance->finalize = 1; - - pthread_mutex_unlock (&ckptInstance->response_mutex); - - ckptInstanceFinalize (ckptInstance); - - if (ckptInstance->response_fd != -1) { - shutdown (ckptInstance->response_fd, 0); - close (ckptInstance->response_fd); - } - - if (ckptInstance->dispatch_fd != -1) { - shutdown (ckptInstance->dispatch_fd, 0); - close (ckptInstance->dispatch_fd); - } - - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); - - return (SA_AIS_OK); -} - -SaAisErrorT -saCkptCheckpointOpen ( - SaCkptHandleT ckptHandle, - const SaNameT *checkpointName, - const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes, - SaCkptCheckpointOpenFlagsT checkpointOpenFlags, - SaTimeT timeout, - SaCkptCheckpointHandleT *checkpointHandle) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct ckptInstance *ckptInstance; - struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen; - struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen; - - if (checkpointHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (checkpointName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (checkpointOpenFlags & ~(SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE|SA_CKPT_CHECKPOINT_CREATE)) { - return (SA_AIS_ERR_BAD_FLAGS); - } - - if ((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) && - checkpointCreationAttributes == NULL) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) && - checkpointCreationAttributes != NULL) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (checkpointCreationAttributes && - (checkpointCreationAttributes->checkpointSize > - (checkpointCreationAttributes->maxSections * checkpointCreationAttributes->maxSectionSize))) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, - (void *)&ckptInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saHandleCreate (&checkpointHandleDatabase, - sizeof (struct ckptCheckpointInstance), checkpointHandle); - if (error != SA_AIS_OK) { - goto error_put_ckpt; - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, - *checkpointHandle, (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - ckptCheckpointInstance->response_fd = ckptInstance->response_fd; - - ckptCheckpointInstance->ckptHandle = ckptHandle; - ckptCheckpointInstance->checkpointHandle = *checkpointHandle; - ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags; - list_init (&ckptCheckpointInstance->section_iteration_list_head); - - req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen); - req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN; - marshall_to_mar_name_t (&req_lib_ckpt_checkpointopen.checkpoint_name, - (SaNameT *)checkpointName); - memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, sizeof (SaNameT)); - req_lib_ckpt_checkpointopen.async_call = 0; - req_lib_ckpt_checkpointopen.invocation = 0; - req_lib_ckpt_checkpointopen.fail_with_error = SA_AIS_OK; - req_lib_ckpt_checkpointopen.checkpoint_creation_attributes_set = 0; - if (checkpointCreationAttributes) { - marshall_to_mar_ckpt_checkpoint_creation_attributes_t ( - &req_lib_ckpt_checkpointopen.checkpoint_creation_attributes, - (SaCkptCheckpointCreationAttributesT *)checkpointCreationAttributes); - req_lib_ckpt_checkpointopen.checkpoint_creation_attributes_set = 1; - } - req_lib_ckpt_checkpointopen.checkpoint_open_flags = checkpointOpenFlags; - - error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointopen, - sizeof (struct req_lib_ckpt_checkpointopen)); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_checkpointopen, - sizeof (struct res_lib_ckpt_checkpointopen)); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - if (res_lib_ckpt_checkpointopen.header.error != SA_AIS_OK) { - error = res_lib_ckpt_checkpointopen.header.error; - goto error_put_destroy; - } - ckptCheckpointInstance->checkpointId = - res_lib_ckpt_checkpointopen.ckpt_id; - - pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL); - - saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle); - - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); - - list_init (&ckptCheckpointInstance->list); - - list_add (&ckptCheckpointInstance->list, &ckptInstance->checkpoint_list); - return (error); - -error_put_destroy: - saHandleInstancePut (&checkpointHandleDatabase, *checkpointHandle); -error_destroy: - saHandleDestroy (&checkpointHandleDatabase, *checkpointHandle); -error_put_ckpt: - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); -error_exit: - return (error); -} - -SaAisErrorT -saCkptCheckpointOpenAsync ( - const SaCkptHandleT ckptHandle, - SaInvocationT invocation, - const SaNameT *checkpointName, - const SaCkptCheckpointCreationAttributesT *checkpointCreationAttributes, - SaCkptCheckpointOpenFlagsT checkpointOpenFlags) -{ - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct ckptInstance *ckptInstance; - SaCkptCheckpointHandleT checkpointHandle; - SaAisErrorT error; - struct req_lib_ckpt_checkpointopen req_lib_ckpt_checkpointopen; - struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync; - SaAisErrorT failWithError = SA_AIS_OK; - - if (checkpointName == NULL) { - failWithError = SA_AIS_ERR_INVALID_PARAM; - } else - if (checkpointOpenFlags & - ~(SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE|SA_CKPT_CHECKPOINT_CREATE)) { - failWithError = SA_AIS_ERR_BAD_FLAGS; - } else - if ((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) && - checkpointCreationAttributes == NULL) { - - failWithError = SA_AIS_ERR_INVALID_PARAM; - } else - if (((checkpointOpenFlags & SA_CKPT_CHECKPOINT_CREATE) == 0) && - checkpointCreationAttributes != NULL) { - - failWithError = SA_AIS_ERR_INVALID_PARAM; - } else - if (checkpointCreationAttributes && - (checkpointCreationAttributes->checkpointSize > - (checkpointCreationAttributes->maxSections * checkpointCreationAttributes->maxSectionSize))) { - - failWithError = SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, - (void *)&ckptInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if (ckptInstance->callbacks.saCkptCheckpointOpenCallback == NULL) { - error = SA_AIS_ERR_INIT; - goto error_put_ckpt; - } - - error = saHandleCreate (&checkpointHandleDatabase, - sizeof (struct ckptCheckpointInstance), &checkpointHandle); - if (error != SA_AIS_OK) { - goto error_put_ckpt; - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - ckptCheckpointInstance->response_fd = ckptInstance->response_fd; - ckptCheckpointInstance->ckptHandle = ckptHandle; - ckptCheckpointInstance->checkpointHandle = checkpointHandle; - ckptCheckpointInstance->checkpointOpenFlags = checkpointOpenFlags; - if (failWithError == SA_AIS_OK) { - memcpy (&ckptCheckpointInstance->checkpointName, checkpointName, - sizeof (SaNameT)); - marshall_to_mar_name_t (&req_lib_ckpt_checkpointopen.checkpoint_name, - (SaNameT *)checkpointName); - } - - req_lib_ckpt_checkpointopen.header.size = sizeof (struct req_lib_ckpt_checkpointopen); - req_lib_ckpt_checkpointopen.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTOPEN; - req_lib_ckpt_checkpointopen.async_call = 1; - req_lib_ckpt_checkpointopen.invocation = invocation; - req_lib_ckpt_checkpointopen.fail_with_error = failWithError; - req_lib_ckpt_checkpointopen.checkpoint_creation_attributes_set = 0; - if (checkpointCreationAttributes) { - marshall_to_mar_ckpt_checkpoint_creation_attributes_t ( - &req_lib_ckpt_checkpointopen.checkpoint_creation_attributes, - (SaCkptCheckpointCreationAttributesT *)checkpointCreationAttributes); - req_lib_ckpt_checkpointopen.checkpoint_creation_attributes_set = 1; - } - - req_lib_ckpt_checkpointopen.checkpoint_open_flags = checkpointOpenFlags; - req_lib_ckpt_checkpointopen.checkpoint_handle = checkpointHandle; - - error = saSendReceiveReply (ckptInstance->response_fd, - &req_lib_ckpt_checkpointopen, - sizeof (struct req_lib_ckpt_checkpointopen), - &res_lib_ckpt_checkpointopenasync, - sizeof (struct res_lib_ckpt_checkpointopenasync)); - - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - if (res_lib_ckpt_checkpointopenasync.header.error != SA_AIS_OK) { - error = res_lib_ckpt_checkpointopenasync.header.error; - goto error_put_destroy; - } - - pthread_mutex_init (&ckptCheckpointInstance->response_mutex, NULL); - - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_checkpointopenasync.header.error : error); - -error_put_destroy: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); -error_destroy: - saHandleDestroy (&checkpointHandleDatabase, checkpointHandle); -error_put_ckpt: - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); -error_exit: - return (error); -} - -SaAisErrorT -saCkptCheckpointClose ( - SaCkptCheckpointHandleT checkpointHandle) -{ - struct req_lib_ckpt_checkpointclose req_lib_ckpt_checkpointclose; - struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose; - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_ckpt_checkpointclose.header.size = sizeof (struct req_lib_ckpt_checkpointclose); - req_lib_ckpt_checkpointclose.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTCLOSE; - marshall_to_mar_name_t (&req_lib_ckpt_checkpointclose.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_checkpointclose.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendReceiveReply (ckptCheckpointInstance->response_fd, - &req_lib_ckpt_checkpointclose, - sizeof (struct req_lib_ckpt_checkpointclose), - &res_lib_ckpt_checkpointclose, - sizeof (struct res_lib_ckpt_checkpointclose)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - - if (error == SA_AIS_OK) { - error = res_lib_ckpt_checkpointclose.header.error; - } - - if (error == SA_AIS_OK) { - ckptCheckpointInstanceFinalize (ckptCheckpointInstance); - } - - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error); -} - -SaAisErrorT -saCkptCheckpointUnlink ( - SaCkptHandleT ckptHandle, - const SaNameT *checkpointName) -{ - SaAisErrorT error; - struct ckptInstance *ckptInstance; - struct req_lib_ckpt_checkpointunlink req_lib_ckpt_checkpointunlink; - struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink; - - if (checkpointName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - error = saHandleInstanceGet (&ckptHandleDatabase, ckptHandle, (void *)&ckptInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_ckpt_checkpointunlink.header.size = sizeof (struct req_lib_ckpt_checkpointunlink); - req_lib_ckpt_checkpointunlink.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTUNLINK; - marshall_to_mar_name_t (&req_lib_ckpt_checkpointunlink.checkpoint_name, - (SaNameT *)checkpointName); - - pthread_mutex_lock (&ckptInstance->response_mutex); - - error = saSendReceiveReply (ckptInstance->response_fd, - &req_lib_ckpt_checkpointunlink, - sizeof (struct req_lib_ckpt_checkpointunlink), - &res_lib_ckpt_checkpointunlink, - sizeof (struct res_lib_ckpt_checkpointunlink)); - - pthread_mutex_unlock (&ckptInstance->response_mutex); - - saHandleInstancePut (&ckptHandleDatabase, ckptHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_checkpointunlink.header.error : error); - -} - -SaAisErrorT -saCkptCheckpointRetentionDurationSet ( - SaCkptCheckpointHandleT checkpointHandle, - SaTimeT retentionDuration) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_checkpointretentiondurationset req_lib_ckpt_checkpointretentiondurationset; - struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset; - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_lib_ckpt_checkpointretentiondurationset); - req_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET; - - req_lib_ckpt_checkpointretentiondurationset.retention_duration = retentionDuration; - marshall_to_mar_name_t (&req_lib_ckpt_checkpointretentiondurationset.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_checkpointretentiondurationset.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendReceiveReply (ckptCheckpointInstance->response_fd, - &req_lib_ckpt_checkpointretentiondurationset, - sizeof (struct req_lib_ckpt_checkpointretentiondurationset), - &res_lib_ckpt_checkpointretentiondurationset, - sizeof (struct res_lib_ckpt_checkpointretentiondurationset)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - return (error == SA_AIS_OK ? res_lib_ckpt_checkpointretentiondurationset.header.error : error); -} - -SaAisErrorT -saCkptActiveReplicaSet ( - SaCkptCheckpointHandleT checkpointHandle) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_activereplicaset req_lib_ckpt_activereplicaset; - struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset; - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_put; - } - - req_lib_ckpt_activereplicaset.header.size = sizeof (struct req_lib_ckpt_activereplicaset); - req_lib_ckpt_activereplicaset.header.id = MESSAGE_REQ_CKPT_ACTIVEREPLICASET; - marshall_to_mar_name_t (&req_lib_ckpt_activereplicaset.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_activereplicaset.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendReceiveReply (ckptCheckpointInstance->response_fd, - &req_lib_ckpt_activereplicaset, - sizeof (struct req_lib_ckpt_activereplicaset), - &res_lib_ckpt_activereplicaset, - sizeof (struct res_lib_ckpt_activereplicaset)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_put: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_activereplicaset.header.error : error); -} - -SaAisErrorT -saCkptCheckpointStatusGet ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptCheckpointDescriptorT *checkpointStatus) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_checkpointstatusget req_lib_ckpt_checkpointstatusget; - struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget; - - if (checkpointStatus == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_ckpt_checkpointstatusget.header.size = sizeof (struct req_lib_ckpt_checkpointstatusget); - req_lib_ckpt_checkpointstatusget.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET; - - marshall_to_mar_name_t (&req_lib_ckpt_checkpointstatusget.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_checkpointstatusget.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendReceiveReply (ckptCheckpointInstance->response_fd, - &req_lib_ckpt_checkpointstatusget, - sizeof (struct req_lib_ckpt_checkpointstatusget), - &res_lib_ckpt_checkpointstatusget, - sizeof (struct res_lib_ckpt_checkpointstatusget)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - - marshall_from_mar_ckpt_checkpoint_descriptor_t ( - checkpointStatus, - &res_lib_ckpt_checkpointstatusget.checkpoint_descriptor); - - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_checkpointstatusget.header.error : error); -} - -SaAisErrorT -saCkptSectionCreate ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptSectionCreationAttributesT *sectionCreationAttributes, - const void *initialData, - SaUint32T initialDataSize) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_sectioncreate req_lib_ckpt_sectioncreate; - struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate; - - if (sectionCreationAttributes == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (initialData == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_exit; - } - - req_lib_ckpt_sectioncreate.header.size = - sizeof (struct req_lib_ckpt_sectioncreate) + - sectionCreationAttributes->sectionId->idLen + - initialDataSize; - - req_lib_ckpt_sectioncreate.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONCREATE; - req_lib_ckpt_sectioncreate.id_len = sectionCreationAttributes->sectionId->idLen; - req_lib_ckpt_sectioncreate.expiration_time = sectionCreationAttributes->expirationTime; - req_lib_ckpt_sectioncreate.initial_data_size = initialDataSize; - - marshall_to_mar_name_t (&req_lib_ckpt_sectioncreate.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectioncreate.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate, - sizeof (struct req_lib_ckpt_sectioncreate)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Write section identifier to server - */ - error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id, - sectionCreationAttributes->sectionId->idLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saSendRetry (ckptCheckpointInstance->response_fd, initialData, - initialDataSize); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (ckptCheckpointInstance->response_fd, - &res_lib_ckpt_sectioncreate, - sizeof (struct res_lib_ckpt_sectioncreate)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_exit: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_sectioncreate.header.error : error); -} - - -SaAisErrorT -saCkptSectionDelete ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptSectionIdT *sectionId) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_sectiondelete req_lib_ckpt_sectiondelete; - struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete; - - if (sectionId == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_put; - } - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - req_lib_ckpt_sectiondelete.header.size = sizeof (struct req_lib_ckpt_sectiondelete) + sectionId->idLen; - req_lib_ckpt_sectiondelete.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONDELETE; - req_lib_ckpt_sectiondelete.id_len = sectionId->idLen; - - marshall_to_mar_name_t ( - &req_lib_ckpt_sectiondelete.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectiondelete.ckpt_id = - ckptCheckpointInstance->checkpointId; - - error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete, - sizeof (struct req_lib_ckpt_sectiondelete)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Write section identifier to server - */ - error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id, - sectionId->idLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - error = saRecvRetry (ckptCheckpointInstance->response_fd, - &res_lib_ckpt_sectiondelete, - sizeof (struct res_lib_ckpt_sectiondelete)); - -error_exit: - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_put: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - return (error == SA_AIS_OK ? res_lib_ckpt_sectiondelete.header.error : error); -} - -SaAisErrorT -saCkptSectionExpirationTimeSet ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptSectionIdT *sectionId, - SaTimeT expirationTime) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_sectionexpirationtimeset req_lib_ckpt_sectionexpirationtimeset; - struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset; - - if (sectionId == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_put; - } - - - req_lib_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_lib_ckpt_sectionexpirationtimeset) + sectionId->idLen; - req_lib_ckpt_sectionexpirationtimeset.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET; - req_lib_ckpt_sectionexpirationtimeset.id_len = sectionId->idLen; - req_lib_ckpt_sectionexpirationtimeset.expiration_time = expirationTime; - - marshall_to_mar_name_t (&req_lib_ckpt_sectionexpirationtimeset.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectionexpirationtimeset.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionexpirationtimeset, - sizeof (struct req_lib_ckpt_sectionexpirationtimeset)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Write section identifier to server - */ - if (sectionId->idLen) { - error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id, - sectionId->idLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - } - - error = saRecvRetry (ckptCheckpointInstance->response_fd, - &res_lib_ckpt_sectionexpirationtimeset, - sizeof (struct res_lib_ckpt_sectionexpirationtimeset)); - -error_exit: - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_put: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_sectionexpirationtimeset.header.error : error); -} - -SaAisErrorT -saCkptSectionIterationInitialize ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptSectionsChosenT sectionsChosen, - SaTimeT expirationTime, - SaCkptSectionIterationHandleT *sectionIterationHandle) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct ckptSectionIterationInstance *ckptSectionIterationInstance; - struct req_lib_ckpt_sectioniterationinitialize req_lib_ckpt_sectioniterationinitialize; - struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize; - - if (sectionIterationHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (sectionsChosen != SA_CKPT_SECTIONS_FOREVER && - sectionsChosen != SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME && - sectionsChosen != SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME && - sectionsChosen != SA_CKPT_SECTIONS_CORRUPTED && - sectionsChosen != SA_CKPT_SECTIONS_ANY) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - error = saHandleCreate (&ckptSectionIterationHandleDatabase, - sizeof (struct ckptSectionIterationInstance), sectionIterationHandle); - if (error != SA_AIS_OK) { - goto error_put_checkpoint_db; - } - - error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase, - *sectionIterationHandle, (void *)&ckptSectionIterationInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - ckptSectionIterationInstance->response_fd = ckptCheckpointInstance->response_fd; - ckptSectionIterationInstance->sectionIterationHandle = *sectionIterationHandle; - - memcpy (&ckptSectionIterationInstance->checkpointName, - &ckptCheckpointInstance->checkpointName, sizeof (SaNameT)); - - list_init (&ckptSectionIterationInstance->list); - - list_add (&ckptSectionIterationInstance->list, - &ckptCheckpointInstance->section_iteration_list_head); - - pthread_mutex_init (&ckptSectionIterationInstance->response_mutex, NULL); - - /* - * Setup section id list for iterator next - */ - list_init (&ckptSectionIterationInstance->sectionIdListHead); - - req_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct req_lib_ckpt_sectioniterationinitialize); - req_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATIONINITIALIZE; - req_lib_ckpt_sectioniterationinitialize.sections_chosen = sectionsChosen; - req_lib_ckpt_sectioniterationinitialize.expiration_time = expirationTime; - marshall_to_mar_name_t ( - &req_lib_ckpt_sectioniterationinitialize.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectioniterationinitialize.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex); - - error = saSendReceiveReply (ckptSectionIterationInstance->response_fd, - &req_lib_ckpt_sectioniterationinitialize, - sizeof (struct req_lib_ckpt_sectioniterationinitialize), - &res_lib_ckpt_sectioniterationinitialize, - sizeof (struct res_lib_ckpt_sectioniterationinitialize)); - - pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex); - - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - ckptSectionIterationInstance->executive_iteration_handle = - res_lib_ckpt_sectioniterationinitialize.iteration_handle; - ckptSectionIterationInstance->maxSectionIdSize = - res_lib_ckpt_sectioniterationinitialize.max_section_id_size; - - saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle); - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationinitialize.header.error : error); - -error_put_destroy: - saHandleInstancePut (&ckptSectionIterationHandleDatabase, *sectionIterationHandle); -error_destroy: - saHandleDestroy (&ckptSectionIterationHandleDatabase, *sectionIterationHandle); -error_put_checkpoint_db: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - return (error); -} - -SaAisErrorT -saCkptSectionIterationNext ( - SaCkptSectionIterationHandleT sectionIterationHandle, - SaCkptSectionDescriptorT *sectionDescriptor) -{ - SaAisErrorT error; - struct ckptSectionIterationInstance *ckptSectionIterationInstance; - struct req_lib_ckpt_sectioniterationnext req_lib_ckpt_sectioniterationnext; - struct res_lib_ckpt_sectioniterationnext res_lib_ckpt_sectioniterationnext; - struct iteratorSectionIdListEntry *iteratorSectionIdListEntry; - - if (sectionDescriptor == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase, - sectionIterationHandle, (void *)&ckptSectionIterationInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - /* - * Allocate section id storage area - */ - iteratorSectionIdListEntry = malloc (sizeof (struct list_head) + - ckptSectionIterationInstance->maxSectionIdSize); - if (iteratorSectionIdListEntry == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_put_nounlock; - } - - req_lib_ckpt_sectioniterationnext.header.size = sizeof (struct req_lib_ckpt_sectioniterationnext); - req_lib_ckpt_sectioniterationnext.header.id = MESSAGE_REQ_CKPT_SECTIONITERATIONNEXT; - req_lib_ckpt_sectioniterationnext.iteration_handle = ckptSectionIterationInstance->executive_iteration_handle; - - pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex); - - error = saSendReceiveReply (ckptSectionIterationInstance->response_fd, - &req_lib_ckpt_sectioniterationnext, - sizeof (struct req_lib_ckpt_sectioniterationnext), - &res_lib_ckpt_sectioniterationnext, - sizeof (struct res_lib_ckpt_sectioniterationnext)); - - if (error != SA_AIS_OK) { - goto error_put_unlock; - } - - marshall_from_mar_ckpt_section_descriptor_t ( - sectionDescriptor, - &res_lib_ckpt_sectioniterationnext.section_descriptor); - - sectionDescriptor->sectionId.id = &iteratorSectionIdListEntry->data[0]; - - if ((res_lib_ckpt_sectioniterationnext.header.size - sizeof (struct res_lib_ckpt_sectioniterationnext)) > 0) { - error = saRecvRetry (ckptSectionIterationInstance->response_fd, - sectionDescriptor->sectionId.id, - res_lib_ckpt_sectioniterationnext.header.size - - sizeof (struct res_lib_ckpt_sectioniterationnext)); - } - - error = (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationnext.header.error : error); - - /* - * Add to persistent memory list for this sectioniterator - */ - if (error == SA_AIS_OK) { - list_init (&iteratorSectionIdListEntry->list); - list_add (&iteratorSectionIdListEntry->list, &ckptSectionIterationInstance->sectionIdListHead); - } - -error_put_unlock: - pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex); - if (error != SA_AIS_OK) { - free (iteratorSectionIdListEntry); - } - -error_put_nounlock: - saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle); - -error_exit: - return (error); -} - -SaAisErrorT -saCkptSectionIterationFinalize ( - SaCkptSectionIterationHandleT sectionIterationHandle) -{ - SaAisErrorT error; - struct ckptSectionIterationInstance *ckptSectionIterationInstance; - struct req_lib_ckpt_sectioniterationfinalize req_lib_ckpt_sectioniterationfinalize; - struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize; - - error = saHandleInstanceGet (&ckptSectionIterationHandleDatabase, - sectionIterationHandle, (void *)&ckptSectionIterationInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - req_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct req_lib_ckpt_sectioniterationfinalize); - req_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_REQ_CKPT_SECTIONITERATIONFINALIZE; - req_lib_ckpt_sectioniterationfinalize.iteration_handle = ckptSectionIterationInstance->executive_iteration_handle; - - pthread_mutex_lock (&ckptSectionIterationInstance->response_mutex); - - error = saSendReceiveReply (ckptSectionIterationInstance->response_fd, - &req_lib_ckpt_sectioniterationfinalize, - sizeof (struct req_lib_ckpt_sectioniterationfinalize), - &res_lib_ckpt_sectioniterationfinalize, - sizeof (struct res_lib_ckpt_sectioniterationfinalize)); - - pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex); - - if (error != SA_AIS_OK) { - goto error_put; - } - - ckptSectionIterationInstanceFinalize (ckptSectionIterationInstance); - - saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle); - - return (error); - -error_put: - pthread_mutex_unlock (&ckptSectionIterationInstance->response_mutex); - - saHandleInstancePut (&ckptSectionIterationHandleDatabase, sectionIterationHandle); -error_exit: - return (error == SA_AIS_OK ? res_lib_ckpt_sectioniterationfinalize.header.error : error); -} - -SaAisErrorT -saCkptCheckpointWrite ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptIOVectorElementT *ioVector, - SaUint32T numberOfElements, - SaUint32T *erroneousVectorIndex) -{ - SaAisErrorT error = SA_AIS_OK; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_sectionwrite req_lib_ckpt_sectionwrite; - struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite; - int i; - struct iovec iov[3]; - int iov_len = 0; - int iov_idx; - - if (ioVector == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_put; - } - req_lib_ckpt_sectionwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONWRITE; - - /* - * Make sure ioVector is valid - */ - for (i = 0; i < numberOfElements; i++) { - if (ioVector[i].dataSize == 0) { - *erroneousVectorIndex = i; - error = SA_AIS_ERR_INVALID_PARAM; - goto error_put; - } - if (ioVector[i].dataBuffer == NULL) { - *erroneousVectorIndex = i; - error = SA_AIS_ERR_INVALID_PARAM; - goto error_put; - } - } - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - for (i = 0; i < numberOfElements; i++) { - - req_lib_ckpt_sectionwrite.header.size = sizeof (struct req_lib_ckpt_sectionwrite) + ioVector[i].sectionId.idLen + ioVector[i].dataSize; - - req_lib_ckpt_sectionwrite.data_offset = ioVector[i].dataOffset; - req_lib_ckpt_sectionwrite.data_size = ioVector[i].dataSize; - req_lib_ckpt_sectionwrite.id_len = ioVector[i].sectionId.idLen; - - marshall_to_mar_name_t (&req_lib_ckpt_sectionwrite.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectionwrite.ckpt_id = - ckptCheckpointInstance->checkpointId; - - iov_len = 0; - iov_idx = 0; - iov[iov_idx].iov_base = (char *)&req_lib_ckpt_sectionwrite; - iov[iov_idx].iov_len = sizeof (struct req_lib_ckpt_sectionwrite); - iov_idx++; - - if (ioVector[i].sectionId.idLen) { - iov[iov_idx].iov_base = (char *)ioVector[i].sectionId.id; - iov[iov_idx].iov_len = ioVector[i].sectionId.idLen; - iov_idx++; - } - iov[iov_idx].iov_base = ioVector[i].dataBuffer; - iov[iov_idx].iov_len = ioVector[i].dataSize; - iov_idx++; - - error = saSendMsgRetry (ckptCheckpointInstance->response_fd, - iov, - iov_idx); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Receive response - */ - error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionwrite, - sizeof (struct res_lib_ckpt_sectionwrite)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if (res_lib_ckpt_sectionwrite.header.error == SA_AIS_ERR_TRY_AGAIN) { - error = SA_AIS_ERR_TRY_AGAIN; - goto error_exit; - } - /* - * If error, report back erroneous index - */ - if (res_lib_ckpt_sectionwrite.header.error != SA_AIS_OK) { - if (erroneousVectorIndex) { - *erroneousVectorIndex = i; - } - goto error_exit; - } - } - -error_exit: - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_put: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_sectionwrite.header.error : error); -} - -SaAisErrorT -saCkptSectionOverwrite ( - SaCkptCheckpointHandleT checkpointHandle, - const SaCkptSectionIdT *sectionId, - const void *dataBuffer, - SaSizeT dataSize) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_sectionoverwrite req_lib_ckpt_sectionoverwrite; - struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite; - - if (dataBuffer == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (sectionId == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - return (SA_AIS_ERR_ACCESS); - } - - req_lib_ckpt_sectionoverwrite.header.size = sizeof (struct req_lib_ckpt_sectionoverwrite) + sectionId->idLen + dataSize; - req_lib_ckpt_sectionoverwrite.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONOVERWRITE; - req_lib_ckpt_sectionoverwrite.id_len = sectionId->idLen; - req_lib_ckpt_sectionoverwrite.data_size = dataSize; - marshall_to_mar_name_t (&req_lib_ckpt_sectionoverwrite.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectionoverwrite.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite, - sizeof (struct req_lib_ckpt_sectionoverwrite)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if (sectionId->idLen) { - error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id, - sectionId->idLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - } - error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (ckptCheckpointInstance->response_fd, - &res_lib_ckpt_sectionoverwrite, - sizeof (struct res_lib_ckpt_sectionoverwrite)); - -error_exit: - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_sectionoverwrite.header.error : error); -} - -SaAisErrorT -saCkptCheckpointRead ( - SaCkptCheckpointHandleT checkpointHandle, - SaCkptIOVectorElementT *ioVector, - SaUint32T numberOfElements, - SaUint32T *erroneousVectorIndex) -{ - SaAisErrorT error = SA_AIS_OK; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_sectionread req_lib_ckpt_sectionread; - struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread; - int dataLength; - int i; - struct iovec iov[3]; - - if (ioVector == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_READ) == 0) { - return (SA_AIS_ERR_ACCESS); - } - - req_lib_ckpt_sectionread.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_SECTIONREAD; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - for (i = 0; i < numberOfElements; i++) { - req_lib_ckpt_sectionread.header.size = sizeof (struct req_lib_ckpt_sectionread) + - ioVector[i].sectionId.idLen; - - req_lib_ckpt_sectionread.id_len = ioVector[i].sectionId.idLen; - req_lib_ckpt_sectionread.data_offset = ioVector[i].dataOffset; - req_lib_ckpt_sectionread.data_size = ioVector[i].dataSize; - - marshall_to_mar_name_t (&req_lib_ckpt_sectionread.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_sectionread.ckpt_id = - ckptCheckpointInstance->checkpointId; - - iov[0].iov_base = (char *)&req_lib_ckpt_sectionread; - iov[0].iov_len = sizeof (struct req_lib_ckpt_sectionread); - iov[1].iov_base = (char *)ioVector[i].sectionId.id; - iov[1].iov_len = ioVector[i].sectionId.idLen; - - error = saSendMsgRetry (ckptCheckpointInstance->response_fd, - iov, - 2); - - /* - * Receive response header - */ - error = saRecvRetry (ckptCheckpointInstance->response_fd, &res_lib_ckpt_sectionread, - sizeof (struct res_lib_ckpt_sectionread)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - dataLength = res_lib_ckpt_sectionread.header.size - sizeof (struct res_lib_ckpt_sectionread); - - /* - * Receive checkpoint section data - */ - if (ioVector[i].dataBuffer == 0) { - ioVector[i].dataBuffer = - malloc (dataLength); - if (ioVector[i].dataBuffer == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - } - - if (dataLength > 0) { - error = saRecvRetry (ckptCheckpointInstance->response_fd, ioVector[i].dataBuffer, - dataLength); - if (error != SA_AIS_OK) { - goto error_exit; - } - } - if (res_lib_ckpt_sectionread.header.error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Report back bytes of data read - */ - ioVector[i].readSize = res_lib_ckpt_sectionread.data_read; - } - -error_exit: - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - if (error != SA_AIS_OK && erroneousVectorIndex) { - *erroneousVectorIndex = i; - } - return (error == SA_AIS_OK ? res_lib_ckpt_sectionread.header.error : error); -} - -SaAisErrorT -saCkptCheckpointSynchronize ( - SaCkptCheckpointHandleT checkpointHandle, - SaTimeT timeout) -{ - SaAisErrorT error; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_checkpointsynchronize req_lib_ckpt_checkpointsynchronize; - struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize; - - if (timeout == 0) { - return (SA_AIS_ERR_TIMEOUT); - } - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_put; - } - - req_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronize); - req_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE; - marshall_to_mar_name_t (&req_lib_ckpt_checkpointsynchronize.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_checkpointsynchronize.ckpt_id = - ckptCheckpointInstance->checkpointId; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendReceiveReply (ckptCheckpointInstance->response_fd, - &req_lib_ckpt_checkpointsynchronize, - sizeof (struct req_lib_ckpt_checkpointsynchronize), - &res_lib_ckpt_checkpointsynchronize, - sizeof (struct res_lib_ckpt_checkpointsynchronize)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_put: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronize.header.error : error); -} - -SaAisErrorT -saCkptCheckpointSynchronizeAsync ( - SaCkptCheckpointHandleT checkpointHandle, - SaInvocationT invocation) -{ - SaAisErrorT error; - struct ckptInstance *ckptInstance; - struct ckptCheckpointInstance *ckptCheckpointInstance; - struct req_lib_ckpt_checkpointsynchronizeasync req_lib_ckpt_checkpointsynchronizeasync; - struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync; - - error = saHandleInstanceGet (&checkpointHandleDatabase, checkpointHandle, - (void *)&ckptCheckpointInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((ckptCheckpointInstance->checkpointOpenFlags & SA_CKPT_CHECKPOINT_WRITE) == 0) { - error = SA_AIS_ERR_ACCESS; - goto error_put; - } - - error = saHandleInstanceGet (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle, - (void *)&ckptInstance); - if (error != SA_AIS_OK) { - goto error_put; - } - - if (ckptInstance->callbacks.saCkptCheckpointSynchronizeCallback == NULL) { - saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle); - error = SA_AIS_ERR_INIT; - goto error_put; - } - - saHandleInstancePut (&ckptHandleDatabase, ckptCheckpointInstance->ckptHandle); - - req_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct req_lib_ckpt_checkpointsynchronizeasync); - req_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_REQ_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC; - marshall_to_mar_name_t ( - &req_lib_ckpt_checkpointsynchronizeasync.checkpoint_name, - &ckptCheckpointInstance->checkpointName); - req_lib_ckpt_checkpointsynchronizeasync.ckpt_id = - ckptCheckpointInstance->checkpointId; - req_lib_ckpt_checkpointsynchronizeasync.invocation = invocation; - - pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - - error = saSendReceiveReply (ckptCheckpointInstance->response_fd, - &req_lib_ckpt_checkpointsynchronizeasync, - sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), - &res_lib_ckpt_checkpointsynchronizeasync, - sizeof (struct res_lib_ckpt_checkpointsynchronizeasync)); - - pthread_mutex_unlock (&ckptCheckpointInstance->response_mutex); - -error_put: - saHandleInstancePut (&checkpointHandleDatabase, checkpointHandle); - - return (error == SA_AIS_OK ? res_lib_ckpt_checkpointsynchronizeasync.header.error : error); -} - -/** @} */ diff --git a/openais/lib/clm.c b/openais/lib/clm.c deleted file mode 100644 index 670cbdc2..00000000 --- a/openais/lib/clm.c +++ /dev/null @@ -1,748 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * Copyright (c) 2006 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PROCESSOR_COUNT_MAX 384 -#include -#include -#include -#include -#include -#include -#include "../include/mar_clm.h" - -#include "util.h" - -struct res_overlay { - mar_res_header_t header; - char data[512000]; -}; - -struct clmInstance { - int response_fd; - int dispatch_fd; - SaClmCallbacksT callbacks; - int finalize; - pthread_mutex_t response_mutex; - pthread_mutex_t dispatch_mutex; -}; - -static void clmHandleInstanceDestructor (void *); - -static struct saHandleDatabase clmHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = clmHandleInstanceDestructor -}; - -/* - * Versions supported - */ -static SaVersionT clmVersionsSupported[] = { - { 'B', 1, 1 } -}; - -static struct saVersionDatabase clmVersionDatabase = { - sizeof (clmVersionsSupported) / sizeof (SaVersionT), - clmVersionsSupported -}; - -void clmHandleInstanceDestructor (void *instance) -{ - struct clmInstance *clmInstance = instance; - - pthread_mutex_destroy (&clmInstance->response_mutex); - pthread_mutex_destroy (&clmInstance->dispatch_mutex); -} - - -/** - * @defgroup saClm SAF AIS Cluster Membership API - * @ingroup saf - * - * @{ - */ -/** - * This function initializes the Cluster Membership Service for the invoking - * process and registers the various callback functions. This function must - * be invoked prior to the invocation of any other Cluster Membership Service - * functionality. The handle clmHandle is returned as the reference to this - * association between the process and the Cluster Membership Service. The - * process uses this handle in subsequent communication with the Cluster - * Membership Service. - * - * @param clmHandle A pointer to the handle designating this particular - * initialization of the Cluster Membership Service that is to be - * returned by the Cluster Membership Service. - * @param clmCallbacks If clmCallbacks is set to NULL, no callback is - * registered; otherise, it is a pointer to an SaClmCallbacksT structure, - * containing the callback functions of the process that the Cluster - * Membership Service may invoke. Only non-NULL callback functions - * in this structure will be registered. - * @param version The version requested from the application is passed into - * this parameter and the version supported is returned. - * - * @returns SA_AIS_OK if the function completed successfully. - * @returns SA_AIS_ERR_LIBRARY if an unexpected problem occurred in - * the library. - * @returns SA_AIS_ERR_TRY_AGAIN if the service cannot be provided at this - * time. - * @returns SA_AIS_ERR_INVALID_PARAM if a parameter is not set correctly. - * @returns SA_AIS_ERR_NO_MEMORY if the Cluster Membership Service is out - * of memory and cannot provide the service. - * @returns SA_AIS_ERR_VERSION if the version parameter is not compatible with - * the version of the Cluster Membership Service implementation. - */ -SaAisErrorT -saClmInitialize ( - SaClmHandleT *clmHandle, - const SaClmCallbacksT *clmCallbacks, - SaVersionT *version) -{ - struct clmInstance *clmInstance; - SaAisErrorT error = SA_AIS_OK; - - - if (clmHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - if (version == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saVersionVerify (&clmVersionDatabase, version); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleCreate (&clmHandleDatabase, sizeof (struct clmInstance), - clmHandle); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleInstanceGet (&clmHandleDatabase, *clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - clmInstance->response_fd = -1; - - clmInstance->dispatch_fd = -1; - - error = saServiceConnect (&clmInstance->response_fd, - &clmInstance->dispatch_fd, CLM_SERVICE); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - if (clmCallbacks) { - memcpy (&clmInstance->callbacks, clmCallbacks, sizeof (SaClmCallbacksT)); - } else { - memset (&clmInstance->callbacks, 0, sizeof (SaClmCallbacksT)); - } - - pthread_mutex_init (&clmInstance->response_mutex, NULL); - - pthread_mutex_init (&clmInstance->dispatch_mutex, NULL); - - saHandleInstancePut (&clmHandleDatabase, *clmHandle); - - return (SA_AIS_OK); - -error_put_destroy: - saHandleInstancePut (&clmHandleDatabase, *clmHandle); -error_destroy: - saHandleDestroy (&clmHandleDatabase, *clmHandle); -error_no_destroy: - return (error); -} - -/** - * This function returns the operating system handle, selectionObject, - * assocated with the handle clmHandle. The invoking process can use this - * handle to detect pending callbacks, instead of repeatedly invoking - * saClmDispatch() for this purpose. - * - * In a POSIX environment, the operating system handle is a file descriptor - * that is used with the poll() or select() system calls to detect pending - * callbacks. - * - * The selectionObject returned by saClmSelectionObjectGet() is valid until - * saClmFinalize() is invoked on the same handle clmHandle. - * - * @param clmHandle The handle, obtained through the saClmInitialize function, - * designating this particular initialization of the Cluster Membership - * @param selectionObject A pointer to the operating system handle that the - * invoking process can use to detect pending callbacks. - * - * @returns SA_AIS_OK if the function completed successfully. - * @returns SA_AIS_ERR_BAD_HANDLE if the handle clmHandle is invalid, since it is - * corrupted, uninitialized, or has already been finalized. - */ -SaAisErrorT -saClmSelectionObjectGet ( - SaClmHandleT clmHandle, - SaSelectionObjectT *selectionObject) -{ - struct clmInstance *clmInstance; - SaAisErrorT error; - - if (selectionObject == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - *selectionObject = clmInstance->dispatch_fd; - - saHandleInstancePut (&clmHandleDatabase, clmHandle); - return (SA_AIS_OK); -} - -/** - * This function invokes, in the context of the calling thread, pending callbacks for - * the handle clmhandle in a way that is specified by the dispatchFlags parameter. - * - * @param clmHandle The handle, obtained through the saClmInitialize() function, - * designating the particular initialization of the Cluster Membership Service. - * @param dispatchFlags Flags that specify the callback exection behavior of - * saClmDispatch, which have the values SA_DISPATCH_ONE, SA_DISPATCH_ALL, or - * SA_DISPATCH_BLOCKING. - * @returns SA_AIS_OK if the function completed successfully. - * @returns SA_AIS_ERR_TRY_AGAIN if the service cannot be provided at this time. The - * process may retry later. - * @returns SA_AIS_ERR_BAD_HANDLE if the handle clmHandle is invalid, since it is - * corrupted, uninitialized, or has already been finalized. - * @returns SA_AIS_ERR_INVALID_PARAM if the dispatchFlags parameter is valid. - */ -SaAisErrorT -saClmDispatch ( - SaClmHandleT clmHandle, - SaDispatchFlagsT dispatchFlags) -{ - struct pollfd ufds; - int timeout = -1; - SaAisErrorT error; - int cont = 1; /* always continue do loop except when set to 0 */ - int dispatch_avail; - struct clmInstance *clmInstance; - struct res_lib_clm_clustertrack *res_lib_clm_clustertrack; - struct res_clm_nodegetcallback *res_clm_nodegetcallback; - SaClmCallbacksT callbacks; - struct res_overlay dispatch_data; - SaClmClusterNotificationBufferT notificationBuffer; - SaClmClusterNotificationT notification[PROCESSOR_COUNT_MAX]; - SaClmClusterNodeT clusterNode; - int items_to_copy; - unsigned int i; - - if (dispatchFlags != SA_DISPATCH_ONE && - dispatchFlags != SA_DISPATCH_ALL && - dispatchFlags != SA_DISPATCH_BLOCKING) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* - * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and - * wait indefinately for SA_DISPATCH_BLOCKING - */ - if (dispatchFlags == SA_DISPATCH_ALL) { - timeout = 0; - } - - do { - ufds.fd = clmInstance->dispatch_fd; - ufds.events = POLLIN; - ufds.revents = 0; - - pthread_mutex_lock (&clmInstance->dispatch_mutex); - - error = saPollRetry (&ufds, 1, timeout); - if (error != SA_AIS_OK) { - goto error_unlock; - } - - /* - * Handle has been finalized in another thread - */ - if (clmInstance->finalize == 1) { - error = SA_AIS_OK; - goto error_unlock; - } - - if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_unlock; - } - - dispatch_avail = ufds.revents & POLLIN; - if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) { - pthread_mutex_unlock (&clmInstance->dispatch_mutex); - break; /* exit do while cont is 1 loop */ - } else - if (dispatch_avail == 0) { - pthread_mutex_unlock (&clmInstance->dispatch_mutex); - continue; /* next poll */ - } - - if (ufds.revents & POLLIN) { - error = saRecvRetry (clmInstance->dispatch_fd, &dispatch_data.header, - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - if (dispatch_data.header.size > sizeof (mar_res_header_t)) { - error = saRecvRetry (clmInstance->dispatch_fd, &dispatch_data.data, - dispatch_data.header.size - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - } - } else { - pthread_mutex_unlock (&clmInstance->dispatch_mutex); - continue; - } - - /* - * Make copy of callbacks, message data, unlock instance, and call callback - * A risk of this dispatch method is that the callback routines may - * operate at the same time that clmFinalize has been called in another thread. - */ - memcpy (&callbacks, &clmInstance->callbacks, sizeof (SaClmCallbacksT)); - pthread_mutex_unlock (&clmInstance->dispatch_mutex); - - /* - * Dispatch incoming message - */ - switch (dispatch_data.header.id) { - - case MESSAGE_RES_CLM_TRACKCALLBACK: - if (callbacks.saClmClusterTrackCallback == NULL) { - continue; - } - res_lib_clm_clustertrack = (struct res_lib_clm_clustertrack *)&dispatch_data; - error = SA_AIS_OK; - - notificationBuffer.notification = notification; - - notificationBuffer.viewNumber = res_lib_clm_clustertrack->view; - notificationBuffer.notification = notification; - notificationBuffer.numberOfItems = - res_lib_clm_clustertrack->number_of_items; - - items_to_copy = notificationBuffer.numberOfItems - < res_lib_clm_clustertrack->number_of_items ? - notificationBuffer.numberOfItems : - res_lib_clm_clustertrack->number_of_items; - - for (i = 0; i < items_to_copy; i++) { - marshall_from_mar_clm_cluster_notification_t ( - ¬ificationBuffer.notification[i], - &res_lib_clm_clustertrack->notification[i]); - } - - callbacks.saClmClusterTrackCallback ( - (const SaClmClusterNotificationBufferT *)¬ificationBuffer, - res_lib_clm_clustertrack->number_of_items, error); - - break; - - case MESSAGE_RES_CLM_NODEGETCALLBACK: - if (callbacks.saClmClusterNodeGetCallback == NULL) { - continue; - } - res_clm_nodegetcallback = (struct res_clm_nodegetcallback *)&dispatch_data; - marshall_from_mar_clm_cluster_node_t ( - &clusterNode, - &res_clm_nodegetcallback->cluster_node); - - callbacks.saClmClusterNodeGetCallback ( - res_clm_nodegetcallback->invocation, - &clusterNode, - res_clm_nodegetcallback->header.error); - break; - - default: - error = SA_AIS_ERR_LIBRARY; - goto error_put; - break; - } - - /* - * Determine if more messages should be processed - * */ - switch (dispatchFlags) { - case SA_DISPATCH_ONE: - cont = 0; - break; - case SA_DISPATCH_ALL: - break; - case SA_DISPATCH_BLOCKING: - break; - } - } while (cont); - - goto error_put; - -error_unlock: - pthread_mutex_unlock (&clmInstance->dispatch_mutex); - -error_put: - saHandleInstancePut (&clmHandleDatabase, clmHandle); - return (error); -} - - -/** - * The saClmFinalize function closes the assocation, represented by the clmHandle - * parameter, between the invoking process and the Cluster Membership Service. The - * process must have invoked saClmInitialize before it invokes this function. A - * process must invoke this function once for each handle it acquired by invoking - * saClmInitialize(). - * - * If the saClmFinalize() function returns successfully, the saClmFinalize() function - * releases all resources acquired when saClmInitialize(0 was called. Moreover, it - * stops any tracking associated with the particular handle. Furthermore, it cancels - * all pending callbacks related to the particular handle. Note that because the - * callback invocation is asynchronous, it is still possible that some callback calls - * are processed after this call returns successfully. - * - * After saClmFinalize() is invoked, the selection object is no longer valid. - * - * @param clmHandle The handle, obtained through the saClmInitialize() function, - * designating this particular initialization of the Cluster Membership Service. - * - * @returns SA_AIS_OK if the function completed successfully. - * @returns SA_AIS_ERR_BAD_HANDLE if the handle clmHandle is invalid, since it is - * corrupted, uninitialized, or has already been finalized. - */ -SaAisErrorT -saClmFinalize ( - SaClmHandleT clmHandle) -{ - struct clmInstance *clmInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&clmInstance->response_mutex); - - /* - * Another thread has already started finalizing - */ - if (clmInstance->finalize) { - pthread_mutex_unlock (&clmInstance->response_mutex); - saHandleInstancePut (&clmHandleDatabase, clmHandle); - return (SA_AIS_ERR_BAD_HANDLE); - } - - clmInstance->finalize = 1; - - pthread_mutex_unlock (&clmInstance->response_mutex); - - saHandleDestroy (&clmHandleDatabase, clmHandle); - - if (clmInstance->response_fd != -1) { - shutdown (clmInstance->response_fd, 0); - close (clmInstance->response_fd); - } - if (clmInstance->dispatch_fd != -1) { - shutdown (clmInstance->dispatch_fd, 0); - close (clmInstance->dispatch_fd); - } - - saHandleInstancePut (&clmHandleDatabase, clmHandle); - - return (error); -} - -SaAisErrorT -saClmClusterTrack ( - SaClmHandleT clmHandle, - SaUint8T trackFlags, - SaClmClusterNotificationBufferT *notificationBuffer) -{ - struct req_lib_clm_clustertrack req_lib_clm_clustertrack; - struct res_lib_clm_clustertrack res_lib_clm_clustertrack; - struct clmInstance *clmInstance; - SaAisErrorT error = SA_AIS_OK; - int items_to_copy; - unsigned int i; - - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - if ((trackFlags & SA_TRACK_CHANGES) && (trackFlags & SA_TRACK_CHANGES_ONLY)) { - error = SA_AIS_ERR_BAD_FLAGS; - goto error_nounlock; - } - - if (trackFlags & ~(SA_TRACK_CURRENT | SA_TRACK_CHANGES | SA_TRACK_CHANGES_ONLY)) { - error = SA_AIS_ERR_BAD_FLAGS; - goto error_nounlock; - } - - if ((notificationBuffer != NULL) && - (notificationBuffer->notification != NULL) && - (notificationBuffer->numberOfItems == 0)) { - - error = SA_AIS_ERR_INVALID_PARAM; - goto error_nounlock; - } - - req_lib_clm_clustertrack.header.size = sizeof (struct req_lib_clm_clustertrack); - req_lib_clm_clustertrack.header.id = MESSAGE_REQ_CLM_TRACKSTART; - req_lib_clm_clustertrack.track_flags = trackFlags; - req_lib_clm_clustertrack.return_in_callback = 0; - if ((trackFlags & SA_TRACK_CURRENT) && (notificationBuffer == NULL)) { - req_lib_clm_clustertrack.return_in_callback = 1; - } - - pthread_mutex_lock (&clmInstance->response_mutex); - - if ((clmInstance->callbacks.saClmClusterTrackCallback == 0) && - ((notificationBuffer == NULL) || - (trackFlags & (SA_TRACK_CHANGES | SA_TRACK_CHANGES_ONLY)))) { - - error = SA_AIS_ERR_INIT; - goto error_exit; - } - - error = saSendReceiveReply (clmInstance->response_fd, - &req_lib_clm_clustertrack, - sizeof (struct req_lib_clm_clustertrack), - &res_lib_clm_clustertrack, - sizeof (struct res_lib_clm_clustertrack)); - - if ((trackFlags & SA_TRACK_CURRENT) && (notificationBuffer != NULL)) { - if (notificationBuffer->notification == 0) { - notificationBuffer->viewNumber = res_lib_clm_clustertrack.view; - - notificationBuffer->notification = - malloc (res_lib_clm_clustertrack.number_of_items * - sizeof (SaClmClusterNotificationT)); - - notificationBuffer->numberOfItems = - res_lib_clm_clustertrack.number_of_items; - } - - items_to_copy = notificationBuffer->numberOfItems < - res_lib_clm_clustertrack.number_of_items ? - notificationBuffer->numberOfItems : - res_lib_clm_clustertrack.number_of_items; - - for (i = 0; i < items_to_copy; i++) { - marshall_from_mar_clm_cluster_notification_t ( - ¬ificationBuffer->notification[i], - &res_lib_clm_clustertrack.notification[i]); - } - - notificationBuffer->viewNumber = res_lib_clm_clustertrack.view; - notificationBuffer->numberOfItems = items_to_copy; - } - -error_exit: - pthread_mutex_unlock (&clmInstance->response_mutex); - -error_nounlock: - saHandleInstancePut (&clmHandleDatabase, clmHandle); - - return (error == SA_AIS_OK ? res_lib_clm_clustertrack.header.error : error); -} - -SaAisErrorT -saClmClusterTrackStop ( - SaClmHandleT clmHandle) -{ - struct clmInstance *clmInstance; - struct req_lib_clm_trackstop req_lib_clm_trackstop; - struct res_lib_clm_trackstop res_lib_clm_trackstop; - SaAisErrorT error = SA_AIS_OK; - - req_lib_clm_trackstop.header.size = sizeof (struct req_lib_clm_trackstop); - req_lib_clm_trackstop.header.id = MESSAGE_REQ_CLM_TRACKSTOP; - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&clmInstance->response_mutex); - - error = saSendReceiveReply (clmInstance->response_fd, - &req_lib_clm_trackstop, - sizeof (struct req_lib_clm_trackstop), - &res_lib_clm_trackstop, - sizeof (struct res_lib_clm_trackstop)); - - pthread_mutex_unlock (&clmInstance->response_mutex); - - saHandleInstancePut (&clmHandleDatabase, clmHandle); - - return (error == SA_AIS_OK ? res_lib_clm_trackstop.header.error : error); -} - -SaAisErrorT -saClmClusterNodeGet ( - SaClmHandleT clmHandle, - SaClmNodeIdT nodeId, - SaTimeT timeout, - SaClmClusterNodeT *clusterNode) -{ - struct clmInstance *clmInstance; - struct req_lib_clm_nodeget req_lib_clm_nodeget; - struct res_clm_nodeget res_clm_nodeget; - SaAisErrorT error = SA_AIS_OK; - - if (clusterNode == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (timeout == 0) { - return (SA_AIS_ERR_TIMEOUT); - } - - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&clmInstance->response_mutex); - - /* - * Send request message - */ - req_lib_clm_nodeget.header.size = sizeof (struct req_lib_clm_nodeget); - req_lib_clm_nodeget.header.id = MESSAGE_REQ_CLM_NODEGET; - req_lib_clm_nodeget.node_id = nodeId; - - error = saSendReceiveReply (clmInstance->response_fd, &req_lib_clm_nodeget, - sizeof (struct req_lib_clm_nodeget), &res_clm_nodeget, sizeof (res_clm_nodeget)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = res_clm_nodeget.header.error; - - marshall_from_mar_clm_cluster_node_t (clusterNode, - &res_clm_nodeget.cluster_node); - -error_exit: - pthread_mutex_unlock (&clmInstance->response_mutex); - - saHandleInstancePut (&clmHandleDatabase, clmHandle); - - return (error); -} - -SaAisErrorT -saClmClusterNodeGetAsync ( - SaClmHandleT clmHandle, - SaInvocationT invocation, - SaClmNodeIdT nodeId) -{ - struct clmInstance *clmInstance; - struct req_lib_clm_nodegetasync req_lib_clm_nodegetasync; - struct res_clm_nodegetasync res_clm_nodegetasync; - SaAisErrorT error = SA_AIS_OK; - - req_lib_clm_nodegetasync.header.size = sizeof (struct req_lib_clm_nodegetasync); - req_lib_clm_nodegetasync.header.id = MESSAGE_REQ_CLM_NODEGETASYNC; - req_lib_clm_nodegetasync.invocation = invocation; - req_lib_clm_nodegetasync.node_id = nodeId; - - error = saHandleInstanceGet (&clmHandleDatabase, clmHandle, - (void *)&clmInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&clmInstance->response_mutex); - - if (clmInstance->callbacks.saClmClusterNodeGetCallback == NULL) { - error = SA_AIS_ERR_INIT; - goto error_exit; - } - - error = saSendReceiveReply (clmInstance->response_fd, &req_lib_clm_nodegetasync, - sizeof (struct req_lib_clm_nodegetasync), - &res_clm_nodegetasync, sizeof (struct res_clm_nodegetasync)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = res_clm_nodegetasync.header.error; - -error_exit: - pthread_mutex_unlock (&clmInstance->response_mutex); - - saHandleInstancePut (&clmHandleDatabase, clmHandle); - - return (error); -} - -/** @} */ diff --git a/openais/lib/evt.c b/openais/lib/evt.c deleted file mode 100644 index 73c52c1c..00000000 --- a/openais/lib/evt.c +++ /dev/null @@ -1,2285 +0,0 @@ -/* - * Copyright (c) 2004-2005 Mark Haverkamp - * Copyright (c) 2004-2005 Open Source Development Lab - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the Open Source Developement Lab nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/ipc_evt.h" - -#define MESSAGE_SIZE_MAX 1024*1024 - -static void evtHandleInstanceDestructor(void *instance); -static void chanHandleInstanceDestructor(void *instance); -static void eventHandleInstanceDestructor(void *instance); - -/* - * Versions of the SAF AIS specification supported by this library - */ -static SaVersionT supported_versions[] = { - {'B', 0x01, 0x01} -}; - -static struct saVersionDatabase evt_version_database = { - sizeof(supported_versions) / sizeof(SaVersionT), - supported_versions -}; - -/* - * Event instance data - */ -struct saHandleDatabase evt_instance_handle_db = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = evtHandleInstanceDestructor -}; - -/* - * Channel instance data - */ -struct saHandleDatabase channel_handle_db = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = chanHandleInstanceDestructor -}; - -/* - * Event instance data - */ -struct saHandleDatabase event_handle_db = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = eventHandleInstanceDestructor -}; - -struct res_overlay { - mar_res_header_t header __attribute__((aligned(8))); - char data[MESSAGE_SIZE_MAX]; -}; - -struct handle_list { - SaUint64T hl_handle; - struct list_head hl_entry; -}; - -/* - * data required to support events for a given initialization - * - * ei_dispatch_fd: fd used for getting callback data e.g. async event data - * ei_response_fd: fd used for everything else (i.e. evt sync api commands). - * ei_callback: callback function. - * ei_version: version sent to the evtInitialize call. - * ei_node_id: our node id. - * ei_node_name: our node name. - * ei_dispatch_mutex: mutex for dispatch fd. This lock also ensures that - * only one thread is using ei_dispatch_data. - * ei_response_mutex: mutex for response fd - * ei_channel_list: list of associated channels (struct handle_list) - * ei_dispatch_data: event buffer for evtDispatch - * ei_finalize: instance in finalize flag - * ei_data_available: Indicates that there is a pending event message though - * there may not be a poll event. This can happen - * when we get a SA_AIS_ERR_TRY_AGAIN when asking for an - * event. - * - */ -struct event_instance { - int ei_dispatch_fd; - int ei_response_fd; - SaEvtCallbacksT ei_callback; - SaVersionT ei_version; - SaClmNodeIdT ei_node_id; - SaNameT ei_node_name; - pthread_mutex_t ei_dispatch_mutex; - pthread_mutex_t ei_response_mutex; - struct list_head ei_channel_list; - struct res_overlay ei_dispatch_data; - unsigned int ei_finalize:1; - unsigned int ei_data_available:1; -}; - - -/* - * Data associated with an opened channel - * - * eci_channel_name: name of channel - * eci_open_flags: channel open flags - * eci_svr_channel_handle: channel handle returned from server - * eci_closing: channel in process of being closed - * eci_mutex: channel mutex - * eci_event_list: events associated with this - * channel (struct handle_list) - * eci_hl: pointer to event instance handle struct - * for this channel. - */ -struct event_channel_instance { - - SaNameT eci_channel_name; - SaEvtChannelOpenFlagsT eci_open_flags; - uint32_t eci_svr_channel_handle; - SaEvtHandleT eci_instance_handle; - int eci_closing; - pthread_mutex_t eci_mutex; - struct list_head eci_event_list; - struct handle_list *eci_hl; - -}; - -/* - * Event data. - * - * Store event data from saEvtEventAllocate function. - * Store event data from received events. - * - * edi_channel_handle: handle (local) of assocated channel - * edi_patterns: event patterns - * edi_priority: event priority - * edi_retention_time: event's retention time - * edi_pub_name: event's publisher name - * edi_pub_node: event's publisher node - * edi_pub_time: event's publish time - * edi_event_id: event's Id - * edi_event_data: event's data - * edi_event_data_size: size of edi_event_data - * edi_freeing: event is being freed - * edi_mutex: event data mutex - * edi_hl: pointer to channel's handle - * struct for this event. - * edi_ro: read only flag - */ -struct event_data_instance { - SaEvtChannelHandleT edi_channel_handle; - SaEvtEventPatternArrayT edi_patterns; - SaUint8T edi_priority; - SaTimeT edi_retention_time; - SaNameT edi_pub_name; - SaClmNodeIdT edi_pub_node; - SaTimeT edi_pub_time; - SaEvtEventIdT edi_event_id; - void *edi_event_data; - SaSizeT edi_event_data_size; - int edi_freeing; - pthread_mutex_t edi_mutex; - struct handle_list *edi_hl; - int edi_ro; -}; - - -#define min(a,b) ((a) < (b) ? (a) : (b)) - -static inline int is_valid_event_id(SaEvtEventIdT evt_id) -{ - if (evt_id > 1000) { - return 1; - } else { - return 0; - } -} - -/* - * Clean up function for an evt instance (saEvtInitialize) handle - * Not to be confused with event data. - */ -static void evtHandleInstanceDestructor(void *instance) -{ - struct event_instance *evti = instance; - struct event_channel_instance *eci; - struct handle_list *hl; - struct list_head *l, *nxt; - uint64_t handle; - SaAisErrorT error; - - /* - * Free up any channel data - */ - for (l = evti->ei_channel_list.next; - l != &evti->ei_channel_list; l = nxt) { - nxt = l->next; - - hl = list_entry(l, struct handle_list, hl_entry); - handle = hl->hl_handle; - error = saHandleInstanceGet(&channel_handle_db, hl->hl_handle, - (void*)&eci); - if (error != SA_AIS_OK) { - /* - * already gone - */ - continue; - } - saHandleDestroy(&channel_handle_db, handle); - saHandleInstancePut(&channel_handle_db, handle); - } - - pthread_mutex_destroy(&evti->ei_dispatch_mutex); - pthread_mutex_destroy(&evti->ei_response_mutex); -} - -/* - * Clean up function for an open channel handle - */ -static void chanHandleInstanceDestructor(void *instance) -{ - struct event_channel_instance *eci = instance; - struct list_head *l, *nxt; - struct handle_list *hl; - uint64_t handle; - - if (eci->eci_hl) { - list_del(&eci->eci_hl->hl_entry); - free(eci->eci_hl); - eci->eci_hl = 0; - } - /* - * Free up any channel associated events - */ - for (l = eci->eci_event_list.next; l != &eci->eci_event_list; l = nxt) { - nxt = l->next; - hl = list_entry(l, struct handle_list, hl_entry); - handle = hl->hl_handle; - saEvtEventFree(handle); - } - - pthread_mutex_destroy(&eci->eci_mutex); -} - -/* - * Clean up function for an event handle - */ -static void eventHandleInstanceDestructor(void *instance) -{ - struct event_data_instance *edi = instance; - int i; - - if (edi->edi_hl) { - list_del(&edi->edi_hl->hl_entry); - free(edi->edi_hl); - edi->edi_hl = 0; - } - if (edi->edi_patterns.patterns) { - for (i = 0; i < edi->edi_patterns.patternsNumber; i++) { - free(edi->edi_patterns.patterns[i].pattern); - } - free(edi->edi_patterns.patterns); - } - if (edi->edi_event_data) { - free(edi->edi_event_data); - } - - pthread_mutex_destroy(&edi->edi_mutex); -} - -static SaAisErrorT evt_recv_event(int fd, struct lib_event_data **msg) -{ - SaAisErrorT error; - mar_res_header_t hdr; - void *data; - - error = saRecvRetry(fd, &hdr, sizeof(hdr)); - if (error != SA_AIS_OK) { - goto msg_out; - } - *msg = malloc(hdr.size); - if (!*msg) { - error = SA_AIS_ERR_LIBRARY; - goto msg_out; - } - data = (void *)((unsigned long)*msg) + sizeof(hdr); - memcpy(*msg, &hdr, sizeof(hdr)); - if (hdr.size > sizeof(hdr)) { - error = saRecvRetry(fd, data, hdr.size - sizeof(hdr)); - if (error != SA_AIS_OK) { - goto msg_out; - } - } -msg_out: - return error; -} - -/* - * The saEvtInitialize() function initializes the Event Service for the - * invoking process. A user of the Event Service must invoke this function - * before it invokes any other function of the Event Service API. Each - * initialization returns a different callback handle that the process - * can use to communicate with that library instance. - */ - -SaAisErrorT -saEvtInitialize( - SaEvtHandleT *evtHandle, - const SaEvtCallbacksT *callbacks, - SaVersionT *version) -{ - SaAisErrorT error = SA_AIS_OK; - struct event_instance *evti; - - if (!version || !evtHandle) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_nofree; - } - /* - * validate the requested version with what we support - */ - error = saVersionVerify(&evt_version_database, version); - if (error != SA_AIS_OK) { - goto error_nofree; - } - - /* - * Allocate instance data, allocate unique handle for instance, - * assign instance data to unique handle - */ - error = saHandleCreate(&evt_instance_handle_db, sizeof(*evti), - evtHandle); - if (error != SA_AIS_OK) { - goto error_nofree; - } - error = saHandleInstanceGet(&evt_instance_handle_db, *evtHandle, - (void*)&evti); - if (error != SA_AIS_OK) { - if (error == SA_AIS_ERR_BAD_HANDLE) { - error = SA_AIS_ERR_LIBRARY; - } - goto error_handle_free; - } - memset(evti, 0, sizeof(*evti)); - - list_init(&evti->ei_channel_list); - - /* - * Save the version so we can check with the event server - * and see if it supports this version. - */ - evti->ei_version = *version; - - /* - * Set up communication with the event server - */ - error = saServiceConnect(&evti->ei_response_fd, - &evti->ei_dispatch_fd, EVT_SERVICE); - if (error != SA_AIS_OK) { - goto error_handle_put; - } - - /* - * The callback function is saved in the event instance for - * saEvtDispatch() to use. - */ - if (callbacks) { - memcpy(&evti->ei_callback, callbacks, - sizeof(evti->ei_callback)); - } - - pthread_mutex_init(&evti->ei_dispatch_mutex, NULL); - pthread_mutex_init(&evti->ei_response_mutex, NULL); - saHandleInstancePut(&evt_instance_handle_db, *evtHandle); - - return SA_AIS_OK; - -error_handle_put: - saHandleInstancePut(&evt_instance_handle_db, *evtHandle); -error_handle_free: - (void)saHandleDestroy(&evt_instance_handle_db, *evtHandle); -error_nofree: - return error; -} - -/* - * The saEvtSelectionObjectGet() function returns the operating system - * handle selectionObject, associated with the handle evtHandle, allowing - * the invoking process to ascertain when callbacks are pending. This - * function allows a process to avoid repeated invoking saEvtDispatch() to - * see if there is a new event, thus, needlessly consuming CPU time. In a - * POSIX environment the system handle could be a file descriptor that is - * used with the poll() or select() system calls to detect incoming callbacks. - */ -SaAisErrorT -saEvtSelectionObjectGet( - SaEvtHandleT evtHandle, - SaSelectionObjectT *selectionObject) -{ - struct event_instance *evti; - SaAisErrorT error; - - if (!selectionObject) { - return SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle, - (void *)&evti); - - if (error != SA_AIS_OK) { - return error; - } - - *selectionObject = evti->ei_dispatch_fd; - - saHandleInstancePut(&evt_instance_handle_db, evtHandle); - - return SA_AIS_OK; -} - - -/* - * Alocate an event data structure and associated handle to be - * used to supply event data to a call back function. - */ -static SaAisErrorT make_event(SaEvtEventHandleT *event_handle, - struct lib_event_data *evt) -{ - struct event_data_instance *edi; - struct event_channel_instance *eci; - mar_evt_event_pattern_t *pat; - SaUint8T *str; - SaAisErrorT error; - struct handle_list *hl; - int i; - - error = saHandleCreate(&event_handle_db, sizeof(*edi), - event_handle); - if (error != SA_AIS_OK) { - if (error == SA_AIS_ERR_NO_MEMORY) { - error = SA_AIS_ERR_LIBRARY; - } - goto make_evt_done; - } - - error = saHandleInstanceGet(&event_handle_db, *event_handle, - (void*)&edi); - if (error != SA_AIS_OK) { - saHandleDestroy(&event_handle_db, *event_handle); - goto make_evt_done; - } - - error = saHandleInstanceGet(&channel_handle_db, - evt->led_lib_channel_handle, - (void*)&eci); - if (error != SA_AIS_OK) { - saHandleDestroy(&event_handle_db, *event_handle); - goto make_evt_done_put; - } - - pthread_mutex_init(&edi->edi_mutex, NULL); - edi->edi_ro = 1; - edi->edi_freeing = 0; - edi->edi_channel_handle = evt->led_lib_channel_handle; - edi->edi_priority = evt->led_priority; - edi->edi_retention_time = evt->led_retention_time; - edi->edi_pub_node = evt->led_publisher_node_id; - edi->edi_pub_time = evt->led_publish_time; - edi->edi_event_data_size = evt->led_user_data_size; - edi->edi_event_id = evt->led_event_id; - marshall_from_mar_name_t (&edi->edi_pub_name, &evt->led_publisher_name); - - if (edi->edi_event_data_size) { - edi->edi_event_data = malloc(edi->edi_event_data_size); - if (!edi->edi_event_data) { - saHandleDestroy(&event_handle_db, *event_handle); - - /* - * saEvtDispatch doesn't return SA_AIS_ERR_NO_MEMORY - */ - error = SA_AIS_ERR_LIBRARY; - goto make_evt_done_put2; - } - memcpy(edi->edi_event_data, - evt->led_body + evt->led_user_data_offset, - edi->edi_event_data_size); - } - - /* - * Move the pattern bits into the SaEvtEventPatternArrayT - */ - edi->edi_patterns.patternsNumber = evt->led_patterns_number; - edi->edi_patterns.allocatedNumber = evt->led_patterns_number; - edi->edi_patterns.patterns = malloc(sizeof(SaEvtEventPatternT) * - edi->edi_patterns.patternsNumber); - if (!edi->edi_patterns.patterns) { - /* - * The destructor will take care of freeing event data already - * allocated. - */ - edi->edi_patterns.patternsNumber = 0; - saHandleDestroy(&event_handle_db, *event_handle); - - /* - * saEvtDispatch doesn't return SA_AIS_ERR_NO_MEMORY - */ - error = SA_AIS_ERR_LIBRARY; - goto make_evt_done_put2; - } - memset(edi->edi_patterns.patterns, 0, sizeof(SaEvtEventPatternT) * - edi->edi_patterns.patternsNumber); - pat = (mar_evt_event_pattern_t *)evt->led_body; - str = evt->led_body + sizeof(mar_evt_event_pattern_t) * - edi->edi_patterns.patternsNumber; - for (i = 0; i < evt->led_patterns_number; i++) { - edi->edi_patterns.patterns[i].patternSize = pat->pattern_size; - edi->edi_patterns.patterns[i].allocatedSize = pat->pattern_size; - edi->edi_patterns.patterns[i].pattern = malloc(pat->pattern_size); - if (!edi->edi_patterns.patterns[i].pattern) { - DPRINT (("make_event: couldn't alloc %llu bytes\n", - (unsigned long long)pat->pattern_size)); - saHandleDestroy(&event_handle_db, *event_handle); - error = SA_AIS_ERR_LIBRARY; - goto make_evt_done_put2; - } - memcpy(edi->edi_patterns.patterns[i].pattern, - str, pat->pattern_size); - str += pat->pattern_size; - pat++; - } - - hl = malloc(sizeof(*hl)); - if (!hl) { - saHandleDestroy(&event_handle_db, *event_handle); - error = SA_AIS_ERR_LIBRARY; - } else { - edi->edi_hl = hl; - hl->hl_handle = *event_handle; - list_init(&hl->hl_entry); - list_add(&hl->hl_entry, &eci->eci_event_list); - } - -make_evt_done_put2: - saHandleInstancePut (&channel_handle_db, evt->led_lib_channel_handle); - -make_evt_done_put: - saHandleInstancePut (&event_handle_db, *event_handle); - -make_evt_done: - return error; -} - -/* - * The saEvtDispatch() function invokes, in the context of the calling - * thread, one or all of the pending callbacks for the handle evtHandle. - */ -SaAisErrorT -saEvtDispatch( - SaEvtHandleT evtHandle, - SaDispatchFlagsT dispatchFlags) -{ - struct pollfd ufds; - int timeout = -1; - SaAisErrorT error; - int dispatch_avail; - struct event_instance *evti; - SaEvtEventHandleT event_handle; - SaEvtCallbacksT callbacks; - int ignore_dispatch = 0; - int cont = 1; /* always continue do loop except when set to 0 */ - int poll_fd; - struct lib_event_data *evt = 0; - struct res_evt_event_data res; - - if (dispatchFlags < SA_DISPATCH_ONE || - dispatchFlags > SA_DISPATCH_BLOCKING) { - return SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle, - (void *)&evti); - if (error != SA_AIS_OK) { - return error; - } - - /* - * Timeout instantly for SA_DISPATCH_ALL - */ - if (dispatchFlags == SA_DISPATCH_ALL || dispatchFlags == SA_DISPATCH_ONE) { - timeout = 0; - } - - do { - poll_fd = evti->ei_dispatch_fd; - - ufds.fd = poll_fd; - ufds.events = POLLIN; - ufds.revents = 0; - - error = saPollRetry(&ufds, 1, timeout); - if (error != SA_AIS_OK) { - goto dispatch_put; - } - - pthread_mutex_lock(&evti->ei_dispatch_mutex); - - /* - * Handle has been finalized in another thread - */ - if (evti->ei_finalize == 1) { - error = SA_AIS_OK; - goto dispatch_unlock; - } - - /* - * If we know that we have an event waiting, we can skip the - * polling and just ask for it. - */ - if (!evti->ei_data_available) { - /* - * Check the poll data in case the fd status has changed - * since taking the lock - */ - error = saPollRetry(&ufds, 1, 0); - if (error != SA_AIS_OK) { - goto dispatch_unlock; - } - - if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto dispatch_unlock; - } - - dispatch_avail = ufds.revents & POLLIN; - if (dispatch_avail == 0 && - (dispatchFlags == SA_DISPATCH_ALL || - dispatchFlags == SA_DISPATCH_ONE)) { - pthread_mutex_unlock(&evti->ei_dispatch_mutex); - break; /* exit do while cont is 1 loop */ - } else if (dispatch_avail == 0) { - pthread_mutex_unlock(&evti->ei_dispatch_mutex); - continue; /* next poll */ - } - - if (ufds.revents & POLLIN) { - error = saRecvRetry (evti->ei_dispatch_fd, &evti->ei_dispatch_data.header, - sizeof (mar_res_header_t)); - - if (error != SA_AIS_OK) { - goto dispatch_unlock; - } - if (evti->ei_dispatch_data.header.size > sizeof (mar_res_header_t)) { - error = saRecvRetry (evti->ei_dispatch_fd, &evti->ei_dispatch_data.data, - evti->ei_dispatch_data.header.size - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto dispatch_unlock; - } - } - } else { - pthread_mutex_unlock(&evti->ei_dispatch_mutex); - continue; - } - } else { - /* - * We know that we have an event available from before. - * Fake up a header message and the switch statement will - * take care of the rest. - */ - evti->ei_dispatch_data.header.id = MESSAGE_RES_EVT_AVAILABLE; - } - - /* - * Make copy of callbacks, message data, unlock instance, - * and call callback. A risk of this dispatch method is that - * the callback routines may operate at the same time that - * EvtFinalize has been called in another thread. - */ - memcpy(&callbacks, &evti->ei_callback, sizeof(evti->ei_callback)); - - /* - * Dispatch incoming response - */ - switch (evti->ei_dispatch_data.header.id) { - - case MESSAGE_RES_EVT_AVAILABLE: - evti->ei_data_available = 0; - /* - * There are events available. Send a request for one and then - * dispatch it. - */ - res.evd_head.id = MESSAGE_REQ_EVT_EVENT_DATA; - res.evd_head.size = sizeof(res); - - pthread_mutex_lock(&evti->ei_response_mutex); - error = saSendRetry(evti->ei_response_fd, &res, sizeof(res)); - - if (error != SA_AIS_OK) { - DPRINT (("MESSAGE_RES_EVT_AVAILABLE: send failed: %d\n", error)); - pthread_mutex_unlock(&evti->ei_response_mutex); - break; - } - error = evt_recv_event(evti->ei_response_fd, &evt); - pthread_mutex_unlock(&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - DPRINT (("MESSAGE_RES_EVT_AVAILABLE: receive failed: %d\n", error)); - break; - } - /* - * No data available. This is OK, another thread may have - * grabbed it. - */ - if (evt->led_head.error == SA_AIS_ERR_NOT_EXIST) { - error = SA_AIS_OK; - break; - } - - if (evt->led_head.error != SA_AIS_OK) { - error = evt->led_head.error; - - /* - * If we get a try again response, we've lost the poll event - * so we have a data available flag so that we know that there - * really is an event waiting the next time dispatch gets - * called. - */ - if (error == SA_AIS_ERR_TRY_AGAIN) { - evti->ei_data_available = 1; - } else { - DPRINT (("MESSAGE_RES_EVT_AVAILABLE: Error returned: %d\n", error)); - } - break; - } - - error = make_event(&event_handle, evt); - if (error != SA_AIS_OK) { - break; - } - - /* - * Only call if there was a function registered - */ - if (callbacks.saEvtEventDeliverCallback) { - callbacks.saEvtEventDeliverCallback(evt->led_sub_id, - event_handle, evt->led_user_data_size); - } - break; - - case MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK: - { - struct res_evt_open_chan_async *resa = - (struct res_evt_open_chan_async *)&evti->ei_dispatch_data; - struct event_channel_instance *eci; - - /* - * Check for errors. If there are none, then - * look up the local channel via the handle that we - * got from the callback request. All we need to do - * is place in the handle from the server side and then - * we can call the callback. - */ - error = resa->ica_head.error; - if (error == SA_AIS_OK) { - error = saHandleInstanceGet(&channel_handle_db, - resa->ica_c_handle, (void*)&eci); - if (error == SA_AIS_OK) { - eci->eci_svr_channel_handle = resa->ica_channel_handle; - saHandleInstancePut (&channel_handle_db, - resa->ica_c_handle); - } - } - - /* - * Only call if there was a function registered - */ - if (callbacks.saEvtChannelOpenCallback) { - callbacks.saEvtChannelOpenCallback(resa->ica_invocation, - resa->ica_c_handle, error); - } - - } - break; - - default: - DPRINT (("Dispatch: Bad message type 0x%x\n", evti->ei_dispatch_data.header.id)); - error = SA_AIS_ERR_LIBRARY; - goto dispatch_unlock; - } - - pthread_mutex_unlock(&evti->ei_dispatch_mutex); - - /* - * If empty is zero it means the we got the - * message from the queue and we are responsible - * for freeing it. - */ - if (evt) { - free(evt); - evt = 0; - } - - /* - * Determine if more messages should be processed - */ - switch (dispatchFlags) { - case SA_DISPATCH_ONE: - if (ignore_dispatch) { - ignore_dispatch = 0; - } else { - cont = 0; - } - break; - case SA_DISPATCH_ALL: - if (ignore_dispatch) { - ignore_dispatch = 0; - } - break; - case SA_DISPATCH_BLOCKING: - break; - } - } while (cont); - - goto dispatch_put; - -dispatch_unlock: - pthread_mutex_unlock(&evti->ei_dispatch_mutex); -dispatch_put: - saHandleInstancePut(&evt_instance_handle_db, evtHandle); - return error; -} - -/* - * The saEvtFinalize() function closes the association, represented by the - * evtHandle parameter, between the process and the Event Service. It may - * free up resources. - * This function cannot be invoked before the process has invoked the - * corresponding saEvtInitialize() function for the Event Service. After - * this function is invoked, the selection object is no longer valid. - * Moreover, the Event Service is unavailable for further use unless it is - * reinitialized using the saEvtInitialize() function. - */ -SaAisErrorT -saEvtFinalize(SaEvtHandleT evtHandle) -{ - struct event_instance *evti; - SaAisErrorT error; - - error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle, - (void *)&evti); - if (error != SA_AIS_OK) { - return error; - } - - pthread_mutex_lock(&evti->ei_response_mutex); - - /* - * Another thread has already started finalizing - */ - if (evti->ei_finalize) { - pthread_mutex_unlock(&evti->ei_response_mutex); - saHandleInstancePut(&evt_instance_handle_db, evtHandle); - return SA_AIS_ERR_BAD_HANDLE; - } - - evti->ei_finalize = 1; - - pthread_mutex_unlock(&evti->ei_response_mutex); - - saHandleDestroy(&evt_instance_handle_db, evtHandle); - /* - * Disconnect from the server - */ - if (evti->ei_response_fd != -1) { - shutdown(evti->ei_response_fd, 0); - close(evti->ei_response_fd); - } - - if (evti->ei_dispatch_fd != -1) { - shutdown(evti->ei_dispatch_fd, 0); - close(evti->ei_dispatch_fd); - } - saHandleInstancePut(&evt_instance_handle_db, evtHandle); - - return error; -} - -/* - * The saEvtChannelOpen() function creates a new event channel or open an - * existing channel. The saEvtChannelOpen() function is a blocking operation - * and returns a new event channel handle. An event channel may be opened - * multiple times by the same or different processes for publishing, and - * subscribing to, events. If a process opens an event channel multiple - * times, it is possible to receive the same event multiple times. However, - * a process shall never receive an event more than once on a particular - * event channel handle. If a process opens a channel twice and an event is - * matched on both open channels, the Event Service performs two - * callbacks -- one for each opened channel. - */ -SaAisErrorT -saEvtChannelOpen( - SaEvtHandleT evtHandle, - const SaNameT *channelName, - SaEvtChannelOpenFlagsT channelOpenFlags, - SaTimeT timeout, - SaEvtChannelHandleT *channelHandle) -{ - struct event_instance *evti; - struct req_evt_channel_open req; - struct res_evt_channel_open res; - struct event_channel_instance *eci; - struct handle_list *hl; - SaAisErrorT error; - struct iovec iov; - - if (!channelHandle || !channelName) { - return SA_AIS_ERR_INVALID_PARAM; - } - - if ((channelOpenFlags & ~(SA_EVT_CHANNEL_CREATE|SA_EVT_CHANNEL_PUBLISHER| - SA_EVT_CHANNEL_SUBSCRIBER)) != 0) { - return SA_AIS_ERR_BAD_FLAGS; - } - - if (timeout == 0) { - return (SA_AIS_ERR_TIMEOUT); - } - error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle, - (void*)&evti); - - if (error != SA_AIS_OK) { - goto chan_open_done; - } - - /* - * create a handle for this open channel - */ - error = saHandleCreate(&channel_handle_db, sizeof(*eci), - channelHandle); - if (error != SA_AIS_OK) { - goto chan_open_put; - } - - - error = saHandleInstanceGet(&channel_handle_db, *channelHandle, - (void*)&eci); - if (error != SA_AIS_OK) { - saHandleDestroy(&channel_handle_db, *channelHandle); - goto chan_open_put; - } - - list_init(&eci->eci_event_list); - - /* - * Send the request to the server and wait for a response - */ - req.ico_head.size = sizeof(req); - req.ico_head.id = MESSAGE_REQ_EVT_OPEN_CHANNEL; - req.ico_c_handle = *channelHandle; - req.ico_timeout = timeout; - req.ico_open_flag = channelOpenFlags; - marshall_to_mar_name_t (&req.ico_channel_name, (SaNameT *)channelName); - - iov.iov_base = (char *)&req; - iov.iov_len = sizeof(req); - - pthread_mutex_lock(&evti->ei_response_mutex); - - error = saSendMsgReceiveReply(evti->ei_response_fd, &iov, 1, - &res, sizeof(res)); - - pthread_mutex_unlock (&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - goto chan_open_free; - } - - if (res.ico_head.id != MESSAGE_RES_EVT_OPEN_CHANNEL) { - error = SA_AIS_ERR_LIBRARY; - goto chan_open_free; - } - - error = res.ico_head.error; - if (error != SA_AIS_OK) { - goto chan_open_free; - } - - eci->eci_svr_channel_handle = res.ico_channel_handle; - eci->eci_channel_name = *channelName; - eci->eci_open_flags = channelOpenFlags; - eci->eci_instance_handle = evtHandle; - eci->eci_closing = 0; - hl = malloc(sizeof(*hl)); - if (!hl) { - error = SA_AIS_ERR_NO_MEMORY; - goto chan_open_free; - } - eci->eci_hl = hl; - hl->hl_handle = *channelHandle; - list_init(&hl->hl_entry); - list_add(&hl->hl_entry, &evti->ei_channel_list); - - pthread_mutex_init(&eci->eci_mutex, NULL); - saHandleInstancePut (&evt_instance_handle_db, evtHandle); - saHandleInstancePut (&channel_handle_db, *channelHandle); - - return SA_AIS_OK; - -chan_open_free: - saHandleDestroy(&channel_handle_db, *channelHandle); - saHandleInstancePut (&channel_handle_db, *channelHandle); -chan_open_put: - saHandleInstancePut (&evt_instance_handle_db, evtHandle); -chan_open_done: - return error; -} - -/* - * The saEvtChannelClose() function closes an event channel and frees - * resources allocated for that event channel in the invoking process. - */ - -SaAisErrorT -saEvtChannelClose(SaEvtChannelHandleT channelHandle) -{ - SaAisErrorT error; - struct event_instance *evti; - struct event_channel_instance *eci; - struct req_evt_channel_close req; - struct res_evt_channel_close res; - struct iovec iov; - - error = saHandleInstanceGet(&channel_handle_db, channelHandle, - (void*)&eci); - if (error != SA_AIS_OK) { - goto chan_close_done; - } - - /* - * get the evt handle for the fd - */ - error = saHandleInstanceGet(&evt_instance_handle_db, - eci->eci_instance_handle, (void*)&evti); - if (error != SA_AIS_OK) { - goto chan_close_put1; - } - - /* - * Make sure that the channel isn't being closed elsewhere - */ - pthread_mutex_lock(&eci->eci_mutex); - if (eci->eci_closing) { - pthread_mutex_unlock(&eci->eci_mutex); - saHandleInstancePut(&channel_handle_db, channelHandle); - return SA_AIS_ERR_BAD_HANDLE; - } - eci->eci_closing = 1; - pthread_mutex_unlock(&eci->eci_mutex); - - - /* - * Send the request to the server and wait for a response - */ - req.icc_head.size = sizeof(req); - req.icc_head.id = MESSAGE_REQ_EVT_CLOSE_CHANNEL; - req.icc_channel_handle = eci->eci_svr_channel_handle; - - iov.iov_base = (char *)&req; - iov.iov_len = sizeof (req); - - pthread_mutex_lock(&evti->ei_response_mutex); - - error = saSendMsgReceiveReply (evti->ei_response_fd, &iov, 1, - &res, sizeof (res)); - - pthread_mutex_unlock(&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - eci->eci_closing = 0; - goto chan_close_put2; - } - if (res.icc_head.id != MESSAGE_RES_EVT_CLOSE_CHANNEL) { - error = SA_AIS_ERR_LIBRARY; - eci->eci_closing = 0; - goto chan_close_put2; - } - - error = res.icc_head.error; - if (error == SA_AIS_ERR_TRY_AGAIN) { - pthread_mutex_lock(&eci->eci_mutex); - eci->eci_closing = 0; - pthread_mutex_unlock(&eci->eci_mutex); - goto chan_close_put2; - } - - saHandleInstancePut(&evt_instance_handle_db, - eci->eci_instance_handle); - saHandleDestroy(&channel_handle_db, channelHandle); - saHandleInstancePut(&channel_handle_db, channelHandle); - - return error; - -chan_close_put2: - saHandleInstancePut(&evt_instance_handle_db, - eci->eci_instance_handle); -chan_close_put1: - saHandleInstancePut(&channel_handle_db, channelHandle); -chan_close_done: - return error; -} - -/* - * The saEvtChannelOpenAsync() function creates a new event channel or open an - * existing channel. The saEvtChannelOpenAsync() function is a non-blocking - * operation. A new event channel handle is returned in the channel open - * callback function (SaEvtChannelOpenCallbackT). - */ -SaAisErrorT -saEvtChannelOpenAsync(SaEvtHandleT evtHandle, - SaInvocationT invocation, - const SaNameT *channelName, - SaEvtChannelOpenFlagsT channelOpenFlags) -{ - struct event_instance *evti; - struct req_evt_channel_open req; - struct res_evt_channel_open res; - struct event_channel_instance *eci; - SaEvtChannelHandleT channel_handle; - SaAisErrorT error; - struct handle_list *hl; - struct iovec iov; - - if (!channelName) { - return SA_AIS_ERR_INVALID_PARAM; - } - - if ((channelOpenFlags & ~(SA_EVT_CHANNEL_CREATE|SA_EVT_CHANNEL_PUBLISHER| - SA_EVT_CHANNEL_SUBSCRIBER)) != 0) { - return SA_AIS_ERR_BAD_FLAGS; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle, - (void*)&evti); - - if (error != SA_AIS_OK) { - goto chan_open_done; - } - - /* - * Make sure that an open channel callback has been - * registered before allowing the open to continue. - */ - if (!evti->ei_callback.saEvtChannelOpenCallback) { - error = SA_AIS_ERR_INIT; - goto chan_open_put; - } - - /* - * create a handle for this open channel - */ - error = saHandleCreate(&channel_handle_db, sizeof(*eci), - &channel_handle); - if (error != SA_AIS_OK) { - goto chan_open_put; - } - - - error = saHandleInstanceGet(&channel_handle_db, channel_handle, - (void*)&eci); - if (error != SA_AIS_OK) { - saHandleDestroy(&channel_handle_db, channel_handle); - goto chan_open_put; - } - - list_init(&eci->eci_event_list); - - /* - * Send the request to the server. The response isn't the open channel, - * just an ack. The open channel will be returned when the channel open - * callback is called. - */ - req.ico_head.size = sizeof(req); - req.ico_head.id = MESSAGE_REQ_EVT_OPEN_CHANNEL_ASYNC; - req.ico_c_handle = channel_handle; - req.ico_timeout = 0; - req.ico_invocation = invocation; - req.ico_open_flag = channelOpenFlags; - marshall_to_mar_name_t (&req.ico_channel_name, (SaNameT *)channelName); - iov.iov_base = (char *)&req; - iov.iov_len = sizeof(req); - - - pthread_mutex_lock(&evti->ei_response_mutex); - - error = saSendMsgReceiveReply (evti->ei_response_fd, &iov, 1, - &res, sizeof (res)); - - pthread_mutex_unlock(&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - goto chan_open_free; - } - - if (res.ico_head.id != MESSAGE_RES_EVT_OPEN_CHANNEL) { - error = SA_AIS_ERR_LIBRARY; - goto chan_open_free; - } - - error = res.ico_head.error; - if (error != SA_AIS_OK) { - goto chan_open_free; - } - - eci->eci_svr_channel_handle = 0; /* filled in by callback */ - eci->eci_channel_name = *channelName; - eci->eci_open_flags = channelOpenFlags; - eci->eci_instance_handle = evtHandle; - eci->eci_closing = 0; - list_init(&eci->eci_event_list); - hl = malloc(sizeof(*hl)); - if (!hl) { - error = SA_AIS_ERR_NO_MEMORY; - goto chan_open_free; - } - eci->eci_hl = hl; - hl->hl_handle = channel_handle; - list_init(&hl->hl_entry); - list_add(&hl->hl_entry, &evti->ei_channel_list); - - pthread_mutex_init(&eci->eci_mutex, NULL); - saHandleInstancePut (&evt_instance_handle_db, evtHandle); - saHandleInstancePut (&channel_handle_db, channel_handle); - - return SA_AIS_OK; - -chan_open_free: - saHandleDestroy(&channel_handle_db, channel_handle); - saHandleInstancePut (&channel_handle_db, channel_handle); -chan_open_put: - saHandleInstancePut (&evt_instance_handle_db, evtHandle); -chan_open_done: - return error; -} -/* - * The SaEvtChannelUnlink function deletes an existing event channel - * from the cluster. - * - * After completion of the invocation: - * - An open of the channel name without a create will fail. - * - The channel remains available to any already opened instances. - * - If an open/create is performed on this channel name a new instance - * is created. - * - The ulinked channel's resources will be deleted when the last open - * instance is closed. - * - * Note that an event channel is only deleted from the cluster - * namespace when saEvtChannelUnlink() is invoked on it. The deletion - * of an event channel frees all resources allocated by the Event - * Service for it, such as published events with non-zero retention - * time. - */ -SaAisErrorT -saEvtChannelUnlink( - SaEvtHandleT evtHandle, - const SaNameT *channelName) -{ - struct event_instance *evti; - struct req_evt_channel_unlink req; - struct res_evt_channel_unlink res; - struct iovec iov; - SaAisErrorT error; - - if (!channelName) { - return SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle, - (void*)&evti); - - if (error != SA_AIS_OK) { - goto chan_unlink_done; - } - - /* - * Send the request to the server and wait for a response - */ - req.iuc_head.size = sizeof(req); - req.iuc_head.id = MESSAGE_REQ_EVT_UNLINK_CHANNEL; - marshall_to_mar_name_t (&req.iuc_channel_name, (SaNameT *)channelName); - iov.iov_base = (char *)&req; - iov.iov_len = sizeof(req); - - - pthread_mutex_lock(&evti->ei_response_mutex); - - error = saSendMsgReceiveReply (evti->ei_response_fd, &iov, 1, - &res, sizeof (res)); - - pthread_mutex_unlock(&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - goto chan_unlink_put; - } - - if (res.iuc_head.id != MESSAGE_RES_EVT_UNLINK_CHANNEL) { - error = SA_AIS_ERR_LIBRARY; - goto chan_unlink_put; - } - - error = res.iuc_head.error; - -chan_unlink_put: - saHandleInstancePut (&evt_instance_handle_db, evtHandle); -chan_unlink_done: - return error; -} - -/* - * The saEvtEventAllocate() function allocates memory for the event, but not - * for the eventHandle, and initializes all event attributes to default values. - * The event allocated by saEvtEventAllocate() is freed by invoking - * saEvtEventFree(). - * The memory associated with the eventHandle is not deallocated by the - * saEvtEventAllocate() function or the saEvtEventFree() function. It is the - * responsibility of the invoking process to deallocate the memory for the - * eventHandle when the process has published the event and has freed the - * event by invoking saEvtEventFree(). - */ -SaAisErrorT -saEvtEventAllocate( - const SaEvtChannelHandleT channelHandle, - SaEvtEventHandleT *eventHandle) -{ - SaAisErrorT error; - struct event_data_instance *edi; - struct event_instance *evti; - struct event_channel_instance *eci; - struct handle_list *hl; - - if (!eventHandle) { - return SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet(&channel_handle_db, channelHandle, - (void*)&eci); - if (error != SA_AIS_OK) { - goto alloc_done; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, - eci->eci_instance_handle, (void*)&evti); - if (error != SA_AIS_OK) { - goto alloc_put1; - } - - error = saHandleCreate(&event_handle_db, sizeof(*edi), - eventHandle); - if (error != SA_AIS_OK) { - goto alloc_put2; - } - error = saHandleInstanceGet(&event_handle_db, *eventHandle, - (void*)&edi); - if (error != SA_AIS_OK) { - saHandleDestroy(&event_handle_db, *eventHandle); - goto alloc_put2; - } - - pthread_mutex_init(&edi->edi_mutex, NULL); - edi->edi_ro = 0; - edi->edi_freeing = 0; - edi->edi_channel_handle = channelHandle; - edi->edi_pub_node = evti->ei_node_id; - edi->edi_priority = SA_EVT_LOWEST_PRIORITY; - edi->edi_event_id = SA_EVT_EVENTID_NONE; - edi->edi_pub_time = SA_TIME_UNKNOWN; - edi->edi_retention_time = 0; - hl = malloc(sizeof(*hl)); - if (!hl) { - saHandleDestroy(&event_handle_db, *eventHandle); - error = SA_AIS_ERR_NO_MEMORY; - goto alloc_put2; - } - edi->edi_hl = hl; - hl->hl_handle = *eventHandle; - list_init(&hl->hl_entry); - list_add(&hl->hl_entry, &eci->eci_event_list); - - - saHandleInstancePut (&event_handle_db, *eventHandle); - -alloc_put2: - saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle); -alloc_put1: - saHandleInstancePut (&channel_handle_db, channelHandle); -alloc_done: - return error; -} - -/* - * The saEvtEventFree() function gives the Event Service premission to - * deallocate the memory that contains the attributes of the event that is - * associated with eventHandle. The function is used to free events allocated - * by saEvtEventAllocate() and by saEvtEventDeliverCallback(). - */ -SaAisErrorT -saEvtEventFree(SaEvtEventHandleT eventHandle) -{ - SaAisErrorT error; - struct event_data_instance *edi; - - error = saHandleInstanceGet(&event_handle_db, eventHandle, - (void*)&edi); - if (error != SA_AIS_OK) { - goto evt_free_done; - } - - /* - * Make sure that the event isn't being freed elsewhere - */ - pthread_mutex_lock(&edi->edi_mutex); - if (edi->edi_freeing) { - pthread_mutex_unlock(&edi->edi_mutex); - saHandleInstancePut(&event_handle_db, eventHandle); - return SA_AIS_ERR_BAD_HANDLE; - } - edi->edi_freeing = 1; - - pthread_mutex_unlock(&edi->edi_mutex); - saHandleDestroy(&event_handle_db, eventHandle); - saHandleInstancePut(&event_handle_db, eventHandle); - -evt_free_done: - return error; -} - -/* - * This function may be used to assign writeable event attributes. It takes - * as arguments an event handle eventHandle and the attribute to be set in - * the event structure of the event with that handle. Note: The only - * attributes that a process can set are the patternArray, priority, - * retentionTime and publisherName attributes. - */ -SaAisErrorT -saEvtEventAttributesSet( - const SaEvtEventHandleT eventHandle, - const SaEvtEventPatternArrayT *patternArray, - SaEvtEventPriorityT priority, - SaTimeT retentionTime, - const SaNameT *publisherName) -{ - SaEvtEventPatternT *oldpatterns; - SaSizeT oldnumber; - SaAisErrorT error; - struct event_data_instance *edi; - int i; - - if (priority > SA_EVT_LOWEST_PRIORITY) { - return SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet(&event_handle_db, eventHandle, - (void*)&edi); - if (error != SA_AIS_OK) { - goto attr_set_done; - } - pthread_mutex_lock(&edi->edi_mutex); - - /* - * Cannot modify an event returned via callback. - */ - if (edi->edi_ro) { - error = SA_AIS_ERR_ACCESS; - goto attr_set_unlock; - } - - edi->edi_priority = priority; - edi->edi_retention_time = retentionTime; - - if (publisherName) { - edi->edi_pub_name = *publisherName; - } - - if (!patternArray) { - goto attr_set_unlock; - } - - oldpatterns = edi->edi_patterns.patterns; - oldnumber = edi->edi_patterns.patternsNumber; - edi->edi_patterns.patterns = 0; - edi->edi_patterns.patterns = malloc(sizeof(SaEvtEventPatternT) * - patternArray->patternsNumber); - if (!edi->edi_patterns.patterns) { - error = SA_AIS_ERR_NO_MEMORY; - goto attr_set_done_reset; - } - edi->edi_patterns.patternsNumber = patternArray->patternsNumber; - edi->edi_patterns.allocatedNumber = patternArray->patternsNumber; - - /* - * copy the patterns from the caller. allocating memory for - * of all the strings. - */ - for (i = 0; i < patternArray->patternsNumber; i++) { - edi->edi_patterns.patterns[i].pattern = - malloc(patternArray->patterns[i].patternSize); - if (!edi->edi_patterns.patterns[i].pattern) { - int j; - for (j = 0; j < i; j++) { - free(edi->edi_patterns.patterns[j].pattern); - } - free(edi->edi_patterns.patterns); - error = SA_AIS_ERR_NO_MEMORY; - goto attr_set_done_reset; - } - memcpy(edi->edi_patterns.patterns[i].pattern, - patternArray->patterns[i].pattern, - patternArray->patterns[i].patternSize); - edi->edi_patterns.patterns[i].patternSize = - patternArray->patterns[i].patternSize; - edi->edi_patterns.patterns[i].allocatedSize = - patternArray->patterns[i].patternSize; - } - - /* - * free up the old pattern memory - */ - if (oldpatterns) { - for (i = 0; i < oldnumber; i++) { - if (oldpatterns[i].pattern) { - free(oldpatterns[i].pattern); - } - } - free (oldpatterns); - } - goto attr_set_unlock; - -attr_set_done_reset: - edi->edi_patterns.patterns = oldpatterns; - edi->edi_patterns.patternsNumber = oldnumber; -attr_set_unlock: - pthread_mutex_unlock(&edi->edi_mutex); - saHandleInstancePut(&event_handle_db, eventHandle); -attr_set_done: - return error; -} - -/* - * This function takes as parameters an event handle eventHandle and the - * attributes of the event with that handle. The function retrieves the - * value of the attributes for the event and stores them at the address - * provided for the out parameters. - * It is the responsibility of the invoking process to allocate memory for - * the out parameters before it invokes this function. The Event Service - * assigns the out values into that memory. For each of the out, or in/out, - * parameters, if the invoking process provides a NULL reference, the - * Availability Management Framework does not return the out value. - * Similarly, it is the responsibility of the invoking process to allocate - * memory for the patternArray. - */ -SaAisErrorT -saEvtEventAttributesGet( - SaEvtEventHandleT eventHandle, - SaEvtEventPatternArrayT *patternArray, - SaEvtEventPriorityT *priority, - SaTimeT *retentionTime, - SaNameT *publisherName, - SaTimeT *publishTime, - SaEvtEventIdT *eventId) -{ - SaAisErrorT error; - struct event_data_instance *edi; - SaSizeT npats; - int i; - - error = saHandleInstanceGet(&event_handle_db, eventHandle, - (void*)&edi); - if (error != SA_AIS_OK) { - goto attr_get_done; - } - pthread_mutex_lock(&edi->edi_mutex); - - /* - * Go through the args and send back information if the pointer - * isn't NULL - */ - if (eventId) { - *eventId = edi->edi_event_id; - } - - if (publishTime) { - *publishTime = edi->edi_pub_time; - } - - if (publisherName) { - *publisherName = edi->edi_pub_name; - } - - if (retentionTime) { - *retentionTime = edi->edi_retention_time; - } - - if (priority) { - *priority = edi->edi_priority; - } - - if (!patternArray) { - goto attr_get_unlock; - } - - /* - * The spec says that if the called passes in a NULL patterns array, - * then we allocate the required data and the caller is responsible - * for dealocating later. Otherwise, we copy to pre-allocated space. - * If there are more patterns than allcated space, we set the return - * code to SA_AIS_ERR_NO_SPACE and copy as much as will fit. We will - * return the total number of patterns available in the patternsNumber - * regardless of how much was allocated. - * - */ - if (patternArray->patterns == NULL) { - npats = edi->edi_patterns.patternsNumber; - patternArray->allocatedNumber = edi->edi_patterns.patternsNumber; - patternArray->patternsNumber = edi->edi_patterns.patternsNumber; - patternArray->patterns = malloc(sizeof(*patternArray->patterns) * - edi->edi_patterns.patternsNumber); - if (!patternArray->patterns) { - error = SA_AIS_ERR_LIBRARY; - goto attr_get_unlock; - } - for (i = 0; i < edi->edi_patterns.patternsNumber; i++) { - patternArray->patterns[i].allocatedSize = - edi->edi_patterns.patterns[i].allocatedSize; - patternArray->patterns[i].patternSize = - edi->edi_patterns.patterns[i].patternSize; - patternArray->patterns[i].pattern = - malloc(edi->edi_patterns.patterns[i].patternSize); - if (!patternArray->patterns[i].pattern) { - int j; - /* - * back out previous mallocs - */ - for (j = 0; j < i; j++) { - free(patternArray->patterns[j].pattern); - } - free(patternArray->patterns); - - /* - * saEvtEventAttributesGet doesn't return - * SA_AIS_ERR_NO_MEMORY - */ - error = SA_AIS_ERR_LIBRARY; - goto attr_get_unlock; - } - } - } else { - if (patternArray->allocatedNumber < edi->edi_patterns.allocatedNumber) { - error = SA_AIS_ERR_NO_SPACE; - npats = patternArray->allocatedNumber; - } else { - npats = edi->edi_patterns.patternsNumber; - } - } - patternArray->patternsNumber = edi->edi_patterns.patternsNumber; - - /* - * copy the patterns to the callers structure. If we have pre-allocated - * data, the patterns may not fit in the supplied space. In that case we - * return NO_SPACE. - */ - for (i = 0; i < npats; i++) { - - memcpy(patternArray->patterns[i].pattern, - edi->edi_patterns.patterns[i].pattern, - min(patternArray->patterns[i].allocatedSize, - edi->edi_patterns.patterns[i].patternSize)); - - if (patternArray->patterns[i].allocatedSize < - edi->edi_patterns.patterns[i].patternSize) { - error = SA_AIS_ERR_NO_SPACE; - } - - patternArray->patterns[i].patternSize = - edi->edi_patterns.patterns[i].patternSize; - } - -attr_get_unlock: - pthread_mutex_unlock(&edi->edi_mutex); - saHandleInstancePut(&event_handle_db, eventHandle); -attr_get_done: - return error; -} - -/* - * The saEvtEventDataGet() function allows a process to retrieve the data - * associated with an event previously delivered by - * saEvtEventDeliverCallback(). - */ -SaAisErrorT -saEvtEventDataGet( - const SaEvtEventHandleT eventHandle, - void *eventData, - SaSizeT *eventDataSize) -{ - SaAisErrorT error = SA_AIS_ERR_INVALID_PARAM; - struct event_data_instance *edi; - SaSizeT xfsize; - - if (!eventDataSize) { - goto data_get_done; - } - - error = saHandleInstanceGet(&event_handle_db, eventHandle, - (void*)&edi); - if (error != SA_AIS_OK) { - goto data_get_done; - } - pthread_mutex_lock(&edi->edi_mutex); - - /* - * If no buffer was supplied, then just tell the caller - * how large a buffer is needed. - */ - if (!eventData) { - error = SA_AIS_ERR_NO_SPACE; - *eventDataSize = edi->edi_event_data_size; - goto unlock_put; - } - - /* - * Can't get data from an event that wasn't - * a delivered event. - */ - if (!edi->edi_ro) { - error = SA_AIS_ERR_BAD_HANDLE; - goto unlock_put; - } - - if (edi->edi_event_data && edi->edi_event_data_size) { - xfsize = min(*eventDataSize, edi->edi_event_data_size); - if (*eventDataSize < edi->edi_event_data_size) { - error = SA_AIS_ERR_NO_SPACE; - } - *eventDataSize = edi->edi_event_data_size; - memcpy(eventData, edi->edi_event_data, xfsize); - } else { - *eventDataSize = 0; - } - -unlock_put: - pthread_mutex_unlock(&edi->edi_mutex); - saHandleInstancePut(&event_handle_db, eventHandle); -data_get_done: - return error; -} - -/* - * Calculate the size in bytes for patterns - */ -static size_t patt_size(const SaEvtEventPatternArrayT *patterns) -{ - int i; - size_t size = sizeof(mar_evt_event_pattern_array_t); - for (i = 0; i < patterns->patternsNumber; i++) { - size += sizeof(mar_evt_event_pattern_t); - size += patterns->patterns[i].patternSize; - } - return size; -} - -/* - * copy patterns to a form for sending to the server - */ -static uint32_t aispatt_to_evt_patt( - const SaEvtEventPatternArrayT *patterns, - void *data) -{ - int i; - mar_evt_event_pattern_t *pats = data; - SaUint8T *str = (SaUint8T *)pats + - (patterns->patternsNumber * sizeof(*pats)); - - /* - * Pointers are replaced with offsets into the data array. These - * will be later converted back into pointers when received as events. - */ - for (i = 0; i < patterns->patternsNumber; i++) { - memcpy(str, patterns->patterns[i].pattern, - patterns->patterns[i].patternSize); - pats->pattern_size = patterns->patterns[i].patternSize; - pats->pattern = (SaUint8T *)((void *)str - data); - str += patterns->patterns[i].patternSize; - pats++; - } - return patterns->patternsNumber; -} - -/* - * Calculate the size in bytes for filters - */ -static size_t filt_size(const SaEvtEventFilterArrayT *filters) -{ - int i; - size_t size = sizeof(mar_evt_event_filter_array_t); - - for (i = 0; i < filters->filtersNumber; i++) { - size += sizeof(mar_evt_event_filter_t); - size += filters->filters[i].filter.patternSize; - } - return size; -} - -/* - * Convert the Sa filters to a form that can be sent over the network - * i.e. replace pointers with offsets. The pointers will be reconstituted - * by the receiver. - */ -static uint32_t aisfilt_to_evt_filt( - const SaEvtEventFilterArrayT *filters, - void *data) -{ - int i; - mar_evt_event_filter_array_t *filtd = data; - mar_evt_event_filter_t *filts = data + sizeof(mar_evt_event_filter_array_t); - SaUint8T *str = (SaUint8T *)filts + - (filters->filtersNumber * sizeof(*filts)); - - /* - * Pointers are replaced with offsets into the data array. These - * will be later converted back into pointers by the evt server. - */ - filtd->filters = (mar_evt_event_filter_t *)((void *)filts - data); - filtd->filters_number = filters->filtersNumber; - - for (i = 0; i < filters->filtersNumber; i++) { - filts->filter_type = filters->filters[i].filterType; - filts->filter.pattern_size = - filters->filters[i].filter.patternSize; - memcpy(str, - filters->filters[i].filter.pattern, - filters->filters[i].filter.patternSize); - filts->filter.pattern = (SaUint8T *)((void *)str - data); - str += filters->filters[i].filter.patternSize; - filts++; - } - return filters->filtersNumber; -} - -/* - * The saEvtEventPublish() function publishes an event on the associated - * channel. The event to be published consists of a - * standard set of attributes (the event header) and an optional data part. - * Before an event can be published, the publisher process must invoke the - * saEvtEventPatternArraySet() function to set the event patterns. The event - * is delivered to subscribers whose subscription filter matches the event - * patterns. - * When the Event Service publishes an event, it automatically sets - * the following readonly event attributes: - * - Event attribute time - * - Event publisher identifier - * - Event publisher node identifier - * - Event identifier - * In addition to the event attributes, a process can supply values for the - * eventData and eventDataSize parameters for publication as part of the - * event. The data portion of the event may be at most SA_EVT_DATA_MAX_LEN - * bytes in length. - * The process may assume that the invocation of saEvtEventPublish() copies - * all pertinent parameters, including the memory associated with the - * eventHandle and eventData parameters, to its own local memory. However, - * the invocation does not automatically deallocate memory associated with - * the eventHandle and eventData parameters. It is the responsibility of the - * invoking process to deallocate the memory for those parameters after - * saEvtEventPublish() returns. - */ -SaAisErrorT -saEvtEventPublish( - const SaEvtEventHandleT eventHandle, - const void *eventData, - SaSizeT eventDataSize, - SaEvtEventIdT *eventId) -{ - SaAisErrorT error; - struct event_data_instance *edi; - struct event_instance *evti; - struct event_channel_instance *eci; - struct lib_event_data *req; - struct res_evt_event_publish res; - size_t pattern_size; - struct event_pattern *patterns; - void *data_start; - struct iovec iov; - - if (!eventId) { - return SA_AIS_ERR_INVALID_PARAM; - } - - if (eventDataSize > SA_EVT_DATA_MAX_LEN) { - error = SA_AIS_ERR_TOO_BIG; - goto pub_done; - } - - error = saHandleInstanceGet(&event_handle_db, eventHandle, - (void*)&edi); - if (error != SA_AIS_OK) { - goto pub_done; - } - pthread_mutex_lock(&edi->edi_mutex); - - error = saHandleInstanceGet(&channel_handle_db, edi->edi_channel_handle, - (void*)&eci); - if (error != SA_AIS_OK) { - goto pub_put1; - } - - /* - * See if we can publish to this channel - */ - if (!(eci->eci_open_flags & SA_EVT_CHANNEL_PUBLISHER)) { - error = SA_AIS_ERR_ACCESS; - goto pub_put2; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, - eci->eci_instance_handle, (void*)&evti); - if (error != SA_AIS_OK) { - goto pub_put2; - } - - /* - * Figure out how much memory we need for the patterns and data - */ - pattern_size = patt_size(&edi->edi_patterns); - - req = malloc(sizeof(*req) + eventDataSize + pattern_size); - - if (!req) { - error = SA_AIS_ERR_NO_MEMORY; - goto pub_put3; - } - - patterns = (struct event_pattern *)req->led_body; - data_start = (void *)req->led_body + pattern_size; - - /* - * copy everything to the request structure - */ - aispatt_to_evt_patt(&edi->edi_patterns, patterns); - - req->led_patterns_number = edi->edi_patterns.patternsNumber; - - req->led_user_data_offset = pattern_size; - if (eventData && eventDataSize) { - memcpy(data_start, eventData, eventDataSize); - req->led_user_data_size = eventDataSize; - } else { - req->led_user_data_size = 0; - } - - req->led_head.id = MESSAGE_REQ_EVT_PUBLISH; - req->led_head.size = sizeof(*req) + pattern_size + eventDataSize; - req->led_svr_channel_handle = eci->eci_svr_channel_handle; - req->led_retention_time = edi->edi_retention_time; - req->led_publish_time = clustTimeNow(); - req->led_priority = edi->edi_priority; - marshall_to_mar_name_t (&req->led_publisher_name, &edi->edi_pub_name); - - iov.iov_base = (char *)req; - iov.iov_len = req->led_head.size; - - pthread_mutex_lock(&evti->ei_response_mutex); - - error = saSendMsgReceiveReply(evti->ei_response_fd, &iov, 1, &res, - sizeof(res)); - - pthread_mutex_unlock (&evti->ei_response_mutex); - free(req); - if (error != SA_AIS_OK) { - pthread_mutex_unlock (&evti->ei_response_mutex); - goto pub_put3; - } - - error = res.iep_head.error; - if (error == SA_AIS_OK) { - *eventId = res.iep_event_id; - } - -pub_put3: - saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle); -pub_put2: - saHandleInstancePut (&channel_handle_db, edi->edi_channel_handle); -pub_put1: - pthread_mutex_unlock(&edi->edi_mutex); - saHandleInstancePut(&event_handle_db, eventHandle); -pub_done: - return error; -} - -/* - * The saEvtEventSubscribe() function enables a process to subscribe for - * events on an event channel by registering one or more filters on that - * event channel. The process must have opened the event channel, designated - * by channelHandle, with the SA_EVT_CHANNEL_SUBSCRIBER flag set for an - * invocation of this function to be successful. - * The memory associated with the filters is not deallocated by the - * saEvtEventSubscribe() function. It is the responsibility of the invoking - * process to deallocate the memory when the saEvtEventSubscribe() function - * returns. - * For a given subscription, the filters parameter cannot be modified. To - * change the filters parameter without losing events, a process must - * establish a new subscription with the new filters parameter. After the new - * subscription is established, the old subscription can be removed by - * invoking the saEvtEventUnsubscribe() function. - */ -SaAisErrorT -saEvtEventSubscribe( - const SaEvtChannelHandleT channelHandle, - const SaEvtEventFilterArrayT *filters, - SaEvtSubscriptionIdT subscriptionId) -{ - SaAisErrorT error; - struct event_instance *evti; - struct event_channel_instance *eci; - struct req_evt_event_subscribe *req; - struct res_evt_event_subscribe res; - int sz; - struct iovec iov; - - if (!filters) { - return SA_AIS_ERR_INVALID_PARAM; - } - error = saHandleInstanceGet(&channel_handle_db, channelHandle, - (void*)&eci); - if (error != SA_AIS_OK) { - goto subscribe_done; - } - - /* - * get the evt handle for the fd - */ - error = saHandleInstanceGet(&evt_instance_handle_db, - eci->eci_instance_handle, (void*)&evti); - if (error != SA_AIS_OK) { - goto subscribe_put1; - } - - /* - * Make sure that a deliver callback has been - * registered before allowing the subscribe to continue. - */ - if (!evti->ei_callback.saEvtEventDeliverCallback) { - error = SA_AIS_ERR_INIT; - goto subscribe_put2; - } - - /* - * See if we can subscribe to this channel - */ - if (!(eci->eci_open_flags & SA_EVT_CHANNEL_SUBSCRIBER)) { - error = SA_AIS_ERR_ACCESS; - goto subscribe_put2; - } - - /* - * calculate size needed to store the filters - */ - sz = filt_size(filters); - - req = malloc(sizeof(*req) + sz); - - if (!req) { - error = SA_AIS_ERR_NO_MEMORY; - goto subscribe_put2; - } - - /* - * Copy the supplied filters to the request - */ - req->ics_filter_count = aisfilt_to_evt_filt(filters, - req->ics_filter_data); - req->ics_head.id = MESSAGE_REQ_EVT_SUBSCRIBE; - req->ics_head.size = sizeof(*req) + sz; - req->ics_channel_handle = eci->eci_svr_channel_handle; - req->ics_sub_id = subscriptionId; - req->ics_filter_size = sz; - iov.iov_base = (char *)req; - iov.iov_len = req->ics_head.size; - - pthread_mutex_lock(&evti->ei_response_mutex); - error = saSendMsgReceiveReply(evti->ei_response_fd, &iov, 1, - &res, sizeof(res)); - pthread_mutex_unlock (&evti->ei_response_mutex); - free(req); - - if (res.ics_head.id != MESSAGE_RES_EVT_SUBSCRIBE) { - goto subscribe_put2; - } - - error = res.ics_head.error; - -subscribe_put2: - saHandleInstancePut(&evt_instance_handle_db, - eci->eci_instance_handle); -subscribe_put1: - saHandleInstancePut(&channel_handle_db, channelHandle); -subscribe_done: - return error; -} - -/* - * The saEvtEventUnsubscribe() function allows a process to stop receiving - * events for a particular subscription on an event channel by removing the - * subscription. The saEvtEventUnsubscribe() operation is successful if the - * subscriptionId parameter matches a previously registered subscription. - * Pending events that no longer match any subscription, because the - * saEvtEventUnsubscribe() operation had been invoked, are purged. a process - * that wishes to modify a subscription without losing any events must - * establish the new subscription before removing the existing subscription. - */ -SaAisErrorT -saEvtEventUnsubscribe( - const SaEvtChannelHandleT channelHandle, - SaEvtSubscriptionIdT subscriptionId) -{ - SaAisErrorT error; - struct event_instance *evti; - struct event_channel_instance *eci; - struct req_evt_event_unsubscribe req; - struct res_evt_event_unsubscribe res; - struct iovec iov; - - error = saHandleInstanceGet(&channel_handle_db, channelHandle, - (void*)&eci); - if (error != SA_AIS_OK) { - goto unsubscribe_done; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, - eci->eci_instance_handle, (void*)&evti); - if (error != SA_AIS_OK) { - goto unsubscribe_put1; - } - - req.icu_head.id = MESSAGE_REQ_EVT_UNSUBSCRIBE; - req.icu_head.size = sizeof(req); - - req.icu_channel_handle = eci->eci_svr_channel_handle; - req.icu_sub_id = subscriptionId; - iov.iov_base = (char *)&req; - iov.iov_len = sizeof(req); - - pthread_mutex_lock(&evti->ei_response_mutex); - error = saSendMsgReceiveReply(evti->ei_response_fd, &iov, 1, - &res, sizeof(res)); - pthread_mutex_unlock (&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - goto unsubscribe_put2; - } - - if (res.icu_head.id != MESSAGE_RES_EVT_UNSUBSCRIBE) { - error = SA_AIS_ERR_LIBRARY; - goto unsubscribe_put2; - } - - error = res.icu_head.error; - -unsubscribe_put2: - saHandleInstancePut(&evt_instance_handle_db, - eci->eci_instance_handle); -unsubscribe_put1: - saHandleInstancePut(&channel_handle_db, channelHandle); -unsubscribe_done: - return error; -} - - -/* - * The saEvtEventRetentionTimeClear() function is used to clear the retention - * time of a published event. It indicates to the Event Service that it does - * not need to keep the event any longer for potential new subscribers. Once - * the value of the retention time is reset to 0, the event is no longer - * available for new subscribers. The event is held until all old subscribers - * in the system process the event and free the event using saEvtEventFree(). - */ -SaAisErrorT -saEvtEventRetentionTimeClear( - const SaEvtChannelHandleT channelHandle, - const SaEvtEventIdT eventId) -{ - SaAisErrorT error; - struct event_instance *evti; - struct event_channel_instance *eci; - struct req_evt_event_clear_retentiontime req; - struct res_evt_event_clear_retentiontime res; - struct iovec iov; - - if (!is_valid_event_id(eventId)) { - return SA_AIS_ERR_INVALID_PARAM; - } - - error = saHandleInstanceGet(&channel_handle_db, channelHandle, - (void*)&eci); - if (error != SA_AIS_OK) { - goto ret_time_done; - } - - error = saHandleInstanceGet(&evt_instance_handle_db, - eci->eci_instance_handle, (void*)&evti); - if (error != SA_AIS_OK) { - goto ret_time_put1; - } - - req.iec_head.id = MESSAGE_REQ_EVT_CLEAR_RETENTIONTIME; - req.iec_head.size = sizeof(req); - - req.iec_channel_handle = eci->eci_svr_channel_handle; - req.iec_event_id = eventId; - - iov.iov_base = (char *)&req; - iov.iov_len = sizeof(req); - - pthread_mutex_lock(&evti->ei_response_mutex); - error = saSendMsgReceiveReply(evti->ei_response_fd, &iov, 1, - &res, sizeof(res)); - pthread_mutex_unlock (&evti->ei_response_mutex); - - if (error != SA_AIS_OK) { - goto ret_time_put2; - } - if (res.iec_head.id != MESSAGE_RES_EVT_CLEAR_RETENTIONTIME) { - error = SA_AIS_ERR_LIBRARY; - goto ret_time_put2; - } - - error = res.iec_head.error; - -ret_time_put2: - saHandleInstancePut(&evt_instance_handle_db, - eci->eci_instance_handle); -ret_time_put1: - saHandleInstancePut(&channel_handle_db, channelHandle); -ret_time_done: - return error; -} - -/* - * vi: set autoindent tabstop=4 shiftwidth=4 : - */ diff --git a/openais/lib/lck.c b/openais/lib/lck.c deleted file mode 100644 index d28e5111..00000000 --- a/openais/lib/lck.c +++ /dev/null @@ -1,1168 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include "../include/ipc_lck.h" - -#include "util.h" - -struct message_overlay { - mar_res_header_t header __attribute__((aligned(8))); - char data[4096]; -}; - -/* - * Data structure for instance data - */ -struct lckInstance { - int response_fd; - int dispatch_fd; - SaLckCallbacksT callbacks; - int finalize; - SaLckHandleT lckHandle; - struct list_head resource_list; - pthread_mutex_t response_mutex; - pthread_mutex_t dispatch_mutex; -}; - -struct lckResourceInstance { - int response_fd; - SaLckHandleT lckHandle; - SaLckResourceHandleT lckResourceHandle; - SaLckResourceOpenFlagsT resourceOpenFlags; - SaNameT lockResourceName; - struct list_head list; - mar_message_source_t source; - pthread_mutex_t *response_mutex; -}; - -struct lckLockIdInstance { - int response_fd; - SaLckResourceHandleT lckResourceHandle; - struct list_head list; - void *resource_lock; - pthread_mutex_t *response_mutex; -}; - -void lckHandleInstanceDestructor (void *instance); -void lckResourceHandleInstanceDestructor (void *instance); -void lckResourceHandleLockIdInstanceDestructor (void *instance); - -/* - * All LCK instances in this database - */ -static struct saHandleDatabase lckHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = lckHandleInstanceDestructor -}; - -/* - * All Resource instances in this database - */ -static struct saHandleDatabase lckResourceHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = lckResourceHandleInstanceDestructor -}; - -/* - * All Resource Lock Identifier instances in this database - */ -static struct saHandleDatabase lckLockIdHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = lckResourceHandleLockIdInstanceDestructor -}; - -/* - * Versions supported - */ -static SaVersionT lckVersionsSupported[] = { - { 'B', 1, 1 } -}; - -static struct saVersionDatabase lckVersionDatabase = { - sizeof (lckVersionsSupported) / sizeof (SaVersionT), - lckVersionsSupported -}; - - -/* - * Implementation - */ -void lckHandleInstanceDestructor (void *instance) -{ - struct lckInstance *lckInstance = instance; - - pthread_mutex_destroy (&lckInstance->response_mutex); - pthread_mutex_destroy (&lckInstance->dispatch_mutex); -} - -void lckResourceHandleInstanceDestructor (void *instance) -{ -} - -void lckResourceHandleLockIdInstanceDestructor (void *instance) -{ -} - -#ifdef NOT_DONE -static void lckSectionIterationInstanceFinalize (struct lckSectionIterationInstance *lckSectionIterationInstance) -{ - struct iteratorSectionIdListEntry *iteratorSectionIdListEntry; - struct list_head *sectionIdIterationList; - struct list_head *sectionIdIterationListNext; - /* - * iterate list of section ids for this iterator to free the allocated memory - * be careful to cache next pointer because free removes memory from use - */ - for (sectionIdIterationList = lckSectionIterationInstance->sectionIdListHead.next, - sectionIdIterationListNext = sectionIdIterationList->next; - sectionIdIterationList != &lckSectionIterationInstance->sectionIdListHead; - sectionIdIterationList = sectionIdIterationListNext, - sectionIdIterationListNext = sectionIdIterationList->next) { - - iteratorSectionIdListEntry = list_entry (sectionIdIterationList, - struct iteratorSectionIdListEntry, list); - - free (iteratorSectionIdListEntry); - } - - list_del (&lckSectionIterationInstance->list); - - saHandleDestroy (&lckSectionIterationHandleDatabase, - lckSectionIterationInstance->sectionIterationHandle); -} - -static void lckResourceInstanceFinalize (struct lckResourceInstance *lckResourceInstance) -{ - struct lckSectionIterationInstance *sectionIterationInstance; - struct list_head *sectionIterationList; - struct list_head *sectionIterationListNext; - - for (sectionIterationList = lckResourceInstance->section_iteration_list_head.next, - sectionIterationListNext = sectionIterationList->next; - sectionIterationList != &lckResourceInstance->section_iteration_list_head; - sectionIterationList = sectionIterationListNext, - sectionIterationListNext = sectionIterationList->next) { - - sectionIterationInstance = list_entry (sectionIterationList, - struct lckSectionIterationInstance, list); - - lckSectionIterationInstanceFinalize (sectionIterationInstance); - } - - list_del (&lckResourceInstance->list); - - saHandleDestroy (&lckResourceHandleDatabase, lckResourceInstance->lckResourceHandle); -} - -static void lckInstanceFinalize (struct lckInstance *lckInstance) -{ - struct lckResourceInstance *lckResourceInstance; - struct list_head *resourceInstanceList; - struct list_head *resourceInstanceListNext; - - for (resourceInstanceList = lckInstance->resource_list.next, - resourceInstanceListNext = resourceInstanceList->next; - resourceInstanceList != &lckInstance->resource_list; - resourceInstanceList = resourceInstanceListNext, - resourceInstanceListNext = resourceInstanceList->next) { - - lckResourceInstance = list_entry (resourceInstanceList, - struct lckResourceInstance, list); - - lckResourceInstanceFinalize (lckResourceInstance); - } - - saHandleDestroy (&lckHandleDatabase, lckInstance->lckHandle); -} - -#endif - -SaAisErrorT -saLckInitialize ( - SaLckHandleT *lckHandle, - const SaLckCallbacksT *callbacks, - SaVersionT *version) -{ - struct lckInstance *lckInstance; - SaAisErrorT error = SA_AIS_OK; - - if (lckHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saVersionVerify (&lckVersionDatabase, version); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleCreate (&lckHandleDatabase, sizeof (struct lckInstance), - lckHandle); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleInstanceGet (&lckHandleDatabase, *lckHandle, - (void *)&lckInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - lckInstance->response_fd = -1; - - error = saServiceConnect (&lckInstance->response_fd, - &lckInstance->dispatch_fd, LCK_SERVICE); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - if (callbacks) { - memcpy (&lckInstance->callbacks, callbacks, sizeof (SaLckCallbacksT)); - } else { - memset (&lckInstance->callbacks, 0, sizeof (SaLckCallbacksT)); - } - - list_init (&lckInstance->resource_list); - - lckInstance->lckHandle = *lckHandle; - - pthread_mutex_init (&lckInstance->response_mutex, NULL); - - - saHandleInstancePut (&lckHandleDatabase, *lckHandle); - - return (SA_AIS_OK); - -error_put_destroy: - saHandleInstancePut (&lckHandleDatabase, *lckHandle); -error_destroy: - saHandleDestroy (&lckHandleDatabase, *lckHandle); -error_no_destroy: - return (error); -} - -SaAisErrorT -saLckSelectionObjectGet ( - const SaLckHandleT lckHandle, - SaSelectionObjectT *selectionObject) -{ - struct lckInstance *lckInstance; - SaAisErrorT error; - - if (selectionObject == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - error = saHandleInstanceGet (&lckHandleDatabase, lckHandle, (void *)&lckInstance); - if (error != SA_AIS_OK) { - return (error); - } - - *selectionObject = lckInstance->dispatch_fd; - - saHandleInstancePut (&lckHandleDatabase, lckHandle); - - return (SA_AIS_OK); -} - -SaAisErrorT -saLckOptionCheck ( - SaLckHandleT lckHandle, - SaLckOptionsT *lckOptions) -{ - return (SA_AIS_OK); -} - -SaAisErrorT -saLckDispatch ( - const SaLckHandleT lckHandle, - SaDispatchFlagsT dispatchFlags) -{ - struct pollfd ufds; - int poll_fd; - int timeout = 1; - SaLckCallbacksT callbacks; - SaAisErrorT error; - int dispatch_avail; - struct lckInstance *lckInstance; - struct lckResourceInstance *lckResourceInstance; - struct lckLockIdInstance *lckLockIdInstance; - int cont = 1; /* always continue do loop except when set to 0 */ - struct message_overlay dispatch_data; - struct res_lib_lck_lockwaitercallback *res_lib_lck_lockwaitercallback; - struct res_lib_lck_resourceopenasync *res_lib_lck_resourceopenasync = NULL; - struct res_lib_lck_resourcelockasync *res_lib_lck_resourcelockasync = NULL; - struct res_lib_lck_resourceunlockasync *res_lib_lck_resourceunlockasync; - - - if (dispatchFlags != SA_DISPATCH_ONE && - dispatchFlags != SA_DISPATCH_ALL && - dispatchFlags != SA_DISPATCH_BLOCKING) { - - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&lckHandleDatabase, lckHandle, - (void *)&lckInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Timeout instantly for SA_DISPATCH_ALL - */ - if (dispatchFlags == SA_DISPATCH_ALL) { - timeout = 0; - } - - do { - /* - * Read data directly from socket - */ - poll_fd = lckInstance->dispatch_fd; - ufds.fd = poll_fd; - ufds.events = POLLIN; - ufds.revents = 0; - - error = saPollRetry(&ufds, 1, timeout); - if (error != SA_AIS_OK) { - goto error_put; - } - pthread_mutex_lock(&lckInstance->dispatch_mutex); - - if (lckInstance->finalize == 1) { - error = SA_AIS_OK; - goto error_unlock; - } - - if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_unlock; - } - - dispatch_avail = (ufds.revents & POLLIN); - - if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) { - pthread_mutex_unlock(&lckInstance->dispatch_mutex); - break; /* exit do while cont is 1 loop */ - } else - if (dispatch_avail == 0) { - pthread_mutex_unlock(&lckInstance->dispatch_mutex); - continue; - } - - memset(&dispatch_data,0, sizeof(struct message_overlay)); - error = saRecvRetry (lckInstance->dispatch_fd, &dispatch_data.header, sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - if (dispatch_data.header.size > sizeof (mar_res_header_t)) { - error = saRecvRetry (lckInstance->dispatch_fd, &dispatch_data.data, - dispatch_data.header.size - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - } - - /* - * Make copy of callbacks, message data, unlock instance, - * and call callback. A risk of this dispatch method is that - * the callback routines may operate at the same time that - * LckFinalize has been called in another thread. - */ - memcpy(&callbacks,&lckInstance->callbacks, sizeof(lckInstance->callbacks)); - pthread_mutex_unlock(&lckInstance->dispatch_mutex); - /* - * Dispatch incoming response - */ - switch (dispatch_data.header.id) { - case MESSAGE_RES_LCK_LOCKWAITERCALLBACK: - if (callbacks.saLckResourceOpenCallback == NULL) { - continue; - } - res_lib_lck_lockwaitercallback = (struct res_lib_lck_lockwaitercallback *)&dispatch_data; - callbacks.saLckLockWaiterCallback ( - res_lib_lck_lockwaitercallback->waiter_signal, - res_lib_lck_lockwaitercallback->lock_id, - res_lib_lck_lockwaitercallback->mode_held, - res_lib_lck_lockwaitercallback->mode_requested); - break; - - case MESSAGE_RES_LCK_RESOURCEOPENASYNC: - if (callbacks.saLckLockWaiterCallback == NULL) { - continue; - } - res_lib_lck_resourceopenasync = (struct res_lib_lck_resourceopenasync *)&dispatch_data; - /* - * This instance get/listadd/put required so that close - * later has the proper list of resources - */ - if (res_lib_lck_resourceopenasync->header.error == SA_AIS_OK) { - error = saHandleInstanceGet (&lckResourceHandleDatabase, - res_lib_lck_resourceopenasync->resourceHandle, - (void *)&lckResourceInstance); - - assert (error == SA_AIS_OK); /* should only be valid handles here */ - /* - * open succeeded without error - */ - - callbacks.saLckResourceOpenCallback( - res_lib_lck_resourceopenasync->invocation, - res_lib_lck_resourceopenasync->resourceHandle, - res_lib_lck_resourceopenasync->header.error); - memcpy (&lckResourceInstance->source, - &res_lib_lck_resourceopenasync->source, - sizeof (mar_message_source_t)); - saHandleInstancePut (&lckResourceHandleDatabase, - res_lib_lck_resourceopenasync->resourceHandle); - } else { - /* - * open failed with error - */ - callbacks.saLckResourceOpenCallback( - res_lib_lck_resourceopenasync->invocation, - -1, - res_lib_lck_resourceopenasync->header.error); - } - break; - case MESSAGE_RES_LCK_RESOURCELOCKASYNC: - DPRINT (("grant\n")); - if (callbacks.saLckLockGrantCallback == NULL) { - continue; - } - res_lib_lck_resourcelockasync = (struct res_lib_lck_resourcelockasync *)&dispatch_data; - /* - * This instance get/listadd/put required so that close - * later has the proper list of resources - */ - if (res_lib_lck_resourcelockasync->header.error == SA_AIS_OK) { - error = saHandleInstanceGet (&lckLockIdHandleDatabase, - res_lib_lck_resourcelockasync->lockId, - (void *)&lckLockIdInstance); - - assert (error == SA_AIS_OK); /* should only be valid handles here */ - /* - * open succeeded without error - */ - lckLockIdInstance->resource_lock = res_lib_lck_resourcelockasync->resource_lock; - - callbacks.saLckLockGrantCallback( - res_lib_lck_resourcelockasync->invocation, - res_lib_lck_resourcelockasync->lockStatus, - res_lib_lck_resourcelockasync->header.error); - saHandleInstancePut (&lckLockIdHandleDatabase, - res_lib_lck_resourcelockasync->lockId); - } else { - /* - * open failed with error - */ - callbacks.saLckLockGrantCallback ( - res_lib_lck_resourceopenasync->invocation, - -1, - res_lib_lck_resourceopenasync->header.error); - } - break; - - - case MESSAGE_RES_LCK_RESOURCEUNLOCKASYNC: - if (callbacks.saLckResourceUnlockCallback == NULL) { - continue; - } - res_lib_lck_resourceunlockasync = (struct res_lib_lck_resourceunlockasync *)&dispatch_data; - callbacks.saLckResourceUnlockCallback ( - res_lib_lck_resourceunlockasync->invocation, - res_lib_lck_resourceunlockasync->header.error); - - if (res_lib_lck_resourcelockasync->header.error == SA_AIS_OK) { - error = saHandleInstanceGet (&lckLockIdHandleDatabase, - res_lib_lck_resourceunlockasync->lockId, - (void *)&lckLockIdInstance); - if (error == SA_AIS_OK) { - saHandleInstancePut (&lckLockIdHandleDatabase, res_lib_lck_resourceunlockasync->lockId); - - saHandleDestroy (&lckLockIdHandleDatabase, res_lib_lck_resourceunlockasync->lockId); - } - } - break; -#ifdef NOT_DONE_YET - - case MESSAGE_RES_LCK_RESOURCESYNCHRONIZEASYNC: - if (callbacks.saLckResourceSynchronizeCallback == NULL) { - continue; - } - - res_lib_lck_resourcesynchronizeasync = (struct res_lib_lck_resourcesynchronizeasync *) &dispatch_data; - - callbacks.saLckResourceSynchronizeCallback( - res_lib_lck_resourcesynchronizeasync->invocation, - res_lib_lck_resourcesynchronizeasync->header.error); - break; -#endif - - default: - /* TODO */ - break; - } - /* - * Determine if more messages should be processed - */ - switch (dispatchFlags) { - case SA_DISPATCH_ONE: - cont = 0; - break; - case SA_DISPATCH_ALL: - break; - case SA_DISPATCH_BLOCKING: - break; - } - } while (cont); -error_unlock: - pthread_mutex_unlock(&lckInstance->dispatch_mutex); -error_put: - saHandleInstancePut(&lckHandleDatabase, lckHandle); -error_exit: - return (error); -} - -SaAisErrorT -saLckFinalize ( - const SaLckHandleT lckHandle) -{ - struct lckInstance *lckInstance; - SaAisErrorT error; - - error = saHandleInstanceGet (&lckHandleDatabase, lckHandle, - (void *)&lckInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&lckInstance->response_mutex); - - /* - * Another thread has already started finalizing - */ - if (lckInstance->finalize) { - pthread_mutex_unlock (&lckInstance->response_mutex); - saHandleInstancePut (&lckHandleDatabase, lckHandle); - return (SA_AIS_ERR_BAD_HANDLE); - } - - lckInstance->finalize = 1; - - pthread_mutex_unlock (&lckInstance->response_mutex); - -// TODO lckInstanceFinalize (lckInstance); - - if (lckInstance->response_fd != -1) { - shutdown (lckInstance->response_fd, 0); - close (lckInstance->response_fd); - } - - if (lckInstance->dispatch_fd != -1) { - shutdown (lckInstance->dispatch_fd, 0); - close (lckInstance->dispatch_fd); - } - - saHandleInstancePut (&lckHandleDatabase, lckHandle); - - return (SA_AIS_OK); -} - -SaAisErrorT -saLckResourceOpen ( - SaLckHandleT lckHandle, - const SaNameT *lockResourceName, - SaLckResourceOpenFlagsT resourceOpenFlags, - SaTimeT timeout, - SaLckResourceHandleT *lckResourceHandle) -{ - SaAisErrorT error; - struct lckResourceInstance *lckResourceInstance; - struct lckInstance *lckInstance; - struct req_lib_lck_resourceopen req_lib_lck_resourceopen; - struct res_lib_lck_resourceopen res_lib_lck_resourceopen; - - if (lckResourceHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if (lockResourceName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&lckHandleDatabase, lckHandle, - (void *)&lckInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saHandleCreate (&lckResourceHandleDatabase, - sizeof (struct lckResourceInstance), lckResourceHandle); - if (error != SA_AIS_OK) { - goto error_put_lck; - } - - error = saHandleInstanceGet (&lckResourceHandleDatabase, - *lckResourceHandle, (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - lckResourceInstance->response_fd = lckInstance->response_fd; - - lckResourceInstance->lckHandle = lckHandle; - lckResourceInstance->lckResourceHandle = *lckResourceHandle; - lckResourceInstance->response_mutex = &lckInstance->response_mutex; - - req_lib_lck_resourceopen.header.size = sizeof (struct req_lib_lck_resourceopen); - req_lib_lck_resourceopen.header.id = MESSAGE_REQ_LCK_RESOURCEOPEN; - - marshall_to_mar_name_t (&req_lib_lck_resourceopen.lockResourceName, (SaNameT *)lockResourceName); - - memcpy (&lckResourceInstance->lockResourceName, lockResourceName, sizeof(SaNameT)); - req_lib_lck_resourceopen.resourceOpenFlags = resourceOpenFlags; - req_lib_lck_resourceopen.resourceHandle = *lckResourceHandle; - req_lib_lck_resourceopen.async_call = 0; - - pthread_mutex_lock (&lckInstance->response_mutex); - - error = saSendReceiveReply (lckResourceInstance->response_fd, - &req_lib_lck_resourceopen, - sizeof (struct req_lib_lck_resourceopen), - &res_lib_lck_resourceopen, - sizeof (struct res_lib_lck_resourceopen)); - - pthread_mutex_unlock (&lckInstance->response_mutex); - - if (res_lib_lck_resourceopen.header.error != SA_AIS_OK) { - error = res_lib_lck_resourceopen.header.error; - goto error_put_destroy; - } - - memcpy (&lckResourceInstance->source, - &res_lib_lck_resourceopen.source, - sizeof (mar_message_source_t)); - - saHandleInstancePut (&lckResourceHandleDatabase, *lckResourceHandle); - - saHandleInstancePut (&lckHandleDatabase, lckHandle); - - list_init (&lckResourceInstance->list); - - list_add (&lckResourceInstance->list, &lckInstance->resource_list); - return (error); - -error_put_destroy: - saHandleInstancePut (&lckResourceHandleDatabase, *lckResourceHandle); -error_destroy: - saHandleDestroy (&lckResourceHandleDatabase, *lckResourceHandle); -error_put_lck: - saHandleInstancePut (&lckHandleDatabase, lckHandle); -error_exit: - return (error); -} - -SaAisErrorT -saLckResourceOpenAsync ( - SaLckHandleT lckHandle, - SaInvocationT invocation, - const SaNameT *lockResourceName, - SaLckResourceOpenFlagsT resourceOpenFlags) -{ - struct lckResourceInstance *lckResourceInstance; - struct lckInstance *lckInstance; - SaLckResourceHandleT lckResourceHandle; - SaAisErrorT error; - struct req_lib_lck_resourceopen req_lib_lck_resourceopen; - struct res_lib_lck_resourceopenasync res_lib_lck_resourceopenasync; - - error = saHandleInstanceGet (&lckHandleDatabase, lckHandle, - (void *)&lckInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if (lckInstance->callbacks.saLckResourceOpenCallback == NULL) { - error = SA_AIS_ERR_INIT; - goto error_put_lck; - } - - error = saHandleCreate (&lckResourceHandleDatabase, - sizeof (struct lckResourceInstance), &lckResourceHandle); - if (error != SA_AIS_OK) { - goto error_put_lck; - } - - error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle, - (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - lckResourceInstance->response_fd = lckInstance->response_fd; - lckResourceInstance->response_mutex = &lckInstance->response_mutex; - lckResourceInstance->lckHandle = lckHandle; - lckResourceInstance->lckResourceHandle = lckResourceHandle; - lckResourceInstance->resourceOpenFlags = resourceOpenFlags; - - marshall_to_mar_name_t (&req_lib_lck_resourceopen.lockResourceName, - (SaNameT *)lockResourceName); - memcpy (&lckResourceInstance->lockResourceName, lockResourceName, sizeof (SaNameT)); - req_lib_lck_resourceopen.header.size = sizeof (struct req_lib_lck_resourceopen); - req_lib_lck_resourceopen.header.id = MESSAGE_REQ_LCK_RESOURCEOPENASYNC; - req_lib_lck_resourceopen.invocation = invocation; - req_lib_lck_resourceopen.resourceOpenFlags = resourceOpenFlags; - req_lib_lck_resourceopen.resourceHandle = lckResourceHandle; - req_lib_lck_resourceopen.async_call = 1; - - pthread_mutex_lock (&lckInstance->response_mutex); - - error = saSendReceiveReply (lckResourceInstance->response_fd, - &req_lib_lck_resourceopen, - sizeof (struct req_lib_lck_resourceopen), - &res_lib_lck_resourceopenasync, - sizeof (struct res_lib_lck_resourceopenasync)); - - pthread_mutex_unlock (&lckInstance->response_mutex); - - if (error == SA_AIS_OK) { - saHandleInstancePut (&lckResourceHandleDatabase, - lckResourceHandle); - saHandleInstancePut (&lckHandleDatabase, lckHandle); - return (res_lib_lck_resourceopenasync.header.error); - } - - saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle); -error_destroy: - saHandleDestroy (&lckResourceHandleDatabase, lckResourceHandle); -error_put_lck: - saHandleInstancePut (&lckHandleDatabase, lckHandle); -error_exit: - return (error); -} - -SaAisErrorT -saLckResourceClose ( - SaLckResourceHandleT lckResourceHandle) -{ - struct req_lib_lck_resourceclose req_lib_lck_resourceclose; - struct res_lib_lck_resourceclose res_lib_lck_resourceclose; - SaAisErrorT error; - struct lckResourceInstance *lckResourceInstance; - - error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle, - (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_lck_resourceclose.header.size = sizeof (struct req_lib_lck_resourceclose); - req_lib_lck_resourceclose.header.id = MESSAGE_REQ_LCK_RESOURCECLOSE; - marshall_to_mar_name_t (&req_lib_lck_resourceclose.lockResourceName, - &lckResourceInstance->lockResourceName); - req_lib_lck_resourceclose.resourceHandle = lckResourceHandle; - - pthread_mutex_lock (lckResourceInstance->response_mutex); - - error = saSendReceiveReply (lckResourceInstance->response_fd, - &req_lib_lck_resourceclose, - sizeof (struct req_lib_lck_resourceclose), - &res_lib_lck_resourceclose, - sizeof (struct res_lib_lck_resourceclose)); - - pthread_mutex_unlock (lckResourceInstance->response_mutex); - - saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle); - - saHandleDestroy (&lckResourceHandleDatabase, lckResourceHandle); - - return (error == SA_AIS_OK ? res_lib_lck_resourceclose.header.error : error); -} - -SaAisErrorT -saLckResourceLock ( - SaLckResourceHandleT lckResourceHandle, - SaLckLockIdT *lockId, - SaLckLockModeT lockMode, - SaLckLockFlagsT lockFlags, - SaLckWaiterSignalT waiterSignal, - SaTimeT timeout, - SaLckLockStatusT *lockStatus) -{ - struct req_lib_lck_resourcelock req_lib_lck_resourcelock; - struct res_lib_lck_resourcelock res_lib_lck_resourcelock; - SaAisErrorT error; - struct lckResourceInstance *lckResourceInstance; - struct lckLockIdInstance *lckLockIdInstance; - int lock_fd; - int dummy_fd; - - error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle, - (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - return (error); - } - - error = saHandleCreate (&lckLockIdHandleDatabase, - sizeof (struct lckLockIdInstance), lockId); - if (error != SA_AIS_OK) { - goto error_put_lck; - } - - error = saHandleInstanceGet (&lckLockIdHandleDatabase, *lockId, - (void *)&lckLockIdInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - error = saServiceConnect (&lock_fd, &dummy_fd, LCK_SERVICE); - if (error != SA_AIS_OK) { // TODO error handling - goto error_destroy; - } - - lckLockIdInstance->response_mutex = lckResourceInstance->response_mutex; - lckLockIdInstance->response_fd = lckResourceInstance->response_fd; - lckLockIdInstance->lckResourceHandle = lckResourceHandle; - - req_lib_lck_resourcelock.header.size = sizeof (struct req_lib_lck_resourcelock); - req_lib_lck_resourcelock.header.id = MESSAGE_REQ_LCK_RESOURCELOCK; - marshall_to_mar_name_t (&req_lib_lck_resourcelock.lockResourceName, - &lckResourceInstance->lockResourceName); - req_lib_lck_resourcelock.lockMode = lockMode; - req_lib_lck_resourcelock.lockFlags = lockFlags; - req_lib_lck_resourcelock.waiterSignal = waiterSignal; - req_lib_lck_resourcelock.lockId = *lockId; - req_lib_lck_resourcelock.async_call = 0; - req_lib_lck_resourcelock.invocation = 0; - req_lib_lck_resourcelock.resourceHandle = lckResourceHandle; - - memcpy (&req_lib_lck_resourcelock.source, - &lckResourceInstance->source, - sizeof (mar_message_source_t)); - - /* - * no mutex needed here since its a new connection - */ - error = saSendReceiveReply (lock_fd, - &req_lib_lck_resourcelock, - sizeof (struct req_lib_lck_resourcelock), - &res_lib_lck_resourcelock, - sizeof (struct res_lib_lck_resourcelock)); - - close (lock_fd); - close (dummy_fd); - - if (error == SA_AIS_OK) { - lckLockIdInstance->resource_lock = res_lib_lck_resourcelock.resource_lock; - *lockStatus = res_lib_lck_resourcelock.lockStatus; - - return (res_lib_lck_resourcelock.header.error); - } - - /* - * Error - */ - saHandleInstancePut (&lckLockIdHandleDatabase, *lockId); - -error_destroy: - saHandleDestroy (&lckLockIdHandleDatabase, *lockId); - -error_put_lck: - saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle); - return (error); - -} - -SaAisErrorT -saLckResourceLockAsync ( - SaLckResourceHandleT lckResourceHandle, - SaInvocationT invocation, - SaLckLockIdT *lockId, - SaLckLockModeT lockMode, - SaLckLockFlagsT lockFlags, - SaLckWaiterSignalT waiterSignal) -{ - struct req_lib_lck_resourcelock req_lib_lck_resourcelock; - struct res_lib_lck_resourcelockasync res_lib_lck_resourcelockasync; - SaAisErrorT error; - struct lckResourceInstance *lckResourceInstance; - struct lckLockIdInstance *lckLockIdInstance; - int lock_fd; - int dummy_fd; - - error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle, - (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - return (error); - } - - error = saHandleCreate (&lckLockIdHandleDatabase, - sizeof (struct lckLockIdInstance), lockId); - if (error != SA_AIS_OK) { - goto error_put_lck; - } - - error = saHandleInstanceGet (&lckLockIdHandleDatabase, *lockId, - (void *)&lckLockIdInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - error = saServiceConnect (&lock_fd, &dummy_fd, LCK_SERVICE); - if (error != SA_AIS_OK) { // TODO error handling - goto error_destroy; - } - - lckLockIdInstance->response_mutex = lckResourceInstance->response_mutex; - lckLockIdInstance->response_fd = lckResourceInstance->response_fd; - lckLockIdInstance->lckResourceHandle = lckResourceHandle; - - req_lib_lck_resourcelock.header.size = sizeof (struct req_lib_lck_resourcelock); - req_lib_lck_resourcelock.header.id = MESSAGE_REQ_LCK_RESOURCELOCKASYNC; - marshall_to_mar_name_t (&req_lib_lck_resourcelock.lockResourceName, - &lckResourceInstance->lockResourceName); - req_lib_lck_resourcelock.lockMode = lockMode; - req_lib_lck_resourcelock.lockFlags = lockFlags; - req_lib_lck_resourcelock.waiterSignal = waiterSignal; - req_lib_lck_resourcelock.lockId = *lockId; - req_lib_lck_resourcelock.async_call = 1; - req_lib_lck_resourcelock.invocation = invocation; - req_lib_lck_resourcelock.resourceHandle = lckResourceHandle; - - memcpy (&req_lib_lck_resourcelock.source, - &lckResourceInstance->source, - sizeof (mar_message_source_t)); - - /* - * no mutex needed here since its a new connection - */ - error = saSendReceiveReply (lock_fd, - &req_lib_lck_resourcelock, - sizeof (struct req_lib_lck_resourcelock), - &res_lib_lck_resourcelockasync, - sizeof (struct res_lib_lck_resourcelock)); - - close (lock_fd); - close (dummy_fd); - - if (error == SA_AIS_OK) { - return (res_lib_lck_resourcelockasync.header.error); - } - - /* - * Error - */ - saHandleInstancePut (&lckLockIdHandleDatabase, *lockId); - -error_destroy: - saHandleDestroy (&lckLockIdHandleDatabase, *lockId); - -error_put_lck: - saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle); - return (error); -} - -SaAisErrorT -saLckResourceUnlock ( - SaLckLockIdT lockId, - SaTimeT timeout) -{ - struct req_lib_lck_resourceunlock req_lib_lck_resourceunlock; - struct res_lib_lck_resourceunlock res_lib_lck_resourceunlock; - SaAisErrorT error; - struct lckLockIdInstance *lckLockIdInstance; - struct lckResourceInstance *lckResourceInstance; - - error = saHandleInstanceGet (&lckLockIdHandleDatabase, lockId, - (void *)&lckLockIdInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* - * Retrieve resource name - */ - error = saHandleInstanceGet (&lckResourceHandleDatabase, - lckLockIdInstance->lckResourceHandle, (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - saHandleInstancePut (&lckLockIdHandleDatabase, lockId); - return (error); - } - - marshall_to_mar_name_t (&req_lib_lck_resourceunlock.lockResourceName, - &lckResourceInstance->lockResourceName); - - saHandleInstancePut (&lckResourceHandleDatabase, - lckLockIdInstance->lckResourceHandle); - - req_lib_lck_resourceunlock.header.size = sizeof (struct req_lib_lck_resourceunlock); - req_lib_lck_resourceunlock.header.id = MESSAGE_REQ_LCK_RESOURCEUNLOCK; - req_lib_lck_resourceunlock.lockId = lockId; - req_lib_lck_resourceunlock.timeout = timeout; - req_lib_lck_resourceunlock.invocation = -1; - req_lib_lck_resourceunlock.async_call = 0; - req_lib_lck_resourceunlock.resource_lock = lckLockIdInstance->resource_lock; - - pthread_mutex_lock (lckLockIdInstance->response_mutex); - - error = saSendReceiveReply (lckLockIdInstance->response_fd, - &req_lib_lck_resourceunlock, - sizeof (struct req_lib_lck_resourceunlock), - &res_lib_lck_resourceunlock, - sizeof (struct res_lib_lck_resourceunlock)); - - pthread_mutex_unlock (lckLockIdInstance->response_mutex); - - saHandleInstancePut (&lckLockIdHandleDatabase, lockId); - - saHandleDestroy (&lckLockIdHandleDatabase, lockId); - - return (error == SA_AIS_OK ? res_lib_lck_resourceunlock.header.error : error); -} - -SaAisErrorT -saLckResourceUnlockAsync ( - SaInvocationT invocation, - SaLckLockIdT lockId) -{ - struct req_lib_lck_resourceunlock req_lib_lck_resourceunlock; - struct res_lib_lck_resourceunlockasync res_lib_lck_resourceunlockasync; - SaAisErrorT error; - struct lckLockIdInstance *lckLockIdInstance; - struct lckResourceInstance *lckResourceInstance; - - error = saHandleInstanceGet (&lckLockIdHandleDatabase, lockId, - (void *)&lckLockIdInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* - * Retrieve resource name - */ - error = saHandleInstanceGet (&lckResourceHandleDatabase, - lckLockIdInstance->lckResourceHandle, (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - saHandleInstancePut (&lckLockIdHandleDatabase, lockId); - return (error); - } - - marshall_to_mar_name_t (&req_lib_lck_resourceunlock.lockResourceName, - &lckResourceInstance->lockResourceName); - - saHandleInstancePut (&lckResourceHandleDatabase, - lckLockIdInstance->lckResourceHandle); - - - /* - * Build and send request - */ - req_lib_lck_resourceunlock.header.size = sizeof (struct req_lib_lck_resourceunlock); - req_lib_lck_resourceunlock.header.id = MESSAGE_REQ_LCK_RESOURCEUNLOCKASYNC; - req_lib_lck_resourceunlock.invocation = invocation; - req_lib_lck_resourceunlock.lockId = lockId; - req_lib_lck_resourceunlock.async_call = 1; - - pthread_mutex_lock (lckLockIdInstance->response_mutex); - - error = saSendReceiveReply (lckLockIdInstance->response_fd, - &req_lib_lck_resourceunlock, - sizeof (struct req_lib_lck_resourceunlock), - &res_lib_lck_resourceunlockasync, - sizeof (struct res_lib_lck_resourceunlockasync)); - - pthread_mutex_unlock (lckLockIdInstance->response_mutex); - - saHandleInstancePut (&lckLockIdHandleDatabase, lockId); - - return (error == SA_AIS_OK ? res_lib_lck_resourceunlockasync.header.error : error); -} - -SaAisErrorT -saLckLockPurge ( - SaLckResourceHandleT lckResourceHandle) -{ - struct req_lib_lck_lockpurge req_lib_lck_lockpurge; - struct res_lib_lck_lockpurge res_lib_lck_lockpurge; - SaAisErrorT error; - struct lckResourceInstance *lckResourceInstance; - - error = saHandleInstanceGet (&lckResourceHandleDatabase, lckResourceHandle, - (void *)&lckResourceInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_lck_lockpurge.header.size = sizeof (struct req_lib_lck_lockpurge); - req_lib_lck_lockpurge.header.id = MESSAGE_REQ_LCK_LOCKPURGE; - marshall_to_mar_name_t (&req_lib_lck_lockpurge.lockResourceName, - &lckResourceInstance->lockResourceName); - - pthread_mutex_lock (lckResourceInstance->response_mutex); - - error = saSendReceiveReply (lckResourceInstance->response_fd, - &req_lib_lck_lockpurge, - sizeof (struct req_lib_lck_lockpurge), - &res_lib_lck_lockpurge, - sizeof (struct res_lib_lck_lockpurge)); - - pthread_mutex_unlock (lckResourceInstance->response_mutex); - - saHandleInstancePut (&lckResourceHandleDatabase, lckResourceHandle); - - return (error == SA_AIS_OK ? res_lib_lck_lockpurge.header.error : error); -} diff --git a/openais/lib/libSaAis.versions b/openais/lib/libSaAis.versions deleted file mode 100644 index 055146f0..00000000 --- a/openais/lib/libSaAis.versions +++ /dev/null @@ -1,226 +0,0 @@ -# Version and symbol export for libSaClm.so - -OPENAIS_CLM_B.01.01 { - global: - saClmInitialize; - saClmSelectionObjectGet; - saClmDispatch; - saClmFinalize; - saClmClusterTrack; - saClmClusterTrackStop; - saClmClusterNodeGet; - saClmClusterNodeGetAsync; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSelectRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; - -# Version and symbol export for libSaAmf.so -OPENAIS_AMF_B.01.01 { - global: - saAmfInitialize; - saAmfSelectionObjectGet; - saAmfDispatch; - saAmfFinalize; - saAmfComponentRegister; - saAmfComponentUnregister; - saAmfComponentNameGet; - saAmfPmStart; - saAmfPmStop; - saAmfHealthcheckStart; - saAmfHealthcheckConfirm; - saAmfHealthcheckStop; - saAmfHAStateGet; - saAmfCSIQuiescingComplete; - saAmfProtectionGroupTrack; - saAmfProtectionGroupTrackStop; - saAmfComponentErrorReport; - saAmfComponentErrorClear; - saAmfResponse; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSelectRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; - -# Version and symbol export for libSaCkpt.so -OPENAIS_CKPT_B.01.01 { - global: - saCkptInitialize; - saCkptSelectionObjectGet; - saCkptDispatch; - saCkptFinalize; - saCkptCheckpointOpen; - saCkptCheckpointOpenAsync; - saCkptCheckpointClose; - saCkptCheckpointUnlink; - saCkptCheckpointRetentionDurationSet; - saCkptActiveReplicaSet; - saCkptCheckpointStatusGet; - saCkptSectionCreate; - saCkptSectionDelete; - saCkptSectionExpirationTimeSet; - saCkptSectionIterationInitialize; - saCkptSectionIterationNext; - saCkptSectionIterationFinalize; - saCkptCheckpointWrite; - saCkptCheckpointOverwrite; - saCkptCheckpointRead; - saCkptCheckpointSynchronize; - saCkptCheckpointSynchronizeAsync; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSelectRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; - -# Version and symbol export for libSaEvt.so -OPENAIS_EVT_B.01.01 { - global: - - saEvtInitialize; - saEvtSelectionObjectGet; - saEvtDispatch; - saEvtFinalize; - saEvtChannelOpen; - saEvtChannelClose; - saEvtChannelOpenAsync; - saEvtChannelUnlink; - saEvtChannelAllocate; - saEvtEventFree; - saEvtEventAttributesSet; - saEvtEventAttributesGet; - saEvtEventDataGet; - saEvtEventPublish; - saEvtEventSubscribe; - saEvtEventUnsubscribe; - saEvtEventRetentionTimeClear; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSelectRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; - -# Version and symbol export for libSaLck.so -OPENAIS_LCK_B.01.01 { - global: - saLckInitialize; - saLckSelectionObjectGet; - saLckDispatch; - saLckinalize; - saLckResourceOpen; - saLckResourceOpenAsync; - saLckResourcClose; - saLckResourcLock; - saLckResourceLockAsync; - saLckResourceUnlock; - saLckResourceUnlockAsync; - saLckResourceLockPurge; - - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; - -# Version and symbol export for libSaMsg.so - -OPENAIS_MSG_B.01.01 { - global: - saMsgInitialize; - saMsgSelectionObjectGet; - saMsgDispatch; - saMsginalize; - saMsgQueueOpen; - saMsgQueueOpenAsync; - saMsgQueueClose; - saMsgQueueStatusGet; - saMsgQueueUnlink; - saMsgQueueGroupCreate; - saMsgQueueGroupInsert; - saMsgQueueGroupRemove; - saMsgQueueGroupDelete; - saMsgQueueGroupTrack; - saMsgQueueGroupTrackStop; - saMsgMessageSend; - saMsgMessageSendAsync; - saMsgMessageSendAsync; - saMsgMessageGet; - saMsgMessageCancel; - saMsgMessageReply; - saMsgMessageReplyAsync; - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libSaAmf.versions b/openais/lib/libSaAmf.versions deleted file mode 100644 index 2079fc82..00000000 --- a/openais/lib/libSaAmf.versions +++ /dev/null @@ -1,39 +0,0 @@ -# Version and symbol export for libSaClm.so - -OPENAIS_AMF_B.01.01 { - global: - saAmfInitialize; - saAmfSelectionObjectGet; - saAmfDispatch; - saAmfFinalize; - saAmfComponentRegister; - saAmfComponentUnregister; - saAmfComponentNameGet; - saAmfPmStart; - saAmfPmStop; - saAmfHealthcheckStart; - saAmfHealthcheckConfirm; - saAmfHealthcheckStop; - saAmfHAStateGet; - saAmfCSIQuiescingComplete; - saAmfProtectionGroupTrack; - saAmfProtectionGroupTrackStop; - saAmfComponentErrorReport; - saAmfComponentErrorClear; - saAmfResponse; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libSaCkpt.versions b/openais/lib/libSaCkpt.versions deleted file mode 100644 index 3b0517f2..00000000 --- a/openais/lib/libSaCkpt.versions +++ /dev/null @@ -1,42 +0,0 @@ -# Version and symbol export for libSaCkpt.so - -OPENAIS_CKPT_B.01.01 { - global: - saCkptInitialize; - saCkptSelectionObjectGet; - saCkptDispatch; - saCkptFinalize; - saCkptCheckpointOpen; - saCkptCheckpointOpenAsync; - saCkptCheckpointClose; - saCkptCheckpointUnlink; - saCkptCheckpointRetentionDurationSet; - saCkptActiveReplicaSet; - saCkptCheckpointStatusGet; - saCkptSectionCreate; - saCkptSectionDelete; - saCkptSectionExpirationTimeSet; - saCkptSectionIterationInitialize; - saCkptSectionIterationNext; - saCkptSectionIterationFinalize; - saCkptCheckpointWrite; - saCkptCheckpointOverwrite; - saCkptCheckpointRead; - saCkptCheckpointSynchronize; - saCkptCheckpointSynchronizeAsync; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libSaClm.versions b/openais/lib/libSaClm.versions deleted file mode 100644 index 49dc9063..00000000 --- a/openais/lib/libSaClm.versions +++ /dev/null @@ -1,28 +0,0 @@ -# Version and symbol export for libSaClm.so - -OPENAIS_CLM_B.01.01 { - global: - saClmInitialize; - saClmSelectionObjectGet; - saClmDispatch; - saClmFinalize; - saClmClusterTrack; - saClmClusterTrackStop; - saClmClusterNodeGet; - saClmClusterNodeGetAsync; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libSaEvt.versions b/openais/lib/libSaEvt.versions deleted file mode 100644 index 8aa4a969..00000000 --- a/openais/lib/libSaEvt.versions +++ /dev/null @@ -1,38 +0,0 @@ -# Version and symbol export for libSaClm.so - -OPENAIS_EVT_B.01.01 { - global: - - saEvtInitialize; - saEvtSelectionObjectGet; - saEvtDispatch; - saEvtFinalize; - saEvtChannelOpen; - saEvtChannelClose; - saEvtChannelOpenAsync; - saEvtChannelUnlink; - saEvtChannelAllocate; - saEvtEventFree; - saEvtEventAttributesSet; - saEvtEventAttributesGet; - saEvtEventDataGet; - saEvtEventPublish; - saEvtEventSubscribe; - saEvtEventUnsubscribe; - saEvtEventRetentionTimeClear; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libSaLck.versions b/openais/lib/libSaLck.versions deleted file mode 100644 index 68666695..00000000 --- a/openais/lib/libSaLck.versions +++ /dev/null @@ -1,33 +0,0 @@ -# Version and symbol export for libSaLck.so - -OPENAIS_LCK_B.01.01 { - global: - saLckInitialize; - saLckSelectionObjectGet; - saLckDispatch; - saLckinalize; - saLckinalize; - saLckResourceOpen; - saLckResourceOpenAsync; - saLckResourcClose; - saLckResourcLock; - saLckResourceLockAsync; - saLckResourceUnlock; - saLckResourceUnlockAsync; - saLckResourceLockPurge; - - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libSaMsg.versions b/openais/lib/libSaMsg.versions deleted file mode 100644 index e7a646b0..00000000 --- a/openais/lib/libSaMsg.versions +++ /dev/null @@ -1,41 +0,0 @@ -# Version and symbol export for libSaMsg.so - -OPENAIS_MSG_B.01.01 { - global: - saMsgInitialize; - saMsgSelectionObjectGet; - saMsgDispatch; - saMsginalize; - saMsgQueueOpen; - saMsgQueueOpenAsync; - saMsgQueueClose; - saMsgQueueStatusGet; - saMsgQueueUnlink; - saMsgQueueGroupCreate; - saMsgQueueGroupInsert; - saMsgQueueGroupRemove; - saMsgQueueGroupDelete; - saMsgQueueGroupTrack; - saMsgQueueGroupTrackStop; - saMsgMessageSend; - saMsgMessageSendAsync; - saMsgMessageSendAsync; - saMsgMessageGet; - saMsgMessageCancel; - saMsgMessageReply; - saMsgMessageReplyAsync; - local: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saPollRetry; - saRecvRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/libaisutil.versions b/openais/lib/libaisutil.versions deleted file mode 100644 index 4dff075c..00000000 --- a/openais/lib/libaisutil.versions +++ /dev/null @@ -1,18 +0,0 @@ -# Version and symbol export for libaisutil.so - -OPENAIS_UTIL_2.0 { - global: - saHandleCreate; - saHandleDestroy; - saHandleInstanceGet; - saHandleInstancePut; - saRecvRetry; - saSelectRetry; - saSendMsgReceiveReply; - saSendMsgRetry; - saSendReceiveReply; - saSendRetry; - saServiceConnect; - saVersionVerify; - clustTimeNow; -}; diff --git a/openais/lib/msg.c b/openais/lib/msg.c deleted file mode 100644 index df2d85da..00000000 --- a/openais/lib/msg.c +++ /dev/null @@ -1,1851 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include "../include/ipc_msg.h" -#include "util.h" - - -struct message_overlay { - mar_res_header_t header __attribute__((aligned(8))); - char data[4096]; -}; - -/* - * Data structure for instance data - */ -struct msgInstance { - int response_fd; - int dispatch_fd; - SaMsgCallbacksT callbacks; - int finalize; - SaMsgHandleT msgHandle; - pthread_mutex_t response_mutex; - pthread_mutex_t dispatch_mutex; - struct list_head queue_list; -}; - -struct msgQueueInstance { - int response_fd; - SaMsgHandleT msgHandle; - SaMsgQueueHandleT queueHandle; - SaMsgQueueOpenFlagsT openFlags; - SaNameT queueName; - struct list_head list; - struct list_head section_iteration_list_head; - pthread_mutex_t *response_mutex; -}; - -void msgHandleInstanceDestructor (void *instance); -void queueHandleInstanceDestructor (void *instance); - -/* - * All MSG instances in this database - */ -static struct saHandleDatabase msgHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = msgHandleInstanceDestructor -}; - -/* - * All Queue instances in this database - */ -static struct saHandleDatabase queueHandleDatabase = { - .handleCount = 0, - .handles = 0, - .mutex = PTHREAD_MUTEX_INITIALIZER, - .handleInstanceDestructor = queueHandleInstanceDestructor -}; - -/* - * Versions supported - */ -static SaVersionT msgVersionsSupported[] = { - { 'B', 1, 1 } -}; - -static struct saVersionDatabase msgVersionDatabase = { - sizeof (msgVersionsSupported) / sizeof (SaVersionT), - msgVersionsSupported -}; - -struct iteratorSectionIdListEntry { - struct list_head list; - unsigned char data[0]; -}; - -/* - * Implementation - */ -void msgHandleInstanceDestructor (void *instance) -{ - struct msgInstance *msgInstance = instance; - - pthread_mutex_destroy (&msgInstance->response_mutex); - pthread_mutex_destroy (&msgInstance->dispatch_mutex); -} - -void queueHandleInstanceDestructor (void *instance) -{ - return; -} - -#ifdef COMPILE_OUT - -static void msgQueueInstanceFinalize (struct msgQueueInstance *msgQueueInstance) -{ - struct msgSectionIterationInstance *sectionIterationInstance; - struct list_head *sectionIterationList; - struct list_head *sectionIterationListNext; - - for (sectionIterationList = msgQueueInstance->section_iteration_list_head.next, - sectionIterationListNext = sectionIterationList->next; - sectionIterationList != &msgQueueInstance->section_iteration_list_head; - sectionIterationList = sectionIterationListNext, - sectionIterationListNext = sectionIterationList->next) { - - sectionIterationInstance = list_entry (sectionIterationList, - struct msgSectionIterationInstance, list); - - msgSectionIterationInstanceFinalize (sectionIterationInstance); - } - - list_del (&msgQueueInstance->list); - - saHandleDestroy (&queueHandleDatabase, msgQueueInstance->queueHandle); -} - -static void msgInstanceFinalize (struct msgInstance *msgInstance) -{ - struct msgQueueInstance *msgQueueInstance; - struct list_head *queueInstanceList; - struct list_head *queueInstanceListNext; - - for (queueInstanceList = msgInstance->queue_list.next, - queueInstanceListNext = queueInstanceList->next; - queueInstanceList != &msgInstance->queue_list; - queueInstanceList = queueInstanceListNext, - queueInstanceListNext = queueInstanceList->next) { - - msgQueueInstance = list_entry (queueInstanceList, - struct msgQueueInstance, list); - - msgQueueInstanceFinalize (msgQueueInstance); - } - - saHandleDestroy (&msgHandleDatabase, msgInstance->msgHandle); -} - -#endif /* COMPILE_OUT */ - -SaAisErrorT -saMsgInitialize ( - SaMsgHandleT *msgHandle, - const SaMsgCallbacksT *callbacks, - SaVersionT *version) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - - if (msgHandle == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saVersionVerify (&msgVersionDatabase, version); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleCreate (&msgHandleDatabase, sizeof (struct msgInstance), - msgHandle); - if (error != SA_AIS_OK) { - goto error_no_destroy; - } - - error = saHandleInstanceGet (&msgHandleDatabase, *msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgInitialize { msgHandle = %llx }\n", - (unsigned long long) *msgHandle); - - msgInstance->response_fd = -1; - - error = saServiceConnect (&msgInstance->response_fd, - &msgInstance->dispatch_fd, MSG_SERVICE); - if (error != SA_AIS_OK) { - goto error_put_destroy; - } - - if (callbacks) { - memcpy (&msgInstance->callbacks, callbacks, sizeof (SaMsgCallbacksT)); - } else { - memset (&msgInstance->callbacks, 0, sizeof (SaMsgCallbacksT)); - } - - list_init (&msgInstance->queue_list); - - msgInstance->msgHandle = *msgHandle; - - pthread_mutex_init (&msgInstance->response_mutex, NULL); - - saHandleInstancePut (&msgHandleDatabase, *msgHandle); - - return (SA_AIS_OK); - -error_put_destroy: - saHandleInstancePut (&msgHandleDatabase, *msgHandle); -error_destroy: - saHandleDestroy (&msgHandleDatabase, *msgHandle); -error_no_destroy: - return (error); -} - -SaAisErrorT -saMsgSelectionObjectGet ( - const SaMsgHandleT msgHandle, - SaSelectionObjectT *selectionObject) -{ - struct msgInstance *msgInstance; - SaAisErrorT error; - - /* DEBUG */ - printf ("[DEBUG]: saMsgSelectionObjectGet { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - if (selectionObject == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - *selectionObject = msgInstance->dispatch_fd; - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (SA_AIS_OK); -} - -SaAisErrorT -saMsgDispatch ( - const SaMsgHandleT msgHandle, - SaDispatchFlagsT dispatchFlags) -{ - struct pollfd ufds; - int poll_fd; - int timeout = 1; - SaMsgCallbacksT callbacks; - SaAisErrorT error; - int dispatch_avail; - struct msgInstance *msgInstance; - struct msgQueueInstance *msgQueueInstance; - int cont = 1; /* always continue do loop except when set to 0 */ - struct message_overlay dispatch_data; - - struct res_lib_msg_queueopenasync *res_lib_msg_queueopenasync; - struct res_lib_msg_messagesendasync *res_lib_msg_messagesendasync; - struct res_lib_msg_queuegrouptrack *res_lib_msg_queuegrouptrack; - - if (dispatchFlags != SA_DISPATCH_ONE && - dispatchFlags != SA_DISPATCH_ALL && - dispatchFlags != SA_DISPATCH_BLOCKING) - { - return (SA_AIS_ERR_INVALID_PARAM); - } - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Timeout instantly for SA_DISPATCH_ALL - */ - if (dispatchFlags == SA_DISPATCH_ALL) { - timeout = 0; - } - - do { - /* - * Read data directly from socket - */ - poll_fd = msgInstance->dispatch_fd; - ufds.fd = poll_fd; - ufds.events = POLLIN; - ufds.revents = 0; - - error = saPollRetry(&ufds, 1, timeout); - if (error != SA_AIS_OK) { - goto error_put; - } - pthread_mutex_lock(&msgInstance->dispatch_mutex); - - if (msgInstance->finalize == 1) { - error = SA_AIS_OK; - goto error_unlock; - } - - if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_unlock; - } - - dispatch_avail = (ufds.revents & POLLIN); - - if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) { - pthread_mutex_unlock(&msgInstance->dispatch_mutex); - break; /* exit do while cont is 1 loop */ - } else - - if (dispatch_avail == 0) { - pthread_mutex_unlock(&msgInstance->dispatch_mutex); - continue; - } - - memset(&dispatch_data, 0, sizeof(struct message_overlay)); - - error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.header, - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - - if (dispatch_data.header.size > sizeof (mar_res_header_t)) { - error = saRecvRetry (msgInstance->dispatch_fd, &dispatch_data.data, - dispatch_data.header.size - sizeof (mar_res_header_t)); - if (error != SA_AIS_OK) { - goto error_unlock; - } - } - - /* - * Make copy of callbacks, message data, unlock instance, - * and call callback. A risk of this dispatch method is that - * the callback routines may operate at the same time that - * MsgFinalize has been called in another thread. - */ - memcpy(&callbacks, &msgInstance->callbacks, - sizeof(msgInstance->callbacks)); - - pthread_mutex_unlock(&msgInstance->dispatch_mutex); - - /* DEBUG */ - printf ("[DEBUG]: saMsgDispatch { id = %d }\n", - dispatch_data.header.id); - - /* - * Dispatch incoming response - */ - switch (dispatch_data.header.id) - { - case MESSAGE_RES_MSG_QUEUEOPENASYNC: - - if (callbacks.saMsgQueueOpenCallback == NULL) { - continue; - } - res_lib_msg_queueopenasync = - (struct res_lib_msg_queueopenasync *) &dispatch_data; - - /* - * This instance get/listadd/put required so that close - * later has the proper list of queues - */ - if (res_lib_msg_queueopenasync->header.error == SA_AIS_OK) { - error = saHandleInstanceGet (&queueHandleDatabase, - res_lib_msg_queueopenasync->queueHandle, - (void *)&msgQueueInstance); - - assert (error == SA_AIS_OK); - - /* - * open succeeded without error - */ - list_init (&msgQueueInstance->list); - list_init (&msgQueueInstance->section_iteration_list_head); - list_add (&msgQueueInstance->list, - &msgInstance->queue_list); - - callbacks.saMsgQueueOpenCallback( - res_lib_msg_queueopenasync->invocation, - res_lib_msg_queueopenasync->queueHandle, - res_lib_msg_queueopenasync->header.error); - saHandleInstancePut (&queueHandleDatabase, - res_lib_msg_queueopenasync->queueHandle); - } else { - /* - * open failed with error - */ - callbacks.saMsgQueueOpenCallback( - res_lib_msg_queueopenasync->invocation, - -1, - res_lib_msg_queueopenasync->header.error); - } - - break; - - case MESSAGE_RES_MSG_MESSAGESENDASYNC: - - if (callbacks.saMsgMessageDeliveredCallback == NULL) { - continue; - } - res_lib_msg_messagesendasync = - (struct res_lib_msg_messagesendasync *) &dispatch_data; - - callbacks.saMsgMessageDeliveredCallback ( - res_lib_msg_messagesendasync->invocation, - res_lib_msg_messagesendasync->header.error); - - break; - - case MESSAGE_RES_MSG_QUEUEGROUPTRACK: - - if (callbacks.saMsgQueueGroupTrackCallback == NULL) { - continue; - } - res_lib_msg_queuegrouptrack = - (struct res_lib_msg_queuegrouptrack *) &dispatch_data; - - res_lib_msg_queuegrouptrack->notificationBuffer.notification = - (SaMsgQueueGroupNotificationT *) - (((char *) &dispatch_data) + sizeof (struct res_lib_msg_queuegrouptrack)); - - callbacks.saMsgQueueGroupTrackCallback ( - &res_lib_msg_queuegrouptrack->queueGroupName, - &res_lib_msg_queuegrouptrack->notificationBuffer, - res_lib_msg_queuegrouptrack->numberOfMembers, - res_lib_msg_queuegrouptrack->header.error); - - break; - - default: - /* TODO */ - break; - } - - /* - * Determine if more messages should be processed - */ - switch (dispatchFlags) - { - case SA_DISPATCH_ONE: - cont = 0; - break; - case SA_DISPATCH_ALL: - break; - case SA_DISPATCH_BLOCKING: - break; - } - } while (cont); - -error_unlock: - pthread_mutex_unlock(&msgInstance->dispatch_mutex); -error_put: - saHandleInstancePut(&msgHandleDatabase, msgHandle); -error_exit: - return (error); -} - -SaAisErrorT -saMsgFinalize ( - const SaMsgHandleT msgHandle) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - - /* DEBUG */ - printf ("[DEBUG]: saMsgFinalize { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - pthread_mutex_lock (&msgInstance->response_mutex); - - /* - * Another thread has already started finalizing - */ - if (msgInstance->finalize) { - pthread_mutex_unlock (&msgInstance->response_mutex); - saHandleInstancePut (&msgHandleDatabase, msgHandle); - return (SA_AIS_ERR_BAD_HANDLE); - } - - msgInstance->finalize = 1; - - pthread_mutex_unlock (&msgInstance->response_mutex); - - /* TODO */ - /* msgInstanceFinalize (msgInstance); */ - - if (msgInstance->response_fd != -1) { - shutdown (msgInstance->response_fd, 0); - close (msgInstance->response_fd); - } - - if (msgInstance->dispatch_fd != -1) { - shutdown (msgInstance->dispatch_fd, 0); - close (msgInstance->dispatch_fd); - } - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (SA_AIS_OK); -} - -SaAisErrorT -saMsgQueueOpen ( - SaMsgHandleT msgHandle, - const SaNameT *queueName, - const SaMsgQueueCreationAttributesT *creationAttributes, - SaMsgQueueOpenFlagsT openFlags, - SaTimeT timeout, - SaMsgQueueHandleT *queueHandle) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct msgQueueInstance *msgQueueInstance; - struct req_lib_msg_queueopen req_lib_msg_queueopen; - struct res_lib_msg_queueopen res_lib_msg_queueopen; - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueOpen { queueName = %s }\n", - (char *) queueName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saHandleCreate (&queueHandleDatabase, - sizeof (struct msgQueueInstance), queueHandle); - if (error != SA_AIS_OK) { - goto error_put_msg; - } - - error = saHandleInstanceGet (&queueHandleDatabase, - *queueHandle, (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - msgQueueInstance->response_fd = msgInstance->response_fd; - msgQueueInstance->response_mutex = &msgInstance->response_mutex; - - msgQueueInstance->msgHandle = msgHandle; - msgQueueInstance->queueHandle = *queueHandle; - msgQueueInstance->openFlags = openFlags; - - req_lib_msg_queueopen.header.size = - sizeof (struct req_lib_msg_queueopen); - req_lib_msg_queueopen.header.id = - MESSAGE_REQ_MSG_QUEUEOPEN; - - memcpy (&req_lib_msg_queueopen.queueName, queueName, - sizeof (SaNameT)); - memcpy (&msgQueueInstance->queueName, queueName, - sizeof (SaNameT)); - - req_lib_msg_queueopen.invocation = 0; - req_lib_msg_queueopen.creationAttributesSet = 0; - - if (creationAttributes) { - memcpy (&req_lib_msg_queueopen.creationAttributes, - creationAttributes, - sizeof (SaMsgQueueCreationAttributesT)); - req_lib_msg_queueopen.creationAttributesSet = 1; - } - - req_lib_msg_queueopen.openFlags = openFlags; /* ? */ - req_lib_msg_queueopen.queueHandle = *queueHandle; /* ? */ - req_lib_msg_queueopen.timeout = timeout; /* ? */ - - pthread_mutex_lock (msgQueueInstance->response_mutex); - - error = saSendReceiveReply (msgQueueInstance->response_fd, - &req_lib_msg_queueopen, - sizeof (struct req_lib_msg_queueopen), - &res_lib_msg_queueopen, - sizeof (struct res_lib_msg_queueopen)); - - pthread_mutex_unlock (msgQueueInstance->response_mutex); - - if (res_lib_msg_queueopen.header.error != SA_AIS_OK) { - error = res_lib_msg_queueopen.header.error; - goto error_put_destroy; - } - - saHandleInstancePut (&queueHandleDatabase, *queueHandle); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error); - -error_put_destroy: - saHandleInstancePut (&queueHandleDatabase, *queueHandle); -error_destroy: - saHandleDestroy (&queueHandleDatabase, *queueHandle); -error_put_msg: - saHandleInstancePut (&msgHandleDatabase, msgHandle); -error_exit: - return (error); -} - -SaAisErrorT -saMsgQueueOpenAsync ( - SaMsgHandleT msgHandle, - SaInvocationT invocation, - const SaNameT *queueName, - const SaMsgQueueCreationAttributesT *creationAttributes, - SaMsgQueueOpenFlagsT openFlags) -{ - SaAisErrorT error; - SaMsgQueueHandleT queueHandle; - struct msgInstance *msgInstance; - struct msgQueueInstance *msgQueueInstance; - struct req_lib_msg_queueopen req_lib_msg_queueopen; - struct res_lib_msg_queueopenasync res_lib_msg_queueopenasync; - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueOpenAsync { queueName = %s }\n", - (char *) queueName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if (msgInstance->callbacks.saMsgQueueOpenCallback == NULL) { - error = SA_AIS_ERR_INIT; - goto error_put_msg; - } - - error = saHandleCreate (&queueHandleDatabase, - sizeof (struct msgQueueInstance), &queueHandle); - if (error != SA_AIS_OK) { - goto error_put_msg; - } - - error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - goto error_destroy; - } - - msgQueueInstance->response_fd = msgInstance->response_fd; - msgQueueInstance->response_mutex = &msgInstance->response_mutex; - - msgQueueInstance->msgHandle = msgHandle; - msgQueueInstance->queueHandle = queueHandle; - msgQueueInstance->openFlags = openFlags; - - req_lib_msg_queueopen.header.size = - sizeof (struct req_lib_msg_queueopen); - req_lib_msg_queueopen.header.id = - MESSAGE_REQ_MSG_QUEUEOPENASYNC; - - memcpy (&req_lib_msg_queueopen.queueName, queueName, - sizeof (SaNameT)); - memcpy (&msgQueueInstance->queueName, queueName, - sizeof (SaNameT)); - - req_lib_msg_queueopen.invocation = invocation; - req_lib_msg_queueopen.creationAttributesSet = 0; - - if (creationAttributes) { - memcpy (&req_lib_msg_queueopen.creationAttributes, - creationAttributes, - sizeof (SaMsgQueueCreationAttributesT)); - req_lib_msg_queueopen.creationAttributesSet = 1; - } - - req_lib_msg_queueopen.openFlags = openFlags; /* ? */ - req_lib_msg_queueopen.queueHandle = queueHandle; /* ? */ - req_lib_msg_queueopen.timeout = 0; /* ? */ - - pthread_mutex_lock (msgQueueInstance->response_mutex); - - error = saSendReceiveReply (msgQueueInstance->response_fd, - &req_lib_msg_queueopen, - sizeof (struct req_lib_msg_queueopen), - &res_lib_msg_queueopenasync, - sizeof (struct res_lib_msg_queueopenasync)); - - pthread_mutex_unlock (msgQueueInstance->response_mutex); - - if (res_lib_msg_queueopenasync.header.error != SA_AIS_OK) { - error = res_lib_msg_queueopenasync.header.error; - goto error_put_destroy; - } - - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error); - -error_put_destroy: - saHandleInstancePut (&queueHandleDatabase, queueHandle); -error_destroy: - saHandleDestroy (&queueHandleDatabase, queueHandle); -error_put_msg: - saHandleInstancePut (&msgHandleDatabase, msgHandle); -error_exit: - return (error); -} - -SaAisErrorT -saMsgQueueClose ( - SaMsgQueueHandleT queueHandle) -{ - SaAisErrorT error; - struct msgQueueInstance *msgQueueInstance; - struct req_lib_msg_queueclose req_lib_msg_queueclose; - struct res_lib_msg_queueclose res_lib_msg_queueclose; - - error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queueclose.header.size = - sizeof (struct req_lib_msg_queueclose); - req_lib_msg_queueclose.header.id = - MESSAGE_REQ_MSG_QUEUECLOSE; - - memcpy (&req_lib_msg_queueclose.queueName, &msgQueueInstance->queueName, - sizeof (SaNameT)); - - pthread_mutex_lock (msgQueueInstance->response_mutex); - - error = saSendReceiveReply (msgQueueInstance->response_fd, - &req_lib_msg_queueclose, - sizeof (struct req_lib_msg_queueclose), - &res_lib_msg_queueclose, - sizeof (struct res_lib_msg_queueclose)); - - pthread_mutex_unlock (msgQueueInstance->response_mutex); - - if (error == SA_AIS_OK) { - error = res_lib_msg_queueclose.header.error; - } - - if (error == SA_AIS_OK) { - /* TODO */ - /* msgQueueInstanceFinalize (msgQueueInstance); */ - } - - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - return (error); -} - -SaAisErrorT -saMsgQueueStatusGet ( - SaMsgHandleT msgHandle, - const SaNameT *queueName, - SaMsgQueueStatusT *queueStatus) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuestatusget req_lib_msg_queuestatusget; - struct res_lib_msg_queuestatusget res_lib_msg_queuestatusget; - - if (queueName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueStatusGet { queueName = %s }\n", - (char *) queueName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuestatusget.header.size = - sizeof (struct req_lib_msg_queuestatusget); - req_lib_msg_queuestatusget.header.id = - MESSAGE_REQ_MSG_QUEUESTATUSGET; - - memcpy (&req_lib_msg_queuestatusget.queueName, queueName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuestatusget, - sizeof (struct req_lib_msg_queuestatusget), - &res_lib_msg_queuestatusget, - sizeof (struct res_lib_msg_queuestatusget)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - if (error == SA_AIS_OK) - error = res_lib_msg_queuestatusget.header.error; - if (error == SA_AIS_OK) { - memcpy (queueStatus, &res_lib_msg_queuestatusget.queueStatus, - sizeof (SaMsgQueueStatusT)); - } - - return (error); -} - -SaAisErrorT -saMsgQueueRetentionTimeSet ( - SaMsgQueueHandleT queueHandle, - SaTimeT *retentionTime) -{ - SaAisErrorT error; - struct msgQueueInstance *msgQueueInstance; - - error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* TODO */ - - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - return (error); -} - -SaAisErrorT -saMsgQueueUnlink ( - SaMsgHandleT msgHandle, - const SaNameT *queueName) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queueunlink req_lib_msg_queueunlink; - struct res_lib_msg_queueunlink res_lib_msg_queueunlink; - - if (queueName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueUnlink { queueName = %s }\n", - (char *) queueName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queueunlink.header.size = - sizeof (struct req_lib_msg_queueunlink); - req_lib_msg_queueunlink.header.id = - MESSAGE_REQ_MSG_QUEUEUNLINK; - - memcpy (&req_lib_msg_queueunlink.queueName, queueName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queueunlink, - sizeof (struct req_lib_msg_queueunlink), - &res_lib_msg_queueunlink, - sizeof (struct res_lib_msg_queueunlink)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queueunlink.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupCreate ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - SaMsgQueueGroupPolicyT queueGroupPolicy) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuegroupcreate req_lib_msg_queuegroupcreate; - struct res_lib_msg_queuegroupcreate res_lib_msg_queuegroupcreate; - - if (queueGroupName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupCreate { queueGroupName = %s }\n", - (char *) queueGroupName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuegroupcreate.header.size = - sizeof (struct req_lib_msg_queuegroupcreate); - req_lib_msg_queuegroupcreate.header.id = - MESSAGE_REQ_MSG_QUEUEGROUPCREATE; - - memcpy (&req_lib_msg_queuegroupcreate.queueGroupName, queueGroupName, - sizeof (SaNameT)); - - req_lib_msg_queuegroupcreate.queueGroupPolicy = queueGroupPolicy; - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuegroupcreate, - sizeof (struct req_lib_msg_queuegroupcreate), - &res_lib_msg_queuegroupcreate, - sizeof (struct res_lib_msg_queuegroupcreate)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queuegroupcreate.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupInsert ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - const SaNameT *queueName) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuegroupinsert req_lib_msg_queuegroupinsert; - struct res_lib_msg_queuegroupinsert res_lib_msg_queuegroupinsert; - - if (queueName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupInsert { queueGroupName = %s }\n", - (char *) queueGroupName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuegroupinsert.header.size = - sizeof (struct req_lib_msg_queuegroupinsert); - req_lib_msg_queuegroupinsert.header.id = - MESSAGE_REQ_MSG_QUEUEGROUPINSERT; - - memcpy (&req_lib_msg_queuegroupinsert.queueName, queueName, - sizeof (SaNameT)); - memcpy (&req_lib_msg_queuegroupinsert.queueGroupName, queueGroupName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuegroupinsert, - sizeof (struct req_lib_msg_queuegroupinsert), - &res_lib_msg_queuegroupinsert, - sizeof (struct res_lib_msg_queuegroupinsert)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queuegroupinsert.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupRemove ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - const SaNameT *queueName) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuegroupremove req_lib_msg_queuegroupremove; - struct res_lib_msg_queuegroupremove res_lib_msg_queuegroupremove; - - if (queueName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupRemove { queueGroupName = %s }\n", - (char *) queueGroupName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuegroupremove.header.size = - sizeof (struct req_lib_msg_queuegroupremove); - req_lib_msg_queuegroupremove.header.id = - MESSAGE_REQ_MSG_QUEUEGROUPREMOVE; - - memcpy (&req_lib_msg_queuegroupremove.queueName, queueName, - sizeof (SaNameT)); - memcpy (&req_lib_msg_queuegroupremove.queueGroupName, queueGroupName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuegroupremove, - sizeof (struct req_lib_msg_queuegroupremove), - &res_lib_msg_queuegroupremove, - sizeof (struct res_lib_msg_queuegroupremove)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queuegroupremove.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupDelete ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuegroupdelete req_lib_msg_queuegroupdelete; - struct res_lib_msg_queuegroupdelete res_lib_msg_queuegroupdelete; - - if (queueGroupName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupDelete { queueGroupName = %s }\n", - (char *) queueGroupName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuegroupdelete.header.size = - sizeof (struct req_lib_msg_queuegroupdelete); - req_lib_msg_queuegroupdelete.header.id = - MESSAGE_REQ_MSG_QUEUEGROUPDELETE; - - memcpy (&req_lib_msg_queuegroupdelete.queueGroupName, queueGroupName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuegroupdelete, - sizeof (struct req_lib_msg_queuegroupdelete), - &res_lib_msg_queuegroupdelete, - sizeof (struct res_lib_msg_queuegroupdelete)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queuegroupdelete.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupTrack ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName, - SaUint8T trackFlags, - SaMsgQueueGroupNotificationBufferT *notificationBuffer) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuegrouptrack req_lib_msg_queuegrouptrack; - struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack; - - if (queueGroupName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if ((notificationBuffer != NULL) && - (notificationBuffer->notification != NULL) && - (notificationBuffer->numberOfItems == 0)) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - if ((notificationBuffer != NULL) && - (notificationBuffer->notification == NULL)) { - notificationBuffer->numberOfItems = 0; - } - - if ((trackFlags & SA_TRACK_CHANGES) && - (trackFlags & SA_TRACK_CHANGES_ONLY)) { - return (SA_AIS_ERR_BAD_FLAGS); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupTrack { queueGroupName = %s }\n", - (char *) queueGroupName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuegrouptrack.header.size = - sizeof (struct req_lib_msg_queuegrouptrack); - req_lib_msg_queuegrouptrack.header.id = - MESSAGE_REQ_MSG_QUEUEGROUPTRACK; - - req_lib_msg_queuegrouptrack.trackFlags = trackFlags; - req_lib_msg_queuegrouptrack.bufferFlag = (notificationBuffer != NULL); - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupTrack { bufferFlag = %d }\n", - (int)(req_lib_msg_queuegrouptrack.bufferFlag)); - - memcpy (&req_lib_msg_queuegrouptrack.queueGroupName, queueGroupName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - /* - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuegrouptrack, - sizeof (struct req_lib_msg_queuegrouptrack), - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - */ - - error = saSendRetry (msgInstance->response_fd, &req_lib_msg_queuegrouptrack, - sizeof (struct req_lib_msg_queuegrouptrack)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if ((trackFlags & SA_TRACK_CURRENT) && (notificationBuffer != NULL)) { - if (notificationBuffer->notification != NULL) { - if (notificationBuffer->numberOfItems < res_lib_msg_queuegrouptrack.numberOfMembers) { - error = SA_AIS_ERR_NO_SPACE; - goto error_exit; - } - } else { - notificationBuffer->notification = - malloc (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.numberOfMembers); - - if (notificationBuffer->notification == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - memset (notificationBuffer->notification, 0, - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.numberOfMembers)); - } - - error = saRecvRetry (msgInstance->response_fd, - notificationBuffer->notification, - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.numberOfMembers)); - } - -error_exit: - pthread_mutex_unlock (&msgInstance->response_mutex); -error_put_msg: - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrack.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupTrackStop ( - SaMsgHandleT msgHandle, - const SaNameT *queueGroupName) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_queuegrouptrackstop req_lib_msg_queuegrouptrackstop; - struct res_lib_msg_queuegrouptrackstop res_lib_msg_queuegrouptrackstop; - - if (queueGroupName == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueGroupTrackStop { queueGroupName = %s }\n", - (char *) queueGroupName->value); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_queuegrouptrackstop.header.size = - sizeof (struct req_lib_msg_queuegrouptrackstop); - req_lib_msg_queuegrouptrackstop.header.id = - MESSAGE_REQ_MSG_QUEUEGROUPTRACKSTOP; - - memcpy (&req_lib_msg_queuegrouptrackstop.queueGroupName, queueGroupName, - sizeof (SaNameT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_queuegrouptrackstop, - sizeof (struct req_lib_msg_queuegrouptrackstop), - &res_lib_msg_queuegrouptrackstop, - sizeof (struct res_lib_msg_queuegrouptrackstop)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_queuegrouptrackstop.header.error : error); -} - -SaAisErrorT -saMsgQueueGroupNotificationFree ( - SaMsgHandleT msgHandle, - SaMsgQueueGroupNotificationT *notification) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* TODO */ - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error); -} - -SaAisErrorT -saMsgMessageSend ( - SaMsgHandleT msgHandle, - const SaNameT *destination, - const SaMsgMessageT *message, - SaTimeT timeout) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_messagesend req_lib_msg_messagesend; - struct res_lib_msg_messagesend res_lib_msg_messagesend; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageSend { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messagesend.header.size = - sizeof (struct req_lib_msg_messagesend) + message->size; - req_lib_msg_messagesend.header.id = - MESSAGE_REQ_MSG_MESSAGESEND; - - memcpy (&req_lib_msg_messagesend.destination, destination, - sizeof (SaNameT)); - memcpy (&req_lib_msg_messagesend.message, message, - sizeof (SaMsgMessageT)); - - req_lib_msg_messagesend.invocation = 0; - req_lib_msg_messagesend.ackFlags = 0; - req_lib_msg_messagesend.async_call = 0; - req_lib_msg_messagesend.timeout = timeout; - - pthread_mutex_lock (&msgInstance->response_mutex); - - /* - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_messagesend, - sizeof (struct req_lib_msg_messagesend), - &res_lib_msg_messagesend, - sizeof (struct res_lib_msg_messagesend)); - */ - - error = saSendRetry (msgInstance->response_fd, &req_lib_msg_messagesend, - sizeof (struct req_lib_msg_messagesend)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saSendRetry (msgInstance->response_fd, - message->data, message->size); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_messagesend, - sizeof (struct res_lib_msg_messagesend)); - -error_exit: - pthread_mutex_unlock (&msgInstance->response_mutex); -error_put_msg: - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_messagesend.header.error : error); -} - -SaAisErrorT -saMsgMessageSendAsync ( - SaMsgHandleT msgHandle, - SaInvocationT invocation, - const SaNameT *destination, - const SaMsgMessageT *message, - SaMsgAckFlagsT ackFlags) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_messagesend req_lib_msg_messagesend; - struct res_lib_msg_messagesendasync res_lib_msg_messagesendasync; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageSendAsync { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messagesend.header.size = - sizeof (struct req_lib_msg_messagesend) + message->size; - req_lib_msg_messagesend.header.id = - MESSAGE_REQ_MSG_MESSAGESENDASYNC; - - memcpy (&req_lib_msg_messagesend.destination, destination, - sizeof (SaNameT)); - memcpy (&req_lib_msg_messagesend.message, message, - sizeof (SaMsgMessageT)); - - req_lib_msg_messagesend.invocation = invocation; - req_lib_msg_messagesend.ackFlags = ackFlags; - req_lib_msg_messagesend.async_call = 1; - req_lib_msg_messagesend.timeout = 0; - - pthread_mutex_lock (&msgInstance->response_mutex); - - /* - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_messagesend, - sizeof (struct req_lib_msg_messagesend), - &res_lib_msg_messagesendasync, - sizeof (struct res_lib_msg_messagesendasync)); - */ - - error = saSendRetry (msgInstance->response_fd, &req_lib_msg_messagesend, - sizeof (struct req_lib_msg_messagesend)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saSendRetry (msgInstance->response_fd, - message->data, message->size); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (msgInstance->response_fd, &res_lib_msg_messagesendasync, - sizeof (struct res_lib_msg_messagesendasync)); - -error_exit: - pthread_mutex_unlock (&msgInstance->response_mutex); -error_put_msg: - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_messagesendasync.header.error : error); -} - -SaAisErrorT -saMsgMessageGet ( - SaMsgQueueHandleT queueHandle, - SaMsgMessageT *message, - SaTimeT *sendTime, - SaMsgSenderIdT *senderId, - SaTimeT timeout) -{ - SaAisErrorT error; - struct msgQueueInstance *msgQueueInstance; - struct req_lib_msg_messageget req_lib_msg_messageget; - struct res_lib_msg_messageget res_lib_msg_messageget; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageGet { queueHandle = %llx }\n", - (unsigned long long) queueHandle); - - error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messageget.header.size = - sizeof (struct req_lib_msg_messageget); - req_lib_msg_messageget.header.id = - MESSAGE_REQ_MSG_MESSAGEGET; - - memcpy (&req_lib_msg_messageget.queueName, &msgQueueInstance->queueName, - sizeof (SaNameT)); - - req_lib_msg_messageget.timeout = timeout; - - pthread_mutex_lock (msgQueueInstance->response_mutex); - - /* - error = saSendReceiveReply (msgQueueInstance->response_fd, - &req_lib_msg_messageget, - sizeof (struct req_lib_msg_messageget), - &res_lib_msg_messageget, - sizeof (struct res_lib_msg_messageget)); - */ - - error = saSendRetry (msgQueueInstance->response_fd, &req_lib_msg_messageget, - sizeof (struct req_lib_msg_messageget)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (msgQueueInstance->response_fd, &res_lib_msg_messageget, - sizeof (struct res_lib_msg_messageget)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - if (message->data == NULL) { - message->size = res_lib_msg_messageget.message.size; - message->data = malloc (message->size); - if (message->data == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - } else { - if (res_lib_msg_messageget.message.size > message->size) { - error = SA_AIS_ERR_NO_SPACE; - goto error_exit; - } - } - - error = saRecvRetry (msgQueueInstance->response_fd, - message->data, message->size); - -error_exit: - pthread_mutex_unlock (msgQueueInstance->response_mutex); -error_put_msg: - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - if (error == SA_AIS_OK) - error = res_lib_msg_messageget.header.error; - if (error == SA_AIS_OK) { - *sendTime = res_lib_msg_messageget.sendTime; - memcpy (senderId, &res_lib_msg_messageget.senderId, - sizeof (SaMsgSenderIdT)); - } - - return (error); -} - -SaAisErrorT -saMsgMessageDataFree ( - SaMsgHandleT msgHandle, - void *data) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - - if (data == NULL) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageDataFree { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - free (data); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error); -} - -SaAisErrorT -saMsgMessageCancel ( - SaMsgQueueHandleT queueHandle) -{ - SaAisErrorT error; - struct msgQueueInstance *msgQueueInstance; - struct req_lib_msg_messagecancel req_lib_msg_messagecancel; - struct res_lib_msg_messagecancel res_lib_msg_messagecancel; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageCancel { queueHandle = %llx }\n", - (unsigned long long) queueHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messagecancel.header.size = - sizeof (struct req_lib_msg_messagecancel); - req_lib_msg_messagecancel.header.id = - MESSAGE_REQ_MSG_MESSAGECANCEL; - - pthread_mutex_lock (msgQueueInstance->response_mutex); - - error = saSendReceiveReply (msgQueueInstance->response_fd, - &req_lib_msg_messagecancel, - sizeof (struct req_lib_msg_messagecancel), - &res_lib_msg_messagecancel, - sizeof (struct res_lib_msg_messagecancel)); - - pthread_mutex_unlock (msgQueueInstance->response_mutex); - - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - return (error == SA_AIS_OK ? res_lib_msg_messagecancel.header.error : error); -} - -SaAisErrorT -saMsgMessageSendReceive ( - SaMsgHandleT msgHandle, - const SaNameT *destination, - const SaMsgMessageT *sendMessage, - SaMsgMessageT *receiveMessage, - SaTimeT *replySendTime, - SaTimeT timeout) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_messagesendreceive req_lib_msg_messagesendreceive; - struct res_lib_msg_messagesendreceive res_lib_msg_messagesendreceive; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageSendReceive { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messagesendreceive.header.size = - sizeof (struct req_lib_msg_messagesendreceive); - req_lib_msg_messagesendreceive.header.id = - MESSAGE_REQ_MSG_MESSAGEREPLY; - - memcpy (&req_lib_msg_messagesendreceive.destination, destination, - sizeof (SaNameT)); - - req_lib_msg_messagesendreceive.timeout = timeout; - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_messagesendreceive, - sizeof (struct req_lib_msg_messagesendreceive), - &res_lib_msg_messagesendreceive, - sizeof (struct res_lib_msg_messagesendreceive)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - if (error == SA_AIS_OK) - error = res_lib_msg_messagesendreceive.header.error; - if (error == SA_AIS_OK) { - *replySendTime = res_lib_msg_messagesendreceive.replySendTime; - } - - return (error); -} - -SaAisErrorT -saMsgMessageReply ( - SaMsgHandleT msgHandle, - const SaMsgMessageT *replyMessage, - const SaMsgSenderIdT *senderId, - SaTimeT timeout) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_messagereply req_lib_msg_messagereply; - struct res_lib_msg_messagereply res_lib_msg_messagereply; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageReply { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messagereply.header.size = - sizeof (struct req_lib_msg_messagereply); - req_lib_msg_messagereply.header.id = - MESSAGE_REQ_MSG_MESSAGEREPLY; - - memcpy (&req_lib_msg_messagereply.senderId, senderId, - sizeof (SaMsgSenderIdT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_messagereply, - sizeof (struct req_lib_msg_messagereply), - &res_lib_msg_messagereply, - sizeof (struct res_lib_msg_messagereply)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_messagereply.header.error : error); -} - -SaAisErrorT -saMsgMessageReplyAsync ( - SaMsgHandleT msgHandle, - SaInvocationT invocation, - const SaMsgMessageT *replyMessage, - const SaMsgSenderIdT *senderId, - SaMsgAckFlagsT ackFlags) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - struct req_lib_msg_messagereply req_lib_msg_messagereply; - struct res_lib_msg_messagereplyasync res_lib_msg_messagereplyasync; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMessageReplyAsync { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - req_lib_msg_messagereply.header.size = - sizeof (struct req_lib_msg_messagereply); - req_lib_msg_messagereply.header.id = - MESSAGE_REQ_MSG_MESSAGEREPLY; - - memcpy (&req_lib_msg_messagereply.senderId, senderId, - sizeof (SaMsgSenderIdT)); - - pthread_mutex_lock (&msgInstance->response_mutex); - - error = saSendReceiveReply (msgInstance->response_fd, - &req_lib_msg_messagereply, - sizeof (struct req_lib_msg_messagereply), - &res_lib_msg_messagereplyasync, - sizeof (struct res_lib_msg_messagereplyasync)); - - pthread_mutex_unlock (&msgInstance->response_mutex); - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error == SA_AIS_OK ? res_lib_msg_messagereplyasync.header.error : error); -} - -SaAisErrorT -saMsgQueueCapacityThresholdSet ( - SaMsgQueueHandleT queueHandle, - const SaMsgQueueThresholdsT *thresholds) -{ - SaAisErrorT error; - struct msgQueueInstance *msgQueueInstance; - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueCapacityThresholdsSet { queueHandle = %llx }\n", - (unsigned long long) queueHandle); - - error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* TODO */ - - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - return (error); -} - -SaAisErrorT -saMsgQueueCapacityThresholdGet ( - SaMsgQueueHandleT queueHandle, - SaMsgQueueThresholdsT *thresholds) -{ - SaAisErrorT error; - struct msgQueueInstance *msgQueueInstance; - - /* DEBUG */ - printf ("[DEBUG]: saMsgQueueCapacityThresholdGet { queueHandle = %llx }\n", - (unsigned long long) queueHandle); - - error = saHandleInstanceGet (&queueHandleDatabase, queueHandle, - (void *)&msgQueueInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* TODO */ - - saHandleInstancePut (&queueHandleDatabase, queueHandle); - - return (error); -} - -SaAisErrorT -saMsgMetadataSizeGet ( - SaMsgHandleT msgHandle, - SaUint32T *metadataSize) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - - /* DEBUG */ - printf ("[DEBUG]: saMsgMetadataSizeGet { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* TODO */ - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error); -} - -SaAisErrorT -saMsgLimitGet ( - SaMsgHandleT msgHandle, - SaMsgLimitIdT limitId, - SaLimitValueT *limitValue) -{ - SaAisErrorT error; - struct msgInstance *msgInstance; - - /* DEBUG */ - printf ("[DEBUG]: saMsgLimitGet { msgHandle = %llx }\n", - (unsigned long long) msgHandle); - - error = saHandleInstanceGet (&msgHandleDatabase, msgHandle, - (void *)&msgInstance); - if (error != SA_AIS_OK) { - return (error); - } - - /* TODO */ - - saHandleInstancePut (&msgHandleDatabase, msgHandle); - - return (error); -} diff --git a/openais/lib/util.c b/openais/lib/util.c deleted file mode 100644 index 721a0563..00000000 --- a/openais/lib/util.c +++ /dev/null @@ -1,788 +0,0 @@ -/* - * vi: set autoindent tabstop=4 shiftwidth=4 : - * - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Copyright (c) 2006-2008 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "util.h" - -enum SA_HANDLE_STATE { - SA_HANDLE_STATE_EMPTY, - SA_HANDLE_STATE_PENDINGREMOVAL, - SA_HANDLE_STATE_ACTIVE -}; - -struct saHandle { - int state; - void *instance; - int refCount; - uint32_t check; -}; - -#ifdef OPENAIS_SOLARIS -#define MSG_NOSIGNAL 0 -#endif - -#if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS) -/* SUN_LEN is broken for abstract namespace - */ -#define AIS_SUN_LEN(a) sizeof(*(a)) -#else -#define AIS_SUN_LEN(a) SUN_LEN(a) -#endif - -#ifdef OPENAIS_LINUX -static char *socketname = "libcorosync.socket"; -#else -static char *socketname = "/var/run/libcorosync.socket"; -#endif - -#ifdef SO_NOSIGPIPE -void socket_nosigpipe(int s) -{ - int on = 1; - setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on)); -} -#endif - -SaAisErrorT -saServiceConnect ( - int *responseOut, - int *callbackOut, - enum service_types service) -{ - int responseFD; - int callbackFD; - int result; - struct sockaddr_un address; - mar_req_lib_response_init_t req_lib_response_init; - mar_res_lib_response_init_t res_lib_response_init; - mar_req_lib_dispatch_init_t req_lib_dispatch_init; - mar_res_lib_dispatch_init_t res_lib_dispatch_init; - SaAisErrorT error; - gid_t egid; - - /* - * Allow set group id binaries to be authenticated - */ - egid = getegid(); - setregid (egid, -1); - - memset (&address, 0, sizeof (struct sockaddr_un)); -#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) - address.sun_len = sizeof(struct sockaddr_un); -#endif - address.sun_family = PF_UNIX; -#if defined(OPENAIS_LINUX) - strcpy (address.sun_path + 1, socketname); -#else - strcpy (address.sun_path, socketname); -#endif - responseFD = socket (PF_UNIX, SOCK_STREAM, 0); - if (responseFD == -1) { - return (SA_AIS_ERR_NO_RESOURCES); - } - - socket_nosigpipe (responseFD); - - result = connect (responseFD, (struct sockaddr *)&address, AIS_SUN_LEN(&address)); - if (result == -1) { - close (responseFD); - return (SA_AIS_ERR_TRY_AGAIN); - } - - req_lib_response_init.resdis_header.size = sizeof (req_lib_response_init); - req_lib_response_init.resdis_header.id = MESSAGE_REQ_RESPONSE_INIT; - req_lib_response_init.resdis_header.service = service; - - error = saSendRetry (responseFD, &req_lib_response_init, - sizeof (mar_req_lib_response_init_t)); - if (error != SA_AIS_OK) { - goto error_exit; - } - error = saRecvRetry (responseFD, &res_lib_response_init, - sizeof (mar_res_lib_response_init_t)); - if (error != SA_AIS_OK) { - goto error_exit; - } - - /* - * Check for security errors - */ - if (res_lib_response_init.header.error != SA_AIS_OK) { - error = res_lib_response_init.header.error; - goto error_exit; - } - - *responseOut = responseFD; - -/* if I comment out the 4 lines below the executive crashes */ - callbackFD = socket (PF_UNIX, SOCK_STREAM, 0); - if (callbackFD == -1) { - close (responseFD); - return (SA_AIS_ERR_NO_RESOURCES); - } - - socket_nosigpipe (callbackFD); - - result = connect (callbackFD, (struct sockaddr *)&address, AIS_SUN_LEN(&address)); - if (result == -1) { - close (callbackFD); - close (responseFD); - return (SA_AIS_ERR_TRY_AGAIN); - } - - req_lib_dispatch_init.resdis_header.size = sizeof (req_lib_dispatch_init); - req_lib_dispatch_init.resdis_header.id = MESSAGE_REQ_DISPATCH_INIT; - req_lib_dispatch_init.resdis_header.service = service; - - req_lib_dispatch_init.conn_info = res_lib_response_init.conn_info; - - error = saSendRetry (callbackFD, &req_lib_dispatch_init, - sizeof (mar_req_lib_dispatch_init_t)); - if (error != SA_AIS_OK) { - goto error_exit_two; - } - error = saRecvRetry (callbackFD, &res_lib_dispatch_init, - sizeof (mar_res_lib_dispatch_init_t)); - if (error != SA_AIS_OK) { - goto error_exit_two; - } - - /* - * Check for security errors - */ - if (res_lib_dispatch_init.header.error != SA_AIS_OK) { - error = res_lib_dispatch_init.header.error; - goto error_exit; - } - - *callbackOut = callbackFD; - return (SA_AIS_OK); - -error_exit_two: - close (callbackFD); -error_exit: - close (responseFD); - return (error); -} - -SaAisErrorT -saRecvRetry ( - int s, - void *msg, - size_t len) -{ - SaAisErrorT error = SA_AIS_OK; - int result; - struct msghdr msg_recv; - struct iovec iov_recv; - char *rbuf = (char *)msg; - int processed = 0; - - msg_recv.msg_iov = &iov_recv; - msg_recv.msg_iovlen = 1; - msg_recv.msg_name = 0; - msg_recv.msg_namelen = 0; -#ifndef OPENAIS_SOLARIS - msg_recv.msg_control = 0; - msg_recv.msg_controllen = 0; - msg_recv.msg_flags = 0; -#else - msg_recv.msg_accrights = NULL; - msg_recv.msg_accrightslen = 0; -#endif - -retry_recv: - iov_recv.iov_base = (void *)&rbuf[processed]; - iov_recv.iov_len = len - processed; - - result = recvmsg (s, &msg_recv, MSG_NOSIGNAL); - if (result == -1 && errno == EINTR) { - goto retry_recv; - } - if (result == -1 && errno == EAGAIN) { - goto retry_recv; - } -#if defined(OPENAIS_SOLARIS) || defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) - /* On many OS poll never return POLLHUP or POLLERR. - * EOF is detected when recvmsg return 0. - */ - if (result == 0) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } -#endif - if (result == -1 || result == 0) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - processed += result; - if (processed != len) { - goto retry_recv; - } - assert (processed == len); -error_exit: - return (error); -} - -SaAisErrorT -saSendRetry ( - int s, - const void *msg, - size_t len) -{ - SaAisErrorT error = SA_AIS_OK; - int result; - struct msghdr msg_send; - struct iovec iov_send; - char *rbuf = (char *)msg; - int processed = 0; - - msg_send.msg_iov = &iov_send; - msg_send.msg_iovlen = 1; - msg_send.msg_name = 0; - msg_send.msg_namelen = 0; -#ifndef OPENAIS_SOLARIS - msg_send.msg_control = 0; - msg_send.msg_controllen = 0; - msg_send.msg_flags = 0; -#else - msg_send.msg_accrights = NULL; - msg_send.msg_accrightslen = 0; -#endif - -retry_send: - iov_send.iov_base = (void *)&rbuf[processed]; - iov_send.iov_len = len - processed; - - result = sendmsg (s, &msg_send, MSG_NOSIGNAL); - - /* - * return immediately on any kind of syscall error that maps to - * SA_AIS_ERR if no part of message has been sent - */ - if (result == -1 && processed == 0) { - if (errno == EINTR) { - error = SA_AIS_ERR_TRY_AGAIN; - goto error_exit; - } - if (errno == EAGAIN) { - error = SA_AIS_ERR_TRY_AGAIN; - goto error_exit; - } - if (errno == EFAULT) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - } - - /* - * retry read operations that are already started except - * for fault in that case, return ERR_LIBRARY - */ - if (result == -1 && processed > 0) { - if (errno == EINTR) { - goto retry_send; - } - if (errno == EAGAIN) { - goto retry_send; - } - if (errno == EFAULT) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - } - - /* - * return ERR_LIBRARY on any other syscall error - */ - if (result == -1) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - - processed += result; - if (processed != len) { - goto retry_send; - } - -error_exit: - return (error); -} - -SaAisErrorT saSendMsgRetry ( - int s, - struct iovec *iov, - int iov_len) -{ - SaAisErrorT error = SA_AIS_OK; - int result; - int total_size = 0; - int i; - int csize; - int csize_cntr; - int total_sent = 0; - int iov_len_sendmsg = iov_len; - struct iovec *iov_sendmsg = iov; - struct iovec iovec_save; - int iovec_saved_position = -1; - - struct msghdr msg_send; - - for (i = 0; i < iov_len; i++) { - total_size += iov[i].iov_len; - } - msg_send.msg_iov = iov_sendmsg; - msg_send.msg_iovlen = iov_len_sendmsg; - msg_send.msg_name = 0; - msg_send.msg_namelen = 0; -#ifndef OPENAIS_SOLARIS - msg_send.msg_control = 0; - msg_send.msg_controllen = 0; - msg_send.msg_flags = 0; -#else - msg_send.msg_accrights = NULL; - msg_send.msg_accrightslen = 0; -#endif - -retry_sendmsg: - result = sendmsg (s, &msg_send, MSG_NOSIGNAL); - /* - * Can't send now, and message not committed, so don't retry send - */ - if (result == -1 && iovec_saved_position == -1) { - if (errno == EINTR) { - error = SA_AIS_ERR_TRY_AGAIN; - goto error_exit; - } - if (errno == EAGAIN) { - error = SA_AIS_ERR_TRY_AGAIN; - goto error_exit; - } - if (errno == EFAULT) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - } - - /* - * Retry (and block) if portion of message has already been written - */ - if (result == -1 && iovec_saved_position != -1) { - if (errno == EINTR) { - goto retry_sendmsg; - } - if (errno == EAGAIN) { - goto retry_sendmsg; - } - if (errno == EFAULT) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - } - - /* - * ERR_LIBRARY for any other syscall error - */ - if (result == -1) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - - if (iovec_saved_position != -1) { - memcpy (&iov[iovec_saved_position], &iovec_save, sizeof (struct iovec)); - } - - total_sent += result; - if (total_sent != total_size) { - for (i = 0, csize = 0, csize_cntr = 0; i < iov_len; i++) { - csize += iov[i].iov_len; - if (csize > total_sent) { - break; - } - - csize_cntr += iov[i].iov_len; - } - memcpy (&iovec_save, &iov[i], sizeof (struct iovec)); - iovec_saved_position = i; - iov[i].iov_base = ((char *)(iov[i].iov_base)) + - (total_sent - csize_cntr); - iov[i].iov_len = total_size - total_sent; - msg_send.msg_iov = &iov[i]; - msg_send.msg_iovlen = iov_len - i; - - goto retry_sendmsg; - } - -error_exit: - return (error); -} - -SaAisErrorT saSendMsgReceiveReply ( - int s, - struct iovec *iov, - int iov_len, - void *responseMessage, - int responseLen) -{ - SaAisErrorT error = SA_AIS_OK; - - error = saSendMsgRetry (s, iov, iov_len); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (s, responseMessage, responseLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - -error_exit: - return (error); -} - -SaAisErrorT saSendReceiveReply ( - int s, - void *requestMessage, - int requestLen, - void *responseMessage, - int responseLen) -{ - SaAisErrorT error = SA_AIS_OK; - - error = saSendRetry (s, requestMessage, requestLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - - error = saRecvRetry (s, responseMessage, responseLen); - if (error != SA_AIS_OK) { - goto error_exit; - } - -error_exit: - return (error); -} - -SaAisErrorT -saPollRetry ( - struct pollfd *ufds, - unsigned int nfds, - int timeout) -{ - SaAisErrorT error = SA_AIS_OK; - int result; - -retry_poll: - result = poll (ufds, nfds, timeout); - if (result == -1 && errno == EINTR) { - goto retry_poll; - } - if (result == -1) { - error = SA_AIS_ERR_LIBRARY; - } - - return (error); -} - - -SaAisErrorT -saHandleCreate ( - struct saHandleDatabase *handleDatabase, - int instanceSize, - SaUint64T *handleOut) -{ - uint32_t handle; - uint32_t check; - void *newHandles = NULL; - int found = 0; - void *instance; - int i; - - pthread_mutex_lock (&handleDatabase->mutex); - - for (handle = 0; handle < handleDatabase->handleCount; handle++) { - if (handleDatabase->handles[handle].state == SA_HANDLE_STATE_EMPTY) { - found = 1; - break; - } - } - - if (found == 0) { - handleDatabase->handleCount += 1; - newHandles = (struct saHandle *)realloc (handleDatabase->handles, - sizeof (struct saHandle) * handleDatabase->handleCount); - if (newHandles == NULL) { - pthread_mutex_unlock (&handleDatabase->mutex); - return (SA_AIS_ERR_NO_MEMORY); - } - handleDatabase->handles = newHandles; - } - - instance = malloc (instanceSize); - if (instance == 0) { - free (newHandles); - pthread_mutex_unlock (&handleDatabase->mutex); - return (SA_AIS_ERR_NO_MEMORY); - } - - - /* - * This code makes sure the random number isn't zero - * We use 0 to specify an invalid handle out of the 1^64 address space - * If we get 0 200 times in a row, the RNG may be broken - */ - for (i = 0; i < 200; i++) { - check = random(); - if (check != 0) { - break; - } - } - - memset (instance, 0, instanceSize); - - handleDatabase->handles[handle].state = SA_HANDLE_STATE_ACTIVE; - - handleDatabase->handles[handle].instance = instance; - - handleDatabase->handles[handle].refCount = 1; - - handleDatabase->handles[handle].check = check; - - *handleOut = (SaUint64T)((uint64_t)check << 32 | handle); - - pthread_mutex_unlock (&handleDatabase->mutex); - - return (SA_AIS_OK); -} - - -SaAisErrorT -saHandleDestroy ( - struct saHandleDatabase *handleDatabase, - SaUint64T inHandle) -{ - SaAisErrorT error = SA_AIS_OK; - uint32_t check = inHandle >> 32; - uint32_t handle = inHandle & 0xffffffff; - - pthread_mutex_lock (&handleDatabase->mutex); - - if (check != handleDatabase->handles[handle].check) { - pthread_mutex_unlock (&handleDatabase->mutex); - error = SA_AIS_ERR_BAD_HANDLE; - return (error); - } - - handleDatabase->handles[handle].state = SA_HANDLE_STATE_PENDINGREMOVAL; - - pthread_mutex_unlock (&handleDatabase->mutex); - - saHandleInstancePut (handleDatabase, inHandle); - - return (error); -} - - -SaAisErrorT -saHandleInstanceGet ( - struct saHandleDatabase *handleDatabase, - SaUint64T inHandle, - void **instance) -{ - uint32_t check = inHandle >> 32; - uint32_t handle = inHandle & 0xffffffff; - - SaAisErrorT error = SA_AIS_OK; - pthread_mutex_lock (&handleDatabase->mutex); - - if (handle >= (SaUint64T)handleDatabase->handleCount) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_exit; - } - if (handleDatabase->handles[handle].state != SA_HANDLE_STATE_ACTIVE) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_exit; - } - if (check != handleDatabase->handles[handle].check) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_exit; - } - - - *instance = handleDatabase->handles[handle].instance; - - handleDatabase->handles[handle].refCount += 1; - -error_exit: - pthread_mutex_unlock (&handleDatabase->mutex); - - return (error); -} - - -SaAisErrorT -saHandleInstancePut ( - struct saHandleDatabase *handleDatabase, - SaUint64T inHandle) -{ - void *instance; - SaAisErrorT error = SA_AIS_OK; - uint32_t check = inHandle >> 32; - uint32_t handle = inHandle & 0xffffffff; - - pthread_mutex_lock (&handleDatabase->mutex); - - if (check != handleDatabase->handles[handle].check) { - error = SA_AIS_ERR_BAD_HANDLE; - goto error_exit; - } - - handleDatabase->handles[handle].refCount -= 1; - assert (handleDatabase->handles[handle].refCount >= 0); - - if (handleDatabase->handles[handle].refCount == 0) { - instance = (handleDatabase->handles[handle].instance); - handleDatabase->handleInstanceDestructor (instance); - free (instance); - memset (&handleDatabase->handles[handle], 0, sizeof (struct saHandle)); - } - -error_exit: - pthread_mutex_unlock (&handleDatabase->mutex); - - return (error); -} - - -SaAisErrorT -saVersionVerify ( - struct saVersionDatabase *versionDatabase, - SaVersionT *version) -{ - int i; - SaAisErrorT error = SA_AIS_ERR_VERSION; - - if (version == 0) { - return (SA_AIS_ERR_INVALID_PARAM); - } - - /* - * Look for a release code that we support. If we find it then - * make sure that the supported major version is >= to the required one. - * In any case we return what we support in the version structure. - */ - for (i = 0; i < versionDatabase->versionCount; i++) { - - /* - * Check if the caller requires and old release code that we don't support. - */ - if (version->releaseCode < versionDatabase->versionsSupported[i].releaseCode) { - break; - } - - /* - * Check if we can support this release code. - */ - if (version->releaseCode == versionDatabase->versionsSupported[i].releaseCode) { - - /* - * Check if we can support the major version requested. - */ - if (versionDatabase->versionsSupported[i].majorVersion >= version->majorVersion) { - error = SA_AIS_OK; - break; - } - - /* - * We support the release code, but not the major version. - */ - break; - } - } - - /* - * If we fall out of the if loop, the caller requires a release code - * beyond what we support. - */ - if (i == versionDatabase->versionCount) { - i = versionDatabase->versionCount - 1; - } - - /* - * Tell the caller what we support - */ - memcpy(version, &versionDatabase->versionsSupported[i], sizeof(*version)); - return (error); -} - -/* - * Get the time of day and convert to nanoseconds - */ -SaTimeT clustTimeNow(void) -{ - struct timeval tv; - SaTimeT time_now; - - if (gettimeofday(&tv, 0)) { - return 0ULL; - } - - time_now = (SaTimeT)(tv.tv_sec) * 1000000000ULL; - time_now += (SaTimeT)(tv.tv_usec) * 1000ULL; - - return time_now; -} - diff --git a/openais/lib/util.h b/openais/lib/util.h deleted file mode 100644 index 5169e7cc..00000000 --- a/openais/lib/util.h +++ /dev/null @@ -1,151 +0,0 @@ - -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef AIS_UTIL_H_DEFINED -#define AIS_UTIL_H_DEFINED - -#include -#include -#include - -#include - -/* Debug macro - */ -#ifdef DEBUG - #define DPRINT(s) printf s -#else - #define DPRINT(s) -#endif - -#ifdef SO_NOSIGPIPE -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif -void socket_nosigpipe(int s); -#else -#define socket_nosigpipe(s) -#endif - -struct saHandleDatabase { - unsigned int handleCount; - struct saHandle *handles; - pthread_mutex_t mutex; - void (*handleInstanceDestructor) (void *); -}; - - -struct saVersionDatabase { - int versionCount; - SaVersionT *versionsSupported; -}; - -SaAisErrorT -saServiceConnect ( - int *responseOut, - int *callbackOut, - enum service_types service); - -SaAisErrorT -saRecvRetry ( - int s, - void *msg, - size_t len); - -SaAisErrorT -saSendRetry ( - int s, - const void *msg, - size_t len); - -SaAisErrorT saSendMsgRetry ( - int s, - struct iovec *iov, - int iov_len); - -SaAisErrorT saSendMsgReceiveReply ( - int s, - struct iovec *iov, - int iov_len, - void *responseMessage, - int responseLen); - -SaAisErrorT saSendReceiveReply ( - int s, - void *requestMessage, - int requestLen, - void *responseMessage, - int responseLen); - -SaAisErrorT -saPollRetry ( - struct pollfd *ufds, - unsigned int nfds, - int timeout); - -SaAisErrorT -saHandleCreate ( - struct saHandleDatabase *handleDatabase, - int instanceSize, - SaUint64T *handleOut); - -SaAisErrorT -saHandleDestroy ( - struct saHandleDatabase *handleDatabase, - SaUint64T handle); - -SaAisErrorT -saHandleInstanceGet ( - struct saHandleDatabase *handleDatabase, - SaUint64T handle, - void **instance); - -SaAisErrorT -saHandleInstancePut ( - struct saHandleDatabase *handleDatabase, - SaUint64T handle); - -SaAisErrorT -saVersionVerify ( - struct saVersionDatabase *versionDatabase, - SaVersionT *version); - -#define offset_of(type,member) (int)(&(((type *)0)->member)) - -SaTimeT -clustTimeNow(void); - -#endif /* AIS_UTIL_H_DEFINED */ - diff --git a/openais/loc b/openais/loc deleted file mode 100644 index 9060ec8c..00000000 --- a/openais/loc +++ /dev/null @@ -1,12 +0,0 @@ -echo "Application Interface Specification Implementation Lines Of Code" -echo -n "services LOC " -cat services/*.c services/*.h | wc -l - -echo -n "lib LOC " -cat lib/*.c | wc -l - -echo -n "include LOC " -cat include/*.h | wc -l - -echo -n "total LOC " -cat services/*.c services/*.h lib/*.c include/*.h | wc -l diff --git a/openais/services/Makefile b/openais/services/Makefile deleted file mode 100644 index ed299011..00000000 --- a/openais/services/Makefile +++ /dev/null @@ -1,164 +0,0 @@ -# Copyright (c) 2002-2006 MontaVista Software, Inc. -# Copyright (c) 2006 Sun Microsystems, Inc. -# Copyright (c) 2006-2008 Red Hat, Inc. -# -# 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 -# modification, are permitted provided that the following conditions are met: -# -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# - Neither the name of the MontaVista Software, Inc. nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -# Include configuration -# -srcdir ?= $(CURDIR)/../ - -include $(srcdir)Makefile.inc - -override CFLAGS += -I$(srcdir)include -LDFLAGS += -L./ - -ifeq (${OPENAIS_COMPAT}, LINUX) - override LDFLAGS += -ldl -endif - -ifeq (${OPENAIS_COMPAT}, SOLARIS) - override LDFLAGS += -lnsl -lsocket -lrt -endif - -# AMF objects -AMF_SRC = amf.c amfutil.c amfnode.c amfcluster.c amfapp.c amfsg.c amfsu.c amfcomp.c amfsi.c -AMF_OBJS = amf.o amfutil.o amfnode.o amfcluster.o amfapp.o amfsg.o amfsu.o amfcomp.o amfsi.o - -# LCR objects -LCR_SRC = openaisparser.c clm.c ckpt.c evt.c lck.c msg.c cfg.c openaisparser.c $(AMF_SRC) -LCR_OBJS = openaisparser.o clm.o ckpt.o evt.o lck.o msg.o cfg.o openaisparser.o $(AMF_OBJS) - -override CFLAGS += -fPIC - -all: openaisparser.lcrso service_clm.lcrso service_ckpt.lcrso \ - service_evt.lcrso service_lck.lcrso service_msg.lcrso \ - openais-instantiate - -ifeq (${OPENAIS_COMPAT}, DARWIN) - -service_evs.lcrso: evs.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load evs.o -o $@ - -service_clm.lcrso: clm.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load clm.o -o $@ - -service_amf.lcrso: $(AMF_OBJS) - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load $(AMF_OBJS) -o $@ - -service_ckpt.lcrso: ckpt.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load ckpt.o -o $@ - -service_evt.lcrso: evt.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load evt.o -o $@ - -service_lck.lcrso: lck.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load lck.o -o $@ - -service_msg.lcrso: msg.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load msg.o -o $@ - -service_cfg.lcrso: cfg.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load cfg.o -o $@ - -openaisparser.lcrso: openaisparser.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load openaisparser.o -o $@ - -vsf_ykd.lcrso: vsf_ykd.o - $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load vsf_ykd.o -o $@ - - -else - -service_clm.lcrso: clm.o - $(CC) -shared -Wl,-soname,service_clm.lcrso clm.o -o $@ - -service_amf.lcrso: $(AMF_OBJS) - $(CC) -shared -Wl,-soname,service_amf.lcrso $(AMF_OBJS) -o $@ - -service_ckpt.lcrso: ckpt.o - $(CC) -shared -Wl,-soname,service_ckpt.lcrso ckpt.o -o $@ - -service_evt.lcrso: evt.o - $(CC) -shared -Wl,-soname,service_evt.lcrso evt.o -o $@ - -service_lck.lcrso: lck.o - $(CC) -shared -Wl,-soname,service_lck.lcrso lck.o -o $@ - -service_msg.lcrso: msg.o - $(CC) -shared -Wl,-soname,service_msg.lcrso msg.o -o $@ - -service_cfg.lcrso: cfg.o - $(CC) -shared -Wl,-soname,service_cfg.lcrso cfg.o -o $@ - -openaisparser.lcrso: openaisparser.o - $(CC) -shared -Wl,-soname,openaisparser.lcrso openaisparser.o -o $@ - -vsf_ykd.lcrso: vsf_ykd.o - $(CC) -shared -Wl,-soname,vsf_ykd.lcrso vsf_ykd.o -o $@ - -endif - -keygen: keygen.o - $(CC) $(LDFLAGS) keygen.o -o keygen - -openais-instantiate: openais-instantiate.o - $(CC) $(LDFLAGS) openais-instantiate.o -o openais-instantiate - -clean: - rm -f aisexec $(OBJS) *.o *.lcrso libtotem_pg.so* libtotem_pg.a gmon.out - rm -f keygen keygen.o openais-instantiate *.da *.bb *.bbg liblogsys.so* liblogsys.a - -depend: - makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(EXEC_SRC) $(TOTEM_SRC) $(LOGSYS_SRC) $(LCR_SRC) > /dev/null 2>&1 - -# - fPIC rules required for service handler shared objects -../lcr/lcr_ifact.o: ../lcr/lcr_ifact.c - $(CC) $(CFLAGS) $(CPPFLAGS) -DPREFIX='"$(PREFIX)"' -DLCRSODIR='"$(LCRSODIR)"' -I../lcr -c -o $@ ../lcr/lcr_ifact.c - -clm.o: clm.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -amf.o: amf.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -ckpt.o: ckpt.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -evt.o: evt.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -lck.o: lck.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -msg.o: msg.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -openaisparser.o: openaisparser.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< diff --git a/openais/services/amf.c b/openais/services/amf.c deleted file mode 100644 index 36e49810..00000000 --- a/openais/services/amf.c +++ /dev/null @@ -1,2411 +0,0 @@ -/** @file exec/amf.c - * - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Author: Steven Dake (sdake@redhat.com) - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * Description: - * - Introduced AMF B.02 information model - * - Use DN in API and multicast messages - * - (Re-)Introduction of event based multicast messages - * - Refactoring of code into several AMF files - * - AMF Synchronisation Control State Machine - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Main - * - * The functions in this file are responsible for: - * - starting the AMF service (amf_exec_init_fn) - * - build the information model from the configuration file or by - * synchronizing the state with an already started AMF node - * - receiving AMF library requests (message_handler_req_lib_*) - * - multicast AMF library requests to the cluster - * - receiving multicasts (message_handler_req_exec_*) and dispatch the - * requests to a component instance - * - send responses to the AMF library (return values for API calls) - * - handling EVS configuration change events (node leave/join) - * - handling node synchronisation events (sync_*) - * - printing the AMF runtime attributes upon user request (USR2 signal) - * - * Some API requests are responded to directly in the lib message_handler. - * This is normally done when the API request parameters are wrong, e.g. a - * component cannot be found. In that case, the error handling must be taken - * care of in the lib message handler. - * - * 1. AMF Synchronization Control State Machine - * ========================================= - * - * 1.1 State Transition Table - * - * State: Event: Action: New state: - * =========================================================================== - * - init[AMF disabled] UNCONFIGURED - * - init IDLE - * IDLE node_joined A0 PROBING-1 - * PROBING-1 timer1 timeout A1 PROBING-2 - * PROBING-1 SYNC_START A2 UPDATING_CLUSTER_MODEL - * PROBING-1 node_joined A7 PROBING-1 - * PROBING-2 SYNC_START[From me] CREATING_CLUSTER_MODEL - * PROBING-2 SYNC_START[From other] UPDATING_CLUSTER_MODEL - * PROBING-2 node_joined A7 PROBING-2 - * CREATING_CLUSTER_MODEL Model created A8 SYNCHRONIZING - * SYNCHRONIZING sync_activate A10 NORMAL_OPERATION - * SYNCHRONIZING node_left[sync_master] A5 SYNCHRONIZING - * SYNCHRONIZING node_joined[sync_master - * == me] A1 SYNCHRONIZING - * UPDATING_CLUSTER_MODEL SYNC_DATA A3 UPDATING_CLUSTER_MODEL - * UPDATING_CLUSTER_MODEL sync_activate A4 NORMAL_OPERATION - * UPDATING_CLUSTER_MODEL SYNC_START A5 UPDATING_CLUSTER_MODEL - * UPDATING_CLUSTER_MODEL node_left[sync_master] PROBING-1 - * UPDATING_CLUSTER_MODEL node_joined A7 UPDATING_CLUSTER_MODEL - * NORMAL_OPERATION sync_init SYNCHRONIZING - * NORMAL_OPERATION node_left[sync_master] A6 NORMAL_OPERATION - * NORMAL_OPERATION SYNC_REQUEST A8 NORMAL_OPERATION - * Any SYNC_REQUEST A9 No change - * - * 1.2 State Description - * ===================== - * IDLE - Waiting to join cluster. - * PROBING-1 - Start timer1; wait for timer1 to expire or to get synchronised by - * another node. - * PROBING-2 - Waiting for SYNC_START - * CREATING_CLUSTER_MODEL - Read configuration file and create cluster model - * UPDATING_CLUSTER_MODEL - Save sync master node ID; receive SYNC_DATA, - * deserialize and save. - * SYNCHRONIZING - If sync master: multicast SYNC_START followed by encoded AMF - * objects as SYNC_DATA; - * NORMAL - Start cluster or node; wait for cluster changes - * - * 1.3 Action Description - * ====================== - * A0 - Start timer1 - * A1 - Multicast SYNC_START message - * A2 - Stop timer1 - * A3 - Decode AMF object and save - * A4 - Create cluster model; cluster sync ready - * A5 - Free received SYNC_DATA - * A6 - Calculate new sync master - * A7 - Multicast SYNC_REQUEST message - * A8 - Update AMF node object(s) with CLM nodeid - * A9 - Save CLM nodeid & hostname - * A10- Delete CLM nodes; cluster sync ready - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../include/saAis.h" -#include "../include/saAmf.h" -#include "../include/ipc_gen.h" -#include "../include/ipc_amf.h" -#include "../include/list.h" -#include "../lcr/lcr_comp.h" -#include "totempg.h" -#include "util.h" -#include "amf.h" -#include "main.h" -#include "tlist.h" -#include "flow.h" -#include "ipc.h" -#include "service.h" -#include "objdb.h" -#include "logsys.h" -#include "sync.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -#ifdef AMFTEST -#define static -#endif - -#ifndef HOST_NAME_MAX -# define HOST_NAME_MAX 255 -#endif - -#define SYNCTRACE(format, args...) do { \ - TRACE6(">%s: " format, __FUNCTION__, ##args); \ -} while (0) - -/* - * The time AMF will wait to get synchronised by another node - * before it assumes it is alone in the cluster or the first - * node to start. - */ -#ifndef AMF_SYNC_TIMEOUT -#define AMF_SYNC_TIMEOUT 3000 -#endif - -static void amf_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id); -static int amf_lib_exit_fn (void *conn); -static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb); -static int amf_lib_init_fn (void *conn); -static void message_handler_req_lib_amf_componentregister (void *conn, void *msg); -static void message_handler_req_lib_amf_componentunregister (void *conn, void *msg); -static void message_handler_req_lib_amf_pmstart (void *conn, void *msg); -static void message_handler_req_lib_amf_pmstop (void *conn, void *msg); -static void message_handler_req_lib_amf_healthcheckstart (void *conn, void *msg); -static void message_handler_req_lib_amf_healthcheckconfirm (void *conn, void *msg); -static void message_handler_req_lib_amf_healthcheckstop (void *conn, void *msg); -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_protectiongrouptrack (void *conn, void *msg); -static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg); -static void message_handler_req_lib_amf_componenterrorreport (void *conn, void *msg); -static void message_handler_req_lib_amf_componenterrorclear (void *conn, void *msg); -static void message_handler_req_lib_amf_response (void *conn, void *msg); -static void message_handler_req_exec_amf_comp_register ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_comp_error_report ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_comp_instantiate ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_clc_cleanup_completed ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_healthcheck_tmo ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_response ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_sync_start ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_sync_data ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_cluster_start_tmo ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_sync_request ( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_comp_instantiate_tmo( - void *message, unsigned int nodeid); -static void message_handler_req_exec_amf_comp_cleanup_tmo( - void *message, unsigned int nodeid); -static void amf_dump_fn (void); -static void amf_sync_init (void); -static int amf_sync_process (void); -static void amf_sync_abort (void); -static void amf_sync_activate (void); - -struct amf_pd { - struct amf_comp *comp; - struct list_head list; -}; - -/* - * Service Handler Definition - */ -static struct openais_lib_handler amf_lib_service[] = -{ - { /* 0 */ - .lib_handler_fn = message_handler_req_lib_amf_componentregister, - .response_size = sizeof (struct res_lib_amf_componentregister), - .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER, - .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED - }, - { /* 1 */ - .lib_handler_fn = message_handler_req_lib_amf_componentunregister, - .response_size = sizeof (struct res_lib_amf_componentunregister), - .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER, - .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED - }, - { /* 2 */ - .lib_handler_fn = message_handler_req_lib_amf_pmstart, - .response_size = sizeof (struct res_lib_amf_pmstart), - .response_id = MESSAGE_RES_AMF_PMSTART, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 3 */ - .lib_handler_fn = message_handler_req_lib_amf_pmstop, - .response_size = sizeof (struct res_lib_amf_pmstop), - .response_id = MESSAGE_RES_AMF_PMSTOP, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 4 */ - .lib_handler_fn = message_handler_req_lib_amf_healthcheckstart, - .response_size = sizeof (struct res_lib_amf_healthcheckstart), - .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 5 */ - .lib_handler_fn = message_handler_req_lib_amf_healthcheckconfirm, - .response_size = sizeof (struct res_lib_amf_healthcheckconfirm), - .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 6 */ - .lib_handler_fn = message_handler_req_lib_amf_healthcheckstop, - .response_size = sizeof (struct res_lib_amf_healthcheckstop), - .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 7 */ - .lib_handler_fn = message_handler_req_lib_amf_hastateget, - .response_size = sizeof (struct res_lib_amf_hastateget), - .response_id = MESSAGE_RES_AMF_HASTATEGET, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 8 */ - .lib_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete, - .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete), - .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE, - .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED - }, - { /* 9 */ - .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 */ - .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop, - .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop), - .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 11 */ - .lib_handler_fn = message_handler_req_lib_amf_componenterrorreport, - .response_size = sizeof (struct res_lib_amf_componenterrorreport), - .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT, - .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED - }, - { /* 12 */ - .lib_handler_fn = message_handler_req_lib_amf_componenterrorclear, - .response_size = sizeof (struct res_lib_amf_componenterrorclear), - .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR, - .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED - }, - { /* 13 */ - .lib_handler_fn = message_handler_req_lib_amf_response, - .response_size = sizeof (struct res_lib_amf_response), - .response_id = MESSAGE_RES_AMF_RESPONSE, - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED - }, -}; - -/* - * Multicast message handlers - */ -static struct openais_exec_handler amf_exec_service[] = { - { - .exec_handler_fn = message_handler_req_exec_amf_comp_register, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_comp_error_report, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_comp_instantiate, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_clc_cleanup_completed, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_healthcheck_tmo, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_response, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_sync_start, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_sync_data, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_cluster_start_tmo, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_sync_request, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_comp_instantiate_tmo, - }, - { - .exec_handler_fn = message_handler_req_exec_amf_comp_cleanup_tmo, - }, -}; - -/* - * Exports the interface for the service - */ -static struct openais_service_handler amf_service_handler = { - .name = "openais availability management framework B.01.01", - .id = AMF_SERVICE, - .private_data_size = sizeof (struct amf_pd), - .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED, - .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_fn, - .sync_init = amf_sync_init, - .sync_process = amf_sync_process, - .sync_activate = amf_sync_activate, - .sync_abort = amf_sync_abort, -}; - -struct amf_node *this_amf_node; -struct amf_cluster *amf_cluster; - -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 -}; - -static struct lcr_iface openais_amf_ver0[1] = { - { - .name = "openais_amf", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = NULL - } -}; - -static struct lcr_comp amf_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_amf_ver0 -}; - -static struct openais_service_handler *amf_get_handler_ver0 (void) -{ - return (&amf_service_handler); -} - -__attribute__ ((constructor)) static void register_this_component (void) -{ - lcr_interfaces_set (&openais_amf_ver0[0], &amf_service_handler_iface); - lcr_component_register (&amf_comp_ver0); -} - -struct req_exec_amf_comp_register { - mar_req_header_t header; - SaNameT compName; - SaNameT proxyCompName; -}; - -struct req_exec_amf_comp_error_report { - mar_req_header_t header; - SaNameT reportingComponent; - SaNameT erroneousComponent; - SaTimeT errorDetectionTime; - SaAmfRecommendedRecoveryT recommendedRecovery; - SaNtfIdentifierT ntfIdentifier; -}; - -struct req_exec_amf_response { - mar_req_header_t header; - SaUint32T interface; - SaNameT dn; - SaAmfHealthcheckKeyT healtcheck_key; - SaAisErrorT error; - SaAmfRecommendedRecoveryT recommendedRecovery; -}; - -struct req_exec_amf_sync_data { - mar_req_header_t header; - SaUint32T protocol_version; - SaUint32T object_type; -}; - -struct req_exec_amf_sync_request { - mar_req_header_t header; - SaUint32T protocol_version; - char hostname[HOST_NAME_MAX + 1]; -}; - -typedef struct clm_node { - unsigned int nodeid; - char hostname[HOST_NAME_MAX + 1]; - struct clm_node *next; -} clm_node_t; - -static const char *scsm_state_names[] = { - "Unknown", - "IDLE", - "PROBING-1", - "PROBING-2", - "CREATING_CLUSTER_MODEL", - "SYNCHRONIZING", - "NORMAL_OPERATION", - "UPDATING_CLUSTER_MODEL", - "UNCONFIGURED" -}; - -/** - * Storage for AMF Synchronisation Control State Machine (SCSM). - */ -static struct scsm_descriptor scsm; - -static char hostname[HOST_NAME_MAX + 1]; - -/* - * List (implemented as an array) of nodes in the - * cluster, only used for initial start since - * before the AMF node object exist, we don't have - * storage for the information received in - * SYNC_REQUEST msg. - */ -static clm_node_t *clm_node_list; -static int clm_node_list_entries; - -/****************************************************************************** - * Internal (static) utility functions - *****************************************************************************/ - -/** - * Returns true (1) if the key is a member of the list - * @param nodeid - * @param list - * @param entries - * - * @return int - */ -static int is_list_member ( - unsigned int key, unsigned int *list, unsigned int entries) -{ - int i; - - for (i = 0; i < entries; i++) { - if (list[i] == key) { - return 1; - } - } - - return 0; -} - -/** - * Delete the CLM node list - */ -static void clm_node_list_delete (void) -{ - if (clm_node_list != NULL) { - free (clm_node_list); - clm_node_list = NULL; - clm_node_list_entries = 0; - } -} - -/** - * Update an CLM node list entry using nodeid as key. - * Allocate and initialise new memory object if not found. - * @param nodeid - * @param hostname - */ -static void clm_node_list_update (unsigned int nodeid, char *hostname) -{ - int i; - - for (i = 0; i < clm_node_list_entries; i++) { - if (clm_node_list[i].nodeid == nodeid) { - strcpy (clm_node_list[i].hostname, hostname); - return; - } - } - - /* - * Not found, add at tail of list. - */ - clm_node_list_entries++; - clm_node_list = amf_realloc (clm_node_list, - sizeof (clm_node_t) * clm_node_list_entries); - - clm_node_list[clm_node_list_entries - 1].nodeid = nodeid; - strcpy (clm_node_list[clm_node_list_entries - 1].hostname, hostname); -} - -/** - * Returns true (1) if the nodeid is member of the CLM node list - * @param nodeid - * - * @return int - */ -static int clm_node_list_is_member (unsigned int nodeid) -{ - int j; - - for (j = 0; j < clm_node_list_entries; j++) { - if (nodeid == clm_node_list[j].nodeid) - return 1; - } - - return 0; -} - -/** - * Update the nodeid of each AMF node object using the - * CLM node list. - */ -static void nodeids_init (void) -{ - int i; - amf_node_t *amf_node; - - ENTER (""); - - if (amf_cluster == NULL) { - return; - } - - for (i = 0; i < clm_node_list_entries; i++) { - /* - * Iterate all AMF nodes if several AMF nodes are mapped to this - * particular CLM node. - */ - for (amf_node = amf_cluster->node_head; amf_node != NULL; - amf_node = amf_node->next) { - - if (strcmp ((char*)amf_node->saAmfNodeClmNode.value, - clm_node_list[i].hostname) == 0) { - - dprintf ("%s id set to %u", amf_node->name.value, - clm_node_list[i].nodeid); - amf_node->nodeid = clm_node_list[i].nodeid; - } - } - } -} - -/** - * Return pointer to this AMF node object. - * - * @param cluster - * - * @return struct amf_node* - */ -static struct amf_node *get_this_node_obj (void) -{ - char hostname[HOST_NAME_MAX + 1]; - - if (gethostname (hostname, sizeof(hostname)) == -1) { - log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - - return amf_node_find_by_hostname (hostname); -} - -/** - * Prints old and new sync state, sets new state - * @param state - */ -static void sync_state_set (enum scsm_states state) -{ - SYNCTRACE ("changing sync ctrl state from %s to %s", - scsm_state_names[scsm.state], scsm_state_names[state]); - scsm.state = state; -} - -/** - * Multicast SYNC_DATA message containing a model object. - * - * @param buf - * @param len - * @param object_type - * - * @return int - */ -static int mcast_sync_data ( - void *buf, int len, amf_object_type_t object_type) -{ - struct req_exec_amf_sync_data req_exec; - struct iovec iov[2]; - int res; - - req_exec.header.size = sizeof (struct req_exec_amf_sync_data) + len; - SYNCTRACE ("%d bytes, type %u", req_exec.header.size , object_type); - req_exec.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_SYNC_DATA); - req_exec.protocol_version = AMF_PROTOCOL_VERSION; - req_exec.object_type = object_type; - - iov[0].iov_base = (char *)&req_exec; - iov[0].iov_len = sizeof (struct req_exec_amf_sync_data); - iov[1].iov_base = buf; - iov[1].iov_len = len; - - res = totempg_groups_mcast_joined ( - openais_group_handle, iov, 2, TOTEMPG_AGREED); - - if (res != 0) { - dprintf("Unable to send %d bytes of sync data\n", req_exec.header.size); - } - - return res; -} - -static void mcast_sync_request (char *hostname) -{ - struct req_exec_amf_sync_request msg; - memcpy (msg.hostname, hostname, strlen (hostname) + 1); - msg.protocol_version = AMF_PROTOCOL_VERSION; - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_REQUEST, - &msg.protocol_version, sizeof (msg) - sizeof (mar_req_header_t)); -} - -/** - * Timer callback function. The time waiting for external - * synchronisation has expired, start competing with other - * nodes to determine who should read config file. - * @param data - */ -static void timer_function_scsm_timer1_tmo (void *data) -{ - SYNCTRACE (""); - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0); - sync_state_set (PROBING_2); -} - -/** - * Read the configuration file and create cluster model. - */ -static int create_cluster_model (void) -{ - char *error_string; - - SYNCTRACE(""); - - amf_cluster = amf_config_read (&error_string); - if (amf_cluster == NULL) { - log_printf (LOG_LEVEL_ERROR, error_string); - openais_exit_error (AIS_DONE_AMFCONFIGREAD); - } - log_printf (LOG_LEVEL_NOTICE, error_string); - - this_amf_node = get_this_node_obj (); - - if (this_amf_node == NULL) { - log_printf (LOG_LEVEL_INFO, - "Info: This node is not configured as an AMF node, disabling."); - return -1; - } - - this_amf_node->nodeid = totempg_my_nodeid_get(); - - return 0; -} - -/** - * Calculate a sync master (has the lowest node ID) from the - * members in the cluster. Possibly excluding some members - * from the CLM node list. - * - * @param member_list - * @param member_list_entries - * @param exclude_list - * @param exclude_list_entries - * - * @return int - node ID of new sync master - */ -static unsigned int calc_sync_master ( - unsigned int *member_list, int member_list_entries) -{ - int i; - unsigned int master = totempg_my_nodeid_get(); /* assume this node is master */ - - for (i = 0; i < member_list_entries; i++) { - if (member_list[i] < master && - !clm_node_list_is_member(member_list[i])) { - - master = member_list[i]; - } - } - - return master; -} - -/* - * Delete all received sync data - */ -static void free_synced_data (void) -{ - struct amf_node *node; - struct amf_application *app; - - SYNCTRACE ("state %s", scsm_state_names[scsm.state]); - - if (scsm.cluster) { - for (node = scsm.cluster->node_head; node != NULL;) { - struct amf_node *tmp = node; - node = node->next; - free (tmp); - } - for (app = scsm.cluster->application_head; app != NULL;) { - struct amf_application *tmp = app; - app = app->next; - amf_application_delete (tmp); - } - - free (scsm.cluster); - scsm.cluster = NULL; - } -} - -static int healthcheck_sync (struct amf_healthcheck *healthcheck) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", healthcheck->safHealthcheckKey.key); - - buf = amf_healthcheck_serialize (healthcheck, &len); - res = mcast_sync_data (buf, len, AMF_HEALTHCHECK); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - - return 0; -} - -static int comp_sync (struct amf_comp *comp) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", comp->name.value); - - if (!scsm.comp_sync_completed) { - buf = amf_comp_serialize (comp, &len); - res = mcast_sync_data (buf, len, AMF_COMP); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - scsm.comp_sync_completed = 1; - } - - if (scsm.healthcheck == NULL) { - scsm.healthcheck = scsm.comp->healthcheck_head; - } - for (; scsm.healthcheck != NULL; scsm.healthcheck = scsm.healthcheck->next) { - if (healthcheck_sync (scsm.healthcheck) != 0) { - return 1; /* try again later */ - } - } - - scsm.comp_sync_completed = 0; - - return 0; -} - -static int su_sync (struct amf_su *su) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", su->name.value); - - if (!scsm.su_sync_completed) { - buf = amf_su_serialize (su, &len); - res = mcast_sync_data (buf, len, AMF_SU); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - scsm.su_sync_completed = 1; - } - - if (scsm.comp == NULL) { - scsm.comp = scsm.su->comp_head; - } - for (; scsm.comp != NULL; scsm.comp = scsm.comp->next) { - if (comp_sync (scsm.comp) != 0) { - return 1; /* try again later */ - } - } - scsm.su_sync_completed = 0; - - return 0; -} - -static int sg_sync (struct amf_sg *sg) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", sg->name.value); - - if (!scsm.sg_sync_completed) { - buf = amf_sg_serialize (sg, &len); - res = mcast_sync_data (buf, len, AMF_SG); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - scsm.sg_sync_completed = 1; - } - - if (scsm.su == NULL) { - scsm.su = scsm.sg->su_head; - } - for (; scsm.su != NULL; scsm.su = scsm.su->next) { - if (su_sync (scsm.su) != 0) { - return 1; /* try again later */ - } - } - scsm.sg_sync_completed = 0; - - return 0; -} - -static int csi_assignment_sync (struct amf_csi_assignment *csi_assignment) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", csi_assignment->name.value); - - buf = amf_csi_assignment_serialize (csi_assignment, &len); - res = mcast_sync_data (buf, len, AMF_CSI_ASSIGNMENT); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - - return 0; -} - -static int csi_attribute_sync (struct amf_csi_attribute *csi_attribute) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", csi_attribute->name); - - buf = amf_csi_attribute_serialize (csi_attribute, &len); - res = mcast_sync_data (buf, len, AMF_CSI_ATTRIBUTE); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - - return 0; -} - -static int csi_sync (struct amf_csi *csi) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", csi->name.value); - - if (!scsm.csi_sync_completed) { - buf = amf_csi_serialize (csi, &len); - res = mcast_sync_data (buf, len, AMF_CSI); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - scsm.csi_sync_completed = 1; - } - - if (scsm.csi_assignment == NULL && scsm.csi_attribute == NULL) { - scsm.csi_assignment = scsm.csi->assigned_csis; - } - for (; scsm.csi_assignment != NULL; - scsm.csi_assignment = scsm.csi_assignment->next) { - if (csi_assignment_sync (scsm.csi_assignment) != 0) { - return 1; /* try again later */ - } - } - if (scsm.csi_attribute == NULL) { - scsm.csi_attribute = scsm.csi->attributes_head; - } - for (; scsm.csi_attribute != NULL; scsm.csi_attribute = scsm.csi_attribute->next) { - if (csi_attribute_sync (scsm.csi_attribute) != 0) { - return 1; /* try again later */ - } - } - - scsm.csi_sync_completed = 0; - - return 0; -} - -static int si_assignment_sync (struct amf_si_assignment *si_assignment) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", si_assignment->name.value); - - buf = amf_si_assignment_serialize (si_assignment, &len); - res = mcast_sync_data (buf, len, AMF_SI_ASSIGNMENT); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - - return 0; -} - -static int si_sync (struct amf_si *si) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", si->name.value); - - if (!scsm.si_sync_completed) { - buf = amf_si_serialize (si, &len); - res = mcast_sync_data (buf, len, AMF_SI); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - scsm.si_sync_completed = 1; - } - - if (scsm.si_assignment == NULL && scsm.csi == NULL) { - scsm.si_assignment = scsm.si->assigned_sis; - } - for (; scsm.si_assignment != NULL; scsm.si_assignment = scsm.si_assignment->next) { - if (si_assignment_sync (scsm.si_assignment) != 0) { - return 1; /* try again later */ - } - } - - if (scsm.csi == NULL) { - scsm.csi = scsm.si->csi_head; - } - for (; scsm.csi != NULL; scsm.csi = scsm.csi->next) { - if (csi_sync (scsm.csi) != 0) { - return 1; /* try again later */ - } - } - scsm.si_sync_completed = 0; - - return 0; -} - -static int application_sync (struct amf_application *app) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", app->name.value); - - if (!scsm.app_sync_completed) { - buf = amf_application_serialize (app, &len); - res = mcast_sync_data (buf, len, AMF_APPLICATION); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - scsm.app_sync_completed = 1; - } - - if (scsm.sg == NULL && scsm.si == NULL) { - scsm.sg = scsm.app->sg_head; - } - - for (; scsm.sg != NULL; scsm.sg = scsm.sg->next) { - if (sg_sync (scsm.sg) != 0) { - return 1; /* try again later */ - } - } - - if (scsm.si == NULL) { - scsm.si = scsm.app->si_head; - } - for (; scsm.si != NULL; scsm.si = scsm.si->next) { - if (si_sync (scsm.si) != 0) { - return 1; /* try again later */ - } - } - scsm.app_sync_completed = 0; - - return 0; -} - -static int node_sync (struct amf_node *node) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", node->name.value); - buf = amf_node_serialize (node, &len); - res = mcast_sync_data (buf, len, AMF_NODE); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - - return 0; -} - -static int cluster_sync (struct amf_cluster *cluster) -{ - char *buf; - int len, res; - - SYNCTRACE ("%s", cluster->name.value); - buf = amf_cluster_serialize (cluster, &len); - res = mcast_sync_data (buf, len, AMF_CLUSTER); - free (buf); - if (res != 0) { - return 1; /* try again later */ - } - - return 0; -} - -/** - * Start the AMF nodes that has joined - */ -static void cluster_joined_nodes_start (void) -{ - int i; - struct amf_node *node; - - ENTER (""); - log_printf(LOG_NOTICE, "AMF synchronisation ready, starting cluster"); - - for (i = 0; i < clm_node_list_entries; i++) { - node = amf_node_find_by_nodeid (clm_node_list[i].nodeid); - - if (node != NULL) { - amf_cluster_sync_ready (amf_cluster, node); - } else { - log_printf (LOG_LEVEL_INFO, - "Info: Node %u is not configured as an AMF node", - clm_node_list[i].nodeid); - } - } -} - -/****************************************************************************** - * AMF Framework callback implementation * - *****************************************************************************/ - -static void amf_sync_init (void) -{ - SYNCTRACE ("state %s", scsm_state_names[scsm.state]); - - switch (scsm.state) { - case UNCONFIGURED: - case PROBING_1: - case PROBING_2: - break; - case UPDATING_CLUSTER_MODEL: - case SYNCHRONIZING: - nodeids_init (); - break; - case NORMAL_OPERATION: - if (clm_node_list_entries > 0) { - sync_state_set (SYNCHRONIZING); - } - break; - default: - dprintf ("unknown state: %u", scsm.state);; - assert (0); - break; - } - - if (scsm.state == SYNCHRONIZING && scsm.sync_master == totempg_my_nodeid_get()) { - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0); - assert (amf_cluster != NULL); - scsm.cluster = amf_cluster; - scsm.node = amf_cluster->node_head; - scsm.app = amf_cluster->application_head; - scsm.app_sync_completed = 0; - scsm.sg = NULL; - scsm.sg_sync_completed = 0; - scsm.su = NULL; - scsm.su_sync_completed = 0; - scsm.comp = NULL; - scsm.comp_sync_completed = 0; - scsm.healthcheck = NULL; - scsm.si = NULL; - scsm.si_sync_completed = 0; - scsm.si_assignment = NULL; - scsm.csi = NULL; - scsm.csi_sync_completed = 0; - scsm.csi_assignment = NULL; - scsm.csi_attribute = NULL; - } -} - -/** - * SCSM state SYNCHRONIZING processing function. If in correct - * state, encode and send each object in the information model - * as a SYNC_DATA message. Depth first traversal to preserve - * parent/child relations. - * - * @return int - */ -static int amf_sync_process (void) -{ - SYNCTRACE ("state %s", scsm_state_names[scsm.state]); - - if (scsm.state != SYNCHRONIZING || scsm.sync_master != totempg_my_nodeid_get()) { - return 0; - } - - if (scsm.cluster) { - if (cluster_sync (scsm.cluster) != 0) { - return 1; /* try again later */ - } - scsm.cluster = NULL; /* done with cluster object */ - } - - for (; scsm.node != NULL; scsm.node = scsm.node->next) { - if (node_sync (scsm.node) != 0) { - return 1; /* try again later */ - } - } - -#ifdef AMFTEST - { - /* - * Test code to generate the event "sync master died" in the - * middle of synchronization. - */ - struct stat buf; - if (stat ("/tmp/amf_sync_master_crash", &buf) == 0) { - printf("bye...\n"); - *((int*)NULL) = 0xbad; - } - /* - * Test code to delay the synchronization. - */ - if (stat ("/tmp/amf_sync_delay", &buf) == 0) { - printf("delaying sync...\n"); - return 1; - } - } -#endif - - for (; scsm.app != NULL; scsm.app = scsm.app->next) { - if (application_sync (scsm.app) != 0) { - return 1; /* try again later */ - } - } - - SYNCTRACE ("ready"); - - return 0; /* ready */ -} - -/** - * Sync is aborted due to node leave/join. Free received sync - * data and stay in the same state. - */ -static void amf_sync_abort (void) -{ - SYNCTRACE ("state %s", scsm_state_names[scsm.state]); - free_synced_data (); -} - -/** - * SCSM normal exit function for states SYNCHRONIZING & - * UPDATING_CLUSTER_MODEL. All synced objects are now - * commited, start node/cluster. - */ -static void amf_sync_activate (void) -{ - SYNCTRACE ("state %s", scsm_state_names[scsm.state]); - - switch (scsm.state) { - case SYNCHRONIZING: - sync_state_set (NORMAL_OPERATION); - cluster_joined_nodes_start (); - clm_node_list_delete (); - break; - case UPDATING_CLUSTER_MODEL: - amf_cluster = scsm.cluster; - assert (amf_cluster != NULL); - scsm.cluster = NULL; - this_amf_node = get_this_node_obj (); - sync_state_set (NORMAL_OPERATION); - if (this_amf_node != NULL) { - this_amf_node->nodeid = totempg_my_nodeid_get(); - cluster_joined_nodes_start (); - } else { - log_printf (LOG_LEVEL_INFO, - "Info: This node is not configured as an AMF node, disabling."); - sync_state_set (UNCONFIGURED); - } - clm_node_list_delete (); - break; - case UNCONFIGURED: - case PROBING_1: - case PROBING_2: - case NORMAL_OPERATION: - break; - default: - dprintf ("unknown state: %u", scsm.state);; - assert (0); - break; - } - - SYNCTRACE (""); -} - -/** - * First AMF function to be called by the framework. AMF - * execution continues when this node joins the cluster. - * @param objdb - * - * @return int - */ -static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb) -{ - if (gethostname (hostname, sizeof (hostname)) == -1) { - log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - - if (objdb != NULL && !amf_enabled (objdb)) { - sync_state_set (UNCONFIGURED); - return 0; - } - - sync_state_set (IDLE); - - return (0); -} - -/** - * Cluster configuration change event handler - * @param configuration_type - * @param member_list - * @param member_list_entries - * @param left_list - * @param left_list_entries - * @param joined_list - * @param joined_list_entries - * @param ring_id - */ -static void amf_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id) -{ - ENTER ("mnum: %d, jnum: %d, lnum: %d, sync state: %s, ring ID %llu rep %s\n", - member_list_entries, joined_list_entries, left_list_entries, - scsm_state_names[scsm.state], ring_id->seq, totemip_print (&ring_id->rep)); - - switch (scsm.state) { - case UNCONFIGURED: - break; - case IDLE: { - sync_state_set (PROBING_1); - if (poll_timer_add (aisexec_poll_handle, AMF_SYNC_TIMEOUT, NULL, - timer_function_scsm_timer1_tmo, &scsm.timer_handle) != 0) { - - openais_exit_error (AIS_DONE_FATAL_ERR); - } - break; - } - case PROBING_1: - /* fall-through */ - case PROBING_2: - if (joined_list_entries > 0) { - mcast_sync_request (hostname); - } - break; - case UPDATING_CLUSTER_MODEL: - if (joined_list_entries > 0) { - mcast_sync_request (hostname); - } - - if (!is_list_member (scsm.sync_master, member_list, member_list_entries)) { - free_synced_data (); - sync_state_set (PROBING_1); - if (poll_timer_add (aisexec_poll_handle, AMF_SYNC_TIMEOUT, NULL, - timer_function_scsm_timer1_tmo, &scsm.timer_handle) != 0) { - - openais_exit_error (AIS_DONE_FATAL_ERR); - } - } - break; - case SYNCHRONIZING: { - if (joined_list_entries > 0 && scsm.sync_master == totempg_my_nodeid_get()) { - /* restart sync */ - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0); - } - /* If the sync master left the cluster, calculate a new sync - * master between the remaining nodes in the cluster excluding - * the nodes we are just syncing. - */ - if (!is_list_member (scsm.sync_master, member_list, member_list_entries)) { - scsm.sync_master = - calc_sync_master (member_list, member_list_entries); - - if (scsm.sync_master == totempg_my_nodeid_get()) { - /* restart sync */ - SYNCTRACE ("I am (new) sync master"); - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0); - } - } - break; - } - case NORMAL_OPERATION: { - /* If the sync master left the cluster, calculate a new sync - * master between the remaining nodes in the cluster. - */ - if (!is_list_member (scsm.sync_master, member_list, member_list_entries)) { - scsm.sync_master = - calc_sync_master (member_list, member_list_entries); - - if (scsm.sync_master == totempg_my_nodeid_get()) { - SYNCTRACE ("I am (new) sync master"); - } - } - - if (left_list_entries > 0) { - int i; - struct amf_node *node; - - for (i = 0; i < left_list_entries; i++) { - node = amf_node_find_by_nodeid (left_list[i]); - if (node != NULL) { - amf_node_leave(node); - } - } - } - break; - } - default: - log_printf (LOG_LEVEL_ERROR, "unknown state: %u\n", scsm.state); - assert (0); - break; - } -} - - -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); - - assert (amf_pd != NULL); - comp = amf_pd->comp; - - /* Make sure this is not a new connection */ - if (comp != NULL && comp->conn == conn ) { - comp->conn = NULL; - dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name)); - } - - return (0); -} - -static int amf_lib_init_fn (void *conn) -{ - struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn); - - list_init (&amf_pd->list); - - return (0); -} - -static void amf_dump_fn (void) -{ - if (amf_cluster == NULL) { - return; - } - amf_runtime_attributes_print (amf_cluster); -} - - - -/****************************************************************************** - * Executive Message Implementation - *****************************************************************************/ - -static void message_handler_req_exec_amf_comp_register ( - void *message, unsigned int nodeid) -{ - struct res_lib_amf_componentregister res_lib; - struct req_exec_amf_comp_register *req_exec = message; - struct amf_comp *comp; - SaAisErrorT error; - - if (scsm.state != NORMAL_OPERATION) { - return; - } - - comp = amf_comp_find (amf_cluster, &req_exec->compName); - assert (comp != NULL); - TRACE1 ("ComponentRegister: '%s'", comp->name.value); - error = amf_comp_register (comp); - - if (amf_su_is_local (comp->su)) { - res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER; - res_lib.header.size = sizeof (struct res_lib_amf_componentregister); - res_lib.header.error = error; - openais_conn_send_response ( - comp->conn, &res_lib, sizeof (struct res_lib_amf_componentregister)); - } -} - -static void message_handler_req_exec_amf_comp_error_report ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_comp_error_report *req_exec = message; - struct amf_comp *comp; - amf_comp_t *reporting_comp; - - if (scsm.state != NORMAL_OPERATION) { - return; - } - - comp = amf_comp_find (amf_cluster, &req_exec->erroneousComponent); - reporting_comp = amf_comp_find (amf_cluster, &req_exec->reportingComponent); - assert (comp != NULL); - amf_comp_error_report (comp, reporting_comp,req_exec->recommendedRecovery); -} - -static void message_handler_req_exec_amf_comp_instantiate( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_comp_instantiate *req_exec = message; - struct amf_comp *component; - - component = amf_comp_find (amf_cluster, &req_exec->compName); - if (component == NULL) { - log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value); - return; - - } - - amf_comp_instantiate_event (component); -} - -static void message_handler_req_exec_amf_comp_instantiate_tmo( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_comp_instantiate_tmo *req_exec = message; - struct amf_comp *component; - - component = amf_comp_find (amf_cluster, &req_exec->compName); - if (component == NULL) { - log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value); - return; - - } - amf_comp_instantiate_tmo_event (component); -} - -static void message_handler_req_exec_amf_comp_cleanup_tmo( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_comp_cleanup_tmo *req_exec = message; - struct amf_comp *component; - - component = amf_comp_find (amf_cluster, &req_exec->compName); - if (component == NULL) { - log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value); - return; - - } - amf_comp_cleanup_tmo_event (component); -} - -static void message_handler_req_exec_amf_clc_cleanup_completed ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_clc_cleanup_completed *req_exec = message; - amf_comp_t *comp; - if (scsm.state != NORMAL_OPERATION) { - return; - } - - comp = amf_comp_find (amf_cluster, &req_exec->compName); - ENTER ("%s",comp->name.value); - - if (comp == NULL) { - log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value); - return; - } - - if (req_exec->cleanup_exit_code != 0) { - amf_comp_cleanup_failed_completed (comp); - } else { - amf_comp_cleanup_completed (comp); - - } -} - -static void message_handler_req_exec_amf_healthcheck_tmo ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_healthcheck_tmo *req_exec = message; - struct amf_comp *comp; - struct amf_healthcheck *healthcheck; - - if (scsm.state != NORMAL_OPERATION) { - return; - } - - comp = amf_comp_find (amf_cluster, &req_exec->compName); - if (comp == NULL) { - log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value); - return; - } - - ENTER ("%s", comp->name.value); - - healthcheck = amf_comp_find_healthcheck (comp, &req_exec->safHealthcheckKey); - - amf_comp_healthcheck_tmo (comp, req_exec->recommendedRecovery); -} - -static void message_handler_req_exec_amf_response ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_response *req_exec = message; - struct amf_comp *comp; - struct res_lib_amf_response res_lib; - SaAisErrorT retval; - - if (scsm.state != NORMAL_OPERATION) { - return; - } - - TRACE1 ("AmfResponse: %s", req_exec->dn.value); - - comp = amf_comp_response_2 ( - req_exec->interface, &req_exec->dn, &req_exec->healtcheck_key, - req_exec->error, &retval, req_exec->recommendedRecovery); - assert (comp != NULL); - - if (amf_su_is_local (comp->su)) { - res_lib.header.id = MESSAGE_RES_AMF_RESPONSE; - res_lib.header.size = sizeof (struct res_lib_amf_response); - res_lib.header.error = retval; - openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib)); - } -} - -static void message_handler_req_exec_amf_sync_start ( - void *message, unsigned int nodeid) -{ - SYNCTRACE ("from: %s", totempg_ifaces_print (nodeid)); - - switch (scsm.state) { - case IDLE: - break; - case PROBING_1: - poll_timer_delete (aisexec_poll_handle, scsm.timer_handle); - scsm.timer_handle = 0; - sync_state_set (UPDATING_CLUSTER_MODEL); - scsm.sync_master = nodeid; - break; - case PROBING_2: - if (totempg_my_nodeid_get() == nodeid) { - scsm.sync_master = nodeid; - sync_state_set (CREATING_CLUSTER_MODEL); - if (create_cluster_model() == 0) { - sync_state_set (SYNCHRONIZING); - sync_request (amf_service_handler.name); - } else { - /* TODO: I am sync master but not AMF node */ - log_printf (LOG_LEVEL_ERROR, - "AMF sync error: I am sync master but not AMF node"); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - } else { - sync_state_set (UPDATING_CLUSTER_MODEL); - scsm.sync_master = nodeid; - } - break; - case SYNCHRONIZING: - break; - case UPDATING_CLUSTER_MODEL: - free_synced_data (); - scsm.sync_master = nodeid; - break; - case UNCONFIGURED: - break; - default: - dprintf ("unknown state %d", scsm.state); - assert (0); - break; - } -} - -static void message_handler_req_exec_amf_sync_data ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_sync_data *req_exec = message; - char *tmp = ((char*)message) + sizeof (struct req_exec_amf_sync_data); - - SYNCTRACE ("rec %d bytes, ptr %p, type %d", req_exec->header.size, message, - req_exec->object_type); - -#if 0 - if (req_exec->protocol_version != AMF_PROTOCOL_VERSION) { - log_printf (LOG_ERR, "Error: Protocol version not supported"); - return; - } -#endif - - if (scsm.state != UPDATING_CLUSTER_MODEL) { - return; - } - - switch (req_exec->object_type) - { - case AMF_CLUSTER: - if ((scsm.cluster = amf_cluster_deserialize (tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("Cluster '%s' deserialised", scsm.cluster->name.value); - break; - case AMF_NODE: - if ((scsm.node = amf_node_deserialize (scsm.cluster, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("Node '%s' deserialised", scsm.node->name.value); - break; - case AMF_APPLICATION: - if ((scsm.app = amf_application_deserialize (scsm.cluster, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("App '%s' deserialised", scsm.app->name.value); - break; - case AMF_SG: - if ((scsm.sg = amf_sg_deserialize (scsm.app, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("SG '%s' deserialised", scsm.sg->name.value); - break; - case AMF_SU: - if ((scsm.su = amf_su_deserialize (scsm.sg, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("SU '%s' deserialised", scsm.su->name.value); - break; - case AMF_COMP: - if ((scsm.comp = amf_comp_deserialize (scsm.su, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("Component '%s' deserialised", scsm.comp->name.value); - break; - case AMF_HEALTHCHECK: - if ((scsm.healthcheck = amf_healthcheck_deserialize (scsm.comp, - tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("Healthcheck '%s' deserialised", - scsm.healthcheck->safHealthcheckKey.key); - break; - case AMF_SI: - if ((scsm.si = amf_si_deserialize (scsm.app, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("SI '%s' deserialised", scsm.si->name.value); - break; - case AMF_SI_ASSIGNMENT: - if ((scsm.si_assignment = amf_si_assignment_deserialize (scsm.si, - tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("SI Ass '%s' deserialised", - scsm.si_assignment->name.value); - break; - case AMF_CSI: - if ((scsm.csi = amf_csi_deserialize (scsm.si, - tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("CSI '%s' deserialised", scsm.csi->name.value); - break; - case AMF_CSI_ASSIGNMENT: - if ((scsm.csi_assignment = amf_csi_assignment_deserialize ( - scsm.csi, tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("CSI Ass '%s' deserialised", - scsm.csi_assignment->name.value); - break; - case AMF_CSI_ATTRIBUTE: - if ((scsm.csi_attribute = amf_csi_attribute_deserialize (scsm.csi, - tmp)) == NULL) { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - SYNCTRACE ("CSI Attr '%s' deserialised", - scsm.csi_attribute->name); - break; - default: - dprintf ("unknown object: %u", req_exec->object_type); - assert (0); - break; - } -} - -static void message_handler_req_exec_amf_cluster_start_tmo ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_cluster_start_tmo *req; - req = (struct req_exec_amf_cluster_start_tmo *)message; - - if (scsm.state != NORMAL_OPERATION) { - return; - } - TRACE1("%s", req->sourceNodeName.value); - amf_cluster_start_tmo_event (nodeid == scsm.sync_master, amf_cluster, - &req->sourceNodeName); -} - -static void message_handler_req_exec_amf_sync_request ( - void *message, unsigned int nodeid) -{ - struct req_exec_amf_sync_request *req_exec = message; - - SYNCTRACE ("from: %s, name: %s, state %s", totempg_ifaces_print (nodeid), - req_exec->hostname, scsm_state_names[scsm.state]); - - clm_node_list_update (nodeid, req_exec->hostname); - - if (scsm.state == NORMAL_OPERATION) { - amf_node_t *amf_node = amf_cluster->node_head; - /* - * Iterate all AMF nodes if several AMF nodes are mapped to this - * particular CLM node. - */ - for (; amf_node != NULL; amf_node = amf_node->next) { - if (strcmp ((char*)amf_node->saAmfNodeClmNode.value, - req_exec->hostname) == 0) { - - amf_node->nodeid = nodeid; - } - } - } -} - -/***************************************************************************** - * Library Interface Implementation - ****************************************************************************/ - -static void message_handler_req_lib_amf_componentregister ( - void *conn, - void *msg) -{ - struct req_lib_amf_componentregister *req_lib = msg; - struct amf_comp *comp; - - assert (scsm.state == NORMAL_OPERATION); - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - if (comp) { - struct req_exec_amf_comp_register req_exec; - struct iovec iovec; - struct amf_pd *amf_pd = openais_conn_private_data_get (conn); - - TRACE2("Comp register '%s'", req_lib->compName.value); - comp->conn = conn; - amf_pd->comp = comp; - req_exec.header.size = sizeof (struct req_exec_amf_comp_register); - req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE, - MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER); - memcpy (&req_exec.compName, &req_lib->compName, sizeof (SaNameT)); - memcpy (&req_exec.proxyCompName, - &req_lib->proxyCompName, sizeof (SaNameT)); - iovec.iov_base = (char *)&req_exec; - iovec.iov_len = sizeof (req_exec); - assert (totempg_groups_mcast_joined (openais_group_handle, - &iovec, 1, TOTEMPG_AGREED) == 0); - } else { - struct res_lib_amf_componentregister res_lib; - log_printf (LOG_ERR, "Error: Comp register: '%s' not found", req_lib->compName.value); - res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER; - res_lib.header.size = sizeof (struct res_lib_amf_componentregister); - res_lib.header.error = SA_AIS_ERR_INVALID_PARAM; - openais_conn_send_response ( - conn, &res_lib, sizeof (struct res_lib_amf_componentregister)); - } -} - -static void message_handler_req_lib_amf_componentunregister ( - void *conn, - void *msg) -{ -#ifdef COMPILE_OUT - 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 amf_comp *component; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n"); - - 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); - - 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 = amf_comp_find (amf_cluster, &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); -#endif -} - -static void message_handler_req_lib_amf_pmstart ( - void *conn, - void *msg) -{ - struct req_lib_amf_pmstart *req_lib = msg; - struct res_lib_amf_pmstart res_lib; - struct amf_comp *comp; - SaAisErrorT error = SA_AIS_OK; - - TRACE2("PmStart msg: '%s', %llu %d %d %d", - req_lib->compName.value, - req_lib->processId, - req_lib->descendentsTreeDepth, - req_lib->pmErrors, - req_lib->recommendedRecovery); - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - - if (comp != NULL) { - comp->conn = conn; - - error = amf_comp_pm_start (comp, req_lib->processId, - req_lib->descendentsTreeDepth, - req_lib->pmErrors, - req_lib->recommendedRecovery); - } else { - log_printf (LOG_ERR, "PmStart: Component '%s' not found", - req_lib->compName.value); - error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib.header.id = MESSAGE_RES_AMF_PMSTART; - res_lib.header.size = sizeof (res_lib); - res_lib.header.error = error; - openais_conn_send_response (conn, &res_lib, - sizeof (struct res_lib_amf_pmstart)); - -} - -static void message_handler_req_lib_amf_pmstop ( - void *conn, - void *msg) -{ - struct req_lib_amf_pmstop *req_lib = msg; - struct res_lib_amf_pmstop res_lib; - struct amf_comp *comp; - SaAisErrorT error = SA_AIS_OK; - - TRACE2 ("PmStop msg: '%s', %llu %d %d", - req_lib->compName.value, - req_lib->processId, - req_lib->stopQualifier, - req_lib->pmErrors); - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - - if (comp != NULL) { - comp->conn = conn; - - error = amf_comp_pm_stop (comp, - req_lib->stopQualifier, - req_lib->processId, - req_lib->pmErrors); - } else { - log_printf (LOG_ERR, "PmStop: Component '%s' not found", - req_lib->compName.value); - error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib.header.id = MESSAGE_RES_AMF_PMSTOP; - res_lib.header.size = sizeof (res_lib); - res_lib.header.error = error; - openais_conn_send_response (conn, &res_lib, - sizeof (struct res_lib_amf_pmstop)); - -} - -static void message_handler_req_lib_amf_healthcheckstart ( - void *conn, void *msg) -{ - struct req_lib_amf_healthcheckstart *req_lib = msg; - struct res_lib_amf_healthcheckstart res_lib; - struct amf_comp *comp; - SaAisErrorT error = SA_AIS_OK; - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - - if (comp != NULL) { - comp->conn = conn; - error = amf_comp_healthcheck_start ( - comp, &req_lib->healthcheckKey, req_lib->invocationType, - req_lib->recommendedRecovery); - } else { - log_printf (LOG_ERR, "Healthcheckstart: Component '%s' not found", - req_lib->compName.value); - error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART; - res_lib.header.size = sizeof (res_lib); - res_lib.header.error = error; - openais_conn_send_response (conn, &res_lib, - sizeof (struct res_lib_amf_healthcheckstart)); -} - -static void message_handler_req_lib_amf_healthcheckconfirm ( - void *conn, void *msg) -{ - struct req_lib_amf_healthcheckconfirm *req_lib = msg; - struct res_lib_amf_healthcheckconfirm res_lib; - struct amf_comp *comp; - SaAisErrorT error = SA_AIS_OK; - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - if (comp != NULL) { - error = amf_comp_healthcheck_confirm ( - comp, &req_lib->healthcheckKey, req_lib->healthcheckResult); - } else { - log_printf (LOG_ERR, "Healthcheck confirm: Component '%s' not found", - req_lib->compName.value); - error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM; - res_lib.header.size = sizeof (res_lib); - res_lib.header.error = error; - openais_conn_send_response (conn, &res_lib, sizeof (res_lib)); -} - -static void message_handler_req_lib_amf_healthcheckstop ( - void *conn, void *msg) -{ - struct req_lib_amf_healthcheckstop *req_lib = msg; - struct res_lib_amf_healthcheckstop res_lib; - struct amf_comp *comp; - SaAisErrorT error = SA_AIS_OK; - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - if (comp != NULL) { - error = amf_comp_healthcheck_stop (comp, &req_lib->healthcheckKey); - } else { - log_printf (LOG_ERR, "Healthcheckstop: Component '%s' not found", - req_lib->compName.value); - error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP; - res_lib.header.size = sizeof (res_lib); - res_lib.header.error = error; - openais_conn_send_response (conn, &res_lib, sizeof (res_lib)); -} - -static void message_handler_req_lib_amf_hastateget (void *conn, void *msg) -{ - struct req_lib_amf_hastateget *req_lib = msg; - struct res_lib_amf_hastateget res_lib; - struct amf_comp *comp; - SaAmfHAStateT ha_state; - SaAisErrorT error; - - comp = amf_comp_find (amf_cluster, &req_lib->compName); - if (comp != NULL) { - error = amf_comp_hastate_get (comp, &req_lib->csiName, &ha_state); - res_lib.haState = ha_state; - res_lib.header.error = error; - } else { - log_printf (LOG_ERR, "HA state get: Component '%s' not found", - req_lib->compName.value); - error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib.header.id = MESSAGE_RES_AMF_HASTATEGET; - res_lib.header.size = sizeof (struct res_lib_amf_hastateget); - res_lib.header.error = error; - - openais_conn_send_response (conn, &res_lib, - sizeof (struct res_lib_amf_hastateget)); -} - -static void message_handler_req_lib_amf_protectiongrouptrack ( - void *conn, - void *msg) -{ -#ifdef COMPILE_OUT - 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_protectiongrouptrack()\n"); - - amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName); - if (amfProtectionGroup) { - 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]; - 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_lib_amf_protectiongrouptrack->trackFlags; - track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress; - memcpy (&track->csiName, - &req_lib_amf_protectiongrouptrack->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_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_protectiongrouptrack.header.error = SA_AIS_OK; - } - openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack, - sizeof (struct res_lib_amf_protectiongrouptrack)); - - if (amfProtectionGroup && - req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) { - - protectiongroup_notification_send (conn_info, - track->notificationBufferAddress, - amfProtectionGroup, - 0, - 0, - SA_TRACK_CHANGES_ONLY); - - track->trackFlags &= ~SA_TRACK_CURRENT; - } -#endif -} - -static void message_handler_req_lib_amf_csiquiescingcomplete ( - void *conn, - void *msg) -{ -} - -static void message_handler_req_lib_amf_protectiongrouptrackstop ( - void *conn, - void *msg) -{ -#ifdef COMPILE_OUT - struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_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_lib_amf_protectiongrouptrackstop()\n"); - - for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) { - if (name_match (&req_lib_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_lib_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, &res_lib_amf_protectiongrouptrackstop, - sizeof (struct res_lib_amf_protectiongrouptrackstop)); - -#endif -} - -/** - * multicast a message out reporting a component error - * (to be called by passive monitoring) - */ -void mcast_error_report_from_pm ( - struct amf_comp *comp, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct req_exec_amf_comp_error_report req_exec; - struct iovec iovec; - SaNameT erroneous_comp_name; - - amf_comp_dn_make(comp, &erroneous_comp_name); - - TRACE2("%s %s",comp->name.value, erroneous_comp_name.value); - - req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report); - req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE, - MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT); - - memcpy (&req_exec.erroneousComponent, &erroneous_comp_name, sizeof (SaNameT)); - memcpy (&req_exec.recommendedRecovery, &recommendedRecovery, sizeof (SaAmfRecommendedRecoveryT)); - - iovec.iov_base = (char *)&req_exec; - iovec.iov_len = sizeof (req_exec); - - totempg_groups_mcast_joined (openais_group_handle, - &iovec, 1, TOTEMPG_AGREED); - -} - -static void message_handler_req_lib_amf_componenterrorreport ( - void *conn, - void *msg) -{ - struct req_lib_amf_componenterrorreport *req_lib = msg; - struct amf_comp *comp; - amf_comp_t *reporting_comp; - SaNameT reporting_comp_name; - - assert (scsm.state == NORMAL_OPERATION); - - comp = amf_comp_find (amf_cluster, &req_lib->erroneousComponent); - reporting_comp = amf_comp_find_from_conn_info (conn); - assert (reporting_comp); - - if (comp != NULL) { - struct req_exec_amf_comp_error_report req_exec; - struct iovec iovec; - - TRACE2("Lib comp error report for '%s'", comp->name.value); - - req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report); - req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE, - MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT); - amf_comp_dn_make(reporting_comp, &reporting_comp_name); - memcpy (&req_exec.reportingComponent, &reporting_comp_name, - sizeof (SaNameT)); - memcpy (&req_exec.erroneousComponent, &req_lib->erroneousComponent, - sizeof (SaNameT)); - memcpy (&req_exec.errorDetectionTime, &req_lib->errorDetectionTime, - sizeof (SaTimeT)); - memcpy (&req_exec.recommendedRecovery, &req_lib->recommendedRecovery, - sizeof (SaAmfRecommendedRecoveryT)); - memcpy (&req_exec.ntfIdentifier, &req_lib->ntfIdentifier, - sizeof (SaNtfIdentifierT)); - - iovec.iov_base = (char *)&req_exec; - iovec.iov_len = sizeof (req_exec); - - assert (totempg_groups_mcast_joined ( - openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0); - } else { - struct res_lib_amf_componenterrorreport res_lib; - - log_printf (LOG_ERR, "Component %s not found", - req_lib->erroneousComponent.value); - res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport); - res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT; - res_lib.header.error = SA_AIS_ERR_NOT_EXIST; - openais_conn_send_response (conn, &res_lib, - sizeof (struct res_lib_amf_componenterrorreport)); - } -} - -static void message_handler_req_lib_amf_componenterrorclear ( - void *conn, - void *msg) -{ -#ifdef COMPILLE_OUT - struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message; - struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear; - - struct iovec iovec; - - log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n"); - - req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear); - req_exec_amf_componenterrorclear.header.id = - SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR); - - message_source_set (&req_exec_amf_componenterrorclear.source, conn_info); - - memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear, - req_lib_amf_componenterrorclear, - sizeof (struct req_lib_amf_componenterrorclear)); - - iovec.iov_base = (char *)&req_exec_amf_componenterrorclear; - iovec.iov_len = sizeof (req_exec_amf_componenterrorclear); - - assert (totempg_groups_mcast_joined (openais_group_handle, - &iovec, 1, TOTEMPG_AGREED) == 0); -#endif - -} - -/** - * Handle a response from a component. - * - * Healthcheck responses are handled locally and directly. This - * way we do not get healthcheck duration timeouts during e.g. - * AMF sync. - * - * Other events need to be multicasted. If we are syncing, defer - * these event by returning TRY-AGAIN to the component. - * - * No flow control was requested by AMF from the IPC layer (on - * purpose) for this lib handler. It is needed to handle - * healthcheck responses if it takes longer to sync than the - * duration period. - * - * When multicasting, check for space in the TOTEM outbound - * queue and return TRY-AGAIN if the queue is full. - * - * @param conn - * @param msg - */ -static void message_handler_req_lib_amf_response (void *conn, void *msg) -{ - struct res_lib_amf_response res_lib; - struct req_lib_amf_response *req_lib = msg; - int multicast, send_ok; - SaAisErrorT retval; - SaUint32T interface; - SaNameT dn; - SaAmfHealthcheckKeyT healthcheck_key; - SaAmfRecommendedRecoveryT recommendedRecovery; - /* - * This is an optimisation to avoid multicast of healthchecks while keeping - * a nice design. We multicast and make lib responses from this file. - */ - multicast = amf_comp_response_1 (req_lib->invocation, req_lib->error, - &retval, &interface, &dn, &healthcheck_key, &recommendedRecovery); - - if (multicast) { - struct req_exec_amf_response req_exec; - struct iovec iovec; - - if (scsm.state != NORMAL_OPERATION) { - retval = SA_AIS_ERR_TRY_AGAIN; - goto send_response; - } - - req_exec.header.size = sizeof (struct req_exec_amf_response); - req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE, - MESSAGE_REQ_EXEC_AMF_RESPONSE); - req_exec.interface = interface; - memcpy (&req_exec.dn, &dn, sizeof (SaNameT)); - memcpy (&req_exec.healtcheck_key, &healthcheck_key, - sizeof(SaAmfHealthcheckKeyT)); - req_exec.recommendedRecovery = recommendedRecovery; - req_exec.error = req_lib->error; - iovec.iov_base = (char *)&req_exec; - iovec.iov_len = sizeof (req_exec); - send_ok = totempg_groups_send_ok_joined (openais_group_handle, &iovec, 1); - - if (send_ok) { - if (totempg_groups_mcast_joined ( - openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0) { - goto end; - } else { - openais_exit_error (AIS_DONE_FATAL_ERR); - } - } else { - /* TOTEM queue is full, try again later */ - retval = SA_AIS_ERR_TRY_AGAIN; - } - } - -send_response: - res_lib.header.id = MESSAGE_RES_AMF_RESPONSE; - res_lib.header.size = sizeof (struct res_lib_amf_response); - res_lib.header.error = retval; - openais_conn_send_response (conn, &res_lib, sizeof (res_lib)); -end: - return; -} - diff --git a/openais/services/amf.h b/openais/services/amf.h deleted file mode 100644 index e02a9bf5..00000000 --- a/openais/services/amf.h +++ /dev/null @@ -1,1205 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * Author: Steven Dake (sdake@redhat.com) - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt - * Description: - Reworked to match AMF B.02 information model - * - New state machine design - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef AMF_H_DEFINED -#define AMF_H_DEFINED - -#include -#include -#include - -#include "../include/saAis.h" -#include "../include/saAmf.h" -#include "../include/list.h" -#include "../include/ipc_gen.h" -#include "objdb.h" -#include "timer.h" -#include "aispoll.h" - -typedef void (*async_func_t)(void *param); - -#define AMF_PROTOCOL_VERSION 1 - -enum scsm_states { - IDLE = 1, - PROBING_1, - PROBING_2, - CREATING_CLUSTER_MODEL, - SYNCHRONIZING, - NORMAL_OPERATION, - UPDATING_CLUSTER_MODEL, - UNCONFIGURED -}; - -/** - * State descriptor for the AMF Synchronisation Control State - * Machine (SCSM). - */ -struct scsm_descriptor { - enum scsm_states state; - poll_timer_handle timer_handle; - - /* node ID of current sync master */ - unsigned int sync_master; - - struct amf_cluster *cluster; - struct amf_node *node; - struct amf_application *app; - int app_sync_completed; - struct amf_sg *sg; - int sg_sync_completed; - struct amf_su *su; - int su_sync_completed; - struct amf_comp *comp; - int comp_sync_completed; - struct amf_healthcheck *healthcheck; - struct amf_si *si; - int si_sync_completed; - struct amf_si_assignment *si_assignment; - struct amf_csi *csi; - int csi_sync_completed; - struct amf_csi_assignment *csi_assignment; - struct amf_csi_attribute *csi_attribute; -}; - -enum clc_component_types { - clc_component_sa_aware = 0, /* sa aware */ - clc_component_proxied_pre = 1, /* proxied, pre-instantiable */ - clc_component_proxied_non_pre = 2, /* proxied, non pre-instantiable */ - clc_component_non_proxied_non_sa_aware = 3 /* non-proxied, non sa aware */ -}; - -typedef enum { - USR_AMF_HA_STATE_REMOVED = SA_AMF_HA_QUIESCING + 1 -} UsrAmfHaState; - - -typedef enum { - APP_AC_UNINSTANTIATED = 1, - APP_AC_STARTING_SGS, - APP_AC_STARTED, - APP_AC_ASSIGNING_WORKLOAD, - APP_AC_WORKLOAD_ASSIGNED -} app_avail_control_state_t; - -typedef enum { - NODE_ACSM_REPAIR_NEEDED = 1, - NODE_ACSM_IDLE_ESCALLATION_LEVEL_0, - NODE_ACSM_IDLE_ESCALLATION_LEVEL_2, - NODE_ACSM_IDLE_ESCALLATION_LEVEL_3, - NODE_ACSM_FAILING_FAST_REBOOTING_NODE, - NODE_ACSM_FAILING_FAST_ACTIVATING_STANDBY_NODE, - NODE_ACSM_FAILING_GRACEFULLY_SWITCHING_OVER, - NODE_ACSM_FAILING_GRACEFULLY_FAILING_OVER, - NODE_ACSM_FAILING_GRACEFULLY_REBOOTING_NODE, - NODE_ACSM_LEAVING_SPONTANEOUSLY_FAILING_OVER, - NODE_ACSM_LEAVING_SPONTANEOUSLY_WAITING_FOR_NODE_TO_JOIN, - NODE_ACSM_JOINING_STARTING_APPLICATIONS, - NODE_ACSM_JOINING_ASSIGNING_WORKLOAD -} amf_node_acsm_state_t; - -typedef enum { - SG_AC_Idle = 0, - SG_AC_DeactivatingDependantWorkload, - SG_AC_TerminatingSuspected, - SG_AC_ActivatingStandby, - SG_AC_AssigningStandbyToSpare, - SG_AC_ReparingComponent, - SG_AC_ReparingSu, - SG_AC_AssigningOnRequest, - SG_AC_InstantiatingServiceUnits, - SG_AC_RemovingAssignment, - SG_AC_AssigningActiveworkload, - SG_AC_AssigningAutoAdjust, - SG_AC_AssigningWorkload, - SG_AC_WaitingAfterOperationFailed, - SG_AC_RemovingStandbyAssignments -} sg_avail_control_state_t; - -typedef enum amf_sg_event_type { - SG_UNKNOWN_EV, - SG_FAILOVER_SU_EV, - SG_FAILOVER_NODE_EV, - SG_FAILOVER_COMP_EV, - SG_SWITCH_OVER_NODE_EV, - SG_START_EV, - SG_AUTO_ADJUST_EV, - SG_ASSIGN_SI_EV -} amf_sg_event_type_t; - -typedef enum amf_su_event_type { - SU_COMP_ERROR_SUSPECTED_EV = 1 -} amf_su_event_type_t; - -typedef enum { - SU_RC_IDLE_ESCALATION_LEVEL_0 = 0, - SU_RC_IDLE_ESCALATION_LEVEL_1, - SU_RC_IDLE_ESCALATION_LEVEL_2, - SU_RC_RESTART_COMP_DEACTIVATING, - SU_RC_RESTART_COMP_RESTARTING, - SU_RC_RESTART_COMP_SETTING, - SU_RC_RESTART_COMP_ACTIVATING, - SU_RC_RESTART_SU_DEACTIVATING, - SU_RC_RESTART_SU_TERMINATING, - SU_RC_RESTART_SU_INSTANTIATING, - SU_RC_RESTART_SU_SETTING, - SU_RC_RESTART_SU_ACTIVATING, - SU_RC_TERMINATING_AFTER_INSTANTIATION_FAILED -} su_restart_control_state_t; - -typedef enum { - AMF_NONE, - AMF_APPLICATION, - AMF_CLUSTER, - AMF_NODE, - AMF_SG, - AMF_SU, - AMF_COMP, - AMF_COMP_ENV_VAR, - AMF_COMP_CS_TYPE, - AMF_SI, - AMF_SI_ASSIGNMENT, - AMF_SI_RANKED_SU, - AMF_SI_DEPENDENCY, - AMF_CSI, - AMF_CSI_ASSIGNMENT, - AMF_CSI_ATTRIBUTE, - AMF_HEALTHCHECK, - AMF_CSI_DEPENDENCIES, - AMF_CS_TYPE, -} amf_object_type_t; - -struct amf_si_assignment; -struct amf_csi_assignment; -struct amf_healthcheck; -struct amf_pm; - -typedef enum { - CLUSTER_AC_UNINSTANTIATED = 1, - CLUSTER_AC_STARTING_APPLICATIONS, - CLUSTER_AC_WAITING_OVER_TIME_1, - CLUSTER_AC_WAITING_OVER_TIME_2, - CLUSTER_AC_ASSIGNING_WORKLOAD, - CLUSTER_AC_STARTED, - CLUSTER_AC_TERMINATING_APPLICATIONS, - CLUSTER_AC_WORKLOAD_REMOVESD, - CLUSTER_AC_REMOVING_WORKLOAD, - CLUSTER_AC_DEACTIVATING_WORKLOAD, - CLUSTER_AC_QUISING -} cluster_avail_control_state_t; - -typedef enum amf_cluster_event_type { - CLUSTER_SYNC_READY_EV, - CLUSTER_EVENT_TYPE_CNT -} amf_cluster_event_type_t; - -typedef enum amf_application_event_type { - APPLICATION_ASSIGN_WORKLOAD_EV, - APPLICATION_START_EV, - APPLICATION_EVENT_TYPE_CNT -} amf_application_event_type_t; - -typedef struct amf_fifo { - int entry_type; - struct amf_fifo *next; - int size_of_data; - uint8_t data[]; -} amf_fifo_t; - - -typedef enum { - AMF_PRESENCE_TERMINATION_FAILED_REBOOT = - SA_AMF_PRESENCE_TERMINATION_FAILED + 1 -} AmfPresenceStateT; - -typedef struct amf_cluster { - /* Configuration Attributes */ - SaNameT name; - SaUint32T saAmfClusterStartupTimeout; - SaNameT saAmfClusterClmCluster; - - /* Runtime Attributes */ - SaAmfAdminStateT saAmfClusterAdminState; - - /* Relations */ - struct amf_node *node_head; - struct amf_application *application_head; - - /* Implementation */ - poll_timer_handle timeout_handle; - cluster_avail_control_state_t acsm_state; - amf_fifo_t *deferred_events; -} amf_cluster_t; - -typedef struct amf_node { - /* Configuration Attributes */ - SaNameT name; - SaNameT saAmfNodeClmNode; - SaUint32T saAmfNodeSuFailOverProb; - SaUint32T saAmfNodeSuFailoverMax; - SaBoolT saAmfNodeAutoRepair; - SaBoolT saAmfNodeRebootOnInstantiationFailure; - SaBoolT saAmfNodeRebootOnTerminationFailure; - - /* Runtime Attributes */ - SaAmfAdminStateT saAmfNodeAdminState; - SaAmfOperationalStateT saAmfNodeOperState; - - /* Relations */ - struct amf_cluster *cluster; - - /* Implementation */ - unsigned int nodeid; - struct amf_node *next; - amf_node_acsm_state_t acsm_state; - amf_node_acsm_state_t history_state; - -} amf_node_t; - -typedef struct amf_application { - /* Configuration Attributes */ - SaNameT name; - - /* Runtime Attributes */ - SaAmfAdminStateT saAmfApplicationAdminState; - SaUint32T saAmfApplicationCurrNumSG; - - /* Relations */ - struct amf_cluster *cluster; - struct amf_sg *sg_head; - /* ordered list of SUs */ - struct amf_si *si_head; - - /* Implementation */ - SaStringT clccli_path; - struct amf_application *next; - struct amf_node *node_to_start; - app_avail_control_state_t acsm_state; - amf_fifo_t *deferred_events; -} amf_application_t; - -struct sg_recovery_scope { - amf_sg_event_type_t event_type; - struct amf_si **sis; - struct amf_su **sus; - struct amf_comp *comp; - struct amf_node *node; -}; - -typedef struct amf_sg { - /* Configuration Attributes */ - SaNameT name; - saAmfRedundancyModelT saAmfSGRedundancyModel; - SaBoolT saAmfSGAutoAdjust; - SaUint32T saAmfSGNumPrefActiveSUs; - SaUint32T saAmfSGNumPrefStandbySUs; - SaUint32T saAmfSGNumPrefInserviceSUs; - SaUint32T saAmfSGNumPrefAssignedSUs; - SaUint32T saAmfSGMaxActiveSIsperSUs; - SaUint32T saAmfSGMaxStandbySIsperSUs; - SaUint32T saAmfSGCompRestartProb; - SaUint32T saAmfSGCompRestartMax; - SaUint32T saAmfSGSuRestartProb; - SaUint32T saAmfSGSuRestartMax; - SaUint32T saAmfSGAutoAdjustProb; - SaBoolT saAmfSGAutoRepair; - - /* Runtime Attributes */ - SaAmfAdminStateT saAmfSGAdminState; - SaUint32T saAmfSGNumCurrAssignedSUs; - SaUint32T saAmfSGNumCurrNonInstantiatedSpareSUs; - SaUint32T saAmfSGNumCurrInstantiatedSpareSUs; - - /* Relations */ - struct amf_application *application; - - /* ordered list of SUs */ - struct amf_su *su_head; - - /* Implementation */ - SaStringT clccli_path; - struct amf_sg *next; - sg_avail_control_state_t avail_state; - struct sg_recovery_scope recovery_scope; - struct amf_node *node_to_start; - amf_fifo_t *deferred_events; -} amf_sg_t; - -typedef 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; - - /* Implementation */ - su_restart_control_state_t restart_control_state; - su_restart_control_state_t escalation_level_history_state; - SaStringT clccli_path; - SaUint32T su_failover_cnt; /* missing in SAF specs? */ - SaUint32T current_comp_instantiation_level; - struct amf_su *next; - amf_fifo_t *deferred_events; -} amf_su_t; - -typedef struct amf_comp { - /* Configuration Attributes */ - SaNameT name; - SaNameT **saAmfCompCsTypes; - saAmfCompCategoryT saAmfCompCategory; - saAmfCompCapabilityModelT saAmfCompCapability; - SaUint32T saAmfCompNumMaxActiveCsi; - SaUint32T saAmfCompNumMaxStandbyCsi; - SaStringT *saAmfCompCmdEnv; - SaUint32T saAmfCompDefaultClcCliTimeout; - SaUint32T saAmfCompDefaultCallbackTimeOut; - SaStringT saAmfCompInstantiateCmd; - SaStringT saAmfCompInstantiateCmdArgv; - SaUint32T saAmfCompInstantiateTimeout; - SaUint32T saAmfCompInstantiationLevel; - SaUint32T saAmfCompNumMaxInstantiateWithoutDelay; - SaUint32T saAmfCompNumMaxInstantiateWithDelay; - SaUint32T saAmfCompDelayBetweenInstantiateAttempts; - SaStringT saAmfCompTerminateCmd; - SaUint32T saAmfCompTerminateTimeout; - SaStringT saAmfCompTerminateCmdArgv; - SaStringT saAmfCompCleanupCmd; - SaUint32T saAmfCompCleanupTimeout; - SaStringT saAmfCompCleanupCmdArgv; - SaStringT saAmfCompAmStartCmd; - SaUint32T saAmfCompAmStartTimeout; - SaStringT saAmfCompAmStartCmdArgv; - SaUint32T saAmfCompNumMaxAmStartAttempt; - SaStringT saAmfCompAmStopCmd; - SaUint32T saAmfCompAmStopTimeout; - SaStringT saAmfCompAmStopCmdArgv; - SaUint32T saAmfCompNumMaxAmStopAttempt; - SaUint32T saAmfCompTerminateCallbackTimeout; - SaUint32T saAmfCompCSISetCallbackTimeout; - SaUint32T saAmfCompQuiescingCompleteTimeout; - SaUint32T 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_su *su; - - /* Implementation */ - SaStringT clccli_path; - struct amf_comp *next; - void *conn; - enum clc_component_types comptype; - struct amf_healthcheck *healthcheck_head; - struct list_head pm_head; - poll_timer_handle instantiate_timeout_handle; - poll_timer_handle cleanup_timeout_handle; - /* - * Flag that indicates of this component has a suspected error - */ - SaUint32T error_suspected; -} amf_comp_t; - - -typedef struct amf_healthcheck { - /* Configuration Attributes */ - SaAmfHealthcheckKeyT safHealthcheckKey; - SaUint32T saAmfHealthcheckMaxDuration; - SaUint32T saAmfHealthcheckPeriod; - - /* Relations */ - struct amf_comp *comp; - - /* Implementation */ - struct amf_healthcheck *next; - SaUint32T active; - SaAmfHealthcheckInvocationT invocationType; - SaAmfRecommendedRecoveryT recommendedRecovery; - poll_timer_handle timer_handle_duration; - poll_timer_handle timer_handle_period; - -} amf_healthcheck_t; - - -typedef struct amf_pm { - /* Configuration Attributes */ - SaUint64T pid; - SaAmfPmErrorsT errors; - SaAmfRecommendedRecoveryT recovery; - - /* Implementation */ - struct list_head entry; - poll_timer_handle timer_handle_period; -} amf_pm_t; - - -typedef 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 saAmfSINumCurrStandbyAssignments; */ - - /* Relations */ - struct amf_application *application; - struct amf_csi *csi_head; - struct amf_si_assignment *assigned_sis; - struct amf_si_dependency *depends_on; - struct amf_si_ranked_su *ranked_sus; - - /* Implementation */ - struct amf_si *next; -} amf_si_t; - -typedef struct amf_si_ranked_su { - /* Configuration Attributes */ - SaNameT name; - SaUint32T saAmfRank; - - /* Relations */ - struct amf_si *si; - struct amf_su *su; - - /* Implementation */ - struct amf_si_ranked_su *su_next; - struct amf_si_ranked_su *si_next; -} amf_si_ranked_su_t; - -typedef struct amf_si_dependency { - /* Configuration Attributes */ - SaNameT name; - int saAmfToleranceTime; - - /* Relations */ - - /* Implementation */ - struct amf_si_dependency *next; -} amf_si_dependency_t; - -typedef struct amf_si_assignment { - /* Runtime Attributes */ - SaNameT name; - SaAmfHAStateT saAmfSISUHAState; - - /* Relations */ - struct amf_si *si; - struct amf_su *su; - - /* Implementation */ - SaAmfHAStateT requested_ha_state; - struct amf_si_assignment *next; - void (*assumed_callback_fn) ( - struct amf_si_assignment *si_assignment, int result); - void (*removed_callback_fn) (void *_si_assignment); -} amf_si_assignment_t; - -typedef struct amf_csi { - /* Configuration Attributes */ - SaNameT name; - SaNameT saAmfCSTypeName; - SaNameT **saAmfCSIDependencies; - - /* Relations */ - struct amf_si *si; - struct amf_csi_assignment *assigned_csis; - struct amf_csi_attribute *attributes_head; - - /* Implementation */ - struct amf_csi *next; -} amf_csi_t; - -typedef struct amf_csi_attribute { - /* Configuration Attributes */ - SaStringT name; - SaStringT *value; - - /* Implementation */ - struct amf_csi_attribute *next; -} amf_csi_attribute_t; - -typedef struct amf_csi_assignment { - /* Runtime Attributes */ - SaNameT name; - SaAmfHAStateT saAmfCSICompHAState; /* confirmed HA state */ - - /* Relations */ - struct amf_csi *csi; - struct amf_comp *comp; - - /* Implementation */ - SaAmfHAStateT requested_ha_state; - struct amf_csi_assignment *next; - struct amf_si_assignment *si_assignment; -} amf_csi_assignment_t; - -enum amf_response_interfaces { - AMF_RESPONSE_HEALTHCHECKCALLBACK = 1, - AMF_RESPONSE_CSISETCALLBACK = 2, - AMF_RESPONSE_CSIREMOVECALLBACK = 3, - AMF_RESPONSE_COMPONENTTERMINATECALLBACK = 4 -}; - -enum amf_message_req_types { - MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER = 0, - MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT = 1, - MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE = 2, - MESSAGE_REQ_EXEC_AMF_CLC_CLEANUP_COMPLETED = 3, - MESSAGE_REQ_EXEC_AMF_HEALTHCHECK_TMO = 4, - MESSAGE_REQ_EXEC_AMF_RESPONSE = 5, - MESSAGE_REQ_EXEC_AMF_SYNC_START = 6, - MESSAGE_REQ_EXEC_AMF_SYNC_DATA = 7, - MESSAGE_REQ_EXEC_AMF_CLUSTER_START_TMO = 8, - MESSAGE_REQ_EXEC_AMF_SYNC_REQUEST = 9, - MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE_TMO = 10, - MESSAGE_REQ_EXEC_AMF_COMPONENT_CLEANUP_TMO = 11 -}; - -struct req_exec_amf_clc_cleanup_completed { - mar_req_header_t header; - SaNameT compName; - int cleanup_exit_code; -}; - -struct req_exec_amf_healthcheck_tmo { - mar_req_header_t header; - SaNameT compName; - SaAmfHealthcheckKeyT safHealthcheckKey; - SaAmfRecommendedRecoveryT recommendedRecovery; -}; - -struct req_exec_amf_comp_instantiate { - mar_req_header_t header; - SaNameT compName; -}; - -struct req_exec_amf_comp_instantiate_tmo { - mar_req_header_t header; - SaNameT compName; -}; - -struct req_exec_amf_comp_cleanup_tmo { - mar_req_header_t header; - SaNameT compName; -}; - -struct req_exec_amf_cluster_start_tmo { - mar_req_header_t header; - SaNameT sourceNodeName; -}; - -/*===========================================================================*/ -/* amfutil.c */ - -extern struct amf_cluster *amf_config_read (char **error_string); -extern void amf_runtime_attributes_print (struct amf_cluster *cluster); -extern int amf_enabled (struct objdb_iface_ver0 *objdb); -extern void *_amf_malloc (size_t size, const char *file, unsigned int line); -#define amf_malloc(size) _amf_malloc ((size), __FILE__, __LINE__) -extern void *_amf_realloc (void* ptr, size_t size, const char *file, - unsigned int line); -#define amf_realloc(ptr,size) _amf_realloc ((ptr), (size), __FILE__, __LINE__) -extern void *_amf_calloc (size_t nmemb, size_t size, const char *file, - unsigned int line); -#define amf_calloc(nmemb,size) _amf_calloc ((nmemb), (size), __FILE__, __LINE__) -extern char *_amf_strdup (const char *str, const char *file, unsigned int line); -#define amf_strdup(str) _amf_strdup(str, __FILE__, __LINE__) - -extern const char *amf_admin_state (int state); -extern const char *amf_op_state (int state); -extern const char *amf_presence_state (int state); -extern const char *amf_ha_state (int state); -extern const char *amf_readiness_state (int state); -extern const char *amf_assignment_state (int state); -extern char *amf_serialize_SaNameT ( - char *buf, int *size, int *offset, SaNameT *name); -extern char *amf_serialize_SaStringT ( - char *buf, int *size, int *offset, SaStringT str); -extern char *amf_serialize_SaUint16T ( - char *buf, int *size, int *offset, SaUint16T num); -extern char *amf_serialize_SaUint32T ( - char *buf, int *size, int *offset, SaUint32T num); -extern char *amf_serialize_SaUint64T (char *buf, SaUint64T num); -extern char *amf_serialize_opaque ( - char *buf, int *size, int *offset, void *cp, int cnt); -extern char *amf_deserialize_SaNameT (char *buf, SaNameT *name); -extern char *amf_deserialize_SaStringT (char *buf, SaStringT *str); -extern char *amf_deserialize_SaUint16T (char *buf, SaUint16T *num); -extern char *amf_deserialize_SaUint32T (char *buf, SaUint32T *num); -extern char *amf_deserialize_SaUint64T (char *buf, SaUint64T *num); -extern char *amf_deserialize_opaque (char *buf, void *dst, int *cnt); -extern int amf_msg_mcast (int msg_id, void *buf, size_t len); -extern void amf_fifo_put (int entry_type, amf_fifo_t **root, - int size_of_data, void *data); -extern int amf_fifo_get (amf_fifo_t **root, void *data); -extern void amf_call_function_asynchronous (async_func_t async_func, void *param); - -/*===========================================================================*/ -/* amfnode.c */ - -/* General methods */ -extern struct amf_node *amf_node_new (struct amf_cluster *cluster, char *name); -extern void *amf_node_serialize (struct amf_node *node, int *len); -extern struct amf_node *amf_node_deserialize ( - struct amf_cluster *cluster, char *buf); -extern struct amf_node *amf_node_find (SaNameT *name); -extern struct amf_node *amf_node_find_by_nodeid (unsigned int nodeid); -extern struct amf_node *amf_node_find_by_hostname (const char *hostname); -extern void amf_node_sg_failed_over (struct amf_node *node, - struct amf_sg *sg_in); - -/* Event methods */ -extern void amf_node_sync_ready (struct amf_node *node); -extern void amf_node_leave (struct amf_node *node); -extern void amf_node_failover (struct amf_node *node); -extern void amf_node_switchover (struct amf_node *node); -extern void amf_node_failfast (struct amf_node *node); -extern void amf_node_comp_restart_req ( - struct amf_node *node, struct amf_comp *comp); -extern void amf_node_comp_failover_req ( - struct amf_node *node, struct amf_comp *comp); - -enum amf_reboot_reason { - TERMINATION_FAILED = 1, - INSTANTIATION_FAILED = 2 -}; - -extern int amf_node_reboot ( - struct amf_node *node, enum amf_reboot_reason reason); - -/* Response event methods */ -extern void amf_node_application_started ( - struct amf_node *node, struct amf_application *app); -extern void amf_node_application_workload_assigned ( - struct amf_node *node, struct amf_application *app); - -/* Timer event methods */ -extern void timer_function_node_probation_period_expired (void *node); - -/*===========================================================================*/ -/* amfcluster.c */ - -/* General methods */ -extern struct amf_cluster *amf_cluster_new (void); -extern void *amf_cluster_serialize (struct amf_cluster *cluster, int *len); -extern struct amf_cluster *amf_cluster_deserialize (char *buf); -extern int amf_cluster_applications_assigned (struct amf_cluster *cluster); -extern int amf_cluster_applications_started_with_no_starting_sgs ( - struct amf_cluster *cluster); - - - - -/* Event methods */ -extern void amf_cluster_start_tmo_event (int is_sync_master, - struct amf_cluster *cluster, SaNameT *sourceNodeName); -extern void amf_cluster_sync_ready (struct amf_cluster *cluster, - struct amf_node *node); -/** - * - * @param cluster - * @param app - */ -extern void amf_cluster_start_applications(struct amf_cluster *cluster); - -/* Response event methods */ -extern void amf_cluster_application_started ( - amf_cluster_t *cluster, amf_application_t *app); -extern void amf_cluster_application_workload_assigned ( - struct amf_cluster *cluster, struct amf_application *app); - -/*===========================================================================*/ -/* amfapp.c */ - -/* General methods */ -extern struct amf_application *amf_application_find ( - struct amf_cluster *cluster, char *name); -extern struct amf_application *amf_application_new ( - struct amf_cluster *cluster); -extern void amf_application_delete (struct amf_application *app); -extern int amf_application_calc_and_set_si_dependency_level ( - struct amf_application *app); -extern void *amf_application_serialize ( - struct amf_application *application, int *len); -extern struct amf_application *amf_application_deserialize ( - struct amf_cluster *cluster, char *buf); -extern int amf_application_all_sg_started (struct amf_application *app); - -/* Event methods */ -extern void amf_application_start ( - struct amf_application *app, struct amf_node *node); -extern void amf_application_assign_workload ( - struct amf_application *app, struct amf_node *node); - -/* Response event methods */ -extern void amf_application_sg_started ( - struct amf_application *app, struct amf_sg *sg, struct amf_node *node); -extern void amf_application_sg_assigned ( - struct amf_application *app, struct amf_sg *sg); - -/*===========================================================================*/ -/* amfsg.c */ - -/* General methods */ -extern struct amf_sg *amf_sg_find (struct amf_application *app, char *name); -extern struct amf_sg *amf_sg_new (struct amf_application *app, char *name); -extern void amf_sg_delete (struct amf_sg *sg); -extern void *amf_sg_serialize (struct amf_sg *sg, int *len); -extern struct amf_sg *amf_sg_deserialize ( - struct amf_application *app, char *buf); - -/** - * Request SG to start (instantiate all SUs) - * - * @param sg - * @param node - NULL start all SUs in the SG - * @param node - !NULL start all SUs in the SG for the specified - * node. - */ -extern int amf_sg_start (struct amf_sg *sg, struct amf_node *node); - -/** - * Assign SIs on a certain dependency level to SUs - * @param sg - * @param dependency_level - */ -extern int amf_sg_assign_si_req (struct amf_sg *sg, int dependency_level); - -extern void amf_sg_failover_node_req ( - struct amf_sg *sg, struct amf_node *node); -extern void amf_sg_failover_su_req ( - struct amf_sg *sg, struct amf_su *su, struct amf_node *node); -extern void amf_sg_failover_comp_req ( - struct amf_sg *sg, struct amf_node *node); -extern void amf_sg_switchover_node_req ( - struct amf_sg *sg, struct amf_node *node); -/* Response event methods */ -extern void amf_sg_su_state_changed ( - struct amf_sg *sg, struct amf_su *su, SaAmfStateT type, int state); -extern void amf_sg_si_ha_state_changed ( - struct amf_sg *sg, struct amf_si *si, int state); -extern void amf_sg_su_assignment_removed ( - struct amf_sg *sg, struct amf_su *su); -extern void amf_sg_si_activated ( - struct amf_sg *sg, struct amf_si *si); - -/*===========================================================================*/ -/* amfsu.c */ - -/* General methods */ -extern struct amf_su *amf_su_find ( - struct amf_cluster *cluster, SaNameT *name); -extern struct amf_su *amf_su_new (struct amf_sg *sg, char *name); -extern void amf_su_delete (struct amf_su *su); -extern char *amf_su_dn_make (struct amf_su *su, SaNameT *name); -extern void *amf_su_serialize (struct amf_su *su, int *len); -extern struct amf_su *amf_su_deserialize ( - struct amf_sg *sg, char *buf); -extern int amf_su_is_local (struct amf_su *su); -extern struct amf_si_assignment *amf_su_get_next_si_assignment ( - struct amf_su *su, const struct amf_si_assignment *si_assignment); -extern void amf_su_foreach_si_assignment (struct amf_su *su, - void (*foreach_fn)(struct amf_su *su, - struct amf_si_assignment *si_assignment)); -extern int amf_su_get_saAmfSUNumCurrActiveSIs (struct amf_su *su); -extern int amf_su_get_saAmfSUNumCurrStandbySIs (struct amf_su *su); -extern SaAmfReadinessStateT amf_su_get_saAmfSUReadinessState ( - struct amf_su *su); -extern int amf_su_are_all_comps_in_su (struct amf_su *su, - SaAmfPresenceStateT state); - -/* Event methods */ -/** - * - * @param su - * @param comp - */ -extern amf_si_assignment_t *amf_su_assign_si ( - struct amf_su *su, struct amf_si *si, SaAmfHAStateT ha_state); -extern void amf_su_restart_req (struct amf_su *su); - -/** - * Request termination of all component in an SU - * @param su - */ -void amf_su_terminate (struct amf_su *su); -extern struct amf_node *amf_su_get_node (struct amf_su *su); -extern void amf_su_escalation_level_reset (struct amf_su *su); -extern void amf_su_remove_assignment (struct amf_su *su); - -/* Response event methods */ -extern void amf_su_comp_state_changed ( - struct amf_su *su, struct amf_comp *comp, SaAmfStateT type, int state); -extern void amf_su_comp_error_suspected ( - struct amf_su *su, - struct amf_comp *comp, - SaAmfRecommendedRecoveryT recommended_recovery); -extern void amf_su_restart (struct amf_su *su); -void amf_su_operational_state_set (struct amf_su *su, - SaAmfOperationalStateT oper_state); -extern int amf_su_instantiate (struct amf_su *su); -/*===========================================================================*/ -/* amfcomp.c */ - -/* General methods */ -extern struct amf_comp *amf_comp_new (struct amf_su *su, char *name); -extern void amf_comp_delete (struct amf_comp *comp); -extern char *amf_comp_dn_make (struct amf_comp *comp, SaNameT *name); -extern struct amf_comp *amf_comp_find ( - struct amf_cluster *cluster, SaNameT *name); -extern void *amf_comp_serialize (struct amf_comp *comp, int *len); -extern struct amf_comp *amf_comp_deserialize ( - struct amf_su *su, char *buf); -extern void amf_comp_foreach_csi_assignment ( - struct amf_comp *component, - void (*foreach_fn)(struct amf_comp *component, - struct amf_csi_assignment *csi_assignment)); -extern struct amf_csi_assignment *amf_comp_get_next_csi_assignment ( - struct amf_comp *component, const struct amf_csi_assignment *csi_assignment); -extern SaAmfReadinessStateT amf_comp_get_saAmfCompReadinessState ( - struct amf_comp *comp); -struct amf_comp *amf_comp_find_from_conn_info (void *conn); - -/* Event methods */ -extern void amf_comp_instantiate (struct amf_comp *comp); -extern void amf_comp_terminate (struct amf_comp *comp); -extern void amf_comp_node_left (struct amf_comp *comp); -extern void amf_comp_instantiate_event(struct amf_comp *comp); -extern void amf_comp_instantiate_tmo_event (struct amf_comp *comp); -extern void amf_comp_cleanup_tmo_event (struct amf_comp *comp); - -/** - * Request the component to assume a HA state - * @param comp - * @param csi_assignment - * @param requested_ha_state - */ -extern void amf_comp_hastate_set ( - struct amf_comp *comp, - struct amf_csi_assignment *csi_assignment); - -extern void amf_comp_restart (struct amf_comp *comp); -extern void amf_comp_operational_state_set ( - struct amf_comp *comp, SaAmfOperationalStateT opstate); -extern void amf_comp_readiness_state_set ( - struct amf_comp *comp, SaAmfReadinessStateT state); -extern struct amf_healthcheck *amf_comp_find_healthcheck ( - struct amf_comp *comp, SaAmfHealthcheckKeyT *key); -extern void amf_comp_healthcheck_tmo ( - struct amf_comp *comp, SaAmfRecommendedRecoveryT recommendedRecovery); -extern void amf_comp_cleanup_completed (struct amf_comp *comp); -extern void amf_comp_cleanup_failed_completed (amf_comp_t *comp); - -/** - * Count number of active CSI assignments - * @param component - * - * @return int - */ -extern int amf_comp_get_saAmfCompNumCurrActiveCsi(struct amf_comp *component); - -/** - * Count number of standby CSI assignments - * @param component - * - * @return int - */ -extern int amf_comp_get_saAmfCompNumCurrStandbyCsi(struct amf_comp *component); - -/* - * Originates from library - */ - -extern SaAisErrorT amf_comp_healthcheck_start ( - struct amf_comp *comp, - SaAmfHealthcheckKeyT *healthcheckKey, - SaAmfHealthcheckInvocationT invocationType, - SaAmfRecommendedRecoveryT recommendedRecovery); -extern SaAisErrorT amf_comp_healthcheck_stop ( - struct amf_comp *comp, - SaAmfHealthcheckKeyT *healthcheckKey); -extern SaAisErrorT amf_comp_pm_start ( - struct amf_comp *comp, - SaUint64T pid, - SaInt32T depth, - SaAmfPmErrorsT pmErrors, - SaAmfRecommendedRecoveryT recommendedRecovery); -extern SaAisErrorT amf_comp_pm_stop ( - struct amf_comp *comp, - SaAmfPmStopQualifierT stopQualifier, - SaInt64T pid, - SaAmfPmErrorsT pmErrors); -extern SaAisErrorT amf_comp_register (struct amf_comp *comp); -extern void amf_comp_unregister (struct amf_comp *comp); -extern void amf_comp_error_report ( - struct amf_comp *comp, amf_comp_t *report_comp, - SaAmfRecommendedRecoveryT recommendedRecovery); -extern int amf_comp_response_1 ( - SaInvocationT invocation, SaAisErrorT error, SaAisErrorT *retval, - SaUint32T *interface, SaNameT *dn, SaAmfHealthcheckKeyT *healtcheck_key, - SaAmfRecommendedRecoveryT *recommendedRecovery); -extern struct amf_comp *amf_comp_response_2 ( - SaUint32T interface, SaNameT *dn, SaAmfHealthcheckKeyT *healthcheckKey, - SaAisErrorT error, SaAisErrorT *retval, - SaAmfRecommendedRecoveryT recommendedRecovery); -extern SaAisErrorT amf_comp_hastate_get ( - struct amf_comp *comp, SaNameT *csi_name, SaAmfHAStateT *ha_state); -extern SaAisErrorT amf_comp_healthcheck_confirm ( - struct amf_comp *comp, - SaAmfHealthcheckKeyT *healthcheckKey, - SaAisErrorT healthcheckResult); - -extern amf_healthcheck_t *amf_healthcheck_new (struct amf_comp *comp); -extern void *amf_healthcheck_serialize ( - struct amf_healthcheck *healthcheck, int *len); -extern struct amf_healthcheck *amf_healthcheck_deserialize ( - struct amf_comp *comp, char *buf); - -extern void amf_comp_csi_remove (amf_comp_t *component, - amf_csi_assignment_t *csi_assignment); -extern void amf_comp_error_suspected_clear (amf_comp_t *comp); -extern void amf_comp_error_suspected_set (amf_comp_t *comp); -extern int amf_comp_is_error_suspected (amf_comp_t *comp); - -extern void mcast_error_report_from_pm ( - struct amf_comp *comp, - SaAmfRecommendedRecoveryT recommendedRecovery); - -/*===========================================================================*/ -/* amfsi.c */ - -/* General methods */ -extern struct amf_si *amf_si_find (struct amf_application *app, char *name); -extern struct amf_si *amf_si_new (struct amf_application *app, char *name); -extern void amf_si_delete (struct amf_si *si); -extern int amf_si_calc_and_set_csi_dependency_level (struct amf_si *si); -extern void *amf_si_serialize (struct amf_si *si, int *len); -extern struct amf_si *amf_si_deserialize ( - struct amf_application *app, char *buf); -extern void *amf_si_assignment_serialize ( - struct amf_si_assignment *si_assignment, int *len); -extern struct amf_si_assignment *amf_si_assignment_deserialize ( - struct amf_si *si, char *buf); -extern struct amf_si_assignment *amf_si_assignment_new (struct amf_si *si); -#if 0 -char *amf_si_assignment_dn_make (struct amf_su *su, struct amf_si *si, - SaNameT *name); -#endif -/** - * Get number of active assignments for the specified SI - * @param si - * - * @return int - */ -extern int amf_si_get_saAmfSINumCurrActiveAssignments (struct amf_si *si); -/** - * Get number of active assignments for the specified SI and SU - * @param si - * @param su - * - * @return int - */ -extern int amf_si_su_get_saAmfSINumCurrActiveAssignments (struct amf_si *si, - struct amf_su *su); - -/** - * Get number of standby assignments for the specified SI - * @param si - * - * @return int - */ - -extern int amf_si_get_saAmfSINumCurrStandbyAssignments (struct amf_si *si); - -/** - * Get number of standby assignments for the specified SI and SU - * @param si - * - * @return int - */ -extern int amf_si_su_get_saAmfSINumCurrStandbyAssignments (struct amf_si *si, - struct amf_su *su); - -/** - * Get assignment state for the specified SI. - * @param si - * - * @return SaAmfAssignmentStateT - */ - -extern SaAmfAssignmentStateT amf_si_get_saAmfSIAssignmentState ( - struct amf_si *si); - -/* Event methods */ - -/** - * Activate all active assignments. Request component to change - * HA state to active. - * @param si - * @param activated_callback_fn - */ -extern void amf_si_activate ( - struct amf_si *si, - void (*activated_callback_fn)(struct amf_si *si, int result)); - -/** - * Deactivate all active assignments. Request component to - * change HA state to quiesced. - * - * @param si_assignment - * @param deactivated_callback_fn - * - * @return int 1 - deactived immediately - * @return int 0 - asynchronous response through callback - */ -/***/ -extern int amf_si_deactivate ( - struct amf_si_assignment *si_assignment, - void (*deactivated_callback_fn)(struct amf_si_assignment *si_assignment, - int result)); - -/** - * Request SI (SU) to assume a HA state (request component) - * - * @param si_assignment - * @param assumed_ha_state_callback_fn - */ -extern void amf_si_ha_state_assume ( - struct amf_si_assignment *si_assignment, - void (*assumed_ha_state_callback_fn)(struct amf_si_assignment *si_assignment, - int result)); - -/** - * Component reports to SI that a workload assignment succeeded. - * - * @param si - * @param csi_assignment - */ -extern void amf_si_comp_set_ha_state_done ( - struct amf_si *si, struct amf_csi_assignment *csi_assignment); - -/** - * Component reports to SI that a workload assignment failed. - * @param si - * @param csi_assignment - */ -extern void amf_si_comp_set_ha_state_failed ( - struct amf_si *si, struct amf_csi_assignment *csi_assignment); - -extern void amf_si_assignment_remove (amf_si_assignment_t *si_assignment, - async_func_t async_func); - -extern void amf_si_comp_csi_removed ( - struct amf_si *si, struct amf_csi_assignment *csi_assignment, - SaAisErrorT error); - -/** - * Request a CSI to delete all CSI assignments. - * - * @param component - * @param csi - */ -extern void amf_csi_delete_assignments (struct amf_csi *csi, struct amf_su *su); - -/* General methods */ -extern struct amf_csi *amf_csi_new (struct amf_si *si); -extern struct amf_csi *amf_csi_find (struct amf_si *si, char *name); -extern void amf_csi_delete (struct amf_csi *csi); -extern void *amf_csi_serialize (struct amf_csi *csi, int *len); -extern struct amf_csi *amf_csi_deserialize ( - struct amf_si *si, char *buf); -extern void *amf_csi_assignment_serialize ( - struct amf_csi_assignment *csi_assignment, int *len); -extern struct amf_csi_assignment *amf_csi_assignment_deserialize ( - struct amf_csi *csi, char *buf); -extern char *amf_csi_dn_make (struct amf_csi *csi, SaNameT *name); -extern char *amf_csi_assignment_dn_make ( - struct amf_csi_assignment *csi_assignment, SaNameT *name); -extern struct amf_csi_assignment *amf_csi_assignment_find ( - struct amf_cluster *cluster, SaNameT *name); -extern struct amf_csi_attribute *amf_csi_attribute_new (struct amf_csi *csi); -extern void *amf_csi_attribute_serialize ( - struct amf_csi_attribute *csi_attribute, int *len); -extern struct amf_csi_attribute *amf_csi_attribute_deserialize ( - struct amf_csi *csi, char *buf); -/* extern int sa_amf_grep(const char *string, char *pattern, size_t nmatch, */ -/* char** sub_match_array); */ - -extern int sa_amf_grep(const char *string, char *pattern, size_t nmatch, - SaNameT *sub_match_array); - -/*===========================================================================*/ -extern struct amf_node *this_amf_node; -extern struct amf_cluster *amf_cluster; - -#endif /* AMF_H_DEFINED */ diff --git a/openais/services/amfapp.c b/openais/services/amfapp.c deleted file mode 100644 index e49ff8ab..00000000 --- a/openais/services/amfapp.c +++ /dev/null @@ -1,551 +0,0 @@ -/** @file amfapp.c - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Refactoring of code into several AMF files - * - Constructors/destructors - * - Serializers/deserializers - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Application Class implementation - * - * This file contains functions for handling the AMF Applications. It can - * be viewed as the implementation of the AMF Application class - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for: - * - on request start the service groups it contains - * - on request order the service groups to assign workload to all - * service units contained in the service group, level by level - * - to handle administrative operation support for the application (FUTURE) - * -* The application class contains the following state machines: - * - administrative state machine (ADSM) - * - availability control state machine (ACSM) - * - * The administrative state machine will be implemented in the future. - * - * ACSM handles initial start of an Application. In the future it will also - * handle administrative commands on the application as described in paragraph - * 7.4 of the spec. ACSM includes two stable states (UNINSTANTIATED and - * WORKLOAD_ASSIGNED) and a number of states to control the transition between - * the stable states. - * - * The application is in state UNINSTANTIATED when the application starts. - * (In the future this state will also be assumed after the LOCK_INSTANTIATION - * administrative command.) - * - * State WORKLOAD_ASSIGNED is assumed when the Application has been initially - * started and will in the future be re-assumed after the administrative - * command RESTART have been executed. - * -* 1. AMF Application Availability Control State Machine -* ===================================================== - * - * 1.1 State Transition Table - * - * State: Event: Action: New state: - * =========================================================================== - * UNINSTANTIATED start A6,A1 STARTING_SGS - * STARTING_SGS start [C4] A7 - * STARTING_SGS sg_started [C1] A8,A9 STARTED - * STARTING_SGS assign_workload [C4] A3 ASSIGNING_WORKLOAD - * STARTED start A6,A1 STARTING_SGS - * STARTED start [!C4] A7 STARTED - * STARTED assign_workload A3 ASSIGNING_WORKLOAD - * ASSIGNING_WORKLOAD assign_workload A7 ASSIGNING_WORKLOAD - * ASSIGNING_WORKLOAD start A7 ASSIGNING_WORKLOAD - * ASSIGNING_WORKLOAD sg_assigned [C2] A10,A9 WORKLOAD_ASSIGNED - * WORKLOAD_ASSIGNED start A6,A1 STARTING_SGS - * WORKLOAD_ASSIGNED assign_workload A3 ASSIGNING_WORKLOAD -* -* 1.2 State Description -* ===================== -* UNINSTANTIATED - No SUs within the SGs contained in the Application have been -* instantiated. -* STARTING_SGS - Waiting for the contained SGs to start. -* STARTED - No SUs within the SGs contained in the Application are in the -* process of beein instantiated. Either the SUs are instantiated or -* instantiation was not possible or instantiation has failed. -* ASSIGNING_WORKLOAD - Waiting for the contained SGs to indicate they have -* assigned workload to its SUs. -* WORKLOAD_ASSIGNED - at least some workload has been assigned to the SUs that -* are in-service. -* -* 1.3 Actions -* =========== -* A1 - [foreach SG in Application] sg_start -* A2 - -* A3 - [foreach SG in Application] sg_assign -* A4 - -* A5 - -* A6 - save value of received node parameter -* A7 - defer the event -* A8 - [node == NULL] cluster_application_started else node_application_started -* A9 - recall deferred events -* A10 - [node == NULL] cluster_application_assigned else -* node_application_assigned -* -* 1.4 Guards -* ========== -* C1 - No SU has presence state == INSTANTIATING -* C2 - All SGs have availability control state == IDLE -* C3 - -* C4 - Sender is Cluster -*/ - -#include -#include -#include "amf.h" -#include "logsys.h" -#include "util.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -typedef struct application_event { - amf_application_event_type_t event_type; - amf_application_t *app; - amf_node_t *node; -} application_event_t; - -/****************************************************************************** - * Internal (static) utility functions - *****************************************************************************/ - -static int is_cluster_start(amf_node_t *node_to_start) -{ - return node_to_start == NULL; -} - -static void application_defer_event ( - amf_application_event_type_t event_type, amf_application_t *app, - amf_node_t *node) -{ - application_event_t app_event = {event_type, app, node}; - ENTER(""); - amf_fifo_put (event_type, &app->deferred_events, - sizeof (application_event_t), &app_event); -} - -static void application_recall_deferred_events (amf_application_t *app) -{ - application_event_t application_event; - - if (amf_fifo_get (&app->deferred_events, &application_event)) { - switch (application_event.event_type) { - case APPLICATION_ASSIGN_WORKLOAD_EV: { - log_printf (LOG_NOTICE, - "Recall APPLICATION_ASSIGN_WORKLOAD_EV"); - amf_application_assign_workload ( - application_event.app, - application_event.node); - break; - } - case APPLICATION_START_EV: { - - log_printf (LOG_NOTICE, - "Recall APPLICATION_START_EV"); - amf_application_start (application_event.app, - application_event.node); - break; - } - default: - assert (0); - break; - } - } -} - -static void timer_function_application_recall_deferred_events (void *data) -{ - amf_application_t *app = (amf_application_t*)data; - - ENTER (""); - application_recall_deferred_events (app); -} - -static int no_su_is_instantiating (struct amf_application *app) -{ - struct amf_sg *sg; - struct amf_su *su; - int all_su_instantiated = 1; - - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - if (su->saAmfSUPresenceState == SA_AMF_PRESENCE_INSTANTIATING) { - all_su_instantiated = 0; - break; - } - } - } - return all_su_instantiated; -} - -static int all_sg_assigned (struct amf_application *app) -{ - struct amf_sg *sg; - int all_sg_assigned = 1; - - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - if (sg->avail_state != SG_AC_Idle) { - all_sg_assigned = 0; - break; - } - } - return all_sg_assigned; -} - -static void start_all_sg_for_cluster (amf_application_t *app) -{ - amf_sg_t *sg; - int su_to_instantiate = 0; - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - su_to_instantiate += amf_sg_start (sg, NULL); - } - - if (su_to_instantiate == 0) { - amf_cluster_application_started (app->cluster, app); - } -} - -static void timer_function_cluster_application_started (void* app) -{ - ENTER(""); - amf_application_t *application = (amf_application_t*)app; - amf_cluster_application_started (application->cluster, application); -} - -static void timer_function_node_application_started (void* app) -{ - ENTER(""); - amf_application_t *application = (amf_application_t*)app; - amf_node_application_started (application->node_to_start, application); -} - -static void application_enter_starting_sgs (struct amf_application *app, - struct amf_node *node) -{ - amf_sg_t *sg = 0; - int su_to_instantiate = 0; - app->node_to_start = node; - app->acsm_state = APP_AC_STARTING_SGS; - ENTER ("%s",app->name.value); - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - su_to_instantiate += amf_sg_start (sg, node); - } - - if (su_to_instantiate == 0) { - app->acsm_state = APP_AC_STARTED; - if (is_cluster_start (app->node_to_start)) { - amf_call_function_asynchronous ( - timer_function_cluster_application_started, app); - } else { - amf_call_function_asynchronous ( - timer_function_node_application_started, app); - } - } -} - -static void application_enter_assigning_workload (amf_application_t *app) -{ - amf_sg_t *sg = 0; - int posible_to_assign_si = 0; - ENTER ("%s",app->name.value); - app->acsm_state = APP_AC_ASSIGNING_WORKLOAD; - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - if (amf_sg_assign_si_req (sg, 0)) { - posible_to_assign_si = 1; - } - } - if (posible_to_assign_si == 0) { - app->acsm_state = APP_AC_WORKLOAD_ASSIGNED; - } - -} - -static void application_enter_workload_assigned (amf_application_t *app) -{ - ENTER ("%s", app->name.value); - if (all_sg_assigned (app)){ - app->acsm_state = APP_AC_WORKLOAD_ASSIGNED; - if (app->node_to_start == NULL){ - amf_cluster_application_workload_assigned ( - app->cluster, app); - } else { - TRACE1("%s",app->node_to_start->name.value); - amf_node_application_workload_assigned( - app->node_to_start, app); - } - - amf_call_function_asynchronous ( - timer_function_application_recall_deferred_events, app); - } -} - -/****************************************************************************** - * Event methods - *****************************************************************************/ - - -void amf_application_start ( - struct amf_application *app, struct amf_node *node) -{ - ENTER ("'%s'", app->name.value); - assert (app != NULL); - switch (app->acsm_state) { - case APP_AC_UNINSTANTIATED: - application_enter_starting_sgs (app, node); - break; - case APP_AC_STARTING_SGS: - if (is_cluster_start (app->node_to_start)) { - start_all_sg_for_cluster (app); - } else { /*is_not_cluster_start*/ - application_defer_event (APPLICATION_START_EV, app , node); - } - break; - case APP_AC_STARTED: - if (is_cluster_start (app->node_to_start)) { - app->acsm_state = APP_AC_STARTING_SGS; - start_all_sg_for_cluster (app); - } else { /*is_not_cluster_start*/ - application_defer_event (APPLICATION_START_EV, app , node); - } - break; - case APP_AC_ASSIGNING_WORKLOAD: - log_printf (LOG_LEVEL_ERROR, "Request to start application" - " =%s in state APP_AC_ASSIGNING_WORKLOAD(should be deferred)", - app->name.value); - application_defer_event (APPLICATION_START_EV, app , node); - break; - case APP_AC_WORKLOAD_ASSIGNED: - application_enter_starting_sgs (app, node); - break; - default: - assert (0); - break; - } -} - -void amf_application_assign_workload (struct amf_application *app, - struct amf_node *node) -{ - /* - * TODO: dependency level ignored. Each dependency level should - * be looped and amf_sg_assign_si called several times. - */ - - assert (app != NULL); - app->node_to_start = node; - ENTER("app->acsm_state = %d",app->acsm_state); - - switch (app->acsm_state) { - case APP_AC_STARTING_SGS: - if (is_cluster_start (node)) { - application_enter_assigning_workload (app); - } - break; - case APP_AC_WORKLOAD_ASSIGNED: - application_enter_assigning_workload (app); - break; - case APP_AC_STARTED: - application_enter_assigning_workload (app); - break; - case APP_AC_ASSIGNING_WORKLOAD: - if (app->node_to_start == node) { - /* - * Calling object has violated the contract ! - */ - assert (0); - } else { - log_printf (LOG_LEVEL_ERROR, "Request to assign workload to" - " application =%s in state APP_AC_ASSIGNING_WORKLOAD " - "(should be deferred)", app->name.value); - - application_defer_event (APPLICATION_ASSIGN_WORKLOAD_EV, app, - node); - } - break; - default: - /* - * Calling object has violated the contract ! - */ - dprintf ("acsm_state = %d",app->acsm_state); - assert (0); - break; - } -} - -/****************************************************************************** - * Event response methods - *****************************************************************************/ - -void amf_application_sg_started (struct amf_application *app, struct amf_sg *sg, - struct amf_node *node) -{ - ENTER ("'%s %s'", app->name.value, sg->name.value); - - assert (app != NULL); - - switch (app->acsm_state) { - case APP_AC_STARTING_SGS: - if (no_su_is_instantiating (app)) { - app->acsm_state = APP_AC_STARTED; - if (app->node_to_start == NULL) { - amf_cluster_application_started (app->cluster, app); - } else { - amf_node_application_started (app->node_to_start, app); - } - } - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_application_sg_started()" - " called in state = %d", app->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - } -} - -void amf_application_sg_assigned ( - struct amf_application *app, struct amf_sg *sg) -{ - ENTER ("'%s'", app->name.value); - assert (app != NULL); - - switch (app->acsm_state) { - case APP_AC_ASSIGNING_WORKLOAD: - application_enter_workload_assigned (app); - break; - default: - log_printf (LOG_LEVEL_ERROR, - "amf_application_sg_assigned()" - " called in state = %d", app->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - } -} - -/****************************************************************************** - * General methods - *****************************************************************************/ - -struct amf_application *amf_application_new (struct amf_cluster *cluster) { - struct amf_application *app = amf_calloc (1, - sizeof (struct amf_application)); - - app->cluster = cluster; - app->next = cluster->application_head; - cluster->application_head = app; - app->acsm_state = APP_AC_UNINSTANTIATED; - app->node_to_start = NULL; - return app; -} - -void amf_application_delete (struct amf_application *app) -{ - struct amf_sg *sg; - struct amf_si *si; - - assert (app != NULL); - for (sg = app->sg_head; sg != NULL;) { - struct amf_sg *tmp = sg; - sg = sg->next; - amf_sg_delete (tmp); - } - - for (si = app->si_head; si != NULL;) { - struct amf_si *tmp = si; - si = si->next; - amf_si_delete (tmp); - } - free (app); -} - -void *amf_application_serialize ( - struct amf_application *app, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - assert (app != NULL); - TRACE8 ("%s", app->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &app->name); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, app->saAmfApplicationAdminState); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, app->saAmfApplicationCurrNumSG); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, app->clccli_path); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, app->acsm_state); - - *len = offset; - return buf; -} - -struct amf_application *amf_application_deserialize ( - struct amf_cluster *cluster, char *buf) -{ - char *tmp = buf; - struct amf_application *app = amf_application_new (cluster); - - tmp = amf_deserialize_SaNameT (tmp, &app->name); - tmp = amf_deserialize_SaUint32T (tmp, &app->saAmfApplicationAdminState); - tmp = amf_deserialize_SaUint32T (tmp, &app->saAmfApplicationCurrNumSG); - tmp = amf_deserialize_SaStringT (tmp, &app->clccli_path); - tmp = amf_deserialize_SaUint32T (tmp, &app->acsm_state); - - return app; -} - -struct amf_application *amf_application_find ( - struct amf_cluster *cluster, char *name) -{ - struct amf_application *app; - - assert (cluster != NULL); - for (app = cluster->application_head; app != NULL; app = app->next) { - - if (app->name.length == strlen(name) && - strncmp (name, (char*)app->name.value, app->name.length) - == 0) { - break; - } - } - - if (app == NULL) { - dprintf ("App %s not found!", name); - } - return app; -} - diff --git a/openais/services/amfcluster.c b/openais/services/amfcluster.c deleted file mode 100644 index 6469ecf2..00000000 --- a/openais/services/amfcluster.c +++ /dev/null @@ -1,582 +0,0 @@ - -/** @file amfcluster.c - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Refactoring of code into several AMF files - * - Constructors/destructors - * - Serializers/deserializers - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Cluster Class Implementation - * - * This file contains functions for handling the AMF cluster. It can be - * viewed as the implementation of the AMF Cluster class - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for: - * - to start the cluster initially - * - to handle the administrative operation support for the cluster (FUTURE) - * - * The cluster class contains the following state machines: - * - administrative state machine (ADSM) - * - availability control state machine (ACSM) - * - * The administrative state machine will be implemented in the future. - * - * ACSM handles initial start of the cluster. In the future it will also handle - * administrative commands on the cluster as described in paragraph 7.4 of the - * spec. ACSM includes two stable states (UNINSTANTIATED and STARTED) and a - * number of states to control the transition between the stable states. - * - * The cluster is in state UNINSTANTIATED when the cluster starts. (In the - * future this state will also be assumed after the LOCK_INSTANTIATION - * administrative command.) - * - * State STARTED is assumed when the cluster has been initially started and - * will in the future be re-assumed after the administrative command RESTART - * have been executed. - * - * 1. Cluster Availability Control State Machine - * ============================================= - * - * 1.1 State Transition Table - * - * State: Event: Action: New state: - * =========================================================================== - * UNINSTANTIATED sync_ready [C1] A2,A1 STARTING_APPS - * STARTING_APPS sync_ready A2,A1 STARTING_APPS - * STARTING_APPS app_started [C3] A7,A3 ASSIGNING_WORKLOAD - * STARTING_APPS local_timer_expired A8 STARTING_APPS - * STARTING_APPS time_out A7,A8 WAITING_OVERTIME_1 - * WAITING_OVERTIME_1 sync_ready A4 WAITING_OVERTIME_1 - * WAITING_OVERTIME_1 time_out [C2] A7 ASSIGNING_WORKLOAD - * WAITING_OVERTIME_1 time_out A7 WAITING_OVERTIME_2 - * WAITING_OVERTIME_1 app_started [C2] A3 ASSIGNING_WORKLOAD - * WAITING_OVERTIME_2 sync_ready A4 WAITING_OVERTIME_2 - * WAITING_OVERTIME_2 app_started [C2] A3 ASSIGNING_WORKLOAD - * ASSIGNING_WORKLOAD sync_ready A4 ASSIGNING_WORKLOAD - * ASSIGNING_WORKLOAD app_assigned [C4] A6 STARTED - * STARTED sync_ready A5 STARTED - * - * 1.2 State Description - * ===================== - * UNINSTANTIATED - No SUs within any SG in any Application is instantiated. - * STARTING_APPLICATIONS - All applications have been requested to start - * their contained SGs, which in its turn has requested - * their contained SUs to instantiate all their - * components. The cluster startup timer is running. - * WAITING_OVERTIME_1 - The cluster startup timer has expired but all - * applications have yet not responded that they have been - * started. The time-out message is broadcasted again to - * make sure there are no other broadcast messages pending. - * (This assures first of all that there is no pending - * 'component instantiate' message.) - * WAITING_OVERTIME_2 - The cluster startup timer has expired but all - * applications have yet not responded that they have been - * started. Cluster will wait infinitely for the - * applications to respond. It is correct to do so even when - * the startup timer has expired, because the applications - * will report they are started as soon as there is no - * attempt to instantiate any of its components pending, - * because attempts to instantiate a component can not go on - * forever, see saAmfCompInstantiateTimeout, - * saAmfCompNumMaxInstantiateWithoutDelay and - * saAmfCompNumMaxInstantiateWithDelay. - * ASSIGNING_WORKLOAD - All applications have been requested to assign it's - * specified workload to it's service units according to - * the redundancy model specified by it's SGs. - * STARTED - A best effort has been made to instatiate the components of all - * applications and assign the specified workload as close as possible - * to what is described in the configuration. - * - * 1.3 Actions - * =========== - * A1 - [foreach application in cluster]/start application - * A2 - start cluster startup timer - * A3 - [foreach application in cluster]/assign workload to application - * A4 - defer sync_ready event - * A5 - forward sync_ready to appropriate node object - * A6 - recall deferred event - * A7 - stop node local instance of cluster startup timer - * A8 - multicast 'cluster startup timer time-out' event (time_out) - * - * 1.4 Guards - * ========== - * C1 - Administrative state == UNLOCKED - * C2 - No SU has presence state == INSTANTIATING - * C3 - All SGs are fully instantiated - * C4 - No Application has Availability Control state == ASSIGNING_WORKLOAD - */ - - -#include -#include -#include - -#include "logsys.h" -#include "amf.h" -#include "util.h" -#include "main.h" -#include "service.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -typedef struct cluster_event { - amf_cluster_event_type_t event_type; - amf_cluster_t *cluster; - amf_node_t *node; -} cluster_event_t; - -/****************************************************************************** - * Internal (static) utility functions - *****************************************************************************/ - -static void cluster_defer_event (amf_cluster_event_type_t event_type, - struct amf_cluster *cluster, struct amf_node * node) -{ - cluster_event_t sync_ready_event = {event_type, cluster, node}; - amf_fifo_put (event_type, &cluster->deferred_events, - sizeof (cluster_event_t), - &sync_ready_event); -} - -static void cluster_recall_deferred_events (amf_cluster_t *cluster) -{ - cluster_event_t cluster_event; - - if (amf_fifo_get (&cluster->deferred_events, &cluster_event)) { - switch (cluster_event.event_type) { - case CLUSTER_SYNC_READY_EV: - log_printf (LOG_NOTICE, - "Recall CLUSTER_SYNC_READY_EV"); - - amf_node_sync_ready (cluster_event.node); - break; - default: - assert (0); - break; - } - } -} - -static void timer_function_cluster_recall_deferred_events (void *data) -{ - amf_cluster_t *cluster = (amf_cluster_t*)data; - - ENTER (""); - cluster_recall_deferred_events (cluster); -} - -/** - * Determine if all applications are started so that all - * SUs is in SA_AMF_PRESENCE_INSTANTIATED presense state - * @param cluster - * - * @return 1; All applications are started - */ -static int cluster_applications_started_instantiated (struct amf_cluster *cluster) -{ - int all_started = 1; - struct amf_application *app; - struct amf_sg *sg; - struct amf_su *su; - - for (app = cluster->application_head; app != NULL; app = app->next) { - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - if (su->saAmfSUPresenceState != SA_AMF_PRESENCE_INSTANTIATED) { - all_started = 0; - goto done; - } - } - } - } - - done: - return all_started; -} - -/** - * Determine if any SGs are in the process of instantiating their SUs. - * @param cluster - * - * @return 1; At least one SG is in the process of instantiating. - */ -static int cluster_applications_are_starting_sgs(struct amf_cluster *cluster) -{ - amf_application_t *application; - amf_sg_t *sg; - amf_su_t *su; - int is_starting_sgs = 0; - - for (application = cluster->application_head; application != NULL; - application = application->next) { - for (sg = application->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - - if (su->saAmfSUPresenceState == - SA_AMF_PRESENCE_INSTANTIATING) { - is_starting_sgs = 1; - break; - } - } - } - } - return is_starting_sgs; -} - -static void amf_cluster_assign_workload (struct amf_cluster *cluster) -{ - struct amf_application *app; - ENTER (""); - - for (app = cluster->application_head; app != NULL; app = app->next) { - amf_application_assign_workload (app, NULL); - } -} - -static void acsm_cluster_enter_assigning_workload (struct amf_cluster *cluster) -{ - log_printf(LOG_NOTICE, - "Cluster: all applications started, assigning workload."); - cluster->acsm_state = CLUSTER_AC_ASSIGNING_WORKLOAD; - amf_cluster_assign_workload (cluster); -} - -static void timer_function_cluster_assign_workload_tmo (void *cluster) -{ - ((struct amf_cluster*)cluster)->timeout_handle = 0; - - ENTER (""); - - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_CLUSTER_START_TMO, &this_amf_node->name, - sizeof(SaNameT)); -} - -static inline void stop_cluster_startup_timer (struct amf_cluster *cluster) -{ - if (cluster->timeout_handle) { - dprintf ("Stop cluster startup timer"); - poll_timer_delete (aisexec_poll_handle, - cluster->timeout_handle); - cluster->timeout_handle = 0; - } -} - -static void start_cluster_startup_timer (struct amf_cluster *cluster) -{ - if (cluster->timeout_handle == 0) { - poll_timer_add (aisexec_poll_handle, - cluster->saAmfClusterStartupTimeout, - cluster, - timer_function_cluster_assign_workload_tmo, - &cluster->timeout_handle); - } -} - -static inline void cluster_enter_starting_applications ( - struct amf_cluster *cluster) -{ - ENTER (""); - start_cluster_startup_timer (cluster); - amf_cluster->acsm_state = CLUSTER_AC_STARTING_APPLICATIONS; - amf_cluster_start_applications (cluster); -} - -static void acsm_cluster_enter_started (amf_cluster_t *cluster) -{ - ENTER (""); - amf_cluster->acsm_state = CLUSTER_AC_STARTED; - amf_call_function_asynchronous ( - timer_function_cluster_recall_deferred_events, cluster); -} - -/****************************************************************************** - * Event methods - *****************************************************************************/ - -void amf_cluster_start_tmo_event (int is_sync_masterm, - struct amf_cluster *cluster, SaNameT *sourceNodeName) -{ - ENTER ("acsm_state = %d", amf_cluster->acsm_state); - - stop_cluster_startup_timer (cluster); - - switch (cluster->acsm_state) { - case CLUSTER_AC_WAITING_OVER_TIME_1: - if (cluster_applications_are_starting_sgs (cluster)) { - dprintf ("Cluster startup timeout," - "start waiting over time"); - amf_cluster->acsm_state = - CLUSTER_AC_WAITING_OVER_TIME_2; - } else { - dprintf ("Cluster startup timeout," - " assigning workload"); - acsm_cluster_enter_assigning_workload (cluster); - } - break; - case CLUSTER_AC_STARTING_APPLICATIONS: - cluster->acsm_state = CLUSTER_AC_WAITING_OVER_TIME_1; - if (name_match (&this_amf_node->name, sourceNodeName)) { - timer_function_cluster_assign_workload_tmo (cluster); - } - - break; - case CLUSTER_AC_ASSIGNING_WORKLOAD: - /* ignore cluster startup timer expiration */ - case CLUSTER_AC_STARTED: - /* ignore cluster startup timer expiration */ - case CLUSTER_AC_WAITING_OVER_TIME_2: - /* ignore cluster startup timer expiration */ - break; - default: - log_printf(LOG_LEVEL_ERROR, "Cluster timout expired" - " in wrong cluster" - " state = %d", cluster->acsm_state); - assert(0); - break; - } -} - - -/** - * Start all applications in the cluster and start - * the cluster startup timeout. - * @param cluster - * @param app - */ -void amf_cluster_start_applications(struct amf_cluster *cluster) -{ - struct amf_application *app; - for (app = cluster->application_head; app != NULL; app = app->next) { - amf_application_start (app, NULL); - } -} - -/** - * A new node has joined the cluster and is now synchronized with the nodes that - * was part of the cluster before. - * @param cluster - * @param node - */ -void amf_cluster_sync_ready (struct amf_cluster *cluster, struct amf_node *node) -{ - ENTER (""); - switch (amf_cluster->acsm_state) { - case CLUSTER_AC_UNINSTANTIATED: - if (amf_cluster->saAmfClusterAdminState == - SA_AMF_ADMIN_UNLOCKED) { - cluster_enter_starting_applications (cluster); - } - break; - case CLUSTER_AC_STARTING_APPLICATIONS: - cluster_enter_starting_applications(cluster); - break; - case CLUSTER_AC_ASSIGNING_WORKLOAD: - /* - * Defer assigning workload to those syncronized nodes to - * CLUSTER_AC_STARTED state. - */ - cluster_defer_event (CLUSTER_SYNC_READY_EV, cluster, - node); - break; - case CLUSTER_AC_WAITING_OVER_TIME_2: - /* - * Defer assigning workload to those syncronized nodes to - * CLUSTER_AC_STARTED state. - */ - cluster_defer_event (CLUSTER_SYNC_READY_EV, cluster, - node); - break; - case CLUSTER_AC_STARTED: - TRACE1 ("Node sync ready sent from cluster in " - "CLUSTER_AC_STARTED state"); - amf_node_sync_ready (node); - break; - - default: - log_printf(LOG_LEVEL_ERROR, "Cluster sync ready event" - " received in wrong cluster" - " state = %d", cluster->acsm_state); - assert (0); - break; - } -} - -/****************************************************************************** - * Event response methods - *****************************************************************************/ - -/** - * An application indicates it has been started or the application indicates it - * was not even possible to try to start because the required nodes were not - * available. - * @param cluster - * @param application - */ -void amf_cluster_application_started ( - struct amf_cluster *cluster, struct amf_application *application) -{ - ENTER ("application '%s' started %d", application->name.value, - cluster->acsm_state); - switch (cluster->acsm_state) { - case CLUSTER_AC_STARTING_APPLICATIONS: - if (cluster_applications_started_instantiated (cluster)) { - stop_cluster_startup_timer (cluster); - acsm_cluster_enter_assigning_workload (cluster); - } - break; - case CLUSTER_AC_WAITING_OVER_TIME_1: - case CLUSTER_AC_WAITING_OVER_TIME_2: - if (amf_cluster_applications_started_with_no_starting_sgs (cluster)) { - acsm_cluster_enter_assigning_workload (cluster); - } - break; - default: { - log_printf (LOG_ERR,"Error invalid cluster availability state %d", - cluster->acsm_state); - openais_exit_error(cluster->acsm_state); - break; - } - } -} - -/** - * An application indicates it has assigned workload to all its contained SUs. - * @param cluster - */ -void amf_cluster_application_workload_assigned ( - struct amf_cluster *cluster, struct amf_application *app) -{ - ENTER (""); - switch (cluster->acsm_state) { - case CLUSTER_AC_ASSIGNING_WORKLOAD: - log_printf (LOG_NOTICE, "Cluster: application %s assigned.", - app->name.value); - if (amf_cluster_applications_assigned (cluster)) { - acsm_cluster_enter_started (cluster); - } - break; - default: - assert(0); - break; - } -} - -/****************************************************************************** - * General methods - *****************************************************************************/ - -struct amf_cluster *amf_cluster_new (void) -{ - struct amf_cluster *cluster = amf_calloc (1, - sizeof (struct amf_cluster)); - - cluster->saAmfClusterStartupTimeout = -1; - cluster->saAmfClusterAdminState = SA_AMF_ADMIN_UNLOCKED; - cluster->deferred_events = 0; - cluster->acsm_state = CLUSTER_AC_UNINSTANTIATED; - return cluster; -} - -void *amf_cluster_serialize (struct amf_cluster *cluster, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", cluster->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &cluster->name); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - cluster->saAmfClusterStartupTimeout); - buf = amf_serialize_SaNameT (buf, &size, &offset, - &cluster->saAmfClusterClmCluster); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - cluster->saAmfClusterAdminState); - buf = amf_serialize_SaUint32T (buf, &size, &offset, cluster->acsm_state); - - *len = offset; - - return buf; -} - -struct amf_cluster *amf_cluster_deserialize (char *buf) -{ - char *tmp = buf; - struct amf_cluster *cluster = amf_cluster_new (); - - tmp = amf_deserialize_SaNameT (tmp, &cluster->name); - tmp = amf_deserialize_SaUint32T (tmp, &cluster->saAmfClusterStartupTimeout); - tmp = amf_deserialize_SaNameT (tmp, &cluster->saAmfClusterClmCluster); - tmp = amf_deserialize_SaUint32T (tmp, &cluster->saAmfClusterAdminState); - tmp = amf_deserialize_SaUint32T (tmp, &cluster->acsm_state); - - return cluster; -} - -/** - * Determine if any SGs are in the process of instantiating their SUs. - * @param cluster - * - * @return 1; At least one SG is in the process of instantiating. - */ -int amf_cluster_applications_started_with_no_starting_sgs ( -struct amf_cluster *cluster) -{ - return !cluster_applications_are_starting_sgs (cluster); -} - -/** - * Determine if all Applications have been assigned workload. - * @param cluster - * - * @return 1; All Applications have been assigned workload. - */ -int amf_cluster_applications_assigned (struct amf_cluster *cluster) -{ - struct amf_application *app = 0; - int is_all_application_assigned = 1; - - for (app = cluster->application_head; app != NULL; app = app->next) { - if (app->acsm_state != APP_AC_WORKLOAD_ASSIGNED) { - is_all_application_assigned = 0; - break; - } - } - return is_all_application_assigned; -} - - - - diff --git a/openais/services/amfcomp.c b/openais/services/amfcomp.c deleted file mode 100644 index ac0f49fc..00000000 --- a/openais/services/amfcomp.c +++ /dev/null @@ -1,2761 +0,0 @@ -/** @file amfcomp.c - * - * Copyright (c) 2006 Ericsson AB. - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. Copyright (c) 2006 - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Introduced AMF B.02 information model - * - Use DN in API and multicast messages - * - (Re-)Introduction of event based multicast messages - * - Refactoring of code into several AMF files - * - Component/SU restart, SU failover - * - Constructors/destructors - * - Serializers/deserializers - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Component Class Implementation - * - * This file contains functions for handling AMF-components. It can be - * viewed as the implementation of the AMF Component class (called comp) - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for handling the following - * types of components: - * - sa-aware components - * (proxy or non-proxy) - * - non-sa-aware components - * (non-proxied non-pre-instantiable and - * proxied pre-instantiable or not pre-instantiable) - * - * The functions of this file are also responsible for: - * - handling all communication with the AMF API library supported by the - * AMF main function, see below - * - instantiating and terminating components upon request - * - updating the ha-state of the CSI-assignment related to the component - * - initiating an error report to the parent SU - * - handling all run time attributes of the AMF Component; all cached - * attributes are stored as variables and sent to the IMM service - * upon the changes described in the specification. - * - * Incoming events from the AMF library is primarily handled by the AMF - * main function which: - * <1> transforms the incoming event to an event that is multicast - * to all AMF service instances in the cluster - * <2> the event received from multicast is tranformed to a function - * call of the external interface of comp - * - * Outgoing events to the AMF library is handled by static functions called - * lib__request which creates an invocation handle - * unique to this call and stores any variables comp want to associate to the - * call back so it is possible to pick them up when the component responses - * through the API. Finally, a timer is started to supervise that a response - * really is received. - * - * Comp initiates error reports to its parent SU in the cases described in - * paragraph 3.3.2.2 in the spec. Comp delegates all actions to SU except - * - it stores the received or pre-configured recommended recovery - * action - * - sets the operational state to DISABLED unless the - * recommended recovery action was SA_AMF_COMP_RESTART. (In this case - * SU or node may set operational state of the component later on - * when it has been fully investigated that no escallation to a - * more powerful recovery action shall be made.) - * - * Comp contains the following state machines: - * - presence state machine (PRSM) - * - operational state machine (OPSM) - * - readiness state machine (RESM) - * - ha state per component service instance (CSI) - * - * The behaviour of comp is mainly controlled by the presence state machine, - * while the operational and readiness state machines are used only to report - * information to its parent (service unit SU) and management (IMM). Comp does - * not control the logic to assign a CSI to itself and neither to decide the - * value of the ha-state but only to faciltate the communication of the CSI - * set (or remove) order and to evaluate the response from the library. - * - * The presence state machine implements all the states described in the - * specification. - * The '-ING' states of PRSM are designed as composite states (UML terminology). - * Being a composite state means that the state contains substates. - * PRSM composite states are: - * - TERMINATING (TERMINATE and CLEANUP) - * - INSTANTIATING (INSTANTIATE, INSTANTIATEDELAY and CLEANUP) - * - RESTARTING (TERMINATE, INSTANTIATE, INSTANTIATEDELAY and CLEANUP) - * - * The reason for introducing these composite states is to make it easier to - * understand the implementation of the behaviour described in paragraphs - * 4.1 - 4.6 in the spec. The comp PRSM implements all the logic described - * except for node reboot, which is handled by the AMF Node class. - * Also PRSM reports all changes of state to its parent SU. - * - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../include/saAis.h" -#include "../include/saAmf.h" -#include "../include/ipc_gen.h" -#include "../include/ipc_amf.h" -#include "totempg.h" -#include "timer.h" -#include "flow.h" -#include "tlist.h" -#include "ipc.h" -#include "objdb.h" -#include "service.h" -#include "util.h" -#include "amf.h" -#include "logsys.h" -#include "main.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -enum clc_command_run_operation_type { - CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1, - CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2, - CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3 -}; - -struct clc_command_run_data { - struct amf_comp *comp; - enum clc_command_run_operation_type type; - void (*completion_callback) (void *context); - int exit_code; -}; - -struct clc_interface { - int (*instantiate) (struct amf_comp *comp); - int (*terminate) (struct amf_comp *comp); - int (*cleanup) (struct amf_comp *comp); -}; - -struct csi_remove_callback_data { - struct amf_csi *csi; -}; - -struct component_terminate_callback_data { - struct amf_comp *comp; -}; - -static void comp_presence_state_set ( - struct amf_comp *comp, - SaAmfPresenceStateT presence_state); -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 lib_comp_terminate_request (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_deactivate (struct amf_healthcheck *healthcheck_active); -static void lib_healthcheck_request (struct amf_healthcheck *healthcheck); -static void timer_function_healthcheck_tmo (void *_healthcheck); -static void lib_csi_set_request ( - struct amf_comp *comp, - struct amf_csi_assignment *csi_assignment); - -static void comp_recover_action (amf_comp_t *comp, - SaAmfRecommendedRecoveryT recommendedRecovery); - -/* - * Life cycle functions - */ -static struct clc_interface clc_interface_sa_aware = { - clc_cli_instantiate, - lib_comp_terminate_request, - clc_cli_cleanup -}; - -static struct clc_interface clc_interface_proxied_pre = { - clc_instantiate_callback, - lib_comp_terminate_request, - clc_cli_cleanup -}; - -static struct clc_interface clc_interface_proxied_non_pre = { - clc_csi_set_callback, - clc_csi_remove_callback, - clc_cli_cleanup_local -}; - -static struct clc_interface clc_interface_non_proxied_non_saware = { - clc_cli_instantiate, - clc_cli_terminate, - clc_cli_cleanup_local -}; - -static struct clc_interface *clc_interfaces[4] = { - &clc_interface_sa_aware, - &clc_interface_proxied_pre, - &clc_interface_proxied_non_pre, - &clc_interface_non_proxied_non_saware -}; - -struct invocation { - void *data; - int interface; - int active; -}; - -static struct invocation *invocation_entries = 0; -static int invocation_entries_size = 0; - -static int is_not_instantiating_or_instantiated_or_restarting (amf_comp_t *comp) -{ - return (!(comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING || - comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATED || - comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING)); -} - -static int invocation_create ( - int interface, - void *data) -{ - struct invocation *invocation_addr = 0; - struct invocation *invocation_temp; - int i; - int loc = 0; - - for (i = 0; i < invocation_entries_size; i++) { - if (invocation_entries[i].active == 0) { - invocation_addr = &invocation_entries[i]; - loc = i; - break; - } - } - if (invocation_addr == 0) { - invocation_temp = (struct invocation *)realloc (invocation_entries, - (invocation_entries_size + 1) * sizeof (struct invocation)); - if (invocation_temp == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - invocation_entries = invocation_temp; - invocation_addr = &invocation_entries[invocation_entries_size]; - loc = invocation_entries_size; - invocation_entries_size += 1; - } - invocation_addr->interface = interface; - invocation_addr->data = data; - invocation_addr->active = 1; - - return (loc); -} - -static int invocation_get_and_destroy ( - SaUint64T invocation, unsigned int *interface, void **data) -{ - if (invocation > invocation_entries_size) { - return (-1); - } - if (invocation_entries[invocation].active == 0) { - return (-1); - } - - *interface = invocation_entries[invocation].interface; - *data = invocation_entries[invocation].data; - memset (&invocation_entries[invocation], 0, sizeof (struct invocation)); - - return (0); -} - -static void invocation_destroy_by_data (void *data) -{ - int i; - - for (i = 0; i < invocation_entries_size; i++) { - if (invocation_entries[i].data == data) { - memset (&invocation_entries[i], 0, - sizeof (struct invocation)); - break; - } - } -} - -/** - * Set suspected error flag and report to SU. - * - * @param comp - * @param recommended_recovery - */ -static void report_error_suspected ( - struct amf_comp *comp, - SaAmfRecommendedRecoveryT recommended_recovery) -{ - ENTER ("%s, recommended_recovery = %d", - comp->name.value, recommended_recovery); - amf_comp_error_suspected_set (comp); - comp_recover_action (comp, recommended_recovery); -} - - -#ifndef xprintf -#define xprintf(...) -#endif -static void *clc_command_run (void *context) -{ - struct clc_command_run_data *clc_command_run_data = - (struct clc_command_run_data *)context; - clc_command_run_data->exit_code = 0; - - pid_t pid; - int res; - char **argv = NULL; - char **envp = NULL; - int status; - char path[PATH_MAX]; - char *cmd = 0; - char *comp_argv = 0; - char comp_name[SA_MAX_NAME_LENGTH + 24]; - int i; - int argv_size; - int envp_size; - - ENTER_VOID(); - - pid = fork(); - - if (pid == -1) { - fprintf (stderr, "Couldn't fork process %s\n", strerror (errno)); - return (0); - } - - if (pid) { - xprintf ("waiting for pid %d to finish\n", pid); - waitpid (pid, &status, 0); - if (WIFEXITED (status) != 0 && WEXITSTATUS(status) != 0) { - fprintf (stderr, "Error: CLC_CLI (%d) failed with exit status:" - " %d - %s\n", (int)pid, WEXITSTATUS(status), - strerror (WEXITSTATUS(status))); - /* - * Store the exit code from the script in the return data. - */ - clc_command_run_data->exit_code = WEXITSTATUS(status); - } - if (WIFSIGNALED (status) != 0) { - fprintf (stderr, "Error: CLC_CLI (%d) failed with exit status:" - " %d\n", (int)pid, WTERMSIG(status)); - /* - * TODO: remove this and handle properly later... - */ - - /* - * Healthcheck timout will expire laterfore the component - * and this will lead to Intantiation failed for the component. - */ - - } - xprintf ("process (%d) finished with %x\n", (int)pid, status); - if (clc_command_run_data->completion_callback) { - clc_command_run_data->completion_callback (context); - } - pthread_exit(0); - } - - switch (clc_command_run_data->type) { - case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE: - cmd = clc_command_run_data->comp->saAmfCompInstantiateCmd; - comp_argv = clc_command_run_data->comp->saAmfCompInstantiateCmdArgv; - break; - - case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE: - cmd = clc_command_run_data->comp->saAmfCompTerminateCmd; - comp_argv = clc_command_run_data->comp->saAmfCompTerminateCmdArgv; - break; - - case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP: - cmd = clc_command_run_data->comp->saAmfCompCleanupCmd; - comp_argv = clc_command_run_data->comp->saAmfCompCleanupCmdArgv; - break; - default: - assert (0 != 1); - break; - } - - /* If command is not an absolute path, search for paths in parent objects */ - if (cmd[0] != '/') { - if (clc_command_run_data->comp->clccli_path != NULL) { - sprintf (path, "%s/%s", - clc_command_run_data->comp->clccli_path, cmd); - } else if (clc_command_run_data->comp->su->clccli_path != NULL) { - sprintf (path, "%s/%s", - clc_command_run_data->comp->su->clccli_path, cmd); - } else if (clc_command_run_data->comp->su->sg->clccli_path != NULL) { - sprintf (path, "%s/%s", - clc_command_run_data->comp->su->sg->clccli_path, cmd); - } else if (clc_command_run_data->comp->su->sg->application->clccli_path != NULL) { - sprintf (path, "%s/%s", - clc_command_run_data->comp->su->sg->application->clccli_path, cmd); - } - cmd = path; - } - - argv_size = 2; - argv = amf_malloc (sizeof (char*) * argv_size); - argv[0] = cmd; - { - /* make a proper argv array */ - i = 1; - char *ptrptr; - char *arg = strtok_r(comp_argv, " ", &ptrptr); - while (arg) { - argv_size++; - argv = realloc (argv, sizeof (char*) * argv_size); - if (argv == NULL) { - fprintf (stderr, "out-of-memory"); - exit (-1); - } - argv[i] = arg; - arg = strtok_r(NULL, " ", &ptrptr); - i++; - } - } - argv[i] = NULL; - - i = snprintf (comp_name, SA_MAX_NAME_LENGTH, - "SA_AMF_COMPONENT_NAME=safComp=%s,safSu=%s,safSg=%s,safApp=%s", - clc_command_run_data->comp->name.value, - clc_command_run_data->comp->su->name.value, - clc_command_run_data->comp->su->sg->name.value, - clc_command_run_data->comp->su->sg->application->name.value); - assert (i <= sizeof (comp_name)); - - /* two is for component name and NULL termination */ - envp_size = 2; - envp = amf_malloc (sizeof (char*) * envp_size); - envp[0] = comp_name; - for (i = 1; clc_command_run_data->comp->saAmfCompCmdEnv && - clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; i++) { - envp_size++; - envp = realloc (envp, sizeof (char*) * envp_size); - if (envp == NULL) { - fprintf (stderr, "out-of-memory"); - exit (-1); - } - envp[i] = clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; - } - envp[i] = NULL; - - xprintf ("running command '%s' with environment (%d):\n", cmd, envp_size); - for (i = 0; envp[i] != NULL; i++) { - xprintf (" %s\n", envp[i]); - } - xprintf (" and argv (%d):\n", argv_size); - for (i = 0; argv[i] != NULL; i++) { - xprintf (" %s\n", argv[i]); - } - - res = execve (cmd, argv, envp); - if (res == -1) { - fprintf (stderr, "Couldn't exec program %s (%s)\n", - cmd, strerror (errno)); - } - exit (res); /* abnormal exit of forked process */ - - return (0); -} - -static void amf_comp_instantiate_tmo (void *component) -{ - SaNameT compName; - amf_comp_dn_make (component, &compName); - - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE_TMO, - &compName, sizeof (SaNameT)); -} - -static void amf_comp_cleanup_tmo (void *component) -{ - SaNameT compName; - amf_comp_dn_make (component, &compName); - - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_CLEANUP_TMO, - &compName, sizeof (SaNameT)); -} - -static void start_component_instantiate_timer (struct amf_comp *component) -{ - ENTER("%s",component->name.value); - if (component->instantiate_timeout_handle == 0) { - poll_timer_add (aisexec_poll_handle, - component->saAmfCompInstantiateTimeout, - component, - amf_comp_instantiate_tmo, - &component->instantiate_timeout_handle); - } -} - -static void start_component_cleanup_timer (struct amf_comp *component) -{ - ENTER("%s",component->name.value); - if (component->cleanup_timeout_handle == 0) { - poll_timer_add (aisexec_poll_handle, - component->saAmfCompCleanupTimeout, - component, - amf_comp_cleanup_tmo, - &component->cleanup_timeout_handle); - } -} - -void stop_component_cleanup_timer (struct amf_comp *component) -{ - ENTER("%s",component->name.value); - - if (component->cleanup_timeout_handle != 0) { - poll_timer_delete (aisexec_poll_handle, - component->cleanup_timeout_handle); - component->cleanup_timeout_handle = 0; - } -} - -/* - * Instantiate possible operations - */ -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; - - ENTER("comp '%s'\n", getSaNameT (&comp->name)); - - clc_command_run_data = amf_malloc (sizeof (struct clc_command_run_data)); - clc_command_run_data->comp = comp; - clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE; - clc_command_run_data->completion_callback = NULL; - 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); - } - start_component_instantiate_timer (comp); - return (res); -} - -static int clc_instantiate_callback (struct amf_comp *comp) -{ - ENTER("comp %s\n", getSaNameT (&comp->name)); - return (0); -} - -static int clc_csi_set_callback (struct amf_comp *comp) -{ - ENTER("comp %s\n", getSaNameT (&comp->name)); - return (0); -} - -/* - * Terminate possible operations - */ -static int clc_cli_terminate (struct amf_comp *comp) -{ - ENTER("comp %s\n", getSaNameT (&comp->name)); - return (0); -} - -/** - * Request component to terminate itself - * @param comp - * - * @return int - */ -static int lib_comp_terminate_request (struct amf_comp *comp) -{ - struct res_lib_amf_componentterminatecallback res_lib; - struct component_terminate_callback_data *component_terminate_callback_data; - - ENTER("comp %s\n", getSaNameT (&comp->name)); - - res_lib.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK; - res_lib.header.size = sizeof (struct res_lib_amf_componentterminatecallback); - res_lib.header.error = SA_AIS_OK; - - memcpy (&res_lib.compName, &comp->name, sizeof (SaNameT)); - - component_terminate_callback_data = - amf_malloc (sizeof (struct component_terminate_callback_data)); - component_terminate_callback_data->comp = comp; - - res_lib.invocation = - invocation_create ( - AMF_RESPONSE_COMPONENTTERMINATECALLBACK, - component_terminate_callback_data); - - openais_conn_send_response ( - openais_conn_partner_get (comp->conn), - &res_lib, - sizeof (struct res_lib_amf_componentterminatecallback)); - - return (0); -} - -static int clc_csi_remove_callback (struct amf_comp *comp) -{ - dprintf ("clc_tcsi_remove_callback\n"); - return (0); -} - -/* - * Clean up completed - */ -static void mcast_cleanup_completion_event (void *context) -{ - struct clc_command_run_data *clc_command_run_data = - (struct clc_command_run_data *)context; - struct req_exec_amf_clc_cleanup_completed req; - struct iovec iovec; - req.header.size = sizeof (struct req_exec_amf_clc_cleanup_completed); - req.header.id = SERVICE_ID_MAKE (AMF_SERVICE, - MESSAGE_REQ_EXEC_AMF_CLC_CLEANUP_COMPLETED); - - amf_comp_dn_make (clc_command_run_data->comp, &req.compName); - iovec.iov_base = (char *)&req; - iovec.iov_len = sizeof (req); - - /* - * Exit code from the invoked cleanup script. - */ - req.cleanup_exit_code = clc_command_run_data->exit_code; - - assert (totempg_groups_mcast_joined (openais_group_handle, - &iovec, 1, TOTEMPG_AGREED) == 0); -} - -/* - * Cleanup possible operations - */ -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; - - dprintf ("clc_cli_cleanup\n"); - clc_command_run_data = amf_malloc (sizeof (struct clc_command_run_data)); - clc_command_run_data->comp = comp; - clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP; - clc_command_run_data->completion_callback = mcast_cleanup_completion_event; - start_component_cleanup_timer (comp); - 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); -} - -static int clc_cli_cleanup_local (struct amf_comp *comp) -{ - dprintf ("clc_cli_cleanup_local\n"); - return (0); -} - -#if 0 -static int clc_terminate (struct amf_comp *comp) -{ - int res; - - dprintf ("clc terminate for comp %s\n", getSaNameT (&comp->name)); - assert (0); - comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING); - operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED); - - res = clc_interfaces[comp->comptype]->terminate (comp); - return (0); -} -#endif - -char *amf_comp_dn_make (struct amf_comp *comp, SaNameT *name) -{ - int i = snprintf ((char*) name->value, SA_MAX_NAME_LENGTH, - "safComp=%s,safSu=%s,safSg=%s,safApp=%s", - comp->name.value, comp->su->name.value, - comp->su->sg->name.value, comp->su->sg->application->name.value); - assert (i <= SA_MAX_NAME_LENGTH); - name->length = i; - return (char *)name->value; -} - -struct amf_healthcheck *amf_comp_find_healthcheck ( - struct amf_comp *comp, SaAmfHealthcheckKeyT *key) -{ - struct amf_healthcheck *healthcheck; - struct amf_healthcheck *ret_healthcheck = 0; - - if (key == NULL) { - return NULL; - } - - for (healthcheck = comp->healthcheck_head; - healthcheck != NULL; - healthcheck = healthcheck->next) { - - if (key->keyLen == healthcheck->safHealthcheckKey.keyLen && - memcmp (key, &healthcheck->safHealthcheckKey,key->keyLen) == 0) { - ret_healthcheck = healthcheck; - break; - } - } - - return (ret_healthcheck); -} - -/** - * Constructor for component objects. Adds component last in - * the list owned by the specified SU. Always returns a - * valid comp object, out-of-memory problems are handled - * here. Default values are initialized. - * @param su - * @param name - * - * @return struct amf_comp* - */ -struct amf_comp *amf_comp_new(struct amf_su *su, char *name) -{ - struct amf_comp *tail = su->comp_head; - struct amf_comp *comp = amf_calloc (1, sizeof (struct amf_comp)); - - while (tail != NULL) { - if (tail->next == NULL) { - break; - } - tail = tail->next; - } - - if (tail == NULL) { - su->comp_head = comp; - } else { - tail->next = comp; - } - comp->su = su; - - /* setup default values from spec. */ - comp->saAmfCompNumMaxInstantiateWithoutDelay = 2; - comp->saAmfCompNumMaxAmStartAttempt = 2; - comp->saAmfCompNumMaxAmStopAttempt = 2; - - comp->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED; - comp->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED; - amf_comp_error_suspected_clear (comp); - setSaNameT (&comp->name, name); - comp->instantiate_timeout_handle = 0; - comp->cleanup_timeout_handle = 0; - list_init(&comp->pm_head); - return comp; -} - -void amf_comp_delete (struct amf_comp *comp) -{ - int i; - struct amf_healthcheck *healthcheck; - - for (healthcheck = comp->healthcheck_head; healthcheck != NULL;) { - struct amf_healthcheck *tmp = healthcheck; - healthcheck = healthcheck->next; - free (tmp); - } - - for (i = 0; comp->saAmfCompCsTypes[i] != NULL; i++) { - free (comp->saAmfCompCsTypes[i]); - } - for (i = 0; comp->saAmfCompCmdEnv[i] != NULL; i++) { - free (comp->saAmfCompCmdEnv[i]); - } - - free (comp->saAmfCompInstantiateCmd); - free (comp->saAmfCompInstantiateCmdArgv); - free (comp->saAmfCompTerminateCmd); - free (comp->saAmfCompTerminateCmdArgv); - free (comp->saAmfCompCleanupCmd); - free (comp->saAmfCompCleanupCmdArgv); - free (comp->saAmfCompAmStartCmd); - free (comp->saAmfCompAmStartCmdArgv); - free (comp->saAmfCompAmStopCmd); - free (comp->saAmfCompAmStopCmdArgv); - free (comp->clccli_path); - - free (comp); -} - -struct amf_comp *amf_comp_find_from_conn_info (void *conn) -{ - struct amf_application *app; - struct amf_sg *sg; - struct amf_su *su; - struct amf_comp *comp = NULL; - - for (app = amf_cluster->application_head; app != NULL; app = app->next) { - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - if (comp->conn == conn) { - goto end; - } - } - } - } - } -end: - return comp; -} - -struct amf_comp *amf_comp_find (struct amf_cluster *cluster, SaNameT *name) -{ - struct amf_application *app; - struct amf_sg *sg; - struct amf_su *su; - struct amf_comp *comp = NULL; - char *app_name; - char *sg_name; - char *su_name; - char *comp_name; - char *ptrptr; - char *buf; - - assert (cluster != NULL && name != NULL); - - /* malloc new buffer since strtok_r writes to its first argument */ - buf = amf_malloc (name->length + 1); - memcpy (buf, name->value,name ->length + 1); - - comp_name = strtok_r(buf, ",", &ptrptr); - su_name = strtok_r(NULL, ",", &ptrptr); - sg_name = strtok_r(NULL, ",", &ptrptr); - app_name = strtok_r(NULL, ",", &ptrptr); - - if (comp_name == NULL || su_name == NULL || - sg_name == NULL || app_name == NULL) { - goto end; - } - - comp_name += 8; - su_name += 6; - sg_name += 6; - app_name += 7; - - app = amf_application_find (cluster, app_name); - if (app == NULL) { - goto end; - } - - sg = amf_sg_find (app, sg_name); - if (sg == NULL) { - goto end; - } - - for (su = sg->su_head; su != NULL; su = su->next) { - if (strncmp (su_name, (char*)su->name.value, su->name.length) == 0) { - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - if (comp->name.length == strlen(comp_name) && - strncmp (comp_name, (char*)comp->name.value, - comp->name.length) == 0) { - goto end; - } - } - } - } - -end: - free (buf); - return comp; -} - -void amf_comp_healthcheck_deactivate (struct amf_comp *comp) -{ - struct amf_healthcheck *healthcheck; - - if (!amf_su_is_local (comp->su)) - return; - - ENTER ("'%s'\n", getSaNameT (&comp->name)); - - for (healthcheck = comp->healthcheck_head; - healthcheck != NULL; - healthcheck = healthcheck->next) { - - if (healthcheck->active) { - healthcheck_deactivate (healthcheck); - } - } -} - -static void comp_ha_state_set ( struct amf_comp *comp, - struct amf_csi_assignment *csi_assignment, - SaAmfHAStateT ha_state) -{ - /* set confirmed HA state */ - csi_assignment->saAmfCSICompHAState = ha_state; - TRACE1 ("Setting comp '%s', SU '%s' CSI '%s', HA state: %s\n", - comp->name.value, comp->su->name.value, - csi_assignment->csi->name.value, - amf_ha_state (csi_assignment->saAmfCSICompHAState)); - amf_si_comp_set_ha_state_done (csi_assignment->csi->si, csi_assignment); -} - -static void comp_presence_state_set (struct amf_comp *comp, - SaAmfPresenceStateT presence_state) -{ - comp->saAmfCompPresenceState = presence_state; - TRACE1 ("Setting comp '%s', SU '%s' presence state: %s\n", - comp->name.value, comp->su->name.value, - amf_presence_state (comp->saAmfCompPresenceState)); - - amf_su_comp_state_changed ( - comp->su, comp, SA_AMF_PRESENCE_STATE, presence_state); -} - -struct amf_csi_assignment *amf_comp_get_next_csi_assignment ( - struct amf_comp *component, - const struct amf_csi_assignment *csi_assignment) -{ - struct amf_si *si; - struct amf_csi *csi; - struct amf_csi_assignment *tmp_csi_assignment; - SaNameT dn; - - amf_comp_dn_make (component, &dn); - - if (csi_assignment == NULL) { - si = component->su->sg->application->si_head; - csi = si->csi_head; - tmp_csi_assignment = csi->assigned_csis; - } else { - tmp_csi_assignment = csi_assignment->next; - if (tmp_csi_assignment == NULL) { - csi = csi_assignment->csi->next; - if (csi == NULL) { - si = csi_assignment->csi->si->next; - if (si == NULL) { - return NULL; - } else { - csi = si->csi_head; - tmp_csi_assignment = csi->assigned_csis; - } - } else { - si = csi->si; - tmp_csi_assignment = csi->assigned_csis; - } - } else { - csi = tmp_csi_assignment->csi; - si = csi->si; - } - } - - for (; si != NULL; si = si->next) { - if (tmp_csi_assignment == NULL && csi == NULL && si != NULL) { - csi = si->csi_head; - tmp_csi_assignment = csi->assigned_csis; - } - - for (; csi != NULL; csi = csi->next) { - if (tmp_csi_assignment == NULL && csi != NULL) { - tmp_csi_assignment = csi->assigned_csis; - } - - for (; tmp_csi_assignment != NULL; - tmp_csi_assignment = tmp_csi_assignment->next) { - - if (name_match (&tmp_csi_assignment->name, &dn)) { - return tmp_csi_assignment; - } - } - } - } - - return NULL; -} - -void amf_comp_foreach_csi_assignment ( - struct amf_comp *component, - void (*foreach_fn) (struct amf_comp *component, - struct amf_csi_assignment *csi_assignment)) -{ - struct amf_csi_assignment *csi_assignment; - - assert (foreach_fn != NULL); - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (csi_assignment != NULL) { - foreach_fn (component, csi_assignment); - csi_assignment = amf_comp_get_next_csi_assignment ( - component, csi_assignment); - } -} - -static struct amf_csi_assignment *csi_assignment_find_in ( - struct amf_comp *component, SaNameT *csi_name) -{ - struct amf_csi_assignment *csi_assignment; - SaNameT dn; - - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (csi_assignment != NULL) { - amf_csi_dn_make (csi_assignment->csi, &dn); - if (name_match (csi_name, &dn)) { - return csi_assignment; - } - csi_assignment = amf_comp_get_next_csi_assignment ( - component, csi_assignment); - } - - return NULL; -} - -static void healthcheck_deactivate ( - struct amf_healthcheck *healthcheck_active) -{ - dprintf ("deactivating healthcheck for component %s\n", - getSaNameT (&healthcheck_active->comp->name)); - - poll_timer_delete (aisexec_poll_handle, - healthcheck_active->timer_handle_period); - poll_timer_delete (aisexec_poll_handle, - healthcheck_active->timer_handle_duration); - - invocation_destroy_by_data ((void *)healthcheck_active); - healthcheck_active->active = 0; -} - -/** - * This function is called by the timer subsystem when AMF should request - * a new healthcheck from a component. - * @param data - */ -static void timer_function_healthcheck_next_fn (void *_healthcheck) -{ - struct amf_healthcheck *healthcheck = _healthcheck; - - /* send healthcheck request to component */ - lib_healthcheck_request (healthcheck); - - /* start duration timer for response */ - poll_timer_add (aisexec_poll_handle, - healthcheck->saAmfHealthcheckMaxDuration, - (void *)healthcheck, - timer_function_healthcheck_tmo, - &healthcheck->timer_handle_duration); -} - -/** - * Multicast a healthcheck timeout event. - * @param healthcheck - */ -static void mcast_healthcheck_tmo_event ( - struct amf_healthcheck *healthcheck) -{ - struct req_exec_amf_healthcheck_tmo req_exec; - struct iovec iovec; - if (healthcheck->active == 0) { - log_printf (LOG_ERR, "Healthcheck timeout: ignored key = %s, " - "due to wrong state = %d, comp = %s", - healthcheck->safHealthcheckKey.key, - healthcheck->comp->saAmfCompPresenceState, - healthcheck->comp->name.value); - goto out; - } - req_exec.header.size = sizeof (struct req_exec_amf_healthcheck_tmo); - req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE, - MESSAGE_REQ_EXEC_AMF_HEALTHCHECK_TMO); - - amf_comp_dn_make (healthcheck->comp, &req_exec.compName); - memcpy (&req_exec.safHealthcheckKey, - &healthcheck->safHealthcheckKey, sizeof (SaAmfHealthcheckKeyT)); - req_exec.recommendedRecovery = healthcheck->recommendedRecovery; - iovec.iov_base = (char *)&req_exec; - iovec.iov_len = sizeof (req_exec); - - assert (totempg_groups_mcast_joined (openais_group_handle, - &iovec, 1, TOTEMPG_AGREED) == 0); -out: - return; -} - -/** - * This function is called by the timer subsystem when a component has not - * performed a healthcheck on time. - * The event is multicasted to the cluster. - * @param data - */ -static void timer_function_healthcheck_tmo ( - void *_healthcheck) -{ - struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)_healthcheck; - - TRACE2 ("timeout occured on healthcheck for component %s.\n", - getSaNameT (&healthcheck->comp->name)); - - mcast_healthcheck_tmo_event (healthcheck); -} - -static void lib_healthcheck_request (struct amf_healthcheck *healthcheck) -{ - struct res_lib_amf_healthcheckcallback res_lib; - - res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK; - res_lib.header.size = sizeof (struct res_lib_amf_healthcheckcallback); - res_lib.header.error = SA_AIS_OK; - res_lib.invocation = - invocation_create (AMF_RESPONSE_HEALTHCHECKCALLBACK, healthcheck); - - amf_comp_dn_make (healthcheck->comp, &res_lib.compName); - memcpy (&res_lib.key, &healthcheck->safHealthcheckKey, - sizeof (SaAmfHealthcheckKeyT)); - - TRACE7 ("sending healthcheck request to component %s", - res_lib.compName.value); - openais_conn_send_response ( - openais_conn_partner_get (healthcheck->comp->conn), - &res_lib, sizeof (struct res_lib_amf_healthcheckcallback)); -} - -static void lib_csi_set_request ( - struct amf_comp *comp, - struct amf_csi_assignment *csi_assignment) -{ - struct res_lib_amf_csisetcallback* res_lib; - void* p; - struct amf_csi_attribute *attribute; - size_t char_length_of_csi_attrs=0; - size_t num_of_csi_attrs=0; - int i; - struct amf_csi *csi; - char* csi_attribute_buf; - unsigned int byte_offset; - - if (!amf_su_is_local (comp->su)) - return; - - csi = csi_assignment->csi; - - ENTER ("Assigning CSI '%s' state %s to comp '%s'\n", - getSaNameT (&csi->name), - amf_ha_state (csi_assignment->requested_ha_state), - comp->name.value); - - 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 = amf_malloc(sizeof(struct res_lib_amf_csisetcallback) + - char_length_of_csi_attrs); - res_lib = (struct res_lib_amf_csisetcallback*)p; - - /* Address of the buffer containing the Csi name value pair */ - csi_attribute_buf = res_lib->csi_attr_buf; - - /* Byteoffset start at the zero byte */ - 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; - } - } - - res_lib->number = num_of_csi_attrs; - res_lib->csiFlags = SA_AMF_CSI_ADD_ONE; - - switch (csi_assignment->requested_ha_state) { - case SA_AMF_HA_ACTIVE: { - res_lib->csiStateDescriptor.activeDescriptor.activeCompName.length = 0; - res_lib->csiStateDescriptor.activeDescriptor.transitionDescriptor = - SA_AMF_CSI_NEW_ASSIGN; - break; - } - case SA_AMF_HA_STANDBY: { - res_lib->csiStateDescriptor.standbyDescriptor.activeCompName.length = 0; - res_lib->csiStateDescriptor.standbyDescriptor.standbyRank = 1; - break; - } - case SA_AMF_HA_QUIESCED: { - /*TODO*/ - break; - } - case SA_AMF_HA_QUIESCING: { - /*TODO*/ - break; - } - default: { - assert(SA_AMF_HA_ACTIVE||SA_AMF_HA_STANDBY||SA_AMF_HA_QUIESCING||SA_AMF_HA_QUIESCED); - break; - } - } - - res_lib->header.id = MESSAGE_RES_AMF_CSISETCALLBACK; - res_lib->header.size = - sizeof (struct res_lib_amf_csisetcallback) + - char_length_of_csi_attrs; - res_lib->header.error = SA_AIS_OK; - - amf_comp_dn_make (comp, &res_lib->compName); - amf_csi_dn_make (csi, &res_lib->csiName); - - res_lib->haState = csi_assignment->requested_ha_state; - res_lib->invocation = - invocation_create (AMF_RESPONSE_CSISETCALLBACK, csi_assignment); - openais_conn_send_response ( - openais_conn_partner_get (comp->conn), res_lib, res_lib->header.size); - - free(p); -} - -static void stop_component_instantiate_timer (struct amf_comp *component) -{ - ENTER("%s",component->name.value); - - if (component->instantiate_timeout_handle) { - dprintf ("Stop component instantiate timer"); - poll_timer_delete (aisexec_poll_handle, - component->instantiate_timeout_handle); - component->instantiate_timeout_handle = 0; - } -} - -SaAisErrorT amf_comp_register (struct amf_comp *comp) -{ - TRACE2("Exec comp register '%s'", comp->name.value); - stop_component_instantiate_timer (comp); - - switch (comp->saAmfCompPresenceState) { - case SA_AMF_PRESENCE_RESTARTING: - comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED); - break; - case SA_AMF_PRESENCE_INSTANTIATING: - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_ENABLED); - comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED); - break; - case SA_AMF_PRESENCE_INSTANTIATION_FAILED: - /* ignore due to instantitate timeout a while ago */ - break; - default: - log_printf(LOG_LEVEL_ERROR,"comp->saAmfCompPresenceState = %d", - comp->saAmfCompPresenceState); - assert (0); - break; - - } - - return SA_AIS_OK; -} - -void amf_comp_error_report (struct amf_comp *comp, amf_comp_t* reporting_comp, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct res_lib_amf_componenterrorreport res_lib; - - if (reporting_comp != NULL) { - TRACE2("Exec comp error report on comp'%s' from %s", comp->name.value, - reporting_comp->name.value ); - - if (amf_su_is_local (reporting_comp->su)) { - res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport); - res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT; - res_lib.header.error = SA_AIS_OK; - openais_conn_send_response (reporting_comp->conn, &res_lib, sizeof (res_lib)); - } - } else { - TRACE2("Exec comp error report on comp'%s' from AMF", comp->name.value); - } - - /* Report to SU and let it handle the problem */ - report_error_suspected (comp, recommendedRecovery); -} - -/** - * Healthcheck timeout event handler - * @param comp - * @param healthcheck - */ -void amf_comp_healthcheck_tmo ( - struct amf_comp *comp, SaAmfRecommendedRecoveryT recommendedRecovery) -{ - TRACE2("Exec healthcheck tmo for '%s'", comp->name.value); - - /* report to SU and let it handle the problem */ - report_error_suspected (comp, recommendedRecovery); -} - -static void clear_ha_state ( - struct amf_comp *comp, struct amf_csi_assignment *csi_assignment) -{ - ENTER (""); - csi_assignment->saAmfCSICompHAState = 0; -} - - -static void comp_recover_action (amf_comp_t *comp, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - - - ENTER ("%s %d %d", comp->name.value,recommendedRecovery, - comp->saAmfCompRecoveryOnError); - - amf_node_t *node = amf_node_find (&comp->su->saAmfSUHostedByNode); - switch (recommendedRecovery) { - case SA_AMF_NO_RECOMMENDATION: { - /* - * If the recommendation was SA_AMF_NO_RECOMMENDATION, - * then use the configured recovery action for the component - */ - switch (comp->saAmfCompRecoveryOnError) { - case SA_AMF_NO_RECOMMENDATION: - if (comp->saAmfCompDisableRestart) { - /* Comp or SU failover */ - amf_node_comp_failover_req (node, comp); - } else { - /* Component restart */ - amf_su_comp_error_suspected (comp->su, comp, - recommendedRecovery); - } - case SA_AMF_COMPONENT_RESTART: - if (comp->saAmfCompDisableRestart) { - /* Comp or SU failover */ - amf_node_comp_failover_req (node, comp); - } else { - /* Component restart */ - amf_su_comp_error_suspected (comp->su, comp, - recommendedRecovery); - } - break; - case SA_AMF_COMPONENT_FAILOVER: - /* SU failover */ - amf_node_comp_failover_req (node, comp); - break; - case SA_AMF_NODE_SWITCHOVER: - break; - case SA_AMF_NODE_FAILOVER: { - /* Node failover */ - amf_node_t *node = amf_node_find ( - &comp->su->saAmfSUHostedByNode); - amf_node_failover(node); - } - break; - case SA_AMF_NODE_FAILFAST: - break; - case SA_AMF_CLUSTER_RESET: - break; - case SA_AMF_APPLICATION_RESTART: - default: - dprintf("recommendedRecovery=%d",recommendedRecovery); - assert (0); - break; - } - break; - } - case SA_AMF_COMPONENT_RESTART: - if (comp->saAmfCompDisableRestart == SA_TRUE) { - amf_node_comp_failover_req (node, comp); - } else { - amf_su_comp_error_suspected (comp->su, comp, recommendedRecovery); - } - break; - case SA_AMF_COMPONENT_FAILOVER: - amf_node_comp_failover_req (node, comp); - break; - case SA_AMF_NODE_SWITCHOVER: - break; - case SA_AMF_NODE_FAILOVER: - /* Node failover */ - amf_node_failover (amf_node_find (&comp->su->saAmfSUHostedByNode)); - break; - case SA_AMF_NODE_FAILFAST: - break; - case SA_AMF_CLUSTER_RESET: - break; - case SA_AMF_APPLICATION_RESTART: - default: - assert (0); - break; - - } -} - -/** - * Event method to be called when a cleanup completed event is received - * with failure. - * @param comp - */ -void amf_comp_cleanup_failed_completed (amf_comp_t *comp) -{ - ENTER ("'%s'", comp->name.value); - - stop_component_cleanup_timer (comp); - amf_comp_error_suspected_clear (comp); - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED); - comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATION_FAILED); -} - -/** - * Event method to be called when a cleanup completed event is received - * @param comp - */ -void amf_comp_cleanup_completed (struct amf_comp *comp) -{ - TRACE2("Exec CLC cleanup completed for '%s' %d", comp->name.value, - comp->saAmfCompPresenceState); - - stop_component_cleanup_timer (comp); - - - /* Set all CSI's confirmed HA state to unknown */ - amf_comp_foreach_csi_assignment (comp, clear_ha_state); - - amf_comp_error_suspected_clear (comp); - - if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) { - amf_comp_instantiate (comp); - } else if (comp->saAmfCompPresenceState == - SA_AMF_PRESENCE_TERMINATION_FAILED) { - comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATION_FAILED); - } else { - comp_presence_state_set (comp, SA_AMF_PRESENCE_UNINSTANTIATED); - } -} - -/** - * go through the pids for this component and - * check the existence of of /proc//stat - */ -static void timer_function_pm_fn (void *data) -{ - struct amf_comp *comp = (struct amf_comp *)data; - struct amf_pm *pm = NULL; - struct list_head *pmlist = NULL; - struct list_head *next = NULL; - SaBoolT reported = SA_FALSE; - char f[30]; - - assert (comp); - /* we are going to ignore the pmErrors - * and only check to see if the process exists. - */ - for (pmlist = comp->pm_head.next; - pmlist != &comp->pm_head; - pmlist = next) { - - pm = list_entry(pmlist,struct amf_pm,entry); - next = pmlist->next; - - if (pm->errors == 0) { - list_del(pmlist); - free(pm); - continue; - } - sprintf(f,"/proc/%llu/stat", pm->pid); - if (access( f, R_OK) != 0) { - if ((comp->su->restart_control_state != SU_RC_RESTART_SU_DEACTIVATING) && - (comp->su->restart_control_state != SU_RC_RESTART_SU_TERMINATING) && - (reported == SA_FALSE)) { - - /* don't report it as an error if we are busy - * shutting down - */ - syslog(LOG_ALERT, "component %s:%s exited", - comp->su->saAmfSUHostedByNode.value, comp->name.value); - mcast_error_report_from_pm (comp, pm->recovery); - reported = SA_TRUE; - } - list_del(pmlist); - free(pm); - break; - } - } - - if (!list_empty(&comp->pm_head)) { - pm = list_entry(comp->pm_head.next,struct amf_pm,entry); - poll_timer_add (aisexec_poll_handle, - 500, - (void *)comp, - timer_function_pm_fn, - &pm->timer_handle_period); - } -} - -/** - * Find and add all children of a given PID - * @param comp the component - * @param pmErrors the errors to monitor - * @param recommendedRecovery - * @param dirList list of files in proc filesystem - * @param numProcEntriesFound number of file entries in proc filesystem - * @param ppid the process id to find children of - * @param depth the descendents tree depth to monitor - */ -void amf_comp_find_and_add_child_pids( - struct amf_comp *comp, - SaAmfPmErrorsT pmErrors, - SaAmfRecommendedRecoveryT recommendedRecovery, - struct dirent **dirList, - SaInt32T numProcEntriesFound, - SaUint64T ppid, - SaInt32T depth) -{ - SaUint64T parent; - SaUint64T p_id; - SaInt32T res; - SaInt32T n = numProcEntriesFound; - char f[30]; - FILE *p; - struct amf_pm *pm = NULL; - - while (n--) { - - sprintf(f, "/proc/%s/stat", dirList[n]->d_name); - - p = fopen(f, "r"); - if (p == NULL) - continue; - - res = fscanf(p, "%llu %*s %*c %llu", &p_id, &parent); - - if ((res == 2) && (parent == ppid)) { - - pm = amf_calloc(1, sizeof(struct amf_pm)); - if ( pm == NULL ) { - return; - } - - TRACE2 ("add child (pid=%llu) for comp pid=%llu (%s)\n", p_id, ppid, comp->name.value); - - pm->pid = p_id; - pm->errors = pmErrors; - pm->recovery = recommendedRecovery; - pm->timer_handle_period = 0; - - list_add(&pm->entry, &comp->pm_head); - - if (depth > 1) { - amf_comp_find_and_add_child_pids(comp, - pmErrors, - recommendedRecovery, - dirList, - numProcEntriesFound, - p_id, - depth - 1); - } - } - fclose(p); - } -} - -/** - * Handle the request to start passive monitoring - * - * @param comp the component - * @param pid the process id to monitor - * @param depth the descendents tree depth to monitor - * @param pmErrors the errors to monitor - * @param recommendedRecovery - * - * @return SaAisErrorT - */ -SaAisErrorT amf_comp_pm_start ( - struct amf_comp *comp, - SaUint64T pid, - SaInt32T depth, - SaAmfPmErrorsT pmErrors, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct amf_pm *pm = NULL; - struct list_head *pmlist = NULL; - struct dirent **dirList; - SaInt32T numProcEntriesFound; - - if (is_not_instantiating_or_instantiated_or_restarting (comp)) { - log_printf (LOG_ERR, "PmStart: ignored due to wrong state = %d, comp = %s", - comp->saAmfCompPresenceState, comp->name.value); - return SA_AIS_ERR_FAILED_OPERATION; - } - - /* try and find one thats already there, and mod it */ - - for (pmlist = comp->pm_head.next; - pmlist != &comp->pm_head; - pmlist = pmlist->next) { - - pm = list_entry(pmlist,struct amf_pm,entry); - - if (pm->pid == pid) { - break; - } - } - if ( pm == NULL ) { - /* not found, create it */ - pm = amf_calloc(1, sizeof(struct amf_pm)); - if ( pm == NULL ) { - return SA_AIS_ERR_NO_MEMORY; - } - - pm->pid = pid; - pm->errors = pmErrors; - pm->recovery = recommendedRecovery; - pm->timer_handle_period = 0; - - if ( list_empty(&comp->pm_head)) { - /* only add a timer per comp */ - /* TODO: should this timer period be a define or a config option? - */ - poll_timer_add (aisexec_poll_handle, - 500, - (void *)comp, - timer_function_pm_fn, - &pm->timer_handle_period); - - } - list_add(&pm->entry, &comp->pm_head); - - numProcEntriesFound = scandir("/proc/", &dirList, 0, alphasort); - if (numProcEntriesFound < 0) { - perror("scandir"); - return -2; - } - - amf_comp_find_and_add_child_pids(comp, - pmErrors, - recommendedRecovery, - dirList, - numProcEntriesFound, - pid, - depth); - - free(dirList); - - - } else { - /* only esculate the checking */ - pm->errors |= pmErrors; - - if (pm->recovery < recommendedRecovery) { - pm->recovery = recommendedRecovery; - } - } - - return SA_AIS_OK; -} - -/** - * Handle the request to stop passive monitoring on - * a component (or part of it) - * - * @param comp the component - * @param stopQualifier what processes to stop - * @param pid the process id to monitor - * @param pmErrors the errors to monitor - * - * @return SaAisErrorT - return value to component - */ -SaAisErrorT amf_comp_pm_stop ( - struct amf_comp *comp, - SaAmfPmStopQualifierT stopQualifier, - SaInt64T pid, - SaAmfPmErrorsT pmErrors) -{ - struct amf_pm *pm = NULL; - struct list_head *pmlist = NULL; - - for (pmlist = comp->pm_head.next; pmlist != &comp->pm_head; pmlist = pmlist->next) { - - pm = list_entry(pmlist,struct amf_pm,entry); - - if ((pm->pid == pid) || - ( stopQualifier == SA_AMF_PM_ALL_PROCESSES)) { - /* remove the error to check */ - pm->errors &= ~pmErrors; - } - } - return SA_AIS_OK; -} - - -/** - * Handle the request from a component to start a healthcheck - * - * @param comp - * @param healthcheckKey - * @param invocationType - * @param recommendedRecovery - * - * @return SaAisErrorT - return value to component - */ -SaAisErrorT amf_comp_healthcheck_start ( - struct amf_comp *comp, - SaAmfHealthcheckKeyT *healthcheckKey, - SaAmfHealthcheckInvocationT invocationType, - SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct amf_healthcheck *healthcheck; - SaAisErrorT error = SA_AIS_OK; - - if (is_not_instantiating_or_instantiated_or_restarting (comp)) { - log_printf (LOG_ERR, "Healthcheckstart: ignored key = %s, " - "due to wrong state = %d, comp = %s", - healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value); - error = SA_AIS_OK; - goto error_exit; - } - - - healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey); - if (healthcheck == 0) { - log_printf (LOG_ERR, "Healthcheckstart: Healthcheck '%s' not found", - healthcheckKey->key); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - dprintf ("Healthcheckstart: '%s', key '%s'", - comp->name.value, healthcheckKey->key); - - /* - * Determine if this healthcheck is already active - */ - if (healthcheck->active) { - error = SA_AIS_ERR_EXIST; - goto error_exit; - } - - /* - * Initialise - */ - healthcheck->invocationType = invocationType; - healthcheck->recommendedRecovery = recommendedRecovery; - healthcheck->timer_handle_duration = 0; - healthcheck->timer_handle_period = 0; - healthcheck->active = 1; - - if (invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) { - /* start timer to execute first healthcheck request */ - poll_timer_add (aisexec_poll_handle, - healthcheck->saAmfHealthcheckPeriod, - (void *)healthcheck, - timer_function_healthcheck_next_fn, - &healthcheck->timer_handle_period); - } else if (invocationType == SA_AMF_HEALTHCHECK_COMPONENT_INVOKED) { - /* start supervision timer */ - poll_timer_add (aisexec_poll_handle, - healthcheck->saAmfHealthcheckPeriod, - (void *)healthcheck, - timer_function_healthcheck_tmo, - &healthcheck->timer_handle_period); - } else { - error = SA_AIS_ERR_INVALID_PARAM; - } - -error_exit: - return error; -} - -/** - * Stop all or a specifed healthcheck - * @param comp - * @param healthcheckKey - NULL if all - * - * @return SaAisErrorT - */ -SaAisErrorT amf_comp_healthcheck_stop ( - struct amf_comp *comp, - SaAmfHealthcheckKeyT *healthcheckKey) -{ - struct amf_healthcheck *healthcheck; - SaAisErrorT error = SA_AIS_OK; - - dprintf ("Healthcheckstop: '%s'", comp->name.value); - - if (!amf_su_is_local (comp->su)) { - return SA_AIS_OK; - } - - if (healthcheckKey == NULL) { - for (healthcheck = comp->healthcheck_head; - healthcheck != NULL; - healthcheck = healthcheck->next) { - healthcheck_deactivate (healthcheck); - } - } else { - healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey); - if (healthcheck == NULL) { - log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found", - healthcheckKey->key); - error = SA_AIS_ERR_NOT_EXIST; - } else { - healthcheck_deactivate (healthcheck); - } - } - - return error; -} - -/** - * Instantiate a component - * @param comp - */ -void amf_comp_instantiate (struct amf_comp *comp) -{ - ENTER ("'%s' SU '%s'", getSaNameT (&comp->name), - getSaNameT (&comp->su->name)); - - switch (comp->saAmfCompPresenceState) { - case SA_AMF_PRESENCE_RESTARTING: - /* fall through */ - case SA_AMF_PRESENCE_UNINSTANTIATED: - if (amf_su_is_local (comp->su)) { - TRACE1("Send instantiate event for comp '%s' from host %s", - comp->name.value, comp->su->saAmfSUHostedByNode.value); - SaNameT compName; - amf_comp_dn_make (comp, &compName); - amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE, - &compName, sizeof (SaNameT)); - } - break; - default: - dprintf("Instantiate ignored in Component presence state %d", - comp->saAmfCompPresenceState); - break; - } -} - -void amf_comp_cleanup_tmo_event (struct amf_comp *comp) -{ - ENTER ("Comp cleanup timeout after %d ms '%s' '%s'", - comp->saAmfCompCleanupTimeout, comp->su->name.value, - comp->name.value); - amf_comp_error_suspected_clear(comp); - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED); - comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATION_FAILED); -} - -void amf_comp_instantiate_tmo_event (struct amf_comp *comp) -{ - ENTER ("Comp instantiate timeout after %d ms '%s' '%s'", - comp->saAmfCompInstantiateTimeout, comp->su->name.value, - comp->name.value); - - switch (comp->saAmfCompPresenceState) { - case SA_AMF_PRESENCE_RESTARTING: - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED); - comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED); - - break; - case SA_AMF_PRESENCE_INSTANTIATING: - - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED); - comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED); - break; - case SA_AMF_PRESENCE_INSTANTIATED: - assert (comp->instantiate_timeout_handle == 0); - break; - default: - dprintf("Presence state = %d", comp->saAmfCompPresenceState); - assert (0); - break; - } -} - -void amf_comp_instantiate_event (struct amf_comp *component) -{ - int res; - ENTER (""); - switch (component->saAmfCompPresenceState) { - case SA_AMF_PRESENCE_INSTANTIATING: - case SA_AMF_PRESENCE_INSTANTIATED: - case SA_AMF_PRESENCE_TERMINATING: - case SA_AMF_PRESENCE_INSTANTIATION_FAILED: - case SA_AMF_PRESENCE_TERMINATION_FAILED: - dprintf("Instantiate ignored in Component presence state %d", - component->saAmfCompPresenceState); - break; - case SA_AMF_PRESENCE_UNINSTANTIATED: - - comp_presence_state_set (component, SA_AMF_PRESENCE_INSTANTIATING); - amf_su_comp_state_changed(component->su, - component,SA_AMF_PRESENCE_STATE,SA_AMF_PRESENCE_INSTANTIATING); - if (amf_su_is_local (component->su)) { - res = clc_interfaces[component->comptype]->instantiate ( - component); - } - - break; - case SA_AMF_PRESENCE_RESTARTING: - if (amf_su_is_local (component->su)) { - res = clc_interfaces[component->comptype]->instantiate ( - component); - } - break; - default: - dprintf("Component presence state %d", - component->saAmfCompPresenceState); - assert (0); - break; - } -} - -void amf_comp_readiness_state_set (struct amf_comp *comp, - SaAmfReadinessStateT state) -{ - TRACE1 ("Setting comp '%s' readiness state: %s\n", - comp->name.value, amf_readiness_state (state)); -} - -/** - * Handle a component response (received from the lib) of an earlier AMF request. - * This function should be invoked when the lib request is received. - * @param invocation [in] associates the response with the request (callback) - * @param error [in] response from the component of the associated callback - * @param retval [out] contains return value to component when needed - * - * @return ==0 respond to component, do not multicast - * @return >0 do not respond to component, multicast response - */ -int amf_comp_response_1 ( - SaInvocationT invocation, SaAisErrorT error, SaAisErrorT *retval, - SaUint32T *interface, SaNameT *dn, SaAmfHealthcheckKeyT *healtcheck_key, - SaAmfRecommendedRecoveryT *recommendedRecovery) -{ - int res; - void *data; - - res = invocation_get_and_destroy (invocation, interface, &data); - - if (res == -1) { - log_printf (LOG_ERR, "Lib response: invocation not found\n"); - *retval = SA_AIS_ERR_INVALID_PARAM; - return 0; - } - - switch (*interface) { - case AMF_RESPONSE_HEALTHCHECKCALLBACK: { - struct amf_healthcheck *healthcheck = data; - - amf_comp_dn_make (healthcheck->comp, dn); - TRACE7 ("Healthcheck response from '%s': %d",dn->value, error); - /* - * Healthcheck with erroneous response - * and no recovery action is in progress. - */ - memcpy(healtcheck_key, &healthcheck->safHealthcheckKey, - sizeof (SaAmfHealthcheckKeyT)); - *recommendedRecovery = healthcheck->recommendedRecovery; - - if (error != SA_AIS_OK && - !amf_comp_is_error_suspected (healthcheck->comp)) { - return 1; - } - if (is_not_instantiating_or_instantiated_or_restarting( - healthcheck->comp)) { - log_printf (LOG_ERR, "HealthcheckResponse: ignored for key = %s, " - "due to wrong state = %d comp = %s", - healthcheck->safHealthcheckKey.key, - healthcheck->comp->saAmfCompPresenceState, - healthcheck->comp->name.value); - *retval = SA_AIS_OK; - return 0; /* do not multicast event */ - } - - if (healthcheck->invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) { - /* the response was on time, delete supervision timer */ - poll_timer_delete (aisexec_poll_handle, - healthcheck->timer_handle_duration); - healthcheck->timer_handle_duration = 0; - - /* start timer to execute next healthcheck request */ - poll_timer_add (aisexec_poll_handle, - healthcheck->saAmfHealthcheckPeriod, - (void *)healthcheck, - timer_function_healthcheck_next_fn, - &healthcheck->timer_handle_period); - *retval = SA_AIS_OK; - } else { - *retval = SA_AIS_ERR_INVALID_PARAM; - } - - return 0; /* do not multicast event */ - break; - } - case AMF_RESPONSE_CSISETCALLBACK: /* fall-through */ - case AMF_RESPONSE_CSIREMOVECALLBACK: - amf_csi_assignment_dn_make (data, dn); - return 1; /* multicast event */ - break; -#if 0 - case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: { - struct component_terminate_callback_data *component_terminate_callback_data; - component_terminate_callback_data = data; - - dprintf ("Lib component terminate callback response, error: %d", error); - amf_comp_healthcheck_deactivate (component_terminate_callback_data->comp); - escalation_policy_restart (component_terminate_callback_data->comp); - return 1; - break; - } -#endif - default: - assert (0); - break; - } - - /* XXX we fall here in case NDEBUG is set */ - *retval = -1; - return 0; -} - -/** - * Handle a component response (received from EVS) of an earlier AMF request. - * This function should be invoked when the multicast request is received. - * @param invocation [in] associates the response with the request (callback) - * @param error [in] response from the component of the associated callback - * @param retval [out] contains return value to component when needed - * - * @return component to which the response should be sent - */ -struct amf_comp *amf_comp_response_2 (SaUint32T interface, SaNameT *dn, - SaAmfHealthcheckKeyT *healthcheck_key, SaAisErrorT error, - SaAisErrorT *retval, SaAmfRecommendedRecoveryT recommendedRecovery) -{ - struct amf_csi_assignment *csi_assignment; - struct amf_comp *comp = NULL; - - assert (retval != NULL); - - *retval = SA_AIS_OK; - - switch (interface) { - case AMF_RESPONSE_CSISETCALLBACK: { - ENTER("'%s'", dn->value); - csi_assignment = amf_csi_assignment_find (amf_cluster, dn); - assert (csi_assignment != NULL); - comp = csi_assignment->comp; - dprintf ("CSI '%s' set callback response from '%s', error: %d", - csi_assignment->csi->name.value, - csi_assignment->comp->name.value, error); - comp = csi_assignment->comp; - if (error == SA_AIS_OK) { - comp_ha_state_set ( - comp, csi_assignment, csi_assignment->requested_ha_state); - } else if (error == SA_AIS_ERR_FAILED_OPERATION) { - amf_si_comp_set_ha_state_failed (csi_assignment->csi->si, - csi_assignment); - } else { - *retval = SA_AIS_ERR_INVALID_PARAM; - } - break; - } - case AMF_RESPONSE_CSIREMOVECALLBACK: { - ENTER("'%s'", dn->value); - csi_assignment = amf_csi_assignment_find (amf_cluster, dn); - assert (csi_assignment != NULL); - dprintf ("Lib csi '%s' remove callback response from '%s', error: %d", - csi_assignment->csi->name.value, - csi_assignment->comp->name.value, error); - comp = csi_assignment->comp; - if (error == SA_AIS_OK || error == SA_AIS_ERR_FAILED_OPERATION) { - amf_si_comp_csi_removed (csi_assignment->csi->si, - csi_assignment, error); - } else { - *retval = SA_AIS_ERR_INVALID_PARAM; - } - break; - } - case AMF_RESPONSE_HEALTHCHECKCALLBACK: { - dprintf("AMF_RESPONSE_HEALTHCHECKCALLBACK for %s", dn->value); - comp = amf_comp_find (amf_cluster, dn); - - assert (comp); - amf_healthcheck_t *healthcheck = amf_comp_find_healthcheck ( - comp, healthcheck_key); - assert (comp); - healthcheck->recommendedRecovery = recommendedRecovery; - comp_recover_action (comp, healthcheck->recommendedRecovery); - - break; - } - -#if 0 - case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: { - struct component_terminate_callback_data *callback_data = data; - dprintf ("Lib comp '%s' terminate callback response, error: %d", - callback_data->comp->name.value, error); - comp_presence_state_set (callback_data->comp, - SA_AMF_PRESENCE_UNINSTANTIATED); - break; - } -#endif - default: - assert (0); - break; - } - - return comp; -} - -/** - * Request a component to assume a particular HA state - * @param comp - * @param csi_assignment - * @param requested_ha_state - */ -void amf_comp_hastate_set ( - struct amf_comp *component, - struct amf_csi_assignment *csi_assignment) -{ - ENTER ("'%s'", csi_assignment->csi->name.value); - - assert (component != NULL && csi_assignment != NULL); - - - if (!amf_comp_is_error_suspected (component)) { - lib_csi_set_request(component, csi_assignment); - } else { - if (csi_assignment->requested_ha_state == SA_AMF_HA_QUIESCED) { - csi_assignment->saAmfCSICompHAState = csi_assignment->requested_ha_state; - } else { - dprintf ("csi_assignment->requested_ha_state = %d", - component->error_suspected); - assert (0); - } - } - - LEAVE(""); -} - -/** - * Request termination of a component - * @param comp - */ -void amf_comp_terminate (struct amf_comp *comp) -{ - dprintf ("comp terminate '%s'\n", getSaNameT (&comp->name)); - comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING); - - if (amf_su_is_local (comp->su)) { - amf_comp_healthcheck_stop (comp, NULL); - amf_comp_pm_stop(comp, SA_AMF_PM_ALL_PROCESSES, 0, SA_AMF_PM_ALL_ERRORS); - if (amf_comp_is_error_suspected(comp)) { - clc_interfaces[comp->comptype]->cleanup (comp); - } else { - /*TODO temination implementation */ - /*clc_interfaces[comp->comptype]->terminate (comp);*/ - clc_interfaces[comp->comptype]->cleanup (comp); - } - } -} - -/** - * Request restart of a component - * @param comp - */ -void amf_comp_restart (struct amf_comp *comp) -{ - dprintf ("comp restart '%s'\n", getSaNameT (&comp->name)); - comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING); - comp->saAmfCompRestartCount += 1; - - if (amf_su_is_local (comp->su)) { - amf_comp_healthcheck_stop (comp, NULL); - amf_comp_pm_stop(comp, SA_AMF_PM_ALL_PROCESSES, 0, SA_AMF_PM_ALL_ERRORS); - clc_interfaces[comp->comptype]->cleanup (comp); - } -} - -/** - * Request to return the HA state for a components CSI - * @param comp - * @param csi_name - * @param ha_state - * - * @return SaAisErrorT - */ -SaAisErrorT amf_comp_hastate_get ( - struct amf_comp *comp, SaNameT *csi_name, SaAmfHAStateT *ha_state) -{ - struct amf_csi_assignment *assignment; - - assert (comp != NULL && csi_name != NULL && ha_state != NULL); - - dprintf ("comp ha state get from comp '%s' CSI '%s'\n", - getSaNameT (&comp->name), csi_name->value); - - assignment = csi_assignment_find_in (comp, csi_name); - if (assignment != NULL) { - *ha_state = assignment->saAmfCSICompHAState; - return SA_AIS_OK; - } - - return SA_AIS_ERR_NOT_EXIST; -} - -/** - * Response from a component informs AMF that it has performed a healthcheck - * @param comp - * @param healthcheckKey - * @param healthcheckResult - * - * @return SaAisErrorT - */ -SaAisErrorT amf_comp_healthcheck_confirm ( - struct amf_comp *comp, - SaAmfHealthcheckKeyT *healthcheckKey, - SaAisErrorT healthcheckResult) -{ - struct amf_healthcheck *healthcheck; - SaAisErrorT error = SA_AIS_OK; - - healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey); - if (is_not_instantiating_or_instantiated_or_restarting(comp)) { - log_printf (LOG_ERR, "HealthcheckConfirm: ignored for key = %s, " - "due to wrong state = %d, comp = %s", - healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value); - error = SA_AIS_OK; - goto out; - } - if (healthcheck == NULL) { - log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found", - healthcheckKey->key); - error = SA_AIS_ERR_NOT_EXIST; - } else if (healthcheck->active) { - if (healthcheckResult == SA_AIS_OK) { - /* the response was on time, restart the supervision timer */ - poll_timer_delete (aisexec_poll_handle, - healthcheck->timer_handle_period); - poll_timer_add (aisexec_poll_handle, - healthcheck->saAmfHealthcheckPeriod, - (void *)healthcheck, - timer_function_healthcheck_tmo, - &healthcheck->timer_handle_period); - } else if (healthcheckResult == SA_AIS_ERR_FAILED_OPERATION) { - /* send to cluster */ - if (!comp->error_suspected) { - poll_timer_delete (aisexec_poll_handle, - healthcheck->timer_handle_period); - mcast_healthcheck_tmo_event (healthcheck); - } - } else { - error = SA_AIS_ERR_INVALID_PARAM; - } - } else { - error = SA_AIS_ERR_INVALID_PARAM; - } -out: - return error; -} - -void amf_comp_operational_state_set (struct amf_comp *comp, - SaAmfOperationalStateT oper_state) -{ - comp->saAmfCompOperState = oper_state; - TRACE1 ("Setting comp '%s', SU '%s' operational state: %s\n", - comp->name.value, comp->su->name.value, - amf_op_state (comp->saAmfCompOperState)); - amf_su_comp_state_changed ( - comp->su, comp, SA_AMF_OP_STATE, oper_state); -} - -int amf_comp_get_saAmfCompNumCurrActiveCsi(struct amf_comp *component) -{ - int cnt = 0; - struct amf_csi_assignment *csi_assignment; - - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (csi_assignment != NULL) { - if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_ACTIVE) { - cnt++; - } - csi_assignment = amf_comp_get_next_csi_assignment ( - component, csi_assignment); - } - - return cnt; -} - -int amf_comp_get_saAmfCompNumCurrStandbyCsi(struct amf_comp *component) -{ - int cnt = 0; - struct amf_csi_assignment *csi_assignment; - - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (csi_assignment != NULL) { - if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_STANDBY) { - cnt++; - } - csi_assignment = amf_comp_get_next_csi_assignment ( - component, csi_assignment); - } - - return cnt; -} - -SaAmfReadinessStateT amf_comp_get_saAmfCompReadinessState ( - struct amf_comp *component) -{ - if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) { - return amf_su_get_saAmfSUReadinessState (component->su); - - } else if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_DISABLED) { - return SA_AMF_READINESS_OUT_OF_SERVICE; - } - - assert (0); - /* XXX we fall here in case NDEBUG is set */ - return -1; -} -/** - * Component is informed that the node where the 'real' - * component process is executing has unexpectadly left the - * node. If there is a pending interaction between AMF - * (component) and the 'real' component process, then component - * will indicate to its subordinate objects the interaction - * failed. Pending presence state changes is indicated by - * reporting the new state is uninstantiated while pending csi - * operations are indicated by 'operation failed'. - * @param comp - * - * @return void - */ -void amf_comp_node_left (struct amf_comp *component) -{ - int change_pending = 0; - struct amf_csi_assignment *csi_assignment; - - ENTER("saAmfCompPresenceState = %d", component->saAmfCompPresenceState); - amf_comp_error_suspected_clear (component); - if (component->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING || - component->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING || - component->saAmfCompPresenceState == SA_AMF_PRESENCE_TERMINATING) { - change_pending = 1; - - } - - component->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED; - - if (amf_su_are_all_comps_in_su (component->su, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - component->su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED; - } - - if (change_pending) { - change_pending = 0; - amf_su_comp_state_changed ( component->su, - component, - SA_AMF_PRESENCE_STATE, - SA_AMF_PRESENCE_UNINSTANTIATED); - } - - if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) { - change_pending = 1; - } - - component->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED; - if (change_pending) { - change_pending =0; - amf_su_comp_state_changed (component->su, - component, - SA_AMF_OP_STATE, - SA_AMF_OPERATIONAL_DISABLED); - } - - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (csi_assignment != NULL) { - if (csi_assignment->requested_ha_state != - csi_assignment->saAmfCSICompHAState) { - amf_si_comp_set_ha_state_failed ( - csi_assignment->csi->si,csi_assignment); - } - csi_assignment = amf_comp_get_next_csi_assignment ( - component, csi_assignment); - } -} - -/** - * Serialize a component including variable length arrays and - * strings to a buffer returned. Buffer is to be freed by - * caller. - * @param component - * @param len - * - * @return void* - */ -void *amf_comp_serialize (struct amf_comp *component, int *len) -{ - char *buf = NULL; - int i, offset = 0, size = 0; - - TRACE8 ("%s", component->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &component->name); - - /* count cstypes and write to buf */ - for (i = 0; component->saAmfCompCsTypes && - component->saAmfCompCsTypes[i] != NULL; i++); - buf = amf_serialize_SaUint32T (buf, &size, &offset, i); - - for (i = 0; component->saAmfCompCsTypes && - component->saAmfCompCsTypes[i] != NULL; i++) { - buf = amf_serialize_SaNameT ( - buf, &size, &offset, component->saAmfCompCsTypes[i]); - } - - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompCategory); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompCapability); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompNumMaxActiveCsi); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompNumMaxStandbyCsi); - - /* count environment vars and write to buf */ - for (i = 0; component->saAmfCompCmdEnv && - component->saAmfCompCmdEnv[i] != NULL; i++); - buf = amf_serialize_SaUint32T (buf, &size, &offset, i); - - for (i = 0; component->saAmfCompCmdEnv && - component->saAmfCompCmdEnv[i] != NULL; i++) { - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompCmdEnv[i]); - } - - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompDefaultClcCliTimeout); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompDefaultCallbackTimeOut); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompInstantiateCmd); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompInstantiateCmdArgv); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompInstantiateTimeout); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompInstantiationLevel); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithoutDelay); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithDelay); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompDelayBetweenInstantiateAttempts); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompTerminateCmd); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompTerminateTimeout); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompTerminateCmdArgv); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompCleanupCmd); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompCleanupTimeout); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompCleanupCmdArgv); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompAmStartCmd); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompAmStartTimeout); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompAmStartCmdArgv); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompNumMaxAmStartAttempt); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompAmStopCmd); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompAmStopTimeout); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->saAmfCompAmStopCmdArgv); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompNumMaxAmStopAttempt); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompTerminateCallbackTimeout); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompCSISetCallbackTimeout); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompQuiescingCompleteTimeout); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompCSIRmvCallbackTimeout); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompRecoveryOnError); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompDisableRestart); - buf = amf_serialize_SaNameT ( - buf, &size, &offset, &component->saAmfCompProxyCsi); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompOperState); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompPresenceState); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->saAmfCompRestartCount); - buf = amf_serialize_SaNameT ( - buf, &size, &offset, &component->saAmfCompCurrProxyName); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, component->clccli_path); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->comptype); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, component->error_suspected); - - *len = offset; - - return buf; -} - -/** - * Deserialize a buffer into a AMF component object. - * @param su - * @param buf - * @param size - * - * @return struct amf_comp* - */ -struct amf_comp *amf_comp_deserialize (struct amf_su *su, char *buf) -{ - char *tmp = buf; - int i; - SaUint32T cnt; - struct amf_comp *component = amf_comp_new (su, ""); - - tmp = amf_deserialize_SaNameT (tmp, &component->name); - tmp = amf_deserialize_SaUint32T (tmp, &cnt); - component->saAmfCompCsTypes = amf_malloc ((cnt + 1) * sizeof (SaNameT*)); - for (i = 0; i < cnt; i++) { - component->saAmfCompCsTypes[i] = amf_malloc (sizeof (SaNameT)); - tmp = amf_deserialize_SaNameT (tmp, component->saAmfCompCsTypes[i]); - } - component->saAmfCompCsTypes[i] = NULL; - - tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCategory); - tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCapability); - tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxActiveCsi); - tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxStandbyCsi); - - tmp = amf_deserialize_SaUint32T (tmp, &cnt); - component->saAmfCompCmdEnv = amf_malloc ((cnt + 1) * sizeof (SaStringT*)); - for (i = 0; i < cnt; i++) { - tmp = amf_deserialize_SaStringT (tmp, &component->saAmfCompCmdEnv[i]); - } - component->saAmfCompCmdEnv[i] = NULL; - - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompDefaultClcCliTimeout); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompDefaultCallbackTimeOut); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompInstantiateCmd); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompInstantiateCmdArgv); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompInstantiateTimeout); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompInstantiationLevel); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompNumMaxInstantiateWithoutDelay); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompNumMaxInstantiateWithDelay); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompDelayBetweenInstantiateAttempts); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompTerminateCmd); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompTerminateTimeout); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompTerminateCmdArgv); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompCleanupCmd); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompCleanupTimeout); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompCleanupCmdArgv); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompAmStartCmd); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompAmStartTimeout); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompAmStartCmdArgv); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompNumMaxAmStartAttempt); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompAmStopCmd); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompAmStopTimeout); - tmp = amf_deserialize_SaStringT ( - tmp, &component->saAmfCompAmStopCmdArgv); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompNumMaxAmStopAttempt); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompTerminateCallbackTimeout); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompCSISetCallbackTimeout); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompQuiescingCompleteTimeout); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompCSIRmvCallbackTimeout); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompRecoveryOnError); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompDisableRestart); - tmp = amf_deserialize_SaNameT ( - tmp, &component->saAmfCompProxyCsi); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompOperState); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompPresenceState); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->saAmfCompRestartCount); - tmp = amf_deserialize_SaNameT ( - tmp, &component->saAmfCompCurrProxyName); - tmp = amf_deserialize_SaStringT ( - tmp, &component->clccli_path); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->comptype); - tmp = amf_deserialize_SaUint32T ( - tmp, &component->error_suspected); - - return component; -} - -void *amf_healthcheck_serialize (struct amf_healthcheck *healthcheck, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", healthcheck->safHealthcheckKey.key); - - buf = amf_serialize_opaque (buf, &size, &offset, - &healthcheck->safHealthcheckKey.key, SA_AMF_HEALTHCHECK_KEY_MAX); - buf = amf_serialize_SaUint16T (buf, &size, &offset, - healthcheck->safHealthcheckKey.keyLen); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - healthcheck->saAmfHealthcheckMaxDuration); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - healthcheck->saAmfHealthcheckPeriod); - - *len = offset; - - return buf; -} - -struct amf_healthcheck *amf_healthcheck_deserialize ( - struct amf_comp *comp, char *buf) -{ - char *tmp = buf; - int cnt; - amf_healthcheck_t *healthcheck = amf_healthcheck_new (comp); - - tmp = amf_deserialize_opaque (tmp, &healthcheck->safHealthcheckKey.key, &cnt); - tmp = amf_deserialize_SaUint16T (tmp, - &healthcheck->safHealthcheckKey.keyLen); - tmp = amf_deserialize_SaUint32T (tmp, - &healthcheck->saAmfHealthcheckMaxDuration); - tmp = amf_deserialize_SaUint32T (tmp, - &healthcheck->saAmfHealthcheckPeriod); - - return healthcheck; -} - -amf_healthcheck_t *amf_healthcheck_new (struct amf_comp *comp) -{ - amf_healthcheck_t *healthcheck = amf_calloc (1, sizeof (amf_healthcheck_t)); - - healthcheck->comp = comp; - healthcheck->next = comp->healthcheck_head; - comp->healthcheck_head = healthcheck; - - return healthcheck; -} - -void amf_comp_csi_remove (amf_comp_t *component, - amf_csi_assignment_t *csi_assignment) -{ - struct res_lib_amf_csiremovecallback res_lib; - - ENTER(""); - - res_lib.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK; - res_lib.header.size = sizeof (struct res_lib_amf_csiremovecallback); - res_lib.header.error = SA_AIS_OK; - res_lib.invocation = - invocation_create (AMF_RESPONSE_CSIREMOVECALLBACK, csi_assignment); - - amf_comp_dn_make (component, &res_lib.compName); - amf_csi_dn_make (csi_assignment->csi, &res_lib.csiName); - res_lib.csiFlags = SA_AMF_CSI_TARGET_ONE; - - TRACE7 ("sending CSI remove request to component %s", - res_lib.compName.value); - openais_conn_send_response ( - openais_conn_partner_get (component->conn), - &res_lib, sizeof (struct res_lib_amf_csiremovecallback)); -} - -void amf_comp_error_suspected_clear (amf_comp_t *comp) -{ - comp->error_suspected = 0; -} - -void amf_comp_error_suspected_set (amf_comp_t *comp) -{ - comp->error_suspected = 1; -} - -int amf_comp_is_error_suspected (amf_comp_t *comp) -{ - return comp->error_suspected ? 1 : 0; -} - diff --git a/openais/services/amfnode.c b/openais/services/amfnode.c deleted file mode 100644 index e210aad6..00000000 --- a/openais/services/amfnode.c +++ /dev/null @@ -1,797 +0,0 @@ -/** @file amfnode.c - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Constructors/destructors - * - Serializers/deserializers - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Node Class Implementation - * - * This file contains functions for handling AMF nodes. It can be - * viewed as the implementation of the AMF Node class (called NODE) - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for: - * - controlling the instantiation of the SUs hosted on current node and - * controlling the assigning of workload to them when a node joins the - * cluster (cluster start is controlled by the Cluster Class) - * - controlling node level recovery and repair functions - * - implementing error escallation level 2 and 3 (paragraph 3.12.2.2 and - * 3.12.2.3 in the spec) - * - handling run time attributes of the AMF NODE; cached - * attributes are stored as variables and sent to the IMM service (future) - * upon the changes described in the specification - * - * The node class contains the following state machines: - * - administrative state machine (ADSM) - * - operational state machine (OPSM) - * - availability control state machine (ACSM) - * - * The administrative state machine will be implemented in the future. - * - * The operational state machine is primarily used to report status of the - * node. - * - * The availability control state machine is used for control purposes. - * ACSM contains three states of which two are composite. - * Being a composite state means that the state contains substates. - * ACSM states are: - * - REPAIR_NEEDED - * - IDLE (ESCALATION_LEVEL_0, ESCALATION_LEVEL_2 and ESCALATION_LEVEL_3) - * - MANAGING_HOSTED_SERVICE_UNITS ( - * . FAILING_FAST (REBOOTING_NODE and ACTIVATING_STANDBY_NODE) - * . FAILING_GRACEFULLY (SWITCHING_OVER, FAILING_OVER and REBOOTING_NODE) - * . LEAVING_SPONTANEOUSLY (SWITCHING_OVER, FAILING_OVER and - * WAITING_FOR_NODE_TO_JOIN) - * . JOINING (STARTING_APPLICATIONS and ASSIGNING_WORKLOAD) - * - * REPAIR_NEEDED indicates the node needs a manual repair and this state will be - * maintained until the administrative command REPAIRED is entered (implemented - * in the future) - * - * IDLE is a composite state where no actions are actually performed - * and used only to remember the escallation level. Substate LEVEL_0 indicates - * no escallation. LEVEL_2 indicates that so many component restarts have been - * executed recently that a new component restart request will escalate - * to service unit restart action. Node will request a service unit restart - * from SU. - * LEVEL_3 will be entered if either there are too many service unit restarts - * been made or a component failover recovery action is requested. On level 3 - * the recovery action performed is service unit failover (paragraph 3.12.1.3). - * - * FAILING_FAST state executes a node re-boot and waits for the node to join - * the cluster again. (not implemented) - * - * FAILING_GRACEFULLY state requests all SGs which have SUs hosted on current - * node to switch or failover according to the procedures described in - * paragraphs 3.12.1.3 before re-boot is executed. Then the confirmation is - * awaited from all concerned SGs and finally a node re-boot is executed as - * the repair action (see paragraph 2.12.1.4). - * - * LEAVING_SPONTANEOUSLY state handles the spontaneous leave of a node. - * - * JOINING state handles the start of a node in all cases except cluster start, - * which is handled by the CLUSTER class. - * - * 1. Node Availability Control State Machine - * ========================================== - * - * 1.1 State Transition Table - * - * State: Event: Action: New state: - * ============================================================================ - * ESCALATION_LEVEL_X node_sync_ready A6 JOINING_STARTING_APPLS - * ESCALATION_LEVEL_X node_leave A9,A8 LEAVING_SP_FAILING_OVER - * ESCALATION_LEVEL_X failover A11 GRACEFULLY_FAILING_OVER - * ESCALATION_LEVEL_2 comp_restart_req [!C6]A13 ESCALATION_LEVEL_2 - * ESCALATION_LEVEL_2 comp_restart_req [C6]A14 ESCALATION_LEVEL_3 - * ESCALATION_LEVEL_3 comp_restart_req [!C7]A14 ESCALATION_LEVEL_3 - * ESCALATION_LEVEL_3 comp_failover_req [!C7]A14 ESCALATION_LEVEL_3 - * ESCALATION_LEVEL_3 comp_restart_req [C7]A15 ESCALATION_LEVEL_3 - * ESCALATION_LEVEL_3 comp_failover_req [C7]A15 ESCALATION_LEVEL_3 - * JOINING_STARTING_APPLS appl_started [C4] A7 JOINING_ASSIGNING_WL - * JOINING_ASSIGNING_WL appl_assigned [C5] ESCALATION_LEVEL_X - * LEAVING_SP_FAILING_OVER sg_failed_over [C1] LEAVING_SP_WAIT_FOR_JOIN - * LEAVING_SP_WAIT_FOR_JOIN node_sync_ready A6 JOINING_STARTING_APPLS - * GRACEFULLY_FAILING_OVER sg_failed_over [C1] A12 GRACEFULLY_REBOOTING - * GRACEFULLY_REBOOTING node_leave ESCALATION_LEVEL_X - * - * 1.2 State Description - * ===================== - * ESCALATION_LEVEL_X - Node is synchronized and idle (X = 0,2 or 3). - * JOINING_STARTING_APPLS - JOINING_STARTING_APPLICATIONS - * Node has ordered all applications to start its SUs - * hosted on current node and is now waiting for them - * to acknowledge that they have started. - * GRACEFULLY_FAILING_OVER - FAILING_GRACEFULLY_FAILING_OVER - * Node has ordered all SGs in the cluster to - * failover all SUs that are hosted on a specific - * node and waits for the SGs to confirm the - * failover is completed. - * GRACEFULLY_REBOOTING - FAILING_GRACEFULLY_REBOOTING_NODE - * Node has ordered reboot and waits for the rebooted - * node to join the cluster again. - * JOINING_ASSIGNING_WL - JOINING_ASSIGNING_WORKLOAD - * Node has ordered all applications to assign workload - * to all its SUs which currently have no workload and - * is now waiting for the applications to acknowledge. - * - * LEAVING_SP_FAILING_OVER - LEAVING_SPONTANEOUSLY_FAILING_OVER - * Node has received an event telling that this node - * has left the cluster and has ordered all service - * groups to failover those of its SUs that were - * hosted on current node. - * - * LEAVING_SP_WAIT_FOR_JOIN - LEAVING_SPONTANEOUSLY_WAITING_FOR_NODE_TO_JOIN - * Node is waiting for current node to join again. - * - * 1.3 Actions - * =========== - * A1 - - * A2 - - * A3 - - * A4 - - * A5 - - * A6 - [foreach application in cluster]start application - * A7 - [foreach application in cluster]assign workload to application - * A8 - [foreach application in cluster] - * [foreach SG in application ]failover node - * A9 - [foreach application in cluster] - * [foreach SG in application ] - * [foreach SU in SG where the SU is hosted on current node] - * [foreach comp in such an SU]indicate that the node has left the cluster - * A10- - * A11- [foreach SG in cluster]failover node - * A12- reboot node - * A13- restart SU - * A14- failover SU - * A15- failover node - * - * 1.4 Guards - * ========== - * C1 - All SG availability control state machines (ACSM) == IDLE - * C2 - - * C3 - - * C4 - No applications are in ACSM state == STARTING_SGS - * C5 - All applications have ACSM state == WORKLOAD_ASSIGNED - * C6 - Specified number of SU restarts have been done. - * C7 - Specified number of SU failover actions have been done. - */ - -#include -#include -#include -#include "amf.h" -#include "util.h" -#include "logsys.h" -#include "main.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO) - -/****************************************************************************** - * Internal (static) utility functions - *****************************************************************************/ - -static void node_acsm_enter_leaving_spontaneously(struct amf_node *node) -{ - ENTER("'%s'", node->name.value); - node->saAmfNodeOperState = SA_AMF_OPERATIONAL_DISABLED; - node->nodeid = 0; -} - -static void node_acsm_enter_failing_over (struct amf_node *node) -{ - struct amf_application *app; - struct amf_sg *sg; - struct amf_su *su; - struct amf_comp *component = NULL; - - ENTER("'%s'", node->name.value); - node->acsm_state = NODE_ACSM_LEAVING_SPONTANEOUSLY_FAILING_OVER; - /* - * Indicate to each component object in the model that current - * node has left the cluster - */ - for (app = amf_cluster->application_head; app != NULL; app = app->next) { - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - if (name_match(&node->name, &su->saAmfSUHostedByNode)) { - for (component = su->comp_head; component != NULL; - component = component->next) { - amf_comp_node_left(component); - } - } - } - } - } - - /* - * Let all service groups with service units hosted on current node failover - * its workload - */ - for (app = amf_cluster->application_head; app != NULL; app = - app->next) { - for (sg = app->sg_head; sg != NULL; sg = - sg->next) { - amf_sg_failover_node_req(sg, node); - } - } -} - -static void failover_all_sg_on_node (amf_node_t *node) -{ - amf_application_t *app; - amf_sg_t *sg; - amf_su_t *su; - for (app = amf_cluster->application_head; app != NULL; app = app->next) { - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - if (name_match(&su->saAmfSUHostedByNode, &node->name)) { - amf_sg_failover_node_req (sg, node); - break; - } - } - - } - } -} - -static void node_acsm_enter_failing_gracefully_failing_over (amf_node_t *node) -{ - ENTER(""); - node->acsm_state = NODE_ACSM_FAILING_GRACEFULLY_FAILING_OVER; - failover_all_sg_on_node (node); -} - -static int has_all_sg_on_node_failed_over (amf_node_t *node) -{ - amf_application_t *app; - amf_sg_t *sg; - amf_su_t *su; - int has_all_sg_on_node_failed_over = 1; - - for (app = amf_cluster->application_head; app != NULL; app = app->next) { - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - for (su = sg->su_head; su != NULL; su = su->next) { - if (name_match(&su->saAmfSUHostedByNode, &node->name)) { - - if (sg->avail_state != SG_AC_Idle) { - TRACE1("%s %s",sg->name.value, su->name.value); - has_all_sg_on_node_failed_over = 0; - goto out; - } - break; - } - } - - } - } -out: - return has_all_sg_on_node_failed_over; -} - -static void repair_node (amf_node_t *node) -{ - ENTER(""); - char hostname[256]; - gethostname (hostname, 256); - if (!strcmp (hostname, (const char*)node->saAmfNodeClmNode.value)) { - /* TODO if(saAmfAutoRepair == SA_TRUE) */ -#ifdef DEBUG - exit (0); -#else - system ("reboot"); -#endif - } -} - -static void enter_failing_gracefully_rebooting_node (amf_node_t *node) -{ - ENTER(""); - node->acsm_state = NODE_ACSM_FAILING_GRACEFULLY_REBOOTING_NODE; - repair_node (node); -} - -static void node_acsm_enter_idle (amf_node_t *node) -{ - ENTER ("history_state=%d",node->history_state); - node->acsm_state = node->history_state; -} - -static void node_acsm_enter_joining_assigning_workload (struct amf_node *node, - struct amf_application *app) -{ - log_printf(LOG_NOTICE, - "Node=%s: all applications started, assigning workload.", - node->name.value); - - ENTER(""); - node->acsm_state = NODE_ACSM_JOINING_ASSIGNING_WORKLOAD; - for (app = app->cluster->application_head; app != NULL; - app = app->next) { - amf_application_assign_workload (app, node); - } -} - -/****************************************************************************** - * Event methods - *****************************************************************************/ - -/** - * This event indicates that a node has unexpectedly left the cluster. Node - * leave event is obtained from amf_confchg_fn. - * - * @param node - */ -void amf_node_leave (struct amf_node *node) -{ - assert (node != NULL); - ENTER("'%s', CLM node '%s'", node->name.value, - node->saAmfNodeClmNode.value); - - - switch (node->acsm_state) { - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_0: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_2: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_3: - node_acsm_enter_leaving_spontaneously(node); - node_acsm_enter_failing_over (node); - break; - case NODE_ACSM_REPAIR_NEEDED: - break; - case NODE_ACSM_FAILING_GRACEFULLY_REBOOTING_NODE: - node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED; - node_acsm_enter_idle (node); - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_node_leave called in state = %d" - " (should have been deferred)", node->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - - } -} - -/** - * This function handles a detected error that by a pre-analysis executed - * elsewhere has been decided to be recovered by a node fail over. - * @param node - */ -void amf_node_failover (struct amf_node *node) -{ - assert (node != NULL); - ENTER("'%s', CLM node '%s'", node->name.value, - node->saAmfNodeClmNode.value); - - switch (node->acsm_state) { - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_0: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_2: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_3: - node_acsm_enter_failing_gracefully_failing_over (node); - break; - case NODE_ACSM_REPAIR_NEEDED: - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_node_leave()called in state = %d" - " (should have been deferred)", node->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - } -} - -/** - * - * @param node - */ -void amf_node_switchover (struct amf_node *node) -{ - -} - -/** - * - * @param node - */ -void amf_node_failfast (struct amf_node *node) -{ - -} - -/** - * This event is a request to restart a component which has been escalated, - * because the component has already been restarted the number of times - * specified by the configuration. - * This function evaluates which recovery measure shall now be - * taken and initiates the action which result from the evaluation. - * @param node - * @param comp - */ -void amf_node_comp_restart_req (struct amf_node *node, struct amf_comp *comp) -{ - amf_su_t *su = comp->su; - ENTER(""); - switch (node->acsm_state) { - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_0: - node->acsm_state = NODE_ACSM_IDLE_ESCALLATION_LEVEL_2; - amf_node_comp_restart_req (node, comp); - break; - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_2: - if (su->saAmfSURestartCount >= su->sg->saAmfSGSuRestartMax) { - SaNameT dn; - node->acsm_state = NODE_ACSM_IDLE_ESCALLATION_LEVEL_3; - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED); - amf_su_operational_state_set (su, SA_AMF_OPERATIONAL_DISABLED); - amf_comp_dn_make (comp, &dn); - - log_printf (LOG_NOTICE, "Error detected for '%s', recovery " - "action:\n\t\tSU failover", dn.value); - - amf_sg_failover_su_req (su->sg, su, node); - } else { - amf_su_restart (su); - } - break; - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_3: - if (su->su_failover_cnt < node->saAmfNodeSuFailoverMax) { - SaNameT dn; - amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED); - amf_su_operational_state_set (su, SA_AMF_OPERATIONAL_DISABLED); - amf_comp_dn_make (comp, &dn); - - log_printf (LOG_NOTICE, "Error detected for '%s', recovery " - "action:\n\t\tSU failover", dn.value); - - amf_sg_failover_su_req (su->sg, su, node); - return; - } else { - node->history_state = NODE_ACSM_IDLE_ESCALLATION_LEVEL_0; - amf_node_failover (node); - } - break; - default: - dprintf("%d",node->acsm_state); - assert (0); - break; - } -} - -/** - * This event is a request to failover the specified component. - * This function evaluates which recovery measure shall actually be - * taken considering the escalation policy and initiates the action - * which result from the evaluation. - * @param node - * @param comp - */ -void amf_node_comp_failover_req (amf_node_t *node, amf_comp_t *comp) -{ - ENTER(""); - switch (node->acsm_state) { - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_0: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_2: - if (comp->su->saAmfSUFailover) { - /* SU failover */ - amf_sg_failover_su_req (comp->su->sg,comp->su, node); - } - break; - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_3: - if (comp->su->su_failover_cnt < node->saAmfNodeSuFailoverMax) { - if (comp->su->saAmfSUFailover) { - /* SU failover */ - amf_sg_failover_su_req (comp->su->sg,comp->su, node); - - } - } else { - node->history_state = NODE_ACSM_IDLE_ESCALLATION_LEVEL_0; - amf_node_failover (node); - } - break; - default: - dprintf("%d",node->acsm_state); - assert (0); - break; - } -} - -/** - * This event indicates that current node has joined and its cluster model has - * been synchronized with the other nodes cluster models. - * - * @param node - */ -void amf_node_sync_ready (struct amf_node *node) -{ - struct amf_application *app; - - assert (node != NULL); - - log_printf(LOG_NOTICE, "Node=%s: sync ready, starting hosted SUs.", - node->name.value); - node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED; - - switch (node->acsm_state) { - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_0: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_2: - case NODE_ACSM_IDLE_ESCALLATION_LEVEL_3: - case NODE_ACSM_LEAVING_SPONTANEOUSLY_WAITING_FOR_NODE_TO_JOIN: - node->acsm_state = NODE_ACSM_JOINING_STARTING_APPLICATIONS; - for (app = amf_cluster->application_head; app != NULL; app = app->next) { - amf_application_start (app, node); - } - break; - case NODE_ACSM_REPAIR_NEEDED: - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_node_sync_ready() was called in " - "state = %d (should have been deferred)", - node->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - - } -} - -/****************************************************************************** - * Event response methods - *****************************************************************************/ - -/** - * This event indicates that an application has started. Started in this context - * means that none of its contained service units is in an -ING state with other - * words successfully instantiated, instantiation has failed or instantiation - * was not possible (due to the node on which the SU was to be hosted is not - * operational). - * - * @param node - * @param application which has been started - */ -void amf_node_application_started (struct amf_node *node, - struct amf_application *app) -{ - assert (node != NULL && app != NULL ); - ENTER ("Node=%s: application '%s' started", node->name.value, - app->name.value); - - switch (node->acsm_state) { - case NODE_ACSM_JOINING_STARTING_APPLICATIONS: - if (amf_cluster_applications_started_with_no_starting_sgs( - app->cluster)) { - - node_acsm_enter_joining_assigning_workload(node, app); - } - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_node_application_started()" - "called in state = %d (unexpected !!)", node->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - - } -} - -/** - * This event indicates that an application has been assigned workload. - * - * @param node - * @param app - Application which has been assigned workload - */ -void amf_node_application_workload_assigned (struct amf_node *node, - struct amf_application *app) -{ - assert (node != NULL && app != NULL ); - ENTER ("Node=%s: application '%s' started", node->name.value, - app->name.value); - - switch (node->acsm_state) { - case NODE_ACSM_JOINING_ASSIGNING_WORKLOAD: - - if (amf_cluster_applications_assigned (amf_cluster)) { - log_printf(LOG_NOTICE, "Node=%s: all workload assigned", - node->name.value); - node_acsm_enter_idle (node); - } - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_node_application_workload_assigned()" - "called in state = %d (unexpected !!)", node->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - } -} - -/** - * This event indicates that an SG has failed over its workload after a node - * failure. - * - * @param node - * @param sg_in SG which is now ready with its failover - */ -void amf_node_sg_failed_over (struct amf_node *node, struct amf_sg *sg_in) -{ - assert (node != NULL); - ENTER ("Node=%s: SG '%s' started %d", node->name.value, - sg_in->name.value,node->acsm_state); - - switch (node->acsm_state) { - case NODE_ACSM_LEAVING_SPONTANEOUSLY_FAILING_OVER: - if (has_all_sg_on_node_failed_over (node)) { /*C2*/ - node->acsm_state = - NODE_ACSM_LEAVING_SPONTANEOUSLY_WAITING_FOR_NODE_TO_JOIN; - } - break; - case NODE_ACSM_LEAVING_SPONTANEOUSLY_WAITING_FOR_NODE_TO_JOIN: - /* Accept reports of failed over sg that has completed. */ - break; - case NODE_ACSM_FAILING_GRACEFULLY_FAILING_OVER: - if (has_all_sg_on_node_failed_over (node)) { /*C2*/ - enter_failing_gracefully_rebooting_node (node); - } - break; - default: - log_printf (LOG_LEVEL_ERROR, "amf_node_sg_failed_over()" - "called in state = %d (unexpected !!)", node->acsm_state); - openais_exit_error (AIS_DONE_FATAL_ERR); - break; - } -} - -/****************************************************************************** - * General methods - *****************************************************************************/ - -/** - * Node constructor - * @param cluster - * @param name - RDN of node - */ -struct amf_node *amf_node_new (struct amf_cluster *cluster, char *name) { - struct amf_node *node = amf_calloc (1, sizeof (struct amf_node)); - - setSaNameT (&node->name, name); - node->saAmfNodeAdminState = SA_AMF_ADMIN_UNLOCKED; - node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED; - node->saAmfNodeAutoRepair = SA_TRUE; - node->saAmfNodeSuFailOverProb = -1; - node->saAmfNodeSuFailoverMax = ~0; - node->cluster = cluster; - node->next = cluster->node_head; - cluster->node_head = node; - node->acsm_state = NODE_ACSM_IDLE_ESCALLATION_LEVEL_0; - node->history_state = NODE_ACSM_IDLE_ESCALLATION_LEVEL_0; - return node; -} - -void *amf_node_serialize (struct amf_node *node, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", node->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &node->name); - buf = amf_serialize_SaNameT (buf, &size, &offset, &node->saAmfNodeClmNode); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeSuFailOverProb); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeSuFailoverMax); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeAutoRepair); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeRebootOnInstantiationFailure); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeRebootOnTerminationFailure); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeAdminState); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->saAmfNodeOperState); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->nodeid); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->acsm_state); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - node->history_state); - - *len = offset; - - return buf; -} - -struct amf_node *amf_node_deserialize (struct amf_cluster *cluster, char *buf) { - char *tmp = buf; - struct amf_node *node = amf_node_new (cluster, ""); - - tmp = amf_deserialize_SaNameT (tmp, &node->name); - tmp = amf_deserialize_SaNameT (tmp, &node->saAmfNodeClmNode); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeSuFailOverProb); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeSuFailoverMax); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeAutoRepair); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeRebootOnInstantiationFailure); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeRebootOnTerminationFailure); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeAdminState); - tmp = amf_deserialize_SaUint32T (tmp, &node->saAmfNodeOperState); - tmp = amf_deserialize_SaUint32T (tmp, &node->nodeid); - tmp = amf_deserialize_SaUint32T (tmp, &node->acsm_state); - tmp = amf_deserialize_SaUint32T (tmp, &node->history_state); - - return node; -} - -struct amf_node *amf_node_find (SaNameT *name) { - struct amf_node *node; - - assert (name != NULL && amf_cluster != NULL); - - for (node = amf_cluster->node_head; node != NULL; node = node->next) { - if (name_match (&node->name, name)) { - return node; - } - } - - dprintf ("node %s not found in configuration!", name->value); - - return NULL; -} - -struct amf_node *amf_node_find_by_nodeid (unsigned int nodeid) { - struct amf_node *node; - - assert (amf_cluster != NULL); - - for (node = amf_cluster->node_head; node != NULL; node = node->next) { - if (node->nodeid == nodeid) { - return node; - } - } - - dprintf ("node %u not found in configuration!", nodeid); - - return NULL; -} - -struct amf_node *amf_node_find_by_hostname (const char *hostname) { - struct amf_node *node; - - assert (hostname != NULL && amf_cluster != NULL); - - for (node = amf_cluster->node_head; node != NULL; node = node->next) { - if (strcmp ((char*)node->saAmfNodeClmNode.value, hostname) == 0) { - return node; - } - } - - dprintf ("node %s not found in configuration!", hostname); - - return NULL; -} - diff --git a/openais/services/amfsg.c b/openais/services/amfsg.c deleted file mode 100644 index 1b11cdc1..00000000 --- a/openais/services/amfsg.c +++ /dev/null @@ -1,2854 +0,0 @@ -/** @file amfsg.c - * - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Author: Steven Dake (sdake@redhat.com) - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Introduced AMF B.02 information model - * - Use DN in API and multicast messages - * - (Re-)Introduction of event based multicast messages - * - Refactoring of code into several AMF files - * - Component/SU restart, SU failover - * - Constructors/destructors - * - Serializers/deserializers - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Service Group Class Implementation - * - * This file contains functions for handling AMF-service groups(SGs). It can be - * viewed as the implementation of the AMF Service Group class (called SG) - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for: - * -on request start the service group by instantiating the contained SUs - * -on request assign the service instances it protects to the in-service - * service units it contains respecting as many as possible of the configured - * requirements for the group - * -create and delete an SI-assignment object for each relation between - * an SI and an SU - * -order each contained SU to create and delete CSI-assignments - * -request the Service Instance class (SI) to execute the transfer of the - * HA-state set/remove requests to each component involved - * -fully control the execution of component failover and SU failover - * -on request control the execution of the initial steps of node switchover - * and node failover - * -fully handle the auto adjust procedure - * - * Currently only the 'n+m' redundancy model is implemented. It is the - * ambition to identify n+m specific variables and functions and add the suffix - * '_nplusm' to them so that they can be easily recognized. - * - * When SG is requested to assign workload to all SUs or all SUs hosted on - * a specific node, a procedure containing several steps is executed: - * <1> An algorithm is executed which assigns SIs to SUs respecting the rules - * that has been configured for SG. The algorithm also has to consider - * if assignments between som SIs and SUs already exist. The scope of this - * algorithm is to create SI-assignments and set up requested HA-state for - * each assignment but not to transfer those HA-states to the components. - * <2> All SI-assignments with a requested HA state == ACTIVE are transferred - * to the components concerned before any STANDBY assignments are - * transferred. All components have to acknowledge the setting of the - * ACTIVE HA state before the transfer of any STANDBY assignment is - * initiated. - * <3> All active assignments can not be transferred at the same time to the - * different components because the rules for dependencies between SI and - * SI cluster wide and CSI and CSI within one SI, has to be respected. - * - * SG is fully responsible for step <1> but not fully responsible for handling - * step <2> and <3>. However, SG uses an attribute called 'dependency level' - * when requsted to assign workload. This parameter refers to an integer that - * has been calculated initially for each SI. The 'dependency level' indicates - * to which extent an SI depends on other SIs such that an SI that depends on - * no other SI is on dependecy_level == 1, an SI that depends only on an SI on - * dependency_level == 1 is on dependency-level == 2. - * An SI that depends on several SIs gets a - * dependency_level that is one unit higher than the SI with the highest - * dependency_level it depends on. When SG is requested to assign the workload - * on a certain dependency level, it requests all SI objects on that level to - * activate (all) SI-assignments that during step <1> has been requested to - * assume the active HA state. - * - * SG contains the following state machines: - * - administrative state machine (ADSM) (NOT IN THIS RELEASE) - * - availability control state machine (ACSM) - * - * The availability control state machine contains three states and one of them - * is composite. Being a composite state means that it contains substates. - * The states are: - * - IDLE (non composite state) - * - INSTANTIATING_SERVICE_UNITS - * - MANAGING_SG (composite state) - * MANAGING_SG is entered at several different events which has in common - * the need to set up or change the assignment of SIs to SUs. Only one such - * event can be handled at the time. If new events occur while one event is - * being handled then the new event is saved and will be handled after the - * handling of the first event is ready (return to IDLE state has been done). - * MANAGING_SG handles the following events: - * - start (requests SG to order SU to instantiate all SUs in SG and waits - * for SU to indicate presence state change reports from the SUs and - * finally responds 'started' to the requester) - * - assign_si (requests SG to assign SIs to SUs according to pre-configured - * rules (if not already done) and transfer the HA state of - * the SIs on the requested SI dependency level. Then SG waits for - * confirmation that the HA state has been succesfully set and - * finally responds 'assigned' to the reqeuster) - * - auto_adjust (this event indicates that the auto-adjust probation timer has - * expired and that SG should evaluate current assignments of - * SIs to SUs and if needed remove current assignments and - * create new according to what is specified in paragraph - * 3.7.1.2) - * - failover_comp (requests SG to failover a specific component according to - * the procedure described in paragraph 3.12.1.3) - * - failover_su (requests SG to failover a specific SU according to the - * procedure described in paragraph 3.12.1.3 and 3.12.1.4) - * - switchover_node (requests SG to execute the recovery actions described - * in 3.12.1.3 and respond to the requester when recovery - * is completed) - * - failover_node (requests SG to execute the recovery actions described - * in 3.12.1.3 and respond to the requester when recovery is - * completed) - * -* 1. SG Availability Control State Machine - * ========================================== - * - * 1.1 State Transition Table - * - * State: Event: Action: New state: - * ============================================================================ - * IDLE start A48,A28 INSTANTIATING_SUs - * IDLE assign_si A48,A31 ASSIGNING_ON_REQ - * IDLE failover_su A48,[C22]A10,A11 DEACTIVATING_DEP - * IDLE failover_su A48,[!C22]A12 TERMINATING_SUSP - * IDLE failover_node A48,[!C22]A12 TERMINATING_SUSP - * IDLE failover_node A48,[C22]A10,A11 DEACTIVATING_DEP - * IDLE failover_node A48,[C100]A34 IDLE - * INSTANTIATING_SUs start A48,A28 INSTANTIATING_SUs - * INSTANTIATING_SUs su_state_chg [C101]A26,A53 IDLE - * INSTANTIATING_SUs su_state_chg [C102]A26,A53 IDLE - * INSTANTIATING_SUs assign_si A31 ASSIGNING_ON_REQ - * INSTANTIATING_SUs failover_su A52 INSTANTIATING_SUs - * INSTANTIATING_SUs failover_node A52 INSTANTIATING_SUs - * ASSIGNING_ON_REQ ha_state_assumed [C15]A54 IDLE - * ASSIGNING_ON_REQ failover_su A52 ASSIGNING_ON_REQ - * ASSIGNING_ON_REQ failover_node A52 ASSIGNING_ON_REQ - * DEACTIVATING_DEP si_deactivated [C20] REMOVING_S-BY_ASS - * DEACTIVATING_DEP si_deactivated [!C20]A12 TERMINATING_SUSP - * TERMINATING_SUSP su_state_chg [C103]A24,A20 ASS_S-BY_TO_SPARE - * TERMINATING_SUSP su_state_chg [C104]A24,A50 REMOVING_S-BY_ASS - * TERMINATING_SUSP su_state_chg [C105]A16,A17 ACTIVATING_S-BY - * TERMINATING_SUSP su_state_chg [C106]A20 ASS_S-BY_TO_SPARE - * TERMINATING_SUSP su_state_chg [C108]A23 REPAIRING_SU - * TERMINATING_SUSP su_state_chg [C109] IDLE - * TERMINATING_SUSP failover_su A52 TERMINATING_SUSP - * TERMINATING_SUSP failover_node A52 TERMINATING_SUSP - * REMOVING_S-BY_ASS assignment_removed A51 REMOVING_S-BY_ASS - * REMOVING_S-BY_ASS assignment_removed [C27]&[C24] ACTIVATING_S-BY - * REMOVING_S-BY_ASS assignment_removed [C110]A20 ASS_S-BY_TO_SPARE - * REMOVING_S-BY_ASS assignment_removed [C111]A23 REPAIRING_SU - * REMOVING_S-BY_ASS assignment_removed [C112] IDLE - * REMOVING_S-BY_ASS failover_su A52 REMOVING_S-BY_ASS - * REMOVING_S-BY_ASS failover_node A52 REMOVING_S-BY_ASS - * ACTIVATING_S-BY su_activated [C2]&[C11]A20 ASS_S-BY_TO_SPARE - * ACTIVATING_S-BY su_activated [C113]A23 REPAIRING_SU - * ACTIVATING_S-BY su_activated [C114] IDLE - * ACTIVATING_S-BY failover_su A52 ACTIVATING_S-BY - * ACTIVATING_S-BY failover_node A52 ACTIVATING_S-BY - * ASS_S-BY_TO_SPARE ha_state_assumed [C115]A23 REPAIRING_SU - * ASS_S-BY_TO_SPARE ha_state_assumed [C116] IDLE - * ASS_S-BY_TO_SPARE failover_su A52 ASS_S-BY_TO_SPARE - * ASS_S-BY_TO_SPARE failover_node A52 ASS_S-BY_TO_SPARE - * REPAIRING_SU su_state_chg [C28]A36,A37,A31 ASSIGNING_WL - * REPAIRING_SU su_state_chg [C28][C31] IDLE - * REPAIRING_SU failover_su A52 REPAIRING_SU - * REPAIRING_SU failover_node A52 REPAIRING_SU - * ASSIGNING_WL ha_state_assumed [C15] IDLE - * ASSIGNING_WL failover_su A52 ASSIGNING_WL - * ASSIGNING_WL failover_node A52 ASSIGNING_WL - * - * 1.2 State Description - * ===================== - * IDLE - SG is synchronized and idle. When IDLE state is set, - * the oldest deferred event (if any) is recalled. - * INSTANTIATING_SUs - INSTANTIATING_SERVICE_UNITS - * SG has ordered all contained SUs to instantiate and - * waits for the SUs to report a change of their - * presence state. SG is also prepared to accept an - * order to assign workload in this state. - * ASSIGNING_ON_REQ - ASSIGNING_ON_REQUEST - * SG has on request assigned workload to all service units - * on the requested dependency level and waits for SIs to - * indicate that the requested HA-state have been set to the - * appropriate components. - * TERMINATING_SUSP - TERMINATING_SUSPECTED - * SG has cleaned up all components suspected to be - * erroneous and waits for the concerned SUs to report a - * change of their presence states. - * REMOVING_S-BY_ASS - REMOVING_STANDBY_ASSIGNMENTS - * This state is only applicable to the n-plus-m redundancy - * model. In this state, SG has initiated the removal of - * those assignments from standby SUs that do not match the - * assignments of error suspected SUs. The reason for this - * removal is a preparation for not violating the rule which - * says an SU can not have both active and standby assign- - * ments simultaneously in the n-plus-m redundancy model. - * ACTIVATING_S-BY - ACTIVATING_STANDBY - * SG has located all standby SI-assignments in the recovery - * scope and ordered the corresponding SI to set the active - * HA-state and waits for SI to indicate that the requested - * HA-state has been set to the appropriate components. - * ASS_S-BY_TO_SPARE - ASSIGNING_STANDBY_TO_SPARE - * Current SG is configured with a spare SU. In this state, - * SG has requested all SIs to assign the standby HA-state - * to the spare SU and waits for the SIs to indicate that - * the standby HA-state have been set. - * REPAIRING_SU - REPAIRING_SU - * In this state SG has initiated instantiation of all SUs - * in current recovery scope until the configured preference - * of number of instantiated SUs is fulfiled. SG then waits - * for the concerned SUs to report a change of presence - * state. - * ASSIGNING_WL - ASSIGNING_WORKLOAD - * In this state SG has initiated the assignment of workload - * to all or a subset of its contained SUs and waits for the - * concerned SIs to indicated that the requested HA-state - * has been assumed. - * - * 1.3 Actions - * =========== - * A1 - - * A2 - - * A3 - - * A4 - - * A5 - - * A6 - - * A7 - - * A8 - - * A9 - - * A10 - [foreach SI in the scope]&[foreach SI-assignment with - * confirmed-HA-state == ACTIVE]/set requested-ha-state = QUIESCED - * A11 - [foreach SI in the scope]/deactivate SI - * A12 - [foreach suspected SU]/terminate all components - * A13 - - * A14 - - * A15 - - * A16 - [foreach SI in the scope]&[foreach SI-assignment with - * confirmed-HA-state == STANDBY]/set requested-ha-state = ACTIVE - * A17 - [foreach SI in the scope]/activate SI - * A18 - - * A19 - - * A20 - - * A21 - - * A22 - - * A23 - - * A24 - - * A25 - - * A26 - - * A27 - - * A28 - - * A29 - - * A30 - - * A31 - - * A32 - - * A33 - - * A34 - - * A35 - - * A36 - - * A37 - - * A38 - - * A39 - - * A40 - - * A41 - - * A42 - - * A43 - - * A44 - - * A45 - - * A46 - - * A47 - - * A48 - - * A49 - - - * - * 1.4 Composite Guards - * ==================== - * The meaning with these guards is just to save space in the state transition - * table above. - * C100 - [C7]&[!C22]&[C20] - * C101 - [C12]&[C28] - * C102 - [C13]&[C28] - * C103 - [C6]&[C21]&[C11] - * C104 - [C6]&[C25]&[C26] - * C105 - [C6]&(!([C25]|[C26]))&[C24] - * C106 - [C6]&(!([C25]|[C26]))&[!C24]&[C11] - * C107 - - * C108 - [C6]&(!([C25]|[C26]))&[!C24]&[!C11]&[C9]&[C10]&[!C30] - * C109 - [C6]&(!([C25]|[C26]))&[!C24]&[!C11]&[C9]&[C10]&[C30] - * C110 - [C27]&[!C24]&[C11] - * C111 - [C27]&[!C24]&[!C11]&[C9]&[C10]&[!C30] - * C112 - [C27]&[!C24]&[!C11]&[C9]&[C10]&[C30] - * C113 - [C2]&[!C11]&[C9]&[C10]&[!C30] - * C114 - [C2]&[!C11]&[C9]&[C10]&[C30] - * C115 - [C9]&[C10]&[!C30] - * C116 - [C9]&[C10]&[C30] - * - * 1.4 Guards - * ========== - * C1 - - * C2 - all SI in the recovery scope - * C3 - - * C4 - - * C5 - - * C6 - all supected SUs or components have presence state == UNINSTANTIATED - * or presence state == INSTANTIATION_FAILED - * C7 - original event == failover node - * C8 - - * C9 - original event == failover su - * C10 - SaAmfSGAutoRepair == true - * C11 - spare SUs exist - * C12 - original event == start(all SUs) - * C13 - original event == start(node) - * C14 - - * C15 - all SI-assignments on current dependency-level have requested-ha-state - == confirmed-ha-state or operation failed - * C16 - - * C17 - - * C18 - - * C19 - - * C20 - all suspected SUs have presence state == UNINSTANTIATED or - presence state == xx_FAILED - * C21 - no SI in the scope has an SI-assignment with HA-state == STANDBY - * C22 - the concerned entity has ACTIVE HA-state - * C23 - - * C24 - at least one SI-assignment related to an SI in the scope has HA-state - == STANDBY - * C25 - redundancy model == N plus M - * C26 - at least one SU has STANDBY assignments for more SIs than those SIs - that are within the recovery scope - * C27 - no SI-assignment related to SI protected by current SG has requested - HA-state == REMOVED - * C28 - no SU has presence state == INSTANTIATING - * C29 - - * C30 - more SUs not needed or the node hosting the SU to repair is disabled. - * C31 - no new additional assignments needed or possible - */ - -#include -#include -#include - -#include "amf.h" -#include "logsys.h" -#include "main.h" -#include "util.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -static int assign_si (struct amf_sg *sg, int dependency_level); -static void acsm_enter_activating_standby (struct amf_sg *sg); -static void delete_si_assignments_in_scope (struct amf_sg *sg); -static void acsm_enter_repairing_su (struct amf_sg *sg); -static void standby_su_activated_cbfn ( - struct amf_si_assignment *si_assignment, int result); -static void dependent_si_deactivated_cbfn ( - struct amf_si_assignment *si_assignment, int result); -static void dependent_si_deactivated_cbfn2 (struct amf_sg *sg); -static void assign_si_assumed_cbfn ( - struct amf_si_assignment *si_assignment, int result); -static void acsm_enter_removing_standby_assignments (amf_sg_t *sg); -static void acsm_enter_assigning_standby_to_spare (amf_sg_t *sg); - -static const char *sg_event_type_text[] = { - "Unknown", - "Failover SU", - "Failover node", - "Failover comp", - "Switchover node", - "Start", - "Autoadjust", - "Assign SI" -}; - -typedef struct sg_event { - amf_sg_event_type_t event_type; - amf_sg_t *sg; - amf_su_t *su; - amf_comp_t *comp; - amf_node_t *node; -} sg_event_t; - -/****************************************************************************** - * Internal (static) utility functions - *****************************************************************************/ - -static int is_cluster_start(amf_node_t *node_to_start) -{ - return node_to_start == NULL; -} - -static void sg_set_event (amf_sg_event_type_t sg_event_type, - amf_sg_t *sg, amf_su_t *su, amf_comp_t *comp, amf_node_t * node, - sg_event_t *sg_event) -{ - sg_event->event_type = sg_event_type; - sg_event->node = node; - sg_event->su = su; - sg_event->comp = comp; - sg_event->sg = sg; -} - -static void sg_defer_event (amf_sg_event_type_t event_type, - sg_event_t *sg_event) -{ - ENTER("Defered event = %d", event_type); - amf_fifo_put (event_type, &sg_event->sg->deferred_events, - sizeof (sg_event_t), - sg_event); -} - -static void sg_recall_deferred_events (amf_sg_t *sg) -{ - sg_event_t sg_event; - - ENTER ("%s", sg->name.value); - if (amf_fifo_get (&sg->deferred_events, &sg_event)) { - switch (sg_event.event_type) { - case SG_FAILOVER_SU_EV: - amf_sg_failover_su_req (sg_event.sg, - sg_event.su, sg_event.node); - break; - case SG_FAILOVER_NODE_EV: - amf_sg_failover_node_req (sg_event.sg, - sg_event.node); - break; - case SG_FAILOVER_COMP_EV: - case SG_SWITCH_OVER_NODE_EV: - case SG_START_EV: - case SG_AUTO_ADJUST_EV: - default: - dprintf("event_type = %d", sg_event.event_type); - break; - } - } -} - -static void timer_function_sg_recall_deferred_events (void *data) -{ - amf_sg_t *sg = (amf_sg_t*)data; - ENTER (""); - - sg_recall_deferred_events (sg); -} - -static void acsm_enter_idle (amf_sg_t *sg) -{ - SaNameT dn; - - ENTER ("sg: %s state: %d", sg->name.value, sg->avail_state); - - sg->avail_state = SG_AC_Idle; - if (sg->recovery_scope.event_type != 0) { - switch (sg->recovery_scope.event_type) { - case SG_FAILOVER_SU_EV: - assert (sg->recovery_scope.sus[0] != NULL); - amf_su_dn_make (sg->recovery_scope.sus[0], &dn); - log_printf ( - LOG_NOTICE, - "'%s' %s recovery action finished", - dn.value, - sg_event_type_text[sg->recovery_scope.event_type]); - - break; - case SG_FAILOVER_NODE_EV: - amf_node_sg_failed_over ( - sg->recovery_scope.node, sg); - log_printf ( - LOG_NOTICE, - "'%s for %s' recovery action finished", - sg_event_type_text[sg->recovery_scope.event_type], - sg->name.value); - break; - case SG_START_EV: - amf_application_sg_started (sg->application, - sg, this_amf_node); - break; - case SG_ASSIGN_SI_EV: - log_printf (LOG_NOTICE, "All SI assigned"); - break; - default: - log_printf ( - LOG_NOTICE, - "'%s' recovery action finished", - sg_event_type_text[sg->recovery_scope.event_type]); - break; - } - } - - if (sg->recovery_scope.sus != NULL) { - free ((void *)sg->recovery_scope.sus); - } - if (sg->recovery_scope.sis != NULL) { - free ((void *)sg->recovery_scope.sis); - } - memset (&sg->recovery_scope, 0, sizeof (struct sg_recovery_scope)); - sg->node_to_start = NULL; - - amf_call_function_asynchronous ( - timer_function_sg_recall_deferred_events, sg); -} - -static int su_instantiated_count (struct amf_sg *sg) -{ - int cnt = 0; - struct amf_su *su; - - for (su = sg->su_head; su != NULL; su = su->next) { - if (su->saAmfSUPresenceState == SA_AMF_PRESENCE_INSTANTIATED) - cnt++; - } - - return cnt; -} - -static int has_any_su_in_scope_active_workload (struct amf_sg *sg) -{ - struct amf_su **sus= sg->recovery_scope.sus; - struct amf_si_assignment *si_assignment; - - while (*sus != NULL) { - si_assignment = amf_su_get_next_si_assignment (*sus, NULL); - while (si_assignment != NULL) { - if (si_assignment->saAmfSISUHAState != - SA_AMF_HA_ACTIVE) { - break; - } - si_assignment = amf_su_get_next_si_assignment ( - *sus, si_assignment); - } - if (si_assignment != NULL) { - break; - } - sus++; - } - return(*sus == NULL); -} - -static int is_any_si_in_scope_assigned_standby (struct amf_sg *sg) -{ - struct amf_si **sis= sg->recovery_scope.sis; - struct amf_si_assignment *si_assignment; - - /* - * Check if there is any si in the scope which has no - * active assignment and at least one standby assignment. - */ - while (*sis != NULL) { - si_assignment = (*sis)->assigned_sis; - while (si_assignment != NULL) { - if (si_assignment->saAmfSISUHAState == - SA_AMF_HA_ACTIVE) { - break; - } - si_assignment = si_assignment->next; - } - if (si_assignment == NULL) { - /* There is no ACTIVE assignment ..*/ - si_assignment = (*sis)->assigned_sis; - while (si_assignment != NULL) { - if (si_assignment->saAmfSISUHAState == - SA_AMF_HA_STANDBY) { - break; - } - si_assignment = si_assignment->next; - } - if (si_assignment != NULL) { - /* .. and one STANDBY assignment*/ - break; - } - } - sis++; - } - return(*sis != NULL); -} - - -static void acsm_enter_terminating_suspected (struct amf_sg *sg) -{ - struct amf_su **sus= sg->recovery_scope.sus; - ENTER("%s",sg->name.value); - sg->avail_state = SG_AC_TerminatingSuspected; - /* - * Terminate suspected SU(s) - */ - while (*sus != 0) { - amf_su_terminate (*sus); - sus++; - } -} - -static inline int su_presense_state_is_ored (amf_su_t *su, - SaAmfPresenceStateT state1,SaAmfPresenceStateT state2, - SaAmfPresenceStateT state3) -{ - return(su->saAmfSUPresenceState == state1 || su->saAmfSUPresenceState == - state2 || su->saAmfSUPresenceState == state3) ? 1 : 0; -} - -static inline int su_presense_state_is_not (amf_su_t *su, - SaAmfPresenceStateT state1,SaAmfPresenceStateT state2, - SaAmfPresenceStateT state3) -{ - return(su->saAmfSUPresenceState != state1 && su->saAmfSUPresenceState != - state2 && su->saAmfSUPresenceState != state3) ? 1 : 0; -} - - -static void timer_function_dependent_si_deactivated2 (void *data) -{ - amf_sg_t *sg = (amf_sg_t *)data; - - ENTER (""); - dependent_si_deactivated_cbfn2 (sg); -} - - -static struct amf_si *si_get_dependent (struct amf_si *si) -{ - struct amf_si *tmp_si = NULL; - - if (si->depends_on != NULL) { - SaNameT res_arr[2]; - int is_match; - - if (si->depends_on->name.length < SA_MAX_NAME_LENGTH) { - si->depends_on->name.value[si->depends_on->name.length] = '\0'; - } - - is_match = sa_amf_grep ((char*)si->depends_on->name.value, - "safDepend=.*,safSi=(.*),safApp=.*", - 2, res_arr); - - if (is_match) { - tmp_si = amf_si_find (si->application, (char*)res_arr[1].value); - } else { - log_printf (LOG_LEVEL_ERROR, "distinguished name for " - "amf_si_depedency failed\n"); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - } - - return tmp_si; -} - -static struct amf_si *amf_dependent_get_next (struct amf_si *si, - struct amf_si *si_iter) -{ - struct amf_si *tmp_si; - struct amf_application *application; - - if (si_iter == NULL) { - assert(amf_cluster != NULL); - application = amf_cluster->application_head; - assert(application != NULL); - tmp_si = application->si_head; - } else { - tmp_si = si_iter->next; - if (tmp_si == NULL) { - application = si->application->next; - if (application == NULL) { - goto out; - } - } - } - - for (; tmp_si != NULL; tmp_si = tmp_si->next) { - struct amf_si *depends_on_si = si_get_dependent (tmp_si); - while (depends_on_si != NULL) { - if (depends_on_si == si) { - goto out; - } - depends_on_si = depends_on_si->next; - } - } - -out: - return tmp_si; -} - -static void acsm_enter_deactivating_dependent_workload (amf_sg_t *sg) -{ - struct amf_si **sis= sg->recovery_scope.sis; - struct amf_si_assignment *si_assignment; - int callback_pending = 0; - - sg->avail_state = SG_AC_DeactivatingDependantWorkload; - - ENTER("'%s'",sg->name.value); - /* - * For each SI in the recovery scope, find all active - * assignments and request them to be deactivated. - */ - while (*sis != NULL) { - struct amf_si *dependent_si; - struct amf_si *si = *sis; - si_assignment = si->assigned_sis; - dependent_si = amf_dependent_get_next (si, NULL); - - while (dependent_si != NULL) { - si_assignment = dependent_si->assigned_sis; - - while (si_assignment != NULL) { - - if (si_assignment->saAmfSISUHAState == - SA_AMF_HA_ACTIVE) { - si_assignment->requested_ha_state = - SA_AMF_HA_QUIESCED; - callback_pending = 1; - amf_si_ha_state_assume ( - si_assignment, - dependent_si_deactivated_cbfn); - } - si_assignment = si_assignment->next; - } - dependent_si = amf_dependent_get_next (si, dependent_si); - } - sis++; - } - - if (callback_pending == 0) { - static poll_timer_handle dependent_si_deactivated_handle; - ENTER(""); - poll_timer_add (aisexec_poll_handle, 0, sg, - timer_function_dependent_si_deactivated2, - &dependent_si_deactivated_handle); - } -} -/** - * Enter function for state SG_AC_ActivatingStandby. It activates - * one STANDBY assignment for each SI in the recovery scope. - * @param sg - */ -static void acsm_enter_activating_standby (struct amf_sg *sg) -{ - struct amf_si **sis= sg->recovery_scope.sis; - struct amf_si_assignment *si_assignment; - int is_no_standby_activated = 1; - - ENTER("'%s'",sg->name.value); - sg->avail_state = SG_AC_ActivatingStandby; - - /* - * For each SI in the recovery scope, find one standby - * SI assignment and activate it. - */ - while (*sis != NULL) { - si_assignment = (*sis)->assigned_sis; - while (si_assignment != NULL) { - if (si_assignment->saAmfSISUHAState == - SA_AMF_HA_STANDBY) { - si_assignment->requested_ha_state = - SA_AMF_HA_ACTIVE; - amf_si_ha_state_assume ( - si_assignment, standby_su_activated_cbfn); - is_no_standby_activated = 0; - break; - } - si_assignment = si_assignment->next; - } - sis++; - } - - if (is_no_standby_activated) { - - acsm_enter_assigning_standby_to_spare (sg); - } -} - -static void acsm_enter_repairing_su (struct amf_sg *sg) -{ - struct amf_su **sus= sg->recovery_scope.sus; - int is_any_su_instantiated = 0; - const int PERFORMS_INSTANTIATING = 1; - - ENTER("'%s'",sg->name.value); - sg->avail_state = SG_AC_ReparingSu; - /* - * Instantiate SUs in current recovery scope until the configured - * preference is fulfiled. - */ - while (*sus != NULL) { - if (su_instantiated_count ((*sus)->sg) < - (*sus)->sg->saAmfSGNumPrefInserviceSUs) { - struct amf_node *node = - amf_node_find(&((*sus)->saAmfSUHostedByNode)); - if (node == NULL) { - log_printf (LOG_LEVEL_ERROR, - "Su to recover not hosted on any node\n"); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - if (node->saAmfNodeOperState == SA_AMF_OPERATIONAL_ENABLED) { - /* node is synchronized */ - - if (amf_su_instantiate ((*sus)) == PERFORMS_INSTANTIATING) { - is_any_su_instantiated = 1; - } - } - } - sus++; - } - - if (is_any_su_instantiated == 0) { - acsm_enter_idle (sg); - } -} - -static inline void remove_all_suspected_sus (amf_sg_t *sg) -{ - amf_su_t *su; - ENTER(""); - for (su = sg->su_head; su != NULL; su =su->next) { - - amf_comp_t *component; - - for (component = su->comp_head; component != NULL; - component = component->next) { - - amf_comp_error_suspected_clear (component); - } - } -} -static int is_all_si_assigned (amf_sg_t *sg) -{ - struct amf_si_assignment *si_assignment; - int si_assignment_cnt = 0; - int confirmed_assignments = 0; - amf_si_t *si; - - for (si = sg->application->si_head; si != NULL; si = si->next) { - if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) { - - for (si_assignment = si->assigned_sis; - si_assignment != NULL; - si_assignment = si_assignment->next) { - - si_assignment_cnt++; - if (si_assignment->requested_ha_state == - si_assignment->saAmfSISUHAState) { - - confirmed_assignments++; - } - } - } - } - return (confirmed_assignments == si_assignment_cnt); -} - -/** - * Inquire if SI is assigned to SU - * @param si - * @param su - * - * @return int - */ -static int is_si_assigned_to_su (amf_si_t *si, amf_su_t *su) -{ - amf_si_assignment_t *si_assignment = 0; - int si_assignment_assigned_to_su = 0; - - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - - if (si_assignment->su == su) { - si_assignment_assigned_to_su = 1; - break; - } - } - return si_assignment_assigned_to_su; -} - -/** - * Inquire if SU is a spare. - * @param sg - * @param su - * - * @return int - */ -static int is_spare_su (amf_sg_t *sg, amf_su_t *su) -{ - amf_si_t *si; - int spare_su = 1; - for (si = sg->application->si_head; si != NULL; si = si->next) { - if(name_match(&sg->name, &si->saAmfSIProtectedbySG)) { - if (is_si_assigned_to_su (si, su)) { - - spare_su = 0; - break; - } - } - } - return (spare_su && su->saAmfSUPresenceState == - SA_AMF_PRESENCE_INSTANTIATED); -} -/** - * Inqure if it is any spare SUs covered by SG - * @param sg - * - * @return int - */ -static int is_spare_sus (amf_sg_t *sg) -{ - amf_su_t *su = NULL; - int spare_sus = 0; - - for (su = sg->su_head; su != NULL; su = su->next) { - - if (is_spare_su(sg, su)) { - spare_sus = 1; - break; - } - } - return spare_sus; -} - -/** - * Provide standby assignments for the spare SUs in SG - * @param sg - */ -static void assume_standby_si_assignment_for_spare_sus (amf_sg_t *sg) -{ - ENTER(""); - - assign_si (sg, 0); -} - -/** - * Enter the AssigningStandbyToSpare state. - * @param sg - */ -static void acsm_enter_assigning_standby_to_spare (amf_sg_t *sg) -{ - ENTER("%s", sg->name.value); - - sg->avail_state = SG_AC_AssigningStandbyToSpare; - if (is_spare_sus (sg)) { - assume_standby_si_assignment_for_spare_sus (sg); - } else { - switch (sg->recovery_scope.event_type) { - case SG_FAILOVER_NODE_EV: - acsm_enter_idle (sg); - break; - case SG_FAILOVER_SU_EV: - acsm_enter_repairing_su (sg); - break; - default: - dprintf("event_type %d",sg->recovery_scope.event_type); - assert (0); - break; - } - } -} - -/** - * Checks if the si pointed out is already in the scope. - * @param sg - * @param si - */ -static int is_si_in_scope(struct amf_sg *sg, struct amf_si *si) -{ - struct amf_si **tmp_sis= sg->recovery_scope.sis; - - while (*tmp_sis != NULL) { - if (*tmp_sis == si) { - break; - } - tmp_sis++; - } - return(*tmp_sis == si); -} - -/** - * Adds the si pointed out to the scope. - * @param sg - * @param si - */ -static void add_si_to_scope ( struct amf_sg *sg, struct amf_si *si) -{ - int number_of_si = 2; /* It shall be at least two */ - struct amf_si **tmp_sis= sg->recovery_scope.sis; - - ENTER ("'%s'", si->name.value); - - while (*tmp_sis != NULL) { - number_of_si++; - tmp_sis++; - } - - sg->recovery_scope.sis = (struct amf_si **) - realloc((void *)sg->recovery_scope.sis, - sizeof (struct amf_si *)*number_of_si); - assert (sg->recovery_scope.sis != NULL); - - tmp_sis= sg->recovery_scope.sis; - while (*tmp_sis != NULL) { - tmp_sis++; - } - - *tmp_sis = si; - *(++tmp_sis) = NULL; -} - -/** - * Adds the ssu pointed out to the scope. - * @param sg - * @param su - */ -static void add_su_to_scope (struct amf_sg *sg, struct amf_su *su) -{ - int number_of_su = 2; /* It shall be at least two */ - struct amf_su **tmp_sus= sg->recovery_scope.sus; - - ENTER ("'%s'", su->name.value); - while (*tmp_sus != NULL) { - number_of_su++; - tmp_sus++; - } - sg->recovery_scope.sus = (struct amf_su **) - realloc((void *)sg->recovery_scope.sus, - sizeof (struct amf_su *)*number_of_su); - assert (sg->recovery_scope.sus != NULL); - - tmp_sus= sg->recovery_scope.sus; - while (*tmp_sus != NULL) { - tmp_sus++; - } - - *tmp_sus = su; - *(++tmp_sus) = NULL; -} - -/** - * Set recovery scope for failover SU. - * @param sg - * @param su - */ - -static void set_scope_for_failover_su (struct amf_sg *sg, struct amf_su *su) -{ - struct amf_si_assignment *si_assignment; - struct amf_si **sis; - struct amf_su **sus; - SaNameT dn; - - sg->recovery_scope.event_type = SG_FAILOVER_SU_EV; - sg->recovery_scope.node = NULL; - sg->recovery_scope.comp = NULL; - sg->recovery_scope.sus = (struct amf_su **) - calloc (2, sizeof (struct amf_su *)); - sg->recovery_scope.sis = (struct amf_si **) - calloc (1, sizeof (struct amf_si *)); - - assert ((sg->recovery_scope.sus != NULL) && - (sg->recovery_scope.sis != NULL)); - sg->recovery_scope.sus[0] = su; - - amf_su_dn_make (sg->recovery_scope.sus[0], &dn); - log_printf ( - LOG_NOTICE, "'%s' for %s recovery action started", - sg_event_type_text[sg->recovery_scope.event_type], - dn.value); - - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - if (is_si_in_scope(sg, si_assignment->si) == 0) { - add_si_to_scope(sg,si_assignment->si ); - } - si_assignment = amf_su_get_next_si_assignment (su, si_assignment); - } - - sus = sg->recovery_scope.sus; - dprintf("The following sus are within the scope:\n"); - while (*sus != NULL) { - dprintf("%s\n", (*sus)->name.value); - sus++; - } - sis= sg->recovery_scope.sis; - dprintf("The following sis are within the scope:\n"); - while (*sis != NULL) { - dprintf("%s\n", (*sis)->name.value); - sis++; - } -} - -static void set_scope_for_failover_node (struct amf_sg *sg, struct amf_node *node) -{ - struct amf_si_assignment *si_assignment; - struct amf_si **sis; - struct amf_su **sus; - struct amf_su *su; - - ENTER ("'%s'", node->name.value); - sg->recovery_scope.event_type = SG_FAILOVER_NODE_EV; - sg->recovery_scope.node = node; - sg->recovery_scope.comp = NULL; - sg->recovery_scope.sus = (struct amf_su **) - calloc (1, sizeof (struct amf_su *)); - sg->recovery_scope.sis = (struct amf_si **) - calloc (1, sizeof (struct amf_si *)); - - log_printf ( - LOG_NOTICE, "'%s' for node %s recovery action started", - sg_event_type_text[sg->recovery_scope.event_type], - node->name.value); - - assert ((sg->recovery_scope.sus != NULL) && - (sg->recovery_scope.sis != NULL)); - for (su = sg->su_head; su != NULL; su = su->next) { - if (name_match (&node->name, &su->saAmfSUHostedByNode)) { - add_su_to_scope (sg, su); - } - } - - sus = sg->recovery_scope.sus; - while (*sus != 0) { - su = *sus; - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - if (is_si_in_scope(sg, si_assignment->si) == 0) { - add_si_to_scope(sg, si_assignment->si ); - } - si_assignment = amf_su_get_next_si_assignment ( - su, si_assignment); - } - sus++; - } - - sus = sg->recovery_scope.sus; - dprintf("The following sus are within the scope:\n"); - while (*sus != NULL) { - dprintf("%s\n", (*sus)->name.value); - sus++; - } - sis = sg->recovery_scope.sis; - dprintf("The following sis are within the scope:\n"); - while (*sis != NULL) { - dprintf("%s\n", (*sis)->name.value); - sis++; - } -} - -static void delete_si_assignment (amf_si_assignment_t *si_assignment) -{ - amf_csi_t *csi; - amf_si_assignment_t *si_assignment_tmp; - amf_si_assignment_t **prev = &si_assignment->si->assigned_sis; - - for (csi = si_assignment->si->csi_head; csi != NULL; csi = csi->next) { - amf_csi_delete_assignments (csi, si_assignment->su); - } - - for (si_assignment_tmp = si_assignment->si->assigned_sis; - si_assignment_tmp != NULL; - si_assignment_tmp = si_assignment_tmp->next) { - - if (si_assignment_tmp == si_assignment) { - - amf_si_assignment_t *to_be_removed = si_assignment_tmp; - *prev = si_assignment_tmp->next; - dprintf ("SI assignment %s unlinked", - to_be_removed->name.value); - free (to_be_removed); - } else { - prev = &si_assignment_tmp->next; - } - } -} - -/** - * Delete all SI assignments and all CSI assignments - * by requesting all contained components. - * @param su - */ -static void delete_si_assignments (struct amf_su *su) -{ - struct amf_csi *csi; - struct amf_si *si; - struct amf_si_assignment *si_assignment; - struct amf_si_assignment **prev; - - ENTER ("'%s'", su->name.value); - - for (si = su->sg->application->si_head; si != NULL; si = si->next) { - - prev = &si->assigned_sis; - - if (!name_match (&si->saAmfSIProtectedbySG, &su->sg->name)) { - continue; - } - - for (csi = si->csi_head; csi != NULL; csi = csi->next) { - amf_csi_delete_assignments (csi, su); - } - - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - if (si_assignment->su == su) { - struct amf_si_assignment *tmp = si_assignment; - *prev = si_assignment->next; - dprintf ("SI assignment %s unlinked", tmp->name.value); - free (tmp); - } else { - prev = &si_assignment->next; - } - } - } -} - -/** - * Delete all SI assignments and all CSI assignments in current - * recovery scope. - * @param sg - */ -static void delete_si_assignments_in_scope (struct amf_sg *sg) -{ - struct amf_su **sus= sg->recovery_scope.sus; - - while (*sus != NULL) { - delete_si_assignments (*sus); - sus++; - } -} - -/** - * Given an SI, find and return the SU assigned as standby - * @param si - * - * @return amf_su_t* - */ -static amf_su_t *find_standby_su (amf_si_t *si) -{ - amf_si_assignment_t *si_assignment; - amf_su_t *standby_su = NULL; - - si_assignment = si->assigned_sis; - while (si_assignment != NULL) { - if (si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) { - standby_su = si_assignment->su; - break; - } - si_assignment = si_assignment->next; - } - - return standby_su; -} - -static int no_si_assignment_is_requested_to_be_removed (amf_sg_t *sg) -{ - amf_si_t *si; - int no_to_be_removed = 1; - - for (si = sg->application->si_head; si != NULL; si = si->next) { - - if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) { - amf_si_assignment_t *si_assignment = 0; - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - if (si_assignment->requested_ha_state == - USR_AMF_HA_STATE_REMOVED) { - - no_to_be_removed = 0; - goto out; - } - } - } - } -out: - return no_to_be_removed; -} - -static void removed_si_assignment_callback_fn (void *si_assignment_in) -{ - amf_si_assignment_t *si_assignment = si_assignment_in; - - ENTER(""); - delete_si_assignment (si_assignment); - - /* - * if all si assignments are remove then change state - */ - if (no_si_assignment_is_requested_to_be_removed (si_assignment->su->sg)) { - acsm_enter_activating_standby (si_assignment->su->sg); - } -} - -/** - * - * @param sg - * - * @return int, number of removed SI assignments - */ -static int remove_standby_si_assignments (amf_sg_t *sg) -{ - struct amf_si **sis = sg->recovery_scope.sis; - struct amf_si_assignment *si_assignment; - amf_su_t *standby_su; - int removed = 0; - - ENTER("'%s'", sg->name.value); - - /* - * For each SI in the recovery scope, find a standby - * SU, then remove all 'standby SI assignment' not in - * the recovery scope. - */ - while (*sis != NULL) { - standby_su = find_standby_su (*sis); - if (standby_su != NULL) { - si_assignment = amf_su_get_next_si_assignment (standby_su, NULL); - while (si_assignment != NULL) { - - amf_si_t **sia; - int in_recovery_scope; - - for (sia = sg->recovery_scope.sis, in_recovery_scope = 0; - *sia != NULL; sia++) { - if (name_match (&si_assignment->si->name, &(*sia)->name)) { - in_recovery_scope = 1; - } - } - - /* - * The si_assignment found with standby hastate is not in the - * recovery scope. The found si_assignment will then be - * requested to be removed once. - */ - if (!in_recovery_scope && - si_assignment->requested_ha_state != - USR_AMF_HA_STATE_REMOVED) { - - amf_si_assignment_remove (si_assignment, - removed_si_assignment_callback_fn); - removed++; - } - si_assignment = amf_su_get_next_si_assignment (standby_su, - si_assignment); - } - } - sis++; - } - - return removed; -} - -/** - * Entry function for state 'removing standby assignments' - * @param sg - */ -static void acsm_enter_removing_standby_assignments (amf_sg_t *sg) -{ - ENTER("SG: %s", sg->name.value); - sg->avail_state = SG_AC_RemovingStandbyAssignments; - - if (sg->saAmfSGRedundancyModel == SA_AMF_NPM_REDUNDANCY_MODEL) { - if (!remove_standby_si_assignments (sg)) { - acsm_enter_activating_standby (sg); - } - } -} - -static inline int div_round (int a, int b) -{ - int res; - - assert (b != 0); - res = a / b; - if ((a % b) != 0) - res++; - return res; -} - -static int no_su_has_presence_state ( - struct amf_sg *sg, struct amf_node *node_to_start, - SaAmfPresenceStateT state) -{ - struct amf_su *su; - int no_su_has_presence_state = 1; - - for (su = sg->su_head; su != NULL; su = su->next) { - - if (su->saAmfSUPresenceState == state) { - if (node_to_start == NULL) { - no_su_has_presence_state = 0; - break; - } else { - if (name_match(&node_to_start->name, - &su->saAmfSUHostedByNode)) { - no_su_has_presence_state = 0; - break; - } - } - } - } - - return no_su_has_presence_state; -} - -#if COMPILE_OUT -static int all_su_in_scope_has_presence_state ( - struct amf_sg *sg, SaAmfPresenceStateT state) -{ - struct amf_su **sus= sg->recovery_scope.sus; - - while (*sus != NULL) { - if ((*sus)->saAmfSUPresenceState != state) { - break; - } - sus++; - } - return(*sus == NULL); -} -#endif -static int all_su_in_scope_has_either_two_presence_state ( - amf_sg_t *sg, - SaAmfPresenceStateT state1, - SaAmfPresenceStateT state2) -{ - struct amf_su **sus = sg->recovery_scope.sus; - - while (*sus != NULL) { - if (!((*sus)->saAmfSUPresenceState == state1 || - (*sus)->saAmfSUPresenceState == state2)) { - break; - } - sus++; - } - return (*sus == NULL); -} - - -static int all_su_in_scope_has_either_of_three_presence_state (amf_sg_t *sg, - SaAmfPresenceStateT state1, SaAmfPresenceStateT state2, - SaAmfPresenceStateT state3) -{ - struct amf_su **sus = sg->recovery_scope.sus; - - while (*sus != NULL) { - if (!((*sus)->saAmfSUPresenceState == state1 || - (*sus)->saAmfSUPresenceState == state2 || - (*sus)->saAmfSUPresenceState == state3)) { - break; - } - sus++; - } - return (*sus == NULL); -} - - - -/** - * Get number of SIs protected by the specified SG. - * @param sg - * - * @return int - */ -static int sg_si_count_get (struct amf_sg *sg) -{ - struct amf_si *si; - int cnt = 0; - - for (si = sg->application->si_head; si != NULL; si = si->next) { - if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) { - cnt += 1; - } - } - return(cnt); -} - -static int amf_si_get_saAmfSINumReqActiveAssignments(struct amf_si *si) -{ - struct amf_si_assignment *si_assignment = si->assigned_sis; - int number_of_req_active_assignments = 0; - - for (; si_assignment != NULL; si_assignment = si_assignment->next) { - - if (si_assignment->requested_ha_state == SA_AMF_HA_ACTIVE) { - number_of_req_active_assignments++; - } - } - return number_of_req_active_assignments; -} - -static int amf_si_get_saAmfSINumReqStandbyAssignments(struct amf_si *si) -{ - struct amf_si_assignment *si_assignment = si->assigned_sis; - int number_of_req_active_assignments = 0; - - for (; si_assignment != NULL; si_assignment = si_assignment->next) { - if (si_assignment->requested_ha_state == SA_AMF_HA_STANDBY) { - number_of_req_active_assignments++; - } - } - return number_of_req_active_assignments; -} - -static int sg_assign_active_nplusm (struct amf_sg *sg, int su_active_assign) -{ - struct amf_su *su; - struct amf_si *si; - int assigned = 0; - int assign_to_su = 0; - int total_assigned = 0; - int si_left; - int si_total; - int su_left_to_assign = su_active_assign; - ENTER("SG: %s", sg->name.value); - - si_total = sg_si_count_get (sg); - si_left = si_total; - assign_to_su = div_round (si_left, su_active_assign); - if (assign_to_su > sg->saAmfSGMaxActiveSIsperSUs) { - assign_to_su = sg->saAmfSGMaxActiveSIsperSUs; - } - - su = sg->su_head; - while (su != NULL && su_left_to_assign > 0) { - if (amf_su_get_saAmfSUReadinessState (su) != - SA_AMF_READINESS_IN_SERVICE || - amf_su_get_saAmfSUNumCurrActiveSIs (su) == assign_to_su || - amf_su_get_saAmfSUNumCurrStandbySIs (su) > 0) { - - su = su->next; - continue; /* Not in service */ - } - - si = sg->application->si_head; - assigned = 0; - assign_to_su = div_round (si_left, su_left_to_assign); - if (assign_to_su > sg->saAmfSGMaxActiveSIsperSUs) { - assign_to_su = sg->saAmfSGMaxActiveSIsperSUs; - } - while (si != NULL) { - if (name_match (&si->saAmfSIProtectedbySG, &sg->name) && - assigned < assign_to_su && - amf_si_get_saAmfSINumReqActiveAssignments(si) == 0) { - assigned += 1; - total_assigned += 1; - amf_su_assign_si (su, si, SA_AMF_HA_ACTIVE); - } - - si = si->next; - } - su = su->next; - su_left_to_assign -= 1; - si_left -= assigned; - dprintf (" su_left_to_assign =%d, si_left=%d\n", - su_left_to_assign, si_left); - } - - assert (total_assigned <= si_total); - if (total_assigned == 0) { - dprintf ("Info: No SIs assigned"); - } - - return total_assigned; -} - -static int sg_assign_standby_nplusm (struct amf_sg *sg, int su_standby_assign) -{ - struct amf_su *su; - struct amf_si *si; - int assigned = 0; - int assign_to_su = 0; - int total_assigned = 0; - int si_left; - int si_total; - int su_left_to_assign = su_standby_assign; - - ENTER ("'%s'", sg->name.value); - - if (su_standby_assign == 0) { - return 0; - } - si_total = sg_si_count_get (sg); - si_left = si_total; - assign_to_su = div_round (si_left, su_standby_assign); - if (assign_to_su > sg->saAmfSGMaxStandbySIsperSUs) { - assign_to_su = sg->saAmfSGMaxStandbySIsperSUs; - } - - su = sg->su_head; - while (su != NULL && su_left_to_assign > 0) { - if (amf_su_get_saAmfSUReadinessState (su) != - SA_AMF_READINESS_IN_SERVICE || - amf_su_get_saAmfSUNumCurrActiveSIs (su) > 0 || - amf_su_get_saAmfSUNumCurrStandbySIs (su) == - assign_to_su) { - - su = su->next; - continue; /* Not available for assignment */ - } - - si = sg->application->si_head; - assigned = 0; - assign_to_su = div_round (si_left, su_left_to_assign); - if (assign_to_su > sg->saAmfSGMaxStandbySIsperSUs) { - assign_to_su = sg->saAmfSGMaxStandbySIsperSUs; - } - while (si != NULL) { - if (name_match (&si->saAmfSIProtectedbySG, &sg->name) && - assigned < assign_to_su && - amf_si_get_saAmfSINumReqStandbyAssignments (si) == 0) { - assigned += 1; - total_assigned += 1; - amf_su_assign_si (su, si, SA_AMF_HA_STANDBY); - } - si = si->next; - } - su_left_to_assign -= 1; - si_left -= assigned; - dprintf (" su_left_to_assign =%d, si_left=%d\n", - su_left_to_assign, si_left); - - su = su->next; - } - - assert (total_assigned <= si_total); - if (total_assigned == 0) { - dprintf ("Info: No SIs assigned!"); - } - - return total_assigned; -} - -static int su_inservice_count_get (struct amf_sg *sg) -{ - struct amf_su *su; - int answer = 0; - - for (su = sg->su_head; su != NULL; su = su->next) { - if (amf_su_get_saAmfSUReadinessState (su) == - SA_AMF_READINESS_IN_SERVICE) { - - answer += 1; - } - } - return(answer); -} - -static int su_active_out_of_service_count_get (amf_sg_t *sg) -{ - int active_out_of_service_count = 0; - amf_su_t *su; - for (su = sg->su_head; su != NULL; su = su->next) { - amf_si_assignment_t *si_assignment; - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - if ((si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) && - (amf_su_get_saAmfSUReadinessState (su) == - SA_AMF_READINESS_OUT_OF_SERVICE)) { - active_out_of_service_count += 1; - } - si_assignment = amf_su_get_next_si_assignment (su, si_assignment); - } - } - return active_out_of_service_count; -} - - -static int su_standby_out_of_service_count_get (amf_sg_t *sg) -{ - int active_out_of_service_count = 0; - amf_su_t *su; - for (su = sg->su_head; su != NULL; su = su->next) { - amf_si_assignment_t *si_assignment; - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - if ((si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) && - (amf_su_get_saAmfSUReadinessState (su) == - SA_AMF_READINESS_OUT_OF_SERVICE)) { - active_out_of_service_count += 1; - } - si_assignment = amf_su_get_next_si_assignment (su, si_assignment); - } - } - return active_out_of_service_count; -} - -/** - * This function calculates the number of active and standby assignments that - * shall be done according to what is configured and the number of in-service - * SUs available. This function leaves possible existing assignments as they are - * but possibly adds new assignments. This function also initiates the transfer - * of the calculated assignments to the SUs that shall execute them. - * - * TODO: dependency_level not used, hard coded - * @param sg - * @param dependency_level - * @return - the sum of assignments initiated - */ -static int assign_si (struct amf_sg *sg, int dependency_level) -{ - int active_sus_needed = 0; - int standby_sus_needed = 0; - int inservice_count; - int su_active_assign; - int su_standby_assign; - int su_spare_assign; - int assigned = 0; - int active_out_of_service = 0; - int standby_out_of_service = 0; - ENTER ("'%s'", sg->name.value); - - /** - * Phase 1: Calculate assignments and create all runtime objects in - * information model. Do not do the actual assignment, done in - * phase 2. - */ - - /** - * Calculate number of SUs to assign to active or standby state - */ - inservice_count = su_inservice_count_get (sg); - active_out_of_service = su_active_out_of_service_count_get(sg); - standby_out_of_service = su_standby_out_of_service_count_get(sg); - if (sg->saAmfSGNumPrefActiveSUs > 0) { - - active_sus_needed = div_round ( - sg_si_count_get (sg), - sg->saAmfSGMaxActiveSIsperSUs); - } else { - log_printf (LOG_LEVEL_ERROR, "ERROR: saAmfSGNumPrefActiveSUs == 0 !!"); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - - if (sg->saAmfSGNumPrefStandbySUs > 0) { - standby_sus_needed = div_round ( - sg_si_count_get (sg), - sg->saAmfSGMaxStandbySIsperSUs); - } else { - log_printf (LOG_LEVEL_ERROR, "ERROR: saAmfSGNumPrefStandbySUs == 0 !!"); - openais_exit_error (AIS_DONE_FATAL_ERR); - - } - - dprintf ("(inservice=%d) (active_sus_needed=%d) (standby_sus_needed=%d)" - "\n", - inservice_count, active_sus_needed, standby_sus_needed); - - /* Determine number of active and standby service units - * to assign based upon reduction procedure - */ - if ((inservice_count < active_sus_needed - active_out_of_service)) { - dprintf ("assignment VI - partial assignment with SIs drop outs\n"); - - su_active_assign = inservice_count; - su_standby_assign = 0; - su_spare_assign = 0; - } else - if ((inservice_count < active_sus_needed - active_out_of_service + - standby_sus_needed)) { - dprintf ("assignment V - partial assignment with reduction of" - " standby units\n"); - - su_active_assign = active_sus_needed; - su_standby_assign = inservice_count - active_sus_needed - active_out_of_service; - su_spare_assign = 0; - } else - if ((inservice_count < sg->saAmfSGNumPrefActiveSUs + standby_sus_needed)) { - 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 ((inservice_count < - sg->saAmfSGNumPrefActiveSUs + sg->saAmfSGNumPrefStandbySUs)) { - dprintf ("III: full assignment with reduction of standby service" - " units\n"); - su_active_assign = sg->saAmfSGNumPrefActiveSUs; - su_standby_assign = inservice_count - sg->saAmfSGNumPrefActiveSUs; - su_spare_assign = 0; - } else - if ((inservice_count == - sg->saAmfSGNumPrefActiveSUs + sg->saAmfSGNumPrefStandbySUs)) { - if (sg->saAmfSGNumPrefInserviceSUs > inservice_count) { - dprintf ("II: full assignment with spare reduction\n"); - } else { - dprintf ("II: full assignment without spares\n"); - } - - su_active_assign = sg->saAmfSGNumPrefActiveSUs; - su_standby_assign = sg->saAmfSGNumPrefStandbySUs; - su_spare_assign = 0; - } else { - dprintf ("I: full assignment with spares\n"); - su_active_assign = sg->saAmfSGNumPrefActiveSUs; - su_standby_assign = sg->saAmfSGNumPrefStandbySUs; - su_spare_assign = inservice_count - - sg->saAmfSGNumPrefActiveSUs - sg->saAmfSGNumPrefStandbySUs; - } - - dprintf ("(inservice=%d) (assigning active=%d) (assigning standby=%d)" - " (assigning spares=%d)\n", - inservice_count, su_active_assign, su_standby_assign, su_spare_assign); - - if (inservice_count > 0) { - assigned = sg_assign_active_nplusm (sg, su_active_assign); - assigned += sg_assign_standby_nplusm (sg, su_standby_assign); - sg->saAmfSGNumCurrAssignedSUs = inservice_count; - - /** - * Phase 2: do the actual assignment to the component - * TODO: first do active, then standby - */ - { - struct amf_si *si; - struct amf_si_assignment *si_assignment; - - for (si = sg->application->si_head; si != NULL; si = si->next) { - if (name_match (&si->saAmfSIProtectedbySG, &sg->name)) { - for (si_assignment = si->assigned_sis; - si_assignment != NULL; - si_assignment = si_assignment->next) { - - if (si_assignment->requested_ha_state != - si_assignment->saAmfSISUHAState) { - amf_si_ha_state_assume ( - si_assignment, assign_si_assumed_cbfn); - } - } - } - } - } - } - - LEAVE ("'%s'", sg->name.value); - return assigned; -} - -#ifdef COMPILE_OUT -static void remove_si_in_scope (amf_sg_t *sg, amf_si_t *si) -{ - int i; - int j; - amf_si_t **sis = sg->recovery_scope.sis; - amf_si_t **new_sis = amf_calloc (1, sizeof (amf_si_t*)); - - for (i = 0,j = 0; sis[i] != NULL; i++) { - if (sis[i] == si) { - continue; - } - new_sis[j] = sis[i]; - new_sis = amf_realloc (new_sis, j + sizeof (amf_si_t *)); - j++; - } - - sg->recovery_scope.sis = new_sis; -} -#endif - -#ifdef COMPILE_OUT -static void remove_sis_for_term_failed_su_from_scope (amf_sg_t *sg, - amf_su_t *su) -{ - amf_comp_t *component; - - /* - * foreach component with presense state termiantion failed in su - */ - - for (component = su->comp_head; component != NULL; - component = component->next) { - - amf_csi_assignment_t *csi_assignment; - - if (component->saAmfCompPresenceState != - SA_AMF_PRESENCE_INSTANTIATION_FAILED) { - continue; - } - - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - - while (csi_assignment != NULL) { - - remove_si_in_scope (sg, csi_assignment->csi->si); - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - } - } -} -#endif - -/** - * This function returns 1 if the redundancy model is N plus M and at least one - * component of the specified SU has an active HA-state, else the function - * returns 0. - * @param sg - * @param su - * @return int - */ -static int is_comp_in_active_ha_state_nplusm ( - amf_sg_t *sg, amf_su_t *su) -{ - amf_comp_t *component; - amf_csi_assignment_t *csi_assignment; - int comp_is_in_active_ha_state = 0; - - if(sg->saAmfSGRedundancyModel == SA_AMF_NPM_REDUNDANCY_MODEL) { - for (component = su->comp_head; component != NULL; - component = component->next) { - csi_assignment = amf_comp_get_next_csi_assignment(component, NULL); - while (csi_assignment != NULL) { - if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_ACTIVE) { - comp_is_in_active_ha_state = 1; - goto out; - } - csi_assignment = amf_comp_get_next_csi_assignment(component, - csi_assignment); - } - } - } -out: - return comp_is_in_active_ha_state; -} - -/** - * This function handles a change of presence state reported by an SU contained - * in specified SG. The new presence state is INSTANTIATED. - * @param sg - * @param su - */ -static void sg_su_state_changed_to_instantiated (struct amf_sg *sg, struct amf_su *su) -{ - ENTER("%s %s",sg->name.value, su->name.value); - switch (sg->avail_state) { - case SG_AC_InstantiatingServiceUnits: - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_INSTANTIATING)) { - acsm_enter_idle (sg); - } - break; - case SG_AC_ReparingSu: - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_INSTANTIATING)) { - if (all_su_in_scope_has_either_of_three_presence_state( - su->sg, - SA_AMF_PRESENCE_INSTANTIATED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - su->sg->avail_state = SG_AC_AssigningWorkload; - if (assign_si (sg, 0) == 0) { - acsm_enter_idle (sg); - } - } else { - dprintf ("avail-state: %u", sg->avail_state); - assert (0); - } - } - break; - default: - dprintf ("avail-state: %u", sg->avail_state); - assert (0); - break; - } -} - -/** - * This function handles a change of presence state reported by an SU contained - * in specified SG. The new presence state is UNINSTANTIATED. - * @param sg - * @param su - */ -static void amf_sg_su_state_changed_to_uninstantiated (amf_sg_t *sg, - amf_su_t *su) -{ - ENTER("%s %s",sg->name.value, su->name.value); - switch (sg->avail_state) { - case SG_AC_TerminatingSuspected: - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_TERMINATING)) { - if (all_su_in_scope_has_either_two_presence_state (sg, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED)) { - - delete_si_assignments_in_scope (sg); - - if (is_any_si_in_scope_assigned_standby (sg)) { - remove_all_suspected_sus (sg); - acsm_enter_removing_standby_assignments (sg); - } else { /*is_no_si_in_scope_assigned_standby*/ - remove_all_suspected_sus (sg); - acsm_enter_assigning_standby_to_spare (sg); - } - } - } - break; - case SG_AC_ReparingSu: - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_TERMINATING)) { - if (all_su_in_scope_has_either_of_three_presence_state( - su->sg, - SA_AMF_PRESENCE_INSTANTIATED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - su->sg->avail_state = SG_AC_AssigningWorkload; - if (assign_si (sg, 0) == 0) { - acsm_enter_idle (sg); - } - } - } - break; - default: - log_printf (LOG_ERR, "sg avail_state = %d", sg->avail_state); - assert (0); - break; - } -} - -/** - * This function handles a change of presence state reported by an SU contained - * in specified SG. The new presence state is TERMINATION_FAILED. - * @param sg - * @param su - */ -static void amf_sg_su_state_changed_to_termination_failed (amf_sg_t *sg, - amf_su_t *su) -{ - ENTER("%s %s",sg->name.value, su->name.value); - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_TERMINATING)) { - if (is_comp_in_active_ha_state_nplusm (sg, su)) { - acsm_enter_idle (sg); - goto out; - } - - if (all_su_in_scope_has_either_two_presence_state (sg, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED)) { - - delete_si_assignments_in_scope (sg); - - if (is_any_si_in_scope_assigned_standby (sg)) { - remove_all_suspected_sus (sg); - acsm_enter_removing_standby_assignments (sg); - } else { /*is_no_si_in_scope_assigned_standby*/ - remove_all_suspected_sus (sg); - acsm_enter_assigning_standby_to_spare (sg); - } - } - } -out: - return; -} - -/** - * This function handles a change of presence state reported by an SU contained - * in specified SG. The new presence state is INSTANTIATION_FAILED. - * @param sg - * @param su - */ -static void amf_sg_su_state_changed_to_instantiation_failed (amf_sg_t *sg, - amf_su_t *su) -{ - ENTER("%s %s",sg->name.value, su->name.value); - switch (sg->avail_state) { - case SG_AC_InstantiatingServiceUnits: - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_INSTANTIATING)) { - acsm_enter_idle (sg); - } - break; - case SG_AC_ReparingSu: - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_INSTANTIATING)) { - if (all_su_in_scope_has_either_of_three_presence_state( - su->sg, - SA_AMF_PRESENCE_INSTANTIATED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - su->sg->avail_state = SG_AC_AssigningWorkload; - if (assign_si (sg, 0) == 0) { - acsm_enter_idle (sg); - } - } - } - break; - default: - /* TODO: Insert the assert (0) until solving defers in SU */ - dprintf("sg->avail_state = %d", sg->avail_state); - break; - } -} - -/****************************************************************************** - * Event methods - *****************************************************************************/ - -/** - * This function starts all SUs in the SG or all SUs on a specified node. - * @param sg - * @param node - Node on which all SUs shall be started or - * NULL indicating that all SUs on all nodes shall be started. - * @return - No of SUs that has been attempted to start - */ -int amf_sg_start (struct amf_sg *sg, struct amf_node *node) -{ - - sg->recovery_scope.event_type = SG_START_EV; - ENTER ("'%s'", sg->name.value); - int instantiated_sus = 0; - - switch (sg->avail_state) { - case SG_AC_InstantiatingServiceUnits: - case SG_AC_Idle: { - - amf_su_t *su; - sg_avail_control_state_t old_avail_state = sg->avail_state; - - ENTER ("'%s'", sg->name.value); - - sg->node_to_start = node; - - sg->avail_state = SG_AC_InstantiatingServiceUnits; - - for (su = sg->su_head; - (su != NULL) && - (instantiated_sus < sg->saAmfSGNumPrefInserviceSUs); - su = su->next) { - - if (is_cluster_start (node)) { - - amf_su_instantiate (su); - instantiated_sus++; - - } else { /*is_not_cluster_start*/ - - /* - * Node start, match if SU is hosted on the - * specified node - */ - - if (name_match (&node->name, - &su->saAmfSUHostedByNode)) { - amf_su_instantiate (su); - instantiated_sus++; - } - } - } - - if (instantiated_sus == 0) { - sg->avail_state = old_avail_state; - } - break; - } - case SG_AC_DeactivatingDependantWorkload: - case SG_AC_TerminatingSuspected: - case SG_AC_ActivatingStandby: - case SG_AC_AssigningStandbyToSpare: - case SG_AC_ReparingComponent: - case SG_AC_ReparingSu: - case SG_AC_AssigningOnRequest: - case SG_AC_RemovingAssignment: - case SG_AC_AssigningActiveworkload: - case SG_AC_AssigningAutoAdjust: - case SG_AC_AssigningWorkload: - case SG_AC_WaitingAfterOperationFailed: - case SG_AC_RemovingStandbyAssignments: - default: - assert (0); - break; - } - return instantiated_sus; -} - -/** - * This function initiates assignment of the subset of the workload which - * matches the specified workload dependency level, to all SUs contained in the - * SG according to the requirements specified in the configuration. - * @param sg - - * @param dependency_level - Dependency level to assign - * @return - No of SUs that has been attempted to start - */ -int amf_sg_assign_si_req (struct amf_sg *sg, int dependency_level) -{ -/* TODO: Introduce state control in this function - */ - int posible_to_assign_si; - sg->recovery_scope.event_type = SG_ASSIGN_SI_EV; - sg->avail_state = SG_AC_AssigningOnRequest; - - if ((posible_to_assign_si = assign_si (sg, dependency_level)) == 0) { - acsm_enter_idle (sg); - } - return posible_to_assign_si; -} - -/** - * This function is called because an error has been detected and the analysis - * (done elsewhere) indicated that this error shall be recovered by a Node - * failover. This function initiates the recovery action 'Node failover'. - * @param sg - * @param su - SU to failover - * @param node - - */ -void amf_sg_failover_node_req (struct amf_sg *sg, struct amf_node *node) -{ - ENTER("'%s, %s'",node->name.value, sg->name.value); - sg_event_t sg_event; - - switch (sg->avail_state) { - case SG_AC_Idle: - set_scope_for_failover_node(sg, node); - if (has_any_su_in_scope_active_workload (sg)) { - acsm_enter_deactivating_dependent_workload (sg); - } else { - amf_su_t **sus = sg->recovery_scope.sus; - - /* - * Select next state depending on if some - * SU in the scope needs to be terminated. - */ - while (*sus != NULL) { - - amf_su_t *su = *sus; - ENTER("SU %s pr_state='%d'",su->name.value, - su->saAmfSUPresenceState); - - if (su_presense_state_is_ored (su, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED)) { - sus++; - continue; - } - break; - } - - if (*sus != NULL) { - acsm_enter_terminating_suspected (sg); - } else { - delete_si_assignments_in_scope (sg); - acsm_enter_idle (sg); - } - - } - break; - case SG_AC_DeactivatingDependantWorkload: - case SG_AC_TerminatingSuspected: - case SG_AC_ActivatingStandby: - case SG_AC_AssigningStandbyToSpare: - case SG_AC_ReparingComponent: - case SG_AC_ReparingSu: - case SG_AC_AssigningOnRequest: - case SG_AC_InstantiatingServiceUnits: - case SG_AC_RemovingAssignment: - case SG_AC_AssigningActiveworkload: - case SG_AC_AssigningAutoAdjust: - case SG_AC_AssigningWorkload: - case SG_AC_WaitingAfterOperationFailed: - case SG_AC_RemovingStandbyAssignments: - sg_set_event (SG_FAILOVER_NODE_EV, sg, 0, 0, node, &sg_event); - sg_defer_event (SG_FAILOVER_NODE_EV, &sg_event); - break; - default: - assert (0); - break; - - } -} - -/** - * This function is called because an error has been detected and the analysis - * (done elsewhere) indicated that this error shall be recovered by an SU - * failover. This function initiates the recovery action 'SU failover'. - * @param sg - * @param su - SU to failover - * @param node - - */ -void amf_sg_failover_su_req (struct amf_sg *sg, struct amf_su *su, - struct amf_node *node) -{ - ENTER ("%s", su->name.value); - sg_event_t sg_event; - - switch (sg->avail_state) { - case SG_AC_Idle: - su->su_failover_cnt += 1; - set_scope_for_failover_su (sg, su); - if (has_any_su_in_scope_active_workload (sg)) { - acsm_enter_deactivating_dependent_workload (sg); - } else { - acsm_enter_terminating_suspected (sg); - } - break; - case SG_AC_DeactivatingDependantWorkload: - case SG_AC_TerminatingSuspected: - case SG_AC_ActivatingStandby: - case SG_AC_AssigningStandbyToSpare: - case SG_AC_ReparingComponent: - case SG_AC_ReparingSu: - case SG_AC_AssigningOnRequest: - case SG_AC_InstantiatingServiceUnits: - case SG_AC_RemovingAssignment: - case SG_AC_AssigningActiveworkload: - case SG_AC_AssigningAutoAdjust: - case SG_AC_AssigningWorkload: - case SG_AC_WaitingAfterOperationFailed: - case SG_AC_RemovingStandbyAssignments: - sg_set_event (SG_FAILOVER_SU_EV, sg, su, 0, 0, &sg_event); - sg_defer_event (SG_FAILOVER_SU_EV, &sg_event); - break; - default: - assert (0); - break; - } -} - -/****************************************************************************** - * Event response methods - *****************************************************************************/ - -#ifdef COMPILE_OUT -void amf_sg_su_state_changed_2 (struct amf_sg *sg, - struct amf_su *su, SaAmfStateT type, int state) -{ - ENTER ("'%s' SU '%s' state %s", - sg->name.value, su->name.value, amf_presence_state(state)); - - if (type == SA_AMF_PRESENCE_STATE) { - if (state == SA_AMF_PRESENCE_INSTANTIATED) { - if (sg->avail_state == SG_AC_InstantiatingServiceUnits) { - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_INSTANTIATING)) { - acsm_enter_idle (sg); - } - } else if (sg->avail_state == SG_AC_ReparingSu) { - if (all_su_in_scope_has_either_of_three_presence_state( - su->sg, - SA_AMF_PRESENCE_INSTANTIATED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - su->sg->avail_state = SG_AC_AssigningWorkload; - if (assign_si (sg, 0) == 0) { - acsm_enter_idle (sg); - } - - } else { - dprintf ("avail-state: %u", sg->avail_state); - assert (0); - } - } else { - dprintf ("avail-state: %u", sg->avail_state); - assert (0); - } - } else if (state == SA_AMF_PRESENCE_UNINSTANTIATED) { - if (sg->avail_state == SG_AC_TerminatingSuspected) { - if (all_su_in_scope_has_either_two_presence_state (sg, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED)) { - - delete_si_assignments_in_scope (sg); - - if (is_any_si_in_scope_assigned_standby (sg)) { - remove_all_suspected_sus (sg); - acsm_enter_removing_standby_assignments (sg); - } else { /*is_no_si_in_scope_assigned_standby*/ - remove_all_suspected_sus (sg); - acsm_enter_assigning_standby_to_spare (sg); - } - } - } else if (sg->avail_state == SG_AC_ReparingSu) { - if (all_su_in_scope_has_either_of_three_presence_state( - su->sg, - SA_AMF_PRESENCE_INSTANTIATED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - su->sg->avail_state = SG_AC_AssigningWorkload; - if (assign_si (sg, 0) == 0) { - acsm_enter_idle (sg); - } - } else { - dprintf("%d",sg->avail_state); - assert (0); - } - } - } else if (state == SA_AMF_PRESENCE_TERMINATION_FAILED) { - - if (all_su_in_scope_has_either_two_presence_state (sg, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED) && - is_any_si_in_scope_assigned_standby (sg)) { - remove_all_suspected_sus (sg); - - acsm_enter_removing_standby_assignments (sg); - - } else if (all_su_in_scope_has_either_two_presence_state (sg, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED) && - !is_any_si_in_scope_assigned_standby (sg)) { - - remove_all_suspected_sus (sg); - acsm_enter_assigning_standby_to_spare (sg); - - } else { - - remove_sis_for_term_failed_su_from_scope (sg, su); - } - } else if (state == SA_AMF_PRESENCE_INSTANTIATING) { - ; /* nop */ - } else if (state == SA_AMF_PRESENCE_INSTANTIATION_FAILED) { - if (sg->avail_state == SG_AC_InstantiatingServiceUnits) { - if (no_su_has_presence_state(sg, sg->node_to_start, - SA_AMF_PRESENCE_INSTANTIATING)) { - acsm_enter_idle (sg); - } - - } else if (sg->avail_state == SG_AC_ReparingSu) { - if (all_su_in_scope_has_either_of_three_presence_state( - su->sg, - SA_AMF_PRESENCE_INSTANTIATED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED, - SA_AMF_PRESENCE_UNINSTANTIATED)) { - su->sg->avail_state = SG_AC_AssigningWorkload; - if (assign_si (sg, 0) == 0) { - acsm_enter_idle (sg); - } - } - } else { - /* TODO: Insert the assert (0) until solving defers in SU */ - dprintf("sg->avail_state = %d, su instantiation state = %d", - sg->avail_state, state); - } - } else { - dprintf("sg->avail_state = %d, su instantiation state = %d", - sg->avail_state, state); - assert (0); - } - } -} -#endif - -/** - * SU indicates to SG that one of its state machines has changed state. - * @param sg - SG which contains the SU that has changed state - * @param su - SU which has changed state - * @param type - Indicates which state machine that has changed state - * @param state - The new state that has been assumed. - * - */ -void amf_sg_su_state_changed (struct amf_sg *sg, struct amf_su *su, - SaAmfStateT type, int state) -{ - ENTER ("'%s' SU '%s' state %s", - sg->name.value, su->name.value, amf_presence_state(state)); - - if (sg->avail_state != SG_AC_Idle) { - if (type == SA_AMF_PRESENCE_STATE) { - switch (state) { - case SA_AMF_PRESENCE_INSTANTIATED: - sg_su_state_changed_to_instantiated(sg, su); - break; - case SA_AMF_PRESENCE_UNINSTANTIATED: - amf_sg_su_state_changed_to_uninstantiated(sg, su); - break; - case SA_AMF_PRESENCE_TERMINATION_FAILED: - amf_sg_su_state_changed_to_termination_failed(sg, su); - break; - case SA_AMF_PRESENCE_INSTANTIATING: - ; /* nop */ - break; - case SA_AMF_PRESENCE_INSTANTIATION_FAILED: - amf_sg_su_state_changed_to_instantiation_failed(sg, su); - break; - case SA_AMF_PRESENCE_TERMINATING: - ; /* nop */ - break; - default : - dprintf("sg->avail_state = %d, su instantiation state = %d", - sg->avail_state, state); - assert (0); - break; - } - } - } -} - -/** - * Callback function used by SI when there is no dependent SI to - * deactivate. - * @param sg - */ -static void dependent_si_deactivated_cbfn2 (struct amf_sg *sg) -{ - struct amf_su **sus = sg->recovery_scope.sus; - - ENTER("'%s'", sg->name.value); - - /* - * Select next state depending on if some - * SU in the scope needs to be terminated. - */ - - while (*sus != NULL) { - amf_su_t *su = *sus; - - ENTER("SU %s pr_state='%d'",su->name.value, - su->saAmfSUPresenceState); - - if (su_presense_state_is_ored (su, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED)) { - sus++; - continue; - } - break; - } - - if (*sus != NULL) { - acsm_enter_terminating_suspected (sg); - } else { - delete_si_assignments_in_scope(sg); - acsm_enter_removing_standby_assignments (sg); - } -} - -/** - * Callback function used by SI when an SI has been deactivated, i.e. - * transitioned from active HA-state to any other state. - * @param si_assignment - * @param result - Indicates the result of the operation. - */ -static void dependent_si_deactivated_cbfn ( - struct amf_si_assignment *si_assignment, int result) -{ - struct amf_sg *sg = si_assignment->su->sg; - struct amf_su **sus = sg->recovery_scope.sus; - struct amf_su *su; - - ENTER ("'%s', %d", si_assignment->si->name.value, result); - - /* - * If all SI assignments for all SUs in the SG are not pending, - * goto next state (TerminatingSuspected). - */ - for (su = sg->su_head ; su != NULL; su = su->next) { - struct amf_si_assignment *si_assignment; - si_assignment = amf_su_get_next_si_assignment(su, NULL); - - while (si_assignment != NULL) { - if (si_assignment->saAmfSISUHAState != - si_assignment->requested_ha_state) { - goto still_wating; - } - si_assignment = amf_su_get_next_si_assignment(su, - si_assignment); - } - } - -still_wating: - - if (su == NULL) { - sus = si_assignment->su->sg->recovery_scope.sus; - - /* - * Select next state depending on if some - * SU in the scope is needs to be terminated. - */ - - while (*sus != NULL) { - if (su_presense_state_is_not (*sus, - SA_AMF_PRESENCE_UNINSTANTIATED, - SA_AMF_PRESENCE_TERMINATION_FAILED, - SA_AMF_PRESENCE_INSTANTIATION_FAILED)) { - break; - } - sus++; - } - if (*sus != NULL) { - acsm_enter_terminating_suspected (sg); - } else { - acsm_enter_removing_standby_assignments (sg); - } - } - LEAVE(""); -} - -/** - * Callback function used by SI to indicate an SI has assumed a new HA-state or - * that the attempt to do so failed. - * @param si_assignment - * @param result - Indicates the result of the operation. - */ -static void assign_si_assumed_cbfn ( - struct amf_si_assignment *si_assignment, int result) -{ - struct amf_sg *sg = si_assignment->su->sg; - int si_assignment_cnt = 0; - int confirmed_assignments = 0; - - ENTER ("'%s', %d", si_assignment->si->name.value, result); - - - switch (sg->avail_state) { - case SG_AC_AssigningOnRequest: - if (is_all_si_assigned (sg)) { - acsm_enter_idle (sg); - amf_application_sg_assigned (sg->application, sg); - } else { - dprintf ("%d, %d", si_assignment_cnt, confirmed_assignments); - } - break; - case SG_AC_AssigningWorkload: - { - if (is_all_si_assigned(sg)) { - acsm_enter_idle (sg); - } - break; - } - case SG_AC_AssigningStandbyToSpare: - { - if(is_all_si_assigned (sg)) { - /* - * All si_assignments has asumed - * Prescense state SA_AMF_HA_STANDBY - */ - switch (sg->recovery_scope.event_type) { - case SG_FAILOVER_NODE_EV: - acsm_enter_idle (sg); - break; - case SG_FAILOVER_SU_EV: - if (sg->saAmfSGAutoRepair == SA_TRUE) { - acsm_enter_repairing_su (sg); - } - break; - default: - assert (0); - break; - } - } else { - si_assignment->saAmfSISUHAState = SA_AMF_HA_STANDBY; - } - } - break; - default: - dprintf ("%d, %d, %d", sg->avail_state, si_assignment_cnt, - confirmed_assignments); - amf_runtime_attributes_print (amf_cluster); - assert (0); - break; - } -} - -/** - * Callback function used by SI when an SI has been activated, i.e. transitioned - * from any HA-state to an active HA-state. - * @param si_assignment - * @param result - Indicates the result of the operation. - */ -static void standby_su_activated_cbfn ( - struct amf_si_assignment *si_assignment, int result) -{ - struct amf_su **sus = si_assignment->su->sg->recovery_scope.sus; - struct amf_si **sis = si_assignment->su->sg->recovery_scope.sis; - - ENTER ("'%s', %d", si_assignment->si->name.value, result); - - /* - * If all SI assignments for all SIs in the scope are activated, goto next - * state. - */ - - while (*sis != NULL) { - if ((*sis)->assigned_sis != NULL && - (*sis)->assigned_sis->saAmfSISUHAState != SA_AMF_HA_ACTIVE) { - break; - } - sis++; - } - - if (*sis == NULL) { - - acsm_enter_assigning_standby_to_spare ((*sus)->sg); - } -} - -/****************************************************************************** - * General methods - *****************************************************************************/ - -/** - * Constructor for SG objects. Adds SG to the list owned by - * the specified application. Always returns a valid SG - * object, out-of-memory problems are handled here. Default - * values are initialized. - * @param sg - * @param name - * - * @return struct amf_sg* - */ - -struct amf_sg *amf_sg_new (struct amf_application *app, char *name) -{ - struct amf_sg *sg = amf_calloc (1, sizeof (struct amf_sg)); - - setSaNameT (&sg->name, name); - sg->saAmfSGAdminState = SA_AMF_ADMIN_UNLOCKED; - sg->saAmfSGNumPrefActiveSUs = 1; - sg->saAmfSGNumPrefStandbySUs = 1; - sg->saAmfSGNumPrefInserviceSUs = ~0; - sg->saAmfSGNumPrefAssignedSUs = ~0; - sg->saAmfSGCompRestartProb = -1; - sg->saAmfSGCompRestartMax = ~0; - sg->saAmfSGSuRestartProb = -1; - sg->saAmfSGSuRestartMax = ~0; - sg->saAmfSGAutoAdjustProb = -1; - sg->saAmfSGAutoRepair = SA_TRUE; - sg->application = app; - sg->next = app->sg_head; - app->sg_head = sg; - sg->deferred_events = NULL; - - return sg; -} - -void amf_sg_delete (struct amf_sg *sg) -{ - struct amf_su *su; - - for (su = sg->su_head; su != NULL;) { - struct amf_su *tmp = su; - su = su->next; - amf_su_delete (tmp); - } - - free (sg); -} - -void *amf_sg_serialize (struct amf_sg *sg, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", sg->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &sg->name); - buf = amf_serialize_SaUint32T (buf, &size, &offset, sg->saAmfSGRedundancyModel); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGAutoAdjust); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumPrefActiveSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumPrefStandbySUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumPrefInserviceSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumPrefAssignedSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGMaxActiveSIsperSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGMaxStandbySIsperSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGCompRestartProb); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGCompRestartMax); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGSuRestartProb); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGSuRestartMax); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGAutoAdjustProb); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGAutoRepair); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGAdminState); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumCurrAssignedSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumCurrNonInstantiatedSpareSUs); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->saAmfSGNumCurrInstantiatedSpareSUs); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, sg->clccli_path); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->avail_state); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, sg->recovery_scope.event_type); - - *len = offset; - - return buf; -} - -struct amf_sg *amf_sg_deserialize (struct amf_application *app, char *buf) -{ - char *tmp = buf; - struct amf_sg *sg = amf_sg_new (app, ""); - - tmp = amf_deserialize_SaNameT (tmp, &sg->name); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGRedundancyModel); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAutoAdjust); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefActiveSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefStandbySUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefInserviceSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumPrefAssignedSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGMaxActiveSIsperSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGMaxStandbySIsperSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGCompRestartProb); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGCompRestartMax); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGSuRestartProb); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGSuRestartMax); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAutoAdjustProb); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAutoRepair); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGAdminState); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumCurrAssignedSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumCurrNonInstantiatedSpareSUs); - tmp = amf_deserialize_SaUint32T (tmp, &sg->saAmfSGNumCurrInstantiatedSpareSUs); - tmp = amf_deserialize_SaStringT (tmp, &sg->clccli_path); - tmp = amf_deserialize_SaUint32T (tmp, &sg->avail_state); - tmp = amf_deserialize_SaUint32T (tmp, &sg->recovery_scope.event_type); - - return sg; -} - -struct amf_sg *amf_sg_find (struct amf_application *app, char *name) -{ - struct amf_sg *sg; - - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - if (sg->name.length == strlen(name) && - strncmp (name, (char*)sg->name.value, sg->name.length) == 0) { - break; - } - } - - return sg; -} - diff --git a/openais/services/amfsi.c b/openais/services/amfsi.c deleted file mode 100644 index 18d24bcd..00000000 --- a/openais/services/amfsi.c +++ /dev/null @@ -1,1059 +0,0 @@ -/** @file amfsi.c - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Refactoring of code into several AMF files - * - Component/SU restart, SU failover - * - Constructors/destructors - * - Serializers/deserializers - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Workload related classes Implementation - * - * This file contains functions for handling : - * - AMF service instances(SI) - * - AMF SI Dependency - * - AMF SI Ranked SU - * - AMF SI Assignment - * - AMF component service instances (CSI) - * - AMF CSI Assignment - * - AMF CSI Type - * - AMF CSI Attribute - * The file can be viewed as the implementation of the classes listed above - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for: - * - calculating and storing an SI_dependency_level integer per SI - * - calculating and storing a csi_dependency_level integer per CSI - * - on request change HA state of an SI or CSI in such a way that the - * requirements regarding SI -> SI dependencies (paragraphs 3.9.1.1 and - * 3.9.1.2) and CSI -> CSI dependencies (paragraph 3.9.1.3) are fully - * respected - * - * The si_dependency_level is an attribute calculated at init (in the future - * also at reconfiguration) which indicates dependencies between SIs as - * an integer. The si_dependency level indicates to which extent an SI depends - * on other SIs such that an SI that depends on no other SI is on - * si_dependecy_level == 1, an SI that depends only on an SI on - * si_dependency_level == 1 is on si_dependency-level == 2. - * An SI that depends on several SIs gets a si_dependency_level that is one - * unit higher than the SI with the highest si_dependency_level it depends on. - * - * The csi_dependency_level attribute works the same way. - * - * According to paragraph 3.9.1 of the spec, a change to or from the ACTIVE - * HA state is not always allowed without first deactivate dependent SI and CSI - * assignments. Dependencies between CSIs are absolute while an SI that depends - * on another SI may tolerate that the SI on which it depends is inactive for a - * configurable time (the tolerance time). The consequence of this is that a - * request to change the SI state may require a sequence of requests to - * components to assume a new HA state for a CSI-assignment and to guarantee - * the dependency rules, the active response from the component has to be - * awaited before next HA state can be set. - * - * This file implements an SI state machine that fully implements these rules. - * This state machine is called SI Dependency Control State Machine (dcsm) - * and has the following states: - * - DEACTIVATED (there is no SI-assignment with active HA state) - * - ACTIVATING (a request to set the ACTIVE HA state has been received and - * setting ACTIVE HA states to the appropriate components are - * in progress) - * - ACTIVATED (there is at least one SI-assignment with the ACTIVE HA-state) - * - DEACTIVATING (a request to de-activate an SI or only a specific CSI - * within an SI has been received and setting the QUISCED - * HA states to the appropriate components are in progress) - * - DEPENDENCY_DEACTIVATING (the SI-SI dependency tolerance timer has expired - * and setting the QUISCED HA states to the - * appropriate components are in progress) - * - DEPENDENCY_DEACTIVATED (as state DEACTIVATED but will automatically - * transition to state ACTIVATING when the - * dependency problem is solved, i.e. the SI on - * which it depends has re-assumed the ACTIVE HA - * state) - * - SETTING (a request to change the HA state when neither the existing - * nor the requested state is ACTIVE) - * - * This file also implements: - * - SI: Assignment state (for report purposes) - * - SI Assignment: HA state - * - CSI Assignment: HA state - * - */ - -#include -#include -#include -#include "amf.h" -#include "logsys.h" -#include "util.h" -#include "aispoll.h" -#include "main.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -/** - * Check that all CSI assignments belonging to an SI assignment - * has been removed. - * @param si_assignment - * - * @return int - */ -static int all_csi_assignments_removed (amf_si_assignment_t *si_assignment) -{ - amf_csi_assignment_t *csi_assignment; - amf_csi_t *csi; - int all_removed = 1; - - for (csi = si_assignment->si->csi_head; csi != NULL; csi = csi->next) { - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL; - csi_assignment = csi_assignment->next) { - - /* - * If the CSI assignment and the SI assignment belongs to the - * same SU, we have a match and can request the component to - * remove the CSI. - */ - if (name_match (&csi_assignment->comp->su->name, - &si_assignment->su->name)) { - - if (csi_assignment->requested_ha_state != - csi_assignment->saAmfCSICompHAState) { - all_removed = 0; - } - } - } - } - - return all_removed; -} - -/** - * Check if any CSI assignment belonging to SU has the requested - * state. - * @param su - * @param hastate - * - * @return int - */ -static int any_csi_has_hastate_in_su (struct amf_su *su, SaAmfHAStateT hastate) -{ - struct amf_comp *component; - struct amf_csi_assignment *csi_assignment; - int exist = 0; - - for (component = su->comp_head; component != NULL; - component = component->next) { - - csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (csi_assignment != NULL) { - if (csi_assignment->saAmfCSICompHAState == hastate) { - exist = 1; - goto done; - } - csi_assignment = - amf_comp_get_next_csi_assignment (component, csi_assignment); - } - } - - done: - return exist; -} - -/** - * Check if all CSI assignments belonging to a - * an SI assignemnt has the requested state. - * @param su - * @param hastate - * - * @return int - */ -static int all_csi_has_hastate_for_si ( - struct amf_si_assignment *si_assignment, SaAmfHAStateT hastate) -{ - struct amf_comp *component; - struct amf_csi_assignment *tmp_csi_assignment; - int all = 1; - - for (component = si_assignment->su->comp_head; component != NULL; - component = component->next) { - - tmp_csi_assignment = amf_comp_get_next_csi_assignment (component, NULL); - while (tmp_csi_assignment != NULL) { - if ((tmp_csi_assignment->si_assignment == si_assignment) && - (tmp_csi_assignment->saAmfCSICompHAState != hastate)) { - - all = 0; - goto done; - } - tmp_csi_assignment = - amf_comp_get_next_csi_assignment (component, tmp_csi_assignment); - } - } - - done: - return all; -} - -/** - * Implements table 6 in 3.3.2.4 - * TODO: active & standby is not correct calculated acc. to - * table. This knowledge is e.g. used in assign_si_assumed_cbfn - * (sg.c) - * @param csi_assignment - */ -static void set_si_ha_state (struct amf_csi_assignment *csi_assignment) -{ - SaAmfHAStateT old_ha_state = - csi_assignment->si_assignment->saAmfSISUHAState; - SaAmfAssignmentStateT old_assigment_state = - amf_si_get_saAmfSIAssignmentState (csi_assignment->csi->si); - - if (all_csi_has_hastate_for_si ( - csi_assignment->si_assignment, SA_AMF_HA_ACTIVE)) { - - csi_assignment->si_assignment->saAmfSISUHAState = SA_AMF_HA_ACTIVE; - } - - if (all_csi_has_hastate_for_si ( - csi_assignment->si_assignment, SA_AMF_HA_STANDBY)) { - - csi_assignment->si_assignment->saAmfSISUHAState = SA_AMF_HA_STANDBY; - } - - if (any_csi_has_hastate_in_su ( - csi_assignment->comp->su, SA_AMF_HA_QUIESCING)) { - - csi_assignment->si_assignment->saAmfSISUHAState = SA_AMF_HA_QUIESCING; - } - if (any_csi_has_hastate_in_su ( - csi_assignment->comp->su, SA_AMF_HA_QUIESCED)) { - - csi_assignment->si_assignment->saAmfSISUHAState = SA_AMF_HA_QUIESCED; - } - - /* log changes to HA state */ - if (old_ha_state != csi_assignment->si_assignment->saAmfSISUHAState) { - log_printf (LOG_NOTICE, "SU HA state changed to '%s' for:\n" - "\t\tSI '%s', SU '%s'", - amf_ha_state (csi_assignment->si_assignment->saAmfSISUHAState), - csi_assignment->si_assignment->si->name.value, - csi_assignment->si_assignment->name.value); - } - - /* log changes to assignment state */ - if (old_assigment_state != - amf_si_get_saAmfSIAssignmentState (csi_assignment->csi->si)) { - log_printf (LOG_NOTICE, "SI Assignment state changed to '%s' for:\n" - "\t\tSI '%s', SU '%s'", - amf_assignment_state ( - amf_si_get_saAmfSIAssignmentState (csi_assignment->csi->si)), - csi_assignment->si_assignment->si->name.value, - csi_assignment->si_assignment->name.value); - } -} - -char *amf_csi_dn_make (struct amf_csi *csi, SaNameT *name) -{ - int i = snprintf((char*) name->value, SA_MAX_NAME_LENGTH, - "safCsi=%s,safSi=%s,safApp=%s", - csi->name.value, csi->si->name.value, - csi->si->application->name.value); - assert (i <= SA_MAX_NAME_LENGTH); - name->length = i; - - return(char *)name->value; -} - -void amf_si_comp_set_ha_state_done ( - struct amf_si *si, struct amf_csi_assignment *csi_assignment) -{ - ENTER ("'%s', '%s'", si->name.value, csi_assignment->csi->name.value); - - set_si_ha_state (csi_assignment); - - assert (csi_assignment->si_assignment->assumed_callback_fn != NULL); - - /* - * Report to caller when the requested SI assignment state is - * confirmed. - */ - if (csi_assignment->si_assignment->requested_ha_state == - csi_assignment->si_assignment->saAmfSISUHAState) { - TRACE1("'%s', '%s'", si->name.value, csi_assignment->csi->name.value); - csi_assignment->si_assignment->assumed_callback_fn ( - csi_assignment->si_assignment, 0); - csi_assignment->si_assignment->assumed_callback_fn = NULL; - } -} - -void amf_si_activate ( - struct amf_si *si, - void (*activated_callback_fn)(struct amf_si *si, int result)) -{ - struct amf_csi *csi; - - ENTER ("'%s'", si->name.value); - - for (csi = si->csi_head; csi != NULL; csi = csi->next) { - struct amf_csi_assignment *csi_assignment; - - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL; - csi_assignment = csi_assignment->next) { - - csi_assignment->si_assignment->requested_ha_state = - SA_AMF_HA_ACTIVE; - - /* - * TODO: only active assignments should be set when dependency - * levels are used. - */ - csi_assignment->requested_ha_state = SA_AMF_HA_ACTIVE; - amf_comp_hastate_set (csi_assignment->comp, csi_assignment); - } - } -} - -void amf_si_comp_set_ha_state_failed ( - struct amf_si *si, struct amf_csi_assignment *csi_assignment) -{ - ENTER (""); - assert (0); -} - -static void timer_function_ha_state_assumed (void *_si_assignment) -{ - struct amf_si_assignment *si_assignment = _si_assignment; - - ENTER (""); - si_assignment->saAmfSISUHAState = si_assignment->requested_ha_state; - si_assignment->assumed_callback_fn (si_assignment, 0); -} - -void amf_si_ha_state_assume ( - struct amf_si_assignment *si_assignment, - void (*assumed_ha_state_callback_fn)(struct amf_si_assignment *si_assignment, - int result)) -{ - struct amf_csi_assignment *csi_assignment; - struct amf_csi *csi; - int csi_assignment_cnt = 0; - int hastate_set_done_cnt = 0; - - ENTER ("SI '%s' SU '%s' state %s", si_assignment->si->name.value, - si_assignment->su->name.value, - amf_ha_state (si_assignment->requested_ha_state)); - - si_assignment->assumed_callback_fn = assumed_ha_state_callback_fn; - for (csi = si_assignment->si->csi_head; csi != NULL; csi = csi->next) { - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL; - csi_assignment = csi_assignment->next) { - - /* - * If the CSI assignment and the SI assignment belongs to the - * same SU, we have a match and can request the component to - * change HA state. - */ - if (name_match (&csi_assignment->comp->su->name, - &si_assignment->su->name) && - (csi_assignment->saAmfCSICompHAState != - si_assignment->requested_ha_state)) { - - csi_assignment_cnt++; - csi_assignment->requested_ha_state = - si_assignment->requested_ha_state; - amf_comp_hastate_set (csi_assignment->comp, csi_assignment); - if (csi_assignment->saAmfCSICompHAState == - csi_assignment->requested_ha_state) { - - hastate_set_done_cnt++; - } - } - } - } - - /* - * If the SU has only one component which is the faulty one, we - * will not get an asynchronous response from the component. - * This response (amf_si_comp_set_ha_state_done) is used to do - * the next state transition. The asynchronous response is - * simulated using a timeout instead. - */ - if (csi_assignment_cnt == hastate_set_done_cnt) { - poll_timer_handle handle; - poll_timer_add (aisexec_poll_handle, 0, si_assignment, - timer_function_ha_state_assumed, &handle); - } -} - -/** - * Get number of active assignments for the specified SI - * @param si - * - * @return int - */ -int amf_si_get_saAmfSINumCurrActiveAssignments (struct amf_si *si) - -{ - int cnt = 0; - struct amf_si_assignment *si_assignment; - - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - - if (si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) { - cnt++; - } - } - - return cnt; -} - -int amf_si_su_get_saAmfSINumCurrActiveAssignments (struct amf_si *si, - struct amf_su *su) -{ - int cnt = 0; - struct amf_si_assignment *si_assignment; - - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - - if (si_assignment->su == su && - si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) { - cnt++; - } - } - - return cnt; -} - -int amf_si_get_saAmfSINumCurrStandbyAssignments (struct amf_si *si) -{ - int cnt = 0; - struct amf_si_assignment *si_assignment; - - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - - if (si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) { - cnt++; - } - } - - return cnt; -} - -int amf_si_su_get_saAmfSINumCurrStandbyAssignments (struct amf_si *si, - struct amf_su *su) -{ - int cnt = 0; - struct amf_si_assignment *si_assignment; - - for (si_assignment = si->assigned_sis; si_assignment != NULL; - si_assignment = si_assignment->next) { - - if (si_assignment->su == su && - si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) { - cnt++; - } - } - - return cnt; -} - -SaAmfAssignmentStateT amf_si_get_saAmfSIAssignmentState (struct amf_si *si) -{ - if ((amf_si_get_saAmfSINumCurrActiveAssignments (si) == - si->saAmfSIPrefActiveAssignments) && - (amf_si_get_saAmfSINumCurrStandbyAssignments (si) == - si->saAmfSIPrefStandbyAssignments)) { - - return SA_AMF_ASSIGNMENT_FULLY_ASSIGNED; - } else if (amf_si_get_saAmfSINumCurrActiveAssignments (si) == 0) { - return SA_AMF_ASSIGNMENT_UNASSIGNED; - } else { - return SA_AMF_ASSIGNMENT_PARTIALLY_ASSIGNED; - } -} - -void amf_csi_delete_assignments (struct amf_csi *csi, struct amf_su *su) -{ - struct amf_csi_assignment *csi_assignment; - ENTER ("'%s'", su->name.value); - struct amf_csi_assignment **prev = &csi->assigned_csis; - - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL; - csi_assignment = csi_assignment->next) { - if (csi_assignment->comp->su == su) { - struct amf_csi_assignment *tmp = csi_assignment; - *prev = csi_assignment->next; - dprintf ("CSI assignment %s unlinked", tmp->name.value); - free (tmp); - } else { - prev = &csi_assignment->next; - } - } -} - -/** - * Constructor for SI objects. Adds SI last in the ordered - * list owned by the specified application. Always returns a - * valid SI object, out-of-memory problems are handled here. - * Default values are initialized. - * @param app - * - * @return struct amf_si* - */ -struct amf_si *amf_si_new (struct amf_application *app, char *name) -{ - struct amf_si *tail = app->si_head; - struct amf_si *si = amf_calloc (1, sizeof (struct amf_si)); - - while (tail != NULL) { - if (tail->next == NULL) { - break; - } - tail = tail->next; - } - - if (tail == NULL) { - app->si_head = si; - } else { - tail->next = si; - } - - si->application = app; - - /* setup default values from spec. */ - si->saAmfSIAdminState = SA_AMF_ADMIN_UNLOCKED; - si->saAmfSIRank = 0; - si->saAmfSIPrefActiveAssignments = 1; - si->saAmfSIPrefStandbyAssignments = 1; - - si->assigned_sis = NULL; - si->csi_head = NULL; - setSaNameT (&si->name, name); - - return si; -} - -void amf_si_delete (struct amf_si *si) -{ - struct amf_si_assignment *si_assignment; - struct amf_csi *csi; - - for (csi = si->csi_head; csi != NULL;) { - struct amf_csi *tmp = csi; - csi = csi->next; - amf_csi_delete (tmp); - } - - for (si_assignment = si->assigned_sis; si_assignment != NULL;) { - struct amf_si_assignment *tmp = si_assignment; - si_assignment = si_assignment->next; - free (tmp); - } - - free (si); -} - -void *amf_si_serialize (struct amf_si *si, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", si->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &si->name); - buf = amf_serialize_SaNameT (buf, &size, &offset, - &si->saAmfSIProtectedbySG); - buf = amf_serialize_SaUint32T (buf, &size, &offset, si->saAmfSIRank); - buf = amf_serialize_SaUint32T (buf, &size, &offset, si->saAmfSINumCSIs); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - si->saAmfSIPrefActiveAssignments); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - si->saAmfSIPrefStandbyAssignments); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - si->saAmfSIAdminState); - - *len = offset; - - return buf; -} - -struct amf_si *amf_si_deserialize (struct amf_application *app, char *buf) -{ - char *tmp = buf; - struct amf_si *si = amf_si_new (app, ""); - - tmp = amf_deserialize_SaNameT (tmp, &si->name); - tmp = amf_deserialize_SaNameT (tmp, &si->saAmfSIProtectedbySG); - tmp = amf_deserialize_SaUint32T (tmp, &si->saAmfSIRank); - tmp = amf_deserialize_SaUint32T (tmp, &si->saAmfSINumCSIs); - tmp = amf_deserialize_SaUint32T (tmp, &si->saAmfSIPrefActiveAssignments); - tmp = amf_deserialize_SaUint32T (tmp, &si->saAmfSIPrefStandbyAssignments); - tmp = amf_deserialize_SaUint32T (tmp, &si->saAmfSIAdminState); - - return si; -} - -/***************************************************************************** - * SI Assignment class implementation * - ****************************************************************************/ - -struct amf_si_assignment *amf_si_assignment_new (struct amf_si *si) -{ - struct amf_si_assignment *si_assignment = - amf_calloc (1, sizeof (struct amf_si_assignment)); - - si_assignment->si = si; - si_assignment->next = si->assigned_sis; - si->assigned_sis = si_assignment; - - return si_assignment; -} - -void *amf_si_assignment_serialize ( - amf_si_assignment_t *si_assignment, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", si_assignment->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &si_assignment->name); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - si_assignment->saAmfSISUHAState); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - si_assignment->requested_ha_state); - - *len = offset; - - return buf; -} - -struct amf_si_assignment *amf_si_assignment_deserialize ( - struct amf_si *si, char *buf) -{ - char *tmp = buf; - struct amf_si_assignment *si_assignment = amf_si_assignment_new (si); - - tmp = amf_deserialize_SaNameT (tmp, &si_assignment->name); - tmp = amf_deserialize_SaUint32T (tmp, &si_assignment->saAmfSISUHAState); - tmp = amf_deserialize_SaUint32T (tmp, &si_assignment->requested_ha_state); - si_assignment->su = amf_su_find (si->application->cluster, - &si_assignment->name); - - return si_assignment; -} - -struct amf_si *amf_si_find (struct amf_application *app, char *name) -{ - struct amf_si *si; - - for (si = app->si_head; si != NULL; si = si->next) { - if (si->name.length == strlen(name) && - strncmp (name, (char*)si->name.value, si->name.length) == 0) { - break; - } - } - - if (si == NULL) { - dprintf ("SI %s not found!", name); - } - - return si; -} - -/***************************************************************************** - * CSI class implementation * - ****************************************************************************/ - -struct amf_csi *amf_csi_new (struct amf_si *si) -{ - struct amf_csi *csi = amf_calloc (1, sizeof (struct amf_csi)); - - csi->si = si; - csi->next = si->csi_head; - si->csi_head = csi; - - return csi; -} - -void amf_csi_delete (struct amf_csi *csi) -{ - struct amf_csi_assignment *csi_assignment; - - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL;) { - struct amf_csi_assignment *tmp = csi_assignment; - csi_assignment = csi_assignment->next; - free (tmp); - } - - free (csi); -} - -void *amf_csi_serialize (struct amf_csi *csi, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", csi->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &csi->name); - buf = amf_serialize_SaNameT (buf, &size, &offset, &csi->saAmfCSTypeName); - - *len = offset; - - return buf; -} - -struct amf_csi *amf_csi_deserialize (struct amf_si *si, char *buf) -{ - char *tmp = buf; - struct amf_csi *csi = amf_csi_new (si); - - tmp = amf_deserialize_SaNameT (tmp, &csi->name); - tmp = amf_deserialize_SaNameT (tmp, &csi->saAmfCSTypeName); - - return csi; -} - -struct amf_csi *amf_csi_find (struct amf_si *si, char *name) -{ - struct amf_csi *csi; - - for (csi = si->csi_head; csi != NULL; csi = csi->next) { - if (csi->name.length == strlen(name) && - strncmp (name, (char*)csi->name.value, csi->name.length) == 0) { - break; - } - } - - if (csi == NULL) { - dprintf ("CSI %s not found!", name); - } - return csi; -} - -/***************************************************************************** - * CSI Assignment class implementation * - ****************************************************************************/ - -struct amf_csi_assignment *amf_csi_assignment_new (struct amf_csi *csi) -{ - struct amf_csi_assignment *csi_assignment = - amf_calloc (1, sizeof (struct amf_csi_assignment)); - - csi_assignment->csi = csi; - csi_assignment->next = csi->assigned_csis; - csi->assigned_csis = csi_assignment; - - return csi_assignment; -} - -void *amf_csi_assignment_serialize ( - struct amf_csi_assignment *csi_assignment, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", csi_assignment->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &csi_assignment->name); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - csi_assignment->saAmfCSICompHAState); - buf = amf_serialize_SaUint32T (buf, &size, &offset, - csi_assignment->requested_ha_state); - - *len = offset; - - return buf; -} - -struct amf_si_assignment *si_assignment_find ( - struct amf_csi_assignment *csi_assignment) -{ - struct amf_comp *component; - struct amf_si_assignment *si_assignment = NULL; - - component = amf_comp_find(csi_assignment->csi->si->application->cluster, - &csi_assignment->name); - - for (si_assignment = csi_assignment->csi->si->assigned_sis; - si_assignment != NULL; si_assignment = si_assignment->next) { - SaNameT su_name; - amf_su_dn_make (component->su,&su_name); - - if (name_match(&su_name, &si_assignment->name)) { - break; - } - } - - return si_assignment; -} - -struct amf_csi_assignment *amf_csi_assignment_deserialize ( - struct amf_csi *csi, char *buf) -{ - char *tmp = buf; - struct amf_csi_assignment *csi_assignment = amf_csi_assignment_new (csi); - - tmp = amf_deserialize_SaNameT (tmp, &csi_assignment->name); - tmp = amf_deserialize_SaUint32T (tmp, - &csi_assignment->saAmfCSICompHAState); - tmp = amf_deserialize_SaUint32T (tmp, &csi_assignment->requested_ha_state); - - csi_assignment->comp = amf_comp_find (csi->si->application->cluster, - &csi_assignment->name); - assert (csi_assignment->comp != NULL); - csi_assignment->si_assignment = si_assignment_find(csi_assignment); - - return csi_assignment; -} - -char *amf_csi_assignment_dn_make ( - struct amf_csi_assignment *csi_assignment, SaNameT *name) -{ - SaNameT comp_name; - struct amf_csi *csi = csi_assignment->csi; - int i; - - amf_comp_dn_make (csi_assignment->comp, &comp_name); - - i = snprintf((char*) name->value, SA_MAX_NAME_LENGTH, - "safCSIComp=%s,safCsi=%s,safSi=%s,safApp=%s", - comp_name.value, - csi->name.value, csi->si->name.value, - csi->si->application->name.value); - assert (i <= SA_MAX_NAME_LENGTH); - name->length = i; - - return(char *)name->value; -} - -struct amf_csi_assignment *amf_csi_assignment_find ( - struct amf_cluster *cluster, SaNameT *name) -{ - struct amf_application *app; - struct amf_si *si; - struct amf_csi *csi; - struct amf_csi_assignment *csi_assignment = NULL; - char *app_name; - char *si_name; - char *csi_name; - char *csi_assignment_name; - char *buf; - - /* malloc new buffer since we need to write to the buffer */ - buf = amf_malloc (name->length + 1); - memcpy (buf, name->value, name->length + 1); - - csi_assignment_name = strstr (buf, "safCSIComp="); - csi_name = strstr (buf, "safCsi="); - si_name = strstr (buf, "safSi="); - app_name = strstr (buf, "safApp="); - app_name++; - app_name = strstr (app_name, "safApp="); - - if (csi_assignment_name == NULL || csi_name == NULL || si_name == NULL || - app_name == NULL) { - - goto end; - } - - *(csi_name - 1) = '\0'; - *(si_name - 1) = '\0'; - *(app_name - 1) = '\0'; - - /* jump to value */ - csi_assignment_name += 11; - csi_name += 7; - si_name += 6; - app_name += 7; - - app = amf_application_find (cluster, app_name); - if (app == NULL) { - goto end; - } - - si = amf_si_find (app, si_name); - if (si == NULL) { - goto end; - } - - csi = amf_csi_find (si, csi_name); - if (csi == NULL) { - goto end; - } - - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL; - csi_assignment = csi_assignment->next) { - - if (csi_assignment->name.length == strlen(csi_assignment_name) && - strncmp (csi_assignment_name, - (char*)csi_assignment->name.value, - csi_assignment->name.length) == 0) { - goto end; - } - } - -end: - assert(csi_assignment); - - free (buf); - return csi_assignment; -} - -struct amf_csi_attribute *amf_csi_attribute_new (struct amf_csi *csi) -{ - struct amf_csi_attribute *csi_attribute = - amf_calloc (1, sizeof (struct amf_csi_assignment)); - - csi_attribute->next = csi->attributes_head; - csi->attributes_head = csi_attribute; - - return csi_attribute; -} - -void *amf_csi_attribute_serialize ( - struct amf_csi_attribute *csi_attribute, int *len) -{ - char *buf = NULL; - int i, offset = 0, size = 0; - - TRACE8 ("%s", csi_attribute->name); - - buf = amf_serialize_SaStringT (buf, &size, &offset, csi_attribute->name); - - /* count value and write to buf */ - for (i = 0; csi_attribute->value && - csi_attribute->value[i] != NULL; i++); - buf = amf_serialize_SaUint32T (buf, &size, &offset, i); - - for (i = 0; csi_attribute->value && - csi_attribute->value[i] != NULL; i++) { - buf = amf_serialize_SaStringT ( - buf, &size, &offset, csi_attribute->value[i]); - } - - *len = offset; - - return buf; -} - -struct amf_csi_attribute *amf_csi_attribute_deserialize ( - struct amf_csi *csi, char *buf) -{ - char *tmp = buf; - struct amf_csi_attribute *csi_attribute; - int i; - SaUint32T cnt; - - csi_attribute = amf_csi_attribute_new (csi); - - tmp = amf_deserialize_SaStringT (tmp, &csi_attribute->name); - tmp = amf_deserialize_SaUint32T (tmp, &cnt); - csi_attribute->value = amf_malloc ((cnt + 1) * sizeof (SaStringT*)); - for (i = 0; i < cnt; i++) { - tmp = amf_deserialize_SaStringT (tmp, &csi_attribute->value[i]); - } - csi_attribute->value[i] = NULL; - - return csi_attribute; -} - -void amf_si_assignment_remove (amf_si_assignment_t *si_assignment, - async_func_t async_func) -{ - struct amf_csi_assignment *csi_assignment; - struct amf_csi *csi; - int csi_assignment_cnt = 0; - - ENTER ("SI '%s' SU '%s' state %s", si_assignment->si->name.value, - si_assignment->su->name.value, - amf_ha_state (si_assignment->requested_ha_state)); - - si_assignment->requested_ha_state = USR_AMF_HA_STATE_REMOVED; - si_assignment->removed_callback_fn = async_func; - - for (csi = si_assignment->si->csi_head; csi != NULL; csi = csi->next) { - for (csi_assignment = csi->assigned_csis; csi_assignment != NULL; - csi_assignment = csi_assignment->next) { - - /* - * If the CSI assignment and the SI assignment belongs to the - * same SU, we have a match and can request the component to - * remove the CSI. - */ - if (name_match (&csi_assignment->comp->su->name, - &si_assignment->su->name)) { - - csi_assignment_cnt++; - csi_assignment->requested_ha_state = USR_AMF_HA_STATE_REMOVED; - amf_comp_csi_remove (csi_assignment->comp, csi_assignment); - } - } - } - - /* - * If the SU has only one component which is the faulty one, we - * will not get an asynchronous response from the component. - * This response (amf_si_comp_set_ha_state_done) is used to do - * the next state transition. The asynchronous response is - * simulated using a timeout instead. - */ - if (csi_assignment_cnt == 0) { - amf_call_function_asynchronous (async_func, si_assignment); - } -} - -void amf_si_comp_csi_removed ( - struct amf_si *si, struct amf_csi_assignment *csi_assignment, - SaAisErrorT error) -{ - ENTER ("'%s', '%s'", si->name.value, csi_assignment->csi->name.value); - - assert (csi_assignment->si_assignment->removed_callback_fn != NULL); - - csi_assignment->saAmfCSICompHAState = USR_AMF_HA_STATE_REMOVED; - - /* - * Report to caller when all requested CSI assignments has - * been removed. - */ - if (all_csi_assignments_removed(csi_assignment->si_assignment)) { - csi_assignment->si_assignment->removed_callback_fn ( - csi_assignment->si_assignment); - } -} - diff --git a/openais/services/amfsu.c b/openais/services/amfsu.c deleted file mode 100644 index ad17408b..00000000 --- a/openais/services/amfsu.c +++ /dev/null @@ -1,1802 +0,0 @@ -/** @file exec/amfsu.c - * - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Author: Steven Dake (sdake@redhat.com) - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt, Anders Eriksson, Lars Holm - * - Introduced AMF B.02 information model - * - Use DN in API and multicast messages - * - (Re-)Introduction of event based multicast messages - * - Refactoring of code into several AMF files - * - Component/SU restart, SU failover - * - Constructors/destructors - * - Serializers/deserializers - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF Service Unit Class Implementation - * - * This file contains functions for handling AMF-service units(SUs). It can be - * viewed as the implementation of the AMF Service Unit class (called SU) - * as described in SAI-Overview-B.02.01. The SA Forum specification - * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour - * and is referred to as 'the spec' below. - * - * The functions in this file are responsible for: - * - instantiating and terminating service units on request - * (considering the dependencies between components described in paragraph - * 3.9.2) - * - creating and deleting CSI-assignment objects between its components and - * CSI-objects upon request - * - receiving error reports from its components and forwarding them to - * appropriate handler (SU or SG or node or cluster) - * - implementing restart of itself and its components (paragraph 3.12.1.2) - * - implementing error escallation level 1 (paragraph 3.12.2.2 in the spec) - * - handling all run time attributes of the AMF SU; all cached - * attributes are stored as variables and sent to the IMM service - * upon the changes described in the specification. - * - * SU contains the following state machines: - * - presence state machine (PRSM) - * - administrative state machine (ADSM) (NOT IN THIS RELEASE) - * - operational state machine (OPSM) - * - readiness state machine (RESM) - * - ha state per service instance (SI) - * - restart control state machine (RCSM) - * - * The presence state machine orders intantiation of its components on request. - * It fully respects the dependency rules between components at instantiation - * such that it orders instantiation simultaneously only of components on the - * same instantiation level. The presence state machine is implemented with - * the states described in the spec and the state transitions are trigged by - * reported state transitions from its contained components according to - * paragraph 3.3.1.1. - * - * The operational state machine is not responsible for any control function. - * It assumes the DISABLED state if an incoming operational state change report - * from a component indicates the component has assumed the DISABLED state. - * Operational state changes are reported to IMM. - * - * The readiness state machine is not used for any control but is updated and - * reported to IMM when it is changed. - * - * The restart control state machine (RCSM) is used to implement level 1 of - * the error escallation policy described in chapter 3.12.2 of the spec. It also - * implements component restart and service unit restart as described in - * paragraph 3.12.1.2 and 3.12.1.3. - * RCSM contains three composite states. - * Being a composite state means that the state contains substates. - * RCSM composite states are: - * - IDLE (LEVEL_0, LEVEL_1 and LEVEL_2) - * - RESTARTING_COMPONENT (DEACTIVATING, RESTARTING, SETTING and ACTIVATING) - * - RESTARTING_SERVICE_UNIT (DEACTIVATING, TERMINATING, INSTANTIATING, - * and ACTIVATING) - * - * IDLE is a kind of state where no actions are performed and used only to - * remember the escallation level. Substate LEVEL_0 indicates no escallation. - * LEVEL_1 indicates that a component restart has been executed recently and the - * escallation timer is still running. At this level component restart requests - * will transition to RESTARTING_COMPONENT but if there are too many restart - * requests before the probation timer expires then a transition will be made to - * LEVEL_2 and the restart request will be forwarded to the node instance - * hosting this component. State RESTARTING_SERVICE_UNIT will only be assumed if - * the node explicitly requests the SU to execute a restart of itself (after - * having evaluated its part of the error escallation policy). - * -* 1. Service Unit Restart Control State Machine -* ============================================ - * - * 1.1 State Transition Table - * =========================== - * - * State: Event: Action: New state: - * =========================================================================== - * IDLE_ESCALATION_x comp_restart A9 RS_COMP_RESTARTING - * IDLE_ESCALATION_x su_restart A20 RS_SU_TERMINATING - * IDLE_ESCALATION_0 error_suspected A1,A3 IDLE_ESCALATION_1 - * IDLE_ESCALATION_1 error_suspected [!C3] A1,A3 IDLE_ESCALATION_1 - * IDLE_ESCALATION_1 error_suspected [C3] A2,A5 IDLE_ESCALATION_2 - * IDLE_ESCALATION_2 error_suspected A2 IDLE_ESCALATION_2 - * RS_COMP_RESTARTING comp_instantiated A11 RS_COMP_SETTING - * RS_COMP_RESTARTING comp_inst_failed A14,A15 RS_COMP_T-ING_2 - * RS_COMP_RESTARTING comp_term_failed A19 IDLE_ESCALATION_x - * RS_COMP_RESTARTING error_suspected A18 RS_COMP_RESTARTING - * RS_COMP_T-ING_2 comp_uninst..ed [C8] A16,A15 RS_COMP_T-ING_2 - * RS_COMP_T-ING_2 comp_uninst..ed [C100] IDLE_ESCALATION_x - * RS_COMP_T-ING_2 comp_uninst..ed [C101] A25 IDLE_ESCALATION_x - * RS_COMP_T-ING_2 comp_uninst..ed [C102] A26 IDLE_ESCALATION_x - * RS_COMP_T-ING_2 comp_term_failed [C100] RS_COMP_T-ING_2 - * RS_COMP_T-ING_2 error_suspected A18 RS_COMP_T-ING_2 - * RS_COMP_SETTING ha_state_assumed [C7] A19 IDLE_ESCALATION_x - * RS_COMP_SETTING error_suspected A18 RS_COMP_SETTING - * RS_SU_TERMINATING comp_uninst..ed [C8] A16,A15 RS_SU_TERMINATING - * RS_SU_TERMINATING comp_uninst..ed [C103] A17,A23 RS_SU_INSTANTIATING - * RS_SU_TERMINATING comp_uninst..ed [C104] A19 IDLE_ESCALATION_x - * RS_SU_TERMINATING comp_term_failed [C104]A19 IDLE_ESCALATION_X - * RS_SU_TERMINATING error_suspected A18 RS_SU_TERMINATING - * RS_SU_INSTANTIATING comp_instantiated [C14]A21,A22 RS_SU_INSTANTIATING - * RS_SU_INSTANTIATING comp_instantiated [C105]A15 RS_SU_T-ING_2 - * RS_SU_INSTANTIATING comp_instantiated [C106]A11 RS_SU_SETTING - * RS_SU_INSTANTIATING comp_inst_failed [C105]A15 RS_SU_T-ING_2 - * RS_SU_INSTANTIATING error_suspected A18 RS_SU_INSTANTIATING - * RS_SU_T-ING_2 comp_uninst..ed [C8] A16,A15 RS_SU_T-ING_2 - * RS_SU_T-ING_2 comp_uninst..ed [C100] IDLE_ESCALATION_x - * RS_SU_T-ING_2 comp_uninst..ed [C101] A25 IDLE_ESCALATION_x - * RS_SU_T-ING_2 comp_uninst..ed [C102] A26 IDLE_ESCALATION_x - * RS_SU_T-ING_2 comp_term_failed [C100] RS_SU_T-ING_2 - * RS_SU_T-ING_2 error_suspected A18 RS_SU_T-ING_2 - * RS_SU_SETTING ha_state_assumed [C10] A19 IDLE_ESCALATION_X - * RS_SU_SETTING error_suspected A18 RS_SU_SETTING - * - * 1.2 State Description - * ===================== - * IDLE_ESCALATION_x - This is just an abbreviated notation for - * IDLE_ESCALATION_0, IDLE_ESCALATION_1 or IDLE_ESCALATION_2 - * When leaving any of the idle states, a history state - * is used to save the (exact) state value. When returning - * to idle, the value of the history state is used to set - * the correct idle state. - * - * IDLE_ESCALATION_0 - SU_RC_IDLE_ESCALATION_LEVEL_0 - * Service unit is idle and the restart probation timer is - * off. - * - * IDLE_ESCALATION_1 - SU_RC_IDLE_ESCALATION_LEVEL_1 - * Service unit is idle and the restart probation timer is - * on. This indicates there has recently been an error - * detected on at least one of its components which has been - * recovered by a component restart but we are still in the - * probation period which follows every restart. - * - * IDLE_ESCALATION_2 - SU_RC_IDLE_ESCALATION_LEVEL_2 - * Service unit is idle and handling on potential new error - * indications on any of its components has been delegated - * to the node object where the service unit is hosted. - * - * RS_COMP_DEACTIVATING - SU_RC_RESTART_COMP_DEACTIVATING - * Service unit is busy handling restart of one of its - * components. In this sub-state, the service unit is - * waiting for acknowledgements that all components which - * had csi-assignments that were dependent of csi- - * assignments associated to the restarting component - * have been de-activated. This is a neccesary step to - * take before the component to restart is terminated, - * to avoid that the csi or si dependency rules are - * violated. - * - * RS_COMP_RESTARTING - SU_RC_RESTART_COMP_RESTARTING - * Service unit is busy handling restart of one of its - * components. In this sub-state, the service unit has - * ordered one of its components to restart and waits for - * the component to indicate that the restart is done. - * - * RS_COMP_T-ING_2 - SU_RC_RESTART_COMP_TERMINATING_AFTER_INST_FAILED - * Service unit is busy handling restart of one of its - * components. In this sub-state, the restart of the component - * has failed and the rest of the components in the service - * unit has to be terminated. - * - * RS_COMP_SETTING - SU_RC_RESTART_COMP_SETTING - * Service unit is busy handling restart of one of its - * components. In this sub-state, the service unit has ordered - * the component that just have been restarted to re-assume - * the HA-states it had before, provided none of the states - * were ACTIVE. It waits for an acknowledgement that the - * setting of the HA-states are done. - * - * RS_COMP_ACTIVATING - SU_RC_RESTART_COMP_ACTIVATING - * Service unit is busy handling restart of one of its - * components. In this sub-state, the service unit has - * ordered the component that just have been restarted to - * re-assume the active HA-states it had before and also - * to activate the csi-assignments that possibly were - * de-activated because of this restart. The service unit - * waits in this state for an acknowledgement of the - * activation. - * - * RS_SU_DEACTIVATING - SU_RC_RESTART_SU_DEACTIVATING - * Service unit is busy handling restart of all of its - * components. In this sub-state, the service unit is - * waiting for acknowledgements that all components which - * had csi-assignments that were dependent of si- - * assignments associated to this service unit - * have been de-activated. This is a neccesary step to - * take before all components of the service unit are - * terminated, to avoid that the csi or si dependency rules - * are violated. - * - * RS_SU_TERMINATING - SU_RC_RESTART_SU_TERMINATING - * Service unit is busy handling restart of all of its - * components. In this sub-state, the service unit has - * ordered all its components to terminate and is waiting - * for an acknowledgement that all components are done with - * the termination. - * - * RS_SU_INSTANTIATING - SU_RC_RESTART_SU_INSTANTIATING - * Service unit is busy handling restart of all of its - * components. In this sub-state, the service unit has - * ordered all components to instantiate and is waiting - * for an acknowledgement that all components are done with - * the instantiation. - * - * RS_SU_T-ING_2 - SU_RC_RESTART_SU_TERMINATING_AFTER_INST_FAILED - * Service unit is busy handling restart of all of its - * components. In this sub-state, the instantiation at least - * one component has failed and the rest of the components in - * the service unit has to be terminated. - * - * RS_SU_SETTING - SU_RC_RESTART_SU_SETTING - * Service unit is busy handling restart of all of its - * components. In this sub-state, the service unit has ordered - * all components that just have been restarted to re-assume - * the HA-states they had before, provided none of the states - * were ACTIVE. The service unit waits for an acknowledgement - * that the setting of the HA-states are done. - * - * RS_SU_ACTIVATING - SU_RC_RESTART_SU_ACTIVATING - * Service unit is busy handling restart of all of its - * components. In this sub-state, the service unit has - * ordered all components that just have been restarted to - * re-assume the active HA-states they had before and also - * to activate the csi-assignments that possibly were - * de-activated because of this restart. The service unit - * waits in this state for an acknowledgement of the - * activation. - * - * 1.3 Actions - * =========== - * A1 - generate event comp_restart - * A2 - forward component restart request to the node which hosts current su - * A3 - start probation timer (SaAmfSGCompRestartProb) - * A4 - [foreach component in su]/ cnt += SaAmfSGCompRestartCount - * A5 - stop probation timer - * A6 - restart ?? - * A7 - set restarting_comp = component - * A8 - [foreach csi-assignment assigned to component] SI deactivate csi - * A9 - order component to restart - * A10 - set restarting_comp == ALL - * A11 - initiate setting of the same HA-state as was set before the restart - * A12 - SI activate - * A13 - [foreach si-assignment assigned to su] SI deactivate - * A14 - set current instantiation level = highest level - * A15 - [foreach component on current instantiation level]/terminate component - * A16 - current instantiation level is decremented - * A17 - request the presence state state machine to instantiate the su - * A18 - defer the event - * A19 - recall deferred event - * A20 - restart all components contained in current su - * A21 - current instantiation level is incremented - * A22 - [foreach component on current instantiation level]/instantiate - * component - * A23 - set current instantiation level = lowest level - * A24 - order SG to do component failover - * A25 - order Node to do node failover - * A26 - order SG to do SU failover - * - * 1.4 Guards - * ========== - * C1 - disableRestart == False - * C2 - the component has been restarted less than SaAmfSGCompRestartMax times - * C3 - the component has been restarted SaAmfSGCompRestartMax number of times - * C4 - all si-assignments have confirmed-ha-state == QUIESCED or the - * operation failed flag set. - * C5 - for each si-assignment related to the restarting component where - * requested-ha-state != confirmed-ha-state and requested-ha-state != - * ACTIVE - * C6 - - for each si-assignment related to the restarting component where - * requested-ha-state != confirmed-ha-state and requested-ha-state == - * ACTIVE - * C7 - all si-assignments related to the restarting component have - * requested-ha-state == confirmed-ha-state or has the operation failed - * flag set - * C8 - all components on current instantiation level == UNINSTANTIATED - * C9 - current instantiation level < lowest instantiation level - * C10 - all si-assignments related to current service unit have - * requested-ha-state == confirmed-ha-state or the operation failed - * flag set. - * C11 - for each si-assignment related to current su where - * requested-ha-state != confirmed-ha-state and requested-ha-state == - * ACTIVE - * C12 - for each si-assignment related to current su where - * requested-ha-state != confirmed-ha-state and requested-ha-state == - * STANDBY - * C13 - at least one component has presence state == TERMINATION_FAILED - * C14 - all components on current instantiation level == INSTANTIATED, - * INSTANTIATION_FAILED or INSTANTIATION_FAILED_REBOOT_NODE - * C15 - current instantiation level is highest - * C16 - all components has presence state == INSTANTIATED - * C17 - at least one component has presence state == INSTANTIATION_FAILED and - * it is not allowed to reboot the node because of this problem - * C18 - at least one component has presence state == INSTANTIATION_FAILED and - * it is allowed to reboot the node to recover from this problem - * C19 - all components in the SU permit restart - * - * 1.4.2 Composed Guards - * ===================== - * - * C100 - C9 & C13 - * C101 - C9 & C18 - * C102 - C9 & C17 - * C103 - C8 & C9 & !C13 - * C104 - C8 & C9 & C13 - * C105 - C14 & (C17 | C18) - * C106 - C14 & C15 & C16 - * - * 1.5 Events - * ========== - * - * E1 - component restart request - * E2 - restart - * E3 - probation timer expired - * E4 - escalation reverted - * E5 - operation failed - * E6 - deactivated - * E7 - comp_state(prsm, INSTANTIATED) - * E8 - comp_state(prsm, INSTANTIATION_FAILED) - * E9 - comp_state(prsm, TERMINATION_FAILED) - * E10 - si_state(ha-state) - * E11 - activated - * E12 - comp_state(prsm, UNINSTANTIATED) - * E13 - - * E14 - - * - */ - -#include -#include -#include -#include -#include - -#include "amf.h" -#include "util.h" -#include "logsys.h" -#include "main.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -static int terminate_all_components_in_level (struct amf_su *su, - SaUint32T current_instantiation_level); -static int are_all_comps_in_level_uninst_or_term_failed (struct amf_su *su); -static int are_all_comps_in_level_instantiated (struct amf_su *su); -static int instantiate_all_components_in_level (struct amf_su *su, - SaUint32T current_instantiation_level); -static SaUint32T su_lowest_comp_instantiation_level_set (struct amf_su *su); -static void si_ha_state_assumed_cbfn ( - struct amf_si_assignment *si_assignment, int result); -static int is_any_component_instantiating (amf_su_t *su); - -typedef struct su_event { - amf_su_event_type_t event_type; - amf_su_t *su; - amf_comp_t *comp; - SaAmfRecommendedRecoveryT recommended_recovery; -} su_event_t; - -/****************************************************************************** - * Internal (static) utility functions - *****************************************************************************/ - - -static void su_event_set(struct amf_su *su, struct amf_comp *comp, - SaAmfRecommendedRecoveryT recommended_recovery, - su_event_t *su_event, amf_su_event_type_t event_type) -{ - su_event->event_type = event_type; - su_event->comp = comp; - su_event->su = su; - su_event->recommended_recovery = recommended_recovery; -} - -static void su_defer_event (amf_su_t *su, amf_comp_t *comp, - SaAmfRecommendedRecoveryT recommended_recovery, - amf_su_event_type_t su_event_type) -{ - su_event_t event; - su_event_set(su, comp, recommended_recovery,&event, su_event_type); - - ENTER("event_type = %d", event.event_type); - amf_fifo_put (event.event_type, &event.su->deferred_events, - sizeof (su_event_t), &event); -} - -static void su_recall_deferred_events (amf_su_t *su) -{ - su_event_t su_event; - - ENTER ("%s", su->name.value); - if (amf_fifo_get (&su->deferred_events, &su_event)) { - switch (su_event.event_type) { - case SU_COMP_ERROR_SUSPECTED_EV: - amf_su_comp_error_suspected (su_event.su,su_event.comp, - su_event.recommended_recovery); - break; - default: - dprintf("event_type = %d", su_event.event_type); - break; - } - } -} - -static int has_component_restarted_max_times (amf_comp_t *comp, amf_su_t *su) -{ - return comp->saAmfCompRestartCount >= su->sg->saAmfSGCompRestartMax; -} - -#ifdef COMPILE_OUT -static int has_su_restarted_max_times (amf_su_t *su) -{ - return su->saAmfSURestartCount >= su->sg->saAmfSGSuRestartMax; -} -#endif - -/** - * This function only logs since the readiness state is runtime - * calculated. - * @param su - * @param amf_readiness_state - */ -static void su_readiness_state_set (struct amf_su *su, - SaAmfReadinessStateT readiness_state) -{ - log_printf (LOG_NOTICE, "Setting SU '%s' readiness state: %s\n", - su->name.value, amf_readiness_state (readiness_state)); -} - -static void clear_ha_state ( - struct amf_su *su, struct amf_si_assignment *si_assignment) -{ - ENTER (""); - si_assignment->saAmfSISUHAState = 0; -} - -/** - * This function sets presence state to the specified value. It also has the - * following intentional side effects: - * - sets HA-state to unknown when presence state is set to UNINSTANTIATED - * - reports the change of presence state to the sg in which su is contained - * when the new state is 'stable' - * @param su - * @param presence_state - new value of presence state - */ -static void su_presence_state_set (struct amf_su *su, - SaAmfPresenceStateT presence_state) -{ - /* - * Set all SI's confirmed HA state to unknown if uninstantiated - */ - if (su->saAmfSUPresenceState == SA_AMF_PRESENCE_UNINSTANTIATED) { - amf_su_foreach_si_assignment (su, clear_ha_state); - } - - - su->saAmfSUPresenceState = presence_state; - log_printf (LOG_NOTICE, "Setting SU '%s' presence state: %s\n", - su->name.value, amf_presence_state (presence_state)); - - - if (su->restart_control_state != SU_RC_RESTART_SU_SETTING && - su->restart_control_state != SU_RC_RESTART_COMP_RESTARTING) { - amf_sg_su_state_changed (su->sg, su, SA_AMF_PRESENCE_STATE, - presence_state); - } -} -static void enter_idle (struct amf_su *su) -{ - su->restart_control_state = su->escalation_level_history_state; -} - -static void enter_idle_with_recall (struct amf_su *su) -{ - su->restart_control_state = su->escalation_level_history_state; - su_recall_deferred_events (su); -} - -/** - * This function sets operational state to the specified value. It also has the - * following side effects: - * - sets the readiness state for su - * - sets the readiness state for all components contained in the su - * @param su - * @param oper_state - new value of operational state - */ -void amf_su_operational_state_set (struct amf_su *su, - SaAmfOperationalStateT oper_state) -{ - struct amf_comp* comp; - - su->saAmfSUOperState = oper_state; - log_printf (LOG_NOTICE, "Setting SU '%s' operational state: %s\n", - su->name.value, amf_op_state (oper_state)); - - if (oper_state == SA_AMF_OPERATIONAL_ENABLED) { - su_readiness_state_set (su, SA_AMF_READINESS_IN_SERVICE); - - for (comp = su->comp_head; comp; comp = comp->next) { - amf_comp_readiness_state_set (comp, SA_AMF_READINESS_IN_SERVICE); - } - } else if (oper_state == SA_AMF_OPERATIONAL_DISABLED) { - su_readiness_state_set (su, SA_AMF_READINESS_OUT_OF_SERVICE); - for (comp = su->comp_head; comp; comp = comp->next) { - amf_comp_readiness_state_set (comp, SA_AMF_READINESS_OUT_OF_SERVICE); - } - } -} - -/** - * This function creates a new csi-assignment object and initializes it. The - * function also links the new csi-assignment object to the list of assignments - * held by the specified csi object, sets a pointer to the specified component - * and a pointer to the specified si-assignment. - * @param comp - * @param csi - * @param si_assignment - * @param ha_state - new value of ha-state - */ -static void comp_assign_csi (struct amf_comp *comp, struct amf_csi *csi, - struct amf_si_assignment *si_assignment, SaAmfHAStateT ha_state) -{ - struct amf_csi_assignment *csi_assignment; - - dprintf (" Creating CSI '%s' to comp '%s' with hastate %s\n", - getSaNameT (&csi->name), getSaNameT (&comp->name), - amf_ha_state (ha_state)); - - csi_assignment = amf_malloc (sizeof (struct amf_csi_assignment)); - csi_assignment->next = csi->assigned_csis; - csi->assigned_csis = csi_assignment; - amf_comp_dn_make (comp, &csi_assignment->name); - csi_assignment->comp = comp; - csi_assignment->csi = csi; - csi_assignment->saAmfCSICompHAState = 0; /* undefined confirmed HA state */ - csi_assignment->requested_ha_state = ha_state; - csi_assignment->si_assignment = si_assignment; -} - - -static void comp_restart (struct amf_comp *comp) -{ - SaNameT dn; - - ENTER ("'%s'", comp->name.value); - amf_comp_dn_make (comp, &dn); - log_printf (LOG_NOTICE, "Error detected for '%s', recovery " - "action: Component restart", dn.value); - - comp->su->restart_control_state = SU_RC_RESTART_COMP_DEACTIVATING; - comp->su->restart_control_state = SU_RC_RESTART_COMP_RESTARTING; - comp->su->escalation_level_history_state = SU_RC_IDLE_ESCALATION_LEVEL_1; - amf_comp_restart (comp); -} - -/** - * Set the same HA-state as the before the restart to the SI-assignments - * associated with current SU. As a side effect, this HA-state will also be set - * to all components which are associated with the csi-assignments associated to - * the specified su via its csi and si objects. - * @param su - * @param current_instantiation_level - * - * @return - 1 if there were no components on the specified instantiation level - */ -static void reassume_ha_state(struct amf_su *su) -{ - struct amf_si_assignment *si_assignment; - - ENTER (""); - - si_assignment = amf_su_get_next_si_assignment(su, NULL); - - while (si_assignment != NULL) { - si_assignment->saAmfSISUHAState = 0; /* unknown */ - amf_si_ha_state_assume (si_assignment, si_ha_state_assumed_cbfn); - si_assignment = amf_su_get_next_si_assignment(su, si_assignment); - } -} - -static int is_any_component_instantiating (amf_su_t *su) -{ - amf_comp_t *component; - int any_component_instantiating = 0; - for (component = su->comp_head; component != NULL; - component = component->next) { - if (component->saAmfCompPresenceState == - SA_AMF_PRESENCE_INSTANTIATING) { - any_component_instantiating = 1; - break; - } - - } - return any_component_instantiating; -} - -static int is_any_component_terminating (amf_su_t *su) -{ - amf_comp_t *component; - int any_component_terminating = 0; - for (component = su->comp_head; component != NULL; - component = component->next) { - if (component->saAmfCompPresenceState == - SA_AMF_PRESENCE_TERMINATING) { - any_component_terminating = 1; - break; - } - - } - return any_component_terminating; -} - - -static int is_any_comp_instantiation_failed (amf_su_t *su) -{ - amf_comp_t *comp_; - int comp_instantiation_failed = 0; - - for (comp_ = su->comp_head; comp_ != NULL; comp_ = comp_->next) { - - if (comp_->saAmfCompPresenceState == - SA_AMF_PRESENCE_INSTANTIATION_FAILED) { - comp_instantiation_failed = 1; - break; - } - } - return comp_instantiation_failed; -} - -static int is_any_comp_termination_failed (amf_su_t *su) -{ - amf_comp_t *comp_; - int comp_instantiation_failed = 0; - - for (comp_ = su->comp_head; comp_ != NULL; comp_ = comp_->next) { - - if (comp_->saAmfCompPresenceState == - SA_AMF_PRESENCE_TERMINATION_FAILED) { - comp_instantiation_failed = 1; - break; - } - } - return comp_instantiation_failed; -} - -/** - * Finds the component within the specified su that has the highest value of it - * presence state. With current definition of values the highest value can also - * be regarded as the 'worst' in the sence of capability to be assigned - * workload. In the 'best' presence state (INSTANTIATED) the component is - * immediately available to take workload while in the 'worst' state - * (TERMINATION_FAILED) it can not take any workload before it has been manually - * repaired. - * @param su - * - * @return - worst presence state - */ -static SaAmfPresenceStateT get_worst_comps_presence_state_in_su (amf_su_t *su) -{ - amf_comp_t *component; - SaAmfPresenceStateT worst_presence_state = 0; - - for (component = su->comp_head; component != NULL; - component = component->next) { - if (component->saAmfCompPresenceState > worst_presence_state) { - worst_presence_state = component->saAmfCompPresenceState; - } - } - return worst_presence_state; -} - -/** - * - * @param su - */ -void su_history_state_set(struct amf_su *su, SaAmfPresenceStateT state) -{ - su->restart_control_state = su->escalation_level_history_state; - su->saAmfSUPresenceState = state; -} -/** - * A component notifies its parent su that its presence state has changed. - * @param su - * @param comp - component which has changed its presence state - * @param state - new value of presence state - */ -static void su_comp_presence_state_changed (struct amf_su *su, - struct amf_comp *comp, int state) -{ - ENTER ("'%s', '%s' %d %d", su->name.value, comp->name.value, state, - su->restart_control_state); - amf_node_t *node = amf_node_find (&comp->su->saAmfSUHostedByNode); - switch (state) { - case SA_AMF_PRESENCE_INSTANTIATED: - switch (su->restart_control_state) { - case SU_RC_IDLE_ESCALATION_LEVEL_1: - case SU_RC_IDLE_ESCALATION_LEVEL_2: - case SU_RC_IDLE_ESCALATION_LEVEL_0: - if (!is_any_component_instantiating (su)) { - if (are_all_comps_in_level_instantiated (su)) { - if (instantiate_all_components_in_level (su, - ++comp->su->current_comp_instantiation_level)) { - /* All levels of instantiation is done */ - su_presence_state_set (comp->su, - SA_AMF_PRESENCE_INSTANTIATED); - } - } else { - if (is_any_comp_instantiation_failed (su)) { - su_presence_state_set (su, - SA_AMF_PRESENCE_INSTANTIATION_FAILED); - - } else { - assert (0); - } - } - } - break; - case SU_RC_RESTART_COMP_RESTARTING: - su->restart_control_state = SU_RC_RESTART_COMP_SETTING; - reassume_ha_state (comp->su); - break; - case SU_RC_RESTART_SU_INSTANTIATING: - if (!is_any_component_instantiating(su)) { - if (are_all_comps_in_level_instantiated (su)) { - if (instantiate_all_components_in_level (su, - ++comp->su->current_comp_instantiation_level)) { - su->restart_control_state = SU_RC_RESTART_SU_SETTING; - su_presence_state_set (comp->su, - SA_AMF_PRESENCE_INSTANTIATED); - reassume_ha_state (comp->su); - } - } else if (is_any_comp_instantiation_failed (su)) { - su->restart_control_state = - SU_RC_TERMINATING_AFTER_INSTANTIATION_FAILED; - terminate_all_components_in_level (su, - su->current_comp_instantiation_level); - } else { - assert (0); - } - } - break; - default: - dprintf ("state %d", su->restart_control_state); - assert (0); - break; - } - break; - case SA_AMF_PRESENCE_UNINSTANTIATED: - switch (su->restart_control_state) { - case SU_RC_IDLE_ESCALATION_LEVEL_0: - case SU_RC_IDLE_ESCALATION_LEVEL_1: - case SU_RC_IDLE_ESCALATION_LEVEL_2: - if (!is_any_component_terminating (su)) { - if (are_all_comps_in_level_uninst_or_term_failed (su)) { - if (terminate_all_components_in_level (su, - --su->current_comp_instantiation_level)) { - su_presence_state_set (su, - get_worst_comps_presence_state_in_su (su)); - } else { - if (is_any_comp_termination_failed (su)) { - su_presence_state_set (comp->su, - SA_AMF_PRESENCE_TERMINATION_FAILED); - } else { - assert (0); - } - } - } - } - break; - case SU_RC_RESTART_SU_INSTANTIATING: - break; - case SU_RC_RESTART_COMP_RESTARTING: - break; - case SU_RC_TERMINATING_AFTER_INSTANTIATION_FAILED: - if (!is_any_component_terminating (su)) { - if (terminate_all_components_in_level (su, - --su->current_comp_instantiation_level)) { - if (!is_any_comp_termination_failed (su)) { - su_presence_state_set (su, - SA_AMF_PRESENCE_INSTANTIATION_FAILED); - if (node->saAmfNodeRebootOnInstantiationFailure) { - amf_node_failover(node); - } else { - amf_node_comp_failover_req(node, comp); - } - enter_idle (su); - } else { - if (!node->saAmfNodeRebootOnTerminationFailure) { - su_presence_state_set (su, - get_worst_comps_presence_state_in_su (su)); - } else { - /* TODO Implement and request Node Failed Fast */ - ; - } - enter_idle_with_recall (su); - } - } - } - break; - case SU_RC_RESTART_SU_TERMINATING: - if (!is_any_component_terminating (su)) { - if (terminate_all_components_in_level (su, - --su->current_comp_instantiation_level)) { - if (!is_any_comp_termination_failed (su)) { - su->restart_control_state = - SU_RC_RESTART_SU_INSTANTIATING; - instantiate_all_components_in_level (su, - su_lowest_comp_instantiation_level_set ( - su)); - } else { - if (!node->saAmfNodeRebootOnTerminationFailure) { - su_presence_state_set (su, - get_worst_comps_presence_state_in_su (su)); - } else { - /* TODO Implement and request Node Failed Fast */ - ; - } - enter_idle_with_recall (su); - } - } - } - break; - default: - dprintf ("state %d", su->restart_control_state); - assert (0); - break; - } - break; - case SA_AMF_PRESENCE_INSTANTIATING: - su_presence_state_set (comp->su,SA_AMF_PRESENCE_INSTANTIATING); - break; - case SA_AMF_PRESENCE_RESTARTING: - if (amf_su_are_all_comps_in_su (su, SA_AMF_PRESENCE_RESTARTING)) { - su_presence_state_set (comp->su, SA_AMF_PRESENCE_RESTARTING); - } - break; - case SA_AMF_PRESENCE_TERMINATING: - su_presence_state_set (comp->su, SA_AMF_PRESENCE_TERMINATING); - break; - case SA_AMF_PRESENCE_INSTANTIATION_FAILED: - switch (su->restart_control_state) { - case SU_RC_IDLE_ESCALATION_LEVEL_0: - case SU_RC_IDLE_ESCALATION_LEVEL_1: - case SU_RC_IDLE_ESCALATION_LEVEL_2: - if (!is_any_component_instantiating (su)) { - su_presence_state_set (su, - SA_AMF_PRESENCE_INSTANTIATION_FAILED); - } - break; - case SU_RC_RESTART_COMP_RESTARTING: - su->restart_control_state = - SU_RC_TERMINATING_AFTER_INSTANTIATION_FAILED; - amf_su_terminate (su); - break; - case SU_RC_RESTART_SU_INSTANTIATING: - if (!is_any_component_instantiating (su)) { - su->restart_control_state = - SU_RC_TERMINATING_AFTER_INSTANTIATION_FAILED; - su_presence_state_set (su, - SA_AMF_PRESENCE_INSTANTIATION_FAILED); - terminate_all_components_in_level (su, - su->current_comp_instantiation_level); - } - break; - default: - dprintf ("state %d", su->restart_control_state); - assert (0); - break; - } - break; - case SA_AMF_PRESENCE_TERMINATION_FAILED: - switch (su->restart_control_state) { - case SU_RC_IDLE_ESCALATION_LEVEL_0: - case SU_RC_IDLE_ESCALATION_LEVEL_1: - case SU_RC_IDLE_ESCALATION_LEVEL_2: - break; - case SU_RC_RESTART_COMP_RESTARTING: - if (!node->saAmfNodeRebootOnTerminationFailure) { - su_presence_state_set (su, - SA_AMF_PRESENCE_TERMINATION_FAILED); - enter_idle_with_recall (su); - } else { - /* TODO Implement and request Node Failed Fast */ - ; - } - break; - case SU_RC_TERMINATING_AFTER_INSTANTIATION_FAILED: - case SU_RC_RESTART_SU_TERMINATING: - if (!is_any_component_terminating (su)) { - if (terminate_all_components_in_level (su, - --su->current_comp_instantiation_level)) { - if (!node->saAmfNodeRebootOnTerminationFailure) { - su_presence_state_set (su, - get_worst_comps_presence_state_in_su (su)); - enter_idle_with_recall (su); - } else { - /* TODO Implement and request Node Failed Fast */ - ; - } - } - } - break; - default: - log_printf (LOG_LEVEL_NOTICE,"%s %d",su->name.value, - su->restart_control_state); - dprintf ("state %d", su->restart_control_state); - assert (0); - break; - } - break; - default: - assert (0); - break; - } -} - -/** - * A component notifies its parent su that its operational state has changed. - * @param su - * @param comp - component which has changed its operational state - * @param state - new value of operational state - */ -static void su_comp_op_state_changed ( - struct amf_su *su, struct amf_comp *comp, int state) -{ - ENTER ("'%s', '%s' %d", su->name.value, comp->name.value, state); - - switch (state) { - case SA_AMF_OPERATIONAL_ENABLED: - { - struct amf_comp *comp_compare; - int all_set = 1; - 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) { - amf_su_operational_state_set (comp->su, - SA_AMF_OPERATIONAL_ENABLED); - } else { - amf_su_operational_state_set (comp->su, - SA_AMF_OPERATIONAL_DISABLED); - } - break; - } - case SA_AMF_OPERATIONAL_DISABLED: - amf_su_operational_state_set (comp->su, SA_AMF_OPERATIONAL_DISABLED); - break; - default: - assert (0); - break; - } - return; -} - -/** - * Instantiates all components on specified instantiation level. - * @param su - * @param current_instantiation_level - * - * @return - 1 if there were no components on the specified instantiation level - */ -static int instantiate_all_components_in_level (struct amf_su *su, - SaUint32T current_instantiation_level) -{ - amf_comp_t *comp; - SaUint32T all_components_instantiated = 1; - - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - if (su->current_comp_instantiation_level == - comp->saAmfCompInstantiationLevel) { - all_components_instantiated = 0; - amf_comp_instantiate (comp); - } - } - return all_components_instantiated; -} - -static int are_all_comps_in_level_instantiated (struct amf_su *su) -{ - SaUint32T level = su->current_comp_instantiation_level; - amf_comp_t *comp; - int all = 1; - - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - if (level == comp->saAmfCompInstantiationLevel) { - if (comp->saAmfCompPresenceState != SA_AMF_PRESENCE_INSTANTIATED) { - all = 0; - break; - } - } - } - - return all; -} - - -static int are_all_comps_in_level_uninst_or_term_failed( - struct amf_su *su) -{ - SaUint32T level = su->current_comp_instantiation_level; - amf_comp_t *comp; - int all = 1; - - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - if (level == comp->saAmfCompInstantiationLevel) { - if (comp->saAmfCompPresenceState != SA_AMF_PRESENCE_UNINSTANTIATED && - comp->saAmfCompPresenceState != SA_AMF_PRESENCE_TERMINATION_FAILED) { - all = 0; - break; - } - } - } - - return all; -} -static void su_rc_enter_idle_escalation_level_1 (amf_comp_t *component, - SaAmfRecommendedRecoveryT recommended_recovery) -{ - ENTER(""); - component->su->restart_control_state = SU_RC_IDLE_ESCALATION_LEVEL_1; - if (has_component_restarted_max_times (component, component->su)) { - component->su->restart_control_state = SU_RC_IDLE_ESCALATION_LEVEL_2; - amf_su_comp_error_suspected (component->su, component, recommended_recovery); - } else { - comp_restart (component); - } -} -static void su_rc_enter_idle_escalation_level_2 (amf_comp_t *component, - SaAmfRecommendedRecoveryT recommended_recovery) -{ - ENTER(""); - component->su->restart_control_state = SU_RC_IDLE_ESCALATION_LEVEL_2; - amf_node_t *node = amf_node_find (&component->su->saAmfSUHostedByNode); - amf_node_comp_restart_req (node, component); -} -static int get_instantiation_max_level (amf_su_t *su) -{ - amf_comp_t *comp; - int instantiation_level = 0; - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - if (comp->saAmfCompInstantiationLevel > instantiation_level) { - instantiation_level = comp->saAmfCompInstantiationLevel; - } - } - return instantiation_level; -} -/** - * Initiates the termination of all components which have the specified - * instantiation level. - * @param su - * @param current_instantiation_level - * - * @return int -1 if no component has the specified instantiation level - */ -static int terminate_all_components_in_level (struct amf_su *su, - SaUint32T current_instantiation_level) -{ - amf_comp_t *comp; - int all_components_in_level = 1; - TRACE8("terminate comp->saAmfCompInstantiationLevel=%u", - current_instantiation_level); - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - /* - * Terminate all components in instantiation level in SU - * abruptly. - */ - if (comp->saAmfCompInstantiationLevel == current_instantiation_level) { - amf_comp_error_suspected_set (comp); - amf_comp_terminate (comp); - all_components_in_level = 0; - } - } - return all_components_in_level; -} -/** - * su_current_instantiation_level_init - * @param su - * - * @return SaUint32T - the value of the instantiation level which has been set - */ -static SaUint32T su_lowest_comp_instantiation_level_set (struct amf_su *su) -{ - amf_comp_t *component = su->comp_head; - int comp_instantiation_level = component->saAmfCompInstantiationLevel; - for (; component != NULL; component = component->next) { - TRACE1("component->saAmfCompInstantiationLevel=%d", - component->saAmfCompInstantiationLevel); - - if (component->saAmfCompInstantiationLevel < - comp_instantiation_level) { - comp_instantiation_level = - component->saAmfCompInstantiationLevel; - } - } - su->current_comp_instantiation_level = comp_instantiation_level; - return comp_instantiation_level; -} - - -/** - * An order to SU to instantiate its components. - * @param su - * - * @return int - 1 if its state allows it to request its contained components to - * instantiate or its state indicates that its components are in - * the process of instantiation. - */ -int amf_su_instantiate (struct amf_su *su) -{ - int is_instantiating = 1; - - ENTER ("'%s %d'", su->name.value, su->saAmfSUPresenceState); - switch (su->saAmfSUPresenceState) { - case SA_AMF_PRESENCE_UNINSTANTIATED: - instantiate_all_components_in_level(su, - su_lowest_comp_instantiation_level_set (su)); - break; - case SA_AMF_PRESENCE_RESTARTING: - case SA_AMF_PRESENCE_INSTANTIATING: - break; - case SA_AMF_PRESENCE_INSTANTIATED: - case SA_AMF_PRESENCE_TERMINATING: - case SA_AMF_PRESENCE_INSTANTIATION_FAILED: - case SA_AMF_PRESENCE_TERMINATION_FAILED: - is_instantiating = 0; - break; - default: - assert (0); - break; - - } - return is_instantiating; -} - -/** - * An order to SU to terminate its components. - * @param su - */ -void amf_su_terminate (struct amf_su *su) -{ - ENTER ("'%s'", su->name.value); - su->current_comp_instantiation_level = get_instantiation_max_level (su); - - terminate_all_components_in_level (su, su->current_comp_instantiation_level); -} - -/** - * Called by a component to report a suspected error on a component - * @param su - * @param comp - * @param recommended_recovery - */ -void amf_su_comp_error_suspected ( - struct amf_su *su, - struct amf_comp *comp, - SaAmfRecommendedRecoveryT recommended_recovery) -{ - ENTER ("Comp '%s', SU '%s' %d", comp->name.value, su->name.value, - su->restart_control_state); - - switch (su->restart_control_state) { - case SU_RC_IDLE_ESCALATION_LEVEL_0: - su_rc_enter_idle_escalation_level_1 (comp, - recommended_recovery); - break; - - case SU_RC_IDLE_ESCALATION_LEVEL_1: - if (has_component_restarted_max_times (comp, su)) { - su_rc_enter_idle_escalation_level_2 (comp, - recommended_recovery); - } else { - comp_restart (comp); - } - break; - case SU_RC_IDLE_ESCALATION_LEVEL_2: { - amf_node_t *node = amf_node_find (&comp->su->saAmfSUHostedByNode); - amf_node_comp_restart_req (node, comp); - -#ifdef COMPILE_OUT - if (su->saAmfSURestartCount >= su->sg->saAmfSGSuRestartMax) { - - /* - * TODO: delegate to node - */ - SaNameT dn; - amf_comp_operational_state_set (comp, - SA_AMF_OPERATIONAL_DISABLED); - amf_su_operational_state_set (su, - SA_AMF_OPERATIONAL_DISABLED); - - amf_comp_dn_make (comp, &dn); - log_printf (LOG_NOTICE, "Error detected for '%s', recovery " - "action:\n\t\tSU failover", dn.value); - amf_sg_failover_su_req (comp->su->sg, comp->su, this_amf_node); - return; - } else { - su_restart (comp->su); - } -#endif - break; - } - case SU_RC_RESTART_SU_SETTING: - case SU_RC_RESTART_COMP_RESTARTING: - case SU_RC_RESTART_COMP_SETTING: - /* TODO: Complete the implementation of SU defer event */ - su_defer_event (su, comp, recommended_recovery, - SU_COMP_ERROR_SUSPECTED_EV); - break; - default: - dprintf ("restart_control_state = %d",su->restart_control_state); - break; - } -} - -/** - * An order to SU to unconditionally restart itself. - * @param su - */ -void amf_su_restart (struct amf_su *su) -{ - SaNameT dn; - - ENTER ("'%s'", su->name.value); - - amf_su_dn_make (su, &dn); - log_printf (LOG_NOTICE, "Error detected for '%s', recovery " - "action: SU restart", dn.value); - - su->restart_control_state = SU_RC_RESTART_SU_DEACTIVATING; - su->restart_control_state = SU_RC_RESTART_SU_TERMINATING; - su->escalation_level_history_state = SU_RC_IDLE_ESCALATION_LEVEL_2; - su->current_comp_instantiation_level = get_instantiation_max_level (su); - su->saAmfSURestartCount += 1; - terminate_all_components_in_level(su, su->current_comp_instantiation_level); -} - -/****************************************************************************** - * Event response methods - *****************************************************************************/ - -/** - * Used by a component to report a state change event - * @param su - * @param comp - * @param type type of state - * @param state new state - */ -void amf_su_comp_state_changed ( - struct amf_su *su, struct amf_comp *comp, SaAmfStateT type, int state) -{ - switch (type) { - case SA_AMF_PRESENCE_STATE: - su_comp_presence_state_changed (su, comp, state); - break; - case SA_AMF_OP_STATE: - su_comp_op_state_changed (su, comp, state); - break; - default: - assert (0); - break; - } -} - -static void si_ha_state_assumed_cbfn ( - struct amf_si_assignment *si_assignment, int result) -{ - struct amf_si_assignment *tmp_si_assignment; - struct amf_comp *comp; - struct amf_csi_assignment *csi_assignment; - int all_confirmed = 1; - ENTER (""); - tmp_si_assignment = amf_su_get_next_si_assignment(si_assignment->su, NULL); - - while (tmp_si_assignment != NULL) { - for (comp = tmp_si_assignment->su->comp_head; comp != NULL; - comp = comp->next) { - - csi_assignment = amf_comp_get_next_csi_assignment(comp, NULL); - while (csi_assignment != NULL) { - - if (csi_assignment->requested_ha_state != - csi_assignment->saAmfCSICompHAState) { - all_confirmed = 0; - } - csi_assignment = amf_comp_get_next_csi_assignment( - comp, csi_assignment); - } - } - tmp_si_assignment = amf_su_get_next_si_assignment( - si_assignment->su, tmp_si_assignment); - } - - if (all_confirmed) { - switch (si_assignment->su->restart_control_state) { - case SU_RC_RESTART_COMP_SETTING: - log_printf (LOG_NOTICE, "Component restart recovery finished"); - break; - case SU_RC_RESTART_SU_SETTING: - log_printf (LOG_NOTICE, "SU restart recovery finished"); - break; - default: - assert (0); - break; - } - enter_idle_with_recall (si_assignment->su); - } -} - -/****************************************************************************** - * General methods - *****************************************************************************/ - -/** - * Constructor for SU objects. Adds SU last in the ordered - * list owned by the specified SG. Always returns a - * valid SU object, out-of-memory problems are handled here. - * Default values are initialized. - * @param sg - * @param name - * - * @return struct amf_su* - */ -struct amf_su *amf_su_new (struct amf_sg *sg, char *name) -{ - struct amf_su *tail = sg->su_head; - struct amf_su *su = amf_calloc (1, sizeof (struct amf_su)); - - while (tail != NULL) { - if (tail->next == NULL) { - break; - } - tail = tail->next; - } - - if (tail == NULL) { - sg->su_head = su; - } else { - tail->next = su; - } - su->sg = sg; - - /* setup default values from spec. */ - su->saAmfSURank = 0; - su->saAmfSUIsExternal = 0; - su->saAmfSUFailover = 1; - su->saAmfSUAdminState = SA_AMF_ADMIN_UNLOCKED; - su->saAmfSUOperState = SA_AMF_OPERATIONAL_DISABLED; - su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED; - su->restart_control_state = SU_RC_IDLE_ESCALATION_LEVEL_0; - su->current_comp_instantiation_level = 0; - setSaNameT (&su->name, name); - - return su; -} - -void amf_su_delete (struct amf_su *su) -{ - struct amf_comp *comp; - - for (comp = su->comp_head; comp != NULL;) { - struct amf_comp *tmp = comp; - comp = comp->next; - amf_comp_delete (tmp); - } - - free (su); -} - -void *amf_su_serialize (struct amf_su *su, int *len) -{ - char *buf = NULL; - int offset = 0, size = 0; - - TRACE8 ("%s", su->name.value); - - buf = amf_serialize_SaNameT (buf, &size, &offset, &su->name); - buf = amf_serialize_SaUint32T (buf, &size, &offset, su->saAmfSURank); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUNumComponents); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUIsExternal); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUFailover); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUPreInstantiable); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUOperState); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUAdminState); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSUPresenceState); - buf = amf_serialize_SaNameT (buf, &size, &offset, &su->saAmfSUHostedByNode); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->saAmfSURestartCount); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->restart_control_state); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->escalation_level_history_state); - buf = amf_serialize_SaStringT ( - buf, &size, &offset, su->clccli_path); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->su_failover_cnt); - buf = amf_serialize_SaUint32T ( - buf, &size, &offset, su->current_comp_instantiation_level); - - *len = offset; - - return buf; -} - -struct amf_su *amf_su_deserialize (struct amf_sg *sg, char *buf) -{ - char *tmp = buf; - struct amf_su *su = amf_su_new (sg, ""); - - tmp = amf_deserialize_SaNameT (tmp, &su->name); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSURank); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUNumComponents); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUIsExternal); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUFailover); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUPreInstantiable); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUOperState); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUAdminState); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSUPresenceState); - tmp = amf_deserialize_SaNameT (tmp, &su->saAmfSUHostedByNode); - tmp = amf_deserialize_SaUint32T (tmp, &su->saAmfSURestartCount); - tmp = amf_deserialize_SaUint32T (tmp, &su->restart_control_state); - tmp = amf_deserialize_SaUint32T (tmp, &su->escalation_level_history_state); - tmp = amf_deserialize_SaStringT (tmp, &su->clccli_path); - tmp = amf_deserialize_SaUint32T (tmp, &su->su_failover_cnt); - tmp = amf_deserialize_SaUint32T (tmp, &su->current_comp_instantiation_level); - - return su; -} - -struct amf_su *amf_su_find (struct amf_cluster *cluster, SaNameT *name) -{ - struct amf_application *app; - struct amf_sg *sg; - struct amf_su *su = NULL; - char *app_name; - char *sg_name; - char *su_name; - char *ptrptr; - char *buf; - - assert (cluster != NULL && name != NULL); - - /* malloc new buffer since strtok_r writes to its first argument */ - buf = amf_malloc (name->length + 1); - memcpy (buf, name->value, name->length + 1); - - su_name = strtok_r(buf, ",", &ptrptr); - sg_name = strtok_r(NULL, ",", &ptrptr); - app_name = strtok_r(NULL, ",", &ptrptr); - - if (su_name == NULL || sg_name == NULL || app_name == NULL) { - goto end; - } - - su_name += 6; - sg_name += 6; - app_name += 7; - - app = amf_application_find (cluster, app_name); - if (app == NULL) { - goto end; - } - - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - if (strncmp (sg_name, (char*)sg->name.value, - sg->name.length) == 0) { - for (su = sg->su_head; su != NULL; su = su->next) { - if (su->name.length == strlen(su_name) && - strncmp (su_name, (char*)su->name.value, - su->name.length) == 0) { - goto end; - } - } - } - } - -end: - free (buf); - return su; -} - -/** - * This function makes a distinguished name for specified su object. - * @param su - * @param name -[out] pointer to where the distinguished name shall be stored - * - * @return SaNameT* - distinguished name - */ -char *amf_su_dn_make (struct amf_su *su, SaNameT *name) -{ - int i; - - assert (su != NULL); - - i = snprintf((char*) name->value, SA_MAX_NAME_LENGTH, - "safSu=%s,safSg=%s,safApp=%s", - su->name.value, su->sg->name.value, su->sg->application->name.value); - assert (i <= SA_MAX_NAME_LENGTH); - name->length = i; - return (char *)name->value; -} - -/** - * An order to SU to create an si-assignment object with a specified HA-state - * between it self and a specified si. The created si-assignment is initialized - * and linked to list of assignments held by the specified si. - * This function also orders creation of all csi-assignments required - * considering the cs-types specified for the components and csi objects - * respectively. - * @param su - * @param si - * @param ha_state - * - * @return amf_si_assignment_t* - */ -amf_si_assignment_t *amf_su_assign_si (struct amf_su *su, struct amf_si *si, - SaAmfHAStateT ha_state) -{ - struct amf_si_assignment *si_assignment; - - dprintf ("Creating SI '%s' to SU '%s' with hastate %s\n", - getSaNameT (&si->name), getSaNameT (&su->name), - amf_ha_state (ha_state)); - - si_assignment = amf_malloc (sizeof (struct amf_si_assignment)); - amf_su_dn_make (su, &si_assignment->name); - si_assignment->saAmfSISUHAState = 0; /* undefined confirmed HA state */ - si_assignment->requested_ha_state = ha_state; - si_assignment->next = si->assigned_sis; - si->assigned_sis = si_assignment; - si_assignment->si = si; - si_assignment->su = su; - - { - struct amf_csi *csi; - struct amf_comp *comp; - SaNameT *cs_type; - int i; - - /* - ** for each component in SU, find a CSI in the SI with the same type - */ - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - int no_of_cs_types = 0; - for (i = 0; comp->saAmfCompCsTypes[i]; i++) { - cs_type = comp->saAmfCompCsTypes[i]; - no_of_cs_types++; - int no_of_assignments = 0; - - for (csi = si->csi_head; csi != NULL; csi = csi->next) { - if (!memcmp(csi->saAmfCSTypeName.value, cs_type->value, - cs_type->length)) { - comp_assign_csi (comp, csi, si_assignment, ha_state); - no_of_assignments++; - } - } - if (no_of_assignments == 0) { - log_printf ( - LOG_WARNING, "\t No CSIs of type %s configured?!!\n", - getSaNameT (cs_type)); - } - } - if (no_of_cs_types == 0) { - log_printf (LOG_LEVEL_ERROR, - "\t No CS types configured for comp %s ?!!\n", - getSaNameT (&comp->name)); - } - } - } - return si_assignment; -} - -struct amf_si_assignment *amf_su_get_next_si_assignment ( - struct amf_su *su, const struct amf_si_assignment *si_assignment) -{ - struct amf_si *si; - struct amf_si_assignment *tmp_si_assignment; - SaNameT dn; - - amf_su_dn_make (su, &dn); - - if (si_assignment == NULL) { - assert (su->sg); - assert (su->sg->application); - assert (su->sg->application->si_head); - si = su->sg->application->si_head; - tmp_si_assignment = si->assigned_sis; - } else { - tmp_si_assignment = si_assignment->next; - if (tmp_si_assignment == NULL) { - si = si_assignment->si->next; - if (si == NULL) { - return NULL; - } else { - tmp_si_assignment = si->assigned_sis; - } - } else { - si = tmp_si_assignment->si; - } - } - - for (; si != NULL; si = si->next) { - if (tmp_si_assignment == NULL && si != NULL) { - tmp_si_assignment = si->assigned_sis; - } - for (; tmp_si_assignment != NULL; - tmp_si_assignment = tmp_si_assignment->next) { - - if (name_match (&tmp_si_assignment->name, &dn)) { - return tmp_si_assignment; - } - } - } - - return NULL; -} - -void amf_su_foreach_si_assignment ( - struct amf_su *su, - void (*foreach_fn)(struct amf_su *su, - struct amf_si_assignment *si_assignment)) -{ - struct amf_si_assignment *si_assignment; - - assert (foreach_fn != NULL); - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - foreach_fn (su, si_assignment); - si_assignment = amf_su_get_next_si_assignment (su, si_assignment); - } -} - -/** - * This function calculates the number of si-assignments with active HA-state - * which currently are associated with the specified su. - * TODO: Split into two functions and remove dependency to sg's avail_state - * @param su - * - * @return int - */ -int amf_su_get_saAmfSUNumCurrActiveSIs(struct amf_su *su) -{ - int cnt = 0; - struct amf_si_assignment *si_assignment; - - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - if (su->sg->avail_state == SG_AC_AssigningOnRequest && - si_assignment->requested_ha_state == SA_AMF_HA_ACTIVE) { - cnt++; - } else { - if (si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) { - cnt++; - } - } - si_assignment = amf_su_get_next_si_assignment (su, si_assignment); - } - - return cnt; -} - -/** - * This function calculates the number of si-assignments with standby HA-state - * which currently are associated with the specified su. - * TODO: Split into two functions and remove dependency to sg's avail_state - * @param su - * - * @return int - */ -int amf_su_get_saAmfSUNumCurrStandbySIs(struct amf_su *su) -{ - int cnt = 0; - struct amf_si_assignment *si_assignment; - - si_assignment = amf_su_get_next_si_assignment (su, NULL); - while (si_assignment != NULL) { - if (su->sg->avail_state == SG_AC_AssigningOnRequest && - si_assignment->requested_ha_state == SA_AMF_HA_STANDBY) { - cnt++; - } else { - if (si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) { - cnt++; - } - } - si_assignment = amf_su_get_next_si_assignment (su, si_assignment); - } - - return cnt; -} - -/** - * This function calculates the readiness state for specified su - * @param su - * - * @return SaAmfReadinessStateT - */ -SaAmfReadinessStateT amf_su_get_saAmfSUReadinessState (struct amf_su *su) -{ - if ((su->saAmfSUOperState == SA_AMF_OPERATIONAL_ENABLED) && - ((su->saAmfSUPresenceState == SA_AMF_PRESENCE_INSTANTIATED) || - (su->saAmfSUPresenceState == SA_AMF_PRESENCE_RESTARTING))) { - return SA_AMF_READINESS_IN_SERVICE; - } else if (su->saAmfSUOperState == SA_AMF_OPERATIONAL_ENABLED) { - return SA_AMF_READINESS_STOPPING; - } else { - return SA_AMF_READINESS_OUT_OF_SERVICE; - } -} - -/** - * Determine if the SU is hosted on the local node. - * @param su - * - * @return int - */ -int amf_su_is_local (struct amf_su *su) -{ - if (name_match (&this_amf_node->name, &su->saAmfSUHostedByNode)) { - return 1; - } else { - return 0; - } -} - -/** - * Determine if all components have the specified HA-state. - * @param su - * @param state -specified HA-state - * - * @return int - return 0 if not all components have the specified HA-state - */ -int amf_su_are_all_comps_in_su (struct amf_su *su, - SaAmfPresenceStateT state) -{ - int all_comps_in_su_are_set = 1; - amf_comp_t *component; - for (component = su->comp_head; component != NULL; - component = component->next) { - - if (component->saAmfCompPresenceState != state) { - all_comps_in_su_are_set = 0; - } - } - return all_comps_in_su_are_set; -} - diff --git a/openais/services/amfutil.c b/openais/services/amfutil.c deleted file mode 100644 index 200e366c..00000000 --- a/openais/services/amfutil.c +++ /dev/null @@ -1,1448 +0,0 @@ -/** @file exec/amfutil.c - * - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * Author: Steven Dake (sdake@redhat.com) - * - * Copyright (c) 2006 Ericsson AB. - * Author: Hans Feldt - * Description: - * - Reworked to match AMF B.02 information model Description: - * - Refactoring of code into several AMF files - * - Serializers/deserializers - * - * Copyright (c) 2007-2008 Red Hat, Inc. - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - * - * AMF utility functions - * - * This file contains functions that provide different services used by other - * AMF files. For example parsing the configuration file, printing state etc. - * - */ - -#include -#include -#include -#include -#include -#include - -#include "../include/saAis.h" -#include "../include/saAmf.h" -#include "../include/ipc_amf.h" -#include "../include/list.h" -#include "util.h" -#include "amf.h" -#include "totem.h" -#include "logsys.h" -#include "aispoll.h" -#include "main.h" -#include "service.h" - -LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO); - -#ifndef OPENAIS_CLUSTER_STARTUP_TIMEOUT -#define OPENAIS_CLUSTER_STARTUP_TIMEOUT 5000 -#endif - -struct req_exec_amf_msg { - mar_req_header_t header; -}; - -static const char *presence_state_text[] = { - "UNKNOWN", - "UNINSTANTIATED", - "INSTANTIATING", - "INSTANTIATED", - "TERMINATING", - "RESTARTING", - "INSTANTIATION_FAILED", - "TERMINATION_FAILED" -}; - -static const char *oper_state_text[] = { - "UNKNOWN", - "ENABLED", - "DISABLED" -}; - -static const char *admin_state_text[] = { - "UNKNOWN", - "UNLOCKED", - "LOCKED", - "LOCKED-INSTANTIATION", - "SHUTTING-DOWN" -}; - -static const char *readiness_state_text[] = { - "UNKNOWN", - "OUT-OF-SERVICE", - "IN-SERVICE", -}; - -static const char *ha_state_text[] = { - "UNKNOWN", - "ACTIVE", - "STANDBY", - "QUIESCED", - "QUIESCING", -}; - -static const char *assignment_state_text[] = { - "UNKNOWN", - "UNASSIGNED", - "FULLY-ASSIGNED", - "PARTIALLY-ASSIGNED" -}; - -static int init_category (struct amf_comp *comp, char *loc) -{ - 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 -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 if (strcmp (loc, "no_recomondation") == 0) { - comp->saAmfCompRecoveryOnError = SA_AMF_NO_RECOMMENDATION; - } else { - return -1; - } - - return 0; -} - -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 *trim_str(char *str) -{ - char *s = str + strlen (str) - 1; - while (*s == '\t' || *s == ' ' || *s == '{') { - *s = '\0'; - s--; - } - - return str; -} - -static char *rm_beginning_ws(char *str) -{ - char *s = str + strlen (str) - 1; - while (*s == '\t' || *s == ' ') { - *s = '\0'; - s--; - } - s = str; - while (*s == '\t' || *s == ' ') { - s++; - } - return s; -} - -struct amf_cluster *amf_config_read (char **error_string) -{ - char buf[1024]; - char *line; - FILE *fp; - char *filename; - amf_object_type_t current_parse = AMF_NONE; - int line_number = 0; - char *loc; - int i; - struct amf_cluster *cluster; - 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 su_cnt = 0; - int sg_cnt = 0; - 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/amf.conf"; - } - - fp = fopen (filename, "r"); - if (fp == 0) { - sprintf (buf, "Can't read %s file reason = (%s).\n", - filename, strerror (errno)); - *error_string = buf; - return NULL; - } - - cluster = amf_cluster_new (); - assert (cluster != NULL); - - while (fgets (buf, 255, fp)) { - line_number += 1; - line = buf; - line[strlen(line) - 1] = '\0'; - /* - * Clear out comments and empty lines - */ - if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') { - continue; - } - - /* - * Clear out white space and tabs - */ - for (i = strlen (line) - 1; i > -1; i--) { - if (line[i] == '\t' || line[i] == ' ') { - line[i] = '\0'; - } else { - break; - } - } - - /* Trim whitespace from beginning of string */ - line = rm_beginning_ws(line); - error_reason = line; - error_reason = NULL; - switch (current_parse) { - case AMF_NONE: - if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) { - setSaNameT (&cluster->name, trim_str (loc)); - current_parse = AMF_CLUSTER; - } else { - goto parse_error; - } - break; - - 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 = amf_node_new (cluster, trim_str (loc)); - cluster->node_head = node; - current_parse = AMF_NODE; - } else if ((loc = strstr_rs (line, "safApp=")) != 0) { - app = amf_application_new (cluster); - setSaNameT (&app->name, trim_str (loc)); - current_parse = AMF_APPLICATION; - sg_cnt = 0; - } else if (strstr_rs (line, "}")) { - if (cluster->saAmfClusterStartupTimeout == -1) { - error_reason = "saAmfClusterStartupTimeout missing"; - goto parse_error; - } - /* spec: set to default value if zero */ - if (cluster->saAmfClusterStartupTimeout == 0) { - cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT; - } - current_parse = AMF_NONE; - } else { - goto parse_error; - } - break; - - 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, "saAmfNodeClmNode=")) != 0) { - setSaNameT (&node->saAmfNodeClmNode, trim_str (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 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, "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; - } - if (node->saAmfNodeClmNode.length == 0) { - error_reason = "saAmfNodeClmNode missing"; - goto parse_error; - } - current_parse = AMF_CLUSTER; - } else { - goto parse_error; - } - break; - - case AMF_APPLICATION: - if ((loc = strstr_rs (line, "clccli_path=")) != 0) { - app->clccli_path = amf_strdup(loc); - } else if ((loc = strstr_rs (line, "safSg=")) != 0) { - sg = amf_sg_new (app, trim_str (loc)); - sg_cnt++; - sg->recovery_scope.comp = NULL; - sg->recovery_scope.event_type = 0; - sg->recovery_scope.node = NULL; - sg->recovery_scope.sis = NULL; - sg->recovery_scope.sus = NULL; - current_parse = AMF_SG; - su_cnt = 0; - } else if ((loc = strstr_rs (line, "safSi=")) != 0) { - si = amf_si_new (app, 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, "}")) { - if (sg_cnt == 1) { - for (si = app->si_head; si != NULL; si = si->next) { - memcpy (&si->saAmfSIProtectedbySG, &sg->name, - sizeof (SaNameT)); - } - } else { - for (si = app->si_head; si != NULL; si = si->next) { - if (si->saAmfSIProtectedbySG.length == 0) { - error_reason = "saAmfSIProtectedbySG not set in SI" - ", needed when several SGs are specified."; - goto parse_error; - } - } - } - current_parse = AMF_CLUSTER; - } else { - goto parse_error; - } - break; - - case AMF_SG: - if ((loc = strstr_rs (line, "clccli_path=")) != 0) { - sg->clccli_path = amf_strdup(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, "saAmfSGNumPrefInserviceSUs=")) != 0) { - sg->saAmfSGNumPrefInserviceSUs = atoi (loc); - } else if ((loc = strstr_rs (line, "saAmfSGNumPrefAssignedSUs=")) != 0) { - sg->saAmfSGNumPrefAssignedSUs = 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 = amf_su_new (sg, trim_str (loc)); - su_cnt++; - 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; - } - if (sg->saAmfSGNumPrefInserviceSUs == ~0) { - sg->saAmfSGNumPrefInserviceSUs = su_cnt; - } - if (sg->saAmfSGNumPrefAssignedSUs == ~0) { - sg->saAmfSGNumPrefAssignedSUs = - sg->saAmfSGNumPrefInserviceSUs; - } - current_parse = AMF_APPLICATION; - } else { - goto parse_error; - } - break; - - 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) { - su->clccli_path = amf_strdup(loc); - } else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) { - setSaNameT (&su->saAmfSUHostedByNode, loc); - } else if ((loc = strstr_rs (line, "safComp=")) != 0) { - comp = amf_comp_new (su, trim_str (loc)); - comp_env_var_cnt = 0; - comp_cs_type_cnt = 0; - 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; - } - if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) { - error_reason = "saAmfSUHostedByNode missing"; - goto parse_error; - } - current_parse = AMF_SG; - } else { - goto parse_error; - } - break; - - case AMF_COMP: - if ((loc = strstr_rs (line, "clccli_path=")) != 0) { - comp->clccli_path = amf_strdup(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 = amf_strdup(loc); - } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) { - comp->saAmfCompInstantiateCmd = amf_strdup(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 = amf_strdup(loc); - } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) { - comp->saAmfCompTerminateCmd = amf_strdup(loc); - } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) { - comp->saAmfCompTerminateTimeout = atol (loc); - } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) { - comp->saAmfCompCleanupCmdArgv = amf_strdup(loc); - } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) { - comp->saAmfCompCleanupCmd = amf_strdup(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 ((char *)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] = amf_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] = amf_strdup(line); - } else { - goto parse_error; - } - break; - - case AMF_HEALTHCHECK: - 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 = amf_strdup(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] = - amf_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] = amf_strdup(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: - error_reason = "Invalid state\n"; - goto parse_error; - break; - } - } - - fclose (fp); - - sprintf (buf, "Successfully read AMF configuration file '%s'.\n", filename); - *error_string = buf; - - return cluster; - -parse_error: - sprintf (buf, "parse error at %s: %d: %s\n", - filename, line_number, error_reason); - *error_string = buf; - fclose (fp); - return NULL; -} - -static void print_csi_assignment (struct amf_comp *comp, - struct amf_csi_assignment *csi_assignment) -{ - log_printf (LOG_INFO, " safCSI=%s\n", csi_assignment->csi->name.value); - log_printf (LOG_INFO, " HA state: %s\n", - ha_state_text[csi_assignment->saAmfCSICompHAState]); -} - -static void print_si_assignment (struct amf_su *su, - struct amf_si_assignment *si_assignment) -{ - log_printf (LOG_INFO, " safSi=%s\n", si_assignment->si->name.value); - log_printf (LOG_INFO, " HA state: %s\n", - ha_state_text[si_assignment->saAmfSISUHAState]); -} - -void amf_runtime_attributes_print (struct amf_cluster *cluster) -{ - 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; - - log_printf (LOG_INFO, "AMF runtime attributes:"); - log_printf (LOG_INFO, "==================================================="); - log_printf (LOG_INFO, "safCluster=%s", getSaNameT(&cluster->name)); - log_printf (LOG_INFO, " admin state: %s\n", - admin_state_text[cluster->saAmfClusterAdminState]); - log_printf (LOG_INFO, " state: %u\n", cluster->acsm_state); - for (node = cluster->node_head; node != NULL; node = node->next) { - log_printf (LOG_INFO, " safNode=%s\n", getSaNameT (&node->name)); - log_printf (LOG_INFO, " CLM Node: %s\n", getSaNameT (&node->saAmfNodeClmNode)); - log_printf (LOG_INFO, " node ID: %u\n", node->nodeid); - log_printf (LOG_INFO, " admin state: %s\n", - admin_state_text[node->saAmfNodeAdminState]); - log_printf (LOG_INFO, " oper state: %s\n", - oper_state_text[node->saAmfNodeOperState]); - log_printf (LOG_INFO, " acsm state: %u\n", node->acsm_state); - } - for (app = cluster->application_head; app != NULL; app = app->next) { - log_printf (LOG_INFO, " safApp=%s\n", getSaNameT(&app->name)); - log_printf (LOG_INFO, " admin state: %s\n", - admin_state_text[app->saAmfApplicationAdminState]); - log_printf (LOG_INFO, " num_sg: %d\n", app->saAmfApplicationCurrNumSG); - for (sg = app->sg_head; sg != NULL; sg = sg->next) { - log_printf (LOG_INFO, " safSg=%s\n", getSaNameT(&sg->name)); - log_printf (LOG_INFO, " avail_state: %u\n", - sg->avail_state); - log_printf (LOG_INFO, " admin state: %s\n", - admin_state_text[sg->saAmfSGAdminState]); - log_printf (LOG_INFO, " assigned SUs %d\n", - sg->saAmfSGNumCurrAssignedSUs); - log_printf (LOG_INFO, " non inst. spare SUs %d\n", - sg->saAmfSGNumCurrNonInstantiatedSpareSUs); - log_printf (LOG_INFO, " inst. spare SUs %d\n", - sg->saAmfSGNumCurrInstantiatedSpareSUs); - for (su = sg->su_head; su != NULL; su = su->next) { - log_printf (LOG_INFO, " safSU=%s\n", getSaNameT(&su->name)); - log_printf (LOG_INFO, " oper state: %s\n", - oper_state_text[su->saAmfSUOperState]); - log_printf (LOG_INFO, " admin state: %s\n", - admin_state_text[su->saAmfSUAdminState]); - log_printf (LOG_INFO, " readiness state: %s\n", - readiness_state_text[amf_su_get_saAmfSUReadinessState (su)]); - log_printf (LOG_INFO, " presence state: %s\n", - presence_state_text[su->saAmfSUPresenceState]); - log_printf (LOG_INFO, " hosted by node %s\n", - su->saAmfSUHostedByNode.value); - log_printf (LOG_INFO, " num active SIs %d\n", - amf_su_get_saAmfSUNumCurrActiveSIs (su)); - log_printf (LOG_INFO, " num standby SIs %d\n", - amf_su_get_saAmfSUNumCurrStandbySIs (su)); - log_printf (LOG_INFO, " restart count %d\n", - su->saAmfSURestartCount); - log_printf (LOG_INFO, " restart control state %d\n", - su->restart_control_state); - log_printf (LOG_INFO, " SU failover cnt %d\n", su->su_failover_cnt); - log_printf (LOG_INFO, " assigned SIs:"); - amf_su_foreach_si_assignment (su, print_si_assignment); - - for (comp = su->comp_head; comp != NULL; comp = comp->next) { - log_printf (LOG_INFO, " safComp=%s\n", getSaNameT(&comp->name)); - log_printf (LOG_INFO, " oper state: %s\n", - oper_state_text[comp->saAmfCompOperState]); - log_printf (LOG_INFO, " readiness state: %s\n", - readiness_state_text[amf_comp_get_saAmfCompReadinessState (comp)]); - log_printf (LOG_INFO, " presence state: %s\n", - presence_state_text[comp->saAmfCompPresenceState]); - log_printf (LOG_INFO, " num active CSIs %d\n", - amf_comp_get_saAmfCompNumCurrActiveCsi (comp)); - log_printf (LOG_INFO, " num standby CSIs %d\n", - amf_comp_get_saAmfCompNumCurrStandbyCsi (comp)); - log_printf (LOG_INFO, " restart count %d\n", - comp->saAmfCompRestartCount); - log_printf (LOG_INFO, " assigned CSIs:"); - amf_comp_foreach_csi_assignment ( - comp, print_csi_assignment); - } - } - } - for (si = app->si_head; si != NULL; si = si->next) { - log_printf (LOG_INFO, " safSi=%s\n", getSaNameT(&si->name)); - log_printf (LOG_INFO, " admin state: %s\n", - admin_state_text[si->saAmfSIAdminState]); - log_printf (LOG_INFO, " assignm. state: %s\n", - assignment_state_text[ - amf_si_get_saAmfSIAssignmentState (si)]); - log_printf (LOG_INFO, " active assignments: %d\n", - amf_si_get_saAmfSINumCurrActiveAssignments (si)); - log_printf (LOG_INFO, " standby assignments: %d\n", - amf_si_get_saAmfSINumCurrStandbyAssignments (si)); - for (csi = si->csi_head; csi != NULL; csi = csi->next) { - log_printf (LOG_INFO, " safCsi=%s\n", getSaNameT(&csi->name)); - } - } - } - log_printf (LOG_INFO, "==================================================="); -} - -/* to be removed... */ -int amf_enabled (struct objdb_iface_ver0 *objdb) -{ - unsigned int object_service_handle; - char *value; - int enabled = 0; - unsigned int object_find_handle; - - objdb->object_find_create ( - OBJECT_PARENT_HANDLE, - "amf", - strlen ("amf"), - &object_find_handle); - - if (objdb->object_find_next ( - object_find_handle, - &object_service_handle) == 0) { - - value = NULL; - if (!objdb->object_key_get (object_service_handle, - "mode", - strlen ("mode"), - (void *)&value, - NULL) && value) { - - if (strcmp (value, "enabled") == 0) { - enabled = 1; - } else - if (strcmp (value, "disabled") == 0) { - enabled = 0; - } - } - } - - objdb->object_find_destroy (object_find_handle); - - return enabled; -} - -const char *amf_admin_state (int state) -{ - return admin_state_text[state]; -} - -const char *amf_op_state (int state) -{ - return oper_state_text[state]; -} - -const char *amf_presence_state (int state) -{ - return presence_state_text[state]; -} - -const char *amf_ha_state (int state) -{ - return ha_state_text[state]; -} - -const char *amf_readiness_state (int state) -{ - return readiness_state_text[state]; -} - -const char *amf_assignment_state (int state) -{ - return assignment_state_text[state]; -} - -#define ALIGN_ADDR(addr) ((addr) + (4 - ((unsigned long)(addr) % 4))) - -char *amf_serialize_SaNameT (char *buf, int *size, int *offset, SaNameT *name) -{ - char *tmp = buf; - - if ((*size - *offset ) < sizeof (SaNameT)) { - *size += sizeof (SaNameT); - tmp = realloc (buf, *size); - if (tmp == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - } - - memcpy (&tmp[*offset], name, sizeof (SaNameT)); - - (*offset) += sizeof (SaNameT); - - return tmp; -} - -char *amf_serialize_SaStringT (char *buf, int *size, int *offset, SaStringT str) -{ - unsigned int len; - - if (str != NULL) { - len = strlen ((char*)str); - } else { - len = 0; - } - - return amf_serialize_opaque (buf, size, offset, str, len); -} - -char *amf_serialize_SaUint16T (char *buf, int *size, int *offset, SaUint16T num) -{ - char *tmp = buf; - - if ((*size - *offset ) < sizeof (SaUint16T)) { - *size += sizeof (SaUint16T); - tmp = realloc (buf, *size); - if (tmp == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - } - - *((SaUint16T *)&tmp[*offset]) = num; - (*offset) += sizeof (SaUint16T); - - return tmp; -} - -char *amf_serialize_SaUint32T (char *buf, int *size, int *offset, SaUint32T num) -{ - char *tmp = buf; - - if ((*size - *offset ) < sizeof (SaUint32T)) { - *size += sizeof (SaUint32T); - tmp = realloc (buf, *size); - if (tmp == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - } - - *((SaUint32T *)&tmp[*offset]) = num; - (*offset) += sizeof (SaUint32T); - - return tmp; -} - -char *amf_serialize_opaque ( - char *buf, int *size, int *offset, void *src, int cnt) -{ - unsigned int required_size; - char *tmp = buf; - - required_size = cnt + sizeof (SaUint32T); - - if ((*size - *offset ) < required_size) { - *size += required_size; - tmp = realloc (buf, *size); - if (tmp == NULL) { - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - } - - *((SaUint32T *)&tmp[*offset]) = cnt; - (*offset) += sizeof (SaUint32T); - memcpy (&tmp[*offset], src, cnt); - (*offset) += cnt; - - return tmp; -} - -char *amf_deserialize_SaNameT (char *buf, SaNameT *name) -{ - memcpy (name, buf, sizeof (SaNameT)); - return (buf + sizeof (SaNameT)); -} - -char *amf_deserialize_SaStringT (char *buf, SaStringT *str) -{ - int len; - char *tmp, *tmp_str; - - len = *((SaUint32T *)buf); - tmp = buf + sizeof (SaUint32T); - - if (len > 0) { - tmp_str = amf_malloc (len + 1); - memcpy (tmp_str, tmp, len); - tmp_str[len] = '\0'; - *str = tmp_str; - } else { - *str = NULL; - } - - tmp += len; - - return tmp; -} - -char *amf_deserialize_SaUint16T (char *buf, SaUint16T *num) -{ - *num = *((SaUint16T *)buf); - return buf + sizeof (SaUint16T); -} - -char *amf_deserialize_SaUint32T (char *buf, SaUint32T *num) -{ - *num = *((SaUint32T *)buf); - return buf + sizeof (SaUint32T); -} - -char *amf_deserialize_opaque (char *buf, void *dst, int *cnt) -{ - *cnt = *((SaUint32T *)buf); - memcpy (dst, buf + sizeof (SaUint32T), *cnt); - return buf + *cnt + sizeof (SaUint32T); -} - -void *_amf_malloc (size_t size, const char *file, unsigned int line) -{ - void *tmp = malloc (size); - - if (tmp == NULL) { - log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - - return tmp; -} - -void *_amf_calloc (size_t nmemb, size_t size, const char *file, unsigned int line) -{ - void *tmp = calloc (nmemb, size); - - if (tmp == NULL) { - log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - - return tmp; -} - -void *_amf_realloc (void* ptr, size_t size, const char *file, unsigned int line) -{ - void *tmp = realloc (ptr, size); - - if (tmp == NULL) { - log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - - return tmp; -} - -char *_amf_strdup (const char *in_str, const char *file, unsigned int line) -{ - char *out_str = strdup (in_str); - - if (out_str == NULL) { - log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line); - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); - } - - return out_str; -} - -int sa_amf_grep_one_sub_match(const char *string, char *pattern, - SaNameT *matches_arr) -{ - int status; - regex_t re; - size_t nmatch = 2; - regmatch_t pmatch[nmatch]; - - int i; - - ENTER("'%s %s'",string, pattern); - - if (regcomp(&re, pattern, REG_EXTENDED) != 0) { - status = 0; - goto out; - } - status = regexec(&re, string, nmatch, pmatch, 0); - if (status != 0) { - regfree(&re); - status = 0; - goto out; - } else { - - - for (i = 0; i < nmatch; i++) { - int sub_string_len; - sub_string_len = pmatch[i].rm_eo - pmatch[i].rm_so; - if (i==1) { - - memcpy(matches_arr[i].value, string + pmatch[i].rm_so, - sub_string_len); - matches_arr[i].value[sub_string_len] = '\0'; - } - } - status = 1; - regfree(&re); - } - out: - return status; - -} - - -int sa_amf_grep(const char *string, char *pattern, size_t nmatch, - SaNameT *matches_arr) -{ - int status; - regex_t re; - regmatch_t pmatch[nmatch]; - - int i; - - ENTER("'%s %s'",string, pattern); - if (regcomp(&re, pattern, REG_EXTENDED) != 0) { - status = 0; - goto out; - } - status = regexec(&re, string, nmatch, pmatch, 0); - if (status != 0) { - regfree(&re); - status = 0; - goto out; - } else { - - - for (i = 0; i < nmatch; i++) { - int sub_string_len; - sub_string_len = pmatch[i].rm_eo - pmatch[i].rm_so; - memcpy(matches_arr[i].value, string + pmatch[i].rm_so, - sub_string_len); - matches_arr[i].value[sub_string_len] = '\0'; - matches_arr[i].length = sub_string_len; - } - status = 1; - regfree(&re); - } -out: - return status; - -} - -/** - * Multicast a message to the cluster. Errors are treated as - * fatal and will exit the program. - * @param msg_id - * @param buf - * @param len - * - * @return int - */ -int amf_msg_mcast (int msg_id, void *buf, size_t len) -{ - struct req_exec_amf_msg msg; - struct iovec iov[2]; - int iov_cnt; - int res; - -// ENTER ("%u, %p, %u", msg_id, buf, len); - - msg.header.size = sizeof (msg); - msg.header.id = SERVICE_ID_MAKE (AMF_SERVICE, msg_id); - iov[0].iov_base = (char *)&msg; - iov[0].iov_len = sizeof (msg); - - if (buf == NULL) { - msg.header.size = sizeof (msg); - iov_cnt = 1; - } else { - msg.header.size = sizeof (msg) + len; - iov[1].iov_base = buf; - iov[1].iov_len = len; - iov_cnt = 2; - } - - res = totempg_groups_mcast_joined ( - openais_group_handle, iov, iov_cnt, TOTEMPG_AGREED); - - if (res != 0) { - dprintf("Unable to send %d bytes\n", msg.header.size); - openais_exit_error (AIS_DONE_FATAL_ERR); - } - - return res; -} - -void amf_fifo_put (int entry_type, amf_fifo_t **root, int size_of_data, - void *data) -{ - amf_fifo_t *fifo; - amf_fifo_t **new_item = root; - - /* Insert newest entry at the end of the single linked list */ - for (fifo = *root; fifo != NULL; fifo = fifo->next) { - if (fifo->next == NULL) { - new_item = &fifo->next; - } - } - *new_item = amf_malloc (size_of_data + sizeof (amf_fifo_t)); - fifo = *new_item; - - /* Set data of this entry*/ - fifo->entry_type = entry_type; - fifo->next = NULL; - fifo->size_of_data = size_of_data; - memcpy (fifo->data, data, size_of_data); -} - -int amf_fifo_get (amf_fifo_t **root, void *data) -{ - amf_fifo_t *fifo; - int result = 0; - - fifo = *root; - if (fifo != NULL) { - /* Unlink oldest entry*/ - *root = fifo->next; - memcpy (data, fifo->data, fifo->size_of_data); - free (fifo); - result = 1; - } - return result; -} - - -/** - * - * Use timer to call function f (void *data) after that current - * execution in this thread has been re-assumed because of a - * time-out. Time-out time is 0 msec so f will be called as soon - * as possible. * - * - * @param async_func - * @param func_param - */ - -void amf_call_function_asynchronous (async_func_t async_func, void *func_param) -{ - - static poll_timer_handle async_func_timer_handle; - poll_timer_add (aisexec_poll_handle, 0, func_param, async_func, - &async_func_timer_handle); -} - diff --git a/openais/services/ckpt.c b/openais/services/ckpt.c deleted file mode 100644 index aa70a623..00000000 --- a/openais/services/ckpt.c +++ /dev/null @@ -1,3927 +0,0 @@ -/* - * Copyright (c) 2003-2006 MontaVista Software, Inc. - * Copyright (c) 2006-2007 Red Hat, Inc. - * - * All rights reserved. - * - * Authors: Steven Dake (sdake@redhat.com) - * Muni Bajpai (muni.osdl@gmail.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/saAis.h" -#include "../include/saEvt.h" -#include "../include/ipc_ckpt.h" -#include "../include/mar_ckpt.h" - -LOGSYS_DECLARE_SUBSYS ("CKPT", LOG_INFO); - -#define CKPT_MAX_SECTION_DATA_SEND (1024*400) - -enum ckpt_message_req_types { - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN = 0, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE = 1, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK = 2, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET = 3, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE = 4, - MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE = 5, - MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE = 6, - MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET = 7, - MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE = 8, - MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE = 9, - MESSAGE_REQ_EXEC_CKPT_SECTIONREAD = 10, - MESSAGE_REQ_EXEC_CKPT_SYNCCHECKPOINT = 11, - MESSAGE_REQ_EXEC_CKPT_SYNCCHECKPOINTSECTION = 12, - MESSAGE_REQ_EXEC_CKPT_SYNCCHECKPOINTREFCOUNT = 13 -}; - -struct checkpoint_section { - struct list_head list; - mar_ckpt_section_descriptor_t section_descriptor; - void *section_data; - corosync_timer_handle_t expiration_timer; -}; - -enum sync_state { - SYNC_STATE_CHECKPOINT, - SYNC_STATE_REFCOUNT -}; - -enum iteration_state { - ITERATION_STATE_CHECKPOINT, - ITERATION_STATE_SECTION -}; - -struct refcount_set { - unsigned int refcount; - unsigned int nodeid; -}; - -typedef struct { - unsigned int refcount __attribute__((aligned(8))); - unsigned int nodeid __attribute__((aligned(8))); -} mar_refcount_set_t; - -static inline void marshall_to_mar_refcount_set_t ( - mar_refcount_set_t *dest, - struct refcount_set *src) -{ - dest->refcount = src->refcount; - dest->nodeid = src->nodeid; -} - -static inline void marshall_to_mar_refcount_set_t_all ( - mar_refcount_set_t *dest, - struct refcount_set *src) -{ - unsigned int i; - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - marshall_to_mar_refcount_set_t (&dest[i], &src[i]); - } -} - -static inline void marshall_from_mar_refcount_set_t ( - struct refcount_set *dest, - mar_refcount_set_t *src) -{ - dest->refcount = src->refcount; - dest->nodeid = src->nodeid; -} - -static inline void marshall_from_mar_refcount_set_t_all ( - struct refcount_set *dest, - mar_refcount_set_t *src) -{ - unsigned int i; - - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - marshall_from_mar_refcount_set_t (&dest[i], &src[i]); - } -} - -static inline void swab_mar_refcount_set_t (mar_refcount_set_t *to_swab) -{ - swab_mar_uint32_t (&to_swab->refcount); - swab_mar_uint32_t (&to_swab->nodeid); -} - -struct checkpoint { - struct list_head list; - mar_name_t name; - mar_uint32_t ckpt_id; - mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes; - struct list_head sections_list_head; - int reference_count; - int unlinked; - corosync_timer_handle_t retention_timer; - int active_replica_set; - int section_count; - struct refcount_set refcount_set[PROCESSOR_COUNT_MAX]; -}; - -struct iteration_entry { - char *section_id; - unsigned int section_id_len; -}; - -struct iteration_instance { - struct iteration_entry *iteration_entries; - mar_name_t checkpoint_name; - mar_uint32_t ckpt_id; - int iteration_entries_count; - unsigned int iteration_pos; -}; - -struct ckpt_pd { - struct list_head checkpoint_list; - struct hdb_handle_database iteration_hdb; - unsigned int iteration_pos; -}; - -struct ckpt_identifier { - mar_name_t ckpt_name; - mar_uint32_t ckpt_id; - mar_ckpt_section_id_t ckpt_section_id; -}; - -static int ckpt_exec_init_fn (struct corosync_api_v1 *); - -static int ckpt_lib_exit_fn (void *conn); - -static int ckpt_lib_init_fn (void *conn); - -static void ckpt_dump_fn (void); - -static void message_handler_req_lib_ckpt_checkpointopen ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_checkpointclose ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_checkpointunlink ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_checkpointretentiondurationset ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_activereplicaset ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_checkpointstatusget ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectioncreate ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectiondelete ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectionexpirationtimeset ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectionwrite ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectionoverwrite ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectionread ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_checkpointsynchronize ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_checkpointsynchronizeasync ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectioniterationinitialize ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectioniterationfinalize ( - void *conn, - void *msg); - -static void message_handler_req_lib_ckpt_sectioniterationnext ( - void *conn, - void *msg); - -static void message_handler_req_exec_ckpt_checkpointopen ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sync_checkpoint ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sync_checkpoint_section ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sync_checkpoint_refcount ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_checkpointclose ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_checkpointunlink ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_checkpointretentiondurationset ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_checkpointretentiondurationexpire ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sectioncreate ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sectiondelete ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sectionexpirationtimeset ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sectionwrite ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sectionoverwrite ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_ckpt_sectionread ( - void *message, - unsigned int nodeid); - -static void exec_ckpt_checkpointopen_endian_convert (void *msg); -static void exec_ckpt_checkpointclose_endian_convert (void *msg); -static void exec_ckpt_checkpointunlink_endian_convert (void *msg); -static void exec_ckpt_checkpointretentiondurationset_endian_convert (void *msg); -static void exec_ckpt_checkpointretentiondurationexpire_endian_convert (void *msg); -static void exec_ckpt_sectioncreate_endian_convert (void *msg); -static void exec_ckpt_sectiondelete_endian_convert (void *msg); -static void exec_ckpt_sectrionexpirationtimeset_endian_convert (void *msg); -static void exec_ckpt_sectionwrite_endian_convert (void *msg); -static void exec_ckpt_sectionoverwrite_endian_convert (void *msg); -static void exec_ckpt_sectionread_endian_convert (void *msg); -static void exec_ckpt_sync_checkpoint_endian_convert (void *msg); -static void exec_ckpt_sync_checkpoint_section_endian_convert (void *msg); -static void exec_ckpt_sync_checkpoint_refcount_endian_convert (void *msg); - - -static void ckpt_sync_init (void); -static void ckpt_sync_activate (void); -static int ckpt_sync_process (void); -static void ckpt_sync_abort(void); - -static void sync_refcount_increment ( - struct checkpoint *checkpoint, unsigned int nodeid); - -static void sync_refcount_decrement ( - struct checkpoint *checkpoint, unsigned int nodeid); - -static void sync_refcount_calculate ( - struct checkpoint *checkpoint); - -void checkpoint_release (struct checkpoint *checkpoint); -void timer_function_retention (void *data); -unsigned int abstime_to_msec (mar_time_t time); -void timer_function_section_expire (void *data); -void clean_checkpoint_list(struct list_head* head); - -DECLARE_LIST_INIT(checkpoint_list_head); - -DECLARE_LIST_INIT(sync_checkpoint_list_head); - -DECLARE_LIST_INIT(checkpoint_iteration_list_head); - -DECLARE_LIST_INIT(checkpoint_recovery_list_head); - -static struct corosync_api_v1 *api; - -static mar_uint32_t global_ckpt_id = 0; - -static enum sync_state my_sync_state; - -static enum iteration_state my_iteration_state; - -static struct list_head *my_iteration_state_checkpoint; - -static struct list_head *my_iteration_state_section; - -static unsigned int my_member_list[PROCESSOR_COUNT_MAX]; - -static unsigned int my_member_list_entries = 0; - -static unsigned int my_lowest_nodeid = 0; - -struct checkpoint_cleanup { - struct list_head list; - mar_name_t checkpoint_name; - mar_uint32_t ckpt_id; -}; - -static struct memb_ring_id my_saved_ring_id; - -static void ckpt_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id); - -/* - * Executive Handler Definition - */ -static struct corosync_lib_handler ckpt_lib_engine[] = -{ - { /* 0 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointopen, - .response_size = sizeof (struct res_lib_ckpt_checkpointopen), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 1 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointclose, - .response_size = sizeof (struct res_lib_ckpt_checkpointclose), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 2 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointunlink, - .response_size = sizeof (struct res_lib_ckpt_checkpointunlink), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 3 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointretentiondurationset, - .response_size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 4 */ - .lib_handler_fn = message_handler_req_lib_ckpt_activereplicaset, - .response_size = sizeof (struct res_lib_ckpt_activereplicaset), - .response_id = MESSAGE_RES_CKPT_ACTIVEREPLICASET, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 5 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointstatusget, - .response_size = sizeof (struct res_lib_ckpt_checkpointstatusget), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 6 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectioncreate, - .response_size = sizeof (struct res_lib_ckpt_sectioncreate), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 7 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectiondelete, - .response_size = sizeof (struct res_lib_ckpt_sectiondelete), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 8 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectionexpirationtimeset, - .response_size = sizeof (struct res_lib_ckpt_sectionexpirationtimeset), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 9 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectionwrite, - .response_size = sizeof (struct res_lib_ckpt_sectionwrite), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 10 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectionoverwrite, - .response_size = sizeof (struct res_lib_ckpt_sectionoverwrite), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 11 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectionread, - .response_size = sizeof (struct res_lib_ckpt_sectionread), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 12 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronize, - .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronize), - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 13 */ - .lib_handler_fn = message_handler_req_lib_ckpt_checkpointsynchronizeasync, - .response_size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync), /* TODO RESPONSE */ - .response_id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 14 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectioniterationinitialize, - .response_size = sizeof (struct res_lib_ckpt_sectioniterationinitialize), - .response_id = MESSAGE_RES_CKPT_SECTIONITERATIONINITIALIZE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 15 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectioniterationfinalize, - .response_size = sizeof (struct res_lib_ckpt_sectioniterationfinalize), - .response_id = MESSAGE_RES_CKPT_SECTIONITERATIONFINALIZE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 16 */ - .lib_handler_fn = message_handler_req_lib_ckpt_sectioniterationnext, - .response_size = sizeof (struct res_lib_ckpt_sectioniterationnext), - .response_id = MESSAGE_RES_CKPT_SECTIONITERATIONNEXT, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - } -}; - - -static struct corosync_exec_handler ckpt_exec_engine[] = { - { - .exec_handler_fn = message_handler_req_exec_ckpt_checkpointopen, - .exec_endian_convert_fn = exec_ckpt_checkpointopen_endian_convert - - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_checkpointclose, - .exec_endian_convert_fn = exec_ckpt_checkpointclose_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_checkpointunlink, - .exec_endian_convert_fn = exec_ckpt_checkpointunlink_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_checkpointretentiondurationset, - .exec_endian_convert_fn = exec_ckpt_checkpointretentiondurationset_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_checkpointretentiondurationexpire, - .exec_endian_convert_fn = exec_ckpt_checkpointretentiondurationexpire_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sectioncreate, - .exec_endian_convert_fn = exec_ckpt_sectioncreate_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sectiondelete, - .exec_endian_convert_fn = exec_ckpt_sectiondelete_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sectionexpirationtimeset, - .exec_endian_convert_fn = exec_ckpt_sectrionexpirationtimeset_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sectionwrite, - .exec_endian_convert_fn = exec_ckpt_sectionwrite_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sectionoverwrite, - .exec_endian_convert_fn = exec_ckpt_sectionoverwrite_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sectionread, - .exec_endian_convert_fn = exec_ckpt_sectionread_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sync_checkpoint, - .exec_endian_convert_fn = exec_ckpt_sync_checkpoint_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sync_checkpoint_section, - .exec_endian_convert_fn = exec_ckpt_sync_checkpoint_section_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_ckpt_sync_checkpoint_refcount, - .exec_endian_convert_fn = exec_ckpt_sync_checkpoint_refcount_endian_convert - } -}; - -struct corosync_service_engine ckpt_service_engine = { - .name = "openais checkpoint service B.01.01", - .id = CKPT_SERVICE, - .private_data_size = sizeof (struct ckpt_pd), - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED, - .lib_init_fn = ckpt_lib_init_fn, - .lib_exit_fn = ckpt_lib_exit_fn, - .lib_engine = ckpt_lib_engine, - .lib_engine_count = sizeof (ckpt_lib_engine) / sizeof (struct corosync_lib_handler), - .exec_init_fn = ckpt_exec_init_fn, - .exec_dump_fn = ckpt_dump_fn, - .exec_engine = ckpt_exec_engine, - .exec_engine_count = sizeof (ckpt_exec_engine) / sizeof (struct corosync_exec_handler), - .confchg_fn = ckpt_confchg_fn, - .sync_init = ckpt_sync_init, - .sync_process = ckpt_sync_process, - .sync_activate = ckpt_sync_activate, - .sync_abort = ckpt_sync_abort, -}; - -/* - * Dynamic loader definition - */ -static struct corosync_service_engine *ckpt_get_handler_ver0 (void); - -static struct corosync_service_engine_iface_ver0 ckpt_service_engine_iface = { - .corosync_get_service_engine_ver0 = ckpt_get_handler_ver0 -}; - -static struct lcr_iface openais_ckpt_ver0[1] = { - { - .name = "openais_ckpt", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = NULL - } -}; - -static struct lcr_comp ckpt_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_ckpt_ver0 -}; - -static struct corosync_service_engine *ckpt_get_handler_ver0 (void) -{ - return (&ckpt_service_engine); -} - -__attribute__ ((constructor)) static void register_this_component (void) { - lcr_interfaces_set (&openais_ckpt_ver0[0], &ckpt_service_engine_iface); - - lcr_component_register (&ckpt_comp_ver0); -} - -/* - * All data types used for executive messages - */ -struct req_exec_ckpt_checkpointopen { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8))); - mar_uint32_t checkpoint_creation_attributes_set __attribute__((aligned(8))); - mar_ckpt_checkpoint_open_flags_t checkpoint_open_flags __attribute__((aligned(8))); - mar_ckpt_checkpoint_handle_t checkpoint_handle __attribute__((aligned(8))); - mar_invocation_t invocation __attribute__((aligned(8))); - mar_uint32_t async_call __attribute__((aligned(8))); - mar_uint32_t fail_with_error __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_checkpointclose { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_checkpointretentiondurationset { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_time_t retention_duration __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_checkpointretentiondurationexpire { - mar_req_header_t header __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_checkpointunlink { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sectioncreate { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); - mar_uint32_t initial_data_size __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sectiondelete { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sectionexpirationtimeset { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sectionwrite { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_offset_t data_offset __attribute__((aligned(8))); - mar_offset_t data_size __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sectionoverwrite { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_offset_t data_size __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sectionread { - mar_req_header_t header __attribute__((aligned(8))); - mar_message_source_t source __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_offset_t data_offset __attribute__((aligned(8))); - mar_offset_t data_size __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sync_checkpoint { - mar_req_header_t header __attribute__((aligned(8))); - struct memb_ring_id ring_id __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_ckpt_checkpoint_creation_attributes_t checkpoint_creation_attributes __attribute__((aligned(8))); - mar_uint32_t checkpoint_creation_attributes_set __attribute__((aligned(8))); - mar_uint32_t active_replica_set __attribute__((aligned(8))); - mar_uint32_t unlinked __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sync_checkpoint_section { - mar_req_header_t header __attribute__((aligned(8))); - struct memb_ring_id ring_id __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_uint32_t id_len __attribute__((aligned(8))); - mar_time_t expiration_time __attribute__((aligned(8))); - mar_uint32_t section_size __attribute__((aligned(8))); -}; - -struct req_exec_ckpt_sync_checkpoint_refcount { - mar_req_header_t header __attribute__((aligned(8))); - struct memb_ring_id ring_id __attribute__((aligned(8))); - mar_name_t checkpoint_name __attribute__((aligned(8))); - mar_uint32_t ckpt_id __attribute__((aligned(8))); - mar_refcount_set_t refcount_set[PROCESSOR_COUNT_MAX] __attribute__((aligned(8))); -}; - -/* - * Implementation - */ - -void clean_checkpoint_list(struct list_head *head) -{ - struct list_head *checkpoint_list; - struct checkpoint *checkpoint; - - if (list_empty(head)) { - log_printf (LOG_LEVEL_DEBUG, "clean_checkpoint_list: List is empty \n"); - return; - } - - checkpoint_list = head->next; - while (checkpoint_list != head) { - checkpoint = list_entry (checkpoint_list, - struct checkpoint, list); - assert (checkpoint > 0); - - /* - * If checkpoint has been unlinked and this is the last reference, delete it - */ - if (checkpoint->unlinked && checkpoint->reference_count == 0) { - log_printf (LOG_LEVEL_DEBUG,"clean_checkpoint_list: deallocating checkpoint %s.\n", - checkpoint->name.value); - checkpoint_list = checkpoint_list->next; - checkpoint_release (checkpoint); - continue; - - } - else if (checkpoint->reference_count == 0) { - log_printf (LOG_LEVEL_DEBUG, "clean_checkpoint_list: Starting timer to release checkpoint %s.\n", - checkpoint->name.value); - api->timer_delete (checkpoint->retention_timer); - api->timer_add_duration ( - checkpoint->checkpoint_creation_attributes.retention_duration, - checkpoint, - timer_function_retention, - &checkpoint->retention_timer); - } - checkpoint_list = checkpoint_list->next; - } -} - -static void ckpt_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id) -{ - unsigned int i, j; - - /* - * Determine lowest nodeid in old regular configuration for the - * purpose of executing the synchronization algorithm - */ - if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) { - for (i = 0; i < left_list_entries; i++) { - for (j = 0; j < my_member_list_entries; j++) { - if (left_list[i] == my_member_list[j]) { - my_member_list[j] = 0; - } - } - } - } - - my_lowest_nodeid = 0xffffffff; - - /* - * Handle regular configuration - */ - if (configuration_type == TOTEM_CONFIGURATION_REGULAR) { - memcpy (my_member_list, member_list, - sizeof (unsigned int) * member_list_entries); - my_member_list_entries = member_list_entries; - memcpy (&my_saved_ring_id, ring_id, - sizeof (struct memb_ring_id)); - for (i = 0; i < my_member_list_entries; i++) { - if ((my_member_list[i] != 0) && - (my_member_list[i] < my_lowest_nodeid)) { - - my_lowest_nodeid = my_member_list[i]; - } - } - } -} - -static struct checkpoint *checkpoint_find ( - struct list_head *ckpt_list_head, - mar_name_t *name, - mar_uint32_t ckpt_id) -{ - struct list_head *list; - struct checkpoint *checkpoint; - - for (list = ckpt_list_head->next; - list != ckpt_list_head; - list = list->next) { - - checkpoint = list_entry (list, - struct checkpoint, list); - - if (mar_name_match (name, &checkpoint->name) && - ckpt_id == checkpoint->ckpt_id) { - return (checkpoint); - } - } - return (0); -} - -static struct checkpoint *checkpoint_find_linked ( - struct list_head *ckpt_list_head, - mar_name_t *name) -{ - struct list_head *list; - struct checkpoint *checkpoint; - - for (list = ckpt_list_head->next; - list != ckpt_list_head; - list = list->next) { - - checkpoint = list_entry (list, struct checkpoint, list); - - if (mar_name_match (name, &checkpoint->name) && - checkpoint->unlinked == 0) { - return (checkpoint); - } - } - return (0); -} - -static struct checkpoint *checkpoint_find_specific ( - struct list_head *ckpt_list_head, - mar_name_t *name, - mar_uint32_t ckpt_id) -{ - struct list_head *list; - struct checkpoint *checkpoint; - - for (list = ckpt_list_head->next; - list != ckpt_list_head; - list = list->next) { - - checkpoint = list_entry (list, struct checkpoint, list); - - if (mar_name_match (name, &checkpoint->name) && - (ckpt_id == checkpoint->ckpt_id)) { - return (checkpoint); - } - } - return (0); -} - -static void ckpt_checkpoint_remove_cleanup ( - void *conn, - mar_name_t checkpoint_name, - mar_uint32_t ckpt_id) -{ - struct list_head *list; - struct checkpoint_cleanup *checkpoint_cleanup; - struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)api->ipc_private_data_get (conn); - - for (list = ckpt_pd->checkpoint_list.next; - list != &ckpt_pd->checkpoint_list; - list = list->next) { - - checkpoint_cleanup = list_entry (list, struct checkpoint_cleanup, list); - if (mar_name_match (&checkpoint_cleanup->checkpoint_name, - &checkpoint_name) && - (checkpoint_cleanup->ckpt_id == ckpt_id)) { - - list_del (&checkpoint_cleanup->list); - free (checkpoint_cleanup); - return; - } - } -} - -static struct checkpoint_section *checkpoint_section_find ( - struct checkpoint *checkpoint, - char *id, - int id_len) -{ - struct list_head *checkpoint_section_list; - struct checkpoint_section *checkpoint_section; - - if (id_len != 0) { - log_printf (LOG_LEVEL_DEBUG, "Finding checkpoint section id %s %d\n", (char*)id, id_len); - } - else { - log_printf (LOG_LEVEL_DEBUG, "Finding default checkpoint section\n"); - } - - for (checkpoint_section_list = checkpoint->sections_list_head.next; - checkpoint_section_list != &checkpoint->sections_list_head; - checkpoint_section_list = checkpoint_section_list->next) { - - checkpoint_section = list_entry (checkpoint_section_list, - struct checkpoint_section, list); - if (checkpoint_section->section_descriptor.section_id.id_len) { - log_printf (LOG_LEVEL_DEBUG, "Checking section id %d %*s\n", - checkpoint_section->section_descriptor.section_id.id_len, - checkpoint_section->section_descriptor.section_id.id_len, - checkpoint_section->section_descriptor.section_id.id); - } - else { - log_printf (LOG_LEVEL_DEBUG, "Checking default section id\n"); - } - - /* - All 3 of these values being checked MUST be = 0 to return - The default section. If even one of them is NON zero follow - the normal route - */ - if ((id_len || - checkpoint_section->section_descriptor.section_id.id || - checkpoint_section->section_descriptor.section_id.id_len) == 0) { - log_printf (LOG_LEVEL_DEBUG, "Returning default section\n"); - return (checkpoint_section); - } - - if (checkpoint_section->section_descriptor.section_id.id_len == id_len && - (checkpoint_section->section_descriptor.section_id.id)&& - (id)&& - (memcmp (checkpoint_section->section_descriptor.section_id.id, - id, id_len) == 0)) { - - log_printf (LOG_LEVEL_DEBUG, "Returning section %s(0x%p)\n", checkpoint_section->section_descriptor.section_id.id, - checkpoint_section); - - return (checkpoint_section); - } - } - return 0; -} - -void checkpoint_section_release (struct checkpoint_section *section) -{ - log_printf (LOG_LEVEL_DEBUG, "checkpoint_section_release expiration timer = 0x%p\n", section->expiration_timer); - list_del (§ion->list); - - api->timer_delete (section->expiration_timer); - if (section->section_descriptor.section_id.id) { - free (section->section_descriptor.section_id.id); - } - if (section->section_data) { - free (section->section_data); - } - free (section); -} - - -void checkpoint_release (struct checkpoint *checkpoint) -{ - struct list_head *list; - struct checkpoint_section *section; - - api->timer_delete (checkpoint->retention_timer); - - /* - * Release all checkpoint sections for this checkpoint - */ - for (list = checkpoint->sections_list_head.next; - list != &checkpoint->sections_list_head;) { - - section = list_entry (list, - struct checkpoint_section, list); - - list = list->next; - checkpoint->section_count -= 1; - api->timer_delete (section->expiration_timer); - checkpoint_section_release (section); - } - list_del (&checkpoint->list); - free (checkpoint); -} - -int ckpt_checkpoint_close ( - mar_name_t *checkpoint_name, - mar_uint32_t ckpt_id) -{ - struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose; - struct iovec iovec; - - req_exec_ckpt_checkpointclose.header.size = - sizeof (struct req_exec_ckpt_checkpointclose); - req_exec_ckpt_checkpointclose.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE); - - memcpy (&req_exec_ckpt_checkpointclose.checkpoint_name, - checkpoint_name, sizeof (mar_name_t)); - req_exec_ckpt_checkpointclose.ckpt_id = ckpt_id; - memset (&req_exec_ckpt_checkpointclose.source, 0, - sizeof (mar_message_source_t)); - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointclose; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointclose); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); - - return (-1); -} - -static int ckpt_exec_init_fn (struct corosync_api_v1 *corosync_api) -{ - api = corosync_api; - - return (0); -} - - -/* - * Endian conversion routines for executive message handlers - */ -static void exec_ckpt_checkpointopen_endian_convert (void *msg) -{ - struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_checkpointopen->header); - swab_mar_message_source_t (&req_exec_ckpt_checkpointopen->source); - swab_mar_name_t (&req_exec_ckpt_checkpointopen->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->ckpt_id); - swab_mar_ckpt_checkpoint_creation_attributes_t (&req_exec_ckpt_checkpointopen->checkpoint_creation_attributes); - swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->checkpoint_creation_attributes_set); - swab_mar_ckpt_checkpoint_open_flags_t (&req_exec_ckpt_checkpointopen->checkpoint_open_flags); - swab_mar_ckpt_checkpoint_handle_t (&req_exec_ckpt_checkpointopen->checkpoint_handle); - swab_mar_invocation_t (&req_exec_ckpt_checkpointopen->invocation); - swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->async_call); - swab_mar_uint32_t (&req_exec_ckpt_checkpointopen->fail_with_error); -} - -static void exec_ckpt_checkpointclose_endian_convert (void *msg) -{ - struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_checkpointclose->header); - swab_mar_message_source_t (&req_exec_ckpt_checkpointclose->source); - swab_mar_name_t (&req_exec_ckpt_checkpointclose->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_checkpointclose->ckpt_id); -} -static void exec_ckpt_checkpointunlink_endian_convert (void *msg) -{ - struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_checkpointunlink->header); - swab_mar_message_source_t (&req_exec_ckpt_checkpointunlink->source); - swab_mar_name_t (&req_exec_ckpt_checkpointunlink->checkpoint_name); -} - -static void exec_ckpt_checkpointretentiondurationset_endian_convert (void *msg) -{ - struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_checkpointretentiondurationset->header); - swab_mar_message_source_t (&req_exec_ckpt_checkpointretentiondurationset->source); - swab_mar_name_t (&req_exec_ckpt_checkpointretentiondurationset->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_checkpointretentiondurationset->ckpt_id); - swab_mar_time_t (&req_exec_ckpt_checkpointretentiondurationset->retention_duration); -} - -static void exec_ckpt_checkpointretentiondurationexpire_endian_convert (void *msg) -{ - struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_checkpointretentiondurationexpire->header); - swab_mar_name_t (&req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_checkpointretentiondurationexpire->ckpt_id); -} - -static void exec_ckpt_sectioncreate_endian_convert (void *msg) -{ - struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_sectioncreate->header); - swab_mar_message_source_t (&req_exec_ckpt_sectioncreate->source); - swab_mar_name_t (&req_exec_ckpt_sectioncreate->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sectioncreate->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sectioncreate->id_len); - swab_mar_time_t (&req_exec_ckpt_sectioncreate->expiration_time); - swab_mar_uint32_t (&req_exec_ckpt_sectioncreate->initial_data_size); -} - -static void exec_ckpt_sectiondelete_endian_convert (void *msg) -{ - struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_sectiondelete->header); - swab_mar_message_source_t (&req_exec_ckpt_sectiondelete->source); - swab_mar_name_t (&req_exec_ckpt_sectiondelete->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sectiondelete->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sectiondelete->id_len); -} - -static void exec_ckpt_sectrionexpirationtimeset_endian_convert (void *msg) -{ - struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_sectionexpirationtimeset->header); - swab_mar_message_source_t (&req_exec_ckpt_sectionexpirationtimeset->source); - swab_mar_name_t (&req_exec_ckpt_sectionexpirationtimeset->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sectionexpirationtimeset->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sectionexpirationtimeset->id_len); - swab_mar_time_t (&req_exec_ckpt_sectionexpirationtimeset->expiration_time); -} - -static void exec_ckpt_sectionwrite_endian_convert (void *msg) -{ - struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_sectionwrite->header); - swab_mar_message_source_t (&req_exec_ckpt_sectionwrite->source); - swab_mar_name_t (&req_exec_ckpt_sectionwrite->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sectionwrite->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sectionwrite->id_len); - swab_mar_offset_t (&req_exec_ckpt_sectionwrite->data_size); -} - -static void exec_ckpt_sectionoverwrite_endian_convert (void *msg) -{ - struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_sectionoverwrite->header); - swab_mar_message_source_t (&req_exec_ckpt_sectionoverwrite->source); - swab_mar_name_t (&req_exec_ckpt_sectionoverwrite->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sectionoverwrite->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sectionoverwrite->id_len); - swab_mar_offset_t (&req_exec_ckpt_sectionoverwrite->data_size); -} - -static void exec_ckpt_sectionread_endian_convert (void *msg) -{ - struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)msg; - - swab_mar_req_header_t (&req_exec_ckpt_sectionread->header); - swab_mar_message_source_t (&req_exec_ckpt_sectionread->source); - swab_mar_name_t (&req_exec_ckpt_sectionread->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sectionread->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sectionread->id_len); - swab_mar_offset_t (&req_exec_ckpt_sectionread->data_offset); - swab_mar_offset_t (&req_exec_ckpt_sectionread->data_size); -} - -static void exec_ckpt_sync_checkpoint_endian_convert (void *msg) -{ -} -static void exec_ckpt_sync_checkpoint_section_endian_convert (void *msg) -{ -} -static void exec_ckpt_sync_checkpoint_refcount_endian_convert (void *msg) -{ -} - -#ifdef ABC -static void exec_ckpt_sync_state_endian_convert (void *msg) -{ - struct req_exec_ckpt_sync_state *req_exec_ckpt_sync_state = (struct req_exec_ckpt_sync_state *)msg; - unsigned int i; - - swab_mar_req_header_t (&req_exec_ckpt_sync_state->header); -// swab_mar_memb_ring_id_t (&req_exec_ckpt_sync_state->memb_ring_id); - swab_mar_name_t (&req_exec_ckpt_sync_state->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sync_state->ckpt_id); - swab_mar_ckpt_checkpoint_creation_attributes_t (&req_exec_ckpt_sync_state->checkpoint_creation_attributes); -// swab_mar_ckpt_section_descriptor_t (&req_exec_ckpt_sync_state->section_descriptor); - swab_mar_uint32_t (&req_exec_ckpt_sync_state->nodeid); - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - swab_mar_refcount_set_t (&req_exec_ckpt_sync_state->refcount_set[i]); - } -} - -static void exec_ckpt_sync_section_endian_convert (void *msg) -{ - struct req_exec_ckpt_sync_section *req_exec_ckpt_sync_section = (struct req_exec_ckpt_sync_section *)msg; - swab_mar_req_header_t (&req_exec_ckpt_sync_section->header); -// swab_mar_memb_ring_id_t (&req_exec_ckpt_sync_section->memb_ring_id); - swab_mar_name_t (&req_exec_ckpt_sync_section->checkpoint_name); - swab_mar_uint32_t (&req_exec_ckpt_sync_section->ckpt_id); - swab_mar_uint32_t (&req_exec_ckpt_sync_section->id_len); - swab_mar_offset_t (&req_exec_ckpt_sync_section->data_offset); - swab_mar_offset_t (&req_exec_ckpt_sync_section->data_size); -} -#endif - -/* - * Executive message handlers - */ -static void message_handler_req_exec_ckpt_checkpointopen ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_checkpointopen *req_exec_ckpt_checkpointopen = (struct req_exec_ckpt_checkpointopen *)message; - struct res_lib_ckpt_checkpointopen res_lib_ckpt_checkpointopen; - struct res_lib_ckpt_checkpointopenasync res_lib_ckpt_checkpointopenasync; - - struct checkpoint *checkpoint = 0; - struct checkpoint_section *checkpoint_section = 0; - struct checkpoint_cleanup *checkpoint_cleanup = 0; - struct ckpt_pd *ckpt_pd; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "Executive request to open checkpoint %p\n", req_exec_ckpt_checkpointopen); - - if (req_exec_ckpt_checkpointopen->fail_with_error != SA_AIS_OK) { - error = req_exec_ckpt_checkpointopen->fail_with_error; - goto error_exit; - } - - if (api->ipc_source_is_local(&req_exec_ckpt_checkpointopen->source)) { - checkpoint_cleanup = malloc (sizeof (struct checkpoint_cleanup)); - if (checkpoint_cleanup == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - } - - checkpoint = checkpoint_find_linked ( - &checkpoint_list_head, - &req_exec_ckpt_checkpointopen->checkpoint_name); - - /* - * If checkpoint doesn't exist, create one - */ - if (checkpoint == 0) { - if ((req_exec_ckpt_checkpointopen->checkpoint_open_flags & SA_CKPT_CHECKPOINT_CREATE) == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - checkpoint = malloc (sizeof (struct checkpoint)); - if (checkpoint == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - memcpy (&checkpoint->name, - &req_exec_ckpt_checkpointopen->checkpoint_name, - sizeof (mar_name_t)); - memcpy (&checkpoint->checkpoint_creation_attributes, - &req_exec_ckpt_checkpointopen->checkpoint_creation_attributes, - sizeof (mar_ckpt_checkpoint_creation_attributes_t)); - checkpoint->unlinked = 0; - list_init (&checkpoint->list); - list_init (&checkpoint->sections_list_head); - list_add (&checkpoint->list, &checkpoint_list_head); - checkpoint->reference_count = 1; - checkpoint->retention_timer = 0; - checkpoint->section_count = 0; - checkpoint->ckpt_id = global_ckpt_id++; - - if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) && - (checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) { - checkpoint->active_replica_set = 1; - } else - if ((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_WR_ALL_REPLICAS) == 1) { - checkpoint->active_replica_set = 1; - } else { - checkpoint->active_replica_set = 0; - } - - memset (&checkpoint->refcount_set, 0, - sizeof (struct refcount_set) * PROCESSOR_COUNT_MAX); - - /* - * Create default section id if max_sections is 1 - */ - if (checkpoint->checkpoint_creation_attributes.max_sections == 1) { - /* - * Add in default checkpoint section - */ - checkpoint_section = malloc (sizeof (struct checkpoint_section)); - if (checkpoint_section == 0) { - free (checkpoint); - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - list_init (&checkpoint_section->list); - list_add (&checkpoint_section->list, &checkpoint->sections_list_head); - - - checkpoint_section->section_descriptor.section_id.id = 0; - checkpoint_section->section_descriptor.section_id.id_len = 0; - checkpoint_section->section_descriptor.expiration_time = SA_TIME_END; - checkpoint_section->section_descriptor.section_state = SA_CKPT_SECTION_VALID; - checkpoint_section->section_descriptor.last_update = 0; /*current time*/ - checkpoint_section->section_descriptor.section_size = 0; - checkpoint_section->section_data = NULL; - checkpoint_section->expiration_timer = 0; - } - } else { - if (req_exec_ckpt_checkpointopen->checkpoint_creation_attributes_set && - memcmp (&checkpoint->checkpoint_creation_attributes, - &req_exec_ckpt_checkpointopen->checkpoint_creation_attributes, - sizeof (mar_ckpt_checkpoint_creation_attributes_t)) != 0) { - - error = SA_AIS_ERR_EXIST; - goto error_exit; - } - } - - assert (checkpoint->unlinked == 0); - - /* - * Setup connection information and mark checkpoint as referenced - */ - log_printf (LOG_LEVEL_DEBUG, "CHECKPOINT opened is %p\n", checkpoint); - - sync_refcount_increment (checkpoint, nodeid); - sync_refcount_calculate (checkpoint); - - /* - * Reset retention duration since this checkpoint was just opened - */ - api->timer_delete (checkpoint->retention_timer); - checkpoint->retention_timer = 0; - - /* - * Send error result to CKPT library - */ -error_exit: - /* - * If this node was the source of the message, respond to this node - */ - if (api->ipc_source_is_local(&req_exec_ckpt_checkpointopen->source)) { - /* - * If its an async call respond with the invocation and handle - */ - if (req_exec_ckpt_checkpointopen->async_call) { - res_lib_ckpt_checkpointopenasync.header.size = sizeof (struct res_lib_ckpt_checkpointopenasync); - res_lib_ckpt_checkpointopenasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPENASYNC; - res_lib_ckpt_checkpointopenasync.header.error = error; - res_lib_ckpt_checkpointopenasync.checkpoint_handle = req_exec_ckpt_checkpointopen->checkpoint_handle; - res_lib_ckpt_checkpointopenasync.invocation = req_exec_ckpt_checkpointopen->invocation; - if (error == SA_AIS_OK) { - res_lib_ckpt_checkpointopenasync.ckpt_id = checkpoint->ckpt_id; - } - - api->ipc_conn_send_response ( - req_exec_ckpt_checkpointopen->source.conn, - &res_lib_ckpt_checkpointopenasync, - sizeof (struct res_lib_ckpt_checkpointopenasync)); - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_ckpt_checkpointopen->source.conn), - &res_lib_ckpt_checkpointopenasync, - sizeof (struct res_lib_ckpt_checkpointopenasync)); - } else { - /* - * otherwise respond with the normal checkpointopen response - */ - res_lib_ckpt_checkpointopen.header.size = sizeof (struct res_lib_ckpt_checkpointopen); - res_lib_ckpt_checkpointopen.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTOPEN; - if (error == SA_AIS_OK) { - res_lib_ckpt_checkpointopen.ckpt_id = checkpoint->ckpt_id; - } - res_lib_ckpt_checkpointopen.header.error = error; - - api->ipc_conn_send_response ( - req_exec_ckpt_checkpointopen->source.conn, - &res_lib_ckpt_checkpointopen, - sizeof (struct res_lib_ckpt_checkpointopen)); - } - - /* - * This is the path taken when all goes well and this call was local - */ - if (error == SA_AIS_OK) { - ckpt_pd = api->ipc_private_data_get (req_exec_ckpt_checkpointopen->source.conn); - - memcpy(&checkpoint_cleanup->checkpoint_name, - &checkpoint->name, sizeof (mar_name_t)); - checkpoint_cleanup->ckpt_id = checkpoint->ckpt_id; - - list_add (&checkpoint_cleanup->list, - &ckpt_pd->checkpoint_list); - } else { - /* - * We allocated this in the hope of using it but an error occured - * so deallocate it. - */ - free (checkpoint_cleanup); - } - } -} - -unsigned int abstime_to_msec (mar_time_t time) -{ - struct timeval tv; - unsigned long long curr_time; - unsigned long long msec_time; - - gettimeofday (&tv, NULL); - curr_time = ((((unsigned long long)tv.tv_sec) * ((unsigned long)1000)) + - (((unsigned long long)tv.tv_usec) / ((unsigned long long)1000))); - msec_time = (((unsigned long long)time) / 1000000) - - (unsigned long long)curr_time; - - return ((unsigned int)(msec_time)); -} - -void timer_function_section_expire (void *data) -{ - struct checkpoint *checkpoint = 0; - struct checkpoint_section *checkpoint_section = 0; - struct ckpt_identifier *ckpt_id = 0; - - ckpt_id = (struct ckpt_identifier *)data; - log_printf (LOG_LEVEL_DEBUG, "timer_function_section_expire data = 0x%p\n",data); - if (ckpt_id->ckpt_section_id.id_len && ckpt_id->ckpt_section_id.id) { - log_printf (LOG_LEVEL_DEBUG, "Attempting to expire section %s in ckpt %s\n", - ckpt_id->ckpt_section_id.id, - ckpt_id->ckpt_name.value); - } - else { - log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire data incorect\n"); - goto free_mem; - } - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &ckpt_id->ckpt_name, - ckpt_id->ckpt_id); - if (checkpoint == 0) { - log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire could not find ckpt %s\n", - ckpt_id->ckpt_name.value); - goto free_mem; - } - - checkpoint_section = checkpoint_section_find (checkpoint, - (char *)ckpt_id->ckpt_section_id.id, - (int)ckpt_id->ckpt_section_id.id_len); - if (checkpoint_section == 0) { - log_printf (LOG_LEVEL_ERROR, "timer_function_section_expire could not find section %s in ckpt %s\n", - ckpt_id->ckpt_section_id.id, - ckpt_id->ckpt_name.value); - goto free_mem; - } - - log_printf (LOG_LEVEL_DEBUG, "Expiring section %s in ckpt %s\n", - ckpt_id->ckpt_section_id.id, - ckpt_id->ckpt_name.value); - - checkpoint->section_count -= 1; - checkpoint_section_release (checkpoint_section); - -free_mem : - free (ckpt_id); - -} - -void timer_function_retention (void *data) -{ - struct checkpoint *checkpoint = (struct checkpoint *)data; - struct req_exec_ckpt_checkpointretentiondurationexpire req_exec_ckpt_checkpointretentiondurationexpire; - struct iovec iovec; - - checkpoint->retention_timer = 0; - req_exec_ckpt_checkpointretentiondurationexpire.header.size = - sizeof (struct req_exec_ckpt_checkpointretentiondurationexpire); - req_exec_ckpt_checkpointretentiondurationexpire.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONEXPIRE); - - memcpy (&req_exec_ckpt_checkpointretentiondurationexpire.checkpoint_name, - &checkpoint->name, - sizeof (mar_name_t)); - req_exec_ckpt_checkpointretentiondurationexpire.ckpt_id = - checkpoint->ckpt_id; - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationexpire; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationexpire); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_exec_ckpt_checkpointclose ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_checkpointclose *req_exec_ckpt_checkpointclose = (struct req_exec_ckpt_checkpointclose *)message; - struct res_lib_ckpt_checkpointclose res_lib_ckpt_checkpointclose; - struct checkpoint *checkpoint = 0; - SaAisErrorT error = SA_AIS_OK; - int release_checkpoint = 0; - - log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to close checkpoint %s\n", - get_mar_name_t (&req_exec_ckpt_checkpointclose->checkpoint_name)); - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_checkpointclose->checkpoint_name, - req_exec_ckpt_checkpointclose->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - sync_refcount_decrement (checkpoint, nodeid); - sync_refcount_calculate (checkpoint); - - log_printf (LOG_LEVEL_DEBUG, "Close checkpoint->reference_count %d\n", - checkpoint->reference_count); - assert (checkpoint->reference_count >= 0); - - /* - * If checkpoint has been unlinked and this is the last reference, delete it - */ - if (checkpoint->unlinked && checkpoint->reference_count == 0) { - log_printf (LOG_LEVEL_DEBUG, "Unlinking checkpoint.\n"); - release_checkpoint = 1; - } else - if (checkpoint->reference_count == 0) { - if (checkpoint->checkpoint_creation_attributes.retention_duration != SA_TIME_END) { - api->timer_add_duration ( - checkpoint->checkpoint_creation_attributes.retention_duration, - checkpoint, - timer_function_retention, - &checkpoint->retention_timer); - } - } - -error_exit: - /* - * Remove the checkpoint from my connections checkpoint list - */ - if (api->ipc_source_is_local(&req_exec_ckpt_checkpointclose->source)) { - - res_lib_ckpt_checkpointclose.header.size = sizeof (struct res_lib_ckpt_checkpointclose); - res_lib_ckpt_checkpointclose.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTCLOSE; - res_lib_ckpt_checkpointclose.header.error = error; - api->ipc_conn_send_response (req_exec_ckpt_checkpointclose->source.conn, - &res_lib_ckpt_checkpointclose, sizeof (struct res_lib_ckpt_checkpointclose)); - } - - /* - * Release the checkpoint if instructed to do so. - */ - if (error == SA_AIS_OK && release_checkpoint) { - checkpoint_release(checkpoint); - } -} - -static void message_handler_req_exec_ckpt_checkpointunlink ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_checkpointunlink *req_exec_ckpt_checkpointunlink = (struct req_exec_ckpt_checkpointunlink *)message; - - struct res_lib_ckpt_checkpointunlink res_lib_ckpt_checkpointunlink; - struct checkpoint *checkpoint = 0; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "Got EXEC request to unlink checkpoint %p\n", req_exec_ckpt_checkpointunlink); - checkpoint = checkpoint_find_linked ( - &checkpoint_list_head, - &req_exec_ckpt_checkpointunlink->checkpoint_name); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - assert (checkpoint->unlinked == 0); - - checkpoint->unlinked = 1; - /* - * Immediately delete entry if reference count is zero - */ - if (checkpoint->reference_count == 0) { - /* - * Remove retention timer since this checkpoint was unlinked and is no - * longer referenced - */ - checkpoint_release (checkpoint); - } - -error_exit: - /* - * If this node was the source of the message, respond to this node - */ - if (api->ipc_source_is_local(&req_exec_ckpt_checkpointunlink->source)) { - res_lib_ckpt_checkpointunlink.header.size = sizeof (struct res_lib_ckpt_checkpointunlink); - res_lib_ckpt_checkpointunlink.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTUNLINK; - res_lib_ckpt_checkpointunlink.header.error = error; - api->ipc_conn_send_response ( - req_exec_ckpt_checkpointunlink->source.conn, - &res_lib_ckpt_checkpointunlink, - sizeof (struct res_lib_ckpt_checkpointunlink)); - } -} - -static void message_handler_req_exec_ckpt_checkpointretentiondurationset ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_checkpointretentiondurationset *req_exec_ckpt_checkpointretentiondurationset = (struct req_exec_ckpt_checkpointretentiondurationset *)message; - struct res_lib_ckpt_checkpointretentiondurationset res_lib_ckpt_checkpointretentiondurationset; - struct checkpoint *checkpoint; - SaAisErrorT error = SA_AIS_ERR_BAD_OPERATION; - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_checkpointretentiondurationset->checkpoint_name, - req_exec_ckpt_checkpointretentiondurationset->ckpt_id); - if (checkpoint) { - log_printf (LOG_LEVEL_DEBUG, "Setting retention duration for checkpoint %s\n", - get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationset->checkpoint_name)); - if (checkpoint->unlinked == 0) { - checkpoint->checkpoint_creation_attributes.retention_duration = - req_exec_ckpt_checkpointretentiondurationset->retention_duration; - - if (checkpoint->reference_count == 0) { - api->timer_delete (checkpoint->retention_timer); - - api->timer_add_duration ( - checkpoint->checkpoint_creation_attributes.retention_duration, - checkpoint, - timer_function_retention, - &checkpoint->retention_timer); - } - error = SA_AIS_OK; - } - } - - /* - * Respond to library if this processor sent the duration set request - */ - if (api->ipc_source_is_local(&req_exec_ckpt_checkpointretentiondurationset->source)) { - res_lib_ckpt_checkpointretentiondurationset.header.size = sizeof (struct res_lib_ckpt_checkpointretentiondurationset); - res_lib_ckpt_checkpointretentiondurationset.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTRETENTIONDURATIONSET; - res_lib_ckpt_checkpointretentiondurationset.header.error = error; - - api->ipc_conn_send_response ( - req_exec_ckpt_checkpointretentiondurationset->source.conn, - &res_lib_ckpt_checkpointretentiondurationset, - sizeof (struct res_lib_ckpt_checkpointretentiondurationset)); - } -} - -static void message_handler_req_exec_ckpt_checkpointretentiondurationexpire ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_checkpointretentiondurationexpire *req_exec_ckpt_checkpointretentiondurationexpire = (struct req_exec_ckpt_checkpointretentiondurationexpire *)message; - struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink; - struct checkpoint *checkpoint; - struct iovec iovec; - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name, - req_exec_ckpt_checkpointretentiondurationexpire->ckpt_id); - log_printf (LOG_LEVEL_NOTICE, "Expiring checkpoint %s\n", - get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name)); - if (checkpoint && (checkpoint->reference_count == 0)) { - log_printf (LOG_LEVEL_NOTICE, "Expiring checkpoint %s\n", - get_mar_name_t (&req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name)); - - req_exec_ckpt_checkpointunlink.header.size = - sizeof (struct req_exec_ckpt_checkpointunlink); - req_exec_ckpt_checkpointunlink.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK); - - req_exec_ckpt_checkpointunlink.source.conn = 0; - req_exec_ckpt_checkpointunlink.source.nodeid = 0; - - memcpy (&req_exec_ckpt_checkpointunlink.checkpoint_name, - &req_exec_ckpt_checkpointretentiondurationexpire->checkpoint_name, - sizeof (mar_name_t)); - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointunlink; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointunlink); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); - } -} - - -static void message_handler_req_exec_ckpt_sectioncreate ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sectioncreate *req_exec_ckpt_sectioncreate = (struct req_exec_ckpt_sectioncreate *)message; - struct res_lib_ckpt_sectioncreate res_lib_ckpt_sectioncreate; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - void *initial_data; - void *section_id; - struct ckpt_identifier *ckpt_id = 0; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "Executive request to create a checkpoint section.\n"); - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_sectioncreate->checkpoint_name, - req_exec_ckpt_sectioncreate->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->section_count == checkpoint->checkpoint_creation_attributes.max_sections) { - error = SA_AIS_ERR_NO_SPACE; - goto error_exit; - } - - if (checkpoint->checkpoint_creation_attributes.max_sections == 1) { - error = SA_AIS_ERR_EXIST; - goto error_exit; - } - - if (checkpoint->checkpoint_creation_attributes.max_section_size < - req_exec_ckpt_sectioncreate->initial_data_size) { - - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - if (checkpoint->checkpoint_creation_attributes.max_section_id_size < - req_exec_ckpt_sectioncreate->id_len) { - - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - /* - * Determine if user-specified checkpoint section already exists - */ - checkpoint_section = checkpoint_section_find (checkpoint, - ((char *)req_exec_ckpt_sectioncreate) + - sizeof (struct req_exec_ckpt_sectioncreate), - req_exec_ckpt_sectioncreate->id_len); - if (checkpoint_section) { - error = SA_AIS_ERR_EXIST; - goto error_exit; - } - - /* - * Allocate checkpoint section - */ - checkpoint_section = malloc (sizeof (struct checkpoint_section)); - if (checkpoint_section == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - /* - * Allocate checkpoint section data - */ - initial_data = malloc (req_exec_ckpt_sectioncreate->initial_data_size); - if (initial_data == 0) { - free (checkpoint_section); - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - /* - * Allocate checkpoint section id - */ - section_id = malloc (req_exec_ckpt_sectioncreate->id_len + 1); - if (section_id == 0) { - free (checkpoint_section); - free (initial_data); - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - /* - * Copy checkpoint section and section ID - */ - memcpy (section_id, - ((char *)req_exec_ckpt_sectioncreate) + - sizeof (struct req_exec_ckpt_sectioncreate), - req_exec_ckpt_sectioncreate->id_len); - - /*Must be null terminated if it already isn't*/ - ((char*)(section_id))[req_exec_ckpt_sectioncreate->id_len] = '\0'; - - memcpy (initial_data, - ((char *)req_exec_ckpt_sectioncreate) + - sizeof (struct req_exec_ckpt_sectioncreate) + - req_exec_ckpt_sectioncreate->id_len, - req_exec_ckpt_sectioncreate->initial_data_size); - - /* - * Configure checkpoint section - */ - checkpoint_section->section_descriptor.section_id.id = section_id; - checkpoint_section->section_descriptor.section_id.id_len = - req_exec_ckpt_sectioncreate->id_len; - checkpoint_section->section_descriptor.section_size = - req_exec_ckpt_sectioncreate->initial_data_size; - checkpoint_section->section_descriptor.expiration_time = - req_exec_ckpt_sectioncreate->expiration_time; - checkpoint_section->section_descriptor.section_state = - SA_CKPT_SECTION_VALID; - checkpoint_section->section_descriptor.last_update = 0; /* TODO current time */ - checkpoint_section->section_data = initial_data; - checkpoint_section->expiration_timer = 0; - - if (req_exec_ckpt_sectioncreate->expiration_time != SA_TIME_END) { - ckpt_id = malloc (sizeof(struct ckpt_identifier)); - assert(ckpt_id); - memcpy(&ckpt_id->ckpt_name, - &req_exec_ckpt_sectioncreate->checkpoint_name, - sizeof(mar_name_t)); - ckpt_id->ckpt_id = req_exec_ckpt_sectioncreate->ckpt_id; - memcpy(&ckpt_id->ckpt_section_id, - &checkpoint_section->section_descriptor.section_id, - sizeof(mar_ckpt_section_id_t)); - log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectioncreate Enqueuing Timer to Expire section %s in ckpt %s\n", - ckpt_id->ckpt_section_id.id, - ckpt_id->ckpt_name.value); - api->timer_add_absolute ( - checkpoint_section->section_descriptor.expiration_time, - ckpt_id, - timer_function_section_expire, - &checkpoint_section->expiration_timer); - log_printf (LOG_LEVEL_DEBUG, - "req_exec_ckpt_sectionicreate expiration timer = 0x%p\n", - checkpoint_section->expiration_timer); - } - - log_printf (LOG_LEVEL_DEBUG, - "message_handler_req_exec_ckpt_sectioncreate created section with id = %s, id_len = %d\n", - checkpoint_section->section_descriptor.section_id.id, - checkpoint_section->section_descriptor.section_id.id_len); - /* - * Add checkpoint section to checkpoint - */ - list_init (&checkpoint_section->list); - list_add (&checkpoint_section->list, - &checkpoint->sections_list_head); - checkpoint->section_count += 1; - -error_exit: - if (api->ipc_source_is_local(&req_exec_ckpt_sectioncreate->source)) { - res_lib_ckpt_sectioncreate.header.size = sizeof (struct res_lib_ckpt_sectioncreate); - res_lib_ckpt_sectioncreate.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONCREATE; - res_lib_ckpt_sectioncreate.header.error = error; - - api->ipc_conn_send_response (req_exec_ckpt_sectioncreate->source.conn, - &res_lib_ckpt_sectioncreate, - sizeof (struct res_lib_ckpt_sectioncreate)); - } -} - -static void message_handler_req_exec_ckpt_sectiondelete ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sectiondelete *req_exec_ckpt_sectiondelete = (struct req_exec_ckpt_sectiondelete *)message; - struct res_lib_ckpt_sectiondelete res_lib_ckpt_sectiondelete; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - SaAisErrorT error = SA_AIS_OK; - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_sectiondelete->checkpoint_name, - req_exec_ckpt_sectiondelete->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->active_replica_set == 0) { - log_printf (LOG_LEVEL_DEBUG, "sectiondelete: no active replica, returning error.\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * Determine if the user is trying to delete the default section - */ - if (req_exec_ckpt_sectiondelete->id_len == 0) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - /* - * Find checkpoint section to be deleted - */ - checkpoint_section = checkpoint_section_find (checkpoint, - ((char *)(req_exec_ckpt_sectiondelete) + sizeof (struct req_exec_ckpt_sectiondelete)), - req_exec_ckpt_sectiondelete->id_len); - if (checkpoint_section == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * Delete checkpoint section - */ - checkpoint->section_count -= 1; - checkpoint_section_release (checkpoint_section); - - /* - * return result to CKPT library - */ -error_exit: - if (api->ipc_source_is_local(&req_exec_ckpt_sectiondelete->source)) { - res_lib_ckpt_sectiondelete.header.size = sizeof (struct res_lib_ckpt_sectiondelete); - res_lib_ckpt_sectiondelete.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONDELETE; - res_lib_ckpt_sectiondelete.header.error = error; - - api->ipc_conn_send_response ( - req_exec_ckpt_sectiondelete->source.conn, - &res_lib_ckpt_sectiondelete, - sizeof (struct res_lib_ckpt_sectiondelete)); - } -} - -static void message_handler_req_exec_ckpt_sectionexpirationtimeset ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sectionexpirationtimeset *req_exec_ckpt_sectionexpirationtimeset = (struct req_exec_ckpt_sectionexpirationtimeset *)message; - struct res_lib_ckpt_sectionexpirationtimeset res_lib_ckpt_sectionexpirationtimeset; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - struct ckpt_identifier *ckpt_id = 0; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "Executive request to set section expiration time\n"); - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_sectionexpirationtimeset->checkpoint_name, - req_exec_ckpt_sectionexpirationtimeset->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->active_replica_set == 0) { - log_printf (LOG_LEVEL_DEBUG, "expirationset: no active replica, returning error.\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * Determine if the user is trying to set expiration time for the default section - */ - if (req_exec_ckpt_sectionexpirationtimeset->id_len == 0) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - /* - * Find checkpoint section that expiration time should be set for - */ - checkpoint_section = checkpoint_section_find (checkpoint, - ((char *)req_exec_ckpt_sectionexpirationtimeset) + - sizeof (struct req_exec_ckpt_sectionexpirationtimeset), - req_exec_ckpt_sectionexpirationtimeset->id_len); - - if (checkpoint_section == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - checkpoint_section->section_descriptor.expiration_time = - req_exec_ckpt_sectionexpirationtimeset->expiration_time; - - api->timer_delete (checkpoint_section->expiration_timer); - checkpoint_section->expiration_timer = 0; - - if (req_exec_ckpt_sectionexpirationtimeset->expiration_time != SA_TIME_END) { - ckpt_id = malloc (sizeof(struct ckpt_identifier)); - assert(ckpt_id); - memcpy(&ckpt_id->ckpt_name, - &req_exec_ckpt_sectionexpirationtimeset->checkpoint_name, - sizeof(mar_name_t)); - ckpt_id->ckpt_id = - req_exec_ckpt_sectionexpirationtimeset->ckpt_id; - memcpy(&ckpt_id->ckpt_section_id, - &checkpoint_section->section_descriptor.section_id, - sizeof(mar_ckpt_section_id_t)); - log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionexpirationtimeset Enqueuing Timer to Expire section %s in ckpt %s, ref = 0x%p\n", - ckpt_id->ckpt_section_id.id, - ckpt_id->ckpt_name.value, - ckpt_id); - api->timer_add_absolute ( - checkpoint_section->section_descriptor.expiration_time, - ckpt_id, - timer_function_section_expire, - &checkpoint_section->expiration_timer); - log_printf (LOG_LEVEL_DEBUG, "req_exec_ckpt_sectionexpirationtimeset expiration timer = 0x%p\n", - checkpoint_section->expiration_timer); - } - -error_exit: - if (api->ipc_source_is_local (&req_exec_ckpt_sectionexpirationtimeset->source)) { - res_lib_ckpt_sectionexpirationtimeset.header.size = - sizeof (struct res_lib_ckpt_sectionexpirationtimeset); - res_lib_ckpt_sectionexpirationtimeset.header.id = - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONEXPIRATIONTIMESET; - res_lib_ckpt_sectionexpirationtimeset.header.error = error; - - api->ipc_conn_send_response ( - req_exec_ckpt_sectionexpirationtimeset->source.conn, - &res_lib_ckpt_sectionexpirationtimeset, - sizeof (struct res_lib_ckpt_sectionexpirationtimeset)); - } -} - -static void message_handler_req_exec_ckpt_sectionwrite ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sectionwrite *req_exec_ckpt_sectionwrite = (struct req_exec_ckpt_sectionwrite *)message; - struct res_lib_ckpt_sectionwrite res_lib_ckpt_sectionwrite; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section = 0; - int size_required; - void *section_data; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "Executive request to section write.\n"); - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_sectionwrite->checkpoint_name, - req_exec_ckpt_sectionwrite->ckpt_id); - if (checkpoint == 0) { - log_printf (LOG_LEVEL_ERROR, "checkpoint_find returned 0 Calling error_exit.\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->active_replica_set == 0) { - log_printf (LOG_LEVEL_DEBUG, "checkpointwrite: no active replica, returning error.\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->checkpoint_creation_attributes.max_section_size < req_exec_ckpt_sectionwrite->data_size) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - log_printf (LOG_LEVEL_DEBUG, "writing checkpoint section is %s\n", - ((char *)req_exec_ckpt_sectionwrite) + - sizeof (struct req_exec_ckpt_sectionwrite)); - - /* - * Find checkpoint section to be written - */ - checkpoint_section = checkpoint_section_find (checkpoint, - ((char *)req_exec_ckpt_sectionwrite) + - sizeof (struct req_exec_ckpt_sectionwrite), - req_exec_ckpt_sectionwrite->id_len); - if (checkpoint_section == 0) { - if (req_exec_ckpt_sectionwrite->id_len == 0) { - log_printf (LOG_LEVEL_DEBUG, "CANT FIND DEFAULT SECTION.\n"); - } - else { - log_printf (LOG_LEVEL_DEBUG, "CANT FIND SECTION '%s'\n", - ((char *)req_exec_ckpt_sectionwrite) + - sizeof (struct req_exec_ckpt_sectionwrite)); - } - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * If write would extend past end of section data, enlarge section - */ - size_required = req_exec_ckpt_sectionwrite->data_offset + - req_exec_ckpt_sectionwrite->data_size; - if (size_required > checkpoint_section->section_descriptor.section_size) { - section_data = realloc (checkpoint_section->section_data, size_required); - if (section_data == 0) { - log_printf (LOG_LEVEL_ERROR, "section_data realloc returned 0 Calling error_exit.\n"); - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - /* - * Install new section data - */ - checkpoint_section->section_data = section_data; - checkpoint_section->section_descriptor.section_size = size_required; - } - - /* - * Write checkpoint section to section data - */ - if (req_exec_ckpt_sectionwrite->data_size > 0) { - char *sd; - int *val; - val = checkpoint_section->section_data; - sd = (char *)checkpoint_section->section_data; - memcpy (&sd[req_exec_ckpt_sectionwrite->data_offset], - ((char *)req_exec_ckpt_sectionwrite) + - sizeof (struct req_exec_ckpt_sectionwrite) + - req_exec_ckpt_sectionwrite->id_len, - req_exec_ckpt_sectionwrite->data_size); - } - /* - * Write sectionwrite response to CKPT library - */ -error_exit: - if (api->ipc_source_is_local(&req_exec_ckpt_sectionwrite->source)) { - res_lib_ckpt_sectionwrite.header.size = - sizeof (struct res_lib_ckpt_sectionwrite); - res_lib_ckpt_sectionwrite.header.id = - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONWRITE; - res_lib_ckpt_sectionwrite.header.error = error; - - api->ipc_conn_send_response ( - req_exec_ckpt_sectionwrite->source.conn, - &res_lib_ckpt_sectionwrite, - sizeof (struct res_lib_ckpt_sectionwrite)); - } -} - -static void message_handler_req_exec_ckpt_sectionoverwrite ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sectionoverwrite *req_exec_ckpt_sectionoverwrite = (struct req_exec_ckpt_sectionoverwrite *)message; - struct res_lib_ckpt_sectionoverwrite res_lib_ckpt_sectionoverwrite; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - void *section_data; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "Executive request to section overwrite.\n"); - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_sectionoverwrite->checkpoint_name, - req_exec_ckpt_sectionoverwrite->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->active_replica_set == 0) { - log_printf (LOG_LEVEL_DEBUG, "sectionoverwrite: no active replica, returning error.\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->checkpoint_creation_attributes.max_section_size < - req_exec_ckpt_sectionoverwrite->data_size) { - - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - /* - * Find checkpoint section to be overwritten - */ - checkpoint_section = checkpoint_section_find (checkpoint, - ((char *)req_exec_ckpt_sectionoverwrite) + - sizeof (struct req_exec_ckpt_sectionoverwrite), - req_exec_ckpt_sectionoverwrite->id_len); - if (checkpoint_section == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * Allocate checkpoint section data - */ - section_data = malloc (req_exec_ckpt_sectionoverwrite->data_size); - if (section_data == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - memcpy (section_data, - ((char *)req_exec_ckpt_sectionoverwrite) + - sizeof (struct req_exec_ckpt_sectionoverwrite) + - req_exec_ckpt_sectionoverwrite->id_len, - req_exec_ckpt_sectionoverwrite->data_size); - - /* - * release old checkpoint section data - */ - free (checkpoint_section->section_data); - - /* - * Install overwritten checkpoint section data - */ - checkpoint_section->section_descriptor.section_size = - req_exec_ckpt_sectionoverwrite->data_size; - checkpoint_section->section_descriptor.section_state = - SA_CKPT_SECTION_VALID; - /* - * TODO current time - */ - checkpoint_section->section_descriptor.last_update = 0; - checkpoint_section->section_data = section_data; - - /* - * return result to CKPT library - */ -error_exit: - if (api->ipc_source_is_local(&req_exec_ckpt_sectionoverwrite->source)) { - res_lib_ckpt_sectionoverwrite.header.size = - sizeof (struct res_lib_ckpt_sectionoverwrite); - res_lib_ckpt_sectionoverwrite.header.id = - MESSAGE_RES_CKPT_CHECKPOINT_SECTIONOVERWRITE; - res_lib_ckpt_sectionoverwrite.header.error = error; - - api->ipc_conn_send_response ( - req_exec_ckpt_sectionoverwrite->source.conn, - &res_lib_ckpt_sectionoverwrite, - sizeof (struct res_lib_ckpt_sectionoverwrite)); - } -} - -static void message_handler_req_exec_ckpt_sectionread ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sectionread *req_exec_ckpt_sectionread = (struct req_exec_ckpt_sectionread *)message; - struct res_lib_ckpt_sectionread res_lib_ckpt_sectionread; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section = 0; - int section_size = 0; - SaAisErrorT error = SA_AIS_OK; - - res_lib_ckpt_sectionread.data_read = 0; - - log_printf (LOG_LEVEL_DEBUG, "Executive request for section read.\n"); - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_exec_ckpt_sectionread->checkpoint_name, - req_exec_ckpt_sectionread->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - - if (checkpoint->active_replica_set == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * Find checkpoint section to be read - */ - checkpoint_section = checkpoint_section_find (checkpoint, - ((char *)req_exec_ckpt_sectionread) + - sizeof (struct req_exec_ckpt_sectionread), - req_exec_ckpt_sectionread->id_len); - if (checkpoint_section == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - /* - * If data size is greater then max section size, return INVALID_PARAM - */ - if (checkpoint->checkpoint_creation_attributes.max_section_size < - req_exec_ckpt_sectionread->data_size) { - - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - /* - * If data_offset is past end of data, return INVALID_PARAM - */ - if (req_exec_ckpt_sectionread->data_offset > checkpoint_section->section_descriptor.section_size) { - error = SA_AIS_ERR_INVALID_PARAM; - goto error_exit; - } - - /* - * Determine the section size - */ - section_size = checkpoint_section->section_descriptor.section_size - - req_exec_ckpt_sectionread->data_offset; - - /* - * If the library has less space available then can be sent from the - * section, reduce bytes sent to library to max requested - */ - if (section_size > req_exec_ckpt_sectionread->data_size) { - section_size = req_exec_ckpt_sectionread->data_size; - } - - /* - * Write read response to CKPT library - */ -error_exit: - if (api->ipc_source_is_local(&req_exec_ckpt_sectionread->source)) { - res_lib_ckpt_sectionread.header.size = sizeof (struct res_lib_ckpt_sectionread) + section_size; - res_lib_ckpt_sectionread.header.id = MESSAGE_RES_CKPT_CHECKPOINT_SECTIONREAD; - res_lib_ckpt_sectionread.header.error = error; - - if (section_size != 0) { - res_lib_ckpt_sectionread.data_read = section_size; - } - - api->ipc_conn_send_response ( - req_exec_ckpt_sectionread->source.conn, - &res_lib_ckpt_sectionread, - sizeof (struct res_lib_ckpt_sectionread)); - - /* - * Write checkpoint to CKPT library section if section has data - */ - if (error == SA_AIS_OK) { - char *sd; - sd = (char *)checkpoint_section->section_data; - api->ipc_conn_send_response ( - req_exec_ckpt_sectionread->source.conn, - &sd[req_exec_ckpt_sectionread->data_offset], - section_size); - } - } -} - -static int ckpt_lib_init_fn (void *conn) -{ - struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)api->ipc_private_data_get (conn); - - hdb_create (&ckpt_pd->iteration_hdb); - - list_init (&ckpt_pd->checkpoint_list); - - return (0); - -} - -static int ckpt_lib_exit_fn (void *conn) -{ - struct checkpoint_cleanup *checkpoint_cleanup; - struct list_head *list; - struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)api->ipc_private_data_get (conn); - - log_printf (LOG_LEVEL_DEBUG, "checkpoint exit conn %p\n", conn); - - /* - * close all checkpoints opened on this connection - */ - list = ckpt_pd->checkpoint_list.next; - while (!list_empty(&ckpt_pd->checkpoint_list)) { - - checkpoint_cleanup = list_entry (list, - struct checkpoint_cleanup, list); - - assert (checkpoint_cleanup->checkpoint_name.length != 0); - ckpt_checkpoint_close ( - &checkpoint_cleanup->checkpoint_name, - checkpoint_cleanup->ckpt_id); - - list_del (&checkpoint_cleanup->list); - free (checkpoint_cleanup); - - list = ckpt_pd->checkpoint_list.next; - } - - hdb_destroy (&ckpt_pd->iteration_hdb); - - return (0); -} - - -static void message_handler_req_lib_ckpt_checkpointopen ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointopen *req_lib_ckpt_checkpointopen = (struct req_lib_ckpt_checkpointopen *)msg; - struct req_exec_ckpt_checkpointopen req_exec_ckpt_checkpointopen; - struct iovec iovec; - - log_printf (LOG_LEVEL_DEBUG, "Library request to open checkpoint.\n"); - req_exec_ckpt_checkpointopen.header.size = - sizeof (struct req_exec_ckpt_checkpointopen); - req_exec_ckpt_checkpointopen.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTOPEN); - - api->ipc_source_set (&req_exec_ckpt_checkpointopen.source, conn); - memcpy (&req_exec_ckpt_checkpointopen.checkpoint_name, - &req_lib_ckpt_checkpointopen->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_checkpointopen.ckpt_id = - req_lib_ckpt_checkpointopen->ckpt_id; - memcpy (&req_exec_ckpt_checkpointopen.checkpoint_creation_attributes, - &req_lib_ckpt_checkpointopen->checkpoint_creation_attributes, - sizeof (mar_ckpt_checkpoint_creation_attributes_t)); - req_exec_ckpt_checkpointopen.checkpoint_creation_attributes_set = - req_lib_ckpt_checkpointopen->checkpoint_creation_attributes_set; - req_exec_ckpt_checkpointopen.checkpoint_open_flags = - req_lib_ckpt_checkpointopen->checkpoint_open_flags; - req_exec_ckpt_checkpointopen.invocation = - req_lib_ckpt_checkpointopen->invocation; - req_exec_ckpt_checkpointopen.checkpoint_handle = - req_lib_ckpt_checkpointopen->checkpoint_handle; - req_exec_ckpt_checkpointopen.fail_with_error = - req_lib_ckpt_checkpointopen->fail_with_error; - req_exec_ckpt_checkpointopen.async_call = - req_lib_ckpt_checkpointopen->async_call; - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointopen; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointopen); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_ckpt_checkpointclose ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointclose *req_lib_ckpt_checkpointclose = (struct req_lib_ckpt_checkpointclose *)msg; - struct req_exec_ckpt_checkpointclose req_exec_ckpt_checkpointclose; - struct iovec iovec; - - req_exec_ckpt_checkpointclose.header.size = - sizeof (struct req_exec_ckpt_checkpointclose); - req_exec_ckpt_checkpointclose.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTCLOSE); - - api->ipc_source_set (&req_exec_ckpt_checkpointclose.source, conn); - - memcpy (&req_exec_ckpt_checkpointclose.checkpoint_name, - &req_lib_ckpt_checkpointclose->checkpoint_name, sizeof (mar_name_t)); - req_exec_ckpt_checkpointclose.ckpt_id = - req_lib_ckpt_checkpointclose->ckpt_id; - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointclose; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointclose); - - ckpt_checkpoint_remove_cleanup ( - conn, - req_lib_ckpt_checkpointclose->checkpoint_name, - req_lib_ckpt_checkpointclose->ckpt_id); - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_ckpt_checkpointunlink ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointunlink *req_lib_ckpt_checkpointunlink = (struct req_lib_ckpt_checkpointunlink *)msg; - struct req_exec_ckpt_checkpointunlink req_exec_ckpt_checkpointunlink; - struct iovec iovec; - - req_exec_ckpt_checkpointunlink.header.size = - sizeof (struct req_exec_ckpt_checkpointunlink); - req_exec_ckpt_checkpointunlink.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, MESSAGE_REQ_EXEC_CKPT_CHECKPOINTUNLINK); - - api->ipc_source_set (&req_exec_ckpt_checkpointunlink.source, conn); - - memcpy (&req_exec_ckpt_checkpointunlink.checkpoint_name, - &req_lib_ckpt_checkpointunlink->checkpoint_name, - sizeof (mar_name_t)); - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointunlink; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointunlink); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_ckpt_checkpointretentiondurationset ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointretentiondurationset *req_lib_ckpt_checkpointretentiondurationset = (struct req_lib_ckpt_checkpointretentiondurationset *)msg; - struct req_exec_ckpt_checkpointretentiondurationset req_exec_ckpt_checkpointretentiondurationset; - struct iovec iovec; - - log_printf (LOG_LEVEL_DEBUG, "DURATION SET FROM API conn %p\n", conn); - req_exec_ckpt_checkpointretentiondurationset.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_CHECKPOINTRETENTIONDURATIONSET); - req_exec_ckpt_checkpointretentiondurationset.header.size = sizeof (struct req_exec_ckpt_checkpointretentiondurationset); - - api->ipc_source_set (&req_exec_ckpt_checkpointretentiondurationset.source, conn); - memcpy (&req_exec_ckpt_checkpointretentiondurationset.checkpoint_name, - &req_lib_ckpt_checkpointretentiondurationset->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_checkpointretentiondurationset.ckpt_id = - req_lib_ckpt_checkpointretentiondurationset->ckpt_id; - req_exec_ckpt_checkpointretentiondurationset.retention_duration = - req_lib_ckpt_checkpointretentiondurationset->retention_duration; - - iovec.iov_base = (char *)&req_exec_ckpt_checkpointretentiondurationset; - iovec.iov_len = sizeof (req_exec_ckpt_checkpointretentiondurationset); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_ckpt_activereplicaset ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_activereplicaset *req_lib_ckpt_activereplicaset = (struct req_lib_ckpt_activereplicaset *)msg; - struct res_lib_ckpt_activereplicaset res_lib_ckpt_activereplicaset; - struct checkpoint *checkpoint; - SaAisErrorT error = SA_AIS_OK; - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_lib_ckpt_activereplicaset->checkpoint_name, - req_lib_ckpt_activereplicaset->ckpt_id); - - /* - * Make sure checkpoint is collocated and async update option - */ - if (((checkpoint->checkpoint_creation_attributes.creation_flags & SA_CKPT_CHECKPOINT_COLLOCATED) == 0) || - (checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) { - error = SA_AIS_ERR_BAD_OPERATION; - } - checkpoint->active_replica_set = 1; - res_lib_ckpt_activereplicaset.header.size = sizeof (struct res_lib_ckpt_activereplicaset); - res_lib_ckpt_activereplicaset.header.id = MESSAGE_RES_CKPT_ACTIVEREPLICASET; - res_lib_ckpt_activereplicaset.header.error = error; - - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_activereplicaset, - sizeof (struct res_lib_ckpt_activereplicaset)); -} - -static void message_handler_req_lib_ckpt_checkpointstatusget ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointstatusget *req_lib_ckpt_checkpointstatusget = (struct req_lib_ckpt_checkpointstatusget *)msg; - struct res_lib_ckpt_checkpointstatusget res_lib_ckpt_checkpointstatusget; - struct checkpoint *checkpoint; - int memory_used = 0; - int number_of_sections = 0; - struct list_head *checkpoint_section_list; - struct checkpoint_section *checkpointSection; - - /* - * Count memory used by checkpoint sections - */ - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_lib_ckpt_checkpointstatusget->checkpoint_name, - req_lib_ckpt_checkpointstatusget->ckpt_id); - - if (checkpoint) { - - for (checkpoint_section_list = checkpoint->sections_list_head.next; - checkpoint_section_list != &checkpoint->sections_list_head; - checkpoint_section_list = checkpoint_section_list->next) { - - checkpointSection = list_entry (checkpoint_section_list, - struct checkpoint_section, list); - - memory_used += checkpointSection->section_descriptor.section_size; - number_of_sections += 1; - } - - /* - * Build checkpoint status get response - */ - res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget); - res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET; - if (checkpoint->active_replica_set == 1) { - res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_OK; - } else { - res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST; - } - - memcpy (&res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.checkpoint_creation_attributes, - &checkpoint->checkpoint_creation_attributes, - sizeof (mar_ckpt_checkpoint_creation_attributes_t)); - res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.number_of_sections = number_of_sections; - res_lib_ckpt_checkpointstatusget.checkpoint_descriptor.memory_used = memory_used; - } - else { - log_printf (LOG_LEVEL_ERROR, "#### Could Not Find the Checkpoint's status so Returning Error. ####\n"); - - res_lib_ckpt_checkpointstatusget.header.size = sizeof (struct res_lib_ckpt_checkpointstatusget); - res_lib_ckpt_checkpointstatusget.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSTATUSGET; - res_lib_ckpt_checkpointstatusget.header.error = SA_AIS_ERR_NOT_EXIST; - } - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_checkpointstatusget, - sizeof (struct res_lib_ckpt_checkpointstatusget)); -} - -static void message_handler_req_lib_ckpt_sectioncreate ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectioncreate *req_lib_ckpt_sectioncreate = (struct req_lib_ckpt_sectioncreate *)msg; - struct req_exec_ckpt_sectioncreate req_exec_ckpt_sectioncreate; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_DEBUG, "Section create from conn %p\n", conn); - - req_exec_ckpt_sectioncreate.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SECTIONCREATE); - req_exec_ckpt_sectioncreate.header.size = sizeof (struct req_exec_ckpt_sectioncreate); - - api->ipc_source_set (&req_exec_ckpt_sectioncreate.source, conn); - - memcpy (&req_exec_ckpt_sectioncreate.checkpoint_name, - &req_lib_ckpt_sectioncreate->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_sectioncreate.ckpt_id = - req_lib_ckpt_sectioncreate->ckpt_id; - req_exec_ckpt_sectioncreate.id_len = req_lib_ckpt_sectioncreate->id_len; - req_exec_ckpt_sectioncreate.expiration_time = - req_lib_ckpt_sectioncreate->expiration_time; - req_exec_ckpt_sectioncreate.initial_data_size = - req_lib_ckpt_sectioncreate->initial_data_size; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sectioncreate; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sectioncreate); - - /* - * Send section name and initial data in message - */ - iovecs[1].iov_base = ((char *)req_lib_ckpt_sectioncreate) + sizeof (struct req_lib_ckpt_sectioncreate); - iovecs[1].iov_len = req_lib_ckpt_sectioncreate->header.size - sizeof (struct req_lib_ckpt_sectioncreate); - req_exec_ckpt_sectioncreate.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len) { - log_printf (LOG_LEVEL_DEBUG, "message_handler_req_lib_ckpt_sectioncreate Section = %p, id_len = %d\n", - iovecs[1].iov_base, - (int)iovecs[1].iov_len); - } - - if (iovecs[1].iov_len > 0) { - log_printf (LOG_LEVEL_DEBUG, "IOV_BASE is %p\n", iovecs[1].iov_base); - assert (api->totem_mcast (iovecs, 2, TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_ckpt_sectiondelete ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectiondelete *req_lib_ckpt_sectiondelete = (struct req_lib_ckpt_sectiondelete *)msg; - struct req_exec_ckpt_sectiondelete req_exec_ckpt_sectiondelete; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_DEBUG, "section delete from conn %p\n", conn); - - req_exec_ckpt_sectiondelete.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SECTIONDELETE); - req_exec_ckpt_sectiondelete.header.size = sizeof (struct req_exec_ckpt_sectiondelete); - - api->ipc_source_set (&req_exec_ckpt_sectiondelete.source, conn); - - memcpy (&req_exec_ckpt_sectiondelete.checkpoint_name, - &req_lib_ckpt_sectiondelete->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_sectiondelete.ckpt_id = - req_lib_ckpt_sectiondelete->ckpt_id; - req_exec_ckpt_sectiondelete.id_len = req_lib_ckpt_sectiondelete->id_len; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sectiondelete; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sectiondelete); - - /* - * Send section name - */ - iovecs[1].iov_base = ((char *)req_lib_ckpt_sectiondelete) + - sizeof (struct req_lib_ckpt_sectiondelete); - iovecs[1].iov_len = req_lib_ckpt_sectiondelete->header.size - - sizeof (struct req_lib_ckpt_sectiondelete); - req_exec_ckpt_sectiondelete.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_ckpt_sectionexpirationtimeset ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectionexpirationtimeset *req_lib_ckpt_sectionexpirationtimeset = (struct req_lib_ckpt_sectionexpirationtimeset *)msg; - struct req_exec_ckpt_sectionexpirationtimeset req_exec_ckpt_sectionexpirationtimeset; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_DEBUG, "section expiration time set from conn %p\n", conn); - req_exec_ckpt_sectionexpirationtimeset.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SECTIONEXPIRATIONTIMESET); - req_exec_ckpt_sectionexpirationtimeset.header.size = sizeof (struct req_exec_ckpt_sectionexpirationtimeset); - - api->ipc_source_set (&req_exec_ckpt_sectionexpirationtimeset.source, conn); - - memcpy (&req_exec_ckpt_sectionexpirationtimeset.checkpoint_name, - &req_lib_ckpt_sectionexpirationtimeset->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_sectionexpirationtimeset.ckpt_id = - req_lib_ckpt_sectionexpirationtimeset->ckpt_id; - req_exec_ckpt_sectionexpirationtimeset.id_len = - req_lib_ckpt_sectionexpirationtimeset->id_len; - req_exec_ckpt_sectionexpirationtimeset.expiration_time = - req_lib_ckpt_sectionexpirationtimeset->expiration_time; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionexpirationtimeset; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionexpirationtimeset); - - /* - * Send section name - */ - iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionexpirationtimeset) + - sizeof (struct req_lib_ckpt_sectionexpirationtimeset); - iovecs[1].iov_len = req_lib_ckpt_sectionexpirationtimeset->header.size - - sizeof (struct req_lib_ckpt_sectionexpirationtimeset); - req_exec_ckpt_sectionexpirationtimeset.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_ckpt_sectionwrite ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectionwrite *req_lib_ckpt_sectionwrite = (struct req_lib_ckpt_sectionwrite *)msg; - struct req_exec_ckpt_sectionwrite req_exec_ckpt_sectionwrite; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_DEBUG, "Received data from lib with len = %d and ref = 0x%lx\n", - (int)req_lib_ckpt_sectionwrite->data_size, - (long)req_lib_ckpt_sectionwrite->data_offset); - - log_printf (LOG_LEVEL_DEBUG, "Checkpoint section being written to is %s, id_len = %d\n", - ((char *)req_lib_ckpt_sectionwrite) + - sizeof (struct req_lib_ckpt_sectionwrite), - req_lib_ckpt_sectionwrite->id_len); - - log_printf (LOG_LEVEL_DEBUG, "Section write from conn %p\n", conn); - - /* - * checkpoint opened is writeable mode so send message to cluster - */ - req_exec_ckpt_sectionwrite.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SECTIONWRITE); - req_exec_ckpt_sectionwrite.header.size = - sizeof (struct req_exec_ckpt_sectionwrite); - - api->ipc_source_set (&req_exec_ckpt_sectionwrite.source, conn); - - memcpy (&req_exec_ckpt_sectionwrite.checkpoint_name, - &req_lib_ckpt_sectionwrite->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_sectionwrite.ckpt_id = - req_lib_ckpt_sectionwrite->ckpt_id; - req_exec_ckpt_sectionwrite.id_len = - req_lib_ckpt_sectionwrite->id_len; - req_exec_ckpt_sectionwrite.data_offset = - req_lib_ckpt_sectionwrite->data_offset; - req_exec_ckpt_sectionwrite.data_size = - req_lib_ckpt_sectionwrite->data_size; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionwrite; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionwrite); - - /* - * Send section name and data to write in message - */ - iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionwrite) + - sizeof (struct req_lib_ckpt_sectionwrite); - iovecs[1].iov_len = req_lib_ckpt_sectionwrite->header.size - - sizeof (struct req_lib_ckpt_sectionwrite); - req_exec_ckpt_sectionwrite.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_ckpt_sectionoverwrite ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectionoverwrite *req_lib_ckpt_sectionoverwrite = (struct req_lib_ckpt_sectionoverwrite *)msg; - struct req_exec_ckpt_sectionoverwrite req_exec_ckpt_sectionoverwrite; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_DEBUG, "Section overwrite from conn %p\n", conn); - - req_exec_ckpt_sectionoverwrite.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SECTIONOVERWRITE); - req_exec_ckpt_sectionoverwrite.header.size = - sizeof (struct req_exec_ckpt_sectionoverwrite); - api->ipc_source_set (&req_exec_ckpt_sectionoverwrite.source, conn); - memcpy (&req_exec_ckpt_sectionoverwrite.checkpoint_name, - &req_lib_ckpt_sectionoverwrite->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_sectionoverwrite.ckpt_id = - req_lib_ckpt_sectionoverwrite->ckpt_id; - req_exec_ckpt_sectionoverwrite.id_len = - req_lib_ckpt_sectionoverwrite->id_len; - req_exec_ckpt_sectionoverwrite.data_size = - req_lib_ckpt_sectionoverwrite->data_size; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionoverwrite; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionoverwrite); - - /* - * Send section name and data to overwrite in message - */ - iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionoverwrite) + - sizeof (struct req_lib_ckpt_sectionoverwrite); - iovecs[1].iov_len = req_lib_ckpt_sectionoverwrite->header.size - - sizeof (struct req_lib_ckpt_sectionoverwrite); - req_exec_ckpt_sectionoverwrite.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_ckpt_sectionread ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectionread *req_lib_ckpt_sectionread = (struct req_lib_ckpt_sectionread *)msg; - struct req_exec_ckpt_sectionread req_exec_ckpt_sectionread; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_DEBUG, "Section read from conn %p\n", conn); - - /* - * checkpoint opened is writeable mode so send message to cluster - */ - req_exec_ckpt_sectionread.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SECTIONREAD); - req_exec_ckpt_sectionread.header.size = - sizeof (struct req_exec_ckpt_sectionread); - api->ipc_source_set (&req_exec_ckpt_sectionread.source, conn); - memcpy (&req_exec_ckpt_sectionread.checkpoint_name, - &req_lib_ckpt_sectionread->checkpoint_name, - sizeof (mar_name_t)); - req_exec_ckpt_sectionread.ckpt_id = - req_lib_ckpt_sectionread->ckpt_id; - req_exec_ckpt_sectionread.id_len = - req_lib_ckpt_sectionread->id_len; - req_exec_ckpt_sectionread.data_offset = - req_lib_ckpt_sectionread->data_offset; - req_exec_ckpt_sectionread.data_size = - req_lib_ckpt_sectionread->data_size; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sectionread; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sectionread); - - /* - * Send section name and data to overwrite in message - */ - iovecs[1].iov_base = ((char *)req_lib_ckpt_sectionread) + - sizeof (struct req_lib_ckpt_sectionread); - iovecs[1].iov_len = req_lib_ckpt_sectionread->header.size - - sizeof (struct req_lib_ckpt_sectionread); - req_exec_ckpt_sectionread.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_ckpt_checkpointsynchronize ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointsynchronize *req_lib_ckpt_checkpointsynchronize = (struct req_lib_ckpt_checkpointsynchronize *)msg; - struct res_lib_ckpt_checkpointsynchronize res_lib_ckpt_checkpointsynchronize; - struct checkpoint *checkpoint; - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_lib_ckpt_checkpointsynchronize->checkpoint_name, - req_lib_ckpt_checkpointsynchronize->ckpt_id); - if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) { - res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_BAD_OPERATION; - } else - if (checkpoint->active_replica_set == 1) { - res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_OK; - } else { - res_lib_ckpt_checkpointsynchronize.header.error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib_ckpt_checkpointsynchronize.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronize); - res_lib_ckpt_checkpointsynchronize.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZE; - - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_checkpointsynchronize, - sizeof (struct res_lib_ckpt_checkpointsynchronize)); -} - -static void message_handler_req_lib_ckpt_checkpointsynchronizeasync ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_checkpointsynchronizeasync *req_lib_ckpt_checkpointsynchronizeasync = (struct req_lib_ckpt_checkpointsynchronizeasync *)msg; - struct res_lib_ckpt_checkpointsynchronizeasync res_lib_ckpt_checkpointsynchronizeasync; - struct checkpoint *checkpoint; - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_lib_ckpt_checkpointsynchronizeasync->checkpoint_name, - req_lib_ckpt_checkpointsynchronizeasync->ckpt_id); - if ((checkpoint->checkpoint_creation_attributes.creation_flags & (SA_CKPT_WR_ACTIVE_REPLICA | SA_CKPT_WR_ACTIVE_REPLICA_WEAK)) == 0) { - res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_BAD_OPERATION; - } else - if (checkpoint->active_replica_set == 1) { - res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_OK; - } else { - res_lib_ckpt_checkpointsynchronizeasync.header.error = SA_AIS_ERR_NOT_EXIST; - } - - res_lib_ckpt_checkpointsynchronizeasync.header.size = sizeof (struct res_lib_ckpt_checkpointsynchronizeasync); - res_lib_ckpt_checkpointsynchronizeasync.header.id = MESSAGE_RES_CKPT_CHECKPOINT_CHECKPOINTSYNCHRONIZEASYNC; - res_lib_ckpt_checkpointsynchronizeasync.invocation = req_lib_ckpt_checkpointsynchronizeasync->invocation; - - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_checkpointsynchronizeasync, - sizeof (struct res_lib_ckpt_checkpointsynchronizeasync)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (conn), - &res_lib_ckpt_checkpointsynchronizeasync, - sizeof (struct res_lib_ckpt_checkpointsynchronizeasync)); -} - -static void message_handler_req_lib_ckpt_sectioniterationinitialize ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectioniterationinitialize *req_lib_ckpt_sectioniterationinitialize = (struct req_lib_ckpt_sectioniterationinitialize *)msg; - struct res_lib_ckpt_sectioniterationinitialize res_lib_ckpt_sectioniterationinitialize; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - struct iteration_entry *iteration_entries; - struct list_head *section_list; - struct iteration_instance *iteration_instance; - void *iteration_instance_p; - unsigned int iteration_handle = 0; - int res; - SaAisErrorT error = SA_AIS_OK; - - struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)api->ipc_private_data_get (conn); - - log_printf (LOG_LEVEL_DEBUG, "section iteration initialize\n"); - - checkpoint = checkpoint_find ( - &checkpoint_list_head, - &req_lib_ckpt_sectioniterationinitialize->checkpoint_name, - req_lib_ckpt_sectioniterationinitialize->ckpt_id); - if (checkpoint == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (checkpoint->active_replica_set == 0) { - log_printf (LOG_LEVEL_DEBUG, "iterationinitialize: no active replica, returning error.\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - res = hdb_handle_create (&ckpt_pd->iteration_hdb, sizeof(struct iteration_instance), - &iteration_handle); - if (res != 0) { - goto error_exit; - } - - res = hdb_handle_get (&ckpt_pd->iteration_hdb, iteration_handle, - &iteration_instance_p); - if (res != 0) { - hdb_handle_destroy (&ckpt_pd->iteration_hdb, iteration_handle); - goto error_exit; - } - iteration_instance = (struct iteration_instance *)iteration_instance_p; - - iteration_instance->iteration_entries = NULL; - iteration_instance->iteration_entries_count = 0; - iteration_instance->iteration_pos = 0; - - memcpy (&iteration_instance->checkpoint_name, - &req_lib_ckpt_sectioniterationinitialize->checkpoint_name, - sizeof (mar_name_t)); - iteration_instance->ckpt_id = - req_lib_ckpt_sectioniterationinitialize->ckpt_id; - - /* - * Iterate list of checkpoint sections - */ - for (section_list = checkpoint->sections_list_head.next; - section_list != &checkpoint->sections_list_head; - section_list = section_list->next) { - - checkpoint_section = list_entry (section_list, - struct checkpoint_section, list); - - switch (req_lib_ckpt_sectioniterationinitialize->sections_chosen) { - case SA_CKPT_SECTIONS_FOREVER: - if (checkpoint_section->section_descriptor.expiration_time != SA_TIME_END) { - continue; - } - break; - case SA_CKPT_SECTIONS_LEQ_EXPIRATION_TIME: - if (checkpoint_section->section_descriptor.expiration_time > req_lib_ckpt_sectioniterationinitialize->expiration_time) { - continue; - } - break; - case SA_CKPT_SECTIONS_GEQ_EXPIRATION_TIME: - if (checkpoint_section->section_descriptor.expiration_time < req_lib_ckpt_sectioniterationinitialize->expiration_time) { - continue; - } - break; - case SA_CKPT_SECTIONS_CORRUPTED: - /* there can be no corrupted sections - do nothing */ - break; - case SA_CKPT_SECTIONS_ANY: - /* iterate all sections - do nothing */ - break; - } - iteration_entries = realloc ( - iteration_instance->iteration_entries, - sizeof (struct iteration_entry) * - (iteration_instance->iteration_entries_count + 1)); - if (iteration_entries == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_put; - } - iteration_instance->iteration_entries = iteration_entries; - - iteration_entries[iteration_instance->iteration_entries_count].section_id = - malloc (checkpoint_section->section_descriptor.section_id.id_len); - assert (iteration_entries[iteration_instance->iteration_entries_count].section_id); - memcpy (iteration_entries[iteration_instance->iteration_entries_count].section_id, - checkpoint_section->section_descriptor.section_id.id, - checkpoint_section->section_descriptor.section_id.id_len); - iteration_entries[iteration_instance->iteration_entries_count].section_id_len = checkpoint_section->section_descriptor.section_id.id_len; - iteration_instance->iteration_entries_count += 1; - - } - -error_put: - hdb_handle_put (&ckpt_pd->iteration_hdb, iteration_handle); - -error_exit: - res_lib_ckpt_sectioniterationinitialize.header.size = sizeof (struct res_lib_ckpt_sectioniterationinitialize); - res_lib_ckpt_sectioniterationinitialize.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONINITIALIZE; - res_lib_ckpt_sectioniterationinitialize.header.error = error; - res_lib_ckpt_sectioniterationinitialize.iteration_handle = iteration_handle; - res_lib_ckpt_sectioniterationinitialize.max_section_id_size = - checkpoint->checkpoint_creation_attributes.max_section_id_size; - - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_sectioniterationinitialize, - sizeof (struct res_lib_ckpt_sectioniterationinitialize)); -} - -static void message_handler_req_lib_ckpt_sectioniterationfinalize ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectioniterationfinalize *req_lib_ckpt_sectioniterationfinalize = (struct req_lib_ckpt_sectioniterationfinalize *)msg; - struct res_lib_ckpt_sectioniterationfinalize res_lib_ckpt_sectioniterationfinalize; - SaAisErrorT error = SA_AIS_OK; - struct iteration_instance *iteration_instance; - void *iteration_instance_p; - unsigned int res; - - struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)api->ipc_private_data_get (conn); - - res = hdb_handle_get (&ckpt_pd->iteration_hdb, - req_lib_ckpt_sectioniterationfinalize->iteration_handle, - &iteration_instance_p); - if (res != 0) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - iteration_instance = (struct iteration_instance *)iteration_instance_p; - - free (iteration_instance->iteration_entries); - - hdb_handle_put (&ckpt_pd->iteration_hdb, - req_lib_ckpt_sectioniterationfinalize->iteration_handle); - - hdb_handle_destroy (&ckpt_pd->iteration_hdb, - req_lib_ckpt_sectioniterationfinalize->iteration_handle); - -error_exit: - res_lib_ckpt_sectioniterationfinalize.header.size = sizeof (struct res_lib_ckpt_sectioniterationfinalize); - res_lib_ckpt_sectioniterationfinalize.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONFINALIZE; - res_lib_ckpt_sectioniterationfinalize.header.error = error; - - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_sectioniterationfinalize, - sizeof (struct res_lib_ckpt_sectioniterationfinalize)); -} - -static void message_handler_req_lib_ckpt_sectioniterationnext ( - void *conn, - void *msg) -{ - struct req_lib_ckpt_sectioniterationnext *req_lib_ckpt_sectioniterationnext = (struct req_lib_ckpt_sectioniterationnext *)msg; - struct res_lib_ckpt_sectioniterationnext res_lib_ckpt_sectioniterationnext; - SaAisErrorT error = SA_AIS_OK; - int section_id_size = 0; - unsigned int res; - struct iteration_instance *iteration_instance = NULL; - void *iteration_instance_p; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section = NULL; - - struct ckpt_pd *ckpt_pd = (struct ckpt_pd *)api->ipc_private_data_get (conn); - - log_printf (LOG_LEVEL_DEBUG, "section iteration next\n"); - res = hdb_handle_get (&ckpt_pd->iteration_hdb, - req_lib_ckpt_sectioniterationnext->iteration_handle, - &iteration_instance_p); - if (res != 0) { - error = SA_AIS_ERR_LIBRARY; - goto error_exit; - } - - iteration_instance = (struct iteration_instance *)iteration_instance_p; - assert (iteration_instance); - /* - * Find active iteration entry - */ - for (;;) { - /* - * No more sections in iteration - */ - if (iteration_instance->iteration_pos == iteration_instance->iteration_entries_count) { - error = SA_AIS_ERR_NO_SECTIONS; - goto error_put; - } - - /* - * Find the checkpoint section to respond to library - */ - checkpoint = checkpoint_find_specific ( - &checkpoint_list_head, - &iteration_instance->checkpoint_name, - iteration_instance->ckpt_id); - - assert (checkpoint); - - checkpoint_section = checkpoint_section_find ( - checkpoint, - iteration_instance->iteration_entries[iteration_instance->iteration_pos].section_id, - iteration_instance->iteration_entries[iteration_instance->iteration_pos].section_id_len); - - - iteration_instance->iteration_pos += 1; - /* - * If checkpoint section found, then return it in iteration - */ - if (checkpoint_section) { - section_id_size = checkpoint_section->section_descriptor.section_id.id_len; - - memcpy (&res_lib_ckpt_sectioniterationnext.section_descriptor, - &checkpoint_section->section_descriptor, - sizeof (mar_ckpt_section_descriptor_t)); - - /* - * This drops out of for loop - */ - break; - } - - } - -error_put: - hdb_handle_put (&ckpt_pd->iteration_hdb, req_lib_ckpt_sectioniterationnext->iteration_handle); - -error_exit: - res_lib_ckpt_sectioniterationnext.header.size = sizeof (struct res_lib_ckpt_sectioniterationnext) + section_id_size; - res_lib_ckpt_sectioniterationnext.header.id = MESSAGE_RES_CKPT_SECTIONITERATIONNEXT; - res_lib_ckpt_sectioniterationnext.header.error = error; - - api->ipc_conn_send_response ( - conn, - &res_lib_ckpt_sectioniterationnext, - sizeof (struct res_lib_ckpt_sectioniterationnext)); - - if (error == SA_AIS_OK) { - api->ipc_conn_send_response ( - conn, - checkpoint_section->section_descriptor.section_id.id, - checkpoint_section->section_descriptor.section_id.id_len); - } -} - -/* - * Recovery after network partition or merge - */ -void sync_refcount_increment ( - struct checkpoint *checkpoint, - unsigned int nodeid) -{ - unsigned int i; - - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - if (checkpoint->refcount_set[i].nodeid == 0) { - checkpoint->refcount_set[i].nodeid = nodeid; - checkpoint->refcount_set[i].refcount = 1; - break; - } - if (checkpoint->refcount_set[i].nodeid == nodeid) { - checkpoint->refcount_set[i].refcount += 1; - break; - } - } -} - -void sync_refcount_add ( - struct checkpoint *checkpoint, - unsigned int nodeid, - unsigned int count) -{ - unsigned int i; - - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - if (checkpoint->refcount_set[i].nodeid == 0) { - checkpoint->refcount_set[i].nodeid = nodeid; - checkpoint->refcount_set[i].refcount = count; - break; - } - if (checkpoint->refcount_set[i].nodeid == nodeid) { - checkpoint->refcount_set[i].refcount += count; - break; - } - } -} - -void sync_refcount_decrement ( - struct checkpoint *checkpoint, - unsigned int nodeid) -{ - unsigned int i; - - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - if (checkpoint->refcount_set[i].nodeid == 0) { - break; - } - if (checkpoint->refcount_set[i].nodeid == nodeid) { - checkpoint->refcount_set[i].refcount -= 1; - break; - } - } -} - -/* - * Sum all reference counts for the checkpoint - */ -void sync_refcount_calculate ( - struct checkpoint *checkpoint) -{ - checkpoint->reference_count = 0; - unsigned int i; - - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - if (checkpoint->refcount_set[i].nodeid == 0) { - break; - } - - checkpoint->reference_count += checkpoint->refcount_set[i].refcount; - } -} - -void sync_checkpoints_free (struct list_head *ckpt_list_head) -{ - struct checkpoint *checkpoint; - struct list_head *list; - - list = ckpt_list_head->next; - while (list != ckpt_list_head) { - checkpoint = list_entry (list, struct checkpoint, list); - list = list->next; - checkpoint_release (checkpoint); - } - list_init (ckpt_list_head); -} - -static inline void sync_checkpoints_enter (void) -{ - struct checkpoint *checkpoint; - - ENTER(); - - my_sync_state = SYNC_STATE_CHECKPOINT; - my_iteration_state = ITERATION_STATE_CHECKPOINT; - my_iteration_state_checkpoint = checkpoint_list_head.next; - - checkpoint = list_entry (checkpoint_list_head.next, struct checkpoint, - list); - my_iteration_state_section = checkpoint->sections_list_head.next; - - LEAVE(); -} - -static inline void sync_refcounts_enter (void) -{ - my_sync_state = SYNC_STATE_REFCOUNT; -} - -static void ckpt_sync_init (void) -{ - ENTER(); - - sync_checkpoints_enter(); - - LEAVE(); -} - -static int sync_checkpoint_transmit (struct checkpoint *checkpoint) -{ - struct req_exec_ckpt_sync_checkpoint req_exec_ckpt_sync_checkpoint; - struct iovec iovec; - - req_exec_ckpt_sync_checkpoint.header.size = - sizeof (struct req_exec_ckpt_sync_checkpoint); - req_exec_ckpt_sync_checkpoint.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SYNCCHECKPOINT); - - memcpy (&req_exec_ckpt_sync_checkpoint.ring_id, - &my_saved_ring_id, sizeof (struct memb_ring_id)); - - memcpy (&req_exec_ckpt_sync_checkpoint.checkpoint_name, - &checkpoint->name, sizeof (mar_name_t)); - - req_exec_ckpt_sync_checkpoint.ckpt_id = checkpoint->ckpt_id; - - memcpy (&req_exec_ckpt_sync_checkpoint.checkpoint_creation_attributes, - &checkpoint->checkpoint_creation_attributes, - sizeof (mar_ckpt_checkpoint_creation_attributes_t)); - - req_exec_ckpt_sync_checkpoint.active_replica_set = - checkpoint->active_replica_set; - - req_exec_ckpt_sync_checkpoint.unlinked = - checkpoint->unlinked; - - iovec.iov_base = (char *)&req_exec_ckpt_sync_checkpoint; - iovec.iov_len = sizeof (req_exec_ckpt_sync_checkpoint); - - return (api->totem_mcast (&iovec, 1, TOTEM_AGREED)); -} - -static int sync_checkpoint_section_transmit ( - struct checkpoint *checkpoint, - struct checkpoint_section *checkpoint_section) -{ - struct req_exec_ckpt_sync_checkpoint_section req_exec_ckpt_sync_checkpoint_section; - struct iovec iovecs[3]; - - ENTER(); - - TRACE1 ("transmitting section\n"); - req_exec_ckpt_sync_checkpoint_section.header.size = - sizeof (struct req_exec_ckpt_sync_checkpoint_section); - req_exec_ckpt_sync_checkpoint_section.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SYNCCHECKPOINTSECTION); - - memcpy (&req_exec_ckpt_sync_checkpoint_section.ring_id, - &my_saved_ring_id, sizeof (struct memb_ring_id)); - - memcpy (&req_exec_ckpt_sync_checkpoint_section.checkpoint_name, - &checkpoint->name, sizeof (mar_name_t)); - - req_exec_ckpt_sync_checkpoint_section.ckpt_id = checkpoint->ckpt_id; - - req_exec_ckpt_sync_checkpoint_section.id_len = - checkpoint_section->section_descriptor.section_id.id_len; - - req_exec_ckpt_sync_checkpoint_section.section_size = - checkpoint_section->section_descriptor.section_size; - - req_exec_ckpt_sync_checkpoint_section.section_size = - checkpoint_section->section_descriptor.section_size; - - req_exec_ckpt_sync_checkpoint_section.expiration_time = - checkpoint_section->section_descriptor.expiration_time; - - iovecs[0].iov_base = (char *)&req_exec_ckpt_sync_checkpoint_section; - iovecs[0].iov_len = sizeof (req_exec_ckpt_sync_checkpoint_section); - iovecs[1].iov_base = (char *)checkpoint_section->section_descriptor.section_id.id; - iovecs[1].iov_len = checkpoint_section->section_descriptor.section_id.id_len; - iovecs[2].iov_base = checkpoint_section->section_data; - iovecs[2].iov_len = checkpoint_section->section_descriptor.section_size; - - LEAVE(); - return (api->totem_mcast (iovecs, 3, TOTEM_AGREED)); -} - -static int sync_checkpoint_refcount_transmit ( - struct checkpoint *checkpoint) -{ - struct req_exec_ckpt_sync_checkpoint_refcount req_exec_ckpt_sync_checkpoint_refcount; - struct iovec iovec; - - ENTER(); - - TRACE1 ("transmitting refcounts for checkpoints\n"); - req_exec_ckpt_sync_checkpoint_refcount.header.size = - sizeof (struct req_exec_ckpt_sync_checkpoint_refcount); - req_exec_ckpt_sync_checkpoint_refcount.header.id = - SERVICE_ID_MAKE (CKPT_SERVICE, - MESSAGE_REQ_EXEC_CKPT_SYNCCHECKPOINTREFCOUNT); - - memcpy (&req_exec_ckpt_sync_checkpoint_refcount.ring_id, - &my_saved_ring_id, sizeof (struct memb_ring_id)); - - memcpy (&req_exec_ckpt_sync_checkpoint_refcount.checkpoint_name, - &checkpoint->name, sizeof (mar_name_t)); - - req_exec_ckpt_sync_checkpoint_refcount.ckpt_id = checkpoint->ckpt_id; - - marshall_to_mar_refcount_set_t_all ( - req_exec_ckpt_sync_checkpoint_refcount.refcount_set, - checkpoint->refcount_set); - - iovec.iov_base = (char *)&req_exec_ckpt_sync_checkpoint_refcount; - iovec.iov_len = sizeof (struct req_exec_ckpt_sync_checkpoint_refcount); - - LEAVE(); - return (api->totem_mcast (&iovec, 1, TOTEM_AGREED)); -} - -unsigned int sync_checkpoints_iterate (void) -{ - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - struct list_head *checkpoint_list; - struct list_head *section_list; - unsigned int res = 0; - - for (checkpoint_list = checkpoint_list_head.next; - checkpoint_list != &checkpoint_list_head; - checkpoint_list = checkpoint_list->next) { - - checkpoint = list_entry (checkpoint_list, struct checkpoint, list); - - res = sync_checkpoint_transmit (checkpoint); - if (res != 0) { - break; - } - for (section_list = checkpoint->sections_list_head.next; - section_list != &checkpoint->sections_list_head; - section_list = section_list->next) { - - checkpoint_section = list_entry (section_list, struct checkpoint_section, list); - res = sync_checkpoint_section_transmit (checkpoint, checkpoint_section); - } - } - return (res); -} - -unsigned int sync_refcounts_iterate (void) -{ - struct checkpoint *checkpoint; - struct list_head *list; - unsigned int res = 0; - - for (list = checkpoint_list_head.next; - list != &checkpoint_list_head; - list = list->next) { - - checkpoint = list_entry (list, struct checkpoint, list); - - res = sync_checkpoint_refcount_transmit (checkpoint); - if (res != 0) { - break; - } - } - return (res); -} - -static int ckpt_sync_process (void) -{ - unsigned int done_queueing = 1; - unsigned int continue_processing = 0; - unsigned int res; - - ENTER(); - - switch (my_sync_state) { - case SYNC_STATE_CHECKPOINT: - if (my_lowest_nodeid == api->totem_nodeid_get ()) { - TRACE1 ("should transmit checkpoints because lowest member in old configuration.\n"); - res = sync_checkpoints_iterate (); - - if (res == 0) { - done_queueing = 1; - } - } - if (done_queueing) { - sync_refcounts_enter (); - } - - /* - * TODO recover current iteration state - */ - continue_processing = 1; - break; - - case SYNC_STATE_REFCOUNT: - done_queueing = 1; - if (my_lowest_nodeid == api->totem_nodeid_get()) { - TRACE1 ("transmit refcounts because this processor is the lowest member in old configuration.\n"); - res = sync_refcounts_iterate (); - } - if (done_queueing) { - continue_processing = 0; - } - break; - } - - LEAVE(); - return (continue_processing); -} - -static void ckpt_sync_activate (void) -{ - ENTER(); - - sync_checkpoints_free (&checkpoint_list_head); - - list_init (&checkpoint_list_head); - - if (!list_empty (&sync_checkpoint_list_head)) { - list_splice (&sync_checkpoint_list_head, &checkpoint_list_head); - } - - list_init (&sync_checkpoint_list_head); - - my_sync_state = SYNC_STATE_CHECKPOINT; - - LEAVE(); -} - -static void ckpt_sync_abort (void) -{ - sync_checkpoints_free (&sync_checkpoint_list_head); -} - -static void message_handler_req_exec_ckpt_sync_checkpoint ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sync_checkpoint *req_exec_ckpt_sync_checkpoint = - (struct req_exec_ckpt_sync_checkpoint *)message; - struct checkpoint *checkpoint = 0; - - ENTER(); - - /* - * Ignore messages from previous ring ids - */ - if (memcmp (&req_exec_ckpt_sync_checkpoint->ring_id, - &my_saved_ring_id, sizeof (struct memb_ring_id)) != 0) { - return; - } - - checkpoint = checkpoint_find_specific ( - &sync_checkpoint_list_head, - &req_exec_ckpt_sync_checkpoint->checkpoint_name, - req_exec_ckpt_sync_checkpoint->ckpt_id); - - /* - * If checkpoint doesn't exist, create one - */ - if (checkpoint == 0) { - checkpoint = malloc (sizeof (struct checkpoint)); - if (checkpoint == 0) { - LEAVE(); -#ifdef TODO - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); -#endif - } - memset (checkpoint, 0, sizeof (struct checkpoint)); - - memcpy (&checkpoint->name, - &req_exec_ckpt_sync_checkpoint->checkpoint_name, - sizeof (mar_name_t)); - - memcpy (&checkpoint->checkpoint_creation_attributes, - &req_exec_ckpt_sync_checkpoint->checkpoint_creation_attributes, - sizeof (mar_ckpt_checkpoint_creation_attributes_t)); - - memset (&checkpoint->refcount_set, 0, sizeof (struct refcount_set) * PROCESSOR_COUNT_MAX); - checkpoint->ckpt_id = req_exec_ckpt_sync_checkpoint->ckpt_id; - - checkpoint->active_replica_set = req_exec_ckpt_sync_checkpoint->active_replica_set; - - checkpoint->unlinked = req_exec_ckpt_sync_checkpoint->unlinked; - checkpoint->reference_count = 0; - checkpoint->retention_timer = 0; - checkpoint->section_count = 0; - - list_init (&checkpoint->list); - list_init (&checkpoint->sections_list_head); - list_add (&checkpoint->list, &sync_checkpoint_list_head); - - memset (checkpoint->refcount_set, 0, - sizeof (struct refcount_set) * PROCESSOR_COUNT_MAX); - } - - if (checkpoint->ckpt_id >= global_ckpt_id) { - global_ckpt_id = checkpoint->ckpt_id + 1; - } - - LEAVE(); -} - -static void message_handler_req_exec_ckpt_sync_checkpoint_section ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sync_checkpoint_section *req_exec_ckpt_sync_checkpoint_section = - (struct req_exec_ckpt_sync_checkpoint_section *)message; - struct checkpoint *checkpoint; - struct checkpoint_section *checkpoint_section; - char *section_contents; - char *section_id; - - ENTER(); - - /* - * Ignore messages from previous ring ids - */ - if (memcmp (&req_exec_ckpt_sync_checkpoint_section->ring_id, - &my_saved_ring_id, sizeof (struct memb_ring_id)) != 0) { - LEAVE(); - return; - } - - checkpoint = checkpoint_find_specific ( - &sync_checkpoint_list_head, - &req_exec_ckpt_sync_checkpoint_section->checkpoint_name, - req_exec_ckpt_sync_checkpoint_section->ckpt_id); - - assert (checkpoint != NULL); - - /* - * Determine if user-specified checkpoint section already exists - */ - checkpoint_section = checkpoint_section_find ( - checkpoint, - ((char *)req_exec_ckpt_sync_checkpoint_section) + - sizeof (struct req_exec_ckpt_sync_checkpoint_section), - req_exec_ckpt_sync_checkpoint_section->id_len); - if (checkpoint_section == NULL) { - /* - * Allocate checkpoint section - */ - checkpoint_section = malloc (sizeof (struct checkpoint_section)); - if (checkpoint_section == 0) { - LEAVE(); -#ifdef TODO - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); -#endif - } - section_contents = malloc (req_exec_ckpt_sync_checkpoint_section->section_size); - if (section_contents == 0) { - free (checkpoint_section); - LEAVE(); -#ifdef TODO - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); -#endif - } - if (req_exec_ckpt_sync_checkpoint_section->id_len) { - - section_id = malloc (req_exec_ckpt_sync_checkpoint_section->id_len + 1); - if (section_id == 0) { - free (checkpoint_section); - free (section_contents); - LEAVE(); -#ifdef TODO - openais_exit_error (AIS_DONE_OUT_OF_MEMORY); -#endif - } - - /* - * Copy checkpoint section and section ID - */ - memcpy (section_id, - ((char *)req_exec_ckpt_sync_checkpoint_section) + - sizeof (struct req_exec_ckpt_sync_checkpoint_section), - req_exec_ckpt_sync_checkpoint_section->id_len); - - /* - * Null terminate the section id for printing purposes - */ - ((char*)(section_id))[req_exec_ckpt_sync_checkpoint_section->id_len] = '\0'; - - } else { - /* - * Default section - */ - section_id = NULL; - } - - memcpy (section_contents, - ((char *)req_exec_ckpt_sync_checkpoint_section) + - sizeof (struct req_exec_ckpt_sync_checkpoint_section) + - req_exec_ckpt_sync_checkpoint_section->id_len, - req_exec_ckpt_sync_checkpoint_section->section_size); - - /* - * Configure checkpoint section - */ - checkpoint_section->section_descriptor.section_id.id = (unsigned char *)section_id; - checkpoint_section->section_descriptor.section_id.id_len = - req_exec_ckpt_sync_checkpoint_section->id_len; - checkpoint_section->section_descriptor.section_size = - req_exec_ckpt_sync_checkpoint_section->section_size; - checkpoint_section->section_descriptor.expiration_time = - req_exec_ckpt_sync_checkpoint_section->expiration_time; - checkpoint_section->section_descriptor.section_state = - SA_CKPT_SECTION_VALID; - checkpoint_section->section_descriptor.last_update = 0; /* TODO current time */ - checkpoint_section->section_data = section_contents; - checkpoint_section->expiration_timer = 0; - - /* - * Add checkpoint section to checkpoint - */ - list_init (&checkpoint_section->list); - list_add (&checkpoint_section->list, - &checkpoint->sections_list_head); - checkpoint->section_count += 1; - } - - LEAVE(); -} - -static void message_handler_req_exec_ckpt_sync_checkpoint_refcount ( - void *message, - unsigned int nodeid) -{ - struct req_exec_ckpt_sync_checkpoint_refcount *req_exec_ckpt_sync_checkpoint_refcount - = (struct req_exec_ckpt_sync_checkpoint_refcount *)message; - struct checkpoint *checkpoint; - unsigned int i, j; - - ENTER(); - - /* - * Ignore messages from previous ring ids - */ - if (memcmp (&req_exec_ckpt_sync_checkpoint_refcount->ring_id, - &my_saved_ring_id, sizeof (struct memb_ring_id)) != 0) { - LEAVE(); - return; - } - - checkpoint = checkpoint_find_specific ( - &sync_checkpoint_list_head, - &req_exec_ckpt_sync_checkpoint_refcount->checkpoint_name, - req_exec_ckpt_sync_checkpoint_refcount->ckpt_id); - - assert (checkpoint != NULL); - - for (i = 0; i < PROCESSOR_COUNT_MAX; i++) { - if (req_exec_ckpt_sync_checkpoint_refcount->refcount_set[i].nodeid == 0) { - break; - } - for (j = 0; j < PROCESSOR_COUNT_MAX; j++) { - if (checkpoint->refcount_set[j].nodeid == 0) { - checkpoint->refcount_set[j].nodeid = - req_exec_ckpt_sync_checkpoint_refcount->refcount_set[i].nodeid; - checkpoint->refcount_set[j].refcount = - req_exec_ckpt_sync_checkpoint_refcount->refcount_set[i].refcount; - /* - * No match found, added processor reference count - */ - break; - } - - if (req_exec_ckpt_sync_checkpoint_refcount->refcount_set[i].nodeid == checkpoint->refcount_set[j].nodeid) { - checkpoint->refcount_set[j].refcount += - req_exec_ckpt_sync_checkpoint_refcount->refcount_set[i].refcount; - /* - * Found match, so look at next processor ref count - */ - break; - } - } - } - - sync_refcount_calculate (checkpoint); - - LEAVE(); -} - - -static void ckpt_dump_fn (void) -{ - struct list_head *checkpoint_list; - struct checkpoint *checkpoint; - struct list_head *checkpoint_section_list; - struct checkpoint_section *section; - - log_printf (LOG_LEVEL_NOTICE, - "========== Checkpoint Information ==========="); - log_printf (LOG_LEVEL_NOTICE, "global_ckpt_id: %u", global_ckpt_id); - - for (checkpoint_list = checkpoint_list_head.next; - checkpoint_list != &checkpoint_list_head; - checkpoint_list = checkpoint_list->next) { - - checkpoint = list_entry (checkpoint_list, struct checkpoint, list); - - if (checkpoint == NULL) { - return; - } - - log_printf (LOG_LEVEL_NOTICE, "Checkpoint %s (%d):", - checkpoint->name.value, checkpoint->name.length); - log_printf (LOG_LEVEL_NOTICE, " id: %u", checkpoint->ckpt_id); - log_printf (LOG_LEVEL_NOTICE, " sec cnt: %u", checkpoint->section_count); - log_printf (LOG_LEVEL_NOTICE, " ref cnt: %u", checkpoint->reference_count); - log_printf (LOG_LEVEL_NOTICE, " unlinked: %u", checkpoint->unlinked); - - for (checkpoint_section_list = checkpoint->sections_list_head.next; - checkpoint_section_list != &checkpoint->sections_list_head; - checkpoint_section_list = checkpoint_section_list->next) { - - section = list_entry (checkpoint_section_list, - struct checkpoint_section, list); - - log_printf (LOG_LEVEL_NOTICE, " Section %s (%d)", - section->section_descriptor.section_id.id, - section->section_descriptor.section_id.id_len); - log_printf (LOG_LEVEL_NOTICE, " size: %llu", - section->section_descriptor.section_size); - log_printf (LOG_LEVEL_NOTICE, " state: %u", - section->section_descriptor.section_state); - log_printf (LOG_LEVEL_NOTICE, " exp time: %llu", - section->section_descriptor.expiration_time); - } - } -} diff --git a/openais/services/clm.c b/openais/services/clm.c deleted file mode 100644 index 2c2f3c39..00000000 --- a/openais/services/clm.c +++ /dev/null @@ -1,812 +0,0 @@ -/* - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Copyright (c) 2006-2007 Red Hat, Inc. - * Copyright (C) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#if defined(OPENAIS_LINUX) -#include -#elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) -#include -#elif defined(OPENAIS_SOLARIS) -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "../include/saAis.h" -#include "../include/saClm.h" -#include "../include/ipc_clm.h" -#include "../include/mar_clm.h" - -LOGSYS_DECLARE_SUBSYS ("CLM", LOG_INFO); - - -enum clm_message_req_types { - MESSAGE_REQ_EXEC_CLM_NODEJOIN = 0 -}; - -mar_clm_cluster_change_t my_cluster_node_last_change = SA_CLM_NODE_JOINED; - -mar_clm_cluster_node_t my_cluster_node; - -static struct corosync_api_v1 *api; - -static mar_clm_cluster_node_t cluster_node_entries[PROCESSOR_COUNT_MAX]; - -static int cluster_node_count = 0; - -static unsigned long long view_current = 0; - -static unsigned long long view_initial = 0; - -static DECLARE_LIST_INIT (library_notification_send_listhead); - -SaClmClusterNodeT *clm_get_by_nodeid (unsigned int node_id) -{ - static SaClmClusterNodeT cluster_node; - int i; - - if (node_id == SA_CLM_LOCAL_NODE_ID) { - marshall_from_mar_clm_cluster_node_t ( - &cluster_node, - &cluster_node_entries[0]); - return (&cluster_node); - } - for (i = 0; i < cluster_node_count; i++) { - if (cluster_node_entries[i].node_id == node_id) { - marshall_from_mar_clm_cluster_node_t ( - &cluster_node, - &cluster_node_entries[i]); - return (&cluster_node); - break; - } - } - return (NULL); -} - -/* - * Service Interfaces required by service_message_handler struct - */ -static void clm_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id); - -static void clm_sync_init (void); - -static int clm_sync_process (void); - -static void clm_sync_activate (void); - -static void clm_sync_abort (void); - -static int clm_exec_init_fn (struct corosync_api_v1 *corosync_api); - -static int clm_exec_exit_fn (void); - -static int clm_lib_init_fn (void *conn); - -static int clm_lib_exit_fn (void *conn); - -static void message_handler_req_exec_clm_nodejoin ( - void *message, - unsigned int nodeid); - -static void exec_clm_nodejoin_endian_convert (void *msg); - -static void message_handler_req_lib_clm_clustertrack (void *conn, void *message); - -static void message_handler_req_lib_clm_trackstop (void *conn, void *message); - -static void message_handler_req_lib_clm_nodeget (void *conn, void *message); - -static void message_handler_req_lib_clm_nodegetasync (void *conn, void *message); - -struct clm_pd { - unsigned char track_flags; - int tracking_enabled; - struct list_head list; - void *conn; -}; - -/* - * Executive Handler Definition - */ -static struct corosync_lib_handler clm_lib_engine[] = -{ - { /* 0 */ - .lib_handler_fn = message_handler_req_lib_clm_clustertrack, - .response_size = sizeof (struct res_lib_clm_clustertrack), - .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 1 */ - .lib_handler_fn = message_handler_req_lib_clm_trackstop, - .response_size = sizeof (struct res_lib_clm_trackstop), - .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 2 */ - .lib_handler_fn = message_handler_req_lib_clm_nodeget, - .response_size = sizeof (struct res_clm_nodeget), - .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { /* 3 */ - .lib_handler_fn = message_handler_req_lib_clm_nodegetasync, - .response_size = sizeof (struct res_clm_nodegetasync), - .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - } -}; - -static struct corosync_exec_handler clm_exec_engine[] = -{ - { - .exec_handler_fn = message_handler_req_exec_clm_nodejoin, - .exec_endian_convert_fn = exec_clm_nodejoin_endian_convert - } -}; - -struct corosync_service_engine clm_service_engine = { - .name = "openais cluster membership service B.01.01", - .id = CLM_SERVICE, - .private_data_size = sizeof (struct clm_pd), - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED, - .lib_init_fn = clm_lib_init_fn, - .lib_exit_fn = clm_lib_exit_fn, - .lib_engine = clm_lib_engine, - .lib_engine_count = sizeof (clm_lib_engine) / sizeof (struct corosync_lib_handler), - .exec_init_fn = clm_exec_init_fn, - .exec_exit_fn = clm_exec_exit_fn, - .exec_dump_fn = NULL, - .exec_engine = clm_exec_engine, - .exec_engine_count = sizeof (clm_exec_engine) / sizeof (struct corosync_exec_handler), - .confchg_fn = clm_confchg_fn, - .sync_init = clm_sync_init, - .sync_process = clm_sync_process, - .sync_activate = clm_sync_activate, - .sync_abort = clm_sync_abort, -}; - -/* - * Dynamic loader definition - */ -static struct corosync_service_engine *clm_get_service_engine_ver0 (void); - -static struct corosync_service_engine_iface_ver0 clm_service_engine_iface = { - .corosync_get_service_engine_ver0 = clm_get_service_engine_ver0 -}; - -static struct lcr_iface openais_clm_ver0[1] = { - { - .name = "openais_clm", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = NULL - } -}; - -static struct lcr_comp clm_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_clm_ver0 -}; - -static struct corosync_service_engine *clm_get_service_engine_ver0 (void) -{ - return (&clm_service_engine); -} - -__attribute__ ((constructor)) static void clm_comp_register (void) { - lcr_interfaces_set (&openais_clm_ver0[0], &clm_service_engine_iface); - - lcr_component_register (&clm_comp_ver0); -} - -struct req_exec_clm_nodejoin { - mar_req_header_t header __attribute__((aligned(8))); - mar_clm_cluster_node_t cluster_node __attribute__((aligned(8))); -}; - -static void my_cluster_node_load (void) -{ - struct totem_ip_address interfaces[INTERFACE_MAX]; - unsigned int iface_count; - char **status; - const char *iface_string; - - api->totem_ifaces_get ( - api->totem_nodeid_get (), - interfaces, - &status, - &iface_count); - - iface_string = api->totem_ip_print (&interfaces[0]); - - sprintf ((char *)my_cluster_node.node_address.value, "%s", - iface_string); - my_cluster_node.node_address.length = - strlen ((char *)my_cluster_node.node_address.value); - if (api->totem_family_get () == AF_INET) { - my_cluster_node.node_address.family = SA_CLM_AF_INET; - } else - if (api->totem_family_get () == AF_INET6) { - my_cluster_node.node_address.family = SA_CLM_AF_INET6; - } else { - assert (0); - } - - strcpy ((char *)my_cluster_node.node_name.value, - (char *)my_cluster_node.node_address.value); - my_cluster_node.node_name.length = - my_cluster_node.node_address.length; - my_cluster_node.node_id = api->totem_nodeid_get (); - my_cluster_node.member = 1; - - memcpy (&cluster_node_entries[0], &my_cluster_node, - sizeof (mar_clm_cluster_node_t)); -} - -static int clm_exec_init_fn (struct corosync_api_v1 *corosync_api) -{ - api = corosync_api; - - memset (cluster_node_entries, 0, - sizeof (mar_clm_cluster_node_t) * PROCESSOR_COUNT_MAX); - - { -#ifndef NANOSEC -#define NANOSEC 1000000000 -#endif -#if defined(OPENAIS_LINUX) - struct sysinfo s_info; - time_t current_time; - sysinfo (&s_info); - current_time = time (NULL); - /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */ - my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * NANOSEC; -#elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) - int mib[2] = { CTL_KERN, KERN_BOOTTIME }; - struct timeval boot_time; - size_t size = sizeof(boot_time); - - if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 ) - boot_time.tv_sec = time (NULL); - /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */ - my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * NANOSEC; -#elif defined(OPENAIS_SOLARIS) - struct utmpx ut, *utp; - ut.ut_type = BOOT_TIME; - setutxent(); - if ((utp = getutxid(&ut)) == NULL) { - my_cluster_node.boot_timestamp = ((SaTimeT)time(NULL)) * NANOSEC; - } else { - my_cluster_node.boot_timestamp = ((SaTimeT)utp->ut_xtime) * NANOSEC; - } - endutxent(); -#else - #warning "no bootime support" -#endif - } - - cluster_node_count = 1; - -//TODO main_clm_get_by_nodeid = clm_get_by_nodeid; - return (0); -} - -static int clm_exec_exit_fn (void) -{ - return (0); -} - -static int clm_lib_exit_fn (void *conn) -{ - struct clm_pd *clm_pd = (struct clm_pd *)api->ipc_private_data_get (conn); - /* - * Delete track entry if there is one - */ - list_del (&clm_pd->list); - clm_pd->conn = conn; - - return (0); -} - -static void library_notification_send ( - mar_clm_cluster_notification_t *cluster_notification_entries, - int notify_count) -{ - struct res_lib_clm_clustertrack res_lib_clm_clustertrack; - struct clm_pd *clm_pd; - struct list_head *list; - int i; - - if (notify_count == 0) { - return; - } - - res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack); - res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK; - res_lib_clm_clustertrack.header.error = SA_AIS_OK; - res_lib_clm_clustertrack.view = view_current; - - for (list = library_notification_send_listhead.next; - list != &library_notification_send_listhead; - list = list->next) { - - clm_pd = list_entry (list, struct clm_pd, list); - - /* - * Track current and changes - */ - if (clm_pd->track_flags & SA_TRACK_CHANGES) { - /* - * Copy all cluster nodes - */ - for (i = 0; i < cluster_node_count; i++) { - memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node, - &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t)); - res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE; - res_lib_clm_clustertrack.notification[i].cluster_node.member = 1; - } - /* - * Copy change_only notificaiton - */ - res_lib_clm_clustertrack.number_of_items = notify_count + i; - memcpy (&res_lib_clm_clustertrack.notification[i], - cluster_notification_entries, - sizeof (mar_clm_cluster_notification_t) * notify_count); - } else - - /* - * Track only changes - */ - if (clm_pd->track_flags & SA_TRACK_CHANGES_ONLY) { - res_lib_clm_clustertrack.number_of_items = notify_count; - memcpy (&res_lib_clm_clustertrack.notification, - cluster_notification_entries, - sizeof (mar_clm_cluster_notification_t) * notify_count); - } - - /* - * Send notifications to all CLM listeners - */ - api->ipc_conn_send_response ( - clm_pd->conn, - &res_lib_clm_clustertrack, - sizeof (struct res_lib_clm_clustertrack)); - } -} - -static void notification_join (mar_clm_cluster_node_t *cluster_node) -{ - mar_clm_cluster_notification_t notification; - - /* - * Generate notification element - */ - notification.cluster_change = SA_CLM_NODE_JOINED; - notification.cluster_node.member = 1; - memcpy (¬ification.cluster_node, cluster_node, - sizeof (mar_clm_cluster_node_t)); - library_notification_send (¬ification, 1); -} - -static void lib_notification_leave (unsigned int *nodes, int nodes_entries) -{ - mar_clm_cluster_notification_t cluster_notification[PROCESSOR_COUNT_MAX]; - int i, j; - int notify_count; - - /* - * Determine notification list - */ - for (notify_count = 0, i = 0; i < cluster_node_count; i++) { - for (j = 0; j < nodes_entries; j++) { - if (cluster_node_entries[i].node_id == nodes[j]) { - memcpy (&cluster_notification[notify_count].cluster_node, - &cluster_node_entries[i], - sizeof (mar_clm_cluster_node_t)); - cluster_notification[notify_count].cluster_change = SA_CLM_NODE_LEFT; - cluster_notification[notify_count].cluster_node.member = 0; - notify_count += 1; - break; - } - } - } - - /* - * Remove entries from cluster_node_entries array - */ - for (i = 0; i < nodes_entries; i++) { - for (j = 0; j < cluster_node_count;) { - if (nodes[i] == cluster_node_entries[j].node_id) { - cluster_node_count -= 1; - memmove (&cluster_node_entries[j], &cluster_node_entries[j + 1], - (cluster_node_count - j) * sizeof (mar_clm_cluster_node_t)); - } else { - /* - * next cluster_node entry - */ - j++; - } - } - } - - library_notification_send (cluster_notification, notify_count); -} - -static int clm_nodejoin_send (void) -{ - struct req_exec_clm_nodejoin req_exec_clm_nodejoin; - struct iovec req_exec_clm_iovec; - int result; - - req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin); - req_exec_clm_nodejoin.header.id = - SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN); - - my_cluster_node.initial_view_number = view_initial; - - memcpy (&req_exec_clm_nodejoin.cluster_node, &my_cluster_node, - sizeof (mar_clm_cluster_node_t)); - - req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin; - req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin); - - result = api->totem_mcast (&req_exec_clm_iovec, 1, TOTEM_AGREED); - - return (result); -} - -static void clm_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id) -{ - int i; - unsigned int node_ids[PROCESSOR_COUNT_MAX]; - - view_current = ring_id->seq / 4; - if (view_initial == 0) { - view_initial = ring_id->seq / 4; - } - - log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n"); - log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n"); - for (i = 0; i < member_list_entries; i++) { - log_printf (LOG_LEVEL_NOTICE, "\t%s\n", api->totem_ifaces_print (member_list[i])); - } - log_printf (LOG_LEVEL_NOTICE, "Members Left:\n"); - for (i = 0; i < left_list_entries; i++) { - log_printf (LOG_LEVEL_NOTICE, "\t%s\n", api->totem_ifaces_print (left_list[i])); - } - - log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n"); - for (i = 0; i < joined_list_entries; i++) { - log_printf (LOG_LEVEL_NOTICE, "\t%s\n", api->totem_ifaces_print (joined_list[i])); - } - - for (i = 0; i < left_list_entries; i++) { - node_ids[i] = left_list[i]; - } - - lib_notification_leave (node_ids, i); - - /* - * Load the my_cluster_node data structure in case we are - * transitioning to network interface up or down - */ - my_cluster_node_load (); -} - -/* - * This is a noop for this service - */ -static void clm_sync_init (void) -{ - return; -} - -/* - * If a processor joined in the configuration change and clm_sync_activate hasn't - * yet been called, issue a node join to share CLM specific data about the processor - */ -static int clm_sync_process (void) -{ - /* - * Send node information to other nodes - */ - return (clm_nodejoin_send ()); -} - -/* - * This is a noop for this service - */ -static void clm_sync_activate (void) -{ - return; -} - -/* - * This is a noop for this service - */ -static void clm_sync_abort (void) -{ - return; -} - - -static void exec_clm_nodejoin_endian_convert (void *msg) -{ - struct req_exec_clm_nodejoin *node_join = msg; - - swab_mar_req_header_t (&node_join->header); - swab_mar_clm_cluster_node_t (&node_join->cluster_node); -} - -static void message_handler_req_exec_clm_nodejoin ( - void *message, - unsigned int nodeid) -{ - struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message; - int found = 0; - int i; - - log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", - req_exec_clm_nodejoin->cluster_node.node_name.value); - - /* - * Determine if nodejoin already received - */ - for (found = 0, i = 0; i < cluster_node_count; i++) { - if (cluster_node_entries[i].node_id == req_exec_clm_nodejoin->cluster_node.node_id) { - found = 1; - } - } - - /* - * If not received, add to internal list - */ - if (found == 0) { - notification_join (&req_exec_clm_nodejoin->cluster_node); - memcpy (&cluster_node_entries[cluster_node_count], - &req_exec_clm_nodejoin->cluster_node, - sizeof (mar_clm_cluster_node_t)); - - cluster_node_count += 1; - } -} - -static int clm_lib_init_fn (void *conn) -{ - log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n"); - struct clm_pd *clm_pd = (struct clm_pd *)api->ipc_private_data_get (conn); - - list_init (&clm_pd->list); - clm_pd->conn = conn; - - return (0); -} - -static void message_handler_req_lib_clm_clustertrack (void *conn, void *msg) -{ - struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)msg; - struct res_lib_clm_clustertrack res_lib_clm_clustertrack; - struct clm_pd *clm_pd = (struct clm_pd *)api->ipc_private_data_get (conn); - int i; - - res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack); - res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART; - res_lib_clm_clustertrack.header.error = SA_AIS_OK; - res_lib_clm_clustertrack.view = view_current; - res_lib_clm_clustertrack.number_of_items = 0; - - /* - * If an immediate listing of the current cluster membership - * is requested, generate membership list - */ - if (req_lib_clm_clustertrack->track_flags & SA_TRACK_CURRENT || - req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES) { - for (i = 0; i < cluster_node_count; i++) { - res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE; - - memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node, - &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t)); - } - res_lib_clm_clustertrack.number_of_items = cluster_node_count; - } - - /* - * Record requests for cluster tracking - */ - if (req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES || - req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES_ONLY) { - - clm_pd->track_flags = req_lib_clm_clustertrack->track_flags; - clm_pd->tracking_enabled = 1; - - list_add (&clm_pd->list, &library_notification_send_listhead); - } - - api->ipc_conn_send_response (conn, &res_lib_clm_clustertrack, - sizeof (struct res_lib_clm_clustertrack)); - - if (req_lib_clm_clustertrack->return_in_callback) { - res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK; - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (conn), - &res_lib_clm_clustertrack, - sizeof (struct res_lib_clm_clustertrack)); - } -} - - -static void message_handler_req_lib_clm_trackstop (void *conn, void *msg) -{ - struct res_lib_clm_trackstop res_lib_clm_trackstop; - struct clm_pd *clm_pd = (struct clm_pd *)api->ipc_private_data_get (conn); - - res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop); - res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP; - - if (clm_pd->tracking_enabled) { - res_lib_clm_trackstop.header.error = SA_AIS_OK; - clm_pd->tracking_enabled = 0; - } else { - res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST; - } - - list_del (&clm_pd->list); - list_init (&clm_pd->list); - - api->ipc_conn_send_response (conn, &res_lib_clm_trackstop, - sizeof (struct res_lib_clm_trackstop)); -} - -static void message_handler_req_lib_clm_nodeget (void *conn, void *msg) -{ - struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)msg; - struct res_clm_nodeget res_clm_nodeget; - mar_clm_cluster_node_t *cluster_node = 0; - int valid = 0; - int i; - - log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n", - (int)req_lib_clm_nodeget->node_id); - - if (req_lib_clm_nodeget->node_id == SA_CLM_LOCAL_NODE_ID) { - cluster_node = &cluster_node_entries[0]; - valid = 1; - } else - for (i = 0; i < cluster_node_count; i++) { - if (cluster_node_entries[i].node_id == req_lib_clm_nodeget->node_id) { - log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n"); - cluster_node = &cluster_node_entries[i]; - valid = 1; - break; - } - } - - res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget); - res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET; - res_clm_nodeget.header.error = SA_AIS_OK; - res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation; - res_clm_nodeget.valid = valid; - if (valid) { - memcpy (&res_clm_nodeget.cluster_node, cluster_node, sizeof (mar_clm_cluster_node_t)); - } - api->ipc_conn_send_response (conn, &res_clm_nodeget, sizeof (struct res_clm_nodeget)); -} - -static void message_handler_req_lib_clm_nodegetasync (void *conn, void *msg) -{ - struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)msg; - struct res_clm_nodegetasync res_clm_nodegetasync; - struct res_clm_nodegetcallback res_clm_nodegetcallback; - mar_clm_cluster_node_t *cluster_node = 0; - int error = SA_AIS_ERR_INVALID_PARAM; - int i; - - log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", - (int)req_lib_clm_nodegetasync->node_id); - - if (req_lib_clm_nodegetasync->node_id == SA_CLM_LOCAL_NODE_ID) { - cluster_node = &cluster_node_entries[0]; - error = SA_AIS_OK; - } else - for (i = 0; i < cluster_node_count; i++) { - if (cluster_node_entries[i].node_id == req_lib_clm_nodegetasync->node_id) { - log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n"); - cluster_node = &cluster_node_entries[i]; - error = SA_AIS_OK; - break; - } - } - - /* - * Respond to library request - */ - res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync); - res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC; - res_clm_nodegetasync.header.error = SA_AIS_OK; - - api->ipc_conn_send_response (conn, &res_clm_nodegetasync, - sizeof (struct res_clm_nodegetasync)); - - /* - * Send async response - */ - res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback); - res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK; - res_clm_nodegetcallback.header.error = error; - res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation; - if (error == SA_AIS_OK) { - memcpy (&res_clm_nodegetcallback.cluster_node, cluster_node, - sizeof (mar_clm_cluster_node_t)); - } - api->ipc_conn_send_response (api->ipc_conn_partner_get (conn), - &res_clm_nodegetcallback, - sizeof (struct res_clm_nodegetcallback)); -} diff --git a/openais/services/evt.c b/openais/services/evt.c deleted file mode 100644 index ffac3b75..00000000 --- a/openais/services/evt.c +++ /dev/null @@ -1,4369 +0,0 @@ -/* - * Copyright (c) 2004-2006 Mark Haverkamp - * Copyright (c) 2004-2006 Open Source Development Lab - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the Open Source Development Lab nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define DUMP_CHAN_INFO -#define RECOVERY_EVENT_DEBUG LOG_LEVEL_DEBUG -#define RECOVERY_DEBUG LOG_LEVEL_DEBUG -#define CHAN_DEL_DEBUG LOG_LEVEL_DEBUG -#define CHAN_OPEN_DEBUG LOG_LEVEL_DEBUG -#define CHAN_UNLINK_DEBUG LOG_LEVEL_DEBUG -#define REMOTE_OP_DEBUG LOG_LEVEL_DEBUG -#define RETENTION_TIME_DEBUG LOG_LEVEL_DEBUG - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../include/saAis.h" -#include "../include/saEvt.h" -#include "../include/ipc_evt.h" - -LOGSYS_DECLARE_SUBSYS ("EVT", LOG_INFO); -/* - * event instance structure. Contains information about the - * active connection to the API library. - * - * esi_version: Version that the library is running. - * esi_open_chans: list of open channels associated with this - * instance. Used to clean up any data left - * allocated when the finalize is done. - * (event_svr_channel_open.eco_instance_entry) - * esi_events: list of pending events to be delivered on this - * instance (struct chan_event_list.cel_entry) - * esi_queue_blocked: non-zero if the delivery queue got too full - * and we're blocking new messages until we - * drain some of the queued messages. - * esi_nevents: Number of events in events lists to be sent. - * esi_hdb: Handle data base for open channels on this - * instance. Used for a quick lookup of - * open channel data from a lib api message. - */ -struct libevt_pd { - SaVersionT esi_version; - struct list_head esi_open_chans; - struct list_head esi_events[SA_EVT_LOWEST_PRIORITY+1]; - int esi_nevents; - int esi_queue_blocked; - struct hdb_handle_database esi_hdb; -}; - - -enum evt_message_req_types { - MESSAGE_REQ_EXEC_EVT_EVENTDATA = 0, - MESSAGE_REQ_EXEC_EVT_CHANCMD = 1, - MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA = 2 -}; - -static void lib_evt_open_channel(void *conn, void *message); -static void lib_evt_open_channel_async(void *conn, void *message); -static void lib_evt_close_channel(void *conn, void *message); -static void lib_evt_unlink_channel(void *conn, void *message); -static void lib_evt_event_subscribe(void *conn, void *message); -static void lib_evt_event_unsubscribe(void *conn, void *message); -static void lib_evt_event_publish(void *conn, void *message); -static void lib_evt_event_clear_retentiontime(void *conn, void *message); -static void lib_evt_event_data_get(void *conn, void *message); - -static void evt_conf_change( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id); - -static int evt_lib_init(void *conn); -static int evt_lib_exit(void *conn); -static int evt_exec_init(struct corosync_api_v1 *); - -/* - * Recovery sync functions - */ -static void evt_sync_init(void); -static int evt_sync_process(void); -static void evt_sync_activate(void); -static void evt_sync_abort(void); - -static void convert_event(void *msg); -static void convert_chan_packet(void *msg); - -struct corosync_api_v1 *api; - -static struct corosync_lib_handler evt_lib_engine[] = { - { - .lib_handler_fn = lib_evt_open_channel, - .response_size = sizeof(struct res_evt_channel_open), - .response_id = MESSAGE_RES_EVT_OPEN_CHANNEL, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { - .lib_handler_fn = lib_evt_open_channel_async, - .response_size = sizeof(struct res_evt_channel_open), - .response_id = MESSAGE_RES_EVT_OPEN_CHANNEL, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { - .lib_handler_fn = lib_evt_close_channel, - .response_size = sizeof(struct res_evt_channel_close), - .response_id = MESSAGE_RES_EVT_CLOSE_CHANNEL, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { - .lib_handler_fn = lib_evt_unlink_channel, - .response_size = sizeof(struct res_evt_channel_unlink), - .response_id = MESSAGE_RES_EVT_UNLINK_CHANNEL, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { - .lib_handler_fn = lib_evt_event_subscribe, - .response_size = sizeof(struct res_evt_event_subscribe), - .response_id = MESSAGE_RES_EVT_SUBSCRIBE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { - .lib_handler_fn = lib_evt_event_unsubscribe, - .response_size = sizeof(struct res_evt_event_unsubscribe), - .response_id = MESSAGE_RES_EVT_UNSUBSCRIBE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, - { - .lib_handler_fn = lib_evt_event_publish, - .response_size = sizeof(struct res_evt_event_publish), - .response_id = MESSAGE_RES_EVT_PUBLISH, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { - .lib_handler_fn = lib_evt_event_clear_retentiontime, - .response_size = sizeof(struct res_evt_event_clear_retentiontime), - .response_id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { - .lib_handler_fn = lib_evt_event_data_get, - .response_size = sizeof(struct lib_event_data), - .response_id = MESSAGE_RES_EVT_EVENT_DATA, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED - }, -}; - - -static void evt_remote_evt(void *msg, unsigned int nodeid); -static void evt_remote_recovery_evt(void *msg, unsigned int nodeid); -static void evt_remote_chan_op(void *msg, unsigned int nodeid); - -static struct corosync_exec_handler evt_exec_engine[] = { - { - .exec_handler_fn = evt_remote_evt, - .exec_endian_convert_fn = convert_event - }, - { - .exec_handler_fn = evt_remote_chan_op, - .exec_endian_convert_fn = convert_chan_packet - }, - { - .exec_handler_fn = evt_remote_recovery_evt, - .exec_endian_convert_fn = convert_event - } -}; - -struct corosync_service_engine evt_service_engine = { - .name = "openais event service B.01.01", - .id = EVT_SERVICE, - .private_data_size = sizeof (struct libevt_pd), - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED, - .lib_init_fn = evt_lib_init, - .lib_exit_fn = evt_lib_exit, - .lib_engine = evt_lib_engine, - .lib_engine_count = sizeof(evt_lib_engine) / sizeof(struct corosync_lib_handler), - .exec_init_fn = evt_exec_init, - .exec_engine = evt_exec_engine, - .exec_engine_count = sizeof(evt_exec_engine) / sizeof(struct corosync_exec_handler), - .exec_dump_fn = NULL, - .confchg_fn = evt_conf_change, - .sync_init = evt_sync_init, - .sync_process = evt_sync_process, - .sync_activate = evt_sync_activate, - .sync_abort = evt_sync_abort -}; - -static struct corosync_service_engine *evt_get_engine_ver0(void); - -static struct corosync_service_engine_iface_ver0 evt_service_engine_iface = { - .corosync_get_service_engine_ver0 = evt_get_engine_ver0 -}; - -static struct lcr_iface openais_evt_ver0[1] = { - { - .name = "openais_evt", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = NULL, - } -}; - -static struct lcr_comp evt_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_evt_ver0 -}; - -static struct corosync_service_engine *evt_get_engine_ver0(void) -{ - return (&evt_service_engine); -} - -__attribute__ ((constructor)) static void evt_comp_register (void) { - lcr_interfaces_set (&openais_evt_ver0[0], &evt_service_engine_iface); - - lcr_component_register (&evt_comp_ver0); -} - -/* - * MESSAGE_REQ_EXEC_EVT_CHANCMD - * - * Used for various event related operations. - * - */ -enum evt_chan_ops { - EVT_OPEN_CHAN_OP, /* chc_chan */ - EVT_CLOSE_CHAN_OP, /* chc_close_unlink_chan */ - EVT_UNLINK_CHAN_OP, /* chc_close_unlink_chan */ - EVT_CLEAR_RET_OP, /* chc_event_id */ - EVT_SET_ID_OP, /* chc_set_id */ - EVT_CONF_DONE, /* no data used */ - EVT_OPEN_COUNT, /* chc_set_opens */ - EVT_OPEN_COUNT_DONE /* no data used */ -}; - -/* - * Used during recovery to set the next issued event ID - * based on the highest ID seen by any of the members - */ -struct evt_set_id { - mar_uint32_t chc_nodeid __attribute__((aligned(8))); - mar_uint64_t chc_last_id __attribute__((aligned(8))); -}; - -/* - * For set open count used during recovery to syncronize all nodes - * - * chc_chan_name: Channel name. - * chc_open_count: number of local opens of this channel. - */ -struct evt_set_opens { - mar_name_t chc_chan_name __attribute__((aligned(8))); - mar_uint32_t chc_open_count __attribute__((aligned(8))); -}; - -/* - * Used to communicate channel to close or unlink. - */ -#define EVT_CHAN_ACTIVE 0 -struct evt_close_unlink_chan { - mar_name_t chcu_name __attribute__((aligned(8))); - mar_uint64_t chcu_unlink_id __attribute__((aligned(8))); -}; - -struct open_chan_req { - mar_name_t ocr_name __attribute__((aligned(8))); - mar_uint64_t ocr_serial_no __attribute__((aligned(8))); -}; - -/* - * Sent via MESSAGE_REQ_EXEC_EVT_CHANCMD - * - * chc_head: Request head - * chc_op: Channel operation (open, close, clear retentiontime) - * u: union of operation options. - */ -struct req_evt_chan_command { - mar_req_header_t chc_head __attribute__((aligned(8))); - mar_uint32_t chc_op __attribute__((aligned(8))); - union { - struct open_chan_req chc_chan __attribute__((aligned(8))); - mar_evteventid_t chc_event_id __attribute__((aligned(8))); - struct evt_set_id chc_set_id __attribute__((aligned(8))); - struct evt_set_opens chc_set_opens __attribute__((aligned(8))); - struct evt_close_unlink_chan chcu __attribute__((aligned(8))); - } u; -}; - -/* - * list of all retained events - * struct event_data - */ -static DECLARE_LIST_INIT(retained_list); - -/* - * list of all event channel information - * struct event_svr_channel_instance - */ -static DECLARE_LIST_INIT(esc_head); - -/* - * list of all unlinked event channel information - * struct event_svr_channel_instance - */ -static DECLARE_LIST_INIT(esc_unlinked_head); - -/* - * Track the state of event service recovery. - * - * evt_recovery_complete: Normal operational mode - * - * evt_send_event_id: Node is sending known last - * event IDs. - * - * evt_send_open_count: Node is sending its open - * Channel information. - * - * evt_wait_open_count_done: Node is done sending open channel data and - * is waiting for the other nodes to finish. - * - * evt_send_retained_events: Node is sending retained event data. - * - * evt_send_retained_events_done: Node is sending done message. - * - * evt_wait_send_retained_events: Node is waiting for other nodes to - * finish sending retained event data. - */ -enum recovery_phases { - evt_recovery_complete, - evt_send_event_id, - evt_send_open_count, - evt_wait_open_count_done, - evt_send_retained_events, - evt_send_retained_events_done, - evt_wait_send_retained_events -}; - -/* - * Global varaibles used by the event service - * - * base_id_top: upper bits of next event ID to assign - * base_id: Lower bits of Next event ID to assign - * my_node_id: My cluster node id - * checked_in: keep track during config change. - * recovery_node: True if we're the recovery node. i.e. the - * node that sends the retained events. - * next_retained: pointer to next retained message to send - * during recovery. - * next_chan: pointer to next channel to send during recovery. - * recovery_phase: Indicates what recovery is taking place. - * left_member_count: How many left this configuration. - * left_member_list: Members that left this config - * joined_member_count: How many joined this configuration. - * joined_member_list: Members that joined this config - * total_member_count: how many members in this cluster - * current_member_list: Total membership this config - * trans_member_count: Node count in transitional membership - * trans_member_list: Total membership from the transitional membership - * add_count: count of joined members used for sending event id - * recovery data. - * add_list: pointer to joined list used for sending event id - * recovery data. - * processed_open_counts: Flag used to coordinate clearing open - * channel counts for config change recovery. - * - */ - -#define BASE_ID_MASK 0xffffffffLL -static mar_evteventid_t base_id = 1; -static mar_evteventid_t base_id_top = 0; -static mar_uint32_t my_node_id = 0; -static int checked_in = 0; -static int recovery_node = 0; -static struct list_head *next_retained = 0; -static struct list_head *next_chan = 0; -static enum recovery_phases recovery_phase = evt_recovery_complete; -static int left_member_count = 0; -static unsigned int *left_member_list = 0; -static int joined_member_count = 0; -static unsigned int *joined_member_list = 0; -static int total_member_count = 0; -static unsigned int *current_member_list = 0; -static int trans_member_count = 0; -static unsigned int *trans_member_list = 0; -static int add_count = 0; -static unsigned int *add_list = 0; -static int processed_open_counts = 0; - -/* - * Structure to track pending channel open requests. - * ocp_async: 1 for async open - * ocp_invocation: invocation for async open - * ocp_chan_name: requested channel - * ocp_conn: conn for returning to the library. - * ocp_open_flags: channel open flags - * ocp_timer_handle: timer handle for sync open - * ocp_serial_no: Identifier for the request - * ocp_entry: list entry for pending open list. - */ -struct open_chan_pending { - int ocp_async; - mar_invocation_t ocp_invocation; - mar_name_t ocp_chan_name; - void *ocp_conn; - mar_evtchannelopenflags_t ocp_open_flag; - corosync_timer_handle_t ocp_timer_handle; - uint64_t ocp_c_handle; - uint64_t ocp_serial_no; - struct list_head ocp_entry; -}; -static uint64_t open_serial_no = 0; - -/* - * code to indicate that the open request has timed out. The - * invocation data element is used for this code since it is - * only used by the open async call which cannot have a timeout. - */ -#define OPEN_TIMED_OUT 0x5a6b5a6b5a6b5a6bLLU - -/* - * list of pending channel opens - */ -static DECLARE_LIST_INIT(open_pending); -static void chan_open_timeout(void *data); - -/* - * Structure to track pending channel unlink requests. - * ucp_unlink_id: unlink ID of unlinked channel. - * ucp_conn: conn for returning to the library. - * ucp_entry: list entry for pending unlink list. - */ -struct unlink_chan_pending { - uint64_t ucp_unlink_id; - void *ucp_conn; - struct list_head ucp_entry; -}; - -/* - * list of pending unlink requests - */ -static DECLARE_LIST_INIT(unlink_pending); - -/* - * Structure to track pending retention time clear requests. - * rtc_event_id: event ID to clear. - * rtc_conn: conn for returning to the library. - * rtc_entry: list entry for pending clear list. - */ -struct retention_time_clear_pending { - mar_evteventid_t rtc_event_id; - void *rtc_conn; - struct list_head rtc_entry; -}; - -/* - * list of pending clear requests. - */ -static DECLARE_LIST_INIT(clear_pending); - -/* - * Next unlink ID - */ -static uint64_t base_unlink_id = 0; -inline uint64_t -next_chan_unlink_id() -{ - uint64_t uid = my_node_id; - uid = (uid << 32ULL) | base_unlink_id; - base_unlink_id = (base_unlink_id + 1ULL) & BASE_ID_MASK; - return uid; -} - -#define min(a,b) ((a) < (b) ? (a) : (b)) - -/* - * Throttle event delivery to applications to keep - * the exec from using too much memory if the app is - * slow to process its events. - */ -#define MAX_EVT_DELIVERY_QUEUE 1000 -#define MIN_EVT_QUEUE_RESUME (MAX_EVT_DELIVERY_QUEUE / 2) - -static unsigned int evt_delivery_queue_size = MAX_EVT_DELIVERY_QUEUE; -static unsigned int evt_delivery_queue_resume = MIN_EVT_QUEUE_RESUME; - - -#define LOST_PUB "EVENT_SERIVCE" -#define LOST_CHAN "LOST EVENT" -/* - * Event to send when the delivery queue gets too full - */ -char lost_evt[] = SA_EVT_LOST_EVENT; -static int dropped_event_size; -static struct event_data *dropped_event; -struct evt_pattern { - mar_evt_event_pattern_t pat; - char str[sizeof(lost_evt)]; -}; -static struct evt_pattern dropped_pattern = { - .pat = { - sizeof(lost_evt), - sizeof(lost_evt), - (SaUint8T *) &dropped_pattern.str[0]}, - .str = {SA_EVT_LOST_EVENT} -}; - -mar_name_t lost_chan = { - .value = LOST_CHAN, - .length = sizeof(LOST_CHAN) -}; - -mar_name_t dropped_publisher = { - .value = LOST_PUB, - .length = sizeof(LOST_PUB) -}; - -struct event_svr_channel_open; -struct event_svr_channel_subscr; - -struct open_count { - mar_uint32_t oc_node_id; - int32_t oc_open_count; -}; - -/* - * Structure to contain global channel releated information - * - * esc_channel_name: The name of this channel. - * esc_total_opens: The total number of opens on this channel including - * other nodes. - * esc_local_opens: The number of opens on this channel for this node. - * esc_oc_size: The total number of entries in esc_node_opens; - * esc_node_opens: list of node IDs and how many opens are associated. - * esc_retained_count: How many retained events for this channel - * esc_open_chans: list of opens of this channel. - * (event_svr_channel_open.eco_entry) - * esc_entry: links to other channels. (used by esc_head) - * esc_unlink_id: If non-zero, then the channel has been marked - * for unlink. This unlink ID is used to - * mark events still associated with current openings - * so they get delivered to the proper recipients. - */ -struct event_svr_channel_instance { - mar_name_t esc_channel_name; - int32_t esc_total_opens; - int32_t esc_local_opens; - uint32_t esc_oc_size; - struct open_count *esc_node_opens; - uint32_t esc_retained_count; - struct list_head esc_open_chans; - struct list_head esc_entry; - uint64_t esc_unlink_id; -}; - -/* - * Has the event data in the correct format to send to the library API - * with aditional field for accounting. - * - * ed_ref_count: how many other strutures are referencing. - * ed_retained: retained event list. - * ed_timer_handle: Timer handle for retained event expiration. - * ed_delivered: arrays of open channel pointers that this event - * has been delivered to. (only used for events - * with a retention time). - * ed_delivered_count: Number of entries available in ed_delivered. - * ed_delivered_next: Next free spot in ed_delivered - * ed_my_chan: pointer to the global channel instance associated - * with this event. - * ed_event: The event data formatted to be ready to send. - */ -struct event_data { - uint32_t ed_ref_count; - struct list_head ed_retained; - corosync_timer_handle_t ed_timer_handle; - struct event_svr_channel_open **ed_delivered; - uint32_t ed_delivered_count; - uint32_t ed_delivered_next; - struct event_svr_channel_instance *ed_my_chan; - struct lib_event_data ed_event; -}; - -/* - * Contains a list of pending events to be delivered to a subscribed - * application. - * - * cel_chan_handle: associated library channel handle - * cel_sub_id: associated library subscription ID - * cel_event: event structure to deliver. - * cel_entry: list of pending events - * (struct event_server_instance.esi_events) - */ -struct chan_event_list { - uint64_t cel_chan_handle; - uint32_t cel_sub_id; - struct event_data* cel_event; - struct list_head cel_entry; -}; - -/* - * Contains information about each open for a given channel - * - * eco_flags: How the channel was opened. - * eco_lib_handle: channel handle in the app. Used for event delivery. - * eco_my_handle: the handle used to access this data structure. - * eco_channel: Pointer to global channel info. - * eco_entry: links to other opeinings of this channel. - * eco_instance_entry: links to other channel opeinings for the - * associated server instance. - * eco_subscr: head of list of sbuscriptions for this channel open. - * (event_svr_channel_subscr.ecs_entry) - * eco_conn: refrence to EvtInitialize who owns this open. - */ -struct event_svr_channel_open { - uint8_t eco_flags; - uint64_t eco_lib_handle; - uint32_t eco_my_handle; - struct event_svr_channel_instance *eco_channel; - struct list_head eco_entry; - struct list_head eco_instance_entry; - struct list_head eco_subscr; - void *eco_conn; -}; - -/* - * Contains information about each channel subscription - * - * ecs_open_chan: Link to our open channel. - * ecs_sub_id: Subscription ID. - * ecs_filter_count: number of filters in ecs_filters - * ecs_filters: filters for determining event delivery. - * ecs_entry: Links to other subscriptions to this channel opening. - */ -struct event_svr_channel_subscr { - struct event_svr_channel_open *ecs_open_chan; - uint32_t ecs_sub_id; - mar_evt_event_filter_array_t *ecs_filters; - struct list_head ecs_entry; -}; - - -/* - * Member node data - * mn_node_info: cluster node info from membership - * mn_last_msg_id: last seen message ID for this node - * mn_started: Indicates that event service has started - * on this node. - * mn_next: pointer to the next node in the hash chain. - * mn_entry: List of all nodes. - */ -struct member_node_data { - unsigned int mn_nodeid; - SaClmClusterNodeT mn_node_info; - mar_evteventid_t mn_last_msg_id; - mar_uint32_t mn_started; - struct member_node_data *mn_next; - struct list_head mn_entry; -}; -DECLARE_LIST_INIT(mnd); -/* - * Take the filters we received from the application via the library and - * make them into a real mar_evt_event_filter_array_t - */ -static SaAisErrorT evtfilt_to_aisfilt(struct req_evt_event_subscribe *req, - mar_evt_event_filter_array_t **evtfilters) -{ - - mar_evt_event_filter_array_t *filta = - (mar_evt_event_filter_array_t *)req->ics_filter_data; - mar_evt_event_filter_array_t *filters; - mar_evt_event_filter_t *filt = (void *)filta + sizeof(mar_evt_event_filter_array_t); - SaUint8T *str = (void *)filta + sizeof(mar_evt_event_filter_array_t) + - (sizeof(mar_evt_event_filter_t) * filta->filters_number); - int i; - int j; - - filters = malloc(sizeof(mar_evt_event_filter_array_t)); - if (!filters) { - return SA_AIS_ERR_NO_MEMORY; - } - - filters->filters_number = filta->filters_number; - filters->filters = malloc(sizeof(mar_evt_event_filter_t) * - filta->filters_number); - if (!filters->filters) { - free(filters); - return SA_AIS_ERR_NO_MEMORY; - } - - for (i = 0; i < filters->filters_number; i++) { - filters->filters[i].filter.pattern = - malloc(filt[i].filter.pattern_size); - - if (!filters->filters[i].filter.pattern) { - for (j = 0; j < i; j++) { - free(filters->filters[j].filter.pattern); - } - free(filters->filters); - free(filters); - return SA_AIS_ERR_NO_MEMORY; - } - filters->filters[i].filter.pattern_size = - filt[i].filter.pattern_size; - filters->filters[i].filter.allocated_size = - filt[i].filter.pattern_size; - memcpy(filters->filters[i].filter.pattern, - str, filters->filters[i].filter.pattern_size); - filters->filters[i].filter_type = filt[i].filter_type; - str += filters->filters[i].filter.pattern_size; - } - - *evtfilters = filters; - - return SA_AIS_OK; -} - -SaTimeT clust_time_now(void) -{ - struct timeval tv; - SaTimeT time_now; - - if (gettimeofday(&tv, 0)) { - return 0ULL; - } - - time_now = (SaTimeT)(tv.tv_sec) * 1000000000ULL; - time_now += (SaTimeT)(tv.tv_usec) * 1000ULL; - - return time_now; -} - -static void free_filters(mar_evt_event_filter_array_t *fp) -{ - int i; - - for (i = 0; i < fp->filters_number; i++) { - free(fp->filters[i].filter.pattern); - } - - free(fp->filters); - free(fp); -} - -/* - * Look up a channel in the global channel list - */ -static struct event_svr_channel_instance * -find_channel(mar_name_t *chan_name, uint64_t unlink_id) -{ - struct list_head *l, *head; - struct event_svr_channel_instance *eci; - - /* - * choose which list to look through - */ - if (unlink_id == EVT_CHAN_ACTIVE) { - head = &esc_head; - } else { - head = &esc_unlinked_head; - } - - for (l = head->next; l != head; l = l->next) { - - eci = list_entry(l, struct event_svr_channel_instance, esc_entry); - if (!mar_name_match(chan_name, &eci->esc_channel_name)) { - continue; - } else if (unlink_id != eci->esc_unlink_id) { - continue; - } - return eci; - } - return 0; -} - -/* - * Find the last unlinked version of a channel. - */ -static struct event_svr_channel_instance * -find_last_unlinked_channel(mar_name_t *chan_name) -{ - struct list_head *l; - struct event_svr_channel_instance *eci; - - /* - * unlinked channels are added to the head of the list - * so the first one we see is the last one added. - */ - for (l = esc_unlinked_head.next; l != &esc_unlinked_head; l = l->next) { - - eci = list_entry(l, struct event_svr_channel_instance, esc_entry); - if (!mar_name_match(chan_name, &eci->esc_channel_name)) { - continue; - } - } - return 0; -} - -/* - * Create and initialize a channel instance structure - */ -static struct event_svr_channel_instance *create_channel(mar_name_t *cn) -{ - struct event_svr_channel_instance *eci; - eci = (struct event_svr_channel_instance *) malloc(sizeof(*eci)); - if (!eci) { - return (eci); - } - - memset(eci, 0, sizeof(*eci)); - list_init(&eci->esc_entry); - list_init(&eci->esc_open_chans); - eci->esc_oc_size = total_member_count; - eci->esc_node_opens = - malloc(sizeof(struct open_count) * total_member_count); - if (!eci->esc_node_opens) { - free(eci); - return 0; - } - memset(eci->esc_node_opens, 0, - sizeof(struct open_count) * total_member_count); - eci->esc_channel_name = *cn; - eci->esc_channel_name.value[eci->esc_channel_name.length] = '\0'; - list_add(&eci->esc_entry, &esc_head); - - return eci; -} - - -/* - * Make sure that the list of nodes is large enough to hold the whole - * membership - */ -static int check_open_size(struct event_svr_channel_instance *eci) -{ - struct open_count *esc_node_opens_tmp; - - if (total_member_count > eci->esc_oc_size) { - esc_node_opens_tmp = realloc (eci->esc_node_opens, - sizeof(struct open_count) * total_member_count); - if (esc_node_opens_tmp == NULL) { - log_printf(LOG_LEVEL_WARNING, - "Memory error realloc of node list\n"); - return -1; - } - eci->esc_node_opens = esc_node_opens_tmp; - memset(&eci->esc_node_opens[eci->esc_oc_size], 0, - sizeof(struct open_count) * - (total_member_count - eci->esc_oc_size)); - eci->esc_oc_size = total_member_count; - } - return 0; -} - -/* - * Find the specified node ID in the node list of the channel. - * If it's not in the list, add it. - */ -static struct open_count* find_open_count( - struct event_svr_channel_instance *eci, - mar_uint32_t node_id) -{ - int i; - - for (i = 0; i < eci->esc_oc_size; i++) { - if (eci->esc_node_opens[i].oc_node_id == 0) { - eci->esc_node_opens[i].oc_node_id = node_id; - eci->esc_node_opens[i].oc_open_count = 0; - } - if (eci->esc_node_opens[i].oc_node_id == node_id) { - return &eci->esc_node_opens[i]; - } - } - log_printf(LOG_LEVEL_DEBUG, - "find_open_count: node id %s not found\n", - api->totem_ifaces_print (node_id)); - return 0; -} - -static void dump_chan_opens(struct event_svr_channel_instance *eci) -{ - int i; - log_printf(LOG_LEVEL_NOTICE, - "Channel %s, total %d, local %d\n", - eci->esc_channel_name.value, - eci->esc_total_opens, - eci->esc_local_opens); - for (i = 0; i < eci->esc_oc_size; i++) { - if (eci->esc_node_opens[i].oc_node_id == 0) { - break; - } - log_printf(LOG_LEVEL_NOTICE, "Node %s, count %d\n", - api->totem_ifaces_print (eci->esc_node_opens[i].oc_node_id), - eci->esc_node_opens[i].oc_open_count); - } -} - -#ifdef DUMP_CHAN_INFO -/* - * Scan the list of channels and dump the open count info. - */ -static void dump_all_chans() -{ - struct list_head *l; - struct event_svr_channel_instance *eci; - - for (l = esc_head.next; l != &esc_head; l = l->next) { - eci = list_entry(l, struct event_svr_channel_instance, esc_entry); - dump_chan_opens(eci); - - } -} -#endif - -/* - * Scan the list of channels and zero out the open counts - */ -static void zero_chan_open_counts() -{ - struct list_head *l; - struct event_svr_channel_instance *eci; - int i; - - for (l = esc_head.next; l != &esc_head; l = l->next) { - eci = list_entry(l, struct event_svr_channel_instance, esc_entry); - for (i = 0; i < eci->esc_oc_size; i++) { - if (eci->esc_node_opens[i].oc_node_id == 0) { - break; - } - eci->esc_node_opens[i].oc_open_count = 0; - } - eci->esc_total_opens = 0; - } -} -/* - * Replace the current open count for a node with the specified value. - */ -static int set_open_count(struct event_svr_channel_instance *eci, - mar_uint32_t node_id, uint32_t open_count) -{ - struct open_count *oc; - int i; - - if ((i = check_open_size(eci)) != 0) { - return i; - } - - oc = find_open_count(eci, node_id); - if (oc) { - log_printf(RECOVERY_DEBUG, - "Set count: Chan %s for node %s, was %d, now %d\n", - eci->esc_channel_name.value, api->totem_ifaces_print (node_id), - oc->oc_open_count, open_count); - - eci->esc_total_opens -= oc->oc_open_count; - eci->esc_total_opens += open_count; - oc->oc_open_count = open_count; - return 0; - } - return -1; -} - -/* - * Increment the open count for the specified node. - */ -static int inc_open_count(struct event_svr_channel_instance *eci, - mar_uint32_t node_id) -{ - - struct open_count *oc; - int i; - - if ((i = check_open_size(eci)) != 0) { - return i; - } - - if (node_id == my_node_id) { - eci->esc_local_opens++; - } - oc = find_open_count(eci, node_id); - if (oc) { - eci->esc_total_opens++; - oc->oc_open_count++; - return 0; - } - return -1; -} - -/* - * Decrement the open count for the specified node in the - * specified channel. - */ -static int dec_open_count(struct event_svr_channel_instance *eci, - mar_uint32_t node_id) -{ - - struct open_count *oc; - int i; - - if ((i = check_open_size(eci)) != 0) { - return i; - } - - if (node_id == my_node_id) { - eci->esc_local_opens--; - } - oc = find_open_count(eci, node_id); - if (oc) { - eci->esc_total_opens--; - oc->oc_open_count--; - if ((eci->esc_total_opens < 0) || (oc->oc_open_count < 0)) { - log_printf(LOG_LEVEL_ERROR, "Channel open decrement error\n"); - dump_chan_opens(eci); - } - return 0; - } - return -1; -} - - -/* - * Remove a channel and free its memory if it's not in use anymore. - */ -static void delete_channel(struct event_svr_channel_instance *eci) -{ - - log_printf(CHAN_DEL_DEBUG, - "Called Delete channel %s t %d, l %d, r %d\n", - eci->esc_channel_name.value, - eci->esc_total_opens, eci->esc_local_opens, - eci->esc_retained_count); - /* - * If no one has the channel open anywhere and there are no unexpired - * retained events for this channel, and it has been marked for deletion - * by an unlink, then it is OK to delete the data structure. - */ - if ((eci->esc_retained_count == 0) && (eci->esc_total_opens == 0) && - (eci->esc_unlink_id != EVT_CHAN_ACTIVE)) { - log_printf(CHAN_DEL_DEBUG, "Delete channel %s\n", - eci->esc_channel_name.value); - log_printf(CHAN_UNLINK_DEBUG, "Delete channel %s, unlink_id %0llx\n", - eci->esc_channel_name.value, (unsigned long long)eci->esc_unlink_id); - - if (!list_empty(&eci->esc_open_chans)) { - log_printf(LOG_LEVEL_NOTICE, - "Last channel close request for %s (still open)\n", - eci->esc_channel_name.value); - dump_chan_opens(eci); - return; - } - - /* - * adjust if we're sending open counts on a config change. - */ - if ((recovery_phase != evt_recovery_complete) && - (&eci->esc_entry == next_chan)) { - next_chan = eci->esc_entry.next; - } - - list_del(&eci->esc_entry); - if (eci->esc_node_opens) { - free(eci->esc_node_opens); - } - free(eci); - } -} - -/* - * Free up an event structure if it isn't being used anymore. - */ -static void -free_event_data(struct event_data *edp) -{ - if (--edp->ed_ref_count) { - return; - } - log_printf(LOG_LEVEL_DEBUG, "Freeing event ID: 0x%llx\n", - (unsigned long long)edp->ed_event.led_event_id); - if (edp->ed_delivered) { - free(edp->ed_delivered); - } - - free(edp); -} - -/* - * Mark a channel for deletion. - */ -static void unlink_channel(struct event_svr_channel_instance *eci, - uint64_t unlink_id) -{ - struct event_data *edp; - struct list_head *l, *nxt; - - log_printf(CHAN_UNLINK_DEBUG, "Unlink request: %s, id 0x%llx\n", - eci->esc_channel_name.value, (unsigned long long)unlink_id); - /* - * The unlink ID is used to note that the channel has been marked - * for deletion and is a way to distinguish between multiple - * channels of the same name each marked for deletion. - */ - eci->esc_unlink_id = unlink_id; - - /* - * Move the unlinked channel to the unlinked list. This way - * we don't have to worry about filtering it out when we need to - * distribute retained events at recovery time. - */ - list_del(&eci->esc_entry); - list_add(&eci->esc_entry, &esc_unlinked_head); - - /* - * Scan the retained event list and remove any retained events. - * Since no new opens can occur there won't be any need of sending - * retained events on the channel. - */ - for (l = retained_list.next; l != &retained_list; l = nxt) { - nxt = l->next; - edp = list_entry(l, struct event_data, ed_retained); - if ((edp->ed_my_chan == eci) && - (edp->ed_event.led_chan_unlink_id == EVT_CHAN_ACTIVE)) { - api->timer_delete(edp->ed_timer_handle); - edp->ed_event.led_retention_time = 0; - list_del(&edp->ed_retained); - list_init(&edp->ed_retained); - edp->ed_my_chan->esc_retained_count--; - - log_printf(CHAN_UNLINK_DEBUG, - "Unlink: Delete retained event id 0x%llx\n", - (unsigned long long)edp->ed_event.led_event_id); - free_event_data(edp); - } - } - - delete_channel(eci); -} - -/* - * Remove the specified node from the node list in this channel. - */ -static int remove_open_count( - struct event_svr_channel_instance *eci, - mar_uint32_t node_id) -{ - int i; - int j; - - /* - * Find the node, remove it and re-pack the array. - */ - for (i = 0; i < eci->esc_oc_size; i++) { - if (eci->esc_node_opens[i].oc_node_id == 0) { - break; - } - - log_printf(RECOVERY_DEBUG, "roc: %s/%s, t %d, oc %d\n", - api->totem_ifaces_print (node_id), - api->totem_ifaces_print (eci->esc_node_opens[i].oc_node_id), - eci->esc_total_opens, eci->esc_node_opens[i].oc_open_count); - - if (eci->esc_node_opens[i].oc_node_id == node_id) { - - eci->esc_total_opens -= eci->esc_node_opens[i].oc_open_count; - - for (j = i+1; j < eci->esc_oc_size; j++, i++) { - eci->esc_node_opens[i].oc_node_id = - eci->esc_node_opens[j].oc_node_id; - eci->esc_node_opens[i].oc_open_count = - eci->esc_node_opens[j].oc_open_count; - } - - eci->esc_node_opens[eci->esc_oc_size-1].oc_node_id = 0; - eci->esc_node_opens[eci->esc_oc_size-1].oc_open_count = 0; - - /* - * Remove the channel if it's not being used anymore - */ - delete_channel(eci); - return 0; - } - } - return -1; -} - - -/* - * Send a request to open a channel to the rest of the cluster. - */ -static SaAisErrorT evt_open_channel(mar_name_t *cn, SaUint8T flgs) -{ - struct req_evt_chan_command cpkt; - struct event_svr_channel_instance *eci; - struct iovec chn_iovec; - int res; - SaAisErrorT ret; - - ret = SA_AIS_OK; - - eci = find_channel(cn, EVT_CHAN_ACTIVE); - - /* - * If the create flag set, and it doesn't exist, we can make the channel. - * Otherwise, it's an error since we're notified of channels being created - * and opened. - */ - if (!eci && !(flgs & SA_EVT_CHANNEL_CREATE)) { - ret = SA_AIS_ERR_NOT_EXIST; - goto chan_open_end; - } - - /* - * create the channel packet to send. Tell the the cluster - * to create the channel. - */ - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_OPEN_CHAN_OP; - cpkt.u.chc_chan.ocr_name = *cn; - cpkt.u.chc_chan.ocr_serial_no = ++open_serial_no; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Send open mcast\n"); - res = api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED); - log_printf(CHAN_OPEN_DEBUG, "evt_open_channel: Open mcast result: %d\n", - res); - if (res != 0) { - ret = SA_AIS_ERR_LIBRARY; - } - -chan_open_end: - return ret; - -} - -/* - * Send a request to close a channel with the rest of the cluster. - */ -static SaAisErrorT evt_close_channel(mar_name_t *cn, uint64_t unlink_id) -{ - struct req_evt_chan_command cpkt; - struct iovec chn_iovec; - int res; - SaAisErrorT ret; - - ret = SA_AIS_OK; - - /* - * create the channel packet to send. Tell the the cluster - * to close the channel. - */ - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_CLOSE_CHAN_OP; - cpkt.u.chcu.chcu_name = *cn; - cpkt.u.chcu.chcu_unlink_id = unlink_id; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - res = api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED); - if (res != 0) { - ret = SA_AIS_ERR_LIBRARY; - } - return ret; - -} - -/* - * Node data access functions. Used to keep track of event IDs - * delivery of messages. - * - * add_node: Add a new member node to our list. - * remove_node: Remove a node that left membership. - * find_node: Given the node ID return a pointer to node information. - * - */ -#define NODE_HASH_SIZE 256 -static struct member_node_data *nl[NODE_HASH_SIZE] = {0}; -inline int -hash_sock_addr(unsigned int nodeid) -{ - return nodeid & (NODE_HASH_SIZE - 1); -} - -static struct member_node_data **lookup_node(unsigned int nodeid) -{ - int index = hash_sock_addr(nodeid); - struct member_node_data **nlp; - - nlp = &nl[index]; - for (nlp = &nl[index]; *nlp; nlp = &((*nlp)->mn_next)) { - if ((*(nlp))->mn_nodeid == nodeid) { - break; - } - } - - return nlp; -} - -static struct member_node_data * -evt_find_node(unsigned int nodeid) -{ - struct member_node_data **nlp; - - nlp = lookup_node(nodeid); - - if (!nlp) { - log_printf(LOG_LEVEL_DEBUG, "find_node: Got NULL nlp?\n"); - return 0; - } - - return *nlp; -} - -static SaAisErrorT -evt_add_node( - unsigned int nodeid, - SaClmClusterNodeT *cn) -{ - struct member_node_data **nlp; - struct member_node_data *nl; - SaAisErrorT err = SA_AIS_ERR_EXIST; - - nlp = lookup_node(nodeid); - - if (!nlp) { - log_printf(LOG_LEVEL_DEBUG, "add_node: Got NULL nlp?\n"); - goto an_out; - } - - if (*nlp) { - goto an_out; - } - - *nlp = malloc(sizeof(struct member_node_data)); - if (!(*nlp)) { - return SA_AIS_ERR_NO_MEMORY; - } - nl = *nlp; - if (nl) { - memset(nl, 0, sizeof(*nl)); - err = SA_AIS_OK; - nl->mn_nodeid = nodeid; - nl->mn_started = 1; - } - list_init(&nl->mn_entry); - list_add(&nl->mn_entry, &mnd); - nl->mn_node_info = *cn; - -an_out: - return err; -} - -/* - * Find the oldest node in the membership. This is the one we choose to - * perform some cluster-wide functions like distributing retained events. - * We only check nodes that were in our transitional configuration. In this - * way there is a recovery node chosen for each original partition in case - * of a merge. - */ -static struct member_node_data* oldest_node() -{ - struct member_node_data *mn = 0; - struct member_node_data *oldest = 0; - int i; - - for (i = 0; i < trans_member_count; i++) { - mn = evt_find_node(trans_member_list[i]); - if (!mn || (mn->mn_started == 0)) { - log_printf(LOG_LEVEL_ERROR, - "Transitional config Node %s not active\n", - api->totem_ifaces_print (trans_member_list[i])); - continue; - } - if ((oldest == NULL) || - (mn->mn_node_info.bootTimestamp < - oldest->mn_node_info.bootTimestamp )) { - oldest = mn; - } else if (mn->mn_node_info.bootTimestamp == - oldest->mn_node_info.bootTimestamp) { - if (mn->mn_node_info.nodeId < oldest->mn_node_info.nodeId) { - oldest = mn; - } - } - } - return oldest; -} - - -/* - * keep track of the last event ID from a node. - * If we get an event ID less than our last, we've already - * seen it. It's probably a retained event being sent to - * a new node. - */ -static int check_last_event( - struct lib_event_data *evtpkt, - unsigned int nodeid) -{ - struct member_node_data *nd; - SaClmClusterNodeT *cn; - -#ifdef TODO - nd = evt_find_node(nodeid); - if (!nd) { - log_printf(LOG_LEVEL_DEBUG, - "Node ID %s not found for event %llx\n", - api->totem_ifaces_print (evtpkt->led_publisher_node_id), - (unsigned long long)evtpkt->led_event_id); - cn = main_clm_get_by_nodeid(nodeid); - if (!cn) { - log_printf(LOG_LEVEL_DEBUG, - "Cluster Node 0x%s not found for event %llx\n", - api->totem_ifaces_print (evtpkt->led_publisher_node_id), - (unsigned long long)evtpkt->led_event_id); - } else { - evt_add_node(nodeid, cn); - nd = evt_find_node(nodeid); - } - } - - if (!nd) { - return 0; - } - - if ((nd->mn_last_msg_id < evtpkt->led_msg_id)) { - nd->mn_last_msg_id = evtpkt->led_msg_id; - return 0; - } - #endif - return 1; -} - -/* - * event id generating code. We use the node ID for this node for the - * upper 32 bits of the event ID to make sure that we can generate a cluster - * wide unique event ID for a given event. - */ -SaAisErrorT set_event_id(mar_uint32_t node_id) -{ - SaAisErrorT err = SA_AIS_OK; - if (base_id_top) { - err = SA_AIS_ERR_EXIST; - } - base_id_top = (mar_evteventid_t)node_id << 32; - return err; -} - -/* - * See if an event Id is still in use in the retained event - * list. - */ -static int id_in_use(uint64_t id, uint64_t base) -{ - struct list_head *l; - struct event_data *edp; - mar_evteventid_t evtid = (id << 32) | (base & BASE_ID_MASK); - - for (l = retained_list.next; l != &retained_list; l = l->next) { - edp = list_entry(l, struct event_data, ed_retained); - if (edp->ed_event.led_event_id == evtid) { - return 1; - } - } - return 0; -} - -static SaAisErrorT get_event_id(uint64_t *event_id, uint64_t *msg_id) -{ - /* - * Don't reuse an event ID if it is still valid because of - * a retained event. - */ - while (id_in_use(base_id_top, base_id)) { - base_id++; - } - - *event_id = base_id_top | (base_id & BASE_ID_MASK) ; - *msg_id = base_id++; - return SA_AIS_OK; -} - - - -/* - * Timer handler to delete expired events. - * - */ -static void -event_retention_timeout(void *data) -{ - struct event_data *edp = data; - log_printf(RETENTION_TIME_DEBUG, "Event ID %llx expired\n", - (unsigned long long)edp->ed_event.led_event_id); - /* - * adjust next_retained if we're in recovery and - * were in charge of sending retained events. - */ - if (recovery_phase != evt_recovery_complete && recovery_node) { - if (next_retained == &edp->ed_retained) { - next_retained = edp->ed_retained.next; - } - } - list_del(&edp->ed_retained); - list_init(&edp->ed_retained); - /* - * Check to see if the channel isn't in use anymore. - */ - edp->ed_my_chan->esc_retained_count--; - if (edp->ed_my_chan->esc_retained_count == 0) { - delete_channel(edp->ed_my_chan); - } - free_event_data(edp); -} - -/* - * clear a particular event's retention time. - * This will free the event as long as it isn't being - * currently used. - * - */ -static SaAisErrorT -clear_retention_time(mar_evteventid_t event_id) -{ - struct event_data *edp; - struct list_head *l, *nxt; - - log_printf(RETENTION_TIME_DEBUG, "Search for Event ID %llx\n", - (unsigned long long)event_id); - for (l = retained_list.next; l != &retained_list; l = nxt) { - nxt = l->next; - edp = list_entry(l, struct event_data, ed_retained); - if (edp->ed_event.led_event_id != event_id) { - continue; - } - - log_printf(RETENTION_TIME_DEBUG, - "Clear retention time for Event ID %llx\n", - (unsigned long long)edp->ed_event.led_event_id); - api->timer_delete(edp->ed_timer_handle); - edp->ed_event.led_retention_time = 0; - list_del(&edp->ed_retained); - list_init(&edp->ed_retained); - - /* - * Check to see if the channel isn't in use anymore. - */ - edp->ed_my_chan->esc_retained_count--; - if (edp->ed_my_chan->esc_retained_count == 0) { - delete_channel(edp->ed_my_chan); - } - free_event_data(edp); - return SA_AIS_OK; - } - return SA_AIS_ERR_NOT_EXIST; -} - -/* - * Remove specified channel from event delivery list - */ -static void -remove_delivered_channel(struct event_svr_channel_open *eco) -{ - int i; - struct list_head *l; - struct event_data *edp; - - for (l = retained_list.next; l != &retained_list; l = l->next) { - edp = list_entry(l, struct event_data, ed_retained); - - for (i = 0; i < edp->ed_delivered_next; i++) { - if (edp->ed_delivered[i] == eco) { - edp->ed_delivered_next--; - if (edp->ed_delivered_next == i) { - break; - } - memmove(&edp->ed_delivered[i], - &edp->ed_delivered[i+1], - &edp->ed_delivered[edp->ed_delivered_next] - - &edp->ed_delivered[i]); - break; - } - } - } -} - -/* - * If there is a retention time, add this open channel to the event so - * we can check if we've already delivered this message later if a new - * subscription matches. - */ -#define DELIVER_SIZE 8 -static void -evt_delivered(struct event_data *evt, struct event_svr_channel_open *eco) -{ - if (!evt->ed_event.led_retention_time) { - return; - } - - log_printf(LOG_LEVEL_DEBUG, "delivered ID %llx to eco %p\n", - (unsigned long long)evt->ed_event.led_event_id, eco); - if (evt->ed_delivered_count == evt->ed_delivered_next) { - struct event_svr_channel_open **ed_delivered_tmp; - - ed_delivered_tmp = realloc (evt->ed_delivered, - DELIVER_SIZE * sizeof(struct event_svr_channel_open *)); - if (ed_delivered_tmp == NULL) { - log_printf(LOG_LEVEL_WARNING, "Memory error realloc\n"); - return; - } - evt->ed_delivered = ed_delivered_tmp; - memset(evt->ed_delivered + evt->ed_delivered_next, 0, - DELIVER_SIZE * sizeof(struct event_svr_channel_open *)); - evt->ed_delivered_next = evt->ed_delivered_count; - evt->ed_delivered_count += DELIVER_SIZE; - } - - evt->ed_delivered[evt->ed_delivered_next++] = eco; -} - -/* - * Check to see if an event has already been delivered to this open channel - */ -static int -evt_already_delivered(struct event_data *evt, - struct event_svr_channel_open *eco) -{ - int i; - - if (!evt->ed_event.led_retention_time) { - return 0; - } - - log_printf(LOG_LEVEL_DEBUG, "Deliver count: %d deliver_next %d\n", - evt->ed_delivered_count, evt->ed_delivered_next); - for (i = 0; i < evt->ed_delivered_next; i++) { - log_printf(LOG_LEVEL_DEBUG, "Checking ID %llx delivered %p eco %p\n", - (unsigned long long)evt->ed_event.led_event_id, - evt->ed_delivered[i], eco); - if (evt->ed_delivered[i] == eco) { - return 1; - } - } - return 0; -} - -/* - * Compare a filter to a given pattern. - * return SA_AIS_OK if the pattern matches a filter - */ -static SaAisErrorT -filter_match(mar_evt_event_pattern_t *ep, mar_evt_event_filter_t *ef) -{ - int ret; - ret = SA_AIS_ERR_FAILED_OPERATION; - - switch (ef->filter_type) { - case SA_EVT_PREFIX_FILTER: - if (ef->filter.pattern_size > ep->pattern_size) { - break; - } - if (strncmp((char *)ef->filter.pattern, (char *)ep->pattern, - ef->filter.pattern_size) == 0) { - ret = SA_AIS_OK; - } - break; - case SA_EVT_SUFFIX_FILTER: - if (ef->filter.pattern_size > ep->pattern_size) { - break; - } - if (strncmp((char *)ef->filter.pattern, - (char *)&ep->pattern[ep->pattern_size - ef->filter.pattern_size], - ef->filter.pattern_size) == 0) { - ret = SA_AIS_OK; - } - - break; - case SA_EVT_EXACT_FILTER: - if (ef->filter.pattern_size != ep->pattern_size) { - break; - } - if (strncmp((char *)ef->filter.pattern, (char *)ep->pattern, - ef->filter.pattern_size) == 0) { - ret = SA_AIS_OK; - } - break; - case SA_EVT_PASS_ALL_FILTER: - ret = SA_AIS_OK; - break; - default: - break; - } - return ret; -} - -/* - * compare the event's patterns with the subscription's filter rules. - * SA_AIS_OK is returned if the event matches the filter rules. - */ -static SaAisErrorT -event_match(struct event_data *evt, - struct event_svr_channel_subscr *ecs) -{ - mar_evt_event_filter_t *ef; - mar_evt_event_pattern_t *ep; - uint32_t filt_count; - SaAisErrorT ret = SA_AIS_OK; - int i; - - ep = (mar_evt_event_pattern_t *)(&evt->ed_event.led_body[0]); - ef = ecs->ecs_filters->filters; - filt_count = min(ecs->ecs_filters->filters_number, - evt->ed_event.led_patterns_number); - - for (i = 0; i < filt_count; i++) { - ret = filter_match(ep, ef); - if (ret != SA_AIS_OK) { - break; - } - ep++; - ef++; - } - return ret; -} - -/* - * Scan undelivered pending events and either remove them if no subscription - * filters match anymore or re-assign them to another matching subscription - */ -static void -filter_undelivered_events(struct event_svr_channel_open *op_chan) -{ - struct event_svr_channel_open *eco; - struct event_svr_channel_instance *eci; - struct event_svr_channel_subscr *ecs; - struct chan_event_list *cel; - struct libevt_pd *esip; - struct list_head *l, *nxt; - struct list_head *l1, *l2; - int i; - - esip = (struct libevt_pd *)api->ipc_private_data_get(op_chan->eco_conn); - eci = op_chan->eco_channel; - - /* - * Scan each of the priority queues for messages - */ - for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) { - /* - * examine each message queued for delivery - */ - for (l = esip->esi_events[i].next; l != &esip->esi_events[i]; l = nxt) { - nxt = l->next; - cel = list_entry(l, struct chan_event_list, cel_entry); - /* - * Check open channels - */ - for (l1 = eci->esc_open_chans.next; - l1 != &eci->esc_open_chans; l1 = l1->next) { - eco = list_entry(l1, struct event_svr_channel_open, eco_entry); - - /* - * See if this channel open instance belongs - * to this evtinitialize instance - */ - if (eco->eco_conn != op_chan->eco_conn) { - continue; - } - - /* - * See if enabled to receive - */ - if (!(eco->eco_flags & SA_EVT_CHANNEL_SUBSCRIBER)) { - continue; - } - - /* - * Check subscriptions - */ - for (l2 = eco->eco_subscr.next; - l2 != &eco->eco_subscr; l2 = l2->next) { - ecs = list_entry(l2, - struct event_svr_channel_subscr, ecs_entry); - if (event_match(cel->cel_event, ecs) == SA_AIS_OK) { - /* - * Something still matches. - * We'll assign it to - * the new subscription. - */ - cel->cel_sub_id = ecs->ecs_sub_id; - cel->cel_chan_handle = eco->eco_lib_handle; - goto next_event; - } - } - } - /* - * No subscription filter matches anymore. We - * can delete this event. - */ - list_del(&cel->cel_entry); - list_init(&cel->cel_entry); - esip->esi_nevents--; - - free_event_data(cel->cel_event); - free(cel); -next_event: - continue; - } - } -} - -/* - * Notify the library of a pending event - */ -static void __notify_event(void *conn) -{ - struct res_evt_event_data res; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - log_printf(LOG_LEVEL_DEBUG, "DELIVER: notify\n"); - if (esip->esi_nevents != 0) { - res.evd_head.size = sizeof(res); - res.evd_head.id = MESSAGE_RES_EVT_AVAILABLE; - res.evd_head.error = SA_AIS_OK; - api->ipc_conn_send_response(api->ipc_conn_partner_get(conn), - &res, sizeof(res)); - } - -} -inline void notify_event(void *conn) -{ - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - - /* - * Give the library a kick if there aren't already - * events queued for delivery. - */ - if (esip->esi_nevents++ == 0) { - __notify_event(conn); - } -} - -/* - * sends/queues up an event for a subscribed channel. - */ -static void -deliver_event(struct event_data *evt, - struct event_svr_channel_open *eco, - struct event_svr_channel_subscr *ecs) -{ - struct chan_event_list *ep; - SaEvtEventPriorityT evt_prio = evt->ed_event.led_priority; - struct chan_event_list *cel; - int do_deliver_event = 0; - int do_deliver_warning = 0; - int i; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(eco->eco_conn); - - if (evt_prio > SA_EVT_LOWEST_PRIORITY) { - evt_prio = SA_EVT_LOWEST_PRIORITY; - } - - /* - * Delivery queue check. - * - If the queue is blocked, see if we've sent enough messages to - * unblock it. - * - If it isn't blocked, see if this message will put us over the top. - * - If we can't deliver this message, see if we can toss some lower - * priority message to make room for this one. - * - If we toss any messages, queue up an event of SA_EVT_LOST_EVENT_PATTERN - * to let the application know that we dropped some messages. - */ - if (esip->esi_queue_blocked) { - if (esip->esi_nevents < evt_delivery_queue_resume) { - esip->esi_queue_blocked = 0; - log_printf(LOG_LEVEL_DEBUG, "unblock\n"); - } - } - - assert (esip->esi_nevents >= 0); - if (!esip->esi_queue_blocked && - (esip->esi_nevents >= evt_delivery_queue_size)) { - log_printf(LOG_LEVEL_DEBUG, "block\n"); - esip->esi_queue_blocked = 1; - do_deliver_warning = 1; - } - - if (esip->esi_queue_blocked) { - do_deliver_event = 0; - for (i = SA_EVT_LOWEST_PRIORITY; i > evt_prio; i--) { - if (!list_empty(&esip->esi_events[i])) { - /* - * Get the last item on the list, so we drop the most - * recent lowest priority event. - */ - cel = list_entry(esip->esi_events[i].prev, - struct chan_event_list, cel_entry); - log_printf(LOG_LEVEL_DEBUG, "Drop 0x%0llx\n", - (unsigned long long)cel->cel_event->ed_event.led_event_id); - list_del(&cel->cel_entry); - free_event_data(cel->cel_event); - free(cel); - esip->esi_nevents--; - do_deliver_event = 1; - break; - } - } - } else { - do_deliver_event = 1; - } - - /* - * Queue the event for delivery - */ - if (do_deliver_event) { - ep = malloc(sizeof(*ep)); - if (!ep) { - log_printf(LOG_LEVEL_WARNING, - "3Memory allocation error, can't deliver event\n"); - return; - } - evt->ed_ref_count++; - ep->cel_chan_handle = eco->eco_lib_handle; - ep->cel_sub_id = ecs->ecs_sub_id; - list_init(&ep->cel_entry); - ep->cel_event = evt; - list_add_tail(&ep->cel_entry, &esip->esi_events[evt_prio]); - evt_delivered(evt, eco); - notify_event(eco->eco_conn); - } - - /* - * If we dropped an event, queue this so that the application knows - * what has happened. - */ - if (do_deliver_warning) { - struct event_data *ed; - ed = malloc(dropped_event_size); - if (!ed) { - log_printf(LOG_LEVEL_WARNING, - "4Memory allocation error, can't deliver event\n"); - return; - } - log_printf(LOG_LEVEL_DEBUG, "Warn 0x%0llx\n", - (unsigned long long)evt->ed_event.led_event_id); - memcpy(ed, dropped_event, dropped_event_size); - ed->ed_event.led_publish_time = clust_time_now(); - ed->ed_event.led_event_id = SA_EVT_EVENTID_LOST; - list_init(&ed->ed_retained); - - ep = malloc(sizeof(*ep)); - if (!ep) { - log_printf(LOG_LEVEL_WARNING, - "5Memory allocation error, can't deliver event\n"); - return; - } - ep->cel_chan_handle = eco->eco_lib_handle; - ep->cel_sub_id = ecs->ecs_sub_id; - list_init(&ep->cel_entry); - ep->cel_event = ed; - list_add_tail(&ep->cel_entry, &esip->esi_events[SA_EVT_HIGHEST_PRIORITY]); - notify_event(eco->eco_conn); - } -} - -/* - * Take the event data and swap the elements so they match our architectures - * word order. - */ -static void -convert_event(void *msg) -{ - struct lib_event_data *evt = (struct lib_event_data *)msg; - mar_evt_event_pattern_t *eps; - int i; - - /* - * The following elements don't require processing: - * - * converted in the main deliver_fn: - * led_head.id, led_head.size. - * - * Supplied localy: - * source_addr, publisher_node_id, receive_time. - * - * Used internaly only: - * led_svr_channel_handle and led_lib_channel_handle. - */ - - swab_mar_name_t (&evt->led_chan_name); - evt->led_chan_unlink_id = swab64(evt->led_chan_unlink_id); - evt->led_event_id = swab64(evt->led_event_id); - evt->led_sub_id = swab32(evt->led_sub_id); - swab_mar_name_t (&evt->led_publisher_name); - evt->led_retention_time = swab64(evt->led_retention_time); - evt->led_publish_time = swab64(evt->led_publish_time); - evt->led_user_data_offset = swab32(evt->led_user_data_offset); - evt->led_user_data_size = swab32(evt->led_user_data_size); - evt->led_patterns_number = swab32(evt->led_patterns_number); - - /* - * Now we need to go through the led_body and swizzle pattern counts. - * We can't do anything about user data since it doesn't have a specified - * format. The application is on its own here. - */ - eps = (mar_evt_event_pattern_t *)evt->led_body; - for (i = 0; i < evt->led_patterns_number; i++) { - eps->pattern_size = swab32(eps->pattern_size); - eps->allocated_size = swab32(eps->allocated_size); - eps++; - } - -} - -/* - * Take an event received from the network and fix it up to be usable. - * - fix up pointers for pattern list. - * - fill in some channel info - */ -static struct event_data * -make_local_event(struct lib_event_data *p, - struct event_svr_channel_instance *eci) -{ - struct event_data *ed; - mar_evt_event_pattern_t *eps; - SaUint8T *str; - uint32_t ed_size; - int i; - - ed_size = sizeof(*ed) + p->led_user_data_offset + p->led_user_data_size; - ed = malloc(ed_size); - if (!ed) { - log_printf(LOG_LEVEL_WARNING, - "Failed to allocate %u bytes for event, offset %u, data size %u\n", - ed_size, p->led_user_data_offset, p->led_user_data_size); - return 0; - } - memset(ed, 0, ed_size); - list_init(&ed->ed_retained); - ed->ed_my_chan = eci; - - /* - * Fill in lib_event_data and make the pattern pointers valid - */ - memcpy(&ed->ed_event, p, sizeof(*p) + - p->led_user_data_offset + p->led_user_data_size); - - eps = (mar_evt_event_pattern_t *)ed->ed_event.led_body; - str = ed->ed_event.led_body + - (ed->ed_event.led_patterns_number * sizeof(mar_evt_event_pattern_t)); - for (i = 0; i < ed->ed_event.led_patterns_number; i++) { - eps->pattern = str; - str += eps->pattern_size; - eps++; - } - - ed->ed_ref_count++; - return ed; -} - -/* - * Set an event to be retained. - */ -static void retain_event(struct event_data *evt) -{ - uint32_t ret; - evt->ed_ref_count++; - evt->ed_my_chan->esc_retained_count++; - list_add_tail(&evt->ed_retained, &retained_list); - - ret = api->timer_add_duration ( - evt->ed_event.led_retention_time, - evt, - event_retention_timeout, - &evt->ed_timer_handle); - - if (ret != 0) { - log_printf(LOG_LEVEL_ERROR, - "retention of event id 0x%llx failed\n", - (unsigned long long)evt->ed_event.led_event_id); - } else { - log_printf(RETENTION_TIME_DEBUG, "Retain event ID 0x%llx for %llu ms\n", - (unsigned long long)evt->ed_event.led_event_id, evt->ed_event.led_retention_time/100000LL); - } -} - -/* - * Scan the subscription list and look for the specified subsctiption ID. - * Only look for the ID in subscriptions that are associated with the - * saEvtInitialize associated with the specified open channel. - */ -static struct event_svr_channel_subscr *find_subscr( - struct event_svr_channel_open *open_chan, SaEvtSubscriptionIdT sub_id) -{ - struct event_svr_channel_instance *eci; - struct event_svr_channel_subscr *ecs; - struct event_svr_channel_open *eco; - struct list_head *l, *l1; - void *conn = open_chan->eco_conn; - - eci = open_chan->eco_channel; - - /* - * Check for subscription id already in use. - * Subscriptions are unique within saEvtInitialize (Callback scope). - */ - for (l = eci->esc_open_chans.next; l != &eci->esc_open_chans; l = l->next) { - eco = list_entry(l, struct event_svr_channel_open, eco_entry); - /* - * Don't bother with open channels associated with another - * EvtInitialize - */ - if (eco->eco_conn != conn) { - continue; - } - - for (l1 = eco->eco_subscr.next; l1 != &eco->eco_subscr; l1 = l1->next) { - ecs = list_entry(l1, struct event_svr_channel_subscr, ecs_entry); - if (ecs->ecs_sub_id == sub_id) { - return ecs; - } - } - } - return 0; -} - -/* - * Handler for saEvtInitialize - */ -static int evt_lib_init(void *conn) -{ - struct libevt_pd *libevt_pd; - int i; - - libevt_pd = (struct libevt_pd *)api->ipc_private_data_get(conn); - - - log_printf(LOG_LEVEL_DEBUG, "saEvtInitialize request.\n"); - - /* - * Initailze event instance data - */ - memset(libevt_pd, 0, sizeof(*libevt_pd)); - - /* - * Initialize the open channel handle database. - */ - hdb_create(&libevt_pd->esi_hdb); - - /* - * list of channels open on this instance - */ - list_init(&libevt_pd->esi_open_chans); - - /* - * pending event lists for each piriority - */ - for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) { - list_init(&libevt_pd->esi_events[i]); - } - - return 0; -} - -/* - * Handler for saEvtChannelOpen - */ -static void lib_evt_open_channel(void *conn, void *message) -{ - SaAisErrorT error; - struct req_evt_channel_open *req; - struct res_evt_channel_open res; - struct open_chan_pending *ocp; - int ret; - - req = message; - - - log_printf(CHAN_OPEN_DEBUG, - "saEvtChannelOpen (Open channel request)\n"); - log_printf(CHAN_OPEN_DEBUG, - "handle 0x%llx, to 0x%llx\n", - (unsigned long long)req->ico_c_handle, - (unsigned long long)req->ico_timeout); - log_printf(CHAN_OPEN_DEBUG, "flags %x, channel name(%d) %s\n", - req->ico_open_flag, - req->ico_channel_name.length, - req->ico_channel_name.value); - /* - * Open the channel. - * - */ - error = evt_open_channel(&req->ico_channel_name, req->ico_open_flag); - - if (error != SA_AIS_OK) { - goto open_return; - } - - ocp = malloc(sizeof(struct open_chan_pending)); - if (!ocp) { - error = SA_AIS_ERR_NO_MEMORY; - goto open_return; - } - - ocp->ocp_async = 0; - ocp->ocp_invocation = 0; - ocp->ocp_chan_name = req->ico_channel_name; - ocp->ocp_open_flag = req->ico_open_flag; - ocp->ocp_conn = conn; - ocp->ocp_c_handle = req->ico_c_handle; - ocp->ocp_timer_handle = 0; - ocp->ocp_serial_no = open_serial_no; - list_init(&ocp->ocp_entry); - list_add_tail(&ocp->ocp_entry, &open_pending); - ret = api->timer_add_duration ( - req->ico_timeout, - ocp, - chan_open_timeout, - &ocp->ocp_timer_handle); - if (ret != 0) { - log_printf(LOG_LEVEL_WARNING, - "Error setting timeout for open channel %s\n", - req->ico_channel_name.value); - } - return; - - -open_return: - res.ico_head.size = sizeof(res); - res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL; - res.ico_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - -/* - * Handler for saEvtChannelOpen - */ -static void lib_evt_open_channel_async(void *conn, void *message) -{ - SaAisErrorT error; - struct req_evt_channel_open *req; - struct res_evt_channel_open res; - struct open_chan_pending *ocp; - - req = message; - - - log_printf(CHAN_OPEN_DEBUG, - "saEvtChannelOpenAsync (Async Open channel request)\n"); - log_printf(CHAN_OPEN_DEBUG, - "handle 0x%llx, to 0x%llx\n", - (unsigned long long)req->ico_c_handle, - (unsigned long long)req->ico_invocation); - log_printf(CHAN_OPEN_DEBUG, "flags %x, channel name(%d) %s\n", - req->ico_open_flag, - req->ico_channel_name.length, - req->ico_channel_name.value); - /* - * Open the channel. - * - */ - error = evt_open_channel(&req->ico_channel_name, req->ico_open_flag); - - if (error != SA_AIS_OK) { - goto open_return; - } - - ocp = malloc(sizeof(struct open_chan_pending)); - if (!ocp) { - error = SA_AIS_ERR_NO_MEMORY; - goto open_return; - } - - ocp->ocp_async = 1; - ocp->ocp_invocation = req->ico_invocation; - ocp->ocp_c_handle = req->ico_c_handle; - ocp->ocp_chan_name = req->ico_channel_name; - ocp->ocp_open_flag = req->ico_open_flag; - ocp->ocp_conn = conn; - ocp->ocp_timer_handle = 0; - ocp->ocp_serial_no = open_serial_no; - list_init(&ocp->ocp_entry); - list_add_tail(&ocp->ocp_entry, &open_pending); - -open_return: - res.ico_head.size = sizeof(res); - res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL; - res.ico_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - - - -/* - * Used by the channel close code and by the implicit close - * when saEvtFinalize is called with channels open. - */ -static SaAisErrorT -common_chan_close(struct event_svr_channel_open *eco, struct libevt_pd *esip) -{ - struct event_svr_channel_subscr *ecs; - struct list_head *l, *nxt; - - log_printf(LOG_LEVEL_DEBUG, "Close channel %s flags 0x%02x\n", - eco->eco_channel->esc_channel_name.value, - eco->eco_flags); - - /* - * Disconnect the channel open structure. - * - * Check for subscriptions and deal with them. In this case - * if there are any, we just implicitly unsubscribe. - * - * When We're done with the channel open data then we can - * remove it's handle (this frees the memory too). - * - */ - list_del(&eco->eco_entry); - list_del(&eco->eco_instance_entry); - - for (l = eco->eco_subscr.next; l != &eco->eco_subscr; l = nxt) { - nxt = l->next; - ecs = list_entry(l, struct event_svr_channel_subscr, ecs_entry); - log_printf(LOG_LEVEL_DEBUG, "Unsubscribe ID: %x\n", - ecs->ecs_sub_id); - list_del(&ecs->ecs_entry); - free(ecs); - /* - * Purge any pending events associated with this subscription - * that don't match another subscription. - */ - filter_undelivered_events(eco); - } - - /* - * Remove this channel from the retained event's notion - * of who they have been delivered to. - */ - remove_delivered_channel(eco); - return evt_close_channel(&eco->eco_channel->esc_channel_name, - eco->eco_channel->esc_unlink_id); -} - -/* - * Handler for saEvtChannelClose - */ -static void lib_evt_close_channel(void *conn, void *message) -{ - struct req_evt_channel_close *req; - struct res_evt_channel_close res; - struct event_svr_channel_open *eco; - unsigned int ret; - void *ptr; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - - req = message; - - log_printf(LOG_LEVEL_DEBUG, - "saEvtChannelClose (Close channel request)\n"); - log_printf(LOG_LEVEL_DEBUG, "handle 0x%x\n", req->icc_channel_handle); - - /* - * look up the channel handle - */ - ret = hdb_handle_get(&esip->esi_hdb, - req->icc_channel_handle, &ptr); - if (ret != 0) { - goto chan_close_done; - } - eco = ptr; - - common_chan_close(eco, esip); - hdb_handle_destroy(&esip->esi_hdb, req->icc_channel_handle); - hdb_handle_put(&esip->esi_hdb, req->icc_channel_handle); - -chan_close_done: - res.icc_head.size = sizeof(res); - res.icc_head.id = MESSAGE_RES_EVT_CLOSE_CHANNEL; - res.icc_head.error = ((ret == 0) ? SA_AIS_OK : SA_AIS_ERR_BAD_HANDLE); - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - -/* - * Handler for saEvtChannelUnlink - */ -static void lib_evt_unlink_channel(void *conn, void *message) -{ - struct req_evt_channel_unlink *req; - struct res_evt_channel_unlink res; - struct iovec chn_iovec; - struct unlink_chan_pending *ucp = 0; - struct req_evt_chan_command cpkt; - SaAisErrorT error = SA_AIS_ERR_LIBRARY; - - req = message; - - log_printf(CHAN_UNLINK_DEBUG, - "saEvtChannelUnlink (Unlink channel request)\n"); - log_printf(CHAN_UNLINK_DEBUG, "Channel Name %s\n", - req->iuc_channel_name.value); - - if (!find_channel(&req->iuc_channel_name, EVT_CHAN_ACTIVE)) { - log_printf(CHAN_UNLINK_DEBUG, "Channel Name doesn't exist\n"); - error = SA_AIS_ERR_NOT_EXIST; - goto evt_unlink_err; - } - - /* - * Set up the data structure so that the channel op - * mcast handler can complete the unlink comamnd back to the - * requestor. - */ - ucp = malloc(sizeof(*ucp)); - if (!ucp) { - log_printf(LOG_LEVEL_ERROR, - "saEvtChannelUnlink: Memory allocation failure\n"); - error = SA_AIS_ERR_TRY_AGAIN; - goto evt_unlink_err; - } - - ucp->ucp_unlink_id = next_chan_unlink_id(); - ucp->ucp_conn = conn; - list_init(&ucp->ucp_entry); - list_add_tail(&ucp->ucp_entry, &unlink_pending); - - /* - * Put together a mcast packet to notify everyone - * of the channel unlink. - */ - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_UNLINK_CHAN_OP; - cpkt.u.chcu.chcu_name = req->iuc_channel_name; - cpkt.u.chcu.chcu_unlink_id = ucp->ucp_unlink_id; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - if (api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED) == 0) { - return; - } - -evt_unlink_err: - if (ucp) { - list_del(&ucp->ucp_entry); - free(ucp); - } - res.iuc_head.size = sizeof(res); - res.iuc_head.id = MESSAGE_RES_EVT_UNLINK_CHANNEL; - res.iuc_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - -/* - * Subscribe to an event channel. - * - * - First look up the channel to subscribe. - * - Make sure that the subscription ID is not already in use. - * - Fill in the subscription data structures and add them to the channels - * subscription list. - * - See if there are any events with retetion times that need to be delivered - * because of the new subscription. - */ -static char *filter_types[] = { - "INVALID FILTER TYPE", - "SA_EVT_PREFIX_FILTER", - "SA_EVT_SUFFIX_FILTER", - "SA_EVT_EXACT_FILTER", - "SA_EVT_PASS_ALL_FILTER", -}; - -/* - * saEvtEventSubscribe Handler - */ -static void lib_evt_event_subscribe(void *conn, void *message) -{ - struct req_evt_event_subscribe *req; - struct res_evt_event_subscribe res; - mar_evt_event_filter_array_t *filters; - SaAisErrorT error; - struct event_svr_channel_open *eco; - struct event_svr_channel_instance *eci; - struct event_svr_channel_subscr *ecs; - struct event_data *evt; - struct list_head *l; - void *ptr; - unsigned int ret; - int i; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - - req = message; - - log_printf(LOG_LEVEL_DEBUG, - "saEvtEventSubscribe (Subscribe request)\n"); - log_printf(LOG_LEVEL_DEBUG, "subscription Id: 0x%llx\n", - (unsigned long long)req->ics_sub_id); - - /* - * look up the channel handle - */ - ret = hdb_handle_get(&esip->esi_hdb, req->ics_channel_handle, &ptr); - if (ret != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto subr_done; - } - eco = ptr; - - eci = eco->eco_channel; - - /* - * See if the id is already being used - */ - ecs = find_subscr(eco, req->ics_sub_id); - if (ecs) { - error = SA_AIS_ERR_EXIST; - goto subr_put; - } - - error = evtfilt_to_aisfilt(req, &filters); - - if (error == SA_AIS_OK) { - log_printf(LOG_LEVEL_DEBUG, "Subscribe filters count %d\n", - (int)filters->filters_number); - for (i = 0; i < filters->filters_number; i++) { - log_printf(LOG_LEVEL_DEBUG, "type %s(%d) sz %d, <%s>\n", - filter_types[filters->filters[i].filter_type], - filters->filters[i].filter_type, - (int)filters->filters[i].filter.pattern_size, - (filters->filters[i].filter.pattern_size) - ? (char *)filters->filters[i].filter.pattern - : ""); - } - } - - if (error != SA_AIS_OK) { - goto subr_put; - } - - ecs = (struct event_svr_channel_subscr *)malloc(sizeof(*ecs)); - if (!ecs) { - error = SA_AIS_ERR_NO_MEMORY; - goto subr_put; - } - ecs->ecs_filters = filters; - ecs->ecs_sub_id = req->ics_sub_id; - list_init(&ecs->ecs_entry); - list_add(&ecs->ecs_entry, &eco->eco_subscr); - - - res.ics_head.size = sizeof(res); - res.ics_head.id = MESSAGE_RES_EVT_SUBSCRIBE; - res.ics_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); - - /* - * See if an existing event with a retention time - * needs to be delivered based on this subscription - */ - for (l = retained_list.next; l != &retained_list; l = l->next) { - evt = list_entry(l, struct event_data, ed_retained); - log_printf(LOG_LEVEL_DEBUG, - "Checking event ID %llx chanp %p -- sub chanp %p\n", - (unsigned long long)evt->ed_event.led_event_id, - evt->ed_my_chan, eci); - if (evt->ed_my_chan == eci) { - if (evt_already_delivered(evt, eco)) { - continue; - } - if (event_match(evt, ecs) == SA_AIS_OK) { - log_printf(LOG_LEVEL_DEBUG, - "deliver event ID: 0x%llx\n", - (unsigned long long)evt->ed_event.led_event_id); - deliver_event(evt, eco, ecs); - } - } - } - hdb_handle_put(&esip->esi_hdb, req->ics_channel_handle); - return; - -subr_put: - hdb_handle_put(&esip->esi_hdb, req->ics_channel_handle); -subr_done: - res.ics_head.size = sizeof(res); - res.ics_head.id = MESSAGE_RES_EVT_SUBSCRIBE; - res.ics_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - -/* - * saEvtEventUnsubscribe Handler - */ -static void lib_evt_event_unsubscribe(void *conn, void *message) -{ - struct req_evt_event_unsubscribe *req; - struct res_evt_event_unsubscribe res; - struct event_svr_channel_open *eco; - struct event_svr_channel_instance *eci; - struct event_svr_channel_subscr *ecs; - SaAisErrorT error = SA_AIS_OK; - unsigned int ret; - void *ptr; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - - req = message; - - log_printf(LOG_LEVEL_DEBUG, - "saEvtEventUnsubscribe (Unsubscribe request)\n"); - log_printf(LOG_LEVEL_DEBUG, "subscription Id: 0x%llx\n", - (unsigned long long)req->icu_sub_id); - - /* - * look up the channel handle, get the open channel - * data. - */ - ret = hdb_handle_get(&esip->esi_hdb, - req->icu_channel_handle, &ptr); - if (ret != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto unsubr_done; - } - eco = ptr; - - eci = eco->eco_channel; - - /* - * Make sure that the id exists. - */ - ecs = find_subscr(eco, req->icu_sub_id); - if (!ecs) { - error = SA_AIS_ERR_NOT_EXIST; - goto unsubr_put; - } - - list_del(&ecs->ecs_entry); - - log_printf(LOG_LEVEL_DEBUG, - "unsubscribe from channel %s subscription ID 0x%x " - "with %d filters\n", - eci->esc_channel_name.value, - ecs->ecs_sub_id, (int)ecs->ecs_filters->filters_number); - - free_filters(ecs->ecs_filters); - free(ecs); - -unsubr_put: - hdb_handle_put(&esip->esi_hdb, req->icu_channel_handle); -unsubr_done: - res.icu_head.size = sizeof(res); - res.icu_head.id = MESSAGE_RES_EVT_UNSUBSCRIBE; - res.icu_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - -/* - * saEvtEventPublish Handler - */ -static void lib_evt_event_publish(void *conn, void *message) -{ - struct lib_event_data *req; - struct res_evt_event_publish res; - struct event_svr_channel_open *eco; - struct event_svr_channel_instance *eci; - mar_evteventid_t event_id = 0; - uint64_t msg_id = 0; - SaAisErrorT error = SA_AIS_OK; - struct iovec pub_iovec; - void *ptr; - int result; - unsigned int ret; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - - - req = message; - - log_printf(LOG_LEVEL_DEBUG, - "saEvtEventPublish (Publish event request)\n"); - - - /* - * look up and validate open channel info - */ - ret = hdb_handle_get(&esip->esi_hdb, - req->led_svr_channel_handle, &ptr); - if (ret != 0) { - error = SA_AIS_ERR_BAD_HANDLE; - goto pub_done; - } - eco = ptr; - - eci = eco->eco_channel; - - /* - * modify the request structure for sending event data to subscribed - * processes. - */ - get_event_id(&event_id, &msg_id); - req->led_head.id = SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_EVENTDATA); - req->led_chan_name = eci->esc_channel_name; - req->led_event_id = event_id; - req->led_msg_id = msg_id; - req->led_chan_unlink_id = eci->esc_unlink_id; - - /* - * Distribute the event. - * The multicasted event will be picked up and delivered - * locally by the local network event receiver. - */ - pub_iovec.iov_base = (char *)req; - pub_iovec.iov_len = req->led_head.size; - result = api->totem_mcast (&pub_iovec, 1, TOTEM_AGREED); - if (result != 0) { - error = SA_AIS_ERR_LIBRARY; - } - - hdb_handle_put(&esip->esi_hdb, req->led_svr_channel_handle); -pub_done: - res.iep_head.size = sizeof(res); - res.iep_head.id = MESSAGE_RES_EVT_PUBLISH; - res.iep_head.error = error; - res.iep_event_id = event_id; - api->ipc_conn_send_response(conn, &res, sizeof(res)); -} - -/* - * saEvtEventRetentionTimeClear handler - */ -static void lib_evt_event_clear_retentiontime(void *conn, void *message) -{ - struct req_evt_event_clear_retentiontime *req; - struct res_evt_event_clear_retentiontime res; - struct req_evt_chan_command cpkt; - struct retention_time_clear_pending *rtc = 0; - struct iovec rtn_iovec; - SaAisErrorT error; - int ret; - - req = message; - - log_printf(RETENTION_TIME_DEBUG, - "saEvtEventRetentionTimeClear (Clear event retentiontime request)\n"); - log_printf(RETENTION_TIME_DEBUG, - "event ID 0x%llx, chan handle 0x%x\n", - (unsigned long long)req->iec_event_id, - req->iec_channel_handle); - - rtc = malloc(sizeof(*rtc)); - if (!rtc) { - log_printf(LOG_LEVEL_ERROR, - "saEvtEventRetentionTimeClear: Memory allocation failure\n"); - error = SA_AIS_ERR_TRY_AGAIN; - goto evt_ret_clr_err; - } - rtc->rtc_event_id = req->iec_event_id; - rtc->rtc_conn = conn; - list_init(&rtc->rtc_entry); - list_add_tail(&rtc->rtc_entry, &clear_pending); - - /* - * Send the clear request - */ - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_CLEAR_RET_OP; - cpkt.u.chc_event_id = req->iec_event_id; - rtn_iovec.iov_base = (char *)&cpkt; - rtn_iovec.iov_len = cpkt.chc_head.size; - ret = api->totem_mcast (&rtn_iovec, 1, TOTEM_AGREED); - if (ret == 0) { - // TODO this should really assert - return; - } - error = SA_AIS_ERR_LIBRARY; - -evt_ret_clr_err: - if (rtc) { - list_del(&rtc->rtc_entry); - free(rtc); - } - res.iec_head.size = sizeof(res); - res.iec_head.id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME; - res.iec_head.error = error; - api->ipc_conn_send_response(conn, &res, sizeof(res)); - -} - -/* - * Send requested event data to the application - */ -static void lib_evt_event_data_get(void *conn, void *message) -{ - struct lib_event_data res; - struct chan_event_list *cel; - struct event_data *edp; - int i; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(conn); - - - /* - * Deliver events in publish order within priority - */ - for (i = SA_EVT_HIGHEST_PRIORITY; i <= SA_EVT_LOWEST_PRIORITY; i++) { - if (!list_empty(&esip->esi_events[i])) { - cel = list_entry(esip->esi_events[i].next, struct chan_event_list, - cel_entry); - list_del(&cel->cel_entry); - list_init(&cel->cel_entry); - esip->esi_nevents--; - if (esip->esi_queue_blocked && - (esip->esi_nevents < evt_delivery_queue_resume)) { - esip->esi_queue_blocked = 0; - log_printf(LOG_LEVEL_DEBUG, "unblock\n"); - } - edp = cel->cel_event; - edp->ed_event.led_lib_channel_handle = cel->cel_chan_handle; - edp->ed_event.led_sub_id = cel->cel_sub_id; - edp->ed_event.led_head.id = MESSAGE_RES_EVT_EVENT_DATA; - edp->ed_event.led_head.error = SA_AIS_OK; - free(cel); - api->ipc_conn_send_response(conn, &edp->ed_event, - edp->ed_event.led_head.size); - free_event_data(edp); - goto data_get_done; - } - } - - res.led_head.size = sizeof(res.led_head); - res.led_head.id = MESSAGE_RES_EVT_EVENT_DATA; - res.led_head.error = SA_AIS_ERR_NOT_EXIST; - api->ipc_conn_send_response(conn, &res, res.led_head.size); - - /* - * See if there are any events that the app doesn't know about - * because the notify pipe was full. - */ -data_get_done: - if (esip->esi_nevents) { - __notify_event(conn); - } -} - -/* - * Scan the list of channels and remove the specified node. - */ -static void remove_chan_open_info(mar_uint32_t node_id) -{ - struct list_head *l, *nxt; - struct event_svr_channel_instance *eci; - - for (l = esc_head.next; l != &esc_head; l = nxt) { - nxt = l->next; - eci = list_entry(l, struct event_svr_channel_instance, esc_entry); - remove_open_count(eci, node_id); - - } -} - - -/* - * Called when there is a configuration change in the cluster. - * This function looks at any joiners and leavers and updates the evt - * node list. The node list is used to keep track of event IDs - * received for each node for the detection of duplicate events. - */ -static void evt_conf_change( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id) -{ - log_printf(RECOVERY_DEBUG, "Evt conf change %d\n", - configuration_type); - log_printf(RECOVERY_DEBUG, "m %d, j %d, l %d\n", - member_list_entries, - joined_list_entries, - left_list_entries); - - /* - * Save the various membership lists for later processing by - * the synchronization functions. The left list is only - * valid in the transitional configuration, the joined list is - * only valid in the regular configuration. Other than for the - * purposes of delivering retained events from merging partitions, - * we only care about the final membership from the regular - * configuration. - */ - if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) { - - left_member_count = left_list_entries; - trans_member_count = member_list_entries; - - if (left_member_list) { - free(left_member_list); - left_member_list = 0; - } - if (left_list_entries) { - left_member_list = - malloc(sizeof(unsigned int) * left_list_entries); - if (!left_member_list) { - /* - * ERROR: No recovery. - */ - log_printf(LOG_LEVEL_ERROR, - "Config change left list allocation error\n"); - assert(0); - } - memcpy(left_member_list, left_list, - sizeof(unsigned int) * left_list_entries); - } - - if (trans_member_list) { - free(trans_member_list); - trans_member_list = 0; - } - if (member_list_entries) { - trans_member_list = - malloc(sizeof(unsigned int) * member_list_entries); - - if (!trans_member_list) { - /* - * ERROR: No recovery. - */ - log_printf(LOG_LEVEL_ERROR, - "Config change transitional member list allocation error\n"); - assert(0); - } - memcpy(trans_member_list, member_list, - sizeof(unsigned int) * member_list_entries); - } - } - - if (configuration_type == TOTEM_CONFIGURATION_REGULAR) { - - joined_member_count = joined_list_entries; - total_member_count = member_list_entries; - - if (joined_member_list) { - free(joined_member_list); - joined_member_list = 0; - } - if (joined_list_entries) { - joined_member_list = - malloc(sizeof(unsigned int) * joined_list_entries); - if (!joined_member_list) { - /* - * ERROR: No recovery. - */ - log_printf(LOG_LEVEL_ERROR, - "Config change joined list allocation error\n"); - assert(0); - } - memcpy(joined_member_list, joined_list, - sizeof(unsigned int) * joined_list_entries); - } - - - if (current_member_list) { - free(current_member_list); - current_member_list = 0; - } - if (member_list_entries) { - current_member_list = - malloc(sizeof(unsigned int) * member_list_entries); - - if (!current_member_list) { - /* - * ERROR: No recovery. - */ - log_printf(LOG_LEVEL_ERROR, - "Config change member list allocation error\n"); - assert(0); - } - memcpy(current_member_list, member_list, - sizeof(unsigned int) * member_list_entries); - } - } -} - -/* - * saEvtFinalize Handler - */ -static int evt_lib_exit(void *conn) -{ - - struct event_svr_channel_open *eco; - struct list_head *l, *nxt; - struct open_chan_pending *ocp; - struct unlink_chan_pending *ucp; - struct retention_time_clear_pending *rtc; - struct libevt_pd *esip = - api->ipc_private_data_get(api->ipc_conn_partner_get(conn)); - - log_printf(LOG_LEVEL_DEBUG, "saEvtFinalize (Event exit request)\n"); - log_printf(LOG_LEVEL_DEBUG, "saEvtFinalize %d evts on list\n", - esip->esi_nevents); - - /* - * Clean up any open channels and associated subscriptions. - */ - for (l = esip->esi_open_chans.next; l != &esip->esi_open_chans; l = nxt) { - nxt = l->next; - eco = list_entry(l, struct event_svr_channel_open, eco_instance_entry); - common_chan_close(eco, esip); - hdb_handle_destroy(&esip->esi_hdb, eco->eco_my_handle); - } - - /* - * Clean up any pending async operations - */ - for (l = open_pending.next; l != &open_pending; l = nxt) { - nxt = l->next; - ocp = list_entry(l, struct open_chan_pending, ocp_entry); - if (esip == api->ipc_private_data_get(ocp->ocp_conn)) { - list_del(&ocp->ocp_entry); - free(ocp); - } - } - - for (l = unlink_pending.next; l != &unlink_pending; l = nxt) { - nxt = l->next; - ucp = list_entry(l, struct unlink_chan_pending, ucp_entry); - if (esip == api->ipc_private_data_get(ucp->ucp_conn)) { - list_del(&ucp->ucp_entry); - free(ucp); - } - } - - for (l = clear_pending.next; - l != &clear_pending; l = nxt) { - nxt = l->next; - rtc = list_entry(l, struct retention_time_clear_pending, rtc_entry); - if (esip == api->ipc_private_data_get(rtc->rtc_conn)) { - list_del(&rtc->rtc_entry); - free(rtc); - } - } - - /* - * Destroy the open channel handle database - */ - hdb_destroy(&esip->esi_hdb); - - return 0; -} - -/* - * Called at service start time. - */ -static int evt_exec_init(struct corosync_api_v1 *corosync_api) -{ - unsigned int object_service_handle; - unsigned int object_find_handle; - char *value; - - api = corosync_api; - - log_printf(LOG_LEVEL_DEBUG, "Evt exec init request\n"); - - api->object_find_create ( - OBJECT_PARENT_HANDLE, - "event", - strlen ("event"), - &object_find_handle); - - if (api->object_find_next ( - object_find_handle, - &object_service_handle) == 0) { - - value = NULL; - if ( !api->object_key_get (object_service_handle, - "delivery_queue_size", - strlen ("delivery_queue_size"), - (void *)&value, - NULL) && value) { - evt_delivery_queue_size = atoi(value); - log_printf(LOG_LEVEL_NOTICE, - "event delivery_queue_size set to %u\n", - evt_delivery_queue_size); - } - value = NULL; - if ( !api->object_key_get (object_service_handle, - "delivery_queue_resume", - strlen ("delivery_queue_resume"), - (void *)&value, - NULL) && value) { - evt_delivery_queue_resume = atoi(value); - log_printf(LOG_LEVEL_NOTICE, - "event delivery_queue_resume set to %u\n", - evt_delivery_queue_size); - } - } - - /* - * Create an event to be sent when we have to drop messages - * for an application. - */ - dropped_event_size = sizeof(*dropped_event) + sizeof(dropped_pattern); - dropped_event = malloc(dropped_event_size); - if (dropped_event == 0) { - log_printf(LOG_LEVEL_ERROR, - "Memory Allocation Failure, event service not started\n"); - errno = ENOMEM; - return -1; - } - memset(dropped_event, 0, sizeof(*dropped_event) + sizeof(dropped_pattern)); - dropped_event->ed_ref_count = 1; - list_init(&dropped_event->ed_retained); - dropped_event->ed_event.led_head.size = - sizeof(*dropped_event) + sizeof(dropped_pattern); - dropped_event->ed_event.led_head.error = SA_AIS_OK; - dropped_event->ed_event.led_priority = SA_EVT_HIGHEST_PRIORITY; - dropped_event->ed_event.led_chan_name = lost_chan; - dropped_event->ed_event.led_publisher_name = dropped_publisher; - dropped_event->ed_event.led_patterns_number = 1; - memcpy(&dropped_event->ed_event.led_body[0], - &dropped_pattern, sizeof(dropped_pattern)); - return 0; -} - -static int -try_deliver_event(struct event_data *evt, - struct event_svr_channel_instance *eci) -{ - struct list_head *l, *l1; - struct event_svr_channel_open *eco; - struct event_svr_channel_subscr *ecs; - int delivered_event = 0; - /* - * Check open channels - */ - for (l = eci->esc_open_chans.next; l != &eci->esc_open_chans; l = l->next) { - eco = list_entry(l, struct event_svr_channel_open, eco_entry); - /* - * See if enabled to receive - */ - if (!(eco->eco_flags & SA_EVT_CHANNEL_SUBSCRIBER)) { - continue; - } - - /* - * Check subscriptions - */ - for (l1 = eco->eco_subscr.next; l1 != &eco->eco_subscr; l1 = l1->next) { - ecs = list_entry(l1, struct event_svr_channel_subscr, ecs_entry); - /* - * Apply filter rules and deliver if patterns - * match filters. - * Only deliver one event per open channel - */ - if (event_match(evt, ecs) == SA_AIS_OK) { - deliver_event(evt, eco, ecs); - delivered_event++; - break; - } - } - } - return delivered_event; -} - -/* - * Receive the network event message and distribute it to local subscribers - */ -static void evt_remote_evt(void *msg, unsigned int nodeid) -{ - /* - * - retain events that have a retention time - * - Find assocated channel - * - Scan list of subscribers - * - Apply filters - * - Deliver events that pass the filter test - */ - struct lib_event_data *evtpkt = msg; - struct event_svr_channel_instance *eci; - struct event_data *evt; - SaClmClusterNodeT *cn; - - log_printf(LOG_LEVEL_DEBUG, "Remote event data received from nodeid %s\n", - api->totem_ifaces_print (nodeid)); - - /* - * See where the message came from so that we can set the - * publishing node id in the message before delivery. - */ -#ifdef TODO - cn = main_clm_get_by_nodeid(nodeid); - if (!cn) { - /* - * Not sure how this can happen... - */ - log_printf(LOG_LEVEL_DEBUG, "No cluster node data for nodeid %s\n", - api->totem_ifaces_print (nodeid)); - errno = ENXIO; - return; - } - log_printf(LOG_LEVEL_DEBUG, "Cluster node ID %s name %s\n", - api->totem_ifaces_print (cn->nodeId), cn->nodeName.value); - - evtpkt->led_publisher_node_id = nodeid; - evtpkt->led_nodeid = nodeid; - evtpkt->led_receive_time = clust_time_now(); -#endif - - if (evtpkt->led_chan_unlink_id != EVT_CHAN_ACTIVE) { - log_printf(CHAN_UNLINK_DEBUG, - "evt_remote_evt(0): chan %s, id 0x%llx\n", - evtpkt->led_chan_name.value, - (unsigned long long)evtpkt->led_chan_unlink_id); - } - eci = find_channel(&evtpkt->led_chan_name, evtpkt->led_chan_unlink_id); - /* - * We may have had some events that were already queued when an - * unlink happened, if we don't find the channel in the active list - * look for the last unlinked channel of the same name. If this channel - * is re-opened the messages will still be routed correctly because new - * active channel messages will be ordered behind the open. - */ - if (!eci && (evtpkt->led_chan_unlink_id == EVT_CHAN_ACTIVE)) { - log_printf(CHAN_UNLINK_DEBUG, - "evt_remote_evt(1): chan %s, id 0x%llx\n", - evtpkt->led_chan_name.value, - (unsigned long long)evtpkt->led_chan_unlink_id); - eci = find_last_unlinked_channel(&evtpkt->led_chan_name); - } - - /* - * We shouldn't normally see an event for a channel that we - * don't know about. - */ - if (!eci) { - log_printf(LOG_LEVEL_DEBUG, "Channel %s doesn't exist\n", - evtpkt->led_chan_name.value); - return; - } - - if (check_last_event(evtpkt, nodeid)) { - return; - } - - evt = make_local_event(evtpkt, eci); - if (!evt) { - log_printf(LOG_LEVEL_WARNING, - "1Memory allocation error, can't deliver event\n"); - return; - } - - if (evt->ed_event.led_retention_time) { - retain_event(evt); - } - - try_deliver_event(evt, eci); - free_event_data(evt); -} - -/* - * Calculate the remaining retention time of a received event during recovery - */ -inline mar_time_t calc_retention_time(mar_time_t retention, - mar_time_t received, mar_time_t now) -{ - if ((received < now) && ((now - received) < retention)) { - return retention - (now - received); - } else { - return 0; - } -} - -/* - * Receive a recovery network event message and save it in the retained list - */ -static void evt_remote_recovery_evt(void *msg, unsigned int nodeid) -{ - /* - * - calculate remaining retention time - * - Find assocated channel - * - Scan list of subscribers - * - Apply filters - * - Deliver events that pass the filter test - */ - struct lib_event_data *evtpkt = msg; - struct event_svr_channel_instance *eci; - struct event_data *evt; - struct member_node_data *md; - int num_delivered; - mar_time_t now; - - now = clust_time_now(); - - log_printf(RECOVERY_EVENT_DEBUG, - "Remote recovery event data received from nodeid %d\n", nodeid); - - if (recovery_phase == evt_recovery_complete) { - log_printf(RECOVERY_EVENT_DEBUG, - "Received recovery data, not in recovery mode\n"); - return; - } - - log_printf(RECOVERY_EVENT_DEBUG, - "Processing recovery of retained events\n"); - if (recovery_node) { - log_printf(RECOVERY_EVENT_DEBUG, "This node is the recovery node\n"); - } - - log_printf(RECOVERY_EVENT_DEBUG, "(1)EVT ID: %llx, Time: %llx\n", - (unsigned long long)evtpkt->led_event_id, - (unsigned long long)evtpkt->led_retention_time); - /* - * Calculate remaining retention time - */ - evtpkt->led_retention_time = calc_retention_time( - evtpkt->led_retention_time, - evtpkt->led_receive_time, - now); - - log_printf(RECOVERY_EVENT_DEBUG, - "(2)EVT ID: %llx, ret: %llx, rec: %llx, now: %llx\n", - (unsigned long long)evtpkt->led_event_id, - (unsigned long long)evtpkt->led_retention_time, - (unsigned long long)evtpkt->led_receive_time, - (unsigned long long)now); - - /* - * If we haven't seen this event yet and it has remaining time, process - * the event. - */ - if (!check_last_event(evtpkt, evtpkt->led_nodeid) && - evtpkt->led_retention_time) { - /* - * See where the message came from so that we can set the - * publishing node id in the message before delivery. - */ - md = evt_find_node(evtpkt->led_nodeid); - if (!md) { - /* - * Not sure how this can happen - */ - log_printf(LOG_LEVEL_NOTICE, "No node for nodeid %s\n", - api->totem_ifaces_print (evtpkt->led_nodeid)); - return; - } - log_printf(LOG_LEVEL_DEBUG, "Cluster node ID %s name %s\n", - api->totem_ifaces_print (md->mn_node_info.nodeId), - md->mn_node_info.nodeName.value); - - log_printf(CHAN_UNLINK_DEBUG, - "evt_recovery_event: chan %s, id 0x%llx\n", - evtpkt->led_chan_name.value, - (unsigned long long)evtpkt->led_chan_unlink_id); - eci = find_channel(&evtpkt->led_chan_name, evtpkt->led_chan_unlink_id); - - /* - * We shouldn't normally see an event for a channel that we don't - * know about. - */ - if (!eci) { - log_printf(RECOVERY_EVENT_DEBUG, "Channel %s doesn't exist\n", - evtpkt->led_chan_name.value); - return; - } - - evt = make_local_event(evtpkt, eci); - if (!evt) { - log_printf(LOG_LEVEL_WARNING, - "2Memory allocation error, can't deliver event\n"); - errno = ENOMEM; - return; - } - - retain_event(evt); - num_delivered = try_deliver_event(evt, eci); - log_printf(RECOVERY_EVENT_DEBUG, "Delivered to %d subscribers\n", - num_delivered); - free_event_data(evt); - } -} - - -/* - * Timeout handler for event channel open. We flag the structure - * as timed out. Then if the open request is ever returned, we can - * issue a close channel and keep the reference counting correct. - */ -static void chan_open_timeout(void *data) -{ - struct open_chan_pending *ocp = (struct open_chan_pending *)data; - struct res_evt_channel_open res; - - res.ico_head.size = sizeof(res); - res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL; - res.ico_head.error = SA_AIS_ERR_TIMEOUT; - ocp->ocp_invocation = OPEN_TIMED_OUT; - api->ipc_conn_send_response(ocp->ocp_conn, &res, sizeof(res)); -} - -/* - * Called by the channel open exec handler to finish the open and - * respond to the application - */ -static void evt_chan_open_finish(struct open_chan_pending *ocp, - struct event_svr_channel_instance *eci) -{ - struct event_svr_channel_open *eco; - SaAisErrorT error = SA_AIS_OK; - unsigned int ret = 0; - unsigned int timer_del_status = 0; - void *ptr = 0; - uint32_t handle = 0; - struct libevt_pd *esip; - - esip = (struct libevt_pd *)api->ipc_private_data_get(ocp->ocp_conn); - - log_printf(CHAN_OPEN_DEBUG, "Open channel finish %s\n", - get_mar_name_t(&ocp->ocp_chan_name)); - if (ocp->ocp_timer_handle) { - api->timer_delete (ocp->ocp_timer_handle); - } - - /* - * If this is a finished open for a timed out request, then - * send out a close on this channel to clean things up. - */ - if (ocp->ocp_invocation == OPEN_TIMED_OUT) { - log_printf(CHAN_OPEN_DEBUG, "Closing timed out open of %s\n", - get_mar_name_t(&ocp->ocp_chan_name)); - error = evt_close_channel(&ocp->ocp_chan_name, EVT_CHAN_ACTIVE); - if (error != SA_AIS_OK) { - log_printf(CHAN_OPEN_DEBUG, - "Close of timed out open failed for %s\n", - get_mar_name_t(&ocp->ocp_chan_name)); - } - list_del(&ocp->ocp_entry); - free(ocp); - return; - } - - /* - * Create a handle to give back to the caller to associate - * with this channel open instance. - */ - ret = hdb_handle_create(&esip->esi_hdb, sizeof(*eco), &handle); - if (ret != 0) { - goto open_return; - } - ret = hdb_handle_get(&esip->esi_hdb, handle, &ptr); - if (ret != 0) { - goto open_return; - } - eco = ptr; - - /* - * Initailize and link into the global channel structure. - */ - list_init(&eco->eco_subscr); - list_init(&eco->eco_entry); - list_init(&eco->eco_instance_entry); - eco->eco_flags = ocp->ocp_open_flag; - eco->eco_channel = eci; - eco->eco_lib_handle = ocp->ocp_c_handle; - eco->eco_my_handle = handle; - eco->eco_conn = ocp->ocp_conn; - list_add_tail(&eco->eco_entry, &eci->esc_open_chans); - list_add_tail(&eco->eco_instance_entry, &esip->esi_open_chans); - - /* - * respond back with a handle to access this channel - * open instance for later subscriptions, etc. - */ - hdb_handle_put(&esip->esi_hdb, handle); - -open_return: - log_printf(CHAN_OPEN_DEBUG, "Open channel finish %s send response %d\n", - get_mar_name_t(&ocp->ocp_chan_name), - error); - if (ocp->ocp_async) { - struct res_evt_open_chan_async resa; - resa.ica_head.size = sizeof(resa); - resa.ica_head.id = MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK; - resa.ica_head.error = (ret == 0 ? SA_AIS_OK: SA_AIS_ERR_BAD_HANDLE); - resa.ica_channel_handle = handle; - resa.ica_c_handle = ocp->ocp_c_handle; - resa.ica_invocation = ocp->ocp_invocation; - api->ipc_conn_send_response(api->ipc_conn_partner_get(ocp->ocp_conn), - &resa, sizeof(resa)); - } else { - struct res_evt_channel_open res; - res.ico_head.size = sizeof(res); - res.ico_head.id = MESSAGE_RES_EVT_OPEN_CHANNEL; - res.ico_head.error = (ret == 0 ? SA_AIS_OK : SA_AIS_ERR_BAD_HANDLE); - res.ico_channel_handle = handle; - api->ipc_conn_send_response(ocp->ocp_conn, &res, sizeof(res)); - } - - if (timer_del_status == 0) { - list_del(&ocp->ocp_entry); - free(ocp); - } -} - -/* - * Called by the channel unlink exec handler to - * respond to the application. - */ -static void evt_chan_unlink_finish(struct unlink_chan_pending *ucp) -{ - struct res_evt_channel_unlink res; - - log_printf(CHAN_UNLINK_DEBUG, "Unlink channel finish ID 0x%llx\n", - (unsigned long long)ucp->ucp_unlink_id); - - list_del(&ucp->ucp_entry); - - res.iuc_head.size = sizeof(res); - res.iuc_head.id = MESSAGE_RES_EVT_UNLINK_CHANNEL; - res.iuc_head.error = SA_AIS_OK; - api->ipc_conn_send_response(ucp->ucp_conn, &res, sizeof(res)); - - free(ucp); -} - -/* - * Called by the retention time clear exec handler to - * respond to the application. - */ -static void evt_ret_time_clr_finish(struct retention_time_clear_pending *rtc, - SaAisErrorT ret) -{ - struct res_evt_event_clear_retentiontime res; - - log_printf(RETENTION_TIME_DEBUG, "Retention Time Clear finish ID 0x%llx\n", - (unsigned long long)rtc->rtc_event_id); - - res.iec_head.size = sizeof(res); - res.iec_head.id = MESSAGE_RES_EVT_CLEAR_RETENTIONTIME; - res.iec_head.error = ret; - api->ipc_conn_send_response(rtc->rtc_conn, &res, sizeof(res)); - - list_del(&rtc->rtc_entry); - free(rtc); -} - -/* - * Take the channel command data and swap the elements so they match - * our architectures word order. - */ -static void -convert_chan_packet(void *msg) -{ - struct req_evt_chan_command *cpkt = (struct req_evt_chan_command *)msg; - - /* - * converted in the main deliver_fn: - * led_head.id, led_head.size. - * - */ - - cpkt->chc_op = swab32(cpkt->chc_op); - - /* - * Which elements of the packet that are converted depend - * on the operation. - */ - switch (cpkt->chc_op) { - - case EVT_OPEN_CHAN_OP: - swab_mar_name_t (&cpkt->u.chc_chan.ocr_name); - cpkt->u.chc_chan.ocr_serial_no = swab64(cpkt->u.chc_chan.ocr_serial_no); - break; - - case EVT_UNLINK_CHAN_OP: - case EVT_CLOSE_CHAN_OP: - swab_mar_name_t (&cpkt->u.chcu.chcu_name); - cpkt->u.chcu.chcu_unlink_id = swab64(cpkt->u.chcu.chcu_unlink_id); - break; - - case EVT_CLEAR_RET_OP: - cpkt->u.chc_event_id = swab64(cpkt->u.chc_event_id); - break; - - case EVT_SET_ID_OP: - cpkt->u.chc_set_id.chc_nodeid = - swab32(cpkt->u.chc_set_id.chc_nodeid); - cpkt->u.chc_set_id.chc_last_id = swab64(cpkt->u.chc_set_id.chc_last_id); - break; - - case EVT_OPEN_COUNT: - swab_mar_name_t (&cpkt->u.chc_set_opens.chc_chan_name); - cpkt->u.chc_set_opens.chc_open_count = - swab32(cpkt->u.chc_set_opens.chc_open_count); - break; - - /* - * No data assocaited with these ops. - */ - case EVT_CONF_DONE: - case EVT_OPEN_COUNT_DONE: - break; - - /* - * Make sure that this function is updated when new ops are added. - */ - default: - assert(0); - } -} - - -/* - * Receive and process remote event operations. - * Used to communicate channel opens/closes, clear retention time, - * config change updates... - */ -static void evt_remote_chan_op(void *msg, unsigned int nodeid) -{ - struct req_evt_chan_command *cpkt = msg; - unsigned int local_node = {SA_CLM_LOCAL_NODE_ID}; - SaClmClusterNodeT *cn, *my_node; - struct member_node_data *mn; - struct event_svr_channel_instance *eci; - -#ifdef TODO - log_printf(REMOTE_OP_DEBUG, "Remote channel operation request\n"); - my_node = main_clm_get_by_nodeid(local_node); - log_printf(REMOTE_OP_DEBUG, "my node ID: 0x%x\n", my_node->nodeId); - - mn = evt_find_node(nodeid); - if (mn == NULL) { - cn = main_clm_get_by_nodeid(nodeid); - if (cn == NULL) { - log_printf(LOG_LEVEL_WARNING, - "Evt remote channel op: Node data for nodeid %d is NULL\n", - nodeid); - return; - } else { - evt_add_node(nodeid, cn); - mn = evt_find_node(nodeid); - } - } -#endif - - switch (cpkt->chc_op) { - /* - * Open channel remote command. The open channel request is done - * in two steps. When an pplication tries to open, we send an open - * channel message to the other nodes. When we receive an open channel - * message, we may create the channel structure if it doesn't exist - * and also complete applicaiton open requests for the specified - * channel. We keep a counter of total opens for the given channel and - * later when it has been completely closed (everywhere in the cluster) - * we will free up the assocated channel data. - */ - case EVT_OPEN_CHAN_OP: { - struct open_chan_pending *ocp; - struct list_head *l, *nxt; - - log_printf(CHAN_OPEN_DEBUG, "Opening channel %s for node %s\n", - cpkt->u.chc_chan.ocr_name.value, - api->totem_ifaces_print (mn->mn_node_info.nodeId)); - eci = find_channel(&cpkt->u.chc_chan.ocr_name, EVT_CHAN_ACTIVE); - - if (!eci) { - eci = create_channel(&cpkt->u.chc_chan.ocr_name); - } - if (!eci) { - log_printf(LOG_LEVEL_WARNING, "Could not create channel %s\n", - get_mar_name_t(&cpkt->u.chc_chan.ocr_name)); - break; - } - - inc_open_count(eci, mn->mn_node_info.nodeId); - - if (mn->mn_node_info.nodeId == my_node->nodeId) { - /* - * Complete one of our pending open requests - */ - for (l = open_pending.next; l != &open_pending; l = nxt) { - nxt = l->next; - ocp = list_entry(l, struct open_chan_pending, ocp_entry); - log_printf(CHAN_OPEN_DEBUG, - "Compare channel req no %llu %llu\n", - (unsigned long long)ocp->ocp_serial_no, - (unsigned long long)cpkt->u.chc_chan.ocr_serial_no); - if (ocp->ocp_serial_no == cpkt->u.chc_chan.ocr_serial_no) { - evt_chan_open_finish(ocp, eci); - break; - } - } - } - log_printf(CHAN_OPEN_DEBUG, - "Open channel %s t %d, l %d, r %d\n", - get_mar_name_t(&eci->esc_channel_name), - eci->esc_total_opens, eci->esc_local_opens, - eci->esc_retained_count); - break; - } - - /* - * Handle a channel close. We'll decrement the global open counter and - * free up channel associated data when all instances are closed. - */ - case EVT_CLOSE_CHAN_OP: - log_printf(LOG_LEVEL_DEBUG, "Closing channel %s for node 0x%x\n", - cpkt->u.chcu.chcu_name.value, mn->mn_node_info.nodeId); - eci = find_channel(&cpkt->u.chcu.chcu_name, cpkt->u.chcu.chcu_unlink_id); - if (!eci) { - log_printf(LOG_LEVEL_NOTICE, - "Channel close request for %s not found\n", - cpkt->u.chcu.chcu_name.value); - break; - } - - /* - * if last instance, we can free up assocated data. - */ - dec_open_count(eci, mn->mn_node_info.nodeId); - log_printf(LOG_LEVEL_DEBUG, - "Close channel %s t %d, l %d, r %d\n", - eci->esc_channel_name.value, - eci->esc_total_opens, eci->esc_local_opens, - eci->esc_retained_count); - delete_channel(eci); - break; - - /* - * Handle a request for channel unlink saEvtChannelUnlink(). - * We'll look up the channel and mark it as unlinked. Respond to - * local library unlink commands. - */ - case EVT_UNLINK_CHAN_OP: { - struct unlink_chan_pending *ucp; - struct list_head *l, *nxt; - - log_printf(CHAN_UNLINK_DEBUG, - "Unlink request channel %s unlink ID 0x%llx from node 0x%x\n", - cpkt->u.chcu.chcu_name.value, - (unsigned long long)cpkt->u.chcu.chcu_unlink_id, - mn->mn_node_info.nodeId); - - - /* - * look up the channel name and get its assoicated data. - */ - eci = find_channel(&cpkt->u.chcu.chcu_name, - EVT_CHAN_ACTIVE); - if (!eci) { - log_printf(LOG_LEVEL_NOTICE, - "Channel unlink request for %s not found\n", - cpkt->u.chcu.chcu_name.value); - } else { - /* - * Mark channel as unlinked. - */ - unlink_channel(eci, cpkt->u.chcu.chcu_unlink_id); - } - - /* - * respond only to local library requests. - */ - if (mn->mn_node_info.nodeId == my_node->nodeId) { - /* - * Complete one of our pending unlink requests - */ - for (l = unlink_pending.next; l != &unlink_pending; l = nxt) { - nxt = l->next; - ucp = list_entry(l, struct unlink_chan_pending, ucp_entry); - log_printf(CHAN_UNLINK_DEBUG, - "Compare channel id 0x%llx 0x%llx\n", - (unsigned long long)ucp->ucp_unlink_id, - (unsigned long long)cpkt->u.chcu.chcu_unlink_id); - if (ucp->ucp_unlink_id == cpkt->u.chcu.chcu_unlink_id) { - evt_chan_unlink_finish(ucp); - break; - } - } - } - break; - } - - - /* - * saEvtClearRetentionTime handler. - */ - case EVT_CLEAR_RET_OP: - { - SaAisErrorT did_clear; - struct retention_time_clear_pending *rtc; - struct list_head *l, *nxt; - - log_printf(RETENTION_TIME_DEBUG, "Clear retention time request %llx\n", - (unsigned long long)cpkt->u.chc_event_id); - did_clear = clear_retention_time(cpkt->u.chc_event_id); - - /* - * Respond to local library requests - */ - if (mn->mn_node_info.nodeId == my_node->nodeId) { - /* - * Complete pending request - */ - for (l = clear_pending.next; l != &clear_pending; l = nxt) { - nxt = l->next; - rtc = list_entry(l, struct retention_time_clear_pending, - rtc_entry); - if (rtc->rtc_event_id == cpkt->u.chc_event_id) { - evt_ret_time_clr_finish(rtc, did_clear); - break; - } - } - } - break; - } - - /* - * Set our next event ID based on the largest event ID seen - * by others in the cluster. This way, if we've left and re-joined, we'll - * start using an event ID that is unique. - */ - case EVT_SET_ID_OP: { - int log_level = LOG_LEVEL_DEBUG; - if (cpkt->u.chc_set_id.chc_nodeid == my_node->nodeId) { - log_level = RECOVERY_DEBUG; - } - log_printf(log_level, - "Received Set event ID OP from nodeid %x to %llx for %x my addr %s base %llx\n", - nodeid, - (unsigned long long)cpkt->u.chc_set_id.chc_last_id, - cpkt->u.chc_set_id.chc_nodeid, - api->totem_ifaces_print (my_node->nodeId), - (unsigned long long)base_id); - if (cpkt->u.chc_set_id.chc_nodeid == my_node->nodeId) { - if (cpkt->u.chc_set_id.chc_last_id >= base_id) { - log_printf(RECOVERY_DEBUG, - "Set event ID from nodeid %s to %llx\n", - api->totem_ifaces_print (nodeid), - (unsigned long long)cpkt->u.chc_set_id.chc_last_id); - base_id = cpkt->u.chc_set_id.chc_last_id + 1; - } - } - break; - } - - /* - * Receive the open count for a particular channel during recovery. - * This insures that everyone has the same notion of who has a channel - * open so that it can be removed when no one else has it open anymore. - */ - case EVT_OPEN_COUNT: - if (recovery_phase == evt_recovery_complete) { - log_printf(LOG_LEVEL_ERROR, - "Evt open count msg from nodeid %s, but not in membership change\n", - api->totem_ifaces_print (nodeid)); - } - - /* - * Zero out all open counts because we're setting then based - * on each nodes local counts. - */ - if (!processed_open_counts) { - zero_chan_open_counts(); - processed_open_counts = 1; - } - log_printf(RECOVERY_DEBUG, - "Open channel count %s is %d for node %s\n", - cpkt->u.chc_set_opens.chc_chan_name.value, - cpkt->u.chc_set_opens.chc_open_count, - api->totem_ifaces_print (mn->mn_node_info.nodeId)); - - eci = find_channel(&cpkt->u.chc_set_opens.chc_chan_name, - EVT_CHAN_ACTIVE); - if (!eci) { - eci = create_channel(&cpkt->u.chc_set_opens.chc_chan_name); - } - if (!eci) { - log_printf(LOG_LEVEL_WARNING, "Could not create channel %s\n", - get_mar_name_t(&cpkt->u.chc_set_opens.chc_chan_name)); - break; - } - if (set_open_count(eci, mn->mn_node_info.nodeId, - cpkt->u.chc_set_opens.chc_open_count)) { - log_printf(LOG_LEVEL_ERROR, - "Error setting Open channel count %s for node %s\n", - cpkt->u.chc_set_opens.chc_chan_name.value, - api->totem_ifaces_print (mn->mn_node_info.nodeId)); - } - break; - - /* - * Once we get all the messages from - * the current membership, determine who delivers any retained events. - */ - case EVT_OPEN_COUNT_DONE: { - if (recovery_phase == evt_recovery_complete) { - log_printf(LOG_LEVEL_ERROR, - "Evt config msg from nodeid %s, but not in membership change\n", - api->totem_ifaces_print (nodeid)); - } - log_printf(RECOVERY_DEBUG, - "Receive EVT_CONF_CHANGE_DONE from nodeid %s members %d checked in %d\n", - api->totem_ifaces_print (nodeid), total_member_count, checked_in+1); - if (!mn) { - log_printf(RECOVERY_DEBUG, - "NO NODE DATA AVAILABLE FOR nodeid %s\n", api->totem_ifaces_print (nodeid)); - } - - if (++checked_in == total_member_count) { - /* - * We're all here, now figure out who should send the - * retained events. - */ - mn = oldest_node(); - if (mn && mn->mn_node_info.nodeId == my_node_id) { - log_printf(RECOVERY_DEBUG, - "I am oldest in my transitional config\n"); - recovery_node = 1; - recovery_phase = evt_send_retained_events; - } else { - recovery_phase = evt_send_retained_events_done; - recovery_node = 0; - } - checked_in = 0; - } - break; - } - - /* - * Count up the nodes again, when all the nodes have responded, we've - * distributed the retained events and we're done with recovery and can - * continue operations. - */ - case EVT_CONF_DONE: { - log_printf(RECOVERY_DEBUG, - "Receive EVT_CONF_DONE from nodeid %s, members %d checked in %d\n", - api->totem_ifaces_print (nodeid), - total_member_count, checked_in+1); - if (++checked_in == total_member_count) { - /* - * All recovery complete, carry on. - */ - recovery_phase = evt_recovery_complete; -#ifdef DUMP_CHAN_INFO - dump_all_chans(); -#endif - } - - break; - } - - default: - log_printf(LOG_LEVEL_NOTICE, "Invalid channel operation %d\n", - cpkt->chc_op); - break; - } -} - -/* - * Set up initial conditions for processing event service - * recovery. - */ -static void evt_sync_init(void) -{ - SaClmClusterNodeT *cn; - struct member_node_data *md; - unsigned int my_node = {SA_CLM_LOCAL_NODE_ID}; - int left_list_entries = left_member_count; - unsigned int *left_list = left_member_list; - - log_printf(RECOVERY_DEBUG, "Evt synchronize initialization\n"); - - /* - * Set the base event id - */ - #ifdef TODO - if (!my_node_id) { - cn = main_clm_get_by_nodeid(my_node); - log_printf(RECOVERY_DEBUG, "My node ID %s\n", - api->totem_ifaces_print (cn->nodeId)); - my_node_id = cn->nodeId; - set_event_id(my_node_id); - } -#endif - - /* - * account for nodes that left the membership - */ - while (left_list_entries--) { - md = evt_find_node(*left_list); - if (md == 0) { - log_printf(LOG_LEVEL_WARNING, - "Can't find cluster node at %s\n", - api->totem_ifaces_print (*left_list)); - /* - * Mark this one as down. - */ - } else { - log_printf(RECOVERY_DEBUG, "cluster node at %s down\n", - api->totem_ifaces_print(*left_list)); - md->mn_started = 0; - remove_chan_open_info(md->mn_node_info.nodeId); - } - left_list++; - } - - /* - * set up for recovery processing, first phase: - */ - recovery_phase = evt_send_event_id; - - /* - * List used to distribute last know event IDs. - */ - add_list = current_member_list; - add_count = total_member_count; - processed_open_counts = 0; - - /* - * List used for distributing open channel counts - */ - next_chan = esc_head.next; - - /* - * List used for distributing retained events - */ - next_retained = retained_list.next; - - /* - * Member check in counts for open channel counts and - * retained events. - */ - checked_in = 0; -} - -/* - * Handle event service recovery. It passes through a number of states to - * finish the recovery. - * - * First, the node broadcasts the highest event ID that it has seen for any - * joinig node. This helps to make sure that rejoining nodes don't re-use - * event IDs that have already been seen. - * - * Next, The node broadcasts its open channel information to the other nodes. - * This makes sure that any joining nodes have complete data on any channels - * already open. - * - * Once done sending open channel information the node waits in a state for - * the rest of the nodes to finish sending their data. When the last node - * has checked in, then the remote channel operation handler selects the next - * state which is evt_send_retained_events if this is the oldest node in the - * cluster, or otherwise to evt_wait_send_retained_events to wait for the - * retained events to be sent. When the retained events have been sent, the - * state is changed to evt_recovery_complete and this function exits with - * zero to inidicate that recovery is done. - */ -static int evt_sync_process(void) -{ - - log_printf(RECOVERY_DEBUG, "Process Evt synchronization \n"); - - switch (recovery_phase) { - - /* - * Send last know event ID to joining nodes to prevent duplicate - * event IDs. - */ - case evt_send_event_id: - { - struct member_node_data *md; - SaClmClusterNodeT *cn; - struct req_evt_chan_command cpkt; - struct iovec chn_iovec; - int res; - - log_printf(RECOVERY_DEBUG, "Send max event ID updates\n"); - while (add_count) { - /* - * If we've seen this node before, send out the last msg ID - * that we've seen from him. He will set his base ID for - * generating event and message IDs to the highest one seen. - */ - md = evt_find_node(*add_list); - if (md != NULL) { - log_printf(RECOVERY_DEBUG, - "Send set evt ID %llx to %s\n", - (unsigned long long)md->mn_last_msg_id, - api->totem_ifaces_print (*add_list)); - md->mn_started = 1; - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE (EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_SET_ID_OP; - cpkt.u.chc_set_id.chc_nodeid = *add_list; - cpkt.u.chc_set_id.chc_last_id = md->mn_last_msg_id; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - res = api->totem_mcast(&chn_iovec, 1, TOTEM_AGREED); - if (res != 0) { - log_printf(RECOVERY_DEBUG, - "Unable to send event id to %s\n", - api->totem_ifaces_print (*add_list)); - /* - * We'll try again later. - */ - return 1; - } - - } else { - /* - * Not seen before, add it to our list of nodes. - */ -#ifdef TODO - cn = main_clm_get_by_nodeid(*add_list); - if (!cn) { - /* - * Error: shouldn't happen - */ - log_printf(LOG_LEVEL_ERROR, - "recovery error node: %s not found\n", - api->totem_ifaces_print (*add_list)); - assert(0); - } else { - evt_add_node(*add_list, cn); - } -#endif - } - - add_list++; - add_count--; - } - recovery_phase = evt_send_open_count; - return 1; - } - - /* - * Send channel open counts so all members have the same channel open - * counts. - */ - case evt_send_open_count: - { - struct req_evt_chan_command cpkt; - struct iovec chn_iovec; - struct event_svr_channel_instance *eci; - int res; - - log_printf(RECOVERY_DEBUG, "Send open count updates\n"); - /* - * Process messages. When we're done, send the done message - * to the nodes. - */ - memset(&cpkt, 0, sizeof(cpkt)); - for (;next_chan != &esc_head; - next_chan = next_chan->next) { - log_printf(RECOVERY_DEBUG, "Sending next open count\n"); - eci = list_entry(next_chan, struct event_svr_channel_instance, - esc_entry); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_OPEN_COUNT; - cpkt.u.chc_set_opens.chc_chan_name = eci->esc_channel_name; - cpkt.u.chc_set_opens.chc_open_count = eci->esc_local_opens; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - res = api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED); - - if (res != 0) { - /* - * Try again later. - */ - return 1; - } - } - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_OPEN_COUNT_DONE; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - res = api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED); - if (res != 0) { - /* - * Try again later. - */ - return 1; - } - log_printf(RECOVERY_DEBUG, "DONE Sending open counts\n"); - - recovery_phase = evt_wait_open_count_done; - return 1; - } - - /* - * Wait for all nodes to finish sending open updates before proceding. - * the EVT_OPEN_COUNT_DONE handler will set the state to - * evt_send_retained_events to get us out of this. - */ - case evt_wait_open_count_done: - { - log_printf(RECOVERY_DEBUG, "Wait for open count done\n"); - return 1; - } - - /* - * If I'm the oldest node, send out retained events so that new nodes - * have all the information. - */ - case evt_send_retained_events: - { - struct iovec chn_iovec; - struct event_data *evt; - int res; - - log_printf(RECOVERY_DEBUG, "Send retained event updates\n"); - - /* - * Process messages. When we're done, send the done message - * to the nodes. - */ - for (;next_retained != &retained_list; - next_retained = next_retained->next) { - log_printf(LOG_LEVEL_DEBUG, "Sending next retained event\n"); - evt = list_entry(next_retained, struct event_data, ed_retained); - evt->ed_event.led_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_RECOVERY_EVENTDATA); - chn_iovec.iov_base = (char *)&evt->ed_event; - chn_iovec.iov_len = evt->ed_event.led_head.size; - res = api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED); - - if (res != 0) { - /* - * Try again later. - */ - return -1; - } - } - - recovery_phase = evt_send_retained_events_done; - return 1; - } - - case evt_send_retained_events_done: - { - struct req_evt_chan_command cpkt; - struct iovec chn_iovec; - int res; - - log_printf(RECOVERY_DEBUG, "DONE Sending retained events\n"); - memset(&cpkt, 0, sizeof(cpkt)); - cpkt.chc_head.id = - SERVICE_ID_MAKE(EVT_SERVICE, MESSAGE_REQ_EXEC_EVT_CHANCMD); - cpkt.chc_head.size = sizeof(cpkt); - cpkt.chc_op = EVT_CONF_DONE; - chn_iovec.iov_base = (char *)&cpkt; - chn_iovec.iov_len = cpkt.chc_head.size; - res = api->totem_mcast (&chn_iovec, 1, TOTEM_AGREED); - - recovery_phase = evt_wait_send_retained_events; - return 1; - } - - /* - * Wait for send of retained events to finish - * the EVT_CONF_DONE handler will set the state to - * evt_recovery_complete to get us out of this. - */ - case evt_wait_send_retained_events: - { - log_printf(RECOVERY_DEBUG, "Wait for retained events\n"); - return 1; - } - - case evt_recovery_complete: - { - log_printf(RECOVERY_DEBUG, "Recovery complete\n"); - return 0; - } - - default: - log_printf(LOG_LEVEL_WARNING, "Bad recovery phase state: %u\n", - recovery_phase); - recovery_phase = evt_recovery_complete; - return 0; - } - - return 0; -} - -/* - * Not used at this time - */ -static void evt_sync_activate(void) -{ - log_printf(RECOVERY_DEBUG, "Evt synchronize activation\n"); -} - -/* - * Not used at this time - */ -static void evt_sync_abort(void) -{ - log_printf(RECOVERY_DEBUG, "Abort Evt synchronization\n"); -} - -/* - * vi: set autoindent tabstop=4 shiftwidth=4 : - */ diff --git a/openais/services/lck.c b/openais/services/lck.c deleted file mode 100644 index d4035a0d..00000000 --- a/openais/services/lck.c +++ /dev/null @@ -1,1632 +0,0 @@ -/* - * Copyright (c) 2005-2006 MontaVista Software, Inc. - * Copyright (c) 2006 Red Hat, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "../include/saAis.h" -#include "../include/saAis.h" -#include "../include/saLck.h" -#include "../include/ipc_lck.h" - -LOGSYS_DECLARE_SUBSYS ("LCK", LOG_INFO); - -enum lck_message_req_types { - MESSAGE_REQ_EXEC_LCK_RESOURCEOPEN = 0, - MESSAGE_REQ_EXEC_LCK_RESOURCECLOSE = 1, - MESSAGE_REQ_EXEC_LCK_RESOURCELOCK = 2, - MESSAGE_REQ_EXEC_LCK_RESOURCEUNLOCK = 3, - MESSAGE_REQ_EXEC_LCK_RESOURCELOCKORPHAN = 4, - MESSAGE_REQ_EXEC_LCK_LOCKPURGE = 5 -}; - -struct resource; -struct resource_lock { - SaLckLockModeT lock_mode; - SaLckLockIdT lock_id; - SaLckLockFlagsT lock_flags; - SaLckWaiterSignalT waiter_signal; - SaLckLockStatusT lock_status; - SaTimeT timeout; - struct resource *resource; - int async_call; - SaInvocationT invocation; - mar_message_source_t callback_source; - mar_message_source_t response_source; - struct list_head list; /* locked resource lock list */ - struct list_head resource_list; /* resource locks on a resource */ - struct list_head resource_cleanup_list; /* cleanup data for resource locks */ -}; - -struct resource { - mar_name_t name; - int refcount; - struct list_head list; - struct list_head resource_lock_list_head; - struct list_head pr_granted_list_head; - struct list_head pr_pending_list_head; - struct list_head ex_pending_list_head; - struct resource_lock *ex_granted; -}; - -struct resource_cleanup { - struct resource *resource; - SaLckResourceHandleT resource_handle; - struct list_head resource_lock_list_head; - struct list_head list; -}; - -DECLARE_LIST_INIT(resource_list_head); - -static int lck_exec_init_fn (struct corosync_api_v1 *); - -static int lck_lib_exit_fn (void *conn); - -static int lck_lib_init_fn (void *conn); - -static void message_handler_req_exec_lck_resourceopen ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_lck_resourceclose ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_lck_resourcelock ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_lck_resourceunlock ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_lck_resourcelockorphan ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_lck_lockpurge ( - void *message, - unsigned int nodeid); - -static void message_handler_req_lib_lck_resourceopen ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_resourceopenasync ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_resourceclose ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_resourcelock ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_resourcelockasync ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_resourceunlock ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_resourceunlockasync ( - void *conn, - void *msg); - -static void message_handler_req_lib_lck_lockpurge ( - void *conn, - void *msg); - -static void exec_lck_resourceopen_endian_convert (void *msg); - -static void exec_lck_resourceclose_endian_convert (void *msg); - -static void exec_lck_resourcelock_endian_convert (void *msg); - -static void exec_lck_resourceunlock_endian_convert (void *msg); - -static void exec_lck_resourcelockorphan_endian_convert (void *msg); - -static void exec_lck_lockpurge_endian_convert (void *msg); - -#ifdef TODO -static void lck_sync_init (void); -#endif -static int lck_sync_process (void); -static void lck_sync_activate (void); -static void lck_sync_abort (void); - -void resource_release (struct resource *resource); - -/* -static struct list_head *recovery_lck_next = 0; -static struct list_head *recovery_lck_section_next = 0; -static int recovery_section_data_offset = 0; -static int recovery_section_send_flag = 0; -static int recovery_abort = 0; -//static struct memb_ring_id saved_ring_id; -*/ - -static struct corosync_api_v1 *api; - -static void lck_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id); - -struct lck_pd { - struct list_head resource_list; - struct list_head resource_cleanup_list; -}; - - -/* - * Executive Handler Definition - */ -static struct corosync_lib_handler lck_lib_engine[] = -{ - { /* 0 */ - .lib_handler_fn = message_handler_req_lib_lck_resourceopen, - .response_size = sizeof (struct res_lib_lck_resourceopen), - .response_id = MESSAGE_RES_LCK_RESOURCEOPEN, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 1 */ - .lib_handler_fn = message_handler_req_lib_lck_resourceopenasync, - .response_size = sizeof (struct res_lib_lck_resourceopenasync), - .response_id = MESSAGE_RES_LCK_RESOURCEOPENASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 2 */ - .lib_handler_fn = message_handler_req_lib_lck_resourceclose, - .response_size = sizeof (struct res_lib_lck_resourceclose), - .response_id = MESSAGE_RES_LCK_RESOURCECLOSE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 3 */ - .lib_handler_fn = message_handler_req_lib_lck_resourcelock, - .response_size = sizeof (struct res_lib_lck_resourcelock), - .response_id = MESSAGE_RES_LCK_RESOURCELOCK, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 4 */ - .lib_handler_fn = message_handler_req_lib_lck_resourcelockasync, - .response_size = sizeof (struct res_lib_lck_resourcelockasync), - .response_id = MESSAGE_RES_LCK_RESOURCELOCKASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 5 */ - .lib_handler_fn = message_handler_req_lib_lck_resourceunlock, - .response_size = sizeof (struct res_lib_lck_resourceunlock), - .response_id = MESSAGE_RES_LCK_RESOURCELOCK, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 6 */ - .lib_handler_fn = message_handler_req_lib_lck_resourceunlockasync, - .response_size = sizeof (struct res_lib_lck_resourceunlock), - .response_id = MESSAGE_RES_LCK_RESOURCEUNLOCKASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 7 */ - .lib_handler_fn = message_handler_req_lib_lck_lockpurge, - .response_size = sizeof (struct res_lib_lck_lockpurge), - .response_id = MESSAGE_RES_LCK_LOCKPURGE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - } -}; - - -static struct corosync_exec_handler lck_exec_engine[] = { - { - .exec_handler_fn = message_handler_req_exec_lck_resourceopen, - .exec_endian_convert_fn = exec_lck_resourceopen_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_lck_resourceclose, - .exec_endian_convert_fn = exec_lck_resourceclose_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_lck_resourcelock, - .exec_endian_convert_fn = exec_lck_resourcelock_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_lck_resourceunlock, - .exec_endian_convert_fn = exec_lck_resourceunlock_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_lck_resourcelockorphan, - .exec_endian_convert_fn = exec_lck_resourcelockorphan_endian_convert - }, - { - .exec_handler_fn = message_handler_req_exec_lck_lockpurge, - .exec_endian_convert_fn = exec_lck_lockpurge_endian_convert - } -}; - -struct corosync_service_engine lck_service_engine = { - .name = "openais distributed locking service B.01.01", - .id = LCK_SERVICE, - .private_data_size = sizeof (struct lck_pd), - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED, - .lib_init_fn = lck_lib_init_fn, - .lib_exit_fn = lck_lib_exit_fn, - .lib_engine = lck_lib_engine, - .lib_engine_count = sizeof (lck_lib_engine) / sizeof (struct corosync_lib_handler), - .exec_init_fn = lck_exec_init_fn, - .exec_engine = lck_exec_engine, - .exec_engine_count = sizeof (lck_exec_engine) / sizeof (struct corosync_exec_handler), - .exec_dump_fn = NULL, - .confchg_fn = lck_confchg_fn, - .sync_init = NULL, -// .sync_init = lck_sync_init, - .sync_process = lck_sync_process, - .sync_activate = lck_sync_activate, - .sync_abort = lck_sync_abort, -}; - -/* - * Dynamic loader definition - */ -static struct corosync_service_engine *lck_get_engine_ver0 (void); - -static struct corosync_service_engine_iface_ver0 lck_service_engine_iface = { - .corosync_get_service_engine_ver0 = lck_get_engine_ver0 -}; - -static struct lcr_iface openais_lck_ver0[1] = { - { - .name = "openais_lck", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = (void **)(void *)&lck_service_engine_iface, - } -}; - -static struct lcr_comp lck_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_lck_ver0 -}; - -static struct corosync_service_engine *lck_get_engine_ver0 (void) -{ - return (&lck_service_engine); -} - -__attribute__ ((constructor)) static void register_this_component (void) { - lcr_interfaces_set (&openais_lck_ver0[0], &lck_service_engine_iface); - - lcr_component_register (&lck_comp_ver0); -} - -/* - * All data types used for executive messages - */ -struct req_exec_lck_resourceopen { - mar_req_header_t header; - mar_message_source_t source; - mar_name_t resource_name; - SaLckResourceHandleT resource_handle; - SaInvocationT invocation; - SaTimeT timeout; - SaLckResourceOpenFlagsT open_flags; - int async_call; - SaAisErrorT fail_with_error; -}; - -static void exec_lck_resourceopen_endian_convert (void *msg) -{ - struct req_exec_lck_resourceopen *to_swab = - (struct req_exec_lck_resourceopen *)msg; - - swab_mar_req_header_t (&to_swab->header); - swab_mar_message_source_t (&to_swab->source); - swab_mar_name_t (&to_swab->resource_name); - to_swab->resource_handle = swab64 (to_swab->resource_handle); - to_swab->invocation = swab64 (to_swab->invocation); - to_swab->timeout = swab64 (to_swab->timeout); - to_swab->open_flags = swab32 (to_swab->open_flags); - to_swab->async_call = swab32 (to_swab->async_call); - to_swab->fail_with_error = swab32 (to_swab->fail_with_error); -} - -struct req_exec_lck_resourceclose { - mar_req_header_t header; - mar_message_source_t source; - mar_name_t lockResourceName; - SaLckResourceHandleT resource_handle; -}; - -static void exec_lck_resourceclose_endian_convert (void *msg) -{ - struct req_exec_lck_resourceclose *to_swab = - (struct req_exec_lck_resourceclose *)msg; - - swab_mar_req_header_t (&to_swab->header); - swab_mar_message_source_t (&to_swab->source); - swab_mar_name_t (&to_swab->lockResourceName); - to_swab->resource_handle = swab64 (to_swab->resource_handle); -} - -struct req_exec_lck_resourcelock { - mar_req_header_t header; - SaLckResourceHandleT resource_handle; - SaInvocationT invocation; - int async_call; - SaAisErrorT fail_with_error; - mar_message_source_t source; - struct req_lib_lck_resourcelock req_lib_lck_resourcelock; -}; - -static void exec_lck_resourcelock_endian_convert (void *msg) -{ - struct req_exec_lck_resourcelock *to_swab = - (struct req_exec_lck_resourcelock *)msg; - - swab_mar_req_header_t (&to_swab->header); - to_swab->resource_handle = swab64 (to_swab->resource_handle); - to_swab->invocation = swab64 (to_swab->invocation); - to_swab->async_call = swab32 (to_swab->async_call); - to_swab->fail_with_error = swab32 (to_swab->fail_with_error); - swab_mar_message_source_t (&to_swab->source); - swab_req_lib_lck_resourcelock (&to_swab->req_lib_lck_resourcelock); -} - -struct req_exec_lck_resourceunlock { - mar_req_header_t header; - mar_message_source_t source; - mar_name_t resource_name; - SaLckLockIdT lock_id; - SaInvocationT invocation; - SaTimeT timeout; - int async_call; -}; - -static void exec_lck_resourceunlock_endian_convert (void *msg) -{ - struct req_exec_lck_resourceunlock *to_swab = - (struct req_exec_lck_resourceunlock *)msg; - - swab_mar_req_header_t (&to_swab->header); - swab_mar_message_source_t (&to_swab->source); - swab_mar_name_t (&to_swab->resource_name); - to_swab->lock_id = swab64 (to_swab->lock_id); - to_swab->invocation = swab64 (to_swab->invocation); - to_swab->timeout = swab64 (to_swab->timeout); - to_swab->async_call = swab32 (to_swab->async_call); -} - -struct req_exec_lck_resourcelockorphan { - mar_req_header_t header; - mar_message_source_t source; - mar_name_t resource_name; - SaLckLockIdT lock_id; -}; - -static void exec_lck_resourcelockorphan_endian_convert (void *msg) -{ - struct req_exec_lck_resourcelockorphan *to_swab = - (struct req_exec_lck_resourcelockorphan *)msg; - - swab_mar_req_header_t (&to_swab->header); - swab_mar_message_source_t (&to_swab->source); - swab_mar_name_t (&to_swab->resource_name); - to_swab->lock_id = swab64 (to_swab->lock_id); -} - -struct req_exec_lck_lockpurge { - mar_req_header_t header; - mar_message_source_t source; - struct req_lib_lck_lockpurge req_lib_lck_lockpurge; -}; - -static void exec_lck_lockpurge_endian_convert (void *msg) -{ - struct req_exec_lck_lockpurge *to_swab = - (struct req_exec_lck_lockpurge *)msg; - - swab_mar_req_header_t (&to_swab->header); - swab_mar_message_source_t (&to_swab->source); - swab_req_lib_lck_lockpurge (&to_swab->req_lib_lck_lockpurge); -} - -#ifdef TODO -static void lck_sync_init (void) -{ - return; -} -#endif - -static int lck_sync_process (void) -{ - return (0); -} - -static void lck_sync_activate (void) -{ - return; -} - -static void lck_sync_abort (void) -{ - return; -} - -static void lck_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id) -{ -} - -static struct resource *resource_find (mar_name_t *name) -{ - struct list_head *resource_list; - struct resource *resource; - - for (resource_list = resource_list_head.next; - resource_list != &resource_list_head; - resource_list = resource_list->next) { - - resource = list_entry (resource_list, - struct resource, list); - - if (mar_name_match (name, &resource->name)) { - return (resource); - } - } - return (0); -} - -static struct resource_lock *resource_lock_find ( - struct resource *resource, - mar_message_source_t *source, - SaLckLockIdT lock_id) -{ - struct list_head *list; - struct resource_lock *resource_lock; - - for (list = resource->resource_lock_list_head.next; - list != &resource->resource_lock_list_head; - list = list->next) { - - resource_lock = list_entry (list, struct resource_lock, resource_list); - - if ((memcmp (&resource_lock->callback_source, - source, sizeof (mar_message_source_t)) == 0) && - (lock_id == resource_lock->lock_id)) { - - return (resource_lock); - } - } - return (0); -} - -struct resource_cleanup *lck_resource_cleanup_find ( - void *conn, - SaLckResourceHandleT resource_handle) -{ - struct list_head *list; - struct resource_cleanup *resource_cleanup; - struct lck_pd *lck_pd = (struct lck_pd *)api->ipc_private_data_get (conn); - - for (list = lck_pd->resource_cleanup_list.next; - list != &lck_pd->resource_cleanup_list; list = list->next) { - - resource_cleanup = list_entry (list, struct resource_cleanup, list); - if (resource_cleanup->resource_handle == resource_handle) { - return (resource_cleanup); - } - } - return (0); -} - - -int lck_resource_close (struct resource *resource) -{ - struct req_exec_lck_resourceclose req_exec_lck_resourceclose; - struct iovec iovec; - - req_exec_lck_resourceclose.header.size = - sizeof (struct req_exec_lck_resourceclose); - req_exec_lck_resourceclose.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCECLOSE); - - memcpy (&req_exec_lck_resourceclose.lockResourceName, - &resource->name, sizeof (mar_name_t)); - - iovec.iov_base = (char *)&req_exec_lck_resourceclose; - iovec.iov_len = sizeof (req_exec_lck_resourceclose); - - if (api->totem_send_ok (&iovec, 1)) { - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); - return (0); - } - - return (-1); -} - -void resource_lock_orphan (struct resource_lock *resource_lock) -{ - struct req_exec_lck_resourcelockorphan req_exec_lck_resourcelockorphan; - struct iovec iovec; - - req_exec_lck_resourcelockorphan.header.size = - sizeof (struct req_exec_lck_resourcelockorphan); - req_exec_lck_resourcelockorphan.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCELOCKORPHAN); - - memcpy (&req_exec_lck_resourcelockorphan.source, - &resource_lock->callback_source, - sizeof (mar_message_source_t)); - - memcpy (&req_exec_lck_resourcelockorphan.resource_name, - &resource_lock->resource->name, - sizeof (mar_name_t)); - - req_exec_lck_resourcelockorphan.lock_id = resource_lock->lock_id; - - iovec.iov_base = (char *)&req_exec_lck_resourcelockorphan; - iovec.iov_len = sizeof (req_exec_lck_resourcelockorphan); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -void lck_resource_cleanup_lock_remove ( - struct resource_cleanup *resource_cleanup) -{ - struct list_head *list; - struct resource_lock *resource_lock; - - for (list = resource_cleanup->resource_lock_list_head.next; - list != &resource_cleanup->resource_lock_list_head; - list = list->next) { - - resource_lock = list_entry (list, struct resource_lock, resource_cleanup_list); - resource_lock_orphan (resource_lock); - } -} - -void lck_resource_cleanup_remove ( - void *conn, - SaLckResourceHandleT resource_handle) -{ - - struct list_head *list; - struct resource_cleanup *resource_cleanup; - struct lck_pd *lck_pd = (struct lck_pd *)api->ipc_private_data_get (conn); - - for (list = lck_pd->resource_cleanup_list.next; - list != &lck_pd->resource_cleanup_list; - list = list->next) { - - resource_cleanup = list_entry (list, struct resource_cleanup, list); - if (resource_cleanup->resource_handle == resource_handle) { - list_del (&resource_cleanup->list); - free (resource_cleanup); - return; - } - } -} - - -static int lck_exec_init_fn (struct corosync_api_v1 *corosync_api) -{ - api = corosync_api; - - /* - * Initialize the saved ring ID. - */ - return (0); -} - -static int lck_lib_exit_fn (void *conn) -{ - struct resource_cleanup *resource_cleanup; - struct list_head *cleanup_list; - struct lck_pd *lck_pd = (struct lck_pd *)api->ipc_private_data_get (conn); - - log_printf(LOG_LEVEL_NOTICE, "lck_exit_fn conn_info %p\n", conn); - - /* - * close all resources opened on this fd - */ - cleanup_list = lck_pd->resource_cleanup_list.next; - while (!list_empty(cleanup_list)) { - - resource_cleanup = list_entry (cleanup_list, struct resource_cleanup, list); - - if (resource_cleanup->resource->name.length > 0) { - lck_resource_cleanup_lock_remove (resource_cleanup); - lck_resource_close (resource_cleanup->resource); - } - - list_del (&resource_cleanup->list); - free (resource_cleanup); - - cleanup_list = lck_pd->resource_cleanup_list.next; - } - - return (0); -} - -static int lck_lib_init_fn (void *conn) -{ - struct lck_pd *lck_pd = (struct lck_pd *)api->ipc_private_data_get (conn); - - list_init (&lck_pd->resource_list); - list_init (&lck_pd->resource_cleanup_list); - return (0); -} - -static void message_handler_req_exec_lck_resourceopen ( - void *message, - unsigned int nodeid) -{ - struct req_exec_lck_resourceopen *req_exec_lck_resourceopen = (struct req_exec_lck_resourceopen *)message; - struct res_lib_lck_resourceopen res_lib_lck_resourceopen; - struct res_lib_lck_resourceopenasync res_lib_lck_resourceopenasync; - struct resource *resource; - struct resource_cleanup *resource_cleanup; - SaAisErrorT error = SA_AIS_OK; - struct lck_pd *lck_pd; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saLckResourceOpen %s\n", - get_mar_name_t (&req_exec_lck_resourceopen->resource_name)); - - if (req_exec_lck_resourceopen->fail_with_error != SA_AIS_OK) { - error = req_exec_lck_resourceopen->fail_with_error; - goto error_exit; - } - - resource = resource_find (&req_exec_lck_resourceopen->resource_name); - - /* - * If resource doesn't exist, create one - */ - if (resource == 0) { - if ((req_exec_lck_resourceopen->open_flags & SA_LCK_RESOURCE_CREATE) == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - resource = malloc (sizeof (struct resource)); - if (resource == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - memset (resource, 0, sizeof (struct resource)); - - memcpy (&resource->name, - &req_exec_lck_resourceopen->resource_name, - sizeof (mar_name_t)); - list_init (&resource->list); - list_init (&resource->resource_lock_list_head); - list_add (&resource->list, &resource_list_head); - list_init (&resource->pr_granted_list_head); - list_init (&resource->pr_pending_list_head); - list_init (&resource->ex_pending_list_head); - resource->refcount = 0; - resource->ex_granted = NULL; - } - - /* - * Setup connection information and mark resource as referenced - */ - if (api->ipc_source_is_local (&req_exec_lck_resourceopen->source)) { - log_printf (LOG_LEVEL_DEBUG, "Lock resource opened is %p\n", resource); - resource_cleanup = malloc (sizeof (struct resource_cleanup)); - if (resource_cleanup == 0) { - free (resource); - error = SA_AIS_ERR_NO_MEMORY; - } else { - lck_pd = (struct lck_pd *)api->ipc_private_data_get (req_exec_lck_resourceopen->source.conn); - list_init (&resource_cleanup->list); - list_init (&resource_cleanup->resource_lock_list_head); - resource_cleanup->resource = resource; - log_printf (LOG_LEVEL_DEBUG, "resource is %p\n", resource); - resource_cleanup->resource_handle = req_exec_lck_resourceopen->resource_handle; - list_add ( - &resource_cleanup->list, - &lck_pd->resource_cleanup_list); - } - resource->refcount += 1; - } - - - /* - * Send error result to LCK library - */ -error_exit: - /* - * If this node was the source of the message, respond to this node - */ - if (api->ipc_source_is_local (&req_exec_lck_resourceopen->source)) { - /* - * If its an async call respond with the invocation and handle - */ - if (req_exec_lck_resourceopen->async_call) { - res_lib_lck_resourceopenasync.header.size = sizeof (struct res_lib_lck_resourceopenasync); - res_lib_lck_resourceopenasync.header.id = MESSAGE_RES_LCK_RESOURCEOPENASYNC; - res_lib_lck_resourceopenasync.header.error = error; - res_lib_lck_resourceopenasync.resourceHandle = req_exec_lck_resourceopen->resource_handle; - res_lib_lck_resourceopenasync.invocation = req_exec_lck_resourceopen->invocation; - memcpy (&res_lib_lck_resourceopenasync.source, - &req_exec_lck_resourceopen->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response ( - req_exec_lck_resourceopen->source.conn, - &res_lib_lck_resourceopenasync, - sizeof (struct res_lib_lck_resourceopenasync)); - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_lck_resourceopen->source.conn), - &res_lib_lck_resourceopenasync, - sizeof (struct res_lib_lck_resourceopenasync)); - } else { - /* - * otherwise respond with the normal resourceopen response - */ - res_lib_lck_resourceopen.header.size = sizeof (struct res_lib_lck_resourceopen); - res_lib_lck_resourceopen.header.id = MESSAGE_RES_LCK_RESOURCEOPEN; - res_lib_lck_resourceopen.header.error = error; - memcpy (&res_lib_lck_resourceopen.source, - &req_exec_lck_resourceopen->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response (req_exec_lck_resourceopen->source.conn, - &res_lib_lck_resourceopen, - sizeof (struct res_lib_lck_resourceopen)); - } - } -} - -static void message_handler_req_exec_lck_resourceclose ( - void *message, - unsigned int nodeid) -{ - struct req_exec_lck_resourceclose *req_exec_lck_resourceclose = (struct req_exec_lck_resourceclose *)message; - struct res_lib_lck_resourceclose res_lib_lck_resourceclose; - struct resource *resource = 0; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saLckResourceClose %s\n", - get_mar_name_t (&req_exec_lck_resourceclose->lockResourceName)); - - resource = resource_find (&req_exec_lck_resourceclose->lockResourceName); - if (resource == 0) { - goto error_exit; - } - - resource->refcount -= 1; - if (resource->refcount == 0) { - } -error_exit: - if (api->ipc_source_is_local(&req_exec_lck_resourceclose->source)) { - lck_resource_cleanup_remove ( - req_exec_lck_resourceclose->source.conn, - req_exec_lck_resourceclose->resource_handle); - - res_lib_lck_resourceclose.header.size = sizeof (struct res_lib_lck_resourceclose); - res_lib_lck_resourceclose.header.id = MESSAGE_RES_LCK_RESOURCECLOSE; - res_lib_lck_resourceclose.header.error = error; - api->ipc_conn_send_response ( - req_exec_lck_resourceclose->source.conn, - &res_lib_lck_resourceclose, sizeof (struct res_lib_lck_resourceclose)); - } -} - -void waiter_notification_send (struct resource_lock *resource_lock) -{ - struct res_lib_lck_lockwaitercallback res_lib_lck_lockwaitercallback; - - if (api->ipc_source_is_local (&resource_lock->callback_source) == 0) { - return; - } - - res_lib_lck_lockwaitercallback.header.size = sizeof (struct res_lib_lck_lockwaitercallback); - res_lib_lck_lockwaitercallback.header.id = MESSAGE_RES_LCK_LOCKWAITERCALLBACK; - res_lib_lck_lockwaitercallback.header.error = SA_AIS_OK; - res_lib_lck_lockwaitercallback.waiter_signal = resource_lock->waiter_signal; - res_lib_lck_lockwaitercallback.lock_id = resource_lock->lock_id; - res_lib_lck_lockwaitercallback.mode_requested = resource_lock->lock_mode; - - if (resource_lock->resource->ex_granted) { - res_lib_lck_lockwaitercallback.mode_held = SA_LCK_EX_LOCK_MODE; - } else { - res_lib_lck_lockwaitercallback.mode_held = SA_LCK_PR_LOCK_MODE; - } - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (resource_lock->callback_source.conn), - &res_lib_lck_lockwaitercallback, - sizeof (struct res_lib_lck_lockwaitercallback)); -} - -void waiter_notification_list_send (struct list_head *list_notify_head) -{ - struct list_head *list; - struct resource_lock *resource_lock; - - for (list = list_notify_head->next; - list != list_notify_head; - list = list->next) { - - resource_lock = list_entry (list, struct resource_lock, list); - waiter_notification_send (resource_lock); - } -} - -void resource_lock_async_deliver ( - mar_message_source_t *source, - struct resource_lock *resource_lock, - SaAisErrorT error) -{ - struct res_lib_lck_resourcelockasync res_lib_lck_resourcelockasync; - - if (source && api->ipc_source_is_local(source)) { - if (resource_lock->async_call) { - res_lib_lck_resourcelockasync.header.size = sizeof (struct res_lib_lck_resourcelockasync); - res_lib_lck_resourcelockasync.header.id = MESSAGE_RES_LCK_RESOURCELOCKASYNC; - res_lib_lck_resourcelockasync.header.error = error; - res_lib_lck_resourcelockasync.resource_lock = (void *)resource_lock; - res_lib_lck_resourcelockasync.lockStatus = resource_lock->lock_status; - res_lib_lck_resourcelockasync.invocation = resource_lock->invocation; - res_lib_lck_resourcelockasync.lockId = resource_lock->lock_id; - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (source->conn), - &res_lib_lck_resourcelockasync, - sizeof (struct res_lib_lck_resourcelockasync)); - } - } -} - -void lock_response_deliver ( - mar_message_source_t *source, - struct resource_lock *resource_lock, - SaAisErrorT error) -{ - struct res_lib_lck_resourcelock res_lib_lck_resourcelock; - - if (source && api->ipc_source_is_local(source)) { - if (resource_lock->async_call) { - resource_lock_async_deliver (&resource_lock->callback_source, resource_lock, error); - } else { - res_lib_lck_resourcelock.header.size = sizeof (struct res_lib_lck_resourcelock); - res_lib_lck_resourcelock.header.id = MESSAGE_RES_LCK_RESOURCELOCK; - res_lib_lck_resourcelock.header.error = error; - res_lib_lck_resourcelock.resource_lock = (void *)resource_lock; - res_lib_lck_resourcelock.lockStatus = resource_lock->lock_status; - api->ipc_conn_send_response (source->conn, - &res_lib_lck_resourcelock, - sizeof (struct res_lib_lck_resourcelock)); - } - } -} - - -/* - * Queue a lock if resource flags allow it - */ -void lock_queue ( - struct resource *resource, - struct resource_lock *resource_lock) -{ - if ((resource_lock->lock_flags & SA_LCK_LOCK_NO_QUEUE) == 0) { - /* - * Add lock to the list - */ - if (resource_lock->lock_mode == SA_LCK_PR_LOCK_MODE) { - list_add_tail (&resource_lock->list, - &resource->pr_pending_list_head); - waiter_notification_send (resource->ex_granted); - } else - if (resource_lock->lock_mode == SA_LCK_EX_LOCK_MODE) { - list_add_tail (&resource_lock->list, - &resource->ex_pending_list_head); - waiter_notification_list_send (&resource->pr_granted_list_head); - } - } else { - resource_lock->lock_status = SA_LCK_LOCK_NOT_QUEUED; - } -} - -/* -The algorithm: - -if ex lock granted - if ex pending list has locks - send waiter notification to ex lock granted -else - if ex pending list has locks - if pr granted list has locks - send waiter notification to all pr granted locks - else - grant ex lock from pending to granted - else - grant all pr pending locks to pr granted list -*/ -#define SA_LCK_LOCK_NO_STATUS 0 -void lock_algorithm ( - struct resource *resource, - struct resource_lock *resource_lock) -{ - resource_lock->lock_status = SA_LCK_LOCK_NO_STATUS; /* no status */ - if (resource->ex_granted) { - /* - * Exclusive lock granted - */ - lock_queue (resource, resource_lock); - } else { - /* - * Exclusive lock not granted - */ - if (resource_lock->lock_mode == SA_LCK_EX_LOCK_MODE) { - if (list_empty (&resource->pr_granted_list_head) == 0) { - lock_queue (resource, resource_lock); - } else { - /* - * grant ex lock from pending to granted - */ - resource->ex_granted = resource_lock; - resource_lock->lock_status = SA_LCK_LOCK_GRANTED; - } - } else { - /* - * grant all pr pending locks to pr granted list - */ - list_add (&resource_lock->list, - &resource->pr_granted_list_head); - resource_lock->lock_status = SA_LCK_LOCK_GRANTED; - } - } -} - -/* - * if lock in ex, set ex to null - * delete resource lock from list - * - * if ex lock not granted - * if ex pending list has locks - * grant first ex pending list lock to ex lock - * if ex lock not granted - * if pr pending list has locks - * assign all pr pending locks to pr granted lock list - */ -void unlock_algorithm ( - struct resource *resource, - struct resource_lock *resource_lock) -{ - struct resource_lock *resource_lock_grant; - struct list_head *list; - struct list_head *list_p; - - /* - * If unlocking the ex lock, reset ex granted - */ - if (resource_lock == resource->ex_granted) { - resource->ex_granted = 0; - } - else { - /* - * Delete resource lock from whichever list it is on - */ - list_del (&resource_lock->list); - } - list_del (&resource_lock->resource_list); - - /* - * Check if EX locks are available, if so assign one - */ - if (resource->ex_granted == 0) { - if (list_empty (&resource->ex_pending_list_head) == 0) { - /* - * grant first ex pending list lock to ex lock - */ - resource_lock_grant = list_entry ( - resource->ex_pending_list_head.next, - struct resource_lock, list); - - list_del (&resource_lock_grant->list); - resource->ex_granted = resource_lock_grant; - - resource_lock_grant->lock_status = SA_LCK_LOCK_GRANTED; - lock_response_deliver ( - &resource_lock_grant->response_source, - resource_lock_grant, - SA_AIS_OK); - } - } - - /* - * Couldn't assign EX lock, so assign any pending PR locks - */ - if (resource->ex_granted == 0) { - if (list_empty (&resource->pr_pending_list_head) == 0) { - /* - * assign all pr pending locks to pr granted lock list - */ - - for (list = resource->pr_pending_list_head.next; - list != &resource->pr_pending_list_head; - list = list->next) { - - resource_lock_grant = list_entry (list, struct resource_lock, list); - resource_lock_grant->lock_status = SA_LCK_LOCK_GRANTED; - - lock_response_deliver ( - &resource_lock_grant->response_source, - resource_lock_grant, - SA_AIS_OK); - } - - /* - * Add pending locks to granted list - */ - list_p = resource->pr_pending_list_head.next; - list_del (&resource->pr_pending_list_head); - list_init (&resource->pr_pending_list_head); - list_add_tail (list_p, - &resource->pr_granted_list_head); - } - } -} - -static void message_handler_req_exec_lck_resourcelock ( - void *message, - unsigned int nodeid) -{ - struct req_exec_lck_resourcelock *req_exec_lck_resourcelock = (struct req_exec_lck_resourcelock *)message; - struct resource *resource = 0; - struct resource_lock *resource_lock = 0; - struct resource_cleanup *resource_cleanup = 0; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saLckResourceLock %s\n", - get_mar_name_t (&req_exec_lck_resourcelock->req_lib_lck_resourcelock.lockResourceName)); - - resource = resource_find (&req_exec_lck_resourcelock->req_lib_lck_resourcelock.lockResourceName); - if (resource == 0) { - goto error_exit; - } - resource->refcount += 1; - - resource_lock = malloc (sizeof (struct resource_lock)); - if (resource_lock == 0) { - lock_response_deliver (&req_exec_lck_resourcelock->source, - resource_lock, - SA_AIS_ERR_NO_MEMORY); - goto error_exit; - } - - /* - * Build resource lock structure - */ - memset (resource_lock, 0, sizeof (struct resource_lock)); - - list_init (&resource_lock->list); - list_init (&resource_lock->resource_list); - list_init (&resource_lock->resource_cleanup_list); - - list_add (&resource_lock->resource_list, &resource->resource_lock_list_head); - - resource_lock->resource = resource; - - resource_lock->lock_mode = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.lockMode; - resource_lock->lock_flags = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.lockFlags; - resource_lock->waiter_signal = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.waiterSignal; - resource_lock->timeout = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.timeout; - resource_lock->lock_id = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.lockId; - resource_lock->async_call = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.async_call; - resource_lock->invocation = - req_exec_lck_resourcelock->req_lib_lck_resourcelock.invocation; - - /* - * Waiter callback source - */ - memcpy (&resource_lock->callback_source, - &req_exec_lck_resourcelock->req_lib_lck_resourcelock.source, - sizeof (mar_message_source_t)); - - lock_algorithm (resource, resource_lock); - - /* - * Add resource lock to cleanup handler for this api resource instance - */ - if (api->ipc_source_is_local (&req_exec_lck_resourcelock->source)) { - resource_cleanup = lck_resource_cleanup_find ( - resource_lock->callback_source.conn, - req_exec_lck_resourcelock->resource_handle); - - assert (resource_cleanup); - - list_add (&resource_lock->resource_cleanup_list, - &resource_cleanup->resource_lock_list_head); - - /* - * If lock queued by lock algorithm, dont send response to library now - */ - if (resource_lock->lock_status != SA_LCK_LOCK_NO_STATUS) { - /* - * If lock granted or denied, deliver callback or - * response to library for non-async calls - */ - lock_response_deliver ( - &req_exec_lck_resourcelock->source, - resource_lock, - SA_AIS_OK); - } else { - memcpy (&resource_lock->response_source, - &req_exec_lck_resourcelock->source, - sizeof (mar_message_source_t)); - } - - /* - * Deliver async response to library - */ - req_exec_lck_resourcelock->source.conn = - api->ipc_conn_partner_get (req_exec_lck_resourcelock->source.conn); - resource_lock_async_deliver ( - &req_exec_lck_resourcelock->source, - resource_lock, - SA_AIS_OK); -// TODO why is this twice ? - req_exec_lck_resourcelock->source.conn = - api->ipc_conn_partner_get (req_exec_lck_resourcelock->source.conn); - } - -error_exit: - return; -} - -static void message_handler_req_exec_lck_resourceunlock ( - void *message, - unsigned int nodeid) -{ - struct req_exec_lck_resourceunlock *req_exec_lck_resourceunlock = (struct req_exec_lck_resourceunlock *)message; - struct res_lib_lck_resourceunlock res_lib_lck_resourceunlock; - struct res_lib_lck_resourceunlockasync res_lib_lck_resourceunlockasync; - struct resource *resource = NULL; - struct resource_lock *resource_lock = NULL; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saLckResourceUnlock %s\n", - get_mar_name_t (&req_exec_lck_resourceunlock->resource_name)); - - resource = resource_find (&req_exec_lck_resourceunlock->resource_name); - if (resource == 0) { - goto error_exit; - } - resource->refcount -= 1; - - resource_lock = resource_lock_find (resource, - &req_exec_lck_resourceunlock->source, - req_exec_lck_resourceunlock->lock_id); - assert (resource_lock); - - list_del (&resource_lock->resource_cleanup_list); - unlock_algorithm (resource, resource_lock); - -error_exit: - if (api->ipc_source_is_local(&req_exec_lck_resourceunlock->source)) { - if (req_exec_lck_resourceunlock->async_call) { - res_lib_lck_resourceunlockasync.header.size = sizeof (struct res_lib_lck_resourceunlockasync); - res_lib_lck_resourceunlockasync.header.id = MESSAGE_RES_LCK_RESOURCEUNLOCKASYNC; - res_lib_lck_resourceunlockasync.header.error = error; - res_lib_lck_resourceunlockasync.invocation = - req_exec_lck_resourceunlock->invocation; - res_lib_lck_resourceunlockasync.lockId = req_exec_lck_resourceunlock->lock_id; - - api->ipc_conn_send_response ( - req_exec_lck_resourceunlock->source.conn, - &res_lib_lck_resourceunlockasync, - sizeof (struct res_lib_lck_resourceunlockasync)); - api->ipc_conn_send_response ( - api->ipc_conn_partner_get(req_exec_lck_resourceunlock->source.conn), - &res_lib_lck_resourceunlockasync, - sizeof (struct res_lib_lck_resourceunlockasync)); - } else { - res_lib_lck_resourceunlock.header.size = sizeof (struct res_lib_lck_resourceunlock); - res_lib_lck_resourceunlock.header.id = MESSAGE_RES_LCK_RESOURCEUNLOCK; - res_lib_lck_resourceunlock.header.error = error; - api->ipc_conn_send_response (req_exec_lck_resourceunlock->source.conn, - &res_lib_lck_resourceunlock, sizeof (struct res_lib_lck_resourceunlock)); - } - } -} - -static void message_handler_req_exec_lck_resourcelockorphan ( - void *message, - unsigned int nodeid) -{ - struct req_exec_lck_resourcelockorphan *req_exec_lck_resourcelockorphan = (struct req_exec_lck_resourcelockorphan *)message; - struct resource *resource = 0; - struct resource_lock *resource_lock = 0; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: Orphan resource locks for resource %s\n", - get_mar_name_t (&req_exec_lck_resourcelockorphan->resource_name)); - - resource = resource_find (&req_exec_lck_resourcelockorphan->resource_name); - if (resource == 0) { - assert (0); - } - resource->refcount -= 1; - - resource_lock = resource_lock_find (resource, - &req_exec_lck_resourcelockorphan->source, - req_exec_lck_resourcelockorphan->lock_id); - assert (resource_lock); - - list_del (&resource_lock->resource_cleanup_list); - unlock_algorithm (resource, resource_lock); -} - -static void message_handler_req_exec_lck_lockpurge ( - void *msg, - unsigned int nodeid) -{ - struct req_exec_lck_lockpurge *req_exec_lck_lockpurge = (struct req_exec_lck_lockpurge *)msg; - struct res_lib_lck_lockpurge res_lib_lck_lockpurge; - struct resource *resource = 0; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_DEBUG, "EXEC request: saLckLockPurge %s\n", - get_mar_name_t (&req_exec_lck_lockpurge->req_lib_lck_lockpurge.lockResourceName)); - - resource = resource_find (&req_exec_lck_lockpurge->req_lib_lck_lockpurge.lockResourceName); - if (resource == 0) { - goto error_exit; - } - -error_exit: - if (api->ipc_source_is_local(&req_exec_lck_lockpurge->source)) { -// lck_resource_cleanup_remove (req_exec_lck_lockpurge->source.conn, -// resource); - - res_lib_lck_lockpurge.header.size = sizeof (struct res_lib_lck_lockpurge); - res_lib_lck_lockpurge.header.id = MESSAGE_RES_LCK_LOCKPURGE; - res_lib_lck_lockpurge.header.error = error; - api->ipc_conn_send_response (req_exec_lck_lockpurge->source.conn, - &res_lib_lck_lockpurge, sizeof (struct res_lib_lck_lockpurge)); - } -} - -static void message_handler_req_lib_lck_resourceopen ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourceopen *req_lib_lck_resourceopen = (struct req_lib_lck_resourceopen *)msg; - struct req_exec_lck_resourceopen req_exec_lck_resourceopen; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceOpen %s\n", - get_mar_name_t (&req_lib_lck_resourceopen->lockResourceName)); - - req_exec_lck_resourceopen.header.size = - sizeof (struct req_exec_lck_resourceopen); - req_exec_lck_resourceopen.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCEOPEN); - - api->ipc_source_set (&req_exec_lck_resourceopen.source, conn); - - memcpy (&req_exec_lck_resourceopen.resource_name, - &req_lib_lck_resourceopen->lockResourceName, - sizeof (SaNameT)); - - req_exec_lck_resourceopen.open_flags = req_lib_lck_resourceopen->resourceOpenFlags; - req_exec_lck_resourceopen.async_call = 0; - req_exec_lck_resourceopen.invocation = 0; - req_exec_lck_resourceopen.resource_handle = req_lib_lck_resourceopen->resourceHandle; - req_exec_lck_resourceopen.fail_with_error = SA_AIS_OK; - - iovec.iov_base = (char *)&req_exec_lck_resourceopen; - iovec.iov_len = sizeof (req_exec_lck_resourceopen); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_lck_resourceopenasync ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourceopen *req_lib_lck_resourceopen = (struct req_lib_lck_resourceopen *)msg; - struct req_exec_lck_resourceopen req_exec_lck_resourceopen; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceOpenAsync %s\n", - get_mar_name_t (&req_lib_lck_resourceopen->lockResourceName)); - - req_exec_lck_resourceopen.header.size = - sizeof (struct req_exec_lck_resourceopen); - req_exec_lck_resourceopen.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCEOPEN); - - api->ipc_source_set (&req_exec_lck_resourceopen.source, conn); - - memcpy (&req_exec_lck_resourceopen.resource_name, - &req_lib_lck_resourceopen->lockResourceName, - sizeof (mar_name_t)); - - req_exec_lck_resourceopen.resource_handle = req_lib_lck_resourceopen->resourceHandle; - req_exec_lck_resourceopen.invocation = req_lib_lck_resourceopen->invocation; - req_exec_lck_resourceopen.open_flags = req_lib_lck_resourceopen->resourceOpenFlags; - req_exec_lck_resourceopen.fail_with_error = SA_AIS_OK; - req_exec_lck_resourceopen.timeout = 0; - req_exec_lck_resourceopen.async_call = 1; - - iovec.iov_base = (char *)&req_exec_lck_resourceopen; - iovec.iov_len = sizeof (req_exec_lck_resourceopen); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_lck_resourceclose ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourceclose *req_lib_lck_resourceclose = (struct req_lib_lck_resourceclose *)msg; - struct req_exec_lck_resourceclose req_exec_lck_resourceclose; - struct iovec iovecs[2]; - struct resource *resource; - struct res_lib_lck_resourceclose res_lib_lck_resourceclose; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceClose %s\n", - get_mar_name_t (&req_lib_lck_resourceclose->lockResourceName)); - - resource = resource_find (&req_lib_lck_resourceclose->lockResourceName); - if (resource) { - req_exec_lck_resourceclose.header.size = - sizeof (struct req_exec_lck_resourceclose); - req_exec_lck_resourceclose.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCECLOSE); - - api->ipc_source_set (&req_exec_lck_resourceclose.source, conn); - - memcpy (&req_exec_lck_resourceclose.lockResourceName, - &req_lib_lck_resourceclose->lockResourceName, sizeof (mar_name_t)); - - req_exec_lck_resourceclose.resource_handle = req_lib_lck_resourceclose->resourceHandle; - iovecs[0].iov_base = (char *)&req_exec_lck_resourceclose; - iovecs[0].iov_len = sizeof (req_exec_lck_resourceclose); - - if (api->totem_send_ok (iovecs, 1)) { - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); - } - } - else { - log_printf (LOG_LEVEL_ERROR, "#### LCK: Could Not Find the Checkpoint to close so Returning Error. ####\n"); - - res_lib_lck_resourceclose.header.size = sizeof (struct res_lib_lck_resourceclose); - res_lib_lck_resourceclose.header.id = MESSAGE_RES_LCK_RESOURCECLOSE; - res_lib_lck_resourceclose.header.error = SA_AIS_ERR_NOT_EXIST; - - api->ipc_conn_send_response (conn, - &res_lib_lck_resourceclose, - sizeof (struct res_lib_lck_resourceclose)); - } -} - -static void message_handler_req_lib_lck_resourcelock ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourcelock *req_lib_lck_resourcelock = (struct req_lib_lck_resourcelock *)msg; - struct req_exec_lck_resourcelock req_exec_lck_resourcelock; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceLock %s\n", - get_mar_name_t (&req_lib_lck_resourcelock->lockResourceName)); - - req_exec_lck_resourcelock.header.size = - sizeof (struct req_exec_lck_resourcelock); - req_exec_lck_resourcelock.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCELOCK); - - api->ipc_source_set (&req_exec_lck_resourcelock.source, conn); - - memcpy (&req_exec_lck_resourcelock.req_lib_lck_resourcelock, - req_lib_lck_resourcelock, - sizeof (struct req_lib_lck_resourcelock)); - - req_exec_lck_resourcelock.resource_handle = req_lib_lck_resourcelock->resourceHandle; - req_exec_lck_resourcelock.async_call = 0; - req_exec_lck_resourcelock.invocation = 0; - req_exec_lck_resourcelock.fail_with_error = SA_AIS_OK; - - iovecs[0].iov_base = (char *)&req_exec_lck_resourcelock; - iovecs[0].iov_len = sizeof (req_exec_lck_resourcelock); - - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_lck_resourcelockasync ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourcelock *req_lib_lck_resourcelock = (struct req_lib_lck_resourcelock *)msg; - struct req_exec_lck_resourcelock req_exec_lck_resourcelock; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceLockAsync %s\n", - get_mar_name_t (&req_lib_lck_resourcelock->lockResourceName)); - - req_exec_lck_resourcelock.header.size = - sizeof (struct req_exec_lck_resourcelock); - req_exec_lck_resourcelock.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCELOCK); - - api->ipc_source_set (&req_exec_lck_resourcelock.source, conn); - - memcpy (&req_exec_lck_resourcelock.req_lib_lck_resourcelock, - req_lib_lck_resourcelock, - sizeof (struct req_lib_lck_resourcelock)); - - req_exec_lck_resourcelock.resource_handle = req_lib_lck_resourcelock->resourceHandle; - req_exec_lck_resourcelock.async_call = 1; - req_exec_lck_resourcelock.invocation = req_lib_lck_resourcelock->invocation; - req_exec_lck_resourcelock.fail_with_error = SA_AIS_OK; - - iovecs[0].iov_base = (char *)&req_exec_lck_resourcelock; - iovecs[0].iov_len = sizeof (req_exec_lck_resourcelock); - - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_lck_resourceunlock ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourceunlock *req_lib_lck_resourceunlock = (struct req_lib_lck_resourceunlock *)msg; - struct req_exec_lck_resourceunlock req_exec_lck_resourceunlock; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceUnlock %s\n", - get_mar_name_t (&req_lib_lck_resourceunlock->lockResourceName)); - - req_exec_lck_resourceunlock.header.size = - sizeof (struct req_exec_lck_resourceunlock); - req_exec_lck_resourceunlock.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCEUNLOCK); - - api->ipc_source_set (&req_exec_lck_resourceunlock.source, conn); - - memcpy (&req_exec_lck_resourceunlock.resource_name, - &req_lib_lck_resourceunlock->lockResourceName, - sizeof (mar_name_t)); - - req_exec_lck_resourceunlock.lock_id = req_lib_lck_resourceunlock->lockId; - req_exec_lck_resourceunlock.async_call = 0; - req_exec_lck_resourceunlock.invocation = 0; - - iovec.iov_base = (char *)&req_exec_lck_resourceunlock; - iovec.iov_len = sizeof (req_exec_lck_resourceunlock); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_lck_resourceunlockasync ( - void *conn, - void *msg) -{ - struct req_lib_lck_resourceunlock *req_lib_lck_resourceunlock = (struct req_lib_lck_resourceunlock *)msg; - struct req_exec_lck_resourceunlock req_exec_lck_resourceunlock; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceUnlockAsync %s\n", - get_mar_name_t (&req_lib_lck_resourceunlock->lockResourceName)); - - req_exec_lck_resourceunlock.header.size = - sizeof (struct req_exec_lck_resourceunlock); - req_exec_lck_resourceunlock.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_RESOURCEUNLOCK); - - api->ipc_source_set (&req_exec_lck_resourceunlock.source, conn); - - memcpy (&req_exec_lck_resourceunlock.resource_name, - &req_lib_lck_resourceunlock->lockResourceName, - sizeof (mar_name_t)); - - req_exec_lck_resourceunlock.lock_id = req_lib_lck_resourceunlock->lockId; - req_exec_lck_resourceunlock.invocation = req_lib_lck_resourceunlock->invocation; - req_exec_lck_resourceunlock.async_call = 1; - - iovec.iov_base = (char *)&req_exec_lck_resourceunlock; - iovec.iov_len = sizeof (req_exec_lck_resourceunlock); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_lck_lockpurge ( - void *conn, - void *msg) -{ - struct req_lib_lck_lockpurge *req_lib_lck_lockpurge = (struct req_lib_lck_lockpurge *)msg; - struct req_exec_lck_lockpurge req_exec_lck_lockpurge; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saLckResourceLockPurge %s\n", - get_mar_name_t (&req_lib_lck_lockpurge->lockResourceName)); - - req_exec_lck_lockpurge.header.size = - sizeof (struct req_exec_lck_lockpurge); - req_exec_lck_lockpurge.header.id = - SERVICE_ID_MAKE (LCK_SERVICE, MESSAGE_REQ_EXEC_LCK_LOCKPURGE); - - api->ipc_source_set (&req_exec_lck_lockpurge.source, conn); - - memcpy (&req_exec_lck_lockpurge.req_lib_lck_lockpurge, - req_lib_lck_lockpurge, - sizeof (struct req_lib_lck_lockpurge)); - - iovecs[0].iov_base = (char *)&req_exec_lck_lockpurge; - iovecs[0].iov_len = sizeof (req_exec_lck_lockpurge); - - assert (api->totem_mcast (iovecs, 1, TOTEM_AGREED) == 0); -} - diff --git a/openais/services/lck.h b/openais/services/lck.h deleted file mode 100644 index 7d3330b8..00000000 --- a/openais/services/lck.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "../include/saAis.h" -#include "../include/saCkpt.h" -#include "aispoll.h" -#include "totemsrp.h" - -#ifndef LCK_H_DEFINED -#define LCK_H_DEFINED - -extern struct openais_service_handler lck_service_handler; - -#endif /* CKPT_H_DEFINED */ diff --git a/openais/services/msg.c b/openais/services/msg.c deleted file mode 100644 index a199e6a8..00000000 --- a/openais/services/msg.c +++ /dev/null @@ -1,2384 +0,0 @@ -/* - * Copyright (c) 2005-2006 MontaVista Software, Inc. - * Copyright (c) 2006 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "../include/saAis.h" -#include "../include/saMsg.h" -#include "../include/ipc_msg.h" - - -LOGSYS_DECLARE_SUBSYS ("MSG", LOG_INFO); - -enum msg_exec_message_req_types { - MESSAGE_REQ_EXEC_MSG_QUEUEOPEN = 0, - MESSAGE_REQ_EXEC_MSG_QUEUECLOSE = 1, - MESSAGE_REQ_EXEC_MSG_QUEUESTATUSGET = 2, - MESSAGE_REQ_EXEC_MSG_QUEUEUNLINK = 3, - MESSAGE_REQ_EXEC_MSG_QUEUEGROUPCREATE = 4, - MESSAGE_REQ_EXEC_MSG_QUEUEGROUPINSERT = 5, - MESSAGE_REQ_EXEC_MSG_QUEUEGROUPREMOVE = 6, - MESSAGE_REQ_EXEC_MSG_QUEUEGROUPDELETE = 7, - MESSAGE_REQ_EXEC_MSG_QUEUEGROUPTRACK = 8, - MESSAGE_REQ_EXEC_MSG_QUEUEGROUPTRACKSTOP = 9, - MESSAGE_REQ_EXEC_MSG_MESSAGESEND = 10, - MESSAGE_REQ_EXEC_MSG_MESSAGEGET = 11, - MESSAGE_REQ_EXEC_MSG_MESSAGECANCEL = 12, - MESSAGE_REQ_EXEC_MSG_MESSAGESENDRECEIVE = 13, - MESSAGE_REQ_EXEC_MSG_MESSAGEREPLY = 14 -}; - -struct message_entry { - SaTimeT time; - SaMsgMessageT message; - struct list_head list; -}; - -struct message_queue { - SaNameT name; - int refcount; - struct list_head list; - struct list_head message_list_head; -}; - -struct queue_group { - SaNameT name; - SaUint8T track_flags; - SaMsgQueueGroupPolicyT policy; - struct list_head list; - struct list_head message_queue_head; -}; - -struct queue_group_entry { - SaMsgQueueGroupChangesT change; - struct message_queue *message_queue; - struct list_head list; -}; - -/* -struct queue_cleanup { - struct message_queue *queue; - SaMsgResourceHandleT queue_handle; - struct list_head queue_lock_list_head; - struct list_head list; -}; -*/ - -DECLARE_LIST_INIT(queue_list_head); -DECLARE_LIST_INIT(queue_group_list_head); - -static struct corosync_api_v1 *api; - -static int msg_exec_init_fn (struct corosync_api_v1 *); - -static int msg_lib_exit_fn (void *conn); - -static int msg_lib_init_fn (void *conn); - -static void message_handler_req_exec_msg_queueopen ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queueclose ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuestatusget ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queueunlink ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuegroupcreate ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuegroupinsert ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuegroupremove ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuegroupdelete ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuegrouptrack ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_queuegrouptrackstop ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_messagesend ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_messageget ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_messagecancel ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_messagesendreceive ( - void *message, - unsigned int nodeid); - -static void message_handler_req_exec_msg_messagereply ( - void *message, - unsigned int nodeid); - -static void message_handler_req_lib_msg_queueopen ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queueopenasync ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queueclose ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuestatusget ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queueunlink ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuegroupcreate ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuegroupinsert ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuegroupremove ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuegroupdelete ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuegrouptrack ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_queuegrouptrackstop ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messagesend ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messagesendasync ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messageget ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messagecancel ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messagesendreceive ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messagereply ( - void *conn, - void *msg); - -static void message_handler_req_lib_msg_messagereplyasync ( - void *conn, - void *msg); - -#ifdef TODO -static void msg_sync_init (void); -#endif /* TODO */ - -static void msg_sync_activate (void); -static int msg_sync_process (void); -static void msg_sync_abort(void); - -void queue_release (struct message_queue *queue); - -static void msg_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id); - -struct msg_pd { - struct list_head queue_list; - struct list_head queue_cleanup_list; -}; - -/* - * Executive Handler Definition - */ -struct corosync_lib_handler msg_lib_engine[] = -{ - { /* 0 */ - .lib_handler_fn = message_handler_req_lib_msg_queueopen, - .response_size = sizeof (struct res_lib_msg_queueopen), - .response_id = MESSAGE_RES_MSG_QUEUEOPEN, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 1 */ - .lib_handler_fn = message_handler_req_lib_msg_queueopenasync, - .response_size = sizeof (struct res_lib_msg_queueopenasync), - .response_id = MESSAGE_RES_MSG_QUEUEOPENASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 2 */ - .lib_handler_fn = message_handler_req_lib_msg_queueclose, - .response_size = sizeof (struct res_lib_msg_queueclose), - .response_id = MESSAGE_RES_MSG_QUEUECLOSE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 3 */ - .lib_handler_fn = message_handler_req_lib_msg_queuestatusget, - .response_size = sizeof (struct res_lib_msg_queuestatusget), - .response_id = MESSAGE_RES_MSG_QUEUESTATUSGET, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 4 */ - .lib_handler_fn = message_handler_req_lib_msg_queueunlink, - .response_size = sizeof (struct res_lib_msg_queueunlink), - .response_id = MESSAGE_RES_MSG_QUEUEUNLINK, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 5 */ - .lib_handler_fn = message_handler_req_lib_msg_queuegroupcreate, - .response_size = sizeof (struct res_lib_msg_queuegroupcreate), - .response_id = MESSAGE_RES_MSG_QUEUEGROUPCREATE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 6 */ - .lib_handler_fn = message_handler_req_lib_msg_queuegroupinsert, - .response_size = sizeof (struct res_lib_msg_queuegroupinsert), - .response_id = MESSAGE_RES_MSG_QUEUEGROUPINSERT, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 7 */ - .lib_handler_fn = message_handler_req_lib_msg_queuegroupremove, - .response_size = sizeof (struct res_lib_msg_queuegroupremove), - .response_id = MESSAGE_RES_MSG_QUEUEGROUPREMOVE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 8 */ - .lib_handler_fn = message_handler_req_lib_msg_queuegroupdelete, - .response_size = sizeof (struct res_lib_msg_queuegroupdelete), - .response_id = MESSAGE_RES_MSG_QUEUEGROUPDELETE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 9 */ - .lib_handler_fn = message_handler_req_lib_msg_queuegrouptrack, - .response_size = sizeof (struct res_lib_msg_queuegrouptrack), - .response_id = MESSAGE_RES_MSG_QUEUEGROUPTRACK, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 10 */ - .lib_handler_fn = message_handler_req_lib_msg_queuegrouptrackstop, - .response_size = sizeof (struct res_lib_msg_queuegrouptrackstop), - .response_id = MESSAGE_RES_MSG_QUEUEGROUPTRACKSTOP, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 11 */ - .lib_handler_fn = message_handler_req_lib_msg_messagesend, - .response_size = sizeof (struct res_lib_msg_messagesend), - .response_id = MESSAGE_RES_MSG_MESSAGESEND, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 12 */ - .lib_handler_fn = message_handler_req_lib_msg_messagesendasync, - .response_size = sizeof (struct res_lib_msg_messagesendasync), - .response_id = MESSAGE_RES_MSG_MESSAGESENDASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 13 */ - .lib_handler_fn = message_handler_req_lib_msg_messageget, - .response_size = sizeof (struct res_lib_msg_messageget), - .response_id = MESSAGE_RES_MSG_MESSAGEGET, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 14 */ - .lib_handler_fn = message_handler_req_lib_msg_messagecancel, - .response_size = sizeof (struct res_lib_msg_messagecancel), - .response_id = MESSAGE_RES_MSG_MESSAGECANCEL, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 15 */ - .lib_handler_fn = message_handler_req_lib_msg_messagesendreceive, - .response_size = sizeof (struct res_lib_msg_messagesendreceive), - .response_id = MESSAGE_RES_MSG_MESSAGESENDRECEIVE, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 16 */ - .lib_handler_fn = message_handler_req_lib_msg_messagereply, - .response_size = sizeof (struct res_lib_msg_messagereply), - .response_id = MESSAGE_RES_MSG_MESSAGEREPLY, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, - { /* 17 */ - .lib_handler_fn = message_handler_req_lib_msg_messagereplyasync, - .response_size = sizeof (struct res_lib_msg_messagereplyasync), - .response_id = MESSAGE_RES_MSG_MESSAGEREPLYASYNC, - .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED - }, -}; - - -static struct corosync_exec_handler msg_exec_engine[] = { - { - .exec_handler_fn = message_handler_req_exec_msg_queueopen, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queueclose, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuestatusget, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queueunlink, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuegroupcreate, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuegroupinsert, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuegroupremove, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuegroupdelete, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuegrouptrack, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_queuegrouptrackstop, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_messagesend, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_messageget, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_messagecancel, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_messagesendreceive, - }, - { - .exec_handler_fn = message_handler_req_exec_msg_messagereply - } -}; - -struct corosync_service_engine msg_service_engine = { - .name = "openais message service B.01.01", - .id = MSG_SERVICE, - .private_data_size = sizeof (struct msg_pd), - .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED, - .lib_init_fn = msg_lib_init_fn, - .lib_exit_fn = msg_lib_exit_fn, - .lib_engine = msg_lib_engine, - .lib_engine_count = sizeof (msg_lib_engine) / sizeof (struct corosync_lib_handler), - .exec_init_fn = msg_exec_init_fn, - .exec_engine = msg_exec_engine, - .exec_engine_count = sizeof (msg_exec_engine) / sizeof (struct corosync_exec_handler), - .confchg_fn = msg_confchg_fn, - .exec_dump_fn = NULL, - .sync_init = NULL, // TODO msg_sync_init, - .sync_process = msg_sync_process, - .sync_activate = msg_sync_activate, - .sync_abort = msg_sync_abort -}; - -static struct corosync_service_engine *msg_get_engine_ver0 (void); - -static struct corosync_service_engine_iface_ver0 msg_service_engine_iface = { - .corosync_get_service_engine_ver0 = msg_get_engine_ver0 -}; - -static struct lcr_iface openais_msg_ver0[1] = { - { - .name = "openais_msg", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = NULL - } -}; - -static struct lcr_comp msg_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_msg_ver0 -}; - -static struct corosync_service_engine *msg_get_engine_ver0 (void) -{ - return (&msg_service_engine); -} - -__attribute__ ((constructor)) static void register_this_component (void) { - lcr_interfaces_set (&openais_msg_ver0[0], &msg_service_engine_iface); - - lcr_component_register (&msg_comp_ver0); -} - -/* - * All data types used for executive messages - */ -struct req_exec_msg_queueopen { - mar_req_header_t header; - mar_message_source_t source; - int async_call; - SaNameT queue_name; - SaInvocationT invocation; - SaMsgQueueHandleT queue_handle; - SaMsgQueueCreationAttributesT creation_attributes; - SaMsgQueueOpenFlagsT openFlags; - SaTimeT timeout; -}; - -struct req_exec_msg_queueclose { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; -}; - -struct req_exec_msg_queuestatusget { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; -}; - -struct req_exec_msg_queueunlink { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; -}; - -struct req_exec_msg_queuegroupcreate { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_group_name; - SaMsgQueueGroupPolicyT policy; -}; - -struct req_exec_msg_queuegroupinsert { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; - SaNameT queue_group_name; -}; - -struct req_exec_msg_queuegroupremove { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; - SaNameT queue_group_name; -}; - -struct req_exec_msg_queuegroupdelete { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_group_name; -}; - -struct req_exec_msg_queuegrouptrack { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_group_name; - SaUint8T track_flags; - SaUint8T buffer_flag; -}; - -struct req_exec_msg_queuegrouptrackstop { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_group_name; -}; - -struct req_exec_msg_messagesend { - mar_req_header_t header; - mar_message_source_t source; - SaNameT destination; - SaTimeT timeout; - SaMsgMessageT message; - SaInvocationT invocation; - SaMsgAckFlagsT ack_flags; - int async_call; -}; - -struct req_exec_msg_messageget { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; -}; - -struct req_exec_msg_messagecancel { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; -}; - -struct req_exec_msg_messagesendreceive { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; -}; - -struct req_exec_msg_messagereply { - mar_req_header_t header; - mar_message_source_t source; - SaNameT queue_name; - int async_call; -}; - -char *getSaNameT (SaNameT *name) -{ -#if 0 - static char ret_name[300]; - - memset (ret_name, 0, sizeof (ret_name)); - if (name->length > 299) { - memcpy (ret_name, name->value, 299); - } else { - - memcpy (ret_name, name->value, name->length); - } - return (ret_name); -#endif -// TODO - return ((char *)name->value); -} - -int name_match(SaNameT *name1, SaNameT *name2) -{ - if (name1->length == name2->length) { - return ((strncmp ((char *)name1->value, (char *)name2->value, name1->length)) == 0); - } - return 0; -} - -SaTimeT clust_time_now(void) -{ - struct timeval tv; - SaTimeT time_now; - - if (gettimeofday(&tv, 0)) { - return 0ULL; - } - - time_now = (SaTimeT)(tv.tv_sec) * 1000000000ULL; - time_now += (SaTimeT)(tv.tv_usec) * 1000ULL; - - return time_now; -} - -#ifdef TODO -static void msg_sync_init (void) -{ - return; -} -#endif /* TODO */ - -static int msg_sync_process (void) -{ - return (0); -} - -static void msg_sync_activate (void) -{ - return; -} - -static void msg_sync_abort (void) -{ - return; -} - -static void msg_confchg_fn ( - enum totem_configuration_type configuration_type, - unsigned int *member_list, int member_list_entries, - unsigned int *left_list, int left_list_entries, - unsigned int *joined_list, int joined_list_entries, - struct memb_ring_id *ring_id) -{ - return; -} - -static void print_message_list (struct message_queue *queue) -{ - struct list_head *list; - struct message_entry *entry; - - for (list = queue->message_list_head.next; - list != &queue->message_list_head; - list = list->next) - { - entry = list_entry (list, struct message_entry, list); - - log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: print_message_list (%s) (%llu)\n", - (char *)(entry->message.data), - (unsigned long long)(entry->time)); - } -} - -static void print_queue_group_list (struct queue_group *group) -{ - struct list_head *list; - struct queue_group_entry *entry; - - for (list = group->message_queue_head.next; - list != &group->message_queue_head; - list = list->next) - { - entry = list_entry (list, struct queue_group_entry, list); - - log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: print_queue_group_list (%s) (%u)\n", - (char *)(entry->message_queue->name.value), - (unsigned int)(entry->change)); - } -} - -static struct message_queue *queue_find (SaNameT *name) -{ - struct list_head *list; - struct message_queue *queue; - - for (list = queue_list_head.next; - list != &queue_list_head; - list = list->next) - { - queue = list_entry (list, struct message_queue, list); - - if (name_match (name, &queue->name)) { - return (queue); - } - } - return (0); -} - -static struct queue_group *queue_group_find (SaNameT *name) -{ - struct list_head *list; - struct queue_group *group; - - for (list = queue_group_list_head.next; - list != &queue_group_list_head; - list = list->next) - { - group = list_entry (list, struct queue_group, list); - - if (name_match (name, &group->name)) { - return (group); - } - } - return (0); -} - -static struct queue_group_entry *queue_group_entry_find (struct queue_group *group, struct message_queue *queue) -{ - struct list_head *list; - struct queue_group_entry *entry; - - for (list = group->message_queue_head.next; - list != &group->message_queue_head; - list = list->next) - { - entry = list_entry (list, struct queue_group_entry, list); - - if (entry->message_queue == queue) { - return (entry); - } - } - return (0); -} - -static unsigned int queue_group_member_count (struct queue_group *group) -{ - struct list_head *list; - - unsigned int count = 0; - - for (list = group->message_queue_head.next; - list != &group->message_queue_head; - list = list->next) - { - count++; - } - return (count); -} - -static unsigned int queue_group_change_count (struct queue_group *group) -{ - struct list_head *list; - struct queue_group_entry *entry; - - unsigned int count = 0; - - for (list = group->message_queue_head.next; - list != &group->message_queue_head; - list = list->next) - { - entry = list_entry (list, struct queue_group_entry, list); - - if (entry->change != SA_MSG_QUEUE_GROUP_NO_CHANGE) { - count++; - } - } - return (count); -} - -static unsigned int queue_group_track ( - struct queue_group *group, - unsigned int flags, - void *buffer) -{ - struct list_head *list; - struct queue_group_entry *entry; - - unsigned int i = 0; - - SaMsgQueueGroupNotificationT *notification = - (SaMsgQueueGroupNotificationT *) buffer; - - - switch (flags) { - - case SA_TRACK_CURRENT: - case SA_TRACK_CHANGES: - - for (list = group->message_queue_head.next; - list != &group->message_queue_head; - list = list->next) - { - entry = list_entry (list, struct queue_group_entry, list); - memcpy (¬ification[i].member.queueName, - &entry->message_queue->name, - sizeof (SaNameT)); - notification[i].change = entry->change; - i++; - } - break; - - case SA_TRACK_CHANGES_ONLY: - - for (list = group->message_queue_head.next; - list != &group->message_queue_head; - list = list->next) - { - entry = list_entry (list, struct queue_group_entry, list); - if (entry->change != SA_MSG_QUEUE_GROUP_NO_CHANGE) { - memcpy (¬ification[i].member.queueName, - &entry->message_queue->name, - sizeof (SaNameT)); - notification[i].change = entry->change; - i++; - } - } - break; - - default: - break; - } - - return (i); -} - -static int msg_exec_init_fn (struct corosync_api_v1 *corosync_api) -{ - api = corosync_api; - - /* - * Initialize the saved ring ID. - */ - - /* saved_ring_id.seq = 0; */ - /* saved_ring_id.rep.s_addr = this_ip->sin_addr.s_addr; */ - - return (0); -} - -static int msg_lib_exit_fn (void *conn) -{ - /* - * struct msg_pd *msg_pd = (struct msg_pd *)api->ipc_private_data_get (conn); - */ - -#ifdef COMPILE_OUT - struct queue_cleanup *queue_cleanup; - struct list_head *list; - - /* - * close all queues opened on this fd - */ - list = conn_info->conn_info_partner->ais_ci.u.libmsg_ci.queue_cleanup_list.next; - while (!list_empty(&conn_info->conn_info_partner->ais_ci.u.libmsg_ci.queue_cleanup_list)) { - - queue_cleanup = list_entry (list, struct queue_cleanup, list); - - if (queue_cleanup->queue->name.length > 0) { - msg_queue_cleanup_lock_remove (queue_cleanup); - msg_queue_close (queue_cleanup->queue); - } - - list_del (&queue_cleanup->list); - free (queue_cleanup); - - list = conn_info->conn_info_partner->ais_ci.u.libmsg_ci.queue_cleanup_list.next; - } -#endif /* COMPILE_OUT */ - - return (0); -} - -static int msg_lib_init_fn (void *conn) -{ - struct msg_pd *msg_pd = (struct msg_pd *)api->ipc_private_data_get (conn); - - list_init (&msg_pd->queue_list); - list_init (&msg_pd->queue_cleanup_list); - - return (0); -} - -static void message_handler_req_exec_msg_queueopen ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queueopen *req_exec_msg_queueopen = - (struct req_exec_msg_queueopen *)message; - struct res_lib_msg_queueopen res_lib_msg_queueopen; - struct res_lib_msg_queueopenasync res_lib_msg_queueopenasync; - struct message_queue *queue; - /* struct queue_cleanup *queue_cleanup; */ - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saMsgQueueOpen %s\n", - getSaNameT (&req_exec_msg_queueopen->queue_name)); - - queue = queue_find (&req_exec_msg_queueopen->queue_name); - - /* - * If queue doesn't exist, create one - */ - if (queue == 0) { - if ((req_exec_msg_queueopen->openFlags & SA_MSG_QUEUE_CREATE) == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - queue = malloc (sizeof (struct message_queue)); - if (queue == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - memset (queue, 0, sizeof (struct message_queue)); - - memcpy (&queue->name, - &req_exec_msg_queueopen->queue_name, - sizeof (SaNameT)); - list_init (&queue->list); - list_init (&queue->message_list_head); - list_add (&queue->list, &queue_list_head); - queue->refcount = 0; - } - queue->refcount += 1; - -#ifdef COMPILE_OUT - /* - * Setup connection information and mark queue as referenced - */ - queue_cleanup = malloc (sizeof (struct queue_cleanup)); - if (queue_cleanup == 0) { - free (queue); - error = SA_AIS_ERR_NO_MEMORY; - } else { - list_init (&queue_cleanup->list); - list_init (&queue_cleanup->queue_lock_list_head); - queue_cleanup->queue = queue; - queue_cleanup->queue_handle = req_exec_msg_queueopen->queue_handle; - list_add ( - &queue_cleanup->list, - &req_exec_msg_queueopen->source.conn_info->ais_ci.u.libmsg_ci.queue_cleanup_list); - } - queue->refcount += 1; -#endif /* COMPILE_OUT */ - - /* - * Send error result to MSG library - */ -error_exit: - /* - * If this node was the source of the message, respond to this node - */ - if (api->ipc_source_is_local (&req_exec_msg_queueopen->source)) { - /* - * If its an async call respond with the invocation and handle - */ - if (req_exec_msg_queueopen->async_call) - { - res_lib_msg_queueopenasync.header.size = - sizeof (struct res_lib_msg_queueopenasync); - res_lib_msg_queueopenasync.header.id = - MESSAGE_RES_MSG_QUEUEOPENASYNC; - res_lib_msg_queueopenasync.header.error = error; - - res_lib_msg_queueopenasync.invocation = - req_exec_msg_queueopen->invocation; - res_lib_msg_queueopenasync.queueHandle = - req_exec_msg_queueopen->queue_handle; - - memcpy (&res_lib_msg_queueopenasync.source, - &req_exec_msg_queueopen->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response ( - req_exec_msg_queueopen->source.conn, - &res_lib_msg_queueopenasync, - sizeof (struct res_lib_msg_queueopenasync)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queueopen->source.conn), - &res_lib_msg_queueopenasync, - sizeof (struct res_lib_msg_queueopenasync)); - } else { - /* - * otherwise respond with the normal queueopen response - */ - res_lib_msg_queueopen.header.size = - sizeof (struct res_lib_msg_queueopen); - res_lib_msg_queueopen.header.id = - MESSAGE_RES_MSG_QUEUEOPEN; - res_lib_msg_queueopen.header.error = error; - - res_lib_msg_queueopen.queueHandle = - req_exec_msg_queueopen->queue_handle; - - memcpy (&res_lib_msg_queueopen.source, - &req_exec_msg_queueopen->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response ( - req_exec_msg_queueopen->source.conn, - &res_lib_msg_queueopen, - sizeof (struct res_lib_msg_queueopen)); - } - } -} - -static void message_handler_req_exec_msg_queueclose ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queueclose *req_exec_msg_queueclose = - (struct req_exec_msg_queueclose *)message; - struct res_lib_msg_queueclose res_lib_msg_queueclose; - struct message_queue *queue = 0; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saMsgQueueClose %s\n", - getSaNameT (&req_exec_msg_queueclose->queue_name)); - - queue = queue_find (&req_exec_msg_queueclose->queue_name); - if (queue == 0) { - goto error_exit; - } - - queue->refcount -= 1; - - if (queue->refcount == 0) { - /* free queue */ - } - -error_exit: - if (api->ipc_source_is_local(&req_exec_msg_queueclose->source)) - { - - /* TODO */ - - /* - * msg_queue_cleanup_remove ( - * req_exec_msg_queueclose->source.conn_info, - * req_exec_msg_queueclose->queue_handle); - */ - - res_lib_msg_queueclose.header.size = - sizeof (struct res_lib_msg_queueclose); - res_lib_msg_queueclose.header.id = - MESSAGE_RES_MSG_QUEUECLOSE; - res_lib_msg_queueclose.header.error = error; - - api->ipc_conn_send_response ( - req_exec_msg_queueclose->source.conn, - &res_lib_msg_queueclose, - sizeof (struct res_lib_msg_queueclose)); - } -} - -static void message_handler_req_exec_msg_queuestatusget ( - void *message, - unsigned int nodeid) -{ -#if 0 - struct req_exec_msg_queuestatusget *req_exec_msg_queuestatusget = - (struct req_exec_msg_queuestatusget *)message; - struct res_lib_msg_queuestatusget res_lib_msg_queuestatusget; -#endif -} - -static void message_handler_req_exec_msg_queueunlink ( - void *message, - unsigned int nodeid) -{ -#if 0 - struct req_exec_msg_queueunlink *req_exec_msg_queueunlink = - (struct req_exec_msg_queueunlink *)message; - struct res_lib_msg_queueunlink res_lib_msg_queueunlink; -#endif -} - -static void message_handler_req_exec_msg_queuegroupcreate ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queuegroupcreate *req_exec_msg_queuegroupcreate = - (struct req_exec_msg_queuegroupcreate *)message; - struct res_lib_msg_queuegroupcreate res_lib_msg_queuegroupcreate; - struct queue_group *queue_group; - SaAisErrorT error = SA_AIS_OK; - - queue_group = queue_group_find (&req_exec_msg_queuegroupcreate->queue_group_name); - - if (queue_group == 0) { - queue_group = malloc (sizeof (struct queue_group)); - if (queue_group == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - memset (queue_group, 0, sizeof (struct queue_group)); - - memcpy (&queue_group->name, - &req_exec_msg_queuegroupcreate->queue_group_name, - sizeof (SaNameT)); - list_init (&queue_group->list); - list_init (&queue_group->message_queue_head); - list_add (&queue_group->list, &queue_group_list_head); - } else { - error = SA_AIS_ERR_EXIST; - } - -error_exit: - if (api->ipc_source_is_local(&req_exec_msg_queuegroupcreate->source)) { - res_lib_msg_queuegroupcreate.header.size = - sizeof (struct res_lib_msg_queuegroupcreate); - res_lib_msg_queuegroupcreate.header.id = - MESSAGE_RES_MSG_QUEUEGROUPCREATE; - res_lib_msg_queuegroupcreate.header.error = error; - - api->ipc_conn_send_response ( - req_exec_msg_queuegroupcreate->source.conn, - &res_lib_msg_queuegroupcreate, - sizeof (struct res_lib_msg_queuegroupcreate)); - } -} - -static void message_handler_req_exec_msg_queuegroupinsert ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queuegroupinsert *req_exec_msg_queuegroupinsert = - (struct req_exec_msg_queuegroupinsert *)message; - struct res_lib_msg_queuegroupinsert res_lib_msg_queuegroupinsert; - struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack; - struct message_queue *queue; - struct queue_group *queue_group; - struct queue_group_entry *queue_group_entry; - SaMsgQueueGroupNotificationT *notification; - SaAisErrorT error = SA_AIS_OK; - SaAisErrorT error_cb = SA_AIS_OK; - - unsigned int change_count = 0; - unsigned int member_count = 0; - - queue_group = queue_group_find (&req_exec_msg_queuegroupinsert->queue_group_name); - - if (queue_group == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - queue = queue_find (&req_exec_msg_queuegroupinsert->queue_name); - if (queue == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - queue_group_entry = malloc (sizeof (struct queue_group_entry)); - if (queue_group_entry == 0) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - list_init (&queue_group_entry->list); - list_add (&queue_group_entry->list, &queue_group->message_queue_head); - list_add (&queue->list, &queue_list_head); - - queue_group_entry->message_queue = queue; - queue_group_entry->change = SA_MSG_QUEUE_GROUP_ADDED; - - if (queue_group->track_flags & SA_TRACK_CHANGES) { - member_count = queue_group_member_count (queue_group); - change_count = queue_group_change_count (queue_group); - - notification = malloc (sizeof (SaMsgQueueGroupNotificationT) * member_count); - - if (notification == NULL) { - error_cb = SA_AIS_ERR_NO_MEMORY; - goto error_track; - } - - memset (notification, 0, sizeof (SaMsgQueueGroupNotificationT) * member_count); - - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems = - queue_group_track (queue_group, - SA_TRACK_CHANGES, - (void *)(notification)); - } - - if (queue_group->track_flags & SA_TRACK_CHANGES_ONLY) { - member_count = queue_group_member_count (queue_group); - change_count = queue_group_change_count (queue_group); - - notification = malloc (sizeof (SaMsgQueueGroupNotificationT) * change_count); - - if (notification == NULL) { - error_cb = SA_AIS_ERR_NO_MEMORY; - goto error_track; - } - - memset (notification, 0, sizeof (SaMsgQueueGroupNotificationT) * change_count); - - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems = - queue_group_track (queue_group, - SA_TRACK_CHANGES_ONLY, - (void *)(notification)); - } - -error_track: - queue_group_entry->change = SA_MSG_QUEUE_GROUP_NO_CHANGE; - -error_exit: - if (api->ipc_source_is_local(&req_exec_msg_queuegroupinsert->source)) { - res_lib_msg_queuegroupinsert.header.size = - sizeof (struct res_lib_msg_queuegroupinsert); - res_lib_msg_queuegroupinsert.header.id = - MESSAGE_RES_MSG_QUEUEGROUPINSERT; - res_lib_msg_queuegroupinsert.header.error = error; - - api->ipc_conn_send_response ( - req_exec_msg_queuegroupinsert->source.conn, - &res_lib_msg_queuegroupinsert, - sizeof (struct res_lib_msg_queuegroupinsert)); - - /* - * Track changes (callback) if tracking is enabled - */ - - if ((queue_group->track_flags & SA_TRACK_CHANGES) || - (queue_group->track_flags & SA_TRACK_CHANGES_ONLY)) - { - res_lib_msg_queuegrouptrack.header.size = - (sizeof (struct res_lib_msg_queuegrouptrack) + - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems)); - res_lib_msg_queuegrouptrack.header.id = - MESSAGE_RES_MSG_QUEUEGROUPTRACK; - res_lib_msg_queuegrouptrack.header.error = error_cb; - res_lib_msg_queuegrouptrack.numberOfMembers = member_count; - - memcpy (&res_lib_msg_queuegrouptrack.queueGroupName, - &req_exec_msg_queuegroupinsert->queue_group_name, - sizeof (SaNameT)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queuegroupinsert->source.conn), - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queuegroupinsert->source.conn), - notification, - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems)); - } - } -} - -static void message_handler_req_exec_msg_queuegroupremove ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queuegroupremove *req_exec_msg_queuegroupremove = - (struct req_exec_msg_queuegroupremove *)message; - struct res_lib_msg_queuegroupremove res_lib_msg_queuegroupremove; - struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack; - struct queue_group *queue_group; - struct message_queue *queue; - struct queue_group_entry *queue_group_entry; - SaMsgQueueGroupNotificationT *notification; - SaAisErrorT error = SA_AIS_OK; - SaAisErrorT error_cb = SA_AIS_OK; - - unsigned int change_count = 0; - unsigned int member_count = 0; - - queue_group = queue_group_find (&req_exec_msg_queuegroupremove->queue_group_name); - if (queue_group == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - queue = queue_find (&req_exec_msg_queuegroupremove->queue_name); - if (queue == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - queue_group_entry = queue_group_entry_find (queue_group, queue); - if (queue_group_entry == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - queue_group_entry->change = SA_MSG_QUEUE_GROUP_REMOVED; - - if (queue_group->track_flags & SA_TRACK_CHANGES) { - member_count = queue_group_member_count (queue_group); - change_count = queue_group_change_count (queue_group); - - notification = malloc (sizeof (SaMsgQueueGroupNotificationT) * member_count); - - if (notification == NULL) { - error_cb = SA_AIS_ERR_NO_MEMORY; - goto error_track; - } - - memset (notification, 0, (sizeof (SaMsgQueueGroupNotificationT) * member_count)); - - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems = - queue_group_track (queue_group, - SA_TRACK_CHANGES, - (void *)(notification)); - } - - if (queue_group->track_flags & SA_TRACK_CHANGES_ONLY) { - member_count = queue_group_member_count (queue_group); - change_count = queue_group_change_count (queue_group); - - notification = malloc (sizeof (SaMsgQueueGroupNotificationT) * change_count); - - if (notification == NULL) { - error_cb = SA_AIS_ERR_NO_MEMORY; - goto error_track; - } - - memset (notification, 0, (sizeof (SaMsgQueueGroupNotificationT) * change_count)); - - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems = - queue_group_track (queue_group, - SA_TRACK_CHANGES_ONLY, - (void *)(notification)); - } - -error_track: - queue_group_entry->change = SA_MSG_QUEUE_GROUP_NO_CHANGE; - - list_del (&queue_group_entry->list); - -error_exit: - if (api->ipc_source_is_local(&req_exec_msg_queuegroupremove->source)) { - res_lib_msg_queuegroupremove.header.size = - sizeof (struct res_lib_msg_queuegroupremove); - res_lib_msg_queuegroupremove.header.id = - MESSAGE_RES_MSG_QUEUEGROUPREMOVE; - res_lib_msg_queuegroupremove.header.error = error; - - api->ipc_conn_send_response ( - req_exec_msg_queuegroupremove->source.conn, - &res_lib_msg_queuegroupremove, - sizeof (struct res_lib_msg_queuegroupremove)); - - /* - * Track changes (callback) if tracking is enabled - */ - - if ((queue_group->track_flags & SA_TRACK_CHANGES) || - (queue_group->track_flags & SA_TRACK_CHANGES_ONLY)) - { - res_lib_msg_queuegrouptrack.header.size = - (sizeof (struct res_lib_msg_queuegrouptrack) + - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems)); - res_lib_msg_queuegrouptrack.header.id = - MESSAGE_RES_MSG_QUEUEGROUPTRACK; - res_lib_msg_queuegrouptrack.header.error = error_cb; - res_lib_msg_queuegrouptrack.numberOfMembers = member_count; - - memcpy (&res_lib_msg_queuegrouptrack.queueGroupName, - &req_exec_msg_queuegroupremove->queue_group_name, - sizeof (SaNameT)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queuegroupremove->source.conn), - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queuegroupremove->source.conn), - notification, - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems)); - } - } -} - -static void message_handler_req_exec_msg_queuegroupdelete ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queuegroupdelete *req_exec_msg_queuegroupdelete = - (struct req_exec_msg_queuegroupdelete *)message; - struct res_lib_msg_queuegroupdelete res_lib_msg_queuegroupdelete; - struct queue_group *queue_group; - SaAisErrorT error = SA_AIS_OK; - - queue_group = queue_group_find (&req_exec_msg_queuegroupdelete->queue_group_name); - - if (queue_group) { - list_del (&queue_group->list); - free (queue_group); - } else { - error = SA_AIS_ERR_NOT_EXIST; - } - - if (api->ipc_source_is_local(&req_exec_msg_queuegroupdelete->source)) { - res_lib_msg_queuegroupdelete.header.size = - sizeof (struct res_lib_msg_queuegroupdelete); - res_lib_msg_queuegroupdelete.header.id = - MESSAGE_RES_MSG_QUEUEGROUPDELETE; - res_lib_msg_queuegroupdelete.header.error = error; - - api->ipc_conn_send_response ( - req_exec_msg_queuegroupdelete->source.conn, - &res_lib_msg_queuegroupdelete, - sizeof (struct res_lib_msg_queuegroupdelete)); - } -} - -static void message_handler_req_exec_msg_queuegrouptrack ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queuegrouptrack *req_exec_msg_queuegrouptrack = - (struct req_exec_msg_queuegrouptrack *)message; - struct res_lib_msg_queuegrouptrack res_lib_msg_queuegrouptrack; - struct queue_group *queue_group; - SaAisErrorT error = SA_AIS_OK; - - unsigned int change_count = 0; - unsigned int member_count = 0; - - SaMsgQueueGroupNotificationT *notification; - - queue_group = queue_group_find (&req_exec_msg_queuegrouptrack->queue_group_name); - - if (queue_group == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - member_count = queue_group_member_count (queue_group); - change_count = queue_group_change_count (queue_group); - - if (req_exec_msg_queuegrouptrack->track_flags & SA_TRACK_CURRENT) { - /* DEBUG */ - log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: SA_TRACK_CURRENT\n"); - - notification = malloc (sizeof (SaMsgQueueGroupNotificationT) * member_count); - - if (notification == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - memset (notification, 0, sizeof (SaMsgQueueGroupNotificationT) * member_count); - - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems = - queue_group_track (queue_group, SA_TRACK_CURRENT, (void *)(notification)); - } - - if (req_exec_msg_queuegrouptrack->track_flags & SA_TRACK_CHANGES) { - /* DEBUG */ - log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: SA_TRACK_CHANGES\n"); - queue_group->track_flags = req_exec_msg_queuegrouptrack->track_flags; - } - - if (req_exec_msg_queuegrouptrack->track_flags & SA_TRACK_CHANGES_ONLY) { - /* DEBUG */ - log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: SA_TRACK_CHANGES_ONLY\n"); - queue_group->track_flags = req_exec_msg_queuegrouptrack->track_flags; - } - -error_exit: - if (api->ipc_source_is_local(&req_exec_msg_queuegrouptrack->source)) { - res_lib_msg_queuegrouptrack.header.size = - sizeof (struct res_lib_msg_queuegrouptrack); - res_lib_msg_queuegrouptrack.header.id = - MESSAGE_RES_MSG_QUEUEGROUPTRACK; - res_lib_msg_queuegrouptrack.header.error = error; - res_lib_msg_queuegrouptrack.numberOfMembers = member_count; - - memcpy (&res_lib_msg_queuegrouptrack.queueGroupName, - &req_exec_msg_queuegrouptrack->queue_group_name, - sizeof (SaNameT)); - - if (req_exec_msg_queuegrouptrack->track_flags & SA_TRACK_CURRENT) { - if (req_exec_msg_queuegrouptrack->buffer_flag) { - res_lib_msg_queuegrouptrack.header.size += - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems); - - api->ipc_conn_send_response ( - req_exec_msg_queuegrouptrack->source.conn, - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - - api->ipc_conn_send_response ( - req_exec_msg_queuegrouptrack->source.conn, - notification, - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems)); - } else { - api->ipc_conn_send_response ( - req_exec_msg_queuegrouptrack->source.conn, - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - - res_lib_msg_queuegrouptrack.header.size += - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queuegrouptrack->source.conn), - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_queuegrouptrack->source.conn), - notification, - (sizeof (SaMsgQueueGroupNotificationT) * - res_lib_msg_queuegrouptrack.notificationBuffer.numberOfItems)); - } - } else { - api->ipc_conn_send_response ( - req_exec_msg_queuegrouptrack->source.conn, - &res_lib_msg_queuegrouptrack, - sizeof (struct res_lib_msg_queuegrouptrack)); - } - } -} - -static void message_handler_req_exec_msg_queuegrouptrackstop ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_queuegrouptrackstop *req_exec_msg_queuegrouptrackstop = - (struct req_exec_msg_queuegrouptrackstop *)message; - struct res_lib_msg_queuegrouptrackstop res_lib_msg_queuegrouptrackstop; - struct queue_group *queue_group; - SaAisErrorT error = SA_AIS_OK; - - queue_group = queue_group_find (&req_exec_msg_queuegrouptrackstop->queue_group_name); - - if (queue_group == 0) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if ((queue_group->track_flags != SA_TRACK_CHANGES) && - (queue_group->track_flags != SA_TRACK_CHANGES_ONLY)) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - queue_group->track_flags = 0; - -error_exit: - if (api->ipc_source_is_local(&req_exec_msg_queuegrouptrackstop->source)) { - res_lib_msg_queuegrouptrackstop.header.size = - sizeof (struct res_lib_msg_queuegrouptrackstop); - res_lib_msg_queuegrouptrackstop.header.id = - MESSAGE_RES_MSG_QUEUEGROUPTRACKSTOP; - res_lib_msg_queuegrouptrackstop.header.error = error; - - api->ipc_conn_send_response ( - req_exec_msg_queuegrouptrackstop->source.conn, - &res_lib_msg_queuegrouptrackstop, - sizeof (struct res_lib_msg_queuegrouptrackstop)); - } -} - -static void message_handler_req_exec_msg_messagesend ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_messagesend *req_exec_msg_messagesend = - (struct req_exec_msg_messagesend *)message; - struct res_lib_msg_messagesend res_lib_msg_messagesend; - struct res_lib_msg_messagesendasync res_lib_msg_messagesendasync; - struct message_queue *queue; - struct message_entry *entry; - SaAisErrorT error = SA_AIS_OK; - - char *data = ((char *)(req_exec_msg_messagesend) + - sizeof (struct req_exec_msg_messagesend)); - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saMsgMessageSend %s\n", - getSaNameT (&req_exec_msg_messagesend->destination)); - - queue = queue_find (&req_exec_msg_messagesend->destination); - if (queue == NULL) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - entry = malloc (sizeof (struct message_entry)); - if (entry == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - memset (entry, 0, sizeof (struct message_entry)); - memcpy (&entry->message, &req_exec_msg_messagesend->message, - sizeof (SaMsgMessageT)); - - entry->message.data = malloc (entry->message.size); - if (entry->message.data == NULL) { - error = SA_AIS_ERR_NO_MEMORY; - goto error_exit; - } - - memset (entry->message.data, 0, entry->message.size); - memcpy (entry->message.data, (void *)(data), entry->message.size); - - entry->time = clust_time_now(); - - list_add_tail (&entry->list, &queue->message_list_head); - -error_exit: - - if (api->ipc_source_is_local(&req_exec_msg_messagesend->source)) { - if (req_exec_msg_messagesend->async_call) { - res_lib_msg_messagesendasync.header.size = - sizeof (struct res_lib_msg_messagesendasync); - res_lib_msg_messagesendasync.header.id = - MESSAGE_RES_MSG_MESSAGESENDASYNC; - res_lib_msg_messagesendasync.header.error = error; - res_lib_msg_messagesendasync.invocation = - req_exec_msg_messagesend->invocation; - - memcpy (&res_lib_msg_messagesendasync.source, - &req_exec_msg_messagesend->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response ( - req_exec_msg_messagesend->source.conn, - &res_lib_msg_messagesendasync, - sizeof (struct res_lib_msg_messagesendasync)); - - api->ipc_conn_send_response ( - api->ipc_conn_partner_get (req_exec_msg_messagesend->source.conn), - &res_lib_msg_messagesendasync, - sizeof (struct res_lib_msg_messagesendasync)); - } else { - res_lib_msg_messagesend.header.size = - sizeof (struct res_lib_msg_messagesend); - res_lib_msg_messagesend.header.id = - MESSAGE_RES_MSG_MESSAGESEND; - res_lib_msg_messagesend.header.error = error; - - memcpy (&res_lib_msg_messagesend.source, - &req_exec_msg_messagesend->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response ( - req_exec_msg_messagesend->source.conn, - &res_lib_msg_messagesend, - sizeof (struct res_lib_msg_messagesend)); - } - } -} - -static void message_handler_req_exec_msg_messageget ( - void *message, - unsigned int nodeid) -{ - struct req_exec_msg_messageget *req_exec_msg_messageget = - (struct req_exec_msg_messageget *)message; - struct res_lib_msg_messageget res_lib_msg_messageget; - struct message_queue *queue; - struct message_entry *entry; - SaAisErrorT error = SA_AIS_OK; - - log_printf (LOG_LEVEL_NOTICE, "EXEC request: saMsgMessageGet %s\n", - getSaNameT (&req_exec_msg_messageget->queue_name)); - - queue = queue_find (&req_exec_msg_messageget->queue_name); - if (queue == NULL) { - error = SA_AIS_ERR_NOT_EXIST; - goto error_exit; - } - - if (list_empty (queue->message_list_head.next)) { - error = SA_AIS_ERR_TIMEOUT; /* FIX ME */ - goto error_exit; - } - - entry = list_entry (queue->message_list_head.next, struct message_entry, list); - if (entry == NULL) { - error = SA_AIS_ERR_LIBRARY; /* FIX ME */ - goto error_exit; - } - - list_del (queue->message_list_head.next); - -error_exit: - - if (api->ipc_source_is_local(&req_exec_msg_messageget->source)) { - res_lib_msg_messageget.header.size = - sizeof (struct res_lib_msg_messageget); - res_lib_msg_messageget.header.id = - MESSAGE_RES_MSG_MESSAGEGET; - res_lib_msg_messageget.header.error = error; - - memcpy (&res_lib_msg_messageget.message, &entry->message, - sizeof (SaMsgMessageT)); - memcpy (&res_lib_msg_messageget.source, - &req_exec_msg_messageget->source, - sizeof (mar_message_source_t)); - - api->ipc_conn_send_response ( - req_exec_msg_messageget->source.conn, - &res_lib_msg_messageget, - sizeof (struct res_lib_msg_messageget)); - - api->ipc_conn_send_response ( - req_exec_msg_messageget->source.conn, - res_lib_msg_messageget.message.data, - res_lib_msg_messageget.message.size); - } -} - -static void message_handler_req_exec_msg_messagecancel ( - void *message, - unsigned int nodeid) -{ -#if 0 - struct req_exec_msg_messagecancel *req_exec_msg_messagecancel = - (struct req_exec_msg_messagecancel *)message; - struct res_lib_msg_messagecancel res_lib_msg_messagecancel; -#endif -} - -static void message_handler_req_exec_msg_messagesendreceive ( - void *message, - unsigned int nodeid) -{ -#if 0 - struct req_exec_msg_messagesendreceive *req_exec_msg_messagesendreceive = - (struct req_exec_msg_messagesendreceive *)message; - struct res_lib_msg_messagesendreceive res_lib_msg_messagesendreceive; -#endif -} - -static void message_handler_req_exec_msg_messagereply ( - void *message, - unsigned int nodeid) -{ -#if 0 - struct req_exec_msg_messagereply *req_exec_msg_messagereply = - (struct req_exec_msg_messagereply *)message; - struct res_lib_msg_messagereply res_lib_msg_messagereply; -#endif -} - -static void message_handler_req_lib_msg_queueopen ( - void *conn, - void *msg) -{ - struct req_lib_msg_queueopen *req_lib_msg_queueopen = - (struct req_lib_msg_queueopen *)msg; - struct req_exec_msg_queueopen req_exec_msg_queueopen; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueOpen %s\n", - getSaNameT (&req_lib_msg_queueopen->queueName)); - - req_exec_msg_queueopen.header.size = - sizeof (struct req_exec_msg_queueopen); - req_exec_msg_queueopen.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEOPEN); - - api->ipc_source_set (&req_exec_msg_queueopen.source, conn); - - memcpy (&req_exec_msg_queueopen.queue_name, - &req_lib_msg_queueopen->queueName, sizeof (SaNameT)); - - memcpy (&req_exec_msg_queueopen.creation_attributes, - &req_lib_msg_queueopen->creationAttributes, - sizeof (SaMsgQueueCreationAttributesT)); - - req_exec_msg_queueopen.async_call = 0; - req_exec_msg_queueopen.invocation = 0; - req_exec_msg_queueopen.queue_handle = req_lib_msg_queueopen->queueHandle; - req_exec_msg_queueopen.openFlags = req_lib_msg_queueopen->openFlags; - req_exec_msg_queueopen.timeout = req_lib_msg_queueopen->timeout; - - iovec.iov_base = (char *)&req_exec_msg_queueopen; - iovec.iov_len = sizeof (req_exec_msg_queueopen); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queueopenasync ( - void *conn, - void *msg) -{ - struct req_lib_msg_queueopen *req_lib_msg_queueopen = - (struct req_lib_msg_queueopen *)msg; - struct req_exec_msg_queueopen req_exec_msg_queueopen; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueOpenAsync %s\n", - getSaNameT (&req_lib_msg_queueopen->queueName)); - - req_exec_msg_queueopen.header.size = - sizeof (struct req_exec_msg_queueopen); - req_exec_msg_queueopen.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEOPEN); - - api->ipc_source_set (&req_exec_msg_queueopen.source, conn); - - memcpy (&req_exec_msg_queueopen.queue_name, - &req_lib_msg_queueopen->queueName, sizeof (SaNameT)); - - memcpy (&req_exec_msg_queueopen.creation_attributes, - &req_lib_msg_queueopen->creationAttributes, - sizeof (SaMsgQueueCreationAttributesT)); - - req_exec_msg_queueopen.async_call = 1; - req_exec_msg_queueopen.invocation = req_lib_msg_queueopen->invocation; - req_exec_msg_queueopen.queue_handle = req_lib_msg_queueopen->queueHandle; - req_exec_msg_queueopen.openFlags = req_lib_msg_queueopen->openFlags; - req_exec_msg_queueopen.timeout = SA_TIME_END; - - iovec.iov_base = (char *)&req_exec_msg_queueopen; - iovec.iov_len = sizeof (req_exec_msg_queueopen); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queueclose ( - void *conn, - void *msg) -{ - struct req_lib_msg_queueclose *req_lib_msg_queueclose = - (struct req_lib_msg_queueclose *)msg; - struct req_exec_msg_queueclose req_exec_msg_queueclose; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueClose %s\n", - getSaNameT (&req_lib_msg_queueclose->queueName)); - - req_exec_msg_queueclose.header.size = - sizeof (struct req_exec_msg_queueclose); - req_exec_msg_queueclose.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUECLOSE); - - api->ipc_source_set (&req_exec_msg_queueclose.source, conn); - - memcpy (&req_exec_msg_queueclose.queue_name, - &req_lib_msg_queueclose->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queueclose; - iovec.iov_len = sizeof (req_exec_msg_queueclose); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuestatusget ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuestatusget *req_lib_msg_queuestatusget = - (struct req_lib_msg_queuestatusget *)msg; - struct req_exec_msg_queuestatusget req_exec_msg_queuestatusget; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueStatusGet %s\n", - getSaNameT (&req_lib_msg_queuestatusget->queueName)); - - req_exec_msg_queuestatusget.header.size = - sizeof (struct req_exec_msg_queuestatusget); - req_exec_msg_queuestatusget.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUESTATUSGET); - - api->ipc_source_set (&req_exec_msg_queuestatusget.source, conn); - - memcpy (&req_exec_msg_queuestatusget.queue_name, - &req_lib_msg_queuestatusget->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queuestatusget; - iovec.iov_len = sizeof (req_exec_msg_queuestatusget); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queueunlink ( - void *conn, - void *msg) -{ - struct req_lib_msg_queueunlink *req_lib_msg_queueunlink = - (struct req_lib_msg_queueunlink *)msg; - struct req_exec_msg_queueunlink req_exec_msg_queueunlink; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueUnlink %s\n", - getSaNameT (&req_lib_msg_queueunlink->queueName)); - - req_exec_msg_queueunlink.header.size = - sizeof (struct req_exec_msg_queueunlink); - req_exec_msg_queueunlink.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEUNLINK); - - api->ipc_source_set (&req_exec_msg_queueunlink.source, conn); - - memcpy (&req_exec_msg_queueunlink.queue_name, - &req_lib_msg_queueunlink->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queueunlink; - iovec.iov_len = sizeof (req_exec_msg_queueunlink); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuegroupcreate ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuegroupcreate *req_lib_msg_queuegroupcreate = - (struct req_lib_msg_queuegroupcreate *)msg; - struct req_exec_msg_queuegroupcreate req_exec_msg_queuegroupcreate; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueGroupCreate %s\n", - getSaNameT (&req_lib_msg_queuegroupcreate->queueGroupName)); - - req_exec_msg_queuegroupcreate.header.size = - sizeof (struct req_exec_msg_queuegroupcreate); - req_exec_msg_queuegroupcreate.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEGROUPCREATE); - - api->ipc_source_set (&req_exec_msg_queuegroupcreate.source, conn); - - memcpy (&req_exec_msg_queuegroupcreate.queue_group_name, - &req_lib_msg_queuegroupcreate->queueGroupName, sizeof (SaNameT)); - - req_exec_msg_queuegroupcreate.policy = - req_lib_msg_queuegroupcreate->queueGroupPolicy; - - iovec.iov_base = (char *)&req_exec_msg_queuegroupcreate; - iovec.iov_len = sizeof (req_exec_msg_queuegroupcreate); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuegroupinsert ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuegroupinsert *req_lib_msg_queuegroupinsert = - (struct req_lib_msg_queuegroupinsert *)msg; - struct req_exec_msg_queuegroupinsert req_exec_msg_queuegroupinsert; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueGroupInsert %s\n", - getSaNameT (&req_lib_msg_queuegroupinsert->queueGroupName)); - - req_exec_msg_queuegroupinsert.header.size = - sizeof (struct req_exec_msg_queuegroupinsert); - req_exec_msg_queuegroupinsert.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEGROUPINSERT); - - api->ipc_source_set (&req_exec_msg_queuegroupinsert.source, conn); - - memcpy (&req_exec_msg_queuegroupinsert.queue_name, - &req_lib_msg_queuegroupinsert->queueName, sizeof (SaNameT)); - memcpy (&req_exec_msg_queuegroupinsert.queue_group_name, - &req_lib_msg_queuegroupinsert->queueGroupName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queuegroupinsert; - iovec.iov_len = sizeof (req_exec_msg_queuegroupinsert); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuegroupremove ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuegroupremove *req_lib_msg_queuegroupremove = - (struct req_lib_msg_queuegroupremove *)msg; - struct req_exec_msg_queuegroupremove req_exec_msg_queuegroupremove; - struct iovec iovec; - - req_exec_msg_queuegroupremove.header.size = - sizeof (struct req_exec_msg_queuegroupremove); - req_exec_msg_queuegroupremove.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEGROUPREMOVE); - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueGroupRemove %s\n", - getSaNameT (&req_lib_msg_queuegroupremove->queueGroupName)); - - api->ipc_source_set (&req_exec_msg_queuegroupremove.source, conn); - - memcpy (&req_exec_msg_queuegroupremove.queue_name, - &req_lib_msg_queuegroupremove->queueName, sizeof (SaNameT)); - memcpy (&req_exec_msg_queuegroupremove.queue_group_name, - &req_lib_msg_queuegroupremove->queueGroupName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queuegroupremove; - iovec.iov_len = sizeof (req_exec_msg_queuegroupremove); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuegroupdelete ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuegroupdelete *req_lib_msg_queuegroupdelete = - (struct req_lib_msg_queuegroupdelete *)msg; - struct req_exec_msg_queuegroupdelete req_exec_msg_queuegroupdelete; - struct iovec iovec; - - req_exec_msg_queuegroupdelete.header.size = - sizeof (struct req_exec_msg_queuegroupdelete); - req_exec_msg_queuegroupdelete.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEGROUPDELETE); - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueGroupDelete %s\n", - getSaNameT (&req_lib_msg_queuegroupdelete->queueGroupName)); - - api->ipc_source_set (&req_exec_msg_queuegroupdelete.source, conn); - - memcpy (&req_exec_msg_queuegroupdelete.queue_group_name, - &req_lib_msg_queuegroupdelete->queueGroupName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queuegroupdelete; - iovec.iov_len = sizeof (req_exec_msg_queuegroupdelete); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuegrouptrack ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuegrouptrack *req_lib_msg_queuegrouptrack = - (struct req_lib_msg_queuegrouptrack *)msg; - struct req_exec_msg_queuegrouptrack req_exec_msg_queuegrouptrack; - struct iovec iovec; - - req_exec_msg_queuegrouptrack.header.size = - sizeof (struct req_exec_msg_queuegrouptrack); - req_exec_msg_queuegrouptrack.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEGROUPTRACK); - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueGroupTrack %s\n", - getSaNameT (&req_lib_msg_queuegrouptrack->queueGroupName)); - - api->ipc_source_set (&req_exec_msg_queuegrouptrack.source, conn); - - memcpy (&req_exec_msg_queuegrouptrack.queue_group_name, - &req_lib_msg_queuegrouptrack->queueGroupName, sizeof (SaNameT)); - - req_exec_msg_queuegrouptrack.track_flags = - req_lib_msg_queuegrouptrack->trackFlags; - req_exec_msg_queuegrouptrack.buffer_flag = - req_lib_msg_queuegrouptrack->bufferFlag; - - iovec.iov_base = (char *)&req_exec_msg_queuegrouptrack; - iovec.iov_len = sizeof (req_exec_msg_queuegrouptrack); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_queuegrouptrackstop ( - void *conn, - void *msg) -{ - struct req_lib_msg_queuegrouptrackstop *req_lib_msg_queuegrouptrackstop = - (struct req_lib_msg_queuegrouptrackstop *)msg; - struct req_exec_msg_queuegrouptrackstop req_exec_msg_queuegrouptrackstop; - struct iovec iovec; - - req_exec_msg_queuegrouptrackstop.header.size = - sizeof (struct req_exec_msg_queuegrouptrackstop); - req_exec_msg_queuegrouptrackstop.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_QUEUEGROUPTRACKSTOP); - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgQueueGroupTrackStop %s\n", - getSaNameT (&req_lib_msg_queuegrouptrackstop->queueGroupName)); - - api->ipc_source_set (&req_exec_msg_queuegrouptrackstop.source, conn); - - memcpy (&req_exec_msg_queuegrouptrackstop.queue_group_name, - &req_lib_msg_queuegrouptrackstop->queueGroupName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_queuegrouptrackstop; - iovec.iov_len = sizeof (req_exec_msg_queuegrouptrackstop); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_messagesend ( - void *conn, - void *msg) -{ - struct req_lib_msg_messagesend *req_lib_msg_messagesend = - (struct req_lib_msg_messagesend *)msg; - struct req_exec_msg_messagesend req_exec_msg_messagesend; - struct iovec iovecs[2]; - - req_exec_msg_messagesend.header.size = - sizeof (struct req_exec_msg_messagesend); - req_exec_msg_messagesend.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGESEND); - req_exec_msg_messagesend.async_call = 0; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageSend %s\n", - getSaNameT (&req_lib_msg_messagesend->destination)); - - api->ipc_source_set (&req_exec_msg_messagesend.source, conn); - - memcpy (&req_exec_msg_messagesend.destination, - &req_lib_msg_messagesend->destination, sizeof (SaNameT)); - memcpy (&req_exec_msg_messagesend.message, - &req_lib_msg_messagesend->message, sizeof (SaMsgMessageT)); - - req_exec_msg_messagesend.async_call = 0; - req_exec_msg_messagesend.invocation = 0; - req_exec_msg_messagesend.ack_flags = req_lib_msg_messagesend->ackFlags; - req_exec_msg_messagesend.timeout = req_lib_msg_messagesend->timeout; - - iovecs[0].iov_base = (char *)&req_exec_msg_messagesend; - iovecs[0].iov_len = sizeof (req_exec_msg_messagesend); - - iovecs[1].iov_base = ((char *)req_lib_msg_messagesend) + - sizeof (struct req_lib_msg_messagesend); - iovecs[1].iov_len = req_lib_msg_messagesend->header.size - - sizeof (struct req_lib_msg_messagesend); - - req_exec_msg_messagesend.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, - TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 1, - TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_msg_messagesendasync ( - void *conn, - void *msg) -{ - struct req_lib_msg_messagesend *req_lib_msg_messagesend = - (struct req_lib_msg_messagesend *)msg; - struct req_exec_msg_messagesend req_exec_msg_messagesend; - struct iovec iovecs[2]; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageSendAsync %s\n", - getSaNameT (&req_lib_msg_messagesend->destination)); - - req_exec_msg_messagesend.header.size = - sizeof (struct req_exec_msg_messagesend); - req_exec_msg_messagesend.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGESEND); - - api->ipc_source_set (&req_exec_msg_messagesend.source, conn); - - memcpy (&req_exec_msg_messagesend.destination, - &req_lib_msg_messagesend->destination, sizeof (SaNameT)); - memcpy (&req_exec_msg_messagesend.message, - &req_lib_msg_messagesend->message, sizeof (SaMsgMessageT)); - - req_exec_msg_messagesend.async_call = 1; - req_exec_msg_messagesend.invocation = req_lib_msg_messagesend->invocation; - req_exec_msg_messagesend.ack_flags = req_lib_msg_messagesend->ackFlags; - req_exec_msg_messagesend.timeout = SA_TIME_END; - - iovecs[0].iov_base = (char *)&req_exec_msg_messagesend; - iovecs[0].iov_len = sizeof (req_exec_msg_messagesend); - - iovecs[1].iov_base = ((char *)req_lib_msg_messagesend) + - sizeof (struct req_lib_msg_messagesend); - iovecs[1].iov_len = req_lib_msg_messagesend->header.size - - sizeof (struct req_lib_msg_messagesend); - - req_exec_msg_messagesend.header.size += iovecs[1].iov_len; - - if (iovecs[1].iov_len > 0) { - assert (api->totem_mcast (iovecs, 2, - TOTEM_AGREED) == 0); - } else { - assert (api->totem_mcast (iovecs, 2, - TOTEM_AGREED) == 0); - } -} - -static void message_handler_req_lib_msg_messageget ( - void *conn, - void *msg) -{ - struct req_lib_msg_messageget *req_lib_msg_messageget = - (struct req_lib_msg_messageget *)msg; - struct req_exec_msg_messageget req_exec_msg_messageget; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageGet %s\n", - getSaNameT (&req_lib_msg_messageget->queueName)); - - req_exec_msg_messageget.header.size = - sizeof (struct req_exec_msg_messageget); - req_exec_msg_messageget.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGEGET); - - api->ipc_source_set (&req_exec_msg_messageget.source, conn); - - memcpy (&req_exec_msg_messageget.queue_name, - &req_lib_msg_messageget->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_messageget; - iovec.iov_len = sizeof (req_exec_msg_messageget); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_messagecancel ( - void *conn, - void *msg) -{ - struct req_lib_msg_messagecancel *req_lib_msg_messagecancel = - (struct req_lib_msg_messagecancel *)msg; - struct req_exec_msg_messagecancel req_exec_msg_messagecancel; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageCancel %s\n", - getSaNameT (&req_lib_msg_messagecancel->queueName)); - - req_exec_msg_messagecancel.header.size = - sizeof (struct req_exec_msg_messagecancel); - req_exec_msg_messagecancel.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGECANCEL); - - api->ipc_source_set (&req_exec_msg_messagecancel.source, conn); - - memcpy (&req_exec_msg_messagecancel.queue_name, - &req_lib_msg_messagecancel->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_messagecancel; - iovec.iov_len = sizeof (req_exec_msg_messagecancel); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_messagesendreceive ( - void *conn, - void *msg) -{ - struct req_lib_msg_messagesendreceive *req_lib_msg_messagesendreceive = - (struct req_lib_msg_messagesendreceive *)msg; - struct req_exec_msg_messagesendreceive req_exec_msg_messagesendreceive; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageSendReceive %s\n", - getSaNameT (&req_lib_msg_messagesendreceive->queueName)); - - req_exec_msg_messagesendreceive.header.size = - sizeof (struct req_exec_msg_messagesendreceive); - req_exec_msg_messagesendreceive.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGESENDRECEIVE); - - api->ipc_source_set (&req_exec_msg_messagesendreceive.source, conn); - - memcpy (&req_exec_msg_messagesendreceive.queue_name, - &req_lib_msg_messagesendreceive->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_messagesendreceive; - iovec.iov_len = sizeof (req_exec_msg_messagesendreceive); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_messagereply ( - void *conn, - void *msg) -{ - struct req_lib_msg_messagereply *req_lib_msg_messagereply = - (struct req_lib_msg_messagereply *)msg; - struct req_exec_msg_messagereply req_exec_msg_messagereply; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageReply %s\n", - getSaNameT (&req_lib_msg_messagereply->queueName)); - - req_exec_msg_messagereply.header.size = - sizeof (struct req_exec_msg_messagereply); - req_exec_msg_messagereply.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGEREPLY); - req_exec_msg_messagereply.async_call = 0; - - api->ipc_source_set (&req_exec_msg_messagereply.source, conn); - - memcpy (&req_exec_msg_messagereply.queue_name, - &req_lib_msg_messagereply->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_messagereply; - iovec.iov_len = sizeof (req_exec_msg_messagereply); - - assert (api->totem_mcast (&iovec, 1, - TOTEM_AGREED) == 0); -} - -static void message_handler_req_lib_msg_messagereplyasync ( - void *conn, - void *msg) -{ - struct req_lib_msg_messagereply *req_lib_msg_messagereply = - (struct req_lib_msg_messagereply *)msg; - struct req_exec_msg_messagereply req_exec_msg_messagereply; - struct iovec iovec; - - log_printf (LOG_LEVEL_NOTICE, "LIB request: saMsgMessageReplyAsync %s\n", - getSaNameT (&req_lib_msg_messagereply->queueName)); - - req_exec_msg_messagereply.header.size = - sizeof (struct req_exec_msg_messagereply); - req_exec_msg_messagereply.header.id = - SERVICE_ID_MAKE (MSG_SERVICE, MESSAGE_REQ_EXEC_MSG_MESSAGEREPLY); - req_exec_msg_messagereply.async_call = 1; - - api->ipc_source_set (&req_exec_msg_messagereply.source, conn); - - memcpy (&req_exec_msg_messagereply.queue_name, - &req_lib_msg_messagereply->queueName, sizeof (SaNameT)); - - iovec.iov_base = (char *)&req_exec_msg_messagereply; - iovec.iov_len = sizeof (req_exec_msg_messagereply); - - assert (api->totem_mcast (&iovec, 1, TOTEM_AGREED) == 0); -} diff --git a/openais/services/openais-instantiate.c b/openais/services/openais-instantiate.c deleted file mode 100644 index 97a2989b..00000000 --- a/openais/services/openais-instantiate.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -struct timespec sleeptime = { - .tv_sec = 0, - .tv_nsec = 10000 /* 10 msec */ -}; - -#ifndef xprintf -#define xprintf(...) -#endif - -/* - * The method by which the status is returned from execve - * needs some performance enhancement - */ -int main (int argc, char **argv, char **envp) -{ - pid_t pid; - pid_t res; - int status; - int i; - - pid = fork(); - if (pid == -1) { - fprintf (stderr, "openais-instantiate: could not fork process %s\n", - strerror (errno)); - return (errno); - } - if (pid) { - /* - * Wait for a status code for at most 100 msec (10 * sleeptime) - * if child never returns a code, it is assumed to have been instantiated - */ - for (i = 0; i < 10; i++) { - res = waitpid (pid, &status, WNOHANG); - if (res) { - if (WEXITSTATUS(status) == 0) { - xprintf ("openais-instantiate: component instantiated\n"); - return (0); - } else { - fprintf (stderr, "openais-instantiate: could not execute " - "program %s, (return code %d = %s)\n", - argv[1], WEXITSTATUS(status), - strerror (WEXITSTATUS(status))); - return (WEXITSTATUS(status)); - } - } - nanosleep (&sleeptime, 0); - - } - xprintf ("openais-instantiate: component instantiated\n"); - return (0); - } else { - - xprintf ("childs pid %d\n", getpid()); - /* - * child process - */ - res = execve (argv[1], &argv[1], envp); - if (res == -1) { - return (errno); - } - } - return (0); -} diff --git a/openais/services/openaisparser.c b/openais/services/openaisparser.c deleted file mode 100644 index 876b19aa..00000000 --- a/openais/services/openaisparser.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (c) 2006 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Patrick Caulfield (pcaulfie@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -static int read_config_file_into_objdb( - struct objdb_iface_ver0 *objdb, - char **error_string); -static char error_string_response[512]; - -static 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); -} - -static int aisparser_readconfig (struct objdb_iface_ver0 *objdb, char **error_string) -{ - if (read_config_file_into_objdb(objdb, error_string)) { - return -1; - } - - return 0; -} - - -static char *remove_whitespace(char *string) -{ - char *start = string+strspn(string, " \t"); - char *end = start+(strlen(start))-1; - - while ((*end == ' ' || *end == '\t' || *end == ':' || *end == '{') && end > start) - end--; - if (end != start) - *(end+1) = '\0'; - - return start; -} - -static int parse_section(FILE *fp, - struct objdb_iface_ver0 *objdb, - unsigned int parent_handle, - char **error_string) -{ - char line[512]; - int i; - char *loc; - - while (fgets (line, 255, fp)) { - line[strlen(line) - 1] = '\0'; - /* - * Clear out white space and tabs - */ - for (i = strlen (line) - 1; i > -1; i--) { - if (line[i] == '\t' || line[i] == ' ') { - line[i] = '\0'; - } else { - break; - } - } - /* - * Clear out comments and empty lines - */ - if (line[0] == '#' || line[0] == '\0') { - continue; - } - - /* New section ? */ - if ((loc = strstr_rs (line, "{"))) { - unsigned int new_parent; - char *section = remove_whitespace(line); - - loc--; - *loc = '\0'; - objdb->object_create (parent_handle, &new_parent, - section, strlen (section)); - if (parse_section(fp, objdb, new_parent, error_string)) - return -1; - } - - /* New key/value */ - if ((loc = strstr_rs (line, ":"))) { - char *key; - char *value; - - *(loc-1) = '\0'; - key = remove_whitespace(line); - value = remove_whitespace(loc); - objdb->object_key_create (parent_handle, key, - strlen (key), - value, strlen (value) + 1); - } - - if ((loc = strstr_rs (line, "}"))) { - return 0; - } - } - - if (parent_handle != OBJECT_PARENT_HANDLE) { - *error_string = "Missing closing brace"; - return -1; - } - - return 0; -} - - - -/* Read config file and load into objdb */ -static int read_config_file_into_objdb( - struct objdb_iface_ver0 *objdb, - char **error_string) -{ - FILE *fp; - char *filename = "/etc/ais/openais.conf"; - char *error_reason = error_string_response; - int res; - unsigned int object_handle; - - fp = fopen (filename, "r"); - if (fp == 0) { - sprintf (error_reason, "Can't read file %s reason = (%s)\n", - filename, strerror (errno)); - *error_string = error_reason; - return -1; - } - - res = parse_section(fp, objdb, OBJECT_PARENT_HANDLE, error_string); - - fclose(fp); - - /* - * Load clm module - */ - objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle, - "service", strlen("service")); - objdb->object_key_create(object_handle, "name", strlen("name"), - "openais_clm", strlen("openais_clm") + 1); - objdb->object_key_create(object_handle, "ver", strlen("ver"), - "0", 2); - - /* - * Load ckpt module - */ - objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle, - "service", strlen("service")); - objdb->object_key_create(object_handle, "name", strlen("name"), - "openais_ckpt", strlen("openais_ckpt") + 1); - objdb->object_key_create(object_handle, "ver", strlen("ver"), - "0", 2); - - /* - * Load evt module - */ - objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle, - "service", strlen("service")); - objdb->object_key_create(object_handle, "name", strlen("name"), - "openais_evt", strlen("openais_evt") + 1); - objdb->object_key_create(object_handle, "ver", strlen("ver"), - "0", 2); - - /* - * Load msg module - */ - objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle, - "service", strlen("service")); - objdb->object_key_create(object_handle, "name", strlen("name"), - "openais_msg", strlen("openais_msg") + 1); - objdb->object_key_create(object_handle, "ver", strlen("ver"), - "0", 2); - - /* - * Load lck module - */ - objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle, - "service", strlen("service")); - objdb->object_key_create(object_handle, "name", strlen("name"), - "openais_lck", strlen("openais_lck") + 1); - objdb->object_key_create(object_handle, "ver", strlen("ver"), - "0", 2); - - sprintf (error_reason, "Successfully read main configuration file '%s'.\n", filename); - *error_string = error_reason; - - return res; -} - -/* - * Dynamic Loader definition - */ - -struct config_iface_ver0 aisparser_iface_ver0 = { - .config_readconfig = aisparser_readconfig, - .config_writeconfig = NULL -}; - -struct lcr_iface openais_aisparser_ver0[1] = { - { - .name = "openaisparser", - .version = 0, - .versions_replace = 0, - .versions_replace_count = 0, - .dependencies = 0, - .dependency_count = 0, - .constructor = NULL, - .destructor = NULL, - .interfaces = NULL, - } -}; - -struct openais_service_handler *aisparser_get_handler_ver0 (void); - -struct lcr_comp aisparser_comp_ver0 = { - .iface_count = 1, - .ifaces = openais_aisparser_ver0 -}; - - -__attribute__ ((constructor)) static void aisparser_comp_register (void) { - lcr_interfaces_set (&openais_aisparser_ver0[0], &aisparser_iface_ver0); - lcr_component_register (&aisparser_comp_ver0); -} - - diff --git a/openais/test/Makefile b/openais/test/Makefile deleted file mode 100644 index b7bd1c6d..00000000 --- a/openais/test/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2002-2004 MontaVista Software, Inc. -# Copyright (c) 2006-2008 Red Hat, Inc. -# -# 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 -# modification, are permitted provided that the following conditions are met: -# -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# - Neither the name of the MontaVista Software, Inc. nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -# Include configuration -# -include ../Makefile.inc - -ifeq (${OPENAIS_COMPAT}, SOLARIS) - override LDFLAGS += -lnsl -lsocket -lrt -endif - -LIBRARIES= ../lib/libSaCkpt.a ../lib/libSaMsg.a sa_error.o -LIBS = $(LIBRARIES) -BINARIES= testckpt testmsg testmsg2 - -override CFLAGS += -I../include -override LDFLAGS += -L../lib - -EXTRA_CFLAGS = -I$(srcdir)include -TEST_SRC = testckpt.c - -all: $(BINARIES) - -testckpt: testckpt.o $(LIBRARIES) - $(CC) $(LDFLAGS) -o testckpt testckpt.o $(LIBS) - -testmsg: testmsg.o $(LIBRARIES) - $(CC) $(LDFLAGS) -o testmsg testmsg.o $(LIBS) - -testmsg2: testmsg2.o $(LIBRARIES) - $(CC) $(LDFLAGS) -o testmsg2 testmsg2.o $(LIBS) - -clean: - rm -f *.o $(LIBRARIES) $(BINARIES) - -%.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< - -depend: - makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(TEST_SRC) > /dev/null 2>&1 diff --git a/openais/test/ckpt-rd.c b/openais/test/ckpt-rd.c deleted file mode 100644 index d9327cec..00000000 --- a/openais/test/ckpt-rd.c +++ /dev/null @@ -1,126 +0,0 @@ -#define _BSD_SOURCE -/* - * Copyright (c) 2002-2004 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saCkpt.h" -#include "sa_error.h" - -#define SECONDS_TO_EXPIRE 4 - -int ckptinv; -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -SaVersionT version = { 'B', 1, 1 }; - -SaNameT checkpointName = { 16, "checkpoint-sync\0" }; - -char readBuffer1[1025]; - - -SaCkptIOVectorElementT ReadVectorElements[] = { - { - SA_CKPT_DEFAULT_SECTION_ID, - readBuffer1, - sizeof (readBuffer1), - 0, - 0 - } -}; - -#define DATASIZE 127000 -char data[DATASIZE]; - -SaCkptCallbacksT callbacks = { - 0, - 0 -}; - -int main (void) { - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT checkpointHandle; - SaAisErrorT error; - SaUint32T erroroneousVectorIndex = 0; - struct timespec delay; - delay.tv_sec = 1; - delay.tv_nsec = 0; - - - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - - error = saCkptCheckpointOpen (ckptHandle, - &checkpointName, - 0, - SA_CKPT_CHECKPOINT_READ, - 0, - &checkpointHandle); - printf ("%s: initial open of checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - while (1) { - error = saCkptCheckpointRead (checkpointHandle, - ReadVectorElements, - 1, - &erroroneousVectorIndex); - if (error != SA_AIS_OK) { - printf ("%s: read checkpoint\n", - get_test_output (error, SA_AIS_OK)); - return (0); - } - - printf ("Checkpoint contains %s\n", - ((((char*) ReadVectorElements->dataBuffer)[0] != '\0') ? (char *)ReadVectorElements->dataBuffer : "empty string.")); - nanosleep(&delay,0); - } - - return (0); -} diff --git a/openais/test/ckpt-wr.c b/openais/test/ckpt-wr.c deleted file mode 100644 index fcc59051..00000000 --- a/openais/test/ckpt-wr.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2002-2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saCkpt.h" -#include "sa_error.h" - -#define SECONDS_TO_EXPIRE 500 - -int ckptinv; -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -SaVersionT version = { 'B', 1, 1 }; - -SaNameT checkpointName = { 16, "checkpoint-sync\0" }; - -SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = { - .creationFlags = SA_CKPT_WR_ALL_REPLICAS, - .checkpointSize = 250000, - .retentionDuration = SA_TIME_ONE_SECOND * 60, - .maxSections = 5, - .maxSectionSize = 250000, - .maxSectionIdSize = 10 -}; - -char readBuffer1[1025]; - -SaCkptIOVectorElementT ReadVectorElements[] = { - { - SA_CKPT_DEFAULT_SECTION_ID, - readBuffer1, - sizeof (readBuffer1), - 0, - 0 - } -}; - -#define DATASIZE 127000 -char data[DATASIZE]; -SaCkptIOVectorElementT WriteVectorElements[] = { - { - SA_CKPT_DEFAULT_SECTION_ID, - data, /*"written data #1, this should extend past end of old section data", */ - DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - } -}; - -SaCkptCallbacksT callbacks = { - 0, - 0 -}; - -#define MAX_DATA_SIZE 100 - -int main (void) { - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT checkpointHandle; - SaAisErrorT error; - char data[MAX_DATA_SIZE]; - struct timespec delay; - struct timespec delay2; - SaCkptIOVectorElementT writeElement; - long count = 0; - SaUint32T erroroneousVectorIndex = 0; - - delay.tv_sec = 1; - delay.tv_nsec = 0; - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - - error = saCkptCheckpointOpen (ckptHandle, - &checkpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle); - printf ("%s: initial open of checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - - do{ - error = saCkptCheckpointRead (checkpointHandle, - ReadVectorElements, - 1, - &erroroneousVectorIndex); - if (error != SA_AIS_OK) { - if (error == SA_AIS_ERR_TRY_AGAIN) { - continue; - } -printf ("error is %d\n", error); - return (0); - } - - if (ReadVectorElements->dataBuffer == 0) { - printf ("Default Checkpoint has no data\n"); - } else { - count = atol((char *)ReadVectorElements->dataBuffer); - } - - count++; - sprintf((char*)&data, "%d",(int)count); - writeElement.sectionId = (SaCkptSectionIdT)SA_CKPT_DEFAULT_SECTION_ID; - writeElement.dataBuffer = data; - writeElement.dataSize = strlen (data) + 1; - writeElement.dataOffset = 0; - writeElement.readSize = 0; - - do { - error = saCkptCheckpointWrite (checkpointHandle, - &writeElement, - 1, - &erroroneousVectorIndex); - - printf ("%s: checkpoint write with data %s\n", - get_test_output (error, SA_AIS_OK), (char*)data); - }while (error == SA_AIS_ERR_TRY_AGAIN); - - nanosleep(&delay,&delay2); - }while (1); - - return (0); - -} diff --git a/openais/test/ckptbench.c b/openais/test/ckptbench.c deleted file mode 100644 index 84a2003e..00000000 --- a/openais/test/ckptbench.c +++ /dev/null @@ -1,266 +0,0 @@ -#define _BSD_SOURCE -/* - * Copyright (c) 2002-2004 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saCkpt.h" -#include "sa_error.h" - -#ifdef OPENAIS_SOLARIS -#define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ - } while (0) -#endif - -int alarm_notice; - -void fail_on_error(SaAisErrorT error, char* opName) { - if (error != SA_AIS_OK) { - printf ("%s: result %s\n", opName, get_sa_error_b(error)); - exit (1); - } -} - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -SaVersionT version = { 'B', 1, 1 }; - -SaCkptCallbacksT callbacks = { - 0, - 0 -}; - -SaNameT checkpointName = { 5, "abra\0" }; - -SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = { - .creationFlags = SA_CKPT_WR_ALL_REPLICAS, - .checkpointSize = 250000, - .retentionDuration = 0, - .maxSections = 5, - .maxSectionSize = 250000, - .maxSectionIdSize = 15 -}; - -SaCkptSectionIdT sectionId1 = { - 14, - (SaUint8T *) "section ID #1" -}; - -SaCkptSectionIdT sectionId2 = { - 14, - (SaUint8T *) "section ID #2" -}; -SaCkptSectionCreationAttributesT sectionCreationAttributes1 = { - §ionId1, - 0xFFFFFFFF -}; - -SaCkptSectionCreationAttributesT sectionCreationAttributes2 = { - §ionId2, - 0xFFFFFFFF -}; - -char readBuffer1[1025]; - -char readBuffer2[1025]; - -SaCkptIOVectorElementT ReadVectorElements[] = { - { - { - 14, - (SaUint8T *) "section ID #1" - }, - readBuffer1, - sizeof (readBuffer1), - 0, - 0 - }, - { - { - 14, - (SaUint8T *) "section ID #2" - }, - readBuffer2, - sizeof (readBuffer2), - 0, - 0 - } -}; - -#define DATASIZE 200000 -#define LOOPS 5000 - -char data[500000]; -SaCkptIOVectorElementT WriteVectorElements[] = { - { - { - 14, - (SaUint8T *) "section ID #1" - }, - data, /*"written data #1, this should extend past end of old section data", */ - DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - } -#ifdef COMPILE_OUT - { - { - 14, - (SaUint8T *) "section ID #2" - }, - data, /*"written data #2, this should extend past end of old section data" */ - DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */ - 0, //3, - 0 - } -#endif -}; - -void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle, - int write_size) -{ - struct timeval tv1, tv2, tv_elapsed; - SaUint32T erroroneousVectorIndex = 0; - SaAisErrorT error; - int write_count = 0; - - alarm_notice = 0; - alarm (10); - WriteVectorElements[0].dataSize = write_size; - - gettimeofday (&tv1, NULL); - do { - /* - * Test checkpoint write - */ -retry: - error = saCkptCheckpointWrite (checkpointHandle, - WriteVectorElements, - 1, - &erroroneousVectorIndex); - if (error == SA_AIS_ERR_TRY_AGAIN) { - goto retry; - } - fail_on_error(error, "saCkptCheckpointWrite"); - write_count += 1; - } while (alarm_notice == 0); - gettimeofday (&tv2, NULL); - timersub (&tv2, &tv1, &tv_elapsed); - - printf ("%5d Writes ", write_count); - printf ("%5d bytes per write ", write_size); - printf ("%7.3f Seconds runtime ", - (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); - printf ("%9.3f TP/s ", - ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); - printf ("%7.3f MB/s.\n", - ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0)); -} - -void sigalrm_handler (int num) -{ - alarm_notice = 1; -} - -int main (void) { - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT checkpointHandle; - SaAisErrorT error; - int size; - int i; - - signal (SIGALRM, sigalrm_handler); - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - fail_on_error(error, "saCkptInitialize"); - - error = saCkptCheckpointOpen (ckptHandle, - &checkpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle); - fail_on_error(error, "saCkptCheckpointOpen"); - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - fail_on_error(error, "saCkptCheckpointSectionCreate"); - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes2, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - fail_on_error(error, "saCkptCheckpointSectionCreate"); - - size = 1; - - for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */ - ckpt_benchmark (checkpointHandle, size); - size += 1000; - } - - error = saCkptFinalize (ckptHandle); - return (0); -} diff --git a/openais/test/ckptbenchth.c b/openais/test/ckptbenchth.c deleted file mode 100644 index a1346da0..00000000 --- a/openais/test/ckptbenchth.c +++ /dev/null @@ -1,341 +0,0 @@ -#define _BSD_SOURCE -/* - * Copyright (c) 2002-2004 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saCkpt.h" -#include "sa_error.h" - -#ifdef OPENAIS_SOLARIS -#define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ - } while (0) -#endif - -int alarm_notice = 0; - -void fail_on_error(SaAisErrorT error, char* opName) { - if (error != SA_AIS_OK) { - printf ("%s: result %s\n", opName, get_sa_error_b(error)); - exit (1); - } -} - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -SaVersionT version = { 'B', 1, 1 }; - -SaCkptCallbacksT callbacks = { - 0, - 0 -}; - -SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = { - .creationFlags = SA_CKPT_WR_ALL_REPLICAS, - .checkpointSize = 100000, - .retentionDuration = 0, - .maxSections = 5, - .maxSectionSize = 150000, - .maxSectionIdSize = 15 -}; - -SaCkptSectionIdT sectionId1 = { - 14, - (SaUint8T *) "section ID #1" -}; - -SaCkptSectionIdT sectionId2 = { - 14, - (SaUint8T *) "section ID #2" -}; -SaCkptSectionCreationAttributesT sectionCreationAttributes1 = { - §ionId1, - 0xFFFFFFFF -}; - -SaCkptSectionCreationAttributesT sectionCreationAttributes2 = { - §ionId2, - 0xFFFFFFFF -}; - -char readBuffer1[1025]; - -char readBuffer2[1025]; - -SaCkptIOVectorElementT ReadVectorElements[] = { - { - { - 14, - (SaUint8T *) "section ID #1" - }, - readBuffer1, - sizeof (readBuffer1), - 0, - 0 - }, - { - { - 14, - (SaUint8T *) "section ID #2" - }, - readBuffer2, - sizeof (readBuffer2), - 0, - 0 - } -}; - -#define DATASIZE 1000 -#define LOOPS 5000 - -char data[500000]; -SaCkptIOVectorElementT WriteVectorElements[] = { - { - { - 14, - (SaUint8T *) "section ID #1" - }, - data, /*"written data #1, this should extend past end of old section data", */ - DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - } -#ifdef COMPILE_OUT - { - { - 14, - (SaUint8T *) "section ID #2" - }, - data, /*"written data #2, this should extend past end of old section data" */ - DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */ - 0, //3, - 0 - } -#endif -}; - -int runs = 0; - -struct threaddata { - SaCkptHandleT ckpt_handle; - SaCkptCheckpointHandleT checkpoint_handle; - int write_size; - int thread; - pthread_attr_t thread_attr; - pthread_t thread_id; - int written; -}; - -extern void pthread_exit(void *) __attribute__((noreturn)); - -void *benchmark_thread (void *arg) -{ - - SaCkptCheckpointHandleT checkpoint_handle; - SaCkptHandleT ckpt_handle; - int write_size; - SaAisErrorT error; - SaUint32T erroroneousVectorIndex = 0; - struct threaddata *td = (struct threaddata *)arg; - - checkpoint_handle = td->checkpoint_handle; - ckpt_handle = td->ckpt_handle; - write_size = td->write_size; - - WriteVectorElements[0].dataSize = write_size; - - do { - /* - * Test checkpoint write - */ - do { - error = saCkptCheckpointWrite (checkpoint_handle, - WriteVectorElements, - 1, - &erroroneousVectorIndex); - } while (error == SA_AIS_ERR_TRY_AGAIN); - fail_on_error(error, "saCkptCheckpointWrite"); - td->written += 1; - } while (alarm_notice == 0); - pthread_exit (0); -} - - -void threaded_bench ( - SaCkptHandleT *ckpt_handles, - SaCkptCheckpointHandleT *checkpoint_handles, - int threads, - int write_size) -{ - struct timeval tv1, tv2, tv_elapsed; - struct threaddata td[100]; - int i; - int res; - int written = 0; - - runs = threads; - gettimeofday (&tv1, NULL); - - for (i = 0; i < threads; i++) { - td[i].ckpt_handle = ckpt_handles[i]; - td[i].checkpoint_handle = checkpoint_handles[i]; - td[i].write_size = write_size; - td[i].thread = i; - td[i].written = 0; - pthread_attr_init (&td[i].thread_attr); - pthread_attr_setstacksize (&td[i].thread_attr, 16384); - pthread_attr_setdetachstate (&td[i].thread_attr, PTHREAD_CREATE_JOINABLE); - - res = pthread_create (&td[i].thread_id, &td[i].thread_attr, - benchmark_thread, (void *)&td[i]); - } - - for (i = 0; i < threads; i++) { - pthread_join (td[i].thread_id, NULL); - written += td[i].written; - } - alarm_notice = 0; - - gettimeofday (&tv2, NULL); - timersub (&tv2, &tv1, &tv_elapsed); - - printf ("%5d Writes ", written); - printf ("%5d bytes per write ", write_size); - printf ("%7.3f Seconds runtime ", - (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); - printf ("%9.3f TP/s ", - ((float)written) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); - printf ("%7.3f MB/s.\n", - ((float)written) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0)); -} - -SaNameT checkpointName; - -#define CHECKPOINT_THREADS_START 25 -#define CHECKPOINT_THREADS_MAX 500 - -void sigalrm_handler (int num) -{ - alarm_notice = 1; -} - - -int main (void) { - SaCkptHandleT ckpt_handles[CHECKPOINT_THREADS_MAX]; - SaCkptCheckpointHandleT checkpoint_handles[CHECKPOINT_THREADS_MAX]; - SaAisErrorT error; - int size; - int i, j; - - signal (SIGALRM, sigalrm_handler); - - printf ("Creating (%d) checkpoints.\n", CHECKPOINT_THREADS_MAX); - /* - * Create CHECPOINT_THREADS_MAX checkpoints - */ - for (i = 0; i < CHECKPOINT_THREADS_MAX; i++) { - sprintf ((char *)checkpointName.value, "checkpoint (%d)", i); - checkpointName.length = strlen ((char *)checkpointName.value); - do { - error = saCkptInitialize (&ckpt_handles[i], &callbacks, &version); - } while (error == SA_AIS_ERR_TRY_AGAIN); - assert (error == SA_AIS_OK); - - do { - error = saCkptCheckpointOpen (ckpt_handles[i], - &checkpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - SA_TIME_END, - &checkpoint_handles[i]); - } while (error == SA_AIS_ERR_TRY_AGAIN); - assert (error == SA_AIS_OK); - - do { - error = saCkptSectionCreate (checkpoint_handles[i], - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - } while (error == SA_AIS_ERR_TRY_AGAIN); - assert (error == SA_AIS_OK); - - do { - error = saCkptSectionCreate (checkpoint_handles[i], - §ionCreationAttributes2, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - } while (error == SA_AIS_ERR_TRY_AGAIN); - assert (error == SA_AIS_OK); - } - - for (i = CHECKPOINT_THREADS_START; i < CHECKPOINT_THREADS_MAX; i++) { /* i threads */ - printf ("Starting benchmark with (%d) threads.\n", i); - size = 10000; /* initial size */ - for (j = 0; j < 5; j++) { /* number of runs with i threads */ - alarm (10); - threaded_bench (ckpt_handles, checkpoint_handles, i, size); - size += 1000; - } - } - return (0); -} diff --git a/openais/test/ckptstress.c b/openais/test/ckptstress.c deleted file mode 100644 index ad149ddb..00000000 --- a/openais/test/ckptstress.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2002-2004 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saCkpt.h" - -int ckptinv; - -struct thread_data { - int thread_no; -}; - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -SaVersionT version = { 'B', 1, 1 }; - -SaCkptCallbacksT callbacks = { - 0, - 0 -}; - -SaNameT checkpointName = { 5, "abra\0" }; - -SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = { - SA_CKPT_WR_ALL_REPLICAS, - 100000, - 0, - 5, - 20000, - 10 -}; - -SaCkptSectionIdT sectionId1 = { - 14, - (SaUint8T *) "section ID #1" -}; - -SaCkptSectionIdT sectionId2 = { - 14, - (SaUint8T *) "section ID #2" -}; -SaCkptSectionCreationAttributesT sectionCreationAttributes1 = { - §ionId1, - 0xFFFFFFFF -}; - -SaCkptSectionCreationAttributesT sectionCreationAttributes2 = { - §ionId2, - 0xFFFFFFFF -}; - -char readBuffer1[1025]; - -char readBuffer2[1025]; - -SaCkptIOVectorElementT ReadVectorElements[] = { - { - { - 14, - (SaUint8T *) "section ID #1" - }, - readBuffer1, - sizeof (readBuffer1), - 0, - 0 - }, - { - { - 14, - (SaUint8T *) "section ID #2" - }, - readBuffer2, - sizeof (readBuffer2), - 0, - 0 - } -}; - -#define DATASIZE 250000 -char data[DATASIZE]; -SaCkptIOVectorElementT WriteVectorElements[] = { - { - { - 14, - (SaUint8T *) "section ID #1" - }, - data, /*"written data #1, this should extend past end of old section data", */ - DATASIZE, /*sizeof ("written data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - } -#ifdef COMPILE_OUT - { - { - 14, - (SaUint8T *) "section ID #2" - }, - data, /*"written data #2, this should extend past end of old section data" */ - DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */ - 0, //3, - 0 - } -#endif -}; - -void *th_dispatch (void *arg) -{ - struct thread_data *td = (struct thread_data *)arg; - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT handle; - SaAisErrorT error; - int i; - SaUint32T erroroneousVectorIndex = 0; - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - - error = saCkptCheckpointOpen (ckptHandle, - &checkpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &handle); - for (i = 0; i < 1000; i++) { - error = saCkptCheckpointWrite (handle, - WriteVectorElements, - 1, - &erroroneousVectorIndex); - printf ("Thread %d: Attempt %d: error %d\n", - td->thread_no, i, error); - if (error != SA_AIS_OK) { - printf ("Thread %d: Error from write.\n", td->thread_no); - } - } - - error = saCkptFinalize (ckptHandle); - - return (0); -} - -int main (void) { - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT checkpointHandle; - SaAisErrorT error; - int i; - pthread_t dispatch_thread; - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - - error = saCkptCheckpointOpen (ckptHandle, - &checkpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle); - printf ("first open result %d (should be 1)\n", error); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); -printf ("create2 error is %d\n", error); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes2, - "Initial Data #0", - strlen ("Initial Data #0") + 1); -printf ("create2 error is %d\n", error); - - for (i = 0; i < 40; i++) { - struct thread_data *td; - - td = malloc (sizeof (struct thread_data)); - td->thread_no = i; - pthread_create (&dispatch_thread, NULL, th_dispatch, td); - } - pthread_join (dispatch_thread, NULL); - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - - return (0); -} diff --git a/openais/test/clc_cli_script b/openais/test/clc_cli_script deleted file mode 100755 index 2959de1d..00000000 --- a/openais/test/clc_cli_script +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/sh -# Copyright (c) 2005 MontaVista Software, Inc. -# -# 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 -# modification, are permitted provided that the following conditions are met: -# -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# - Neither the name of the MontaVista Software, Inc. nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. - -# This script will instantiate, terminate, or cleanup using default actions -# It may be modified to do any action desired. - -instantiate() { -# echo clc_cli_script instantiating component $SA_AMF_COMPONENT_NAME $1 - openais-instantiate $1 - exit $? -} - -terminate() { - if [ -w /var/run ]; then - PIDFILEPATH=/var/run - else - PIDFILEPATH=/tmp - fi - echo clc_cli_script terminating component $SA_AMF_COMPONENT_NAME on PID \ - `cat $PIDFILEPATH/openais_cleanup_$SA_AMF_COMPONENT_NAME` - kill -15 `cat $PIDFILEPATH/openais_cleanup_$SA_AMF_COMPONENT_NAME` - exit $? -} - -cleanup() { - if [ -w /var/run ]; then - PIDFILEPATH=/var/run - else - PIDFILEPATH=/tmp - fi -# echo clc_cli_script cleaning up component $SA_AMF_COMPONENT_NAME on PID \ -# `cat $PIDFILEPATH/openais_cleanup_$SA_AMF_COMPONENT_NAME` - kill -9 `cat $PIDFILEPATH/openais_cleanup_$SA_AMF_COMPONENT_NAME` - STATUS=$? - if [ $STATUS -eq 1 ]; then - exit 0 - else - exit $STATUS - fi -} - -usage() { - echo $"Usage: $0 {instantiate|terminate|cleanup}" -} - -case "$1" in - instantiate) - if [ $# -gt 1 ]; then - instantiate $2 - else - instantiate $COMP_BINARY_PATH/$COMP_BINARY_NAME - fi - ;; - - terminate) - terminate - ;; - - cleanup) - cleanup - ;; - - *) - usage - exit 1 - -esac -exit 0 diff --git a/openais/test/comp_amf/takeover/Makefile b/openais/test/comp_amf/takeover/Makefile deleted file mode 100644 index fabd0428..00000000 --- a/openais/test/comp_amf/takeover/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -OPTIONS = -Wall -I../../include - -all: test_amf - -serv_main.o: serv_main.c serv_main.h - gcc $(OPTIONS) -c serv_main.c - -serv_amf.o: serv_amf.c serv_amf.h - gcc $(OPTIONS) -c serv_amf.c - -test_amf: serv_main.o serv_amf.o - gcc $(OPTIONS) -o test_amf serv_main.o serv_amf.o ../../lib/libSaAmf.a ../../lib/libSaCkpt.a -lpthread - -clean: - rm -f test_amf - rm -f *.o diff --git a/openais/test/comp_amf/takeover/README.TXT b/openais/test/comp_amf/takeover/README.TXT deleted file mode 100644 index 1debdae4..00000000 --- a/openais/test/comp_amf/takeover/README.TXT +++ /dev/null @@ -1,4 +0,0 @@ -Pollux -> 10.0.0.2 -Castor -> 10.0.0.1 - -Device eth0 <- eth0:0 with 10.0.0.100 diff --git a/openais/test/comp_amf/takeover/amf.conf b/openais/test/comp_amf/takeover/amf.conf deleted file mode 100644 index 788b55e5..00000000 --- a/openais/test/comp_amf/takeover/amf.conf +++ /dev/null @@ -1,111 +0,0 @@ -# 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 /). -# WL - WorkLoad - -safAmfCluster = TEST_AMF { - saAmfClusterStartupTimeout=3000 - safAmfNode = NODE1 { - saAmfNodeSuFailOverProb=1000 - saAmfNodeSuFailoverMax=1 - saAmfNodeClmNode=pollux - } - safAmfNode = NODE2 { - saAmfNodeSuFailOverProb=1000 - saAmfNodeSuFailoverMax=1 - saAmfNodeClmNode=castor - } - safApp = APP-1 { - safSg = RAID { - saAmfSGRedundancyModel=nplusm - saAmfSGNumPrefActiveSUs=1 - saAmfSGMaxActiveSIsperSUs=2 - saAmfSGNumPrefStandbySUs=1 - saAmfSGMaxStandbySIsperSUs=2 - saAmfSGCompRestartProb=100000 - saAmfSGCompRestartMax=1 - saAmfSGSuRestartProb=20000 - saAmfSGSuRestartMax=1 - saAmfSGAutoAdjustProb=5000 - safSu = SERVICE_X_1 { - saAmfSUHostedByNode=NODE1 - saAmfSUNumComponents=1 - safComp = A { - saAmfCompCategory=sa_aware - saAmfCompCapability=x_active_or_y_standby - saAmfCompNumMaxActiveCsi=1 - saAmfCompNumMaxStandbyCsi=1 - saAmfCompDefaultClcCliTimeout = 500 - saAmfCompDefaultCallbackTimeOut = 500 - saAmfCompInstantiateCmd = /root/openais/trunk/test/clc_cli_script - saAmfCompInstantiateCmdArgv= instantiate /root/openais/trunk/test/test_amf - saAmfCompTerminateCmd = /root/openais/trunk/test/clc_cli_script - saAmfCompTerminateCmdArgv = terminate - saAmfCompCleanupCmd = /root/openais/trunk/test/clc_cli_script - saAmfCompCleanupCmdArgv = cleanup - saAmfCompCsTypes { - A - } - saAmfCompCmdEnv { - COMP_BINARY_PATH=/root/openais/trunk/test/ - COMP_BINARY_NAME=test_amf - } - saAmfCompRecoveryOnError=component_restart - safHealthcheckKey = takeoverInvoked { - saAmfHealthcheckPeriod = 1000 - saAmfHealthcheckMaxDuration = 350 - } - } - } - safSu = SERVICE_X_2 { - clccli_path=/root/openais/trunk/test/ - saAmfSUHostedByNode=NODE2 - saAmfSUNumComponents=1 - safComp = A { - saAmfCompCategory=sa_aware - saAmfCompCapability=x_active_or_y_standby - saAmfCompNumMaxActiveCsi=1 - saAmfCompNumMaxStandbyCsi=1 - saAmfCompDefaultClcCliTimeout = 500 - saAmfCompDefaultCallbackTimeOut = 500 - saAmfCompInstantiateCmd = clc_cli_script - saAmfCompInstantiateCmdArgv= instantiate - saAmfCompTerminateCmd = clc_cli_script - saAmfCompTerminateCmdArgv = terminate - saAmfCompCleanupCmd = clc_cli_script - saAmfCompCleanupCmdArgv = cleanup - saAmfCompCsTypes { - A - } - saAmfCompCmdEnv { - COMP_BINARY_PATH=/root/openais/trunk/test/ - COMP_BINARY_NAME=test_amf - } - saAmfCompRecoveryOnError=component_restart - safHealthcheckKey = takeoverInvoked { - saAmfHealthcheckPeriod = 1000 - saAmfHealthcheckMaxDuration = 350 - } - } - } - } - safSi = WL1 { - saAmfSINumCSIs=2 - safCsi = WL1-1 { - saAmfCSTypeName = A - safCSIAttr = interface { - eth0:0 - } - safCSIAttr = ip_addr { - 10.0.0.100 - } - } - } - safCSType = A { - safAmfCSAttrName = interface - safAmfCSAttrName = ip_addr - } - } -} diff --git a/openais/test/comp_amf/takeover/openais.conf b/openais/test/comp_amf/takeover/openais.conf deleted file mode 100644 index caf3fd00..00000000 --- a/openais/test/comp_amf/takeover/openais.conf +++ /dev/null @@ -1,31 +0,0 @@ -# Please read the openais.conf.5 manual page - -totem { - version: 2 - secauth: off - threads: 0 - interface { - ringnumber: 0 - bindnetaddr: 10.0.0.1 - mcastaddr: 226.94.1.1 - mcastport: 5405 - } -} - -logging { - fileline: off - to_stderr: no - to_file: yes - logfile: /tmp/openais.log - debug: off - timestamp: on - logger { - ident: AMF - debug: off - tags: enter|leave|trace1|trace2|trace3|trace4|trace6 - } -} - -amf { - mode: enabled -} diff --git a/openais/test/comp_amf/takeover/serv_amf.c b/openais/test/comp_amf/takeover/serv_amf.c deleted file mode 100644 index 51b87e07..00000000 --- a/openais/test/comp_amf/takeover/serv_amf.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2007 Diginext/C-S - * - * All rights reserved. - * - * Author: Lionel Tricon (lionel.tricon@diginext.fr) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "serv_amf.h" - -// Global variables -SaVersionT VG_amf_version = { 'B', 1, 1 }; // AMF version supported -SaAmfHandleT VG_amf_handle; // AMF handle -SaNameT VG_compNameGlobal; // name of the component - -// Ip takeover -char *VG_interface=NULL; // ip takeover interface -char *VG_ip_addr=NULL; // floating ip address - -SaAmfHAStateT VG_AMF_old_haState; // We store the old state to ease transition detection -SaAmfHAStateT VG_AMF_haState; // Current ha state -SaAmfHAStateT *VG_AMF_remote_haState; // Remote ha state (from the amf_comp_init function) - -// Types for State Management -char *TG_ha_state[128] = { - "null", - "SA_AMF_HA_ACTIVE", - "SA_AMF_HA_STANDBY", - "SA_AMF_HA_QUIESCED", - "SA_AMF_HA_QUIESCING" -}; - -// The key of the healthcheck to be executed -SaAmfHealthcheckKeyT VG_keyAmfInvoked = { - .key = "takeoverInvoked", - .keyLen = 15 -}; - -// Local function Prototypes -static void amf_send_response( SaAmfHandleT, SaInvocationT, SaAisErrorT ); -static void amf_healthcheckCallback( SaInvocationT, const SaNameT*, SaAmfHealthcheckKeyT* ); -static void amf_ip_takeover( SaAmfCSIDescriptorT*, SaAmfHAStateT ); -static void amf_csi_setCallback( SaInvocationT, const SaNameT*, SaAmfHAStateT, SaAmfCSIDescriptorT* ); -static void* amf_comp_callbacks( void* ); - -// Define the various callback functions that AMF may invoke on a component -SaAmfCallbacksT VG_amfCallbacks = { - .saAmfHealthcheckCallback = amf_healthcheckCallback, - .saAmfCSISetCallback = amf_csi_setCallback -}; - -// -// Response to Framework Requests to acknowledge the reception of a -// message or a callback -// -static void -amf_send_response( - SaAmfHandleT p_handle, // AMF handle - SaInvocationT p_invocation, // associate an invocation of this response function - SaAisErrorT p_retval // return SA_AIS_OK in case of success, else returns an appropriate error -){ - SaAisErrorT v_error; - - for (;;usleep(10000)) { - v_error = saAmfResponse( p_handle, p_invocation, p_retval ); - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfResponse failed %d\n", v_error ); - exit( EXIT_FAILURE ); - } -} - -// -// AMF requests the component p_compName to perform a healthcheck -// specified by p_healthcheckKey -// -void -amf_healthcheckCallback( - SaInvocationT p_invocation, - const SaNameT *p_compName, - SaAmfHealthcheckKeyT *p_healthcheckKey -){ - amf_send_response( VG_amf_handle, p_invocation, SA_AIS_OK ); -} - -// -// IP takeover management -// -void -amf_ip_takeover( - SaAmfCSIDescriptorT *p_csiDescriptor, // information about the CSI targeted - SaAmfHAStateT p_action // SA_AMF_HA_ACTIVE=="start", sinon "stop" -){ - char v_action[64], v_exec[256]; - char *v_path = getenv( "COMP_BINARY_PATH" ); - int i; - - // CSI attributs - if (p_csiDescriptor!=NULL && (VG_interface==NULL || VG_ip_addr==NULL)) { - - for(i=0; icsiAttr.number; i++) { - - // Interface - if (VG_interface==NULL && !strcmp((char*)p_csiDescriptor->csiAttr.attr[i].attrName,"interface")) { - VG_interface = (char*)malloc(strlen((char*)p_csiDescriptor->csiAttr.attr[i].attrName)+1); - strcpy( VG_interface, (char*)p_csiDescriptor->csiAttr.attr[i].attrValue ); - } - - // Floating ip address - if (VG_ip_addr==NULL && !strcmp((char*)p_csiDescriptor->csiAttr.attr[i].attrName,"ip_addr")) { - VG_ip_addr = (char*)malloc(strlen((char*)p_csiDescriptor->csiAttr.attr[i].attrName)+1); - strcpy( VG_ip_addr, (char*)p_csiDescriptor->csiAttr.attr[i].attrValue ); - } - } - } - - // Test d'integrite - if (v_path==NULL || VG_interface==NULL || VG_ip_addr==NULL) return; - - // Ip takeover action - strcpy( v_action, "stop" ); - if (p_action == SA_AMF_HA_ACTIVE) strcpy( v_action, "start" ); - - // We execute the takeover script - sprintf( v_exec, "%s/takeover.sh %s %s %s", v_path, VG_interface, VG_ip_addr, v_action ); - system( v_exec ); -} - -// -// AMF invokes this callback to request the component to assume a -// particular HA state -// -static void -amf_csi_setCallback( - SaInvocationT p_invocation, // to acknowledge the new state - const SaNameT *p_compName, // name of the component - SaAmfHAStateT p_haState, // new HA state to be assumed by the component for the CSI - SaAmfCSIDescriptorT *p_csiDescriptor // information about the CSI targeted - -){ - SaAmfHAStateT v_state; - SaAisErrorT v_error; - - // new state - switch( p_haState ) { - - case SA_AMF_HA_ACTIVE: - case SA_AMF_HA_STANDBY: - case SA_AMF_HA_QUIESCED: - case SA_AMF_HA_QUIESCING: - - // Send response to AMF - amf_send_response( VG_amf_handle, p_invocation, SA_AIS_OK ); - - // Takeover of the ip address - amf_ip_takeover( p_csiDescriptor, p_haState ); - - // We change the local state - VG_AMF_haState = p_haState; - - fprintf( stderr, "PID %d: Component '%s' requested to enter hastate %s for \n\tCSI '%s'\n", - (int)getpid(), p_compName->value, TG_ha_state[p_haState], p_csiDescriptor->csiName.value ); - - // We check if the state is changed - v_error = saAmfHAStateGet( VG_amf_handle, p_compName, &p_csiDescriptor->csiName, &v_state ); - if (v_error!=SA_AIS_OK || p_haState!=v_state) { - fprintf( stderr, "saAmfHAStateGet failed: %d\n", v_error ); - exit (-1); - } - break; - - default: - break; - } - - // - // Transition detection - // - if (VG_AMF_haState != VG_AMF_old_haState) { - VG_AMF_old_haState = VG_AMF_haState; - *VG_AMF_remote_haState = VG_AMF_haState; - } -} - -// -// Invoke pending callbacks for the handle amfHandle -// -void* -amf_comp_callbacks( - void* p_select_fd // file descriptor -) { - int v_select_fd = (int)p_select_fd; - struct timeval v_timeval; - SaAisErrorT v_error; - fd_set v_read_fds; - int retval; - - // initialization - pthread_detach( pthread_self() ); - FD_ZERO( &v_read_fds ); - - // saAmfDispatch - for (;;) { - - // related to value in amf.conf! - v_timeval.tv_sec = 0; - v_timeval.tv_usec = 1000; - FD_SET( v_select_fd, &v_read_fds ); - - // we check if there are data waiting - retval = select( v_select_fd+1, &v_read_fds, 0, 0, &v_timeval ); - if (retval == -1) { - if (errno == EINTR) continue; - fprintf( stderr, "select failed - %s",strerror(errno) ); - exit( EXIT_FAILURE ); - } - - // We detect the availability of some date on the file descriptor - // This avoid us to launch saAmfDispatch() too often - if (retval > 0) { - - // invoke pending callbacks for the handle amfHandle - for (;;usleep(10000)) { - v_error = saAmfDispatch( VG_amf_handle, // AMF handle - SA_DISPATCH_ALL ); // callback execution behavior - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfDispatch failed %d", v_error ); - exit( EXIT_FAILURE ); - } - } - } - - pthread_exit( NULL ); - return NULL; -} - -// -// Initialize AMF for the invoking process -// -void -amf_comp_init( - SaAmfHAStateT *p_amf_state // current HA state of the component -){ - char *v_name; // to get the environment variables - SaAisErrorT v_error; // result of the AMF functions - SaSelectionObjectT v_select_fd; // file descriptor to check if there is pending callbacks - pthread_t v_thread; // to create a thread to manage the healthcheck - int retval; - - // We get the environment variable SA_AMF_COMPONENT_NAME - v_name = getenv( "SA_AMF_COMPONENT_NAME" ); - if (v_name == NULL) { - fprintf( stderr, "SA_AMF_COMPONENT_NAME missing\n" ); - exit( EXIT_FAILURE ); - } - - fprintf( stderr, "** %d: Hello world from [%s]\n", (int)getpid(), v_name ); - - // the real application need to know about ha state - VG_AMF_remote_haState = p_amf_state; - - // Initialization - VG_AMF_haState = SA_AMF_HA_STANDBY; - VG_AMF_old_haState = SA_AMF_HA_STANDBY; - *VG_AMF_remote_haState = SA_AMF_HA_STANDBY; - - // Initialize AMF for the invoking process and registers the various callback functions - for (;;usleep(10000)) { - v_error = saAmfInitialize( &VG_amf_handle, // handle of the Availability Management Framework - &VG_amfCallbacks, // callback functions that AMF may invoke - &VG_amf_version ); // version that should support AMF - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfInitialize result is %d\n", v_error ); - exit( EXIT_FAILURE ); - } - - // Handle to detect pending callbacks, - // instead of repeatedly invoking saAmfDispatch() - for (;;usleep(10000)) { - v_error = saAmfSelectionObjectGet( VG_amf_handle, // AMF handle - &v_select_fd ); // descriptor to detect pending callbacks - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfSelectionObjectGet failed %d\n", v_error ); - exit( EXIT_FAILURE ); - } - - // Get the name of the component the calling process belongs to - for (;;usleep(10000)) { - v_error = saAmfComponentNameGet( VG_amf_handle, // AMF handle - &VG_compNameGlobal ); // name of the component - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfComponentNameGet failed %d\n", v_error ); - exit( EXIT_FAILURE ); - } - - // The healthchecks are invoked by the Availability Management Framework - for (;;usleep(10000)) { - v_error = saAmfHealthcheckStart( VG_amf_handle, // AMF handle - &VG_compNameGlobal, // name of the component to be healthchecked - &VG_keyAmfInvoked, // the key of the healthcheck to be executed - SA_AMF_HEALTHCHECK_AMF_INVOKED, // component Healthcheck Monitoring - SA_AMF_NO_RECOMMENDATION ); // What to do if the component fails a healthcheck - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfHealthcheckStart failed %d\n", v_error ); - exit( EXIT_FAILURE ); - } - - // Registration of the componant - for (;;usleep(10000)) { - v_error = saAmfComponentRegister( VG_amf_handle, // AMF handle - &VG_compNameGlobal, // name of the component to be registered - NULL ); // unused (proxy component) - if (v_error != SA_AIS_ERR_TRY_AGAIN) break; - } - if (v_error != SA_AIS_OK) { - fprintf( stderr, "saAmfComponentRegister failed %d\n", v_error ); - exit( EXIT_FAILURE ); - } - - // We start the healthcheck processing - retval = pthread_create( &v_thread, NULL, (void*(*)(void*))amf_comp_callbacks, (void*)(int)v_select_fd ); - if (retval != 0) { - fprintf( stderr, "saAmfComponentRegister failed %d\n", retval ); - exit( EXIT_FAILURE ); - } -} diff --git a/openais/test/comp_amf/takeover/serv_amf.h b/openais/test/comp_amf/takeover/serv_amf.h deleted file mode 100644 index 9c988e36..00000000 --- a/openais/test/comp_amf/takeover/serv_amf.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SERV_AMF_H -#define SERV_AMF_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saAmf.h" - -SaAmfHAStateT *VG_ha_state; - -void amf_comp_init( SaAmfHAStateT* ); - -#endif /* SERV_AMF_H */ diff --git a/openais/test/comp_amf/takeover/serv_main.c b/openais/test/comp_amf/takeover/serv_main.c deleted file mode 100644 index ff067c4c..00000000 --- a/openais/test/comp_amf/takeover/serv_main.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2007 Diginext/C-S - * - * All rights reserved. - * - * Author: Lionel Tricon (lionel.tricon@diginext.fr) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "serv_main.h" -#include "serv_amf.h" - -// Cluster management -SaAmfHAStateT VG_AMF_ha_state; // State of the cluster - -/* - * ================================================================================= - * MAIN - * ================================================================================= - */ - -int -main( - int p_argc, - char *p_argv[] -) { - // This function initializes AMF for the invoking process - // and registers the various callback functions - amf_comp_init( &VG_AMF_ha_state ); - - // - for (;;sleep(1)) { - - switch( VG_AMF_ha_state ) { - - case SA_AMF_HA_ACTIVE: - printf( "Active\n" ); - break; - - case SA_AMF_HA_STANDBY: - printf( "Standby\n" ); - break; - - case SA_AMF_HA_QUIESCED: - printf( "Quiesced\n" ); - break; - - case SA_AMF_HA_QUIESCING: - printf( "Quiescing\n" ); - break; - - default: - printf( "Unkwown\n" ); - break; - } - } - - exit( EXIT_SUCCESS ); -} diff --git a/openais/test/comp_amf/takeover/serv_main.h b/openais/test/comp_amf/takeover/serv_main.h deleted file mode 100644 index edf2205b..00000000 --- a/openais/test/comp_amf/takeover/serv_main.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _SERV_MAIN_H -#define _SERV_MAIN_H - -#endif /* _SERV_MAIN_H */ diff --git a/openais/test/comp_amf/takeover/takeover.sh b/openais/test/comp_amf/takeover/takeover.sh deleted file mode 100755 index 67d7fade..00000000 --- a/openais/test/comp_amf/takeover/takeover.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -INTERFACE=$1 -ADRESSE=$2 -ACTION=$3 - -case "$ACTION" in - start) - /sbin/ifconfig $INTERFACE $ADRESSE - DEVICE=`echo $INTERFACE | /usr/bin/cut -d ":" -f 1` - LISTE=`/sbin/arp -i $DEVICE | /usr/bin/grep -v Address | /usr/bin/awk '{print $1}'` - for elt in $LISTE; do - /sbin/arping -q -c 1 -w 0 $elt & - done - ;; - stop) - (/sbin/ifconfig -a | grep $INTERFACE 1>/dev/null) && /sbin/ifconfig $INTERFACE down - ;; - *) - echo "$0 ethx:y X.Y.Z.W [start|stop]" - ;; -esac diff --git a/openais/test/evtbench.c b/openais/test/evtbench.c deleted file mode 100644 index 41ed099c..00000000 --- a/openais/test/evtbench.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Test program for event service - */ - -#include -#include -#include -#include -#include -#ifndef OPENAIS_SOLARIS -#include -#include -#else -#include -#endif -#include -#include -#include "saAis.h" -#include "saEvt.h" - -// #define EVENT_SUBSCRIBE - -#ifdef OPENAIS_SOLARIS -#define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ - } while (0) -#endif - -SaVersionT version = { 'B', 0x01, 0x01 }; - -void event_callback( SaEvtSubscriptionIdT subscriptionId, - const SaEvtEventHandleT eventHandle, - const SaSizeT eventDataSize); - -SaEvtCallbacksT callbacks = { - 0, - event_callback -}; - - -char channel[256] = "EVENT_TEST_CHANNEL"; -unsigned int subscription_id = 0xfedcba98; -unsigned long long ret_time = 0000000000ULL; /* 0 seconds */ -char pubname[256] = "Test Pub Name"; - - -#define _patt1 "Filter pattern 1" -#define patt1 (SaUint8T *) _patt1 -#define patt1_size sizeof(_patt1) - -#define _patt2 "Filter pattern 2" -#define patt2 (SaUint8T *) _patt2 -#define patt2_size sizeof(_patt2) - -#define _patt3 "Filter pattern 3" -#define patt3 (SaUint8T *) _patt3 -#define patt3_size sizeof(_patt3) - -#define _patt4 "Filter pattern 4" -#define patt4 (SaUint8T *) _patt4 -#define patt4_size sizeof(_patt4) - -SaEvtEventFilterT filters[] = { - {SA_EVT_PREFIX_FILTER, {patt1_size, patt1_size, patt1}}, - {SA_EVT_SUFFIX_FILTER, {patt2_size, patt2_size, patt2}}, - {SA_EVT_EXACT_FILTER, {patt3_size, patt3_size, patt3}}, - {SA_EVT_PASS_ALL_FILTER, {patt4_size, patt4_size, patt4}} -}; - -SaEvtEventFilterArrayT subscribe_filters = { - sizeof(filters)/sizeof(SaEvtEventFilterT), - filters -}; - - - SaUint8T pat0[100]; - SaUint8T pat1[100]; - SaUint8T pat2[100]; - SaUint8T pat3[100]; - SaUint8T pat4[100]; - SaEvtEventPatternT evt_patts[5] = { - {100, 100, pat0}, - {100, 100, pat1}, - {100, 100, pat2}, - {100, 100, pat3}, - {100, 100, pat4}}; - SaEvtEventPatternArrayT evt_pat_get_array = { 100, 0, evt_patts }; - -SaEvtEventPatternT patterns[] = { - {patt1_size, patt1_size, patt1}, - {patt2_size, patt2_size, patt2}, - {patt3_size, patt3_size, patt3}, - {patt4_size, patt4_size, patt4} -}; -SaNameT test_pub_name; -#define TEST_PRIORITY 2 - -SaEvtEventPatternArrayT evt_pat_set_array = { - sizeof(patterns)/sizeof(SaEvtEventPatternT), - sizeof(patterns)/sizeof(SaEvtEventPatternT), - patterns -}; - -char user_data_file[256]; -char user_data[100000]; -int user_data_size = 50000; - -uint64_t clust_time_now(void) -{ - struct timeval tv; - uint64_t time_now; - - if (gettimeofday(&tv, 0)) { - return 0ULL; - } - - time_now = (uint64_t)(tv.tv_sec) * 1000000000ULL; - time_now += (uint64_t)(tv.tv_usec) * 1000ULL; - - return time_now; -} - -void -test_pub() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtEventHandleT event_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - uint64_t test_retention; - SaSelectionObjectT fd; - int i; - struct timeval tv1, tv2, tv_elapsed; - int write_count = 10000; - int write_size = user_data_size; - - - SaEvtEventIdT event_id; -#ifdef EVENT_SUBSCRIBE - struct pollfd pfd; - int nfd; - int timeout = 1000; -#endif - - - - int result; - - flags = SA_EVT_CHANNEL_PUBLISHER | -#ifdef EVENT_SUBSCRIBE - SA_EVT_CHANNEL_SUBSCRIBER | -#endif - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - - - result = saEvtInitialize (&handle, &callbacks, &version); - if (result != SA_AIS_OK) { - printf("Event Initialize result: %d\n", result); - exit(1); - } - result = saEvtChannelOpen(handle, &channel_name, flags, - SA_TIME_MAX, &channel_handle); - if (result != SA_AIS_OK) { - printf("channel open result: %d\n", result); - goto evt_fin; - } - - /* - * Publish with pattens - */ - printf("Publish\n"); - -#ifdef EVENT_SUBSCRIBE - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - - if (result != SA_AIS_OK) { - printf("event subscribe result: %d\n", result); - result = saEvtChannelClose(channel_handle); - if (result != SA_AIS_OK) - printf("Channel close result: %d\n", result); - result = saEvtFinalize(handle); - if (result != SA_AIS_OK) - printf("Finalize result: %d\n", result); - return; - } -#endif - result = saEvtEventAllocate(channel_handle, &event_handle); - if (result != SA_AIS_OK) { - printf("event Allocate result: %d\n", result); - goto evt_free; - } - - strcpy((char *)test_pub_name.value, pubname); - test_pub_name.length = strlen(pubname); - test_retention = ret_time; - result = saEvtEventAttributesSet(event_handle, - &evt_pat_set_array, - TEST_PRIORITY, - test_retention, - &test_pub_name); - if (result != SA_AIS_OK) { - printf("event set attr result(2): %d\n", result); - goto evt_free; - } - - gettimeofday (&tv1, NULL); - for (i = 0; i < write_count; i++) { - result = saEvtEventPublish(event_handle, user_data, - write_size, &event_id); - if (result != SA_AIS_OK) { - printf("event Publish result(2): %d\n", result); - goto evt_close; - } - } - gettimeofday (&tv2, NULL); - timersub (&tv2, &tv1, &tv_elapsed); - - printf ("%5d Writes ", write_count); - printf ("%5d bytes per write ", write_size); - printf ("%7.3f Seconds runtime ", - (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); - printf ("%9.3f TP/s ", - ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); - printf ("%7.3f MB/s.\n", - ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + ( - tv_elapsed.tv_usec / 1000000.0)) * 1000000.0)); - -exit (1); - printf("Published event ID: %llx\n", (unsigned long long)event_id); - - /* - * See if we got the event - */ - result = saEvtSelectionObjectGet(handle, &fd); - if (result != SA_AIS_OK) { - printf("saEvtSelectionObject get %d\n", result); - /* error */ - return; - } -#ifdef EVENT_SUBSCRIBE - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd <= 0) { - printf("poll fds %d\n", nfd); - if (nfd < 0) { - perror("poll error"); - } - goto evt_free; - } - - printf("Got poll event\n"); - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - if (result != SA_AIS_OK) { - printf("saEvtDispatch %d\n", result); - goto evt_fin; - } -#endif - - - /* - * Test cleanup - */ -evt_free: - result = saEvtEventFree(event_handle); - if (result != SA_AIS_OK) { - printf("event free result: %d\n", result); - } - -evt_close: - result = saEvtChannelClose(channel_handle); - - if (result != SA_AIS_OK) { - printf("channel close result: %d\n", result); - } -evt_fin: - result = saEvtFinalize(handle); - - if (result != SA_AIS_OK) { - printf("Event Finalize result: %d\n", result); - } - printf("Done\n"); - -} - -void -event_callback( SaEvtSubscriptionIdT subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT event_data_size) -{ - SaAisErrorT result; - SaUint8T priority; - SaTimeT retention_time; - SaNameT publisher_name = {0, {0}}; - SaTimeT publish_time; - SaEvtEventIdT event_id; - int i; - - printf("event_callback called\n"); - printf("sub ID: %x\n", subscription_id); - printf("event_handle %llx\n", (unsigned long long)event_handle); - printf("event data size %llu\n", (unsigned long long)event_data_size); - - evt_pat_get_array.patternsNumber = 4; - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &priority, /* priority */ - &retention_time, /* retention time */ - &publisher_name, /* publisher name */ - &publish_time, /* publish time */ - &event_id /* event_id */ - ); - if (result != SA_AIS_OK) { - printf("event get attr result(2): %d\n", result); - goto evt_free; - } - printf("pattern array count: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - for (i = 0; i < evt_pat_get_array.patternsNumber; i++) { - printf( "pattern %d =\"%s\"\n", i, - evt_pat_get_array.patterns[i].pattern); - } - - printf("priority: 0x%x\n", priority); - printf("retention: %llx\n", (unsigned long long)retention_time); - printf("publisher name content: \"%s\"\n", publisher_name.value); - printf("event id: %llx\n", (unsigned long long)event_id); -evt_free: - result = saEvtEventFree(event_handle); - printf("event free result: %d\n", result); -} - - -int main (int argc, char **argv) -{ - static const char opts[] = "c:i:t:n:x:u:"; - - int pub_count = 1; - int option; - - while (1) { - option = getopt(argc, argv, opts); - if (option == -1) - break; - - switch (option) { - case 'u': { - int fd; - int sz; - - strcpy(user_data_file, optarg); - fd = open(user_data_file, O_RDONLY); - if (fd < 0) { - printf("Can't open user data file %s\n", - user_data_file); - exit(1); - } - sz = read(fd, user_data, 65536); - if (sz < 0) { - perror("subscription\n"); - exit(1); - } - close(fd); - user_data_size = sz; - break; - } - - case 'c': - strcpy(channel, optarg); - break; - case 'n': - strcpy(pubname, optarg); - break; - case 'i': - subscription_id = - (unsigned int)strtoul(optarg, NULL, 0); - break; - case 't': - ret_time = strtoull(optarg, NULL, 0); - ret_time *= 1000000000; - break; - case 'x': - pub_count = strtoul(optarg, NULL, 0); - break; - default: - printf("invalid arg: \"%s\"\n", optarg); - return 1; - } - } - - while (pub_count--) { - test_pub(); - } - - return 0; -} diff --git a/openais/test/publish.c b/openais/test/publish.c deleted file mode 100644 index fafc593a..00000000 --- a/openais/test/publish.c +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Test program for event service - */ - -#include -#include -#include -#include -#include -#ifndef OPENAIS_SOLARIS -#include -#include -#else -#include -#endif -#include -#include -#include "saAis.h" -#include "saEvt.h" - -// #define EVENT_SUBSCRIBE - -#define PUB_RETRIES 100 -#define TRY_WAIT 2 - -extern int get_sa_error(SaAisErrorT, char *, int); -char result_buf[256]; -int result_buf_len = sizeof(result_buf); - -static int pub_count = 1; -static int wait_time = -1; - -SaVersionT version = { 'B', 0x01, 0x01 }; - -void event_callback( SaEvtSubscriptionIdT subscriptionId, - const SaEvtEventHandleT eventHandle, - const SaSizeT eventDataSize); - -SaEvtCallbacksT callbacks = { - 0, - event_callback -}; - - -char channel[256] = "EVENT_TEST_CHANNEL"; -unsigned int subscription_id = 0xfedcba98; -unsigned long long ret_time = 30000000000ULL; /* 30 seconds */ -char pubname[256] = "Test Pub Name"; - -#define _patt1 "Filter pattern 1" -#define patt1 (SaUint8T *) _patt1 -#define patt1_size sizeof(_patt1) - -#define _patt2 "Filter pattern 2" -#define patt2 (SaUint8T *) _patt2 -#define patt2_size sizeof(_patt2) - -#define _patt3 "Filter pattern 3" -#define patt3 (SaUint8T *) _patt3 -#define patt3_size sizeof(_patt3) - -#define _patt4 "Filter pattern 4" -#define patt4 (SaUint8T *) _patt4 -#define patt4_size sizeof(_patt4) - - -SaEvtEventFilterT filters[] = { - {SA_EVT_PREFIX_FILTER, {patt1_size, patt1_size, patt1}}, - {SA_EVT_SUFFIX_FILTER, {patt2_size, patt2_size, patt2}}, - {SA_EVT_EXACT_FILTER, {patt3_size, patt3_size, patt3}}, - {SA_EVT_PASS_ALL_FILTER, {patt4_size, patt4_size, patt4}} -}; - -SaEvtEventFilterArrayT subscribe_filters = { - sizeof(filters)/sizeof(SaEvtEventFilterT), - filters, -}; - - - SaUint8T pat0[100]; - SaUint8T pat1[100]; - SaUint8T pat2[100]; - SaUint8T pat3[100]; - SaUint8T pat4[100]; - SaEvtEventPatternT evt_patts[5] = { - {100, 100, pat0}, - {100, 100, pat1}, - {100, 100, pat2}, - {100, 100, pat3}, - {100, 100, pat4}}; - SaEvtEventPatternArrayT evt_pat_get_array = { 5, 0, evt_patts }; - -SaEvtEventPatternT patterns[] = { - {patt1_size, patt1_size, patt1}, - {patt2_size, patt2_size, patt2}, - {patt3_size, patt3_size, patt3}, - {patt4_size, patt4_size, patt4} -}; -SaNameT test_pub_name; -#define TEST_PRIORITY 2 - -SaEvtEventPatternArrayT evt_pat_set_array = { - sizeof(patterns)/sizeof(SaEvtEventPatternT), - sizeof(patterns)/sizeof(SaEvtEventPatternT), - patterns -}; - -char user_data_file[256]; -char user_data[65536]; -int user_data_size = 0; - -uint64_t clust_time_now(void) -{ - struct timeval tv; - uint64_t time_now; - - if (gettimeofday(&tv, 0)) { - return 0ULL; - } - - time_now = (uint64_t)(tv.tv_sec) * 1000000000ULL; - time_now += (uint64_t)(tv.tv_usec) * 1000ULL; - - return time_now; -} - -int -test_pub() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtEventHandleT event_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - uint64_t test_retention; - SaSelectionObjectT fd; - int i; - - SaEvtEventIdT event_id; -#ifdef EVENT_SUBSCRIBE - struct pollfd pfd; - int nfd; - int timeout = 1000; -#endif - - - - SaAisErrorT result; - - flags = SA_EVT_CHANNEL_PUBLISHER | -#ifdef EVENT_SUBSCRIBE - SA_EVT_CHANNEL_SUBSCRIBER | -#endif - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - - - do { - result = saEvtInitialize (&handle, &callbacks, &version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("Event Initialize result: %s\n", result_buf); - return(result); - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, - SA_TIME_MAX, &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("channel open result: %s\n", result_buf); - return(result); - } - - /* - * Publish with pattens - */ - printf("Publish\n"); - -#ifdef EVENT_SUBSCRIBE - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event subscribe result: %s\n", result_buf); - return(result); - } -#endif - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event Allocate result: %s\n", result_buf); - return(result); - } - - strcpy((char *)test_pub_name.value, pubname); - test_pub_name.length = strlen(pubname); - test_retention = ret_time; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat_set_array, - TEST_PRIORITY, - test_retention, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event set attr result(2): %s\n", result_buf); - return(result); - } - - for (i = 0; i < pub_count; i++) { - do { - result = saEvtEventPublish(event_handle, user_data, - user_data_size, &event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event Publish result(2): %s\n", result_buf); - return(result); - } - printf("Published event ID: 0x%llx\n", - (unsigned long long)event_id); - } - - /* - * See if we got the event - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("saEvtSelectionObject get %s\n", result_buf); - /* error */ - return(result); - } -#ifdef EVENT_SUBSCRIBE - - for (i = 0; i < pub_count; i++) { - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd <= 0) { - printf("poll fds %d\n", nfd); - if (nfd < 0) { - perror("poll error"); - } - goto evt_free; - } - - printf("Got poll event\n"); - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("saEvtDispatch %s\n", result_buf); - return(result); - } - } -#endif - - - /* - * Test cleanup - */ - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event free result: %s\n", result_buf); - return(result); - } - - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("channel close result: %s\n", result_buf); - return(result); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("Event Finalize result: %s\n", result_buf); - return(result); - } - printf("Done\n"); - return SA_AIS_OK; - -} - -void -event_callback( SaEvtSubscriptionIdT subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT event_data_size) -{ - SaAisErrorT result; - SaUint8T priority; - SaTimeT retention_time; - SaNameT publisher_name = {0, {0}}; - SaTimeT publish_time; - SaEvtEventIdT event_id; - int i; - - printf("event_callback called\n"); - printf("sub ID: %x\n", subscription_id); - printf("event_handle %llx\n", - (unsigned long long)event_handle); - printf("event data size %llu\n", (unsigned long long)event_data_size); - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &priority, /* priority */ - &retention_time, /* retention time */ - &publisher_name, /* publisher name */ - &publish_time, /* publish time */ - &event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event get attr result(2): %s\n", result_buf); - goto evt_free; - } - printf("pattern array count: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - for (i = 0; i < evt_pat_get_array.patternsNumber; i++) { - printf( "pattern %d =\"%s\"\n", i, - evt_pat_get_array.patterns[i].pattern); - } - - printf("priority: 0x%x\n", priority); - printf("retention: 0x%llx\n", - (unsigned long long)retention_time); - printf("publisher name content: \"%s\"\n", publisher_name.value); - printf("event id: 0x%llx\n", - (unsigned long long)event_id); -evt_free: - result = saEvtEventFree(event_handle); - get_sa_error(result, result_buf, result_buf_len); - printf("event free result: %s\n", result_buf); -} - - -static int err_wait_time = -1; - -int main (int argc, char **argv) -{ - static const char opts[] = "c:i:t:n:x:u:w:f:"; - - int ret; - int option; - - while (1) { - option = getopt(argc, argv, opts); - if (option == -1) - break; - - switch (option) { - case 'u': { - int fd; - int sz; - - strcpy(user_data_file, optarg); - fd = open(user_data_file, O_RDONLY); - if (fd < 0) { - printf("Can't open user data file %s\n", - user_data_file); - exit(1); - } - sz = read(fd, user_data, 65536); - if (sz < 0) { - perror("subscription\n"); - exit(1); - } - close(fd); - user_data_size = sz; - break; - } - - case 'c': - strcpy(channel, optarg); - break; - case 'n': - strcpy(pubname, optarg); - break; - case 'f': - err_wait_time = - (unsigned int)strtoul(optarg, NULL, 0); - break; - case 'i': - subscription_id = - (unsigned int)strtoul(optarg, NULL, 0); - break; - case 'w': - wait_time = - (unsigned int)strtoul(optarg, NULL, 0); - break; - case 't': - ret_time = strtoull(optarg, NULL, 0); - ret_time *= 1000000000; - break; - case 'x': - pub_count = strtoul(optarg, NULL, 0); - break; - default: - printf("invalid arg: \"%s\"\n", optarg); - return 1; - } - } - do { - ret = test_pub(); - if (ret != SA_AIS_OK) { - if (err_wait_time < 0) { - exit(ret); - } else { - sleep(err_wait_time); - } - } else if (wait_time < 0) { - break; - } else { - sleep(wait_time); - } - } while(1); - return 0; -} diff --git a/openais/test/sa_error.c b/openais/test/sa_error.c deleted file mode 100644 index 8c488b49..00000000 --- a/openais/test/sa_error.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include "saAis.h" - -const char *sa_error_list[] = { - "OUT_OF_RANGE", - "SA_AIS_OK", - "SA_AIS_ERR_LIBRARY", - "SA_AIS_ERR_VERSION", - "SA_AIS_ERR_INIT", - "SA_AIS_ERR_TIMEOUT", - "SA_AIS_ERR_TRY_AGAIN", - "SA_AIS_ERR_INVALID_PARAM", - "SA_AIS_ERR_NO_MEMORY", - "SA_AIS_ERR_BAD_HANDLE", - "SA_AIS_ERR_BUSY", - "SA_AIS_ERR_ACCESS", - "SA_AIS_ERR_NOT_EXIST", - "SA_AIS_ERR_NAME_TOO_LONG", - "SA_AIS_ERR_EXIST", - "SA_AIS_ERR_NO_SPACE", - "SA_AIS_ERR_INTERRUPT", - "SA_AIS_ERR_NAME_NOT_FOUND", - "SA_AIS_ERR_NO_RESOURCES", - "SA_AIS_ERR_NOT_SUPPORTED", - "SA_AIS_ERR_BAD_OPERATION", - "SA_AIS_ERR_FAILED_OPERATION", - "SA_AIS_ERR_MESSAGE_ERROR", - "SA_AIS_ERR_QUEUE_FULL", - "SA_AIS_ERR_QUEUE_NOT_AVAILABLE", - "SA_AIS_ERR_BAD_CHECKPOINT", - "SA_AIS_ERR_BAD_FLAGS", - "SA_AIS_ERR_NO_SECTIONS", -}; - -int get_sa_error(SaAisErrorT error, char *str, int len) -{ - if (error < SA_AIS_OK || - error > SA_AIS_ERR_NO_SECTIONS || - len < strlen(sa_error_list[error])) { - errno = EINVAL; - return -1; - } - strncpy(str, sa_error_list[error], len); - return 0; -} - -char *get_sa_error_b (SaAisErrorT error) { - return ((char *)sa_error_list[error]); -} - -char *get_test_output (SaAisErrorT result, SaAisErrorT expected) { -static char test_result[256]; - - if (result == expected) { - return ("PASSED"); - } else { - sprintf (test_result, - "FAILED expected %s got %s", - get_sa_error_b(expected), get_sa_error_b(result)); - return (test_result); - } -} diff --git a/openais/test/sa_error.h b/openais/test/sa_error.h deleted file mode 100644 index b73a6d6c..00000000 --- a/openais/test/sa_error.h +++ /dev/null @@ -1,5 +0,0 @@ -extern int get_sa_error(SaAisErrorT error, char *str, int len); - -extern char *get_sa_error_b (SaAisErrorT error); - -extern char *get_test_output (SaAisErrorT result, SaAisErrorT expected); diff --git a/openais/test/subscription.c b/openais/test/subscription.c deleted file mode 100644 index af0dbd12..00000000 --- a/openais/test/subscription.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Test program for event service subscriptions - */ - -#include -#include -#include -#include -#include -#include -#ifndef OPENAIS_SOLARIS -#include -#include -#else -#include -#endif -#include -#include -#include "saAis.h" -#include "saEvt.h" - -#ifdef OPENAIS_SOLARIS -char * strsep(char** str, const char* delims) -{ - char* token; - - if (*str == NULL) { - /* No more tokens */ - return NULL; - } - - token = *str; - while (**str != '\0') { - if (strchr(delims,**str)!=NULL) { - **str = '\0'; - (*str)++; - return token; - } - (*str)++; - } - /* There is no other token */ - *str = NULL; - return token; -} -#endif - -#define TEST_EVENT_ORDER 1 -#define EVT_FREQ 1000 -#define TRY_WAIT 2 -uint32_t evt_count = 0; - -extern int get_sa_error(SaAisErrorT, char *, int); -char result_buf[256]; -int result_buf_len = sizeof(result_buf); - -int quiet = 0; - -SaVersionT version = { 'B', 0x01, 0x01 }; - -void event_callback( SaEvtSubscriptionIdT subscriptionId, - const SaEvtEventHandleT eventHandle, - const SaSizeT eventDataSize); - -SaEvtCallbacksT callbacks = { - 0, - event_callback -}; - -char channel[256] = "EVENT_TEST_CHANNEL"; - -#define MAX_NODES 256 -SaEvtEventIdT last_event_id[MAX_NODES] = {0,}; - -#define MAX_SUB 100 - -uint32_t subscription_id[MAX_SUB] = {0xfedcba98}; - -int sub_next = 0; - -char pubname[256] = "Test Pub Name"; - -#define patt1 "Filter pattern 1" -#define patt1_size sizeof(patt1) - -SaEvtEventFilterT filters[MAX_SUB] = { - {SA_EVT_PASS_ALL_FILTER, {0, 0}} -}; - -SaEvtEventFilterArrayT subscribe_filters[MAX_SUB] = { - { - 1, &filters[0] - }, -}; - - -#define PAT_SIZE 100 -SaUint8T pat0[PAT_SIZE]; -SaUint8T pat1[PAT_SIZE]; -SaUint8T pat2[PAT_SIZE]; -SaUint8T pat3[PAT_SIZE]; -SaUint8T pat4[PAT_SIZE]; -SaEvtEventPatternT evt_patts[5] = { - {PAT_SIZE, PAT_SIZE, pat0}, - {PAT_SIZE, PAT_SIZE, pat1}, - {PAT_SIZE, PAT_SIZE, pat2}, - {PAT_SIZE, PAT_SIZE, pat3}, - {PAT_SIZE, PAT_SIZE, pat4}}; -SaEvtEventPatternArrayT evt_pat_get_array = { 5, 0, evt_patts }; - -SaNameT test_pub_name = {13, "Test Pub Name"}; - - -char user_data_file[256]; -char user_data[65536]; -char event_data[65536]; -int user_data_size = 0; - -int -test_subscription() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 60000; - int i; - - - - SaAisErrorT result; - - flags = SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - - printf("Test subscription:\n"); - - do { - result = saEvtInitialize (&handle, &callbacks, &version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("Event Initialize result: %s\n", result_buf); - return result; - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, - SA_TIME_MAX, &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("channel open result: %s\n", result_buf); - goto init_fin; - } - - if (sub_next == 0) - sub_next = 1; - - for (i = 0; i < sub_next; i++) { - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters[i], - subscription_id[i]); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("event subscribe result: %s\n", result_buf); - goto chan_fin; - } - - } - /* - * See if we got the event - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("saEvtSelectionObject get %s\n", result_buf); - goto sub_fin; - } - - while (1) { - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd < 0) { - printf("poll fds %d\n", nfd); - perror("poll error"); - goto sub_fin; - } else if (nfd == 0) { - printf("Still waiting\n"); - continue; - } - - if (pfd.revents & (POLLERR|POLLHUP)) { - printf("Error received on poll fd %llu\n", - (unsigned long long)fd); - result = SA_AIS_ERR_BAD_OPERATION; - goto sub_fin; - } - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("saEvtDispatch %s\n", result_buf); - goto sub_fin; - } - if (!quiet) - printf(" - - - - - - - - - - - - - - - -\n\n"); - } - -sub_fin: -#if 0 - result = saEvtEventUnsubscribe(channel_handle, subscription_id); - if (result != SA_AIS_OK) - printf("Channel unsubscribe result: %d\n", result); -#endif -chan_fin: - result = saEvtChannelClose(channel_handle); - if (result != SA_AIS_OK) - get_sa_error(result, result_buf, result_buf_len); - printf("Channel close result: %s\n", result_buf); -init_fin: - result = saEvtFinalize(handle); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("Finalize result: %s\n", result_buf); - } - - return result; -} - -static char time_buf[1024]; - -char *ais_time_str(SaTimeT time) -{ - time_t t; - if (time == SA_TIME_UNKNOWN) { - return "Unknown Time"; - } - t = time / 1000000000ULL; - strcpy(time_buf, ctime(&t)); - return time_buf; -} - -#define dprintf(format, ...) \ - { \ - if (did_dot) { \ - printf("\n"); \ - } \ - printf(format, ## __VA_ARGS__); \ - did_dot = 0; \ - } - -void -event_callback( SaEvtSubscriptionIdT subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT event_data_size) -{ - static int did_dot = 0; - SaAisErrorT result; - SaUint8T priority; - SaTimeT retention_time; - SaNameT publisher_name = {0, {0}}; - SaTimeT publish_time; - SaEvtEventIdT event_id; - SaSizeT received_size; - int i; -#ifdef TEST_EVENT_ORDER - int idx; -#endif - - if (!quiet) - dprintf("event_callback called\n"); - if (!quiet) - dprintf("sub ID: %x\n", subscription_id); - if (!quiet) - dprintf("event_handle %llx\n", (unsigned long long)event_handle); - if (!quiet) - dprintf("event data size %llu\n", (unsigned long long)event_data_size); - - evt_pat_get_array.patterns[0].patternSize = PAT_SIZE; - evt_pat_get_array.patterns[1].patternSize = PAT_SIZE; - evt_pat_get_array.patterns[2].patternSize = PAT_SIZE; - evt_pat_get_array.patterns[3].patternSize = PAT_SIZE; - evt_pat_get_array.patternsNumber = 4; - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &priority, /* priority */ - &retention_time, /* retention time */ - &publisher_name, /* publisher name */ - &publish_time, /* publish time */ - &event_id /* event_id */ - ); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - dprintf("event get attr result(2): %s\n", result_buf); - goto evt_free; - } - if (!quiet) { - dprintf("pattern array count: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - for (i = 0; i < evt_pat_get_array.patternsNumber; i++) { - dprintf( "pattern %d =\"%s\"\n", i, - evt_pat_get_array.patterns[i].pattern); - } - - dprintf("priority: 0x%x\n", priority); - dprintf("retention: 0x%llx\n", (unsigned long long)retention_time); - dprintf("publisher name content: \"%s\"\n", - publisher_name.value); - } - - if (event_id == SA_EVT_EVENTID_LOST) { - dprintf("*** Events have been dropped at %s", - ais_time_str(publish_time)); - - if ((evt_pat_get_array.patternsNumber == 0)|| - (strcmp((char *)evt_pat_get_array.patterns[0].pattern, SA_EVT_LOST_EVENT) != 0)) { - dprintf("*** Received SA_EVT_EVENTID_LOST but pattern is wrong: %s\n", - evt_pat_get_array.patterns[0].pattern); - } - } - if (quiet < 2) { - dprintf("event id: 0x%016llx\n", (unsigned long long)event_id); - } - if (quiet == 2) { - if ((++evt_count % EVT_FREQ) == 0) { - fprintf(stderr, "."); - did_dot = 1; - } - } - - if (event_id == SA_EVT_EVENTID_LOST) { - goto evt_free; - } - -#ifdef TEST_EVENT_ORDER - for (idx = 0; idx < MAX_NODES; idx++) { - if (last_event_id[idx] == 0) { - last_event_id[idx] = event_id; - break; - } else { - if ((last_event_id[idx] >> 32) == (event_id >> 32)) { - last_event_id[idx]++; - if (last_event_id[idx] != event_id) { - dprintf("*** expected %016llx got %016llx event_id\n", - (unsigned long long)last_event_id[idx], - (unsigned long long)event_id); - last_event_id[idx] = event_id; - } - break; - } - } - } - if (idx == MAX_NODES) { - dprintf("*** Too many nodes in cluster\n"); - exit(1); - } -#endif - - if (event_data_size != user_data_size) { - dprintf("unexpected data size: e=%d, a=%llu\n", - user_data_size, (unsigned long long)event_data_size); - goto evt_free; - } - - received_size = user_data_size; - result = saEvtEventDataGet(event_handle, event_data, - &received_size); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - dprintf("event get data result: %s\n", result_buf); - goto evt_free; - } - if (received_size != event_data_size) { - dprintf("event data mismatch e=%llu, a=%llu\n", - (unsigned long long)event_data_size, - (unsigned long long)received_size); - goto evt_free; - } - if (memcmp(user_data, event_data, user_data_size) != 0 ) { - dprintf("event data doesn't match specified file data\n"); - goto evt_free; - } - if (!quiet) { - dprintf("Received %d bytes of data OK\n", - user_data_size); - } - -evt_free: - result = saEvtEventFree(event_handle); - if (!quiet) { - get_sa_error(result, result_buf, result_buf_len); - dprintf("event free result: %s\n", result_buf); - } -} - -static int err_wait_time = -1; - -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) -static struct sched_param sched_param = { - sched_priority: 1 -}; -#endif - -int main (int argc, char **argv) -{ - static const char opts[] = "c:s:n:qu:f:"; - - int option; - char *p; - -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) - sched_setscheduler (0, SCHED_RR, &sched_param); -#endif - - while (1) { - option = getopt(argc, argv, opts); - if (option == -1) - break; - - switch (option) { - case 'u': { - int fd; - int sz; - - strcpy(user_data_file, optarg); - fd = open(user_data_file, O_RDONLY); - if (fd < 0) { - printf("Can't open user data file %s\n", - user_data_file); - exit(1); - } - sz = read(fd, user_data, 65536); - if (sz < 0) { - perror("subscription\n"); - exit(1); - } - close(fd); - user_data_size = sz; - break; - } - case 'q': - quiet++; - break; - case 'c': - strcpy(channel, optarg); - break; - case 'f': - err_wait_time = - (unsigned int)strtoul(optarg, NULL, 0); - break; - case 'n': - strcpy(pubname, optarg); - break; - case 's': - p = strsep(&optarg, ","); - subscription_id[sub_next] = - (unsigned int)strtoul(p, NULL, 0); - p = strsep(&optarg, ","); - filters[sub_next].filter.pattern = malloc(strlen(p)); - strcpy((char *)filters[sub_next].filter.pattern, p); - filters[sub_next].filter.patternSize = strlen(p); - p = strsep(&optarg, ","); - filters[sub_next++].filterType = strtoul(p,0, 0); - break; - default: - printf("invalid arg: \"%s\"\n", optarg); - return 1; - } - } - do { - if (test_subscription() != SA_AIS_OK) { - if (err_wait_time > 0) { - sleep(err_wait_time); - } else { - return 1; - } - } - } while (err_wait_time > 0); - - return 0; -} - diff --git a/openais/test/test.cpp b/openais/test/test.cpp deleted file mode 100644 index 713ef927..00000000 --- a/openais/test/test.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "saAis.h" -#include "saCkpt.h" - - -SaVersionT version = { 'B', 1, 1 }; - -SaCkptCallbacksT callbacks = { - 0, - 0 -}; - -SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = { - SA_CKPT_WR_ALL_REPLICAS, - 100000, - 5000000000LL, - 5, - 20000, - 10 -}; - -SaCkptSectionIdT sectionId = { - 14, - (SaUint8T*)"section ID #1" -}; - -SaCkptSectionCreationAttributesT sectionCreationAttributes = { - §ionId, - SA_TIME_END -}; - -char* getPayload(int psize) { - int i; - char* retVal = new char[psize]; - if (retVal == NULL) - { - return NULL; - } - for (i = 0; i < psize; i++) - { - if (i == (psize - 1)) { - *retVal = '\0'; - retVal++; - continue; - } - *retVal = 'z'; - retVal++; - } - retVal = retVal - psize; - return retVal; -} - -SaCkptCheckpointHandleT WriteCheckpointHandle; - -static long sendCount = 0; -void process_message() -{ - struct timeval tv; - long t1; - long t2; - long told; - SaCkptIOVectorElementT writeElement; // KJS - - SaUint32T erroroneousVectorIndex = 0; - SaAisErrorT error; - - writeElement.sectionId = sectionId; - writeElement.dataBuffer = getPayload(200); - writeElement.dataSize = 200; - writeElement.dataOffset = 0; - writeElement.readSize = 0; - - gettimeofday(&tv, NULL); - t1 = tv.tv_usec; - told = tv.tv_sec; - - do { - error = saCkptCheckpointWrite (WriteCheckpointHandle, - &writeElement, - 1, - &erroroneousVectorIndex); - - if (error != SA_AIS_OK) { - fprintf(stderr,"saCkptCheckpointWrite result %d (should be 1)\n", error); - } - sendCount++; - fprintf(stderr,"sendCount = %d",(int)sendCount); - } while (error == SA_AIS_ERR_TRY_AGAIN); - - gettimeofday(&tv, NULL); - t2 = tv.tv_usec; - fprintf(stderr," ,RTT::%d.%d\n",(long)tv.tv_sec - told, t2-t1); -} - -int main () { - SaAisErrorT error; - SaNameT* WriteCheckpointName = (SaNameT*) malloc(sizeof(SaNameT)); - char name[10]; - SaCkptHandleT ckptHandle; - - sprintf(name,"ckpt%d",1); - int namelen = strlen(name) + 1; - memcpy(WriteCheckpointName->value, name, namelen); - WriteCheckpointName->length = namelen; - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - - error = saCkptCheckpointOpen ( - ckptHandle, - WriteCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_WRITE, - 1000000000, /* 1 Second */ - &WriteCheckpointHandle); - - if (error != SA_AIS_OK) { - fprintf(stderr,"saCkptCheckpointOpen result %d (should be 1)\n", error); - return error; - } - - error = saCkptSectionCreate ( WriteCheckpointHandle, - §ionCreationAttributes, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - if (error != SA_AIS_OK) { - fprintf(stderr,"saCkptSectionCreate result = %d\n", error); - return error; - } - - struct timespec tv; - tv.tv_sec = 0; - tv.tv_nsec = 15000000; //15 milliseconds - - while(1) { - process_message(); - nanosleep(&tv,NULL); - } - - return 1; - -} diff --git a/openais/test/testamf.c b/openais/test/testamf.c deleted file mode 100644 index 05cab958..00000000 --- a/openais/test/testamf.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ais_types.h" -#include "ais_amf.h" -#include "saClm.h" - -void printSaClmNodeAddressT (SaClmNodeAddressT *nodeAddress) { - int i; - - for (i = 0; i < nodeAddress->length; i++) { - printf ("%d.", nodeAddress->value[i]); - } -} - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static int health_flag = -1; -static unsigned int healthcheck_count = 0; -static unsigned int healthcheck_no = 0; -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckT checkType) -{ - SaErrorT res; - - healthcheck_no ++; - if (health_flag == -1 || healthcheck_no%healthcheck_count == 0) { - printf ("%u HealthcheckCallback have occured for component: ",healthcheck_no); - printSaNameT ((SaNameT *)compName); - printf ("\n"); - } - res = saAmfResponse (invocation, SA_OK); - if (res != SA_OK) { - printf ("response res is %d\n", res); - } -} - -void ReadinessStateSetCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfReadinessStateT readinessState) -{ - switch (readinessState) { - case SA_AMF_IN_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_OUT_OF_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_STOPPING: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to stop, stopping.\n"); - saAmfStoppingComplete (invocation, SA_OK); - break; - } -} - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); -} - -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - SaAmfCSIFlagsT csiFlags, - SaAmfHAStateT *haState, - SaNameT *activeCompName, - SaAmfCSITransitionDescriptorT transitionDescriptor) -{ - switch (*haState) { - case SA_AMF_ACTIVE: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_STANDBY: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_QUIESCED: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_QUIESCED.\n"); - saAmfResponse (invocation, SA_OK); - break; - } -} - -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - printf ("CSIRemoveCallback invocation id %llu compName ", - (unsigned long long)invocation); - printSaNameT ((SaNameT *)compName); - printf (" csiName "); - printSaNameT ((SaNameT *)csiName); - printf ("\n"); - saAmfResponse (invocation, SA_OK); -} - -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -void ExternalComponentRestartCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName) -{ - printf ("ExternalComponentRestartCallback\n"); -} - -void ExternalComponentControlCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName, - SaAmfExternalComponentActionT controlAction) -{ - printf ("ExternalComponentControlCallback\n"); -} - -void PendingOperationConfirmCallback ( - const SaInvocationT invocation, - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationConfirmCallback\n"); -} - -void PendingOperationExpiredCallback ( - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationExpiredCallback\n"); -} - -SaAmfCallbacksT amfCallbacks = { - HealthcheckCallback, - ReadinessStateSetCallback, - ComponentTerminateCallback, - CSISetCallback, - CSIRemoveCallback, - ProtectionGroupTrackCallback, - ExternalComponentRestartCallback, - ExternalComponentControlCallback, - PendingOperationConfirmCallback, - PendingOperationExpiredCallback -}; - -SaVersionT version = { 'A', 1, 1 }; - -void sigintr_handler (int signum) { - exit (0); -} - -int main (int argc, char **argv) { - SaAmfHandleT handle; - SaAmfHandleT handleproxy; - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - SaNameT compName; - SaNameT csiName; - SaNameT compname_get_name; - SaAmfReadinessStateT readinessState; - SaAmfHAStateT HAState; - SaAmfComponentCapabilityModelT componentCapabilityModel; - SaAmfProtectionGroupNotificationT protectionGroupNotificationBuffer[64]; - SaAmfPendingOperationFlagsT pending_operation; - extern char *optarg; - extern int optind; - int c; - - signal (SIGINT, sigintr_handler); - - for (;;) { - c = getopt(argc,argv,"h:"); - if (c==-1) { - break; - } - switch (c) { - case 0 : - break; - case 'h': - health_flag = 0; - sscanf (optarg,"%ud" ,&healthcheck_count); - break; - default : - break; - } - } - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - result = saAmfInitialize (&handleproxy, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - FD_ZERO (&read_fds); - saAmfSelectionObjectGet (&handle, &select_fd); - FD_SET (select_fd, &read_fds); - saAmfSelectionObjectGet (&handleproxy, &select_fd); - FD_SET (select_fd, &read_fds); - - setSanameT (&compName, "comp_a_in_su_x"); - setSanameT (&csiName, "pgA"); - - result = saAmfComponentRegister (&handle, &compName, NULL); - printf ("saAmfComponentRegister with result %d (should be 1) is:", result); - - result = saAmfCompNameGet (&handle, &compname_get_name); - printf ("saAmfCompNameGet with result %d (should be 1) is:", result); - printSaNameT (&compname_get_name); - printf ("\n"); - - result = saAmfPendingOperationGet (&compName, &pending_operation); - printf ("saAmfPendingOperationGet with value %d result %d (should be 1) is:", - pending_operation, result); - - result = saAmfComponentCapabilityModelGet (&compName, &componentCapabilityModel); - printf ("component capability model get is %d (should be 1)\n", result); - - result = saAmfProtectionGroupTrack (&handle, &csiName, SA_TRACK_CURRENT | SA_TRACK_CHANGES, protectionGroupNotificationBuffer, 64); - printf ("track start result is %d (should be 1)\n", result); - - result = saAmfProtectionGroupTrackStop (&handle, &csiName); - printf ("track stop result is %d (should be 1)\n", result); - - result = saAmfReadinessStateGet (&compName, &readinessState); - printf ("saAmfReadinessStateGet (%d) result %d (should be 1)\n", - readinessState, result); - - result = saAmfHAStateGet (&compName, &csiName, &HAState); - printf ("saAmfHAStateGet (%d) result %d (should be 1)\n", - HAState, result); - - do { - FD_SET (STDIN_FILENO, &read_fds); - select (select_fd + 1, &read_fds, 0, 0, 0); - if (FD_ISSET (STDIN_FILENO, &read_fds)) { - break; - } - saAmfDispatch (&handle, SA_DISPATCH_ALL); - } while (result); - - result = saAmfProtectionGroupTrackStop (&handle, &csiName); - saAmfFinalize (&handle); - - return (0); -} diff --git a/openais/test/testamf1.c b/openais/test/testamf1.c deleted file mode 100644 index 0483156d..00000000 --- a/openais/test/testamf1.c +++ /dev/null @@ -1,627 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006 Ericsson AB. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * Hans Feldt - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saAmf.h" - -SaAmfHandleT handle; - -SaAmfHealthcheckKeyT keyAmfInvoked = { - .key = "amfInvoked", - .keyLen = 10 -}; - -SaAmfHealthcheckKeyT keyCompInvoked = { - .key = "compInvoked", - .keyLen = 11 -}; - -SaNameT compNameGlobal; -int good_health = 0; -int good_health_limit = 0; - -enum { - FINALIZE = 0, - UNREGISTER, - ERROR_REPORT -}; - -#define die(format, args...) _die (__FILE__, __LINE__, format, ##args) - -static void _die (char *file, int line, char *format, ...) __attribute__((format(printf, 3, 4))); -static void _die (char *file, int line, char *format, ...) -{ - char buf[1024]; - va_list ap; - - sprintf (buf, "%d - %s:#%d - Error: '%s', exiting...\n", - (int)getpid(), file, line, format); - - va_start (ap, format); - vfprintf (stderr, buf, ap); - va_end(ap); - - exit (-1); -} - -static void response ( - SaAmfHandleT handle, SaInvocationT invocation, SaAisErrorT error) -{ - SaAisErrorT result; - - do { - result = saAmfResponse (handle, invocation, error); - if (result == SA_AIS_ERR_TRY_AGAIN) { - fprintf(stderr, "%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfResponse failed %d", result); - } -} - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static unsigned int healthcheck_no = 0; - -int stop = 0; - -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckKeyT *healthcheckKey) -{ - SaAisErrorT res; - - if( !good_health && healthcheck_no++); - - if (healthcheck_no == good_health_limit ) { - response (handle, invocation, SA_AIS_OK); - res = saAmfHealthcheckStop (handle, - &compNameGlobal, - &keyAmfInvoked); - printf ("healthcheck stop result %d (should be %d)\n", res, SA_AIS_OK); - - printf ("COMPONENT REPORTING ERROR %s\n", compNameGlobal.value); - saAmfComponentErrorReport (handle, compName, 0, SA_AMF_COMPONENT_RESTART, 0); - printf ("COMPONENT DONE REPORTING ERROR\n"); - } else { - response (handle, invocation, SA_AIS_OK); - } -} - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); - response (handle, invocation, SA_AIS_OK); - exit (0); -} - -#if 0 - #include - #define TRU "%d" - #define TRS "%s" - #define TR(format,x) do { \ - struct timeval t;\ - gettimeofday(&t,NULL); \ - printf("%s:%d: %s : %d : %u: %u :%s : " format "\n",\ - __FILE__,__LINE__,__FUNCTION__, \ - (int)getpid(),(int)t.tv_sec, (int)t.tv_usec,#x,x); \ - }while(0) -#else - #define TRU "%d" - #define TRS "%s" - #define TR(format,x) -#endif - -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor) -{ - SaAmfHAStateT state; - int res; - int i; - - switch (haState) { - case SA_AMF_HA_ACTIVE: - printf ("PID %d: Component '%s' requested to enter hastate SA_AMF_ACTIVE" - " for \n\tCSI '%s'\n", - (int)getpid(), compName->value, csiDescriptor->csiName.value); - response (handle, invocation, SA_AIS_OK); - - res = saAmfHAStateGet (handle, compName, &csiDescriptor->csiName, &state); - if (res != SA_AIS_OK || haState != state) { - fprintf (stderr, "saAmfHAStateGet failed: %d\n", res); - exit (-1); - } - - TR(TRU, csiDescriptor->csiAttr.number); - for(i=0; icsiAttr.number; i++) { - - 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); - - } -#if 0 - TR(TRS,csiDescriptor->csiAttr.attr[i].attrName); - TR(TRS, csiDescriptor->csiAttr.attr[i].attrValue); -#endif - } - - TR(TRU, csiDescriptor->csiFlags); - - - printSaNameT((SaNameT*) &csiDescriptor->csiStateDescriptor.activeDescriptor.activeCompName); - TR(TRU, csiDescriptor->csiStateDescriptor.activeDescriptor.transitionDescriptor); - - break; - - case SA_AMF_HA_STANDBY: - printf ("PID %d: Component '%s' requested to enter hastate SA_AMF_STANDBY " - "for \n\tCSI '%s'\n", - (int)getpid(), compName->value, csiDescriptor->csiName.value); - response (handle, invocation, SA_AIS_OK); - - TR(TRU,csiDescriptor->csiAttr.number); - for(i=0; icsiAttr.number; i++) { - 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); - TR(TRS,csiDescriptor->csiAttr.attr[i].attrValue); - } - TR(TRU,csiDescriptor->csiFlags); - - printSaNameT((SaNameT*) &csiDescriptor->csiStateDescriptor.standbyDescriptor.activeCompName); - TR(TRU,csiDescriptor->csiStateDescriptor.standbyDescriptor.standbyRank); - - break; - case SA_AMF_HA_QUIESCED: - printf ("%d: Component '%s' requested to enter hastate SA_AMF_HA_QUIESCED " - "for \n\tCSI '%s'\n", - (int)getpid(), compName->value, csiDescriptor->csiName.value); - response (handle, invocation, SA_AIS_OK); - break; - case SA_AMF_HA_QUIESCING: - break; - default: - break; - } -} - -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - SaAmfCSIFlagsT csiFlags) -{ - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - response (handle, invocation, SA_AIS_OK); -} - -#ifdef COMPILE_OUT -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaAisErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -#endif - -SaAmfCallbacksT amfCallbacks = { - .saAmfHealthcheckCallback = HealthcheckCallback, - .saAmfComponentTerminateCallback = ComponentTerminateCallback, - .saAmfCSISetCallback = CSISetCallback, - .saAmfCSIRemoveCallback = CSIRemoveCallback, -}; - -SaAmfCallbacksT amfCallbacks; - -SaVersionT version = { 'B', 1, 1 }; -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) -static struct sched_param sched_param; -#endif - -void sigintr_handler (int signum) { - stop = FINALIZE; -} - -void sigusr1_handler (int signum) { - stop = UNREGISTER; -} - -void sigusr2_handler (int signum) { - stop = ERROR_REPORT; -} - -void write_pid (void) { - char pid[256]; - char filename[256]; - int fd; - int res; - - sprintf (filename, "/var/run/openais_cleanup_%s", compNameGlobal.value); - fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); - if (fd == -1) { - printf("%d: Failed using /var/run for pid file, using /tmp\n", (int)getpid()); - sprintf (filename, "/tmp/openais_cleanup_%s", compNameGlobal.value); - fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); - } - sprintf (pid, "%d", (int)getpid()); - res = write (fd, pid, strlen (pid)); - close (fd); -} - -static SaSelectionObjectT comp_init () -{ - char *name; - char *env; - int result; - SaSelectionObjectT select_fd; - SaAmfPmErrorsT pmErrors = (SA_AMF_PM_ZERO_EXIT | - SA_AMF_PM_NON_ZERO_EXIT | - SA_AMF_PM_ABNORMAL_END); - - name = getenv ("SA_AMF_COMPONENT_NAME"); - if (name == NULL) { - die ("SA_AMF_COMPONENT_NAME missing"); - } - - if (strstr (name, "safComp=") == NULL || - strstr (name, "safSu=") == NULL || - strstr (name, "safSg=") == NULL || - strstr (name, "safApp=") == NULL) { - die ("SA_AMF_COMPONENT_NAME value wrong"); - } - - printf("%d: Hello world from %s\n", (int)getpid(), name); - - env = getenv ("var1"); - if (env == NULL) { - die ("var1 missing"); - } - if (strcmp (env, "val1") != 0) { - die ("var1 value wrong"); - } - env = getenv ("var2"); - if (env == NULL) { - die ("var2 wrong"); - } - if (strcmp (env, "val2") != 0) { - die ("var2 value wrong"); - } - - signal (SIGINT, sigintr_handler); - signal (SIGUSR1, sigusr1_handler); - signal (SIGUSR2, sigusr2_handler); - -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) - - sched_param.sched_priority = sched_get_priority_max(SCHED_RR); - if (sched_param.sched_priority == -1) { - fprintf (stderr, "%d: couldn't retrieve the maximum scheduling " \ - "priority supported by the Round-Robin class (%s)\n", - (int)getpid(), strerror(errno)); - } else { - result = sched_setscheduler (0, SCHED_RR, &sched_param); - if (result == -1) { - fprintf (stderr, "%d: couldn't set sched priority (%s)\n", - (int)getpid(), strerror(errno)); - } - } -#endif - - do { - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfInitialize result is %d", result); - } - - do { - result = saAmfSelectionObjectGet (handle, &select_fd); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfSelectionObjectGet failed %d", result); - } - - do { - result = saAmfComponentNameGet (handle, &compNameGlobal); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfComponentNameGet failed %d", result); - } - write_pid (); - - do { - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &keyAmfInvoked, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfHealthcheckStart failed %d", result); - } - - do { - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &keyCompInvoked, - SA_AMF_HEALTHCHECK_COMPONENT_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfHealthcheckStart failed %d", result); - } - - { - SaNameT badname; - strcpy ((char*)badname.value, "badname"); - badname.length = 7; - do { - result = saAmfComponentRegister (handle, &badname, NULL); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_ERR_INVALID_PARAM) { - die ("saAmfComponentRegister failed %d", result); - } - } - - do { - result = saAmfComponentRegister (handle, &compNameGlobal, NULL); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_OK) { - die ("saAmfComponentRegister failed %d", result); - } - - /* - * startup passive monitoring - */ - do { - result = saAmfPmStart (handle, - &compNameGlobal, getpid(), 1, - pmErrors, - SA_AMF_COMPONENT_FAILOVER); - - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - - /* - * Test already started healthcheck - */ - do { - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &keyAmfInvoked, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - if (result == SA_AIS_ERR_TRY_AGAIN) { - printf("%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - if (result != SA_AIS_ERR_EXIST) { - die ("saAmfHealthcheckStart failed %d", result); - } - - return select_fd; -} - -static void handle_intr (void) -{ - SaAisErrorT result; - - switch (stop) { - case FINALIZE: - result = saAmfFinalize (handle); - if (result != SA_AIS_OK) { - die ("saAmfFinalize failed %d", result); - } - fprintf(stderr, "%d: %s exiting\n", - (int)getpid(), compNameGlobal.value); - exit (EXIT_SUCCESS); - break; - case UNREGISTER: - fprintf(stderr, "%d: %s unregistering\n", - (int)getpid(), compNameGlobal.value); - result = saAmfComponentUnregister ( - handle, &compNameGlobal, NULL); - if (result != SA_AIS_OK) { - die ("saAmfComponentUnregister failed %d", result); - } - fprintf(stderr, "%d: waiting after unregister\n", (int)getpid()); - while (1) { - sleep (100000000); - } - break; - case ERROR_REPORT: - fprintf(stderr, "%d: %s error reporting\n", - (int)getpid(), compNameGlobal.value); - result = saAmfComponentErrorReport ( - handle, &compNameGlobal, 0, SA_AMF_COMPONENT_RESTART, 0); - if (result != SA_AIS_OK) { - die ("saAmfComponentErrorReport failed %d", result); - } - fprintf(stderr, "%d: waiting after error report\n", (int)getpid()); - while (1) { - sleep (100000000); - } - break; - default: - die ("unknown %d", stop); - break; - } -} - -int main (int argc, char **argv) -{ - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - struct timeval tv; - - select_fd = comp_init(); - FD_ZERO (&read_fds); - - do { - tv.tv_sec = 2; /* related to value in amf.conf! */ - tv.tv_usec = 0; - FD_SET (select_fd, &read_fds); - result = select (select_fd + 1, &read_fds, 0, 0, &tv); - if (result == -1) { - if (errno == EINTR) { - handle_intr (); - } else { - die ("select failed - %s", strerror (errno)); - } - } else if (result > 0) { - do { - result = saAmfDispatch (handle, SA_DISPATCH_ALL); - if (result == SA_AIS_ERR_TRY_AGAIN) { - fprintf(stderr, "%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - - if (result != SA_AIS_OK) { - die ("saAmfDispatch failed %d", result); - } - } else { - /* timeout */ - do { - result = saAmfHealthcheckConfirm (handle, &compNameGlobal, - &keyCompInvoked, SA_AIS_OK); - if (result == SA_AIS_ERR_TRY_AGAIN) { - fprintf(stderr, "%d: TRY_AGAIN received\n", (int)getpid()); - usleep (100000); - } - } while (result == SA_AIS_ERR_TRY_AGAIN); - - if (result != SA_AIS_OK) { - die ("saAmfHealthcheckConfirm failed %d", result); - } - } - } while (stop == 0); - - fprintf(stderr, "%d: exiting...\n", (int)getpid()); - exit (EXIT_SUCCESS); -} - - diff --git a/openais/test/testamf2.c b/openais/test/testamf2.c deleted file mode 100644 index 2acc76d4..00000000 --- a/openais/test/testamf2.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saAmf.h" - -SaAmfHandleT handle; - -SaAmfHealthcheckKeyT key0 = { - .key = "key1", - .keyLen = 4 -}; -SaNameT compNameGlobal; - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static int health_flag = -1; -static unsigned int healthcheck_count = 0; -static unsigned int healthcheck_no = 0; - -int stop = 0; - -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckKeyT *healthcheckKey) -{ - SaErrorT res; - - healthcheck_no++; -/* - printf ("Healthcheck %u for key '%s' for component ", - healthcheck_no, healthcheckKey->key); - - printSaNameT ((SaNameT *)compName); - printf ("\n"); -*/ - res = saAmfResponse (handle, invocation, SA_AIS_OK); - if (healthcheck_no == 3) { - res = saAmfHealthcheckStop (handle, &compNameGlobal, &key0); - stop = 1; - } -} - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); - saAmfResponse (handle, invocation, SA_AIS_OK); - exit (0); -} - -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor) -{ - int res; - switch (haState) { - case SA_AMF_HA_ACTIVE: - printf ("CSISetCallback:"); - printf ("for CSI '"); - printSaNameT ((SaNameT *)&csiDescriptor->csiName); - printf ("' for component "); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); - res = saAmfResponse (handle, invocation, SA_AIS_OK); - break; - - case SA_AMF_HA_STANDBY: - printf ("CSISetCallback:"); - printf ("for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("' for component "); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); - saAmfResponse (handle, invocation, SA_AIS_OK); - break; - } -} - -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - int res; - - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - res = saAmfResponse (handle, invocation, SA_AIS_OK); -} - -#ifdef COMPILE_OUT -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -#endif - -SaAmfCallbacksT amfCallbacks = { - .saAmfHealthcheckCallback = HealthcheckCallback, - .saAmfComponentTerminateCallback = ComponentTerminateCallback, - .saAmfCSISetCallback = CSISetCallback, - .saAmfCSIRemoveCallback = CSIRemoveCallback, -}; - -SaAmfCallbacksT amfCallbacks; - -SaVersionT version = { 'B', 1, 1 }; - -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) -static struct sched_param sched_param = { - sched_priority: 99 -}; -#endif - -void sigintr_handler (int signum) { - exit (0); -} - -int main (int argc, char **argv) { - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - extern char *optarg; - extern int optind; - int c; - -printf ("testamf2 pid %d\n", getpid()); - memset (&compNameGlobal, 0, sizeof (SaNameT)); - signal (SIGINT, sigintr_handler); -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) - result = sched_setscheduler (0, SCHED_RR, &sched_param); - if (result == -1) { - printf ("couldn't set sched priority\n"); - } -#endif - - for (;;){ - c = getopt(argc,argv,"h:n:"); - if (c==-1) { - break; - } - switch (c) { - case 0 : - break; - case 'h': - health_flag = 0; - sscanf (optarg,"%ud" ,&healthcheck_count); - break; - case 'n': - setSanameT (&compNameGlobal, optarg); - break; - default : - break; - } - } - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_AIS_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - FD_ZERO (&read_fds); - saAmfSelectionObjectGet (handle, &select_fd); - FD_SET (select_fd, &read_fds); - if (compNameGlobal.length <= 0) { - setSanameT (&compNameGlobal, "comp_b_in_su_1"); - } - - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - printf ("start %d\n", result); - - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - printf ("start %d\n", result); - result = saAmfComponentRegister (handle, &compNameGlobal, NULL); - printf ("register result is %d (should be 1)\n", result); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result && stop == 0); - - printf ("healthchecks stopped for 5 seconds\n"); - sleep (5); - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result); - - saAmfFinalize (handle); - - exit (0); -} diff --git a/openais/test/testamf3.c b/openais/test/testamf3.c deleted file mode 100644 index 1c420ce2..00000000 --- a/openais/test/testamf3.c +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ais_types.h" -#include "saAmf.h" - -SaAmfHandleT handle; - -SaAmfHealthcheckKeyT key0 = { - .key = "key1", - .keyLen = 4 -}; -SaNameT compNameGlobal; - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static int health_flag = -1; -static unsigned int healthcheck_count = 0; -static unsigned int healthcheck_no = 0; - -int stop = 0; -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckKeyT *healthcheckKey) -{ - SaErrorT res; - - healthcheck_no++; - printf ("Healthcheck %u for key '%s' for component ", - healthcheck_no, healthcheckKey->key); - - printSaNameT ((SaNameT *)compName); - printf ("\n"); - res = saAmfResponse (handle, invocation, SA_AIS_OK); - if (res != SA_OK) { - printf ("response res is %d\n", res); - } - if (healthcheck_no == 20) { - res = saAmfHealthcheckStop (handle, &compNameGlobal, &key0); - stop = 1; - } - printf ("done res = %d\n", res); -} - -#ifdef COMPILE_OUT - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); -} - -#endif -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor) -{ - int res; - switch (haState) { - case SA_AMF_HA_ACTIVE: - printf ("CSISetCallback:"); - printf ("for CSI '"); - printSaNameT ((SaNameT *)&csiDescriptor->csiName); - printf ("' for component "); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); - res = saAmfResponse (handle, invocation, SA_AIS_OK); - break; - - case SA_AMF_HA_STANDBY: - printf ("CSISetCallback:"); - printf ("for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("' for component "); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); - saAmfResponse (handle, invocation, SA_AIS_OK); - break; - } -} - -#ifdef COMPILE_OUT -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - saAmfResponse (invocation, SA_OK); -} - -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -void ExternalComponentRestartCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName) -{ - printf ("ExternalComponentRestartCallback\n"); -} - -void ExternalComponentControlCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName, - SaAmfExternalComponentActionT controlAction) -{ - printf ("ExternalComponentControlCallback\n"); -} - -void PendingOperationConfirmCallback ( - const SaInvocationT invocation, - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationConfirmCallback\n"); -} - -void PendingOperationExpiredCallback ( - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationExpiredCallback\n"); -} -#endif - -SaAmfCallbacksT amfCallbacks = { - .saAmfHealthcheckCallback = HealthcheckCallback, - .saAmfCSISetCallback = CSISetCallback, -}; - -SaAmfCallbacksT amfCallbacks; - -SaVersionT version = { 'B', 1, 1 }; - -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) -static struct sched_param sched_param = { - sched_priority: 99 -}; -#endif - -void sigintr_handler (int signum) { - exit (0); -} - -int main (int argc, char **argv) { - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - extern char *optarg; - extern int optind; - int c; - - memset (&compNameGlobal, 0, sizeof (SaNameT)); - signal (SIGINT, sigintr_handler); -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) - result = sched_setscheduler (0, SCHED_RR, &sched_param); - if (result == -1) { - printf ("couldn't set sched priority\n"); - } -#endif - - for (;;){ - c = getopt(argc,argv,"h:n:"); - if (c==-1) { - break; - } - switch (c) { - case 0 : - break; - case 'h': - health_flag = 0; - sscanf (optarg,"%ud" ,&healthcheck_count); - break; - case 'n': - setSanameT (&compNameGlobal, optarg); - break; - default : - break; - } - } - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - FD_ZERO (&read_fds); - saAmfSelectionObjectGet (handle, &select_fd); - FD_SET (select_fd, &read_fds); - if (compNameGlobal.length <= 0) { - setSanameT (&compNameGlobal, "comp_a_in_su_2"); - } - - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - printf ("start %d\n", result); - - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - printf ("start %d\n", result); - result = saAmfComponentRegister (handle, &compNameGlobal, NULL); - printf ("register result is %d (should be 1)\n", result); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result && stop == 0); - - sleep (5); - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result); - - saAmfFinalize (handle); - - exit (0); -} diff --git a/openais/test/testamf4.c b/openais/test/testamf4.c deleted file mode 100644 index b58ebe4a..00000000 --- a/openais/test/testamf4.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ais_types.h" -#include "saAmf.h" - -SaAmfHandleT handle; - -SaAmfHealthcheckKeyT key0 = { - .key = "key1", - .keyLen = 4 -}; -SaNameT compNameGlobal; - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static int health_flag = -1; -static unsigned int healthcheck_count = 0; -static unsigned int healthcheck_no = 0; - -int stop = 0; -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckKeyT *healthcheckKey) -{ - SaErrorT res; - - healthcheck_no++; - printf ("Healthcheck %u for key '%s' for component ", - healthcheck_no, healthcheckKey->key); - - printSaNameT ((SaNameT *)compName); - printf ("\n"); - res = saAmfResponse (handle, invocation, SA_AIS_OK); - if (res != SA_OK) { - printf ("response res is %d\n", res); - } - if (healthcheck_no == 20) { - res = saAmfHealthcheckStop (handle, &compNameGlobal, &key0); - stop = 1; - } - printf ("done res = %d\n", res); -} - -#ifdef COMPILE_OUT - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); -} - -#endif -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor) -{ - int res; - switch (haState) { - case SA_AMF_HA_ACTIVE: - printf ("CSISetCallback:"); - printf ("for CSI '"); - printSaNameT ((SaNameT *)&csiDescriptor->csiName); - printf ("' for component "); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); - res = saAmfResponse (handle, invocation, SA_AIS_OK); - break; - - case SA_AMF_HA_STANDBY: - printf ("CSISetCallback:"); - printf ("for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("' for component "); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); - saAmfResponse (handle, invocation, SA_AIS_OK); - break; - } -} - -#ifdef COMPILE_OUT -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - saAmfResponse (invocation, SA_OK); -} - -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -void ExternalComponentRestartCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName) -{ - printf ("ExternalComponentRestartCallback\n"); -} - -void ExternalComponentControlCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName, - SaAmfExternalComponentActionT controlAction) -{ - printf ("ExternalComponentControlCallback\n"); -} - -void PendingOperationConfirmCallback ( - const SaInvocationT invocation, - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationConfirmCallback\n"); -} - -void PendingOperationExpiredCallback ( - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationExpiredCallback\n"); -} -#endif - -SaAmfCallbacksT amfCallbacks = { - .saAmfHealthcheckCallback = HealthcheckCallback, - .saAmfCSISetCallback = CSISetCallback, -}; - -SaAmfCallbacksT amfCallbacks; - -SaVersionT version = { 'B', 1, 1 }; - -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) -static struct sched_param sched_param = { - sched_priority: 99 -}; -#endif - -void sigintr_handler (int signum) { - exit (0); -} - -int main (int argc, char **argv) { - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - extern char *optarg; - extern int optind; - int c; - - memset (&compNameGlobal, 0, sizeof (SaNameT)); - signal (SIGINT, sigintr_handler); -#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)) - result = sched_setscheduler (0, SCHED_RR, &sched_param); - if (result == -1) { - printf ("couldn't set sched priority\n"); - } -#endif - - for (;;){ - c = getopt(argc,argv,"h:n:"); - if (c==-1) { - break; - } - switch (c) { - case 0 : - break; - case 'h': - health_flag = 0; - sscanf (optarg,"%ud" ,&healthcheck_count); - break; - case 'n': - setSanameT (&compNameGlobal, optarg); - break; - default : - break; - } - } - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - FD_ZERO (&read_fds); - saAmfSelectionObjectGet (handle, &select_fd); - FD_SET (select_fd, &read_fds); - if (compNameGlobal.length <= 0) { - setSanameT (&compNameGlobal, "comp_b_in_su_2"); - } - - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - printf ("start %d\n", result); - - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - printf ("start %d\n", result); - result = saAmfComponentRegister (handle, &compNameGlobal, NULL); - printf ("register result is %d (should be 1)\n", result); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result && stop == 0); - - sleep (5); - result = saAmfHealthcheckStart (handle, - &compNameGlobal, - &key0, - SA_AMF_HEALTHCHECK_AMF_INVOKED, - SA_AMF_COMPONENT_FAILOVER); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result); - - saAmfFinalize (handle); - - exit (0); -} diff --git a/openais/test/testamf5.c b/openais/test/testamf5.c deleted file mode 100644 index 27e141ad..00000000 --- a/openais/test/testamf5.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ais_types.h" -#include "saAmf.h" - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static int health_flag = -1; -static unsigned int healthcheck_count = 0; -static unsigned int healthcheck_no = 0; - -#ifdef COMPILE_OUT -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckT checkType) -{ - SaErrorT res; - - healthcheck_no ++; - if (health_flag == -1 || healthcheck_no%healthcheck_count == 0) { - printf ("%u HealthcheckCallback have occured for component: ",healthcheck_no); - printSaNameT ((SaNameT *)compName); - printf ("\n"); - } - res = saAmfResponse (invocation, SA_OK); - if (res != SA_OK) { - printf ("response res is %d\n", res); - } -} - -void ReadinessStateSetCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfReadinessStateT readinessState) -{ - switch (readinessState) { - case SA_AMF_IN_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_OUT_OF_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_STOPPING: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_STOPPING.\n"); - saAmfStoppingComplete (invocation, SA_OK); - break; - } -} - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); -} - -#endif -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor) -{ - switch (haState) { - case SA_AMF_HA_ACTIVE: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)&csiDescriptor->csiName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); -// saAmfResponse (invocation, SA_OK); - break; - - case SA_AMF_HA_STANDBY: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); -// saAmfResponse (invocation, SA_OK); - break; - } -} - -#ifdef COMPILE_OUT -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - saAmfResponse (invocation, SA_OK); -} - -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -void ExternalComponentRestartCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName) -{ - printf ("ExternalComponentRestartCallback\n"); -} - -void ExternalComponentControlCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName, - SaAmfExternalComponentActionT controlAction) -{ - printf ("ExternalComponentControlCallback\n"); -} - -void PendingOperationConfirmCallback ( - const SaInvocationT invocation, - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationConfirmCallback\n"); -} - -void PendingOperationExpiredCallback ( - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationExpiredCallback\n"); -} -#endif - -SaAmfCallbacksT amfCallbacks = { - .saAmfCSISetCallback = CSISetCallback, -}; - -SaAmfCallbacksT amfCallbacks; - -SaVersionT version = { 'B', 1, 1 }; - -static struct sched_param sched_param = { - sched_priority: 99 -}; - -void sigintr_handler (int signum) { - exit (0); -} - - -int main (int argc, char **argv) { - SaAmfHandleT handle; - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - SaNameT compName; - extern char *optarg; - extern int optind; - int c; - - memset (&compName, 0, sizeof (SaNameT)); - signal (SIGINT, sigintr_handler); - result = sched_setscheduler (0, SCHED_RR, &sched_param); - if (result == -1) { - printf ("couldn't set sched priority\n"); - } - - for (;;){ - c = getopt(argc,argv,"h:n:"); - if (c==-1) { - break; - } - switch (c) { - case 0 : - break; - case 'h': - health_flag = 0; - sscanf (optarg,"%ud" ,&healthcheck_count); - break; - case 'n': - setSanameT (&compName, optarg); - break; - default : - break; - } - } - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - FD_ZERO (&read_fds); - saAmfSelectionObjectGet (handle, &select_fd); - FD_SET (select_fd, &read_fds); - if (compName.length <= 0) { - setSanameT (&compName, "comp_a_in_su_3"); - } - - result = saAmfComponentRegister (handle, &compName, NULL); - printf ("register result is %d (should be 1)\n", result); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result); - - saAmfFinalize (handle); - - exit (0); -} diff --git a/openais/test/testamf6.c b/openais/test/testamf6.c deleted file mode 100644 index 9bc89ddb..00000000 --- a/openais/test/testamf6.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ais_types.h" -#include "saAmf.h" - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -static int health_flag = -1; -static unsigned int healthcheck_count = 0; -static unsigned int healthcheck_no = 0; - -#ifdef COMPILE_OUT -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckT checkType) -{ - SaErrorT res; - - healthcheck_no ++; - if (health_flag == -1 || healthcheck_no%healthcheck_count == 0) { - printf ("%u HealthcheckCallback have occured for component: ",healthcheck_no); - printSaNameT ((SaNameT *)compName); - printf ("\n"); - } - res = saAmfResponse (invocation, SA_OK); - if (res != SA_OK) { - printf ("response res is %d\n", res); - } -} - -void ReadinessStateSetCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfReadinessStateT readinessState) -{ - switch (readinessState) { - case SA_AMF_IN_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_OUT_OF_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_STOPPING: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_STOPPING.\n"); - saAmfStoppingComplete (invocation, SA_OK); - break; - } -} - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); -} - -#endif -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - SaAmfHAStateT haState, - SaAmfCSIDescriptorT *csiDescriptor) -{ - switch (haState) { - case SA_AMF_HA_ACTIVE: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)&csiDescriptor->csiName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); -// saAmfResponse (invocation, SA_OK); - break; - - case SA_AMF_HA_STANDBY: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); -// saAmfResponse (invocation, SA_OK); - break; - } -} - -#ifdef COMPILE_OUT -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - saAmfResponse (invocation, SA_OK); -} - -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -void ExternalComponentRestartCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName) -{ - printf ("ExternalComponentRestartCallback\n"); -} - -void ExternalComponentControlCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName, - SaAmfExternalComponentActionT controlAction) -{ - printf ("ExternalComponentControlCallback\n"); -} - -void PendingOperationConfirmCallback ( - const SaInvocationT invocation, - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationConfirmCallback\n"); -} - -void PendingOperationExpiredCallback ( - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationExpiredCallback\n"); -} -#endif - -SaAmfCallbacksT amfCallbacks = { - .saAmfCSISetCallback = CSISetCallback, -}; - -SaAmfCallbacksT amfCallbacks; - -SaVersionT version = { 'B', 1, 1 }; - -static struct sched_param sched_param = { - sched_priority: 99 -}; - -void sigintr_handler (int signum) { - exit (0); -} - - -int main (int argc, char **argv) { - SaAmfHandleT handle; - int result; - SaSelectionObjectT select_fd; - fd_set read_fds; - SaNameT compName; - extern char *optarg; - extern int optind; - int c; - - memset (&compName, 0, sizeof (SaNameT)); - signal (SIGINT, sigintr_handler); - result = sched_setscheduler (0, SCHED_RR, &sched_param); - if (result == -1) { - printf ("couldn't set sched priority\n"); - } - - for (;;){ - c = getopt(argc,argv,"h:n:"); - if (c==-1) { - break; - } - switch (c) { - case 0 : - break; - case 'h': - health_flag = 0; - sscanf (optarg,"%ud" ,&healthcheck_count); - break; - case 'n': - setSanameT (&compName, optarg); - break; - default : - break; - } - } - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - FD_ZERO (&read_fds); - saAmfSelectionObjectGet (handle, &select_fd); - FD_SET (select_fd, &read_fds); - if (compName.length <= 0) { - setSanameT (&compName, "comp_b_in_su_3"); - } - - result = saAmfComponentRegister (handle, &compName, NULL); - printf ("register result is %d (should be 1)\n", result); - - do { - select (select_fd + 1, &read_fds, 0, 0, 0); - saAmfDispatch (handle, SA_DISPATCH_ALL); - } while (result); - - saAmfFinalize (handle); - - exit (0); -} diff --git a/openais/test/testamfth.c b/openais/test/testamfth.c deleted file mode 100644 index 7d0843fe..00000000 --- a/openais/test/testamfth.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ais_types.h" -#include "ais_amf.h" -#include "saClm.h" - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void setSanameT (SaNameT *name, char *str) { - name->length = strlen (str); - memcpy (name->value, str, name->length); -} - -int healthcheck_count = 0; -void HealthcheckCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfHealthcheckT checkType) -{ - -// if (healthcheck_count++ % 20 == 19) { - printf ("20 HealthcheckCallback have occured for component: "); - printSaNameT ((SaNameT *)compName); - printf ("\n"); -// } - saAmfResponse (invocation, SA_OK); - -} - -void ReadinessStateSetCallback (SaInvocationT invocation, - const SaNameT *compName, - SaAmfReadinessStateT readinessState) -{ - switch (readinessState) { - case SA_AMF_IN_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_OUT_OF_SERVICE: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_STOPPING: - printf ("ReadinessStateSetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' requested to enter operational state SA_AMF_STOPPING.\n"); - saAmfStoppingComplete (invocation, SA_OK); - break; - } -} - -void ComponentTerminateCallback ( - SaInvocationT invocation, - const SaNameT *compName) -{ - printf ("ComponentTerminateCallback\n"); -} - -void CSISetCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - SaAmfCSIFlagsT csiFlags, - SaAmfHAStateT *haState, - SaNameT *activeCompName, - SaAmfCSITransitionDescriptorT transitionDescriptor) -{ - switch (*haState) { - case SA_AMF_ACTIVE: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_ACTIVE.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_STANDBY: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_STANDBY.\n"); - saAmfResponse (invocation, SA_OK); - break; - case SA_AMF_QUIESCED: - printf ("CSISetCallback: '"); - printSaNameT ((SaNameT *)compName); - printf ("' for CSI '"); - printSaNameT ((SaNameT *)compName); - printf ("'"); - printf (" requested to enter hastate SA_AMF_QUIESCED.\n"); - saAmfResponse (invocation, SA_OK); - break; - } -} - -void CSIRemoveCallback ( - SaInvocationT invocation, - const SaNameT *compName, - const SaNameT *csiName, - const SaAmfCSIFlagsT *csiFlags) -{ - printf ("CSIRemoveCallback for component '"); - printSaNameT ((SaNameT *)compName); - printf ("' in CSI '"); - printSaNameT ((SaNameT *)csiName); - printf ("'\n"); - saAmfResponse (invocation, SA_OK); -} - -void ProtectionGroupTrackCallback ( - const SaNameT *csiName, - SaAmfProtectionGroupNotificationT *notificationBuffer, - SaUint32T numberOfItems, - SaUint32T numberOfMembers, - SaErrorT error) -{ - int i; - - printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers); - printf ("buffer is %p\n", notificationBuffer); - for (i = 0; i < numberOfItems; i++) { - printf ("component name"); - printSaNameT (¬ificationBuffer[i].member.compName); - printf ("\n"); - printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState); - printf ("\thastate %d\n", notificationBuffer[i].member.haState); - printf ("\tchange is %d\n", notificationBuffer[i].change); - - } -} - -void ExternalComponentRestartCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName) -{ - printf ("ExternalComponentRestartCallback\n"); -} - -void ExternalComponentControlCallback ( - const SaInvocationT invocation, - const SaNameT *externalCompName, - SaAmfExternalComponentActionT controlAction) -{ - printf ("ExternalComponentControlCallback\n"); -} - -void PendingOperationConfirmCallback ( - const SaInvocationT invocation, - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationConfirmCallback\n"); -} - -void PendingOperationExpiredCallback ( - const SaNameT *compName, - SaAmfPendingOperationFlagsT pendingOperationFlags) -{ - printf ("PendingOperationExpiredCallback\n"); -} - -SaAmfCallbacksT amfCallbacks = { - HealthcheckCallback, - ReadinessStateSetCallback, - ComponentTerminateCallback, - CSISetCallback, - CSIRemoveCallback, - ProtectionGroupTrackCallback, - ExternalComponentRestartCallback, - ExternalComponentControlCallback, - PendingOperationConfirmCallback, - PendingOperationExpiredCallback -}; - -SaVersionT version = { 'A', 1, 1 }; - -void *th_dispatch (void *arg) -{ - SaErrorT result; - SaAmfHandleT *handle = (SaAmfHandleT *)arg; - - printf ("THREAD DISPATCH starting.\n"); - result = saAmfDispatch (handle, SA_DISPATCH_BLOCKING); - printf ("THREAD DISPATCH return result is %d\n", result); - return (0); -} - -int main (void) { - SaAmfHandleT handle; - int result; - SaNameT compName; - pthread_t dispatch_thread; - pthread_attr_t dispatch_thread_attribute; - - result = saAmfInitialize (&handle, &amfCallbacks, &version); - if (result != SA_OK) { - printf ("initialize result is %d\n", result); - exit (1); - } - - setSanameT (&compName, "comp_b_in_su_y"); - - result = saAmfComponentRegister (&handle, &compName, NULL); - printf ("register result is %d (should be 1)\n", result); - - pthread_attr_init (&dispatch_thread_attribute); - pthread_attr_setschedpolicy (&dispatch_thread_attribute, SCHED_FIFO); -// pthread_attr_setschedparam (&dispatch_thread_attribute, 99); - pthread_create (&dispatch_thread, NULL, th_dispatch, &handle); - - sleep (5); - -printf ("Finalizing handle\n"); - - saAmfComponentUnregister (&handle, &compName, NULL); - - saAmfFinalize (&handle); - -printf ("Handle Finalized\n"); - sleep (1); /* this sleep isn't really necessary */ - result = saAmfInitialize (&handle, &amfCallbacks, &version); - result = saAmfComponentRegister (&handle, &compName, NULL); - pthread_create (&dispatch_thread, NULL, th_dispatch, &handle); - sleep (10); -// saAmfFinalize (&handle); - - exit (0); -} diff --git a/openais/test/testckpt.c b/openais/test/testckpt.c deleted file mode 100644 index 143bd477..00000000 --- a/openais/test/testckpt.c +++ /dev/null @@ -1,571 +0,0 @@ -#define _BSD_SOURCE -/* - * Copyright (c) 2002-2004 MontaVista Software, Inc. - * Copyright (c) 2006-2007 Red Hat, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@sdake.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saCkpt.h" -#include "sa_error.h" - -#ifdef OPENAIS_SOLARIS -#define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ - } while (0) -#endif - -#define SECONDS_TO_EXPIRE 5 - -int ckptinv; -SaInvocationT open_invocation = 16; -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -SaVersionT version = { 'B', 1, 1 }; - -SaNameT defaultCheckpointName = { 8, "defaults" }; - -SaNameT sectionsCheckpointName = { 8, "sections" }; - -SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = { - .creationFlags = SA_CKPT_WR_ALL_REPLICAS, - .checkpointSize = 100000, - .retentionDuration = 5000000000LL, - .maxSections = 1, - .maxSectionSize = 200000, - .maxSectionIdSize = 20 -}; - -SaCkptSectionIdT sectionId1 = { - 13, - (SaUint8T *) "section ID #1" -}; - -SaCkptSectionIdT sectionId2 = { - 13, - (SaUint8T *) "section ID #2" -}; - -SaCkptSectionCreationAttributesT sectionCreationAttributes1 = { - §ionId1, - SA_TIME_END -}; - -SaCkptSectionCreationAttributesT sectionCreationAttributes2 = { - §ionId2, - SA_TIME_END -}; - -char readBuffer1[1025]; - -char readBuffer2[1025]; - -char default_read_buffer[1025]; - -SaCkptIOVectorElementT ReadVectorElements[] = { - { - { - 13, - (SaUint8T *) "section ID #1" - }, - readBuffer1, - sizeof (readBuffer1), - 0, - 0 - }, - { - { - 13, - (SaUint8T *) "section ID #2" - }, - readBuffer2, - sizeof (readBuffer2), - 0, - 0 - } -}; - -SaCkptIOVectorElementT default_read_vector[] = { - { - SA_CKPT_DEFAULT_SECTION_ID, - default_read_buffer, /*"written data #1, this should extend past end of old section data", */ - sizeof(default_read_buffer), /*sizeof ("data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - } -}; - - -#define DATASIZE 127000 -char data1[DATASIZE]; -char data2[DATASIZE]; -char default_write_data[56]; -SaCkptIOVectorElementT WriteVectorElements[] = { - { - { - 13, - (SaUint8T *) "section ID #1" - }, - data1, /*"written data #1, this should extend past end of old section data", */ - DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - }, - { - { - 13, - (SaUint8T *) "section ID #2", - }, - data2, /*"written data #2, this should extend past end of old section data" */ - DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */ - 0, //3, - 0 - } -}; - -SaCkptIOVectorElementT default_write_vector[] = { - { - SA_CKPT_DEFAULT_SECTION_ID, - default_write_data, /*"written data #1, this should extend past end of old section data", */ - 56, /*sizeof ("data #1, this should extend past end of old section data") + 1, */ - 0, //5, - 0 - } -}; - -SaCkptCheckpointHandleT checkpointHandle; - -void OpenCallBack ( - SaInvocationT invocation, - const SaCkptCheckpointHandleT chckpointHandle, - SaAisErrorT error) { - - printf ("%s: This is a call back for open for invocation = %d\n", - get_test_output (error, SA_AIS_OK), (int)invocation); - - checkpointHandle = chckpointHandle; - -} - -SaCkptCallbacksT callbacks = { - &OpenCallBack, - 0 -}; - -int main (void) { - SaCkptHandleT ckptHandle; - SaCkptCheckpointHandleT checkpointHandle2; - SaCkptCheckpointHandleT checkpointHandleRead; - SaCkptCheckpointDescriptorT checkpointStatus; - SaCkptSectionIterationHandleT sectionIterator; - SaCkptSectionDescriptorT sectionDescriptor; - SaUint32T erroroneousVectorIndex = 0; - SaAisErrorT error; - struct timeval tv_start; - struct timeval tv_end; - struct timeval tv_elapsed; - SaSelectionObjectT sel_fd; - fd_set read_set; - int i; - - error = saCkptInitialize (&ckptHandle, &callbacks, &version); - printf ("%s: checkpoint initialize\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointOpenAsync (ckptHandle, - open_invocation, - &defaultCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE); - printf ("%s: initial asynchronous open of checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSelectionObjectGet (ckptHandle, &sel_fd); - - printf ("%s: Retrieve selection object %llu\n", - get_test_output (error, SA_AIS_OK), (unsigned long long)sel_fd); - - FD_SET (sel_fd, &read_set); - select (sel_fd + 1, &read_set, 0, 0, 0); - - error = saCkptDispatch (ckptHandle, SA_DISPATCH_ALL); - - printf ("%s: Dispatch response for open async of checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointClose (checkpointHandle); - - printf ("%s: Closing checkpoint\n", get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointOpen (ckptHandle, - &defaultCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle); - printf ("%s: initial open of checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointRead (checkpointHandle, - default_read_vector, - 1, - &erroroneousVectorIndex); - printf ("%s: Reading default checkpoint section before update\n", - get_test_output (error, SA_AIS_OK)); - printf (" default_read_buffer:'%s'\n", default_read_buffer); - - memset (default_read_buffer, 0, sizeof (default_read_buffer)); - memcpy(default_write_data, - "This is an update to the default section date, update#1", 56); - error = saCkptCheckpointWrite (checkpointHandle, - default_write_vector, - 1, - &erroroneousVectorIndex); - - printf ("%s: Writing default checkpoint section with data '%s' \n", - get_test_output (error, SA_AIS_OK), default_write_data); - - error = saCkptCheckpointRead (checkpointHandle, - default_read_vector, - 1, - &erroroneousVectorIndex); - - printf ("%s: Reading default checkpoint section \n", - get_test_output (error, SA_AIS_OK)); - - printf (" default_read_buffer:'%s'\n", default_read_buffer); - - error = saCkptCheckpointClose (checkpointHandle); - - checkpointCreationAttributes.maxSections = 5; - error = saCkptCheckpointOpen (ckptHandle, - §ionsCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle); - - printf ("%s: checkpoint create writeable\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - - printf ("%s: checkpoint section create\n", - get_test_output (error, SA_AIS_OK)); - - gettimeofday (&tv_start, 0); - sectionCreationAttributes1.expirationTime = - (((unsigned long long)(tv_start.tv_sec) + SECONDS_TO_EXPIRE) * - 1000000000ULL) + - ((unsigned long long)(tv_start.tv_usec) * 1000ULL); - - error = saCkptSectionExpirationTimeSet (checkpointHandle, - §ionId1, - sectionCreationAttributes1.expirationTime); - printf ("%s: checkpoint section expiration set\n", - get_test_output (error, SA_AIS_OK)); - - printf ("Please wait, testing expiry of checkpoint sections.\n"); - do { - error = saCkptCheckpointRead (checkpointHandle, - ReadVectorElements, - 1, - &erroroneousVectorIndex); -sleep (1); - } while (error != SA_AIS_ERR_NOT_EXIST); - gettimeofday (&tv_end, NULL); - - /* - * avoid div by zero errors - */ - if (tv_elapsed.tv_usec == 0) { - tv_elapsed.tv_usec = 1; - } - timersub (&tv_end, &tv_start, &tv_elapsed); - printf ("Elapsed Time to expiry is %ld & %ld usec (should be about %d seconds)\n", - tv_elapsed.tv_sec, - (long) tv_elapsed.tv_usec, - SECONDS_TO_EXPIRE); - - error = saCkptCheckpointRetentionDurationSet (checkpointHandle, - 5000000000LL); - printf ("%s: RetentionDurationSet\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes2, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - - printf ("%s: Section creation\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointUnlink (ckptHandle, §ionsCheckpointName); - printf ("%s: Unlinking checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointOpen (ckptHandle, - §ionsCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle2); - printf ("%s: Opening unlinked checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointClose (checkpointHandle); - printf ("%s: Closing checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointOpen (ckptHandle, - §ionsCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ, - 0, - &checkpointHandleRead); - - printf ("%s: Open checkpoint read only\n", - get_test_output (error, SA_AIS_OK)); - - - error = saCkptCheckpointOpen (ckptHandle, - §ionsCheckpointName, - &checkpointCreationAttributes, - SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, - 0, - &checkpointHandle); - printf ("%s: open after unlink/close\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointRetentionDurationSet (checkpointHandle, - 5000000000LL); - printf ("%s: set checkpoint retention duration\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointStatusGet (checkpointHandle, - &checkpointStatus); - printf ("%s: Get checkpoint status\n", - get_test_output (error, SA_AIS_OK)); - if (error == SA_AIS_OK) { - printf ("Memory used %d in %d sections.\n", (int)checkpointStatus.memoryUsed, - (int)checkpointStatus.numberOfSections); - } - - error = saCkptSectionCreate (checkpointHandleRead, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - printf ("%s: Create checkpoint section on read only checkpoint\n", - get_test_output (error, SA_AIS_ERR_ACCESS)); - - sectionCreationAttributes1.expirationTime = SA_TIME_END; - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - printf ("%s: Create checkpoint section on writeable checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - printf ("%s: Create checkpoint section when one already exists\n", - get_test_output (error, SA_AIS_ERR_EXIST)); - - error = saCkptSectionDelete (checkpointHandle, - §ionId1); - printf ("%s: deleting section handle\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes1, - "Initial Data #0", - strlen ("Initial Data #0") + 1); - printf ("%s: replacing deleted checkpoint section\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes2, - "Initial Data #2", - strlen ("Initial Data #2") + 1); - printf ("%s: creating section 2 for first time\n", - get_test_output (error, SA_AIS_OK)); - error = saCkptSectionCreate (checkpointHandle, - §ionCreationAttributes2, - "Initial Data #2", - strlen ("Initial Data #2") + 1); - printf ("%s: creating section 2 for second time\n", - get_test_output (error, SA_AIS_ERR_EXIST)); - - error = saCkptSectionExpirationTimeSet (checkpointHandle, - §ionId2, - SA_TIME_END); - printf ("%s: Setting expiration time for section 2\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptSectionOverwrite (checkpointHandle, - §ionId1, - "Overwrite Data #1", - strlen ("Overwrite Data #1") + 1); - printf ("%s: overwriting checkpoint section 1\n", - get_test_output (error, SA_AIS_OK)); - - /* - * Test checkpoint read - */ - memset (readBuffer1, 0, sizeof (readBuffer1)); - memset (readBuffer2, 0, sizeof (readBuffer2)); - - error = saCkptCheckpointRead (checkpointHandle, - ReadVectorElements, - 2, - &erroroneousVectorIndex); - printf ("%s: checkpoint read operation\n", - get_test_output (error, SA_AIS_OK)); - printf ("Buffers after checkpoint read\n"); - printf (" buffer #1: '%s'\n", readBuffer1); - printf (" buffer #2: '%s'\n", readBuffer2); - - for (ckptinv = 0; ckptinv < 10; ckptinv++) { - /* - * Test checkpoint write - */ - error = saCkptCheckpointWrite (checkpointHandle, - WriteVectorElements, - 2, - &erroroneousVectorIndex); - if (error != SA_AIS_OK) { - printf ("Writing checkpoint loop %d\n", ckptinv); - printf ("saCkptCheckpointWrite result %d (should be 1)\n", error); - } - } - printf ("%s: Testing checkpoint writes\n", - get_test_output (error, SA_AIS_OK)); - - error = saCkptCheckpointRead (checkpointHandle, - ReadVectorElements, - 2, - &erroroneousVectorIndex); -// printf ("saCkptCheckpointRead result %d (should be 1)\n", error); -// printf ("Buffers after checkpoint write are:\n"); -// printf (" buffer #1: '%s'\n", readBuffer1); -// printf (" buffer #2: '%s'\n", readBuffer2); - - error = saCkptCheckpointStatusGet (checkpointHandle, - &checkpointStatus); - printf ("%s: get checkpoint status\n", - get_test_output (error, SA_AIS_OK)); - if (error == SA_AIS_OK) { - printf ("Memory used %d in %d sections.\n", - (int)checkpointStatus.memoryUsed, - (int)checkpointStatus.numberOfSections); - } - printf ("iterating all sections 5 times\n"); - /* - * iterate all sections 5 times - */ - for (i = 0; i < 5; i++) { - error = saCkptSectionIterationInitialize (checkpointHandle, - SA_CKPT_SECTIONS_ANY, - 0, - §ionIterator); - printf ("%s: initialize section iterator\n", - get_test_output (error, SA_AIS_OK)); - - - /* - * Iterate all sections - */ - do { - printf ("Starting iteration\n"); - error = saCkptSectionIterationNext (sectionIterator, - §ionDescriptor); - if (error == SA_AIS_ERR_NO_SECTIONS) { - printf ("No more sections to iterate\n"); - } else { - printf ("%s: Get next section in iteration\n", - get_test_output (error, SA_AIS_OK)); - } - if (error == SA_AIS_OK) { - printf ("Section '%s' expires %llx size %llu state %x update %llx\n", - sectionDescriptor.sectionId.id, - (unsigned long long)sectionDescriptor.expirationTime, - (unsigned long long)sectionDescriptor.sectionSize, - sectionDescriptor.sectionState, - (unsigned long long)sectionDescriptor.lastUpdate); - } - } while (error == SA_AIS_OK); - - error = saCkptSectionIterationFinalize (sectionIterator); - printf ("%s: Finalize iteration\n", - get_test_output (error, SA_AIS_OK)); - - } - - error = saCkptSelectionObjectGet (ckptHandle, &sel_fd); - - error = saCkptFinalize (ckptHandle); - printf ("%s: Finalize checkpoint\n", - get_test_output (error, SA_AIS_OK)); - - return (0); -} diff --git a/openais/test/testclm.c b/openais/test/testclm.c deleted file mode 100644 index 33ef06bb..00000000 --- a/openais/test/testclm.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006 Sun Microsystems, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saClm.h" - -void printSaClmNodeAddressT (SaClmNodeAddressT *nodeAddress) { - int i; - - printf ("family=%d - address=", nodeAddress->family); - for (i = 0; i < nodeAddress->length; i++) { - printf ("%c", nodeAddress->value[i]); - } -} - -void printSaNameT (SaNameT *name) -{ - int i; - - for (i = 0; i < name->length; i++) { - printf ("%c", name->value[i]); - } -} - -void printSaClmClusterNodeT (char *description, SaClmClusterNodeT *clusterNode) { - printf ("Node Information for %s\n", description); - - printf ("\tnode id is %x\n", (int)clusterNode->nodeId); - - printf ("\tnode address is "); - printSaClmNodeAddressT (&clusterNode->nodeAddress); - printf ("\n"); - - printf ("\tNode name is "); - printSaNameT (&clusterNode->nodeName); - printf ("\n"); - - printf ("\tMember is %d\n", clusterNode->member); - - printf ("\tTimestamp is %llx nanoseconds\n", (unsigned long long)clusterNode->bootTimestamp); -} - -void NodeGetCallback ( - SaInvocationT invocation, - const SaClmClusterNodeT *clusterNode, - SaAisErrorT error) -{ - char buf[128]; - - if (error != SA_AIS_OK) { - printf ("Node for invocation %llu not found (%d)\n", - (unsigned long long)invocation, error); - } else { - sprintf (buf, "NODEGETCALLBACK %llu\n", (unsigned long long)invocation); - printSaClmClusterNodeT (buf, (SaClmClusterNodeT *)clusterNode); - } -} - -void TrackCallback ( - const SaClmClusterNotificationBufferT *notificationBuffer, - SaUint32T numberOfMembers, - SaAisErrorT error) -{ - int i; - -printf ("Track callback\n"); - printf ("Calling track callback %p\n", notificationBuffer); - for (i = 0; i < numberOfMembers; i++) { - switch (notificationBuffer->notification[i].clusterChange) { - case SA_CLM_NODE_NO_CHANGE: - printf ("NODE STATE NO CHANGE.\n"); - break; - case SA_CLM_NODE_JOINED: - printf ("NODE STATE JOINED.\n"); - break; - case SA_CLM_NODE_LEFT: - printf ("NODE STATE LEFT.\n"); - break; - case SA_CLM_NODE_RECONFIGURED: - printf ("NODE STATE RECONFIGURED.\n"); - break; - } - printSaClmClusterNodeT ("TRACKING", - ¬ificationBuffer->notification[i].clusterNode); - } - printf ("Done calling trackCallback\n"); -} - -SaClmCallbacksT callbacks = { - .saClmClusterNodeGetCallback = NodeGetCallback, - .saClmClusterTrackCallback = TrackCallback -}; - -SaVersionT version = { 'B', 1, 1 }; - -void sigintr_handler (int signum) { - exit (0); -} - -int main (void) { - SaClmHandleT handle; - fd_set read_fds; - SaSelectionObjectT select_fd; - int result; - SaClmClusterNotificationT clusterNotification[64]; - SaClmClusterNotificationBufferT clusterNotificationBuffer; - SaClmClusterNodeT clusterNode; - int i; - - clusterNotificationBuffer.notification = clusterNotification; - clusterNotificationBuffer.numberOfItems = 64; - - signal (SIGINT, sigintr_handler); - - result = saClmInitialize (&handle, &callbacks, &version); - if (result != SA_AIS_OK) { - printf ("Could not initialize Cluster Membership API instance error %d\n", result); - exit (1); - } - - result = saClmClusterNodeGet (handle, SA_CLM_LOCAL_NODE_ID, SA_TIME_END, &clusterNode); - - printf ("Result of saClmClusterNodeGet %d\n", result); - - printSaClmClusterNodeT ("saClmClusterNodeGet SA_CLM_LOCAL_NODE_ID result %d", &clusterNode); - - result = saClmClusterNodeGetAsync (handle, 55, SA_CLM_LOCAL_NODE_ID); - printf ("result is %d\n", result); - - result = saClmClusterNodeGetAsync (handle, 60, 0x6201a8c0); - printf ("result is %d\n", result); - - result = saClmClusterNodeGetAsync (handle, 61, 0x6a01a8f0); - printf ("result is %d\n", result); - - result = saClmClusterNodeGetAsync (handle, 59, SA_CLM_LOCAL_NODE_ID); - printf ("result is %d\n", result); - - result = saClmClusterNodeGetAsync (handle, 57, SA_CLM_LOCAL_NODE_ID); - printf ("result is %d\n", result); - - result = saClmClusterTrack (handle, SA_TRACK_CURRENT | SA_TRACK_CHANGES, - &clusterNotificationBuffer); - printf ("track result is %d\n", result); - for (i = 0; i < clusterNotificationBuffer.numberOfItems; i++) { - printSaClmClusterNodeT ("Results from SA_TRACK_CURRENT:", - &clusterNotificationBuffer.notification[i].clusterNode); - } - - saClmSelectionObjectGet (handle, &select_fd); - -printf ("select fd is %llu\n", (unsigned long long)select_fd); - FD_ZERO (&read_fds); -printf ("press the enter key to exit with track stop and finalize.\n"); - do { - FD_SET (select_fd, &read_fds); - FD_SET (STDIN_FILENO, &read_fds); - result = select (select_fd + 1, &read_fds, 0, 0, 0); - if (result == -1) { - perror ("select\n"); - } - if (FD_ISSET (STDIN_FILENO, &read_fds)) { - break; - } -printf ("done with select\n"); - saClmDispatch (handle, SA_DISPATCH_ALL); - } while (result); - - result = saClmClusterTrackStop (handle); - printf ("TrackStop result is %d (should be 1)\n", result); - - result = saClmFinalize (handle); - printf ("Finalize result is %d (should be 1)\n", result); - return (0); -} diff --git a/openais/test/testclm2.c b/openais/test/testclm2.c deleted file mode 100644 index 9c1b2ea9..00000000 --- a/openais/test/testclm2.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright (c) 2005 Ericsson AB - * - * All rights reserved. - * - * Author: Rabbe Fogelholm (rabbe.fogelholm@ericsson.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * testclm2.c - * - * Simple program to test cluster membership on an SA Forum platform. - * The program expects one command-line argument which is "query" - * or "callback". "Query" means that a single saClmClusterTrack call - * is to be made. "Callback" means that callbacks are wanted when - * there are changes in cluster membership. At least a 2-node cluster - * is required to test this program mode. - * - * Tested on platforms: - * Gentoo Linux 2005-08 (build) - * Fedora Core 4 (build and run) - * - * Change history: - * 2005-08-28 Rabbe Fogelholm: - * Initial version - * 2005-08-30 Rabbe Fogelholm: - * Added call to saClmClusterTrackStop() - * Possible to test SA_TRACK_CHANGES_ONLY - * Improved diagnostics - */ - - -#include -#include -#include -#include -#include -#include - -#include - - -#define PGM_NAME "testclm2" - -#define MODE_QUERY 1 -#define MODE_CALLBACK 2 -#define MODE_UNKNOWN -1 - - -SaClmHandleT handle; - -int mode = MODE_UNKNOWN; - - -void interruptAction(); - -void usage(); - -void clusterTrack(const SaClmClusterNotificationBufferT *, SaUint32T, SaAisErrorT); - -int apiCall(char *, SaAisErrorT); - -char *decodeStatus(int); - -void printBoolean(SaBoolT); - -void printName(SaNameT *); - -void printAddress(SaClmNodeAddressT *); - -void printCluster(const SaClmClusterNotificationBufferT *); - -void printDate(SaTimeT); - -char *decodeClusterChange(int); - - -int main(int argc, char *argv[]) -{ - struct sigaction act; - act.sa_handler = interruptAction; - int status; - if ((status = sigaction(SIGINT, &act, NULL)) != 0) - { - printf("sigaction returned: %d\n", status); - } - - if (argc != 2 && argc != 3) - { - usage(); - return 1; - } - - mode = - strcmp(argv[1], "query") == 0 ? MODE_QUERY : - strcmp(argv[1], "callback") == 0 ? MODE_CALLBACK : - MODE_UNKNOWN; - if (mode == MODE_UNKNOWN) - { - usage(); - return 1; - } - - if (mode == MODE_CALLBACK && argc != 3) - { - usage(); - return 1; - } - int trackingMode = - mode == MODE_QUERY ? SA_TRACK_CURRENT : - mode == MODE_CALLBACK && strcmp(argv[2], "full") == 0 ? SA_TRACK_CHANGES : - mode == MODE_CALLBACK && strcmp(argv[2], "delta") == 0 ? SA_TRACK_CHANGES_ONLY : - -1; - if (trackingMode == -1) - { - usage(); - return 1; - } - - SaClmCallbacksT callbacks; - callbacks.saClmClusterNodeGetCallback = NULL; - callbacks.saClmClusterTrackCallback = (SaClmClusterTrackCallbackT)clusterTrack; - - SaVersionT version; - version.releaseCode = 'B'; - version.majorVersion = 1; - version.minorVersion = 0; - - - if (! apiCall("Initialize", saClmInitialize(&handle ,&callbacks, &version))) - return 1; - - printf("AIS version supported: %c.%d.%d\n", - version.releaseCode, version.majorVersion, version.minorVersion); - - if (mode == MODE_QUERY) - { - SaClmClusterNotificationBufferT buffer = {123456789, 123456789, NULL}; - apiCall("ClusterTrack", saClmClusterTrack(handle, trackingMode, &buffer)); - printCluster(&buffer); - free(buffer.notification); - } - - if (mode == MODE_CALLBACK) - { - printf("(type ctrl-C to finish)\n"); - apiCall("ClusterTrack", saClmClusterTrack(handle, trackingMode, NULL)); - while (1) - { - apiCall("Dispatch", saClmDispatch(handle, SA_DISPATCH_ONE)); - printf("sleep 1 sec\n"); - sleep(1); - } - } - - apiCall("Finalize", saClmFinalize(handle)); - return 0; -} - - -void interruptAction() -{ - fprintf(stderr, "SIGINT signal caught\n"); - if (mode == MODE_CALLBACK) - { - apiCall("ClusterTrackStop", saClmClusterTrackStop(handle)); - } - apiCall("Finalize", saClmFinalize(handle)); - exit(0); -} - - -void usage() -{ - fprintf(stderr, "%s: usage is:\n", PGM_NAME); - fprintf(stderr, " membership query Query for membership once\n"); - fprintf(stderr, " membership callback full Callback on membership change, full report\n"); - fprintf(stderr, " membership callback delta Callback on membership change, delta report\n"); -} - - -void clusterTrack( - const SaClmClusterNotificationBufferT *buffer, - SaUint32T numberOfMembers, - SaAisErrorT error) -{ - apiCall("clusterTrack callback", error); - printf("number of members: %d\n\n", numberOfMembers); - printCluster(buffer); -} - - -int apiCall(char *call, SaAisErrorT code) -{ - char *s = decodeStatus(code); - printf("called: %s, status: %s", call, s); - if (strcmp(s, "unknown error code") == 0) - { - printf(": %d\n\n", code); - } - else - { - printf("\n\n"); - } - return code == SA_AIS_OK ? 1 : 0; -} - - -char *decodeStatus(int code) -{ - return - code == SA_AIS_OK ? "successful" : - code == SA_AIS_ERR_LIBRARY ? "error in library, cannot be used anymore" : - code == SA_AIS_ERR_VERSION ? "version incompatibility" : - code == SA_AIS_ERR_INIT ? "callback function has not been supplied" : - code == SA_AIS_ERR_TIMEOUT ? "timeout occurred, call may or may not have succeeded" : - code == SA_AIS_ERR_TRY_AGAIN ? "service cannot be provided now, try later" : - code == SA_AIS_ERR_INVALID_PARAM ? "a parameter is not set correctly" : - code == SA_AIS_ERR_NO_MEMORY ? "out of memory" : - code == SA_AIS_ERR_BAD_HANDLE ? "handle is invalid" : - code == SA_AIS_ERR_BUSY ? "resource already in use" : - code == SA_AIS_ERR_ACCESS ? "access denied" : - code == SA_AIS_ERR_NOT_EXIST ? "entity does not exist" : - code == SA_AIS_ERR_NAME_TOO_LONG ? "name too long" : - code == SA_AIS_ERR_EXIST ? "entity already exists" : - code == SA_AIS_ERR_NO_SPACE ? "buffer space is not sufficient" : - code == SA_AIS_ERR_INTERRUPT ? "request canceled by timeout or other interrupt" : - code == SA_AIS_ERR_NAME_NOT_FOUND ? "name not found" : - code == SA_AIS_ERR_NOT_SUPPORTED ? "requested function is not supported" : - code == SA_AIS_ERR_BAD_OPERATION ? "requested operation is not allowed" : - code == SA_AIS_ERR_FAILED_OPERATION ? "healthcheck unsuccessful, error callback done" : - code == SA_AIS_ERR_NO_RESOURCES ? "insufficient resources other than memory" : - code == SA_AIS_ERR_MESSAGE_ERROR ? "a communication error occurred" : - code == SA_AIS_ERR_QUEUE_FULL ? "destination queue is full" : - code == SA_AIS_ERR_QUEUE_NOT_AVAILABLE ? "destination queue not available" : - code == SA_AIS_ERR_BAD_FLAGS ? "flags are invalid" : - code == SA_AIS_ERR_TOO_BIG ? "value larger than maximum permitted" : - code == SA_AIS_ERR_NO_SECTIONS ? "no sections matching spec in SectionIteratorInitialize call" : - "unknown error code"; -} - - -void printBoolean(SaBoolT b) -{ - printf("%s\n", b ? "true" : "false"); -} - - -void printName(SaNameT *name) -{ - int i; - for (i=0; ilength; i++) printf("%c", name->value[i]); - printf("\n"); -} - - -void printAddress(SaClmNodeAddressT *nodeAddress) -{ - if (nodeAddress->family == SA_CLM_AF_INET6) - { - printf("sorry, cannot decode IPv6 yet\n"); - } - else if (nodeAddress->length == 4) - { - // we may get here due to defect 833, see - // http://www.osdl.org/developer_bugzilla/show_bug.cgi?id=833 for details - printf("%d.%d.%d.%d\n", - nodeAddress->value[0], - nodeAddress->value[1], - nodeAddress->value[2], - nodeAddress->value[3]); - } - else - { - int k; - for (k = 0; k < nodeAddress->length; k++) - { - printf("%c", nodeAddress->value[k]); - } - printf("\n"); - } -} - - -void printCluster(const SaClmClusterNotificationBufferT *buffer) -{ - printf(" view number: %llu\n", (unsigned long long)buffer->viewNumber); - printf(" number of items: %u\n\n", buffer->numberOfItems); - int j; for (j=0; jnumberOfItems; j++) - { - printf(" node index within sequence: %d\n", j); - printf(" cluster node: %u\n", buffer->notification[j].clusterNode.nodeId); - printf(" address: "); printAddress(& buffer->notification[j].clusterNode.nodeAddress); - printf(" name: "); printName(&(buffer->notification[j].clusterNode.nodeName)); - printf(" member: "); printBoolean(buffer->notification[j].clusterNode.member); - printf(" booted: "); printDate(buffer->notification[j].clusterNode.bootTimestamp); - printf(" initial view number: %llu\n", (unsigned long long)buffer->notification[j].clusterNode.initialViewNumber); - printf(" cluster change: %s\n", decodeClusterChange(buffer->notification[j].clusterChange)); - printf("\n"); - } -} - - -void printDate(SaTimeT nanoseconds) -{ - time_t tt = nanoseconds/SA_TIME_ONE_SECOND; - struct tm *decodedTime = localtime(&tt); - - printf("%d-%02d-%02d %02d:%02d:%02d\n", - decodedTime->tm_year + 1900, - decodedTime->tm_mon + 1, - decodedTime->tm_mday, - decodedTime->tm_hour, - decodedTime->tm_min, - decodedTime->tm_sec); -} - - -char *decodeClusterChange(int code) -{ - return - code == SA_CLM_NODE_NO_CHANGE ? "node has not changed" : - code == SA_CLM_NODE_JOINED ? "node has joined the cluster" : - code == SA_CLM_NODE_LEFT ? "node has left the cluster" : - code == SA_CLM_NODE_RECONFIGURED ? "node has been reconfigured" : - "unknown type of node change"; -} diff --git a/openais/test/testevt.c b/openais/test/testevt.c deleted file mode 100644 index 9bf55d17..00000000 --- a/openais/test/testevt.c +++ /dev/null @@ -1,3237 +0,0 @@ -/* - * Copyright (c) 2004-2005 Mark Haverkamp - * Copyright (c) 2004-2005 Open Source Development Lab - * - * 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 - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the Open Source Development Lab nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Test program for event service - * - * test_initialize (); - * Version check in saEvtInitialze() - * - * test_channel(); - * Test basic channel operations. Open/close/subscribe/unsubscribe - * - * test_event(); - * Event operations: allocation, free, setting and getting - * attributes, publishing. - * - * test_multi_channel1(); - * test_multi_channel1(); - * test_multi_channel1(); - * Test events on multiple channels and multiple subscriptions. - * - * test_retention(); - * Test event retention times. - * - * test_unlink_channel(); - * Test event channel unlink. - */ - -#include -#include -#include -#include -#include -#include -#include "saAis.h" -#include "saEvt.h" - -extern int get_sa_error(SaAisErrorT, char *, int); -char result_buf[256]; -int result_buf_len = sizeof(result_buf); -#define TRY_WAIT 2 - - -void testresult (SaAisErrorT result, SaAisErrorT expected, int test_no) -{ - if (result == expected) { - printf ("Test %d passed\n", test_no); - } else { - get_sa_error(result, result_buf, result_buf_len); - printf ("ERROR: Test %d FAILED (expected %d got %s)\n", - test_no, expected, result_buf); - } -} - -SaVersionT version1 = { 'B', 0x01, 0x01 }; -SaVersionT version2 = { 'A', 0x01, 0x01 }; -SaVersionT version3 = { 'B', 0x02, 0x01 }; -SaVersionT version4 = { 'B', 0x01, 0xff }; -SaVersionT version5 = { 'C', 0xff, 0xff }; - -struct version_test { - SaVersionT *version; - SaAisErrorT result; -}; - -struct version_test versions[] = { - { &version1, SA_AIS_OK }, - { &version2, SA_AIS_ERR_VERSION }, - { &version3, SA_AIS_ERR_VERSION }, - { &version4, SA_AIS_OK}, - { &version5, SA_AIS_ERR_VERSION}, - { 0, SA_AIS_ERR_INVALID_PARAM} -}; - -int version_size = sizeof(versions) / sizeof(struct version_test); - -void open_callback(SaInvocationT invocation, - SaEvtChannelHandleT channelHandle, - SaAisErrorT error); -void event_callback(SaEvtSubscriptionIdT subscriptionId, - const SaEvtEventHandleT eventHandle, - const SaSizeT eventDataSize); - -SaEvtCallbacksT callbacks = { - open_callback, - event_callback -}; - -char channel[256] = "TESTEVT_CHANNEL"; -char unlink_channel[256] = "TESTEVT_UNLINK_CHANNEL"; -SaEvtSubscriptionIdT subscription_id = 0xabcdef; -SaInvocationT open_invocation = 0xaa55cc33; -unsigned long long test_ret_time = 30000000000ULL; /* 30 seconds */ - - -/* - * event data - */ - -long *exp_data; -#define DATA_SIZE 2048 /* default data size */ -#define LCOUNT DATA_SIZE/sizeof(long) - -/* - * Test saEvtInitialize and version checking. - */ -void test_initialize (void) { - SaAisErrorT result; - SaEvtHandleT handle; - int i; - - - /* - * version check tests - */ - printf("Test lib version check on initlialize\n"); - for (i=0; i < version_size; i++) { - do { - result = saEvtInitialize (&handle, 0, versions[i].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - testresult (result, versions[i].result, i); - if (result == SA_AIS_OK) { - saEvtFinalize(handle); - } - } - - -} - -#define _patt1 "Filter pattern 1" -#define patt1 (SaUint8T *) _patt1 -#define patt1_size sizeof(_patt1) - -#define _patt2 "Filter pattern 2" -#define patt2 (SaUint8T *) _patt2 -#define patt2_size sizeof(_patt2) - -#define _patt3 "Filter pattern 3" -#define patt3 (SaUint8T *) _patt3 -#define patt3_size sizeof(_patt3) - -#define _patt4 "Filter pattern 4" -#define patt4 (SaUint8T *) _patt4 -#define patt4_size sizeof(_patt4) - - -SaEvtEventFilterT filters[] = { - {SA_EVT_PREFIX_FILTER, {patt1_size, patt1_size, patt1}}, - {SA_EVT_SUFFIX_FILTER, {patt2_size, patt2_size, patt2}}, - {SA_EVT_EXACT_FILTER, {patt3_size, patt3_size, patt3}}, - {SA_EVT_PASS_ALL_FILTER, {patt4_size, patt4_size, patt4}} -}; - -SaEvtEventFilterArrayT subscribe_filters = { - sizeof(filters)/sizeof(SaEvtEventFilterT), - filters -}; - -/* - * Process the open callback - */ -void open_callback(SaInvocationT invocation, - SaEvtChannelHandleT channel_handle, - SaAisErrorT error) -{ - SaAisErrorT result; - - printf(" Received open channel callback\n"); - if (error != SA_AIS_OK) { - get_sa_error(error, result_buf, result_buf_len); - printf("ERROR: async channel open result: %s\n", result_buf); - return; - } - if (invocation != open_invocation) { - printf("ERROR: Unexpected invocation value: e 0x%llx, a 0x%llx\n", - (long long)open_invocation, (long long)invocation); - } - - printf(" Close async channel:\n"); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result: %s\n", result_buf); - return; - } -} -/* - * Test channel operations. - * 1. Open a channel. - * 2. Close a channel. - * 3. Channel subscription. - * 4. Channel unsubscribe - * 5. unsubscribe/finalize with no channel close. - * 6. Multiple subscriptions. - * 7. Duplicate subscription ID. - * 8. unsubscribe non-exsistent subscription ID. - * 9. Open a channel async. - * - */ -void -test_channel() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - SaAisErrorT result; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 5000; - - flags = SA_EVT_CHANNEL_PUBLISHER | - SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - /* - * Channel open/close test - */ - printf("Test Channel operations:\n"); - - printf(" Channel open:\n"); - do { - result = saEvtInitialize (&handle, - &callbacks, versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - return; - } - - printf(" Channel close:\n"); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result: %s\n", result_buf); - return; - } - - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - return; - } - - /* - * Test channel subscribe - */ - printf(" Channel subscribe:\n"); - do { - result = saEvtInitialize (&handle, &callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - - printf(" Channel unsubscribe:\n"); - - do { - result = saEvtEventUnsubscribe(channel_handle, subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event unsubscribe result: %s\n", result_buf); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - - /* - * Test channel subscribe with no close - */ - printf(" Channel subscribe with no close at end:\n"); - do { - result = saEvtInitialize (&handle, &callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - result = saEvtFinalize(handle); - return; - } - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - result = saEvtChannelClose(channel_handle); - } - - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize failed\n"); - return; - } - - /* - * Test multiple subscriptions - */ - printf(" Multiple subscriptions\n"); - do { - result = saEvtInitialize (&handle, &callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: First event subscribe result: %s\n", result_buf); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id+1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: second event subscribe result: %s\n", result_buf); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - /* - * Test duplicate subscription - */ - printf(" Duplicate subscription\n"); - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_ERR_EXIST) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: First event subscribe result: %s\n", result_buf); - result = saEvtChannelClose(channel_handle); - result = saEvtFinalize(handle); - return; - } - - /* - * Test unsubscribe non-existent sub_id - */ - printf(" Unsubscribe non-existent sub_id\n"); - - do { - result = saEvtEventUnsubscribe(channel_handle, - subscription_id+2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_NOT_EXIST) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event unsubscribe result: %s\n", result_buf); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - do { - result = saEvtEventUnsubscribe(channel_handle, subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: first event unsubscribe result: %s\n", result_buf); - } - do { - result = saEvtEventUnsubscribe(channel_handle, - subscription_id+1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: second event unsubscribe result: %s\n", result_buf); - } - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - - /* - * Test opening a channel async. - */ - printf(" Channel open async:\n"); - do { - result = saEvtInitialize (&handle, &callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - - do { - result = saEvtChannelOpenAsync(handle, open_invocation, - &channel_name, flags); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open async result: %s\n", result_buf); - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - return; - } - /* - * See if we got the open callback - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd <= 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - return; - } - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - return; - } - - - - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - return; - } - - - - printf("Done\n"); - -} - - SaUint8T pat0[100]; - SaUint8T pat1[100]; - SaUint8T pat2[100]; - SaUint8T pat3[100]; - SaUint8T pat4[100]; - SaEvtEventPatternT evt_patts[5] = { - {100, 100, pat0}, - {100, 100, pat1}, - {100, 100, pat2}, - {100, 100, pat3}, - {100, 100, pat4}}; - SaEvtEventPatternArrayT evt_pat_get_array = { 5, 0, evt_patts }; - -SaEvtEventPatternT patterns[] = { - {patt1_size, patt1_size, patt1}, - {patt2_size, patt2_size, patt2}, - {patt3_size, patt3_size, patt3}, - {patt4_size, patt4_size, patt4} -}; -SaNameT test_pub_name = {13, "Test Pub Name"}; -#define TEST_PRIORITY 2 - -SaEvtEventPatternArrayT evt_pat_set_array = { - sizeof(patterns)/sizeof(SaEvtEventPatternT), - sizeof(patterns)/sizeof(SaEvtEventPatternT), - patterns -}; - -char event_data[1000]; -#define EVENT_DATA_SIZE 1000 - -SaEvtEventIdT event_id = 0; -SaUint8T priority; -SaTimeT retention_time = 0ULL; -SaNameT publisher_name = {0, {0}}; -SaSizeT event_data_size = 0; -int expected_pat_count; - -/* - * Test event operations. - * - * 1. Event allocation - * 2. Get event attributes (no pointers). - * 3. Get event attributes with pointers. - * 4. Set/Get event attributes. - * 5. Get event user data no pointer or count - * 6. Get event user data with pointer and no count - * 7. Get event user data with no pointer with a count. - * 8. Get event user data with pointer and count. - * 9. Get event user data woth a short count. - * 10. Free event. - * 11. Publish with no set patterns. - * 12. Publish with set patterns and event user data. - * - */ -void -event_callback(SaEvtSubscriptionIdT my_subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT my_event_data_size) -{ - SaAisErrorT result; - SaUint8T my_priority; - SaTimeT my_retention_time; - SaNameT my_publisher_name = {0, {0}}; - SaTimeT my_publish_time; - SaEvtEventIdT my_event_id; - int i; - long *act_data; - SaSizeT data_size; - - printf(" event_callback called\n"); - if (my_subscription_id != subscription_id) { - printf("ERROR: sub ID: e=%x, a=%x\n", - subscription_id, my_subscription_id); - } - if (my_event_data_size != event_data_size) { - printf("ERROR: event data size e=%llu, a=%llu\n", - (unsigned long long)event_data_size, - (unsigned long long)my_event_data_size); - } - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &my_priority, /* priority */ - &my_retention_time, /* retention time */ - &my_publisher_name, /* publisher name */ - &my_publish_time, /* publish time */ - &my_event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result(2): %s\n", result_buf); - goto evt_free; - } - - if (my_event_id != event_id) { - printf("ERROR: Call back event ID error: e=%llx, a=%llx\n", - (unsigned long long)event_id, (unsigned long long)my_event_id); - } - - if (evt_pat_get_array.patternsNumber != expected_pat_count) { - printf("ERROR: pattern array count not %d: %llu\n", - expected_pat_count, - (unsigned long long)evt_pat_get_array.patternsNumber); - } - - if (expected_pat_count == 0) { - goto evt_free; - } - - for (i = 0; i < evt_pat_get_array.patternsNumber; i++) { - if (evt_pat_get_array.patterns[i].patternSize != - evt_pat_set_array.patterns[i].patternSize) { - printf("ERROR: pattern %d count not equal g=%llu, s=%llu\n", - i, - (unsigned long long)evt_pat_get_array.patterns[i].patternSize, - (unsigned long long)evt_pat_set_array.patterns[i].patternSize); - printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n", - i, - evt_pat_get_array.patterns[i].pattern, - evt_pat_set_array.patterns[i].pattern); - } else { - if (memcmp(evt_pat_get_array.patterns[i].pattern, - evt_pat_set_array.patterns[i].pattern, - evt_pat_get_array.patterns[i].patternSize) != 0){ - printf( - "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n", - i, - evt_pat_get_array.patterns[i].pattern, - evt_pat_set_array.patterns[i].pattern); - } - } - } - - if (priority != my_priority) { - printf("ERROR: priority: e=0x%x a=0x%x\n", - priority, my_priority); - } - if (retention_time != my_retention_time) { - printf("ERROR: retention: e=0x%llx a=0x%llx\n", - (unsigned long long)retention_time, - (unsigned long long)my_retention_time); - } - if (publisher_name.length != my_publisher_name.length) { - printf("ERROR: publisher name length: e=%d, a=%d\n", - publisher_name.length, - my_publisher_name.length); - } else { - if (memcmp(publisher_name.value, my_publisher_name.value, - publisher_name.length) != 0) { - printf("ERROR: publisher name content: e=%s, a=%s\n", - publisher_name.value, - my_publisher_name.value); - } - } - - act_data = malloc(my_event_data_size); - memset(act_data, 0, my_event_data_size); - data_size = my_event_data_size; - do { - result = saEvtEventDataGet(event_handle, act_data, &data_size); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event data get result: %s\n", result_buf); - goto dat_free; - } - if (data_size != event_data_size) { - printf("ERROR: Data size: e=%llu a=%llu\n", - (unsigned long long)event_data_size, - (unsigned long long)data_size); - } - for (i = 0; i < (data_size/sizeof(long)); i++) { - if (act_data[i] != exp_data[i]) { - printf("ERROR: Event Data e=%lx a=%lx at index %d\n", - exp_data[i], act_data[i], i); - break; - } - } - -dat_free: - free(act_data); -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } -} - -void -test_event() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtEventHandleT event_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - - SaTimeT publish_time; - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 5000; - - - - SaAisErrorT result; - - int i; - - flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - - printf("Test Event operations:\n"); - - do { - result = saEvtInitialize (&handle, &callbacks, versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - goto evt_fin; - } - - /* - * Allocate an event - */ - printf(" Event allocation\n"); - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate result: %s\n", result_buf); - goto evt_close; - } - - printf(" Get event attributes(1)\n"); - do { - result = saEvtEventAttributesGet(event_handle, - 0, /* patterns */ - 0, /* priority */ - 0, /* retention time */ - 0, /* publisher name */ - 0, /* publish time */ - 0 /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result(1): %s\n", result_buf); - goto evt_free; - } - - /* - * Get event attributes, this time supply pointers. - * validate the default values. - */ - printf(" Get event attributes(2)\n"); - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &priority, /* priority */ - &retention_time, /* retention time */ - &publisher_name, /* publisher name */ - &publish_time, /* publish time */ - &event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result(2): %s\n", result_buf); - goto evt_free; - } - if (evt_pat_get_array.patternsNumber != 0) { - printf("ERROR: pattern array count not zero: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - } - if (priority != SA_EVT_LOWEST_PRIORITY) { - printf("ERROR: priority not lowest: 0x%x\n", priority); - } - if (retention_time != 0) { - printf("ERROR: retention time not zero: %0llx\n", - (unsigned long long)retention_time); - } - if (publisher_name.length != 0) { - printf("ERROR: publisher name not null: %s\n", publisher_name.value); - } - if (event_id != 0) { - printf("ERROR: event id not zero: 0x%llx\n", - (unsigned long long)event_id); - } - - - /* - * Set some attributes, then read them back - */ - printf(" Set/get event attributes(1)\n"); - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat_set_array, - TEST_PRIORITY, - test_ret_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result(1): %s\n", result_buf); - goto evt_free; - } - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &priority, /* priority */ - &retention_time, /* retention time */ - &publisher_name, /* publisher name */ - &publish_time, /* publish time */ - &event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result(2): %s\n", result_buf); - goto evt_free; - } - if (evt_pat_get_array.patternsNumber != 4) { - printf("ERROR: pattern array count not 4: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - } - for (i = 0; i < evt_pat_get_array.patternsNumber; i++) { - if (evt_pat_get_array.patterns[i].patternSize != - evt_pat_set_array.patterns[i].patternSize) { - printf("ERROR: pattern %d count not equal g=%lld, s=%lld\n", - i, - (unsigned long long)evt_pat_get_array.patterns[i].patternSize, - (unsigned long long)evt_pat_set_array.patterns[i].patternSize); - printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n", - i, - evt_pat_get_array.patterns[i].pattern, - evt_pat_set_array.patterns[i].pattern); - } else { - if (memcmp(evt_pat_get_array.patterns[i].pattern, - evt_pat_set_array.patterns[i].pattern, - evt_pat_get_array.patterns[i].patternSize) != 0){ - printf( - "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n", - i, - evt_pat_get_array.patterns[i].pattern, - evt_pat_set_array.patterns[i].pattern); - } - } - } - - if (priority != TEST_PRIORITY) { - printf("ERROR: priority: e=0x%x a=0x%x\n", - TEST_PRIORITY, priority); - } - if (retention_time != test_ret_time) { - printf("ERROR: retention: e=0x%llx a=0x%llx\n", - (unsigned long long)test_ret_time, - (unsigned long long)retention_time); - } - if (publisher_name.length != test_pub_name.length) { - printf("ERROR: publisher name length: e=%d, a=%d\n", - test_pub_name.length, - publisher_name.length); - } else { - if (memcmp(publisher_name.value, test_pub_name.value, - publisher_name.length) != 0) { - printf("ERROR: publisher name content: e=%s, a=%s\n", - test_pub_name.value, - publisher_name.value); - } - } - - if (event_id != 0) { - printf("ERROR: event id not zero: 0x%llx\n", - (unsigned long long)event_id); - } - - /* - * event user data - */ - event_data_size = 0; - printf(" Get event data(1)\n"); - do { - result = saEvtEventDataGet(event_handle, 0, &event_data_size); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_NO_SPACE) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Get event data(1) result: %s\n", result_buf); - } - printf(" Get event data(2)\n"); - do { - result = saEvtEventDataGet(event_handle, event_data, &event_data_size); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_BAD_HANDLE) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Get event data(2) result: %s\n", result_buf); - } - printf(" Get event data(3)\n"); - event_data_size = EVENT_DATA_SIZE; - do { - result = saEvtEventDataGet(event_handle, 0, &event_data_size); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_NO_SPACE) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Get event data(3) result: %s\n", result_buf); - } - printf(" Get event data(4)\n"); - event_data_size = EVENT_DATA_SIZE; - do { - result = saEvtEventDataGet(event_handle, event_data, - &event_data_size); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_BAD_HANDLE) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Get event data(4) result: %s\n", result_buf); - } - printf(" Get event data(5)\n"); - event_data_size = 1; - do { - result = saEvtEventDataGet(event_handle, event_data, - &event_data_size); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_BAD_HANDLE) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Get event data(5) result: %s\n", result_buf); - } - - printf(" Free event(1)\n"); - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - - /* - * Test publication. - */ - - printf(" Publish with no patterns set\n"); - - event_data_size = 0; - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Channel close result: %s\n", result_buf); - } - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Finalize result: %s\n", result_buf); - } - return; - } - - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate result: %s\n", result_buf); - goto evt_close; - } - - expected_pat_count = 0; - do { - result = saEvtEventPublish(event_handle, 0, 0, &event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result(1): %s\n", result_buf); - goto evt_close; - } - - /* - * See if we got the event - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd <= 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - return; - } - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - return; - } - - - /* - * Publish with pattens - */ - printf(" Publish with patterns set\n"); - - retention_time = 0ULL; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat_set_array, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result(2): %s\n", result_buf); - goto evt_free; - } - - /* - * Generate event data - */ - exp_data = malloc(DATA_SIZE); - for (i = 0; i < LCOUNT; i++) { - exp_data[i] = lrand48(); - } - event_data_size = DATA_SIZE; - expected_pat_count = 4; - - /* - * Send it - */ - do { - result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE, - &event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result(2): %s\n", result_buf); - goto evt_close; - } - - /* - * See if we got the event - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd <= 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - return; - } - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - return; - } - - - - /* - * Test cleanup - */ -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - -evt_close: - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result: %s\n", result_buf); - } -evt_fin: - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - printf("Done\n"); - -} - -SaEvtEventIdT event_id1; -SaEvtEventIdT event_id2; -SaEvtEventIdT event_id3; -SaEvtSubscriptionIdT sub1 = 0x101010; -SaEvtSubscriptionIdT sub2 = 0x202020; -static int call_count = 0; - -/* - * Handle call back for multi-test1 - * Checks event ID with subscription ID to make sure that we - * received an event on the correct subscription. - */ -void -multi_test_callback1(SaEvtSubscriptionIdT my_subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT my_event_data_size) -{ - SaAisErrorT result; - SaUint8T my_priority; - SaTimeT my_retention_time; - SaNameT my_publisher_name = {0, {0}}; - SaTimeT my_publish_time; - SaEvtEventIdT my_event_id; - SaEvtSubscriptionIdT exp_sub_id; - - printf(" multi_test_callback1 called(%d)\n", ++call_count); - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &my_priority, /* priority */ - &my_retention_time, /* retention time */ - &my_publisher_name, /* publisher name */ - &my_publish_time, /* publish time */ - &my_event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result: %s\n", result_buf); - goto evt_free; - } - - if (my_event_id == event_id1) { - exp_sub_id = sub1; - } else if (my_event_id == event_id2) { - exp_sub_id = sub2; - } else if (my_event_id == event_id3) { - printf("ERROR: Received event 3 but not subscribed\n"); - goto evt_free; - } else { - printf("ERROR: Received event %llx but not sent\n", - (unsigned long long)my_event_id); - goto evt_free; - } - - if (my_subscription_id != exp_sub_id) { - printf("ERROR: sub ID: e=%x, a=%x\n", - exp_sub_id, my_subscription_id); - goto evt_free; - } - - if (evt_pat_get_array.patternsNumber != 1) { - printf("ERROR: pattern array count not 1: %lld\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - } - -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } -} - -/* - * Test multiple channel operations - * 1. Test multiple subscriptions on a single channel and receiving - * events. - * 2. Test multiple openings of a single channel and receving events. - * 3. Test opening of multiple channels and receiving events - */ -void -test_multi_channel1() -{ - - SaEvtEventFilterT filt1[1] = { - {SA_EVT_EXACT_FILTER, {8,8, (SaUint8T *) "ChanPat1"}}, - }; - SaEvtEventFilterT filt2[1] = { - {SA_EVT_EXACT_FILTER, {8, 8, (SaUint8T *) "ChanPat2"}}, - }; - - SaEvtEventFilterArrayT sub_filt = { - 1, NULL - }; - - SaEvtEventPatternT pat1 = {8, 8, (SaUint8T *) "ChanPat1"}; - SaEvtEventPatternT pat2 = {8, 8, (SaUint8T *) "ChanPat2"}; - SaEvtEventPatternT pat3 = {8, 8, (SaUint8T *) "ChanPat3"}; - - SaEvtEventPatternArrayT evt_pat = { - 1, 1, NULL - }; - - - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtEventHandleT event_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - SaEvtCallbacksT multi_callbacks = { - 0, - multi_test_callback1 - }; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 5000; - - - - SaAisErrorT result; - - flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - - printf("Test multiple operations:\n"); - - do { - result = saEvtInitialize (&handle, &multi_callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - goto evt_fin; - } - - /* - * Allocate an event - */ - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate result: %s\n", result_buf); - goto evt_close; - } - -/* - * 1. Test multiple subscriptions on a single channel and receiving - * events. - * - * Subscribe twice with two different filters. Then send three events. - * One will match the first filter, the second will match the second - * filter, the third will match none. We will validate that we receive - * two events and that the subscription IDs match what we expect for the - * given pattern. - */ - - sub_filt.filters = filt1; - do { - result = saEvtEventSubscribe(channel_handle, - &sub_filt, - sub1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe(1) result: %s\n", result_buf); - goto evt_free; - } - - sub_filt.filters = filt2; - do { - result = saEvtEventSubscribe(channel_handle, - &sub_filt, - sub2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe(2) result: %s\n", result_buf); - goto evt_free; - } - - - retention_time = 0ULL; - - evt_pat.patterns = &pat1; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result(1): %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE, - &event_id1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result:(1) %s\n", result_buf); - goto evt_close; - } - - evt_pat.patterns = &pat2; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result(2): %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE, - &event_id2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result:(2) %s\n", result_buf); - goto evt_close; - } - - evt_pat.patterns = &pat3; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result(3): %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE, - &event_id3); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result:(3) %s\n", result_buf); - goto evt_close; - } - - /* - * See if we got the event - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - - while(1) { - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd == 0) { - break; - } else if (nfd < 0) { - perror("ERROR: poll error"); - break; - } - - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ALL); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - goto evt_free; - } - } - - - if (call_count != 2) { - printf("ERROR: call back count: e=2, a=%d\n", call_count); - goto evt_free; - } - - /* - * Test cleanup - */ -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - -evt_close: - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result: %s\n", result_buf); - } -evt_fin: - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - printf("Done\n"); - -} - -/* - * Handle call back for multi-test2 - * Counts events received. Makes sure that we get one event from - * each subscription. - * - */ -void -multi_test_callback2(SaEvtSubscriptionIdT my_subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT my_event_data_size) -{ - SaAisErrorT result; - SaUint8T my_priority; - SaTimeT my_retention_time; - SaNameT my_publisher_name = {0, {0}}; - SaTimeT my_publish_time; - SaEvtEventIdT my_event_id; - SaEvtSubscriptionIdT last_sub_id = 0; - - printf(" multi_test_callback2 called(%d)\n", ++call_count); - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &my_priority, /* priority */ - &my_retention_time, /* retention time */ - &my_publisher_name, /* publisher name */ - &my_publish_time, /* publish time */ - &my_event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result: %s\n", result_buf); - goto evt_free; - } - - if (my_event_id != event_id1) { - printf("ERROR: Received wrong event\n"); - goto evt_free; - } - - if (last_sub_id == 0) { - if (my_subscription_id != sub1 && - my_subscription_id != sub2) { - printf("ERROR: Received bad subscription ID\n"); - goto evt_free; - } - last_sub_id = my_subscription_id; - } else { - if (my_subscription_id == last_sub_id) { - printf("ERROR: Received subscription ID twice\n"); - goto evt_free; - } - if (my_subscription_id != sub1 && - my_subscription_id != sub2) { - printf("ERROR: Received bad subscription ID\n"); - goto evt_free; - } - } - - if (evt_pat_get_array.patternsNumber != 1) { - printf("ERROR: pattern array count not 1: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - } - -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } -} - -void -test_multi_channel2() -{ - - SaEvtEventFilterT filt1[1] = { - {SA_EVT_EXACT_FILTER, {8, 8, (SaUint8T *) "ChanPat1"}}, - }; - - SaEvtEventFilterArrayT sub_filt = { - 1, NULL - }; - - SaEvtEventPatternT pat1 = {8, 8, (SaUint8T *) "ChanPat1"}; - - SaEvtEventPatternArrayT evt_pat = { - 1, 1, NULL - }; - - - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtChannelHandleT channel_handle1; - SaEvtEventHandleT event_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - SaEvtCallbacksT multi_callbacks = { - 0, - multi_test_callback2 - }; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 5000; - - - - SaAisErrorT result; - - flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - -/* - * 2. Test multiple openings of a single channel and receving events. - * - * Open and subscribe to a channel twice. When an event is sent, it - * should be delivered twice, once for each open channel. - */ - printf("Test multiple opens/subscribes:\n"); - - do { - result = saEvtInitialize (&handle, &multi_callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(0) result: %s\n", result_buf); - goto evt_fin; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(1) result: %s\n", result_buf); - goto evt_fin; - } - - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate result: %s\n", result_buf); - goto evt_close; - } - sub_filt.filters = filt1; - do { - result = saEvtEventSubscribe(channel_handle, - &sub_filt, - sub1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe(0) result: %s\n", result_buf); - goto evt_free; - } - sub_filt.filters = filt1; - do { - result = saEvtEventSubscribe(channel_handle1, - &sub_filt, - sub2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe(1) result: %s\n", result_buf); - goto evt_free; - } - retention_time = 0ULL; - - evt_pat.patterns = &pat1; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result: %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE, - &event_id1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result: %s\n", result_buf); - goto evt_close; - } - /* - * See if we got the event - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - - call_count = 0; - - while(1) { - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd == 0) { - break; - } else if (nfd < 0) { - perror("ERROR: poll error"); - break; - } - - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ALL); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - goto evt_free; - } - } - - - if (call_count != 2) { - printf("ERROR: call back count: e=2, a=%d\n", call_count); - goto evt_free; - } - - /* - * Test cleanup - */ -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - -evt_close: - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result(0): %s\n", result_buf); - } - do { - result = saEvtChannelClose(channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result(1): %s\n", result_buf); - } -evt_fin: - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - printf("Done\n"); - -} - -/* - * Handle call back for multi-test3 - * Verifies that the event recevied is associated with the correct - * subscription. - * - */ -void -multi_test_callback3(SaEvtSubscriptionIdT my_subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT my_event_data_size) -{ - SaAisErrorT result; - SaUint8T my_priority; - SaTimeT my_retention_time; - SaNameT my_publisher_name = {0, {0}}; - SaTimeT my_publish_time; - SaEvtEventIdT my_event_id; - - printf(" multi_test_callback2 called(%d)\n", ++call_count); - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &my_priority, /* priority */ - &my_retention_time, /* retention time */ - &my_publisher_name, /* publisher name */ - &my_publish_time, /* publish time */ - &my_event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result: %s\n", result_buf); - goto evt_free; - } - - if ((my_subscription_id != sub1) && (my_subscription_id != sub2)) { - printf("ERROR: Received wrong subscription ID %x\n", - my_subscription_id); - printf(" sub1 %x, sub2 %x\n", sub1, sub2); - goto evt_free; - } - - if ((my_event_id != event_id1) && (my_event_id != event_id2)) { - printf("ERROR: Received wrong event ID %llx\n", - (unsigned long long)my_event_id); - printf(" id1 %llx, id2 %llx\n", - (unsigned long long)event_id1, - (unsigned long long)event_id2); - goto evt_free; - } - - if ((my_subscription_id == sub1) && (my_event_id != event_id1)) { - printf("ERROR: Received event on wrong subscription\n"); - goto evt_free; - } - if ((my_subscription_id == sub2) && (my_event_id != event_id2)) { - printf("ERROR: Received event on wrong subscription\n"); - goto evt_free; - } - - if (evt_pat_get_array.patternsNumber != 1) { - printf("ERROR: pattern array count not 1: %llu\n", - (unsigned long long)evt_pat_get_array.patternsNumber); - } - -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } -} - -void -test_multi_channel3() -{ - - SaEvtEventFilterT filt1[1] = { - {SA_EVT_PREFIX_FILTER, {7, 7, (SaUint8T *) "ChanPat"}}, - }; - - SaEvtEventFilterArrayT sub_filt = { - 1, NULL - }; - - SaEvtEventPatternT pat1 = {8, 8, (SaUint8T *) "ChanPat1"}; - SaEvtEventPatternT pat2 = {8, 8, (SaUint8T *) "ChanPat2"}; - - SaEvtEventPatternArrayT evt_pat = { - 1, 1, NULL - }; - - - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtChannelHandleT channel_handle1; - SaEvtEventHandleT event_handle; - SaEvtEventHandleT event_handle1; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - SaNameT channel_name1; - SaEvtCallbacksT multi_callbacks = { - 0, - multi_test_callback3 - }; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 5000; - - - - SaAisErrorT result; - - flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen((char *)channel_name.value); - strcpy((char *)channel_name1.value, channel); - strcat((char *)channel_name1.value, "_1"); - channel_name1.length = strlen((char *)channel_name1.value); - - -/* - * 3. Test opening of multiple channels and receiving events. - * Open and subscribe to two different channels twice. - * Subscribe to each channel with the same filters. - * Sending an event on one channel should be received in the - * call-back with the subscription ID corresponding to the sent - * channel. - */ - printf("Test multiple different channels/subscribes:\n"); - - do { - result = saEvtInitialize (&handle, &multi_callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(0) result: %s\n", result_buf); - goto evt_fin; - } - - do { - result = saEvtChannelOpen(handle, &channel_name1, flags, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(1) result: %s\n", result_buf); - goto evt_fin; - } - - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate(0) result: %s\n", result_buf); - goto evt_close; - } - do { - result = saEvtEventAllocate(channel_handle1, &event_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate(1) result: %s\n", result_buf); - goto evt_close; - } - - sub_filt.filters = filt1; - do { - result = saEvtEventSubscribe(channel_handle, - &sub_filt, - sub1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe(0) result: %s\n", result_buf); - goto evt_free; - } - sub_filt.filters = filt1; - do { - result = saEvtEventSubscribe(channel_handle1, - &sub_filt, - sub2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe(1) result: %s\n", result_buf); - goto evt_free; - } - retention_time = 0ULL; - - evt_pat.patterns = &pat1; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr(0) result: %s\n", result_buf); - goto evt_free; - } - - evt_pat.patterns = &pat2; - do { - result = saEvtEventAttributesSet(event_handle1, - &evt_pat, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr(1) result: %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE, - &event_id1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result: %s\n", result_buf); - goto evt_close; - } - do { - result = saEvtEventPublish(event_handle1, exp_data, DATA_SIZE, - &event_id2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result: %s\n", result_buf); - goto evt_close; - } - /* - * See if we got the events - */ - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - - call_count = 0; - - while(1) { - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd == 0) { - break; - } else if (nfd < 0) { - perror("ERROR: poll error"); - break; - } - - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ALL); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - goto evt_free; - } - } - - - if (call_count != 2) { - printf("ERROR: call back count: e=2, a=%d\n", call_count); - goto evt_free; - } - - /* - * Test cleanup - */ -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - do { - result = saEvtEventFree(event_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - -evt_close: - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result(0): %s\n", result_buf); - } - do { - result = saEvtChannelClose(channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result(1): %s\n", result_buf); - } -evt_fin: - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - printf("Done\n"); - -} - -/* - * Test event retention - * Test 1: publish the event with a retention time and then - * subscribe. If the event was retained, we should receive it. - * - * Test 2: Publish the event, sleep until it expires, then - * subscribe. We shouldn't get an event delivered. - * - * Test 3: Publish an event with a retention time. - * subscribe. - * wait for it. - * unsubscribe - * Clear it. - * Then subscribe and make sure that the messages isn't delivered. - * - */ -#define EXPIRE_TIME 10 /* Seconds */ -SaEvtEventIdT retained_id; -int got_event; - -void -event_callback_retained(SaEvtSubscriptionIdT my_subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT my_event_data_size) -{ - SaAisErrorT result; - //printf("event_callback_retained called\n"); - do { - result = saEvtEventAttributesGet(event_handle, - 0, /* patterns */ - 0, /* priority */ - 0, /* retention time */ - 0, /* publisher name */ - 0, /* publish time */ - &retained_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: callback attr get result: %s\n", result_buf); - return; - } - got_event = 1; -} - -void -test_retention() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle; - SaEvtEventHandleT event_handle; - SaEvtChannelOpenFlagsT flags; - SaNameT channel_name; - SaEvtCallbacksT callbacks_retain = { - 0, - event_callback_retained - }; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = (EXPIRE_TIME + 5); - SaAisErrorT result; - - flags = SA_EVT_CHANNEL_PUBLISHER | - SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - - printf("Test Event retention:\n"); - - do { - result = saEvtInitialize (&handle, &callbacks_retain, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - return; - } - - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags, SA_TIME_MAX, - &channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - goto evt_fin; - } - - /* - * Allocate an event - */ - do { - result = saEvtEventAllocate(channel_handle, &event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Allocate result: %s\n", result_buf); - goto evt_close; - } - - - retention_time = (EXPIRE_TIME)*1000000000ULL; - do { - result = saEvtEventAttributesSet(event_handle, - &evt_pat_set_array, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set attr result: %s\n", result_buf); - goto evt_free; - } - - /* - * Test 1: publish the event with a retention time and then - * subscribe. If the event was retained, we should receive it. - */ - printf(" Receive retained event\n"); - got_event=0; - retained_id=0; - do { - result = saEvtEventPublish(event_handle, exp_data, 0, &event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result(1): %s\n", result_buf); - goto evt_close; - } - - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - goto evt_free; - } - - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, 1000); - if (nfd <= 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - goto evt_free; - } - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - goto evt_free; - } - - if (!got_event) { - printf("ERROR: retained event not recevied\n"); - goto evt_free; - } - if (retained_id != event_id) { - printf("ERROR: received the wrong event: e=%llx, a=%llx\n", - (unsigned long long)event_id, - (unsigned long long)retained_id); - goto evt_free; - } - - do { - result = saEvtEventUnsubscribe(channel_handle, subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: unsubscribe result: %s\n", result_buf); - goto evt_free; - } - - /* - * Test 2: Publish the event, sleep until it expires, then - * subscribe. We shouldn't get an event delivered. - */ - printf(" Expire retained event\n"); - got_event=0; - retained_id=0; - do { - result = saEvtEventPublish(event_handle, exp_data, 0, &event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result(1): %s\n", result_buf); - goto evt_close; - } - - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtSelectionObject get %s\n", result_buf); - /* error */ - return; - } - - /* - * Wait for the event to expire, then subscribe. We shouldn't get - * an event - */ - sleep(timeout); - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - result = saEvtChannelClose(channel_handle); - goto evt_free; - } - - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, 1000); - if (nfd != 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - goto evt_free; - } - - do { - result = saEvtEventUnsubscribe(channel_handle, subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: unsubscribe result: %s\n", result_buf); - goto evt_free; - } - - /* - * Test 3: - * Publish an event with a retention time. - * subscribe. - * wait for it. - * unsubscribe - * Clear it. - * Then subscribe and make sure that the message isn't delivered. - */ - printf(" Clear event retention time\n"); - got_event=0; - retained_id=0; - do { - result = saEvtEventPublish(event_handle, exp_data, 0, &event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event Publish result(2): %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - goto evt_free; - } - - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, 1000); - if (nfd <= 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - goto evt_free; - } - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - /* error */ - goto evt_free; - } - - if (!got_event) { - printf("ERROR: retained event not recevied\n"); - goto evt_free; - } - if (retained_id != event_id) { - printf("ERROR: received the wrong event: e=%llx, a=%llx\n", - (unsigned long long)event_id, - (unsigned long long)retained_id); - goto evt_free; - } - - do { - result = saEvtEventUnsubscribe(channel_handle, subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: unsubscribe result: %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventRetentionTimeClear(channel_handle, event_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: clear retention time result: %s\n", result_buf); - goto evt_free; - } - - do { - result = saEvtEventSubscribe(channel_handle, - &subscribe_filters, - subscription_id); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event subscribe result: %s\n", result_buf); - goto evt_free; - } - - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, 1000); - if (nfd != 0) { - printf("ERROR: poll fds %d\n", nfd); - if (nfd < 0) { - perror("ERROR: poll error"); - } - /* Error */ - goto evt_free; - } - - /* - * Test cleanup - */ -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } - -evt_close: - do { - result = saEvtChannelClose(channel_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close result: %s\n", result_buf); - } -evt_fin: - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - printf("Done\n"); - -} - -void -unlink_chan_callback(SaEvtSubscriptionIdT my_subscription_id, - const SaEvtEventHandleT event_handle, - const SaSizeT my_event_data_size) -{ - SaAisErrorT result; - SaUint8T my_priority; - SaTimeT my_retention_time; - SaNameT my_publisher_name = {0, {0}}; - SaTimeT my_publish_time; - SaEvtEventIdT my_event_id; - SaEvtSubscriptionIdT exp_sub_id; - - printf(" unlink_chan_callback called(%d)\n", ++call_count); - - evt_pat_get_array.patternsNumber = 4; - do { - result = saEvtEventAttributesGet(event_handle, - &evt_pat_get_array, /* patterns */ - &my_priority, /* priority */ - &my_retention_time, /* retention time */ - &my_publisher_name, /* publisher name */ - &my_publish_time, /* publish time */ - &my_event_id /* event_id */ - ); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event get attr result: %s\n", result_buf); - goto evt_free; - } - - if (my_event_id == event_id1) { - exp_sub_id = sub1; - } else if (my_event_id == event_id2) { - exp_sub_id = sub2; - } else { - printf("ERROR: Received event %llx but not sent\n", - (unsigned long long)my_event_id); - goto evt_free; - } - - if (my_subscription_id != exp_sub_id) { - printf("ERROR: sub ID: e=%x, a=%x\n", - exp_sub_id, my_subscription_id); - goto evt_free; - } - -evt_free: - do { - result = saEvtEventFree(event_handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event free result: %s\n", result_buf); - } -} - -/* - * Test channel unlink operations. - * 1. Unlink channel. - * 2. Open/create a channel, close channel, open channel. - * 3. unlink channel, Open channel. - * 4. Open/create, unlink channel, close channel, open channel. - * 5. Open/create a channel, unlink channel, open/create channel, send - * event on each. - * 6. unlink all, close all. - */ -SaEvtCallbacksT unlink_callbacks = { - open_callback, - unlink_chan_callback -}; -void -test_unlink_channel() -{ - SaEvtHandleT handle; - SaEvtChannelHandleT channel_handle1; - SaEvtChannelHandleT channel_handle2; - SaEvtEventHandleT event_handle1; - SaEvtEventHandleT event_handle2; - SaEvtChannelOpenFlagsT flags1, flags2; - SaNameT channel_name; - SaAisErrorT result; - - struct pollfd pfd; - int nfd; - SaSelectionObjectT fd; - int timeout = 5000; - - flags1 = SA_EVT_CHANNEL_PUBLISHER | - SA_EVT_CHANNEL_SUBSCRIBER | - SA_EVT_CHANNEL_CREATE; - - flags2 = SA_EVT_CHANNEL_PUBLISHER | - SA_EVT_CHANNEL_SUBSCRIBER; - - - printf("Test Channel Unlink operations:\n"); - - do { - result = saEvtInitialize (&handle, &unlink_callbacks, - versions[0].version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Initialize result: %s\n", result_buf); - goto unlink_exit; - } - - /* - * 1. Unlink channel. - * - * Unlink previously opened channel should return OK. - * Unlink of non-existent channel should return error. - */ - printf(" 1 Channel unlink:\n"); - - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - do { - result = saEvtChannelUnlink(handle, &channel_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel unlink(1) result: %s\n", result_buf); - goto unlink_exit; - } - - strcpy((char *)channel_name.value, unlink_channel); - channel_name.length = strlen(unlink_channel); - do { - result = saEvtChannelUnlink(handle, &channel_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_NOT_EXIST) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel unlink(2) result: %s\n", result_buf); - goto unlink_exit; - } - - /* - * 2. Open/create a channel, close channel, open channel. - * - * Open/create the channel. - * Close the channel. - * Open without create. This should succeed in the B spec. - */ - printf(" 2 Channel open/close/open:\n"); - - do { - result = saEvtChannelOpen(handle, &channel_name, flags1, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(1) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelClose(channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close(1) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags2, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(2) result: %s\n", result_buf); - goto unlink_exit; - } - - /* - * 3. unlink channel, Open channel, close channel - * - * Unlink the channel. Should mark for deletion but not - * delete it since it is already open. - * Open the channel without create. This should fail since - * the channel is marked for deletion and a new version - * hasn't been created. - * Close channel. - */ - printf(" 3 Channel unlink/open/close:\n"); - - do { - result = saEvtChannelUnlink(handle, &channel_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel unlink result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags2, SA_TIME_MAX, - &channel_handle2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_NOT_EXIST) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - goto unlink_exit; - } - do { - result = saEvtChannelClose(channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close(1) result: %s\n", result_buf); - goto unlink_exit; - } - - /* - * - * 4. Open/create, unlink channel, close channel, open channel. - * - * Open/create the channel. - * unlink the channel. - * close the channel. This should delete the channel instance since - * it was marked for deletion. - * open the channel without create. This should fail since the - * channel doesn't exist anymore. - */ - printf(" 4 Channel open/unlink/close/open:\n"); - do { - result = saEvtChannelOpen(handle, &channel_name, flags1, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(1) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelUnlink(handle, &channel_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel unlink result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelClose(channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel close(1) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags2, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_ERR_NOT_EXIST) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open(2) result: %s\n", result_buf); - goto unlink_exit; - } - - /* - * 5. Open/create a channel, unlink channel, open/create channel, send - * event on each. - * - * Open/create. - * unlink. Mark for deletion. - * open/create. Create new channel of same name. - * send event on each open channel. The events should be received on - * separate channels. - */ - printf(" 5 Channel open/unlink/open/send:\n"); - - do { - result = saEvtChannelOpen(handle, &channel_name, flags1, SA_TIME_MAX, - &channel_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelUnlink(handle, &channel_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel unlink result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtChannelOpen(handle, &channel_name, flags1, SA_TIME_MAX, - &channel_handle2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel open result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtEventSubscribe(channel_handle1, - &subscribe_filters, - sub1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel subscribe(1) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtEventSubscribe(channel_handle2, - &subscribe_filters, - sub2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel subscribe(2) result: %s\n", result_buf); - goto unlink_exit; - } - - retention_time = 0ULL; - do { - result = saEvtEventAllocate(channel_handle1, &event_handle1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event allocate(1) result: %s\n", result_buf); - goto unlink_exit; - } - do { - result = saEvtEventAttributesSet(event_handle1, - &evt_pat_set_array, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set(1) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtEventAllocate(channel_handle2, &event_handle2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event allocate(2) result: %s\n", result_buf); - goto unlink_exit; - } - do { - result = saEvtEventAttributesSet(event_handle2, - &evt_pat_set_array, - TEST_PRIORITY, - retention_time, - &test_pub_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event set(2) result: %s\n", result_buf); - goto unlink_exit; - } - - do { - result = saEvtEventPublish(event_handle1, 0, 0, &event_id1); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event publish(1) result: %s\n", result_buf); - goto unlink_exit; - } - do { - result = saEvtEventPublish(event_handle2, 0, 0, &event_id2); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: event publish(2) result: %s\n", result_buf); - goto unlink_exit; - } - - - do { - result = saEvtSelectionObjectGet(handle, &fd); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: select object get result: %s\n", result_buf); - goto unlink_exit; - } - - /* - * We should see a total of two events processed, not four - * as if both events were recevied on both channels. - */ - call_count = 0; - do { - pfd.fd = fd; - pfd.events = POLLIN; - nfd = poll(&pfd, 1, timeout); - if (nfd <= 0) { - if (nfd < 0) { - perror("ERROR: poll error"); - goto unlink_exit; - } - } else { - - do { - result = saEvtDispatch(handle, SA_DISPATCH_ONE); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: saEvtDispatch %s\n", result_buf); - goto unlink_exit; - } - } - } while (nfd > 0); - - if (call_count != 2) { - printf("ERROR: processed %d events\n", call_count); - goto unlink_exit; - } - - - /* - * 6. unlink all, close all. - * - * close all open channels. - * unlink the channel. - * open without create the channel. Verify that the channel no - * longer exists. - */ - printf(" 6 Channel unlink all/close all/open:\n"); - -unlink_exit: - saEvtChannelClose(channel_handle1); - saEvtChannelClose(channel_handle2); - saEvtChannelUnlink(handle, &channel_name); - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - - printf("Done\n"); - -} -int main (void) -{ - test_initialize (); - test_channel(); - test_event(); - test_multi_channel1(); - test_multi_channel2(); - test_multi_channel3(); - test_retention(); - test_unlink_channel(); - - return (0); -} - -/* - * vi: set autoindent tabstop=4 shiftwidth=4 : - */ diff --git a/openais/test/testlck.c b/openais/test/testlck.c deleted file mode 100644 index 66df9f75..00000000 --- a/openais/test/testlck.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saLck.h" - -SaNameT resource_name_async; -SaLckResourceHandleT resource_handle_async; - -void testLckResourceOpenCallback ( - SaInvocationT invocation, - SaLckResourceHandleT lockResourceHandle, - SaAisErrorT error) -{ - printf ("testLckResourceOpenCallback invocation %llu error %d\n", - (unsigned long long)invocation, error); - resource_handle_async = lockResourceHandle; -} - -void testLckLockGrantCallback ( - SaInvocationT invocation, - SaLckLockStatusT lockStatus, - SaAisErrorT error) -{ - printf ("testLckLockGrantCallback invocation %llu status %d error %d\n", - (unsigned long long)invocation, lockStatus, error); -} - -SaLckLockIdT pr_lock_id; -SaLckLockIdT pr_lock_async_id; - -void testLckLockWaiterCallback ( - SaLckWaiterSignalT waiterSignal, - SaLckLockIdT lockId, - SaLckLockModeT modeHeld, - SaLckLockModeT modeRequested) -{ - int result; - printf ("waiter callback mode held %d mode requested %d lock id %llu\n", - modeHeld, - modeRequested, - (unsigned long long)lockId); - printf ("pr lock id %llu\n", (unsigned long long)pr_lock_async_id); - result = saLckResourceUnlockAsync ( - 25, - lockId); - printf ("saLckResourceUnlockAsync result %d (should be 1)\n", result); -} - -void testLckResourceUnlockCallback ( - SaInvocationT invocation, - SaAisErrorT error) -{ - printf ("testLckResourceUnlockCallback async invocation %llu error %d\n", - (unsigned long long)invocation, error); -} - -SaLckCallbacksT callbacks = { - .saLckResourceOpenCallback = testLckResourceOpenCallback, - .saLckLockGrantCallback = testLckLockGrantCallback, - .saLckLockWaiterCallback = testLckLockWaiterCallback, - .saLckResourceUnlockCallback = testLckResourceUnlockCallback -}; - -SaVersionT version = { 'B', 1, 1 }; - -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); - } -} - -void sigintr_handler (int signum) { - exit (0); -} - -struct th_data { - SaLckHandleT handle; -}; - -void *th_dispatch (void *arg) -{ - struct th_data *th_data = (struct th_data *)arg; - - saLckDispatch (th_data->handle, SA_DISPATCH_BLOCKING); - return (0); -} - -int main (void) { - SaLckHandleT handle; - SaLckResourceHandleT resource_handle; - int result; - SaLckLockIdT ex_lock_id; - SaLckLockStatusT status; - SaNameT resource_name; - pthread_t dispatch_thread; - fd_set read_fds; - struct th_data th_data; - - signal (SIGINT, sigintr_handler); - - result = saLckInitialize (&handle, &callbacks, &version); - if (result != SA_AIS_OK) { - printf ("Could not initialize Lock Service API instance error %d\n", result); - exit (1); - } - printf ("saLckInitialize result is %d (should be 1)\n", result); - - th_data.handle = handle; - pthread_create (&dispatch_thread, NULL, th_dispatch, &th_data); - - setSaNameT (&resource_name_async, "test_resource_async"); - - setSaNameT (&resource_name, "not_existingaabb"); - result = saLckResourceOpen ( - handle, - &resource_name, -// SA_LCK_RESOURCE_CREATE, - 0, - SA_TIME_ONE_SECOND, - &resource_handle); - printf ("saLckResourceOpen %d (should be 12)\n", result); - - result = saLckResourceClose (resource_handle); - printf ("saLckResourceClose %d (should be 9)\n", result); - - setSaNameT (&resource_name, "test_resource"); - result = saLckResourceOpen ( - handle, - &resource_name, - SA_LCK_RESOURCE_CREATE, - SA_TIME_ONE_SECOND, - &resource_handle); - printf ("saLckResourceOpen %d (should be 1)\n", result); - - result = saLckResourceOpenAsync ( - handle, - (SaInvocationT)0x56, - &resource_name_async, - SA_LCK_RESOURCE_CREATE); - printf ("saLckResourceOpenAsync %d (should be 1)\n", result); - - result = saLckResourceLock ( - resource_handle, - &pr_lock_id, - SA_LCK_PR_LOCK_MODE, - SA_LCK_LOCK_ORPHAN, - 55, - SA_TIME_END, - &status); - printf ("saLckResourceLock PR %d (should be 1)\n", result); - printf ("status %d\n", status); - - result = saLckResourceUnlock ( - pr_lock_id, - SA_TIME_END); - printf ("saLckResourceUnlock result %d (should be 1)\n", result); - - result = saLckResourceLock ( - resource_handle, - &pr_lock_id, - SA_LCK_PR_LOCK_MODE, - SA_LCK_LOCK_ORPHAN, - 55, - SA_TIME_END, - &status); - printf ("saLckResourceLock PR %d (should be 1)\n", result); - printf ("status %d\n", status); - - result = saLckResourceLock ( - resource_handle, - &ex_lock_id, - SA_LCK_EX_LOCK_MODE, - 0, - 55, - SA_TIME_END, - &status); - printf ("saLckResourceLock EX %d (should be 1)\n", result); - printf ("status %d\n", status); - - result = saLckResourceLockAsync ( - resource_handle_async, - 0x56, - &pr_lock_async_id, - SA_LCK_PR_LOCK_MODE, - 0, - 55); - printf ("saLckResourceLockAsync PR %d (should be 1)\n", result); - printf ("status %d\n", status); - printf ("press the enter key to exit\n"); - FD_ZERO (&read_fds); - do { - FD_SET (STDIN_FILENO, &read_fds); - result = select (STDIN_FILENO + 1, &read_fds, 0, 0, 0); - if (FD_ISSET (STDIN_FILENO, &read_fds)) { - break; - } - } while (result); - - printf ("Starting saLckResourceUnlock\n"); - result = saLckResourceUnlock ( - ex_lock_id, - SA_TIME_END); - printf ("saLckResourceUnlock result %d (should be 1)\n", - result); - - result = saLckResourceClose (resource_handle); - printf ("saLckResourceClose result %d (should be 1)\n", result); - - result = saLckFinalize (handle); - printf ("saLckFinalize %d (should be 1)\n", result); - return (0); -} diff --git a/openais/test/testmsg.c b/openais/test/testmsg.c deleted file mode 100644 index 07470116..00000000 --- a/openais/test/testmsg.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (c) 2005 MontaVista Software, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saMsg.h" - -SaMsgQueueHandleT async_handle; - -void QueueOpenCallback ( - SaInvocationT invocation, - SaMsgQueueHandleT queueHandle, - SaAisErrorT error) -{ - /* DEBUG */ - printf ("[DEBUG]: testmsg (QueueOpenCallback)\n"); - printf ("[DEBUG]: \t { queueHandle = %llx }\n", - (unsigned long long) queueHandle); - - async_handle = queueHandle; -} - -void QueueGroupTrackCallback ( - const SaNameT *queueGroupName, - const SaMsgQueueGroupNotificationBufferT *notificationBuffer, - SaUint32T numberOfMembers, - SaAisErrorT error) -{ - /* DEBUG */ - printf ("[DEBUG]: testmsg (QueueGroupTrackCallback)\n"); -} - -void MessageDeliveredCallback ( - SaInvocationT invocation, - SaAisErrorT error) -{ - /* DEBUG */ - printf ("[DEBUG]: testmsg (MessageDeliveredCallback)\n"); - printf ("[DEBUG]: \t { invocation = %llx }\n", - (unsigned long long) invocation); -} - -void MessageReceivedCallback ( - SaMsgQueueHandleT queueHandle) -{ - /* DEBUG */ - printf ("[DEBUG]: testmsg (MessageReceivedCallback)\n"); -} - -SaMsgCallbacksT callbacks = { - .saMsgQueueOpenCallback = QueueOpenCallback, - .saMsgQueueGroupTrackCallback = QueueGroupTrackCallback, - .saMsgMessageDeliveredCallback = MessageDeliveredCallback, - .saMsgMessageReceivedCallback = MessageReceivedCallback -}; - -SaVersionT version = { 'B', 1, 1 }; - -SaMsgQueueCreationAttributesT creation_attributes = { - SA_MSG_QUEUE_PERSISTENT, - { 128000, 128000, 128000 }, - SA_TIME_END -}; - -void setSaNameT (SaNameT *name, char *str) { - name->length = strlen (str); - strcpy (name->value, str); -} - -void setSaMsgMessageT (SaMsgMessageT *message, char *data) { - message->type = 1; - message->version = 2; - message->size = strlen (data) + 1; - message->senderName = NULL; - message->data = strdup (data); - message->priority = 0; -} - -void sigintr_handler (int signum) { - exit (0); -} - -int main (void) { - SaMsgHandleT handle; - SaMsgMessageT message; - SaMsgQueueHandleT queue_handle; - SaSelectionObjectT select_fd; - SaInvocationT invocation = 3; - - fd_set read_fds; - int result; - - SaNameT async_name; - SaNameT queue_name; - SaNameT queue_group_name; - SaTimeT time; - SaMsgSenderIdT id; - SaMsgMessageT msg_a; - SaMsgMessageT msg_b; - SaMsgMessageT msg_c; - - memset (&msg_a, 0, sizeof (SaMsgMessageT)); - memset (&msg_b, 0, sizeof (SaMsgMessageT)); - memset (&msg_c, 0, sizeof (SaMsgMessageT)); - - signal (SIGINT, sigintr_handler); - - result = saMsgInitialize (&handle, &callbacks, &version); - if (result != SA_AIS_OK) { - printf ("Could not initialize Cluster Membership API instance error %d\n", result); - exit (1); - } - - saMsgSelectionObjectGet (handle, &select_fd); - - setSaNameT (&async_name, "async"); - setSaNameT (&queue_name, "queue"); - - result = saMsgQueueOpen (handle, - &queue_name, - &creation_attributes, - SA_MSG_QUEUE_CREATE, - SA_TIME_END, - &queue_handle); - printf ("saMsgQueueOpen result is %d (should be 1)\n", result); - printf ("saMsgQueueOpen { queue_handle = %llx }\n", queue_handle); - - result = saMsgQueueOpenAsync (handle, - invocation, - &async_name, - &creation_attributes, - SA_MSG_QUEUE_CREATE); - printf ("saMsgQueueOpenAsync result is %d (should be 1)\n", result); - printf ("saMsgQueueOpen { async_handle = %llx }\n", async_handle); - - setSaNameT (&queue_group_name, "queue_group"); - - result = saMsgQueueGroupCreate ( - handle, - &queue_group_name, - SA_MSG_QUEUE_GROUP_ROUND_ROBIN); - printf ("saMsgQueueGroupCreate result is %d (should be 1)\n", result); - - result = saMsgQueueGroupCreate ( - handle, - &queue_group_name, - SA_MSG_QUEUE_GROUP_ROUND_ROBIN); - printf ("saMsgQueueGroupCreate result is %d (should be 14)\n", result); - - result = saMsgQueueGroupInsert ( - handle, - &queue_group_name, - &queue_name); - printf ("saMsgQueueGroupInsert result is %d (should be 1)\n", result); - - saMsgDispatch (handle, SA_DISPATCH_ALL); - - /* - FD_ZERO (&read_fds); - do { - FD_SET (select_fd, &read_fds); - FD_SET (STDIN_FILENO, &read_fds); - result = select (select_fd + 1, &read_fds, 0, 0, 0); - if (result == -1) { - perror ("select\n"); - } - if (FD_ISSET (STDIN_FILENO, &read_fds)) { - break; - } - saMsgDispatch (handle, SA_DISPATCH_ALL); - } while (result); - */ - - setSaMsgMessageT (&message, "test_msg_01"); - result = saMsgMessageSend (handle, &queue_name, &message, SA_TIME_ONE_SECOND); - printf ("saMsgMessageSend [1] result is %d (should be 1)\n", result); - - setSaMsgMessageT (&message, "test_msg_02"); - result = saMsgMessageSend (handle, &queue_name, &message, SA_TIME_ONE_SECOND); - printf ("saMsgMessageSend [2] result is %d (should be 1)\n", result); - - setSaMsgMessageT (&message, "test_msg_03"); - result = saMsgMessageSend (handle, &queue_name, &message, SA_TIME_ONE_SECOND); - printf ("saMsgMessageSend [3] result is %d (should be 1)\n", result); - - setSaMsgMessageT (&message, "test_msg_04"); - result = saMsgMessageSendAsync (handle, invocation, &queue_name, &message, - SA_MSG_MESSAGE_DELIVERED_ACK); - printf ("saMsgMessageSendAsync [4] result is %d (should be 1)\n", result); - - setSaMsgMessageT (&message, "test_msg_05"); - result = saMsgMessageSendAsync (handle, invocation, &queue_name, &message, - SA_MSG_MESSAGE_DELIVERED_ACK); - printf ("saMsgMessageSendAsync [5] result is %d (should be 1)\n", result); - - saMsgDispatch (handle, SA_DISPATCH_ALL); - - result = saMsgMessageGet (queue_handle, &msg_a, &time, &id, SA_TIME_ONE_MINUTE); - printf ("saMsgMessageGet [a] result is %d (should be 1)\n", result); - - result = saMsgMessageGet (queue_handle, &msg_b, &time, &id, SA_TIME_ONE_MINUTE); - printf ("saMsgMessageGet [b] result is %d (should be 1)\n", result); - - result = saMsgMessageGet (queue_handle, &msg_c, &time, &id, SA_TIME_ONE_MINUTE); - printf ("saMsgMessageGet [c] result is %d (should be 1)\n", result); - - printf ("saMsgMessageGet { (a) data = %s }\n", (char *)(msg_a.data)); - printf ("saMsgMessageGet { (b) data = %s }\n", (char *)(msg_b.data)); - printf ("saMsgMessageGet { (c) data = %s }\n", (char *)(msg_c.data)); - - result = saMsgQueueGroupRemove (handle, &queue_group_name, &queue_name); - printf ("saMsgQueueGroupRemove result is %d (should be 1)\n", result); - - result = saMsgQueueGroupDelete (handle, &queue_group_name); - printf ("saMsgQueueGroupDelete result is %d (should be 1)\n", result); - - printf ("saMsgQueueClose { queue_handle = %llx }\n", queue_handle); - result = saMsgQueueClose (queue_handle); - printf ("saMsgQueueClose result is %d (should be 1)\n", result); - - printf ("saMsgQueueClose { async_handle = %llx }\n", async_handle); - result = saMsgQueueClose (async_handle); - printf ("saMsgQueueClose result is %d (should be 1)\n", result); - - result = saMsgFinalize (handle); - printf ("Finalize result is %d (should be 1)\n", result); - return (0); -} diff --git a/openais/test/testmsg2.c b/openais/test/testmsg2.c deleted file mode 100644 index d00cea6a..00000000 --- a/openais/test/testmsg2.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright (c) 2008 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Ryan O'Hara (rohara@redhat.com) - * - * This software licensed under BSD license, the text of which follows: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the MontaVista Software, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "saAis.h" -#include "saMsg.h" - -void QueueOpenCallback ( - SaInvocationT invocation, - SaMsgQueueHandleT queueHandle, - SaAisErrorT error) -{ - /* DEBUG */ - printf ("[TEST]: testmsg2 (QueueOpenCallback)\n"); - printf ("[TEST]: \t { invocation = %llx }\n", - (unsigned long long)(invocation)); - printf ("[TEST]: \t { queueHandle = %llx }\n", - (unsigned long long)(queueHandle)); - printf ("[TEST]: \t { error = %u }\n", - (unsigned int)(error)); -} - -void QueueGroupTrackCallback ( - const SaNameT *queueGroupName, - const SaMsgQueueGroupNotificationBufferT *notificationBuffer, - SaUint32T numberOfMembers, - SaAisErrorT error) -{ - int i = 0; - - /* DEBUG */ - printf ("[TEST]: testmsg2 (QueueGroupTrackCallback)\n"); - printf ("[TEST]: \t { queueGroupName = %s }\n", - (char *)(queueGroupName->value)); - printf ("[TEST]: \t { numberOfMembers = %u }\n", - (unsigned int)(numberOfMembers)); - printf ("[TEST]: \t { error = %u }\n", - (unsigned int)(error)); - printf ("[TEST]: \t { notificationBuffer->numberOfItems = %u }\n", - (unsigned int)(notificationBuffer->numberOfItems)); - - for (i = 0; i < notificationBuffer->numberOfItems; i++) { - printf ("[TEST]: \t { item #%d => %s (%u) }\n", i, - (char *)(notificationBuffer->notification[i].member.queueName.value), - (unsigned int)(notificationBuffer->notification[i].change)); - } -} - -void MessageDeliveredCallback ( - SaInvocationT invocation, - SaAisErrorT error) -{ - /* DEBUG */ - printf ("[TEST]: testmsg2 (MessageDeliveredCallback)\n"); - printf ("[TEST]: \t { invocation = %llx }\n", - (unsigned long long)(invocation)); - printf ("[TEST]: \t { error = %u }\n", - (unsigned int)(error)); -} - -void MessageReceivedCallback ( - SaMsgQueueHandleT queueHandle) -{ - /* DEBUG */ - printf ("[TEST]: testmsg2 (MessageReceivedCallback)\n"); - printf ("[TEST]: \t { queueHandle = %llx }\n", - (unsigned long long)(queueHandle)); -} - -SaMsgCallbacksT callbacks = { - .saMsgQueueOpenCallback = QueueOpenCallback, - .saMsgQueueGroupTrackCallback = QueueGroupTrackCallback, - .saMsgMessageDeliveredCallback = MessageDeliveredCallback, - .saMsgMessageReceivedCallback = MessageReceivedCallback -}; - -SaVersionT version = { 'B', 1, 1 }; - -SaMsgQueueCreationAttributesT creation_attributes = { - SA_MSG_QUEUE_PERSISTENT, - { 128000, 128000, 128000 }, - SA_TIME_END -}; - -void setSaNameT (SaNameT *name, char *str) { - name->length = strlen (str); - strcpy (name->value, str); -} - -int main (void) -{ - int result; - - SaSelectionObjectT select_obj; - - SaMsgHandleT handle; - - SaMsgQueueHandleT queue_handle_a; - SaMsgQueueHandleT queue_handle_b; - SaMsgQueueHandleT queue_handle_c; - - SaMsgQueueHandleT queue_handle_x; - SaMsgQueueHandleT queue_handle_y; - SaMsgQueueHandleT queue_handle_z; - - SaNameT queue_name_a; - SaNameT queue_name_b; - SaNameT queue_name_c; - - SaNameT queue_name_x; - SaNameT queue_name_y; - SaNameT queue_name_z; - - SaNameT queue_group_one; - SaNameT queue_group_two; - - setSaNameT(&queue_name_a, "QUEUE_A"); - setSaNameT(&queue_name_b, "QUEUE_B"); - setSaNameT(&queue_name_c, "QUEUE_C"); - - setSaNameT(&queue_name_x, "QUEUE_X"); - setSaNameT(&queue_name_y, "QUEUE_Y"); - setSaNameT(&queue_name_z, "QUEUE_Z"); - - setSaNameT(&queue_group_one, "GROUP_ONE"); - setSaNameT(&queue_group_two, "GROUP_TWO"); - - result = saMsgInitialize (&handle, &callbacks, &version); - - if (result != SA_AIS_OK) { - printf ("[ERROR]: (%d) saMsgInitialize\n", result); - exit (1); - } - - saMsgSelectionObjectGet (handle, &select_obj); - - /* - * Create message queues - */ - - result = saMsgQueueOpen (handle, &queue_name_a, &creation_attributes, - SA_MSG_QUEUE_CREATE, SA_TIME_END, &queue_handle_a); - printf ("[DEBUG]: (%d) saMsgQueueOpen { %s }\n", - result, (char *)(queue_name_a.value)); - - result = saMsgQueueOpen (handle, &queue_name_b, &creation_attributes, - SA_MSG_QUEUE_CREATE, SA_TIME_END, &queue_handle_b); - printf ("[DEBUG]: (%d) saMsgQueueOpen { %s }\n", - result, (char *)(queue_name_b.value)); - - result = saMsgQueueOpen (handle, &queue_name_c, &creation_attributes, - SA_MSG_QUEUE_CREATE, SA_TIME_END, &queue_handle_c); - printf ("[DEBUG]: (%d) saMsgQueueOpen { %s }\n", - result, (char *)(queue_name_c.value)); - - result = saMsgQueueOpen (handle, &queue_name_x, &creation_attributes, - SA_MSG_QUEUE_CREATE, SA_TIME_END, &queue_handle_x); - printf ("[DEBUG]: (%d) saMsgQueueOpen { %s }\n", - result, (char *)(queue_name_x.value)); - - result = saMsgQueueOpen (handle, &queue_name_y, &creation_attributes, - SA_MSG_QUEUE_CREATE, SA_TIME_END, &queue_handle_y); - printf ("[DEBUG]: (%d) saMsgQueueOpen { %s }\n", - result, (char *)(queue_name_y.value)); - - result = saMsgQueueOpen (handle, &queue_name_z, &creation_attributes, - SA_MSG_QUEUE_CREATE, SA_TIME_END, &queue_handle_z); - printf ("[DEBUG]: (%d) saMsgQueueOpen { %s }\n", - result, (char *)(queue_name_z.value)); - - /* - * Create queue groups - */ - - result = saMsgQueueGroupCreate (handle, &queue_group_one, - SA_MSG_QUEUE_GROUP_ROUND_ROBIN); - printf ("[DEBUG]: (%d) saMsgQueueGroupCreate { %s }\n", - result, (char *)(queue_group_one.value)); - - result = saMsgQueueGroupCreate (handle, &queue_group_two, - SA_MSG_QUEUE_GROUP_ROUND_ROBIN); - printf ("[DEBUG]: (%d) saMsgQueueGroupCreate { %s }\n", - result, (char *)(queue_group_two.value)); - - /* - * Track GROUP_ONE with SA_TRACK_CHANGES - */ - - result = saMsgQueueGroupTrack (handle, &queue_group_one, - SA_TRACK_CHANGES, NULL); - printf ("[DEBUG]: (%d) saMsgQueueGroupTrack { %s }\n", - result, (char *)(queue_group_one.value)); - - /* - * Track GROUP_TWO with SA_TRACK_CHANGES_ONLY - */ - - result = saMsgQueueGroupTrack (handle, &queue_group_two, - SA_TRACK_CHANGES_ONLY, NULL); - printf ("[DEBUG]: (%d) saMsgQueueGroupTrack { %s }\n", - result, (char *)(queue_group_two.value)); - - /* - * Add queues to GROUP_ONE - */ - - result = saMsgQueueGroupInsert (handle, &queue_group_one, &queue_name_a); - printf ("[DEBUG]: (%d) saMsgQueueGroupInsert { group: %s + queue: %s }\n", - result, (char *)(queue_group_one.value), (char *)(queue_name_a.value)); - - result = saMsgQueueGroupInsert (handle, &queue_group_one, &queue_name_b); - printf ("[DEBUG]: (%d) saMsgQueueGroupInsert { group: %s + queue: %s }\n", - result, (char *)(queue_group_one.value), (char *)(queue_name_b.value)); - - result = saMsgQueueGroupInsert (handle, &queue_group_one, &queue_name_c); - printf ("[DEBUG]: (%d) saMsgQueueGroupInsert { group: %s + queue: %s }\n", - result, (char *)(queue_group_one.value), (char *)(queue_name_c.value)); - - /* - * Add queues to GROUP_TWO - */ - - result = saMsgQueueGroupInsert (handle, &queue_group_two, &queue_name_x); - printf ("[DEBUG]: (%d) saMsgQueueGroupInsert { group: %s + queue: %s }\n", - result, (char *)(queue_group_two.value), (char *)(queue_name_x.value)); - - result = saMsgQueueGroupInsert (handle, &queue_group_two, &queue_name_y); - printf ("[DEBUG]: (%d) saMsgQueueGroupInsert { group: %s + queue: %s }\n", - result, (char *)(queue_group_two.value), (char *)(queue_name_y.value)); - - result = saMsgQueueGroupInsert (handle, &queue_group_two, &queue_name_z); - printf ("[DEBUG]: (%d) saMsgQueueGroupInsert { group: %s + queue: %s }\n", - result, (char *)(queue_group_two.value), (char *)(queue_name_z.value)); - - /* - * Track queue groups with SA_TRACK_CURRENT - */ - - result = saMsgQueueGroupTrack (handle, &queue_group_one, - SA_TRACK_CURRENT, NULL); - printf ("[DEBUG]: (%d) saMsgQueueGroupTrack { %s }\n", - result, (char *)(queue_group_one.value)); - - result = saMsgQueueGroupTrack (handle, &queue_group_two, - SA_TRACK_CURRENT, NULL); - printf ("[DEBUG]: (%d) saMsgQueueGroupTrack { %s }\n", - result, (char *)(queue_group_two.value)); - - /* - * Dispatch callbacks - */ - - result = saMsgDispatch (handle, SA_DISPATCH_ALL); - printf ("[DEBUG]: (%d) saMsgDispatch\n", result); - - /* - * Remove queues from GROUP_ONE - */ - - result = saMsgQueueGroupRemove (handle, &queue_group_one, &queue_name_a); - printf ("[DEBUG]: (%d) saMsgQueueGroupRemove { group: %s - queue: %s }\n", - result, (char *)(queue_group_one.value), (char *)(queue_name_a.value)); - - result = saMsgQueueGroupRemove (handle, &queue_group_one, &queue_name_b); - printf ("[DEBUG]: (%d) saMsgQueueGroupRemove { group: %s - queue: %s }\n", - result, (char *)(queue_group_one.value), (char *)(queue_name_b.value)); - - result = saMsgQueueGroupRemove (handle, &queue_group_one, &queue_name_c); - printf ("[DEBUG]: (%d) saMsgQueueGroupRemove { group: %s - queue: %s }\n", - result, (char *)(queue_group_one.value), (char *)(queue_name_c.value)); - - /* - * Remove queues from GROUP_TWO - */ - - result = saMsgQueueGroupRemove (handle, &queue_group_two, &queue_name_x); - printf ("[DEBUG]: (%d) saMsgQueueGroupRemove { group: %s - queue: %s }\n", - result, (char *)(queue_group_two.value), (char *)(queue_name_x.value)); - - result = saMsgQueueGroupRemove (handle, &queue_group_two, &queue_name_y); - printf ("[DEBUG]: (%d) saMsgQueueGroupRemove { group: %s - queue: %s }\n", - result, (char *)(queue_group_two.value), (char *)(queue_name_y.value)); - - result = saMsgQueueGroupRemove (handle, &queue_group_two, &queue_name_z); - printf ("[DEBUG]: (%d) saMsgQueueGroupRemove { group: %s - queue: %s }\n", - result, (char *)(queue_group_two.value), (char *)(queue_name_z.value)); - - /* - * Dispatch callbacks - */ - - result = saMsgDispatch (handle, SA_DISPATCH_ALL); - printf ("[DEBUG]: (%d) saMsgDispatch\n", result); - - /* - * Stop tracking GROUP_ONE - */ - - result = saMsgQueueGroupTrackStop (handle, &queue_group_one); - printf ("[DEBUG]: (%d) saMsgQueueGroupTrackStop { %s }\n", - result, (char *)(queue_group_one.value)); - - /* - * Stop tracking GROUP_TWO - */ - - result = saMsgQueueGroupTrackStop (handle, &queue_group_two); - printf ("[DEBUG]: (%d) saMsgQueueGroupTrackStop { %s }\n", - result, (char *)(queue_group_two.value)); - - /* - * Close message queues - */ - - result = saMsgQueueClose (queue_handle_a); - printf ("[DEBUG]: (%d) saMsgQueueClose { %llx }\n", - result, ((unsigned long long) queue_handle_a)); - - result = saMsgQueueClose (queue_handle_b); - printf ("[DEBUG]: (%d) saMsgQueueClose { %llx }\n", - result, ((unsigned long long) queue_handle_b)); - - result = saMsgQueueClose (queue_handle_c); - printf ("[DEBUG]: (%d) saMsgQueueClose { %llx }\n", - result, ((unsigned long long) queue_handle_c)); - - result = saMsgQueueClose (queue_handle_x); - printf ("[DEBUG]: (%d) saMsgQueueClose { %llx }\n", - result, ((unsigned long long) queue_handle_x)); - - result = saMsgQueueClose (queue_handle_y); - printf ("[DEBUG]: (%d) saMsgQueueClose { %llx }\n", - result, ((unsigned long long) queue_handle_y)); - - result = saMsgQueueClose (queue_handle_z); - printf ("[DEBUG]: (%d) saMsgQueueClose { %llx }\n", - result, ((unsigned long long) queue_handle_z)); - - /* - * Delete queue groups - */ - - result = saMsgQueueGroupDelete (handle, &queue_group_one); - printf ("[DEBUG]: (%d) saMsgQueueGroupDelete { %s }\n", - result, (char *)(queue_group_one.value)); - - result = saMsgQueueGroupDelete (handle, &queue_group_two); - printf ("[DEBUG]: (%d) saMsgQueueGroupDelete { %s }\n", - result, (char *)(queue_group_two.value)); - - result = saMsgFinalize (handle); - - if (result != SA_AIS_OK) { - printf ("[ERROR]: (%d) saMsgFinalize\n", result); - exit (1); - } - - return (0); -} diff --git a/openais/test/unlink.c b/openais/test/unlink.c deleted file mode 100644 index 50210fd4..00000000 --- a/openais/test/unlink.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Test program for event service - */ - -#include -#include -#include -#include -#include -#ifndef OPENAIS_SOLARIS -#include -#include -#else -#include -#endif -#include -#include -#include "saAis.h" -#include "saEvt.h" - -#define TRY_WAIT 2 - -extern int get_sa_error(SaAisErrorT, char *, int); -char result_buf[256]; -int result_buf_len = sizeof(result_buf); - -SaVersionT version = { 'B', 0x01, 0x01 }; - -SaEvtCallbacksT callbacks = { - 0, - 0 -}; - - -char channel[256] = "EVENT_TEST_CHANNEL"; - - -int -do_unlink() -{ - SaEvtHandleT handle; - SaNameT channel_name; - - SaAisErrorT result; - - do { - result = saEvtInitialize (&handle, &callbacks, &version); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("Event Initialize result: %s\n", result_buf); - return(result); - } - - strcpy((char *)channel_name.value, channel); - channel_name.length = strlen(channel); - do { - result = saEvtChannelUnlink(handle, &channel_name); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: channel unlink result: %s\n", result_buf); - } - - do { - result = saEvtFinalize(handle); - } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT)); - if (result != SA_AIS_OK) { - get_sa_error(result, result_buf, result_buf_len); - printf("ERROR: Event Finalize result: %s\n", result_buf); - } - return 0; -} - -int main (int argc, char **argv) -{ - static const char opts[] = "c:"; - - int option; - - while (1) { - option = getopt(argc, argv, opts); - if (option == -1) - break; - - switch (option) { - - case 'c': - strcpy(channel, optarg); - break; - default: - printf("invalid arg: \"%s\"\n", optarg); - return 1; - } - } - do_unlink(); - - return 0; -} diff --git a/corosync/services/Makefile b/services/Makefile similarity index 100% rename from corosync/services/Makefile rename to services/Makefile diff --git a/corosync/services/cfg.c b/services/cfg.c similarity index 100% rename from corosync/services/cfg.c rename to services/cfg.c diff --git a/corosync/services/confdb.c b/services/confdb.c similarity index 100% rename from corosync/services/confdb.c rename to services/confdb.c diff --git a/corosync/services/cpg.c b/services/cpg.c similarity index 100% rename from corosync/services/cpg.c rename to services/cpg.c diff --git a/corosync/services/evs.c b/services/evs.c similarity index 100% rename from corosync/services/evs.c rename to services/evs.c diff --git a/corosync/test/Makefile b/test/Makefile similarity index 100% rename from corosync/test/Makefile rename to test/Makefile diff --git a/corosync/test/cpgbench.c b/test/cpgbench.c similarity index 100% rename from corosync/test/cpgbench.c rename to test/cpgbench.c diff --git a/corosync/test/evsbench.c b/test/evsbench.c similarity index 100% rename from corosync/test/evsbench.c rename to test/evsbench.c diff --git a/corosync/test/logsys_s.c b/test/logsys_s.c similarity index 100% rename from corosync/test/logsys_s.c rename to test/logsys_s.c diff --git a/corosync/test/logsys_s1.c b/test/logsys_s1.c similarity index 100% rename from corosync/test/logsys_s1.c rename to test/logsys_s1.c diff --git a/corosync/test/logsys_s2.c b/test/logsys_s2.c similarity index 100% rename from corosync/test/logsys_s2.c rename to test/logsys_s2.c diff --git a/corosync/test/logsys_t1.c b/test/logsys_t1.c similarity index 100% rename from corosync/test/logsys_t1.c rename to test/logsys_t1.c diff --git a/corosync/test/logsys_t2.c b/test/logsys_t2.c similarity index 100% rename from corosync/test/logsys_t2.c rename to test/logsys_t2.c diff --git a/corosync/test/sa_error.c b/test/sa_error.c similarity index 100% rename from corosync/test/sa_error.c rename to test/sa_error.c diff --git a/corosync/test/sa_error.h b/test/sa_error.h similarity index 100% rename from corosync/test/sa_error.h rename to test/sa_error.h diff --git a/corosync/test/scripts/spam b/test/scripts/spam similarity index 100% rename from corosync/test/scripts/spam rename to test/scripts/spam diff --git a/corosync/test/scripts/spam2 b/test/scripts/spam2 similarity index 100% rename from corosync/test/scripts/spam2 rename to test/scripts/spam2 diff --git a/corosync/test/testconfdb.c b/test/testconfdb.c similarity index 100% rename from corosync/test/testconfdb.c rename to test/testconfdb.c diff --git a/corosync/test/testcpg.c b/test/testcpg.c similarity index 100% rename from corosync/test/testcpg.c rename to test/testcpg.c diff --git a/corosync/test/testcpg2.c b/test/testcpg2.c similarity index 100% rename from corosync/test/testcpg2.c rename to test/testcpg2.c diff --git a/corosync/test/testevs.c b/test/testevs.c similarity index 100% rename from corosync/test/testevs.c rename to test/testevs.c diff --git a/corosync/test/testevsth.c b/test/testevsth.c similarity index 100% rename from corosync/test/testevsth.c rename to test/testevsth.c diff --git a/corosync/test/testmake.sh b/test/testmake.sh similarity index 100% rename from corosync/test/testmake.sh rename to test/testmake.sh diff --git a/corosync/test/testparse.c b/test/testparse.c similarity index 100% rename from corosync/test/testparse.c rename to test/testparse.c diff --git a/corosync/test/testtimer.c b/test/testtimer.c similarity index 100% rename from corosync/test/testtimer.c rename to test/testtimer.c diff --git a/corosync/tools/Makefile b/tools/Makefile similarity index 100% rename from corosync/tools/Makefile rename to tools/Makefile diff --git a/corosync/tools/corosync-cfgtool.c b/tools/corosync-cfgtool.c similarity index 100% rename from corosync/tools/corosync-cfgtool.c rename to tools/corosync-cfgtool.c diff --git a/corosync/tools/corosync-objctl.c b/tools/corosync-objctl.c similarity index 100% rename from corosync/tools/corosync-objctl.c rename to tools/corosync-objctl.c diff --git a/corosync/tools/keygen.c b/tools/keygen.c similarity index 100% rename from corosync/tools/keygen.c rename to tools/keygen.c