VirtualBox

Changeset 28152 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Apr 9, 2010 5:38:56 PM (15 years ago)
Author:
vboxsync
Message:

Main/OVF: optimizations, cleanup

File:
1 edited

Legend:

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

    r28110 r28152  
    12251225    if (vsdeOS.size() < 1)
    12261226        throw setError(VBOX_E_FILE_ERROR,
    1227                         tr("Missing guest OS type"));
     1227                       tr("Missing guest OS type"));
    12281228    const Utf8Str &strOsTypeVBox = vsdeOS.front()->strVbox;
    12291229
     
    12381238    if (vsdeName.size() < 1)
    12391239        throw setError(VBOX_E_FILE_ERROR,
    1240                         tr("Missing VM name"));
     1240                       tr("Missing VM name"));
    12411241    const Utf8Str &strNameVBox = vsdeName.front()->strVbox;
    12421242    rc = mVirtualBox->CreateMachine(Bstr(strNameVBox),
     
    12921292    if (FAILED(rc)) throw rc;
    12931293
    1294     /* I/O APIC: so far we have no setting for this. Enable it if we
    1295         import a Windows VM because if if Windows was installed without IOAPIC,
    1296         it will not mind finding an one later on, but if Windows was installed
    1297         _with_ an IOAPIC, it will bluescreen if it's not found */
    1298     Bstr bstrFamilyId;
    1299     rc = osType->COMGETTER(FamilyId)(bstrFamilyId.asOutParam());
    1300     if (FAILED(rc)) throw rc;
    1301 
    1302     Utf8Str strFamilyId(bstrFamilyId);
    1303     if (strFamilyId == "Windows")
    1304         fEnableIOApic = true;
    1305 
    1306     /* If IP-APIC should be enabled could be have different reasons.
    1307         See CPU count & the Win test above. Here we enable it if it was
    1308         previously requested. */
     1294    // I/O APIC: Generic OVF has no setting for this. Enable it if we
     1295    // import a Windows VM because if if Windows was installed without IOAPIC,
     1296    // it will not mind finding an one later on, but if Windows was installed
     1297    // _with_ an IOAPIC, it will bluescreen if it's not found
     1298    if (!fEnableIOApic)
     1299    {
     1300        Bstr bstrFamilyId;
     1301        rc = osType->COMGETTER(FamilyId)(bstrFamilyId.asOutParam());
     1302        if (FAILED(rc)) throw rc;
     1303        if (bstrFamilyId == "Windows")
     1304            fEnableIOApic = true;
     1305    }
     1306
    13091307    if (fEnableIOApic)
    13101308    {
     
    13611359        if (FAILED(rc)) throw rc;
    13621360    }
     1361    else if (vsdeNW.size() > SchemaDefs::NetworkAdapterCount)
     1362        throw setError(VBOX_E_FILE_ERROR,
     1363                       tr("Too many network adapters: OVF requests %d network adapters, but VirtualBox only supports %d"),
     1364                       vsdeNW.size(), SchemaDefs::NetworkAdapterCount);
    13631365    else
    13641366    {
    13651367        list<VirtualSystemDescriptionEntry*>::const_iterator nwIt;
    1366         /* Iterate through all network cards. We support 8 network adapters
    1367             * at the maximum. (@todo: warn if there are more!) */
    13681368        size_t a = 0;
    13691369        for (nwIt = vsdeNW.begin();
    1370              (nwIt != vsdeNW.end() && a < SchemaDefs::NetworkAdapterCount);
     1370             nwIt != vsdeNW.end();
    13711371             ++nwIt, ++a)
    13721372        {
     
    13961396                rc = host->COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(nwInterfaces));
    13971397                if (FAILED(rc)) throw rc;
    1398                 /* We search for the first host network interface which
    1399                     * is usable for bridged networking */
     1398                // We search for the first host network interface which
     1399                // is usable for bridged networking
    14001400                for (size_t j = 0;
    1401                         j < nwInterfaces.size();
    1402                         ++j)
     1401                     j < nwInterfaces.size();
     1402                     ++j)
    14031403                {
    14041404                    HostNetworkInterfaceType_T itype;
     
    14291429                rc = host->COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(nwInterfaces));
    14301430                if (FAILED(rc)) throw rc;
    1431                 /* We search for the first host network interface which
    1432                     * is usable for host only networking */
     1431                // We search for the first host network interface which
     1432                // is usable for host only networking
    14331433                for (size_t j = 0;
    1434                         j < nwInterfaces.size();
    1435                         ++j)
     1434                     j < nwInterfaces.size();
     1435                     ++j)
    14361436                {
    14371437                    HostNetworkInterfaceType_T itype;
     
    14571457    if (vsdeHDCIDE.size() > 1)
    14581458        throw setError(VBOX_E_FILE_ERROR,
    1459                         tr("Too many IDE controllers in OVF; import facility only supports one"));
     1459                       tr("Too many IDE controllers in OVF; import facility only supports one"));
    14601460    if (vsdeHDCIDE.size() == 1)
    14611461    {
     
    14821482    if (vsdeHDCSATA.size() > 1)
    14831483        throw setError(VBOX_E_FILE_ERROR,
    1484                         tr("Too many SATA controllers in OVF; import facility only supports one"));
     1484                       tr("Too many SATA controllers in OVF; import facility only supports one"));
    14851485    if (vsdeHDCSATA.size() > 0)
    14861486    {
     
    14941494        else
    14951495            throw setError(VBOX_E_FILE_ERROR,
    1496                             tr("Invalid SATA controller type \"%s\""),
    1497                             hdcVBox.c_str());
     1496                           tr("Invalid SATA controller type \"%s\""),
     1497                           hdcVBox.c_str());
    14981498    }
    14991499#endif /* VBOX_WITH_AHCI */
     
    15041504    if (vsdeHDCSCSI.size() > 1)
    15051505        throw setError(VBOX_E_FILE_ERROR,
    1506                         tr("Too many SCSI controllers in OVF; import facility only supports one"));
     1506                       tr("Too many SCSI controllers in OVF; import facility only supports one"));
    15071507    if (vsdeHDCSCSI.size() > 0)
    15081508    {
     
    15161516        else
    15171517            throw setError(VBOX_E_FILE_ERROR,
    1518                             tr("Invalid SCSI controller type \"%s\""),
    1519                             hdcVBox.c_str());
     1518                           tr("Invalid SCSI controller type \"%s\""),
     1519                           hdcVBox.c_str());
    15201520
    15211521        rc = pNewMachine->AddStorageController(Bstr("SCSI Controller"), StorageBus_SCSI, pController.asOutParam());
     
    15401540    if (vsdeFloppy.size() > 1)
    15411541        throw setError(VBOX_E_FILE_ERROR,
    1542                         tr("Too many floppy controllers in OVF; import facility only supports one"));
     1542                       tr("Too many floppy controllers in OVF; import facility only supports one"));
    15431543    std::list<VirtualSystemDescriptionEntry*> vsdeCDROM = vsdescThis->findByType(VirtualSystemDescriptionType_CDROM);
    15441544    if (    (vsdeFloppy.size() > 0)
    1545             || (vsdeCDROM.size() > 0)
    1546         )
     1545         || (vsdeCDROM.size() > 0)
     1546       )
    15471547    {
    15481548        // If there's an error here we need to close the session, so
     
    15521552        {
    15531553            /* In order to attach things we need to open a session
    1554                 * for the new machine */
     1554             * for the new machine */
    15551555            rc = mVirtualBox->OpenSession(stack.pSession, bstrNewMachineId);
    15561556            if (FAILED(rc)) throw rc;
     
    15921592            }
    15931593
    1594 
    15951594            // CD-ROMs next
    15961595            for (std::list<VirtualSystemDescriptionEntry*>::const_iterator jt = vsdeCDROM.begin();
    1597                     jt != vsdeCDROM.end();
    1598                     ++jt)
     1596                 jt != vsdeCDROM.end();
     1597                 ++jt)
    15991598            {
    16001599                // for now always attach to secondary master on IDE controller;
     
    16951694                    /* This isn't allowed */
    16961695                    throw setError(VBOX_E_FILE_ERROR,
    1697                                     tr("Destination file '%s' exists",
    1698                                         vsdeHD->strVbox.c_str()));
     1696                                   tr("Destination file '%s' exists"),
     1697                                   vsdeHD->strVbox.c_str());
    16991698
    17001699                /* Find the disk from the OVF's disk list */
    17011700                ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
    1702                 /* vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
    1703                    in the virtual system's disks map under that ID and also in the global images map. */
     1701                // vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
     1702                // in the virtual system's disks map under that ID and also in the global images map
    17041703                ovf::VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef);
    17051704
     
    17081707                   )
    17091708                    throw setError(E_FAIL,
    1710                                     tr("Internal inconsistency looking up disk images."));
     1709                                   tr("Internal inconsistency looking up disk images."));
    17111710
    17121711                const ovf::DiskImage &di = itDiskImage->second;
     
    17531752                                            strSrcFilePath.c_str());
    17541753
    1755                     /* Clone the disk image (this is necessary cause the id has
    1756                         * to be recreated for the case the same hard disk is
    1757                         * attached already from a previous import) */
    1758 
    1759                     /* First open the existing disk image */
     1754                    // Clone the disk image (this is necessary cause the id has
     1755                    // to be recreated for the case the same hard disk is
     1756                    // attached already from a previous import)
     1757
     1758                    // First open the existing disk image
    17601759                    rc = mVirtualBox->OpenHardDisk(Bstr(strSrcFilePath),
    17611760                                                    AccessMode_ReadOnly,
     
    18791878    HRESULT rc = pNewMachine.createObject();
    18801879    if (FAILED(rc)) throw rc;
    1881     rc = pNewMachine->init(mVirtualBox, strNameVBox, config);
     1880
     1881    // this magic constructor fills the new machine object with the MachineConfig
     1882    // instance that we created from the vbox:Machine
     1883    rc = pNewMachine->init(mVirtualBox,
     1884                           strNameVBox,         // name from just above (can be suffixed to avoid duplicates)
     1885                           config);             // the whole machine config
    18821886    if (FAILED(rc)) throw rc;
    18831887
     1888    // return the new machine as an IMachine
    18841889    IMachine *p;
    18851890    rc = pNewMachine.queryInterfaceTo(&p);
    18861891    if (FAILED(rc)) throw rc;
    1887 
    18881892    pReturnNewMachine = p;
    18891893
     1894    // and register it
    18901895    rc = mVirtualBox->RegisterMachine(pNewMachine);
    18911896    if (FAILED(rc)) throw rc;
Note: See TracChangeset for help on using the changeset viewer.

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