VirtualBox

Changeset 67193 in vbox


Ignore:
Timestamp:
Jun 1, 2017 8:44:31 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115870
Message:

Main: ApplianceImplExport.cpp: Hacking OPC exporting.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r67184 r67193  
    374374        $(if $(VBOX_WITH_NEW_USB_CODE_ON_DARWIN),VBOX_WITH_NEW_USB_CODE_ON_DARWIN,)
    375375endif
    376 if defined(VBOX_WITH_NEW_TAR_CREATOR) #|| "$(USERNAME)" == "bird" # temporary
     376if defined(VBOX_WITH_NEW_TAR_CREATOR) || "$(USERNAME)" == "bird" # temporary
    377377 VBoxSVC_DEFS += VBOX_WITH_NEW_TAR_CREATOR
    378378endif
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r67184 r67193  
    219219    HRESULT i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
    220220    HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
     221    HRESULT i_writeFSOPC(TaskOVF *pTask, AutoWriteLockBase& writeLock);
    221222#ifdef VBOX_WITH_NEW_TAR_CREATOR
    222     HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst);
     223    HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst,
     224                          bool fOvfFile = true, bool fStreamOptimizedVmdk = true);
    223225    HRESULT i_writeBufferToFile(RTVFSFSSTREAM hVfsFssDst, const char *pszFilename, const void *pvContent, size_t cbContent);
    224226#else
  • trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp

    r67190 r67193  
    673673        return E_ACCESSDENIED;
    674674
    675     // see if we can handle this file; for now we insist it has an ".ovf" extension
    676     if (!(   aPath.endsWith(".ovf", Utf8Str::CaseInsensitive)
    677           || aPath.endsWith(".ova", Utf8Str::CaseInsensitive)))
    678         return setError(VBOX_E_FILE_ERROR,
    679                         tr("Appliance file must have .ovf or .ova extension"));
    680 
     675    // figure the export format.  We exploit the unknown version value for oracle public cloud.
    681676    ovf::OVFVersion_T ovfF;
    682677    if (aFormat == "ovf-0.9")
     
    686681    else if (aFormat == "ovf-2.0")
    687682        ovfF = ovf::OVFVersion_2_0;
     683    else if (aFormat == "opc")
     684        ovfF = ovf::OVFVersion_unknown;
    688685    else
    689686        return setError(VBOX_E_FILE_ERROR,
    690687                        tr("Invalid format \"%s\" specified"), aFormat.c_str());
     688
     689    // Check the extension.
     690    if (ovfF == ovf::OVFVersion_unknown)
     691    {
     692        if (!aPath.endsWith(".tar.gz", Utf8Str::CaseInsensitive))
     693            return setError(VBOX_E_FILE_ERROR,
     694                            tr("OPC appliance file must have .tar.gz extension"));
     695    }
     696    else if (   !aPath.endsWith(".ovf", Utf8Str::CaseInsensitive)
     697             && !aPath.endsWith(".ova", Utf8Str::CaseInsensitive))
     698        return setError(VBOX_E_FILE_ERROR, tr("Appliance file must have .ovf or .ova extension"));
     699
    691700
    692701    /* As of OVF 2.0 we have to use SHA-256 in the manifest. */
     
    19761985    m->state = Data::ApplianceExporting;
    19771986
    1978     if (pTask->locInfo.strPath.endsWith(".ovf", Utf8Str::CaseInsensitive))
     1987    if (pTask->enFormat == ovf::OVFVersion_unknown)
     1988#ifdef VBOX_WITH_NEW_TAR_CREATOR
     1989        rc = i_writeFSOPC(pTask, multiLock);
     1990#else
     1991        rc = E_NOTIMPL;
     1992#endif
     1993    else if (pTask->locInfo.strPath.endsWith(".ovf", Utf8Str::CaseInsensitive))
    19791994        rc = i_writeFSOVF(pTask, multiLock);
    19801995    else
     
    21822197
    21832198#ifdef VBOX_WITH_NEW_TAR_CREATOR
    2184 HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst)
     2199/**
     2200 * Writes the Oracle Public Cloud appliance.
     2201 *
     2202 * It expect raw disk images inside a gzipped tarball.  We enable sparse files
     2203 * to save diskspace on the target host system.
     2204 */
     2205HRESULT Appliance::i_writeFSOPC(TaskOVF *pTask, AutoWriteLockBase &writeLock)
     2206{
     2207    LogFlowFuncEnter();
     2208
     2209    /*
     2210     * Open the output file, pipe it thru gzip and attach a TAR creator.
     2211     */
     2212    HRESULT hrc;
     2213    RTVFSIOSTREAM hVfsIosFile;
     2214    int vrc = RTVfsIoStrmOpenNormal(pTask->locInfo.strPath.c_str(),
     2215                                    RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE,
     2216                                    &hVfsIosFile);
     2217    if (RT_SUCCESS(vrc))
     2218    {
     2219
     2220        RTVFSIOSTREAM hVfsIosGzip;
     2221        vrc = RTZipGzipCompressIoStream(hVfsIosFile, 0 /*fFlags*/, 6 /*uLevel*/, &hVfsIosGzip);
     2222        RTVfsIoStrmRelease(hVfsIosFile);
     2223        if (RT_SUCCESS(vrc))
     2224        {
     2225
     2226            RTVFSFSSTREAM hVfsFssTar;
     2227            vrc = RTZipTarFsStreamToIoStream(hVfsIosGzip, RTZIPTARFORMAT_GNU, RTZIPTAR_C_SPARSE, &hVfsFssTar);
     2228            RTVfsIoStrmRelease(hVfsIosGzip);
     2229            if (RT_SUCCESS(vrc))
     2230            {
     2231                /*
     2232                 * Before we do the actual writing, disable OVF and manifest creation.
     2233                 */
     2234                bool fManifestSaved = m->fManifest;
     2235                m->fManifest = false;
     2236
     2237                __debugbreak();
     2238                hrc = i_writeFSImpl(pTask, writeLock, hVfsFssTar, false /*fOvfFile*/, false /*fStreamOptimizedVmdk*/);
     2239                RTVfsFsStrmRelease(hVfsFssTar);
     2240
     2241                m->fManifest = fManifestSaved;
     2242            }
     2243            else
     2244                hrc = setErrorVrc(vrc, tr("Failed create TAR creator for '%s' (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
     2245        }
     2246        else
     2247            hrc = setErrorVrc(vrc, tr("Failed create gzipper for '%s' (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
     2248
     2249        /* Delete the OVA on failure. */
     2250        if (FAILED(hrc))
     2251            RTFileDelete(pTask->locInfo.strPath.c_str());
     2252    }
     2253    else
     2254        hrc = setErrorVrc(vrc, tr("Failed to open '%s' for writing (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
     2255
     2256    LogFlowFuncLeave();
     2257    return hrc;
     2258
     2259}
     2260#endif
     2261
     2262#ifdef VBOX_WITH_NEW_TAR_CREATOR
     2263HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst,
     2264                                 bool fOvfFile /*= true*/, bool fStreamOptimizedVmdk /*= true*/)
    21852265#else
    21862266HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pIfIo, PSHASTORAGE pStorage)
     
    22142294#endif
    22152295
    2216             /* Render a valid ovf document into a memory buffer. */
     2296            /* Render a valid ovf document into a memory buffer.  The unknown
     2297               version upgrade relates to the OPC hack up in Appliance::write(). */
    22172298            xml::Document doc;
    2218             i_buildXML(writeLock, doc, stack, pTask->locInfo.strPath, pTask->enFormat);
    2219 
    2220             void *pvBuf = NULL;
    2221             size_t cbSize = 0;
    2222             xml::XmlMemWriter writer;
    2223             writer.write(doc, &pvBuf, &cbSize);
    2224             if (RT_UNLIKELY(!pvBuf))
    2225                 throw setError(VBOX_E_FILE_ERROR,
    2226                                tr("Could not create OVF file '%s'"),
    2227                                strOvfFile.c_str());
    2228 
    2229             /* Write the ovf file to "disk". */
     2299            i_buildXML(writeLock, doc, stack, pTask->locInfo.strPath,
     2300                       pTask->enFormat != ovf::OVFVersion_unknown ? pTask->enFormat : ovf::OVFVersion_2_0);
     2301
    22302302#ifdef VBOX_WITH_NEW_TAR_CREATOR
    2231             rc = i_writeBufferToFile(hVfsFssDst, strOvfFile.c_str(), pvBuf, cbSize);
    2232             if (FAILED(rc))
    2233                 throw rc;
     2303            if (fOvfFile)
     2304#endif
     2305            {
     2306                void *pvBuf = NULL;
     2307                size_t cbSize = 0;
     2308                xml::XmlMemWriter writer;
     2309                writer.write(doc, &pvBuf, &cbSize);
     2310                if (RT_UNLIKELY(!pvBuf))
     2311                    throw setError(VBOX_E_FILE_ERROR, tr("Could not create OVF file '%s'"), strOvfFile.c_str());
     2312
     2313                /* Write the ovf file to "disk". */
     2314#ifdef VBOX_WITH_NEW_TAR_CREATOR
     2315                rc = i_writeBufferToFile(hVfsFssDst, strOvfFile.c_str(), pvBuf, cbSize);
     2316                if (FAILED(rc))
     2317                    throw rc;
    22342318#else
    2235             vrc = writeBufferToFile(strOvfFile.c_str(), pvBuf, cbSize, pIfIo, pStorage);
    2236             if (RT_FAILURE(vrc))
    2237                 throw setErrorVrc(vrc, tr("Could not create OVF file '%s' (%Rrc)"), strOvfFile.c_str(), vrc);
     2319                vrc = writeBufferToFile(strOvfFile.c_str(), pvBuf, cbSize, pIfIo, pStorage);
     2320                if (RT_FAILURE(vrc))
     2321                    throw setErrorVrc(vrc, tr("Could not create OVF file '%s' (%Rrc)"), strOvfFile.c_str(), vrc);
    22382322#endif
    22392323
    22402324#ifndef VBOX_WITH_NEW_TAR_CREATOR
    2241             fileList.push_back(STRPAIR(strOvfFile, pStorage->strDigest));
     2325                fileList.push_back(STRPAIR(strOvfFile, pStorage->strDigest));
    22422326#endif
     2327            }
    22432328        }
    22442329
     
    23482433#ifdef VBOX_WITH_NEW_TAR_CREATOR
    23492434                    /* For compressed VMDK fun, we let i_exportFile produce the image bytes. */
    2350                     if (true)
     2435                    if (fStreamOptimizedVmdk)
    23512436                    {
    23522437                        RTVFSIOSTREAM hVfsIosDst;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette