Exemple #1
0
void CUnitDiskObject::Rebind(CDiskObjectPtr newDisk, UINT nIndex)
{
	CUnitDiskObjectPtr newUnitDisk = 
		boost::dynamic_pointer_cast<CUnitDiskObject>(newDisk);
	ATLASSERT( newUnitDisk.get() );
	m_pHandler->Rebind(newUnitDisk, nIndex);
}
Exemple #2
0
void CUnitDiskObject::Mirror(CDiskObjectPtr source)
{
	CUnitDiskObjectPtr unitSource = 
		boost::dynamic_pointer_cast<CUnitDiskObject>(source);
	ATLASSERT( unitSource.get() );
	m_pHandler->Mirror(unitSource);
}
Exemple #3
0
BOOL
WINAPI
NdasBindUnitDevices(PNDAS_UNITDEVICE_GROUP pUnitDeviceIdGroup, NDAS_UNITDEVICE_DISK_TYPE diskType)
{
	int nBindType;
	BOOL bResult;

	_ASSERT(FALSE);
	//
	// Basic validation of parameters
	//
	switch( diskType )
	{
	case NDAS_UNITDEVICE_DISK_TYPE_AGGREGATED:
		nBindType = NMT_AGGREGATE;
		break;
	case NDAS_UNITDEVICE_DISK_TYPE_RAID1:
		if ( (pUnitDeviceIdGroup->cUnitDevices % 2) != 0 )
			return FALSE;	// ERROR : Number of disks must be even.
		nBindType = NMT_RAID1;
		break;
	// TODO : diskType that has been changed by aingoppa should be applied here.
	default:
		// ERROR : Invalid parameters
		return FALSE;
	}
	
	bResult = IsValidBindDiskCount(nBindType, pUnitDeviceIdGroup->cUnitDevices);
	if ( !bResult )
	{
		// ERROR : Invalid number of disks.
		return FALSE;
	}
	//
	// Create disk objects
	//
	CUnitDiskObjectVector vtUnitDisks;
	CUnitDiskObjectPtr unitDisk;
	UINT i;
	for ( i=0; i < pUnitDeviceIdGroup->cUnitDevices; i++ )
	{
		unitDisk = NdasCreateUnitDiskObject( &pUnitDeviceIdGroup->aUnitDevices[i] );
		if ( unitDisk.get() == NULL )
			return FALSE;
		//
		// Validation of disks
		//
		if ( unitDisk->GetInfoHandler()->IsBound() )
			return FALSE;	// ERROR : disk is already bound.
		vtUnitDisks.push_back(unitDisk);
	}

	//
	// Bind disks
	//
	for ( i=0; i < vtUnitDisks.size(); i++ )
	{
		if ( !vtUnitDisks[i]->CanAccessExclusive() )
		{
			// ERROR : cannot access disk exclusively
			return FALSE;
		}
	}

	try {
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->Open( TRUE );
		}
	}
	catch ( CNDASException & )
	{
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->Close();
		}
		// ERROR : Fail to connect to disk
		return FALSE;
	}

	for ( i=0; i < vtUnitDisks.size(); i++ )
	{
		vtUnitDisks[i]->Bind( vtUnitDisks, i, nBindType );
	}

	try {
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->CommitDiskInfo();
		}
	}
	catch ( CNDASException & )
	{
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->Close();
		}
		// ERROR : Unexpected error while writing
		return FALSE;
	}
	for ( i=0; i < vtUnitDisks.size(); i++ )
	{
		vtUnitDisks[i]->Close();
	}
	return TRUE;
}
Exemple #4
0
BOOL
WINAPI
NdasUnBindUnitDevices(PNDAS_UNITDEVICE_GROUP pUnitDeviceIdGroup)
{
	UINT i;

	CUnitDiskObjectVector vtUnitDisks;
	CUnitDiskObjectPtr unitDisk;
	for ( i=0; i < pUnitDeviceIdGroup->cUnitDevices; i++ )
	{
		unitDisk = NdasCreateUnitDiskObject( &pUnitDeviceIdGroup->aUnitDevices[i] );
		if ( unitDisk.get() == NULL )
			return FALSE;
		//
		// Validation of disks
		//
		if ( !unitDisk->GetInfoHandler()->IsBound() )
			return FALSE; // ERROR : disk is not bound
		vtUnitDisks.push_back(unitDisk);
	}

	//
	// Unbind disks
	//
	for ( i=0; i < vtUnitDisks.size(); i++ )
	{
		if ( !vtUnitDisks[i]->CanAccessExclusive() )
		{
			// ERROR : cannot access disk exclusively
			return FALSE;
		}
	}

	try {
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->Open( TRUE );
		}
	}
	catch ( CNDASException & )
	{
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->Close();
		}
		// ERROR : Fail to connect to disk
		return FALSE;
	}

	for ( i=0; i < vtUnitDisks.size(); i++ )
	{
		vtUnitDisks[i]->UnBind( vtUnitDisks[i] );
	}


	try {
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->CommitDiskInfo();
		}
	}
	catch ( CNDASException & )
	{
		for ( i=0; i < vtUnitDisks.size(); i++ )
		{
			vtUnitDisks[i]->Close();
		}
		// ERROR : Unexpected error while writing
		return FALSE;
	}
	for ( i=0; i < vtUnitDisks.size(); i++ )
	{
		vtUnitDisks[i]->Close();
	}
	return TRUE;
}
Exemple #5
0
void CMainFrame::OnAddMirror(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hwndCtl*/)
{
	ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus);

	CTreeItem itemSelected = m_view.GetSelectedItem();

	if ( itemSelected.IsNull() )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		return;
	}

	CDiskObjectList singleDisks;
	CUnitDiskObjectPtr  sourceDisk;
	sourceDisk = 
		boost::dynamic_pointer_cast<CUnitDiskObject>(
			m_mapObject[m_view.GetItemData(itemSelected)]
			);
	ATLASSERT( sourceDisk.get() != NULL );

	CFindIfVisitor<FALSE> singleDiskFinder;
	singleDisks = singleDiskFinder.FindIf(m_pRoot, IsWritableUnitDisk);
	singleDisks.remove( sourceDisk );
	if ( singleDisks.size() == 0 )
	{
		LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
		// TODO : No disk is available
		WTL::CString strMsg;
		strMsg.LoadString( IDS_MAINFRAME_NO_DISK_TO_MIRROR );
		WTL::CString strTitle;
		strTitle.LoadString(IDS_APPLICATION);
		MessageBox(
			strMsg,
			strTitle, 
			MB_OK | MB_ICONWARNING
			);
		return;
	}

	DWORD UnitNo = 0;
	CSelectMirDlg dlgSelDisk(IDD_ADDMIR);
	dlgSelDisk.SetSingleDisks( singleDisks );
	dlgSelDisk.SetSourceDisk( sourceDisk );
	if ( dlgSelDisk.DoModal() == IDOK )
	{
		CUnitDiskObjectPtr mirDisk = dlgSelDisk.GetSelectedDisk();

		// Bind & Synchronize 
		NDAS_CONNECTION_INFO ConnectionInfo[2];

		ZeroMemory(&ConnectionInfo[0], sizeof(NDAS_CONNECTION_INFO));

		ConnectionInfo[0].type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
		ConnectionInfo[0].UnitNo = sourceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
		ConnectionInfo[0].bWriteAccess = TRUE;
		ConnectionInfo[0].ui64OEMCode = NULL;
		ConnectionInfo[0].protocol = IPPROTO_LPXTCP;
		CopyMemory(ConnectionInfo[0].MacAddress, 
				sourceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
			LPXADDR_NODE_LENGTH);

		ZeroMemory(&ConnectionInfo[1], sizeof(NDAS_CONNECTION_INFO));

		ConnectionInfo[1].type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
		ConnectionInfo[1].UnitNo = mirDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
		ConnectionInfo[1].bWriteAccess = TRUE;
		ConnectionInfo[1].ui64OEMCode = NULL;
		ConnectionInfo[1].protocol = IPPROTO_LPXTCP;
		CopyMemory(ConnectionInfo[1].MacAddress, 
			mirDisk->GetLocation()->GetUnitDiskLocation()->MACAddr,
			LPXADDR_NODE_LENGTH);

		UINT32 BindResult = NdasOpBind(
			2,
			ConnectionInfo,
			NMT_SAFE_RAID1);

		if(2 != BindResult)
		{
	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);

			WTL :: CString strMsg;

			DWORD dwLastError = ::GetLastError();

			switch(dwLastError)
	{
			case NDASCOMM_ERROR_RW_USER_EXIST:
			case NDASOP_ERROR_ALREADY_USED:
			case NDASOP_ERROR_DEVICE_FAIL:
			case NDASOP_ERROR_NOT_SINGLE_DISK:
			case NDASOP_ERROR_DEVICE_UNSUPPORTED:
				strMsg.FormatMessage(IDS_BIND_FAIL_AT_SINGLE_NDAS_FMT, 
					(BindResult == 0) ? sourceDisk->GetTitle() : mirDisk->GetTitle());
				break;
			default:
				strMsg.LoadString(IDS_BIND_FAIL);
				break;
	}

			ShowErrorMessageBox(strMsg);

		return;
	}

		CNdasHIXChangeNotify HixChangeNotify(pGetNdasHostGuid());
		BOOL bResults = HixChangeNotify.Initialize();
		if(bResults)
		{
			NDAS_UNITDEVICE_ID unitDeviceId;

			CopyMemory(unitDeviceId.DeviceId.Node, 
				sourceDisk->GetLocation()->GetUnitDiskLocation()->MACAddr, 
				sizeof(unitDeviceId.DeviceId.Node));
			unitDeviceId.UnitNo = 
				sourceDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
			HixChangeNotify.Notify(unitDeviceId);

			CopyMemory(unitDeviceId.DeviceId.Node, 
				mirDisk->GetLocation()->GetUnitDiskLocation()->MACAddr, 
				sizeof(unitDeviceId.DeviceId.Node));
			unitDeviceId.UnitNo = 
				mirDisk->GetLocation()->GetUnitDiskLocation()->UnitNumber;
			HixChangeNotify.Notify(unitDeviceId);
		}

		CRecoverDlg dlgRecover(TRUE, IDS_LOGDEV_TYPE_DISK_RAID1, IDS_RECOVERDLG_TASK_ADD_MIRROR);

		dlgRecover.SetMemberDevice(mirDisk);
		dlgRecover.DoModal();

		OnRefreshStatus(NULL, NULL, NULL);
	}

	LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus);
}