VirtualBox

Changeset 38119 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 22, 2011 2:57:03 PM (14 years ago)
Author:
vboxsync
Message:

Main-CloneVM: keep the "public" interface clean

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImplCloneVM.h

    r37971 r38119  
    3434protected:
    3535    HRESULT run();
    36     HRESULT createDiffHelper(const ComObjPtr<Medium> &pParent,
    37                              const Utf8Str &strSnapshotFolder,
    38                              RTCList<ComObjPtr<Medium> > *pNewMedia,
    39                              ComObjPtr<Medium> *ppDiff);
    4036    void destroy();
    4137
  • trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp

    r38116 r38119  
    114114    void updateSnapshotStorageLists(settings::SnapshotsList &sl, const Bstr &bstrOldId, const Bstr &bstrNewId) const;
    115115    void updateStateFile(settings::SnapshotsList &snl, const Guid &id, const Utf8Str &strFile) const;
     116    HRESULT createDifferencingMedium(const ComObjPtr<Medium> &pParent, const Utf8Str &strSnapshotFolder, RTCList<ComObjPtr<Medium> > &newMedia, ComObjPtr<Medium> *ppDiff) const;
    116117    static int copyStateFileProgress(unsigned uPercentage, void *pvUser);
    117118
     
    432433#endif
    433434            /* Check if there is a "step" in the histogram when going the chain
    434              * upwards. If so, we need this image, cause there is another leave
     435             * upwards. If so, we need this image, cause there is another branch
    435436             * from here in the cloned VM. */
    436437            if (hist > used)
     
    611612            updateStateFile(it->llChildSnapshots, id, strFile);
    612613    }
     614}
     615
     616HRESULT MachineCloneVMPrivate::createDifferencingMedium(const ComObjPtr<Medium> &pParent, const Utf8Str &strSnapshotFolder, RTCList<ComObjPtr<Medium> > &newMedia, ComObjPtr<Medium> *ppDiff) const
     617{
     618    HRESULT rc = S_OK;
     619    try
     620    {
     621        Bstr bstrSrcId;
     622        rc = pParent->COMGETTER(Id)(bstrSrcId.asOutParam());
     623        if (FAILED(rc)) throw rc;
     624        ComObjPtr<Medium> diff;
     625        diff.createObject();
     626        rc = diff->init(p->getVirtualBox(),
     627                        pParent->getPreferredDiffFormat(),
     628                        Utf8StrFmt("%s%c", strSnapshotFolder.c_str(), RTPATH_DELIMITER),
     629                        Guid::Empty, /* empty media registry */
     630                        NULL);       /* pllRegistriesThatNeedSaving */
     631        if (FAILED(rc)) throw rc;
     632        MediumLockList *pMediumLockList(new MediumLockList());
     633        rc = diff->createMediumLockList(true /* fFailIfInaccessible */,
     634                                        true /* fMediumLockWrite */,
     635                                        pParent,
     636                                        *pMediumLockList);
     637        if (FAILED(rc)) throw rc;
     638        rc = pMediumLockList->Lock();
     639        if (FAILED(rc)) throw rc;
     640        /* this already registers the new diff image */
     641        rc = pParent->createDiffStorage(diff, MediumVariant_Standard,
     642                                        pMediumLockList,
     643                                        NULL /* aProgress */,
     644                                        true /* aWait */,
     645                                        NULL); // pllRegistriesThatNeedSaving
     646        delete pMediumLockList;
     647        if (FAILED(rc)) throw rc;
     648        /* Remember created medium. */
     649        newMedia.append(diff);
     650        *ppDiff = diff;
     651    }
     652    catch (HRESULT rc2)
     653    {
     654        rc = rc2;
     655    }
     656    catch (...)
     657    {
     658        rc = VirtualBox::handleUnexpectedExceptions(RT_SRC_POS);
     659    }
     660
     661    return rc;
    613662}
    614663
     
    9721021                        ComObjPtr<Medium> pDiff;
    9731022                        /* create the diff under the snapshot medium */
    974                         rc = createDiffHelper(pLMedium, strTrgSnapshotFolder,
    975                                               &newMedia, &pDiff);
     1023                        rc = d->createDifferencingMedium(pLMedium, strTrgSnapshotFolder,
     1024                                                         newMedia, &pDiff);
    9761025                        if (FAILED(rc)) throw rc;
    9771026                        map.insert(TStrMediumPair(Utf8Str(bstrSrcId), pDiff));
     
    11421191                {
    11431192                    ComObjPtr<Medium> pDiff;
    1144                     rc = createDiffHelper(pNewParent, strTrgSnapshotFolder,
    1145                                           &newMedia, &pDiff);
     1193                    rc = d->createDifferencingMedium(pNewParent, strTrgSnapshotFolder,
     1194                                                     newMedia, &pDiff);
    11461195                    if (FAILED(rc)) throw rc;
    11471196                    /* diff image has to be used... */
     
    12871336}
    12881337
    1289 HRESULT MachineCloneVM::createDiffHelper(const ComObjPtr<Medium> &pParent,
    1290                                          const Utf8Str &strSnapshotFolder,
    1291                                          RTCList< ComObjPtr<Medium> > *pNewMedia,
    1292                                          ComObjPtr<Medium> *ppDiff)
    1293 {
    1294     DPTR(MachineCloneVM);
    1295     ComObjPtr<Machine> &p = d->p;
    1296     HRESULT rc = S_OK;
    1297 
    1298     try
    1299     {
    1300         Bstr bstrSrcId;
    1301         rc = pParent->COMGETTER(Id)(bstrSrcId.asOutParam());
    1302         if (FAILED(rc)) throw rc;
    1303         ComObjPtr<Medium> diff;
    1304         diff.createObject();
    1305         rc = diff->init(p->mParent,
    1306                         pParent->getPreferredDiffFormat(),
    1307                         Utf8StrFmt("%s%c", strSnapshotFolder.c_str(), RTPATH_DELIMITER),
    1308                         Guid::Empty, /* empty media registry */
    1309                         NULL);       /* pllRegistriesThatNeedSaving */
    1310         if (FAILED(rc)) throw rc;
    1311         MediumLockList *pMediumLockList(new MediumLockList());
    1312         rc = diff->createMediumLockList(true /* fFailIfInaccessible */,
    1313                                         true /* fMediumLockWrite */,
    1314                                         pParent,
    1315                                         *pMediumLockList);
    1316         if (FAILED(rc)) throw rc;
    1317         rc = pMediumLockList->Lock();
    1318         if (FAILED(rc)) throw rc;
    1319         /* this already registers the new diff image */
    1320         rc = pParent->createDiffStorage(diff, MediumVariant_Standard,
    1321                                         pMediumLockList,
    1322                                         NULL /* aProgress */,
    1323                                         true /* aWait */,
    1324                                         NULL); // pllRegistriesThatNeedSaving
    1325         delete pMediumLockList;
    1326         if (FAILED(rc)) throw rc;
    1327         /* Remember created medium. */
    1328         pNewMedia->append(diff);
    1329         *ppDiff = diff;
    1330     }
    1331     catch (HRESULT rc2)
    1332     {
    1333         rc = rc2;
    1334     }
    1335     catch (...)
    1336     {
    1337         rc = VirtualBox::handleUnexpectedExceptions(RT_SRC_POS);
    1338     }
    1339 
    1340     return rc;
    1341 }
    1342 
    13431338void MachineCloneVM::destroy()
    13441339{
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