VirtualBox

Changeset 66046 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Mar 10, 2017 4:58:36 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
113912
Message:

Main/Snapshot: When creating a snapshot it's necessary to copy the medium attachment objects (and not use the same ones) to separate the new snapshot from current state. Otherwise changing a removable medium (DVD/floppy) will show up in 'fresh' snapshots, i.e. the ones taken since VBoxSVC was started. Same issue for PCI device attachments (which isn't used as much). Apart from that a lot of error checking cleanup, for consistency reasons.

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

Legend:

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

    r65186 r66046  
    167167
    168168    ComAssertRet(aParent && aThat, E_INVALIDARG);
    169     Assert(!aParent->i_isSnapshotMachine());
    170169
    171170    /* Enclose the state transition NotReady->InInit->Ready */
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r65103 r66046  
    999999     * same as Machine's data) */
    10001000    mUserData.share(pMachine->mUserData);
    1001     /* make a private copy of all other data (recent changes from SessionMachine) */
     1001
     1002    /* make a private copy of all other data */
    10021003    mHWData.attachCopy(aSessionMachine->mHWData);
    1003     mMediaData.attachCopy(aSessionMachine->mMediaData);
    10041004
    10051005    /* SSData is always unique for SnapshotMachine */
     
    10091009    HRESULT rc = S_OK;
    10101010
     1011    /* Create copies of all attachments (mMediaData after attaching a copy
     1012     * contains just references to original objects). Additionally associate
     1013     * media with the snapshot (Machine::uninitDataAndChildObjects() will
     1014     * deassociate at destruction). */
     1015    mMediaData.allocate();
     1016    for (MediaData::AttachmentList::const_iterator
     1017         it = aSessionMachine->mMediaData->mAttachments.begin();
     1018         it != aSessionMachine->mMediaData->mAttachments.end();
     1019         ++it)
     1020    {
     1021        ComObjPtr<MediumAttachment> pAtt;
     1022        pAtt.createObject();
     1023        rc = pAtt->initCopy(this, *it);
     1024        if (FAILED(rc)) return rc;
     1025        mMediaData->mAttachments.push_back(pAtt);
     1026
     1027        Medium *pMedium = pAtt->i_getMedium();
     1028        if (pMedium) // can be NULL for non-harddisk
     1029        {
     1030            rc = pMedium->i_addBackReference(mData->mUuid, mSnapshotId);
     1031            AssertComRC(rc);
     1032        }
     1033    }
     1034
    10111035    /* create copies of all shared folders (mHWData after attaching a copy
    10121036     * contains just references to original objects) */
    1013     for (HWData::SharedFolderList::iterator it = mHWData->mSharedFolders.begin();
     1037    for (HWData::SharedFolderList::iterator
     1038         it = mHWData->mSharedFolders.begin();
    10141039         it != mHWData->mSharedFolders.end();
    10151040         ++it)
    10161041    {
    1017         ComObjPtr<SharedFolder> folder;
    1018         folder.createObject();
    1019         rc = folder->initCopy(this, *it);
     1042        ComObjPtr<SharedFolder> pFolder;
     1043        pFolder.createObject();
     1044        rc = pFolder->initCopy(this, *it);
    10201045        if (FAILED(rc)) return rc;
    1021         *it = folder;
    1022     }
    1023 
    1024     /* associate hard disks with the snapshot
    1025      * (Machine::uninitDataAndChildObjects() will deassociate at destruction) */
    1026     for (MediaData::AttachmentList::const_iterator it = mMediaData->mAttachments.begin();
    1027          it != mMediaData->mAttachments.end();
     1046        *it = pFolder;
     1047    }
     1048
     1049    /* create copies of all PCI device assignments (mHWData after attaching
     1050     * a copy contains just references to original objects) */
     1051    for (HWData::PCIDeviceAssignmentList::iterator
     1052         it = mHWData->mPCIDeviceAssignments.begin();
     1053         it != mHWData->mPCIDeviceAssignments.end();
    10281054         ++it)
    10291055    {
    1030         MediumAttachment *pAtt = *it;
    1031         Medium *pMedium = pAtt->i_getMedium();
    1032         if (pMedium) // can be NULL for non-harddisk
    1033         {
    1034             rc = pMedium->i_addBackReference(mData->mUuid, mSnapshotId);
    1035             AssertComRC(rc);
    1036         }
     1056        ComObjPtr<PCIDeviceAttachment> pDev;
     1057        pDev.createObject();
     1058        rc = pDev->initCopy(this, *it);
     1059        if (FAILED(rc)) return rc;
     1060        *it = pDev;
    10371061    }
    10381062
     
    10471071        ComObjPtr<StorageController> ctrl;
    10481072        ctrl.createObject();
    1049         ctrl->initCopy(this, *it);
     1073        rc = ctrl->initCopy(this, *it);
     1074        if (FAILED(rc)) return rc;
    10501075        mStorageControllers->push_back(ctrl);
    10511076    }
     
    10541079
    10551080    unconst(mBIOSSettings).createObject();
    1056     mBIOSSettings->initCopy(this, pMachine->mBIOSSettings);
     1081    rc = mBIOSSettings->initCopy(this, pMachine->mBIOSSettings);
     1082    if (FAILED(rc)) return rc;
    10571083
    10581084    unconst(mVRDEServer).createObject();
    1059     mVRDEServer->initCopy(this, pMachine->mVRDEServer);
     1085    rc = mVRDEServer->initCopy(this, pMachine->mVRDEServer);
     1086    if (FAILED(rc)) return rc;
    10601087
    10611088    unconst(mAudioAdapter).createObject();
    1062     mAudioAdapter->initCopy(this, pMachine->mAudioAdapter);
     1089    rc = mAudioAdapter->initCopy(this, pMachine->mAudioAdapter);
     1090    if (FAILED(rc)) return rc;
    10631091
    10641092    /* create copies of all USB controllers (mUSBControllerData
     
    10721100        ComObjPtr<USBController> ctrl;
    10731101        ctrl.createObject();
    1074         ctrl->initCopy(this, *it);
     1102        rc = ctrl->initCopy(this, *it);
     1103        if (FAILED(rc)) return rc;
    10751104        mUSBControllers->push_back(ctrl);
    10761105    }
    10771106
    10781107    unconst(mUSBDeviceFilters).createObject();
    1079     mUSBDeviceFilters->initCopy(this, pMachine->mUSBDeviceFilters);
     1108    rc = mUSBDeviceFilters->initCopy(this, pMachine->mUSBDeviceFilters);
     1109    if (FAILED(rc)) return rc;
    10801110
    10811111    mNetworkAdapters.resize(pMachine->mNetworkAdapters.size());
     
    10831113    {
    10841114        unconst(mNetworkAdapters[slot]).createObject();
    1085         mNetworkAdapters[slot]->initCopy(this, pMachine->mNetworkAdapters[slot]);
     1115        rc = mNetworkAdapters[slot]->initCopy(this, pMachine->mNetworkAdapters[slot]);
     1116        if (FAILED(rc)) return rc;
    10861117    }
    10871118
     
    10891120    {
    10901121        unconst(mSerialPorts[slot]).createObject();
    1091         mSerialPorts[slot]->initCopy(this, pMachine->mSerialPorts[slot]);
     1122        rc = mSerialPorts[slot]->initCopy(this, pMachine->mSerialPorts[slot]);
     1123        if (FAILED(rc)) return rc;
    10921124    }
    10931125
     
    10951127    {
    10961128        unconst(mParallelPorts[slot]).createObject();
    1097         mParallelPorts[slot]->initCopy(this, pMachine->mParallelPorts[slot]);
     1129        rc = mParallelPorts[slot]->initCopy(this, pMachine->mParallelPorts[slot]);
     1130        if (FAILED(rc)) return rc;
    10981131    }
    10991132
    11001133    unconst(mBandwidthControl).createObject();
    1101     mBandwidthControl->initCopy(this, pMachine->mBandwidthControl);
     1134    rc = mBandwidthControl->initCopy(this, pMachine->mBandwidthControl);
     1135    if (FAILED(rc)) return rc;
    11021136
    11031137    /* Confirm a successful initialization when it's the case */
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