Hi Hung, Reviewed and tested the patch. Ack from me.
Thanks, Zoran -----Original Message----- From: Hung Nguyen [mailto:hung.d.ngu...@dektech.com.au] Sent: Thursday, April 07, 2016 12:19 PM To: Zoran Milinkovic; reddy.neelaka...@oracle.com Cc: opensaf-devel@lists.sourceforge.net Subject: [PATCH 1 of 1] immtools: Use safe read to retrieve class name for immcfg [#1726] osaf/tools/safimm/immcfg/imm_cfg.c | 149 ++++++++++---------------------- osaf/tools/safimm/immcfg/imm_import.cc | 14 +-- 2 files changed, 53 insertions(+), 110 deletions(-) This patch revert ticket #1283 and use safe read to retrieve class name for chained modify operations. diff --git a/osaf/tools/safimm/immcfg/imm_cfg.c b/osaf/tools/safimm/immcfg/imm_cfg.c --- a/osaf/tools/safimm/immcfg/imm_cfg.c +++ b/osaf/tools/safimm/immcfg/imm_cfg.c @@ -46,12 +46,6 @@ #include "osaf_extended_name.h" -typedef struct ObjectInfo { - char *objectName; - char *className; - struct ObjectInfo *next; -} ObjectInfoT; - static SaVersionT immVersion = { 'A', 2, 17 }; int verbose = 0; int ccb_safe = 1; @@ -62,8 +56,6 @@ SaImmAdminOwnerNameT adminOwnerName = NU SaImmAdminOwnerHandleT ownerHandle = 0; SaImmCcbHandleT ccbHandle = -1; -static ObjectInfoT *objectInfo = NULL; - extern struct ImmutilWrapperProfile immutilWrapperProfile; typedef enum { INVALID = 0, @@ -194,76 +186,6 @@ void sigalarmh(int sig) exit(EXIT_FAILURE); } -void object_info_add(const char *objectName, const char *className) { - ObjectInfoT *oi; - ObjectInfoT *prev; - int rc; - - prev = NULL; - oi = objectInfo; - while(oi) { - if((rc = strcmp(oi->objectName, objectName)) >= 0) { - if(!rc) { - // Object is already in the list - return; - } - - break; - } - - prev = oi; - oi = oi->next; - } - - if(prev) { - oi = (ObjectInfoT *)calloc(1, sizeof(ObjectInfoT)); - oi->objectName = strdup(objectName); - oi->className = strdup(className); - oi->next = prev->next; - prev->next = oi; - } else { - objectInfo = (ObjectInfoT *)calloc(1, sizeof(ObjectInfoT)); - objectInfo->objectName = strdup(objectName); - objectInfo->className = strdup(className); - objectInfo->next = oi; - } -} - -void object_info_clear() { - ObjectInfoT *oi = objectInfo; - ObjectInfoT *next; - - while(oi) { - next = oi->next; - free(oi->objectName); - free(oi->className); - free(oi); - oi = next; - } - - objectInfo = NULL; -} - -char *object_info_get_class(const char *objectName) { - ObjectInfoT *oi; - int rc; - - oi = objectInfo; - while(oi) { - if((rc = strcmp(oi->objectName, objectName)) >= 0) { - if(!rc) { - return strdup(oi->className); - } - - break; - } - - oi = oi->next; - } - - return NULL; -} - static void free_attr_value(SaImmValueTypeT attrValueType, SaImmAttrValueT attrValue) { if(attrValue) { if(attrValueType == SA_IMM_ATTR_SASTRINGT) @@ -324,6 +246,48 @@ static SaAisErrorT get_attrValueType(SaI return SA_AIS_ERR_NOT_EXIST; } +/* Get class name of the object. + * This is a clone of immutil_get_className(). + * If saImmOmAccessorGet_2() returns SA_AIS_ERR_NOT_EXIST, + * it will try with saImmOmCcbObjectRead() to get class name of being created object. + */ +static SaImmClassNameT get_class_name(const SaNameT *objectName) { + SaAisErrorT rc = SA_AIS_OK; + SaImmHandleT omHandle; + SaImmClassNameT className = NULL; + SaImmAccessorHandleT accessorHandle; + SaImmAttrValuesT_2 **attributes; + SaImmAttrNameT attributeNames[] = { "SaImmAttrClassName", NULL }; + + if (immutil_saImmOmInitialize(&omHandle, NULL, &immVersion) != SA_AIS_OK) + goto done; + + if (immutil_saImmOmAccessorInitialize(omHandle, &accessorHandle) != SA_AIS_OK) + goto finalize_om_handle; + + rc = immutil_saImmOmAccessorGet_2(accessorHandle, objectName, attributeNames, &attributes); + if (rc == SA_AIS_OK) { + className = strdup(*((char **) attributes[0]->attrValues[0])); + + } else if (rc == SA_AIS_ERR_NOT_EXIST && ccbHandle != -1) { + /* If ccbHandle is not intialized (value of -1) + * this is absolutely not a chained operation */ + + rc = immutil_saImmOmCcbObjectRead(ccbHandle, osaf_extended_name_borrow(objectName), attributeNames, &attributes); + if (rc == SA_AIS_OK) { + className = strdup(*((char **) attributes[0]->attrValues[0])); + } + } + + (void) immutil_saImmOmAccessorFinalize(accessorHandle); + + finalize_om_handle: + (void) immutil_saImmOmFinalize(omHandle); + + done: + return className; +} + /** * Alloc SaImmAttrModificationT_2 object and initialize its attributes from nameval (x=y) * @param objectName @@ -337,22 +301,11 @@ static SaImmAttrModificationT_2 *new_att char *name = strdup(nameval); char *value; SaImmAttrModificationT_2 *attrMod = NULL; - SaImmClassNameT className; + SaImmClassNameT className = get_class_name(objectName); SaAisErrorT error; SaImmAttrModificationTypeT modType = SA_IMM_ATTR_VALUES_REPLACE; SaImmClassCategoryT classCategory; - SaImmAttrDefinitionT_2 **attrDefinitions = NULL; - - className = object_info_get_class(osaf_extended_name_borrow(objectName)); - if(!className) { - className = immutil_get_className(objectName); - } - - if((error = saImmOmClassDescriptionGet_2(immHandle, className, &classCategory, &attrDefinitions)) != SA_AIS_OK) { - fprintf(stderr, "error - saImmOmClassDescriptionGet_2. FAILED: %s\n", saf_error(error)); - goto done; - } - + SaImmAttrDefinitionT_2 **attrDefinitions = NULL; if (className == NULL) { fprintf(stderr, "Object with DN '%s' does not exist\n", osaf_extended_name_borrow(objectName)); @@ -360,6 +313,11 @@ static SaImmAttrModificationT_2 *new_att goto done; } + if((error = saImmOmClassDescriptionGet_2(immHandle, className, &classCategory, &attrDefinitions)) != SA_AIS_OK) { + fprintf(stderr, "error - saImmOmClassDescriptionGet_2. FAILED: %s\n", saf_error(error)); + goto done; + } + attrMod = malloc(sizeof(SaImmAttrModificationT_2)); if ((value = strstr(name, "=")) == NULL) { @@ -565,13 +523,10 @@ int object_create(const SaNameT **object fprintf(stderr, "error - saImmOmCcbInitialize FAILED: %s\n", saf_error(error)); goto done; } - object_info_clear(); } i = 0; while (objectNames[i] != NULL) { - object_info_add(osaf_extended_name_borrow(objectNames[i]), className); - str = strdup(osaf_extended_name_borrow(objectNames[i])); if ((delim = strchr(str, ',')) != NULL) { /* a parent exist */ @@ -760,7 +715,6 @@ int object_modify(const SaNameT **object fprintf(stderr, "error - saImmOmCcbInitialize FAILED: %s\n", saf_error(error)); goto done; } - object_info_clear(); } i = 0; @@ -834,7 +788,6 @@ int object_delete(const SaNameT **object fprintf(stderr, "error - saImmOmCcbInitialize FAILED: %s\n", saf_error(error)); goto done; } - object_info_clear(); } while (objectNames[i] != NULL) { @@ -1099,8 +1052,6 @@ static int ccb_apply() { } done: - object_info_clear(); - return (transaction_mode) ? rc : 0; } @@ -1117,8 +1068,6 @@ static int ccb_abort() { ccbHandle = -1; } - object_info_clear(); - return (transaction_mode) ? rc : 0; } diff --git a/osaf/tools/safimm/immcfg/imm_import.cc b/osaf/tools/safimm/immcfg/imm_import.cc --- a/osaf/tools/safimm/immcfg/imm_import.cc +++ b/osaf/tools/safimm/immcfg/imm_import.cc @@ -68,10 +68,6 @@ extern "C" SaImmHandleT *immHandle, SaImmAdminOwnerHandleT *ownerHandle, SaImmCcbHandleT *ccbHandle, int mode, const char *xsdPath, int strictParse); int validateImmXML(const char *xmlfile, int verbose, int mode, int strictParse); - - void object_info_add(const char *objectName, const char *className); - void object_info_clear(); - char *object_info_get_class(const char *objectName); } extern ImmutilErrorFnT immutilError; @@ -642,6 +638,7 @@ static void createImmObject(ParserState* SaImmAttrValuesT_2** attrValues; SaAisErrorT errorCode = SA_AIS_OK; int i = 0; + size_t DNlen; SaNameT objectName; std::list<SaImmAttrValuesT_2>::iterator it; @@ -689,17 +686,15 @@ static void createImmObject(ParserState* if(state->ctxt->instate == XML_PARSER_EOF) return; - object_info_add(state->objectName, className); - #ifdef TRACE_8 /* Get the length of the DN and truncate state->objectName */ if (!osaf_is_extended_name_empty(&parentName)) { - i = strlen(state->objectName) - (strlen(osaf_extended_name_borrow(&parentName)) + 1); + DNlen = strlen(state->objectName) - +(strlen(osaf_extended_name_borrow(&parentName)) + 1); } else { - i = strlen(state->objectName); + DNlen = strlen(state->objectName); } - state->objectName[i] = '\0'; + state->objectName[DNlen] = '\0'; TRACE_8("OBJECT NAME: %s", state->objectName); #endif @@ -1710,7 +1705,6 @@ static void endElementHandler(void* user state->parsingStatus = 1; return; } - object_info_clear(); state->ccbInit = 1; } ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/ gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532 _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel