Ack.

Regards, Vu.


>-----Original Message-----
>From: Canh Truong [mailto:canh.v.tru...@dektech.com.au]
>Sent: Thursday, March 17, 2016 10:00 AM
>To: lennart.l...@ericsson.com; anders.wid...@ericsson.com;
>mathi.naic...@oracle.com; vu.m.ngu...@dektech.com.au
>Cc: opensaf-devel@lists.sourceforge.net
>Subject: [PATCH 1 of 1] log: fix trouble when the number app streams reachs
>limitation [#1446]
>
> osaf/services/saf/logsv/lgs/lgs_evt.cc    |   6 ++
> osaf/services/saf/logsv/lgs/lgs_imm.cc    |   7 ++-
> osaf/services/saf/logsv/lgs/lgs_stream.cc |  12 +++++
> osaf/services/saf/logsv/lgs/lgs_stream.h  |   1 +
> tests/logsv/tet_LogOiOps.c                |  74
+++++++++++++++++++++++++++++++
> tests/logsv/tet_saLogStreamOpen_2.c       |  72
>++++++++++++++++++++++++++++++
> 6 files changed, 171 insertions(+), 1 deletions(-)
>
>
>If number of app stream has reached the limitation, logsv get failed to add
this
>stream to stream array in ccbApplyCallback even though immsv creates object
>successfully. This patch help check the limitation of app stream and return
the
>error to abort creating new app stream and new object.
>
>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
>@@ -1036,6 +1036,12 @@ static uint32_t proc_stream_open_msg(lgs
>                       }
>               }
>
>+              if (check_max_stream()) {
>+                      TRACE("The number of stream out of limitation");
>+                      ais_rv = SA_AIS_ERR_NO_RESOURCES;
>+                      goto snd_rsp;
>+              }
>+
>               /* Create the stream:
>                *  - Check parameters
>                *  - Create the stream in the stream "data base"
>diff --git a/osaf/services/saf/logsv/lgs/lgs_imm.cc
>b/osaf/services/saf/logsv/lgs/lgs_imm.cc
>--- a/osaf/services/saf/logsv/lgs/lgs_imm.cc
>+++ b/osaf/services/saf/logsv/lgs/lgs_imm.cc
>@@ -1631,7 +1631,12 @@ static SaAisErrorT stream_ccb_completed_
>       SaAisErrorT rc = SA_AIS_ERR_BAD_OPERATION;
>
>       TRACE_ENTER2("CCB ID %llu", opdata->ccbId);
>-      rc = check_attr_validity(immOiHandle, opdata);
>+      if (!check_max_stream()) {
>+              rc = check_attr_validity(immOiHandle, opdata);
>+      } else {
>+              report_oi_error(immOiHandle, opdata->ccbId,
>+                              "Number of stream out of limitation");
>+      }
>       TRACE_LEAVE2("%u", rc);
>       return rc;
> }
>diff --git a/osaf/services/saf/logsv/lgs/lgs_stream.cc
>b/osaf/services/saf/logsv/lgs/lgs_stream.cc
>--- a/osaf/services/saf/logsv/lgs/lgs_stream.cc
>+++ b/osaf/services/saf/logsv/lgs/lgs_stream.cc
>@@ -1576,3 +1576,15 @@ int log_stream_config_change(bool create
>       TRACE_LEAVE();
>       return rc;
> }
>+
>+/*
>+ * Check if number of stream out of LOG_MAX_APPLICATION_STREAMS
>+ *
>+ * @return
>+ */
>+bool check_max_stream()
>+{
>+      TRACE("  Current number of streams: %u", numb_of_streams);
>+      return (numb_of_streams < stream_array_size ? false:true);
>+}
>+
>diff --git a/osaf/services/saf/logsv/lgs/lgs_stream.h
>b/osaf/services/saf/logsv/lgs/lgs_stream.h
>--- a/osaf/services/saf/logsv/lgs/lgs_stream.h
>+++ b/osaf/services/saf/logsv/lgs/lgs_stream.h
>@@ -124,6 +124,7 @@ extern log_stream_t *log_stream_get_by_n
> extern log_stream_t *log_stream_getnext_by_name(const char *name);
> extern void log_stream_print(log_stream_t *stream);
> extern log_stream_t *log_stream_get_by_id(uint32_t id);
>+extern bool check_max_stream();
> void log_free_stream_resources(log_stream_t *stream);
>
> #endif
>diff --git a/tests/logsv/tet_LogOiOps.c b/tests/logsv/tet_LogOiOps.c
>--- a/tests/logsv/tet_LogOiOps.c
>+++ b/tests/logsv/tet_LogOiOps.c
>@@ -3495,6 +3495,78 @@ restore_notif:
>       rc = system(command);
> }
>
>+
>+/*
>+ * Add test case for ticket #1446
>+ * Verify that invalid Object if number of app streams has reached the
>limitation
>+ *
>+ */
>+void verStrLimit(void)
>+{
>+      SaAisErrorT rc;
>+      char command[1000];
>+      uint32_t curAppCount, maxAppStream = 64;
>+      uint32_t *tmp_to = &maxAppStream;
>+      int num = 0;
>+      FILE *fp = NULL;
>+      char curAppCount_c[10];
>+
>+      /* Get current max app stream values of attributes */
>+      rc = get_attr_value(&configurationObject,
"logMaxApplicationStreams",
>+                          (void**)&tmp_to, NULL);
>+      if (rc != -1) {
>+              maxAppStream = *tmp_to;
>+      }
>+
>+      /*  Get current app stream */
>+      sprintf(command,"(immfind -c SaLogStreamConfig && immfind -c
>SaLogStream) | wc -l");
>+      fp = popen(command, "r");
>+
>+      while (fgets(curAppCount_c, sizeof(curAppCount_c) - 1, fp) != NULL)
{};
>+      pclose(fp);
>+      /* Convert chars to number */
>+      curAppCount = atoi(curAppCount_c) - 3;
>+
>+      for (num = curAppCount; num < maxAppStream; num++) {
>+              /* Create configurable app stream */
>+              sprintf(command,"immcfg -c SaLogStreamConfig
>safLgStrCfg=test%d"
>+                              " -a saLogStreamPathName=."
>+                              " -a saLogStreamFileName=test%d",
>+                              num, num);
>+              rc = system(command);
>+              if (WEXITSTATUS(rc)) {
>+                      /* Fail to perform the command. Report test case
>failed */
>+                      fprintf(stderr, "Failed to perform command = %s\n",
>command);
>+                      rc_validate(WEXITSTATUS(rc), 0);
>+                      goto done;
>+              }
>+      }
>+
>+      if (curAppCount >= maxAppStream) {
>+              num += 1;
>+      }
>+
>+      /* Create configurable app stream while number of app stream
>limitation */
>+      sprintf(command,"immcfg -c SaLogStreamConfig  safLgStrCfg=test%d"
>+                      " -a saLogStreamPathName=."
>+                      " -a saLogStreamFileName=test%d 2> /dev/null",
>+                      num, num);
>+      rc = system(command);
>+      rc_validate(WEXITSTATUS(rc), 1);
>+
>+      if (WEXITSTATUS(rc) == 0) {
>+              sprintf(command,"immcfg -d safLgStrCfg=test%d 2> /dev/null",
>num);
>+              rc = system(command);
>+      }
>+
>+done:
>+      /* Delete app stream  */
>+      for (num = curAppCount; num < maxAppStream; num++) {
>+              sprintf(command,"immcfg -d safLgStrCfg=test%d 2> /dev/null",
>num);
>+              rc = system(command);
>+      }
>+}
>+
> __attribute__ ((constructor)) static void saOiOperations_constructor(void)
> {
>       /* Stream objects */
>@@ -3596,6 +3668,8 @@ restore_notif:
>       test_case_add(5, verLogDataGroupName, "CCB Object Modify: delete
>logDataGroupname, OK");
>       test_case_add(5, verCCBWithValidValues, "CCB Object Modify many
>attributes with valid values, OK");
>       test_case_add(5, verCCBWithInvalidValues, "CCB Object Modify many
>attributes with one invalid values, ERR");
>+      /* Add test case to test #1446 */
>+      test_case_add(5, verStrLimit, "CCB Object Create: invalid Object if
>number of app streams has reached the limitation, ERR");
>
>       /* Stream configuration object */
>       /* Tests for create */
>diff --git a/tests/logsv/tet_saLogStreamOpen_2.c
>b/tests/logsv/tet_saLogStreamOpen_2.c
>--- a/tests/logsv/tet_saLogStreamOpen_2.c
>+++ b/tests/logsv/tet_saLogStreamOpen_2.c
>@@ -633,6 +633,77 @@ done:
>     }
> }
>
>+/*
>+ * Add test case for ticket #1446
>+ * Verify that logsv failed to create app stream  if number of app
>+ * streams has reached the limitation
>+ *
>+ */
>+void saLogStreamOpen_2_50(void)
>+{
>+      SaAisErrorT rc;
>+      char command[1000];
>+      uint32_t curAppCount, maxAppStream = 64;
>+      uint32_t *tmp_to = &maxAppStream;
>+      int num = 0;
>+      FILE *fp = NULL;
>+      char curAppCount_c[10];
>+
>+      /* Get current max app stream values of attributes */
>+      rc = get_attr_value(&configurationObject,
"logMaxApplicationStreams",
>+                          (void**)&tmp_to, NULL);
>+      if (rc != -1) {
>+              maxAppStream = *tmp_to;
>+      }
>+
>+      /*  Get current app stream */
>+      sprintf(command,"(immfind -c SaLogStreamConfig && immfind -c
>SaLogStream) | wc -l");
>+      fp = popen(command, "r");
>+
>+      while (fgets(curAppCount_c, sizeof(curAppCount_c) - 1, fp) != NULL)
{};
>+      pclose(fp);
>+      /* Convert chars to number */
>+      curAppCount = atoi(curAppCount_c) - 3;
>+
>+      for (num = curAppCount; num < maxAppStream; num++) {
>+              /* Create configurable app stream */
>+              sprintf(command,"immcfg -c SaLogStreamConfig
>safLgStrCfg=test%d"
>+                              " -a saLogStreamPathName=."
>+                              " -a saLogStreamFileName=test%d",
>+                              num, num);
>+              rc = system(command);
>+              if (WEXITSTATUS(rc)) {
>+                      /* Fail to perform the command. Report test case
>failed */
>+                      fprintf(stderr, "Failed to perform command = %s\n",
>command);
>+                      rc_validate(WEXITSTATUS(rc), 0);
>+                      goto done;
>+              }
>+      }
>+
>+      rc = saLogInitialize(&logHandle, &logCallbacks, &logVersion);
>+      if (rc != SA_AIS_OK) {
>+              fprintf(stderr, "Failed at saLogInitialize: %d \n",
(int)rc);
>+              test_validate(rc, SA_AIS_OK);
>+              goto done;
>+      }
>+
>+      rc = saLogStreamOpen_2(logHandle, &app1StreamName,
>&appStream1LogFileCreateAttributes,
>+                             SA_LOG_STREAM_CREATE, SA_TIME_ONE_SECOND,
>&logStreamHandle);
>+      test_validate(rc, SA_AIS_ERR_NO_RESOURCES);
>+
>+      rc = saLogFinalize(logHandle);
>+      if (rc != SA_AIS_OK) {
>+              fprintf(stderr, "Failed to call salogFinalize: %d \n", (int)
rc);
>+      }
>+
>+done:
>+      /* Delete app stream  */
>+      for (num = curAppCount; num < maxAppStream; num++) {
>+              sprintf(command,"immcfg -d safLgStrCfg=test%d 2> /dev/null",
>num);
>+              rc = system(command);
>+      }
>+}
>+
> extern void saLogStreamOpenAsync_2_01(void);
> extern void saLogStreamOpenCallbackT_01(void);
> extern void saLogWriteLog_01(void);
>@@ -714,5 +785,6 @@ extern void saLogStreamClose_01(void);
>
>     test_case_add(2, verFixLogRec_Max_Err, "saLogStreamOpen_2 with
>maxLogRecordSize > MAX_RECSIZE, ERR");
>     test_case_add(2, verFixLogRec_Min_Err, "saLogStreamOpen_2 with
>maxLogRecordSize < 150, ERR");
>+    test_case_add(2, saLogStreamOpen_2_50, "saLogStreamOpen_2 with
>stream number out of the limitation, ERR");
> }
>


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to