VirtualBox

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


Ignore:
Timestamp:
Dec 11, 2008 7:37:55 PM (16 years ago)
Author:
vboxsync
Message:

Main: #3377: Implicitly detach DVD/Floppy from an unregistered machine (as opposed to hard disks, this does not have side effects).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/DVDDriveImpl.cpp

    r15051 r15334  
    275275            if (SUCCEEDED (rc))
    276276            {
    277                 mData.backup();
    278 
    279                 unmount();
    280 
    281                 mData->mImage = image;
    282                 mData->mState = DriveState_ImageMounted;
    283 
    284                 /* leave the lock before informing callbacks */
    285                 alock.unlock();
    286 
    287                 mParent->onDVDDriveChange();
     277                /* umount() will backup data */
     278                rc = unmount();
     279                if (SUCCEEDED (rc))
     280                {
     281                    mData->mImage = image;
     282                    mData->mState = DriveState_ImageMounted;
     283
     284                    /* leave the lock before informing callbacks */
     285                    alock.unlock();
     286
     287                    mParent->onDVDDriveChange();
     288                }
    288289            }
    289290        }
     
    309310        !mData->mHostDrive.equalsTo (aHostDVDDrive))
    310311    {
    311         mData.backup();
    312 
    313         unmount();
    314 
    315         mData->mHostDrive = aHostDVDDrive;
    316         mData->mState = DriveState_HostDriveCaptured;
    317 
    318         /* leave the lock before informing callbacks */
    319         alock.unlock();
    320 
    321         mParent->onDVDDriveChange();
     312        /* umount() will backup data */
     313        HRESULT rc = unmount();
     314        if (SUCCEEDED (rc))
     315        {
     316            mData->mHostDrive = aHostDVDDrive;
     317            mData->mState = DriveState_HostDriveCaptured;
     318
     319            /* leave the lock before informing callbacks */
     320            alock.unlock();
     321
     322            mParent->onDVDDriveChange();
     323        }
    322324    }
    323325
     
    338340    if (mData->mState != DriveState_NotMounted)
    339341    {
    340         mData.backup();
    341 
    342         unmount();
    343 
    344         mData->mState = DriveState_NotMounted;
    345 
    346         /* leave the lock before informing callbacks */
    347         alock.unlock();
    348 
    349         mParent->onDVDDriveChange();
     342        /* umount() will backup data */
     343        HRESULT rc = unmount();
     344        if (SUCCEEDED (rc))
     345        {
     346            mData->mState = DriveState_NotMounted;
     347
     348            /* leave the lock before informing callbacks */
     349            alock.unlock();
     350
     351            mParent->onDVDDriveChange();
     352        }
    350353    }
    351354
     
    385388
    386389/**
    387  *  Loads settings from the given machine node.
    388  *  May be called once right after this object creation.
    389  *
    390  *  @param aMachineNode <Machine> node.
    391  *
    392  *  @note Locks this object for writing.
     390 * Loads settings from the given machine node. May be called once right after
     391 * this object creation.
     392 *
     393 * @param aMachineNode <Machine> node.
     394 *
     395 * @note Locks this object for writing.
    393396 */
    394397HRESULT DVDDrive::loadSettings (const settings::Key &aMachineNode)
     
    469472
    470473/**
    471  *  Saves settings to the given machine node.
    472  *
    473  *  @param aMachineNode <Machine> node.
    474  *
    475  *  @note Locks this object for reading.
     474 * Saves settings to the given machine node.
     475 *
     476 * @param aMachineNode <Machine> node.
     477 *
     478 * @note Locks this object for reading.
    476479 */
    477480HRESULT DVDDrive::saveSettings (settings::Key &aMachineNode)
     
    530533
    531534/**
    532  *  @note Locks this object for writing.
     535 * @note Locks this object for writing.
    533536 */
    534537bool DVDDrive::rollback()
     
    567570
    568571/**
    569  *  @note Locks this object for writing, together with the peer object (also
    570  *  for writing) if there is one.
     572 * @note Locks this object for writing, together with the peer object (also for
     573 *      writing) if there is one.
    571574 */
    572575void DVDDrive::commit()
     
    605608
    606609/**
    607  *  @note Locks this object for writing, together with the peer object
    608  *  represented by @a aThat (locked for reading).
     610 * @note Locks this object for writing, together with the peer object
     611 *       represented by @a aThat (locked for reading).
    609612 */
    610613void DVDDrive::copyFrom (DVDDrive *aThat)
     
    628631}
    629632
    630 // private methods
    631 ////////////////////////////////////////////////////////////////////////////////
    632 
    633 /**
    634  *  Helper to unmount a drive.
    635  *
    636  *  @return COM status code
    637  *
     633/**
     634 * Helper to unmount a drive.
     635 *
     636 * @note Must be called from under this object's write lock.
    638637 */
    639638HRESULT DVDDrive::unmount()
    640639{
    641640    AssertReturn (isWriteLockOnCurrentThread(), E_FAIL);
     641
     642    mData.backup();
    642643
    643644    if (mData->mImage)
     
    646647        mData->mHostDrive.setNull();
    647648
    648     return S_OK;
    649 }
     649    mData->mState = DriveState_NotMounted;
     650
     651    return S_OK;
     652}
     653
     654// private methods
     655////////////////////////////////////////////////////////////////////////////////
     656
    650657/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/FloppyDriveImpl.cpp

    r15051 r15334  
    282282            if (SUCCEEDED (rc))
    283283            {
    284                 mData.backup();
    285 
    286                 unmount();
    287 
    288                 mData->mImage = image;
    289                 mData->mState = DriveState_ImageMounted;
    290 
    291                 /* leave the lock before informing callbacks */
    292                 alock.unlock();
    293 
    294                 mParent->onFloppyDriveChange();
     284                /* umount() will backup data */
     285                rc = unmount();
     286                if (SUCCEEDED (rc))
     287                {
     288                    mData->mImage = image;
     289                    mData->mState = DriveState_ImageMounted;
     290
     291                    /* leave the lock before informing callbacks */
     292                    alock.unlock();
     293
     294                    mParent->onFloppyDriveChange();
     295                }
    295296            }
    296297        }
     
    316317        !mData->mHostDrive.equalsTo (aHostFloppyDrive))
    317318    {
    318         mData.backup();
    319 
    320         unmount();
    321 
    322         mData->mHostDrive = aHostFloppyDrive;
    323         mData->mState = DriveState_HostDriveCaptured;
    324 
    325         /* leave the lock before informing callbacks */
    326         alock.unlock();
    327 
    328         mParent->onFloppyDriveChange();
     319        /* umount() will backup data */
     320        HRESULT rc = unmount();
     321        if (SUCCEEDED (rc))
     322        {
     323            mData->mHostDrive = aHostFloppyDrive;
     324            mData->mState = DriveState_HostDriveCaptured;
     325
     326            /* leave the lock before informing callbacks */
     327            alock.unlock();
     328
     329            mParent->onFloppyDriveChange();
     330        }
    329331    }
    330332
     
    345347    if (mData->mState != DriveState_NotMounted)
    346348    {
    347         mData.backup();
    348 
    349         unmount();
    350 
    351         mData->mState = DriveState_NotMounted;
    352 
    353         /* leave the lock before informing callbacks */
    354         alock.unlock();
    355 
    356         mParent->onFloppyDriveChange();
     349        /* umount() will backup data */
     350        HRESULT rc = unmount();
     351        if (SUCCEEDED (rc))
     352        {
     353            mData->mState = DriveState_NotMounted;
     354
     355            /* leave the lock before informing callbacks */
     356            alock.unlock();
     357
     358            mParent->onFloppyDriveChange();
     359        }
    357360    }
    358361
     
    392395
    393396/**
    394  *  Loads settings from the given machine node.
    395  *  May be called once right after this object creation.
    396  *
    397  *  @param aMachineNode <Machine> node.
    398  *
    399  *  @note Locks this object for writing.
     397 * Loads settings from the given machine node. May be called once right after
     398 * this object creation.
     399 *
     400 * @param aMachineNode <Machine> node.
     401 *
     402 * @note Locks this object for writing.
    400403 */
    401404HRESULT FloppyDrive::loadSettings (const settings::Key &aMachineNode)
     
    476479
    477480/**
    478  *  Saves settings to the given machine node.
    479  *
    480  *  @param aMachineNode <Machine> node.
    481  *
    482  *  @note Locks this object for reading.
     481 * Saves settings to the given machine node.
     482 *
     483 * @param aMachineNode <Machine> node.
     484 *
     485 * @note Locks this object for reading.
    483486 */
    484487HRESULT FloppyDrive::saveSettings (settings::Key &aMachineNode)
     
    537540
    538541/**
    539  *  @note Locks this object for writing.
     542 * @note Locks this object for writing.
    540543 */
    541544bool FloppyDrive::rollback()
     
    574577
    575578/**
    576  *  @note Locks this object for writing, together with the peer object (also
    577  *  for writing) if there is one.
     579 * @note Locks this object for writing, together with the peer object (also for
     580 *      writing) if there is one.
    578581 */
    579582void FloppyDrive::commit()
     
    612615
    613616/**
    614  *  @note Locks this object for writing, together with the peer object (locked
    615  *  for reading) if there is one.
     617 * @note Locks this object for writing, together with the peer object (locked
     618 *       for reading) if there is one.
    616619 */
    617620void FloppyDrive::copyFrom (FloppyDrive *aThat)
     
    633636}
    634637
    635 // private methods
    636 /////////////////////////////////////////////////////////////////////////////
    637 
    638 /**
    639  *  Helper to unmount a drive.
    640  *
    641  *  @return COM status code
     638/**
     639 * Helper to unmount a drive.
     640 *
     641 * @note Must be called from under this object's write lock.
    642642 */
    643643HRESULT FloppyDrive::unmount()
    644644{
    645645    AssertReturn (isWriteLockOnCurrentThread(), E_FAIL);
     646
     647    mData.backup();
    646648
    647649    if (mData->mImage)
     
    650652        mData->mHostDrive.setNull();
    651653
    652     return S_OK;
    653 }
     654    mData->mState = DriveState_NotMounted;
     655
     656    return S_OK;
     657}
     658
     659// private methods
     660/////////////////////////////////////////////////////////////////////////////
     661
    654662/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/MachineImpl.cpp

    r15202 r15334  
    41024102    AssertReturn (autoCaller.state() == Ready, E_FAIL);
    41034103
     4104    /* we will probably modify these and want to prevent concurrent
     4105     * modifications until we finish */
     4106    AutoWriteLock dvdLock (mDVDDrive);
     4107    AutoWriteLock floppyLock (mFloppyDrive);
     4108
    41044109    if (aRegistered)
    41054110    {
     
    41384143                    "has %d hard disks attached"),
    41394144                mUserData->mName.raw(), mHDData->mAttachments.size());
    4140     }
     4145
     4146        /* Note that we do not prevent unregistration of a DVD or Floppy image
     4147         * is attached: as opposed to hard disks detaching such an image
     4148         * implicitly in this method (which we will do below) won't have any
     4149         * side effects (like detached orphan base and diff hard disks etc).*/
     4150    }
     4151
     4152    HRESULT rc = S_OK;
    41414153
    41424154    /* Ensure the settings are saved. If we are going to be registered and
    41434155     * isConfigLocked() is FALSE then it means that no config file exists yet,
    4144      * so create it. */
     4156     * so create it by calling saveSettings() too. */
    41454157    if (isModified() || (aRegistered && !isConfigLocked()))
    41464158    {
    4147         HRESULT rc = saveSettings();
     4159        rc = saveSettings();
    41484160        CheckComRCReturnRC (rc);
    41494161    }
    41504162
    4151     mData->mRegistered = aRegistered;
    4152 
    4153     return S_OK;
     4163    /* Implicitly detach DVD/Floppy */
     4164    rc = mDVDDrive->unmount();
     4165    if (SUCCEEDED (rc))
     4166        rc = mFloppyDrive->unmount();
     4167
     4168    if (SUCCEEDED (rc))
     4169    {
     4170        /* we may have had implicit modifications we want to fix on success */
     4171        commit();
     4172
     4173        mData->mRegistered = aRegistered;
     4174    }
     4175    else
     4176    {
     4177        /* we may have had implicit modifications we want to cancel on failure*/
     4178        rollback (false /* aNotify */);
     4179    }
     4180
     4181    return rc;
    41544182}
    41554183
  • trunk/src/VBox/Main/include/DVDDriveImpl.h

    r15051 r15334  
    108108    void copyFrom (DVDDrive *aThat);
    109109
     110    HRESULT unmount();
     111
    110112    // public methods for internal purposes only
    111113    // (ensure there is a caller and a read lock before calling them!)
     
    118120private:
    119121
    120     HRESULT unmount();
    121 
    122122    const ComObjPtr <Machine, ComWeakRef> mParent;
    123123    const ComObjPtr <DVDDrive> mPeer;
  • trunk/src/VBox/Main/include/FloppyDriveImpl.h

    r15051 r15334  
    108108    void copyFrom (FloppyDrive *aThat);
    109109
     110    HRESULT unmount();
     111
    110112    // public methods for internal purposes only
    111113    // (ensure there is a caller and a read lock before calling them!)
     
    118120private:
    119121
    120     HRESULT unmount();
    121 
    122122    const ComObjPtr <Machine, ComWeakRef> mParent;
    123123    const ComObjPtr <FloppyDrive> mPeer;
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