[27558] | 1 | /* $Id: DrvDiskIntegrity.cpp 99739 2023-05-11 01:01:08Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VBox storage devices: Disk integrity check.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[27558] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[27558] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
[57358] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[27558] | 32 | #define LOG_GROUP LOG_GROUP_DRV_DISK_INTEGRITY
|
---|
[35346] | 33 | #include <VBox/vmm/pdmdrv.h>
|
---|
[59252] | 34 | #include <VBox/vmm/pdmstorageifs.h>
|
---|
[27558] | 35 | #include <iprt/assert.h>
|
---|
| 36 | #include <iprt/string.h>
|
---|
| 37 | #include <iprt/uuid.h>
|
---|
| 38 | #include <iprt/avl.h>
|
---|
| 39 | #include <iprt/mem.h>
|
---|
[65703] | 40 | #include <iprt/memcache.h>
|
---|
[27561] | 41 | #include <iprt/message.h>
|
---|
[28114] | 42 | #include <iprt/sg.h>
|
---|
[28902] | 43 | #include <iprt/time.h>
|
---|
[72310] | 44 | #include <iprt/tracelog.h>
|
---|
[28902] | 45 | #include <iprt/semaphore.h>
|
---|
[29306] | 46 | #include <iprt/asm.h>
|
---|
[27558] | 47 |
|
---|
[35353] | 48 | #include "VBoxDD.h"
|
---|
[27558] | 49 |
|
---|
| 50 |
|
---|
[57358] | 51 | /*********************************************************************************************************************************
|
---|
| 52 | * Structures and Typedefs *
|
---|
| 53 | *********************************************************************************************************************************/
|
---|
[27558] | 54 |
|
---|
| 55 | /**
|
---|
[29412] | 56 | * Transfer direction.
|
---|
| 57 | */
|
---|
| 58 | typedef enum DRVDISKAIOTXDIR
|
---|
| 59 | {
|
---|
[63727] | 60 | /** Invalid. */
|
---|
| 61 | DRVDISKAIOTXDIR_INVALID = 0,
|
---|
[29412] | 62 | /** Read */
|
---|
[63727] | 63 | DRVDISKAIOTXDIR_READ,
|
---|
[29412] | 64 | /** Write */
|
---|
| 65 | DRVDISKAIOTXDIR_WRITE,
|
---|
| 66 | /** Flush */
|
---|
[38878] | 67 | DRVDISKAIOTXDIR_FLUSH,
|
---|
| 68 | /** Discard */
|
---|
[51619] | 69 | DRVDISKAIOTXDIR_DISCARD,
|
---|
| 70 | /** Read after write for immediate verification. */
|
---|
| 71 | DRVDISKAIOTXDIR_READ_AFTER_WRITE
|
---|
[29412] | 72 | } DRVDISKAIOTXDIR;
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
[28114] | 75 | * async I/O request.
|
---|
| 76 | */
|
---|
| 77 | typedef struct DRVDISKAIOREQ
|
---|
| 78 | {
|
---|
[29412] | 79 | /** Transfer direction. */
|
---|
| 80 | DRVDISKAIOTXDIR enmTxDir;
|
---|
[28114] | 81 | /** Start offset. */
|
---|
[29443] | 82 | uint64_t off;
|
---|
[28114] | 83 | /** Transfer size. */
|
---|
[29443] | 84 | size_t cbTransfer;
|
---|
[28114] | 85 | /** Segment array. */
|
---|
[29443] | 86 | PCRTSGSEG paSeg;
|
---|
[28114] | 87 | /** Number of array entries. */
|
---|
[29443] | 88 | unsigned cSeg;
|
---|
[28114] | 89 | /** User argument */
|
---|
[29443] | 90 | void *pvUser;
|
---|
[28902] | 91 | /** Slot in the array. */
|
---|
[29443] | 92 | unsigned iSlot;
|
---|
| 93 | /** Start timestamp */
|
---|
| 94 | uint64_t tsStart;
|
---|
| 95 | /** Completion timestamp. */
|
---|
| 96 | uint64_t tsComplete;
|
---|
[38878] | 97 | /** Ranges to discard. */
|
---|
| 98 | PCRTRANGE paRanges;
|
---|
| 99 | /** Number of ranges. */
|
---|
| 100 | unsigned cRanges;
|
---|
[63727] | 101 | /** I/O segment for the extended media interface
|
---|
| 102 | * to hold the data. */
|
---|
| 103 | RTSGSEG IoSeg;
|
---|
[28114] | 104 | } DRVDISKAIOREQ, *PDRVDISKAIOREQ;
|
---|
| 105 |
|
---|
| 106 | /**
|
---|
[27561] | 107 | * I/O log entry.
|
---|
| 108 | */
|
---|
| 109 | typedef struct IOLOGENT
|
---|
| 110 | {
|
---|
| 111 | /** Start offset */
|
---|
| 112 | uint64_t off;
|
---|
| 113 | /** Write size */
|
---|
| 114 | size_t cbWrite;
|
---|
| 115 | /** Number of references to this entry. */
|
---|
| 116 | unsigned cRefs;
|
---|
| 117 | } IOLOGENT, *PIOLOGENT;
|
---|
| 118 |
|
---|
| 119 | /**
|
---|
[27558] | 120 | * Disk segment.
|
---|
| 121 | */
|
---|
| 122 | typedef struct DRVDISKSEGMENT
|
---|
| 123 | {
|
---|
| 124 | /** AVL core. */
|
---|
| 125 | AVLRFOFFNODECORE Core;
|
---|
| 126 | /** Size of the segment */
|
---|
| 127 | size_t cbSeg;
|
---|
| 128 | /** Data for this segment */
|
---|
| 129 | uint8_t *pbSeg;
|
---|
[33540] | 130 | /** Number of entries in the I/O array. */
|
---|
[27561] | 131 | unsigned cIoLogEntries;
|
---|
| 132 | /** Array of I/O log references. */
|
---|
| 133 | PIOLOGENT apIoLog[1];
|
---|
[27558] | 134 | } DRVDISKSEGMENT, *PDRVDISKSEGMENT;
|
---|
| 135 |
|
---|
| 136 | /**
|
---|
[28902] | 137 | * Active requests list entry.
|
---|
| 138 | */
|
---|
| 139 | typedef struct DRVDISKAIOREQACTIVE
|
---|
| 140 | {
|
---|
| 141 | /** Pointer to the request. */
|
---|
| 142 | volatile PDRVDISKAIOREQ pIoReq;
|
---|
| 143 | /** Start timestamp. */
|
---|
| 144 | uint64_t tsStart;
|
---|
| 145 | } DRVDISKAIOREQACTIVE, *PDRVDISKAIOREQACTIVE;
|
---|
| 146 |
|
---|
| 147 | /**
|
---|
[27558] | 148 | * Disk integrity driver instance data.
|
---|
| 149 | *
|
---|
| 150 | * @implements PDMIMEDIA
|
---|
[73094] | 151 | * @implements PDMIMEDIAPORT
|
---|
| 152 | * @implements PDMIMEDIAEX
|
---|
| 153 | * @implements PDMIMEDIAEXPORT
|
---|
| 154 | * @implements PDMIMEDIAMOUNT
|
---|
| 155 | * @implements PDMIMEDIAMOUNTNOTIFY
|
---|
[27558] | 156 | */
|
---|
| 157 | typedef struct DRVDISKINTEGRITY
|
---|
| 158 | {
|
---|
| 159 | /** Pointer driver instance. */
|
---|
| 160 | PPDMDRVINS pDrvIns;
|
---|
| 161 | /** Pointer to the media driver below us.
|
---|
| 162 | * This is NULL if the media is not mounted. */
|
---|
| 163 | PPDMIMEDIA pDrvMedia;
|
---|
| 164 | /** Our media interface */
|
---|
| 165 | PDMIMEDIA IMedia;
|
---|
| 166 |
|
---|
[34433] | 167 | /** The media port interface above. */
|
---|
| 168 | PPDMIMEDIAPORT pDrvMediaPort;
|
---|
| 169 | /** Media port interface */
|
---|
| 170 | PDMIMEDIAPORT IMediaPort;
|
---|
| 171 |
|
---|
[63700] | 172 | /** The extended media port interface above. */
|
---|
| 173 | PPDMIMEDIAEXPORT pDrvMediaExPort;
|
---|
| 174 | /** Our extended media port interface */
|
---|
| 175 | PDMIMEDIAEXPORT IMediaExPort;
|
---|
| 176 |
|
---|
| 177 | /** The extended media interface below. */
|
---|
| 178 | PPDMIMEDIAEX pDrvMediaEx;
|
---|
| 179 | /** Our extended media interface */
|
---|
| 180 | PDMIMEDIAEX IMediaEx;
|
---|
| 181 |
|
---|
[73094] | 182 | /** The mount interface below. */
|
---|
| 183 | PPDMIMOUNT pDrvMount;
|
---|
| 184 | /** Our mount interface */
|
---|
| 185 | PDMIMOUNT IMount;
|
---|
| 186 |
|
---|
| 187 | /** The mount notify interface above. */
|
---|
| 188 | PPDMIMOUNTNOTIFY pDrvMountNotify;
|
---|
| 189 | /** Our mount notify interface. */
|
---|
| 190 | PDMIMOUNTNOTIFY IMountNotify;
|
---|
| 191 |
|
---|
[28902] | 192 | /** Flag whether consistency checks are enabled. */
|
---|
| 193 | bool fCheckConsistency;
|
---|
[46859] | 194 | /** Flag whether the RAM disk was prepopulated. */
|
---|
| 195 | bool fPrepopulateRamDisk;
|
---|
[27558] | 196 | /** AVL tree containing the disk blocks to check. */
|
---|
| 197 | PAVLRFOFFTREE pTreeSegments;
|
---|
[28902] | 198 |
|
---|
| 199 | /** Flag whether async request tracing is enabled. */
|
---|
| 200 | bool fTraceRequests;
|
---|
| 201 | /** Interval the thread should check for expired requests (milliseconds). */
|
---|
| 202 | uint32_t uCheckIntervalMs;
|
---|
| 203 | /** Expire timeout for a request (milliseconds). */
|
---|
| 204 | uint32_t uExpireIntervalMs;
|
---|
| 205 | /** Thread which checks for lost requests. */
|
---|
| 206 | RTTHREAD hThread;
|
---|
| 207 | /** Event semaphore */
|
---|
| 208 | RTSEMEVENT SemEvent;
|
---|
| 209 | /** Flag whether the thread should run. */
|
---|
| 210 | bool fRunning;
|
---|
| 211 | /** Array containing active requests. */
|
---|
| 212 | DRVDISKAIOREQACTIVE apReqActive[128];
|
---|
| 213 | /** Next free slot in the array */
|
---|
| 214 | volatile unsigned iNextFreeSlot;
|
---|
[65703] | 215 | /** Request cache. */
|
---|
| 216 | RTMEMCACHE hReqCache;
|
---|
[29443] | 217 |
|
---|
| 218 | /** Flag whether we check for requests completing twice. */
|
---|
| 219 | bool fCheckDoubleCompletion;
|
---|
| 220 | /** Number of requests we go back. */
|
---|
| 221 | unsigned cEntries;
|
---|
| 222 | /** Array of completed but still observed requests. */
|
---|
| 223 | PDRVDISKAIOREQ *papIoReq;
|
---|
| 224 | /** Current entry in the array. */
|
---|
| 225 | unsigned iEntry;
|
---|
[38541] | 226 |
|
---|
[51619] | 227 | /** Flag whether to do a immediate read after write for verification. */
|
---|
| 228 | bool fReadAfterWrite;
|
---|
[51749] | 229 | /** Flag whether to record the data to write before the write completed successfully.
|
---|
| 230 | * Useful in case the data is modified in place later on (encryption for instance). */
|
---|
| 231 | bool fRecordWriteBeforeCompletion;
|
---|
[63727] | 232 | /** Flag whether to validate memory buffers when the extended media interface is used. */
|
---|
| 233 | bool fValidateMemBufs;
|
---|
[51619] | 234 |
|
---|
[38541] | 235 | /** I/O logger to use if enabled. */
|
---|
[72310] | 236 | RTTRACELOGWR hIoLogger;
|
---|
[63727] | 237 | /** Size of the opaque handle until our tracking structure starts in bytes. */
|
---|
| 238 | size_t cbIoReqOpaque;
|
---|
[27558] | 239 | } DRVDISKINTEGRITY, *PDRVDISKINTEGRITY;
|
---|
| 240 |
|
---|
| 241 |
|
---|
[72310] | 242 | /**
|
---|
| 243 | * Read/Write event items.
|
---|
| 244 | */
|
---|
| 245 | static const RTTRACELOGEVTITEMDESC g_aEvtItemsReadWrite[] =
|
---|
| 246 | {
|
---|
[72336] | 247 | { "Async", "Flag whether the request is asynchronous", RTTRACELOGTYPE_BOOL, 0 },
|
---|
| 248 | { "Offset", "Offset to start reading/writing from/to", RTTRACELOGTYPE_UINT64, 0 },
|
---|
| 249 | { "Size", "Number of bytes to transfer", RTTRACELOGTYPE_SIZE, 0 }
|
---|
[72310] | 250 | };
|
---|
| 251 |
|
---|
| 252 | /**
|
---|
[72336] | 253 | * Flush event items.
|
---|
| 254 | */
|
---|
| 255 | static const RTTRACELOGEVTITEMDESC g_aEvtItemsFlush[] =
|
---|
| 256 | {
|
---|
| 257 | { "Async", "Flag whether the request is asynchronous", RTTRACELOGTYPE_BOOL, 0 }
|
---|
| 258 | };
|
---|
| 259 |
|
---|
| 260 | /**
|
---|
[72310] | 261 | * I/O request complete items.
|
---|
| 262 | */
|
---|
| 263 | static const RTTRACELOGEVTITEMDESC g_aEvtItemsComplete[] =
|
---|
| 264 | {
|
---|
| 265 | { "Status", "Status code the request completed with", RTTRACELOGTYPE_INT32, 0 }
|
---|
| 266 | };
|
---|
| 267 |
|
---|
| 268 | /** Read event descriptor. */
|
---|
| 269 | static const RTTRACELOGEVTDESC g_EvtRead =
|
---|
| 270 | { "Read", "Read data from disk", RTTRACELOGEVTSEVERITY_DEBUG, RT_ELEMENTS(g_aEvtItemsReadWrite), &g_aEvtItemsReadWrite[0] };
|
---|
| 271 | /** Write event descriptor. */
|
---|
| 272 | static const RTTRACELOGEVTDESC g_EvtWrite =
|
---|
| 273 | { "Write", "Write data to disk", RTTRACELOGEVTSEVERITY_DEBUG, RT_ELEMENTS(g_aEvtItemsReadWrite), &g_aEvtItemsReadWrite[0] };
|
---|
| 274 | /** Flush event descriptor. */
|
---|
| 275 | static const RTTRACELOGEVTDESC g_EvtFlush =
|
---|
[72336] | 276 | { "Flush", "Flush written data to disk", RTTRACELOGEVTSEVERITY_DEBUG, RT_ELEMENTS(g_aEvtItemsFlush), &g_aEvtItemsFlush[0] };
|
---|
[72310] | 277 | /** I/O request complete event descriptor. */
|
---|
| 278 | static const RTTRACELOGEVTDESC g_EvtComplete =
|
---|
| 279 | { "Complete", "A previously started I/O request completed", RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
| 280 | RT_ELEMENTS(g_aEvtItemsComplete), &g_aEvtItemsComplete[0]};
|
---|
| 281 |
|
---|
[65703] | 282 | #define DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(a_pThis, a_hIoReq) ((*(PDRVDISKAIOREQ *)((uintptr_t)(a_hIoReq) + (a_pThis)->cbIoReqOpaque)))
|
---|
| 283 | #define DISKINTEGRITY_IOREQ_HANDLE_2_UPPER_OPAQUE(a_pThis, a_hIoReq) ((void *)((uintptr_t)(a_hIoReq) + (a_pThis)->cbIoReqOpaque + sizeof(PDRVDISKAIOREQ)))
|
---|
| 284 | #define DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(a_pvIoReqAlloc) (*(PDRVDISKAIOREQ *)(a_pvIoReqAlloc))
|
---|
| 285 | #define DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(a_pvIoReqAlloc) ((void *)((uintptr_t)(a_pvIoReqAlloc) + sizeof(PDRVDISKAIOREQ)))
|
---|
| 286 |
|
---|
[63727] | 287 | static void drvdiskintIoReqCheckForDoubleCompletion(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq,
|
---|
| 288 | bool fMediaEx)
|
---|
[29443] | 289 | {
|
---|
[63727] | 290 | /* Search if the I/O request completed already. */
|
---|
| 291 | for (unsigned i = 0; i < pThis->cEntries; i++)
|
---|
[29443] | 292 | {
|
---|
[63727] | 293 | if (RT_UNLIKELY(pThis->papIoReq[i] == pIoReq))
|
---|
[29443] | 294 | {
|
---|
[63727] | 295 | RTMsgError("Request %#p completed already!\n", pIoReq);
|
---|
| 296 | if (!fMediaEx)
|
---|
[29443] | 297 | RTMsgError("Start timestamp %llu Completion timestamp %llu (completed after %llu ms)\n",
|
---|
| 298 | pIoReq->tsStart, pIoReq->tsComplete, pIoReq->tsComplete - pIoReq->tsStart);
|
---|
[63727] | 299 | RTAssertDebugBreak();
|
---|
[29443] | 300 | }
|
---|
[63727] | 301 | }
|
---|
[29443] | 302 |
|
---|
[63727] | 303 | pIoReq->tsComplete = RTTimeSystemMilliTS();
|
---|
| 304 | Assert(!pThis->papIoReq[pThis->iEntry]);
|
---|
| 305 | pThis->papIoReq[pThis->iEntry] = pIoReq;
|
---|
[29443] | 306 |
|
---|
[63727] | 307 | pThis->iEntry = (pThis->iEntry+1) % pThis->cEntries;
|
---|
| 308 | if (pThis->papIoReq[pThis->iEntry])
|
---|
| 309 | {
|
---|
| 310 | if (!fMediaEx)
|
---|
[29443] | 311 | RTMemFree(pThis->papIoReq[pThis->iEntry]);
|
---|
[63727] | 312 | pThis->papIoReq[pThis->iEntry] = NULL;
|
---|
[29443] | 313 | }
|
---|
[63727] | 314 | }
|
---|
| 315 |
|
---|
[38670] | 316 | static void drvdiskintIoLogEntryRelease(PIOLOGENT pIoLogEnt)
|
---|
| 317 | {
|
---|
| 318 | pIoLogEnt->cRefs--;
|
---|
| 319 | if (!pIoLogEnt->cRefs)
|
---|
| 320 | RTMemFree(pIoLogEnt);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[29443] | 323 | /**
|
---|
[28114] | 324 | * Record a successful write to the virtual disk.
|
---|
| 325 | *
|
---|
| 326 | * @returns VBox status code.
|
---|
| 327 | * @param pThis Disk integrity driver instance data.
|
---|
| 328 | * @param paSeg Segment array of the write to record.
|
---|
| 329 | * @param cSeg Number of segments.
|
---|
| 330 | * @param off Start offset.
|
---|
| 331 | * @param cbWrite Number of bytes to record.
|
---|
| 332 | */
|
---|
| 333 | static int drvdiskintWriteRecord(PDRVDISKINTEGRITY pThis, PCRTSGSEG paSeg, unsigned cSeg,
|
---|
| 334 | uint64_t off, size_t cbWrite)
|
---|
[27558] | 335 | {
|
---|
[28114] | 336 | int rc = VINF_SUCCESS;
|
---|
[27558] | 337 |
|
---|
[28115] | 338 | LogFlowFunc(("pThis=%#p paSeg=%#p cSeg=%u off=%llx cbWrite=%u\n",
|
---|
| 339 | pThis, paSeg, cSeg, off, cbWrite));
|
---|
| 340 |
|
---|
[27558] | 341 | /* Update the segments */
|
---|
| 342 | size_t cbLeft = cbWrite;
|
---|
| 343 | RTFOFF offCurr = (RTFOFF)off;
|
---|
[28114] | 344 | RTSGBUF SgBuf;
|
---|
[27561] | 345 | PIOLOGENT pIoLogEnt = (PIOLOGENT)RTMemAllocZ(sizeof(IOLOGENT));
|
---|
| 346 | if (!pIoLogEnt)
|
---|
| 347 | return VERR_NO_MEMORY;
|
---|
[27558] | 348 |
|
---|
[27561] | 349 | pIoLogEnt->off = off;
|
---|
| 350 | pIoLogEnt->cbWrite = cbWrite;
|
---|
| 351 | pIoLogEnt->cRefs = 0;
|
---|
| 352 |
|
---|
[28114] | 353 | RTSgBufInit(&SgBuf, paSeg, cSeg);
|
---|
| 354 |
|
---|
[27558] | 355 | while (cbLeft)
|
---|
| 356 | {
|
---|
| 357 | PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetRangeGet(pThis->pTreeSegments, offCurr);
|
---|
| 358 | size_t cbRange = 0;
|
---|
| 359 | bool fSet = false;
|
---|
| 360 | unsigned offSeg = 0;
|
---|
| 361 |
|
---|
| 362 | if (!pSeg)
|
---|
| 363 | {
|
---|
| 364 | /* Get next segment */
|
---|
| 365 | pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetGetBestFit(pThis->pTreeSegments, offCurr, true);
|
---|
| 366 | if ( !pSeg
|
---|
| 367 | || offCurr + (RTFOFF)cbLeft <= pSeg->Core.Key)
|
---|
| 368 | cbRange = cbLeft;
|
---|
| 369 | else
|
---|
| 370 | cbRange = pSeg->Core.Key - offCurr;
|
---|
| 371 |
|
---|
[27561] | 372 | Assert(cbRange % 512 == 0);
|
---|
| 373 |
|
---|
[27558] | 374 | /* Create new segment */
|
---|
[73097] | 375 | pSeg = (PDRVDISKSEGMENT)RTMemAllocZ(RT_UOFFSETOF_DYN(DRVDISKSEGMENT, apIoLog[cbRange / 512]));
|
---|
[27558] | 376 | if (pSeg)
|
---|
| 377 | {
|
---|
[27561] | 378 | pSeg->Core.Key = offCurr;
|
---|
| 379 | pSeg->Core.KeyLast = offCurr + (RTFOFF)cbRange - 1;
|
---|
| 380 | pSeg->cbSeg = cbRange;
|
---|
| 381 | pSeg->pbSeg = (uint8_t *)RTMemAllocZ(cbRange);
|
---|
[65485] | 382 | pSeg->cIoLogEntries = (uint32_t)cbRange / 512;
|
---|
[27558] | 383 | if (!pSeg->pbSeg)
|
---|
| 384 | RTMemFree(pSeg);
|
---|
| 385 | else
|
---|
| 386 | {
|
---|
| 387 | bool fInserted = RTAvlrFileOffsetInsert(pThis->pTreeSegments, &pSeg->Core);
|
---|
[63727] | 388 | AssertMsg(fInserted, ("Bug!\n")); RT_NOREF(fInserted);
|
---|
[27558] | 389 | fSet = true;
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
| 393 | else
|
---|
| 394 | {
|
---|
| 395 | fSet = true;
|
---|
| 396 | offSeg = offCurr - pSeg->Core.Key;
|
---|
[27561] | 397 | cbRange = RT_MIN(cbLeft, (size_t)(pSeg->Core.KeyLast + 1 - offCurr));
|
---|
[27558] | 398 | }
|
---|
| 399 |
|
---|
| 400 | if (fSet)
|
---|
| 401 | {
|
---|
| 402 | AssertPtr(pSeg);
|
---|
[28144] | 403 | size_t cbCopied = RTSgBufCopyToBuf(&SgBuf, pSeg->pbSeg + offSeg, cbRange);
|
---|
[63727] | 404 | Assert(cbCopied == cbRange); RT_NOREF(cbCopied);
|
---|
[27561] | 405 |
|
---|
| 406 | /* Update the I/O log pointers */
|
---|
| 407 | Assert(offSeg % 512 == 0);
|
---|
| 408 | Assert(cbRange % 512 == 0);
|
---|
| 409 | while (offSeg < cbRange)
|
---|
| 410 | {
|
---|
| 411 | uint32_t uSector = offSeg / 512;
|
---|
| 412 | PIOLOGENT pIoLogOld = NULL;
|
---|
| 413 |
|
---|
| 414 | AssertMsg(uSector < pSeg->cIoLogEntries, ("Internal bug!\n"));
|
---|
| 415 |
|
---|
| 416 | pIoLogOld = pSeg->apIoLog[uSector];
|
---|
| 417 | if (pIoLogOld)
|
---|
| 418 | {
|
---|
| 419 | pIoLogOld->cRefs--;
|
---|
| 420 | if (!pIoLogOld->cRefs)
|
---|
| 421 | RTMemFree(pIoLogOld);
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | pSeg->apIoLog[uSector] = pIoLogEnt;
|
---|
| 425 | pIoLogEnt->cRefs++;
|
---|
| 426 |
|
---|
| 427 | offSeg += 512;
|
---|
| 428 | }
|
---|
[27558] | 429 | }
|
---|
[28114] | 430 | else
|
---|
| 431 | RTSgBufAdvance(&SgBuf, cbRange);
|
---|
[27558] | 432 |
|
---|
| 433 | offCurr += cbRange;
|
---|
| 434 | cbLeft -= cbRange;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | return rc;
|
---|
| 438 | }
|
---|
| 439 |
|
---|
[28114] | 440 | /**
|
---|
| 441 | * Verifies a read request.
|
---|
| 442 | *
|
---|
| 443 | * @returns VBox status code.
|
---|
| 444 | * @param pThis Disk integrity driver instance data.
|
---|
| 445 | * @param paSeg Segment array of the containing the data buffers to verify.
|
---|
| 446 | * @param cSeg Number of segments.
|
---|
| 447 | * @param off Start offset.
|
---|
[64274] | 448 | * @param cbRead Number of bytes to verify.
|
---|
[28114] | 449 | */
|
---|
| 450 | static int drvdiskintReadVerify(PDRVDISKINTEGRITY pThis, PCRTSGSEG paSeg, unsigned cSeg,
|
---|
| 451 | uint64_t off, size_t cbRead)
|
---|
| 452 | {
|
---|
| 453 | int rc = VINF_SUCCESS;
|
---|
| 454 |
|
---|
[28115] | 455 | LogFlowFunc(("pThis=%#p paSeg=%#p cSeg=%u off=%llx cbRead=%u\n",
|
---|
| 456 | pThis, paSeg, cSeg, off, cbRead));
|
---|
| 457 |
|
---|
[28114] | 458 | Assert(off % 512 == 0);
|
---|
| 459 | Assert(cbRead % 512 == 0);
|
---|
| 460 |
|
---|
| 461 | /* Compare read data */
|
---|
| 462 | size_t cbLeft = cbRead;
|
---|
| 463 | RTFOFF offCurr = (RTFOFF)off;
|
---|
| 464 | RTSGBUF SgBuf;
|
---|
| 465 |
|
---|
| 466 | RTSgBufInit(&SgBuf, paSeg, cSeg);
|
---|
| 467 |
|
---|
| 468 | while (cbLeft)
|
---|
| 469 | {
|
---|
| 470 | PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetRangeGet(pThis->pTreeSegments, offCurr);
|
---|
| 471 | size_t cbRange = 0;
|
---|
| 472 | bool fCmp = false;
|
---|
| 473 | unsigned offSeg = 0;
|
---|
| 474 |
|
---|
| 475 | if (!pSeg)
|
---|
| 476 | {
|
---|
| 477 | /* Get next segment */
|
---|
| 478 | pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetGetBestFit(pThis->pTreeSegments, offCurr, true);
|
---|
| 479 | if (!pSeg)
|
---|
| 480 | {
|
---|
| 481 | /* No data in the tree for this read. Assume everything is ok. */
|
---|
| 482 | cbRange = cbLeft;
|
---|
| 483 | }
|
---|
| 484 | else if (offCurr + (RTFOFF)cbLeft <= pSeg->Core.Key)
|
---|
| 485 | cbRange = cbLeft;
|
---|
| 486 | else
|
---|
| 487 | cbRange = pSeg->Core.Key - offCurr;
|
---|
[46859] | 488 |
|
---|
| 489 | if (pThis->fPrepopulateRamDisk)
|
---|
| 490 | {
|
---|
| 491 | /* No segment means everything should be 0 for this part. */
|
---|
| 492 | if (!RTSgBufIsZero(&SgBuf, cbRange))
|
---|
| 493 | {
|
---|
| 494 | RTMsgError("Corrupted disk at offset %llu (expected everything to be 0)!\n",
|
---|
| 495 | offCurr);
|
---|
| 496 | RTAssertDebugBreak();
|
---|
| 497 | }
|
---|
| 498 | }
|
---|
[28114] | 499 | }
|
---|
| 500 | else
|
---|
| 501 | {
|
---|
| 502 | fCmp = true;
|
---|
| 503 | offSeg = offCurr - pSeg->Core.Key;
|
---|
| 504 | cbRange = RT_MIN(cbLeft, (size_t)(pSeg->Core.KeyLast + 1 - offCurr));
|
---|
| 505 | }
|
---|
| 506 |
|
---|
| 507 | if (fCmp)
|
---|
| 508 | {
|
---|
| 509 | RTSGSEG Seg;
|
---|
| 510 | RTSGBUF SgBufCmp;
|
---|
[28118] | 511 | size_t cbOff = 0;
|
---|
[28114] | 512 |
|
---|
| 513 | Seg.cbSeg = cbRange;
|
---|
| 514 | Seg.pvSeg = pSeg->pbSeg + offSeg;
|
---|
| 515 |
|
---|
| 516 | RTSgBufInit(&SgBufCmp, &Seg, 1);
|
---|
[28118] | 517 | if (RTSgBufCmpEx(&SgBuf, &SgBufCmp, cbRange, &cbOff, true))
|
---|
[28114] | 518 | {
|
---|
[28118] | 519 | /* Corrupted disk, print I/O log entry of the last write which accessed this range. */
|
---|
[65485] | 520 | uint32_t cSector = (offSeg + (uint32_t)cbOff) / 512;
|
---|
[28118] | 521 | AssertMsg(cSector < pSeg->cIoLogEntries, ("Internal bug!\n"));
|
---|
[28114] | 522 |
|
---|
[28118] | 523 | RTMsgError("Corrupted disk at offset %llu (%u bytes in the current read buffer)!\n",
|
---|
| 524 | offCurr + cbOff, cbOff);
|
---|
| 525 | RTMsgError("Last write to this sector started at offset %llu with %u bytes (%u references to this log entry)\n",
|
---|
| 526 | pSeg->apIoLog[cSector]->off,
|
---|
| 527 | pSeg->apIoLog[cSector]->cbWrite,
|
---|
| 528 | pSeg->apIoLog[cSector]->cRefs);
|
---|
| 529 | RTAssertDebugBreak();
|
---|
[28114] | 530 | }
|
---|
| 531 | }
|
---|
[28144] | 532 | else
|
---|
| 533 | RTSgBufAdvance(&SgBuf, cbRange);
|
---|
[28114] | 534 |
|
---|
| 535 | offCurr += cbRange;
|
---|
| 536 | cbLeft -= cbRange;
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | return rc;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
[28902] | 542 | /**
|
---|
[38670] | 543 | * Discards the given ranges from the disk.
|
---|
| 544 | *
|
---|
| 545 | * @returns VBox status code.
|
---|
| 546 | * @param pThis Disk integrity driver instance data.
|
---|
| 547 | * @param paRanges Array of ranges to discard.
|
---|
| 548 | * @param cRanges Number of ranges in the array.
|
---|
| 549 | */
|
---|
[39518] | 550 | static int drvdiskintDiscardRecords(PDRVDISKINTEGRITY pThis, PCRTRANGE paRanges, unsigned cRanges)
|
---|
[38670] | 551 | {
|
---|
| 552 | int rc = VINF_SUCCESS;
|
---|
| 553 |
|
---|
| 554 | LogFlowFunc(("pThis=%#p paRanges=%#p cRanges=%u\n", pThis, paRanges, cRanges));
|
---|
| 555 |
|
---|
| 556 | for (unsigned i = 0; i < cRanges; i++)
|
---|
| 557 | {
|
---|
| 558 | uint64_t offStart = paRanges[i].offStart;
|
---|
| 559 | size_t cbLeft = paRanges[i].cbRange;
|
---|
| 560 |
|
---|
| 561 | LogFlowFunc(("Discarding off=%llu cbRange=%zu\n", offStart, cbLeft));
|
---|
| 562 |
|
---|
| 563 | while (cbLeft)
|
---|
| 564 | {
|
---|
| 565 | size_t cbRange;
|
---|
| 566 | PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetRangeGet(pThis->pTreeSegments, offStart);
|
---|
| 567 |
|
---|
| 568 | if (!pSeg)
|
---|
| 569 | {
|
---|
| 570 | /* Get next segment */
|
---|
| 571 | pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetGetBestFit(pThis->pTreeSegments, offStart, true);
|
---|
| 572 | if ( !pSeg
|
---|
| 573 | || (RTFOFF)offStart + (RTFOFF)cbLeft <= pSeg->Core.Key)
|
---|
| 574 | cbRange = cbLeft;
|
---|
| 575 | else
|
---|
| 576 | cbRange = pSeg->Core.Key - offStart;
|
---|
| 577 |
|
---|
| 578 | Assert(!(cbRange % 512));
|
---|
| 579 | }
|
---|
| 580 | else
|
---|
| 581 | {
|
---|
| 582 | size_t cbPreLeft, cbPostLeft;
|
---|
| 583 |
|
---|
[44236] | 584 | cbRange = RT_MIN(cbLeft, pSeg->Core.KeyLast - offStart + 1);
|
---|
[38670] | 585 | cbPreLeft = offStart - pSeg->Core.Key;
|
---|
| 586 | cbPostLeft = pSeg->cbSeg - cbRange - cbPreLeft;
|
---|
| 587 |
|
---|
| 588 | Assert(!(cbRange % 512));
|
---|
| 589 | Assert(!(cbPreLeft % 512));
|
---|
| 590 | Assert(!(cbPostLeft % 512));
|
---|
| 591 |
|
---|
| 592 | LogFlowFunc(("cbRange=%zu cbPreLeft=%zu cbPostLeft=%zu\n",
|
---|
| 593 | cbRange, cbPreLeft, cbPostLeft));
|
---|
| 594 |
|
---|
| 595 | RTAvlrFileOffsetRemove(pThis->pTreeSegments, pSeg->Core.Key);
|
---|
| 596 |
|
---|
| 597 | if (!cbPreLeft && !cbPostLeft)
|
---|
| 598 | {
|
---|
| 599 | /* Just free the whole segment. */
|
---|
| 600 | LogFlowFunc(("Freeing whole segment pSeg=%#p\n", pSeg));
|
---|
| 601 | RTMemFree(pSeg->pbSeg);
|
---|
| 602 | for (unsigned idx = 0; idx < pSeg->cIoLogEntries; idx++)
|
---|
| 603 | drvdiskintIoLogEntryRelease(pSeg->apIoLog[idx]);
|
---|
| 604 | RTMemFree(pSeg);
|
---|
| 605 | }
|
---|
| 606 | else if (cbPreLeft && !cbPostLeft)
|
---|
| 607 | {
|
---|
| 608 | /* Realloc to new size and insert. */
|
---|
| 609 | LogFlowFunc(("Realloc segment pSeg=%#p\n", pSeg));
|
---|
| 610 | pSeg->pbSeg = (uint8_t *)RTMemRealloc(pSeg->pbSeg, cbPreLeft);
|
---|
[65485] | 611 | for (unsigned idx = (uint32_t)(cbPreLeft / 512); idx < pSeg->cIoLogEntries; idx++)
|
---|
[38670] | 612 | drvdiskintIoLogEntryRelease(pSeg->apIoLog[idx]);
|
---|
[73097] | 613 | pSeg = (PDRVDISKSEGMENT)RTMemRealloc(pSeg, RT_UOFFSETOF_DYN(DRVDISKSEGMENT, apIoLog[cbPreLeft / 512]));
|
---|
[38670] | 614 | pSeg->Core.KeyLast = pSeg->Core.Key + cbPreLeft - 1;
|
---|
| 615 | pSeg->cbSeg = cbPreLeft;
|
---|
[65485] | 616 | pSeg->cIoLogEntries = (uint32_t)(cbPreLeft / 512);
|
---|
[38670] | 617 | bool fInserted = RTAvlrFileOffsetInsert(pThis->pTreeSegments, &pSeg->Core);
|
---|
[63727] | 618 | Assert(fInserted); RT_NOREF(fInserted);
|
---|
[38670] | 619 | }
|
---|
| 620 | else if (!cbPreLeft && cbPostLeft)
|
---|
| 621 | {
|
---|
| 622 | /* Move data to the front and realloc. */
|
---|
| 623 | LogFlowFunc(("Move data and realloc segment pSeg=%#p\n", pSeg));
|
---|
| 624 | memmove(pSeg->pbSeg, pSeg->pbSeg + cbRange, cbPostLeft);
|
---|
| 625 | for (unsigned idx = 0; idx < cbRange / 512; idx++)
|
---|
| 626 | drvdiskintIoLogEntryRelease(pSeg->apIoLog[idx]);
|
---|
| 627 | for (unsigned idx = 0; idx < cbPostLeft /512; idx++)
|
---|
| 628 | pSeg->apIoLog[idx] = pSeg->apIoLog[(cbRange / 512) + idx];
|
---|
[73097] | 629 | pSeg = (PDRVDISKSEGMENT)RTMemRealloc(pSeg, RT_UOFFSETOF_DYN(DRVDISKSEGMENT, apIoLog[cbPostLeft / 512]));
|
---|
[38670] | 630 | pSeg->pbSeg = (uint8_t *)RTMemRealloc(pSeg->pbSeg, cbPostLeft);
|
---|
| 631 | pSeg->Core.Key += cbRange;
|
---|
| 632 | pSeg->cbSeg = cbPostLeft;
|
---|
[65485] | 633 | pSeg->cIoLogEntries = (uint32_t)(cbPostLeft / 512);
|
---|
[38670] | 634 | bool fInserted = RTAvlrFileOffsetInsert(pThis->pTreeSegments, &pSeg->Core);
|
---|
[63727] | 635 | Assert(fInserted); RT_NOREF(fInserted);
|
---|
[38670] | 636 | }
|
---|
| 637 | else
|
---|
| 638 | {
|
---|
| 639 | /* Split the segment into 2 new segments. */
|
---|
| 640 | LogFlowFunc(("Split segment pSeg=%#p\n", pSeg));
|
---|
[73097] | 641 | PDRVDISKSEGMENT pSegPost = (PDRVDISKSEGMENT)RTMemAllocZ(RT_UOFFSETOF_DYN(DRVDISKSEGMENT, apIoLog[cbPostLeft / 512]));
|
---|
[38670] | 642 | if (pSegPost)
|
---|
| 643 | {
|
---|
| 644 | pSegPost->Core.Key = pSeg->Core.Key + cbPreLeft + cbRange;
|
---|
| 645 | pSegPost->Core.KeyLast = pSeg->Core.KeyLast;
|
---|
| 646 | pSegPost->cbSeg = cbPostLeft;
|
---|
| 647 | pSegPost->pbSeg = (uint8_t *)RTMemAllocZ(cbPostLeft);
|
---|
[65485] | 648 | pSegPost->cIoLogEntries = (uint32_t)(cbPostLeft / 512);
|
---|
[38670] | 649 | if (!pSegPost->pbSeg)
|
---|
| 650 | RTMemFree(pSegPost);
|
---|
| 651 | else
|
---|
| 652 | {
|
---|
| 653 | memcpy(pSegPost->pbSeg, pSeg->pbSeg + cbPreLeft + cbRange, cbPostLeft);
|
---|
[65485] | 654 | for (unsigned idx = 0; idx < (uint32_t)(cbPostLeft / 512); idx++)
|
---|
[38670] | 655 | pSegPost->apIoLog[idx] = pSeg->apIoLog[((cbPreLeft + cbRange) / 512) + idx];
|
---|
| 656 |
|
---|
| 657 | bool fInserted = RTAvlrFileOffsetInsert(pThis->pTreeSegments, &pSegPost->Core);
|
---|
[63727] | 658 | Assert(fInserted); RT_NOREF(fInserted);
|
---|
[38670] | 659 | }
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 | /* Shrink the current segment. */
|
---|
| 663 | pSeg->pbSeg = (uint8_t *)RTMemRealloc(pSeg->pbSeg, cbPreLeft);
|
---|
[65485] | 664 | for (unsigned idx = (uint32_t)(cbPreLeft / 512); idx < (uint32_t)((cbPreLeft + cbRange) / 512); idx++)
|
---|
[38670] | 665 | drvdiskintIoLogEntryRelease(pSeg->apIoLog[idx]);
|
---|
[73097] | 666 | pSeg = (PDRVDISKSEGMENT)RTMemRealloc(pSeg, RT_UOFFSETOF_DYN(DRVDISKSEGMENT, apIoLog[cbPreLeft / 512]));
|
---|
[38670] | 667 | pSeg->Core.KeyLast = pSeg->Core.Key + cbPreLeft - 1;
|
---|
| 668 | pSeg->cbSeg = cbPreLeft;
|
---|
[65485] | 669 | pSeg->cIoLogEntries = (uint32_t)(cbPreLeft / 512);
|
---|
[38670] | 670 | bool fInserted = RTAvlrFileOffsetInsert(pThis->pTreeSegments, &pSeg->Core);
|
---|
[63727] | 671 | Assert(fInserted); RT_NOREF(fInserted);
|
---|
[38670] | 672 | } /* if (cbPreLeft && cbPostLeft) */
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | offStart += cbRange;
|
---|
| 676 | cbLeft -= cbRange;
|
---|
| 677 | }
|
---|
| 678 | }
|
---|
| 679 |
|
---|
| 680 | LogFlowFunc(("returns rc=%Rrc\n", rc));
|
---|
| 681 | return rc;
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | /**
|
---|
[28902] | 685 | * Adds a request to the active list.
|
---|
| 686 | *
|
---|
| 687 | * @param pThis The driver instance data.
|
---|
| 688 | * @param pIoReq The request to add.
|
---|
| 689 | */
|
---|
| 690 | static void drvdiskintIoReqAdd(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq)
|
---|
| 691 | {
|
---|
| 692 | PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[pThis->iNextFreeSlot];
|
---|
| 693 |
|
---|
| 694 | Assert(!pReqActive->pIoReq);
|
---|
[29443] | 695 | pReqActive->tsStart = pIoReq->tsStart;
|
---|
[28902] | 696 | pReqActive->pIoReq = pIoReq;
|
---|
| 697 | pIoReq->iSlot = pThis->iNextFreeSlot;
|
---|
| 698 |
|
---|
| 699 | /* Search for the next one. */
|
---|
| 700 | while (pThis->apReqActive[pThis->iNextFreeSlot].pIoReq)
|
---|
[28948] | 701 | pThis->iNextFreeSlot = (pThis->iNextFreeSlot+1) % RT_ELEMENTS(pThis->apReqActive);
|
---|
[28902] | 702 | }
|
---|
| 703 |
|
---|
| 704 | /**
|
---|
| 705 | * Removes a request from the active list.
|
---|
| 706 | *
|
---|
| 707 | * @param pThis The driver instance data.
|
---|
| 708 | * @param pIoReq The request to remove.
|
---|
| 709 | */
|
---|
| 710 | static void drvdiskintIoReqRemove(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq)
|
---|
| 711 | {
|
---|
| 712 | PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[pIoReq->iSlot];
|
---|
| 713 |
|
---|
| 714 | Assert(pReqActive->pIoReq == pIoReq);
|
---|
| 715 |
|
---|
[30112] | 716 | ASMAtomicWriteNullPtr(&pReqActive->pIoReq);
|
---|
[28902] | 717 | }
|
---|
| 718 |
|
---|
| 719 | /**
|
---|
| 720 | * Thread checking for expired requests.
|
---|
| 721 | *
|
---|
| 722 | * @returns IPRT status code.
|
---|
| 723 | * @param pThread Thread handle.
|
---|
| 724 | * @param pvUser Opaque user data.
|
---|
| 725 | */
|
---|
[63689] | 726 | static DECLCALLBACK(int) drvdiskIntIoReqExpiredCheck(RTTHREAD pThread, void *pvUser)
|
---|
[28902] | 727 | {
|
---|
| 728 | PDRVDISKINTEGRITY pThis = (PDRVDISKINTEGRITY)pvUser;
|
---|
| 729 |
|
---|
[63689] | 730 | RT_NOREF(pThread);
|
---|
| 731 |
|
---|
[28902] | 732 | while (pThis->fRunning)
|
---|
| 733 | {
|
---|
| 734 | int rc = RTSemEventWait(pThis->SemEvent, pThis->uCheckIntervalMs);
|
---|
| 735 |
|
---|
| 736 | if (!pThis->fRunning)
|
---|
| 737 | break;
|
---|
| 738 |
|
---|
[63727] | 739 | Assert(rc == VERR_TIMEOUT); RT_NOREF(rc);
|
---|
[28902] | 740 |
|
---|
| 741 | /* Get current timestamp for comparison. */
|
---|
| 742 | uint64_t tsCurr = RTTimeSystemMilliTS();
|
---|
| 743 |
|
---|
| 744 | /* Go through the array and check for expired requests. */
|
---|
| 745 | for (unsigned i = 0; i < RT_ELEMENTS(pThis->apReqActive); i++)
|
---|
| 746 | {
|
---|
| 747 | PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[i];
|
---|
[30111] | 748 | PDRVDISKAIOREQ pIoReq = ASMAtomicReadPtrT(&pReqActive->pIoReq, PDRVDISKAIOREQ);
|
---|
[28902] | 749 |
|
---|
| 750 | if ( pIoReq
|
---|
[29495] | 751 | && (tsCurr > pReqActive->tsStart)
|
---|
[28902] | 752 | && (tsCurr - pReqActive->tsStart) >= pThis->uExpireIntervalMs)
|
---|
| 753 | {
|
---|
| 754 | RTMsgError("Request %#p expired (active for %llu ms already)\n",
|
---|
| 755 | pIoReq, tsCurr - pReqActive->tsStart);
|
---|
| 756 | RTAssertDebugBreak();
|
---|
| 757 | }
|
---|
| 758 | }
|
---|
| 759 | }
|
---|
| 760 |
|
---|
| 761 | return VINF_SUCCESS;
|
---|
| 762 | }
|
---|
| 763 |
|
---|
[51619] | 764 | /**
|
---|
| 765 | * Verify a completed read after write request.
|
---|
| 766 | *
|
---|
| 767 | * @returns VBox status code.
|
---|
| 768 | * @param pThis The driver instance data.
|
---|
| 769 | * @param pIoReq The request to be verified.
|
---|
| 770 | */
|
---|
| 771 | static int drvdiskintReadAfterWriteVerify(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq)
|
---|
| 772 | {
|
---|
| 773 | int rc = VINF_SUCCESS;
|
---|
| 774 |
|
---|
| 775 | if (pThis->fCheckConsistency)
|
---|
| 776 | rc = drvdiskintReadVerify(pThis, pIoReq->paSeg, pIoReq->cSeg, pIoReq->off, pIoReq->cbTransfer);
|
---|
[63562] | 777 | else /** @todo Implement read after write verification without a memory based image of the disk. */
|
---|
[51619] | 778 | AssertMsgFailed(("TODO\n"));
|
---|
| 779 |
|
---|
| 780 | return rc;
|
---|
| 781 | }
|
---|
| 782 |
|
---|
[72310] | 783 |
|
---|
| 784 | /**
|
---|
| 785 | * Fires a read event if enabled.
|
---|
| 786 | *
|
---|
| 787 | * @param pThis The driver instance data.
|
---|
| 788 | * @param uGrp The group ID.
|
---|
[72336] | 789 | * @param fAsync Flag whether this is an async request.
|
---|
[72310] | 790 | * @param off The offset to put into the event log.
|
---|
| 791 | * @param cbRead Amount of bytes to read.
|
---|
| 792 | */
|
---|
[72336] | 793 | DECLINLINE(void) drvdiskintTraceLogFireEvtRead(PDRVDISKINTEGRITY pThis, uintptr_t uGrp, bool fAsync, uint64_t off, size_t cbRead)
|
---|
[72310] | 794 | {
|
---|
| 795 | if (pThis->hIoLogger)
|
---|
| 796 | {
|
---|
[72312] | 797 | int rc = RTTraceLogWrEvtAddL(pThis->hIoLogger, &g_EvtRead, RTTRACELOG_WR_ADD_EVT_F_GRP_START,
|
---|
[72336] | 798 | (RTTRACELOGEVTGRPID)uGrp, 0, fAsync, off, cbRead);
|
---|
[72310] | 799 | AssertRC(rc);
|
---|
| 800 | }
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 |
|
---|
| 804 | /**
|
---|
| 805 | * Fires a write event if enabled.
|
---|
| 806 | *
|
---|
| 807 | * @param pThis The driver instance data.
|
---|
| 808 | * @param uGrp The group ID.
|
---|
[72336] | 809 | * @param fAsync Flag whether this is an async request.
|
---|
[72310] | 810 | * @param off The offset to put into the event log.
|
---|
| 811 | * @param cbWrite Amount of bytes to write.
|
---|
| 812 | */
|
---|
[72336] | 813 | DECLINLINE(void) drvdiskintTraceLogFireEvtWrite(PDRVDISKINTEGRITY pThis, uintptr_t uGrp, bool fAsync, uint64_t off, size_t cbWrite)
|
---|
[72310] | 814 | {
|
---|
| 815 | if (pThis->hIoLogger)
|
---|
| 816 | {
|
---|
[72312] | 817 | int rc = RTTraceLogWrEvtAddL(pThis->hIoLogger, &g_EvtWrite, RTTRACELOG_WR_ADD_EVT_F_GRP_START,
|
---|
[72338] | 818 | (RTTRACELOGEVTGRPID)uGrp, 0, fAsync, off, cbWrite);
|
---|
[72310] | 819 | AssertRC(rc);
|
---|
| 820 | }
|
---|
| 821 | }
|
---|
| 822 |
|
---|
| 823 |
|
---|
| 824 | /**
|
---|
| 825 | * Fires a flush event if enabled.
|
---|
| 826 | *
|
---|
| 827 | * @param pThis The driver instance data.
|
---|
| 828 | * @param uGrp The group ID.
|
---|
[72336] | 829 | * @param fAsync Flag whether this is an async request.
|
---|
[72310] | 830 | */
|
---|
[72336] | 831 | DECLINLINE(void) drvdiskintTraceLogFireEvtFlush(PDRVDISKINTEGRITY pThis, uintptr_t uGrp, bool fAsync)
|
---|
[72310] | 832 | {
|
---|
| 833 | if (pThis->hIoLogger)
|
---|
| 834 | {
|
---|
[72312] | 835 | int rc = RTTraceLogWrEvtAddL(pThis->hIoLogger, &g_EvtFlush, RTTRACELOG_WR_ADD_EVT_F_GRP_START,
|
---|
[72338] | 836 | (RTTRACELOGEVTGRPID)uGrp, 0, fAsync);
|
---|
[72310] | 837 | AssertRC(rc);
|
---|
| 838 | }
|
---|
| 839 | }
|
---|
| 840 |
|
---|
| 841 |
|
---|
| 842 | /**
|
---|
| 843 | * Fires a request complete event if enabled.
|
---|
| 844 | *
|
---|
| 845 | * @param pThis The driver instance data.
|
---|
| 846 | * @param uGrp The group ID.
|
---|
[72311] | 847 | * @param rcReq Status code the request completed with.
|
---|
[72310] | 848 | * @param pSgBuf The S/G buffer holding the data.
|
---|
| 849 | */
|
---|
[72312] | 850 | DECLINLINE(void) drvdiskintTraceLogFireEvtComplete(PDRVDISKINTEGRITY pThis, uintptr_t uGrp, int rcReq, PRTSGBUF pSgBuf)
|
---|
[72310] | 851 | {
|
---|
| 852 | RT_NOREF(pSgBuf);
|
---|
| 853 |
|
---|
| 854 | if (pThis->hIoLogger)
|
---|
| 855 | {
|
---|
[72312] | 856 | int rc = RTTraceLogWrEvtAddL(pThis->hIoLogger, &g_EvtComplete, RTTRACELOG_WR_ADD_EVT_F_GRP_FINISH,
|
---|
| 857 | (RTTRACELOGEVTGRPID)uGrp, 0, rcReq);
|
---|
[72310] | 858 | AssertRC(rc);
|
---|
| 859 | }
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 |
|
---|
[28114] | 863 | /* -=-=-=-=- IMedia -=-=-=-=- */
|
---|
| 864 |
|
---|
| 865 | /** Makes a PDRVDISKINTEGRITY out of a PPDMIMEDIA. */
|
---|
[73097] | 866 | #define PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface) ( (PDRVDISKINTEGRITY)((uintptr_t)pInterface - RT_UOFFSETOF(DRVDISKINTEGRITY, IMedia)) )
|
---|
[28114] | 867 |
|
---|
| 868 |
|
---|
[57358] | 869 | /*********************************************************************************************************************************
|
---|
| 870 | * Media interface methods *
|
---|
| 871 | *********************************************************************************************************************************/
|
---|
| 872 |
|
---|
[72310] | 873 |
|
---|
[62956] | 874 | /** @interface_method_impl{PDMIMEDIA,pfnRead} */
|
---|
[28114] | 875 | static DECLCALLBACK(int) drvdiskintRead(PPDMIMEDIA pInterface,
|
---|
| 876 | uint64_t off, void *pvBuf, size_t cbRead)
|
---|
| 877 | {
|
---|
[38541] | 878 | int rc = VINF_SUCCESS;
|
---|
[28114] | 879 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
[38541] | 880 |
|
---|
[72336] | 881 | drvdiskintTraceLogFireEvtRead(pThis, (uintptr_t)pvBuf, false /* fAsync */, off, cbRead);
|
---|
[38541] | 882 | rc = pThis->pDrvMedia->pfnRead(pThis->pDrvMedia, off, pvBuf, cbRead);
|
---|
| 883 |
|
---|
| 884 | if (pThis->hIoLogger)
|
---|
| 885 | {
|
---|
| 886 | RTSGSEG Seg;
|
---|
| 887 | RTSGBUF SgBuf;
|
---|
| 888 |
|
---|
| 889 | Seg.pvSeg = pvBuf;
|
---|
| 890 | Seg.cbSeg = cbRead;
|
---|
| 891 | RTSgBufInit(&SgBuf, &Seg, 1);
|
---|
[72312] | 892 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)pvBuf, rc, &SgBuf);
|
---|
[38541] | 893 | }
|
---|
| 894 |
|
---|
[28114] | 895 | if (RT_FAILURE(rc))
|
---|
| 896 | return rc;
|
---|
| 897 |
|
---|
[28902] | 898 | if (pThis->fCheckConsistency)
|
---|
| 899 | {
|
---|
| 900 | /* Verify the read. */
|
---|
| 901 | RTSGSEG Seg;
|
---|
| 902 | Seg.cbSeg = cbRead;
|
---|
| 903 | Seg.pvSeg = pvBuf;
|
---|
| 904 | rc = drvdiskintReadVerify(pThis, &Seg, 1, off, cbRead);
|
---|
| 905 | }
|
---|
| 906 |
|
---|
| 907 | return rc;
|
---|
[28114] | 908 | }
|
---|
| 909 |
|
---|
[62956] | 910 | /** @interface_method_impl{PDMIMEDIA,pfnWrite} */
|
---|
[28114] | 911 | static DECLCALLBACK(int) drvdiskintWrite(PPDMIMEDIA pInterface,
|
---|
| 912 | uint64_t off, const void *pvBuf,
|
---|
| 913 | size_t cbWrite)
|
---|
| 914 | {
|
---|
[38541] | 915 | int rc = VINF_SUCCESS;
|
---|
[28114] | 916 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
[38541] | 917 |
|
---|
[72336] | 918 | drvdiskintTraceLogFireEvtWrite(pThis, (uintptr_t)pvBuf, false /* fAsync */, off, cbWrite);
|
---|
[38541] | 919 |
|
---|
[51749] | 920 | if (pThis->fRecordWriteBeforeCompletion)
|
---|
| 921 | {
|
---|
| 922 | RTSGSEG Seg;
|
---|
| 923 | Seg.cbSeg = cbWrite;
|
---|
| 924 | Seg.pvSeg = (void *)pvBuf;
|
---|
| 925 |
|
---|
| 926 | rc = drvdiskintWriteRecord(pThis, &Seg, 1, off, cbWrite);
|
---|
| 927 | if (RT_FAILURE(rc))
|
---|
| 928 | return rc;
|
---|
| 929 | }
|
---|
| 930 |
|
---|
[38541] | 931 | rc = pThis->pDrvMedia->pfnWrite(pThis->pDrvMedia, off, pvBuf, cbWrite);
|
---|
| 932 |
|
---|
[72312] | 933 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)pvBuf, rc, NULL);
|
---|
[28114] | 934 | if (RT_FAILURE(rc))
|
---|
| 935 | return rc;
|
---|
| 936 |
|
---|
[51749] | 937 | if ( pThis->fCheckConsistency
|
---|
| 938 | && !pThis->fRecordWriteBeforeCompletion)
|
---|
[28902] | 939 | {
|
---|
| 940 | /* Record the write. */
|
---|
| 941 | RTSGSEG Seg;
|
---|
| 942 | Seg.cbSeg = cbWrite;
|
---|
| 943 | Seg.pvSeg = (void *)pvBuf;
|
---|
| 944 | rc = drvdiskintWriteRecord(pThis, &Seg, 1, off, cbWrite);
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | return rc;
|
---|
[28114] | 948 | }
|
---|
| 949 |
|
---|
[62956] | 950 | /** @interface_method_impl{PDMIMEDIA,pfnFlush} */
|
---|
[27558] | 951 | static DECLCALLBACK(int) drvdiskintFlush(PPDMIMEDIA pInterface)
|
---|
| 952 | {
|
---|
[38541] | 953 | int rc = VINF_SUCCESS;
|
---|
[27558] | 954 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
[38541] | 955 |
|
---|
[72336] | 956 | drvdiskintTraceLogFireEvtFlush(pThis, 1, false /* fAsync */);
|
---|
[38541] | 957 | rc = pThis->pDrvMedia->pfnFlush(pThis->pDrvMedia);
|
---|
[72310] | 958 | drvdiskintTraceLogFireEvtComplete(pThis, 1, rc, NULL);
|
---|
[38541] | 959 |
|
---|
| 960 | return rc;
|
---|
[27558] | 961 | }
|
---|
| 962 |
|
---|
[62956] | 963 | /** @interface_method_impl{PDMIMEDIA,pfnGetSize} */
|
---|
[27558] | 964 | static DECLCALLBACK(uint64_t) drvdiskintGetSize(PPDMIMEDIA pInterface)
|
---|
| 965 | {
|
---|
| 966 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 967 | return pThis->pDrvMedia->pfnGetSize(pThis->pDrvMedia);
|
---|
| 968 | }
|
---|
| 969 |
|
---|
[62956] | 970 | /** @interface_method_impl{PDMIMEDIA,pfnIsReadOnly} */
|
---|
[27558] | 971 | static DECLCALLBACK(bool) drvdiskintIsReadOnly(PPDMIMEDIA pInterface)
|
---|
| 972 | {
|
---|
| 973 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 974 | return pThis->pDrvMedia->pfnIsReadOnly(pThis->pDrvMedia);
|
---|
| 975 | }
|
---|
| 976 |
|
---|
[63727] | 977 | /** @interface_method_impl{PDMIMEDIA,pfnBiosIsVisible} */
|
---|
| 978 | static DECLCALLBACK(bool) drvdiskintBiosIsVisible(PPDMIMEDIA pInterface)
|
---|
| 979 | {
|
---|
| 980 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
[65480] | 981 | return pThis->pDrvMedia->pfnBiosIsVisible(pThis->pDrvMedia);
|
---|
[63727] | 982 | }
|
---|
| 983 |
|
---|
| 984 | /** @interface_method_impl{PDMIMEDIA,pfnGetType} */
|
---|
| 985 | static DECLCALLBACK(PDMMEDIATYPE) drvdiskintGetType(PPDMIMEDIA pInterface)
|
---|
| 986 | {
|
---|
| 987 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 988 | return pThis->pDrvMedia->pfnGetType(pThis->pDrvMedia);
|
---|
| 989 | }
|
---|
| 990 |
|
---|
[62956] | 991 | /** @interface_method_impl{PDMIMEDIA,pfnBiosGetPCHSGeometry} */
|
---|
[27558] | 992 | static DECLCALLBACK(int) drvdiskintBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
|
---|
| 993 | PPDMMEDIAGEOMETRY pPCHSGeometry)
|
---|
| 994 | {
|
---|
| 995 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 996 | return pThis->pDrvMedia->pfnBiosGetPCHSGeometry(pThis->pDrvMedia, pPCHSGeometry);
|
---|
| 997 | }
|
---|
| 998 |
|
---|
[62956] | 999 | /** @interface_method_impl{PDMIMEDIA,pfnBiosSetPCHSGeometry} */
|
---|
[27558] | 1000 | static DECLCALLBACK(int) drvdiskintBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
|
---|
| 1001 | PCPDMMEDIAGEOMETRY pPCHSGeometry)
|
---|
| 1002 | {
|
---|
| 1003 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1004 | return pThis->pDrvMedia->pfnBiosSetPCHSGeometry(pThis->pDrvMedia, pPCHSGeometry);
|
---|
| 1005 | }
|
---|
| 1006 |
|
---|
[62956] | 1007 | /** @interface_method_impl{PDMIMEDIA,pfnBiosGetLCHSGeometry} */
|
---|
[27558] | 1008 | static DECLCALLBACK(int) drvdiskintBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
|
---|
| 1009 | PPDMMEDIAGEOMETRY pLCHSGeometry)
|
---|
| 1010 | {
|
---|
| 1011 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1012 | return pThis->pDrvMedia->pfnBiosGetLCHSGeometry(pThis->pDrvMedia, pLCHSGeometry);
|
---|
| 1013 | }
|
---|
| 1014 |
|
---|
[62956] | 1015 | /** @interface_method_impl{PDMIMEDIA,pfnBiosSetLCHSGeometry} */
|
---|
[27558] | 1016 | static DECLCALLBACK(int) drvdiskintBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
|
---|
| 1017 | PCPDMMEDIAGEOMETRY pLCHSGeometry)
|
---|
| 1018 | {
|
---|
| 1019 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1020 | return pThis->pDrvMedia->pfnBiosSetLCHSGeometry(pThis->pDrvMedia, pLCHSGeometry);
|
---|
| 1021 | }
|
---|
| 1022 |
|
---|
[62956] | 1023 | /** @interface_method_impl{PDMIMEDIA,pfnGetUuid} */
|
---|
[27558] | 1024 | static DECLCALLBACK(int) drvdiskintGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
|
---|
| 1025 | {
|
---|
| 1026 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1027 | return pThis->pDrvMedia->pfnGetUuid(pThis->pDrvMedia, pUuid);
|
---|
| 1028 | }
|
---|
| 1029 |
|
---|
[62956] | 1030 | /** @interface_method_impl{PDMIMEDIA,pfnGetSectorSize} */
|
---|
[51619] | 1031 | static DECLCALLBACK(uint32_t) drvdiskintGetSectorSize(PPDMIMEDIA pInterface)
|
---|
| 1032 | {
|
---|
| 1033 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1034 | return pThis->pDrvMedia->pfnGetSectorSize(pThis->pDrvMedia);
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
[62956] | 1037 | /** @interface_method_impl{PDMIMEDIA,pfnDiscard} */
|
---|
[39518] | 1038 | static DECLCALLBACK(int) drvdiskintDiscard(PPDMIMEDIA pInterface, PCRTRANGE paRanges, unsigned cRanges)
|
---|
[38631] | 1039 | {
|
---|
| 1040 | int rc = VINF_SUCCESS;
|
---|
| 1041 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1042 |
|
---|
| 1043 | rc = pThis->pDrvMedia->pfnDiscard(pThis->pDrvMedia, paRanges, cRanges);
|
---|
[72312] | 1044 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)paRanges, rc, NULL);
|
---|
[38631] | 1045 |
|
---|
[38670] | 1046 | if (pThis->fCheckConsistency)
|
---|
| 1047 | rc = drvdiskintDiscardRecords(pThis, paRanges, cRanges);
|
---|
| 1048 |
|
---|
[38631] | 1049 | return rc;
|
---|
| 1050 | }
|
---|
| 1051 |
|
---|
[62956] | 1052 | /** @interface_method_impl{PDMIMEDIA,pfnReadPcBios} */
|
---|
[57527] | 1053 | static DECLCALLBACK(int) drvdiskintReadPcBios(PPDMIMEDIA pInterface,
|
---|
| 1054 | uint64_t off, void *pvBuf, size_t cbRead)
|
---|
| 1055 | {
|
---|
| 1056 | LogFlowFunc(("\n"));
|
---|
| 1057 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1058 |
|
---|
| 1059 | return pThis->pDrvMedia->pfnReadPcBios(pThis->pDrvMedia, off, pvBuf, cbRead);
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
[64724] | 1062 | /** @interface_method_impl{PDMIMEDIA,pfnIsNonRotational} */
|
---|
| 1063 | static DECLCALLBACK(bool) drvdiskintIsNonRotational(PPDMIMEDIA pInterface)
|
---|
| 1064 | {
|
---|
| 1065 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1066 | return pThis->pDrvMedia->pfnIsNonRotational(pThis->pDrvMedia);
|
---|
| 1067 | }
|
---|
| 1068 |
|
---|
[83042] | 1069 | /** @interface_method_impl{PDMIMEDIA,pfnGetRegionCount} */
|
---|
| 1070 | static DECLCALLBACK(uint32_t) drvdiskintGetRegionCount(PPDMIMEDIA pInterface)
|
---|
| 1071 | {
|
---|
| 1072 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1073 | return pThis->pDrvMedia->pfnGetRegionCount(pThis->pDrvMedia);
|
---|
| 1074 | }
|
---|
| 1075 |
|
---|
| 1076 | /** @interface_method_impl{PDMIMEDIA,pfnQueryRegionProperties} */
|
---|
| 1077 | static DECLCALLBACK(int) drvdiskintQueryRegionProperties(PPDMIMEDIA pInterface, uint32_t uRegion, uint64_t *pu64LbaStart,
|
---|
| 1078 | uint64_t *pcBlocks, uint64_t *pcbBlock,
|
---|
| 1079 | PVDREGIONDATAFORM penmDataForm)
|
---|
| 1080 | {
|
---|
| 1081 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1082 | return pThis->pDrvMedia->pfnQueryRegionProperties(pThis->pDrvMedia, uRegion, pu64LbaStart, pcBlocks, pcbBlock, penmDataForm);
|
---|
| 1083 | }
|
---|
| 1084 |
|
---|
| 1085 | /** @interface_method_impl{PDMIMEDIA,pfnQueryRegionPropertiesForLba} */
|
---|
| 1086 | static DECLCALLBACK(int) drvdiskintQueryRegionPropertiesForLba(PPDMIMEDIA pInterface, uint64_t u64LbaStart,
|
---|
| 1087 | uint32_t *puRegion, uint64_t *pcBlocks,
|
---|
| 1088 | uint64_t *pcbBlock, PVDREGIONDATAFORM penmDataForm)
|
---|
| 1089 | {
|
---|
| 1090 | PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1091 | return pThis->pDrvMedia->pfnQueryRegionPropertiesForLba(pThis->pDrvMedia, u64LbaStart, puRegion, pcBlocks, pcbBlock, penmDataForm);
|
---|
| 1092 | }
|
---|
| 1093 |
|
---|
[34433] | 1094 | /* -=-=-=-=- IMediaPort -=-=-=-=- */
|
---|
| 1095 |
|
---|
| 1096 | /** Makes a PDRVBLOCK out of a PPDMIMEDIAPORT. */
|
---|
[73097] | 1097 | #define PDMIMEDIAPORT_2_DRVDISKINTEGRITY(pInterface) ( (PDRVDISKINTEGRITY((uintptr_t)pInterface - RT_UOFFSETOF(DRVDISKINTEGRITY, IMediaPort))) )
|
---|
[34433] | 1098 |
|
---|
| 1099 | /**
|
---|
| 1100 | * @interface_method_impl{PDMIMEDIAPORT,pfnQueryDeviceLocation}
|
---|
| 1101 | */
|
---|
| 1102 | static DECLCALLBACK(int) drvdiskintQueryDeviceLocation(PPDMIMEDIAPORT pInterface, const char **ppcszController,
|
---|
| 1103 | uint32_t *piInstance, uint32_t *piLUN)
|
---|
| 1104 | {
|
---|
| 1105 | PDRVDISKINTEGRITY pThis = PDMIMEDIAPORT_2_DRVDISKINTEGRITY(pInterface);
|
---|
| 1106 |
|
---|
| 1107 | return pThis->pDrvMediaPort->pfnQueryDeviceLocation(pThis->pDrvMediaPort, ppcszController,
|
---|
| 1108 | piInstance, piLUN);
|
---|
| 1109 | }
|
---|
| 1110 |
|
---|
[63700] | 1111 | /* -=-=-=-=- IMediaExPort -=-=-=-=- */
|
---|
| 1112 |
|
---|
| 1113 | /**
|
---|
| 1114 | * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCompleteNotify}
|
---|
| 1115 | */
|
---|
| 1116 | static DECLCALLBACK(int) drvdiskintIoReqCompleteNotify(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
|
---|
| 1117 | void *pvIoReqAlloc, int rcReq)
|
---|
| 1118 | {
|
---|
| 1119 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
|
---|
[65703] | 1120 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(pvIoReqAlloc);
|
---|
[63727] | 1121 | int rc = VINF_SUCCESS;
|
---|
| 1122 |
|
---|
| 1123 | LogFlowFunc(("pIoReq=%#p\n", pIoReq));
|
---|
| 1124 |
|
---|
| 1125 | /* Remove from the active list. */
|
---|
| 1126 | if (pThis->fTraceRequests)
|
---|
| 1127 | drvdiskintIoReqRemove(pThis, pIoReq);
|
---|
| 1128 |
|
---|
| 1129 | if (RT_SUCCESS(rcReq) && pThis->fCheckConsistency)
|
---|
| 1130 | {
|
---|
| 1131 | if (pIoReq->enmTxDir == DRVDISKAIOTXDIR_READ)
|
---|
| 1132 | rc = drvdiskintReadVerify(pThis, &pIoReq->IoSeg, 1, pIoReq->off, pIoReq->cbTransfer);
|
---|
| 1133 | else if ( pIoReq->enmTxDir == DRVDISKAIOTXDIR_WRITE
|
---|
| 1134 | && !pThis->fRecordWriteBeforeCompletion)
|
---|
| 1135 | rc = drvdiskintWriteRecord(pThis, &pIoReq->IoSeg, 1, pIoReq->off, pIoReq->cbTransfer);
|
---|
| 1136 | else if (pIoReq->enmTxDir == DRVDISKAIOTXDIR_DISCARD)
|
---|
| 1137 | rc = drvdiskintDiscardRecords(pThis, pIoReq->paRanges, pIoReq->cRanges);
|
---|
| 1138 | else if (pIoReq->enmTxDir == DRVDISKAIOTXDIR_READ_AFTER_WRITE)
|
---|
| 1139 | rc = drvdiskintReadAfterWriteVerify(pThis, pIoReq);
|
---|
| 1140 | else
|
---|
| 1141 | AssertMsg( pIoReq->enmTxDir == DRVDISKAIOTXDIR_FLUSH
|
---|
| 1142 | || ( pIoReq->enmTxDir == DRVDISKAIOTXDIR_WRITE
|
---|
| 1143 | && pThis->fRecordWriteBeforeCompletion), ("Huh?\n"));
|
---|
| 1144 |
|
---|
| 1145 | AssertRC(rc);
|
---|
| 1146 | }
|
---|
| 1147 |
|
---|
| 1148 | if ( RT_SUCCESS(rcReq)
|
---|
| 1149 | && pThis->fValidateMemBufs
|
---|
| 1150 | && pIoReq->enmTxDir == DRVDISKAIOTXDIR_READ)
|
---|
| 1151 | {
|
---|
| 1152 | /* Check that the guest memory buffer matches what was written. */
|
---|
| 1153 | RTSGSEG SegCmp;
|
---|
| 1154 | SegCmp.pvSeg = RTMemAlloc(pIoReq->cbTransfer);
|
---|
| 1155 | SegCmp.cbSeg = pIoReq->cbTransfer;
|
---|
| 1156 |
|
---|
| 1157 | RTSGBUF SgBufCmp;
|
---|
| 1158 | RTSgBufInit(&SgBufCmp, &SegCmp, 1);
|
---|
[65703] | 1159 | rc = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1160 | DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
|
---|
[63727] | 1161 | 0, &SgBufCmp, pIoReq->cbTransfer);
|
---|
| 1162 | AssertRC(rc);
|
---|
| 1163 |
|
---|
| 1164 | RTSGBUF SgBuf;
|
---|
| 1165 | RTSgBufInit(&SgBuf, &pIoReq->IoSeg, 1);
|
---|
| 1166 | if (RTSgBufCmp(&SgBuf, &SgBufCmp, pIoReq->cbTransfer))
|
---|
| 1167 | {
|
---|
| 1168 | RTMsgError("Corrupted memory buffer at offset %llu!\n", 0);
|
---|
| 1169 | RTAssertDebugBreak();
|
---|
| 1170 | }
|
---|
| 1171 |
|
---|
| 1172 | RTMemFree(SegCmp.pvSeg);
|
---|
| 1173 | }
|
---|
| 1174 |
|
---|
| 1175 | if (pThis->hIoLogger)
|
---|
| 1176 | {
|
---|
| 1177 | RTSGBUF SgBuf;
|
---|
| 1178 |
|
---|
| 1179 | if (pIoReq->enmTxDir == DRVDISKAIOTXDIR_READ)
|
---|
| 1180 | RTSgBufInit(&SgBuf, &pIoReq->IoSeg, 1);
|
---|
[72312] | 1181 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rcReq, &SgBuf);
|
---|
[63727] | 1182 | }
|
---|
| 1183 |
|
---|
| 1184 | if ( pThis->fReadAfterWrite
|
---|
| 1185 | && pIoReq->enmTxDir == DRVDISKAIOTXDIR_WRITE)
|
---|
| 1186 | {
|
---|
| 1187 | #if 0 /** @todo */
|
---|
| 1188 | pIoReq->enmTxDir = DRVDISKAIOTXDIR_READ_AFTER_WRITE;
|
---|
| 1189 |
|
---|
| 1190 | /* Add again because it was removed above. */
|
---|
| 1191 | if (pThis->fTraceRequests)
|
---|
| 1192 | drvdiskintIoReqAdd(pThis, pIoReq);
|
---|
| 1193 |
|
---|
| 1194 | rc = pThis->pDrvMediaAsync->pfnStartRead(pThis->pDrvMediaAsync, pIoReq->off, pIoReq->paSeg, pIoReq->cSeg,
|
---|
| 1195 | pIoReq->cbTransfer, pIoReq);
|
---|
| 1196 | if (rc == VINF_VD_ASYNC_IO_FINISHED)
|
---|
| 1197 | {
|
---|
| 1198 | rc = drvdiskintReadAfterWriteVerify(pThis, pIoReq);
|
---|
| 1199 |
|
---|
| 1200 | if (pThis->fTraceRequests)
|
---|
| 1201 | drvdiskintIoReqRemove(pThis, pIoReq);
|
---|
| 1202 | RTMemFree(pIoReq);
|
---|
| 1203 | }
|
---|
| 1204 | else if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS)
|
---|
| 1205 | rc = VINF_SUCCESS;
|
---|
| 1206 | else if (RT_FAILURE(rc))
|
---|
| 1207 | RTMemFree(pIoReq);
|
---|
| 1208 | #endif
|
---|
| 1209 | }
|
---|
| 1210 | else
|
---|
| 1211 | {
|
---|
[65703] | 1212 | rc = pThis->pDrvMediaExPort->pfnIoReqCompleteNotify(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1213 | DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
|
---|
| 1214 | rcReq);
|
---|
[63727] | 1215 | /* Put on the watch list. */
|
---|
| 1216 | if (pThis->fCheckDoubleCompletion)
|
---|
| 1217 | drvdiskintIoReqCheckForDoubleCompletion(pThis, pIoReq, true /* fMediaEx */);
|
---|
| 1218 | }
|
---|
| 1219 |
|
---|
| 1220 | return rc;
|
---|
[63700] | 1221 | }
|
---|
| 1222 |
|
---|
| 1223 | /**
|
---|
| 1224 | * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyFromBuf}
|
---|
| 1225 | */
|
---|
| 1226 | static DECLCALLBACK(int) drvdiskintIoReqCopyFromBuf(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
|
---|
| 1227 | void *pvIoReqAlloc, uint32_t offDst, PRTSGBUF pSgBuf,
|
---|
| 1228 | size_t cbCopy)
|
---|
| 1229 | {
|
---|
| 1230 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
|
---|
[65703] | 1231 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(pvIoReqAlloc);
|
---|
[63727] | 1232 | RTSGBUF SgBuf;
|
---|
| 1233 |
|
---|
| 1234 | RTSgBufClone(&SgBuf, pSgBuf);
|
---|
| 1235 |
|
---|
[65703] | 1236 | int rc = pThis->pDrvMediaExPort->pfnIoReqCopyFromBuf(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1237 | DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
|
---|
| 1238 | offDst, pSgBuf, cbCopy);
|
---|
[63727] | 1239 | if ( RT_SUCCESS(rc)
|
---|
| 1240 | && pIoReq->IoSeg.pvSeg)
|
---|
| 1241 | {
|
---|
| 1242 | /* Update our copy. */
|
---|
| 1243 | RTSgBufCopyToBuf(&SgBuf, (uint8_t *)pIoReq->IoSeg.pvSeg + offDst, cbCopy);
|
---|
[65479] | 1244 |
|
---|
| 1245 | /* Validate the just read data against our copy if possible. */
|
---|
| 1246 | if ( pThis->fValidateMemBufs
|
---|
| 1247 | && pThis->fCheckConsistency
|
---|
| 1248 | && pIoReq->enmTxDir == DRVDISKAIOTXDIR_READ)
|
---|
| 1249 | {
|
---|
| 1250 | RTSGSEG Seg;
|
---|
| 1251 |
|
---|
| 1252 | Seg.pvSeg = (uint8_t *)pIoReq->IoSeg.pvSeg + offDst;
|
---|
| 1253 | Seg.cbSeg = cbCopy;
|
---|
| 1254 |
|
---|
| 1255 | rc = drvdiskintReadVerify(pThis, &Seg, 1, pIoReq->off + offDst,
|
---|
| 1256 | cbCopy);
|
---|
| 1257 | }
|
---|
[63727] | 1258 | }
|
---|
| 1259 |
|
---|
| 1260 | return rc;
|
---|
[63700] | 1261 | }
|
---|
| 1262 |
|
---|
| 1263 | /**
|
---|
| 1264 | * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyToBuf}
|
---|
| 1265 | */
|
---|
| 1266 | static DECLCALLBACK(int) drvdiskintIoReqCopyToBuf(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
|
---|
| 1267 | void *pvIoReqAlloc, uint32_t offSrc, PRTSGBUF pSgBuf,
|
---|
| 1268 | size_t cbCopy)
|
---|
| 1269 | {
|
---|
| 1270 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
|
---|
[65703] | 1271 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_ALLOC_2_DRVDISKAIOREQ(pvIoReqAlloc);
|
---|
[63727] | 1272 | RTSGBUF SgBuf;
|
---|
| 1273 |
|
---|
| 1274 | RTSgBufClone(&SgBuf, pSgBuf);
|
---|
| 1275 |
|
---|
[65703] | 1276 | int rc = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1277 | DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
|
---|
| 1278 | offSrc, pSgBuf, cbCopy);
|
---|
[63727] | 1279 | if ( RT_SUCCESS(rc)
|
---|
| 1280 | && pIoReq->IoSeg.pvSeg)
|
---|
| 1281 | {
|
---|
| 1282 | if (pThis->fValidateMemBufs)
|
---|
| 1283 | {
|
---|
| 1284 | /* Make sure what the caller requested matches what we got earlier. */
|
---|
| 1285 | RTSGBUF SgBufCmp;
|
---|
| 1286 | RTSgBufInit(&SgBufCmp, &pIoReq->IoSeg, 1);
|
---|
| 1287 | RTSgBufAdvance(&SgBufCmp, offSrc);
|
---|
| 1288 |
|
---|
| 1289 | if (RTSgBufCmp(&SgBuf, &SgBufCmp, cbCopy))
|
---|
| 1290 | {
|
---|
| 1291 | RTMsgError("Corrupted memory buffer at offset %llu!\n", offSrc);
|
---|
| 1292 | RTAssertDebugBreak();
|
---|
| 1293 | }
|
---|
| 1294 | }
|
---|
| 1295 | else
|
---|
| 1296 | {
|
---|
| 1297 | /* Update our copy. */
|
---|
| 1298 | RTSgBufCopyToBuf(&SgBuf, (uint8_t *)pIoReq->IoSeg.pvSeg + offSrc, cbCopy);
|
---|
| 1299 | }
|
---|
| 1300 | }
|
---|
| 1301 |
|
---|
| 1302 | return rc;
|
---|
[63700] | 1303 | }
|
---|
| 1304 |
|
---|
| 1305 | /**
|
---|
[63997] | 1306 | * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqQueryDiscardRanges}
|
---|
| 1307 | */
|
---|
| 1308 | static DECLCALLBACK(int) drvdiskintIoReqQueryDiscardRanges(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
|
---|
| 1309 | void *pvIoReqAlloc, uint32_t idxRangeStart,
|
---|
| 1310 | uint32_t cRanges, PRTRANGE paRanges,
|
---|
| 1311 | uint32_t *pcRanges)
|
---|
| 1312 | {
|
---|
| 1313 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
|
---|
[65703] | 1314 | return pThis->pDrvMediaExPort->pfnIoReqQueryDiscardRanges(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1315 | DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
|
---|
| 1316 | idxRangeStart, cRanges, paRanges, pcRanges);
|
---|
[63997] | 1317 | }
|
---|
| 1318 |
|
---|
| 1319 | /**
|
---|
[63700] | 1320 | * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqStateChanged}
|
---|
| 1321 | */
|
---|
| 1322 | static DECLCALLBACK(void) drvdiskintIoReqStateChanged(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
|
---|
| 1323 | void *pvIoReqAlloc, PDMMEDIAEXIOREQSTATE enmState)
|
---|
| 1324 | {
|
---|
| 1325 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaExPort);
|
---|
[65703] | 1326 | pThis->pDrvMediaExPort->pfnIoReqStateChanged(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1327 | DISKINTEGRITY_IOREQ_ALLOC_2_UPPER(pvIoReqAlloc),
|
---|
| 1328 | enmState);
|
---|
[63700] | 1329 | }
|
---|
| 1330 |
|
---|
| 1331 | /* -=-=-=-=- IMediaEx -=-=-=-=- */
|
---|
| 1332 |
|
---|
| 1333 | /**
|
---|
[64724] | 1334 | * @interface_method_impl{PDMIMEDIAEX,pfnQueryFeatures}
|
---|
| 1335 | */
|
---|
| 1336 | static DECLCALLBACK(int) drvdiskintQueryFeatures(PPDMIMEDIAEX pInterface, uint32_t *pfFeatures)
|
---|
| 1337 | {
|
---|
| 1338 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1339 | return pThis->pDrvMediaEx->pfnQueryFeatures(pThis->pDrvMediaEx, pfFeatures);
|
---|
| 1340 | }
|
---|
| 1341 |
|
---|
| 1342 | /**
|
---|
[83042] | 1343 | * @interface_method_impl{PDMIMEDIAEX,pfnNotifySuspend}
|
---|
| 1344 | */
|
---|
| 1345 | static DECLCALLBACK(void) drvdiskintNotifySuspend(PPDMIMEDIAEX pInterface)
|
---|
| 1346 | {
|
---|
| 1347 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1348 | return pThis->pDrvMediaEx->pfnNotifySuspend(pThis->pDrvMediaEx);
|
---|
| 1349 | }
|
---|
| 1350 |
|
---|
| 1351 | /**
|
---|
[63700] | 1352 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqAllocSizeSet}
|
---|
| 1353 | */
|
---|
| 1354 | static DECLCALLBACK(int) drvdiskintIoReqAllocSizeSet(PPDMIMEDIAEX pInterface, size_t cbIoReqAlloc)
|
---|
| 1355 | {
|
---|
| 1356 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[63727] | 1357 |
|
---|
[65703] | 1358 | /* Increase the amount by the size of a pointer to our private tracking structure. */
|
---|
| 1359 | cbIoReqAlloc += sizeof(PDRVDISKAIOREQ);
|
---|
[63727] | 1360 |
|
---|
| 1361 | pThis->fCheckDoubleCompletion = false;
|
---|
| 1362 |
|
---|
[63700] | 1363 | return pThis->pDrvMediaEx->pfnIoReqAllocSizeSet(pThis->pDrvMediaEx, cbIoReqAlloc);
|
---|
| 1364 | }
|
---|
| 1365 |
|
---|
| 1366 | /**
|
---|
| 1367 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqAlloc}
|
---|
| 1368 | */
|
---|
| 1369 | static DECLCALLBACK(int) drvdiskintIoReqAlloc(PPDMIMEDIAEX pInterface, PPDMMEDIAEXIOREQ phIoReq, void **ppvIoReqAlloc,
|
---|
| 1370 | PDMMEDIAEXIOREQID uIoReqId, uint32_t fFlags)
|
---|
| 1371 | {
|
---|
| 1372 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[65703] | 1373 | int rc = VINF_SUCCESS;
|
---|
| 1374 | PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)RTMemCacheAlloc(pThis->hReqCache);
|
---|
| 1375 | if (RT_LIKELY(pIoReq))
|
---|
[63727] | 1376 | {
|
---|
| 1377 | pIoReq->enmTxDir = DRVDISKAIOTXDIR_INVALID;
|
---|
| 1378 | pIoReq->off = 0;
|
---|
| 1379 | pIoReq->cbTransfer = 0;
|
---|
| 1380 | pIoReq->paSeg = NULL;
|
---|
| 1381 | pIoReq->cSeg = 0;
|
---|
| 1382 | pIoReq->pvUser = NULL;
|
---|
| 1383 | pIoReq->iSlot = 0;
|
---|
| 1384 | pIoReq->tsStart = 0;
|
---|
| 1385 | pIoReq->tsComplete = 0;
|
---|
| 1386 | pIoReq->IoSeg.pvSeg = NULL;
|
---|
| 1387 | pIoReq->IoSeg.cbSeg = 0;
|
---|
| 1388 |
|
---|
[65703] | 1389 | PDRVDISKAIOREQ *ppIoReq = NULL;
|
---|
| 1390 | rc = pThis->pDrvMediaEx->pfnIoReqAlloc(pThis->pDrvMediaEx, phIoReq, (void **)&ppIoReq, uIoReqId, fFlags);
|
---|
| 1391 | if RT_SUCCESS(rc)
|
---|
| 1392 | {
|
---|
| 1393 | /*
|
---|
| 1394 | * Store the size off the start of our tracking structure because it is
|
---|
| 1395 | * required to access it for the read/write callbacks.
|
---|
| 1396 | *
|
---|
| 1397 | * ASSUMPTION that the offset is constant.
|
---|
| 1398 | */
|
---|
| 1399 | if (!pThis->cbIoReqOpaque)
|
---|
| 1400 | pThis->cbIoReqOpaque = (uintptr_t)ppIoReq - (uintptr_t)*phIoReq;
|
---|
| 1401 | else
|
---|
| 1402 | Assert(pThis->cbIoReqOpaque == (uintptr_t)ppIoReq - (uintptr_t)*phIoReq);
|
---|
| 1403 |
|
---|
| 1404 | *ppIoReq = pIoReq;
|
---|
| 1405 | *ppvIoReqAlloc = ((uint8_t *)ppIoReq) + sizeof(PDRVDISKAIOREQ);
|
---|
| 1406 | }
|
---|
[63727] | 1407 | else
|
---|
[65703] | 1408 | RTMemCacheFree(pThis->hReqCache, pIoReq);
|
---|
[63727] | 1409 | }
|
---|
[65703] | 1410 | else
|
---|
| 1411 | rc = VERR_NO_MEMORY;
|
---|
[63727] | 1412 |
|
---|
| 1413 | return rc;
|
---|
[63700] | 1414 | }
|
---|
| 1415 |
|
---|
| 1416 | /**
|
---|
| 1417 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqFree}
|
---|
| 1418 | */
|
---|
| 1419 | static DECLCALLBACK(int) drvdiskintIoReqFree(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq)
|
---|
| 1420 | {
|
---|
| 1421 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[65703] | 1422 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
|
---|
[63727] | 1423 |
|
---|
| 1424 | if (pIoReq->IoSeg.pvSeg)
|
---|
| 1425 | RTMemFree(pIoReq->IoSeg.pvSeg);
|
---|
| 1426 |
|
---|
[63700] | 1427 | return pThis->pDrvMediaEx->pfnIoReqFree(pThis->pDrvMediaEx, hIoReq);
|
---|
| 1428 | }
|
---|
| 1429 |
|
---|
| 1430 | /**
|
---|
[64724] | 1431 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqQueryResidual}
|
---|
| 1432 | */
|
---|
| 1433 | static DECLCALLBACK(int) drvdiskintIoReqQueryResidual(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, size_t *pcbResidual)
|
---|
| 1434 | {
|
---|
| 1435 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1436 | return pThis->pDrvMediaEx->pfnIoReqQueryResidual(pThis->pDrvMediaEx, hIoReq, pcbResidual);
|
---|
| 1437 | }
|
---|
| 1438 |
|
---|
| 1439 | /**
|
---|
| 1440 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqQueryXferSize}
|
---|
| 1441 | */
|
---|
| 1442 | static DECLCALLBACK(int) drvdiskintIoReqQueryXferSize(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, size_t *pcbXfer)
|
---|
| 1443 | {
|
---|
| 1444 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1445 | return pThis->pDrvMediaEx->pfnIoReqQueryXferSize(pThis->pDrvMediaEx, hIoReq, pcbXfer);
|
---|
| 1446 | }
|
---|
| 1447 |
|
---|
| 1448 | /**
|
---|
| 1449 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqCancelAll}
|
---|
| 1450 | */
|
---|
| 1451 | static DECLCALLBACK(int) drvdiskintIoReqCancelAll(PPDMIMEDIAEX pInterface)
|
---|
| 1452 | {
|
---|
| 1453 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1454 | return pThis->pDrvMediaEx->pfnIoReqCancelAll(pThis->pDrvMediaEx);
|
---|
| 1455 | }
|
---|
| 1456 |
|
---|
| 1457 | /**
|
---|
[63700] | 1458 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqCancel}
|
---|
| 1459 | */
|
---|
| 1460 | static DECLCALLBACK(int) drvdiskintIoReqCancel(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQID uIoReqId)
|
---|
| 1461 | {
|
---|
| 1462 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1463 | return pThis->pDrvMediaEx->pfnIoReqCancel(pThis->pDrvMediaEx, uIoReqId);
|
---|
| 1464 | }
|
---|
| 1465 |
|
---|
| 1466 | /**
|
---|
| 1467 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqRead}
|
---|
| 1468 | */
|
---|
| 1469 | static DECLCALLBACK(int) drvdiskintIoReqRead(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, uint64_t off, size_t cbRead)
|
---|
| 1470 | {
|
---|
| 1471 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[65703] | 1472 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
|
---|
[63727] | 1473 |
|
---|
| 1474 | pIoReq->enmTxDir = DRVDISKAIOTXDIR_READ;
|
---|
| 1475 | pIoReq->off = off;
|
---|
| 1476 | pIoReq->cbTransfer = cbRead;
|
---|
| 1477 |
|
---|
| 1478 | /* Allocate a I/O buffer if the I/O is verified.*/
|
---|
| 1479 | if (pThis->fCheckConsistency)
|
---|
| 1480 | {
|
---|
| 1481 | pIoReq->IoSeg.pvSeg = RTMemAlloc(cbRead);
|
---|
| 1482 | pIoReq->IoSeg.cbSeg = cbRead;
|
---|
| 1483 | }
|
---|
| 1484 |
|
---|
| 1485 | if (pThis->fTraceRequests)
|
---|
| 1486 | drvdiskintIoReqAdd(pThis, pIoReq);
|
---|
| 1487 |
|
---|
[72336] | 1488 | drvdiskintTraceLogFireEvtRead(pThis, (uintptr_t)hIoReq, true /* fAsync */, off, cbRead);
|
---|
[63727] | 1489 | int rc = pThis->pDrvMediaEx->pfnIoReqRead(pThis->pDrvMediaEx, hIoReq, off, cbRead);
|
---|
| 1490 | if (rc == VINF_SUCCESS)
|
---|
| 1491 | {
|
---|
| 1492 | /* Verify the read now. */
|
---|
| 1493 | if (pThis->fCheckConsistency)
|
---|
| 1494 | {
|
---|
| 1495 | int rc2 = drvdiskintReadVerify(pThis, &pIoReq->IoSeg, 1, off, cbRead);
|
---|
| 1496 | AssertRC(rc2);
|
---|
| 1497 | }
|
---|
| 1498 |
|
---|
| 1499 | if (pThis->hIoLogger)
|
---|
| 1500 | {
|
---|
| 1501 | RTSGBUF SgBuf;
|
---|
| 1502 |
|
---|
| 1503 | RTSgBufInit(&SgBuf, &pIoReq->IoSeg, 1);
|
---|
[72312] | 1504 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rc, &SgBuf);
|
---|
[63727] | 1505 | }
|
---|
| 1506 |
|
---|
| 1507 | if (pThis->fTraceRequests)
|
---|
| 1508 | drvdiskintIoReqRemove(pThis, pIoReq);
|
---|
| 1509 | }
|
---|
[72310] | 1510 | else if (rc != VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
|
---|
[72312] | 1511 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rc, NULL);
|
---|
[63727] | 1512 |
|
---|
| 1513 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
| 1514 | return rc;
|
---|
[63700] | 1515 | }
|
---|
| 1516 |
|
---|
| 1517 | /**
|
---|
| 1518 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqWrite}
|
---|
| 1519 | */
|
---|
| 1520 | static DECLCALLBACK(int) drvdiskintIoReqWrite(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, uint64_t off, size_t cbWrite)
|
---|
| 1521 | {
|
---|
| 1522 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[65703] | 1523 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
|
---|
[63727] | 1524 |
|
---|
| 1525 | pIoReq->enmTxDir = DRVDISKAIOTXDIR_WRITE;
|
---|
| 1526 | pIoReq->off = off;
|
---|
| 1527 | pIoReq->cbTransfer = cbWrite;
|
---|
| 1528 |
|
---|
| 1529 | /* Allocate a I/O buffer if the I/O is verified.*/
|
---|
| 1530 | if ( pThis->fCheckConsistency
|
---|
| 1531 | || pThis->fValidateMemBufs
|
---|
| 1532 | || pThis->hIoLogger
|
---|
| 1533 | || pThis->fRecordWriteBeforeCompletion)
|
---|
| 1534 | {
|
---|
| 1535 | pIoReq->IoSeg.pvSeg = RTMemAlloc(cbWrite);
|
---|
| 1536 | pIoReq->IoSeg.cbSeg = cbWrite;
|
---|
| 1537 |
|
---|
| 1538 | /* Sync the memory buffer over if we should validate it. */
|
---|
| 1539 | if ( pThis->fValidateMemBufs
|
---|
| 1540 | || pThis->hIoLogger
|
---|
| 1541 | || pThis->fRecordWriteBeforeCompletion)
|
---|
| 1542 | {
|
---|
| 1543 | RTSGBUF SgBuf;
|
---|
| 1544 |
|
---|
| 1545 | RTSgBufInit(&SgBuf, &pIoReq->IoSeg, 1);
|
---|
[65703] | 1546 | int rc2 = pThis->pDrvMediaExPort->pfnIoReqCopyToBuf(pThis->pDrvMediaExPort, hIoReq,
|
---|
| 1547 | DISKINTEGRITY_IOREQ_HANDLE_2_UPPER_OPAQUE(pThis, hIoReq),
|
---|
| 1548 | 0, &SgBuf, cbWrite);
|
---|
[63727] | 1549 | AssertRC(rc2);
|
---|
| 1550 | }
|
---|
| 1551 | }
|
---|
| 1552 |
|
---|
| 1553 | if (pThis->fTraceRequests)
|
---|
| 1554 | drvdiskintIoReqAdd(pThis, pIoReq);
|
---|
| 1555 |
|
---|
[72336] | 1556 | drvdiskintTraceLogFireEvtWrite(pThis, (uintptr_t)hIoReq, true /* fAsync */, off, cbWrite);
|
---|
[63727] | 1557 | if (pThis->fRecordWriteBeforeCompletion)
|
---|
| 1558 | {
|
---|
| 1559 |
|
---|
| 1560 | int rc2 = drvdiskintWriteRecord(pThis, &pIoReq->IoSeg, 1, off, cbWrite);
|
---|
| 1561 | AssertRC(rc2);
|
---|
| 1562 | }
|
---|
| 1563 |
|
---|
| 1564 | int rc = pThis->pDrvMediaEx->pfnIoReqWrite(pThis->pDrvMediaEx, hIoReq, off, cbWrite);
|
---|
| 1565 | if (rc == VINF_SUCCESS)
|
---|
| 1566 | {
|
---|
| 1567 | /* Record the write. */
|
---|
| 1568 | if ( pThis->fCheckConsistency
|
---|
| 1569 | && !pThis->fRecordWriteBeforeCompletion)
|
---|
| 1570 | {
|
---|
| 1571 | int rc2 = drvdiskintWriteRecord(pThis, &pIoReq->IoSeg, 1, off, cbWrite);
|
---|
| 1572 | AssertRC(rc2);
|
---|
| 1573 | }
|
---|
| 1574 |
|
---|
[72310] | 1575 | RTSGBUF SgBuf;
|
---|
| 1576 | RTSgBufInit(&SgBuf, &pIoReq->IoSeg, 1);
|
---|
[72312] | 1577 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rc, &SgBuf);
|
---|
[63727] | 1578 | if (pThis->fTraceRequests)
|
---|
| 1579 | drvdiskintIoReqRemove(pThis, pIoReq);
|
---|
| 1580 | }
|
---|
[72310] | 1581 | else if (rc != VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
|
---|
[72312] | 1582 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rc, NULL);
|
---|
[63727] | 1583 |
|
---|
| 1584 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
| 1585 | return rc;
|
---|
[63700] | 1586 | }
|
---|
| 1587 |
|
---|
| 1588 | /**
|
---|
| 1589 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqFlush}
|
---|
| 1590 | */
|
---|
| 1591 | static DECLCALLBACK(int) drvdiskintIoReqFlush(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq)
|
---|
| 1592 | {
|
---|
| 1593 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[65703] | 1594 | PDRVDISKAIOREQ pIoReq = DISKINTEGRITY_IOREQ_HANDLE_2_DRVDISKAIOREQ(pThis, hIoReq);
|
---|
[63727] | 1595 |
|
---|
| 1596 | pIoReq->enmTxDir = DRVDISKAIOTXDIR_FLUSH;
|
---|
| 1597 | pIoReq->off = 0;
|
---|
| 1598 | pIoReq->cbTransfer = 0;
|
---|
| 1599 |
|
---|
| 1600 | if (pThis->fTraceRequests)
|
---|
| 1601 | drvdiskintIoReqAdd(pThis, pIoReq);
|
---|
| 1602 |
|
---|
[72336] | 1603 | drvdiskintTraceLogFireEvtFlush(pThis, (uintptr_t)hIoReq, true /* fAsync */);
|
---|
[63727] | 1604 | int rc = pThis->pDrvMediaEx->pfnIoReqFlush(pThis->pDrvMediaEx, hIoReq);
|
---|
| 1605 | if (rc == VINF_SUCCESS)
|
---|
[72312] | 1606 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rc, NULL);
|
---|
[72310] | 1607 | else if (rc != VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
|
---|
[72312] | 1608 | drvdiskintTraceLogFireEvtComplete(pThis, (uintptr_t)hIoReq, rc, NULL);
|
---|
[63727] | 1609 |
|
---|
| 1610 | LogFlowFunc(("returns %Rrc\n", rc));
|
---|
| 1611 | return rc;
|
---|
[63700] | 1612 | }
|
---|
| 1613 |
|
---|
| 1614 | /**
|
---|
| 1615 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqDiscard}
|
---|
| 1616 | */
|
---|
[63997] | 1617 | static DECLCALLBACK(int) drvdiskintIoReqDiscard(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq, unsigned cRangesMax)
|
---|
[63700] | 1618 | {
|
---|
| 1619 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
[63997] | 1620 | return pThis->pDrvMediaEx->pfnIoReqDiscard(pThis->pDrvMediaEx, hIoReq, cRangesMax);
|
---|
[63700] | 1621 | }
|
---|
| 1622 |
|
---|
| 1623 | /**
|
---|
| 1624 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqGetActiveCount}
|
---|
| 1625 | */
|
---|
| 1626 | static DECLCALLBACK(uint32_t) drvdiskintIoReqGetActiveCount(PPDMIMEDIAEX pInterface)
|
---|
| 1627 | {
|
---|
| 1628 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1629 | return pThis->pDrvMediaEx->pfnIoReqGetActiveCount(pThis->pDrvMediaEx);
|
---|
| 1630 | }
|
---|
| 1631 |
|
---|
| 1632 | /**
|
---|
| 1633 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqGetSuspendedCount}
|
---|
| 1634 | */
|
---|
| 1635 | static DECLCALLBACK(uint32_t) drvdiskintIoReqGetSuspendedCount(PPDMIMEDIAEX pInterface)
|
---|
| 1636 | {
|
---|
| 1637 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1638 | return pThis->pDrvMediaEx->pfnIoReqGetSuspendedCount(pThis->pDrvMediaEx);
|
---|
| 1639 | }
|
---|
| 1640 |
|
---|
| 1641 | /**
|
---|
| 1642 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqQuerySuspendedStart}
|
---|
| 1643 | */
|
---|
| 1644 | static DECLCALLBACK(int) drvdiskintIoReqQuerySuspendedStart(PPDMIMEDIAEX pInterface, PPDMMEDIAEXIOREQ phIoReq, void **ppvIoReqAlloc)
|
---|
| 1645 | {
|
---|
| 1646 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1647 | return pThis->pDrvMediaEx->pfnIoReqQuerySuspendedStart(pThis->pDrvMediaEx, phIoReq, ppvIoReqAlloc);
|
---|
| 1648 | }
|
---|
| 1649 |
|
---|
| 1650 | /**
|
---|
| 1651 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqQuerySuspendedNext}
|
---|
| 1652 | */
|
---|
| 1653 | static DECLCALLBACK(int) drvdiskintIoReqQuerySuspendedNext(PPDMIMEDIAEX pInterface, PDMMEDIAEXIOREQ hIoReq,
|
---|
| 1654 | PPDMMEDIAEXIOREQ phIoReqNext, void **ppvIoReqAllocNext)
|
---|
| 1655 | {
|
---|
| 1656 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1657 | return pThis->pDrvMediaEx->pfnIoReqQuerySuspendedNext(pThis->pDrvMediaEx, hIoReq, phIoReqNext, ppvIoReqAllocNext);
|
---|
| 1658 | }
|
---|
| 1659 |
|
---|
| 1660 | /**
|
---|
| 1661 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqSuspendedSave}
|
---|
| 1662 | */
|
---|
| 1663 | static DECLCALLBACK(int) drvdiskintIoReqSuspendedSave(PPDMIMEDIAEX pInterface, PSSMHANDLE pSSM, PDMMEDIAEXIOREQ hIoReq)
|
---|
| 1664 | {
|
---|
| 1665 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1666 | return pThis->pDrvMediaEx->pfnIoReqSuspendedSave(pThis->pDrvMediaEx, pSSM, hIoReq);
|
---|
| 1667 | }
|
---|
| 1668 |
|
---|
| 1669 | /**
|
---|
| 1670 | * @interface_method_impl{PDMIMEDIAEX,pfnIoReqSuspendedLoad}
|
---|
| 1671 | */
|
---|
| 1672 | static DECLCALLBACK(int) drvdiskintIoReqSuspendedLoad(PPDMIMEDIAEX pInterface, PSSMHANDLE pSSM, PDMMEDIAEXIOREQ hIoReq)
|
---|
| 1673 | {
|
---|
| 1674 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMediaEx);
|
---|
| 1675 | return pThis->pDrvMediaEx->pfnIoReqSuspendedLoad(pThis->pDrvMediaEx, pSSM, hIoReq);
|
---|
| 1676 | }
|
---|
| 1677 |
|
---|
[73094] | 1678 | /* -=-=-=-=- IMount -=-=-=-=- */
|
---|
| 1679 |
|
---|
| 1680 | /** @interface_method_impl{PDMIMOUNT,pfnUnmount} */
|
---|
| 1681 | static DECLCALLBACK(int) drvdiskintUnmount(PPDMIMOUNT pInterface, bool fForce, bool fEject)
|
---|
| 1682 | {
|
---|
| 1683 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMount);
|
---|
| 1684 | return pThis->pDrvMount->pfnUnmount(pThis->pDrvMount, fForce, fEject);
|
---|
| 1685 | }
|
---|
| 1686 |
|
---|
| 1687 | /** @interface_method_impl{PDMIMOUNT,pfnIsMounted} */
|
---|
| 1688 | static DECLCALLBACK(bool) drvdiskintIsMounted(PPDMIMOUNT pInterface)
|
---|
| 1689 | {
|
---|
| 1690 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMount);
|
---|
| 1691 | return pThis->pDrvMount->pfnIsMounted(pThis->pDrvMount);
|
---|
| 1692 | }
|
---|
| 1693 |
|
---|
| 1694 | /** @interface_method_impl{PDMIMOUNT,pfnLock} */
|
---|
| 1695 | static DECLCALLBACK(int) drvdiskintLock(PPDMIMOUNT pInterface)
|
---|
| 1696 | {
|
---|
| 1697 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMount);
|
---|
| 1698 | return pThis->pDrvMount->pfnLock(pThis->pDrvMount);
|
---|
| 1699 | }
|
---|
| 1700 |
|
---|
| 1701 | /** @interface_method_impl{PDMIMOUNT,pfnUnlock} */
|
---|
| 1702 | static DECLCALLBACK(int) drvdiskintUnlock(PPDMIMOUNT pInterface)
|
---|
| 1703 | {
|
---|
| 1704 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMount);
|
---|
| 1705 | return pThis->pDrvMount->pfnUnlock(pThis->pDrvMount);
|
---|
| 1706 | }
|
---|
| 1707 |
|
---|
| 1708 | /** @interface_method_impl{PDMIMOUNT,pfnIsLocked} */
|
---|
| 1709 | static DECLCALLBACK(bool) drvdiskintIsLocked(PPDMIMOUNT pInterface)
|
---|
| 1710 | {
|
---|
| 1711 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMount);
|
---|
| 1712 | return pThis->pDrvMount->pfnIsLocked(pThis->pDrvMount);
|
---|
| 1713 | }
|
---|
| 1714 |
|
---|
| 1715 | /* -=-=-=-=- IMountNotify -=-=-=-=- */
|
---|
| 1716 |
|
---|
| 1717 | /** @interface_method_impl{PDMIMOUNTNOTIFY,pfnMountNotify} */
|
---|
| 1718 | static DECLCALLBACK(void) drvdiskintMountNotify(PPDMIMOUNTNOTIFY pInterface)
|
---|
| 1719 | {
|
---|
| 1720 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMountNotify);
|
---|
| 1721 | pThis->pDrvMountNotify->pfnMountNotify(pThis->pDrvMountNotify);
|
---|
| 1722 | }
|
---|
| 1723 |
|
---|
| 1724 | /** @interface_method_impl{PDMIMOUNTNOTIFY,pfnUnmountNotify} */
|
---|
| 1725 | static DECLCALLBACK(void) drvdiskintUnmountNotify(PPDMIMOUNTNOTIFY pInterface)
|
---|
| 1726 | {
|
---|
| 1727 | PDRVDISKINTEGRITY pThis = RT_FROM_MEMBER(pInterface, DRVDISKINTEGRITY, IMountNotify);
|
---|
| 1728 | pThis->pDrvMountNotify->pfnUnmountNotify(pThis->pDrvMountNotify);
|
---|
| 1729 | }
|
---|
| 1730 |
|
---|
[27558] | 1731 | /* -=-=-=-=- IBase -=-=-=-=- */
|
---|
| 1732 |
|
---|
| 1733 | /**
|
---|
| 1734 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
| 1735 | */
|
---|
| 1736 | static DECLCALLBACK(void *) drvdiskintQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
| 1737 | {
|
---|
| 1738 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
| 1739 | PDRVDISKINTEGRITY pThis = PDMINS_2_DATA(pDrvIns, PDRVDISKINTEGRITY);
|
---|
| 1740 |
|
---|
| 1741 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
| 1742 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
|
---|
[34433] | 1743 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pThis->IMediaPort);
|
---|
[63700] | 1744 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAEXPORT, &pThis->IMediaExPort);
|
---|
| 1745 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAEX, pThis->pDrvMediaEx ? &pThis->IMediaEx : NULL);
|
---|
[73094] | 1746 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNT, pThis->pDrvMount ? &pThis->IMount : NULL);
|
---|
| 1747 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pThis->IMountNotify);
|
---|
[27558] | 1748 | return NULL;
|
---|
| 1749 | }
|
---|
| 1750 |
|
---|
| 1751 |
|
---|
| 1752 | /* -=-=-=-=- driver interface -=-=-=-=- */
|
---|
| 1753 |
|
---|
[63689] | 1754 | static DECLCALLBACK(int) drvdiskintTreeDestroy(PAVLRFOFFNODECORE pNode, void *pvUser)
|
---|
[27558] | 1755 | {
|
---|
| 1756 | PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)pNode;
|
---|
| 1757 |
|
---|
[63689] | 1758 | RT_NOREF(pvUser);
|
---|
| 1759 |
|
---|
[27558] | 1760 | RTMemFree(pSeg->pbSeg);
|
---|
| 1761 | RTMemFree(pSeg);
|
---|
| 1762 | return VINF_SUCCESS;
|
---|
| 1763 | }
|
---|
| 1764 |
|
---|
| 1765 | /**
|
---|
| 1766 | * @copydoc FNPDMDRVDESTRUCT
|
---|
| 1767 | */
|
---|
| 1768 | static DECLCALLBACK(void) drvdiskintDestruct(PPDMDRVINS pDrvIns)
|
---|
| 1769 | {
|
---|
| 1770 | PDRVDISKINTEGRITY pThis = PDMINS_2_DATA(pDrvIns, PDRVDISKINTEGRITY);
|
---|
| 1771 |
|
---|
| 1772 | if (pThis->pTreeSegments)
|
---|
| 1773 | {
|
---|
| 1774 | RTAvlrFileOffsetDestroy(pThis->pTreeSegments, drvdiskintTreeDestroy, NULL);
|
---|
| 1775 | RTMemFree(pThis->pTreeSegments);
|
---|
| 1776 | }
|
---|
[28902] | 1777 |
|
---|
| 1778 | if (pThis->fTraceRequests)
|
---|
| 1779 | {
|
---|
| 1780 | pThis->fRunning = false;
|
---|
| 1781 | RTSemEventSignal(pThis->SemEvent);
|
---|
| 1782 | RTSemEventDestroy(pThis->SemEvent);
|
---|
| 1783 | }
|
---|
[29443] | 1784 |
|
---|
| 1785 | if (pThis->fCheckDoubleCompletion)
|
---|
| 1786 | {
|
---|
| 1787 | /* Free all requests */
|
---|
| 1788 | while (pThis->papIoReq[pThis->iEntry])
|
---|
| 1789 | {
|
---|
| 1790 | RTMemFree(pThis->papIoReq[pThis->iEntry]);
|
---|
| 1791 | pThis->papIoReq[pThis->iEntry] = NULL;
|
---|
| 1792 | pThis->iEntry = (pThis->iEntry+1) % pThis->cEntries;
|
---|
| 1793 | }
|
---|
| 1794 | }
|
---|
[38541] | 1795 |
|
---|
| 1796 | if (pThis->hIoLogger)
|
---|
[72310] | 1797 | RTTraceLogWrDestroy(pThis->hIoLogger);
|
---|
[65703] | 1798 |
|
---|
| 1799 | if (pThis->hReqCache != NIL_RTMEMCACHE)
|
---|
| 1800 | {
|
---|
| 1801 | RTMemCacheDestroy(pThis->hReqCache);
|
---|
| 1802 | pThis->hReqCache = NIL_RTMEMCACHE;
|
---|
| 1803 | }
|
---|
[27558] | 1804 | }
|
---|
| 1805 |
|
---|
| 1806 | /**
|
---|
| 1807 | * Construct a disk integrity driver instance.
|
---|
| 1808 | *
|
---|
| 1809 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
| 1810 | */
|
---|
| 1811 | static DECLCALLBACK(int) drvdiskintConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
| 1812 | {
|
---|
| 1813 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
[91869] | 1814 | PDRVDISKINTEGRITY pThis = PDMINS_2_DATA(pDrvIns, PDRVDISKINTEGRITY);
|
---|
| 1815 | PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
|
---|
[27558] | 1816 |
|
---|
[91869] | 1817 | LogFlow(("drvdiskintConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
| 1818 |
|
---|
[27558] | 1819 | /*
|
---|
| 1820 | * Validate configuration.
|
---|
| 1821 | */
|
---|
[91869] | 1822 | PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "CheckConsistency"
|
---|
| 1823 | "|TraceRequests"
|
---|
| 1824 | "|CheckIntervalMs"
|
---|
| 1825 | "|ExpireIntervalMs"
|
---|
| 1826 | "|CheckDoubleCompletions"
|
---|
| 1827 | "|HistorySize"
|
---|
| 1828 | "|IoLogType"
|
---|
| 1829 | "|IoLogFile"
|
---|
| 1830 | "|IoLogAddress"
|
---|
| 1831 | "|IoLogPort"
|
---|
| 1832 | "|IoLogData"
|
---|
| 1833 | "|PrepopulateRamDisk"
|
---|
| 1834 | "|ReadAfterWrite"
|
---|
| 1835 | "|RecordWriteBeforeCompletion"
|
---|
| 1836 | "|ValidateMemoryBuffers",
|
---|
| 1837 | "");
|
---|
[27558] | 1838 |
|
---|
[91869] | 1839 | int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "CheckConsistency", &pThis->fCheckConsistency, false);
|
---|
[28902] | 1840 | AssertRC(rc);
|
---|
[91869] | 1841 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "TraceRequests", &pThis->fTraceRequests, false);
|
---|
[28902] | 1842 | AssertRC(rc);
|
---|
[91869] | 1843 | rc = pHlp->pfnCFGMQueryU32Def(pCfg, "CheckIntervalMs", &pThis->uCheckIntervalMs, 5000); /* 5 seconds */
|
---|
[28902] | 1844 | AssertRC(rc);
|
---|
[91869] | 1845 | rc = pHlp->pfnCFGMQueryU32Def(pCfg, "ExpireIntervalMs", &pThis->uExpireIntervalMs, 20000); /* 20 seconds */
|
---|
[28902] | 1846 | AssertRC(rc);
|
---|
[91869] | 1847 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "CheckDoubleCompletions", &pThis->fCheckDoubleCompletion, false);
|
---|
[29443] | 1848 | AssertRC(rc);
|
---|
[91869] | 1849 | rc = pHlp->pfnCFGMQueryU32Def(pCfg, "HistorySize", &pThis->cEntries, 512);
|
---|
[29443] | 1850 | AssertRC(rc);
|
---|
[91869] | 1851 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "PrepopulateRamDisk", &pThis->fPrepopulateRamDisk, false);
|
---|
[46859] | 1852 | AssertRC(rc);
|
---|
[91869] | 1853 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ReadAfterWrite", &pThis->fReadAfterWrite, false);
|
---|
[51619] | 1854 | AssertRC(rc);
|
---|
[91869] | 1855 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "RecordWriteBeforeCompletion", &pThis->fRecordWriteBeforeCompletion, false);
|
---|
[51749] | 1856 | AssertRC(rc);
|
---|
[91869] | 1857 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "ValidateMemoryBuffers", &pThis->fValidateMemBufs, false);
|
---|
[63727] | 1858 | AssertRC(rc);
|
---|
[28902] | 1859 |
|
---|
[65480] | 1860 | bool fIoLogData = false;
|
---|
[91869] | 1861 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "IoLogData", &fIoLogData, false);
|
---|
[65480] | 1862 | AssertRC(rc);
|
---|
[72310] | 1863 |
|
---|
| 1864 | char *pszIoLogType = NULL;
|
---|
[38541] | 1865 | char *pszIoLogFilename = NULL;
|
---|
[72310] | 1866 | char *pszAddress = NULL;
|
---|
| 1867 | uint32_t uPort = 0;
|
---|
[91869] | 1868 | rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "IoLogType", &pszIoLogType);
|
---|
[72310] | 1869 | if (RT_SUCCESS(rc))
|
---|
| 1870 | {
|
---|
| 1871 | if (!RTStrICmp(pszIoLogType, "File"))
|
---|
| 1872 | {
|
---|
[91869] | 1873 | rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "IoLogFile", &pszIoLogFilename);
|
---|
[72310] | 1874 | AssertRC(rc);
|
---|
| 1875 | }
|
---|
| 1876 | else if (!RTStrICmp(pszIoLogType, "Server"))
|
---|
| 1877 | {
|
---|
[91869] | 1878 | rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "IoLogAddress", &pszAddress, NULL);
|
---|
[72310] | 1879 | AssertRC(rc);
|
---|
[91869] | 1880 | rc = pHlp->pfnCFGMQueryU32Def(pCfg, "IoLogPort", &uPort, 4000);
|
---|
[72310] | 1881 | AssertRC(rc);
|
---|
| 1882 | }
|
---|
| 1883 | else if (!RTStrICmp(pszIoLogType, "Client"))
|
---|
| 1884 | {
|
---|
[91869] | 1885 | rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "IoLogAddress", &pszAddress);
|
---|
[72310] | 1886 | AssertRC(rc);
|
---|
[91869] | 1887 | rc = pHlp->pfnCFGMQueryU32Def(pCfg, "IoLogPort", &uPort, 4000);
|
---|
[72310] | 1888 | AssertRC(rc);
|
---|
| 1889 | }
|
---|
| 1890 | else
|
---|
| 1891 | AssertMsgFailed(("Invalid I/O log type given: %s\n", pszIoLogType));
|
---|
| 1892 | }
|
---|
| 1893 | else
|
---|
| 1894 | Assert(rc == VERR_CFGM_VALUE_NOT_FOUND);
|
---|
[38541] | 1895 |
|
---|
[27558] | 1896 | /*
|
---|
| 1897 | * Initialize most of the data members.
|
---|
| 1898 | */
|
---|
| 1899 | pThis->pDrvIns = pDrvIns;
|
---|
[65703] | 1900 | pThis->hReqCache = NIL_RTMEMCACHE;
|
---|
[27558] | 1901 |
|
---|
| 1902 | /* IBase. */
|
---|
| 1903 | pDrvIns->IBase.pfnQueryInterface = drvdiskintQueryInterface;
|
---|
| 1904 |
|
---|
| 1905 | /* IMedia */
|
---|
[83042] | 1906 | pThis->IMedia.pfnRead = drvdiskintRead;
|
---|
| 1907 | pThis->IMedia.pfnWrite = drvdiskintWrite;
|
---|
| 1908 | pThis->IMedia.pfnFlush = drvdiskintFlush;
|
---|
| 1909 | pThis->IMedia.pfnGetSize = drvdiskintGetSize;
|
---|
| 1910 | pThis->IMedia.pfnIsReadOnly = drvdiskintIsReadOnly;
|
---|
| 1911 | pThis->IMedia.pfnBiosIsVisible = drvdiskintBiosIsVisible;
|
---|
| 1912 | pThis->IMedia.pfnBiosGetPCHSGeometry = drvdiskintBiosGetPCHSGeometry;
|
---|
| 1913 | pThis->IMedia.pfnBiosSetPCHSGeometry = drvdiskintBiosSetPCHSGeometry;
|
---|
| 1914 | pThis->IMedia.pfnBiosGetLCHSGeometry = drvdiskintBiosGetLCHSGeometry;
|
---|
| 1915 | pThis->IMedia.pfnBiosSetLCHSGeometry = drvdiskintBiosSetLCHSGeometry;
|
---|
| 1916 | pThis->IMedia.pfnGetUuid = drvdiskintGetUuid;
|
---|
| 1917 | pThis->IMedia.pfnGetSectorSize = drvdiskintGetSectorSize;
|
---|
| 1918 | pThis->IMedia.pfnGetType = drvdiskintGetType;
|
---|
| 1919 | pThis->IMedia.pfnReadPcBios = drvdiskintReadPcBios;
|
---|
| 1920 | pThis->IMedia.pfnIsNonRotational = drvdiskintIsNonRotational;
|
---|
| 1921 | pThis->IMedia.pfnSendCmd = NULL;
|
---|
| 1922 | pThis->IMedia.pfnGetRegionCount = drvdiskintGetRegionCount;
|
---|
| 1923 | pThis->IMedia.pfnQueryRegionProperties = drvdiskintQueryRegionProperties;
|
---|
| 1924 | pThis->IMedia.pfnQueryRegionPropertiesForLba = drvdiskintQueryRegionPropertiesForLba;
|
---|
[27558] | 1925 |
|
---|
[83042] | 1926 |
|
---|
[63700] | 1927 | /* IMediaEx. */
|
---|
[64724] | 1928 | pThis->IMediaEx.pfnQueryFeatures = drvdiskintQueryFeatures;
|
---|
[83042] | 1929 | pThis->IMediaEx.pfnNotifySuspend = drvdiskintNotifySuspend;
|
---|
[63700] | 1930 | pThis->IMediaEx.pfnIoReqAllocSizeSet = drvdiskintIoReqAllocSizeSet;
|
---|
| 1931 | pThis->IMediaEx.pfnIoReqAlloc = drvdiskintIoReqAlloc;
|
---|
| 1932 | pThis->IMediaEx.pfnIoReqFree = drvdiskintIoReqFree;
|
---|
[64724] | 1933 | pThis->IMediaEx.pfnIoReqQueryResidual = drvdiskintIoReqQueryResidual;
|
---|
| 1934 | pThis->IMediaEx.pfnIoReqQueryXferSize = drvdiskintIoReqQueryXferSize;
|
---|
| 1935 | pThis->IMediaEx.pfnIoReqCancelAll = drvdiskintIoReqCancelAll;
|
---|
[63700] | 1936 | pThis->IMediaEx.pfnIoReqCancel = drvdiskintIoReqCancel;
|
---|
| 1937 | pThis->IMediaEx.pfnIoReqRead = drvdiskintIoReqRead;
|
---|
| 1938 | pThis->IMediaEx.pfnIoReqWrite = drvdiskintIoReqWrite;
|
---|
| 1939 | pThis->IMediaEx.pfnIoReqFlush = drvdiskintIoReqFlush;
|
---|
| 1940 | pThis->IMediaEx.pfnIoReqDiscard = drvdiskintIoReqDiscard;
|
---|
| 1941 | pThis->IMediaEx.pfnIoReqGetActiveCount = drvdiskintIoReqGetActiveCount;
|
---|
| 1942 | pThis->IMediaEx.pfnIoReqGetSuspendedCount = drvdiskintIoReqGetSuspendedCount;
|
---|
| 1943 | pThis->IMediaEx.pfnIoReqQuerySuspendedStart = drvdiskintIoReqQuerySuspendedStart;
|
---|
| 1944 | pThis->IMediaEx.pfnIoReqQuerySuspendedNext = drvdiskintIoReqQuerySuspendedNext;
|
---|
| 1945 | pThis->IMediaEx.pfnIoReqSuspendedSave = drvdiskintIoReqSuspendedSave;
|
---|
| 1946 | pThis->IMediaEx.pfnIoReqSuspendedLoad = drvdiskintIoReqSuspendedLoad;
|
---|
| 1947 |
|
---|
[34433] | 1948 | /* IMediaPort. */
|
---|
| 1949 | pThis->IMediaPort.pfnQueryDeviceLocation = drvdiskintQueryDeviceLocation;
|
---|
| 1950 |
|
---|
[63700] | 1951 | /* IMediaExPort. */
|
---|
[63997] | 1952 | pThis->IMediaExPort.pfnIoReqCompleteNotify = drvdiskintIoReqCompleteNotify;
|
---|
| 1953 | pThis->IMediaExPort.pfnIoReqCopyFromBuf = drvdiskintIoReqCopyFromBuf;
|
---|
| 1954 | pThis->IMediaExPort.pfnIoReqCopyToBuf = drvdiskintIoReqCopyToBuf;
|
---|
| 1955 | pThis->IMediaExPort.pfnIoReqQueryDiscardRanges = drvdiskintIoReqQueryDiscardRanges;
|
---|
| 1956 | pThis->IMediaExPort.pfnIoReqStateChanged = drvdiskintIoReqStateChanged;
|
---|
[63700] | 1957 |
|
---|
[73094] | 1958 | /* IMount */
|
---|
| 1959 | pThis->IMount.pfnUnmount = drvdiskintUnmount;
|
---|
| 1960 | pThis->IMount.pfnIsMounted = drvdiskintIsMounted;
|
---|
| 1961 | pThis->IMount.pfnLock = drvdiskintLock;
|
---|
| 1962 | pThis->IMount.pfnUnlock = drvdiskintUnlock;
|
---|
| 1963 | pThis->IMount.pfnIsLocked = drvdiskintIsLocked;
|
---|
| 1964 |
|
---|
| 1965 | /* IMountNotify */
|
---|
| 1966 | pThis->IMountNotify.pfnMountNotify = drvdiskintMountNotify;
|
---|
| 1967 | pThis->IMountNotify.pfnUnmountNotify = drvdiskintUnmountNotify;
|
---|
| 1968 |
|
---|
[34433] | 1969 | /* Query the media port interface above us. */
|
---|
| 1970 | pThis->pDrvMediaPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAPORT);
|
---|
| 1971 | if (!pThis->pDrvMediaPort)
|
---|
| 1972 | return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_BELOW,
|
---|
[72310] | 1973 | N_("No media port interface above"));
|
---|
[34433] | 1974 |
|
---|
[63700] | 1975 | /* Try to attach extended media port interface above.*/
|
---|
| 1976 | pThis->pDrvMediaExPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAEXPORT);
|
---|
| 1977 |
|
---|
[65703] | 1978 | rc = RTMemCacheCreate(&pThis->hReqCache, sizeof(DRVDISKAIOREQ), 0, UINT32_MAX,
|
---|
| 1979 | NULL, NULL, NULL, 0);
|
---|
| 1980 | if (RT_FAILURE(rc))
|
---|
| 1981 | return PDMDRV_SET_ERROR(pDrvIns, rc,
|
---|
| 1982 | N_("Failed to create request tracking structure cache"));
|
---|
| 1983 |
|
---|
[27558] | 1984 | /*
|
---|
| 1985 | * Try attach driver below and query it's media interface.
|
---|
| 1986 | */
|
---|
| 1987 | PPDMIBASE pBase;
|
---|
[28902] | 1988 | rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pBase);
|
---|
[27558] | 1989 | if (RT_FAILURE(rc))
|
---|
| 1990 | return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
|
---|
[28902] | 1991 | N_("Failed to attach driver below us! %Rrc"), rc);
|
---|
[27558] | 1992 |
|
---|
| 1993 | pThis->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIA);
|
---|
| 1994 | if (!pThis->pDrvMedia)
|
---|
| 1995 | return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_BELOW,
|
---|
| 1996 | N_("No media or async media interface below"));
|
---|
| 1997 |
|
---|
[63700] | 1998 | pThis->pDrvMediaEx = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIAEX);
|
---|
[73094] | 1999 | pThis->pDrvMount = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMOUNT);
|
---|
[28114] | 2000 |
|
---|
[38631] | 2001 | if (pThis->pDrvMedia->pfnDiscard)
|
---|
| 2002 | pThis->IMedia.pfnDiscard = drvdiskintDiscard;
|
---|
| 2003 |
|
---|
[28902] | 2004 | if (pThis->fCheckConsistency)
|
---|
| 2005 | {
|
---|
| 2006 | /* Create the AVL tree. */
|
---|
| 2007 | pThis->pTreeSegments = (PAVLRFOFFTREE)RTMemAllocZ(sizeof(AVLRFOFFTREE));
|
---|
| 2008 | if (!pThis->pTreeSegments)
|
---|
| 2009 | rc = VERR_NO_MEMORY;
|
---|
| 2010 | }
|
---|
[27558] | 2011 |
|
---|
[28902] | 2012 | if (pThis->fTraceRequests)
|
---|
| 2013 | {
|
---|
| 2014 | for (unsigned i = 0; i < RT_ELEMENTS(pThis->apReqActive); i++)
|
---|
| 2015 | {
|
---|
| 2016 | pThis->apReqActive[i].pIoReq = NULL;
|
---|
| 2017 | pThis->apReqActive[i].tsStart = 0;
|
---|
| 2018 | }
|
---|
| 2019 |
|
---|
| 2020 | pThis->iNextFreeSlot = 0;
|
---|
| 2021 |
|
---|
| 2022 | /* Init event semaphore. */
|
---|
| 2023 | rc = RTSemEventCreate(&pThis->SemEvent);
|
---|
| 2024 | AssertRC(rc);
|
---|
| 2025 | pThis->fRunning = true;
|
---|
| 2026 | rc = RTThreadCreate(&pThis->hThread, drvdiskIntIoReqExpiredCheck, pThis,
|
---|
| 2027 | 0, RTTHREADTYPE_INFREQUENT_POLLER, 0, "DiskIntegrity");
|
---|
| 2028 | AssertRC(rc);
|
---|
| 2029 | }
|
---|
| 2030 |
|
---|
[29443] | 2031 | if (pThis->fCheckDoubleCompletion)
|
---|
| 2032 | {
|
---|
| 2033 | pThis->iEntry = 0;
|
---|
| 2034 | pThis->papIoReq = (PDRVDISKAIOREQ *)RTMemAllocZ(pThis->cEntries * sizeof(PDRVDISKAIOREQ));
|
---|
| 2035 | AssertPtr(pThis->papIoReq);
|
---|
| 2036 | }
|
---|
| 2037 |
|
---|
[72310] | 2038 | if (pszIoLogType)
|
---|
[38541] | 2039 | {
|
---|
[72310] | 2040 | if (!RTStrICmp(pszIoLogType, "File"))
|
---|
| 2041 | {
|
---|
| 2042 | rc = RTTraceLogWrCreateFile(&pThis->hIoLogger, NULL, pszIoLogFilename);
|
---|
[91897] | 2043 | PDMDrvHlpMMHeapFree(pDrvIns, pszIoLogFilename);
|
---|
[72310] | 2044 | }
|
---|
| 2045 | else if (!RTStrICmp(pszIoLogType, "Server"))
|
---|
| 2046 | {
|
---|
| 2047 | rc = RTTraceLogWrCreateTcpServer(&pThis->hIoLogger, NULL, pszAddress, uPort);
|
---|
| 2048 | if (pszAddress)
|
---|
[91897] | 2049 | PDMDrvHlpMMHeapFree(pDrvIns, pszAddress);
|
---|
[72310] | 2050 | }
|
---|
| 2051 | else if (!RTStrICmp(pszIoLogType, "Client"))
|
---|
| 2052 | {
|
---|
| 2053 | rc = RTTraceLogWrCreateTcpClient(&pThis->hIoLogger, NULL, pszAddress, uPort);
|
---|
[91897] | 2054 | PDMDrvHlpMMHeapFree(pDrvIns, pszAddress);
|
---|
[72310] | 2055 | }
|
---|
| 2056 | else
|
---|
| 2057 | AssertMsgFailed(("Invalid I/O log type given: %s\n", pszIoLogType));
|
---|
| 2058 |
|
---|
[91897] | 2059 | PDMDrvHlpMMHeapFree(pDrvIns, pszIoLogType);
|
---|
[38541] | 2060 | }
|
---|
| 2061 |
|
---|
[46859] | 2062 | /* Read in all data before the start if requested. */
|
---|
| 2063 | if (pThis->fPrepopulateRamDisk)
|
---|
| 2064 | {
|
---|
| 2065 | uint64_t cbDisk = 0;
|
---|
| 2066 |
|
---|
| 2067 | LogRel(("DiskIntegrity: Prepopulating RAM disk, this will take some time...\n"));
|
---|
| 2068 |
|
---|
| 2069 | cbDisk = pThis->pDrvMedia->pfnGetSize(pThis->pDrvMedia);
|
---|
| 2070 | if (cbDisk)
|
---|
| 2071 | {
|
---|
| 2072 | uint64_t off = 0;
|
---|
| 2073 | uint8_t abBuffer[_64K];
|
---|
| 2074 | RTSGSEG Seg;
|
---|
| 2075 |
|
---|
| 2076 | Seg.pvSeg = abBuffer;
|
---|
| 2077 |
|
---|
| 2078 | while (cbDisk)
|
---|
| 2079 | {
|
---|
| 2080 | size_t cbThisRead = RT_MIN(cbDisk, sizeof(abBuffer));
|
---|
| 2081 |
|
---|
| 2082 | rc = pThis->pDrvMedia->pfnRead(pThis->pDrvMedia, off, abBuffer, cbThisRead);
|
---|
| 2083 | if (RT_FAILURE(rc))
|
---|
| 2084 | break;
|
---|
| 2085 |
|
---|
| 2086 | if (ASMBitFirstSet(abBuffer, sizeof(abBuffer) * 8) != -1)
|
---|
| 2087 | {
|
---|
| 2088 | Seg.cbSeg = cbThisRead;
|
---|
| 2089 | rc = drvdiskintWriteRecord(pThis, &Seg, 1,
|
---|
| 2090 | off, cbThisRead);
|
---|
| 2091 | if (RT_FAILURE(rc))
|
---|
| 2092 | break;
|
---|
| 2093 | }
|
---|
| 2094 |
|
---|
| 2095 | cbDisk -= cbThisRead;
|
---|
| 2096 | off += cbThisRead;
|
---|
| 2097 | }
|
---|
| 2098 |
|
---|
| 2099 | LogRel(("DiskIntegrity: Prepopulating RAM disk finished with %Rrc\n", rc));
|
---|
| 2100 | }
|
---|
| 2101 | else
|
---|
| 2102 | return PDMDRV_SET_ERROR(pDrvIns, VERR_INTERNAL_ERROR,
|
---|
| 2103 | N_("DiskIntegrity: Error querying the media size below"));
|
---|
| 2104 | }
|
---|
| 2105 |
|
---|
[27561] | 2106 | return rc;
|
---|
[27558] | 2107 | }
|
---|
| 2108 |
|
---|
| 2109 |
|
---|
| 2110 | /**
|
---|
| 2111 | * Block driver registration record.
|
---|
| 2112 | */
|
---|
| 2113 | const PDMDRVREG g_DrvDiskIntegrity =
|
---|
| 2114 | {
|
---|
| 2115 | /* u32Version */
|
---|
| 2116 | PDM_DRVREG_VERSION,
|
---|
| 2117 | /* szName */
|
---|
| 2118 | "DiskIntegrity",
|
---|
| 2119 | /* szRCMod */
|
---|
| 2120 | "",
|
---|
| 2121 | /* szR0Mod */
|
---|
| 2122 | "",
|
---|
| 2123 | /* pszDescription */
|
---|
| 2124 | "Disk integrity driver.",
|
---|
| 2125 | /* fFlags */
|
---|
| 2126 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
| 2127 | /* fClass. */
|
---|
| 2128 | PDM_DRVREG_CLASS_BLOCK,
|
---|
| 2129 | /* cMaxInstances */
|
---|
[40282] | 2130 | ~0U,
|
---|
[27558] | 2131 | /* cbInstance */
|
---|
| 2132 | sizeof(DRVDISKINTEGRITY),
|
---|
| 2133 | /* pfnConstruct */
|
---|
| 2134 | drvdiskintConstruct,
|
---|
| 2135 | /* pfnDestruct */
|
---|
| 2136 | drvdiskintDestruct,
|
---|
| 2137 | /* pfnRelocate */
|
---|
| 2138 | NULL,
|
---|
| 2139 | /* pfnIOCtl */
|
---|
| 2140 | NULL,
|
---|
| 2141 | /* pfnPowerOn */
|
---|
| 2142 | NULL,
|
---|
| 2143 | /* pfnReset */
|
---|
| 2144 | NULL,
|
---|
| 2145 | /* pfnSuspend */
|
---|
| 2146 | NULL,
|
---|
| 2147 | /* pfnResume */
|
---|
| 2148 | NULL,
|
---|
| 2149 | /* pfnAttach */
|
---|
| 2150 | NULL,
|
---|
| 2151 | /* pfnDetach */
|
---|
| 2152 | NULL,
|
---|
| 2153 | /* pfnPowerOff */
|
---|
| 2154 | NULL,
|
---|
| 2155 | /* pfnSoftReset */
|
---|
| 2156 | NULL,
|
---|
| 2157 | /* u32EndVersion */
|
---|
| 2158 | PDM_DRVREG_VERSION
|
---|
| 2159 | };
|
---|
| 2160 |
|
---|