VirtualBox

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


Ignore:
Timestamp:
Jul 13, 2018 6:10:44 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123720
Message:

Main/Appliance: fix a regression caused by introducing the custom VM folder feature (which only happened because there was seriously misplaced code), and additionally move code for importing images to the right place, eliminating a lot of unreadable code duplication.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r72902 r73132  
    124124    bool i_isApplianceIdle();
    125125    HRESULT i_searchUniqueVMName(Utf8Str& aName) const;
    126     HRESULT i_searchUniqueDiskImageFilePath(const Utf8Str &aMachineFolder, Utf8Str &aName) const;
     126    HRESULT i_searchUniqueImageFilePath(const Utf8Str &aMachineFolder,
     127                                        DeviceType_T aDeviceType,
     128                                        Utf8Str &aName) const;
    127129    HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress,
    128130                            const Utf8Str &strDescription,
  • trunk/src/VBox/Main/src-server/ApplianceImpl.cpp

    r72973 r73132  
    896896    char *tmpName = RTStrDup(aName.c_str());
    897897    int i = 1;
    898     /** @todo Maybe too cost-intensive; try to find a lighter way */
    899898    while (mVirtualBox->FindMachine(Bstr(tmpName).raw(), &machine) != VBOX_E_OBJECT_NOT_FOUND)
    900899    {
     
    909908}
    910909
    911 HRESULT Appliance::i_searchUniqueDiskImageFilePath(const Utf8Str &aMachineFolder, Utf8Str &aName) const
    912 {
    913     IMedium *harddisk = NULL;
     910HRESULT Appliance::i_searchUniqueImageFilePath(const Utf8Str &aMachineFolder, DeviceType_T aDeviceType, Utf8Str &aName) const
     911{
     912    IMedium *pMedium = NULL;
    914913    char *tmpName = RTStrDup(aName.c_str());
    915914    char *tmpAbsName = RTPathAbsExDup(aMachineFolder.c_str(), tmpName);
    916915    int i = 1;
    917     /* Check if the file exists or if a file with this path is registered
    918      * already */
    919     /** @todo Maybe too cost-intensive; try to find a lighter way */
     916    /* Check if the file exists or if a medium with this path is registered already */
    920917    while (    RTPathExists(tmpAbsName)
    921             || mVirtualBox->OpenMedium(Bstr(tmpAbsName).raw(), DeviceType_HardDisk, AccessMode_ReadWrite,
    922                                        FALSE /* fForceNewUuid */,  &harddisk) != VBOX_E_OBJECT_NOT_FOUND)
     918            || mVirtualBox->OpenMedium(Bstr(tmpAbsName).raw(), aDeviceType, AccessMode_ReadWrite,
     919                                       FALSE /* fForceNewUuid */,  &pMedium) != VBOX_E_OBJECT_NOT_FOUND)
    923920    {
    924921        RTStrFree(tmpAbsName);
     
    928925        RTPathStripSuffix(tmpFile);
    929926        const char *pszTmpSuff = RTPathSuffix(aName.c_str());
    930         RTStrAPrintf(&tmpName, "%s%c%s_%d%s", tmpDir, RTPATH_DELIMITER, tmpFile, i, pszTmpSuff);
     927        if (!strcmp(tmpDir, "."))
     928            RTStrAPrintf(&tmpName, "%s_%d%s", tmpFile, i, pszTmpSuff);
     929        else
     930            RTStrAPrintf(&tmpName, "%s%c%s_%d%s", tmpDir, RTPATH_DELIMITER, tmpFile, i, pszTmpSuff);
    931931        tmpAbsName = RTPathAbsExDup(aMachineFolder.c_str(), tmpName);
    932932        RTStrFree(tmpFile);
     
    11571157    {
    11581158        ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
    1159         /* One for every hard disk of the Virtual System */
     1159        /* One for every medium of the Virtual System */
    11601160        std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
    11611161        std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
     
    15501550 * Internal method; adds a new description item to the member list.
    15511551 * @param aType Type of description for the new item.
    1552  * @param strRef Reference item; only used with hard disk controllers.
     1552 * @param strRef Reference item; only used with storage controllers.
    15531553 * @param aOvfValue Corresponding original value from OVF.
    15541554 * @param aVBoxValue Initial configuration value (can be overridden by caller with setFinalValues).
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r73003 r73132  
    134134
    135135    // Change the appliance state so we can safely leave the lock while doing time-consuming
    136     // disk imports; also the below method calls do all kinds of locking which conflicts with
     136    // medium imports; also the below method calls do all kinds of locking which conflicts with
    137137    // the appliance object lock
    138138    m->state = Data::ApplianceImporting;
     
    549549                pNewDesc->i_addEntry(VirtualSystemDescriptionType_CDROM, "", "", "");
    550550
    551             /* Hard disk Controller */
     551            /* Storage Controller */
    552552            uint16_t cIDEused = 0;
    553553            uint16_t cSATAused = 0; NOREF(cSATAused);
    554554            uint16_t cSCSIused = 0; NOREF(cSCSIused);
    555555            ovf::ControllersMap::const_iterator hdcIt;
    556             /* Iterate through all hard disk controllers */
     556            /* Iterate through all storage controllers */
    557557            for (hdcIt = vsysThis.mapControllers.begin();
    558558                 hdcIt != vsysThis.mapControllers.end();
     
    644644            }
    645645
    646             /* Hard disks */
     646            /* Storage devices (hard disks/DVDs/...) */
    647647            if (vsysThis.mapVirtualDisks.size() > 0)
    648648            {
    649649                ovf::VirtualDisksMap::const_iterator itVD;
    650                 /* Iterate through all hard disks ()*/
     650                /* Iterate through all storage devices */
    651651                for (itVD = vsysThis.mapVirtualDisks.begin();
    652652                     itVD != vsysThis.mapVirtualDisks.end();
     
    654654                {
    655655                    const ovf::VirtualDisk &hd = itVD->second;
    656                     /* Get the associated disk image */
     656                    /* Get the associated image */
    657657                    ovf::DiskImage di;
    658658                    std::map<RTCString, ovf::DiskImage>::iterator foundDisk;
     
    667667
    668668                    /*
    669                      * Figure out from URI which format the image of disk has.
    670                      * URI must have inside section <Disk>                   .
    671                      * But there aren't strong requirements about correspondence one URI for one disk virtual format.
    672                      * So possibly, we aren't able to recognize some URIs.
     669                     * Figure out from URI which format the image has.
     670                     * There is no strict mapping of image URI to image format.
     671                     * It's possible we aren't able to recognize some URIs.
    673672                     */
    674673
     
    690689
    691690                    Utf8Str strFilename = di.strHref;
     691                    DeviceType_T devType = DeviceType_Null;
    692692                    if (vdf.compare("VMDK", Utf8Str::CaseInsensitive) == 0)
    693693                    {
     
    695695                        if (!strFilename.length())
    696696                            strFilename = Utf8StrFmt("%s.vmdk", hd.strDiskId.c_str());
     697                        devType = DeviceType_HardDisk;
    697698                    }
    698699                    else if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0)
     
    701702                        if (!strFilename.length())
    702703                            strFilename = Utf8StrFmt("%s.iso", hd.strDiskId.c_str());
     704                        devType = DeviceType_DVD;
    703705                    }
    704706                    else
     
    714716                        strFilename.stripSuffix();
    715717
    716                     i_searchUniqueDiskImageFilePath(strMachineFolder, strFilename);
    717 
    718                     /* find the description for the hard disk controller
     718                    i_searchUniqueImageFilePath(strMachineFolder, devType, strFilename);
     719
     720                    /* find the description for the storage controller
    719721                     * that has the same ID as hd.idController */
    720722                    const VirtualSystemDescriptionEntry *pController;
    721723                    if (!(pController = pNewDesc->i_findControllerFromID(hd.idController)))
    722724                        throw setError(E_FAIL,
    723                                        tr("Cannot find hard disk controller with OVF instance ID %RI32 "
    724                                           "to which disk \"%s\" should be attached"),
     725                                       tr("Cannot find storage controller with OVF instance ID %RI32 "
     726                                          "to which medium \"%s\" should be attached"),
    725727                                       hd.idController,
    726728                                       di.strHref.c_str());
     
    20322034
    20332035    /* Change the appliance state so we can safely leave the lock while doing
    2034      * time-consuming disk imports; also the below method calls do all kinds of
     2036     * time-consuming image imports; also the below method calls do all kinds of
    20352037     * locking which conflicts with the appliance object lock. */
    20362038    AutoWriteLock writeLock(this COMMA_LOCKVAL_SRC_POS);
     
    20532055    {
    20542056        /* With _whatever_ error we've had, do a complete roll-back of
    2055          * machines and disks we've created */
     2057         * machines and images we've created */
    20562058        writeLock.release();
    20572059        ErrorInfoKeeper eik;
     
    22742276 * @param hdc in: the HardDiskController structure to attach to.
    22752277 * @param ulAddressOnParent in: the AddressOnParent parameter from OVF.
    2276  * @param controllerName out: the name of the hard disk controller to attach to (e.g. "IDE").
     2278 * @param controllerName out: the name of the storage controller to attach to (e.g. "IDE").
    22772279 * @param lControllerPort out: the channel (controller port) of the controller to attach to.
    22782280 * @param lDevice out: the device number to attach to.
     
    23722374
    23732375/**
    2374  * Imports one disk image.
     2376 * Imports one image.
    23752377 *
    23762378 * This is common code shared between
     
    23832385 * the caller needs to pass in the ovf::DiskImage structure from ovfreader.cpp.
    23842386 *
    2385  * As a result, in both cases, if di.strHref is empty, we create a new disk as per the OVF
     2387 * As a result, in both cases, if di.strHref is empty, we create a new image as per the OVF
    23862388 * spec, even though this cannot really happen in the vbox:Machine case since such data
    23872389 * would never have been exported.
    23882390 *
    2389  * This advances stack.pProgress by one operation with the disk's weight.
    2390  *
    2391  * @param di ovfreader.cpp structure describing the disk image from the OVF that is to be imported
     2391 * This advances stack.pProgress by one operation with the image's weight.
     2392 *
     2393 * @param di ovfreader.cpp structure describing the image from the OVF that is to be imported
    23922394 * @param strDstPath Where to create the target image.
    2393  * @param pTargetHD out: The newly created target disk. This also gets pushed on stack.llHardDisksCreated for cleanup.
     2395 * @param pTargetMedium out: The newly created target medium. This also gets pushed on stack.llHardDisksCreated for cleanup.
    23942396 * @param stack
    23952397 */
    23962398void Appliance::i_importOneDiskImage(const ovf::DiskImage &di,
    23972399                                     const Utf8Str &strDstPath,
    2398                                      ComObjPtr<Medium> &pTargetHD,
     2400                                     ComObjPtr<Medium> &pTargetMedium,
    23992401                                     ImportStack &stack)
    24002402{
     
    24322434
    24332435    /* First of all check if the original (non-absolute) destination path is
    2434      * a valid hard disk UUID. If so, the user wants to import the disk into
     2436     * a valid medium UUID. If so, the user wants to import the image into
    24352437     * an existing path. This is useful for iSCSI for example. */
     2438    /** @todo r=klaus the code structure after this point is totally wrong,
     2439     * full of unnecessary code duplication and other issues. 4.2 still had
     2440     * the right structure for importing into existing medium objects, which
     2441     * the current code can't possibly handle. */
    24362442    RTUUID uuid;
    24372443    int vrc = RTUuidFromStr(&uuid, strDstPath.c_str());
    24382444    if (vrc == VINF_SUCCESS)
    24392445    {
    2440         rc = mVirtualBox->i_findHardDiskById(Guid(uuid), true, &pTargetHD);
     2446        rc = mVirtualBox->i_findHardDiskById(Guid(uuid), true, &pTargetMedium);
    24412447        if (FAILED(rc)) throw rc;
    24422448    }
     
    24462452
    24472453        /* check read file to GZIP compression */
    2448         bool const fGzipped = di.strCompression.compare("gzip",Utf8Str::CaseInsensitive) == 0;
     2454        bool const fGzipped = di.strCompression.compare("gzip", Utf8Str::CaseInsensitive) == 0;
    24492455        Utf8Str strDeleteTemp;
    24502456        try
     
    25142520            }
    25152521
    2516             /* Create an IMedium object. */
    2517             pTargetHD.createObject();
    2518 
    25192522            /*CD/DVD case*/
    25202523            if (strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) == 0)
     
    25262529                    else
    25272530                        i_importCopyFile(stack, strSrcFilePath, strAbsDstPath, strSourceOVF.c_str());
     2531
     2532                    ComPtr<IMedium> pTmp;
     2533                    rc = mVirtualBox->OpenMedium(Bstr(strAbsDstPath).raw(),
     2534                                                 DeviceType_DVD,
     2535                                                 AccessMode_ReadWrite,
     2536                                                 false,
     2537                                                 pTmp.asOutParam());
     2538                    if (FAILED(rc))
     2539                        throw rc;
     2540
     2541                    IMedium *iM = pTmp;
     2542                    pTargetMedium = static_cast<Medium*>(iM);
    25282543                }
    25292544                catch (HRESULT /*arc*/)
     
    25402555            else/* HDD case*/
    25412556            {
    2542                 rc = pTargetHD->init(mVirtualBox,
    2543                                      strTrgFormat,
    2544                                      strAbsDstPath,
    2545                                      Guid::Empty /* media registry: none yet */,
    2546                                      DeviceType_HardDisk);
    2547                 if (FAILED(rc)) throw rc;
    2548 
    2549                 /* Now create an empty hard disk. */
    2550                 rc = mVirtualBox->CreateMedium(Bstr(strTrgFormat).raw(),
    2551                                                Bstr(strAbsDstPath).raw(),
    2552                                                AccessMode_ReadWrite, DeviceType_HardDisk,
    2553                                                ComPtr<IMedium>(pTargetHD).asOutParam());
     2557                /* Create an IMedium object. */
     2558                pTargetMedium.createObject();
     2559
     2560                rc = pTargetMedium->init(mVirtualBox,
     2561                                         strTrgFormat,
     2562                                         strAbsDstPath,
     2563                                         Guid::Empty /* media registry: none yet */,
     2564                                         DeviceType_HardDisk);
    25542565                if (FAILED(rc)) throw rc;
    25552566
     
    25602571                    mediumVariant.push_back(MediumVariant_Standard);
    25612572
    2562                     /* Kick of the creation of a dynamic growing disk image with the given capacity. */
    2563                     rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M,
     2573                    /* Kick off the creation of a dynamic growing disk image with the given capacity. */
     2574                    rc = pTargetMedium->CreateBaseStorage(di.iCapacity / _1M,
    25642575                                                      ComSafeArrayAsInParam(mediumVariant),
    25652576                                                      ComPtr<IProgress>(pProgress).asOutParam());
     
    26222633                    /* Start the source image cloning operation. */
    26232634                    ComObjPtr<Medium> nullParent;
    2624                     rc = pTargetHD->i_importFile(strSrcFilePath.c_str(),
    2625                                                  srcFormat,
    2626                                                  MediumVariant_Standard,
    2627                                                  hVfsIosReadAhead,
    2628                                                  nullParent,
    2629                                                  pProgress);
     2635                    rc = pTargetMedium->i_importFile(strSrcFilePath.c_str(),
     2636                                                     srcFormat,
     2637                                                     MediumVariant_Standard,
     2638                                                     hVfsIosReadAhead,
     2639                                                     nullParent,
     2640                                                     pProgress);
    26302641                    RTVfsIoStrmRelease(hVfsIosReadAhead);
    26312642                    hVfsIosSrc = NIL_RTVFSIOSTREAM;
     
    26402651                }
    26412652
    2642                 /* Now wait for the background disk operation to complete; this throws
     2653                /* Now wait for the background import operation to complete; this throws
    26432654                 * HRESULTs on error. */
    26442655                ComPtr<IProgress> pp(pProgress);
     
    29302941    }
    29312942
    2932     // IDE Hard disk controller
     2943    // Storage controller IDE
    29332944    std::list<VirtualSystemDescriptionEntry*> vsdeHDCIDE =
    29342945        vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskControllerIDE);
     
    29632974    }
    29642975
    2965     /* Hard disk controller SATA */
     2976    /* Storage controller SATA */
    29662977    std::list<VirtualSystemDescriptionEntry*> vsdeHDCSATA =
    29672978        vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskControllerSATA);
     
    29862997    }
    29872998
    2988     /* Hard disk controller SCSI */
     2999    /* Storage controller SCSI */
    29893000    std::list<VirtualSystemDescriptionEntry*> vsdeHDCSCSI =
    29903001        vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskControllerSCSI);
     
    30213032    }
    30223033
    3023     /* Hard disk controller SAS */
     3034    /* Storage controller SAS */
    30243035    std::list<VirtualSystemDescriptionEntry*> vsdeHDCSAS =
    30253036        vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskControllerSAS);
     
    30383049    }
    30393050
    3040     /* Now its time to register the machine before we add any hard disks */
     3051    /* Now its time to register the machine before we add any storage devices */
    30413052    rc = mVirtualBox->RegisterMachine(pNewMachine);
    30423053    if (FAILED(rc)) throw rc;
     
    31083119            if (FAILED(rc)) throw rc;
    31093120
    3110             // only now that we're done with all disks, close the session
     3121            // only now that we're done with all storage devices, close the session
    31113122            rc = stack.pSession->UnlockMachine();
    31123123            if (FAILED(rc)) throw rc;
     
    31273138    }
    31283139
    3129     // create the hard disks & connect them to the appropriate controllers
     3140    // create the storage devices & connect them to the appropriate controllers
    31303141    std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
    31313142    if (!avsdeHDs.empty())
     
    31733184
    31743185                Log(("diCurrent.strDiskId=%s diCurrent.strHref=%s\n", diCurrent.strDiskId.c_str(), diCurrent.strHref.c_str()));
    3175                 /* Iterate over all given disk images of the virtual system
    3176                  * disks description. We need to find the target disk path,
     3186                /* Iterate over all given images of the virtual system
     3187                 * description. We need to find the target image path,
    31773188                 * which could be changed by the user. */
    31783189                VirtualSystemDescriptionEntry *vsdeTargetHD = NULL;
     
    31903201                if (!vsdeTargetHD)
    31913202                {
    3192                     /* possible case if a disk image belongs to other virtual system (OVF package with multiple VMs inside) */
     3203                    /* possible case if an image belongs to other virtual system (OVF package with multiple VMs inside) */
    31933204                    Log1Warning(("OVA/OVF import: Disk image %s was missed during import of VM %s\n",
    31943205                                 oit->first.c_str(), vmNameEntry->strOvf.c_str()));
     
    31983209                }
    31993210
    3200                 //diCurrent.strDiskId contains the disk identifier (e.g. "vmdisk1"), which should exist
    3201                 //in the virtual system's disks map under that ID and also in the global images map
     3211                //diCurrent.strDiskId contains the image identifier (e.g. "vmdisk1"), which should exist
     3212                //in the virtual system's images map under that ID and also in the global images map
    32023213                ovf::VirtualDisksMap::const_iterator itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId);
    32033214                if (itVDisk == vsysThis.mapVirtualDisks.end())
     
    32163227                    if (h != disksResolvedNames.end())
    32173228                    {
    3218                         /* Yes, disk name was found, we can skip it*/
     3229                        /* Yes, image name was found, we can skip it*/
    32193230                        ++oit;
    32203231                        continue;
     
    32273238                        if (RTStrICmp(diCurrent.strHref.c_str(), stack.pszOvaLookAheadName) != 0)
    32283239                        {
    3229                             /* availableImage contains the disk file reference (e.g. "disk1.vmdk"), which should
     3240                            /* availableImage contains the image file reference (e.g. "disk1.vmdk"), which should
    32303241                             * exist in the global images map.
    3231                              * And find the disk from the OVF's disk list */
     3242                             * And find the image from the OVF's disk list */
    32323243                            ovf::DiskImagesMap::const_iterator itDiskImage;
    32333244                            for (itDiskImage = stack.mapDisks.begin();
     
    32443255                            }
    32453256
    3246                             /* replace with a new found disk image */
     3257                            /* replace with a new found image */
    32473258                            diCurrent = *(&itDiskImage->second);
    32483259
    32493260                            /*
    3250                              * Again iterate over all given disk images of the virtual system
    3251                              * disks description using the found disk image
     3261                             * Again iterate over all given images of the virtual system
     3262                             * description using the found image
    32523263                             */
    32533264                            for (list<VirtualSystemDescriptionEntry*>::const_iterator itHD = avsdeHDs.begin();
     
    32953306                }
    32963307
    3297                 /* very important to store disk name for the next checks */
     3308                /* very important to store image name for the next checks */
    32983309                disksResolvedNames.insert(diCurrent.strHref);
    32993310////// end of duplicated code.
    33003311                const ovf::VirtualDisk &ovfVdisk = itVDisk->second;
    33013312
    3302                 ComObjPtr<Medium> pTargetHD;
    3303 
    3304                 Utf8Str savedVBoxCurrent = vsdeTargetHD->strVBoxCurrent;
    3305 
     3313                ComObjPtr<Medium> pTargetMedium;
    33063314                i_importOneDiskImage(diCurrent,
    33073315                                     vsdeTargetHD->strVBoxCurrent,
    3308                                      pTargetHD,
     3316                                     pTargetMedium,
    33093317                                     stack);
    33103318
    3311                 // now use the new uuid to attach the disk image to our new machine
     3319                // now use the new uuid to attach the medium to our new machine
    33123320                ComPtr<IMachine> sMachine;
    33133321                rc = stack.pSession->COMGETTER(Machine)(sMachine.asOutParam());
     
    33313339                     vsdeTargetHD->strVBoxCurrent.c_str(), mhda.lControllerPort, mhda.lDevice));
    33323340
    3333                 ComObjPtr<MediumFormat> mediumFormat;
    3334                 rc = i_findMediumFormatFromDiskImage(diCurrent, mediumFormat);
     3341                DeviceType_T devType = DeviceType_Null;
     3342                rc = pTargetMedium->COMGETTER(DeviceType)(&devType);
    33353343                if (FAILED(rc))
    33363344                    throw rc;
    33373345
    3338                 Bstr bstrFormatName;
    3339                 rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
     3346                rc = sMachine->AttachDevice(Bstr(mhda.controllerName).raw(),// name
     3347                                            mhda.lControllerPort,     // long controllerPort
     3348                                            mhda.lDevice,             // long device
     3349                                            devType,                  // DeviceType_T type
     3350                                            pTargetMedium);
    33403351                if (FAILED(rc))
    33413352                    throw rc;
    3342 
    3343                 Utf8Str vdf = Utf8Str(bstrFormatName);
    3344 
    3345                 if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0)
    3346                 {
    3347                     ComPtr<IMedium> dvdImage(pTargetHD);
    3348 
    3349                     rc = mVirtualBox->OpenMedium(Bstr(vsdeTargetHD->strVBoxCurrent).raw(),
    3350                                                  DeviceType_DVD,
    3351                                                  AccessMode_ReadWrite,
    3352                                                  false,
    3353                                                  dvdImage.asOutParam());
    3354 
    3355                     if (FAILED(rc))
    3356                         throw rc;
    3357 
    3358                     rc = sMachine->AttachDevice(Bstr(mhda.controllerName).raw(),// name
    3359                                                 mhda.lControllerPort,     // long controllerPort
    3360                                                 mhda.lDevice,             // long device
    3361                                                 DeviceType_DVD,           // DeviceType_T type
    3362                                                 dvdImage);
    3363                     if (FAILED(rc))
    3364                         throw rc;
    3365                 }
    3366                 else
    3367                 {
    3368                     rc = sMachine->AttachDevice(Bstr(mhda.controllerName).raw(),// name
    3369                                                 mhda.lControllerPort,     // long controllerPort
    3370                                                 mhda.lDevice,             // long device
    3371                                                 DeviceType_HardDisk,      // DeviceType_T type
    3372                                                 pTargetHD);
    3373 
    3374                     if (FAILED(rc))
    3375                         throw rc;
    3376                 }
    33773353
    33783354                stack.llHardDiskAttachments.push_back(mhda);
     
    33813357                if (FAILED(rc))
    33823358                    throw rc;
    3383 
    3384                 /* restore */
    3385                 vsdeTargetHD->strVBoxCurrent = savedVBoxCurrent;
    33863359
    33873360                ++cImportedDisks;
     
    38173790            settings::StorageController &sc = *sit;
    38183791
    3819             // find the OVF virtual system description entry for this storage controller
    3820 /** @todo
    3821  * r=bird: What on earh this is switch supposed to do?  (I've added the default:break;, so don't
    3822  * get confused by it.)  Kind of looks like it's supposed to do something error handling related
    3823  * in the default case...
    3824  */
    3825             switch (sc.storageBus)
    3826             {
    3827                 case StorageBus_SATA:
    3828                     break;
    3829                 case StorageBus_SCSI:
    3830                     break;
    3831                 case StorageBus_IDE:
    3832                     break;
    3833                 case StorageBus_SAS:
    3834                     break;
    3835                 default: break; /* Shut up MSC. */
    3836             }
    3837 
    38383792            // for each medium attachment to this controller...
    38393793            for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin();
     
    38733827                 * step 3: import disk
    38743828                 */
    3875                 Utf8Str savedVBoxCurrent = vsdeTargetHD->strVBoxCurrent;
    3876                 ComObjPtr<Medium> pTargetHD;
    3877 
     3829                ComObjPtr<Medium> pTargetMedium;
    38783830                i_importOneDiskImage(diCurrent,
    38793831                                     vsdeTargetHD->strVBoxCurrent,
    3880                                      pTargetHD,
     3832                                     pTargetMedium,
    38813833                                     stack);
    38823834
     3835                // ... and replace the old UUID in the machine config with the one of
     3836                // the imported disk that was just created
    38833837                Bstr hdId;
    3884 
    3885                 ComObjPtr<MediumFormat> mediumFormat;
    3886                 rc = i_findMediumFormatFromDiskImage(diCurrent, mediumFormat);
    3887                 if (FAILED(rc))
    3888                     throw rc;
    3889 
    3890                 Bstr bstrFormatName;
    3891                 rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
    3892                 if (FAILED(rc))
    3893                     throw rc;
    3894 
    3895                 Utf8Str vdf = Utf8Str(bstrFormatName);
    3896 
    3897                 if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0)
    3898                 {
    3899                     ComPtr<IMedium> dvdImage(pTargetHD);
    3900 
    3901                     rc = mVirtualBox->OpenMedium(Bstr(vsdeTargetHD->strVBoxCurrent).raw(),
    3902                                                  DeviceType_DVD,
    3903                                                  AccessMode_ReadWrite,
    3904                                                  false,
    3905                                                  dvdImage.asOutParam());
    3906 
    3907                     if (FAILED(rc)) throw rc;
    3908 
    3909                     // ... and replace the old UUID in the machine config with the one of
    3910                     // the imported disk that was just created
    3911                     rc = dvdImage->COMGETTER(Id)(hdId.asOutParam());
    3912                     if (FAILED(rc)) throw rc;
    3913                 }
    3914                 else
    3915                 {
    3916                     // ... and replace the old UUID in the machine config with the one of
    3917                     // the imported disk that was just created
    3918                     rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam());
    3919                     if (FAILED(rc)) throw rc;
    3920                 }
    3921 
    3922                 /* restore */
    3923                 vsdeTargetHD->strVBoxCurrent = savedVBoxCurrent;
     3838                rc = pTargetMedium->COMGETTER(Id)(hdId.asOutParam());
     3839                if (FAILED(rc)) throw rc;
    39243840
    39253841                /*
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