VirtualBox

Changeset 37558 in vbox


Ignore:
Timestamp:
Jun 20, 2011 2:44:35 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72399
Message:

Main-CloneVM: use the same medium type in the target like in the source image

File:
1 edited

Legend:

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

    r37555 r37558  
    454454    AutoWriteLock trgLock(d->pTrgMachine COMMA_LOCKVAL_SRC_POS);
    455455
    456     MultiResult rc = S_OK;
     456    HRESULT rc = S_OK;
    457457
    458458    /*
     
    587587                    }
    588588
    589                     /* Start creating the clone. */
    590                     ComObjPtr<Medium> pTarget;
    591                     rc = pTarget.createObject();
    592                     if (FAILED(rc)) throw rc;
    593 
    594589                    /* Check if this medium comes from the snapshot folder, if
    595590                     * so, put it there in the cloned machine as well.
     
    605600                        strFile = Utf8StrFmt("%s%c%lS", strTrgMachineFolder.c_str(), RTPATH_DELIMITER, bstrSrcName.raw());
    606601
     602                    /* Start creating the clone. */
     603                    ComObjPtr<Medium> pTarget;
     604                    rc = pTarget.createObject();
     605                    if (FAILED(rc)) throw rc;
     606
    607607                    rc = pTarget->init(p->mParent,
    608608                                       Utf8Str(bstrSrcFormat),
    609609                                       strFile,
    610                                        d->pTrgMachine->mData->mUuid,  /* media registry */
    611                                        NULL                           /* llRegistriesThatNeedSaving */);
     610                                       Guid(),  /* empty media registry */
     611                                       NULL     /* llRegistriesThatNeedSaving */);
    612612                    if (FAILED(rc)) throw rc;
    613613
     
    638638                    }
    639639
     640                    /* Get the medium type from the source and set it to the
     641                     * new medium. */
     642                    MediumType_T type;
     643                    rc = pMedium->COMGETTER(Type)(&type);
     644                    if (FAILED(rc)) throw rc;
     645                    rc = pTarget->COMSETTER(Type)(type);
     646                    if (FAILED(rc)) throw rc;
    640647                    map.insert(TStrMediumPair(Utf8Str(bstrSrcId), pTarget));
    641648
     
    654661                rc = pNewParent->COMGETTER(Id)(bstrSrcId.asOutParam());
    655662                if (FAILED(rc)) throw rc;
    656                 GuidList *pllRegistriesThatNeedSaving;
    657663                ComObjPtr<Medium> diff;
    658664                diff.createObject();
     
    660666                                pNewParent->getPreferredDiffFormat(),
    661667                                Utf8StrFmt("%s%c", strTrgSnapshotFolder.c_str(), RTPATH_DELIMITER),
    662                                 d->pTrgMachine->mData->mUuid,
    663                                 NULL); // pllRegistriesThatNeedSaving
    664                 if (FAILED(rc)) throw rc;
    665                 MediumLockList *pMediumLockList(new MediumLockList()); /* todo: deleteeeeeeeee */
     668                                Guid(), /* empty media registry */
     669                                NULL);  /* pllRegistriesThatNeedSaving */
     670                if (FAILED(rc)) throw rc;
     671                MediumLockList *pMediumLockList(new MediumLockList());
    666672                rc = diff->createMediumLockList(true /* fFailIfInaccessible */,
    667673                                                true /* fMediumLockWrite */,
     
    691697            d->updateStorageLists(trgMCF.storageMachine.llStorageControllers, bstrSrcId, bstrTrgId);
    692698            d->updateSnapshotStorageLists(trgMCF.llFirstSnapshot, bstrSrcId, bstrTrgId);
     699            /* Make sure all disks know of the new machine uuid. We do this
     700             * last to be able to change the medium type above. */
     701            rc = pNewParent->addRegistry(d->pTrgMachine->mData->mUuid, true /* fRecursive */);
     702            if (FAILED(rc)) throw rc;
    693703        }
    694704        /* Clone all save state files. */
     
    783793        }
    784794
    785         /* The medias are created before the machine was there. We have to make
    786          * sure the new medias know of there new parent or we get in trouble
    787          * when the media registry is saved for this VM, especially in case of
    788          * difference image chain's. See VirtualBox::saveMediaRegistry.*/
    789 //        for (size_t i = 0; i < newBaseMedias.size(); ++i)
    790 //        {
    791 //            rc = newBaseMedias.at(i)->addRegistry(d->pTrgMachine->mData->mUuid, true /* fRecursive */);
    792 //            if (FAILED(rc)) throw rc;
    793 //        }
    794 
    795795        /* Now save the new configuration to disk. */
    796796        rc = d->pTrgMachine->SaveSettings();
     
    806806    }
    807807
     808    MultiResult mrc(rc);
    808809    /* Cleanup on failure (CANCEL also) */
    809810    if (FAILED(rc))
     
    815816            vrc = RTFileDelete(newFiles.at(i).c_str());
    816817            if (RT_FAILURE(vrc))
    817                 rc = p->setError(VBOX_E_IPRT_ERROR, p->tr("Could not delete file '%s' (%Rrc)"), newFiles.at(i).c_str(), vrc);
     818                mrc = p->setError(VBOX_E_IPRT_ERROR, p->tr("Could not delete file '%s' (%Rrc)"), newFiles.at(i).c_str(), vrc);
    818819        }
    819820        /* Delete all already created medias. (Reverse, cause there could be
     
    826827            {
    827828                AutoCaller mac(pMedium);
    828                 if (FAILED(mac.rc())) { continue; rc = mac.rc(); }
     829                if (FAILED(mac.rc())) { continue; mrc = mac.rc(); }
    829830                AutoReadLock mlock(pMedium COMMA_LOCKVAL_SRC_POS);
    830831                fFile = pMedium->isMediumFormatFile();
     
    835836                vrc = RTFileDelete(strLoc.c_str());
    836837                if (RT_FAILURE(vrc))
    837                     rc = p->setError(VBOX_E_IPRT_ERROR, p->tr("Could not delete file '%s' (%Rrc)"), strLoc.c_str(), vrc);
     838                    mrc = p->setError(VBOX_E_IPRT_ERROR, p->tr("Could not delete file '%s' (%Rrc)"), strLoc.c_str(), vrc);
    838839            }
    839840        }
     
    845846    }
    846847
    847     return rc;
     848    return mrc;
    848849}
    849850
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