Hi Canh This patch Ack Will continue reviewing patch 2
Thanks Lennart > -----Original Message----- > From: Canh Van Truong [mailto:canh.v.tru...@dektech.com.au] > Sent: den 16 februari 2017 07:49 > To: Lennart Lund <lennart.l...@ericsson.com>; Vu Minh Nguyen > <vu.m.ngu...@dektech.com.au>; mahesh.va...@oracle.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: [PATCH 3 of 3] log: fix checking version in log agent [#2146] > > src/log/agent/lga_api.c | 58 > ++++++++++++++++++++++---- > src/log/apitest/tet_saLogFilterSetCallbackT.c | 53 > ++++++++++++++++++++++++ > src/log/apitest/tet_saLogInitialize.c | 24 +++++++++++ > 3 files changed, 126 insertions(+), 9 deletions(-) > > > Fix checking version in log agent > > The agent report highest supported version except getting ERR_VERSION > from > server. if agent get ERR_VERSION, it will set supported version to A.02.03 > > diff --git a/src/log/agent/lga_api.c b/src/log/agent/lga_api.c > --- a/src/log/agent/lga_api.c > +++ b/src/log/agent/lga_api.c > @@ -1,6 +1,7 @@ > /* -*- OpenSAF -*- > * > * (C) Copyright 2008 The OpenSAF Foundation > + * Copyright Ericsson AB 2008, 2017 - All Rights Reserved. > * > * This program is distributed in the hope that it will be useful, but > * WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY > @@ -73,6 +74,24 @@ static bool is_lgs_state(lgs_state_t sta > return rc; > } > > +/** > + * Check if the log version is valid > + * @param version > + * @param client_ver > + * > + * @return true if log version is valid > + */ > +static bool is_log_version_valid(const SaVersionT *ver) { > + bool rc = false; > + if ((ver->releaseCode == LOG_RELEASE_CODE) && > + (ver->majorVersion <= LOG_MAJOR_VERSION) && > + (ver->majorVersion > 0) && > + (ver->minorVersion <= LOG_MINOR_VERSION)) { > + rc = true; > + } > + return rc; > +} > + > static void populate_open_params(lgsv_stream_open_req_t *open_param, > const char *logStreamName, > lga_client_hdl_rec_t *hdl_rec, > @@ -151,6 +170,7 @@ SaAisErrorT saLogInitialize(SaLogHandleT > int rc; > uint32_t client_id = 0; > bool is_locked = false; > + SaVersionT client_ver; > > TRACE_ENTER(); > > @@ -161,11 +181,18 @@ SaAisErrorT saLogInitialize(SaLogHandleT > goto done; > } > > - /* validate the version */ > - if ((version->releaseCode == LOG_RELEASE_CODE) && (version- > >majorVersion <= LOG_MAJOR_VERSION)) { > + /*** > + * Validate the version > + * Store client version that will be sent to log server. In case minor > + * version has not set, it is set to 1 > + * Update the [out] version to highest supported version in log agent > + */ > + if (is_log_version_valid(version)) { > + client_ver = *version; > + if (version->minorVersion < LOG_MINOR_VERSION_0) > + client_ver.minorVersion = LOG_MINOR_VERSION_0; > version->majorVersion = LOG_MAJOR_VERSION; > - if (version->minorVersion != LOG_MINOR_VERSION_0) > - version->minorVersion = LOG_MINOR_VERSION; > + version->minorVersion = LOG_MINOR_VERSION; > } else { > TRACE("version FAILED, required: %c.%u.%u, supported: > %c.%u.%u\n", > version->releaseCode, version->majorVersion, version- > >minorVersion, > @@ -230,7 +257,7 @@ SaAisErrorT saLogInitialize(SaLogHandleT > memset(&i_msg, 0, sizeof(lgsv_msg_t)); > i_msg.type = LGSV_LGA_API_MSG; > i_msg.info.api_info.type = LGSV_INITIALIZE_REQ; > - i_msg.info.api_info.param.init.version = *version; > + i_msg.info.api_info.param.init.version = client_ver; > > /* Send a message to LGS to obtain a client_id/server ref id which is > cluster > * wide unique. > @@ -242,10 +269,23 @@ SaAisErrorT saLogInitialize(SaLogHandleT > goto done; > } > > - /** Make sure the LGS return status was SA_AIS_OK > - **/ > + /* > + * Make sure the LGS return status was SA_AIS_OK > + * If the returned status was SA_AIS_ERR_VERSION, the [out] > version is > + * updated to highest supported version in log server. But now the > log > + * server has not returned the highest version in the response. Here > is > + * temporary updating [out] version to A.02.03. > + * TODO: This may be fixed to update the highest version when log > server > + * return the response with version. > + */ > ais_rc = o_msg->info.api_resp_info.rc; > - if (SA_AIS_OK != ais_rc) { > + if (ais_rc == SA_AIS_ERR_VERSION) { > + TRACE("%s LGS error response %s", __FUNCTION__, > saf_error(ais_rc)); > + version->releaseCode = LOG_RELEASE_CODE_1; > + version->majorVersion = LOG_RELEASE_CODE_1; > + version->minorVersion = LOG_RELEASE_CODE_1; > + goto err; > + } else if (SA_AIS_OK != ais_rc) { > TRACE("%s LGS error response %s", __FUNCTION__, > saf_error(ais_rc)); > goto err; > } > @@ -265,7 +305,7 @@ SaAisErrorT saLogInitialize(SaLogHandleT > > /* pass the handle value to the appl */ > *logHandle = lga_hdl_rec->local_hdl; > - lga_hdl_rec->version = *version; > + lga_hdl_rec->version = client_ver; > > err: > /* free up the response message */ > diff --git a/src/log/apitest/tet_saLogFilterSetCallbackT.c > b/src/log/apitest/tet_saLogFilterSetCallbackT.c > --- a/src/log/apitest/tet_saLogFilterSetCallbackT.c > +++ b/src/log/apitest/tet_saLogFilterSetCallbackT.c > @@ -376,6 +376,58 @@ done: > systemCall(command); > } > > +void saLogFilterSetCallbackT_05(void) > +{ > + int ret; > + SaAisErrorT rc; > + struct pollfd fds[1]; > + char command[MAX_DATA]; > + const unsigned int serverity_filter = 7; > + > + SaVersionT old_version = { 'A', 0x02, 0x02 }; > + logCallbacks.saLogFilterSetCallback = logFilterSetCallbackT; > + rc = saLogInitialize(&logHandle, &logCallbacks, &old_version); > + if (rc != SA_AIS_OK) { > + test_validate(rc, SA_AIS_OK); > + return; > + } > + > + rc = saLogSelectionObjectGet(logHandle, &selectionObject); > + if (rc != SA_AIS_OK) { > + test_validate(rc, SA_AIS_OK); > + goto done; > + } > + > + rc = logAppStreamOpen(&app1StreamName, > &appStreamLogFileCreateAttributes); > + if (rc != SA_AIS_OK) { > + test_validate(rc, SA_AIS_OK); > + goto done; > + } > + > + cb_index = 0; > + sprintf(command, "immadm -o 1 -p > saLogStreamSeverityFilter:SA_UINT32_T:%u %s 2> /dev/null", > + serverity_filter, SA_LOG_STREAM_APPLICATION1); > + ret = systemCall(command); > + if (ret != 0) { > + rc_validate(ret, 0); > + goto done; > + } > + > + fds[0].fd = (int) selectionObject; > + fds[0].events = POLLIN; > + ret = poll(fds, 1, 1000); > + if (ret == 1) { > + fprintf(stderr, " poll log callback failed: %d \n", ret); > + rc_validate(ret, 0); > + goto done; > + } else { > + rc_validate(0, 0);; > + } > + > +done: > + logCallbacks.saLogFilterSetCallback = NULL; > + logFinalize(); > +} > > __attribute__ ((constructor)) static void > saLibraryLifeCycle_constructor(void) > { > @@ -384,4 +436,5 @@ done: > test_case_add(17, saLogFilterSetCallbackT_02, "saLogFilterSetCallbackT, > severity filter is changed for runtime stream"); > test_case_add(17, saLogFilterSetCallbackT_03, "saLogFilterSetCallbackT, > severity filter is changed for runtime & cfg streams"); > test_case_add(17, saLogFilterSetCallbackT_04, "saLogFilterSetCallbackT, > after closing stream"); > + test_case_add(17, saLogFilterSetCallbackT_05, "saLogFilterSetCallbackT, > if > client initialize with version < A.02.03, ER"); > } > diff --git a/src/log/apitest/tet_saLogInitialize.c > b/src/log/apitest/tet_saLogInitialize.c > --- a/src/log/apitest/tet_saLogInitialize.c > +++ b/src/log/apitest/tet_saLogInitialize.c > @@ -1,6 +1,7 @@ > /* -*- OpenSAF -*- > * > * (C) Copyright 2008 The OpenSAF Foundation > + * Copyright Ericsson AB 2008, 2017 - All Rights Reserved. > * > * This program is distributed in the hope that it will be useful, but > * WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY > @@ -82,6 +83,27 @@ void saLogInitialize_09(void) > test_validate(rc, SA_AIS_ERR_VERSION); > } > > +void saLogInitialize_10(void) > +{ > + SaVersionT version = logVersion; > + > + version.minorVersion = logVersion.minorVersion + 1; > + rc = saLogInitialize(&logHandle, &logCallbacks, &version); > + logFinalize(); > + > + test_validate(rc, SA_AIS_ERR_VERSION); > +} > + > +void saLogInitialize_11(void) > +{ > + SaVersionT version = {'A', 2}; > + > + rc = saLogInitialize(&logHandle, &logCallbacks, &version); > + logFinalize(); > + > + test_validate(rc, SA_AIS_OK); > +} > + > extern void saLogSelectionObjectGet_01(void); > extern void saLogSelectionObjectGet_02(void); > extern void saLogFinalize_01(void); > @@ -100,6 +122,8 @@ extern void saLogDispatch_01(void); > test_case_add(1, saLogInitialize_07, "saLogInitialize() with too high > release > level"); > test_case_add(1, saLogInitialize_08, "saLogInitialize() with minor > version > set to 1"); > test_case_add(1, saLogInitialize_09, "saLogInitialize() with major > version > set to 3"); > + test_case_add(1, saLogInitialize_10, "saLogInitialize() with minor > version > is set bigger than supported version"); > + test_case_add(1, saLogInitialize_11, "saLogInitialize() with minor > version > is not set"); > test_case_add(1, saLogSelectionObjectGet_01, > "saLogSelectionObjectGet() OK"); > test_case_add(1, saLogSelectionObjectGet_02, > "saLogSelectionObjectGet() with NULL log handle"); > test_case_add(1, saLogDispatch_01, "saLogDispatch() OK"); ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel