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; }
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; }
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; }
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; }