VirtualBox

Changeset 30864 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Jul 15, 2010 8:30:17 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63693
Message:

VD/Parallels: Implement async I/O support. Completely untestet right now, thatswhy disabled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/ParallelsHDDCore.cpp

    r30863 r30864  
    662662    LogFlowFunc(("returns %Rrc\n", rc));
    663663    return rc;
    664 
    665664}
    666665
     
    11771176static bool parallelsIsAsyncIOSupported(void *pvBackendData)
    11781177{
     1178#if 0 /** @todo: Remove when tested */
     1179    return true;
     1180#else
    11791181    return false;
    1180 }
    1181 
    1182 static int parallelsAsyncRead(void *pvBackendData, uint64_t uOffset, size_t cbRead,
     1182#endif
     1183}
     1184
     1185static int parallelsAsyncRead(void *pvBackendData, uint64_t uOffset, size_t cbToRead,
    11831186                              PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
    11841187{
    1185     int rc = VERR_NOT_IMPLEMENTED;
    1186     LogFlowFunc(("returns %Rrc\n", rc));
    1187     return rc;
    1188 }
    1189 
    1190 static int parallelsAsyncWrite(void *pvBackendData, uint64_t uOffset, size_t cbWrite,
     1188    LogFlowFunc(("pvBackendData=%#p uOffset=%llu pIoCtx=%#p cbToRead=%zu pcbActuallyRead=%#p\n",
     1189                 pvBackendData, uOffset, pIoCtx, cbToRead, pcbActuallyRead));
     1190    int rc = VINF_SUCCESS;
     1191    PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pvBackendData;
     1192    uint64_t uSector;
     1193    uint64_t uOffsetInFile;
     1194    uint32_t iIndexInAllocationTable;
     1195
     1196    Assert(pImage);
     1197    Assert(uOffset % 512 == 0);
     1198    Assert(cbToRead % 512 == 0);
     1199
     1200    if (pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)
     1201    {
     1202        rc = pImage->pInterfaceIOCallbacks->pfnReadUserAsync(pImage->pInterfaceIO->pvUser,
     1203                                                             pImage->pStorage,
     1204                                                             uOffset, pIoCtx, cbToRead);
     1205    }
     1206    else
     1207    {
     1208        /* Calculate offset in the real file. */
     1209        uSector = uOffset / 512;
     1210        /* One chunk in the file is always one track big. */
     1211        iIndexInAllocationTable = (uint32_t)(uSector / pImage->PCHSGeometry.cSectors);
     1212        uSector = uSector % pImage->PCHSGeometry.cSectors;
     1213
     1214        cbToRead = RT_MIN(cbToRead, (pImage->PCHSGeometry.cSectors - uSector)*512);
     1215
     1216        if (pImage->pAllocationBitmap[iIndexInAllocationTable] == 0)
     1217        {
     1218            rc = VERR_VD_BLOCK_FREE;
     1219        }
     1220        else
     1221        {
     1222            uOffsetInFile = (pImage->pAllocationBitmap[iIndexInAllocationTable] + uSector) * 512;
     1223            rc = pImage->pInterfaceIOCallbacks->pfnReadUserAsync(pImage->pInterfaceIO->pvUser,
     1224                                                                 pImage->pStorage,
     1225                                                                 uOffsetInFile, pIoCtx, cbToRead);
     1226        }
     1227    }
     1228
     1229    *pcbActuallyRead = cbToRead;
     1230
     1231    LogFlowFunc(("returns %Rrc\n", rc));
     1232    return rc;
     1233}
     1234
     1235static int parallelsAsyncWrite(void *pvBackendData, uint64_t uOffset, size_t cbToWrite,
    11911236                               PVDIOCTX pIoCtx,
    11921237                               size_t *pcbWriteProcess, size_t *pcbPreRead,
    11931238                               size_t *pcbPostRead, unsigned fWrite)
    11941239{
    1195     int rc = VERR_NOT_IMPLEMENTED;
     1240    LogFlowFunc(("pvBackendData=%#p uOffset=%llu pIoCtx=%#p cbToWrite=%zu pcbWriteProcess=%#p\n",
     1241                 pvBackendData, uOffset, pIoCtx, cbToWrite, pcbWriteProcess));
     1242    int rc = VINF_SUCCESS;
     1243    PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pvBackendData;
     1244    uint64_t uSector;
     1245    uint64_t uOffsetInFile;
     1246    uint32_t iIndexInAllocationTable;
     1247
     1248    Assert(pImage);
     1249    Assert(uOffset % 512 == 0);
     1250    Assert(cbToWrite % 512 == 0);
     1251
     1252    if (pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)
     1253    {
     1254        rc = pImage->pInterfaceIOCallbacks->pfnWriteUserAsync(pImage->pInterfaceIO->pvUser,
     1255                                                              pImage->pStorage,
     1256                                                              uOffset, pIoCtx, cbToWrite,
     1257                                                              NULL, NULL);
     1258    }
     1259    else
     1260    {
     1261        /* Calculate offset in the real file. */
     1262        uSector = uOffset / 512;
     1263        /* One chunk in the file is always one track big. */
     1264        iIndexInAllocationTable = (uint32_t)(uSector / pImage->PCHSGeometry.cSectors);
     1265        uSector = uSector % pImage->PCHSGeometry.cSectors;
     1266
     1267        cbToWrite = RT_MIN(cbToWrite, (pImage->PCHSGeometry.cSectors - uSector)*512);
     1268
     1269        if (pImage->pAllocationBitmap[iIndexInAllocationTable] == 0)
     1270        {
     1271            if (fWrite & VD_WRITE_NO_ALLOC)
     1272            {
     1273                *pcbPreRead  = uSector * 512;
     1274                *pcbPostRead = pImage->PCHSGeometry.cSectors * 512 - cbToWrite - *pcbPreRead;
     1275
     1276                if (pcbWriteProcess)
     1277                    *pcbWriteProcess = cbToWrite;
     1278                return VERR_VD_BLOCK_FREE;
     1279            }
     1280
     1281            /* Allocate new chunk in the file. */
     1282            Assert(uSector == 0);
     1283            AssertMsg(pImage->cbFileCurrent % 512 == 0, ("File size is not a multiple of 512\n"));
     1284            pImage->pAllocationBitmap[iIndexInAllocationTable] = (uint32_t)(pImage->cbFileCurrent / 512);
     1285            pImage->cbFileCurrent += pImage->PCHSGeometry.cSectors * 512;
     1286            pImage->fAllocationBitmapChanged = true;
     1287            uOffsetInFile = (uint64_t)pImage->pAllocationBitmap[iIndexInAllocationTable] * 512;
     1288
     1289            /*
     1290             * Write the new block at the current end of the file.
     1291             */
     1292            rc = pImage->pInterfaceIOCallbacks->pfnWriteUserAsync(pImage->pInterfaceIO->pvUser,
     1293                                                                  pImage->pStorage,
     1294                                                                  uOffsetInFile, pIoCtx, cbToWrite,
     1295                                                                  NULL, NULL);
     1296            if (RT_SUCCESS(rc) || (rc == VERR_VD_ASYNC_IO_IN_PROGRESS))
     1297            {
     1298                /* Write the changed allocation bitmap entry. */
     1299                /** @todo: Error handling. */
     1300                rc = pImage->pInterfaceIOCallbacks->pfnWriteMetaAsync(pImage->pInterfaceIO->pvUser,
     1301                                                                      pImage->pStorage,
     1302                                                                      sizeof(ParallelsHeader) + iIndexInAllocationTable * sizeof(uint32_t),
     1303                                                                      &pImage->pAllocationBitmap[iIndexInAllocationTable],
     1304                                                                      sizeof(uint32_t),
     1305                                                                      pIoCtx,
     1306                                                                      NULL, NULL);
     1307            }
     1308        }
     1309        else
     1310        {
     1311            uOffsetInFile = (pImage->pAllocationBitmap[iIndexInAllocationTable] + uSector) * 512;
     1312            rc = pImage->pInterfaceIOCallbacks->pfnWriteUserAsync(pImage->pInterfaceIO->pvUser,
     1313                                                                  pImage->pStorage,
     1314                                                                  uOffsetInFile, pIoCtx, cbToWrite,
     1315                                                                  NULL, NULL);
     1316        }
     1317    }
     1318
     1319    if (pcbWriteProcess)
     1320        *pcbWriteProcess = cbToWrite;
     1321
    11961322    LogFlowFunc(("returns %Rrc\n", rc));
    11971323    return rc;
     
    12001326static int parallelsAsyncFlush(void *pvBackendData, PVDIOCTX pIoCtx)
    12011327{
    1202     int rc = VERR_NOT_IMPLEMENTED;
     1328    int rc = VINF_SUCCESS;
     1329    PPARALLELSIMAGE pImage = (PPARALLELSIMAGE)pvBackendData;
     1330
     1331    LogFlowFunc(("pImage=#%p\n", pImage));
     1332
     1333    /* Flush the file, everything is up to date already. */
     1334    rc = pImage->pInterfaceIOCallbacks->pfnFlushAsync(pImage->pInterfaceIO->pvUser,
     1335                                                      pImage->pStorage, pIoCtx,
     1336                                                      NULL, NULL);
     1337
    12031338    LogFlowFunc(("returns %Rrc\n", rc));
    12041339    return rc;
     
    12121347    sizeof(VBOXHDDBACKEND),
    12131348    /* uBackendCaps */
    1214     VD_CAP_FILE | VD_CAP_CREATE_FIXED | VD_CAP_CREATE_DYNAMIC,
     1349    VD_CAP_FILE | VD_CAP_ASYNC,
    12151350    /* papszFileExtensions */
    12161351    s_apszParallelsFileExtensions,
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