Hi Canh,
Such a problem was fixed in #1818 (may be in part) and current tests in
tests/ntfsv case does not reproduce it.
Will the test case provided in this patch reproduce the problem if the
fix is not applied?
Thanks,
Praveen
On 01-Sep-16 3:12 PM, Canh Van Truong wrote:
> osaf/libs/agents/saf/ntfa/ntfa_api.c | 1 +
> osaf/libs/agents/saf/ntfa/ntfa_util.c | 19 ++++++++---------
> tests/ntfsv/tet_saNtfFinalize.c | 36
> ++++++++++++++++++++++++++++++++--
> 3 files changed, 43 insertions(+), 13 deletions(-)
>
>
> Currently, when finalizing the last client, ntfa uninstall MDS connection.
> This causes that the NCSMDS_DOWN event will be sent to ntfs. ntfs will remove
> all clients that relates to this MDS.
> But if we initializes new client immediately after finalizing, ntfs may
> reviece
> the message of initialization before message of NCSMDS_DOWN event. This cause
> new
> client will be removed without finalizing and all action will be failed after
> that.
>
> This patch fixes that ntfa keep MDS connection when last client finalized, and
> re-use it when next initializing call.
>
> diff --git a/osaf/libs/agents/saf/ntfa/ntfa_api.c
> b/osaf/libs/agents/saf/ntfa/ntfa_api.c
> --- a/osaf/libs/agents/saf/ntfa/ntfa_api.c
> +++ b/osaf/libs/agents/saf/ntfa/ntfa_api.c
> @@ -35,6 +35,7 @@
> ntfa_cb_t ntfa_cb = {
> .cb_lock = PTHREAD_MUTEX_INITIALIZER,
> .ntfa_ntfsv_state = NTFA_NTFSV_NONE,
> + .mds_hdl = 0,
> };
>
> /* list of subscriptions for this process */
> diff --git a/osaf/libs/agents/saf/ntfa/ntfa_util.c
> b/osaf/libs/agents/saf/ntfa/ntfa_util.c
> --- a/osaf/libs/agents/saf/ntfa/ntfa_util.c
> +++ b/osaf/libs/agents/saf/ntfa/ntfa_util.c
> @@ -25,7 +25,7 @@
>
> /* Variables used during startup/shutdown only */
> static pthread_mutex_t ntfa_lock = PTHREAD_MUTEX_INITIALIZER;
> -static unsigned int ntfa_use_count;
> +static unsigned int ntfa_use_count = 0;
>
> /**
> *
> @@ -604,21 +604,20 @@ unsigned int ntfa_startup(void)
> pthread_mutex_lock(&ntfa_lock);
>
> TRACE_ENTER2("ntfa_use_count: %u", ntfa_use_count);
> - if (ntfa_use_count > 0) {
> - /* Already created, just increment the use_count */
> - ntfa_use_count++;
> - goto done;
> - } else {
> + if (ntfa_cb.mds_hdl == 0) {
> if ((rc = ncs_agents_startup()) != NCSCC_RC_SUCCESS) {
> TRACE("ncs_agents_startup FAILED");
> goto done;
> }
>
> if ((rc = ntfa_create()) != NCSCC_RC_SUCCESS) {
> + ntfa_cb.mds_hdl = 0;
> ncs_agents_shutdown();
> goto done;
> } else
> ntfa_use_count = 1;
> + } else {
> + ntfa_use_count++;
> }
>
> done:
> @@ -639,14 +638,14 @@ unsigned int ntfa_shutdown(bool forced)
> TRACE_ENTER2("ntfa_use_count: %u, forced: %u", ntfa_use_count, forced);
> pthread_mutex_lock(&ntfa_lock);
>
> - if ((forced && (ntfa_use_count > 0)) || (ntfa_use_count == 1)) {
> + if (ntfa_use_count > 0) {
> + /* Decrement the use count */
> + ntfa_use_count--;
> + } else if (forced) {
> ntfa_destroy();
> rc = ncs_agents_shutdown();
> ntfa_use_count = 0;
> ntfa_cb.ntfa_ntfsv_state = NTFA_NTFSV_NONE;
> - } else if (ntfa_use_count > 1) {
> - /* Users still exist, just decrement the use count */
> - ntfa_use_count--;
> }
>
> pthread_mutex_unlock(&ntfa_lock);
> diff --git a/tests/ntfsv/tet_saNtfFinalize.c b/tests/ntfsv/tet_saNtfFinalize.c
> --- a/tests/ntfsv/tet_saNtfFinalize.c
> +++ b/tests/ntfsv/tet_saNtfFinalize.c
> @@ -42,7 +42,7 @@ void saNtfFinalize_03(void)
> test_validate(rc, SA_AIS_ERR_BAD_HANDLE);
> }
>
> -SaAisErrorT subscribe()
> +SaAisErrorT subscribe(SaNtfSubscriptionIdT subscriptionId)
> {
> SaAisErrorT ret;
> SaNtfObjectCreateDeleteNotificationFilterT obcf;
> @@ -54,7 +54,7 @@ SaAisErrorT subscribe()
> obcf.notificationFilterHeader.notificationClassIds->majorId = 222;
> obcf.notificationFilterHeader.notificationClassIds->minorId = 222;
> FilterHandles.objectCreateDeleteFilterHandle =
> obcf.notificationFilterHandle;
> - ret = saNtfNotificationSubscribe(&FilterHandles, 111);
> + ret = saNtfNotificationSubscribe(&FilterHandles, subscriptionId);
> return ret;
> }
>
> @@ -69,7 +69,7 @@ void saNtfFinalize_04()
> {
> SaAisErrorT ret1, ret2;
> safassert(saNtfInitialize(&ntfHandle, &ntfCallbacks, &ntfVersion),
> SA_AIS_OK);
> - safassert(subscribe(),SA_AIS_OK);
> + safassert(subscribe(111),SA_AIS_OK);
> pthread_t thread;
> pthread_create(&thread, NULL, unsubscribe, (void *) &ret2);
> usleep(1);
> @@ -144,6 +144,35 @@ void saNtfFinalize_05()
>
> }
>
> +void saNtfFinalize_06()
> +{
> + SaAisErrorT ret;
> + unsigned int count = 100;
> + for (int i = 0; i < count; i++) {
> + ret = saNtfInitialize(&ntfHandle, &ntfCallbacks, &ntfVersion);
> + if (ret != SA_AIS_OK) {
> + fprintf(stderr, " saNtfInitialize failed rc = %d \n", (int)ret);
> + break;
> + }
> + ret = subscribe(206);
> + if (ret != SA_AIS_OK) {
> + fprintf(stderr, " subscribe failed rc = %d \n", (int)ret);
> + break;
> + }
> + ret = saNtfNotificationUnsubscribe(206);
> + if (ret != SA_AIS_OK) {
> + fprintf(stderr, " saNtfNotificationUnsubscribe failed rc = %d
> \n", (int)ret);
> + break;
> + }
> + ret = saNtfFinalize(ntfHandle);
> + if (ret != SA_AIS_OK) {
> + fprintf(stderr, " saNtfFinalize failed rc = %d \n", (int)ret);
> + break;
> + }
> + }
> + test_validate(ret, SA_AIS_OK);
> +}
> +
> __attribute__ ((constructor)) static void saNtfFinalize_constructor(void)
> {
> test_suite_add(2, "Life cycle, finalize, API 2");
> @@ -152,5 +181,6 @@ void saNtfFinalize_05()
> test_case_add(2, saNtfFinalize_03, "saNtfFinalize SA_AIS_ERR_BAD_HANDLE
> - handle already returned");
> test_case_add(2, saNtfFinalize_04, "Finalize and Unsubscribe in parallel
> SA_AIS_OK");
> test_case_add(2, saNtfFinalize_05, "Finalize and
> saNtfStateChangeNotificationAllocate in parallel SA_AIS_OK");
> + test_case_add(2, saNtfFinalize_06, "Initialize/Finalize in multiple
> times SA_AIS_OK");
> }
>
>
------------------------------------------------------------------------------
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel