Re: [devel] [PATCH 1/1] clm: add clm tool for tracking and for getting node info [#2429]

2017-07-28 Thread praveen malviya

Hi Anders,

Attached is the patch after incorporating the comments.
I will be pushing it on Monday.
Please go through it.

Thanks
Praveen

On 18-Jul-17 9:20 PM, Anders Widell wrote:

Ack with comments:

* Indentation seems to be according to Google C++ style guide, although 
the file is written in C and should be indented according to the Linux 
Kernel coding style. Either change the file extension from .c to .cc or 
change the formatting. It can also be a good idea to run the style 
checkers: "make cpplint" for C++ code or "make checkpatch" for C code.


* The program is installed in sbin, but shouldn't it be installed in 
bin? sbin is intended for system administration tools.


* The name of the program is not consistent with already existing tools 
like clm-adm etc. Maybe rename it to clm-app? Though "app" doesn't say 
much about what the program is doing. Better choices could be clm-list, 
clm-show, or clm-print.


* Since there is only one source file, it is probably a good idea to 
give it the same name as the executable, but with a .c or .cc extension 
and any hyphens replaced with underscores (e.g. clm_print.cc)


* It is probably better to remove the -f and -i flags, and replace them 
with optional arguments for the -n, -a, -m flags.


* Node id (-i flag) doesn't support hexadecimal numbers. Use e.g. 
strtoul() with base 0 instead of atoi().


* It is probably better to use comma (,) instead of vertical bar (|) to 
separate track flags, because vertical bar is treated specially by the 
shell and must thus always be quoted.


* Why not use the value supplied with the -t parameter also when using 
-n, instead of the hard-coded TIME_OUT value (if -t was not specified or 
negative then you can use TIME_OUT)?


* Shouldn't the program exit once it has received the asynchronous node 
get callback?


* osaf_extended_name_borrow() and osaf_extended_name_length() are mainly 
intended to be used in agent libraries. Please use saAisNameBorrow() and 
strlen(saAisNameBorrow()) instead.


* Inconsistent use of EXIT_FAILURE/EXIT_SUCCESS and 1/0 for exit() and 
return from main (sometimes name is used, sometimes number).


regards,

Anders Widell

On 07/14/2017 11:02 AM, Praveen wrote:

Add a utility/application which enables user to:
-perform tracking using saClmClusterTrack_4().
-get node info by calling saClmClusterNodeGet_4().
-get node info asynchronously by calling saClmClusterNodeGetAsync().
---
  opensaf.spec.in |   1 +
  src/clm/Makefile.am |  13 ++
  src/clm/tools/clm_api_app.c | 349 


  3 files changed, 363 insertions(+)
  create mode 100644 src/clm/tools/clm_api_app.c

diff --git a/opensaf.spec.in b/opensaf.spec.in
index 56e8d78..8c4b2c1 100644
--- a/opensaf.spec.in
+++ b/opensaf.spec.in
@@ -995,6 +995,7 @@ fi
  %defattr(-,root,root)
  %{_sbindir}/amfpm
  %{_sbindir}/amfclusterstatus
+%{_sbindir}/clmapp
  %if %is_ais_ckpt
diff --git a/src/clm/Makefile.am b/src/clm/Makefile.am
index be3a668..417dc63 100644
--- a/src/clm/Makefile.am
+++ b/src/clm/Makefile.am
@@ -85,6 +85,7 @@ noinst_HEADERS += \
  src/clm/common/clmsv_enc_dec.h \
  src/clm/common/clmsv_msg.h
+sbin_PROGRAMS += bin/clmapp
  osaf_execbin_PROGRAMS += bin/osafclmd bin/osafclmna
  nodist_pkgclccli_SCRIPTS += \
@@ -165,6 +166,18 @@ dist_bin_SCRIPTS += \
 src/clm/tools/clm-find \
 src/clm/tools/clm-state
+bin_clmapp_CPPFLAGS = \
+-DSA_EXTENDED_NAME_SOURCE \
+$(AM_CPPFLAGS)
+
+bin_clmapp_SOURCES = \
+src/clm/tools/clm_api_app.c
+
+bin_clmapp_LDADD = \
+lib/libSaClm.la \
+lib/libopensaf_core.la
+
+
  if ENABLE_TESTS
  bin_PROGRAMS += bin/clmtest
diff --git a/src/clm/tools/clm_api_app.c b/src/clm/tools/clm_api_app.c
new file mode 100644
index 000..cae27f2
--- /dev/null
+++ b/src/clm/tools/clm_api_app.c
@@ -0,0 +1,349 @@
+/*  -*- OpenSAF  -*-
+ *
+ * Copyright (C) 2017, Oracle and/or its affiliates. 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
+ * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are 
licensed
+ * under the GNU Lesser General Public License Version 2.1, February 
1999.

+ * The complete license can be accessed from the following location:
+ * 
https://urldefense.proofpoint.com/v2/url?u=http-3A__opensource.org_licenses_lgpl-2Dlicense.php=DwICaQ=RoP1YumCXCgaWHvlZYR8PQcxBKCX5YTpkKY057SbK10=Lehk1PZKwfDQtYJXNyUKbPAqrw5O--SlPRAF9DIEps4=WlWfNt4__h4REFw1hAKezXL8ZHVNlOzgMtMpNjhhWes=l2RAg-511WMwwdADnRrm1xBQSVnrb_z3zcohqea1vEA= 
+ * See the Copying file included with the OpenSAF distribution for full

+ * licensing terms.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define SIZE_NOTIFICATIONS 100
+#define TIME_OUT  ((SaTimeT)15 * 

[devel] [PATCH 1/1] base: Add osaf_get_boot_time and osaf_timespec_average functions [#2535]

2017-07-28 Thread Anders Widell
The osaf_get_boot_time function returns the time stamp when the node was booted.
The osaf_timespec_average function returns the average of two time stamps.
---
 src/base/Makefile.am |  12 ++-
 src/base/osaf_time.c |  24 +
 src/base/osaf_time.h |  40 +++
 src/base/tests/mock_clock_gettime.cc |  20 
 src/base/tests/mock_clock_gettime.h  |   3 +
 src/base/tests/osaf_get_boot_time_test.cc|  77 ++
 src/base/tests/osaf_timespec_average_test.cc | 152 +++
 7 files changed, 323 insertions(+), 5 deletions(-)
 create mode 100644 src/base/tests/osaf_get_boot_time_test.cc
 create mode 100644 src/base/tests/osaf_timespec_average_test.cc

diff --git a/src/base/Makefile.am b/src/base/Makefile.am
index e39fdd322..f278a8ffb 100644
--- a/src/base/Makefile.am
+++ b/src/base/Makefile.am
@@ -221,17 +221,19 @@ bin_core_common_test_LDFLAGS = \
src/base/lib_libopensaf_core_la-osaf_utility.lo
 
 bin_core_common_test_SOURCES = \
+   src/base/tests/mock_clock_gettime.cc \
+   src/base/tests/mock_clock_nanosleep.cc \
+   src/base/tests/mock_syslog.cc \
src/base/tests/osaf_clock_gettime_test.cc \
+   src/base/tests/osaf_get_boot_time_test.cc \
+   src/base/tests/osaf_millis_timeout_test.cc \
src/base/tests/osaf_nanosleep_test.cc \
src/base/tests/osaf_normalize_timespec_test.cc \
src/base/tests/osaf_timespec_add_test.cc \
+   src/base/tests/osaf_timespec_average_test.cc \
src/base/tests/osaf_timespec_compare_test.cc \
src/base/tests/osaf_timespec_convert_test.cc \
-   src/base/tests/osaf_timespec_subtract_test.cc \
-   src/base/tests/osaf_millis_timeout_test.cc \
-   src/base/tests/mock_clock_gettime.cc \
-   src/base/tests/mock_clock_nanosleep.cc \
-   src/base/tests/mock_syslog.cc
+   src/base/tests/osaf_timespec_subtract_test.cc
 
 bin_core_common_test_LDADD = \
$(GTEST_DIR)/lib/libgtest.la \
diff --git a/src/base/osaf_time.c b/src/base/osaf_time.c
index fa3b3d2c0..c8e898a38 100644
--- a/src/base/osaf_time.c
+++ b/src/base/osaf_time.c
@@ -1,6 +1,7 @@
 /*  -*- OpenSAF  -*-
  *
  * (C) Copyright 2013 The OpenSAF Foundation
+ * Copyright Ericsson AB 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
@@ -18,6 +19,10 @@
 #include "base/osaf_time.h"
 #include 
 
+#ifndef CLOCK_BOOTTIME
+#define CLOCK_BOOTTIME 7
+#endif
+
 const struct timespec kZeroSeconds = {0, 0};
 const struct timespec kTenMilliseconds = {0, 1000};
 const struct timespec kHundredMilliseconds = {0, 1};
@@ -42,3 +47,22 @@ void osaf_nanosleep(const struct timespec *sleep_duration)
if (retval != 0)
osaf_abort(retval);
 }
+
+void osaf_get_boot_time(struct timespec *boot_time)
+{
+   struct timespec uptime;
+   struct timespec realtime;
+   struct timespec uptime_after;
+   int result = clock_gettime(CLOCK_BOOTTIME, );
+   result |= clock_gettime(CLOCK_REALTIME, );
+   result |= clock_gettime(CLOCK_BOOTTIME, _after);
+   if (result == 0) {
+   osaf_timespec_average(, _after, );
+   if (osaf_timespec_compare(, ) >= 0) {
+   osaf_timespec_subtract(, , boot_time);
+   return;
+   }
+   }
+   boot_time->tv_sec = 0;
+   boot_time->tv_nsec = 0;
+}
diff --git a/src/base/osaf_time.h b/src/base/osaf_time.h
index 9fb7b0d1f..5454020ba 100644
--- a/src/base/osaf_time.h
+++ b/src/base/osaf_time.h
@@ -1,6 +1,7 @@
 /*  -*- OpenSAF  -*-
  *
  * (C) Copyright 2013 The OpenSAF Foundation
+ * Copyright Ericsson AB 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
@@ -81,6 +82,17 @@ extern const struct timespec kOneHour;
 extern void osaf_nanosleep(const struct timespec* sleep_duration);
 
 /**
+ * @brief Get the time when the node booted
+ *
+ * This function gets the time stamp of the CLOCK_REALTIME clock when the node
+ * booted, and stores the result in @a boot_time. Zero is returned in case of 
an
+ * error. Note that since the boot time is calculated by reading the current
+ * time and the node's uptime, you may not get the exact same result when
+ * calling this function multiple times.
+ */
+extern void osaf_get_boot_time(struct timespec* boot_time);
+
+/**
  * @brief Get the time
  *
  * This is a convenience function that behaves exactly like the POSIX function
@@ -131,6 +143,19 @@ static inline void osaf_timespec_subtract(const struct 
timespec* i_end,
   struct timespec* o_difference);
 
 /**
+ * @brief Calculate the average of two timespec structures.
+ *
+ * This function 

[devel] [PATCH 0/1] Review Request for base: Add osaf_get_boot_time and osaf_timespec_average functions [#2535]

2017-07-28 Thread Anders Widell
Summary: base: Add osaf_get_boot_time and osaf_timespec_average functions 
[#2535]
Review request for Ticket(s): 2535
Peer Reviewer(s): Mahesh
Pull request to: 
Affected branch(es): develop
Development branch: ticket-2535
Base revision: ac580c6389d5fe3b3f5e0300947957d2da338ba1
Personal repository: git://git.code.sf.net/u/anders-w/review


Impacted area   Impact y/n

 Docsn
 Build systemn
 RPM/packaging   n
 Configuration files n
 Startup scripts n
 SAF servicesn
 OpenSAF servicesn
 Core libraries  y
 Samples n
 Tests   n
 Other   n


Comments (indicate scope for each "y" above):
-

revision 10a76da49f211674579fe5e03fe9d72c44e63709
Author: Anders Widell 
Date:   Fri, 28 Jul 2017 10:08:08 +0200

base: Add osaf_get_boot_time and osaf_timespec_average functions [#2535]

The osaf_get_boot_time function returns the time stamp when the node was booted.
The osaf_timespec_average function returns the average of two time stamps.



Added Files:

 src/base/tests/osaf_get_boot_time_test.cc
 src/base/tests/osaf_timespec_average_test.cc


Complete diffstat:
--
 src/base/Makefile.am |  12 ++-
 src/base/osaf_time.c |  24 +
 src/base/osaf_time.h |  40 +++
 src/base/tests/mock_clock_gettime.cc |  20 
 src/base/tests/mock_clock_gettime.h  |   3 +
 src/base/tests/osaf_get_boot_time_test.cc|  77 ++
 src/base/tests/osaf_timespec_average_test.cc | 152 +++
 7 files changed, 323 insertions(+), 5 deletions(-)


Testing Commands:
-

make check


Testing, Expected Results:
--

unit tests shall pass


Conditions of Submission:
-

Ack from reviewer(s) or on 2017-08-04


Arch  Built StartedLinux distro
---
mipsn  n
mips64  n  n
x86 n  n
x86_64  y  y
powerpc n  n
powerpc64   n  n


Reviewer Checklist:
---
[Submitters: make sure that your review doesn't trigger any checkmarks!]


Your checkin has not passed review because (see checked entries):

___ Your RR template is generally incomplete; it has too many blank entries
that need proper data filled in.

___ You have failed to nominate the proper persons for review and push.

___ Your patches do not have proper short+long header

___ You have grammar/spelling in your header that is unacceptable.

___ You have exceeded a sensible line length in your headers/comments/text.

___ You have failed to put in a proper Trac Ticket # into your commits.

___ You have incorrectly put/left internal data in your comments/files
(i.e. internal bug tracking tool IDs, product names etc)

___ You have not given any evidence of testing beyond basic build tests.
Demonstrate some level of runtime or other sanity testing.

___ You have ^M present in some of your files. These have to be removed.

___ You have needlessly changed whitespace or added whitespace crimes
like trailing spaces, or spaces before tabs.

___ You have mixed real technical changes with whitespace and other
cosmetic code cleanup changes. These have to be separate commits.

___ You need to refactor your submission into logical chunks; there is
too much content into a single commit.

___ You have extraneous garbage in your review (merge commits etc)

___ You have giant attachments which should never have been sent;
Instead you should place your content in a public tree to be pulled.

___ You have too many commits attached to an e-mail; resend as threaded
commits, or place in a public tree for a pull.

___ You have resent this content multiple times without a clear indication
of what has changed between each re-send.

___ You have failed to adequately and individually address all of the
comments and change requests that were proposed in the initial review.

___ You have a misconfigured ~/.gitconfig file (i.e. user.name, user.email etc)

___ Your computer have a badly configured date and time; confusing the
the threaded patch review.

___ Your changes affect IPC mechanism, and you don't present any results
for in-service upgradability test.

___ Your changes affect user manual and documentation, your patch series
do not contain the patch that updates the Doxygen manual.


--
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

[devel] [PATCH 1/1] amfa: return BAD HANDLE in error report or error clear [#248]

2017-07-28 Thread Nagendra Kumar
---
 src/amf/agent/amf_agent.cc | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/src/amf/agent/amf_agent.cc b/src/amf/agent/amf_agent.cc
index 20528e9..af4b30b 100644
--- a/src/amf/agent/amf_agent.cc
+++ b/src/amf/agent/amf_agent.cc
@@ -2686,6 +2686,13 @@ SaAisErrorT 
AmfAgent::ComponentErrorReport_4(SaAmfHandleT hdl,
   SaAisErrorT rc = SA_AIS_OK;
   TRACE_ENTER2("SaAmfHandleT passed is %llx", hdl);
 
+  /* Verifying the input Handle & global handle */
+  if (!gl_ava_hdl || hdl > AVSV_UNS32_HDL_MAX) {
+TRACE_2("Invalid SaAmfHandle passed by component: %llx", hdl);
+rc = SA_AIS_ERR_BAD_HANDLE;
+goto done;
+  }
+
   /* Version is previously set in in initialize function */
   if (!ava_B4_ver_used(0)) {
 TRACE_2(
@@ -2779,6 +2786,14 @@ SaAisErrorT AmfAgent::ComponentErrorClear_4(SaAmfHandleT 
hdl,
   SaAisErrorT rc = SA_AIS_OK;
   TRACE_ENTER2("SaAmfHandleT passed is %llx", hdl);
 
+  /* Verifying the input Handle & global handle */
+  if (!gl_ava_hdl || hdl > AVSV_UNS32_HDL_MAX) {
+TRACE_2("Invalid SaAmfHandle passed by component: %llx", hdl);
+rc = SA_AIS_ERR_BAD_HANDLE;
+goto done;
+  }
+
+
   /* Version is previously set in in initialize function */
   if (!ava_B4_ver_used(0)) {
 TRACE_2(
-- 
1.9.1


--
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