Exemplo n.º 1
0
monitor::EventMonitor::~EventMonitor()
{
	if (get_lib_store())
	{
		close_lib_store();
	}
}
Exemplo n.º 2
0
monitor::EventMonitor::EventMonitor() : NvmMonitorBase("EVENT"), m_nsMgmtCallbackId(-1)
{
	if (!get_lib_store())
	{
		open_default_lib_store();
	}
}
Exemplo n.º 3
0
/*
 * Clear existing diagnostic results for the specified diagnostic
 * and optionally for the specified device.
 */
void diag_clear_results(const enum diagnostic_test type,
		const NVM_BOOL clear_specific_device, const NVM_GUID device_guid)
{
	int event_count;
	PersistentStore *p_store = get_lib_store();
	if (p_store)
	{
		db_get_event_count_by_event_type_type(p_store, type, &event_count);
		struct db_event events[event_count];
		db_get_events_by_event_type_type(p_store, type, events, event_count);
		for (int i = 0; i < event_count; i++)
		{
			NVM_BOOL matched = 1;
			// check for a matching guid is requested
			if (clear_specific_device)
			{
				COMMON_GUID guid;
				str_to_guid(events[i].guid, guid);
				if (guid_cmp(guid, device_guid) != 1)
				{
					matched = 0;
				}
			}
			if (matched)
			{
				db_delete_event_by_id(p_store, events[i].id);
			}
		}
	}
}
Exemplo n.º 4
0
void monitor::EventMonitor::monitor()
{
	PersistentStore *pStore = get_lib_store();
	if (pStore)
	{
		LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

		// clean up any context
		nvm_create_context();

		DeviceMap devMap;
		buildDeviceMap(devMap);
		for (DeviceMap::const_iterator devIter = devMap.begin();
				devIter != devMap.end(); devIter++)
		{
			const std::string &uidStr = devIter->first;
			const struct device_discovery &discovery = devIter->second.discovery;

			// ignore unmanageable dimms
			if (discovery.manageability == MANAGEMENT_VALIDCONFIG)
			{
				bool storedStateChanged = false;
				bool firstState = false;

				// get stored device state
				struct db_dimm_state storedState;
				memset(&storedState, 0, sizeof (storedState));
				if (db_get_dimm_state_by_device_handle(pStore,
						discovery.device_handle.handle, &storedState) != DB_SUCCESS)
				{
					// initial state, just store current
					firstState = true;
					COMMON_LOG_INFO_F("Failed to retrieve the stored health state of dimm %u",
							discovery.device_handle.handle);
					storedState.device_handle = discovery.device_handle.handle;
					storedStateChanged = true;
				}

				// check for dimm health state transition
				monitorDimmStatus(uidStr, discovery, storedState,
						storedStateChanged, firstState);

				// check for dimm sensor transitions
				monitorDimmSensors(uidStr, discovery, storedState,
						storedStateChanged, firstState);

				// update stored dimm state
				if (storedStateChanged)
				{
					// clear existing dimm state
					if (!firstState)
					{
						db_delete_dimm_state_by_device_handle(pStore,
								discovery.device_handle.handle);
					}
					// add current state
					if (db_add_dimm_state(pStore, &storedState) != DB_SUCCESS)
					{
						COMMON_LOG_ERROR_F("Failed to store the health state of dimm %u",
								discovery.device_handle.handle);
					}
				}
			}
		}

		// Monitor namespace health transitions
		monitorNamespaces(pStore);

		// clean up
		devMap.clear();
		nvm_free_context();
	}

}
Exemplo n.º 5
0
/*
 * Build a map of uids to discovery information for all NVM-DIMM in the system
 */
void monitor::EventMonitor::buildDeviceMap(DeviceMap& map, bool addStoredTopology)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// build a map of the current devices
	int devCount = nvm_get_device_count();
	if (devCount < 0) // error getting dimm count
	{
		COMMON_LOG_ERROR_F("nvm_get_device_count failed with error %d", devCount);
	}
	else if (devCount > 0) // at least one dimm
	{
		struct device_discovery devList[devCount];
		devCount = nvm_get_devices(devList, devCount);
		if (devCount < 0) // error get dimm discovery
		{
			COMMON_LOG_ERROR_F("nvm_get_devices failed with error %d", devCount);
		}
		else if (devCount > 0) // at least one dimm
		{
			for (int i = 0; i < devCount; i++)
			{
				NVM_UID uidStr;
				uid_copy(devList[i].uid, uidStr);
				struct deviceInfo devInfo;
				memset(&devInfo, 0, sizeof (deviceInfo));
				devInfo.discovered = true;
				devInfo.discovery = devList[i];
				if (devList[i].manageability == MANAGEMENT_VALIDCONFIG)
				{
					// Fetch the device status
					int rc = nvm_get_device_status(devList[i].uid, &devInfo.status);
					if (rc != NVM_SUCCESS)
					{
						COMMON_LOG_ERROR_F("nvm_get_device_status failed for dimm %s, error = %d",
								uidStr, rc);
					}
				}
				map[uidStr] = devInfo;
			}
		}
	}

	// add stored db info
	if (addStoredTopology)
	{
		int valid = 0;
		PersistentStore *pStore = get_lib_store();
		if (pStore)
		{
			if ((get_config_value_int(SQL_KEY_TOPOLOGY_STATE_VALID, &valid) == COMMON_SUCCESS) &&
					(valid))
			{
				int topoStateCount = 0;
				if (db_get_topology_state_count(pStore, &topoStateCount) == DB_SUCCESS &&
						topoStateCount > 0)
				{
					// Populate the previous topology state map
					struct db_topology_state topologyState[topoStateCount];
					if (db_get_topology_states(pStore, topologyState, topoStateCount) == topoStateCount)
					{
						for (int i = 0; i < topoStateCount; i++)
						{
							std::string uidStr = topologyState[i].uid;
							if (map.find(uidStr) == map.end()) // doesn't exist - missing dimm
							{
								struct deviceInfo devInfo;
								memset(&devInfo, 0, sizeof (deviceInfo));
								devInfo.discovered = false;
								devInfo.stored = true;
								devInfo.storedState = topologyState[i];
								map[uidStr] = devInfo;
							}
							else
							{
								map[uidStr].stored = true;
								map[uidStr].storedState = topologyState[i];
							}
						}
					}
				}
			}
		}
	}
}
Exemplo n.º 6
0
void monitor::EventMonitor::saveCurrentTopologyState(const DeviceMap &devices)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	bool saved = true;

	PersistentStore *pStore = get_lib_store();
	if (pStore)
	{
		// Only keep the latest topology
		if (db_delete_all_topology_states(pStore) != DB_SUCCESS)
		{
			COMMON_LOG_ERROR("couldn't delete old topology_state");
			saved = false;
		}
		else
		{
			// Preserve topology state in config DB
			for (DeviceMap::const_iterator iter = devices.begin();
					iter != devices.end(); iter++)
			{
				const std::string &uidStr = iter->first;
				const struct deviceInfo &device = iter->second;

				// only store current devices
				if (device.discovered)
				{
					struct db_topology_state topoState;
					memset(&topoState, 0, sizeof(topoState));
					s_strcpy(topoState.uid, uidStr.c_str(), NVM_MAX_UID_LEN);
					topoState.device_handle = device.discovery.device_handle.handle;
					topoState.manufacturer = MANUFACTURER_TO_UINT(device.discovery.manufacturer);
					topoState.serial_num = SERIAL_NUMBER_TO_UINT(device.discovery.serial_number);
					memmove(topoState.model_num, device.discovery.model_number, NVM_MODEL_LEN);

					topoState.current_config_status = device.status.config_status;
					topoState.config_goal_status = CONFIG_GOAL_STATUS_UNKNOWN;

					struct config_goal goal;
					memset(&goal, 0, sizeof (goal));
					int rc = nvm_get_config_goal(device.discovery.uid, &goal);
					if (rc == NVM_SUCCESS)
					{
						topoState.config_goal_status = goal.status;
					}
					else if (rc == NVM_ERR_NOTFOUND)
					{
						COMMON_LOG_DEBUG_F("No goal for DIMM %s", uidStr.c_str());
					}
					else
					{
						COMMON_LOG_ERROR_F("Error fetching config goalfor DIMM %s: %d",
						                   uidStr.c_str(),
						                   rc);
					}

					if (db_add_topology_state(pStore, &topoState) != DB_SUCCESS)
					{
						COMMON_LOG_ERROR_F("couldn't add topology_state for DIMM %s",
								topoState.uid);
						saved = false;
						break;
					}
				}
			}
		}

		// everything succeeded
		if (saved)
		{
			add_config_value(SQL_KEY_TOPOLOGY_STATE_VALID, "1");
		}
	}
}