예제 #1
0
SaAisErrorT set_implementer(SaImmHandleT immOiHandle, const SaImmOiImplementerNameT implementerName,
                            const SaNameT *objectName, SaImmScopeT scope){

    SaAisErrorT rc;

    rc = saImmOiImplementerSet(immOiHandle, implementerName);

    if (rc != SA_AIS_OK) {
        if (rc==SA_AIS_ERR_EXIST)
            syslog(LOG_INFO, "saImmOiImplementerSet() Implementer name already exist!");
        else {
            syslog(LOG_ERR, "saImmOiImplementerSet() failed, rc= %d", rc);
            return rc;
        }
    }
    rc = saImmOiObjectImplementerSet( immOiHandle, objectName, scope);
    if (rc != SA_AIS_OK){
        if (rc==SA_AIS_ERR_EXIST)
            syslog(LOG_INFO, "saImmOiObjectImplementerSet() Object Implementer name already exist!");
        else {
            syslog(LOG_ERR, "saImmOiObjectImplementerSet() failed, rc= %d", rc);
            return rc;
        }
    }
    else {
        syslog(LOG_ERR, "Object Implementer %s is set %s!",implementerName,(char*)objectName->value);
    }

    return rc;
}
void saImmOiClassImplementerSet_06(void)
{
    const SaImmAdminOwnerNameT adminOwnerName = (SaImmAdminOwnerNameT) __FUNCTION__;
    SaImmAdminOwnerHandleT ownerHandle;
    SaImmCcbHandleT ccbHandle;
    const SaNameT rdn = {strlen("Obj1"), "Obj1"};
    const SaNameT* nameValues[] = {&rdn};
    SaImmAttrValuesT_2 v2 = {"rdn",  SA_IMM_ATTR_SANAMET, 1, (void**)nameValues};
    SaUint32T  int1Value1 = 7;
    SaUint32T* int1Values[] = {&int1Value1};
    SaImmAttrValuesT_2 v1 = {"attr1", SA_IMM_ATTR_SAUINT32T, 1, (void**)int1Values};
    const SaImmAttrValuesT_2 * attrValues[] = {&v1, &v2, NULL};

    /* Test interference between saImmOiObjectImplementerSet and saImmOiClassImplementerSet */
    SaImmOiHandleT newhandle;
    SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT) __FUNCTION__;
    SaImmOiImplementerNameT implementerName2 = (SaImmOiImplementerNameT) __FILE__;

    safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK);
    safassert(saImmOmAdminOwnerInitialize(immOmHandle, adminOwnerName, SA_TRUE, &ownerHandle), SA_AIS_OK);
    safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK);
    safassert(config_class_create(immOmHandle), SA_AIS_OK);

    /* Create test object under root */
    safassert(saImmOmCcbObjectCreate_2(ccbHandle, "TestClassConfig", NULL, attrValues), SA_AIS_OK);
    safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);

    safassert(saImmOiInitialize_2(&immOiHandle, &immOiCallbacks, &immVersion), SA_AIS_OK);
    safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK);

    safassert(saImmOiInitialize_2(&newhandle, &immOiCallbacks, &immVersion), SA_AIS_OK);
    safassert(saImmOiImplementerSet(newhandle, implementerName2), SA_AIS_OK);
    safassert(saImmOiObjectImplementerSet(newhandle, &rdn, SA_IMM_ONE), SA_AIS_OK);

    rc = saImmOiClassImplementerSet(immOiHandle, configClassName);

    /* Cleanup */
    safassert(saImmOiObjectImplementerRelease(newhandle, &rdn, SA_IMM_ONE), SA_AIS_OK);
    safassert(saImmOiImplementerClear(newhandle), SA_AIS_OK);
    safassert(saImmOiImplementerClear(immOiHandle), SA_AIS_OK);
    safassert(saImmOiFinalize(newhandle), SA_AIS_OK);
    safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK);

    safassert(saImmOmCcbObjectDelete(ccbHandle, &rdn), SA_AIS_OK);
    safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);
    safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK);

    safassert(config_class_delete(immOmHandle), SA_AIS_OK);
    safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK);
    test_validate(rc, SA_AIS_ERR_EXIST);
}
void saImmOmThreadInterference_01(void) {
	SaImmHandleT immHandle;
	SaImmOiHandleT immOiHandle;
	SaImmAdminOwnerHandleT ownerHandle;
	SaImmSearchHandleT searchHandle;
	SaImmCcbHandleT ccbHandle;
	pthread_t threadid1, threadid2;
	SaAisErrorT rc;
	SaImmAttrDefinitionT_2 attrDef = { "rdn", SA_IMM_ATTR_SASTRINGT, SA_IMM_ATTR_RDN | SA_IMM_ATTR_CONFIG, NULL };
	const SaImmAttrDefinitionT_2 *attrDefs[2] = { &attrDef, NULL };
	SaImmClassCategoryT classCategory;
	SaImmAttrDefinitionT_2 **attrDefinitions;
	SaImmAccessorHandleT accessorHandle;
	SaImmAttrNameT attributeNames[2] = { "SaImmAttrClassName", NULL};
	SaImmAttrValuesT_2 **attributes;
	SaImmAttrValueT objNames[2] = { &objectName, NULL };
	SaImmAttrValuesT_2 attrValue = { (SaImmAttrNameT)"rdn", SA_IMM_ATTR_SANAMET, 1, (SaImmAttrValueT *)objNames };
	const SaImmAttrValuesT_2 *attrValues[2] = { &attrValue, NULL };
	SaImmAttrValueT modAttrValue[2] = { "Test", NULL };
	const SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, { "attr4", SA_IMM_ATTR_SASTRINGT, 1, modAttrValue } };
	const SaImmAttrModificationT_2 *attrMods[] = { &attrMod, NULL };

	objectName.length = strlen("Obj1");
	strcpy((char *)objectName.value, "Obj1");

	/* management */
	safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK);
	safassert(saImmOmAdminOwnerInitialize(immHandle, adminOwnerName, SA_TRUE, &ownerHandle), SA_AIS_OK);
	/* create test object */
	safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK);
	safassert(saImmOmCcbObjectCreate_2(ccbHandle, configClassName, NULL, attrValues), SA_AIS_OK);
	safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);
	safassert(saImmOmAdminOwnerSet(ownerHandle, objectNames, SA_IMM_ONE), SA_AIS_OK);

	/* implementer */
	isReady = 0;
	isOiDone = 0;
	safassert(saImmOiInitialize_2(&immOiHandle, &immOiCallbacks, &immVersion), SA_AIS_OK);
	safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK);
	safassert(saImmOiObjectImplementerSet(immOiHandle, &objectName, SA_IMM_ONE), SA_AIS_OK);
	assert(!pthread_create(&threadid1, NULL, implementer_thread, &immOiHandle));

	while(!isReady)
		usleep(100);

	/* "lock" IMM OM handle */
	isReady = 0;
	isOmDone = 0;
	isAdminOperDone = 0;
	assert(!pthread_create(&threadid2, NULL, lockomhandle_thread, &ownerHandle));

	while(!isReady)
		usleep(100);

	/* OM function tests */
	if((rc = saImmOmFinalize(immHandle)) !=  SA_AIS_ERR_LIBRARY) goto done;

	if((rc = saImmOmClassCreate_2(immHandle, (const SaImmClassNameT)"TestClass", SA_IMM_CLASS_CONFIG, (const SaImmAttrDefinitionT_2 **)attrDefs)) !=  SA_AIS_ERR_LIBRARY) goto done;
	if((rc = saImmOmClassDescriptionGet_2(immHandle, (const SaImmClassNameT)"TestClass", &classCategory, &attrDefinitions)) !=  SA_AIS_ERR_LIBRARY) goto done;
	if((rc = saImmOmClassDelete(immHandle, (const SaImmClassNameT)"TestClass")) !=  SA_AIS_ERR_LIBRARY) goto done;

	if((rc = saImmOmSearchInitialize_2(immHandle, NULL, SA_IMM_SUBTREE,
			SA_IMM_SEARCH_ONE_ATTR | SA_IMM_SEARCH_GET_NO_ATTR, NULL, NULL, &searchHandle)) !=  SA_AIS_ERR_LIBRARY) goto done;

	safassert(saImmOmAccessorInitialize(immHandle, &accessorHandle), SA_AIS_OK);
	if((rc = saImmOmAccessorGet_2(accessorHandle, &objectName, attributeNames, &attributes)) !=  SA_AIS_ERR_LIBRARY) goto done;
	safassert(saImmOmAccessorFinalize(accessorHandle), SA_AIS_OK);

	if((rc = saImmOmCcbObjectModify_2(ccbHandle, &objectName, attrMods)) !=  SA_AIS_ERR_LIBRARY) goto done;
	if((rc = saImmOmCcbObjectDelete(ccbHandle, &objectName)) !=  SA_AIS_ERR_LIBRARY) goto done;

done:
	isAdminOperDone = 1;
	while(!isOmDone)
		usleep(200);

	test_validate(rc, SA_AIS_ERR_LIBRARY);

	/* Finalize OI handle */
	safassert(saImmOiObjectImplementerRelease(immOiHandle, &objectName, SA_IMM_ONE), SA_AIS_OK);
	safassert(saImmOiImplementerClear(immOiHandle), SA_AIS_OK);
	safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK);

	/* Use pthread_detach() to remove pthread_create@@GLIBC leak from valgrind */
	pthread_detach(threadid1);
	pthread_detach(threadid2);

	while(!isOiDone)
		usleep(200);

	/* Remove test object and test class */
	safassert(saImmOmCcbObjectDelete(ccbHandle, &objectName), SA_AIS_OK);
	safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK);

	/* Finalize OM handles */
	saImmOmCcbFinalize(ccbHandle);
	saImmOmAdminOwnerRelease(ownerHandle, objectNames, SA_IMM_ONE);
	saImmOmAdminOwnerFinalize(ownerHandle);
	saImmOmFinalize(immHandle);
}