VirtualBox

Changeset 24579 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Nov 11, 2009 1:50:27 PM (15 years ago)
Author:
vboxsync
Message:

Main/Console: fix taking snapshots of a VM with several hard disk attachments, a
nd deal correctly with DVD/floppy drives. Plus a bit of cleanup/renaming.

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

Legend:

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

    r24558 r24579  
    26962696
    26972697
    2698 const char *Console::controllerTypeToDev(StorageControllerType_T enmCtrlType)
     2698/* static */
     2699const char *Console::convertControllerTypeToDev(StorageControllerType_T enmCtrlType)
    26992700{
    27002701    switch (enmCtrlType)
     
    27922793    rc = ctrl->COMGETTER(ControllerType)(&enmCtrlType);
    27932794    AssertComRC(rc);
    2794     pszDevice = controllerTypeToDev(enmCtrlType);
     2795    pszDevice = convertControllerTypeToDev(enmCtrlType);
    27952796
    27962797    /** @todo support multiple instances of a controller */
     
    70007001
    70017002/**
    7002  * Reconfigures a VDI.
     7003 * Reconfigures a medium attachment (part of taking an online snapshot).
    70037004 *
    70047005 * @param   pVM           The VM handle.
    70057006 * @param   lInstance     The instance of the controller.
    70067007 * @param   enmController The type of the controller.
    7007  * @param   hda           The harddisk attachment.
     7008 * @param   enmBus        The storage bus type of the controller.
     7009 * @param   aMediumAtt    The medium attachment.
    70087010 * @param   phrc          Where to store com error - only valid if we return VERR_GENERAL_FAILURE.
    70097011 * @return  VBox status code.
    70107012 */
    7011 static DECLCALLBACK(int) reconfigureHardDisks(PVM pVM, ULONG lInstance,
    7012                                               StorageControllerType_T enmController,
    7013                                               IMediumAttachment *hda,
    7014                                               HRESULT *phrc)
    7015 {
    7016     LogFlowFunc(("pVM=%p hda=%p phrc=%p\n", pVM, hda, phrc));
     7013static DECLCALLBACK(int) reconfigureMedium(PVM pVM, ULONG lInstance,
     7014                                           StorageControllerType_T enmController,
     7015                                           StorageBus_T enmBus,
     7016                                           IMediumAttachment *aMediumAtt,
     7017                                           HRESULT *phrc)
     7018{
     7019    LogFlowFunc(("pVM=%p aMediumAtt=%p phrc=%p\n", pVM, aMediumAtt, phrc));
    70177020
    70187021    int             rc;
     
    70247027
    70257028    /*
    7026      * Figure out which IDE device this is.
     7029     * Figure out medium and other attachment details.
    70277030     */
    7028     ComPtr<IMedium> hardDisk;
    7029     hrc = hda->COMGETTER(Medium)(hardDisk.asOutParam());                      H();
     7031    ComPtr<IMedium> medium;
     7032    hrc = aMediumAtt->COMGETTER(Medium)(medium.asOutParam());                   H();
    70307033    LONG lDev;
    7031     hrc = hda->COMGETTER(Device)(&lDev);                                        H();
     7034    hrc = aMediumAtt->COMGETTER(Device)(&lDev);                                 H();
    70327035    LONG lPort;
    7033     hrc = hda->COMGETTER(Port)(&lPort);                                         H();
    7034 
    7035     int         iLUN;
    7036     const char *pcszDevice = NULL;
    7037     bool        fSCSI = false;
    7038 
    7039     switch (enmController)
    7040     {
    7041         case StorageControllerType_PIIX3:
    7042         case StorageControllerType_PIIX4:
    7043         case StorageControllerType_ICH6:
    7044         {
    7045             if (lPort >= 2 || lPort < 0)
    7046             {
    7047                 AssertMsgFailed(("invalid controller channel number: %d\n", lPort));
    7048                 return VERR_GENERAL_FAILURE;
    7049             }
    7050 
    7051             if (lDev >= 2 || lDev < 0)
    7052             {
    7053                 AssertMsgFailed(("invalid controller device number: %d\n", lDev));
    7054                 return VERR_GENERAL_FAILURE;
    7055             }
    7056 
    7057             iLUN = 2*lPort + lDev;
    7058             pcszDevice = "piix3ide";
    7059             break;
    7060         }
    7061         case StorageControllerType_IntelAhci:
    7062         {
    7063             iLUN = lPort;
    7064             pcszDevice = "ahci";
    7065             break;
    7066         }
    7067         case StorageControllerType_BusLogic:
    7068         {
    7069             iLUN = lPort;
    7070             pcszDevice = "buslogic";
    7071             fSCSI = true;
    7072             break;
    7073         }
    7074         case StorageControllerType_LsiLogic:
    7075         {
    7076             iLUN = lPort;
    7077             pcszDevice = "lsilogicscsi";
    7078             fSCSI = true;
    7079             break;
    7080         }
    7081         default:
    7082         {
    7083             AssertMsgFailed(("invalid disk controller type: %d\n", enmController));
    7084             return VERR_GENERAL_FAILURE;
    7085         }
    7086     }
     7036    hrc = aMediumAtt->COMGETTER(Port)(&lPort);                                  H();
     7037    DeviceType_T lType;
     7038    hrc = aMediumAtt->COMGETTER(Type)(&lType);                                  H();
     7039
     7040    unsigned iLUN;
     7041    const char *pcszDevice = Console::convertControllerTypeToDev(enmController);
     7042    AssertMsgReturn(pcszDevice, ("invalid disk controller type: %d\n", enmController), VERR_GENERAL_FAILURE);
     7043    hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, iLUN);        H();
     7044
     7045    /* Ignore attachments other than hard disks, since at the moment they are
     7046     * not subject to snapshotting in general. */
     7047    if (lType != DeviceType_HardDisk || medium.isNull())
     7048        return VINF_SUCCESS;
    70877049
    70887050    /** @todo this should be unified with the relevant part of
     
    70917053    /*
    70927054     * Is there an existing LUN? If not create it.
    7093      * We ASSUME that this will NEVER collide with the DVD.
    70947055     */
    70957056    PCFGMNODE pCfg;
     
    70977058
    70987059    /* SCSI has an extra driver between the device and the block driver. */
    7099     if (fSCSI)
    7100         pLunL1 = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/LUN#%d/AttachedDriver/AttachedDriver/", pcszDevice, lInstance, iLUN);
     7060    if (enmBus == StorageBus_SCSI)
     7061        pLunL1 = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/LUN#%u/AttachedDriver/AttachedDriver/", pcszDevice, lInstance, iLUN);
    71017062    else
    7102         pLunL1 = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/LUN#%d/AttachedDriver/", pcszDevice, lInstance, iLUN);
     7063        pLunL1 = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/LUN#%u/AttachedDriver/", pcszDevice, lInstance, iLUN);
    71037064
    71047065    if (!pLunL1)
     
    71087069
    71097070        PCFGMNODE pLunL0;
    7110         rc = CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%d", iLUN);                     RC_CHECK();
    7111 
    7112         if (fSCSI)
     7071        rc = CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%u", iLUN);                     RC_CHECK();
     7072
     7073        if (enmBus == StorageBus_SCSI)
    71137074        {
    71147075            rc = CFGMR3InsertString(pLunL0, "Driver",              "SCSI");             RC_CHECK();
     
    71557116     * Create the driver configuration.
    71567117     */
    7157     hrc = hardDisk->COMGETTER(Location)(bstr.asOutParam());                     H();
    7158     LogFlowFunc(("LUN#%d: leaf location '%ls'\n", iLUN, bstr.raw()));
     7118    hrc = medium->COMGETTER(Location)(bstr.asOutParam());                       H();
     7119    LogFlowFunc(("LUN#%u: leaf location '%ls'\n", iLUN, bstr.raw()));
    71597120    rc = CFGMR3InsertString(pCfg, "Path", Utf8Str(bstr).c_str());                       RC_CHECK();
    7160     hrc = hardDisk->COMGETTER(Format)(bstr.asOutParam());                       H();
    7161     LogFlowFunc(("LUN#%d: leaf format '%ls'\n", iLUN, bstr.raw()));
     7121    hrc = medium->COMGETTER(Format)(bstr.asOutParam());                         H();
     7122    LogFlowFunc(("LUN#%u: leaf format '%ls'\n", iLUN, bstr.raw()));
    71627123    rc = CFGMR3InsertString(pCfg, "Format", Utf8Str(bstr).c_str());                     RC_CHECK();
    71637124
     
    71667127    SafeArray<BSTR> names;
    71677128    SafeArray<BSTR> values;
    7168     hrc = hardDisk->GetProperties(NULL,
    7169                                   ComSafeArrayAsOutParam(names),
    7170                                   ComSafeArrayAsOutParam(values));      H();
     7129    hrc = medium->GetProperties(NULL,
     7130                                ComSafeArrayAsOutParam(names),
     7131                                ComSafeArrayAsOutParam(values));        H();
    71717132
    71727133    if (names.size() != 0)
     
    71897150
    71907151    /* Create an inversed tree of parents. */
    7191     ComPtr<IMedium> parentHardDisk = hardDisk;
     7152    ComPtr<IMedium> parentMedium = medium;
    71927153    for (PCFGMNODE pParent = pCfg;;)
    71937154    {
    7194         hrc = parentHardDisk->COMGETTER(Parent)(hardDisk.asOutParam());     H();
    7195         if (hardDisk.isNull())
     7155        hrc = parentMedium->COMGETTER(Parent)(medium.asOutParam());             H();
     7156        if (medium.isNull())
    71967157            break;
    71977158
    71987159        PCFGMNODE pCur;
    71997160        rc = CFGMR3InsertNode(pParent, "Parent", &pCur);                        RC_CHECK();
    7200         hrc = hardDisk->COMGETTER(Location)(bstr.asOutParam());                 H();
     7161        hrc = medium->COMGETTER(Location)(bstr.asOutParam());                   H();
    72017162        rc = CFGMR3InsertString(pCur,  "Path", Utf8Str(bstr).c_str());          RC_CHECK();
    72027163
    7203         hrc = hardDisk->COMGETTER(Format)(bstr.asOutParam());                   H();
     7164        hrc = medium->COMGETTER(Format)(bstr.asOutParam());                     H();
    72047165        rc = CFGMR3InsertString(pCur,  "Format", Utf8Str(bstr).c_str());        RC_CHECK();
    72057166
     
    72077168        SafeArray<BSTR> names;
    72087169        SafeArray<BSTR> values;
    7209         hrc = hardDisk->GetProperties(NULL,
    7210                                       ComSafeArrayAsOutParam(names),
    7211                                       ComSafeArrayAsOutParam(values));  H();
     7170        hrc = medium->GetProperties(NULL,
     7171                                    ComSafeArrayAsOutParam(names),
     7172                                    ComSafeArrayAsOutParam(values));            H();
    72127173
    72137174        if (names.size() != 0)
     
    72297190        }
    72307191
    7231 
    72327192        /* Custom code: put marker to not use host IP stack to driver
    72337193        * configuration node. Simplifies life of DrvVD a bit. */
     
    72407200        /* next */
    72417201        pParent = pCur;
    7242         parentHardDisk = hardDisk;
     7202        parentMedium = medium;
    72437203    }
    72447204
     
    73377297            LogFlowFunc(("Reattaching new differencing hard disks...\n"));
    73387298
    7339             pTask->mProgress->SetNextOperation(Bstr(tr("Reconfiguring hard disks")),
     7299            pTask->mProgress->SetNextOperation(Bstr(tr("Reconfiguring medium attachments")),
    73407300                                               1);       // operation weight, same as computed when setting up progress object
    73417301
     
    73527312                ULONG lInstance;
    73537313                StorageControllerType_T enmController;
     7314                StorageBus_T enmBus;
    73547315
    73557316                /*
     
    73597320                */
    73607321                rc = atts[i]->COMGETTER(Controller)(&controllerName);
    7361                 if (FAILED(rc))
    7362                     break;
     7322                if (FAILED(rc)) throw rc;
    73637323
    73647324                rc = that->mMachine->GetStorageControllerByName(controllerName, controller.asOutParam());
     
    73667326
    73677327                rc = controller->COMGETTER(ControllerType)(&enmController);
     7328                if (FAILED(rc)) throw rc;
    73687329                rc = controller->COMGETTER(Instance)(&lInstance);
     7330                if (FAILED(rc)) throw rc;
     7331                rc = controller->COMGETTER(Bus)(&enmBus);
     7332                if (FAILED(rc)) throw rc;
    73697333
    73707334                /*
    7371                  * don't leave the lock since reconfigureHardDisks isn't going
     7335                 * don't leave the lock since reconfigureMedium isn't going
    73727336                 * to access Console.
    73737337                 */
    73747338                int vrc = VMR3ReqCallWait(that->mpVM,
    73757339                                          VMCPUID_ANY,
    7376                                           (PFNRT)reconfigureHardDisks,
    7377                                           5,
     7340                                          (PFNRT)reconfigureMedium,
     7341                                          6,
    73787342                                          that->mpVM,
    73797343                                          lInstance,
    73807344                                          enmController,
     7345                                          enmBus,
    73817346                                          atts[i],
    73827347                                          &rc);
     
    73847349                    throw setError(E_FAIL, Console::tr("%Rrc"), vrc);
    73857350                if (FAILED(rc)) throw rc;
    7386                     break;
    7387                 if (FAILED(rc))
    7388                     break;
    73897351            }
    73907352        }
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r24546 r24579  
    809809
    810810        /* /Devices/<ctrldev>/ */
    811         const char *pszCtrlDev = pConsole->controllerTypeToDev(enmCtrlType);
     811        const char *pszCtrlDev = pConsole->convertControllerTypeToDev(enmCtrlType);
    812812        pDev = aCtrlNodes[enmCtrlType];
    813813        if (!pDev)
     
    825825        rc = CFGMR3InsertNode(pCtlInst,    "Config",    &pCfg);                                 RC_CHECK();
    826826
    827         bool fSCSI = false;
    828827        switch (enmCtrlType)
    829828        {
     
    834833                afPciDeviceNo[20] = true;
    835834                rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo",        0);                  RC_CHECK();
    836                 fSCSI = true;
    837835
    838836                /* Attach the status driver */
     
    852850                afPciDeviceNo[21] = true;
    853851                rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo",        0);                  RC_CHECK();
    854                 fSCSI = true;
    855852
    856853                /* Attach the status driver */
     
    961958        }
    962959
    963         /* Attach the hard disks. */
     960        /* Attach the media to the storage controllers. */
    964961        com::SafeIfaceArray<IMediumAttachment> atts;
    965962        hrc = pMachine->GetMediumAttachmentsOfController(controllerName,
     
    982979
    983980            /* SCSI has a another driver between device and block. */
    984             if (fSCSI)
     981            if (enmBus == StorageBus_SCSI)
    985982            {
    986983                rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI");                              RC_CHECK();
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r24493 r24579  
    223223    }
    224224
     225    static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
     226    static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
     227
    225228    // for VirtualBoxSupportErrorInfoImpl
    226229    static const wchar_t *getComponentName() { return L"Console"; }
     
    443446                                          const char *pszFormat, bool fPassthrough,
    444447                                          bool fForce);
    445     const char *controllerTypeToDev(StorageControllerType_T enmCtrlType);
    446     HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
    447448    HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce);
    448449
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