VirtualBox

Changeset 37525 in vbox


Ignore:
Timestamp:
Jun 17, 2011 10:09:21 AM (13 years ago)
Author:
vboxsync
Message:

Main/VirtualBox+Medium: resurrect the feature of changing the medium UUID when opening the image, which allows to resolve duplicate UUIDs without using external tools. Also fixes Medium::setIDs, which wasn't correctly working.
Frontends/*: corresponding changes.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/en_US/SDKRef.xml

    r37200 r37525  
    34483448      <itemizedlist>
    34493449        <listitem>
     3450          <para>The method <xref linkend="IVirtualBox__openMedium"
     3451          xreflabel="IVirtualBox::openMedium()" /> has one more parameter
     3452          now, which allows resolving duplicate medium UUIDs without the need
     3453          for external tools.</para>
     3454        </listitem>
     3455
     3456        <listitem>
    34503457          <para>The <xref linkend="INetworkAdapter" xreflabel="INetworkAdapter"/>
    34513458          interface has been cleaned up. The various methods to activate an
  • trunk/doc/manual/en_US/user_VBoxManage.xml

    r37489 r37525  
    15071507                            [--mtype normal|writethrough|immutable|shareable]
    15081508                            [--comment &lt;text&gt;]
     1509                            [--setuuid &lt;uuid&gt;]
     1510                            [--setparentuuid &lt;uuid&gt;]
    15091511                            [--passthrough on|off]
    15101512                            [--bandwidthgroup name|none]
     
    16431645            server downstairs"). This is purely descriptive and not needed for
    16441646            the medium to function correctly.</para>
     1647          </glossdef>
     1648        </glossentry>
     1649
     1650        <glossentry>
     1651          <glossterm>setuuid, setparentuuid</glossterm>
     1652
     1653          <glossdef>
     1654            <para>Modifies the UUID or parent UUID of a medium before
     1655            attaching it to a VM. This is an expert option. Inappropriate use
     1656            can make the medium unusable or lead to broken VM configurations
     1657            if any other VM is referring to the same media already. The most
     1658            frequently used variant is <code>--setuuid ""</code>, which assigns
     1659            a new (random) UUID to an image. This is useful to resolve the
     1660            duplicate UUID errors if one duplicated an image using file copy
     1661            utilities.</para>
    16451662          </glossdef>
    16461663        </glossentry>
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r37074 r37525  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    227227HRESULT findOrOpenMedium(HandlerArg *a, const char *pszFilenameOrUuid,
    228228                         DeviceType_T enmDevType, ComPtr<IMedium> &pMedium,
    229                          bool *pfWasUnknown);
     229                         bool fForceNewUuidOnOpen, bool *pfWasUnknown);
    230230int handleCreateHardDisk(HandlerArg *a);
    231231int handleModifyHardDisk(HandlerArg *a);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r36527 r37525  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    181181HRESULT findOrOpenMedium(HandlerArg *a, const char *pszFilenameOrUuid,
    182182                         DeviceType_T enmDevType, ComPtr<IMedium> &pMedium,
    183                          bool *pfWasUnknown)
     183                         bool fForceNewUuidOnOpen, bool *pfWasUnknown)
    184184{
    185185    HRESULT rc;
     
    207207        CHECK_ERROR(a->virtualBox, OpenMedium(Bstr(pszFilenameOrUuid).raw(),
    208208                                              enmDevType, AccessMode_ReadWrite,
     209                                              fForceNewUuidOnOpen,
    209210                                              pMedium.asOutParam()));
    210211        if (SUCCEEDED(rc))
     
    476477    else
    477478        rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk,
    478                               hardDisk, &unknown);
     479                              hardDisk, false /* fForceNewUuidOnOpen */, &unknown);
    479480    if (FAILED(rc))
    480481        return 1;
     
    630631    bool fDstUnknown = false;
    631632
    632     rc = findOrOpenMedium(a, pszSrc, DeviceType_HardDisk, srcDisk, &fSrcUnknown);
     633    rc = findOrOpenMedium(a, pszSrc, DeviceType_HardDisk, srcDisk,
     634                          false /* fForceNewUuidOnOpen */, &fSrcUnknown);
    633635    if (FAILED(rc))
    634636        return 1;
     
    639641        if (fExisting)
    640642        {
    641             rc = findOrOpenMedium(a, pszDst, DeviceType_HardDisk, dstDisk, &fDstUnknown);
     643            rc = findOrOpenMedium(a, pszDst, DeviceType_HardDisk, dstDisk,
     644                                  false /* fForceNewUuidOnOpen */, &fDstUnknown);
    642645            if (FAILED(rc))
    643646                break;
     
    925928    bool unknown = false;
    926929
    927     rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk, hardDisk, &unknown);
     930    rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk, hardDisk,
     931                          false /* fForceNewUuidOnOpen */, &unknown);
    928932    if (FAILED(rc))
    929933        return 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r37450 r37525  
    462462                     "                                     readonly|multiattach]\n"
    463463                     "                            [--comment <text>]\n"
     464                     "                            [--setuuid <uuid>]\n"
     465                     "                            [--setparentuuid <uuid>]\n"
    464466                     "                            [--passthrough on|off]\n"
    465467                     "                            [--bandwidthgroup <name>]\n"
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r37202 r37525  
    712712                    ComPtr<IMedium> hardDisk;
    713713                    rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk,
    714                                           hardDisk, NULL);
     714                                          hardDisk, false /* fForceNewUuidOnOpen */,
     715                                          NULL);
    715716                    if (FAILED(rc))
    716717                        break;
     
    807808                    ComPtr<IMedium> hardDisk;
    808809                    rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk,
    809                                           hardDisk, NULL);
     810                                          hardDisk, false /* fForceNewUuidOnOpen */,
     811                                          NULL);
    810812                    if (FAILED(rc))
    811813                        break;
     
    934936                {
    935937                    rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_DVD,
    936                                           dvdMedium, NULL);
     938                                          dvdMedium, false /* fForceNewUuidOnOpen */,
     939                                          NULL);
    937940                    if (FAILED(rc))
    938941                        break;
     
    9971000                    {
    9981001                        rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_Floppy,
    999                                               floppyMedium, NULL);
     1002                                              floppyMedium, false /* fForceNewUuidOnOpen */,
     1003                                              NULL);
    10001004                        if (FAILED(rc))
    10011005                            break;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp

    r36652 r37525  
    5555    { "--forceunmount",     'f', RTGETOPT_REQ_NOTHING },
    5656    { "--comment",          'C', RTGETOPT_REQ_STRING },
     57    { "--setuuid",          'q', RTGETOPT_REQ_STRING },
     58    { "--setparentuuid",    'Q', RTGETOPT_REQ_STRING },
    5759    // iSCSI options
    5860    { "--server",           'S', RTGETOPT_REQ_STRING },
     
    7476    bool fForceUnmount = false;
    7577    bool fSetMediumType = false;
     78    bool fSetNewUuid = false;
     79    bool fSetNewParentUuid = false;
    7680    MediumType_T mediumType = MediumType_Normal;
    7781    Bstr bstrComment;
     
    8185    const char *pszPassThrough = NULL;
    8286    const char *pszBandwidthGroup = NULL;
     87    Bstr bstrNewUuid;
     88    Bstr bstrNewParentUuid;
    8389    // iSCSI options
    8490    Bstr bstrServer;
     
    181187                else
    182188                    rc = E_FAIL;
    183             break;
     189                break;
     190
     191            case 'q':
     192                if (ValueUnion.psz)
     193                {
     194                    bstrNewUuid = ValueUnion.psz;
     195                    fSetNewUuid = true;
     196                }
     197                else
     198                    rc = E_FAIL;
     199                break;
     200
     201            case 'Q':
     202                if (ValueUnion.psz)
     203                {
     204                    bstrNewParentUuid = ValueUnion.psz;
     205                    fSetNewParentUuid = true;
     206                }
     207                else
     208                    rc = E_FAIL;
     209                break;
    184210
    185211            case 'S':   // --server
     
    544570
    545571                rc = findOrOpenMedium(a, pszMedium, devTypeRequested,
    546                                       pMedium2Mount, NULL);
     572                                      pMedium2Mount, fSetNewUuid, NULL);
    547573                if (FAILED(rc) || !pMedium2Mount)
    548574                    throw Utf8StrFmt("Invalid UUID or filename \"%s\"", pszMedium);
     575            }
     576
     577            // set medium/parent medium UUID, if so desired
     578            if (fSetNewUuid || fSetNewParentUuid)
     579            {
     580                CHECK_ERROR(pMedium2Mount, SetIDs(fSetNewUuid, bstrNewUuid.raw(),
     581                                                  fSetNewParentUuid, bstrNewParentUuid.raw()));
     582                if (FAILED(rc))
     583                    throw  Utf8Str("Failed to set the medium/parent medium UUID");
    549584            }
    550585
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r37423 r37525  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    14591459            RTPrintf("Adding hard disk '%s'...\n", hdaFile);
    14601460            pVirtualBox->OpenMedium(bstrHdaFile.raw(), DeviceType_HardDisk,
    1461                                     AccessMode_ReadWrite, pMedium.asOutParam());
     1461                                    AccessMode_ReadWrite, FALSE /* fForceNewUuid */,
     1462                                    pMedium.asOutParam());
    14621463        }
    14631464        /* do we have the right image now? */
     
    15441545                                                 DeviceType_Floppy,
    15451546                                                 AccessMode_ReadWrite,
     1547                                                 FALSE /* fForceNewUuid */,
    15461548                                                 pMedium.asOutParam()));
    15471549                }
     
    16241626                                                 DeviceType_DVD,
    16251627                                                 AccessMode_ReadWrite,
     1628                                                 FALSE /* fForceNewUuid */,
    16261629                                                 pMedium.asOutParam()));
    16271630                }
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r37470 r37525  
    77
    88/*
    9  * Copyright (C) 2006-2010 Oracle Corporation
     9 * Copyright (C) 2006-2011 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    16511651    }
    16521652
    1653     CMedium med = mVBox.OpenMedium(aLocation, devType, KAccessMode_ReadWrite);
     1653    CMedium med = mVBox.OpenMedium(aLocation, devType, KAccessMode_ReadWrite, false /* fForceNewUuid */);
    16541654    if (mVBox.isOk())
    16551655        medium = VBoxMedium(CMedium(med), aType, KMediumState_Created);
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r37374 r37525  
    27542754
    27552755    /* Open corresponding medium: */
    2756     CMedium comMedium = vbox.OpenMedium(strMediumLocation, mediumTypeToGlobal(mediumType), KAccessMode_ReadWrite);
     2756    CMedium comMedium = vbox.OpenMedium(strMediumLocation, mediumTypeToGlobal(mediumType), KAccessMode_ReadWrite, false);
    27572757
    27582758    if (vbox.isOk())
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r36364 r37525  
    77
    88/*
    9  * Copyright (C) 2011 Oracle Corporation
     9 * Copyright (C) 2006-2011 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    426426        if (image.isNull())
    427427        {
    428             image = vbox.OpenMedium(strSource, KDeviceType_DVD, KAccessMode_ReadWrite);
     428            image = vbox.OpenMedium(strSource, KDeviceType_DVD, KAccessMode_ReadWrite, false /* fForceNewUuid */);
    429429            if (vbox.isOk())
    430430                strUuid = image.GetId();
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r37487 r37525  
    13921392  <interface
    13931393    name="IVirtualBox" extends="$unknown"
    1394     uuid="bc166b9b-9b62-4145-b1f6-6c39068aaf00"
     1394    uuid="d627bf11-2758-46be-9a4d-7d9ef794c247"
    13951395    wsmap="managed"
    13961396    >
     
    19131913        <desc>Whether to open the image in read/write or read-only mode. For
    19141914        a "DVD" device type, this is ignored and read-only mode is always assumed.</desc>
     1915      </param>
     1916      <param name="forceNewUuid" type="boolean" dir="in">
     1917        <desc>Allows the caller to request a completely new medium UUID for
     1918        the image which is to be opened. Useful if one intends to open an exact
     1919        copy of a previously opened image, as this would normally fail due to
     1920        the duplicate UUID.</desc>
    19151921      </param>
    19161922      <param name="medium" type="IMedium" dir="return">
  • trunk/src/VBox/Main/include/MediumImpl.h

    r35982 r37525  
    77
    88/*
    9  * Copyright (C) 2008-2010 Oracle Corporation
     9 * Copyright (C) 2008-2011 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    7878                 const Utf8Str &aLocation,
    7979                 HDDOpenMode enOpenMode,
     80                 bool fForceNewUuid,
    8081                 DeviceType_T aDeviceType);
    8182
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r37244 r37525  
    140140                          DeviceType_T deviceType,
    141141                          AccessMode_T accessMode,
     142                          BOOL fForceNewUuid,
    142143                          IMedium **aMedium);
    143144    STDMETHOD(FindMedium)(IN_BSTR aLocation,
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r37162 r37525  
    138138    bool autoReset : 1;
    139139
     140    /** New UUID to be set on the next queryInfo() call. */
    140141    const Guid uuidImage;
     142    /** New parent UUID to be set on the next queryInfo() call. */
    141143    const Guid uuidParentImage;
    142144
     
    929931 * @param aFormat
    930932 * @param aLocation     Storage unit location.
    931  * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUI or medium UUID or empty if none).
     933 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUID or machine UUID or empty if none).
    932934 * @param pllRegistriesThatNeedSaving Optional list to receive the UUIDs of the media registries that need saving.
    933935 */
     
    10121014 * @param aLocation     Storage unit location.
    10131015 * @param enOpenMode    Whether to open the medium read/write or read-only.
     1016 * @param fForceNewUuid Whether a new UUID should be set to avoid duplicates.
    10141017 * @param aDeviceType   Device type of medium.
    10151018 */
     
    10171020                     const Utf8Str &aLocation,
    10181021                     HDDOpenMode enOpenMode,
     1022                     bool fForceNewUuid,
    10191023                     DeviceType_T aDeviceType)
    10201024{
     
    10511055
    10521056    /* get all the information about the medium from the storage unit */
    1053     rc = queryInfo(false /* fSetImageId */, false /* fSetParentId */);
     1057    if (fForceNewUuid)
     1058        unconst(m->uuidImage).create();
     1059    rc = queryInfo(fForceNewUuid /* fSetImageId */, false /* fSetParentId */);
    10541060
    10551061    if (SUCCEEDED(rc))
     
    10891095 * @param aParent       Parent medium disk or NULL for a root (base) medium.
    10901096 * @param aDeviceType   Device type of the medium.
    1091  * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUI or medium UUID).
     1097 * @param uuidMachineRegistry The registry to which this medium should be added (global registry UUID or machine UUID).
    10921098 * @param aNode         Configuration settings.
    10931099 * @param strMachineFolder The machine folder with which to resolve relative paths; if empty, then we use the VirtualBox home directory
     
    19531959    if (aSetImageId)
    19541960    {
    1955         imageId = Guid(aImageId);
    1956         if (imageId.isEmpty())
    1957             return setError(E_INVALIDARG, tr("Argument %s is empty"), "aImageId");
     1961        if (Bstr(aImageId).isEmpty())
     1962            imageId.create();
     1963        else
     1964        {
     1965            imageId = Guid(aImageId);
     1966            if (imageId.isEmpty())
     1967                return setError(E_INVALIDARG, tr("Argument %s is empty"), "aImageId");
     1968        }
    19581969    }
    19591970    if (aSetParentId)
    1960         parentId = Guid(aParentId);
     1971    {
     1972        if (Bstr(aParentId).isEmpty())
     1973            parentId.create();
     1974        else
     1975            parentId = Guid(aParentId);
     1976    }
    19611977
    19621978    unconst(m->uuidImage) = imageId;
     
    50905106     * time in VirtualBox (such as VMDK for which VDOpen() needs to
    50915107     * generate an UUID if it is missing) */
    5092     if (    (m->hddOpenMode == OpenReadOnly)
     5108    if (    m->hddOpenMode == OpenReadOnly
    50935109         || m->type == MediumType_Readonly
    5094          || !isImport
     5110         || (!isImport && !fSetImageId && !fSetParentId)
    50955111       )
    50965112        uOpenFlags |= VD_OPEN_FLAGS_READONLY;
     
    51695185                    vrc = VDSetUuid(hdd, 0, m->uuidImage.raw());
    51705186                    ComAssertRCThrow(vrc, E_FAIL);
     5187                    mediumId = m->uuidImage;
    51715188                }
    51725189                if (fSetParentId)
     
    51985215                    if (mediumId != uuid)
    51995216                    {
     5217                        /** @todo r=klaus this always refers to VirtualBox.xml as the medium registry, even for new VMs */
    52005218                        lastAccessError = Utf8StrFmt(
    52015219                                tr("UUID {%RTuuid} of the medium '%s' does not match the value {%RTuuid} stored in the media registry ('%s')"),
     
    52135231                 * underlying storage so use what we store in XML */
    52145232
    5215                 /* generate an UUID for an imported UUID-less medium */
    5216                 if (isImport)
     5233                if (fSetImageId)
    52175234                {
    5218                     if (fSetImageId)
    5219                         mediumId = m->uuidImage;
    5220                     else
    5221                         mediumId.create();
     5235                    /* set the UUID if an API client wants to change it */
     5236                    mediumId = m->uuidImage;
     5237                }
     5238                else if (isImport)
     5239                {
     5240                    /* generate an UUID for an imported UUID-less medium */
     5241                    mediumId.create();
    52225242                }
    52235243            }
     
    53055325                        && m->pParent->getId() != parentId)
    53065326                    {
     5327                        /** @todo r=klaus this always refers to VirtualBox.xml as the medium registry, even for new VMs */
    53075328                        lastAccessError = Utf8StrFmt(
    53085329                                tr("Parent UUID {%RTuuid} of the medium '%s' does not match UUID {%RTuuid} of its parent medium stored in the media registry ('%s')"),
     
    53385359    alock.enter();
    53395360
    5340     if (isImport)
     5361    if (isImport || fSetImageId)
    53415362        unconst(m->id) = mediumId;
    53425363
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r37244 r37525  
    14821482                                    DeviceType_T deviceType,
    14831483                                    AccessMode_T accessMode,
     1484                                    BOOL fForceNewUuid,
    14841485                                    IMedium **aMedium)
    14851486{
     
    15291530                           aLocation,
    15301531                           (accessMode == AccessMode_ReadWrite) ? Medium::OpenReadWrite : Medium::OpenReadOnly,
     1532                           fForceNewUuid,
    15311533                           deviceType);
    15321534
  • trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp

    r33604 r37525  
    88
    99/*
    10  * Copyright (C) 2006-2010 Oracle Corporation
     10 * Copyright (C) 2006-2011 Oracle Corporation
    1111 *
    1212 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    359359                                DeviceType_DVD,
    360360                                AccessMode_ReadOnly,
     361                                false /* fForceNewUuid */,
    361362                                getter_AddRefs(dvdImage));
    362363    if (NS_FAILED(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