Example #1
0
STDMETHODIMP 
CNdasUnitImpl::CheckNdasfsCompatibility()
{
	CAutoInstanceLock autolock(this);

	HRESULT hr;

	// Unit devices other than disks are not allowed for NDFS

	if (m_type != NDAS_UNITDEVICE_TYPE_DISK) {

		return E_FAIL;
	}

	// LfsFilter compatibility check.
	// NDFS Major version should be same
 
	WORD wHostNDFSVerMajor;
	BOOL success = ::LfsFiltCtlGetVersion( NULL, NULL, NULL, NULL, &wHostNDFSVerMajor, NULL );

	if (!success) {

		ATLASSERT(FALSE);

		hr = HRESULT_FROM_WIN32(GetLastError());
		hr = SUCCEEDED(hr) ? E_FAIL : hr;
		
		return hr;
	}

	ATLASSERT( wHostNDFSVerMajor == 0x0006 );

	// Primary Host Info is valid for 30 seconds

#if 0
	DWORD dwMaxTickAllowance = 30 * 1000;
	if (0 != m_PrimaryHostInfo.NDFSCompatVersion &&
		::GetTickCount() < m_PrimaryHostInfo.LastUpdate + dwMaxTickAllowance) 
	{
		// primary host info is valid
		return (wHostNDFSVerMajor == m_PrimaryHostInfo.NDFSCompatVersion);
	}
#endif

	// No Primary Host Info is available (IX)
	// Use HIX to discover

	CNdasHIXDiscover hixdisc(pGetNdasHostGuid());

	success = hixdisc.Initialize();

	if (!success) {

		ATLASSERT(FALSE);

		hr = HRESULT_FROM_WIN32(GetLastError());
		hr = SUCCEEDED(hr) ? E_FAIL : hr;

		return hr;
	}

	NDAS_UNITDEVICE_ID ndasUnitId;

	get_NdasUnitId( &ndasUnitId );

	ATLASSERT( ndasUnitId.DeviceId.Reserved == 0 );

	DWORD timeout = NdasServiceConfig::Get(nscWriteShareCheckTimeout);

	success = hixdisc.HixDiscover( ndasUnitId, NHIX_UDA_SHRW_PRIM, 1, timeout );

	if (!success) {

		ATLASSERT(FALSE);

		hr = HRESULT_FROM_WIN32(GetLastError());
		hr = SUCCEEDED(hr) ? E_FAIL : hr;

		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"hixdisc.Discover failed, hr=0x%X\n", hr);

		return hr;
	}

	DWORD nHosts = hixdisc.GetHostCount(ndasUnitId);

	if (nHosts == 0) {

		hr = HRESULT_FROM_WIN32(GetLastError());
		hr = SUCCEEDED(hr) ? E_FAIL : hr;

		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"GetHostCount failed, hr=0x%X\n", hr);

		return hr;
	}

	GUID hostGuid;

	success = hixdisc.GetHostData( ndasUnitId, 0, NULL, &hostGuid, NULL, NULL );
	
	if (!success) {

		ATLASSERT(FALSE);

		hr = HRESULT_FROM_WIN32(GetLastError());
		hr = SUCCEEDED(hr) ? E_FAIL : hr;

		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"GetHostData failed, hr=0x%X\n", hr);

		return hr;
	}

	CNdasHostInfoCache* phic = pGetNdasHostInfoCache();

	XTLASSERT(phic); // phic is not null (by pGetNdasHostInfoCache)
	const NDAS_HOST_INFO* pHostInfo = phic->GetHostInfo(&hostGuid);
	
	if (pHostInfo == NULL) {

		ATLASSERT(FALSE);

		hr = HRESULT_FROM_WIN32(GetLastError());
		hr = SUCCEEDED(hr) ? E_FAIL : hr;

		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"GetHostInfo failed, hr=0x%X\n", hr);

		return hr;
	}

	// ReservedVerInfo contains NDFS Version Information

	if (pHostInfo->ReservedVerInfo.VersionMajor != wHostNDFSVerMajor) {

		NdasUiDbgCall( 1, "Host NDFS %d, Primary NDFS %d failed\n", wHostNDFSVerMajor, pHostInfo->ReservedVerInfo.VersionMajor );

		return E_FAIL;
	}

	// Primary and this host's NDFS compatible version is same

	return S_OK;
}
Example #2
0
STDMETHODIMP
CNdasUnitImpl::GetActualHostUsageCount (
	LPDWORD lpnROHosts, 
	LPDWORD lpnRWHosts, 
	BOOL	bUpdate
	)
{
	DWORD nROHosts = 0;
	DWORD nRWHosts = 0;

	HRESULT hr = GetHostUsageCount( &nROHosts, &nRWHosts, bUpdate );
	
	if (FAILED(hr)) {

		return hr;
	}

	// Following cases does not need further consideration
	// - RW = 0, RO any
	// - RW = 1, RO = 0
	// Neither RO or RW is not NDAS_HOST_COUNT_UNKNOWN
	// Otherwise, we need HIX to discover the actual count

	if (nRWHosts != NDAS_HOST_COUNT_UNKNOWN && nROHosts == 0) {

		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;

		return S_OK;
	}

	DWORD nHosts = (NDAS_HOST_COUNT_UNKNOWN == nRWHosts || NDAS_HOST_COUNT_UNKNOWN == nROHosts) ? 
						NDAS_MAX_CONNECTION_V11 : nROHosts + nRWHosts;

	NDAS_UNITDEVICE_ID unitDeviceId;

	hr = get_NdasUnitId(&unitDeviceId);
	
	if (FAILED(hr)) {

		return hr;
	}

	CNdasHIXDiscover hixdisc(pGetNdasHostGuid());

	BOOL success = hixdisc.Initialize();
	
	if (!success) {

		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return S_OK;
	}

	success = hixdisc.HixDiscover( unitDeviceId,
								NHIX_UDA_READ_ACCESS, // read bit is set - all hosts
								nHosts,
								2000 );

	if (!success) {

		ATLASSERT(FALSE);

		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return S_OK;
	}

	if (nRWHosts == NDAS_HOST_COUNT_UNKNOWN || nROHosts == NDAS_HOST_COUNT_UNKNOWN) {

		DWORD rawROHosts = nROHosts;
		DWORD rawRWHosts = nRWHosts;

		// If any host count is unknown, use HIX counter only
		
		nROHosts = 0;
		nRWHosts = 0;
		
		DWORD nRepliedHosts = hixdisc.GetHostCount(unitDeviceId);
		
		for (DWORD i = 0; i < nRepliedHosts; ++i) {

			NHIX_UDA uda = 0;
			success = hixdisc.GetHostData(unitDeviceId,i,&uda);

			XTLASSERT(success); // index must be valid!
			
			if (uda == NHIX_UDA_SHARED_READ_WRITE_SECONDARY_ACCESS	||
				uda == NHIX_UDA_SHARED_READ_WRITE_PRIMARY_ACCESS	||
				uda == NHIX_UDA_READ_WRITE_ACCESS) {

				++nRWHosts;
			
			} else if (uda == NHIX_UDA_READ_ACCESS) {

				++nROHosts;
			
			} else {

				ATLASSERT(FALSE);
				XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_WARNING,
					"Invalid uda=0x%08X\n", uda);
			}
		}

		// If HIX counter is not available either, we should at least show
		// the original counter.

		if (rawRWHosts != NDAS_HOST_COUNT_UNKNOWN && rawRWHosts > nRWHosts) {

			XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_WARNING,
				"RWHost adjusted to Raw=%d from HIX=%d\n", rawRWHosts, nRWHosts);

			nRWHosts = rawRWHosts;
		}
	
	} else {

		// Otherwise, use SharedRW counter
		
		DWORD nRepliedHosts = hixdisc.GetHostCount(unitDeviceId);
		
		for (DWORD i = 0; i < nRepliedHosts; ++i) {

			NHIX_UDA uda = 0;

			success = hixdisc.GetHostData(unitDeviceId,i,&uda);
			XTLASSERT(success); // index must be valid!
			
			if (uda == NHIX_UDA_SHARED_READ_WRITE_SECONDARY_ACCESS) {

				--nROHosts;
				++nRWHosts;
			}
		}
	}

	*lpnROHosts = nROHosts;
	*lpnRWHosts = nRWHosts;

	ATLASSERT( *lpnRWHosts != NDAS_HOST_COUNT_UNKNOWN && *lpnROHosts != NDAS_HOST_COUNT_UNKNOWN );

	NdasUiDbgCall( 2, "Actual Host Usage Count: RO=%d, RW=%d.\n", *lpnROHosts, *lpnRWHosts );

	return S_OK;
}
Example #3
0
BOOL
CNdasUnitDevice::CheckNDFSCompatibility()
{
	ximeta::CAutoLock autolock(this);
	//
	// Unit devices other than disks are not allowed for NDFS
	//
	if (m_type != NDAS_UNITDEVICE_TYPE_DISK) {
		return FALSE;
	}

	//
	// LfsFilter compatibility check.
	// NDFS Major version should be same
	// 
	WORD wHostNDFSVerMajor;
	BOOL fSuccess = ::LfsFiltCtlGetVersion(
		NULL,
		NULL,
		NULL,
		NULL,
		&wHostNDFSVerMajor,
		NULL);

	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("Getting LFS Filter Version failed:"));
		return FALSE;
	}

	//
	// Primary Host Info is valid for 30 seconds
	//
	DWORD dwMaxTickAllowance = 30 * 1000;
	if (0 != m_PrimaryHostInfo.NDFSCompatVersion &&
		::GetTickCount() < m_PrimaryHostInfo.LastUpdate + dwMaxTickAllowance) 
	{
		// primary host info is valid
		return (wHostNDFSVerMajor == m_PrimaryHostInfo.NDFSCompatVersion);
	}

	//
	// No Primary Host Info is available (IX)
	// Use HIX to discover
	//
	CNdasHIXDiscover hixdisc(pGetNdasHostGuid());
	fSuccess = hixdisc.Initialize();
	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("HIXDiscover init failed: "));
		return FALSE;
	}

	NDAS_UNITDEVICE_ID udid = GetUnitDeviceId();

	hixdisc.Discover(udid,NHIX_UDA_SHRW_PRIM,1,1000);
	DWORD nHosts = hixdisc.GetHostCount(udid);
	if (0 == nHosts) {
		DBGPRT_ERR_EX(_FT("GetHostCount failed: "));
		return FALSE;
	}

	GUID hostGuid;
	fSuccess = hixdisc.GetHostData(udid,0,NULL,&hostGuid,NULL,NULL);
	if (!fSuccess) {
		DBGPRT_ERR_EX(_FT("GetHostData failed: "));
		return FALSE;
	}

	CNdasHostInfoCache* phic = pGetNdasHostInfoCache();
	_ASSERTE(phic); // phic is not null (by pGetNdasHostInfoCache)
	CONST NDAS_HOST_INFO* pHostInfo = phic->GetHostInfo(&hostGuid);
	if (NULL == pHostInfo) {
		DBGPRT_ERR_EX(_FT("GetHostInfo failed: "));
		return FALSE;
	}

	if (pHostInfo->NDASSWVerInfo.VersionMajor != wHostNDFSVerMajor) {
		DBGPRT_ERR(_FT("Host NDFS %d, Primary NDFS %d failed: "),
			wHostNDFSVerMajor, pHostInfo->NDASSWVerInfo.VersionMajor);
		return FALSE;
	}

	//
	// Primary and this host's NDFS compat version is same
	//

	return TRUE;

}
Example #4
0
BOOL
CNdasUnitDevice::GetActualHostUsageCount(
	LPDWORD lpnROHosts, 
	LPDWORD lpnRWHosts, 
	BOOL bUpdate)
{
	ximeta::CAutoLock autolock(this);

	DWORD nROHosts, nRWHosts;
	BOOL fSuccess = GetHostUsageCount(&nROHosts, &nRWHosts, bUpdate);
	if (!fSuccess) {
		return FALSE;
	}

	//
	// Following cases does not need further consideration
	// - RW = 0, RO = any
	// - RW = 1, RO = 0
	// Otherwise, we need HIX to discover the actual count
	//
	if (nRWHosts == 0 || nROHosts == 0) {
		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return TRUE;
	}

	DWORD nHosts = nROHosts + nRWHosts;
	NDAS_UNITDEVICE_ID unitDeviceId = GetUnitDeviceId();
	CNdasHIXDiscover hixdisc(pGetNdasHostGuid());
	fSuccess = hixdisc.Initialize();
	if (!fSuccess) {
		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return TRUE;
	}

	fSuccess = hixdisc.Discover(
		unitDeviceId,
		NHIX_UDA_READ_ACCESS, // read bit is set - all hosts
		nHosts,
		2000);

	if (!fSuccess) {
		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return TRUE;
	}

	DWORD nRepliedHosts = hixdisc.GetHostCount(unitDeviceId);
	for (DWORD i = 0; i < nRepliedHosts; ++i) {
		NHIX_UDA uda = 0;
		fSuccess = hixdisc.GetHostData(unitDeviceId,i,&uda);
		_ASSERTE(fSuccess); // index must be valid!
		if (uda == NHIX_UDA_SHARED_READ_WRITE_SECONDARY_ACCESS)
		{
			--nROHosts;
			++nRWHosts;
		}
	}

	*lpnROHosts = nROHosts;
	*lpnRWHosts = nRWHosts;

	return TRUE;
}
Example #5
0
BOOL
CNdasUnitDevice::CheckNDFSCompatibility()
{
	InstanceAutoLock autolock(this);
	//
	// Unit devices other than disks are not allowed for NDFS
	//
	if (m_type != NDAS_UNITDEVICE_TYPE_DISK) 
	{
		return FALSE;
	}

	//
	// LfsFilter compatibility check.
	// NDFS Major version should be same
	// 
	WORD wHostNDFSVerMajor;
	BOOL fSuccess = ::LfsFiltCtlGetVersion(
		NULL, NULL, NULL, NULL,
		&wHostNDFSVerMajor, NULL);

	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"Getting LFS Filter Version failed, error=0x%X\n", GetLastError());
		return FALSE;
	}

	//
	// Primary Host Info is valid for 30 seconds
	//
#if 0
	DWORD dwMaxTickAllowance = 30 * 1000;
	if (0 != m_PrimaryHostInfo.NDFSCompatVersion &&
		::GetTickCount() < m_PrimaryHostInfo.LastUpdate + dwMaxTickAllowance) 
	{
		// primary host info is valid
		return (wHostNDFSVerMajor == m_PrimaryHostInfo.NDFSCompatVersion);
	}
#endif

	//
	// No Primary Host Info is available (IX)
	// Use HIX to discover
	//
	CNdasHIXDiscover hixdisc(pGetNdasHostGuid());
	fSuccess = hixdisc.Initialize();
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"HIXDiscover init failed, error=0x%X\n", GetLastError());
		return FALSE;
	}

	NDAS_UNITDEVICE_ID udid = GetUnitDeviceId();

	DWORD timeout = NdasServiceConfig::Get(nscWriteShareCheckTimeout);

	fSuccess = hixdisc.Discover(udid,NHIX_UDA_SHRW_PRIM,1,timeout);
	if (!fSuccess)
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"hixdisc.Discover failed, error=0x%X\n", GetLastError());
		return FALSE;
	}

	DWORD nHosts = hixdisc.GetHostCount(udid);
	if (0 == nHosts) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"GetHostCount failed, error=0x%X\n", GetLastError());
		return FALSE;
	}

	GUID hostGuid;
	fSuccess = hixdisc.GetHostData(udid,0,NULL,&hostGuid,NULL,NULL);
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"GetHostData failed, error=0x%X\n", GetLastError());
		return FALSE;
	}

	CNdasHostInfoCache* phic = pGetNdasHostInfoCache();
	XTLASSERT(phic); // phic is not null (by pGetNdasHostInfoCache)
	const NDAS_HOST_INFO* pHostInfo = phic->GetHostInfo(&hostGuid);
	if (NULL == pHostInfo) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR, 
			"GetHostInfo failed, error=0x%X\n", GetLastError());
		return FALSE;
	}

	//
	// ReservedVerInfo contains NDFS Version Information
	//
	if (pHostInfo->ReservedVerInfo.VersionMajor != wHostNDFSVerMajor) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
			"Host NDFS %d, Primary NDFS %d failed.\n",
			wHostNDFSVerMajor, pHostInfo->ReservedVerInfo.VersionMajor);
		return FALSE;
	}

	//
	// Primary and this host's NDFS compatible version is same
	//
	return TRUE;
}
Example #6
0
BOOL
CNdasUnitDevice::GetActualHostUsageCount(
	LPDWORD lpnROHosts, 
	LPDWORD lpnRWHosts, 
	BOOL bUpdate)
{
	InstanceAutoLock autolock(this);

	DWORD nROHosts = 0;
	DWORD nRWHosts = 0;

	if (!GetHostUsageCount(&nROHosts, &nRWHosts, bUpdate))
	{
		return FALSE;
	}

	//
	// Following cases does not need further consideration
	// - RW = 0, RO any
	// - RW = 1, RO = 0
	// Neither RO or RW is not NDAS_HOST_COUNT_UNKNOWN
	// Otherwise, we need HIX to discover the actual count
	//
	if ((nRWHosts == 0 || nROHosts == 0) &&
		(NDAS_HOST_COUNT_UNKNOWN != nRWHosts) &&
		(NDAS_HOST_COUNT_UNKNOWN != nROHosts))
	{
		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return TRUE;
	}

	DWORD nHosts = 
		(NDAS_HOST_COUNT_UNKNOWN == nRWHosts || NDAS_HOST_COUNT_UNKNOWN == nROHosts) ? 
		NDAS_MAX_CONNECTION_V11 : nROHosts + nRWHosts;

	NDAS_UNITDEVICE_ID unitDeviceId = GetUnitDeviceId();

	//
	// BUG: Workaround for weird lock
	// We should unlock the global lock (yes, it's global lock at the moment)
	// for local HIX server to work!
	//

	autolock.Release();

	CNdasHIXDiscover hixdisc(pGetNdasHostGuid());
	BOOL fSuccess = hixdisc.Initialize();
	if (!fSuccess) 
	{
		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return TRUE;
	}

	fSuccess = hixdisc.Discover(
		unitDeviceId,
		NHIX_UDA_READ_ACCESS, // read bit is set - all hosts
		nHosts,
		2000);

	if (!fSuccess) 
	{
		*lpnROHosts = nROHosts;
		*lpnRWHosts = nRWHosts;
		return TRUE;
	}

	if (NDAS_HOST_COUNT_UNKNOWN == nRWHosts || NDAS_HOST_COUNT_UNKNOWN == nROHosts)
	{
		DWORD rawROHosts = nROHosts;
		DWORD rawRWHosts = nRWHosts;

		// If any host count is unknown, use HIX counter only
		nROHosts = 0;
		nRWHosts = 0;
		DWORD nRepliedHosts = hixdisc.GetHostCount(unitDeviceId);
		for (DWORD i = 0; i < nRepliedHosts; ++i) 
		{
			NHIX_UDA uda = 0;
			fSuccess = hixdisc.GetHostData(unitDeviceId,i,&uda);
			XTLASSERT(fSuccess); // index must be valid!
			if (NHIX_UDA_SHARED_READ_WRITE_SECONDARY_ACCESS == uda ||
				NHIX_UDA_SHARED_READ_WRITE_PRIMARY_ACCESS == uda ||
				NHIX_UDA_READ_WRITE_ACCESS == uda)
			{
				++nRWHosts;
			}
			else if (uda == NHIX_UDA_READ_ACCESS)
			{
				++nROHosts;
			}
			else
			{
				XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_WARNING,
					"Invalid uda=0x%08X\n", uda);
			}
		}
		//
		// If HIX counter is not available either, we should at least show
		// the original counter.
		//
		if (NDAS_HOST_COUNT_UNKNOWN != rawRWHosts && rawRWHosts > nRWHosts)
		{
			XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_WARNING,
				"RWHost adjusted to Raw=%d from HIX=%d\n", rawRWHosts, nRWHosts);
			nRWHosts = rawRWHosts;
		}
	}
	else
	{
		// Otherwise, use SharedRW counter
		DWORD nRepliedHosts = hixdisc.GetHostCount(unitDeviceId);
		for (DWORD i = 0; i < nRepliedHosts; ++i) 
		{
			NHIX_UDA uda = 0;
			fSuccess = hixdisc.GetHostData(unitDeviceId,i,&uda);
			XTLASSERT(fSuccess); // index must be valid!
			if (uda == NHIX_UDA_SHARED_READ_WRITE_SECONDARY_ACCESS)
			{
				--nROHosts;
				++nRWHosts;
			}
		}
	}

	*lpnROHosts = nROHosts;
	*lpnRWHosts = nRWHosts;

	XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_INFORMATION,
		"Actual Host Usage Count: RO=%d, RW=%d.\n",
		*lpnROHosts, *lpnRWHosts);

	return TRUE;
}