Changeset 32430 in vbox
- Timestamp:
- Sep 11, 2010 4:06:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DrvVD.cpp
r32277 r32430 174 174 /** Target image index for merging. */ 175 175 unsigned uMergeTarget; 176 177 /** Flag whether boot acceleration is enabled. */ 178 bool fBootAccelEnabled; 179 /** Flag whether boot acceleration is currently active. */ 180 bool fBootAccelActive; 181 /** Size of the disk, used for read truncation. */ 182 size_t cbDisk; 183 /** Size of the configured buffer. */ 184 size_t cbBootAccelBuffer; 185 /** Start offset for which the buffer holds data. */ 186 uint64_t offDisk; 187 /** Number of valid bytes in the buffer. */ 188 size_t cbDataValid; 189 /** The disk buffer. */ 190 uint8_t *pbData; 176 191 } VBOXDISK, *PVBOXDISK; 177 192 … … 1428 1443 uint64_t off, void *pvBuf, size_t cbRead) 1429 1444 { 1445 int rc = VINF_SUCCESS; 1446 1430 1447 LogFlow(("%s: off=%#llx pvBuf=%p cbRead=%d\n", __FUNCTION__, 1431 1448 off, pvBuf, cbRead)); 1432 1449 PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface); 1433 int rc = VDRead(pThis->pDisk, off, pvBuf, cbRead); 1450 1451 if (!pThis->fBootAccelActive) 1452 rc = VDRead(pThis->pDisk, off, pvBuf, cbRead); 1453 else 1454 { 1455 /* Can we serve the request from the buffer? */ 1456 if ( off >= pThis->offDisk 1457 && off - pThis->offDisk < pThis->cbDataValid) 1458 { 1459 size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off); 1460 1461 memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy); 1462 cbRead -= cbToCopy; 1463 off += cbToCopy; 1464 pvBuf = (char *)pvBuf + cbToCopy; 1465 } 1466 1467 if ( cbRead > 0 1468 && cbRead < pThis->cbBootAccelBuffer) 1469 { 1470 /* Increase request to the buffer size and read. */ 1471 pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer); 1472 pThis->offDisk = off; 1473 rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid); 1474 if (RT_FAILURE(rc)) 1475 pThis->cbDataValid = 0; 1476 else 1477 memcpy(pvBuf, pThis->pbData, cbRead); 1478 } 1479 else if (cbRead >= pThis->cbBootAccelBuffer) 1480 { 1481 pThis->fBootAccelActive = false; /* Deactiviate */ 1482 } 1483 } 1484 1434 1485 if (RT_SUCCESS(rc)) 1435 1486 Log2(("%s: off=%#llx pvBuf=%p cbRead=%d %.*Rhxd\n", __FUNCTION__, … … 1449 1500 Log2(("%s: off=%#llx pvBuf=%p cbWrite=%d %.*Rhxd\n", __FUNCTION__, 1450 1501 off, pvBuf, cbWrite, cbWrite, pvBuf)); 1502 1503 /* Invalidate any buffer if boot acceleration is enabled. */ 1504 if (pThis->fBootAccelActive) 1505 { 1506 pThis->cbDataValid = 0; 1507 pThis->offDisk = 0; 1508 } 1509 1451 1510 int rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite); 1452 1511 LogFlow(("%s: returns %Rrc\n", __FUNCTION__, rc)); … … 1614 1673 uOffset, paSeg, cSeg, cbRead, pvUser)); 1615 1674 PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface); 1675 1676 pThis->fBootAccelActive = false; 1677 1616 1678 int rc = VDAsyncRead(pThis->pDisk, uOffset, cbRead, paSeg, cSeg, 1617 1679 drvvdAsyncReqComplete, pThis, pvUser); … … 1627 1689 uOffset, paSeg, cSeg, cbWrite, pvUser)); 1628 1690 PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface); 1691 1692 pThis->fBootAccelActive = false; 1693 1629 1694 int rc = VDAsyncWrite(pThis->pDisk, uOffset, cbWrite, paSeg, cSeg, 1630 1695 drvvdAsyncReqComplete, pThis, pvUser); … … 1772 1837 1773 1838 /** 1839 * @copydoc FNPDMDRVRESET 1840 */ 1841 static DECLCALLBACK(void) drvvdReset(PPDMDRVINS pDrvIns) 1842 { 1843 LogFlow(("%s:\n", __FUNCTION__)); 1844 PVBOXDISK pThis = PDMINS_2_DATA(pDrvIns, PVBOXDISK); 1845 1846 if (pThis->fBootAccelEnabled) 1847 { 1848 pThis->fBootAccelActive = true; 1849 pThis->cbDataValid = 0; 1850 pThis->offDisk = 0; 1851 } 1852 } 1853 1854 /** 1774 1855 * @copydoc FNPDMDRVDESTRUCT 1775 1856 */ … … 1808 1889 pThis->MergeLock = NIL_RTSEMRW; 1809 1890 } 1891 if (pThis->pbData) 1892 RTMemFree(pThis->pbData); 1810 1893 } 1811 1894 … … 1907 1990 "Format\0Path\0" 1908 1991 "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0" 1909 "HostIPStack\0UseNewIo\0 "1992 "HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0" 1910 1993 "SetupMerge\0MergeSource\0MergeTarget\0"); 1911 1994 } … … 1998 2081 rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES, 1999 2082 N_("DrvVD: Configuration error: Both \"ReadOnly\" and \"MergePending\" are set")); 2083 break; 2084 } 2085 rc = CFGMR3QueryBoolDef(pCurNode, "BootAcceleration", &pThis->fBootAccelEnabled, false); 2086 if (RT_FAILURE(rc)) 2087 { 2088 rc = PDMDRV_SET_ERROR(pDrvIns, rc, 2089 N_("DrvVD: Configuration error: Querying \"BootAcceleration\" as boolean failed")); 2090 break; 2091 } 2092 rc = CFGMR3QueryU32Def(pCurNode, "BootAccelerationBuffer", (uint32_t *)&pThis->cbBootAccelBuffer, 16 * _1K); 2093 if (RT_FAILURE(rc)) 2094 { 2095 rc = PDMDRV_SET_ERROR(pDrvIns, rc, 2096 N_("DrvVD: Configuration error: Querying \"BootAccelerationBuffer\" as integer failed")); 2000 2097 break; 2001 2098 } … … 2312 2409 NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone); 2313 2410 2411 /* Setup the boot acceleration stuff if enabled. */ 2412 if (RT_SUCCESS(rc) && pThis->fBootAccelEnabled) 2413 { 2414 pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE); 2415 Assert(pThis->cbDisk > 0); 2416 pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer); 2417 if (pThis->pbData) 2418 { 2419 pThis->fBootAccelActive = true; 2420 pThis->offDisk = 0; 2421 pThis->cbDataValid = 0; 2422 LogRel(("VD: Boot acceleration enabled\n")); 2423 } 2424 else 2425 LogRel(("VD: Boot acceleration, out of memory, disabled\n")); 2426 } 2314 2427 2315 2428 if (RT_FAILURE(rc)) … … 2360 2473 drvvdPowerOn, 2361 2474 /* pfnReset */ 2362 NULL,2475 drvvdReset, 2363 2476 /* pfnSuspend */ 2364 2477 drvvdSuspend,
Note:
See TracChangeset
for help on using the changeset viewer.