VirtualBox

Changeset 74003 in vbox for trunk/src


Ignore:
Timestamp:
Aug 31, 2018 2:47:37 PM (6 years ago)
Author:
vboxsync
Message:

Main: bugref:9231: added ability to set IMedium:location for medium moved by user

Location:
trunk/src/VBox
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r73716 r74003  
    493493    { "--resizebyte",   'R', RTGETOPT_REQ_UINT64 },
    494494    { "--move",         'm', RTGETOPT_REQ_STRING },
     495    { "--setlocation",  'l', RTGETOPT_REQ_STRING },
    495496    { "--description",  'd', RTGETOPT_REQ_STRING }
    496497};
     
    517518    bool fModifyResize = false;
    518519    bool fModifyResizeMB = false;
    519     bool fModifyLocation = false;
     520    bool fMoveMedium = false;
    520521    bool fModifyDescription = false;
     522    bool fSetNewLocation = false;
    521523    uint64_t cbResize = 0;
    522524    const char *pszFilenameOrUuid = NULL;
     
    615617                /* Get a new location  */
    616618                pszNewLocation = RTPathAbsDup(ValueUnion.psz);
    617                 fModifyLocation = true;
     619                fMoveMedium = true;
     620                break;
     621
     622            case 'l':   // --setlocation
     623                /* Get a new location  */
     624                pszNewLocation = RTPathAbsDup(ValueUnion.psz);
     625                fSetNewLocation = true;
    618626                break;
    619627
     
    659667        && !fModifyCompact
    660668        && !fModifyResize
    661         && !fModifyLocation
    662         && !fModifyDescription)
     669        && !fMoveMedium
     670        && !fSetNewLocation
     671        && !fModifyDescription
     672        )
    663673        return errorSyntax(USAGE_MODIFYMEDIUM, "No operation specified");
    664674
     
    766776    }
    767777
    768     if (fModifyLocation)
     778    if (fMoveMedium)
    769779    {
    770780        do
     
    773783            Utf8Str strLocation(pszNewLocation);
    774784            RTStrFree(pszNewLocation);
    775             CHECK_ERROR(pMedium, SetLocation(Bstr(strLocation).raw(), pProgress.asOutParam()));
     785            CHECK_ERROR(pMedium, MoveTo(Bstr(strLocation).raw(), pProgress.asOutParam()));
    776786
    777787            if (SUCCEEDED(rc) && !pProgress.isNull())
     
    784794            CHECK_ERROR_BREAK(pMedium, COMGETTER(Id)(uuid.asOutParam()));
    785795
    786             RTPrintf("Move medium with UUID %s finished \n", Utf8Str(uuid).c_str());
     796            RTPrintf("Move medium with UUID %s finished\n", Utf8Str(uuid).c_str());
    787797        }
    788798        while (0);
    789799    }
    790800
     801    if (fSetNewLocation)
     802    {
     803        Utf8Str strLocation(pszNewLocation);
     804        RTStrFree(pszNewLocation);
     805        CHECK_ERROR(pMedium, COMSETTER(Location)(Bstr(strLocation).raw()));
     806
     807        Bstr uuid;
     808        CHECK_ERROR(pMedium, COMGETTER(Id)(uuid.asOutParam()));
     809        RTPrintf("Set new location of medium with UUID %s finished\n", Utf8Str(uuid).c_str());
     810    }
     811
    791812    if (fModifyDescription)
    792813    {
    793814        CHECK_ERROR(pMedium, COMSETTER(Description)(Bstr(pszNewLocation).raw()));
    794815
    795         RTPrintf("Medium description has been changed. \n");
     816        RTPrintf("Medium description has been changed.\n");
    796817    }
    797818
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r73768 r74003  
    982982                     "                            [--compact]\n"
    983983                     "                            [--resize <megabytes>|--resizebyte <bytes>]\n"
    984                      "                            [--move <path]\n"
     984                     "                            [--move <path>]\n"
     985                     "                            [--setlocation <path>]\n"
    985986                     "                            [--description <description string>]"
    986987                     "\n", SEP);
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumItem.cpp

    r73953 r74003  
    8888    {
    8989        /* Prepare move storage progress: */
    90         CProgress comProgress = comMedium.SetLocation(strFileName);
     90        CProgress comProgress = comMedium.MoveTo(strFileName);
    9191
    9292        /* Show error message if necessary: */
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r73953 r74003  
    310310    {
    311311        /* Prepare move storage progress: */
    312         CProgress comProgress = comMedium.SetLocation(newData.m_options.m_strLocation);
     312        CProgress comProgress = comMedium.MoveTo(newData.m_options.m_strLocation);
    313313
    314314        /* Show error message if necessary: */
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r73971 r74003  
    1503015030  <interface
    1503115031    name="IMedium" extends="$unknown"
    15032     uuid="c3a390cd-4efa-458d-2afb-d07eb4e105bb"
     15032    uuid="a570ac5b-d90d-42bb-b577-a3e2697044e4"
    1503315033    wsmap="managed"
    1503415034    reservedMethods="4" reservedAttributes="8"
     
    1524515245    </attribute>
    1524615246
    15247     <attribute name="location" type="wstring" readonly="yes">
     15247    <attribute name="location" type="wstring">
    1524815248      <desc>
    1524915249        Location of the storage unit holding medium data.
     
    1616016160    <!-- other methods -->
    1616116161
    16162     <method name="setLocation" wrap-hint-server="passcaller">
     16162    <method name="moveTo" wrap-hint-server="passcaller">
    1616316163      <desc>
    1616416164        Changes the location of this medium. Some medium types may support
  • trunk/src/VBox/Main/include/MediumImpl.h

    r72999 r74003  
    239239    HRESULT getVariant(std::vector<MediumVariant_T> &aVariant);
    240240    HRESULT getLocation(com::Utf8Str &aLocation);
     241    HRESULT setLocation(const com::Utf8Str &aLocation);
    241242    HRESULT getName(com::Utf8Str &aName);
    242243    HRESULT getDeviceType(DeviceType_T *aDeviceType);
     
    297298                        const std::vector<MediumVariant_T> &aVariant,
    298299                        ComPtr<IProgress> &aProgress);
    299     HRESULT setLocation(AutoCaller &autoCaller,
    300                         const com::Utf8Str &aLocation,
    301                         ComPtr<IProgress> &aProgress);
     300    HRESULT moveTo(AutoCaller &autoCaller,
     301                   const com::Utf8Str &aLocation,
     302                   ComPtr<IProgress> &aProgress);
    302303    HRESULT compact(ComPtr<IProgress> &aProgress);
    303304    HRESULT resize(LONG64 aLogicalSize,
  • trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp

    r73757 r74003  
    11031103            if (FAILED(rc)) throw rc;
    11041104
    1105             /* Drop lock early because IMedium::SetLocation needs to get the VirtualBox one. */
     1105            /* Drop lock early because IMedium::MoveTo needs to get the VirtualBox one. */
    11061106            machineLock.release();
    11071107
    11081108            ComPtr<IProgress> moveDiskProgress;
    1109             rc = pMedium->SetLocation(bstrLocation.raw(), moveDiskProgress.asOutParam());
     1109            rc = pMedium->MoveTo(bstrLocation.raw(), moveDiskProgress.asOutParam());
    11101110            if (SUCCEEDED(rc))
    11111111            {
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r73858 r74003  
    29192919}
    29202920
    2921 HRESULT Medium::setLocation(AutoCaller &autoCaller, const com::Utf8Str &aLocation, ComPtr<IProgress> &aProgress)
     2921HRESULT Medium::moveTo(AutoCaller &autoCaller, const com::Utf8Str &aLocation, ComPtr<IProgress> &aProgress)
    29222922{
    29232923    ComObjPtr<Medium> pParent;
     
    29302930    /// @todo NEWMEDIA for file names, add the default extension if no extension
    29312931    /// is present (using the information from the VD backend which also implies
    2932     /// that one more parameter should be passed to setLocation() requesting
     2932    /// that one more parameter should be passed to moveTo() requesting
    29332933    /// that functionality since it is only allowed when called from this method
    29342934
     
    32003200}
    32013201
     3202HRESULT Medium::setLocation(const com::Utf8Str &aLocation)
     3203{
     3204    HRESULT rc = S_OK;
     3205
     3206    try
     3207    {
     3208        // locking: we need the tree lock first because we access parent pointers
     3209        // and we need to write-lock the media involved
     3210        AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
     3211
     3212        AutoCaller autoCaller(this);
     3213        AssertComRCThrowRC(autoCaller.rc());
     3214
     3215        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     3216
     3217        Utf8Str destPath(aLocation);
     3218
     3219        // some check for file based medium
     3220        if (i_isMediumFormatFile())
     3221        {
     3222            /* Path must be absolute */
     3223            if (!RTPathStartsWithRoot(destPath.c_str()))
     3224            {
     3225                rc = setError(VBOX_E_FILE_ERROR,
     3226                              tr("The given path '%s' is not fully qualified"),
     3227                              destPath.c_str());
     3228                throw rc;
     3229            }
     3230
     3231            /* Simple check for existence */
     3232            if (!RTFileExists(destPath.c_str()))
     3233            {
     3234                rc = setError(VBOX_E_FILE_ERROR,
     3235                              tr("The given path '%s' is not an existing file. New location is invalid."),
     3236                              destPath.c_str());
     3237                throw rc;
     3238            }
     3239        }
     3240
     3241        /* Check VMs which have this medium attached to*/
     3242        std::vector<com::Guid> aMachineIds;
     3243        rc = getMachineIds(aMachineIds);
     3244
     3245        // switch locks only if there are machines with this medium attached
     3246        if (!aMachineIds.empty())
     3247        {
     3248            std::vector<com::Guid>::const_iterator currMachineID = aMachineIds.begin();
     3249            std::vector<com::Guid>::const_iterator lastMachineID = aMachineIds.end();
     3250
     3251            alock.release();
     3252            autoCaller.release();
     3253            treeLock.release();
     3254
     3255            while (currMachineID != lastMachineID)
     3256            {
     3257                Guid id(*currMachineID);
     3258                ComObjPtr<Machine> aMachine;
     3259                rc = m->pVirtualBox->i_findMachine(id, false, true, &aMachine);
     3260                if (SUCCEEDED(rc))
     3261                {
     3262                    ComObjPtr<SessionMachine> sm;
     3263                    ComPtr<IInternalSessionControl> ctl;
     3264
     3265                    bool ses = aMachine->i_isSessionOpenVM(sm, &ctl);
     3266                    if (ses)
     3267                    {
     3268                        treeLock.acquire();
     3269                        autoCaller.add();
     3270                        AssertComRCThrowRC(autoCaller.rc());
     3271                        alock.acquire();
     3272
     3273                        rc = setError(VERR_VM_UNEXPECTED_VM_STATE,
     3274                                      tr("At least the VM '%s' to whom this medium '%s' attached has currently an opened session. Stop all VMs before set location for this medium"),
     3275                                      id.toString().c_str(),
     3276                                      i_getLocationFull().c_str());
     3277                        throw rc;
     3278                    }
     3279                }
     3280                ++currMachineID;
     3281            }
     3282
     3283            treeLock.acquire();
     3284            autoCaller.add();
     3285            AssertComRCThrowRC(autoCaller.rc());
     3286            alock.acquire();
     3287        }
     3288
     3289        m->strLocationFull = destPath;
     3290
     3291        // save the settings
     3292        alock.release();
     3293        autoCaller.release();
     3294        treeLock.release();
     3295
     3296        i_markRegistriesModified();
     3297        m->pVirtualBox->i_saveModifiedRegistries();
     3298
     3299        MediumState_T mediumState;
     3300        refreshState(autoCaller, &mediumState);
     3301    }
     3302    catch (HRESULT aRC) { rc = aRC; }
     3303
     3304    return rc;
     3305}
     3306
    32023307HRESULT Medium::compact(ComPtr<IProgress> &aProgress)
    32033308{
     
    81548259
    81558260        /* The object may request a specific UUID (through a special form of
    8156         * the setLocation() argument). Otherwise we have to generate it */
     8261        * the moveTo() argument). Otherwise we have to generate it */
    81578262        Guid id = m->id;
    81588263
     
    83328437
    83338438        /* The object may request a specific UUID (through a special form of
    8334          * the setLocation() argument). Otherwise we have to generate it */
     8439         * the moveTo() argument). Otherwise we have to generate it */
    83358440        Guid targetId = pTarget->m->id;
    83368441
     
    88808985
    88818986        /* The object may request a specific UUID (through a special form of
    8882          * the setLocation() argument). Otherwise we have to generate it */
     8987         * the moveTo() argument). Otherwise we have to generate it */
    88838988        Guid targetId = pTarget->m->id;
    88848989
     
    91669271 * Implementation code for the "move" task.
    91679272 *
    9168  * This only gets started from Medium::SetLocation() and always
     9273 * This only gets started from Medium::MoveTo() and always
    91699274 * runs asynchronously.
    91709275 *
     
    97899894
    97909895        /* The object may request a specific UUID (through a special form of
    9791          * the setLocation() argument). Otherwise we have to generate it */
     9896         * the moveTo() argument). Otherwise we have to generate it */
    97929897        Guid targetId = m->id;
    97939898
  • trunk/src/VBox/ValidationKit/testdriver/vbox.py

    r73171 r74003  
    783783        self.fImportedVBoxApi   = False;
    784784        self.fpApiVer           = 3.2;
     785        self.uRevision          = 0;
    785786        self.oBuild             = None;
    786787        self.oVBoxMgr           = None;
     
    13181319                else:
    13191320                    self.fpApiVer += 1.1;
     1321
     1322            try:
     1323                self.uRevision = oVBox.revision;
     1324            except:
     1325                reporter.logXcpt('Failed to get VirtualBox revision, assuming 0');
     1326                self.uRevision = 0;
     1327            reporter.log("IVirtualBox.revision=%u" % (self.uRevision,));
    13201328
    13211329            # Patch VBox manage to gloss over portability issues (error constants, etc).
  • trunk/src/VBox/ValidationKit/tests/api/tdMoveMedium1.py

    r72732 r74003  
    6666    #
    6767
    68     def setLocation(self, sLocation, aoMediumAttachments):
     68    def moveTo(self, sLocation, aoMediumAttachments):
    6969        for oAttachment in aoMediumAttachments:
    7070            try:
     
    7474                reporter.errorXcpt('failed to get the medium from the IMediumAttachment "%s"' % (oAttachment))
    7575
    76             try:
    77                 oProgress = vboxwrappers.ProgressWrapper(oMedium.setLocation(sLocation), self.oTstDrv.oVBoxMgr, self.oTstDrv,
    78                                                          'move "%s"' % (oMedium.name,))
    79             except:
    80                 return reporter.errorXcpt('Medium::setLocation("%s") for medium "%s" failed' % (sLocation, oMedium.name,))
     76            if self.oTstDrv.fpApiVer >= 5.3 and self.oTstDrv.uRevision > 124748:
     77                try:
     78                    oProgress = vboxwrappers.ProgressWrapper(oMedium.moveTo(sLocation), self.oTstDrv.oVBoxMgr, self.oTstDrv,
     79                                                             'move "%s"' % (oMedium.name,));
     80                except:
     81                    return reporter.errorXcpt('Medium::moveTo("%s") for medium "%s" failed' % (sLocation, oMedium.name,));
     82            else:
     83                try:
     84                    oProgress = vboxwrappers.ProgressWrapper(oMedium.setLocation(sLocation), self.oTstDrv.oVBoxMgr, self.oTstDrv,
     85                                                             'move "%s"' % (oMedium.name,));
     86                except:
     87                    return reporter.errorXcpt('Medium::setLocation("%s") for medium "%s" failed' % (sLocation, oMedium.name,));
     88
    8189
    8290            oProgress.wait()
     
    149157            aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
    150158            #case 1. Only path without file name, with trailing separator
    151             fRc = self.setLocation(sNewLoc + os.sep, aoMediumAttachments) and fRc
     159            fRc = self.moveTo(sNewLoc + os.sep, aoMediumAttachments) and fRc
    152160            fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asFiles) and fRc
    153161
    154162            #case 2. Only path without file name, without trailing separator
    155             fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
     163            fRc = self.moveTo(sOrigLoc, aoMediumAttachments) and fRc
    156164            fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asFiles) and fRc
    157165
     
    162170            #and the file name is processed as folder name (aka mv(1) logic).
    163171            #Be discussed.
    164             fRc = self.setLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments) and fRc
     172            fRc = self.moveTo(os.path.join(sNewLoc, 'newName'), aoMediumAttachments) and fRc
    165173            asNewFiles = ['newName' + os.path.splitext(s)[1] for s in asFiles]
    166174            fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments, asFiles) and fRc
     
    170178
    171179            #case 4. Only file name
    172             fRc = self.setLocation('onlyMediumName', aoMediumAttachments) and fRc
     180            fRc = self.moveTo('onlyMediumName', aoMediumAttachments) and fRc
    173181            asNewFiles = ['onlyMediumName' + os.path.splitext(s)[1] for s in asFiles]
    174182            if self.oTstDrv.fpApiVer >= 5.3:
     
    183191                aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
    184192                asSnapFiles = [os.path.basename(o.medium.name) for o in aoMediumAttachments]
    185                 fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
     193                fRc = self.moveTo(sOrigLoc, aoMediumAttachments) and fRc
    186194                fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asSnapFiles) and fRc
    187195
  • trunk/src/VBox/ValidationKit/tests/api/tdMoveVM1.py

    r72742 r74003  
    287287        aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController)
    288288        oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv)
    289         oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments)
     289        oSubTstDrvMoveMedium1Instance.moveTo(sOldLoc, aoMediumAttachments)
    290290
    291291        del oSubTstDrvMoveMedium1Instance
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