VirtualBox

Changeset 46247 in vbox


Ignore:
Timestamp:
May 23, 2013 7:19:42 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
85976
Message:

Storage/tstVDIo: Integrate runtime async I/O manager and add a file based storage backend in addition to the memory based backend

Location:
trunk/src/VBox/Storage/testcase
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/testcase/Makefile.kmk

    r44891 r46247  
    5353  tstVDIo_TEMPLATE = VBOXR3TSTEXE
    5454  tstVDIo_SOURCES  = tstVDIo.cpp \
     55        VDIoBackend.cpp \
    5556        VDIoBackendMem.cpp \
    5657        VDMemDisk.cpp \
  • trunk/src/VBox/Storage/testcase/VDIoBackendMem.cpp

    r44529 r46247  
    4444    /** Size of the transfer. */
    4545    size_t          cbTransfer;
    46     /** Number of segments in the array. */
    47     unsigned        cSegs;
    4846    /** Completion handler to call. */
    4947    PFNVDIOCOMPLETE pfnComplete;
    5048    /** Opaque user data. */
    5149    void           *pvUser;
    52     /** Segment array - variable in size */
     50    /** S/G buffer. */
     51    RTSGBUF         SgBuf;
     52    /** Segment array - variable size. */
    5353    RTSGSEG         aSegs[1];
    5454} VDIOBACKENDREQ, *PVDIOBACKENDREQ;
     
    143143
    144144int VDIoBackendMemTransfer(PVDIOBACKENDMEM pIoBackend, PVDMEMDISK pMemDisk,
    145                            VDIOTXDIR enmTxDir, uint64_t off, size_t cbTransfer, PCRTSGSEG paSegs,
    146                            unsigned cSegs, PFNVDIOCOMPLETE pfnComplete, void *pvUser)
     145                           VDIOTXDIR enmTxDir, uint64_t off, size_t cbTransfer,
     146                           PRTSGBUF pSgBuf, PFNVDIOCOMPLETE pfnComplete, void *pvUser)
    147147{
    148148    PVDIOBACKENDREQ pReq = NULL;
    149149    PPVDIOBACKENDREQ ppReq = NULL;
    150150    size_t cbData;
     151    unsigned cSegs = 0;
    151152
    152153    LogFlowFunc(("Queuing request\n"));
     154
     155    if (enmTxDir != VDIOTXDIR_FLUSH)
     156        RTSgBufSegArrayCreate(pSgBuf, NULL, &cSegs, cbTransfer);
    153157
    154158    pReq = (PVDIOBACKENDREQ)RTMemAlloc(RT_OFFSETOF(VDIOBACKENDREQ, aSegs[cSegs]));
     
    168172    pReq->off         = off;
    169173    pReq->pMemDisk    = pMemDisk;
    170     pReq->cSegs       = cSegs;
    171174    pReq->pfnComplete = pfnComplete;
    172175    pReq->pvUser      = pvUser;
    173     for (unsigned i = 0; i < cSegs; i++)
    174     {
    175         pReq->aSegs[i].pvSeg = paSegs[i].pvSeg;
    176         pReq->aSegs[i].cbSeg = paSegs[i].cbSeg;
     176    if (enmTxDir != VDIOTXDIR_FLUSH)
     177    {
     178        RTSgBufSegArrayCreate(pSgBuf, &pReq->aSegs[0], &cSegs, cbTransfer);
     179        RTSgBufInit(&pReq->SgBuf, pReq->aSegs, cSegs);
    177180    }
    178181
     
    226229                case VDIOTXDIR_READ:
    227230                {
    228                     RTSGBUF SgBuf;
    229                     RTSgBufInit(&SgBuf, pReq->aSegs, pReq->cSegs);
    230                     rcReq = VDMemDiskRead(pReq->pMemDisk, pReq->off, pReq->cbTransfer, &SgBuf);
     231                    rcReq = VDMemDiskRead(pReq->pMemDisk, pReq->off, pReq->cbTransfer, &pReq->SgBuf);
    231232                    break;
    232233                }
    233234                case VDIOTXDIR_WRITE:
    234235                {
    235                     RTSGBUF SgBuf;
    236                     RTSgBufInit(&SgBuf, pReq->aSegs, pReq->cSegs);
    237                     rcReq = VDMemDiskWrite(pReq->pMemDisk, pReq->off, pReq->cbTransfer, &SgBuf);
     236                    rcReq = VDMemDiskWrite(pReq->pMemDisk, pReq->off, pReq->cbTransfer, &pReq->SgBuf);
    238237                    break;
    239238                }
  • trunk/src/VBox/Storage/testcase/VDIoBackendMem.h

    r35471 r46247  
    2121#include <iprt/sg.h>
    2222
    23 /**
    24  * I/O transfer direction.
    25  */
    26 typedef enum VDIOTXDIR
    27 {
    28     /** Read. */
    29     VDIOTXDIR_READ = 0,
    30     /** Write. */
    31     VDIOTXDIR_WRITE,
    32     /** Flush. */
    33     VDIOTXDIR_FLUSH,
    34     /** Invalid. */
    35     VDIOTXDIR_INVALID
    36 } VDIOTXDIR;
     23#include "VDDefs.h"
    3724
    3825/** Memory backend handle. */
     
    8673 */
    8774int VDIoBackendMemTransfer(PVDIOBACKENDMEM pIoBackend, PVDMEMDISK pMemDisk,
    88                            VDIOTXDIR enmTxDir, uint64_t off, size_t cbTransfer, PCRTSGSEG paSegs,
    89                            unsigned cSegs,
    90                            PFNVDIOCOMPLETE pfnComplete, void *pvUser);
     75                           VDIOTXDIR enmTxDir, uint64_t off, size_t cbTransfer,
     76                           PRTSGBUF pSgBuf, PFNVDIOCOMPLETE pfnComplete, void *pvUser);
    9177
    9278#endif /* __VDIoBackendMem_h__ */
  • trunk/src/VBox/Storage/testcase/tstVDIo.cpp

    r44942 r46247  
    3535
    3636#include "VDMemDisk.h"
    37 #include "VDIoBackendMem.h"
     37#include "VDIoBackend.h"
    3838#include "VDIoRnd.h"
    3939
     
    4949    /** Name of the file. */
    5050    char          *pszName;
    51     /** Memory file baking the file. */
    52     PVDMEMDISK     pMemDisk;
     51    /** Storage backing the file. */
     52    PVDIOSTORAGE   pIoStorage;
    5353    /** Flag whether the file is read locked. */
    5454    bool           fReadLock;
     
    127127    /** Head of the pattern list. */
    128128    RTLISTNODE       ListPatterns;
    129     /** Memory I/O backend. */
    130     PVDIOBACKENDMEM  pIoBackend;
     129    /** I/O backend, common data. */
     130    PVDIOBACKEND     pIoBackend;
    131131    /** Error interface. */
    132132    VDINTERFACEERROR VDIfError;
     
    139139    /** I/O RNG handle. */
    140140    PVDIORND         pIoRnd;
     141    /** Current storage backend to use. */
     142    char            *pszIoBackend;
    141143} VDTESTGLOB, *PVDTESTGLOB;
    142144
     
    242244static DECLCALLBACK(int) vdScriptHandlerResetStatistics(PVDSCRIPTARG paScriptArgs, void *pvUser);
    243245static DECLCALLBACK(int) vdScriptHandlerResize(PVDSCRIPTARG paScriptArgs, void *pvUser);
     246static DECLCALLBACK(int) vdScriptHandlerSetFileBackend(PVDSCRIPTARG paScriptArgs, void *pvUser);
    244247
    245248/* create action */
     
    442445};
    443446
     447/* Set file backend. */
     448const VDSCRIPTTYPE g_aArgSetFileBackend[] =
     449{
     450    VDSCRIPTTYPE_STRING /* new file backend */
     451};
    444452
    445453const VDSCRIPTCALLBACK g_aScriptActions[] =
     
    472480    {"resetstatistics",            VDSCRIPTTYPE_VOID, g_aArgResetStatistics,             RT_ELEMENTS(g_aArgResetStatistics),            vdScriptHandlerResetStatistics},
    473481    {"resize",                     VDSCRIPTTYPE_VOID, g_aArgResize,                      RT_ELEMENTS(g_aArgResize),                     vdScriptHandlerResize},
     482    {"setfilebackend",             VDSCRIPTTYPE_VOID, g_aArgSetFileBackend,              RT_ELEMENTS(g_aArgSetFileBackend),             vdScriptHandlerSetFileBackend},
    474483};
    475484
     
    523532    bool fDynamic = true;
    524533    bool fIgnoreFlush = false;
     534    PVDIOBACKEND pIoBackend = NULL;
    525535
    526536    pcszDisk = paScriptArgs[0].psz;
     
    17071717    {
    17081718        RTPrintf("Dumping memory file %s to %s, this might take some time\n", pcszFile, pcszPathToDump);
    1709         rc = VDMemDiskWriteToFile(pIt->pMemDisk, pcszPathToDump);
     1719        //rc = VDMemDiskWriteToFile(pIt->pIo, pcszPathToDump);
     1720        rc = VERR_NOT_IMPLEMENTED;
    17101721    }
    17111722    else
     
    19942005}
    19952006
     2007static DECLCALLBACK(int) vdScriptHandlerSetFileBackend(PVDSCRIPTARG paScriptArgs, void *pvUser)
     2008{
     2009    int rc = VINF_SUCCESS;
     2010    PVDTESTGLOB pGlob = (PVDTESTGLOB)pvUser;
     2011    const char *pcszBackend = paScriptArgs[0].psz;
     2012
     2013    RTStrFree(pGlob->pszIoBackend);
     2014    pGlob->pszIoBackend = RTStrDup(pcszBackend);
     2015    if (!pGlob->pszIoBackend)
     2016        rc = VERR_NO_MEMORY;
     2017
     2018    return rc;
     2019}
     2020
    19962021static DECLCALLBACK(int) tstVDIoFileOpen(void *pvUser, const char *pszLocation,
    19972022                                         uint32_t fOpen,
     
    20282053        /* If the file exists delete the memory disk. */
    20292054        if (fFound)
    2030             rc = VDMemDiskSetSize(pIt->pMemDisk, 0);
     2055            rc = VDIoBackendStorageSetSize(pIt->pIoStorage, 0);
    20312056        else
    20322057        {
     
    20392064                if (pIt->pszName)
    20402065                {
    2041                     rc = VDMemDiskCreate(&pIt->pMemDisk, 0);
     2066                    rc = VDIoBackendStorageCreate(pGlob->pIoBackend, pGlob->pszIoBackend,
     2067                                                  pszLocation, pfnCompleted, &pIt->pIoStorage);
    20422068                }
    20432069                else
     
    20502076                    RTMemFree(pIt);
    20512077                }
     2078                else
     2079                    RTListAppend(&pGlob->ListFiles, &pIt->Node);
    20522080            }
    20532081            else
    20542082                rc = VERR_NO_MEMORY;
    2055 
    2056             RTListAppend(&pGlob->ListFiles, &pIt->Node);
    20572083        }
    20582084    }
     
    21182144    {
    21192145        RTListNodeRemove(&pIt->Node);
    2120         VDMemDiskDestroy(pIt->pMemDisk);
     2146        VDIoBackendStorageDestroy(pIt->pIoStorage);
    21212147        RTStrFree(pIt->pszName);
    21222148        RTMemFree(pIt);
     
    21822208    PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage;
    21832209
    2184     return VDMemDiskGetSize(pIoStorage->pFile->pMemDisk, pcbSize);
     2210    return VDIoBackendStorageGetSize(pIoStorage->pFile->pIoStorage, pcbSize);
    21852211}
    21862212
     
    21892215    PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage;
    21902216
    2191     return VDMemDiskSetSize(pIoStorage->pFile->pMemDisk, cbSize);
     2217    return VDIoBackendStorageSetSize(pIoStorage->pFile->pIoStorage, cbSize);
    21922218}
    21932219
     
    22042230    Seg.cbSeg = cbBuffer;
    22052231    RTSgBufInit(&SgBuf, &Seg, 1);
    2206     rc = VDMemDiskWrite(pIoStorage->pFile->pMemDisk, uOffset, cbBuffer, &SgBuf);
     2232    rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_WRITE, uOffset,
     2233                             cbBuffer, &SgBuf, NULL, true /* fSync */);
    22072234    if (RT_SUCCESS(rc))
    22082235    {
     
    22272254    Seg.cbSeg = cbBuffer;
    22282255    RTSgBufInit(&SgBuf, &Seg, 1);
    2229     rc = VDMemDiskRead(pIoStorage->pFile->pMemDisk, uOffset, cbBuffer, &SgBuf);
     2256    rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_READ, uOffset,
     2257                             cbBuffer, &SgBuf, NULL, true /* fSync */);
    22302258    if (RT_SUCCESS(rc))
    22312259    {
     
    22412269{
    22422270    PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage;
     2271    int rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_FLUSH, 0,
     2272                                 0, NULL, NULL, true /* fSync */);
    22432273    pIoStorage->pFile->cFlushes++;
    2244     return VINF_SUCCESS;
     2274    return rc;
    22452275}
    22462276
     
    22532283    PVDTESTGLOB pGlob = (PVDTESTGLOB)pvUser;
    22542284    PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage;
    2255 
    2256     rc = VDIoBackendMemTransfer(pGlob->pIoBackend, pIoStorage->pFile->pMemDisk, VDIOTXDIR_READ, uOffset,
    2257                                 cbRead, paSegments, cSegments, pIoStorage->pfnComplete, pvCompletion);
     2285    RTSGBUF SgBuf;
     2286
     2287    RTSgBufInit(&SgBuf, paSegments, cSegments);
     2288    rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_READ, uOffset,
     2289                             cbRead, &SgBuf, pvCompletion, false /* fSync */);
    22582290    if (RT_SUCCESS(rc))
    22592291    {
     
    22732305    PVDTESTGLOB pGlob = (PVDTESTGLOB)pvUser;
    22742306    PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage;
    2275 
    2276     rc = VDIoBackendMemTransfer(pGlob->pIoBackend, pIoStorage->pFile->pMemDisk, VDIOTXDIR_WRITE, uOffset,
    2277                                 cbWrite, paSegments, cSegments, pIoStorage->pfnComplete, pvCompletion);
     2307    RTSGBUF SgBuf;
     2308
     2309    RTSgBufInit(&SgBuf, paSegments, cSegments);
     2310    rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_WRITE, uOffset,
     2311                             cbWrite, &SgBuf, pvCompletion, false /* fSync */);
    22782312    if (RT_SUCCESS(rc))
    22792313    {
     
    22922326    PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage;
    22932327
    2294     rc = VDIoBackendMemTransfer(pGlob->pIoBackend, pIoStorage->pFile->pMemDisk, VDIOTXDIR_FLUSH, 0,
    2295                                 0, NULL, 0, pIoStorage->pfnComplete, pvCompletion);
     2328    rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_FLUSH, 0,
     2329                             0, NULL, pvCompletion, false /* fSync */);
    22962330    if (RT_SUCCESS(rc))
    22972331    {
     
    26312665    RTListInit(&GlobTest.ListDisks);
    26322666    RTListInit(&GlobTest.ListPatterns);
     2667    GlobTest.pszIoBackend = RTStrDup("memory");
     2668    if (!GlobTest.pszIoBackend)
     2669    {
     2670        RTPrintf("Out of memory allocating I/O backend string\n");
     2671        return;
     2672    }
    26332673
    26342674    rc = RTFileReadAll(pcszFilename, &pvFile, &cbFile);
     
    26672707
    26682708        /* Init I/O backend. */
    2669         rc = VDIoBackendMemCreate(&GlobTest.pIoBackend);
     2709        rc = VDIoBackendCreate(&GlobTest.pIoBackend);
    26702710        if (RT_SUCCESS(rc))
    26712711        {
     
    26862726                VDScriptCtxDestroy(hScriptCtx);
    26872727            }
    2688             VDIoBackendMemDestroy(GlobTest.pIoBackend);
     2728            VDIoBackendDestroy(GlobTest.pIoBackend);
    26892729        }
    26902730        else
     
    26932733    else
    26942734        RTPrintf("Opening script failed rc=%Rrc\n", rc);
     2735
     2736    RTStrFree(GlobTest.pszIoBackend);
    26952737}
    26962738
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