VirtualBox

Ignore:
Timestamp:
Oct 21, 2010 10:00:15 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
66857
Message:

Runtime;Main-OVF-Import: added online creation of SHA1 sums; preread/calc is done in a second worker thread; reading is cached; directly read out of an ova file; started to make reading fully streaming aware

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r33238 r33289  
    1919#include <iprt/path.h>
    2020#include <iprt/cpp/utils.h>
    21 #include <iprt/tar.h>
    2221
    2322#include <VBox/com/array.h>
     
    633632
    634633/**
     634 * Called from Appliance::importImpl() and Appliance::writeImpl() to set up a
     635 * progress object with the proper weights and maximum progress values.
     636 *
     637 * @param pProgress
     638 * @param bstrDescription
     639 * @param mode
     640 * @return
     641 */
     642HRESULT Appliance::setUpProgress(ComObjPtr<Progress> &pProgress,
     643                                 const Bstr &bstrDescription,
     644                                 SetUpProgressMode mode)
     645{
     646    HRESULT rc;
     647
     648    /* Create the progress object */
     649    pProgress.createObject();
     650
     651    // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
     652    disksWeight();
     653
     654    m->ulWeightForManifestOperation = 0;
     655
     656    ULONG cOperations;
     657    ULONG ulTotalOperationsWeight;
     658
     659    cOperations =   1               // one for XML setup
     660                  + m->cDisks;      // plus one per disk
     661    if (m->ulTotalDisksMB)
     662    {
     663        m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100);    // use 1% of the progress for the XML
     664        ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
     665    }
     666    else
     667    {
     668        // no disks to export:
     669        m->ulWeightForXmlOperation = 1;
     670        ulTotalOperationsWeight = 1;
     671    }
     672
     673    switch (mode)
     674    {
     675        case ImportFile:
     676        {
     677            break;
     678        }
     679        case WriteFile:
     680        {
     681            // assume that creating the manifest will take .1% of the time it takes to export the disks
     682            if (m->fManifest)
     683            {
     684                ++cOperations;          // another one for creating the manifest
     685
     686                m->ulWeightForManifestOperation = (ULONG)((double)m->ulTotalDisksMB * .1 / 100);    // use .5% of the progress for the manifest
     687                ulTotalOperationsWeight += m->ulWeightForManifestOperation;
     688            }
     689            break;
     690        }
     691        case ImportS3:
     692        {
     693            cOperations += 1 + 1;     // another one for the manifest file & another one for the import
     694            ulTotalOperationsWeight = m->ulTotalDisksMB;
     695            if (!m->ulTotalDisksMB)
     696                // no disks to export:
     697                ulTotalOperationsWeight = 1;
     698
     699            ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50  / 100);  // use 50% for import
     700            ulTotalOperationsWeight += ulImportWeight;
     701
     702            m->ulWeightForXmlOperation = ulImportWeight; /* save for using later */
     703
     704            ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1  / 100);  // use 0.1% for init
     705            ulTotalOperationsWeight += ulInitWeight;
     706            break;
     707        }
     708        case WriteS3:
     709        {
     710            cOperations += 1 + 1;     // another one for the mf & another one for temporary creation
     711
     712            if (m->ulTotalDisksMB)
     713            {
     714                m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1  / 100);    // use 1% of the progress for OVF file upload (we didn't know the size at this point)
     715                ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
     716            }
     717            else
     718            {
     719                // no disks to export:
     720                ulTotalOperationsWeight = 1;
     721                m->ulWeightForXmlOperation = 1;
     722            }
     723            ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the creation of the OVF & the disks */
     724            ulTotalOperationsWeight += ulOVFCreationWeight;
     725            break;
     726        }
     727    }
     728
     729    Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightForXmlOperation = %d\n",
     730         m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
     731
     732    rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
     733                         bstrDescription.raw(),
     734                         TRUE /* aCancelable */,
     735                         cOperations, // ULONG cOperations,
     736                         ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
     737                         bstrDescription.raw(), // CBSTR bstrFirstOperationDescription,
     738                         m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
     739    return rc;
     740}
     741
     742/**
    635743 * Called from the import and export background threads to synchronize the second
    636744 * background disk thread's progress object with the current progress object so
     
    746854}
    747855
    748 /**
    749  * Called from Appliance::importImpl() and Appliance::writeImpl() to set up a
    750  * progress object with the proper weights and maximum progress values.
    751  *
    752  * @param pProgress
    753  * @param bstrDescription
    754  * @param mode
    755  * @return
    756  */
    757 HRESULT Appliance::setUpProgress(const LocationInfo &locInfo,
    758                                  ComObjPtr<Progress> &pProgress,
    759                                  const Bstr &bstrDescription,
    760                                  SetUpProgressMode mode)
    761 {
    762     HRESULT rc;
    763 
    764     /* Create the progress object */
    765     pProgress.createObject();
    766 
    767     // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
    768     disksWeight();
    769 
    770     m->ulWeightForManifestOperation = 0;
    771 
    772     ULONG cOperations;
    773     ULONG ulTotalOperationsWeight;
    774 
    775     cOperations =   1               // one for XML setup
    776                   + m->cDisks;      // plus one per disk
    777     if (m->ulTotalDisksMB)
    778     {
    779         m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100);    // use 1% of the progress for the XML
    780         ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
    781     }
    782     else
    783     {
    784         // no disks to export:
    785         m->ulWeightForXmlOperation = 1;
    786         ulTotalOperationsWeight = 1;
    787     }
    788 
    789     bool fOVA = locInfo.strPath.endsWith(".ova", Utf8Str::CaseInsensitive);
    790     switch (mode)
    791     {
    792         case ImportFileNoManifest:
    793         {
    794             if (fOVA)
    795             {
    796                 // Another operation for packing
    797                 ++cOperations;
    798 
    799                 // assume that packing the files into the archive has the same weight than creating all files in the ovf exporting step
    800                 ulTotalOperationsWeight += m->ulTotalDisksMB;
    801             }
    802             break;
    803         }
    804         case ImportFileWithManifest:
    805         {
    806             ++cOperations;          // another one for creating the manifest
    807 
    808             // assume that creating the manifest will take 10% of the time it takes to export the disks
    809             m->ulWeightForManifestOperation = m->ulTotalDisksMB / 10;
    810             ulTotalOperationsWeight += m->ulWeightForManifestOperation;
    811             if (fOVA)
    812             {
    813                 // Another operation for packing
    814                 ++cOperations;
    815 
    816                 // assume that packing the files into the archive has the same weight than creating all files in the ovf exporting step
    817                 ulTotalOperationsWeight += m->ulTotalDisksMB;
    818             }
    819             break;
    820         }
    821         case WriteFile:
    822         {
    823             // assume that creating the manifest will take .1% of the time it takes to export the disks
    824             if (m->fManifest)
    825             {
    826                 ++cOperations;          // another one for creating the manifest
    827 
    828                 m->ulWeightForManifestOperation = (ULONG)((double)m->ulTotalDisksMB * .1 / 100);    // use .5% of the progress for the manifest
    829                 ulTotalOperationsWeight += m->ulWeightForManifestOperation;
    830             }
    831             break;
    832         }
    833         case ImportS3:
    834         {
    835             cOperations += 1 + 1;     // another one for the manifest file & another one for the import
    836             ulTotalOperationsWeight = m->ulTotalDisksMB;
    837             if (!m->ulTotalDisksMB)
    838                 // no disks to export:
    839                 ulTotalOperationsWeight = 1;
    840 
    841             ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50  / 100);  // use 50% for import
    842             ulTotalOperationsWeight += ulImportWeight;
    843 
    844             m->ulWeightForXmlOperation = ulImportWeight; /* save for using later */
    845 
    846             ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1  / 100);  // use 0.1% for init
    847             ulTotalOperationsWeight += ulInitWeight;
    848             break;
    849         }
    850         case WriteS3:
    851         {
    852             cOperations += 1 + 1;     // another one for the mf & another one for temporary creation
    853 
    854             if (m->ulTotalDisksMB)
    855             {
    856                 m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1  / 100);    // use 1% of the progress for OVF file upload (we didn't know the size at this point)
    857                 ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
    858             }
    859             else
    860             {
    861                 // no disks to export:
    862                 ulTotalOperationsWeight = 1;
    863                 m->ulWeightForXmlOperation = 1;
    864             }
    865             ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the creation of the OVF & the disks */
    866             ulTotalOperationsWeight += ulOVFCreationWeight;
    867             break;
    868         }
    869     }
    870 
    871     Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightForXmlOperation = %d\n",
    872          m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
    873 
    874     rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
    875                          bstrDescription.raw(),
    876                          TRUE /* aCancelable */,
    877                          cOperations, // ULONG cOperations,
    878                          ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
    879                          bstrDescription.raw(), // CBSTR bstrFirstOperationDescription,
    880                          m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
    881     return rc;
    882 }
    883 
    884856void Appliance::parseURI(Utf8Str strUri, LocationInfo &locInfo) const
    885857{
     
    947919}
    948920
    949 Utf8Str Appliance::manifestFileName(const Utf8Str& aPath) const
    950 {
    951     Utf8Str strTmpPath = aPath;
    952     /* Get the name part */
    953     char *pszMfName = RTStrDup(RTPathFilename(strTmpPath.c_str()));
    954     /* Strip any extensions */
    955     RTPathStripExt(pszMfName);
    956     /* Path without the filename */
    957     strTmpPath.stripFilename();
    958     /* Format the manifest path */
    959     Utf8StrFmt strMfFile("%s/%s.mf", strTmpPath.c_str(), pszMfName);
    960     RTStrFree(pszMfName);
    961     return strMfFile;
    962 }
    963 
    964921/**
    965922 *
     
    1005962        case TaskOVF::Read:
    1006963            if (task->locInfo.storageType == VFSType_File)
    1007                 taskrc = pAppliance->readFS(task->locInfo, task->pProgress);
     964                taskrc = pAppliance->readFS(task.get());
    1008965            else if (task->locInfo.storageType == VFSType_S3)
    1009966                taskrc = pAppliance->readS3(task.get());
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