Exemple #1
0
int LibWrapper::getNamespaceDetails(const NVM_UID namespaceUid,
	struct namespace_details *pNamespace) const
{
	LogEnterExit(__FUNCTION__, __FILE__, __LINE__);
	return nvm_get_namespace_details(namespaceUid, pNamespace);
}
Exemple #2
0
/*
 * Check for namespace health transitions
 */
void monitor::EventMonitor::monitorNamespaces(PersistentStore *pStore)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	if (pStore)
	{
		// get namespaces
		int nsCount = nvm_get_namespace_count();
		if (nsCount < 0)
		{
			COMMON_LOG_ERROR_F("nvm_get_namespace_count failed with error %d", nsCount);
		}
		else if (nsCount > 0)
		{
			struct namespace_discovery namespaces[nsCount];
			memset(namespaces, 0, sizeof (struct namespace_discovery) * nsCount);
			nsCount = nvm_get_namespaces(namespaces, nsCount);
			if (nsCount < 0)
			{
				COMMON_LOG_ERROR_F("nvm_get_namespaces failed with error %d", nsCount);
			}
			else if (nsCount > 0)
			{
				// for each namespace
				for (int i = 0; i < nsCount; i++)
				{
					struct namespace_details details;
					memset(&details, 0, sizeof (details));
					NVM_UID uidStr;
					uid_copy(namespaces[i].namespace_uid, uidStr);
					int rc = nvm_get_namespace_details(namespaces[i].namespace_uid, &details);
					if (rc != NVM_SUCCESS)
					{
						COMMON_LOG_ERROR_F("nvm_get_namespace_details for namespace %s failed with error %d",
								uidStr, rc);
					}
					else
					{
						// get the stored state for this namespace
						bool storedStateChanged = false;

						struct db_namespace_state storedState;
						memset(&storedState, 0, sizeof (storedState));
						if (db_get_namespace_state_by_namespace_uid(pStore,
								uidStr, &storedState) != DB_SUCCESS)
						{
							// initial state, just store current state
							s_strcpy(storedState.namespace_uid, uidStr,
									NAMESPACE_STATE_NAMESPACE_UID_LEN);
							storedState.health_state = details.health;
							storedStateChanged = true;
						}
						// log health transition event
						else if (details.health != storedState.health_state)
						{
							enum event_severity severity = EVENT_SEVERITY_INFO;
							bool actionRequired = false;
							// namespace is failed
							if (details.health == NAMESPACE_HEALTH_CRITICAL ||
								details.health == NAMESPACE_HEALTH_BROKENMIRROR)
							{
								severity = EVENT_SEVERITY_CRITICAL;
								actionRequired = true;
							}
							// namespace is not failed
							else
							{
								// auto-acknowledge any old namespace health failed events
								acknowledgeEvent(EVENT_CODE_HEALTH_NAMESPACE_HEALTH_STATE_CHANGED,
										namespaces[i].namespace_uid);
							}

							std::string oldState = namespaceHealthToStr(
									(enum namespace_health)storedState.health_state);
							std::string newState = namespaceHealthToStr(details.health);
							store_event_by_parts(
									EVENT_TYPE_HEALTH,
									severity,
									EVENT_CODE_HEALTH_NAMESPACE_HEALTH_STATE_CHANGED,
									namespaces[i].namespace_uid,
									actionRequired,
									uidStr,
									oldState.c_str(),
									newState.c_str(),
									DIAGNOSTIC_RESULT_UNKNOWN);

							storedStateChanged = true;
							storedState.health_state = details.health;
							if (db_delete_namespace_state_by_namespace_uid(pStore,
									uidStr) != DB_SUCCESS)
							{
								COMMON_LOG_ERROR_F(
									"Failed to clean up the stored health state for namespace %s",
									uidStr);
							}
						}

						if (storedStateChanged)
						{
							if (db_add_namespace_state(pStore, &storedState) != DB_SUCCESS)
							{
								COMMON_LOG_ERROR_F(
									"Failed to update the stored health state for namespace %s",
									uidStr);
							}
						}
					} // end nvm_get_namespace_details
				} // end for each namespace
			} // end nvm_get_namespaces
		} // end nvm_get_namespace_count
	} // end get peristent store
}