VirtualBox

Ignore:
Timestamp:
Apr 26, 2010 7:37:29 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60601
Message:

Main/Console: clean up CFGM handling for medium attachments, make one implementation out of 2.5 previous ones

File:
1 edited

Legend:

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

    r28580 r28727  
    231231                                    empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
    232232    if (RT_FAILURE(rc))
    233         AssertComRCReturn (rc, VERR_FILE_NOT_FOUND);
     233        AssertComRCReturn(rc, VERR_FILE_NOT_FOUND);
    234234
    235235    if (!fPresent)
     
    279279    BOOL fIs64BitGuest = false;
    280280
    281 #if !defined (VBOX_WITH_XPCOM)
     281#if !defined(VBOX_WITH_XPCOM)
    282282    {
    283283        /* initialize COM */
     
    285285                                     COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
    286286                                     COINIT_SPEED_OVER_MEMORY);
    287         LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
    288         AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
     287        LogFlow(("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
     288        AssertComRCReturn(hrc, VERR_GENERAL_FAILURE);
    289289    }
    290290#endif
    291291
    292292    AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
    293     ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
     293    ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
    294294
    295295    AutoCaller autoCaller(pConsole);
    296     AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
     296    AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
    297297
    298298    /* lock the console because we widely use internal fields and methods */
     
    933933        if (SchemaDefs::MaxBootPosition > 9)
    934934        {
    935             AssertMsgFailed (("Too many boot devices %d\n",
    936                               SchemaDefs::MaxBootPosition));
     935            AssertMsgFailed(("Too many boot devices %d\n",
     936                             SchemaDefs::MaxBootPosition));
    937937            return VERR_INVALID_PARAMETER;
    938938        }
     
    943943
    944944            char szParamName[] = "BootDeviceX";
    945             szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
     945            szParamName[sizeof(szParamName) - 2] = ((char (pos - 1)) + '0');
    946946
    947947            const char *pszBootDevice;
     
    12601260        for (size_t j = 0; j < atts.size(); ++j)
    12611261        {
    1262             ComPtr<IMedium> medium;
    1263             hrc = atts[j]->COMGETTER(Medium)(medium.asOutParam());                              H();
    1264             LONG lDev;
    1265             hrc = atts[j]->COMGETTER(Device)(&lDev);                                            H();
    1266             LONG lPort;
    1267             hrc = atts[j]->COMGETTER(Port)(&lPort);                                             H();
    1268             DeviceType_T lType;
    1269             hrc = atts[j]->COMGETTER(Type)(&lType);                                             H();
    1270 
    1271             unsigned uLUN;
    1272             hrc = pConsole->convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN);               H();
    1273             rc = CFGMR3InsertNodeF(pCtlInst, &pLunL0, "LUN#%u", uLUN);                          RC_CHECK();
    1274 
    1275             /* SCSI has a another driver between device and block. */
    1276             if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
    1277             {
    1278                 rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI");                              RC_CHECK();
    1279                 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                                 RC_CHECK();
    1280 
    1281                 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);                       RC_CHECK();
    1282             }
    1283 
    1284             BOOL fHostDrive = FALSE;
    1285             if (!medium.isNull())
    1286             {
    1287                 hrc = medium->COMGETTER(HostDrive)(&fHostDrive);                                H();
    1288             }
    1289 
    1290             if (fHostDrive)
    1291             {
    1292                 Assert(!medium.isNull());
    1293                 if (lType == DeviceType_DVD)
    1294                 {
    1295                     rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD");                       RC_CHECK();
    1296                     rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                             RC_CHECK();
    1297 
    1298                     hrc = medium->COMGETTER(Location)(&str);                                    H();
    1299                     rc = CFGMR3InsertStringW(pCfg, "Path", str);                                RC_CHECK();
    1300                     STR_FREE();
    1301 
    1302                     BOOL fPassthrough;
    1303                     hrc = atts[j]->COMGETTER(Passthrough)(&fPassthrough);                       H();
    1304                     rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough);              RC_CHECK();
    1305                 }
    1306                 else if (lType == DeviceType_Floppy)
    1307                 {
    1308                     rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy");                    RC_CHECK();
    1309                     rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                             RC_CHECK();
    1310 
    1311                     hrc = medium->COMGETTER(Location)(&str);                                    H();
    1312                     rc = CFGMR3InsertStringW(pCfg, "Path", str);                                RC_CHECK();
    1313                     STR_FREE();
    1314                 }
    1315             }
    1316             else
    1317             {
    1318                 rc = CFGMR3InsertString(pLunL0, "Driver", "Block");                             RC_CHECK();
    1319                 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                                 RC_CHECK();
    1320                 switch (lType)
    1321                 {
    1322                     case DeviceType_DVD:
    1323                         rc = CFGMR3InsertString(pCfg, "Type", "DVD");                           RC_CHECK();
    1324                         rc = CFGMR3InsertInteger(pCfg, "Mountable", 1);                         RC_CHECK();
    1325                         break;
    1326                     case DeviceType_Floppy:
    1327                         rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44");                   RC_CHECK();
    1328                         rc = CFGMR3InsertInteger(pCfg, "Mountable", 1);                         RC_CHECK();
    1329                         break;
    1330                     case DeviceType_HardDisk:
    1331                     default:
    1332                         rc = CFGMR3InsertString(pCfg, "Type", "HardDisk");                      RC_CHECK();
    1333                         rc = CFGMR3InsertInteger(pCfg, "Mountable", 0);                         RC_CHECK();
    1334                 }
    1335 
    1336                 if (!medium.isNull())
    1337                 {
    1338                     rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1);                   RC_CHECK();
    1339                     rc = CFGMR3InsertString(pLunL1, "Driver", "VD");                            RC_CHECK();
    1340                     rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg);                             RC_CHECK();
    1341 
    1342                     hrc = medium->COMGETTER(Location)(&str);                                    H();
    1343                     rc = CFGMR3InsertStringW(pCfg, "Path", str);                                RC_CHECK();
    1344                     STR_FREE();
    1345 
    1346                     hrc = medium->COMGETTER(Format)(&str);                                      H();
    1347                     rc = CFGMR3InsertStringW(pCfg, "Format", str);                              RC_CHECK();
    1348                     STR_FREE();
    1349 
    1350                     /* DVDs are always readonly */
    1351                     if (lType == DeviceType_DVD)
    1352                     {
    1353                         rc = CFGMR3InsertInteger(pCfg, "ReadOnly", 1);                          RC_CHECK();
    1354                     }
    1355                     /* Start without exclusive write access to the images. */
    1356                     /** @todo Live Migration: I don't quite like this, we risk screwing up when
    1357                      *        we're resuming the VM if some 3rd dude have any of the VDIs open
    1358                      *        with write sharing denied.  However, if the two VMs are sharing a
    1359                      *        image it really is necessary....
    1360                      *
    1361                      *        So, on the "lock-media" command, the target teleporter should also
    1362                      *        make DrvVD undo TempReadOnly.  It gets interesting if we fail after
    1363                      *        that. Grumble. */
    1364                     else if (pConsole->mMachineState == MachineState_TeleportingIn)
    1365                     {
    1366                         rc = CFGMR3InsertInteger(pCfg, "TempReadOnly", 1);                      RC_CHECK();
    1367                     }
    1368 
    1369                     /* Pass all custom parameters. */
    1370                     bool fHostIP = true;
    1371                     SafeArray<BSTR> names;
    1372                     SafeArray<BSTR> values;
    1373                     hrc = medium->GetProperties(NULL,
    1374                                                 ComSafeArrayAsOutParam(names),
    1375                                                 ComSafeArrayAsOutParam(values));                H();
    1376 
    1377                     if (names.size() != 0)
    1378                     {
    1379                         PCFGMNODE pVDC;
    1380                         rc = CFGMR3InsertNode(pCfg, "VDConfig", &pVDC);                         RC_CHECK();
    1381                         for (size_t ii = 0; ii < names.size(); ++ii)
    1382                         {
    1383                             if (values[ii] && *values[ii])
    1384                             {
    1385                                 Utf8Str name = names[ii];
    1386                                 Utf8Str value = values[ii];
    1387                                 rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str());     RC_CHECK();
    1388                                 if (    name.compare("HostIPStack") == 0
    1389                                     &&  value.compare("0") == 0)
    1390                                     fHostIP = false;
    1391                             }
    1392                         }
    1393                     }
    1394 
    1395                     /* Create an inversed tree of parents. */
    1396                     ComPtr<IMedium> parentMedium = medium;
    1397                     for (PCFGMNODE pParent = pCfg;;)
    1398                     {
    1399                         hrc = parentMedium->COMGETTER(Parent)(medium.asOutParam());             H();
    1400                         if (medium.isNull())
    1401                             break;
    1402 
    1403                         PCFGMNODE pCur;
    1404                         rc = CFGMR3InsertNode(pParent, "Parent", &pCur);                        RC_CHECK();
    1405                         hrc = medium->COMGETTER(Location)(&str);                                H();
    1406                         rc = CFGMR3InsertStringW(pCur, "Path", str);                            RC_CHECK();
    1407                         STR_FREE();
    1408 
    1409                         hrc = medium->COMGETTER(Format)(&str);                                  H();
    1410                         rc = CFGMR3InsertStringW(pCur, "Format", str);                          RC_CHECK();
    1411                         STR_FREE();
    1412 
    1413                         /* Pass all custom parameters. */
    1414                         SafeArray<BSTR> aNames;
    1415                         SafeArray<BSTR> aValues;
    1416                         hrc = medium->GetProperties(NULL,
    1417                                                     ComSafeArrayAsOutParam(aNames),
    1418                                                     ComSafeArrayAsOutParam(aValues));           H();
    1419 
    1420                         if (aNames.size() != 0)
    1421                         {
    1422                             PCFGMNODE pVDC;
    1423                             rc = CFGMR3InsertNode(pCur, "VDConfig", &pVDC);                     RC_CHECK();
    1424                             for (size_t ii = 0; ii < aNames.size(); ++ii)
    1425                             {
    1426                                 if (aValues[ii] && *aValues[ii])
    1427                                 {
    1428                                     Utf8Str name = aNames[ii];
    1429                                     Utf8Str value = aValues[ii];
    1430                                     rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str()); RC_CHECK();
    1431                                     if (    name.compare("HostIPStack") == 0
    1432                                         &&  value.compare("0") == 0)
    1433                                         fHostIP = false;
    1434                                 }
    1435                             }
    1436                         }
    1437 
    1438                         /* Custom code: put marker to not use host IP stack to driver
    1439                          * configuration node. Simplifies life of DrvVD a bit. */
    1440                         if (!fHostIP)
    1441                         {
    1442                             rc = CFGMR3InsertInteger(pCfg, "HostIPStack", 0);                   RC_CHECK();
    1443                         }
    1444 
    1445                         /* next */
    1446                         pParent = pCur;
    1447                         parentMedium = medium;
    1448                     }
    1449                 }
    1450             }
    1451 
    1452             if (paLedDevType)
    1453                 paLedDevType[uLUN] = lType;
     1262            rc = Console::configMediumAttachment(pCtlInst, pszCtrlDev,
     1263                                                 ulInstance, enmBus, atts[j],
     1264                                                 pConsole->mMachineState,
     1265                                                 NULL /* phrc */,
     1266                                                 false /* fAttachDetach */,
     1267                                                 false /* fForceUnmount */,
     1268                                                 NULL /* pVM */,
     1269                                                 paLedDevType);                                 RC_CHECK();
    14541270        }
    14551271        H();
     
    16371453         * Configure the network card now
    16381454         */
    1639         rc = configNetwork(pConsole, pszAdapterName, ulInstance, 0, networkAdapter,
    1640                            pCfg, pLunL0, pInst, false /*fAttachDetach*/);           RC_CHECK();
     1455        rc = pConsole->configNetwork(pszAdapterName, ulInstance, 0,
     1456                                     networkAdapter, pCfg, pLunL0, pInst,
     1457                                     false /*fAttachDetach*/);                      RC_CHECK();
    16411458    }
    16421459
     
    16731490    {
    16741491        ComPtr<ISerialPort> serialPort;
    1675         hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam());        H();
     1492        hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam());        H();
    16761493        BOOL fEnabled = FALSE;
    16771494        if (serialPort)
     
    19011718# endif
    19021719#endif /* RT_OS_LINUX */
    1903 #if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
     1720#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
    19041721            case AudioDriverType_OSS:
    19051722            {
     
    21021919        {
    21031920            /* Load the service */
    2104             rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
     1921            rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedClipboard", "VBoxSharedClipboard");
    21051922
    21061923            if (RT_FAILURE(rc))
     
    21461963                }
    21471964
    2148                 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
     1965                pConsole->mVMMDev->hgcmHostCall("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
    21491966
    21501967                Log(("Set VBoxSharedClipboard mode\n"));
     
    21641981        {
    21651982            /* Load the service */
    2166             rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
     1983            rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
    21671984            if (RT_FAILURE(rc))
    21681985            {
     
    24222239
    24232240    /* Register VM state change handler */
    2424     int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
     2241    int rc2 = VMR3AtStateRegister(pVM, Console::vmstateChangeCallback, pConsole);
    24252242    AssertRC(rc2);
    24262243    if (RT_SUCCESS(rc))
     
    24282245
    24292246    /* Register VM runtime error handler */
    2430     rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
     2247    rc2 = VMR3AtRuntimeErrorRegister(pVM, Console::setVMRuntimeErrorCallback, pConsole);
    24312248    AssertRC(rc2);
    24322249    if (RT_SUCCESS(rc))
    24332250        rc = rc2;
    24342251
    2435     LogFlowFunc (("vrc = %Rrc\n", rc));
     2252    LogFlowFunc(("vrc = %Rrc\n", rc));
    24362253    LogFlowFuncLeave();
    24372254
     
    24502267}
    24512268
     2269/* static */
     2270int Console::configMediumAttachment(PCFGMNODE pCtlInst, const char *pcszDevice,
     2271                                    unsigned uInstance, StorageBus_T enmBus,
     2272                                    IMediumAttachment *pMediumAtt,
     2273                                    MachineState_T aMachineState,
     2274                                    HRESULT *phrc, bool fAttachDetach,
     2275                                    bool fForceUnmount, PVM pVM,
     2276                                    DeviceType_T *paLedDevType)
     2277{
     2278    int rc = VINF_SUCCESS;
     2279    HRESULT hrc;
     2280    BSTR str = NULL;
     2281
     2282#define STR_FREE()  do { if (str) { SysFreeString(str); str = NULL; } } while (0)
     2283#define RC_CHECK()  do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc));  STR_FREE(); return rc;                   } } while (0)
     2284#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
     2285
     2286    LONG lDev;
     2287    hrc = pMediumAtt->COMGETTER(Device)(&lDev);                         H();
     2288    LONG lPort;
     2289    hrc = pMediumAtt->COMGETTER(Port)(&lPort);                          H();
     2290    DeviceType_T lType;
     2291    hrc = pMediumAtt->COMGETTER(Type)(&lType);                          H();
     2292
     2293    unsigned uLUN;
     2294    PCFGMNODE pLunL0 = NULL;
     2295    PCFGMNODE pCfg = NULL;
     2296    hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN);    H();
     2297
     2298    /* First check if the LUN already exists. */
     2299    pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
     2300    if (pLunL0)
     2301    {
     2302        if (fAttachDetach)
     2303        {
     2304            if (lType != DeviceType_HardDisk)
     2305            {
     2306                /* Unmount existing media only for floppy and DVD drives. */
     2307                PPDMIBASE pBase;
     2308                rc = PDMR3QueryLun(pVM, pcszDevice, uInstance, uLUN, &pBase);
     2309                if (RT_FAILURE(rc))
     2310                {
     2311                    if (rc == VERR_PDM_LUN_NOT_FOUND || rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
     2312                        rc = VINF_SUCCESS;
     2313                    AssertRC(rc);
     2314                }
     2315                else
     2316                {
     2317                    PPDMIMOUNT pIMount = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMOUNT);
     2318                    AssertReturn(pIMount, VERR_INVALID_POINTER);
     2319
     2320                    /* Unmount the media. */
     2321                    rc = pIMount->pfnUnmount(pIMount, fForceUnmount);
     2322                    if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
     2323                        rc = VINF_SUCCESS;
     2324                }
     2325            }
     2326
     2327            rc = PDMR3DeviceDetach(pVM, pcszDevice, 0, uLUN, PDM_TACH_FLAGS_NOT_HOT_PLUG);
     2328            if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
     2329                rc = VINF_SUCCESS;
     2330            RC_CHECK();
     2331
     2332            CFGMR3RemoveNode(pLunL0);
     2333        }
     2334        else
     2335            AssertFailedReturn(VERR_INTERNAL_ERROR);
     2336    }
     2337
     2338    rc = CFGMR3InsertNodeF(pCtlInst, &pLunL0, "LUN#%u", uLUN);              RC_CHECK();
     2339
     2340    /* SCSI has a another driver between device and block. */
     2341    if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
     2342    {
     2343        rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI");              RC_CHECK();
     2344        rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                 RC_CHECK();
     2345
     2346        rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);       RC_CHECK();
     2347    }
     2348
     2349    ComPtr<IMedium> pMedium;
     2350    hrc = pMediumAtt->COMGETTER(Medium)(pMedium.asOutParam());          H();
     2351    BOOL fPassthrough;
     2352    hrc = pMediumAtt->COMGETTER(Passthrough)(&fPassthrough);            H();
     2353    rc = Console::configMedium(pLunL0, !!fPassthrough, lType,
     2354                               pMedium, aMachineState, phrc);           RC_CHECK();
     2355
     2356    if (fAttachDetach)
     2357    {
     2358        /* Attach the new driver. */
     2359        rc = PDMR3DeviceAttach(pVM, pcszDevice, 0, uLUN,
     2360                               PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);   RC_CHECK();
     2361
     2362        /* There is no need to handle removable medium mounting, as we
     2363         * unconditionally replace everthing including the block driver level.
     2364         * This means the new medium will be picked up automatically. */
     2365    }
     2366
     2367    if (paLedDevType)
     2368        paLedDevType[uLUN] = lType;
     2369
     2370#undef STR_FREE
     2371#undef H
     2372#undef RC_CHECK
     2373
     2374    return VINF_SUCCESS;;
     2375}
     2376
     2377int Console::configMedium(PCFGMNODE pLunL0,
     2378                          bool fPassthrough,
     2379                          DeviceType_T enmType,
     2380                          IMedium *pMedium,
     2381                          MachineState_T aMachineState,
     2382                          HRESULT *phrc)
     2383{
     2384    int rc = VINF_SUCCESS;
     2385    HRESULT hrc;
     2386    BSTR str = NULL;
     2387
     2388#define STR_FREE()  do { if (str) { SysFreeString(str); str = NULL; } } while (0)
     2389#define RC_CHECK()  do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc));  STR_FREE(); return rc;                   } } while (0)
     2390#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); if (phrc) *phrc = hrc; return VERR_GENERAL_FAILURE; } } while (0)
     2391
     2392    PCFGMNODE pLunL1 = NULL;
     2393    PCFGMNODE pCfg = NULL;
     2394
     2395    BOOL fHostDrive = FALSE;
     2396    if (pMedium)
     2397    {
     2398        hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive);                               H();
     2399    }
     2400
     2401    if (fHostDrive)
     2402    {
     2403        Assert(pMedium);
     2404        if (enmType == DeviceType_DVD)
     2405        {
     2406            rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD");                       RC_CHECK();
     2407            rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                             RC_CHECK();
     2408
     2409            hrc = pMedium->COMGETTER(Location)(&str);                                   H();
     2410            rc = CFGMR3InsertStringW(pCfg, "Path", str);                                RC_CHECK();
     2411            STR_FREE();
     2412
     2413            rc = CFGMR3InsertInteger(pCfg, "Passthrough", fPassthrough);                RC_CHECK();
     2414        }
     2415        else if (enmType == DeviceType_Floppy)
     2416        {
     2417            rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy");                    RC_CHECK();
     2418            rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                             RC_CHECK();
     2419
     2420            hrc = pMedium->COMGETTER(Location)(&str);                                   H();
     2421            rc = CFGMR3InsertStringW(pCfg, "Path", str);                                RC_CHECK();
     2422            STR_FREE();
     2423        }
     2424    }
     2425    else
     2426    {
     2427        rc = CFGMR3InsertString(pLunL0, "Driver", "Block");                             RC_CHECK();
     2428        rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                                 RC_CHECK();
     2429        switch (enmType)
     2430        {
     2431            case DeviceType_DVD:
     2432                rc = CFGMR3InsertString(pCfg, "Type", "DVD");                           RC_CHECK();
     2433                rc = CFGMR3InsertInteger(pCfg, "Mountable", 1);                         RC_CHECK();
     2434                break;
     2435            case DeviceType_Floppy:
     2436                rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44");                   RC_CHECK();
     2437                rc = CFGMR3InsertInteger(pCfg, "Mountable", 1);                         RC_CHECK();
     2438                break;
     2439            case DeviceType_HardDisk:
     2440            default:
     2441                rc = CFGMR3InsertString(pCfg, "Type", "HardDisk");                      RC_CHECK();
     2442                rc = CFGMR3InsertInteger(pCfg, "Mountable", 0);                         RC_CHECK();
     2443        }
     2444
     2445        if (pMedium)
     2446        {
     2447            rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1);                   RC_CHECK();
     2448            rc = CFGMR3InsertString(pLunL1, "Driver", "VD");                            RC_CHECK();
     2449            rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg);                             RC_CHECK();
     2450
     2451            hrc = pMedium->COMGETTER(Location)(&str);                                   H();
     2452            rc = CFGMR3InsertStringW(pCfg, "Path", str);                                RC_CHECK();
     2453            STR_FREE();
     2454
     2455            hrc = pMedium->COMGETTER(Format)(&str);                                     H();
     2456            rc = CFGMR3InsertStringW(pCfg, "Format", str);                              RC_CHECK();
     2457            STR_FREE();
     2458
     2459            /* DVDs are always readonly */
     2460            if (enmType == DeviceType_DVD)
     2461            {
     2462                rc = CFGMR3InsertInteger(pCfg, "ReadOnly", 1);                          RC_CHECK();
     2463            }
     2464
     2465            /* Start without exclusive write access to the images. */
     2466            /** @todo Live Migration: I don't quite like this, we risk screwing up when
     2467             *        we're resuming the VM if some 3rd dude have any of the VDIs open
     2468             *        with write sharing denied.  However, if the two VMs are sharing a
     2469             *        image it really is necessary....
     2470             *
     2471             *        So, on the "lock-media" command, the target teleporter should also
     2472             *        make DrvVD undo TempReadOnly.  It gets interesting if we fail after
     2473             *        that. Grumble. */
     2474            else if (aMachineState == MachineState_TeleportingIn)
     2475            {
     2476                rc = CFGMR3InsertInteger(pCfg, "TempReadOnly", 1);                      RC_CHECK();
     2477            }
     2478
     2479            /* Pass all custom parameters. */
     2480            bool fHostIP = true;
     2481            SafeArray<BSTR> names;
     2482            SafeArray<BSTR> values;
     2483            hrc = pMedium->GetProperties(NULL,
     2484                                         ComSafeArrayAsOutParam(names),
     2485                                         ComSafeArrayAsOutParam(values));               H();
     2486
     2487            if (names.size() != 0)
     2488            {
     2489                PCFGMNODE pVDC;
     2490                rc = CFGMR3InsertNode(pCfg, "VDConfig", &pVDC);                         RC_CHECK();
     2491                for (size_t ii = 0; ii < names.size(); ++ii)
     2492                {
     2493                    if (values[ii] && *values[ii])
     2494                    {
     2495                        Utf8Str name = names[ii];
     2496                        Utf8Str value = values[ii];
     2497                        rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str());     RC_CHECK();
     2498                        if (    name.compare("HostIPStack") == 0
     2499                            &&  value.compare("0") == 0)
     2500                            fHostIP = false;
     2501                    }
     2502                }
     2503            }
     2504
     2505            /* Create an inversed tree of parents. */
     2506            IMedium *pParentMedium = pMedium;
     2507            for (PCFGMNODE pParent = pCfg;;)
     2508            {
     2509                hrc = pParentMedium->COMGETTER(Parent)(&pMedium);                       H();
     2510                if (!pMedium)
     2511                    break;
     2512
     2513                PCFGMNODE pCur;
     2514                rc = CFGMR3InsertNode(pParent, "Parent", &pCur);                        RC_CHECK();
     2515                hrc = pMedium->COMGETTER(Location)(&str);                               H();
     2516                rc = CFGMR3InsertStringW(pCur, "Path", str);                            RC_CHECK();
     2517                STR_FREE();
     2518
     2519                hrc = pMedium->COMGETTER(Format)(&str);                                 H();
     2520                rc = CFGMR3InsertStringW(pCur, "Format", str);                          RC_CHECK();
     2521                STR_FREE();
     2522
     2523                /* Pass all custom parameters. */
     2524                SafeArray<BSTR> aNames;
     2525                SafeArray<BSTR> aValues;
     2526                hrc = pMedium->GetProperties(NULL,
     2527                                             ComSafeArrayAsOutParam(aNames),
     2528                                             ComSafeArrayAsOutParam(aValues));          H();
     2529
     2530                if (aNames.size() != 0)
     2531                {
     2532                    PCFGMNODE pVDC;
     2533                    rc = CFGMR3InsertNode(pCur, "VDConfig", &pVDC);                     RC_CHECK();
     2534                    for (size_t ii = 0; ii < aNames.size(); ++ii)
     2535                    {
     2536                        if (aValues[ii] && *aValues[ii])
     2537                        {
     2538                            Utf8Str name = aNames[ii];
     2539                            Utf8Str value = aValues[ii];
     2540                            rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str()); RC_CHECK();
     2541                            if (    name.compare("HostIPStack") == 0
     2542                                &&  value.compare("0") == 0)
     2543                                fHostIP = false;
     2544                        }
     2545                    }
     2546                }
     2547
     2548                /* Custom code: put marker to not use host IP stack to driver
     2549                 * configuration node. Simplifies life of DrvVD a bit. */
     2550                if (!fHostIP)
     2551                {
     2552                    rc = CFGMR3InsertInteger(pCfg, "HostIPStack", 0);                   RC_CHECK();
     2553                }
     2554
     2555                /* next */
     2556                pParent = pCur;
     2557                pParentMedium = pMedium;
     2558            }
     2559        }
     2560    }
     2561
     2562#undef STR_FREE
     2563#undef H
     2564#undef RC_CHECK
     2565
     2566    return VINF_SUCCESS;
     2567}
     2568
    24522569/**
    24532570 *  Construct the Network configuration tree
     
    24552572 *  @returns VBox status code.
    24562573 *
    2457  *  @param   pThis               Pointer to the Console object.
    24582574 *  @param   pszDevice           The PDM device name.
    24592575 *  @param   uInstance           The PDM device instance.
     
    24672583 *                               configuration.
    24682584 *
    2469  *  @note Locks the Console object for writing.
     2585 *  @note Locks this object for writing.
    24702586 */
    2471 /*static*/ int Console::configNetwork(Console *pThis, const char *pszDevice,
    2472                                       unsigned uInstance, unsigned uLun,
    2473                                       INetworkAdapter *aNetworkAdapter,
    2474                                       PCFGMNODE pCfg, PCFGMNODE pLunL0,
    2475                                       PCFGMNODE pInst, bool fAttachDetach)
     2587int Console::configNetwork(const char *pszDevice, unsigned uInstance,
     2588                           unsigned uLun, INetworkAdapter *aNetworkAdapter,
     2589                           PCFGMNODE pCfg, PCFGMNODE pLunL0, PCFGMNODE pInst,
     2590                           bool fAttachDetach)
    24762591{
     2592    AutoCaller autoCaller(this);
     2593    AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
     2594
    24772595    int rc = VINF_SUCCESS;
    2478 
    2479     AutoCaller autoCaller(pThis);
    2480     AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
     2596    HRESULT hrc;
     2597    BSTR str = NULL;
     2598
     2599#define STR_FREE()  do { if (str) { SysFreeString(str); str = NULL; } } while (0)
     2600#define RC_CHECK()  do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc));  STR_FREE(); return rc;                   } } while (0)
     2601#define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
    24812602
    24822603    /*
     
    24852606     * meAttachmentType member.
    24862607     */
    2487     AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
    2488 
    2489     PVM     pVM = pThis->mpVM;
    2490     BSTR    str = NULL;
    2491 
    2492 #define STR_FREE()  do { if (str) { SysFreeString(str); str = NULL; } } while (0)
    2493 #define RC_CHECK()  do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc));  STR_FREE(); return rc;                   } } while (0)
    2494 #define H()         do { if (FAILED(hrc))    { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
    2495 
    2496     HRESULT hrc;
    2497     ComPtr<IMachine> pMachine = pThis->machine();
     2608    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     2609
     2610    PVM pVM = mpVM;
     2611
     2612    ComPtr<IMachine> pMachine = machine();
    24982613
    24992614    ComPtr<IVirtualBox> virtualBox;
     
    25122627    {
    25132628        const char *pszNetDriver = "IntNet";
    2514         if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
     2629        if (meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
    25152630            pszNetDriver = "NAT";
    25162631#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
    2517         if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
     2632        if (meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
    25182633            pszNetDriver = "HostInterface";
    25192634#endif
     
    27012816                    Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \
    27022817                    ppos = pos + 1;                                 \
    2703                 }while (0)
     2818                } while (0)
    27042819                ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
    27052820                ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
     
    27582873        {
    27592874#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
    2760             hrc = pThis->attachToTapInterface(aNetworkAdapter);
     2875            hrc = attachToTapInterface(aNetworkAdapter);
    27612876            if (FAILED(hrc))
    27622877            {
     
    27772892            }
    27782893
    2779             Assert((int)pThis->maTapFD[uInstance] >= 0);
    2780             if ((int)pThis->maTapFD[uInstance] >= 0)
     2894            Assert((int)maTapFD[uInstance] >= 0);
     2895            if ((int)maTapFD[uInstance] >= 0)
    27812896            {
    27822897                if (fSniffer)
     
    27902905                rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface");                 RC_CHECK();
    27912906                rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                             RC_CHECK();
    2792                 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]);    RC_CHECK();
     2907                rc = CFGMR3InsertInteger(pCfg, "FileHandle", maTapFD[uInstance]);    RC_CHECK();
    27932908            }
    27942909
     
    29723087             */
    29733088            if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
    2974                 hrc = pThis->attachToTapInterface(aNetworkAdapter);
     3089                hrc = attachToTapInterface(aNetworkAdapter);
    29753090                if (FAILED(hrc))
    29763091                {
     
    29913106                }
    29923107
    2993                 Assert((int)pThis->maTapFD[uInstance] >= 0);
    2994                 if ((int)pThis->maTapFD[uInstance] >= 0)
     3108                Assert((int)maTapFD[uInstance] >= 0);
     3109                if ((int)maTapFD[uInstance] >= 0)
    29953110                {
    29963111                    rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface");                 RC_CHECK();
    29973112                    rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);                             RC_CHECK();
    2998                     rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]);    RC_CHECK();
     3113                    rc = CFGMR3InsertInteger(pCfg, "FileHandle", maTapFD[uInstance]);           RC_CHECK();
    29993114                }
    30003115                break;
     
    30163131                        if ((Req.ifr_flags & IFF_UP) == 0)
    30173132                        {
    3018                             setVMRuntimeErrorCallbackF(pVM, pThis, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
     3133                            setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
    30193134                        }
    30203135
     
    35103625    }
    35113626
    3512     pThis->meAttachmentType[uInstance] = eAttachmentType;
     3627    meAttachmentType[uInstance] = eAttachmentType;
    35133628
    35143629#undef STR_FREE
     
    35653680    parms[2].u.pointer.addr = (void *)pszFlags;
    35663681    parms[2].u.pointer.size = strlen(pszFlags) + 1;
    3567     pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
    3568                            &parms[0]);
     3682    pVMMDev->hgcmHostCall("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
     3683                          &parms[0]);
    35693684}
    35703685
     
    35813696    VBOXHGCMSVCPARM paParm;
    35823697    paParm.setUInt32(eFlags);
    3583     int rc = pVMMDev->hgcmHostCall ("VBoxGuestPropSvc",
    3584                                     guestProp::SET_GLOBAL_FLAGS_HOST, 1,
    3585                                     &paParm);
     3698    int rc = pVMMDev->hgcmHostCall("VBoxGuestPropSvc",
     3699                                   guestProp::SET_GLOBAL_FLAGS_HOST, 1,
     3700                                   &paParm);
    35863701    if (RT_FAILURE(rc))
    35873702    {
     
    36043719#ifdef VBOX_WITH_GUEST_PROPS
    36053720    AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
    3606     ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
     3721    ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
    36073722
    36083723    /* Load the service */
    3609     int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
     3724    int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
    36103725
    36113726    if (RT_FAILURE(rc))
     
    37443859#ifdef VBOX_WITH_GUEST_CONTROL
    37453860    AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
    3746     ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
     3861    ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
    37473862
    37483863    /* Load the service */
    3749     int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestControlSvc", "VBoxGuestControlSvc");
     3864    int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
    37503865
    37513866    if (RT_FAILURE(rc))
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