VirtualBox

Changeset 28872 in vbox


Ignore:
Timestamp:
Apr 28, 2010 2:54:03 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60802
Message:

Main/Medium: new helper method for fixing up parent UUIDs of children moved around by merging, make diff reset rely on documented VBoxHDD behavior by opening the entire medium chain, minor bugfixing to get the reported image sizes in the GUI right, fixing the parameters of an error message to print the right image name

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

Legend:

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

    r28835 r28872  
    49494949
    49504950/**
     4951 * Fix the parent UUID of all children to point to this medium as their
     4952 * parent.
     4953 */
     4954HRESULT Medium::fixParentUuidOfChildren(const MediaList &childrenToReparent)
     4955{
     4956    MediumLockList mediumLockList;
     4957    HRESULT rc = createMediumLockList(false, this, mediumLockList);
     4958    AssertComRCReturnRC(rc);
     4959
     4960    try
     4961    {
     4962        PVBOXHDD hdd;
     4963        int vrc = VDCreate(m->vdDiskIfaces, &hdd);
     4964        ComAssertRCThrow(vrc, E_FAIL);
     4965
     4966        try
     4967        {
     4968            MediumLockList::Base::iterator lockListBegin =
     4969                mediumLockList.GetBegin();
     4970            MediumLockList::Base::iterator lockListEnd =
     4971                mediumLockList.GetEnd();
     4972            for (MediumLockList::Base::iterator it = lockListBegin;
     4973                 it != lockListEnd;
     4974                 ++it)
     4975            {
     4976                MediumLock &mediumLock = *it;
     4977                const ComObjPtr<Medium> &pMedium = mediumLock.GetMedium();
     4978                AutoReadLock(pMedium COMMA_LOCKVAL_SRC_POS);
     4979
     4980                // open the image
     4981                vrc = VDOpen(hdd,
     4982                             pMedium->m->strFormat.c_str(),
     4983                             pMedium->m->strLocationFull.c_str(),
     4984                             VD_OPEN_FLAGS_READONLY,
     4985                             pMedium->m->vdDiskIfaces);
     4986                if (RT_FAILURE(vrc))
     4987                    throw vrc;
     4988            }
     4989
     4990            for (MediaList::const_iterator it = childrenToReparent.begin();
     4991                 it != childrenToReparent.end();
     4992                 ++it)
     4993            {
     4994                /* VD_OPEN_FLAGS_INFO since UUID is wrong yet */
     4995                vrc = VDOpen(hdd,
     4996                             (*it)->m->strFormat.c_str(),
     4997                             (*it)->m->strLocationFull.c_str(),
     4998                             VD_OPEN_FLAGS_INFO,
     4999                             (*it)->m->vdDiskIfaces);
     5000                if (RT_FAILURE(vrc))
     5001                    throw vrc;
     5002
     5003                vrc = VDSetParentUuid(hdd, VD_LAST_IMAGE, m->id);
     5004                if (RT_FAILURE(vrc))
     5005                    throw vrc;
     5006
     5007                vrc = VDClose(hdd, false /* fDelete */);
     5008                if (RT_FAILURE(vrc))
     5009                    throw vrc;
     5010
     5011                (*it)->UnlockWrite(NULL);
     5012            }
     5013        }
     5014        catch (HRESULT aRC) { rc = aRC; }
     5015        catch (int aVRC)
     5016        {
     5017            throw setError(E_FAIL,
     5018                            tr("Could not update medium UUID references to parent '%s' (%s)"),
     5019                            m->strLocationFull.raw(),
     5020                            vdError(aVRC).raw());
     5021        }
     5022
     5023        VDDestroy(hdd);
     5024    }
     5025    catch (HRESULT aRC) { rc = aRC; }
     5026
     5027    return rc;
     5028}
     5029
     5030/**
    49515031 * Runs Medium::Task::handler() on the current thread instead of creating
    49525032 * a new one.
     
    52175297                                targetLocation.raw(), vdError(vrc).raw());
    52185298
    5219             size = VDGetFileSize(hdd, 1);
    5220             logicalSize = VDGetSize(hdd, 1) / _1M;
     5299            size = VDGetFileSize(hdd, VD_LAST_IMAGE);
     5300            logicalSize = VDGetSize(hdd, VD_LAST_IMAGE) / _1M;
    52215301        }
    52225302        catch (HRESULT aRC) { rc = aRC; }
     
    54215501                            throw vrc;
    54225502
    5423                         vrc = VDSetParentUuid(hdd, 1,
     5503                        vrc = VDSetParentUuid(hdd, VD_LAST_IMAGE,
    54245504                                              pTarget->m->id);
    54255505                        if (RT_FAILURE(vrc))
     
    54405520            throw setError(E_FAIL,
    54415521                            tr("Could not merge the hard disk '%s' to '%s'%s"),
    5442                             m->strLocationFull.raw(), m->strLocationFull.raw(),
     5522                            m->strLocationFull.raw(),
     5523                            pTarget->m->strLocationFull.raw(),
    54435524                            vdError(aVRC).raw());
    54445525        }
     
    55015582
    55025583                    pMedium->deparent();  // removes pMedium from source
    5503                     pTarget->m->llChildren.push_back(pMedium);
    5504                     pMedium->m->pParent = pTarget;
     5584                    pMedium->setParent(pTarget);
    55055585                }
    55065586            }
     
    57485828                                    targetLocation.raw(), vdError(vrc).raw());
    57495829
    5750                 size = VDGetFileSize(targetHdd, 0);
    5751                 logicalSize = VDGetSize(targetHdd, 0) / _1M;
     5830                size = VDGetFileSize(targetHdd, VD_LAST_IMAGE);
     5831                logicalSize = VDGetSize(targetHdd, VD_LAST_IMAGE) / _1M;
    57525832            }
    57535833            catch (HRESULT aRC) { rc = aRC; }
     
    59436023        try
    59446024        {
     6025            /* Open all hard disk images in the target chain but the last. */
     6026            MediumLockList::Base::const_iterator targetListBegin =
     6027                task.mpMediumLockList->GetBegin();
     6028            MediumLockList::Base::const_iterator targetListEnd =
     6029                task.mpMediumLockList->GetEnd();
     6030            for (MediumLockList::Base::const_iterator it = targetListBegin;
     6031                 it != targetListEnd;
     6032                 ++it)
     6033            {
     6034                const MediumLock &mediumLock = *it;
     6035                const ComObjPtr<Medium> &pMedium = mediumLock.GetMedium();
     6036
     6037                AutoReadLock alock(pMedium COMMA_LOCKVAL_SRC_POS);
     6038
     6039                /* sanity check */
     6040                Assert(pMedium->m->state == MediumState_LockedRead);
     6041
     6042                /* Open all images in appropriate mode. */
     6043                vrc = VDOpen(hdd,
     6044                             pMedium->m->strFormat.c_str(),
     6045                             pMedium->m->strLocationFull.c_str(),
     6046                             VD_OPEN_FLAGS_READONLY,
     6047                             pMedium->m->vdDiskIfaces);
     6048                if (RT_FAILURE(vrc))
     6049                    throw setError(E_FAIL,
     6050                                   tr("Could not open the hard disk storage unit '%s'%s"),
     6051                                   pMedium->m->strLocationFull.raw(),
     6052                                   vdError(vrc).raw());
     6053
     6054                /* Done when we hit the image which should be reset */
     6055                if (pMedium == this)
     6056                    break;
     6057            }
     6058
    59456059            /* first, delete the storage unit */
    5946             vrc = VDOpen(hdd,
    5947                          format.c_str(),
    5948                          location.c_str(),
    5949                          VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_INFO,
    5950                          m->vdDiskIfaces);
    5951             if (RT_SUCCESS(vrc))
    5952                 vrc = VDClose(hdd, true /* fDelete */);
    5953 
     6060            vrc = VDClose(hdd, true /* fDelete */);
    59546061            if (RT_FAILURE(vrc))
    59556062                throw setError(E_FAIL,
     
    59846091                                location.raw(), vdError(vrc).raw());
    59856092
    5986             size = VDGetFileSize(hdd, 1);
    5987             logicalSize = VDGetSize(hdd, 1) / _1M;
     6093            size = VDGetFileSize(hdd, VD_LAST_IMAGE);
     6094            logicalSize = VDGetSize(hdd, VD_LAST_IMAGE) / _1M;
    59886095        }
    59896096        catch (HRESULT aRC) { rc = aRC; }
  • trunk/src/VBox/Main/include/MediumImpl.h

    r28835 r28872  
    219219                       MediumLockList *aMediumLockList);
    220220
     221    HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
     222
    221223    /** Returns a preferred format for a differencing hard disk. */
    222224    Bstr preferredDiffFormat();
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