void wbem::mem_config::MemoryConfigurationFactory::populateInstanceDimmInfoFromDiscovery(
		framework::attribute_names_t &attributes,
		wbem::framework::Instance *pInstance,
		const struct device_discovery &discovery)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// Parent - dimm UID
	if (containsAttribute(PARENT_KEY, attributes))
	{
		NVM_UID uidStr;
		uid_copy(discovery.uid, uidStr);

		framework::Attribute uidAttr(uidStr, false);
		pInstance->setAttribute(PARENT_KEY, uidAttr, attributes);
	}

	// SocketID of DIMM
	if (containsAttribute(SOCKETID_KEY, attributes))
	{
		framework::Attribute socketIdAttr(discovery.socket_id, false);
		pInstance->setAttribute(SOCKETID_KEY, socketIdAttr, attributes);
	}

}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::mem_config::MemoryConfigurationCapabilitiesFactory::getInstance(
		framework::ObjectPath &path,
		framework::attribute_names_t &attributes)
				throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// Verify ObjectPath ...
	std::string hostName = wbem::server::getHostName();

	// Verify InstanceID
	framework::Attribute attribute = path.getKeyValue(INSTANCEID_KEY);
	if (attribute.stringValue() != (hostName + MEMORYCONFIGURATIONCAPABILITIES_INSTANCEID))
	{
		throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
	}

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);

	try
	{
		checkAttributes(attributes);

		// ElementName - hostname + " NVM Configuration Capabilities"
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			framework::Attribute a((hostName + MEMORYCONFIGURATIONCAPABILITIES_ELEMENTNAME), false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}

		// SynchronousMethodsSupported
		if (containsAttribute(SUPPORTEDSYNCHRONOUSOPERATIONS_KEY, attributes))
		{
			// empty list
			framework::UINT16_LIST synchmethods;
			framework::Attribute a(synchmethods, false);
			pInstance->setAttribute(SUPPORTEDSYNCHRONOUSOPERATIONS_KEY, a, attributes);
		}

		// AsynchronousMethodsSupported - none
		if (containsAttribute(SUPPORTEDASYNCHRONOUSOPERATIONS_KEY, attributes))
		{
			framework::UINT16_LIST asynchmethods;
			asynchmethods.push_back(METHOD_ALLOCATEFROMPOOL);
			framework::Attribute a(asynchmethods, false);
			pInstance->setAttribute(SUPPORTEDASYNCHRONOUSOPERATIONS_KEY, a, attributes);
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
Пример #3
0
// ********************************************************************
// *
// *            containsAttribute 
// *            -----------------
// *
// *     checks if construct node or its subnodes contain 
// *            given attribute
// *
// *********************************************************************
booleanT construct::containsAttribute(constructNode *Node, int attributeIdx)
{
   if (Node->attrIdx == attributeIdx)
      return mTRUE ;
   
   if (Node->left)
      if (containsAttribute(Node->left, attributeIdx))
         return mTRUE ;
   
   if (Node->right)
     return containsAttribute(Node->right, attributeIdx) ;
        
   return mFALSE ;
   
}
Пример #4
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::support::DiagnosticLogFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		// get the host server name
		std::string hostName = wbem::server::getHostName();

		// make sure the instance ID passed in matches this host
		framework::Attribute instanceID = path.getKeyValue(INSTANCEID_KEY);
		if (instanceID.stringValue() == std::string(DIAGNOSTICLOG_NAME + hostName))
		{
			// ElementName - "NVDIMM Diagnostic Log"
			if (containsAttribute(ELEMENTNAME_KEY, attributes))
			{
				framework::Attribute elementNameAttr(DIAGNOSTICLOG_NAME, false);
				pInstance->setAttribute(ELEMENTNAME_KEY, elementNameAttr, attributes);
			}

			// CurrentNumberOfRecords - One per test type per dimm
			if (containsAttribute(CURRENTNUMBEROFRECORDS_KEY, attributes))
			{
				diagnosticResults_t results;
				int count = gatherDiagnosticResults(&results);
				framework::Attribute recordCntAttr((NVM_UINT64)count, false);
				pInstance->setAttribute(CURRENTNUMBEROFRECORDS_KEY, recordCntAttr, attributes);
			}
		}
		else
		{
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
Пример #5
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::erasure::ErasureServiceFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	checkPath(path);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		// ElementName - "Erasure Service"
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			framework::Attribute a(ERASURESERVICE_ELEMENTNAME, false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::software::NVDIMMSoftwareInstallationServiceFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);



	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);
		checkPath(path);

		// ElementName - "Intel NVM FW Installation Service for" + host name
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			std::string hostName = wbem::server::getHostName();
			framework::Attribute a(std::string("Intel NVM FW Installation Service for ") + hostName, false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::mem_config::MemoryConfigurationFactory::getInstance(
		framework::ObjectPath &path,
		framework::attribute_names_t &attributes)
				throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);

	try
	{
		checkAttributes(attributes);
		lib_interface::NvmApi *pApi = lib_interface::NvmApi::getApi();

		// parse InstanceID
		framework::Attribute idAttr = path.getKeyValue(INSTANCEID_KEY);
		std::string instanceId = idAttr.stringValue();

		if (!isValidInstanceId(instanceId))
		{
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}

		std::string uidStr = instanceId.substr(0, instanceId.length() - 1);
		struct device_discovery deviceDiscovery;
		pApi->getDeviceDiscoveryForDimm(uidStr, deviceDiscovery);

		// ElementName - host name + " NVM allocation setting"
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			// Get the real host name
			std::string elementName = pApi->getHostName() +
					MEMORYCONFIGURATION_ELEMENTNAME;
			framework::Attribute a(elementName, false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}

		populateInstanceDimmInfoFromDiscovery(attributes, pInstance, deviceDiscovery);

		if (isGoalConfig(instanceId))
		{
			populateGoalInstance(attributes, uidStr, pInstance, &deviceDiscovery);
		}
		else
		{
			populateCurrentConfigInstance(attributes, uidStr, pInstance, &deviceDiscovery);
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
Пример #8
0
/*
 * Helper function that adds the non-key attributes to an already existing instance
 */
void wbem::memory::MemoryControllerFactory::addNonKeyAttributesToInstance(
		framework::Instance *pInstance,
		framework::attribute_names_t *pAttrNames,
		struct device_discovery *pDiscovery)
{
	// Affinity = processor socket id (same as proximity domain)
	if (containsAttribute(PROCESSORAFFINITY_KEY, *pAttrNames))
	{
		std::stringstream socketIdStr;
		socketIdStr << pDiscovery->socket_id;

		framework::Attribute attrSocketID(socketIdStr.str(), false);
		pInstance->setAttribute(PROCESSORAFFINITY_KEY, attrSocketID, *pAttrNames);
	}
	// ProtocolSupported = "DDR4"
	if (containsAttribute(PROTOCOLSUPPORTED_KEY, *pAttrNames))
	{
		framework::Attribute attrProtocolSupported((NVM_UINT16)50, (std::string)"DDR4", false);
		pInstance->setAttribute(PROTOCOLSUPPORTED_KEY, attrProtocolSupported, *pAttrNames);
	}
}
Пример #9
0
void wbem::profile::RegisteredProfileFactory::buildInstanceFromProfileInfo(framework::Instance& instance,
		const framework::attribute_names_t& attributes, const struct ProfileInfo& info)
{
	// RegisteredName - string
	if (containsAttribute(REGISTEREDNAME_KEY, attributes))
	{
		framework::Attribute attr(info.registeredName, false);
		instance.setAttribute(REGISTEREDNAME_KEY, attr);
	}

	// RegisteredVersion - string
	if (containsAttribute(REGISTEREDVERSION_KEY, attributes))
	{
		framework::Attribute attr(info.version, false);
		instance.setAttribute(REGISTEREDVERSION_KEY, attr);
	}

	// RegisteredOrganization - uint16
	if (containsAttribute(REGISTEREDORGANIZATION_KEY, attributes))
	{
		framework::Attribute attr(info.registeredOrg, false);
		instance.setAttribute(REGISTEREDORGANIZATION_KEY, attr);
	}

	// OtherRegisteredOrganization - string
	if (containsAttribute(OTHERREGISTEREDORGANIZATION_KEY, attributes))
	{
		framework::Attribute attr(info.otherRegisteredOrg, false);
		instance.setAttribute(OTHERREGISTEREDORGANIZATION_KEY, attr);
	}

	// AdvertiseTypes - uint16[]
	if (containsAttribute(ADVERTISETYPES_KEY, attributes))
	{
		framework::Attribute attr(info.advertiseTypes, false);
		instance.setAttribute(ADVERTISETYPES_KEY, attr);
	}
}
Пример #10
0
// ********************************************************************
// *
// *            containsAttribute 
// *            -----------------
// *
// *     checks if construct contains attribute of
// *         given attribute's value
// *
// *********************************************************************
booleanT construct::containsAttribute(construct &AttrConstruct)
{
#if defined(DEBUG)
   if (AttrConstruct.root->left != 0 || AttrConstruct.root->right != 0 ||
       (AttrConstruct.root->nodeType != cnCONTattrValue && 
        AttrConstruct.root->nodeType != cnDISCattrValue &&
        AttrConstruct.root->nodeType != cnCONTattribute &&
        AttrConstruct.root->nodeType != cnDISCattribute) )
      merror("construct::containsAttribute", "unexpected construct was given as input") ;
#endif

    if (root)
       return containsAttribute(root, AttrConstruct.root->attrIdx) ;
    else
       return mFALSE ;
}
Пример #11
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::software::HostSoftwareFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		// get the host server name
		std::string hostName = wbem::server::getHostName();

		// make sure the instance ID passed in matches this host
		framework::Attribute instanceID = path.getKeyValue(INSTANCEID_KEY);
		if (instanceID.stringValue() == std::string(HOSTSOFTWARE_INSTANCEID + hostName))
		{
			// ElementName - "Host software for " + host name
			if (containsAttribute(ELEMENTNAME_KEY, attributes))
			{
				framework::Attribute a(std::string("Host software for ") + hostName, false);
				pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
			}
		}
		else
		{
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}
	}
	catch (framework::Exception) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::software::ManagementSoftwareIdentityFactory::getInstance(
    framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
    LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

    // create the instance, initialize with attributes from the path
    framework::Instance *pInstance = new framework::Instance(path);
    try
    {
        m_hostName = m_systemService.getHostName();
        checkAttributes(attributes);

        // make sure the instance ID passed in matches this host
        framework::Attribute instanceID = path.getKeyValue(INSTANCEID_KEY);
        if (instanceID.stringValue() == getInstanceId())
        {
            core::Result<core::system::SoftwareInfo> swInfo = m_systemService.getSoftwareInfo();

            // ElementName - mgmt sw name + host name
            if (containsAttribute(ELEMENTNAME_KEY, attributes))
            {
                framework::Attribute a(getElementName(), false);
                pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
            }
            // MajorVersion - Mgmt sw major version number
            if (containsAttribute(MAJORVERSION_KEY, attributes))
            {
                framework::Attribute a(swInfo.getValue().getMgmtSoftwareMajorVersion(),
                                       false);
                pInstance->setAttribute(MAJORVERSION_KEY, a, attributes);
            }
            // MinorVersion - Mgmt sw minor version number
            if (containsAttribute(MINORVERSION_KEY, attributes))
            {
                framework::Attribute a(swInfo.getValue().getMgmtSoftwareMinorVersion(),
                                       false);
                pInstance->setAttribute(MINORVERSION_KEY, a, attributes);
            }
            // RevisionNumber - Mgmt sw hotfix number
            if (containsAttribute(REVISIONNUMBER_KEY, attributes))
            {
                framework::Attribute a(swInfo.getValue().getMgmtSoftwareHotfixVersion(),
                                       false);
                pInstance->setAttribute(REVISIONNUMBER_KEY, a, attributes);
            }
            // BuildNumber - Mgmt sw build number
            if (containsAttribute(BUILDNUMBER_KEY, attributes))
            {
                framework::Attribute a(swInfo.getValue().getMgmtSoftwareBuildVersion(),
                                       false);
                pInstance->setAttribute(BUILDNUMBER_KEY, a, attributes);
            }
            // VersionString - Mgmt sw version as a string
            if (containsAttribute(VERSIONSTRING_KEY, attributes))
            {
                framework::Attribute a(swInfo.getValue().getMgmtSoftwareVersion(), false);
                pInstance->setAttribute(VERSIONSTRING_KEY, a, attributes);
            }
            // Manufacturer - Intel
            if (containsAttribute(MANUFACTURER_KEY, attributes))
            {
                framework::Attribute a("Intel", false);
                pInstance->setAttribute(MANUFACTURER_KEY, a, attributes);
            }
            // Classifications - 3, "Configuration Software"
            if (containsAttribute(CLASSIFICATIONS_KEY, attributes))
            {
                framework::UINT16_LIST classifications;
                classifications.push_back(MANAGEMENTSWIDENTITY_CLASSIFICATIONS_CONFIGSW);
                framework::Attribute a(classifications, false);
                pInstance->setAttribute(CLASSIFICATIONS_KEY, a, attributes);
            }
            // IsEntity = true
            if (containsAttribute(ISENTITY_KEY, attributes))
            {
                framework::Attribute a(true, false);
                pInstance->setAttribute(ISENTITY_KEY, a, attributes);
            }
        }
        else
        {
            throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
        }
    }
    catch (framework::Exception &) // clean up and re-throw
    {
        delete pInstance;
        throw;
    }
    catch (core::LibraryException &e)
    {
        delete pInstance;
        throw exception::NvmExceptionLibError(e.getErrorCode());
    }

    return pInstance;
}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance *wbem::pmem_config::PersistentMemoryCapabilitiesFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw(wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	struct pool *pPool = NULL;
	try
	{
		checkAttributes(attributes);

		pPool = getPool(path);
		struct nvm_capabilities capabilities = getNvmCapabilities();

		// ElementName = "Pool Capabilities for: " + pool UUID
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			NVM_UID poolUidStr;
			uid_copy(pPool->pool_uid, poolUidStr);
			std::string elementNameStr = PMCAP_ELEMENTNAME + poolUidStr;
			framework::Attribute a(elementNameStr, false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}

		// MaxNamespaces = Max namespaces for this pool
		if (containsAttribute(MAXNAMESPACES_KEY, attributes))
		{
			framework::UINT64 maxNs = getMaxNamespacesPerPool(pPool, capabilities.sw_capabilities.min_namespace_size);
			framework::Attribute a(maxNs, false);
			pInstance->setAttribute(MAXNAMESPACES_KEY, a, attributes);
		}

		// SecurityFeatures = Supported security features of the pool
		if (containsAttribute(SECURITYFEATURES_KEY, attributes))
		{
			framework::UINT16_LIST secFeaturesList = getPoolSecurityFeatures(pPool);
			framework::Attribute a(secFeaturesList, false);
			pInstance->setAttribute(SECURITYFEATURES_KEY, a, attributes);
		}

		// AccessGranularity = Block/byte
		if (containsAttribute(ACCESSGRANULARITY_KEY, attributes))
		{
			framework::UINT16_LIST accessList;
			accessList.push_back(PMCAP_ACCESSGRANULARITY_BYTE); // all app direct is byte accessible
			if (pPool->type == POOL_TYPE_PERSISTENT)
			{
				accessList.push_back(PMCAP_ACCESSGRANULARITY_BLOCK); // non mirrored = block capable
			}
			framework::Attribute a(accessList, false);
			pInstance->setAttribute(ACCESSGRANULARITY_KEY, a, attributes);
		}

		// MemoryArchitecture = NUMA
		if (containsAttribute(MEMORYARCHITECTURE_KEY, attributes))
		{
			framework::UINT16_LIST memArchList;
			memArchList.push_back(PMCAP_MEMORYARCHITECTURE_NUMA);
			framework::Attribute a(memArchList, false);
			pInstance->setAttribute(MEMORYARCHITECTURE_KEY, a, attributes);
		}

		// Replication = Mirrored locally or nothing
		if (containsAttribute(REPLICATION_KEY, attributes))
		{
			framework::UINT16_LIST replicationList;
			if (pPool->type == POOL_TYPE_PERSISTENT_MIRROR)
			{
				replicationList.push_back(PMCAP_REPLICATION_LOCAL);
			}
			framework::Attribute a(replicationList, false);
			pInstance->setAttribute(REPLICATION_KEY, a, attributes);
		}

		if (containsAttribute(MEMORYPAGEALLOCATIONCAPABLE_KEY, attributes))
		{
			framework::BOOLEAN capable = capabilities.sw_capabilities.namespace_memory_page_allocation_capable;
			framework::Attribute a(capable, false);
			pInstance->setAttribute(MEMORYPAGEALLOCATIONCAPABLE_KEY, a, attributes);
		}
		delete pPool;
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		if (pInstance)
		{
			delete pInstance;
			pInstance = NULL;
		}
		if (pPool)
		{
			delete pPool;
			pPool = NULL;
		}
		throw;
	}

	return pInstance;
}
void wbem::mem_config::MemoryConfigurationFactory::configGoalToGoalInstance(
		const framework::attribute_names_t &attributes, const struct device_discovery *pDiscovery,
		const struct config_goal &goal, wbem::framework::Instance *pInstance)
{
	// MemorySize
	if (containsAttribute(MEMORYSIZE_KEY, attributes))
	{
		NVM_UINT64 memorySizeBytes = goal.memory_size * BYTES_PER_GIB;
		framework::Attribute a(memorySizeBytes, false);
		pInstance->setAttribute(MEMORYSIZE_KEY, a, attributes);
	}

	framework::UINT32_LIST interleaveFormats;
	framework::UINT16_LIST interleaveIndexes;
	framework::UINT64_LIST interleaveSizes;
	framework::UINT16_LIST packageRedundancy;

	if (goal.app_direct_count > 0)
	{
		interleaveSizes.push_back(goal.app_direct_1_size * BYTES_PER_GIB);
		packageRedundancy.push_back(goal.app_direct_1_settings.mirrored);

		NVM_UINT32 format1 = 0;
		interleave_struct_to_format(&goal.app_direct_1_settings.interleave, &format1);
		interleaveFormats.push_back(format1);
		interleaveIndexes.push_back(goal.app_direct_1_set_id);
	}

	if (goal.app_direct_count > 1)
	{
		interleaveSizes.push_back(goal.app_direct_2_size * BYTES_PER_GIB);
		packageRedundancy.push_back(goal.app_direct_2_settings.mirrored);

		NVM_UINT32 format2 = 0;
		interleave_struct_to_format(&goal.app_direct_2_settings.interleave, &format2);
		interleaveFormats.push_back(format2);
		interleaveIndexes.push_back(goal.app_direct_2_set_id);
	}

	// Interleave set sizes
	if (containsAttribute(INTERLEAVESIZES_KEY, attributes))
	{
		framework::Attribute a(interleaveSizes, false);
		pInstance->setAttribute(INTERLEAVESIZES_KEY, a, attributes);
	}

	// Package redundancy
	if (containsAttribute(PACKAGEREDUNDANCY_KEY, attributes))
	{
		framework::Attribute a(packageRedundancy, false);
		pInstance->setAttribute(PACKAGEREDUNDANCY_KEY, a, attributes);
	}

	// Interleave formats
	if (containsAttribute(INTERLEAVEFORMATS_KEY, attributes))
	{
		framework::Attribute a(interleaveFormats, false);
		pInstance->setAttribute(INTERLEAVEFORMATS_KEY, a, attributes);
	}

	// Interleave indexes
	if (containsAttribute(INTERLEAVEINDEXES_KEY, attributes))
	{
		framework::Attribute indexes(interleaveIndexes, false);
		pInstance->setAttribute(INTERLEAVEINDEXES_KEY, indexes, attributes);
	}

	// Storage capacity
	if (containsAttribute(STORAGECAPACITY_KEY, attributes))
	{
		NVM_UINT64 storageCapacity = getDimmStorageCapacityFromGoal(pDiscovery, goal);

		framework::Attribute a(storageCapacity, false);
		pInstance->setAttribute(STORAGECAPACITY_KEY, a, attributes);
	}

	// Status
	if (containsAttribute(STATUS_KEY, attributes))
	{
		framework::Attribute a((NVM_UINT32)goal.status,
				configGoalStatusToString(goal.status), false);
		pInstance->setAttribute(STATUS_KEY, a, attributes);
	}
}
/*
 * Populate a current config instance with memory and storage sizes and also interleave set information
 */
void wbem::mem_config::MemoryConfigurationFactory::populateCurrentConfigInstance(
		const framework::attribute_names_t &attributes,
		const std::string &uidStr,
		wbem::framework::Instance* pInstance,
		const struct device_discovery *p_discovery)
{
	framework::UINT64 memoryCapacity = 0;
	framework::UINT64 storageCapacity = 0;
	framework::UINT32_LIST interleaveFormats;
	framework::UINT64_LIST interleaveSizes;
	framework::UINT16_LIST redundancies;
	framework::UINT16_LIST setIndexes;

	NVM_UID uid;
	lib_interface::NvmApi::stringToNvmUid(uidStr, uid);

	lib_interface::NvmApi *pApi = lib_interface::NvmApi::getApi();

	std::vector<struct pool> pools;
	pApi->getPools(pools);

	if (pools.size() > 0)
	{
		memoryCapacity = getDimmMemoryCapacityFromCurrentConfig(uid, pools);
		storageCapacity = getDimmStorageCapacityFromCurrentConfig(uid, pools);

		std::vector <InterleaveSetInfo> infos;
		getCurrentIlsetInfo(uid, pools, infos);

		for (size_t i = 0; i < infos.size(); i++)
		{

			interleaveFormats.push_back(infos[i].settings);
			interleaveSizes.push_back(infos[i].size);
			redundancies.push_back(infos[i].mirrored);
			setIndexes.push_back(infos[i].setIndex);
		}
	}

	// MemorySize
	if (containsAttribute(MEMORYSIZE_KEY, attributes))
	{
		framework::Attribute a(memoryCapacity, false);
		pInstance->setAttribute(MEMORYSIZE_KEY, a, attributes);
	}

	// StorageCapacity - unmapped storage capacity in this pool
	if (containsAttribute(STORAGECAPACITY_KEY, attributes))
	{
		framework::Attribute a(storageCapacity, false);
		pInstance->setAttribute(STORAGECAPACITY_KEY, a, attributes);
	}

	// InterleaveFormats - list of uint16 bitmaps representing channel size, iMC size, way
	// of each interleave set in this pool.
	if (containsAttribute(INTERLEAVEFORMATS_KEY, attributes))
	{
		framework::Attribute a(interleaveFormats, false);
		pInstance->setAttribute(INTERLEAVEFORMATS_KEY, a, attributes);
	}
		
	// InterleaveSizes - corresponding sizes of each interleave set listed in InterleaveFormats
	if (containsAttribute(INTERLEAVESIZES_KEY, attributes))
	{
		framework::Attribute a(interleaveSizes, false);
		pInstance->setAttribute(INTERLEAVESIZES_KEY, a, attributes);
	}

	// PackageRedundancy - 1 for mirrored, 0 for other (including memory mode)
	if (containsAttribute(PACKAGEREDUNDANCY_KEY, attributes))
	{
		framework::Attribute a(redundancies, false);
		pInstance->setAttribute(PACKAGEREDUNDANCY_KEY, a, attributes);
	}

	// InterleaveSetIndex - unique index of interleave set
	if (containsAttribute(INTERLEAVEINDEXES_KEY, attributes))
	{
		framework::Attribute a(setIndexes, false);
		pInstance->setAttribute(INTERLEAVEINDEXES_KEY, a, attributes);
	}

	// Status - doesn't apply to current config
	if (containsAttribute(STATUS_KEY, attributes))
	{
		framework::Attribute a(wbem::NA, false);
		pInstance->setAttribute(STATUS_KEY, a, attributes);
	}
}
Пример #16
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance *wbem::pmem_config::NamespaceSettingsFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw(wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		std::string nsUidStr = path.getKeyValue(INSTANCEID_KEY).stringValue();
		if (!core::Helper::isValidNamespaceUid(nsUidStr))
		{
			COMMON_LOG_ERROR_F("NamespaceSettings InstanceID is not a valid namespace uid %s",
					nsUidStr.c_str());
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}

		struct namespace_details ns = NamespaceViewFactory::getNamespaceDetails(nsUidStr);

		// ElementName = Friendly Name
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			framework::Attribute a(
					std::string(NSSETTINGS_ELEMENTNAME_PREFIX + ns.discovery.friendly_name), false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}

		// AllocationUnits = block size as a string
		if (containsAttribute(ALLOCATIONUNITS_KEY, attributes))
		{
			std::stringstream allocationUnits;
			allocationUnits << NSSETTINGS_ALLOCATIONUNITS_BYTES;
			allocationUnits << "*";
			allocationUnits << ns.block_size;
			framework::Attribute a(allocationUnits.str(), false);
			pInstance->setAttribute(ALLOCATIONUNITS_KEY, a, attributes);
		}

		// Reservation = block count
		if (containsAttribute(RESERVATION_KEY, attributes))
		{
			NVM_UINT64 nsBytes = ns.block_count * ns.block_size;
			framework::Attribute a(nsBytes, false);
			pInstance->setAttribute(RESERVATION_KEY, a, attributes);
		}

		// PoolID = Pool UID
		if (containsAttribute(POOLID_KEY, attributes))
		{
			NVM_UID poolUidStr;
			uid_copy(ns.pool_uid, poolUidStr);
			framework::Attribute a(poolUidStr, false);
			pInstance->setAttribute(POOLID_KEY, a, attributes);
		}

		// ResourceType = type
		if (containsAttribute(RESOURCETYPE_KEY, attributes))
		{
			framework::Attribute a(
					namespaceResourceTypeToValue(ns.type),
					namespaceResourceTypeToStr(ns.type), false);
			pInstance->setAttribute(RESOURCETYPE_KEY, a, attributes);
		}

		// Optimize = Btt
		if (containsAttribute(OPTIMIZE_KEY, attributes))
		{
			framework::Attribute a(
					NamespaceViewFactory::namespaceOptimizeToValue(ns.btt),
					NamespaceViewFactory::namespaceOptimizeToStr(ns.btt), false);
			pInstance->setAttribute(OPTIMIZE_KEY, a, attributes);
		}

		// ChangeableType = 0 - "Fixed � Not Changeable"
		if (containsAttribute(CHANGEABLETYPE_KEY, attributes))
		{
			framework::Attribute a(NSSETTINGS_CHANGEABLETYPE_NOTCHANGEABLETRANSIENT, false);
			pInstance->setAttribute(CHANGEABLETYPE_KEY, a, attributes);
		}
	
		// SecurityFeatures
                if (containsAttribute(ENCRYPTIONENABLED_KEY, attributes))
                {
                        pInstance->setAttribute(ENCRYPTIONENABLED_KEY,
                                framework::Attribute((NVM_UINT16)ns.security_features.encryption, false));
                }

                if (containsAttribute(ERASECAPABLE_KEY, attributes))
                {
                        pInstance->setAttribute(ERASECAPABLE_KEY,
                                framework::Attribute((NVM_UINT16)ns.security_features.erase_capable, false));
                }

		// ChannelInterleaveSize
		if (containsAttribute(CHANNELINTERLEAVESIZE_KEY, attributes))
		{
			NVM_UINT16 channelSize =
					(NVM_UINT16)mem_config::InterleaveSet::getExponentFromInterleaveSize(
								ns.interleave_format.channel);

			framework::Attribute a(channelSize, false);
			pInstance->setAttribute(CHANNELINTERLEAVESIZE_KEY, a, attributes);
		}

		// ControllerInterleaveSize
		if (containsAttribute(CONTROLLERINTERLEAVESIZE_KEY, attributes))
		{
			NVM_UINT16 channelSize =
					(NVM_UINT16)mem_config::InterleaveSet::getExponentFromInterleaveSize(
								ns.interleave_format.imc);

			framework::Attribute a(channelSize, false);
			pInstance->setAttribute(CONTROLLERINTERLEAVESIZE_KEY, a, attributes);
		}

		if (containsAttribute(MEMORYPAGEALLOCATION_KEY, attributes))
		{
			framework::Attribute a((NVM_UINT16)ns.memory_page_allocation,
				NamespaceViewFactory::namespaceMemoryPageAllocationToStr(ns.memory_page_allocation), false);
			pInstance->setAttribute(MEMORYPAGEALLOCATION_KEY, a, attributes);
		}

		// NOTE: No need to populate Parent, or InitialState - only for create
	}
	catch (framework::Exception &)
	{
		if (pInstance)
		{
			delete pInstance;
			pInstance = NULL;
		}
		throw;
	}

	return pInstance;
}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::support::NVDIMMSensorViewFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
		throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	framework::Instance *pInstance = new framework::Instance(path);

	try
	{
		// Get the sensorViewAttributes
		checkAttributes(attributes);

		framework::Attribute attribute = path.getKeyValue(DEVICEID_KEY);

		std::string guidStr;
		enum sensor_type type;
		if(!NVDIMMSensorFactory::splitDeviceIdAttribute(attribute, guidStr, (int &)type))
		{
			throw framework::ExceptionBadParameter(DEVICEID_KEY.c_str());
		}

		NVM_GUID guid;
		str_to_guid(guidStr.c_str(), guid);

		struct sensor sensor;
		int rc = NVM_SUCCESS;
		if ((rc = nvm_get_sensor(guid, type, &sensor)) != NVM_SUCCESS)
		{
			throw exception::NvmExceptionLibError(rc);
		}

		// DimmID = handle or guid depending on user selection
		if (containsAttribute(DIMMID_KEY, attributes))
		{
				framework::Attribute attrDimmId = physical_asset::NVDIMMFactory::guidToDimmIdAttribute(guidStr);
				pInstance->setAttribute(DIMMID_KEY, attrDimmId, attributes);
		}
		// DimmGUID
		if (containsAttribute(DIMMGUID_KEY, attributes))
		{
			framework::Attribute attrDimmHandle(guidStr, false);
			pInstance->setAttribute(DIMMGUID_KEY, attrDimmHandle, attributes);
		}
		// DimmHandle = NFIT Handle
		if (containsAttribute(DIMMHANDLE_KEY, attributes))
		{
			NVM_UINT32 handle;
			physical_asset::NVDIMMFactory::guidToHandle(guidStr, handle);
			framework::Attribute attrDimmHandle(handle, false);
			pInstance->setAttribute(DIMMHANDLE_KEY, attrDimmHandle, attributes);
		}
		if (containsAttribute(TYPE_KEY, attributes))
		{
			framework::Attribute a(getSensorNameStr(type), false);
			pInstance->setAttribute(TYPE_KEY, a, attributes);
		}
		if (containsAttribute(CURRENTVALUE_KEY, attributes))
		{
			std::stringstream currentValue;
			if (sensor.units == UNIT_SECONDS)
			{
				// convert to HH:MM:SS, note HH can grow beyond 2 digits which is fine.
				NVM_UINT64 hours, minutes, seconds, remainder = 0;
				// 60 seconds in a minute, 60 minutes in an hour
				hours = sensor.reading / (60*60);
				remainder = sensor.reading % (60*60);
				minutes = remainder / 60;
				seconds = remainder % 60;
				currentValue << std::setfill('0') << std::setw(2) << hours << ":";
				currentValue << std::setfill('0') << std::setw(2) << minutes << ":";
				currentValue << std::setfill('0') << std::setw(2) << seconds;
			}
			else if (sensor.type == SENSOR_MEDIA_TEMPERATURE || sensor.type == SENSOR_CONTROLLER_TEMPERATURE)
			{
				float celsius = nvm_decode_temperature(sensor.reading);
				currentValue << celsius << baseUnitToString(sensor.units);
			}
			else
			{
				NVM_INT32 scaled = 0;
				NVM_INT32 scaler = 0;
				NVDIMMSensorFactory::scaleNumberBaseTen(sensor.reading, &scaled, &scaler);
				currentValue << scaled << baseUnitToString(sensor.units);
				if (scaler > 0)
				{
					currentValue << "* 10 ^" << scaler;
				}
			}

			framework::Attribute a(currentValue.str(), false);
			pInstance->setAttribute(CURRENTVALUE_KEY, a, attributes);
		}
		if (containsAttribute(ENABLEDSTATE_KEY, attributes))
		{
			std::string enabledState;
			if ((sensor.type == SENSOR_MEDIA_TEMPERATURE) || (sensor.type == SENSOR_SPARECAPACITY)
				|| (sensor.type == SENSOR_CONTROLLER_TEMPERATURE))
			{
				enabledState = getEnabledStateStr(
						sensor.settings.enabled ? SENSOR_ENABLEDSTATE_ENABLED : SENSOR_ENABLEDSTATE_DISABLED);
			}
			else
			{
				enabledState = getEnabledStateStr(SENSOR_ENABLEDSTATE_NA);
			}
			framework::Attribute a(enabledState, false);
			pInstance->setAttribute(ENABLEDSTATE_KEY, a, attributes);
		}
		if (containsAttribute(LOWERTHRESHOLDCRITICAL_KEY, attributes))
		{
			framework::Attribute a(sensor.settings.lower_critical_threshold, false);
			pInstance->setAttribute(LOWERTHRESHOLDCRITICAL_KEY, a, attributes);
		}
		if (containsAttribute(UPPERTHRESHOLDCRITICAL_KEY, attributes))
		{
			if (sensor.type == SENSOR_MEDIA_TEMPERATURE || sensor.type == SENSOR_CONTROLLER_TEMPERATURE)
			{
				float celsius = nvm_decode_temperature(sensor.settings.upper_critical_threshold);
				pInstance->setAttribute(UPPERTHRESHOLDCRITICAL_KEY,
						framework::Attribute (celsius, false),
						attributes);
			}
			else
			{
				pInstance->setAttribute(UPPERTHRESHOLDCRITICAL_KEY,
						framework::Attribute (sensor.settings.upper_critical_threshold, false),
						attributes);
			}

		}
		if (containsAttribute(CURRENTSTATE_KEY, attributes))
		{
			framework::Attribute a(NVDIMMSensorFactory::getSensorStateStr(sensor.current_state), false);
			pInstance->setAttribute(CURRENTSTATE_KEY, a, attributes);
		}
		if (containsAttribute(SUPPORTEDTHRESHOLDS_KEY, attributes))
		{
			framework::STR_LIST supportedThresholds;
			if (sensor.lower_critical_support)
			{
				supportedThresholds.push_back(getThresholdTypeStr(SENSOR_LOWER_CRITICAL_THRESHOLD));
			}
			if (sensor.upper_critical_support)
			{
				supportedThresholds.push_back(getThresholdTypeStr(SENSOR_UPPER_CRITICAL_THRESHOLD));
			}
			framework::Attribute a(supportedThresholds, false);
			pInstance->setAttribute(SUPPORTEDTHRESHOLDS_KEY, a, attributes);
		}
		if (containsAttribute(SETTABLETHRESHOLDS_KEY, attributes))
		{
			framework::STR_LIST settableThresholds;
			if (sensor.lower_critical_settable)
			{
				settableThresholds.push_back(getThresholdTypeStr(SENSOR_LOWER_CRITICAL_THRESHOLD));
			}
			if (sensor.upper_critical_settable)
			{
				settableThresholds.push_back(getThresholdTypeStr(SENSOR_UPPER_CRITICAL_THRESHOLD));
			}
			framework::Attribute a(settableThresholds, false);
			pInstance->setAttribute(SETTABLETHRESHOLDS_KEY, a, attributes);
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		if (pInstance != NULL)
		{
			delete pInstance;
		}
		throw;
	}

	return pInstance;
}
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::support::DiagnosticCompletionRecordFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		// gather results
		bool diagFound = false;
		wbem::support::diagnosticResults_t results;
		DiagnosticLogFactory::gatherDiagnosticResults(&results);

		// match the instance ID
		framework::Attribute instanceID = path.getKeyValue(INSTANCEID_KEY);
		for (diagnosticResults_t::iterator iter = results.begin(); iter != results.end(); iter++)
		{
			struct diagnosticResult diag = *iter;
			std::stringstream instanceIdStr;
			instanceIdStr << DIAGNOSTICCOMPLETION_INSTANCEID << diag.id;
			if (instanceID.stringValue() == instanceIdStr.str())
			{
				diagFound = true;

				// ServiceName = Diagnostic Test Name
				if (containsAttribute(SERVICENAME_KEY, attributes))
				{
					std::string testName;
					switch (diag.type)
					{
						case EVENT_TYPE_DIAG_QUICK:
							testName = NVDIMMDIAGNOSTIC_TEST_QUICK;
							break;
						case EVENT_TYPE_DIAG_PLATFORM_CONFIG:
							testName = NVDIMMDIAGNOSTIC_TEST_PLATFORM;
							break;
						case EVENT_TYPE_DIAG_PM_META:
							testName = NVDIMMDIAGNOSTIC_TEST_STORAGE;
							break;
						case EVENT_TYPE_DIAG_SECURITY:
							testName = NVDIMMDIAGNOSTIC_TEST_SECURITY;
							break;
						case EVENT_TYPE_DIAG_FW_CONSISTENCY:
							testName = NVDIMMDIAGNOSTIC_TEST_SETTING;
							break;
						default:
							testName = "Unknown";
							break;
					}
					framework::Attribute serviceNameAttr(testName, false);
					pInstance->setAttribute(SERVICENAME_KEY, serviceNameAttr, attributes);
				}

				// ManagedElementName - Intel NVDIMM + UUID
				if (containsAttribute(MANAGEDELEMENTNAME_KEY, attributes))
				{
					std::string elementName = "";
					if (diag.device_uid)
					{
						NVM_UID uid_str;
						uid_copy(diag.device_uid, uid_str);
						elementName = wbem::physical_asset::NVDIMM_ELEMENTNAME_prefix + uid_str;
					}

					framework::Attribute dimmAttr(elementName, false);
					pInstance->setAttribute(MANAGEDELEMENTNAME_KEY, dimmAttr, attributes);
				}

				// CreationTimeStamp - record time stamp
				if (containsAttribute(CREATIONTIMESTAMP_KEY, attributes))
				{
					framework::Attribute timeAttr(diag.time,
									wbem::framework::DATETIME_SUBTYPE_DATETIME, false);
					pInstance->setAttribute(CREATIONTIMESTAMP_KEY, timeAttr, attributes);
				}

				// ErrorCode - Array of diagnostic result messages
				if (containsAttribute(ERRORCODE_KEY, attributes))
				{
					framework::Attribute msgsAttr(diag.messages, false);
					pInstance->setAttribute(ERRORCODE_KEY, msgsAttr, attributes);
				}

				// CompletionState - Combined result of diagnostic
				if (containsAttribute(COMPLETIONSTATE_KEY, attributes))
				{
					std::string stateStr;
					switch (diag.result)
					{
						case DIAGNOSTIC_RESULT_OK:
							stateStr = "OK";
							break;
						case DIAGNOSTIC_RESULT_WARNING:
							stateStr = "Warning";
							break;
						case DIAGNOSTIC_RESULT_FAILED:
							stateStr = "Failed";
							break;
						case DIAGNOSTIC_RESULT_ABORTED:
							stateStr = "Aborted";
							break;
						case DIAGNOSTIC_RESULT_UNKNOWN:
						default:
							stateStr = "Unknown";
							break;
					}
					framework::Attribute stateAttr((NVM_UINT16)diag.result, stateStr, false);
					pInstance->setAttribute(COMPLETIONSTATE_KEY, stateAttr, attributes);
				}

				break;
			} // end record found
		} // for

		if (!diagFound)
		{
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}
	}
	catch (framework::Exception) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}