VirtualBox

Ignore:
Timestamp:
Dec 3, 2013 12:29:19 PM (11 years ago)
Author:
vboxsync
Message:

pr7074. OVF import: Restoring original UUIDs of imported images in VM configuration settings in case of failure.

File:
1 edited

Legend:

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

    r49742 r49749  
    14881488    void *pvCertBuf = NULL;
    14891489    writeLock.release();
     1490
     1491    /* Create the import stack for the rollback on errors. */
     1492    ImportStack stack(pTask->locInfo, m->pReader->m_mapDisks, pTask->pProgress);
     1493
    14901494    try
    14911495    {
     
    15071511        if (RT_FAILURE(vrc))
    15081512            throw setError(VBOX_E_IPRT_ERROR, "Creation of the VD interface failed (%Rrc)", vrc);
    1509 
    1510         /* Create the import stack for the rollback on errors. */
    1511         ImportStack stack(pTask->locInfo, m->pReader->m_mapDisks, pTask->pProgress);
    15121513
    15131514        if (RTFileExists(strMfFile.c_str()))
     
    15631564    {
    15641565        rc = rc2;
     1566        /*
     1567         * Restoring original UUID from OVF description file.
     1568         * During import VB creates new UUIDs for imported images and
     1569         * assigns them to the images. In case of failure we have to restore
     1570         * the original UUIDs because those new UUIDs are obsolete now and
     1571         * won't be used anymore.
     1572         */
     1573        {
     1574            list< ComObjPtr<VirtualSystemDescription> >::const_iterator itvsd;
     1575            /* Iterate through all virtual systems of that appliance */
     1576            for (itvsd = m->virtualSystemDescriptions.begin();
     1577                 itvsd != m->virtualSystemDescriptions.end();
     1578                 ++itvsd)
     1579            {
     1580                ComObjPtr<VirtualSystemDescription> vsdescThis = (*itvsd);
     1581                settings::MachineConfigFile *pConfig = vsdescThis->m->pConfig;
     1582                if(vsdescThis->m->pConfig!=NULL)
     1583                    stack.restoreOriginalUUIDOfAttachedDevice(pConfig);
     1584            }
     1585        }
    15651586    }
    15661587    writeLock.acquire();
     
    16051626
    16061627    writeLock.release();
     1628
     1629    /* Create the import stack for the rollback on errors. */
     1630    ImportStack stack(pTask->locInfo, m->pReader->m_mapDisks, pTask->pProgress);
     1631
    16071632    try
    16081633    {
     
    16851710        pStorage->fCreateDigest = true;
    16861711
    1687         /* Create the import stack for the rollback on errors. */
    1688         ImportStack stack(pTask->locInfo, m->pReader->m_mapDisks, pTask->pProgress);
    16891712        /*
    16901713         * Try to read the manifest file. First try.
     
    17661789    {
    17671790        rc = rc2;
     1791
     1792        /*
     1793         * Restoring original UUID from OVF description file.
     1794         * During import VB creates new UUIDs for imported images and
     1795         * assigns them to the images. In case of failure we have to restore
     1796         * the original UUIDs because those new UUIDs are obsolete now and
     1797         * won't be used anymore.
     1798         */
     1799        {
     1800            list< ComObjPtr<VirtualSystemDescription> >::const_iterator itvsd;
     1801            /* Iterate through all virtual systems of that appliance */
     1802            for (itvsd = m->virtualSystemDescriptions.begin();
     1803                 itvsd != m->virtualSystemDescriptions.end();
     1804                 ++itvsd)
     1805            {
     1806                ComObjPtr<VirtualSystemDescription> vsdescThis = (*itvsd);
     1807                settings::MachineConfigFile *pConfig = vsdescThis->m->pConfig;
     1808                if(vsdescThis->m->pConfig!=NULL)
     1809                  stack.restoreOriginalUUIDOfAttachedDevice(pConfig);
     1810            }
     1811        }
    17681812    }
    17691813    writeLock.acquire();
     
    37193763                vsdeTargetHD->strVboxCurrent = savedVboxCurrent;
    37203764
    3721                 d.uuid = hdId;
     3765                /*
     3766                 * 1. saving original UUID for restoring in case of failure.
     3767                 * 2. replacement of original UUID by new UUID in the current VM config (settings::MachineConfigFile).
     3768                 */
     3769                {
     3770                    rc = stack.saveOriginalUUIDOfAttachedDevice(d, Utf8Str(hdId));
     3771                    d.uuid = hdId;
     3772                }
     3773
    37223774                fFound = true;
    37233775                break;
     
    38943946}
    38953947
     3948HRESULT Appliance::ImportStack::saveOriginalUUIDOfAttachedDevice(settings::AttachedDevice &device,
     3949                                                     const Utf8Str &newlyUuid)
     3950{
     3951    HRESULT rc = S_OK;
     3952
     3953    /* save for restoring */
     3954    mapNewUUIDsToOriginalUUIDs.insert(std::make_pair(newlyUuid, device.uuid.toString()));
     3955
     3956    return rc;
     3957}
     3958
     3959HRESULT Appliance::ImportStack::restoreOriginalUUIDOfAttachedDevice(settings::MachineConfigFile *config)
     3960{
     3961    HRESULT rc = S_OK;
     3962
     3963    settings::StorageControllersList &llControllers = config->storageMachine.llStorageControllers;
     3964    settings::StorageControllersList::iterator itscl;
     3965    for (itscl = llControllers.begin();
     3966         itscl != llControllers.end();
     3967         ++itscl)
     3968    {
     3969        settings::AttachedDevicesList &llAttachments = itscl->llAttachedDevices;
     3970        settings::AttachedDevicesList::iterator itadl = llAttachments.begin();
     3971        while (itadl != llAttachments.end())
     3972        {
     3973            std::map<Utf8Str , Utf8Str>::const_iterator cit =
     3974                mapNewUUIDsToOriginalUUIDs.find(itadl->uuid.toString());
     3975            if(cit!=mapNewUUIDsToOriginalUUIDs.end())
     3976            {
     3977                Utf8Str uuidOriginal = cit->second;
     3978                itadl->uuid = Guid(uuidOriginal);
     3979                mapNewUUIDsToOriginalUUIDs.erase(cit);
     3980            }
     3981            ++itadl;
     3982        }
     3983    }
     3984
     3985    return rc;
     3986}
     3987
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