Changeset 67249 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jun 2, 2017 3:24:58 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 115944
- Location:
- trunk/src/VBox/Main
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r67211 r67249 374 374 $(if $(VBOX_WITH_NEW_USB_CODE_ON_DARWIN),VBOX_WITH_NEW_USB_CODE_ON_DARWIN,) 375 375 endif 376 if !defined(VBOX_WITHOUT_NEW_TAR_CREATOR)377 VBoxSVC_DEFS += VBOX_WITH_NEW_TAR_CREATOR378 endif379 376 VBoxSVC_DEFS.win += VBOX_COM_OUTOFPROC_MODULE 380 377 VBoxSVC_DEFS.win += _WIN32_WINNT=0x0510 … … 447 444 src-server/ApplianceImplExport.cpp \ 448 445 src-server/ApplianceImplImport.cpp \ 449 src-server/ApplianceImplIO.cpp \450 446 src-server/AudioAdapterImpl.cpp \ 451 447 src-server/BandwidthControlImpl.cpp \ -
trunk/src/VBox/Main/include/ApplianceImpl.h
r67208 r67249 220 220 HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock); 221 221 HRESULT i_writeFSOPC(TaskOVF *pTask, AutoWriteLockBase& writeLock); 222 #ifdef VBOX_WITH_NEW_TAR_CREATOR223 222 HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst); 224 223 HRESULT i_writeBufferToFile(RTVFSFSSTREAM hVfsFssDst, const char *pszFilename, const void *pvContent, size_t cbContent); 225 #else226 HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);227 #endif228 224 229 225 struct XMLStack; -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r67199 r67249 71 71 , hOurManifest(NIL_RTMANIFEST) 72 72 , fManifest(true) 73 #ifndef VBOX_WITH_NEW_TAR_CREATOR74 , fSha256(false)75 #endif76 73 , fDeterminedDigestTypes(false) 77 74 , hTheirManifest(NIL_RTMANIFEST) … … 162 159 * @{ */ 163 160 bool fManifest; // Create a manifest file on export 164 #ifndef VBOX_WITH_NEW_TAR_CREATOR165 bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)166 #endif167 161 /** @} */ 168 162 … … 429 423 430 424 431 #ifndef VBOX_WITH_NEW_TAR_CREATOR432 typedef struct SHASTORAGE433 {434 PVDINTERFACE pVDImageIfaces;435 bool fCreateDigest;436 bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */437 Utf8Str strDigest;438 } SHASTORAGE, *PSHASTORAGE;439 440 PVDINTERFACEIO ShaCreateInterface();441 PVDINTERFACEIO FileCreateInterface();442 PVDINTERFACEIO tarWriterCreateInterface(void);443 #endif444 445 int writeBufferToFile(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);446 447 425 #endif // !____H_APPLIANCEIMPLPRIVATE 448 426 -
trunk/src/VBox/Main/include/MediumImpl.h
r67244 r67249 210 210 MediumVariant_T aVariant, 211 211 SecretKeyStore *pKeyStore, 212 #ifdef VBOX_WITH_NEW_TAR_CREATOR213 212 RTVFSIOSTREAM hVfsIosDst, 214 #else215 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,216 #endif217 213 const ComObjPtr<Progress> &aProgress); 218 214 HRESULT i_importFile(const char *aFilename, … … 382 378 class DeleteTask; 383 379 class MergeTask; 384 #ifndef VBOX_WITH_NEW_TAR_CREATOR385 class ExportTask;386 #endif387 380 class ImportTask; 388 381 class EncryptTask; … … 397 390 friend class DeleteTask; 398 391 friend class MergeTask; 399 #ifndef VBOX_WITH_NEW_TAR_CREATOR400 friend class ExportTask;401 #endif402 392 friend class ImportTask; 403 393 friend class EncryptTask; … … 412 402 HRESULT i_taskCompactHandler(Medium::CompactTask &task); 413 403 HRESULT i_taskResizeHandler(Medium::ResizeTask &task); 414 #ifndef VBOX_WITH_NEW_TAR_CREATOR415 HRESULT i_taskExportHandler(Medium::ExportTask &task);416 #endif417 404 HRESULT i_taskImportHandler(Medium::ImportTask &task); 418 405 HRESULT i_taskEncryptHandler(Medium::EncryptTask &task); … … 426 413 }; 427 414 428 #endif /* ____H_MEDIUMIMPL */429 415 #endif /* !____H_MEDIUMIMPL */ 416 -
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r67244 r67249 22 22 #include <iprt/manifest.h> 23 23 #include <iprt/stream.h> 24 #ifndef VBOX_WITH_NEW_TAR_CREATOR 25 # include <iprt/tar.h> 26 #else 27 # include <iprt/zip.h> 28 #endif 24 #include <iprt/zip.h> 29 25 30 26 #include <VBox/version.h> … … 705 701 if (m->fManifest) 706 702 m->fDigestTypes = ovfF >= ovf::OVFVersion_2_0 ? RTMANIFEST_ATTR_SHA256 : RTMANIFEST_ATTR_SHA1; 707 #ifndef VBOX_WITH_NEW_TAR_CREATOR708 m->fSha256 = ovfF >= ovf::OVFVersion_2_0;709 #endif710 703 Assert(m->hOurManifest == NIL_RTMANIFEST); 711 704 … … 1988 1981 1989 1982 if (pTask->enFormat == ovf::OVFVersion_unknown) 1990 #ifdef VBOX_WITH_NEW_TAR_CREATOR1991 1983 rc = i_writeFSOPC(pTask, multiLock); 1992 #else1993 rc = E_NOTIMPL;1994 #endif1995 1984 else if (pTask->locInfo.strPath.endsWith(".ovf", Utf8Str::CaseInsensitive)) 1996 1985 rc = i_writeFSOVF(pTask, multiLock); … … 2010 1999 LogFlowFuncEnter(); 2011 2000 2012 #ifdef VBOX_WITH_NEW_TAR_CREATOR2013 2001 /* 2014 2002 * Create write-to-dir file system stream for the target directory. … … 2046 2034 LogFlowFuncLeave(); 2047 2035 return hrc; 2048 2049 #else /* VBOX_WITH_NEW_TAR_CREATOR */2050 HRESULT rc = S_OK;2051 2052 PVDINTERFACEIO pShaIo = 0;2053 PVDINTERFACEIO pFileIo = 0;2054 do2055 {2056 pShaIo = ShaCreateInterface();2057 if (!pShaIo)2058 {2059 rc = E_OUTOFMEMORY;2060 break;2061 }2062 pFileIo = FileCreateInterface();2063 if (!pFileIo)2064 {2065 rc = E_OUTOFMEMORY;2066 break;2067 }2068 2069 SHASTORAGE storage;2070 RT_ZERO(storage);2071 storage.fCreateDigest = m->fManifest;2072 storage.fSha256 = m->fSha256;2073 2074 2075 Utf8Str name = i_applianceIOName(applianceIOFile);2076 2077 int vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(),2078 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),2079 &storage.pVDImageIfaces);2080 if (RT_FAILURE(vrc))2081 {2082 rc = E_FAIL;2083 break;2084 }2085 rc = i_writeFSImpl(pTask, writeLock, pShaIo, &storage);2086 } while (0);2087 2088 /* Cleanup */2089 if (pShaIo)2090 RTMemFree(pShaIo);2091 if (pFileIo)2092 RTMemFree(pFileIo);2093 2094 LogFlowFuncLeave();2095 return rc;2096 #endif2097 2036 } 2098 2037 … … 2101 2040 LogFlowFuncEnter(); 2102 2041 2103 #ifdef VBOX_WITH_NEW_TAR_CREATOR2104 2042 /* 2105 2043 * Open the output file and attach a TAR creator to it. … … 2134 2072 LogFlowFuncLeave(); 2135 2073 return hrc; 2136 2137 #else /* VBOX_WITH_NEW_TAR_CREATOR */2138 2139 RTTAR tar;2140 int vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL);2141 if (RT_FAILURE(vrc))2142 return setError(VBOX_E_FILE_ERROR,2143 tr("Could not create OVA file '%s' (%Rrc)"),2144 pTask->locInfo.strPath.c_str(), vrc);2145 2146 HRESULT rc = S_OK;2147 2148 PVDINTERFACEIO pShaIo = 0;2149 PVDINTERFACEIO pTarIo = 0;2150 do2151 {2152 pShaIo = ShaCreateInterface();2153 if (!pShaIo)2154 {2155 rc = E_OUTOFMEMORY;2156 break;2157 }2158 pTarIo = tarWriterCreateInterface();2159 if (!pTarIo)2160 {2161 rc = E_OUTOFMEMORY;2162 break;2163 }2164 SHASTORAGE storage;2165 RT_ZERO(storage);2166 storage.fCreateDigest = m->fManifest;2167 storage.fSha256 = m->fSha256;2168 2169 Utf8Str name = i_applianceIOName(applianceIOTar);2170 2171 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(),2172 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),2173 &storage.pVDImageIfaces);2174 2175 if (RT_FAILURE(vrc))2176 {2177 rc = E_FAIL;2178 break;2179 }2180 rc = i_writeFSImpl(pTask, writeLock, pShaIo, &storage);2181 } while (0);2182 2183 RTTarClose(tar);2184 2185 /* Cleanup */2186 if (pShaIo)2187 RTMemFree(pShaIo);2188 if (pTarIo)2189 RTMemFree(pTarIo);2190 2191 /* Delete ova file on error */2192 if (FAILED(rc))2193 RTFileDelete(pTask->locInfo.strPath.c_str());2194 2195 LogFlowFuncLeave();2196 return rc;2197 #endif2198 2074 } 2199 2075 2200 #ifdef VBOX_WITH_NEW_TAR_CREATOR2201 2076 /** 2202 2077 * Writes the Oracle Public Cloud appliance. … … 2381 2256 2382 2257 } 2383 #endif 2384 2385 #ifdef VBOX_WITH_NEW_TAR_CREATOR 2258 2386 2259 HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst) 2387 #else2388 HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pIfIo, PSHASTORAGE pStorage)2389 #endif2390 2260 { 2391 2261 LogFlowFuncEnter(); … … 2393 2263 HRESULT rc = S_OK; 2394 2264 int vrc; 2395 #ifndef VBOX_WITH_NEW_TAR_CREATOR2396 list<STRPAIR> fileList;2397 #endif2398 2265 try 2399 2266 { … … 2406 2273 /* Construct the OVF name. */ 2407 2274 Utf8Str strOvfFile(pTask->locInfo.strPath); 2408 #ifdef VBOX_WITH_NEW_TAR_CREATOR2409 2275 strOvfFile.stripPath().stripSuffix().append(".ovf"); 2410 #else2411 strOvfFile.stripSuffix().append(".ovf");2412 #endif2413 2276 2414 2277 /* Render a valid ovf document into a memory buffer. The unknown … … 2418 2281 pTask->enFormat != ovf::OVFVersion_unknown ? pTask->enFormat : ovf::OVFVersion_2_0); 2419 2282 2420 { 2421 void *pvBuf = NULL; 2422 size_t cbSize = 0; 2423 xml::XmlMemWriter writer; 2424 writer.write(doc, &pvBuf, &cbSize); 2425 if (RT_UNLIKELY(!pvBuf)) 2426 throw setError(VBOX_E_FILE_ERROR, tr("Could not create OVF file '%s'"), strOvfFile.c_str()); 2427 2428 /* Write the ovf file to "disk". */ 2429 #ifdef VBOX_WITH_NEW_TAR_CREATOR 2430 rc = i_writeBufferToFile(hVfsFssDst, strOvfFile.c_str(), pvBuf, cbSize); 2431 if (FAILED(rc)) 2432 throw rc; 2433 #else 2434 vrc = writeBufferToFile(strOvfFile.c_str(), pvBuf, cbSize, pIfIo, pStorage); 2435 if (RT_FAILURE(vrc)) 2436 throw setErrorVrc(vrc, tr("Could not create OVF file '%s' (%Rrc)"), strOvfFile.c_str(), vrc); 2437 #endif 2438 2439 #ifndef VBOX_WITH_NEW_TAR_CREATOR 2440 fileList.push_back(STRPAIR(strOvfFile, pStorage->strDigest)); 2441 #endif 2442 } 2283 void *pvBuf = NULL; 2284 size_t cbSize = 0; 2285 xml::XmlMemWriter writer; 2286 writer.write(doc, &pvBuf, &cbSize); 2287 if (RT_UNLIKELY(!pvBuf)) 2288 throw setError(VBOX_E_FILE_ERROR, tr("Could not create OVF file '%s'"), strOvfFile.c_str()); 2289 2290 /* Write the ovf file to "disk". */ 2291 rc = i_writeBufferToFile(hVfsFssDst, strOvfFile.c_str(), pvBuf, cbSize); 2292 if (FAILED(rc)) 2293 throw rc; 2443 2294 } 2444 2295 … … 2514 2365 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf; 2515 2366 // target path needs to be composed from where the output OVF is 2516 #ifdef VBOX_WITH_NEW_TAR_CREATOR2517 2367 const Utf8Str &strTargetFilePath = strTargetFileNameOnly; 2518 #else2519 Utf8Str strTargetFilePath(pTask->locInfo.strPath);2520 strTargetFilePath.stripFilename()2521 .append("/")2522 .append(strTargetFileNameOnly);2523 #endif2524 2368 2525 2369 // The exporting requests a lock on the media tree. So leave our lock temporary. … … 2539 2383 * Export a disk image. 2540 2384 */ 2541 #ifdef VBOX_WITH_NEW_TAR_CREATOR2542 2385 /* For compressed VMDK fun, we let i_exportFile produce the image bytes. */ 2543 2386 RTVFSIOSTREAM hVfsIosDst; … … 2558 2401 pTask->pProgress); 2559 2402 RTVfsIoStrmRelease(hVfsIosDst); 2560 if (FAILED(rc)) throw rc;2561 #else2562 /** @todo this progress object needs to be hooked up to pTask->pProgress... */2563 ComObjPtr<Progress> pProgress2;2564 pProgress2.createObject();2565 rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this),2566 BstrFmt(tr("Creating medium '%s'"),2567 strTargetFilePath.c_str()).raw(), TRUE);2568 if (FAILED(rc)) throw rc;2569 2570 rc = pSourceDisk->i_exportFile(strTargetFilePath.c_str(),2571 format,2572 MediumVariant_VmdkStreamOptimized,2573 m->m_pSecretKeyStore,2574 pIfIo,2575 pStorage,2576 pProgress2);2577 if (FAILED(rc)) throw rc;2578 2579 ComPtr<IProgress> pProgress3(pProgress2);2580 // now wait for the background disk operation to complete; this throws HRESULTs on error2581 i_waitForAsyncProgress(pTask->pProgress, pProgress3);2582 #endif2583 2403 } 2584 2404 else … … 2588 2408 */ 2589 2409 Assert(pDiskEntry->type == VirtualSystemDescriptionType_CDROM); 2590 2591 #ifdef VBOX_WITH_NEW_TAR_CREATOR2592 2410 rc = pSourceDisk->i_addRawToFss(strTargetFilePath.c_str(), m->m_pSecretKeyStore, hVfsFssDst, 2593 2411 pTask->pProgress, false /*fSparse*/); 2594 if (FAILED(rc)) throw rc;2595 #else2596 /* Read the ISO file and add one to OVA/OVF package */2597 void *pvStorage;2598 RTFILE pFile = NULL;2599 void *pvUser = pStorage;2600 2601 vrc = pIfIo->pfnOpen(pvUser, strTargetFilePath.c_str(),2602 RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE,2603 0,2604 &pvStorage);2605 if (RT_FAILURE(vrc))2606 throw setError(VBOX_E_FILE_ERROR,2607 tr("Could not create or open file '%s' (%Rrc)"),2608 strTargetFilePath.c_str(), vrc);2609 2610 vrc = RTFileOpen(&pFile,2611 strSrcFilePath.c_str(),2612 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);2613 2614 if (RT_FAILURE(vrc) || pFile == NULL)2615 {2616 pIfIo->pfnClose(pvUser, pvStorage);2617 throw setError(VBOX_E_FILE_ERROR,2618 tr("Could not create or open file '%s' (%Rrc)"),2619 strSrcFilePath.c_str(), vrc);2620 }2621 2622 uint64_t cbFile = 0;2623 vrc = RTFileGetSize(pFile, &cbFile);2624 if (RT_SUCCESS(vrc))2625 {2626 size_t const cbTmpSize = _1M;2627 void *pvTmpBuf = RTMemAlloc(cbTmpSize);2628 if (pvTmpBuf)2629 {2630 /* The copy loop. */2631 uint64_t offDstFile = 0;2632 for (;;)2633 {2634 size_t cbChunk = 0;2635 vrc = RTFileRead(pFile, pvTmpBuf, cbTmpSize, &cbChunk);2636 if (RT_FAILURE(vrc) || cbChunk == 0)2637 break;2638 2639 size_t cbWritten = 0;2640 vrc = pIfIo->pfnWriteSync(pvUser,2641 pvStorage,2642 offDstFile,2643 pvTmpBuf,2644 cbChunk,2645 &cbWritten);2646 if (RT_FAILURE(vrc))2647 break;2648 Assert(cbWritten == cbChunk);2649 2650 offDstFile += cbWritten;2651 }2652 2653 RTMemFree(pvTmpBuf);2654 }2655 else2656 vrc = VERR_NO_MEMORY;2657 }2658 2659 pIfIo->pfnClose(pvUser, pvStorage);2660 RTFileClose(pFile);2661 2662 if (RT_FAILURE(vrc))2663 {2664 if (vrc == VERR_EOF)2665 vrc = VINF_SUCCESS;2666 else2667 throw setError(VBOX_E_FILE_ERROR,2668 tr("Error during copy CD/DVD image '%s' (%Rrc)"),2669 strSrcFilePath.c_str(), vrc);2670 }2671 #endif2672 2412 } 2413 if (FAILED(rc)) throw rc; 2673 2414 } 2674 2415 catch (HRESULT rc3) … … 2681 2422 // in the meantime) 2682 2423 writeLock.acquire(); 2683 #ifndef VBOX_WITH_NEW_TAR_CREATOR2684 fileList.push_back(STRPAIR(strTargetFilePath, pStorage->strDigest));2685 #endif2686 2424 } 2687 2425 … … 2694 2432 m->ulWeightForManifestOperation); // operation's weight, as set up 2695 2433 // with the IProgress originally); 2696 #ifdef VBOX_WITH_NEW_TAR_CREATOR2697 2434 /* Create a memory I/O stream and write the manifest to it. */ 2698 2435 RTVFSIOSTREAM hVfsIosManifest; … … 2724 2461 if (FAILED(rc)) 2725 2462 throw rc; 2726 #else2727 PRTMANIFESTTEST paManifestFiles = (PRTMANIFESTTEST)RTMemAlloc(sizeof(RTMANIFESTTEST) * fileList.size());2728 size_t i = 0;2729 for (list<STRPAIR>::const_iterator2730 it = fileList.begin();2731 it != fileList.end();2732 ++it, ++i)2733 {2734 paManifestFiles[i].pszTestFile = (*it).first.c_str();2735 paManifestFiles[i].pszTestDigest = (*it).second.c_str();2736 }2737 void *pvBuf;2738 size_t cbSize;2739 vrc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, m->fSha256 ? RTDIGESTTYPE_SHA256 : RTDIGESTTYPE_SHA1,2740 paManifestFiles, fileList.size());2741 RTMemFree(paManifestFiles);2742 if (RT_FAILURE(vrc))2743 throw setError(VBOX_E_FILE_ERROR,2744 tr("Could not create manifest file '%s' (%Rrc)"),2745 strMfFileName.c_str(), vrc);2746 /* Disable digest creation for the manifest file. */2747 pStorage->fCreateDigest = false;2748 /* Write the manifest file to disk. */2749 vrc = writeBufferToFile(strMfFilePath.c_str(), pvBuf, cbSize, pIfIo, pStorage);2750 RTMemFree(pvBuf);2751 if (RT_FAILURE(vrc))2752 throw setError(VBOX_E_FILE_ERROR,2753 tr("Could not create manifest file '%s' (%Rrc)"),2754 strMfFilePath.c_str(), vrc);2755 #endif2756 2463 } 2757 2464 } … … 2766 2473 } 2767 2474 2768 #ifndef VBOX_WITH_NEW_TAR_CREATOR /* done in caller now */2769 /* Cleanup on error */2770 if (FAILED(rc))2771 {2772 for (list<STRPAIR>::const_iterator2773 it = fileList.begin();2774 it != fileList.end();2775 ++it)2776 pIfIo->pfnDelete(pStorage, (*it).first.c_str());2777 }2778 #endif2779 2780 2475 LogFlowFunc(("rc=%Rhrc\n", rc)); 2781 2476 LogFlowFuncLeave(); … … 2785 2480 2786 2481 2787 #ifdef VBOX_WITH_NEW_TAR_CREATOR2788 2482 /** 2789 2483 * Writes a memory buffer to a file in the output file system stream. … … 2827 2521 return hrc; 2828 2522 } 2829 #endif 2830 2523 -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r67184 r67249 1507 1507 m->fDeterminedDigestTypes = true; 1508 1508 1509 #ifndef VBOX_WITH_NEW_TAR_CREATOR1510 m->fSha256 = RT_BOOL(m->fDigestTypes & RTMANIFEST_ATTR_SHA256); /** @todo retire this member */1511 #endif1512 1509 return S_OK; 1513 1510 } -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r67244 r67249 651 651 }; 652 652 653 #ifndef VBOX_WITH_NEW_TAR_CREATOR654 class Medium::ExportTask : public Medium::Task655 {656 public:657 ExportTask(Medium *aMedium,658 Progress *aProgress,659 const char *aFilename,660 MediumFormat *aFormat,661 MediumVariant_T aVariant,662 SecretKeyStore *pSecretKeyStore,663 VDINTERFACEIO *aVDImageIOIf,664 void *aVDImageIOUser,665 MediumLockList *aSourceMediumLockList,666 bool fKeepSourceMediumLockList = false)667 : Medium::Task(aMedium, aProgress),668 mpSourceMediumLockList(aSourceMediumLockList),669 mFilename(aFilename),670 mFormat(aFormat),671 mVariant(aVariant),672 m_pSecretKeyStore(pSecretKeyStore),673 mfKeepSourceMediumLockList(fKeepSourceMediumLockList)674 {675 AssertReturnVoidStmt(aSourceMediumLockList != NULL, mRC = E_FAIL);676 677 mVDImageIfaces = aMedium->m->vdImageIfaces;678 679 if (aVDImageIOIf)680 {681 int vrc = VDInterfaceAdd(&aVDImageIOIf->Core, "Medium::vdInterfaceIO",682 VDINTERFACETYPE_IO, aVDImageIOUser,683 sizeof(VDINTERFACEIO), &mVDImageIfaces);684 AssertRCReturnVoidStmt(vrc, mRC = E_FAIL);685 }686 m_strTaskName = "createExport";687 }688 689 ~ExportTask()690 {691 if (!mfKeepSourceMediumLockList && mpSourceMediumLockList)692 delete mpSourceMediumLockList;693 }694 695 MediumLockList *mpSourceMediumLockList;696 Utf8Str mFilename;697 ComObjPtr<MediumFormat> mFormat;698 MediumVariant_T mVariant;699 PVDINTERFACE mVDImageIfaces;700 SecretKeyStore *m_pSecretKeyStore;701 702 private:703 HRESULT executeTask();704 bool mfKeepSourceMediumLockList;705 };706 #endif /* !VBOX_WITH_NEW_TAR_CREATOR */707 708 653 class Medium::ImportTask : public Medium::Task 709 654 { … … 956 901 return mMedium->i_taskMergeHandler(*this); 957 902 } 958 959 #ifndef VBOX_WITH_NEW_TAR_CREATOR960 /**961 * Implementation code for the "export" task.962 */963 HRESULT Medium::ExportTask::executeTask()964 {965 return mMedium->i_taskExportHandler(*this);966 }967 #endif968 903 969 904 /** … … 6141 6076 * @param pKeyStore The optional key store for decrypting the data for 6142 6077 * encrypted media during the export. 6143 * @param aVDImageIOIf Pointer to the callback table for a VDINTERFACEIO 6144 * interface. May be NULL. 6145 * @param aVDImageIOUser Opaque data for the callbacks. 6078 * @param hVfsIosDst The destination I/O stream object. 6146 6079 * @param aProgress Progress object to use. 6147 6080 * @return … … 6153 6086 MediumVariant_T aVariant, 6154 6087 SecretKeyStore *pKeyStore, 6155 #ifdef VBOX_WITH_NEW_TAR_CREATOR6156 6088 RTVFSIOSTREAM hVfsIosDst, 6157 #else6158 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,6159 #endif6160 6089 const ComObjPtr<Progress> &aProgress) 6161 6090 { … … 6163 6092 AssertReturn(aFormat.isNotNull(), E_INVALIDARG); 6164 6093 AssertReturn(aProgress.isNotNull(), E_INVALIDARG); 6165 6166 #ifdef VBOX_WITH_NEW_TAR_CREATOR6167 6094 6168 6095 AutoCaller autoCaller(this); … … 6256 6183 } 6257 6184 return hrc; 6258 #else6259 6260 AutoCaller autoCaller(this);6261 if (FAILED(autoCaller.rc())) return autoCaller.rc();6262 6263 HRESULT rc = S_OK;6264 Medium::Task *pTask = NULL;6265 6266 try6267 {6268 // This needs no extra locks besides what is done in the called methods.6269 6270 /* Build the source lock list. */6271 MediumLockList *pSourceMediumLockList(new MediumLockList());6272 rc = i_createMediumLockList(true /* fFailIfInaccessible */,6273 NULL /* pToLockWrite */,6274 false /* fMediumLockWriteAll */,6275 NULL,6276 *pSourceMediumLockList);6277 if (FAILED(rc))6278 {6279 delete pSourceMediumLockList;6280 throw rc;6281 }6282 6283 rc = pSourceMediumLockList->Lock();6284 if (FAILED(rc))6285 {6286 delete pSourceMediumLockList;6287 throw setError(rc,6288 tr("Failed to lock source media '%s'"),6289 i_getLocationFull().c_str());6290 }6291 6292 /* setup task object to carry out the operation asynchronously */6293 pTask = new Medium::ExportTask(this, aProgress, aFilename, aFormat, aVariant,6294 pKeyStore, aVDImageIOIf, aVDImageIOUser, pSourceMediumLockList);6295 rc = pTask->rc();6296 AssertComRC(rc);6297 if (FAILED(rc))6298 throw rc;6299 }6300 catch (HRESULT aRC) { rc = aRC; }6301 6302 if (SUCCEEDED(rc))6303 rc = pTask->createThread();6304 else if (pTask != NULL)6305 delete pTask;6306 6307 return rc;6308 #endif6309 6185 } 6310 6186 … … 9767 9643 } 9768 9644 9769 #ifndef VBOX_WITH_NEW_TAR_CREATOR9770 /**9771 * Implementation code for the "export" task.9772 *9773 * This only gets started from Medium::exportFile() and always runs9774 * asynchronously. It doesn't touch anything configuration related, so9775 * we never save the VirtualBox.xml file here.9776 *9777 * @param task9778 * @return9779 */9780 HRESULT Medium::i_taskExportHandler(Medium::ExportTask &task)9781 {9782 HRESULT rc = S_OK;9783 9784 try9785 {9786 /* Lock all in {parent,child} order. The lock is also used as a9787 * signal from the task initiator (which releases it only after9788 * RTThreadCreate()) that we can start the job. */9789 ComObjPtr<Medium> pBase = i_getBase();9790 AutoWriteLock thisLock(this COMMA_LOCKVAL_SRC_POS);9791 9792 PVDISK hdd;9793 int vrc = VDCreate(m->vdDiskIfaces, i_convertDeviceType(), &hdd);9794 ComAssertRCThrow(vrc, E_FAIL);9795 9796 try9797 {9798 settings::StringsMap::iterator itKeyStore = pBase->m->mapProperties.find("CRYPT/KeyStore");9799 if (itKeyStore != pBase->m->mapProperties.end())9800 {9801 settings::StringsMap::iterator itKeyId = pBase->m->mapProperties.find("CRYPT/KeyId");9802 9803 #ifdef VBOX_WITH_EXTPACK9804 ExtPackManager *pExtPackManager = m->pVirtualBox->i_getExtPackManager();9805 if (pExtPackManager->i_isExtPackUsable(ORACLE_PUEL_EXTPACK_NAME))9806 {9807 /* Load the plugin */9808 Utf8Str strPlugin;9809 rc = pExtPackManager->i_getLibraryPathForExtPack(g_szVDPlugin, ORACLE_PUEL_EXTPACK_NAME, &strPlugin);9810 if (SUCCEEDED(rc))9811 {9812 vrc = VDPluginLoadFromFilename(strPlugin.c_str());9813 if (RT_FAILURE(vrc))9814 throw setError(VBOX_E_NOT_SUPPORTED,9815 tr("Retrieving encryption settings of the image failed because the encryption plugin could not be loaded (%s)"),9816 i_vdError(vrc).c_str());9817 }9818 else9819 throw setError(VBOX_E_NOT_SUPPORTED,9820 tr("Encryption is not supported because the extension pack '%s' is missing the encryption plugin (old extension pack installed?)"),9821 ORACLE_PUEL_EXTPACK_NAME);9822 }9823 else9824 throw setError(VBOX_E_NOT_SUPPORTED,9825 tr("Encryption is not supported because the extension pack '%s' is missing"),9826 ORACLE_PUEL_EXTPACK_NAME);9827 #else9828 throw setError(VBOX_E_NOT_SUPPORTED,9829 tr("Encryption is not supported because extension pack support is not built in"));9830 #endif9831 9832 if (itKeyId == pBase->m->mapProperties.end())9833 throw setError(VBOX_E_INVALID_OBJECT_STATE,9834 tr("Image '%s' is configured for encryption but doesn't has a key identifier set"),9835 pBase->m->strLocationFull.c_str());9836 9837 /* Find the proper secret key in the key store. */9838 if (!task.m_pSecretKeyStore)9839 throw setError(VBOX_E_INVALID_OBJECT_STATE,9840 tr("Image '%s' is configured for encryption but there is no key store to retrieve the password from"),9841 pBase->m->strLocationFull.c_str());9842 9843 SecretKey *pKey = NULL;9844 vrc = task.m_pSecretKeyStore->retainSecretKey(itKeyId->second, &pKey);9845 if (RT_FAILURE(vrc))9846 throw setError(VBOX_E_INVALID_OBJECT_STATE,9847 tr("Failed to retrieve the secret key with ID \"%s\" from the store (%Rrc)"),9848 itKeyId->second.c_str(), vrc);9849 9850 /** @todo r=bird: Someone explain why this continue to work when9851 * CryptoSettingsRead goes out of the scope? */9852 Medium::CryptoFilterSettings CryptoSettingsRead;9853 i_taskEncryptSettingsSetup(&CryptoSettingsRead, NULL, itKeyStore->second.c_str(), (const char *)pKey->getKeyBuffer(),9854 false /* fCreateKeyStore */);9855 vrc = VDFilterAdd(hdd, "CRYPT", VD_FILTER_FLAGS_READ, CryptoSettingsRead.vdFilterIfaces);9856 if (vrc == VERR_VD_PASSWORD_INCORRECT)9857 {9858 task.m_pSecretKeyStore->releaseSecretKey(itKeyId->second);9859 throw setError(VBOX_E_PASSWORD_INCORRECT,9860 tr("The password to decrypt the image is incorrect"));9861 }9862 else if (RT_FAILURE(vrc))9863 {9864 task.m_pSecretKeyStore->releaseSecretKey(itKeyId->second);9865 throw setError(VBOX_E_INVALID_OBJECT_STATE,9866 tr("Failed to load the decryption filter: %s"),9867 i_vdError(vrc).c_str());9868 }9869 9870 task.m_pSecretKeyStore->releaseSecretKey(itKeyId->second);9871 }9872 9873 /* Open all media in the source chain. */9874 MediumLockList::Base::const_iterator sourceListBegin =9875 task.mpSourceMediumLockList->GetBegin();9876 MediumLockList::Base::const_iterator sourceListEnd =9877 task.mpSourceMediumLockList->GetEnd();9878 for (MediumLockList::Base::const_iterator it = sourceListBegin;9879 it != sourceListEnd;9880 ++it)9881 {9882 const MediumLock &mediumLock = *it;9883 const ComObjPtr<Medium> &pMedium = mediumLock.GetMedium();9884 AutoReadLock alock(pMedium COMMA_LOCKVAL_SRC_POS);9885 9886 /* sanity check */9887 Assert(pMedium->m->state == MediumState_LockedRead);9888 9889 /* Open all media in read-only mode. */9890 vrc = VDOpen(hdd,9891 pMedium->m->strFormat.c_str(),9892 pMedium->m->strLocationFull.c_str(),9893 VD_OPEN_FLAGS_READONLY | m->uOpenFlagsDef,9894 pMedium->m->vdImageIfaces);9895 if (RT_FAILURE(vrc))9896 throw setError(VBOX_E_FILE_ERROR,9897 tr("Could not open the medium storage unit '%s'%s"),9898 pMedium->m->strLocationFull.c_str(),9899 i_vdError(vrc).c_str());9900 }9901 9902 Utf8Str targetFormat(task.mFormat->i_getId());9903 Utf8Str targetLocation(task.mFilename);9904 uint64_t capabilities = task.mFormat->i_getCapabilities();9905 9906 Assert(m->state == MediumState_LockedRead);9907 9908 /* unlock before the potentially lengthy operation */9909 thisLock.release();9910 9911 /* ensure the target directory exists */9912 if (capabilities & MediumFormatCapabilities_File)9913 {9914 rc = VirtualBox::i_ensureFilePathExists(targetLocation,9915 !(task.mVariant & MediumVariant_NoCreateDir) /* fCreate */);9916 if (FAILED(rc))9917 throw rc;9918 }9919 9920 PVDISK targetHdd;9921 vrc = VDCreate(m->vdDiskIfaces, i_convertDeviceType(), &targetHdd);9922 ComAssertRCThrow(vrc, E_FAIL);9923 9924 try9925 {9926 vrc = VDCopy(hdd,9927 VD_LAST_IMAGE,9928 targetHdd,9929 targetFormat.c_str(),9930 targetLocation.c_str(),9931 false /* fMoveByRename */,9932 0 /* cbSize */,9933 task.mVariant & ~MediumVariant_NoCreateDir,9934 NULL /* pDstUuid */,9935 VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_SEQUENTIAL,9936 NULL /* pVDIfsOperation */,9937 task.mVDImageIfaces,9938 task.mVDOperationIfaces);9939 if (RT_FAILURE(vrc))9940 throw setError(VBOX_E_FILE_ERROR,9941 tr("Could not create the exported medium '%s'%s"),9942 targetLocation.c_str(), i_vdError(vrc).c_str());9943 }9944 catch (HRESULT aRC) { rc = aRC; }9945 9946 VDDestroy(targetHdd);9947 }9948 catch (HRESULT aRC) { rc = aRC; }9949 9950 VDDestroy(hdd);9951 }9952 catch (HRESULT aRC) { rc = aRC; }9953 9954 /* Everything is explicitly unlocked when the task exits,9955 * as the task destruction also destroys the source chain. */9956 9957 /* Make sure the source chain is released early, otherwise it can9958 * lead to deadlocks with concurrent IAppliance activities. */9959 task.mpSourceMediumLockList->Clear();9960 9961 return rc;9962 }9963 #endif /* !VBOX_WITH_NEW_TAR_CREATOR */9964 9965 9645 /** 9966 9646 * Implementation code for the "import" task.
Note:
See TracChangeset
for help on using the changeset viewer.