VirtualBox

Changeset 24214 in vbox


Ignore:
Timestamp:
Oct 30, 2009 6:23:31 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
54163
Message:

Main/MachineImpl: fix SessionMachine::lockMedia() to get the medium status before locking, since the medium status can't be updated for obvious reasons if the medium is locked for writing

File:
1 edited

Legend:

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

    r24209 r24214  
    1023610236
    1023710237    typedef std::list <ComPtr<IMedium> > MediaList;
    10238     MediaList mediaToCheck;
    10239     MediumState_T mediaState;
    1024010238
    1024110239    try
     
    1024310241        HRESULT rc = S_OK;
    1024410242
    10245         /* lock all medium objects attached to the VM */
     10243        ErrorInfoKeeper eik(true /* aIsNull */);
     10244        MultiResult mrc(S_OK);
     10245
     10246        /* Lock all medium objects attached to the VM.
     10247         * Get status for inaccessible media as well. */
    1024610248        for (MediaData::AttachmentList::const_iterator it = mMediaData->mAttachments.begin();
    1024710249             it != mMediaData->mAttachments.end();
     
    1024910251        {
    1025010252            DeviceType_T devType = (*it)->type();
    10251             ComObjPtr<Medium> hd = (*it)->medium();
     10253            ComObjPtr<Medium> medium = (*it)->medium();
    1025210254
    1025310255            bool first = true;
     
    1025510257            /** @todo split out the media locking, and put it into
    1025610258             * MediumImpl.cpp, as it needs this functionality too. */
    10257             while (!hd.isNull())
     10259            while (!medium.isNull())
    1025810260            {
     10261                MediumState_T mediumState = medium->state();
     10262
     10263                /* accessibility check must be first, otherwise locking
     10264                 * interferes with getting the medium state. */
     10265                if (mediumState == MediumState_Inaccessible)
     10266                {
     10267                    rc = medium->COMGETTER(State)(&mediumState);
     10268                    CheckComRCThrowRC(rc);
     10269
     10270                    if (mediumState == MediumState_Inaccessible)
     10271                    {
     10272                        Bstr error;
     10273                        rc = medium->COMGETTER(LastAccessError)(error.asOutParam());
     10274                        CheckComRCThrowRC(rc);
     10275
     10276                        Bstr loc;
     10277                        rc = medium->COMGETTER(Location)(loc.asOutParam());
     10278                        CheckComRCThrowRC(rc);
     10279
     10280                        /* collect multiple errors */
     10281                        eik.restore();
     10282
     10283                        /* be in sync with MediumBase::setStateError() */
     10284                        Assert(!error.isEmpty());
     10285                        mrc = setError(E_FAIL,
     10286                                       tr("Medium '%ls' is not accessible. %ls"),
     10287                                       loc.raw(),
     10288                                       error.raw());
     10289
     10290                        eik.fetch();
     10291                    }
     10292                }
     10293
    1025910294                if (first)
    1026010295                {
     
    1026210297                    {
    1026310298                        /* HardDisk and Floppy medium must be locked for writing */
    10264                         rc = hd->LockWrite(&mediaState);
     10299                        rc = medium->LockWrite(NULL);
    1026510300                        CheckComRCThrowRC(rc);
    1026610301                    }
     
    1026810303                    {
    1026910304                        /* DVD medium must be locked for reading */
    10270                         rc = hd->LockRead(&mediaState);
     10305                        rc = medium->LockRead(NULL);
    1027110306                        CheckComRCThrowRC(rc);
    1027210307                    }
    1027310308
    10274                     mData->mSession.mLockedMedia.push_back (
    10275                         Data::Session::LockedMedia::value_type (
    10276                             ComPtr<IMedium> (hd), true));
     10309                    mData->mSession.mLockedMedia.push_back(
     10310                        Data::Session::LockedMedia::value_type(
     10311                            ComPtr<IMedium>(medium), true));
    1027710312
    1027810313                    first = false;
     
    1028010315                else
    1028110316                {
    10282                     rc = hd->LockRead (&mediaState);
     10317                    rc = medium->LockRead(NULL);
    1028310318                    CheckComRCThrowRC(rc);
    1028410319
    10285                     mData->mSession.mLockedMedia.push_back (
    10286                         Data::Session::LockedMedia::value_type (
    10287                             ComPtr<IMedium> (hd), false));
     10320                    mData->mSession.mLockedMedia.push_back(
     10321                        Data::Session::LockedMedia::value_type(
     10322                            ComPtr<IMedium>(medium), false));
    1028810323                }
    1028910324
    10290                 if (mediaState == MediumState_Inaccessible)
    10291                     mediaToCheck.push_back (ComPtr<IMedium> (hd));
    1029210325
    1029310326                /* no locks or callers here since there should be no way to
    1029410327                 * change the hard disk parent at this point (as it is still
    1029510328                 * attached to the machine) */
    10296                 hd = hd->parent();
     10329                medium = medium->parent();
    1029710330            }
    1029810331        }
    1029910332
    10300         /* SUCCEEDED locking all media, now check accessibility */
    10301 
    10302         ErrorInfoKeeper eik (true /* aIsNull */);
    10303         MultiResult mrc (S_OK);
    10304 
    10305         /* perform a check of inaccessible media deferred above */
    10306         for (MediaList::const_iterator
    10307              it = mediaToCheck.begin();
    10308              it != mediaToCheck.end(); ++it)
    10309         {
    10310             MediumState_T mediaState;
    10311             rc = (*it)->COMGETTER(State) (&mediaState);
    10312             CheckComRCThrowRC(rc);
    10313 
    10314             Assert (mediaState == MediumState_LockedRead ||
    10315                     mediaState == MediumState_LockedWrite);
    10316 
    10317             /* Note that we locked the medium already, so use the error
    10318              * value to see if there was an accessibility failure */
    10319 
    10320             Bstr error;
    10321             rc = (*it)->COMGETTER(LastAccessError) (error.asOutParam());
    10322             CheckComRCThrowRC(rc);
    10323 
    10324             if (!error.isEmpty())
    10325             {
    10326                 Bstr loc;
    10327                 rc = (*it)->COMGETTER(Location) (loc.asOutParam());
    10328                 CheckComRCThrowRC(rc);
    10329 
    10330                 /* collect multiple errors */
    10331                 eik.restore();
    10332 
    10333                 /* be in sync with MediumBase::setStateError() */
    10334                 Assert (!error.isEmpty());
    10335                 mrc = setError(E_FAIL,
    10336                                tr("Medium '%ls' is not accessible. %ls"),
    10337                                loc.raw(),
    10338                                error.raw());
    10339 
    10340                 eik.fetch();
    10341             }
    10342         }
    10343 
    1034410333        eik.restore();
    10345         CheckComRCThrowRC((HRESULT) mrc);
     10334        CheckComRCThrowRC((HRESULT)mrc);
    1034610335    }
    1034710336    catch (HRESULT aRC)
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