- Timestamp:
- Dec 24, 2010 4:05:54 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VD.cpp
r35188 r35321 274 274 volatile size_t cbTransfer; 275 275 /** Current image in the chain. */ 276 PVDIMAGE pImage; 276 PVDIMAGE pImageCur; 277 /** Start image to read from. pImageCur is reset to this 278 * value after it reached the first image in the chain. */ 279 PVDIMAGE pImageStart; 277 280 /** S/G buffer */ 278 281 RTSGBUF SgBuf; … … 903 906 DECLINLINE(PVDIOCTX) vdIoCtxAlloc(PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir, 904 907 uint64_t uOffset, size_t cbTransfer, 908 PVDIMAGE pImageStart, 905 909 PCRTSGBUF pcSgBuf, void *pvAllocation, 906 910 PFNVDIOCTXTRANSFER pfnIoCtxTransfer) … … 916 920 pIoCtx->uOffset = uOffset; 917 921 pIoCtx->cbTransfer = cbTransfer; 922 pIoCtx->pImageStart = pImageStart; 923 pIoCtx->pImageCur = pImageStart; 918 924 pIoCtx->cDataTransfersPending = 0; 919 925 pIoCtx->cMetaTransfersPending = 0; … … 937 943 DECLINLINE(PVDIOCTX) vdIoCtxRootAlloc(PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir, 938 944 uint64_t uOffset, size_t cbTransfer, 939 P CRTSGBUF pcSgBuf,945 PVDIMAGE pImageStart, PCRTSGBUF pcSgBuf, 940 946 PFNVDASYNCTRANSFERCOMPLETE pfnComplete, 941 947 void *pvUser1, void *pvUser2, … … 943 949 PFNVDIOCTXTRANSFER pfnIoCtxTransfer) 944 950 { 945 PVDIOCTX pIoCtx = vdIoCtxAlloc(pDisk, enmTxDir, uOffset, cbTransfer, 951 PVDIOCTX pIoCtx = vdIoCtxAlloc(pDisk, enmTxDir, uOffset, cbTransfer, pImageStart, 946 952 pcSgBuf, pvAllocation, pfnIoCtxTransfer); 947 953 … … 960 966 DECLINLINE(PVDIOCTX) vdIoCtxChildAlloc(PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir, 961 967 uint64_t uOffset, size_t cbTransfer, 962 P CRTSGBUF pcSgBuf,968 PVDIMAGE pImageStart, PCRTSGBUF pcSgBuf, 963 969 PVDIOCTX pIoCtxParent, size_t cbTransferParent, 964 970 size_t cbWriteParent, void *pvAllocation, 965 971 PFNVDIOCTXTRANSFER pfnIoCtxTransfer) 966 972 { 967 PVDIOCTX pIoCtx = vdIoCtxAlloc(pDisk, enmTxDir, uOffset, cbTransfer, 973 PVDIOCTX pIoCtx = vdIoCtxAlloc(pDisk, enmTxDir, uOffset, cbTransfer, pImageStart, 968 974 pcSgBuf, pvAllocation, pfnIoCtxTransfer); 969 975 … … 1272 1278 do 1273 1279 { 1274 pCurrImage = pIoCtx->pImage ;1280 pCurrImage = pIoCtx->pImageCur; 1275 1281 1276 1282 /* Search for image with allocated block. Do not attempt to read more … … 1329 1335 pIoCtx->uOffset = uOffset; 1330 1336 pIoCtx->cbTransfer = cbToRead; 1331 pIoCtx->pImage = pCurrImage;1337 pIoCtx->pImageCur = pCurrImage ? pCurrImage : pIoCtx->pImageStart; 1332 1338 } 1333 1339 … … 1727 1733 } 1728 1734 1735 static int vdWriteHelperOptimizedCommitAsync(PVDIOCTX pIoCtx) 1736 { 1737 int rc = VINF_SUCCESS; 1738 PVDIMAGE pImage = pIoCtx->pImageCur; 1739 size_t cbPreRead = pIoCtx->Type.Child.cbPreRead; 1740 size_t cbPostRead = pIoCtx->Type.Child.cbPostRead; 1741 size_t cbThisWrite = pIoCtx->Type.Child.cbTransferParent; 1742 1743 LogFlowFunc(("pIoCtx=%#p\n", pIoCtx)); 1744 rc = pImage->Backend->pfnAsyncWrite(pImage->pBackendData, 1745 pIoCtx->uOffset - cbPreRead, 1746 cbPreRead + cbThisWrite + cbPostRead, 1747 pIoCtx, NULL, &cbPreRead, &cbPostRead, 0); 1748 Assert(rc != VERR_VD_BLOCK_FREE); 1749 Assert(rc == VERR_VD_NOT_ENOUGH_METADATA || cbPreRead == 0); 1750 Assert(rc == VERR_VD_NOT_ENOUGH_METADATA || cbPostRead == 0); 1751 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 1752 rc = VINF_SUCCESS; 1753 else if (rc == VERR_VD_IOCTX_HALT) 1754 { 1755 pIoCtx->fBlocked = true; 1756 rc = VINF_SUCCESS; 1757 } 1758 1759 LogFlowFunc(("returns rc=%Rrc\n", rc)); 1760 return rc; 1761 } 1762 1729 1763 static int vdWriteHelperOptimizedCmpAndWriteAsync(PVDIOCTX pIoCtx) 1730 1764 { 1731 1765 int rc = VINF_SUCCESS; 1732 PVDIMAGE pImage = pIoCtx->pImage ;1766 PVDIMAGE pImage = pIoCtx->pImageCur; 1733 1767 size_t cbThisWrite = 0; 1734 1768 size_t cbPreRead = pIoCtx->Type.Child.cbPreRead; … … 1800 1834 /* Write the full block to the virtual disk. */ 1801 1835 RTSgBufReset(&pIoCtx->SgBuf); 1802 rc = pImage->Backend->pfnAsyncWrite(pImage->pBackendData, 1803 pIoCtx->uOffset - cbPreRead, 1804 cbPreRead + cbThisWrite + cbPostRead, 1805 pIoCtx, NULL, &cbPreRead, &cbPostRead, 0); 1806 Assert(rc != VERR_VD_BLOCK_FREE); 1807 Assert(cbPreRead == 0); 1808 Assert(cbPostRead == 0); 1809 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 1810 rc = VINF_SUCCESS; 1811 else if (rc == VERR_VD_IOCTX_HALT) 1812 { 1813 pIoCtx->fBlocked = true; 1814 rc = VINF_SUCCESS; 1815 } 1836 pIoCtx->pfnIoCtxTransferNext = vdWriteHelperOptimizedCommitAsync; 1816 1837 1817 1838 return rc; … … 1901 1922 size_t cbWrite = pIoCtx->cbTransfer; 1902 1923 uint64_t uOffset = pIoCtx->uOffset; 1903 PVDIMAGE pImage = pIoCtx->pImage ;1924 PVDIMAGE pImage = pIoCtx->pImageCur; 1904 1925 PVBOXHDD pDisk = pIoCtx->pDisk; 1905 1926 unsigned fWrite; … … 1942 1963 1943 1964 PVDIOCTX pIoCtxWrite = vdIoCtxChildAlloc(pDisk, VDIOCTXTXDIR_WRITE, 1944 uOffset, pSeg->cbSeg, 1965 uOffset, pSeg->cbSeg, pImage, 1945 1966 pTmp, 1946 1967 pIoCtx, cbThisWrite, … … 1960 1981 pIoCtx, pIoCtxWrite)); 1961 1982 1962 pIoCtxWrite->pImage = pImage;1963 1983 pIoCtxWrite->Type.Child.cbPreRead = cbPreRead; 1964 1984 pIoCtxWrite->Type.Child.cbPostRead = cbPostRead; … … 2039 2059 int rc = VINF_SUCCESS; 2040 2060 PVBOXHDD pDisk = pIoCtx->pDisk; 2041 PVDIMAGE pImage = pIoCtx->pImage ;2061 PVDIMAGE pImage = pIoCtx->pImageCur; 2042 2062 2043 2063 rc = vdIoCtxLockDisk(pDisk, pIoCtx); … … 8003 8023 uOffset, cbRead, pDisk->cbSize), 8004 8024 rc = VERR_INVALID_PARAMETER); 8025 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED); 8005 8026 8006 8027 pIoCtx = vdIoCtxRootAlloc(pDisk, VDIOCTXTXDIR_READ, uOffset, 8007 cbRead, p cSgBuf,8028 cbRead, pDisk->pLast, pcSgBuf, 8008 8029 pfnComplete, pvUser1, pvUser2, 8009 8030 NULL, vdReadHelperAsync); … … 8013 8034 break; 8014 8035 } 8015 8016 pIoCtx->pImage = pDisk->pLast;8017 AssertPtrBreakStmt(pIoCtx->pImage, rc = VERR_VD_NOT_OPENED);8018 8036 8019 8037 rc = vdIoCtxProcess(pIoCtx); … … 8076 8094 uOffset, cbWrite, pDisk->cbSize), 8077 8095 rc = VERR_INVALID_PARAMETER); 8096 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED); 8078 8097 8079 8098 pIoCtx = vdIoCtxRootAlloc(pDisk, VDIOCTXTXDIR_WRITE, uOffset, 8080 cbWrite, p cSgBuf,8099 cbWrite, pDisk->pLast, pcSgBuf, 8081 8100 pfnComplete, pvUser1, pvUser2, 8082 8101 NULL, vdWriteHelperAsync); … … 8086 8105 break; 8087 8106 } 8088 8089 PVDIMAGE pImage = pDisk->pLast;8090 AssertPtrBreakStmt(pImage, rc = VERR_VD_NOT_OPENED);8091 pIoCtx->pImage = pImage;8092 8107 8093 8108 rc = vdIoCtxProcess(pIoCtx); … … 8135 8150 fLockWrite = true; 8136 8151 8152 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED); 8153 8137 8154 pIoCtx = vdIoCtxRootAlloc(pDisk, VDIOCTXTXDIR_FLUSH, 0, 8138 0, NULL,8155 0, pDisk->pLast, NULL, 8139 8156 pfnComplete, pvUser1, pvUser2, 8140 8157 NULL, vdFlushHelperAsync); … … 8144 8161 break; 8145 8162 } 8146 8147 PVDIMAGE pImage = pDisk->pLast;8148 AssertPtrBreakStmt(pImage, rc = VERR_VD_NOT_OPENED);8149 pIoCtx->pImage = pImage;8150 8163 8151 8164 rc = vdIoCtxProcess(pIoCtx);
Note:
See TracChangeset
for help on using the changeset viewer.