Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Vu Looks good, Ack Thanks Lennart > -Original Message- > From: Vu Minh Nguyen [mailto:vu.m.ngu...@dektech.com.au] > Sent: den 22 september 2016 09:17 > To: Lennart Lund ; mahesh.va...@oracle.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > osaf/services/saf/logsv/lgs/lgs_amf.cc| 29 --- > osaf/services/saf/logsv/lgs/lgs_config.cc | 10 ++--- > osaf/services/saf/logsv/lgs/lgs_evt.cc| 27 -- > osaf/services/saf/logsv/lgs/lgs_imm.cc| 56 ++--- > - > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 19 -- > osaf/services/saf/logsv/lgs/lgs_stream.cc | 48 ++- > -- > osaf/services/saf/logsv/lgs/lgs_stream.h | 2 +- > 7 files changed, 110 insertions(+), 81 deletions(-) > > > The `number of streams` refers to total existing log streams in cluster. > And `stream_array` is the database holding all existing log streams. > When interating all log streams, logsv first started at the index `number of > streams`, > if getting NULL, logsv considered that case as `no stream`. This is absolutely > wrong. > > This patch provides other way to iterate all log streams. > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > @@ -26,13 +26,13 @@ > > static void close_all_files() { >log_stream_t *stream; > - int num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > + > + // Iterate all existing log streams in cluster. > + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > +jstart = SA_FALSE; > if (log_stream_file_close(stream) != 0) >LOG_WA("Could not close file for stream %s", stream->name.c_str()); > - > -stream = log_stream_get_by_id(--num); >} > } > > @@ -52,7 +52,8 @@ static void close_all_files() { > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { >log_stream_t *stream; >SaAisErrorT error = SA_AIS_OK; > - int num; > + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > + uint32_t count = 0; > >TRACE_ENTER2("HA ACTIVE request"); > > @@ -65,15 +66,15 @@ static SaAisErrorT amf_active_state_hand >conf_runtime_obj_create(cb->immOiHandle); >lgs_start_gcfg_applier(); > > - /* check existing streams */ > - num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - if (!stream) > + // Iterate all existing log streams in cluster. > + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > +jstart = SA_FALSE; > +*stream->p_fd = -1; /* First Initialize fd */ > +count++; > + } > + > + if (count == 0) > LOG_ER("No streams exist!"); > - while (stream != NULL) { > -*stream->p_fd = -1; /* First Initialize fd */ > -stream = log_stream_get_by_id(--num); > - } > > done: >/* Update role independent of stream processing */ > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > @@ -458,7 +458,7 @@ int lgs_cfg_verify_root_dir(const std::s >int rc = 0; >log_stream_t *stream = NULL; >size_t n = root_str_in.size(); > - int num; > + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > >if (n > PATH_MAX) { > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > @@ -470,17 +470,15 @@ int lgs_cfg_verify_root_dir(const std::s > * Make sure that the path /rootPath/streamPath/ > * must not be larger than PATH_MAX. > */ > - num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + // Iterate all existing log streams in cluster. > + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > +jstart = SA_FALSE; > if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, > root_str_in) == false) { >TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); >rc = -1; >goto done; > } > - > -stream = log_stream_get_by_id(--num); >} > >if (lgs_path_is_writeable_dir_h(root_str_in) == false) { > diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc > b/osaf/services/saf/logsv/lgs/lgs_evt.cc > --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_evt.cc > @@ -532,14 +532,17 @@ static uint32_t proc_rda_cb_msg(lgsv_lgs > lgs_process_lga_down_list(); > > /* Check existing streams */ > -int num = get_number_of_streams(); > -stream = log_stream_get_by_id(--num); > -if (!stream) > +// Iterate all existing log streams in cluster. > +uint32_t count = 0; > +SaBoolT endloop =
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Vu, This patch looks optimal . ACK , not tested -AVM On 9/22/2016 12:47 PM, Vu Minh Nguyen wrote: > osaf/services/saf/logsv/lgs/lgs_amf.cc| 29 --- > osaf/services/saf/logsv/lgs/lgs_config.cc | 10 ++--- > osaf/services/saf/logsv/lgs/lgs_evt.cc| 27 -- > osaf/services/saf/logsv/lgs/lgs_imm.cc| 56 > ++ > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 19 -- > osaf/services/saf/logsv/lgs/lgs_stream.cc | 48 ++--- > osaf/services/saf/logsv/lgs/lgs_stream.h | 2 +- > 7 files changed, 110 insertions(+), 81 deletions(-) > > > The `number of streams` refers to total existing log streams in cluster. > And `stream_array` is the database holding all existing log streams. > When interating all log streams, logsv first started at the index `number of > streams`, > if getting NULL, logsv considered that case as `no stream`. This is > absolutely wrong. > > This patch provides other way to iterate all log streams. > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > @@ -26,13 +26,13 @@ > > static void close_all_files() { > log_stream_t *stream; > - int num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > + > + // Iterate all existing log streams in cluster. > + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > +jstart = SA_FALSE; > if (log_stream_file_close(stream) != 0) > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > - > -stream = log_stream_get_by_id(--num); > } > } > > @@ -52,7 +52,8 @@ static void close_all_files() { > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { > log_stream_t *stream; > SaAisErrorT error = SA_AIS_OK; > - int num; > + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > + uint32_t count = 0; > > TRACE_ENTER2("HA ACTIVE request"); > > @@ -65,15 +66,15 @@ static SaAisErrorT amf_active_state_hand > conf_runtime_obj_create(cb->immOiHandle); > lgs_start_gcfg_applier(); > > - /* check existing streams */ > - num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - if (!stream) > + // Iterate all existing log streams in cluster. > + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > +jstart = SA_FALSE; > +*stream->p_fd = -1; /* First Initialize fd */ > +count++; > + } > + > + if (count == 0) > LOG_ER("No streams exist!"); > - while (stream != NULL) { > -*stream->p_fd = -1; /* First Initialize fd */ > -stream = log_stream_get_by_id(--num); > - } > > done: > /* Update role independent of stream processing */ > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > @@ -458,7 +458,7 @@ int lgs_cfg_verify_root_dir(const std::s > int rc = 0; > log_stream_t *stream = NULL; > size_t n = root_str_in.size(); > - int num; > + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > > if (n > PATH_MAX) { > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > @@ -470,17 +470,15 @@ int lgs_cfg_verify_root_dir(const std::s > * Make sure that the path /rootPath/streamPath/ > * must not be larger than PATH_MAX. > */ > - num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + // Iterate all existing log streams in cluster. > + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > +jstart = SA_FALSE; > if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, > root_str_in) == false) { > TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); > rc = -1; > goto done; > } > - > -stream = log_stream_get_by_id(--num); > } > > if (lgs_path_is_writeable_dir_h(root_str_in) == false) { > diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc > b/osaf/services/saf/logsv/lgs/lgs_evt.cc > --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_evt.cc > @@ -532,14 +532,17 @@ static uint32_t proc_rda_cb_msg(lgsv_lgs > lgs_process_lga_down_list(); > > /* Check existing streams */ > -int num = get_number_of_streams(); > -stream = log_stream_get_by_id(--num); > -if (!stream) > +// Iterate all existing log streams in cluster. > +uint32_t count = 0; > +SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; > +while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { > + jstart = SA_FALSE; > + *stream->p_fd = -1; /
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Thanks Mahesh, and Lennart. I just send V3 patch. Please have a look. Thanks. Regards, Vu > -Original Message- > From: A V Mahesh [mailto:mahesh.va...@oracle.com] > Sent: Thursday, September 22, 2016 11:34 AM > To: Vu Minh Nguyen ; > lennart.l...@ericsson.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: Re: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > Hi Vu, > > Still we can convert this below logic to a function which is use in > multiple places > > like log_stream_get_next_by_id() > > === > > /* Check existing streams */ > uint32_t count = 0, stream_id = 0, max = 0; > uint32_t num = get_number_of_streams(); > max = get_max_number_of_streams(); > while (count < num && stream_id < max) { >stream = log_stream_get_by_id(stream_id++); >if (stream == nullptr) continue; > > = > > -AVM > > > On 9/21/2016 3:38 PM, Vu Minh Nguyen wrote: > > osaf/services/saf/logsv/lgs/lgs_amf.cc| 34 ++- > > osaf/services/saf/logsv/lgs/lgs_config.cc | 12 +++-- > > osaf/services/saf/logsv/lgs/lgs_evt.cc| 31 +- > > osaf/services/saf/logsv/lgs/lgs_imm.cc| 63 +++- > -- > > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 29 + > > osaf/services/saf/logsv/lgs/lgs_stream.cc | 16 ++- > > osaf/services/saf/logsv/lgs/lgs_stream.h | 3 +- > > 7 files changed, 123 insertions(+), 65 deletions(-) > > > > > > The `number of streams` refers to total existing log streams in cluster. > > And `stream_array` is the database holding all existing log streams. > > When interating all log streams, logsv first started at the index `number of > streams`, > > if getting NULL, logsv considered that case as `no stream`. This is > absolutely wrong. > > > > This patch provides other way to iterate all log streams. > > > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > > @@ -26,13 +26,19 @@ > > > > static void close_all_files() { > > log_stream_t *stream; > > - int num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > - while (stream != NULL) { > > + uint32_t count = 0, stream_id = 0, max = 0, num = 0; > > + > > + num = get_number_of_streams(); > > + max = get_max_number_of_streams(); > > + // Iterate all existing log streams in cluster > > + // the condition `stream_id < max` to avoid blocking > > + while (count < num && stream_id < max) { > > +stream = log_stream_get_by_id(stream_id++); > > +if (stream == nullptr) continue; > > + > > +count++; > > if (log_stream_file_close(stream) != 0) > > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > > - > > -stream = log_stream_get_by_id(--num); > > } > > } > > > > @@ -52,7 +58,7 @@ static void close_all_files() { > > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { > > log_stream_t *stream; > > SaAisErrorT error = SA_AIS_OK; > > - int num; > > + uint32_t count = 0, stream_id = 0, max = 0, num = 0; > > > > TRACE_ENTER2("HA ACTIVE request"); > > > > @@ -67,13 +73,17 @@ static SaAisErrorT amf_active_state_hand > > > > /* check existing streams */ > > num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > - if (!stream) > > + max = get_max_number_of_streams(); > > + while (count < num && stream_id < max) { > > +stream = log_stream_get_by_id(stream_id++); > > +if (stream == nullptr) continue; > > + > > +count++; > > +*stream->p_fd = -1; /* First Initialize fd */ > > + } > > + > > + if (count == 0) > > LOG_ER("No streams exist!"); > > - while (stream != NULL) { > > -*stream->p_fd = -1; /* First Initialize fd */ > > -stream = log_stream_get_by_id(--num); > > - } > > > > done: > > /* Update role independent of stream processing */ > > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > > @@ -458,7 +458,7 @@ int lgs_cfg_verify_root_dir(const std::s > > int rc = 0; > > log_stream_t *stream = NULL; > > size_t n = root_str_in.size(); > > - int num; > > + uint32_t count = 0, stream_id = 0, max = 0, num = 0; > > > > if (n > PATH_MAX) { > > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > > @@ -471,16 +471,18 @@ int lgs_cfg_verify_root_dir(const std::s > > * must not be larger than PATH_MAX. > > */ > > num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > - while (stream != NULL) { > > + max = get_max_number_of_streams(); > > + while (count < num && stream_id < max) { > > +stream = log_stream_get_by_id(stream_id++);
[devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
osaf/services/saf/logsv/lgs/lgs_amf.cc| 29 --- osaf/services/saf/logsv/lgs/lgs_config.cc | 10 ++--- osaf/services/saf/logsv/lgs/lgs_evt.cc| 27 -- osaf/services/saf/logsv/lgs/lgs_imm.cc| 56 ++ osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 19 -- osaf/services/saf/logsv/lgs/lgs_stream.cc | 48 ++--- osaf/services/saf/logsv/lgs/lgs_stream.h | 2 +- 7 files changed, 110 insertions(+), 81 deletions(-) The `number of streams` refers to total existing log streams in cluster. And `stream_array` is the database holding all existing log streams. When interating all log streams, logsv first started at the index `number of streams`, if getting NULL, logsv considered that case as `no stream`. This is absolutely wrong. This patch provides other way to iterate all log streams. diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc b/osaf/services/saf/logsv/lgs/lgs_amf.cc --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc @@ -26,13 +26,13 @@ static void close_all_files() { log_stream_t *stream; - int num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - while (stream != NULL) { + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; + + // Iterate all existing log streams in cluster. + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { +jstart = SA_FALSE; if (log_stream_file_close(stream) != 0) LOG_WA("Could not close file for stream %s", stream->name.c_str()); - -stream = log_stream_get_by_id(--num); } } @@ -52,7 +52,8 @@ static void close_all_files() { static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT invocation) { log_stream_t *stream; SaAisErrorT error = SA_AIS_OK; - int num; + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; + uint32_t count = 0; TRACE_ENTER2("HA ACTIVE request"); @@ -65,15 +66,15 @@ static SaAisErrorT amf_active_state_hand conf_runtime_obj_create(cb->immOiHandle); lgs_start_gcfg_applier(); - /* check existing streams */ - num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - if (!stream) + // Iterate all existing log streams in cluster. + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { +jstart = SA_FALSE; +*stream->p_fd = -1; /* First Initialize fd */ +count++; + } + + if (count == 0) LOG_ER("No streams exist!"); - while (stream != NULL) { -*stream->p_fd = -1; /* First Initialize fd */ -stream = log_stream_get_by_id(--num); - } done: /* Update role independent of stream processing */ diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc b/osaf/services/saf/logsv/lgs/lgs_config.cc --- a/osaf/services/saf/logsv/lgs/lgs_config.cc +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc @@ -458,7 +458,7 @@ int lgs_cfg_verify_root_dir(const std::s int rc = 0; log_stream_t *stream = NULL; size_t n = root_str_in.size(); - int num; + SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; if (n > PATH_MAX) { LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); @@ -470,17 +470,15 @@ int lgs_cfg_verify_root_dir(const std::s * Make sure that the path /rootPath/streamPath/ * must not be larger than PATH_MAX. */ - num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - while (stream != NULL) { + // Iterate all existing log streams in cluster. + while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { +jstart = SA_FALSE; if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, root_str_in) == false) { TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); rc = -1; goto done; } - -stream = log_stream_get_by_id(--num); } if (lgs_path_is_writeable_dir_h(root_str_in) == false) { diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc b/osaf/services/saf/logsv/lgs/lgs_evt.cc --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc +++ b/osaf/services/saf/logsv/lgs/lgs_evt.cc @@ -532,14 +532,17 @@ static uint32_t proc_rda_cb_msg(lgsv_lgs lgs_process_lga_down_list(); /* Check existing streams */ -int num = get_number_of_streams(); -stream = log_stream_get_by_id(--num); -if (!stream) +// Iterate all existing log streams in cluster. +uint32_t count = 0; +SaBoolT endloop = SA_FALSE, jstart = SA_TRUE; +while ((stream = iterate_all_streams(endloop, jstart)) && !endloop) { + jstart = SA_FALSE; + *stream->p_fd = -1; /* Initialize fd */ + count++; +} + +if (count == 0) LOG_ER("No streams exist!"); -while (stream != NULL) { - *stream->p_fd = -1; /* Initialize fd */ - stream = log_stream_get_by_id(--num); -} } TRACE_LEAVE(); @@ -800,7 +803,8 @@ SaAisErrorT create_new_app_stream(lgsv_s SaBoolT twelveHourModeFlag; SaUint32T logMaxLogrecsize_conf = 0; SaConstStringT str_na
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Vu, Still we can convert this below logic to a function which is use in multiple places like log_stream_get_next_by_id() === /* Check existing streams */ uint32_t count = 0, stream_id = 0, max = 0; uint32_t num = get_number_of_streams(); max = get_max_number_of_streams(); while (count < num && stream_id < max) { stream = log_stream_get_by_id(stream_id++); if (stream == nullptr) continue; = -AVM On 9/21/2016 3:38 PM, Vu Minh Nguyen wrote: > osaf/services/saf/logsv/lgs/lgs_amf.cc| 34 ++- > osaf/services/saf/logsv/lgs/lgs_config.cc | 12 +++-- > osaf/services/saf/logsv/lgs/lgs_evt.cc| 31 +- > osaf/services/saf/logsv/lgs/lgs_imm.cc| 63 > +++--- > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 29 + > osaf/services/saf/logsv/lgs/lgs_stream.cc | 16 ++- > osaf/services/saf/logsv/lgs/lgs_stream.h | 3 +- > 7 files changed, 123 insertions(+), 65 deletions(-) > > > The `number of streams` refers to total existing log streams in cluster. > And `stream_array` is the database holding all existing log streams. > When interating all log streams, logsv first started at the index `number of > streams`, > if getting NULL, logsv considered that case as `no stream`. This is > absolutely wrong. > > This patch provides other way to iterate all log streams. > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > @@ -26,13 +26,19 @@ > > static void close_all_files() { > log_stream_t *stream; > - int num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + uint32_t count = 0, stream_id = 0, max = 0, num = 0; > + > + num = get_number_of_streams(); > + max = get_max_number_of_streams(); > + // Iterate all existing log streams in cluster > + // the condition `stream_id < max` to avoid blocking > + while (count < num && stream_id < max) { > +stream = log_stream_get_by_id(stream_id++); > +if (stream == nullptr) continue; > + > +count++; > if (log_stream_file_close(stream) != 0) > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > - > -stream = log_stream_get_by_id(--num); > } > } > > @@ -52,7 +58,7 @@ static void close_all_files() { > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { > log_stream_t *stream; > SaAisErrorT error = SA_AIS_OK; > - int num; > + uint32_t count = 0, stream_id = 0, max = 0, num = 0; > > TRACE_ENTER2("HA ACTIVE request"); > > @@ -67,13 +73,17 @@ static SaAisErrorT amf_active_state_hand > > /* check existing streams */ > num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - if (!stream) > + max = get_max_number_of_streams(); > + while (count < num && stream_id < max) { > +stream = log_stream_get_by_id(stream_id++); > +if (stream == nullptr) continue; > + > +count++; > +*stream->p_fd = -1; /* First Initialize fd */ > + } > + > + if (count == 0) > LOG_ER("No streams exist!"); > - while (stream != NULL) { > -*stream->p_fd = -1; /* First Initialize fd */ > -stream = log_stream_get_by_id(--num); > - } > > done: > /* Update role independent of stream processing */ > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > @@ -458,7 +458,7 @@ int lgs_cfg_verify_root_dir(const std::s > int rc = 0; > log_stream_t *stream = NULL; > size_t n = root_str_in.size(); > - int num; > + uint32_t count = 0, stream_id = 0, max = 0, num = 0; > > if (n > PATH_MAX) { > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > @@ -471,16 +471,18 @@ int lgs_cfg_verify_root_dir(const std::s > * must not be larger than PATH_MAX. > */ > num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + max = get_max_number_of_streams(); > + while (count < num && stream_id < max) { > +stream = log_stream_get_by_id(stream_id++); > +if (stream == nullptr) continue; > + > +count++; > if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, > root_str_in) == false) { > TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); > rc = -1; > goto done; > } > - > -stream = log_stream_get_by_id(--num); > } > > if (lgs_path_is_writeable_dir_h(root_str_in) == false) { > diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc > b/osaf/services/saf/logsv/lgs/lgs_evt.cc > --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc > +++ b/osaf/services/saf
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Lennart, Thanks for your comments. Yesterday, I sent out the V2 patch as attached. Can you have a look to see it could cover your comments #1 and #3? I will handle your comment #2 before pushing the code. Regards, Vu > -Original Message- > From: Lennart Lund [mailto:lennart.l...@ericsson.com] > Sent: Wednesday, September 21, 2016 9:49 PM > To: Vu Minh Nguyen ; > mahesh.va...@oracle.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: RE: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > Hi Vu > > I have a few comments. There are no comments inline. > > 1) > In several places the following (or almost the same)code can be found: > > uint32_t count = 0, stream_id = 0; > uint32_t num = get_number_of_streams(); > stream = log_stream_get_by_id(stream_id); > while (count < num) { > if (stream == nullptr) goto next; > > count++; > if (log_stream_file_close(stream) != 0) > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > > next: > stream = log_stream_get_by_id(++stream_id); > } > > The while loop could look like: > - > -- > while (count < num) { > if (stream == nullptr) { > stream = log_stream_get_by_id(stream_id); > stream_id++; > continue; > } > > count++; > if (log_stream_file_close(stream) != 0) > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > } > > 2) > Try to avoid more than one operation per code line. In this case separate > increasing the stream_id and getting the stream pointer. > > 3) > Since this code (or almost the same) can be found in several places a > common function could be created e.g. a function that could be used > to iterate over all existing streams and return the stream pointers > > Thanks > Lennart > > > -Original Message- > > From: Vu Minh Nguyen [mailto:vu.m.ngu...@dektech.com.au] > > Sent: den 19 september 2016 11:08 > > To: Lennart Lund ; mahesh.va...@oracle.com > > Cc: opensaf-devel@lists.sourceforge.net > > Subject: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > > > osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- > > osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- > > osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- > > osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 ++- > - > > -- > > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- > > osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- > > 6 files changed, 120 insertions(+), 51 deletions(-) > > > > > > The `number of streams` refers to total existing log streams in cluster. > > And `stream_array` is the database holding all existing log streams. > > When interating all log streams, logsv first started at the index `number of > > streams`, > > if getting NULL, logsv considered that case as `no stream`. This is > absolutely > > wrong. > > > > This patch provides other way to iterate all log streams. > > > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > > @@ -26,13 +26,18 @@ > > > > static void close_all_files() { > >log_stream_t *stream; > > - int num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > - while (stream != NULL) { > > + uint32_t count = 0, stream_id = 0; > > + uint32_t num = get_number_of_streams(); > > + stream = log_stream_get_by_id(stream_id); > > + while (count < num) { > > +if (stream == nullptr) goto next; > > + > > +count++; > > if (log_stream_file_close(stream) != 0) > >LOG_WA("Could not close file for stream %s", stream->name.c_str()); > > > > -stream = log_stream_get_by_id(--num); > > + next: > > +stream = log_stream_get_by_id(++stream_id); > >} > > } > > > > @@ -52,7 +57,8 @@ static void close_all_files() { > > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > > invocation) { > >log_stream_t *stream; > >SaAisErrorT error = SA_AIS_OK; > > - int num; > > + uint32_t num; > > + uint32_t count = 0, stream_id = 0; > > > >TRACE_ENTER2("HA ACTIVE request"); > > > > @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand > > > >/* check existing streams */ > >num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > + stream = log_stream_get_by_id(stream_id); > >if (!stream) > > LOG_ER("No streams exist!"); > > - while (stream != NULL) { > > + while (count < num) { > > +if (stream == nullptr) goto next; > > + > > +count++; > > *stream->p_fd = -1; /* First Initialize fd */ > > -stream = log_stream_get_by_id(--num); > > + > > + next: > > +stream = log_stream_get_by_id(++stream_id); > >} > > > > done: > > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Vu I have a few comments. There are no comments inline. 1) In several places the following (or almost the same)code can be found: uint32_t count = 0, stream_id = 0; uint32_t num = get_number_of_streams(); stream = log_stream_get_by_id(stream_id); while (count < num) { if (stream == nullptr) goto next; count++; if (log_stream_file_close(stream) != 0) LOG_WA("Could not close file for stream %s", stream->name.c_str()); next: stream = log_stream_get_by_id(++stream_id); } The while loop could look like: --- while (count < num) { if (stream == nullptr) { stream = log_stream_get_by_id(stream_id); stream_id++; continue; } count++; if (log_stream_file_close(stream) != 0) LOG_WA("Could not close file for stream %s", stream->name.c_str()); } 2) Try to avoid more than one operation per code line. In this case separate increasing the stream_id and getting the stream pointer. 3) Since this code (or almost the same) can be found in several places a common function could be created e.g. a function that could be used to iterate over all existing streams and return the stream pointers Thanks Lennart > -Original Message- > From: Vu Minh Nguyen [mailto:vu.m.ngu...@dektech.com.au] > Sent: den 19 september 2016 11:08 > To: Lennart Lund ; mahesh.va...@oracle.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- > osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- > osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- > osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 ++-- > -- > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- > osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- > 6 files changed, 120 insertions(+), 51 deletions(-) > > > The `number of streams` refers to total existing log streams in cluster. > And `stream_array` is the database holding all existing log streams. > When interating all log streams, logsv first started at the index `number of > streams`, > if getting NULL, logsv considered that case as `no stream`. This is absolutely > wrong. > > This patch provides other way to iterate all log streams. > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > @@ -26,13 +26,18 @@ > > static void close_all_files() { >log_stream_t *stream; > - int num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + uint32_t count = 0, stream_id = 0; > + uint32_t num = get_number_of_streams(); > + stream = log_stream_get_by_id(stream_id); > + while (count < num) { > +if (stream == nullptr) goto next; > + > +count++; > if (log_stream_file_close(stream) != 0) >LOG_WA("Could not close file for stream %s", stream->name.c_str()); > > -stream = log_stream_get_by_id(--num); > + next: > +stream = log_stream_get_by_id(++stream_id); >} > } > > @@ -52,7 +57,8 @@ static void close_all_files() { > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { >log_stream_t *stream; >SaAisErrorT error = SA_AIS_OK; > - int num; > + uint32_t num; > + uint32_t count = 0, stream_id = 0; > >TRACE_ENTER2("HA ACTIVE request"); > > @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand > >/* check existing streams */ >num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > + stream = log_stream_get_by_id(stream_id); >if (!stream) > LOG_ER("No streams exist!"); > - while (stream != NULL) { > + while (count < num) { > +if (stream == nullptr) goto next; > + > +count++; > *stream->p_fd = -1; /* First Initialize fd */ > -stream = log_stream_get_by_id(--num); > + > + next: > +stream = log_stream_get_by_id(++stream_id); >} > > done: > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > @@ -458,7 +458,8 @@ int lgs_cfg_verify_root_dir(const std::s >int rc = 0; >log_stream_t *stream = NULL; >size_t n = root_str_in.size(); > - int num; > + uint32_t num; > + uint32_t count = 0, stream_id = 0; > >if (n > PATH_MAX) { > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > @@ -471,8 +472,11 @@ int lgs_cfg_verify_root_dir(const std::s > * must not be larger than PATH_MAX. > */ >num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + stream = log_stream_get_by_id(stream_id); > + while (count < num) { > +if (stream == nullptr) goto ne
[devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
osaf/services/saf/logsv/lgs/lgs_amf.cc| 34 ++- osaf/services/saf/logsv/lgs/lgs_config.cc | 12 +++-- osaf/services/saf/logsv/lgs/lgs_evt.cc| 31 +- osaf/services/saf/logsv/lgs/lgs_imm.cc| 63 +++--- osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 29 + osaf/services/saf/logsv/lgs/lgs_stream.cc | 16 ++- osaf/services/saf/logsv/lgs/lgs_stream.h | 3 +- 7 files changed, 123 insertions(+), 65 deletions(-) The `number of streams` refers to total existing log streams in cluster. And `stream_array` is the database holding all existing log streams. When interating all log streams, logsv first started at the index `number of streams`, if getting NULL, logsv considered that case as `no stream`. This is absolutely wrong. This patch provides other way to iterate all log streams. diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc b/osaf/services/saf/logsv/lgs/lgs_amf.cc --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc @@ -26,13 +26,19 @@ static void close_all_files() { log_stream_t *stream; - int num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - while (stream != NULL) { + uint32_t count = 0, stream_id = 0, max = 0, num = 0; + + num = get_number_of_streams(); + max = get_max_number_of_streams(); + // Iterate all existing log streams in cluster + // the condition `stream_id < max` to avoid blocking + while (count < num && stream_id < max) { +stream = log_stream_get_by_id(stream_id++); +if (stream == nullptr) continue; + +count++; if (log_stream_file_close(stream) != 0) LOG_WA("Could not close file for stream %s", stream->name.c_str()); - -stream = log_stream_get_by_id(--num); } } @@ -52,7 +58,7 @@ static void close_all_files() { static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT invocation) { log_stream_t *stream; SaAisErrorT error = SA_AIS_OK; - int num; + uint32_t count = 0, stream_id = 0, max = 0, num = 0; TRACE_ENTER2("HA ACTIVE request"); @@ -67,13 +73,17 @@ static SaAisErrorT amf_active_state_hand /* check existing streams */ num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - if (!stream) + max = get_max_number_of_streams(); + while (count < num && stream_id < max) { +stream = log_stream_get_by_id(stream_id++); +if (stream == nullptr) continue; + +count++; +*stream->p_fd = -1; /* First Initialize fd */ + } + + if (count == 0) LOG_ER("No streams exist!"); - while (stream != NULL) { -*stream->p_fd = -1; /* First Initialize fd */ -stream = log_stream_get_by_id(--num); - } done: /* Update role independent of stream processing */ diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc b/osaf/services/saf/logsv/lgs/lgs_config.cc --- a/osaf/services/saf/logsv/lgs/lgs_config.cc +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc @@ -458,7 +458,7 @@ int lgs_cfg_verify_root_dir(const std::s int rc = 0; log_stream_t *stream = NULL; size_t n = root_str_in.size(); - int num; + uint32_t count = 0, stream_id = 0, max = 0, num = 0; if (n > PATH_MAX) { LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); @@ -471,16 +471,18 @@ int lgs_cfg_verify_root_dir(const std::s * must not be larger than PATH_MAX. */ num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - while (stream != NULL) { + max = get_max_number_of_streams(); + while (count < num && stream_id < max) { +stream = log_stream_get_by_id(stream_id++); +if (stream == nullptr) continue; + +count++; if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, root_str_in) == false) { TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); rc = -1; goto done; } - -stream = log_stream_get_by_id(--num); } if (lgs_path_is_writeable_dir_h(root_str_in) == false) { diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc b/osaf/services/saf/logsv/lgs/lgs_evt.cc --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc +++ b/osaf/services/saf/logsv/lgs/lgs_evt.cc @@ -532,14 +532,19 @@ static uint32_t proc_rda_cb_msg(lgsv_lgs lgs_process_lga_down_list(); /* Check existing streams */ -int num = get_number_of_streams(); -stream = log_stream_get_by_id(--num); -if (!stream) +uint32_t count = 0, stream_id = 0, max = 0; +uint32_t num = get_number_of_streams(); +max = get_max_number_of_streams(); +while (count < num && stream_id < max) { + stream = log_stream_get_by_id(stream_id++); + if (stream == nullptr) continue; + + count++; + *stream->p_fd = -1; /* Initialize fd */ +} + +if (count == 0) LOG_ER("No streams exist!"); -while (stream != NULL) { - *stream->p_fd = -1; /* Initialize fd */ - stream = log_stream_get_by_id(--num); -} } TRACE_LEAVE(); @@ -800,7 +805,8 @@
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
I will send the V2 patch soon. Regards, Vu > -Original Message- > From: A V Mahesh [mailto:mahesh.va...@oracle.com] > Sent: Wednesday, September 21, 2016 4:13 PM > To: Vu Minh Nguyen ; > lennart.l...@ericsson.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: Re: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > Hi VU, > > Try**to have function **log_stream_get_next_by_id(). > > -AVM > > On 9/21/2016 2:35 PM, Vu Minh Nguyen wrote: > > Hi Mahesh, > > > > I do think about it but not yet found out the better way. > > I can use the macro for this, somethings like > > GET { > > .. > > } NEXT; > > > > but it will violate the coding rule - avoid using the macro. > > > > I would appreciate if you have any proposal for this. Thanks. > > > > Regards, Vu > > > >> -Original Message- > >> From: A V Mahesh [mailto:mahesh.va...@oracle.com] > >> Sent: Wednesday, September 21, 2016 3:58 PM > >> To: Vu Minh Nguyen ; > >> lennart.l...@ericsson.com > >> Cc: opensaf-devel@lists.sourceforge.net > >> Subject: Re: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > >> > >> Hi Vu, > >> > >> You used this similar code logic number of time in multiple file in log > >> service code > >> > >> is it possibly to optimize this logic in single function , to make > >> maintainability of code , > >> > >> so that any bug fix will not trigger multiple places code changes > >> > >> > >> > >> /* Verify that path and file are unique */ > >> num = get_number_of_streams(); > >> stream = log_stream_get_by_id(stream_id); > >> while (count < num) { > >> if (stream == nullptr) goto next > >> > >> > >> > >> next: > >> stream = log_stream_get_by_id(++stream_id); > >> > >> === > >> > >> -AVM > >> > >> > >> On 9/19/2016 2:38 PM, Vu Minh Nguyen wrote: > >>>osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- > >>>osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- > >>>osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- > >>>osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 > >> ++ > >>>osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- > >>>osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- > >>>6 files changed, 120 insertions(+), 51 deletions(-) > >>> > >>> > >>> The `number of streams` refers to total existing log streams in cluster. > >>> And `stream_array` is the database holding all existing log streams. > >>> When interating all log streams, logsv first started at the index > > `number of > >> streams`, > >>> if getting NULL, logsv considered that case as `no stream`. This is > >> absolutely wrong. > >>> This patch provides other way to iterate all log streams. > >>> > >>> diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > >> b/osaf/services/saf/logsv/lgs/lgs_amf.cc > >>> --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > >>> +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > >>> @@ -26,13 +26,18 @@ > >>> > >>>static void close_all_files() { > >>> log_stream_t *stream; > >>> - int num = get_number_of_streams(); > >>> - stream = log_stream_get_by_id(--num); > >>> - while (stream != NULL) { > >>> + uint32_t count = 0, stream_id = 0; > >>> + uint32_t num = get_number_of_streams(); > >>> + stream = log_stream_get_by_id(stream_id); > >>> + while (count < num) { > >>> +if (stream == nullptr) goto next; > >>> + > >>> +count++; > >>>if (log_stream_file_close(stream) != 0) > >>> LOG_WA("Could not close file for stream %s", > > stream->name.c_str()); > >>> -stream = log_stream_get_by_id(--num); > >>> + next: > >>> +stream = log_stream_get_by_id(++stream_id); > >>> } > >>>} > >>> > >>> @@ -52,7 +57,8 @@ static void close_all_files() { > >>>static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, > > SaInvocationT > >> invocation) { > >>> log_stream_t *stream; > >>> SaAisErrorT error = SA_AIS_OK; > >>> - int num; > >>> + uint32_t num; > >>> + uint32_t count = 0, stream_id = 0; > >>> > >>> TRACE_ENTER2("HA ACTIVE request"); > >>> > >>> @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand > >>> > >>> /* check existing streams */ > >>> num = get_number_of_streams(); > >>> - stream = log_stream_get_by_id(--num); > >>> + stream = log_stream_get_by_id(stream_id); > >>> if (!stream) > >>>LOG_ER("No streams exist!"); > >>> - while (stream != NULL) { > >>> + while (count < num) { > >>> +if (stream == nullptr) goto next; > >>> + > >>> +count++; > >>>*stream->p_fd = -1; /* First Initialize fd */ > >>> -stream = log_stream_get_by_id(--num); > >>> + > >>> + next: > >>> +stream = log_stream_get_by_id(++stream_id); > >>> } > >>> > >>>done: > >>> diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > >> b/osaf/services/saf/logsv/lgs/lgs_config.cc
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi VU, Try**to have function **log_stream_get_next_by_id(). -AVM On 9/21/2016 2:35 PM, Vu Minh Nguyen wrote: > Hi Mahesh, > > I do think about it but not yet found out the better way. > I can use the macro for this, somethings like > GET { > .. > } NEXT; > > but it will violate the coding rule - avoid using the macro. > > I would appreciate if you have any proposal for this. Thanks. > > Regards, Vu > >> -Original Message- >> From: A V Mahesh [mailto:mahesh.va...@oracle.com] >> Sent: Wednesday, September 21, 2016 3:58 PM >> To: Vu Minh Nguyen ; >> lennart.l...@ericsson.com >> Cc: opensaf-devel@lists.sourceforge.net >> Subject: Re: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] >> >> Hi Vu, >> >> You used this similar code logic number of time in multiple file in log >> service code >> >> is it possibly to optimize this logic in single function , to make >> maintainability of code , >> >> so that any bug fix will not trigger multiple places code changes >> >> >> >> /* Verify that path and file are unique */ >> num = get_number_of_streams(); >> stream = log_stream_get_by_id(stream_id); >> while (count < num) { >> if (stream == nullptr) goto next >> >> >> >> next: >> stream = log_stream_get_by_id(++stream_id); >> >> === >> >> -AVM >> >> >> On 9/19/2016 2:38 PM, Vu Minh Nguyen wrote: >>>osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- >>>osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- >>>osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- >>>osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 >> ++ >>>osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- >>>osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- >>>6 files changed, 120 insertions(+), 51 deletions(-) >>> >>> >>> The `number of streams` refers to total existing log streams in cluster. >>> And `stream_array` is the database holding all existing log streams. >>> When interating all log streams, logsv first started at the index > `number of >> streams`, >>> if getting NULL, logsv considered that case as `no stream`. This is >> absolutely wrong. >>> This patch provides other way to iterate all log streams. >>> >>> diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc >> b/osaf/services/saf/logsv/lgs/lgs_amf.cc >>> --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc >>> +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc >>> @@ -26,13 +26,18 @@ >>> >>>static void close_all_files() { >>> log_stream_t *stream; >>> - int num = get_number_of_streams(); >>> - stream = log_stream_get_by_id(--num); >>> - while (stream != NULL) { >>> + uint32_t count = 0, stream_id = 0; >>> + uint32_t num = get_number_of_streams(); >>> + stream = log_stream_get_by_id(stream_id); >>> + while (count < num) { >>> +if (stream == nullptr) goto next; >>> + >>> +count++; >>>if (log_stream_file_close(stream) != 0) >>> LOG_WA("Could not close file for stream %s", > stream->name.c_str()); >>> -stream = log_stream_get_by_id(--num); >>> + next: >>> +stream = log_stream_get_by_id(++stream_id); >>> } >>>} >>> >>> @@ -52,7 +57,8 @@ static void close_all_files() { >>>static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, > SaInvocationT >> invocation) { >>> log_stream_t *stream; >>> SaAisErrorT error = SA_AIS_OK; >>> - int num; >>> + uint32_t num; >>> + uint32_t count = 0, stream_id = 0; >>> >>> TRACE_ENTER2("HA ACTIVE request"); >>> >>> @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand >>> >>> /* check existing streams */ >>> num = get_number_of_streams(); >>> - stream = log_stream_get_by_id(--num); >>> + stream = log_stream_get_by_id(stream_id); >>> if (!stream) >>>LOG_ER("No streams exist!"); >>> - while (stream != NULL) { >>> + while (count < num) { >>> +if (stream == nullptr) goto next; >>> + >>> +count++; >>>*stream->p_fd = -1; /* First Initialize fd */ >>> -stream = log_stream_get_by_id(--num); >>> + >>> + next: >>> +stream = log_stream_get_by_id(++stream_id); >>> } >>> >>>done: >>> diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc >> b/osaf/services/saf/logsv/lgs/lgs_config.cc >>> --- a/osaf/services/saf/logsv/lgs/lgs_config.cc >>> +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc >>> @@ -458,7 +458,8 @@ int lgs_cfg_verify_root_dir(const std::s >>> int rc = 0; >>> log_stream_t *stream = NULL; >>> size_t n = root_str_in.size(); >>> - int num; >>> + uint32_t num; >>> + uint32_t count = 0, stream_id = 0; >>> >>> if (n > PATH_MAX) { >>>LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); >>> @@ -471,8 +472,11 @@ int lgs_cfg_verify_root_dir(const std::s >>> * must not be larger than PATH_MAX. >>> */ >>> num = get_number_of_streams(); >>> - stream = lo
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Mahesh, I do think about it but not yet found out the better way. I can use the macro for this, somethings like GET { .. } NEXT; but it will violate the coding rule - avoid using the macro. I would appreciate if you have any proposal for this. Thanks. Regards, Vu > -Original Message- > From: A V Mahesh [mailto:mahesh.va...@oracle.com] > Sent: Wednesday, September 21, 2016 3:58 PM > To: Vu Minh Nguyen ; > lennart.l...@ericsson.com > Cc: opensaf-devel@lists.sourceforge.net > Subject: Re: [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043] > > Hi Vu, > > You used this similar code logic number of time in multiple file in log > service code > > is it possibly to optimize this logic in single function , to make > maintainability of code , > > so that any bug fix will not trigger multiple places code changes > > > > /* Verify that path and file are unique */ >num = get_number_of_streams(); >stream = log_stream_get_by_id(stream_id); >while (count < num) { > if (stream == nullptr) goto next > > > > next: >stream = log_stream_get_by_id(++stream_id); > > === > > -AVM > > > On 9/19/2016 2:38 PM, Vu Minh Nguyen wrote: > > osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- > > osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- > > osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- > > osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 > ++ > > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- > > osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- > > 6 files changed, 120 insertions(+), 51 deletions(-) > > > > > > The `number of streams` refers to total existing log streams in cluster. > > And `stream_array` is the database holding all existing log streams. > > When interating all log streams, logsv first started at the index `number of > streams`, > > if getting NULL, logsv considered that case as `no stream`. This is > absolutely wrong. > > > > This patch provides other way to iterate all log streams. > > > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > > @@ -26,13 +26,18 @@ > > > > static void close_all_files() { > > log_stream_t *stream; > > - int num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > - while (stream != NULL) { > > + uint32_t count = 0, stream_id = 0; > > + uint32_t num = get_number_of_streams(); > > + stream = log_stream_get_by_id(stream_id); > > + while (count < num) { > > +if (stream == nullptr) goto next; > > + > > +count++; > > if (log_stream_file_close(stream) != 0) > > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > > > > -stream = log_stream_get_by_id(--num); > > + next: > > +stream = log_stream_get_by_id(++stream_id); > > } > > } > > > > @@ -52,7 +57,8 @@ static void close_all_files() { > > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { > > log_stream_t *stream; > > SaAisErrorT error = SA_AIS_OK; > > - int num; > > + uint32_t num; > > + uint32_t count = 0, stream_id = 0; > > > > TRACE_ENTER2("HA ACTIVE request"); > > > > @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand > > > > /* check existing streams */ > > num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > + stream = log_stream_get_by_id(stream_id); > > if (!stream) > > LOG_ER("No streams exist!"); > > - while (stream != NULL) { > > + while (count < num) { > > +if (stream == nullptr) goto next; > > + > > +count++; > > *stream->p_fd = -1; /* First Initialize fd */ > > -stream = log_stream_get_by_id(--num); > > + > > + next: > > +stream = log_stream_get_by_id(++stream_id); > > } > > > > done: > > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > > @@ -458,7 +458,8 @@ int lgs_cfg_verify_root_dir(const std::s > > int rc = 0; > > log_stream_t *stream = NULL; > > size_t n = root_str_in.size(); > > - int num; > > + uint32_t num; > > + uint32_t count = 0, stream_id = 0; > > > > if (n > PATH_MAX) { > > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > > @@ -471,8 +472,11 @@ int lgs_cfg_verify_root_dir(const std::s > > * must not be larger than PATH_MAX. > > */ > > num = get_number_of_streams(); > > - stream = log_stream_get_by_id(--num); > > - while (stream != NULL) { > > + stream = log_stream_get_by_id(stream_id); > > + while (count < num) { > > +if (stream == nullptr) goto next; > > + > > +count++;
Re: [devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
Hi Vu, You used this similar code logic number of time in multiple file in log service code is it possibly to optimize this logic in single function , to make maintainability of code , so that any bug fix will not trigger multiple places code changes /* Verify that path and file are unique */ num = get_number_of_streams(); stream = log_stream_get_by_id(stream_id); while (count < num) { if (stream == nullptr) goto next next: stream = log_stream_get_by_id(++stream_id); === -AVM On 9/19/2016 2:38 PM, Vu Minh Nguyen wrote: > osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- > osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- > osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- > osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 > ++ > osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- > osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- > 6 files changed, 120 insertions(+), 51 deletions(-) > > > The `number of streams` refers to total existing log streams in cluster. > And `stream_array` is the database holding all existing log streams. > When interating all log streams, logsv first started at the index `number of > streams`, > if getting NULL, logsv considered that case as `no stream`. This is > absolutely wrong. > > This patch provides other way to iterate all log streams. > > diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc > b/osaf/services/saf/logsv/lgs/lgs_amf.cc > --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc > @@ -26,13 +26,18 @@ > > static void close_all_files() { > log_stream_t *stream; > - int num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + uint32_t count = 0, stream_id = 0; > + uint32_t num = get_number_of_streams(); > + stream = log_stream_get_by_id(stream_id); > + while (count < num) { > +if (stream == nullptr) goto next; > + > +count++; > if (log_stream_file_close(stream) != 0) > LOG_WA("Could not close file for stream %s", stream->name.c_str()); > > -stream = log_stream_get_by_id(--num); > + next: > +stream = log_stream_get_by_id(++stream_id); > } > } > > @@ -52,7 +57,8 @@ static void close_all_files() { > static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT > invocation) { > log_stream_t *stream; > SaAisErrorT error = SA_AIS_OK; > - int num; > + uint32_t num; > + uint32_t count = 0, stream_id = 0; > > TRACE_ENTER2("HA ACTIVE request"); > > @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand > > /* check existing streams */ > num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > + stream = log_stream_get_by_id(stream_id); > if (!stream) > LOG_ER("No streams exist!"); > - while (stream != NULL) { > + while (count < num) { > +if (stream == nullptr) goto next; > + > +count++; > *stream->p_fd = -1; /* First Initialize fd */ > -stream = log_stream_get_by_id(--num); > + > + next: > +stream = log_stream_get_by_id(++stream_id); > } > > done: > diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc > b/osaf/services/saf/logsv/lgs/lgs_config.cc > --- a/osaf/services/saf/logsv/lgs/lgs_config.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc > @@ -458,7 +458,8 @@ int lgs_cfg_verify_root_dir(const std::s > int rc = 0; > log_stream_t *stream = NULL; > size_t n = root_str_in.size(); > - int num; > + uint32_t num; > + uint32_t count = 0, stream_id = 0; > > if (n > PATH_MAX) { > LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); > @@ -471,8 +472,11 @@ int lgs_cfg_verify_root_dir(const std::s > * must not be larger than PATH_MAX. > */ > num = get_number_of_streams(); > - stream = log_stream_get_by_id(--num); > - while (stream != NULL) { > + stream = log_stream_get_by_id(stream_id); > + while (count < num) { > +if (stream == nullptr) goto next; > + > +count++; > if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, > root_str_in) == false) { > TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); > @@ -480,7 +484,8 @@ int lgs_cfg_verify_root_dir(const std::s > goto done; > } > > -stream = log_stream_get_by_id(--num); > + next: > +stream = log_stream_get_by_id(++stream_id); > } > > if (lgs_path_is_writeable_dir_h(root_str_in) == false) { > diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc > b/osaf/services/saf/logsv/lgs/lgs_evt.cc > --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc > +++ b/osaf/services/saf/logsv/lgs/lgs_evt.cc > @@ -532,13 +532,19 @@ static uint32_t proc_rda_cb_msg(lgsv_lgs > lgs_process_lga_down_list(); > > /*
[devel] [PATCH 1 of 1] log: fix ER no stream exists in syslog [#2043]
osaf/services/saf/logsv/lgs/lgs_amf.cc| 27 --- osaf/services/saf/logsv/lgs/lgs_config.cc | 13 +++- osaf/services/saf/logsv/lgs/lgs_evt.cc| 28 --- osaf/services/saf/logsv/lgs/lgs_imm.cc| 70 ++ osaf/services/saf/logsv/lgs/lgs_mbcsv.cc | 27 --- osaf/services/saf/logsv/lgs/lgs_stream.cc | 6 +- 6 files changed, 120 insertions(+), 51 deletions(-) The `number of streams` refers to total existing log streams in cluster. And `stream_array` is the database holding all existing log streams. When interating all log streams, logsv first started at the index `number of streams`, if getting NULL, logsv considered that case as `no stream`. This is absolutely wrong. This patch provides other way to iterate all log streams. diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.cc b/osaf/services/saf/logsv/lgs/lgs_amf.cc --- a/osaf/services/saf/logsv/lgs/lgs_amf.cc +++ b/osaf/services/saf/logsv/lgs/lgs_amf.cc @@ -26,13 +26,18 @@ static void close_all_files() { log_stream_t *stream; - int num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - while (stream != NULL) { + uint32_t count = 0, stream_id = 0; + uint32_t num = get_number_of_streams(); + stream = log_stream_get_by_id(stream_id); + while (count < num) { +if (stream == nullptr) goto next; + +count++; if (log_stream_file_close(stream) != 0) LOG_WA("Could not close file for stream %s", stream->name.c_str()); -stream = log_stream_get_by_id(--num); + next: +stream = log_stream_get_by_id(++stream_id); } } @@ -52,7 +57,8 @@ static void close_all_files() { static SaAisErrorT amf_active_state_handler(lgs_cb_t *cb, SaInvocationT invocation) { log_stream_t *stream; SaAisErrorT error = SA_AIS_OK; - int num; + uint32_t num; + uint32_t count = 0, stream_id = 0; TRACE_ENTER2("HA ACTIVE request"); @@ -67,12 +73,17 @@ static SaAisErrorT amf_active_state_hand /* check existing streams */ num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); + stream = log_stream_get_by_id(stream_id); if (!stream) LOG_ER("No streams exist!"); - while (stream != NULL) { + while (count < num) { +if (stream == nullptr) goto next; + +count++; *stream->p_fd = -1; /* First Initialize fd */ -stream = log_stream_get_by_id(--num); + + next: +stream = log_stream_get_by_id(++stream_id); } done: diff --git a/osaf/services/saf/logsv/lgs/lgs_config.cc b/osaf/services/saf/logsv/lgs/lgs_config.cc --- a/osaf/services/saf/logsv/lgs/lgs_config.cc +++ b/osaf/services/saf/logsv/lgs/lgs_config.cc @@ -458,7 +458,8 @@ int lgs_cfg_verify_root_dir(const std::s int rc = 0; log_stream_t *stream = NULL; size_t n = root_str_in.size(); - int num; + uint32_t num; + uint32_t count = 0, stream_id = 0; if (n > PATH_MAX) { LOG_NO("verify_root_dir Fail. Path > PATH_MAX"); @@ -471,8 +472,11 @@ int lgs_cfg_verify_root_dir(const std::s * must not be larger than PATH_MAX. */ num = get_number_of_streams(); - stream = log_stream_get_by_id(--num); - while (stream != NULL) { + stream = log_stream_get_by_id(stream_id); + while (count < num) { +if (stream == nullptr) goto next; + +count++; if (lgs_is_valid_pathlength(stream->pathName, stream->fileName, root_str_in) == false) { TRACE("The rootPath is invalid (%s)", root_str_in.c_str()); @@ -480,7 +484,8 @@ int lgs_cfg_verify_root_dir(const std::s goto done; } -stream = log_stream_get_by_id(--num); + next: +stream = log_stream_get_by_id(++stream_id); } if (lgs_path_is_writeable_dir_h(root_str_in) == false) { diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.cc b/osaf/services/saf/logsv/lgs/lgs_evt.cc --- a/osaf/services/saf/logsv/lgs/lgs_evt.cc +++ b/osaf/services/saf/logsv/lgs/lgs_evt.cc @@ -532,13 +532,19 @@ static uint32_t proc_rda_cb_msg(lgsv_lgs lgs_process_lga_down_list(); /* Check existing streams */ -int num = get_number_of_streams(); -stream = log_stream_get_by_id(--num); +uint32_t num = get_number_of_streams(); +uint32_t count = 0, stream_id = 0; +stream = log_stream_get_by_id(stream_id); if (!stream) LOG_ER("No streams exist!"); -while (stream != NULL) { +while (count < num) { + if (stream == nullptr) goto next; + + count++; *stream->p_fd = -1; /* Initialize fd */ - stream = log_stream_get_by_id(--num); + + next: + stream = log_stream_get_by_id(++stream_id); } } @@ -800,7 +806,8 @@ SaAisErrorT create_new_app_stream(lgsv_s SaBoolT twelveHourModeFlag; SaUint32T logMaxLogrecsize_conf = 0; SaConstStringT str_name; - int num, err = 0; + int err = 0; + uint32_t count = 0, stream_id = 0, num; const char *dnPrefix = "safLgStr="; TRACE_ENTER(); @@ -863,15 +870,20 @@ SaAisErrorT create_new_app_stream(lgsv_s /* Verify that path and file are un