VirtualBox

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


Ignore:
Timestamp:
Apr 6, 2011 1:07:54 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
71014
Message:

Main/src-server/ApplianceImplImport: automatically repair broken OVF images with multiple disks, created by 3.2.8 and earlier

File:
1 edited

Legend:

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

    r36523 r36575  
    66
    77/*
    8  * Copyright (C) 2008-2010 Oracle Corporation
     8 * Copyright (C) 2008-2011 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    25682568    bool fDVD = vsdescThis->findByType(VirtualSystemDescriptionType_CDROM).size() > 0;
    25692569    /* Iterate over all storage controller check the attachments and remove
    2570      * them when necessary. */
     2570     * them when necessary. Also detect broken configs with more than one
     2571     * attachment. Old VirtualBox versions (prior to 3.2.10) had all disk
     2572     * attachments pointing to the last hard disk image, which causes import
     2573     * failures. A long fixed bug, however the OVF files are long lived. */
    25712574    settings::StorageControllersList &llControllers = config.storageMachine.llStorageControllers;
     2575    Guid hdUuid;
     2576    uint32_t cHardDisks = 0;
     2577    bool fInconsistent = false;
     2578    bool fRepairDuplicate = false;
    25722579    settings::StorageControllersList::iterator it3;
    25732580    for (it3 = llControllers.begin();
     
    25872594                   && it4->deviceType == DeviceType_Floppy))
    25882595                llAttachments.erase(it4++);
     2596            else if (it4->deviceType == DeviceType_HardDisk)
     2597            {
     2598                const Guid &thisUuid = it4->uuid;
     2599                cHardDisks++;
     2600                if (cHardDisks == 1)
     2601                {
     2602                    if (hdUuid.isEmpty())
     2603                        hdUuid = thisUuid;
     2604                    else
     2605                        fInconsistent = true;
     2606                }
     2607                else
     2608                {
     2609                    if (thisUuid.isEmpty())
     2610                        fInconsistent = true;
     2611                    else if (thisUuid == hdUuid)
     2612                        fRepairDuplicate = true;
     2613                }
     2614            }
    25892615        }
    25902616    }
    2591 
     2617    /* paranoia... */
     2618    if (fInconsistent || cHardDisks == 1)
     2619        fRepairDuplicate = false;
    25922620
    25932621    /*
     
    25962624     *
    25972625     */
     2626
     2627    /* Get all hard disk descriptions. */
     2628    std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
     2629    std::list<VirtualSystemDescriptionEntry*>::iterator avsdeHDsIt = avsdeHDs.begin();
     2630    /* paranoia - if there is no 1:1 match do not try to repair. */
     2631    if (cHardDisks != avsdeHDs.size())
     2632        fRepairDuplicate = false;
    25982633
    25992634    // for each storage controller...
     
    26172652        }
    26182653
    2619         /* Get all hard disk descriptions. */
    2620         std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
    2621 
    26222654        // for each medium attachment to this controller...
    26232655        for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin();
     
    26312663                continue;
    26322664
     2665            // When repairing a broken VirtualBox xml config section (written
     2666            // by VirtualBox versions earlier than 3.2.10) assume the disks
     2667            // show up in the same order as in the OVF description.
     2668            if (fRepairDuplicate)
     2669            {
     2670                VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt;
     2671                ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
     2672                if (itDiskImage != stack.mapDisks.end())
     2673                {
     2674                    const ovf::DiskImage &di = itDiskImage->second;
     2675                    d.uuid = Guid(di.uuidVbox);
     2676                }
     2677                ++avsdeHDsIt;
     2678            }
     2679
    26332680            // convert the Guid to string
    26342681            Utf8Str strUuid = d.uuid.toString();
    2635 
    26362682
    26372683            // there must be an image in the OVF disk structs with the same UUID
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