VirtualBox

Ignore:
Timestamp:
Nov 16, 2021 5:59:16 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
148322
Message:

Main/Medium: Improve a few API calls where a concurrent Medium::queryInfo activity can lead to errors about incorrect medium state which is transient. bugref:10149

File:
1 edited

Legend:

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

    r91718 r92464  
    18391839    AutoWriteLock mlock(this COMMA_LOCKVAL_SRC_POS);
    18401840
     1841    /* Wait for a concurrently running Medium::i_queryInfo to complete. */
     1842    while (m->queryInfoRunning)
     1843    {
     1844        mlock.release();
     1845        autoCaller.release();
     1846        treeLock.release();
     1847        /* Must not hold the media tree lock, as Medium::i_queryInfo needs
     1848         * this lock and thus we would run into a deadlock here. */
     1849        Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     1850        /* must not hold the object lock now */
     1851        Assert(!isWriteLockOnCurrentThread());
     1852        {
     1853            AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     1854        }
     1855        treeLock.acquire();
     1856        autoCaller.add();
     1857        if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1858        mlock.acquire();
     1859    }
     1860
    18411861    switch (m->state)
    18421862    {
     
    21112131    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    21122132
     2133    /* Wait for a concurrently running Medium::i_queryInfo to complete. */
     2134    if (m->queryInfoRunning)
     2135    {
     2136        /* Must not hold the media tree lock, as Medium::i_queryInfo needs this
     2137         * lock and thus we would run into a deadlock here. */
     2138        Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     2139        while (m->queryInfoRunning)
     2140        {
     2141            alock.release();
     2142            /* must not hold the object lock now */
     2143            Assert(!isWriteLockOnCurrentThread());
     2144            {
     2145                AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     2146            }
     2147            alock.acquire();
     2148        }
     2149    }
     2150
    21132151    switch (m->state)
    21142152    {
     
    24982536{
    24992537    AutoWriteLock mlock(this COMMA_LOCKVAL_SRC_POS);
     2538
     2539    /* Wait for a concurrently running Medium::i_queryInfo to complete. */
     2540    if (m->queryInfoRunning)
     2541    {
     2542        /* Must not hold the media tree lock, as Medium::i_queryInfo needs this
     2543         * lock and thus we would run into a deadlock here. */
     2544        Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     2545        while (m->queryInfoRunning)
     2546        {
     2547            mlock.release();
     2548            /* must not hold the object lock now */
     2549            Assert(!isWriteLockOnCurrentThread());
     2550            {
     2551                AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     2552            }
     2553            mlock.acquire();
     2554        }
     2555    }
    25002556
    25012557    switch (m->state)
     
    52305286    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    52315287
     5288    /* Wait for a concurrently running Medium::i_queryInfo to complete. */
     5289    while (m->queryInfoRunning)
     5290    {
     5291        autoCaller.release();
     5292        multilock.release();
     5293        /* Must not hold the media tree lock, as Medium::i_queryInfo needs
     5294         * this lock and thus we would run into a deadlock here. */
     5295        Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     5296        /* must not hold the object lock now */
     5297        Assert(!isWriteLockOnCurrentThread());
     5298        {
     5299            AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     5300        }
     5301        multilock.acquire();
     5302        autoCaller.add();
     5303        if (FAILED(autoCaller.rc())) return autoCaller.rc();
     5304    }
     5305
    52325306    LogFlowFunc(("ENTER for %s\n", i_getLocationFull().c_str()));
    52335307
     
    53185392 */
    53195393HRESULT Medium::i_deleteStorage(ComObjPtr<Progress> *aProgress,
    5320                               bool aWait, bool aNotify)
     5394                                bool aWait, bool aNotify)
    53215395{
    53225396    AssertReturn(aProgress != NULL || aWait == true, E_FAIL);
     
    53475421        /** @todo r=klaus would be great if this could be moved to the async
    53485422         * part of the operation as it can take quite a while */
    5349         if (m->queryInfoRunning)
    5350         {
    5351             while (m->queryInfoRunning)
    5352             {
    5353                 alock.release();
    5354                 autoCaller.release();
    5355                 treelock.release();
    5356                 /* Must not hold the media tree lock or the object lock, as
    5357                  * Medium::i_queryInfo needs this lock and thus we would run
    5358                  * into a deadlock here. */
    5359                 Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
    5360                 Assert(!isWriteLockOnCurrentThread());
    5361                 {
    5362                     AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
    5363                 }
    5364                 treelock.acquire();
    5365                 autoCaller.add();
    5366                 AssertComRCThrowRC(autoCaller.rc());
    5367                 alock.acquire();
    5368             }
     5423        while (m->queryInfoRunning)
     5424        {
     5425            alock.release();
     5426            autoCaller.release();
     5427            treelock.release();
     5428            /* Must not hold the media tree lock or the object lock, as
     5429             * Medium::i_queryInfo needs this lock and thus we would run
     5430             * into a deadlock here. */
     5431            Assert(!m->pVirtualBox->i_getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     5432            Assert(!isWriteLockOnCurrentThread());
     5433            {
     5434                AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     5435            }
     5436            treelock.acquire();
     5437            autoCaller.add();
     5438            AssertComRCThrowRC(autoCaller.rc());
     5439            alock.acquire();
    53695440        }
    53705441
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