Changeset 46247 in vbox
- Timestamp:
- May 23, 2013 7:19:42 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 85976
- Location:
- trunk/src/VBox/Storage/testcase
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/Makefile.kmk
r44891 r46247 53 53 tstVDIo_TEMPLATE = VBOXR3TSTEXE 54 54 tstVDIo_SOURCES = tstVDIo.cpp \ 55 VDIoBackend.cpp \ 55 56 VDIoBackendMem.cpp \ 56 57 VDMemDisk.cpp \ -
trunk/src/VBox/Storage/testcase/VDIoBackendMem.cpp
r44529 r46247 44 44 /** Size of the transfer. */ 45 45 size_t cbTransfer; 46 /** Number of segments in the array. */47 unsigned cSegs;48 46 /** Completion handler to call. */ 49 47 PFNVDIOCOMPLETE pfnComplete; 50 48 /** Opaque user data. */ 51 49 void *pvUser; 52 /** Segment array - variable in size */ 50 /** S/G buffer. */ 51 RTSGBUF SgBuf; 52 /** Segment array - variable size. */ 53 53 RTSGSEG aSegs[1]; 54 54 } VDIOBACKENDREQ, *PVDIOBACKENDREQ; … … 143 143 144 144 int 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) 147 147 { 148 148 PVDIOBACKENDREQ pReq = NULL; 149 149 PPVDIOBACKENDREQ ppReq = NULL; 150 150 size_t cbData; 151 unsigned cSegs = 0; 151 152 152 153 LogFlowFunc(("Queuing request\n")); 154 155 if (enmTxDir != VDIOTXDIR_FLUSH) 156 RTSgBufSegArrayCreate(pSgBuf, NULL, &cSegs, cbTransfer); 153 157 154 158 pReq = (PVDIOBACKENDREQ)RTMemAlloc(RT_OFFSETOF(VDIOBACKENDREQ, aSegs[cSegs])); … … 168 172 pReq->off = off; 169 173 pReq->pMemDisk = pMemDisk; 170 pReq->cSegs = cSegs;171 174 pReq->pfnComplete = pfnComplete; 172 175 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); 177 180 } 178 181 … … 226 229 case VDIOTXDIR_READ: 227 230 { 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); 231 232 break; 232 233 } 233 234 case VDIOTXDIR_WRITE: 234 235 { 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); 238 237 break; 239 238 } -
trunk/src/VBox/Storage/testcase/VDIoBackendMem.h
r35471 r46247 21 21 #include <iprt/sg.h> 22 22 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" 37 24 38 25 /** Memory backend handle. */ … … 86 73 */ 87 74 int 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); 91 77 92 78 #endif /* __VDIoBackendMem_h__ */ -
trunk/src/VBox/Storage/testcase/tstVDIo.cpp
r44942 r46247 35 35 36 36 #include "VDMemDisk.h" 37 #include "VDIoBackend Mem.h"37 #include "VDIoBackend.h" 38 38 #include "VDIoRnd.h" 39 39 … … 49 49 /** Name of the file. */ 50 50 char *pszName; 51 /** Memory file baking the file. */52 PVD MEMDISK pMemDisk;51 /** Storage backing the file. */ 52 PVDIOSTORAGE pIoStorage; 53 53 /** Flag whether the file is read locked. */ 54 54 bool fReadLock; … … 127 127 /** Head of the pattern list. */ 128 128 RTLISTNODE ListPatterns; 129 /** Memory I/O backend. */130 PVDIOBACKEND MEMpIoBackend;129 /** I/O backend, common data. */ 130 PVDIOBACKEND pIoBackend; 131 131 /** Error interface. */ 132 132 VDINTERFACEERROR VDIfError; … … 139 139 /** I/O RNG handle. */ 140 140 PVDIORND pIoRnd; 141 /** Current storage backend to use. */ 142 char *pszIoBackend; 141 143 } VDTESTGLOB, *PVDTESTGLOB; 142 144 … … 242 244 static DECLCALLBACK(int) vdScriptHandlerResetStatistics(PVDSCRIPTARG paScriptArgs, void *pvUser); 243 245 static DECLCALLBACK(int) vdScriptHandlerResize(PVDSCRIPTARG paScriptArgs, void *pvUser); 246 static DECLCALLBACK(int) vdScriptHandlerSetFileBackend(PVDSCRIPTARG paScriptArgs, void *pvUser); 244 247 245 248 /* create action */ … … 442 445 }; 443 446 447 /* Set file backend. */ 448 const VDSCRIPTTYPE g_aArgSetFileBackend[] = 449 { 450 VDSCRIPTTYPE_STRING /* new file backend */ 451 }; 444 452 445 453 const VDSCRIPTCALLBACK g_aScriptActions[] = … … 472 480 {"resetstatistics", VDSCRIPTTYPE_VOID, g_aArgResetStatistics, RT_ELEMENTS(g_aArgResetStatistics), vdScriptHandlerResetStatistics}, 473 481 {"resize", VDSCRIPTTYPE_VOID, g_aArgResize, RT_ELEMENTS(g_aArgResize), vdScriptHandlerResize}, 482 {"setfilebackend", VDSCRIPTTYPE_VOID, g_aArgSetFileBackend, RT_ELEMENTS(g_aArgSetFileBackend), vdScriptHandlerSetFileBackend}, 474 483 }; 475 484 … … 523 532 bool fDynamic = true; 524 533 bool fIgnoreFlush = false; 534 PVDIOBACKEND pIoBackend = NULL; 525 535 526 536 pcszDisk = paScriptArgs[0].psz; … … 1707 1717 { 1708 1718 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; 1710 1721 } 1711 1722 else … … 1994 2005 } 1995 2006 2007 static 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 1996 2021 static DECLCALLBACK(int) tstVDIoFileOpen(void *pvUser, const char *pszLocation, 1997 2022 uint32_t fOpen, … … 2028 2053 /* If the file exists delete the memory disk. */ 2029 2054 if (fFound) 2030 rc = VD MemDiskSetSize(pIt->pMemDisk, 0);2055 rc = VDIoBackendStorageSetSize(pIt->pIoStorage, 0); 2031 2056 else 2032 2057 { … … 2039 2064 if (pIt->pszName) 2040 2065 { 2041 rc = VDMemDiskCreate(&pIt->pMemDisk, 0); 2066 rc = VDIoBackendStorageCreate(pGlob->pIoBackend, pGlob->pszIoBackend, 2067 pszLocation, pfnCompleted, &pIt->pIoStorage); 2042 2068 } 2043 2069 else … … 2050 2076 RTMemFree(pIt); 2051 2077 } 2078 else 2079 RTListAppend(&pGlob->ListFiles, &pIt->Node); 2052 2080 } 2053 2081 else 2054 2082 rc = VERR_NO_MEMORY; 2055 2056 RTListAppend(&pGlob->ListFiles, &pIt->Node);2057 2083 } 2058 2084 } … … 2118 2144 { 2119 2145 RTListNodeRemove(&pIt->Node); 2120 VD MemDiskDestroy(pIt->pMemDisk);2146 VDIoBackendStorageDestroy(pIt->pIoStorage); 2121 2147 RTStrFree(pIt->pszName); 2122 2148 RTMemFree(pIt); … … 2182 2208 PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage; 2183 2209 2184 return VD MemDiskGetSize(pIoStorage->pFile->pMemDisk, pcbSize);2210 return VDIoBackendStorageGetSize(pIoStorage->pFile->pIoStorage, pcbSize); 2185 2211 } 2186 2212 … … 2189 2215 PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage; 2190 2216 2191 return VD MemDiskSetSize(pIoStorage->pFile->pMemDisk, cbSize);2217 return VDIoBackendStorageSetSize(pIoStorage->pFile->pIoStorage, cbSize); 2192 2218 } 2193 2219 … … 2204 2230 Seg.cbSeg = cbBuffer; 2205 2231 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 */); 2207 2234 if (RT_SUCCESS(rc)) 2208 2235 { … … 2227 2254 Seg.cbSeg = cbBuffer; 2228 2255 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 */); 2230 2258 if (RT_SUCCESS(rc)) 2231 2259 { … … 2241 2269 { 2242 2270 PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage; 2271 int rc = VDIoBackendTransfer(pIoStorage->pFile->pIoStorage, VDIOTXDIR_FLUSH, 0, 2272 0, NULL, NULL, true /* fSync */); 2243 2273 pIoStorage->pFile->cFlushes++; 2244 return VINF_SUCCESS;2274 return rc; 2245 2275 } 2246 2276 … … 2253 2283 PVDTESTGLOB pGlob = (PVDTESTGLOB)pvUser; 2254 2284 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 */); 2258 2290 if (RT_SUCCESS(rc)) 2259 2291 { … … 2273 2305 PVDTESTGLOB pGlob = (PVDTESTGLOB)pvUser; 2274 2306 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 */); 2278 2312 if (RT_SUCCESS(rc)) 2279 2313 { … … 2292 2326 PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage; 2293 2327 2294 rc = VDIoBackend MemTransfer(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 */); 2296 2330 if (RT_SUCCESS(rc)) 2297 2331 { … … 2631 2665 RTListInit(&GlobTest.ListDisks); 2632 2666 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 } 2633 2673 2634 2674 rc = RTFileReadAll(pcszFilename, &pvFile, &cbFile); … … 2667 2707 2668 2708 /* Init I/O backend. */ 2669 rc = VDIoBackend MemCreate(&GlobTest.pIoBackend);2709 rc = VDIoBackendCreate(&GlobTest.pIoBackend); 2670 2710 if (RT_SUCCESS(rc)) 2671 2711 { … … 2686 2726 VDScriptCtxDestroy(hScriptCtx); 2687 2727 } 2688 VDIoBackend MemDestroy(GlobTest.pIoBackend);2728 VDIoBackendDestroy(GlobTest.pIoBackend); 2689 2729 } 2690 2730 else … … 2693 2733 else 2694 2734 RTPrintf("Opening script failed rc=%Rrc\n", rc); 2735 2736 RTStrFree(GlobTest.pszIoBackend); 2695 2737 } 2696 2738
Note:
See TracChangeset
for help on using the changeset viewer.