void Task_MigrateCtSource::finalizeTask()
{
	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &getClient()->getAuthHelper() );
	SmartPtr<IOPackage> pPackage;

	Disconnect();

	if (PRL_SUCCEEDED(getLastErrorCode())) {
		CProtoCommandPtr pResponse =
			CProtoSerializer::CreateDspWsResponseCommand(getRequestPackage(), PRL_ERR_SUCCESS);
		getClient()->sendResponse(pResponse, getRequestPackage());
		/* We may not report error here since CT already live on destination */
		bool bDeleteSource = !(m_nMigrationFlags & PVMT_CLONE_MODE);
		PRL_RESULT nRetCode = CVzHelper::src_complete_migrate_env(m_nCtid, &m_pOpaqueLock, bDeleteSource);
		if (PRL_FAILED(nRetCode))
			WRITE_TRACE(DBG_FATAL, "Can not complete source CT migration for uuid %s", QSTR2UTF8(m_sVmUuid));
	} else {
		/* send response */
		CProtoCommandPtr pResponse =
			CProtoSerializer::CreateDspWsResponseCommand(getRequestPackage(), getLastErrorCode());
		CProtoCommandDspWsResponse *wsResponse =
			CProtoSerializer::CastToProtoCommand<CProtoCommandDspWsResponse>( pResponse );
		getLastError()->setEventCode(getLastErrorCode());
		wsResponse->SetError(getLastError()->toString());
		getClient()->sendResponse( pResponse, getRequestPackage() );

		getClient()->sendResponseError( getLastError(), getRequestPackage() );
	}

	if (m_bExVmOperationRegistered)
		CDspService::instance()->getVmDirHelper().unregisterExclusiveVmOperation(
				m_sVmUuid, m_sVzDirUuid, PVE::DspCmdDirVmMigrate, getClient());
}
PRL_RESULT Task_GetBackupTreeTarget::run_body()
{
	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &getClient()->getAuthHelper() );

	PRL_RESULT nRetCode = PRL_ERR_SUCCESS;
	QString msg;
	CDispToDispCommandPtr pReply;
	SmartPtr<IOPackage> pPackage;

	getBackupTree(msg);
	pReply = CDispToDispProtoSerializer::CreateGetBackupTreeReply(msg);
	pPackage = DispatcherPackage::createInstance(
			pReply->GetCommandId(),
			pReply->GetCommand()->toString(),
			getRequestPackage());

	IOSendJob::Handle hJob = m_pDispConnection->sendPackage(pPackage);
	if (CDspService::instance()->getIOServer().waitForSend(hJob, m_nTimeout) != IOSendJob::Success) {
		WRITE_TRACE(DBG_FATAL, "Package sending failure");
		setLastErrorCode(PRL_ERR_BACKUP_INTERNAL_PROTO_ERROR);
		return PRL_ERR_BACKUP_INTERNAL_PROTO_ERROR;
	}

	return nRetCode;
}
PRL_RESULT Task_GetBackupTreeSource::run_body()
{
	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &getClient()->getAuthHelper() );

	PRL_RESULT nRetCode = PRL_ERR_SUCCESS;
	QFileInfoList excludeList;
	QFileInfoList dirList;
	QFileInfoList fileList;

	if (PRL_FAILED(nRetCode = connect()))
		goto exit;

	if (PRL_FAILED(nRetCode = GetBackupTreeRequest(m_sUuid, m_sBackupTree)))
		goto exit;


exit:
	setLastErrorCode(nRetCode);
	return nRetCode;
}
/* process VmMigrateCheckPreconditionsCommand */
PRL_RESULT Task_MigrateCtTarget::prepareTask()
{
	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &getClient()->getAuthHelper() );

	PRL_RESULT nRetCode = PRL_ERR_SUCCESS;
	QString sVmDirPath;

	if (CDspService::instance()->isServerStopping()) {
		WRITE_TRACE(DBG_FATAL, "Dispatcher shutdown is in progress - CT migrate rejected!");
		nRetCode = PRL_ERR_DISP_SHUTDOWN_IN_PROCESS;
		goto exit;
	}

	m_pVmConfig = SmartPtr<CVmConfiguration>(new CVmConfiguration(m_sVmConfig));
	if (PRL_FAILED(m_pVmConfig->m_uiRcInit)) {
		nRetCode = PRL_ERR_PARSE_VM_CONFIG;
		WRITE_TRACE(DBG_FATAL, "Wrong VM condiguration was received: [%s]", QSTR2UTF8(m_sVmConfig));
		goto exit;
	}
	m_sOriginVmUuid = m_pVmConfig->getVmIdentification()->getVmUuid();
	m_nCtid = m_nOriginCtid = m_pVmConfig->getVmIdentification()->getEnvId();
	m_sVmName = m_pVmConfig->getVmIdentification()->getVmName();

	nRetCode = CVzHelper::dst_start_migrate_env(&m_nCtid, &m_pOpaqueLock);
	if (PRL_FAILED(nRetCode)) {
		WRITE_TRACE(DBG_FATAL, "Can not start destination CT migration for uuid %s", QSTR2UTF8(m_sVmUuid));
		goto exit;
	}

	if (m_nCtid != m_nOriginCtid)
		m_pVmConfig->getVmIdentification()->setEnvId(m_nCtid);

	{
		CDspLockedPointer<CVmDirectory> pDir = CDspService::instance()->getVmDirManager().getVzDirectory();
		if (!pDir) {
			nRetCode = PRL_ERR_VM_UUID_NOT_FOUND;
			WRITE_TRACE(DBG_FATAL, "Couldn't to find VZ directiory UUID");
			goto exit;
		}
		m_sVzDirUuid = pDir->getUuid();
	}
	m_sVmUuid = (PVMT_CLONE_MODE & getRequestFlags()) ? Uuid::createUuid().toString() : m_sOriginVmUuid;

	WRITE_TRACE(DBG_FATAL, "Start migrate origin CTID=%u to CTID=%u for uuid %s",
		    m_nOriginCtid, m_nCtid, QSTR2UTF8(m_sVmUuid));

	/*  to get target VM home directory path */
	if (!m_sVmDirPath.isEmpty())
		m_sTargetVmHomePath = m_sVmDirPath;
	else {
		m_sTargetVmHomePath = CVzHelper::getCtPrivatePath(m_nCtid);
	}
	m_sTargetVmHomePath = QFileInfo(m_sTargetVmHomePath).absoluteFilePath();
	m_sVmConfigPath = QString("%1/" VMDIR_DEFAULT_VM_CONFIG_FILE).arg(m_sTargetVmHomePath);

	/* lock Vm exclusive parameters */
	m_pVmInfo = SmartPtr<CVmDirectory::TemporaryCatalogueItem>(new CVmDirectory::TemporaryCatalogueItem(
			m_sVmUuid, m_sVmConfigPath, m_sVmName));

	nRetCode = CDspService::instance()->getVmDirManager()
			.checkAndLockNotExistsExclusiveVmParameters(QStringList(), m_pVmInfo.getImpl());
	if (PRL_FAILED(nRetCode))
	{
		switch (nRetCode)
		{
		case PRL_ERR_VM_ALREADY_REGISTERED_VM_UUID:
			WRITE_TRACE(DBG_FATAL, "UUID '%s' already registered", QSTR2UTF8(m_pVmInfo->vmUuid));
			getLastError()->addEventParameter(
				new CVmEventParameter( PVE::String, m_pVmInfo->vmUuid, EVT_PARAM_RETURN_PARAM_TOKEN));
			break;

		case PRL_ERR_VM_ALREADY_REGISTERED_VM_PATH:
			WRITE_TRACE(DBG_FATAL, "path '%s' already registered", QSTR2UTF8(m_pVmInfo->vmXmlPath));
			getLastError()->addEventParameter(
				new CVmEventParameter( PVE::String, m_pVmInfo->vmName, EVT_PARAM_MESSAGE_PARAM_0));
			getLastError()->addEventParameter(
				new CVmEventParameter( PVE::String, m_pVmInfo->vmXmlPath, EVT_PARAM_MESSAGE_PARAM_1));
			break;

		case PRL_ERR_VM_ALREADY_REGISTERED_VM_NAME:
			WRITE_TRACE(DBG_FATAL, "name '%s' already registered", QSTR2UTF8(m_pVmInfo->vmName));
			getLastError()->addEventParameter(
				new CVmEventParameter( PVE::String, m_pVmInfo->vmName, EVT_PARAM_MESSAGE_PARAM_0));
			break;

		case PRL_ERR_VM_ALREADY_REGISTERED:
			WRITE_TRACE(DBG_FATAL, "container '%s' already registered", QSTR2UTF8(m_pVmInfo->vmName));
			getLastError()->addEventParameter(
					new CVmEventParameter( PVE::String, m_pVmInfo->vmName, EVT_PARAM_MESSAGE_PARAM_0));
			break;

		case PRL_ERR_VM_ALREADY_REGISTERED_UNIQUE_PARAMS:; // use default

		default:
			WRITE_TRACE(DBG_FATAL, "can't register container with UUID '%s', name '%s', path '%s",
				QSTR2UTF8(m_pVmInfo->vmUuid), QSTR2UTF8(m_pVmInfo->vmName), QSTR2UTF8(m_pVmInfo->vmXmlPath));
			getLastError()->addEventParameter(
				 new CVmEventParameter( PVE::String, m_pVmInfo->vmUuid, EVT_PARAM_RETURN_PARAM_TOKEN));
			getLastError()->addEventParameter(
				 new CVmEventParameter( PVE::String, m_pVmInfo->vmXmlPath, EVT_PARAM_RETURN_PARAM_TOKEN));
			getLastError()->addEventParameter(
				 new CVmEventParameter( PVE::String, m_pVmInfo->vmName, EVT_PARAM_RETURN_PARAM_TOKEN));
		}
		goto exit;
	}
	m_nSteps |= MIGRATE_VM_EXCL_PARAMS_LOCKED;

	if (!(PVMT_SWITCH_TEMPLATE & getRequestFlags())) {
		/* skip checking for copy to template case (https://jira.sw.ru/browse/PSBM-9597) */
		//checkTargetCpusNumber();
		//checkTargetCpuCompatibility();
	}

exit:
	setLastErrorCode(nRetCode);
	return nRetCode;
}
PRL_RESULT Task_MigrateCtSource::run_body()
{
	SmartPtr<CVmEvent> pEvent;
	SmartPtr<IOPackage> pPackage;
	IOSendJob::Response pResponse;
	CDispToDispCommandPtr pCmd;
	CDispToDispResponseCommand *pRespCmd;

	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &getClient()->getAuthHelper() );

	if (operationIsCancelled())
		setLastErrorCode(PRL_ERR_OPERATION_WAS_CANCELED);

	PRL_RESULT nRetCode = PRL_ERR_SUCCESS;

	if (PRL_FAILED(nRetCode = CheckVmMigrationPreconditions()))
		goto exit;

	/* set migration mode */
	switch (m_nPrevVmState) {
	case VMS_RUNNING:
	case VMS_PAUSED:
		nRetCode = PRL_ERR_VM_MIGRATE_WARM_MODE_NOT_SUPPORTED;
		goto exit;
	default:
		m_nMigrationFlags |= PVMT_COLD_MIGRATION;
	}

	if (operationIsCancelled())
		setLastErrorCode(PRL_ERR_OPERATION_WAS_CANCELED);

	pEvent = SmartPtr<CVmEvent>(new CVmEvent(PET_DSP_EVT_VM_MIGRATE_STARTED, m_sVmUuid, PIE_DISPATCHER));
	pEvent->addEventParameter(new CVmEventParameter(PVE::Boolean, "true", EVT_PARAM_MIGRATE_IS_SOURCE));
	pPackage = DispatcherPackage::createInstance(PVE::DspVmEvent, pEvent->toString());

	m_nSteps |= MIGRATE_VM_STATE_CHANGED;
	/* and notify clients about VM migration start event */
	CDspService::instance()->getClientManager().sendPackageToVmClients(pPackage, m_sVzDirUuid, m_sVmUuid);

	/* remove target Vm config from watcher (#448235) */
	CDspService::instance()->getVmConfigWatcher().unregisterVmToWatch(m_sVmConfigPath);
	m_nSteps |= MIGRATE_UNREGISTER_VM_WATCH;

	nRetCode = migrateStoppedCt();
	if (PRL_FAILED(nRetCode))
		goto exit;

	/* wait finish reply from target (https://jira.sw.ru/browse/PSBM-9596) */
	quint32 nTimeout = m_nTimeout;

	/* wait target task finish */
	if (PVMT_CHANGE_SID & getRequestFlags())
		/* wait reply during changeSID task timeout (https://jira.sw.ru/browse/PSBM-9733) */
		nTimeout = CHANGESID_TIMEOUT;
	if (m_pIoClient->waitForResponse(m_hCheckReqJob, nTimeout) != IOSendJob::Success) {
		WRITE_TRACE(DBG_FATAL, "Finish acknowledgement receiving failure");
		nRetCode = PRL_ERR_CT_MIGRATE_INTERNAL_ERROR;
		goto exit;
	}
	pResponse = m_pIoClient->takeResponse(m_hCheckReqJob);
	if (pResponse.responseResult != IOSendJob::Success) {
		WRITE_TRACE(DBG_FATAL, "Finish acknowledgement receiving failure");
		nRetCode = PRL_ERR_CT_MIGRATE_INTERNAL_ERROR;
		goto exit;
	}
	pPackage  = pResponse.responsePackages[0];
	if (pPackage->header.type != DispToDispResponseCmd) {
		WRITE_TRACE(DBG_FATAL, "Invalid package type : %d", pPackage->header.type);
		nRetCode = PRL_ERR_CT_MIGRATE_INTERNAL_ERROR;
		goto exit;
	}

	pCmd = CDispToDispProtoSerializer::ParseCommand(
		DispToDispResponseCmd, UTF8_2QSTR(pPackage->buffers[0].getImpl()));
	pRespCmd = CDispToDispProtoSerializer::CastToDispToDispCommand<CDispToDispResponseCommand>(pCmd);
	nRetCode = pRespCmd->GetRetCode();
	if (PRL_FAILED(nRetCode))
		getLastError()->fromString(pRespCmd->GetErrorInfo()->toString());

exit:
	setLastErrorCode(nRetCode);
	return nRetCode;
}
PRL_RESULT Task_MigrateCtSource::prepareTask()
{
	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &getClient()->getAuthHelper() );

	PRL_RESULT nRetCode = PRL_ERR_SUCCESS;

	if (CDspService::instance()->isServerStopping())
	{
		WRITE_TRACE(DBG_FATAL, "Dispatcher shutdown is in progress - VM migrate rejected!");
		nRetCode = PRL_ERR_DISP_SHUTDOWN_IN_PROCESS;
		goto exit;
	}

	if (CDspService::instance()->getShellServiceHelper().isLocalAddress(m_sServerHostname)) {
		WRITE_TRACE(DBG_FATAL,
			"Host %s is a local host, migration is impossible", QSTR2UTF8(m_sServerHostname));
		nRetCode = PRL_ERR_VM_MIGRATE_TO_THE_SAME_NODE;
		goto exit;
	}

	/* will use Vz dir uuid for Vm */
	{
		CDspLockedPointer<CVmDirectory> pDir = CDspService::instance()->getVmDirManager().getVzDirectory();
		if (!pDir) {
			nRetCode = PRL_ERR_VM_UUID_NOT_FOUND;
			WRITE_TRACE(DBG_FATAL, "Couldn't to find VZ directiory UUID");
			goto exit;
		}
		m_sVzDirUuid = pDir->getUuid();

		nRetCode = CDspService::instance()->getVmDirHelper().registerExclusiveVmOperation(
			m_sVmUuid, m_sVzDirUuid, PVE::DspCmdDirVmMigrate, getClient());
		if ( PRL_FAILED(nRetCode) ) {
			WRITE_TRACE(DBG_FATAL, "[%s] registerExclusiveVmOperation failed. Reason: %#x (%s)",
				    __FUNCTION__, nRetCode, PRL_RESULT_TO_STRING(nRetCode));
			goto exit;
		}
		m_bExVmOperationRegistered = true;
	}

	m_pVmConfig = CDspService::instance()->getVzHelper()->getCtConfig(getClient(), m_sVmUuid);
	if (!m_pVmConfig.isValid()) {
		WRITE_TRACE(DBG_FATAL, "Can not load config for uuid %s", QSTR2UTF8(m_sVmUuid));
		goto exit;
	}
	m_sVmHomePath = m_pVmConfig->getVmIdentification()->getHomePath();
	m_nCtid = m_pVmConfig->getVmIdentification()->getEnvId();

	nRetCode = CDspService::instance()->getVzHelper()->getVzlibHelper().get_env_status(m_sVmUuid, m_nPrevVmState);
	if (PRL_FAILED(nRetCode)) {
		WRITE_TRACE(DBG_FATAL, "Can not get status for uuid %s", QSTR2UTF8(m_sVmUuid));
		goto exit;
	}

	if (m_nPrevVmState != VMS_STOPPED) {
		WRITE_TRACE(DBG_FATAL, "CT must be stopped for migration");
		nRetCode = PRL_ERR_VM_MIGRATE_UNSUITABLE_VM_STATE;
		goto exit;
	}

	nRetCode = CVzHelper::src_start_migrate_env(m_nCtid, &m_pOpaqueLock);
	if (PRL_FAILED(nRetCode)) {
		WRITE_TRACE(DBG_FATAL, "Can not start source CT migration for uuid %s", QSTR2UTF8(m_sVmUuid));
		goto exit;
	}

	{
		/* LOCK inside brackets */
		CDspLockedPointer<CDspHostInfo> lockedHostInfo = CDspService::instance()->getHostInfo();
		m_cHostInfo.fromString( lockedHostInfo->data()->toString() );
	}

	nRetCode = Connect(
		m_sServerHostname, m_nServerPort, m_sServerSessionUuid, QString(), QString(), m_nMigrationFlags);
	if (PRL_FAILED(nRetCode))
		goto exit;

exit:
	setLastErrorCode(nRetCode);
	return nRetCode;
}
PRL_RESULT Mixin_CreateVmSupport::setDefaultVmPermissions(
	SmartPtr<CDspClient> pUser,
	QString vmPathToConfig,
	bool bKeepOthersPermissions
)
{
	PRL_ASSERT( pUser );
	PRL_ASSERT( ! vmPathToConfig.isEmpty() );

	if( ! pUser || vmPathToConfig.isEmpty() )
		return PRL_ERR_INVALID_ARG;

	// FIXME: isFsSupportPermsAndOwner() should be moved near setFullAccessRightsToVm() and united with it.
	{
		//https://bugzilla.sw.ru/show_bug.cgi?id=267152
		CAuthHelperImpersonateWrapper _impersonate( &pUser->getAuthHelper() );

		// # https://bugzilla.sw.ru/show_bug.cgi?id=112901
		// https://jira.sw.ru/browse/PSBM-9040
		if( !CFileHelper::isFsSupportPermsAndOwner( vmPathToConfig ) )
		{
			WRITE_TRACE(DBG_FATAL, "File system does not support permissions. Setting default Vm permission will be ignored. (path=%s)"
				, QSTR2UTF8( vmPathToConfig ) );
			return PRL_ERR_SUCCESS;
		}
	}

	// get vm directory path

	// To prevent stupid errors see https://bugzilla.sw.ru/show_bug.cgi?id=483700 for more details
	PRL_ASSERT(QFileInfo( vmPathToConfig ).isFile());
	QString strVmDirPath;
	if ( QFileInfo( vmPathToConfig ).isFile() )
		strVmDirPath = CFileHelper::GetFileRoot( vmPathToConfig );
	else
	{
		strVmDirPath = vmPathToConfig;
		vmPathToConfig = QString("%1/%2").arg(strVmDirPath).arg(VMDIR_DEFAULT_VM_CONFIG_FILE);
	}

	if ( !CDspAccessManager::setOwner( strVmDirPath, &pUser->getAuthHelper(), true )  )
	{
		WRITE_TRACE(DBG_FATAL, "Can't change owner to vm dir files [%s]. error=[%s]"
			, QSTR2UTF8( strVmDirPath )
			, QSTR2UTF8( Prl::GetLastErrorAsString() ) );
		return PRL_ERR_CANT_CHANGE_OWNER_OF_FILE;
	}

	//////////////////////////////////////////////////////////////////////////
	// set default access rigths
	//////////////////////////////////////////////////////////////////////////
	CVmDirectoryItem vmDirItem;
	vmDirItem.setVmHome( vmPathToConfig );
	PRL_SEC_AM ownerAccess = CDspAccessManager::VmAccessRights::makeModeRWX() ;
	PRL_SEC_AM otherAccess = CDspAccessManager::VmAccessRights::makeModeNO_ACCESS() ;

	PRL_RESULT err = CDspService::instance()->getAccessManager()
		.setFullAccessRightsToVm( pUser, &vmDirItem, &ownerAccess,
		// Do not change others permissions during registration at desktop mode
		// https://bugzilla.sw.ru/show_bug.cgi?id=120191
		 ! bKeepOthersPermissions ? &otherAccess : NULL );
	if( PRL_FAILED( err ) )
	{
		WRITE_TRACE(DBG_FATAL, "Can't change permission to vm dir files [%s]. error=[%s]"
			, QSTR2UTF8( strVmDirPath )
			, QSTR2UTF8( Prl::GetLastErrorAsString() ) );
		return PRL_ERR_CANT_CHANGE_FILE_PERMISSIONS;
	}

	return PRL_ERR_SUCCESS;
}
PRL_RESULT Task_GetInfoFromParallelsUtils::GetDiskImageInformation(
		const QString & strPathToFile,
		CVmHardDisk & cHardDisk,
		SmartPtr<CDspClient> pUserSession)
{
// VirtualDisk commented out by request from CP team
//	PARALLELS_DISK_PARAMETERS DiskParameters;
//	PRL_RESULT nRetVal = PRL_ERR_SUCCESS;

	LOG_MESSAGE(DBG_DEBUG,
				"Task_GetInfoFromParallelsUtils::GetDiskImageInformation(%s)",
				strPathToFile.toUtf8().data());

	// Pointer to argument is not valid
	if (strPathToFile.isEmpty())
		return PRL_ERR_VM_GET_HDD_IMG_INVALID_ARG;

	//https://bugzilla.sw.ru/show_bug.cgi?id=267152
	CAuthHelperImpersonateWrapper _impersonate( &pUserSession->getAuthHelper() );

	QString strDirPathToFile = strPathToFile;
	if (!QFileInfo(strPathToFile).isDir() && !strPathToFile.endsWith(".vmdk"))
		strDirPathToFile = CFileHelper::GetFileRoot(strPathToFile);

	SmartPtr<CVmHardDisk> pCachedHardDisk =
		CDspService::instance()->getVmConfigManager().getHardDiskConfigCache().
				getConfig(strDirPathToFile, pUserSession );
	if( pCachedHardDisk )
	{
		// Fill only Disk specific fields
		cHardDisk.setVersion(pCachedHardDisk->getVersion());
		cHardDisk.setSystemName(pCachedHardDisk->getSystemName());
		cHardDisk.setUserFriendlyName(pCachedHardDisk->getUserFriendlyName());
		cHardDisk.setEmulatedType(pCachedHardDisk->getEmulatedType());
		cHardDisk.setSplitted(pCachedHardDisk->isSplitted());
		cHardDisk.setDiskType(pCachedHardDisk->getDiskType());
		cHardDisk.setBlockSize(pCachedHardDisk->getBlockSize());
		cHardDisk.setSize(pCachedHardDisk->getSize());
		cHardDisk.setCompatLevel(pCachedHardDisk->getCompatLevel());
		cHardDisk.setSizeOnDisk(pCachedHardDisk->getSizeOnDisk());

		/* FIXME: get size by demand */
		// set size on disk in MB
		quint64 ui64Size = 0;
		CSimpleFileHelper::GetDirSize(strDirPathToFile, &ui64Size);
		cHardDisk.setSizeOnDisk(ui64Size/(1024*1024));

		return PRL_ERR_SUCCESS;
	}

// VirtualDisk commented out by request from CP team
//	IDisk* pDisk = IDisk::OpenDisk( strDirPathToFile,
//			PRL_DISK_READ | PRL_DISK_FAKE_OPEN,
//			&nRetVal);
//	if ( !pDisk )
//	{
//		switch (IDisk::IsDiskValid(strPathToFile))
//		{
//			case PRL_CHECKED_DISK_VALID:
//				// Can not happen
//				break;
//			case PRL_CHECKED_DISK_OLD_VERSION:
//				cHardDisk.setVersion(PVE::HardDiskV1);
//				return PRL_ERR_SUCCESS;
//			case PRL_CHECKED_DISK_INVALID:
//				cHardDisk.setVersion(PVE::HardDiskInvalidVersion);
//				return PRL_ERR_SUCCESS;
//			default:
//				cHardDisk.setVersion(PVE::HardDiskInvalidVersion);
//				return PRL_ERR_SUCCESS;
//		}
//
//		WRITE_TRACE(DBG_FATAL, "Error opening disk %s to get info."
//				" Received NULL reference. Error 0x%x",
//				QSTR2UTF8(strPathToFile), nRetVal);
//		return PRL_ERR_VM_GET_HDD_IMG_NOT_OPEN;
//	}
//
//	nRetVal = pDisk->GetParameters(DiskParameters);
//	if (PRL_FAILED(nRetVal)) {
//		pDisk->Close();
//		pDisk->Release();
//		return PRL_ERR_VM_GET_HDD_IMG_NOT_OPEN;
//	}
//
//	LOG_MESSAGE(DBG_FATAL, "Cyl %u Head %u SPT %u\n",
//		DiskParameters.m_Cylinders,
//		DiskParameters.m_Heads,
//		DiskParameters.m_Sectors);
//
//	cHardDisk.setVersion(PVE::HardDiskV2);
//	cHardDisk.setSystemName(strDirPathToFile);
//	cHardDisk.setUserFriendlyName(strDirPathToFile);
//	cHardDisk.setEmulatedType(PVE::HardDiskImage);
//	cHardDisk.setSplitted(DiskParameters.m_Storages.size() > 1);
//
//	switch ((*DiskParameters.m_Storages.begin()).Type)
//	{
//		case PRL_IMAGE_PLAIN:
//		case PRL_IMAGE_VMDK_MONOLITHIC_FLAT:
//		case PRL_IMAGE_VMDK_EXTENT_2GB_FLAT:
//			cHardDisk.setDiskType(PHD_PLAIN_HARD_DISK);
//			break;
//		case PRL_IMAGE_COMPRESSED:
//		case PRL_IMAGE_VMDK_MONOLITHIC_SPARSE:
//		case PRL_IMAGE_VMDK_EXTENT_2GB_SPARSE:
//			cHardDisk.setDiskType(PHD_EXPANDING_HARD_DISK);
//			break;
//		default:
//			nRetVal = PRL_ERR_INVALID_HDD_GEOMETRY;
//			break;
//	}
//
//	cHardDisk.setBlockSize(DiskParameters.m_BlockSize);
//	// virtual size of hdd image
//	// size in MB - one sector 512 byte
//	cHardDisk.setSize(DiskParameters.m_SizeInSectors/2048);
//	// set size on disk in MB
//	quint64 ui64Size = 0;
//	CSimpleFileHelper::GetDirSize(strDirPathToFile,&ui64Size);
//	cHardDisk.setSizeOnDisk(ui64Size/(1024*1024));
//
//	// check suspend and change state flags on disk
//	if (cHardDisk.getVersion() == PVE::HardDiskV2)
//	{
//		QString strParam;
//
//		PRL_RESULT res = pDisk->GetUserParameter(SUSPEND_STATE_PARAM_NAME, strParam);
//		if (PRL_SUCCEEDED(res) && strParam.toUInt())
//			cHardDisk.setVersion(PVE::HardDiskV2Suspended);
//	}
//
//	if (PRL_SUCCEEDED(nRetVal))
//	{
//		QString qsCompatLevel;
//		PRL_RESULT Err = pDisk->GetUserParameter(QString(COMPAT_LEVEL_PARAM_NAME), qsCompatLevel);
//		if (PRL_SUCCEEDED(Err))
//			cHardDisk.setCompatLevel(qsCompatLevel);
//	}
//
//	pDisk->Close();
//	pDisk->Release();
//
//	CDspService::instance()->getVmConfigManager().
//		getHardDiskConfigCache().update(strDirPathToFile,
//				SmartPtr<CVmHardDisk>(new CVmHardDisk(cHardDisk)),
//				pUserSession);
//
//	return nRetVal;
	return PRL_ERR_FAILURE;
}