1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
|
/* $Id: DrvSCSI.cpp $ */
/** @file
* VBox storage drivers: Generic SCSI command parser and execution driver
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
//#define DEBUG
#define LOG_GROUP LOG_GROUP_DRV_SCSI
#include <VBox/vmm/pdmdrv.h>
#include <VBox/vmm/pdmifs.h>
#include <VBox/vmm/pdmthread.h>
#include <VBox/vscsi.h>
#include <VBox/scsi.h>
#include <iprt/asm.h>
#include <iprt/assert.h>
#include <iprt/mem.h>
#include <iprt/req.h>
#include <iprt/semaphore.h>
#include <iprt/string.h>
#include <iprt/uuid.h>
#include "VBoxDD.h"
/** The maximum number of release log entries per device. */
#define MAX_LOG_REL_ERRORS 1024
/**
* SCSI driver instance data.
*
* @implements PDMISCSICONNECTOR
* @implements PDMIBLOCKASYNCPORT
* @implements PDMIMOUNTNOTIFY
*/
typedef struct DRVSCSI
{
/** Pointer driver instance. */
PPDMDRVINS pDrvIns;
/** Pointer to the attached driver's base interface. */
PPDMIBASE pDrvBase;
/** Pointer to the attached driver's block interface. */
PPDMIBLOCK pDrvBlock;
/** Pointer to the attached driver's async block interface. */
PPDMIBLOCKASYNC pDrvBlockAsync;
/** Pointer to the attached driver's block bios interface. */
PPDMIBLOCKBIOS pDrvBlockBios;
/** Pointer to the attached driver's mount interface. */
PPDMIMOUNT pDrvMount;
/** Pointer to the SCSI port interface of the device above. */
PPDMISCSIPORT pDevScsiPort;
/** pointer to the Led port interface of the dveice above. */
PPDMILEDPORTS pLedPort;
/** The scsi connector interface .*/
PDMISCSICONNECTOR ISCSIConnector;
/** The block port interface. */
PDMIBLOCKPORT IPort;
/** The optional block async port interface. */
PDMIBLOCKASYNCPORT IPortAsync;
/** The mount notify interface. */
PDMIMOUNTNOTIFY IMountNotify;
/** Fallback status LED state for this drive.
* This is used in case the device doesn't has a LED interface. */
PDMLED Led;
/** Pointer to the status LED for this drive. */
PPDMLED pLed;
/** VSCSI device handle. */
VSCSIDEVICE hVScsiDevice;
/** VSCSI LUN handle. */
VSCSILUN hVScsiLun;
/** I/O callbacks. */
VSCSILUNIOCALLBACKS VScsiIoCallbacks;
/** The dedicated I/O thread for the non async approach. */
PPDMTHREAD pAsyncIOThread;
/** Queue for passing the requests to the thread. */
RTREQQUEUE hQueueRequests;
/** Request that we've left pending on wakeup or reset. */
PRTREQ pPendingDummyReq;
/** Indicates whether PDMDrvHlpAsyncNotificationCompleted should be called by
* any of the dummy functions. */
bool volatile fDummySignal;
/** Release statistics: number of bytes written. */
STAMCOUNTER StatBytesWritten;
/** Release statistics: number of bytes read. */
STAMCOUNTER StatBytesRead;
/** Release statistics: Current I/O depth. */
volatile uint32_t StatIoDepth;
/** Errors printed in the release log. */
unsigned cErrors;
/** Mark the drive as having a non-rotational medium (i.e. as a SSD). */
bool fNonRotational;
/** Medium is readonly */
bool fReadonly;
} DRVSCSI, *PDRVSCSI;
/** Converts a pointer to DRVSCSI::ISCSIConnector to a PDRVSCSI. */
#define PDMISCSICONNECTOR_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, ISCSIConnector)) )
/** Converts a pointer to DRVSCSI::IPortAsync to a PDRVSCSI. */
#define PDMIBLOCKASYNCPORT_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IPortAsync)) )
/** Converts a pointer to DRVSCSI::IMountNotify to PDRVSCSI. */
#define PDMIMOUNTNOTIFY_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IMountNotify)) )
/** Converts a pointer to DRVSCSI::IPort to a PDRVSCSI. */
#define PDMIBLOCKPORT_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IPort)) )
static bool drvscsiIsRedoPossible(int rc)
{
if ( rc == VERR_DISK_FULL
|| rc == VERR_FILE_TOO_BIG
|| rc == VERR_BROKEN_PIPE
|| rc == VERR_NET_CONNECTION_REFUSED)
return true;
return false;
}
static int drvscsiProcessRequestOne(PDRVSCSI pThis, VSCSIIOREQ hVScsiIoReq)
{
int rc = VINF_SUCCESS;
VSCSIIOREQTXDIR enmTxDir;
enmTxDir = VSCSIIoReqTxDirGet(hVScsiIoReq);
switch (enmTxDir)
{
case VSCSIIOREQTXDIR_FLUSH:
{
rc = pThis->pDrvBlock->pfnFlush(pThis->pDrvBlock);
if ( RT_FAILURE(rc)
&& pThis->cErrors++ < MAX_LOG_REL_ERRORS)
LogRel(("SCSI#%u: Flush returned rc=%Rrc\n",
pThis->pDrvIns->iInstance, rc));
break;
}
case VSCSIIOREQTXDIR_READ:
case VSCSIIOREQTXDIR_WRITE:
{
uint64_t uOffset = 0;
size_t cbTransfer = 0;
size_t cbSeg = 0;
PCRTSGSEG paSeg = NULL;
unsigned cSeg = 0;
rc = VSCSIIoReqParamsGet(hVScsiIoReq, &uOffset, &cbTransfer, &cSeg, &cbSeg,
&paSeg);
AssertRC(rc);
while (cbTransfer && cSeg)
{
size_t cbProcess = (cbTransfer < paSeg->cbSeg) ? cbTransfer : paSeg->cbSeg;
Log(("%s: uOffset=%llu cbProcess=%u\n", __FUNCTION__, uOffset, cbProcess));
if (enmTxDir == VSCSIIOREQTXDIR_READ)
{
pThis->pLed->Asserted.s.fReading = pThis->pLed->Actual.s.fReading = 1;
rc = pThis->pDrvBlock->pfnRead(pThis->pDrvBlock, uOffset,
paSeg->pvSeg, cbProcess);
pThis->pLed->Actual.s.fReading = 0;
if (RT_FAILURE(rc))
break;
STAM_REL_COUNTER_ADD(&pThis->StatBytesRead, cbProcess);
}
else
{
pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
rc = pThis->pDrvBlock->pfnWrite(pThis->pDrvBlock, uOffset,
paSeg->pvSeg, cbProcess);
pThis->pLed->Actual.s.fWriting = 0;
if (RT_FAILURE(rc))
break;
STAM_REL_COUNTER_ADD(&pThis->StatBytesWritten, cbProcess);
}
/* Go to the next entry. */
uOffset += cbProcess;
cbTransfer -= cbProcess;
paSeg++;
cSeg--;
}
if ( RT_FAILURE(rc)
&& pThis->cErrors++ < MAX_LOG_REL_ERRORS)
LogRel(("SCSI#%u: %s at offset %llu (%u bytes left) returned rc=%Rrc\n",
pThis->pDrvIns->iInstance,
enmTxDir == VSCSIIOREQTXDIR_READ
? "Read"
: "Write",
uOffset,
cbTransfer, rc));
break;
}
case VSCSIIOREQTXDIR_UNMAP:
{
PCRTRANGE paRanges;
unsigned cRanges;
rc = VSCSIIoReqUnmapParamsGet(hVScsiIoReq, &paRanges, &cRanges);
AssertRC(rc);
pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
rc = pThis->pDrvBlock->pfnDiscard(pThis->pDrvBlock, paRanges, cRanges);
pThis->pLed->Actual.s.fWriting = 0;
if ( RT_FAILURE(rc)
&& pThis->cErrors++ < MAX_LOG_REL_ERRORS)
LogRel(("SCSI#%u: Unmap returned rc=%Rrc\n",
pThis->pDrvIns->iInstance, rc));
break;
}
default:
AssertMsgFailed(("Invalid transfer direction %d\n", enmTxDir));
}
if (RT_SUCCESS(rc))
VSCSIIoReqCompleted(hVScsiIoReq, rc, false /* fRedoPossible */);
else
VSCSIIoReqCompleted(hVScsiIoReq, rc, drvscsiIsRedoPossible(rc));
return VINF_SUCCESS;
}
static DECLCALLBACK(int) drvscsiGetSize(VSCSILUN hVScsiLun, void *pvScsiLunUser, uint64_t *pcbSize)
{
PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
*pcbSize = pThis->pDrvBlock->pfnGetSize(pThis->pDrvBlock);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) drvscsiGetSectorSize(VSCSILUN hVScsiLun, void *pvScsiLunUser, uint32_t *pcbSectorSize)
{
PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
*pcbSectorSize = pThis->pDrvBlock->pfnGetSectorSize(pThis->pDrvBlock);
return VINF_SUCCESS;
}
static DECLCALLBACK(int) drvscsiSetLock(VSCSILUN hVScsiLun, void *pvScsiLunUser, bool fLocked)
{
PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
if (fLocked)
pThis->pDrvMount->pfnLock(pThis->pDrvMount);
else
pThis->pDrvMount->pfnUnlock(pThis->pDrvMount);
return VINF_SUCCESS;
}
static int drvscsiTransferCompleteNotify(PPDMIBLOCKASYNCPORT pInterface, void *pvUser, int rc)
{
PDRVSCSI pThis = PDMIBLOCKASYNCPORT_2_DRVSCSI(pInterface);
VSCSIIOREQ hVScsiIoReq = (VSCSIIOREQ)pvUser;
VSCSIIOREQTXDIR enmTxDir = VSCSIIoReqTxDirGet(hVScsiIoReq);
LogFlowFunc(("Request hVScsiIoReq=%#p completed\n", hVScsiIoReq));
if (enmTxDir == VSCSIIOREQTXDIR_READ)
pThis->pLed->Actual.s.fReading = 0;
else if ( enmTxDir == VSCSIIOREQTXDIR_WRITE
|| enmTxDir == VSCSIIOREQTXDIR_UNMAP)
pThis->pLed->Actual.s.fWriting = 0;
else
AssertMsg(enmTxDir == VSCSIIOREQTXDIR_FLUSH, ("Invalid transfer direction %u\n", enmTxDir));
if (RT_SUCCESS(rc))
VSCSIIoReqCompleted(hVScsiIoReq, rc, false /* fRedoPossible */);
else
{
pThis->cErrors++;
if (pThis->cErrors < MAX_LOG_REL_ERRORS)
{
if (enmTxDir == VSCSIIOREQTXDIR_FLUSH)
LogRel(("SCSI#%u: Flush returned rc=%Rrc\n",
pThis->pDrvIns->iInstance, rc));
else if (enmTxDir == VSCSIIOREQTXDIR_UNMAP)
LogRel(("SCSI#%u: Unmap returned rc=%Rrc\n",
pThis->pDrvIns->iInstance, rc));
else
{
uint64_t uOffset = 0;
size_t cbTransfer = 0;
size_t cbSeg = 0;
PCRTSGSEG paSeg = NULL;
unsigned cSeg = 0;
VSCSIIoReqParamsGet(hVScsiIoReq, &uOffset, &cbTransfer,
&cSeg, &cbSeg, &paSeg);
LogRel(("SCSI#%u: %s at offset %llu (%u bytes left) returned rc=%Rrc\n",
pThis->pDrvIns->iInstance,
enmTxDir == VSCSIIOREQTXDIR_READ
? "Read"
: "Write",
uOffset,
cbTransfer, rc));
}
}
VSCSIIoReqCompleted(hVScsiIoReq, rc, drvscsiIsRedoPossible(rc));
}
return VINF_SUCCESS;
}
static DECLCALLBACK(int) drvscsiReqTransferEnqueue(VSCSILUN hVScsiLun,
void *pvScsiLunUser,
VSCSIIOREQ hVScsiIoReq)
{
int rc = VINF_SUCCESS;
PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
if (pThis->pDrvBlockAsync)
{
/* async I/O path. */
VSCSIIOREQTXDIR enmTxDir;
LogFlowFunc(("Enqueuing hVScsiIoReq=%#p\n", hVScsiIoReq));
enmTxDir = VSCSIIoReqTxDirGet(hVScsiIoReq);
switch (enmTxDir)
{
case VSCSIIOREQTXDIR_FLUSH:
{
rc = pThis->pDrvBlockAsync->pfnStartFlush(pThis->pDrvBlockAsync, hVScsiIoReq);
if ( RT_FAILURE(rc)
&& rc != VERR_VD_ASYNC_IO_IN_PROGRESS
&& pThis->cErrors++ < MAX_LOG_REL_ERRORS)
LogRel(("SCSI#%u: Flush returned rc=%Rrc\n",
pThis->pDrvIns->iInstance, rc));
break;
}
case VSCSIIOREQTXDIR_UNMAP:
{
PCRTRANGE paRanges;
unsigned cRanges;
rc = VSCSIIoReqUnmapParamsGet(hVScsiIoReq, &paRanges, &cRanges);
AssertRC(rc);
pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
rc = pThis->pDrvBlockAsync->pfnStartDiscard(pThis->pDrvBlockAsync, paRanges, cRanges, hVScsiIoReq);
if ( RT_FAILURE(rc)
&& rc != VERR_VD_ASYNC_IO_IN_PROGRESS
&& pThis->cErrors++ < MAX_LOG_REL_ERRORS)
LogRel(("SCSI#%u: Discard returned rc=%Rrc\n",
pThis->pDrvIns->iInstance, rc));
break;
}
case VSCSIIOREQTXDIR_READ:
case VSCSIIOREQTXDIR_WRITE:
{
uint64_t uOffset = 0;
size_t cbTransfer = 0;
size_t cbSeg = 0;
PCRTSGSEG paSeg = NULL;
unsigned cSeg = 0;
rc = VSCSIIoReqParamsGet(hVScsiIoReq, &uOffset, &cbTransfer,
&cSeg, &cbSeg, &paSeg);
AssertRC(rc);
if (enmTxDir == VSCSIIOREQTXDIR_READ)
{
pThis->pLed->Asserted.s.fReading = pThis->pLed->Actual.s.fReading = 1;
rc = pThis->pDrvBlockAsync->pfnStartRead(pThis->pDrvBlockAsync, uOffset,
paSeg, cSeg, cbTransfer,
hVScsiIoReq);
STAM_REL_COUNTER_ADD(&pThis->StatBytesRead, cbTransfer);
}
else
{
pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
rc = pThis->pDrvBlockAsync->pfnStartWrite(pThis->pDrvBlockAsync, uOffset,
paSeg, cSeg, cbTransfer,
hVScsiIoReq);
STAM_REL_COUNTER_ADD(&pThis->StatBytesWritten, cbTransfer);
}
if ( RT_FAILURE(rc)
&& rc != VERR_VD_ASYNC_IO_IN_PROGRESS
&& pThis->cErrors++ < MAX_LOG_REL_ERRORS)
LogRel(("SCSI#%u: %s at offset %llu (%u bytes left) returned rc=%Rrc\n",
pThis->pDrvIns->iInstance,
enmTxDir == VSCSIIOREQTXDIR_READ
? "Read"
: "Write",
uOffset,
cbTransfer, rc));
break;
}
default:
AssertMsgFailed(("Invalid transfer direction %u\n", enmTxDir));
}
if (rc == VINF_VD_ASYNC_IO_FINISHED)
{
if (enmTxDir == VSCSIIOREQTXDIR_READ)
pThis->pLed->Actual.s.fReading = 0;
else if (enmTxDir == VSCSIIOREQTXDIR_WRITE)
pThis->pLed->Actual.s.fWriting = 0;
else
AssertMsg(enmTxDir == VSCSIIOREQTXDIR_FLUSH, ("Invalid transfer direction %u\n", enmTxDir));
VSCSIIoReqCompleted(hVScsiIoReq, VINF_SUCCESS, false);
rc = VINF_SUCCESS;
}
else if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS)
rc = VINF_SUCCESS;
else if (RT_FAILURE(rc))
{
if (enmTxDir == VSCSIIOREQTXDIR_READ)
pThis->pLed->Actual.s.fReading = 0;
else if (enmTxDir == VSCSIIOREQTXDIR_WRITE)
pThis->pLed->Actual.s.fWriting = 0;
else
AssertMsg(enmTxDir == VSCSIIOREQTXDIR_FLUSH, ("Invalid transfer direction %u\n", enmTxDir));
VSCSIIoReqCompleted(hVScsiIoReq, rc, drvscsiIsRedoPossible(rc));
rc = VINF_SUCCESS;
}
else
AssertMsgFailed(("Invalid return code rc=%Rrc\n", rc));
}
else
{
/* I/O thread. */
rc = RTReqQueueCallEx(pThis->hQueueRequests, NULL, 0, RTREQFLAGS_NO_WAIT,
(PFNRT)drvscsiProcessRequestOne, 2, pThis, hVScsiIoReq);
}
return rc;
}
static DECLCALLBACK(int) drvscsiGetFeatureFlags(VSCSILUN hVScsiLun,
void *pvScsiLunUser,
uint64_t *pfFeatures)
{
int rc = VINF_SUCCESS;
PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
*pfFeatures = 0;
if ( pThis->pDrvBlock->pfnDiscard
|| ( pThis->pDrvBlockAsync
&& pThis->pDrvBlockAsync->pfnStartDiscard))
*pfFeatures |= VSCSI_LUN_FEATURE_UNMAP;
if (pThis->fNonRotational)
*pfFeatures |= VSCSI_LUN_FEATURE_NON_ROTATIONAL;
if (pThis->fReadonly)
*pfFeatures |= VSCSI_LUN_FEATURE_READONLY;
return VINF_SUCCESS;
}
static void drvscsiVScsiReqCompleted(VSCSIDEVICE hVScsiDevice, void *pVScsiDeviceUser,
void *pVScsiReqUser, int rcScsiCode, bool fRedoPossible,
int rcReq)
{
PDRVSCSI pThis = (PDRVSCSI)pVScsiDeviceUser;
ASMAtomicDecU32(&pThis->StatIoDepth);
pThis->pDevScsiPort->pfnSCSIRequestCompleted(pThis->pDevScsiPort, (PPDMSCSIREQUEST)pVScsiReqUser,
rcScsiCode, fRedoPossible, rcReq);
if (RT_UNLIKELY(pThis->fDummySignal) && !pThis->StatIoDepth)
PDMDrvHlpAsyncNotificationCompleted(pThis->pDrvIns);
}
/**
* Dummy request function used by drvscsiReset to wait for all pending requests
* to complete prior to the device reset.
*
* @param pThis Pointer to the instance data.
* @returns VINF_SUCCESS.
*/
static int drvscsiAsyncIOLoopSyncCallback(PDRVSCSI pThis)
{
if (pThis->fDummySignal)
PDMDrvHlpAsyncNotificationCompleted(pThis->pDrvIns);
return VINF_SUCCESS;
}
/**
* Request function to wakeup the thread.
*
* @param pThis Pointer to the instance data.
* @returns VWRN_STATE_CHANGED.
*/
static int drvscsiAsyncIOLoopWakeupFunc(PDRVSCSI pThis)
{
if (pThis->fDummySignal)
PDMDrvHlpAsyncNotificationCompleted(pThis->pDrvIns);
return VWRN_STATE_CHANGED;
}
/**
* The thread function which processes the requests asynchronously.
*
* @returns VBox status code.
* @param pDrvIns Pointer to the driver instance data.
* @param pThread Pointer to the thread instance data.
*/
static int drvscsiAsyncIOLoop(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
{
int rc = VINF_SUCCESS;
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
LogFlowFunc(("Entering async IO loop.\n"));
if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
return VINF_SUCCESS;
while (pThread->enmState == PDMTHREADSTATE_RUNNING)
{
rc = RTReqQueueProcess(pThis->hQueueRequests, RT_INDEFINITE_WAIT);
AssertMsg(rc == VWRN_STATE_CHANGED, ("Left RTReqProcess and error code is not VWRN_STATE_CHANGED rc=%Rrc\n", rc));
}
return VINF_SUCCESS;
}
/**
* Deals with any pending dummy request
*
* @returns true if no pending dummy request, false if still pending.
* @param pThis The instance data.
* @param cMillies The number of milliseconds to wait for any
* pending request to finish.
*/
static bool drvscsiAsyncIOLoopNoPendingDummy(PDRVSCSI pThis, uint32_t cMillies)
{
if (!pThis->pPendingDummyReq)
return true;
int rc = RTReqWait(pThis->pPendingDummyReq, cMillies);
if (RT_FAILURE(rc))
return false;
RTReqRelease(pThis->pPendingDummyReq);
pThis->pPendingDummyReq = NULL;
return true;
}
static int drvscsiAsyncIOLoopWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
{
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
PRTREQ pReq;
int rc;
AssertMsgReturn(pThis->hQueueRequests != NIL_RTREQQUEUE, ("hQueueRequests is NULL\n"), VERR_INVALID_STATE);
if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 10000 /* 10 sec */))
{
LogRel(("drvscsiAsyncIOLoopWakeup#%u: previous dummy request is still pending\n", pDrvIns->iInstance));
return VERR_TIMEOUT;
}
rc = RTReqQueueCall(pThis->hQueueRequests, &pReq, 10000 /* 10 sec. */, (PFNRT)drvscsiAsyncIOLoopWakeupFunc, 1, pThis);
if (RT_SUCCESS(rc))
RTReqRelease(pReq);
else
{
pThis->pPendingDummyReq = pReq;
LogRel(("drvscsiAsyncIOLoopWakeup#%u: %Rrc pReq=%p\n", pDrvIns->iInstance, rc, pReq));
}
return rc;
}
/* -=-=-=-=- ISCSIConnector -=-=-=-=- */
#ifdef DEBUG
/**
* Dumps a SCSI request structure for debugging purposes.
*
* @returns nothing.
* @param pRequest Pointer to the request to dump.
*/
static void drvscsiDumpScsiRequest(PPDMSCSIREQUEST pRequest)
{
Log(("Dump for pRequest=%#p Command: %s\n", pRequest, SCSICmdText(pRequest->pbCDB[0])));
Log(("cbCDB=%u\n", pRequest->cbCDB));
for (uint32_t i = 0; i < pRequest->cbCDB; i++)
Log(("pbCDB[%u]=%#x\n", i, pRequest->pbCDB[i]));
Log(("cbScatterGather=%u\n", pRequest->cbScatterGather));
Log(("cScatterGatherEntries=%u\n", pRequest->cScatterGatherEntries));
/* Print all scatter gather entries. */
for (uint32_t i = 0; i < pRequest->cScatterGatherEntries; i++)
{
Log(("ScatterGatherEntry[%u].cbSeg=%u\n", i, pRequest->paScatterGatherHead[i].cbSeg));
Log(("ScatterGatherEntry[%u].pvSeg=%#p\n", i, pRequest->paScatterGatherHead[i].pvSeg));
}
Log(("pvUser=%#p\n", pRequest->pvUser));
}
#endif
/** @copydoc PDMISCSICONNECTOR::pfnSCSIRequestSend. */
static DECLCALLBACK(int) drvscsiRequestSend(PPDMISCSICONNECTOR pInterface, PPDMSCSIREQUEST pSCSIRequest)
{
int rc;
PDRVSCSI pThis = PDMISCSICONNECTOR_2_DRVSCSI(pInterface);
VSCSIREQ hVScsiReq;
#ifdef DEBUG
drvscsiDumpScsiRequest(pSCSIRequest);
#endif
rc = VSCSIDeviceReqCreate(pThis->hVScsiDevice, &hVScsiReq,
pSCSIRequest->uLogicalUnit,
pSCSIRequest->pbCDB,
pSCSIRequest->cbCDB,
pSCSIRequest->cbScatterGather,
pSCSIRequest->cScatterGatherEntries,
pSCSIRequest->paScatterGatherHead,
pSCSIRequest->pbSenseBuffer,
pSCSIRequest->cbSenseBuffer,
pSCSIRequest);
if (RT_FAILURE(rc))
return rc;
ASMAtomicIncU32(&pThis->StatIoDepth);
rc = VSCSIDeviceReqEnqueue(pThis->hVScsiDevice, hVScsiReq);
return rc;
}
/* -=-=-=-=- IBase -=-=-=-=- */
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
static DECLCALLBACK(void *) drvscsiQueryInterface(PPDMIBASE pInterface, const char *pszIID)
{
PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNT, pThis->pDrvMount);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKBIOS, pThis->pDrvBlockBios);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMISCSICONNECTOR, &pThis->ISCSIConnector);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pThis->IPort);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pThis->IMountNotify);
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKASYNCPORT, &pThis->IPortAsync);
return NULL;
}
static DECLCALLBACK(int) drvscsiQueryDeviceLocation(PPDMIBLOCKPORT pInterface, const char **ppcszController,
uint32_t *piInstance, uint32_t *piLUN)
{
PDRVSCSI pThis = PDMIBLOCKPORT_2_DRVSCSI(pInterface);
return pThis->pDevScsiPort->pfnQueryDeviceLocation(pThis->pDevScsiPort, ppcszController,
piInstance, piLUN);
}
/**
* Called when media is mounted.
*
* @param pInterface Pointer to the interface structure containing the called function pointer.
*/
static DECLCALLBACK(void) drvscsiMountNotify(PPDMIMOUNTNOTIFY pInterface)
{
PDRVSCSI pThis = PDMIMOUNTNOTIFY_2_DRVSCSI(pInterface);
LogFlowFunc(("mounting LUN#%p\n", pThis->hVScsiLun));
/* Ignore the call if we're called while being attached. */
if (!pThis->pDrvBlock)
return;
/* Let the LUN know that a medium was mounted. */
VSCSILunMountNotify(pThis->hVScsiLun);
}
/**
* Called when media is unmounted
*
* @param pInterface Pointer to the interface structure containing the called function pointer.
*/
static DECLCALLBACK(void) drvscsiUnmountNotify(PPDMIMOUNTNOTIFY pInterface)
{
PDRVSCSI pThis = PDMIMOUNTNOTIFY_2_DRVSCSI(pInterface);
LogFlowFunc(("unmounting LUN#%p\n", pThis->hVScsiLun));
/* Let the LUN know that the medium was unmounted. */
VSCSILunUnmountNotify(pThis->hVScsiLun);
}
/**
* Worker for drvscsiReset, drvscsiSuspend and drvscsiPowerOff.
*
* @param pDrvIns The driver instance.
* @param pfnAsyncNotify The async callback.
*/
static void drvscsiR3ResetOrSuspendOrPowerOff(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
{
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
if (!pThis->pDrvBlockAsync)
{
if (pThis->hQueueRequests != NIL_RTREQQUEUE)
return;
ASMAtomicWriteBool(&pThis->fDummySignal, true);
if (drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
{
if (!RTReqQueueIsBusy(pThis->hQueueRequests))
{
ASMAtomicWriteBool(&pThis->fDummySignal, false);
return;
}
PRTREQ pReq;
int rc = RTReqQueueCall(pThis->hQueueRequests, &pReq, 0 /*ms*/, (PFNRT)drvscsiAsyncIOLoopSyncCallback, 1, pThis);
if (RT_SUCCESS(rc))
{
ASMAtomicWriteBool(&pThis->fDummySignal, false);
RTReqRelease(pReq);
return;
}
pThis->pPendingDummyReq = pReq;
}
}
else
{
if (pThis->StatIoDepth > 0)
{
ASMAtomicWriteBool(&pThis->fDummySignal, true);
}
return;
}
PDMDrvHlpSetAsyncNotification(pDrvIns, pfnAsyncNotify);
}
/**
* Callback employed by drvscsiSuspend and drvscsiPowerOff.
*
* @returns true if we've quiesced, false if we're still working.
* @param pDrvIns The driver instance.
*/
static DECLCALLBACK(bool) drvscsiIsAsyncSuspendOrPowerOffDone(PPDMDRVINS pDrvIns)
{
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
if (pThis->pDrvBlockAsync)
{
if (pThis->StatIoDepth > 0)
return false;
else
return true;
}
else
{
if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
return false;
ASMAtomicWriteBool(&pThis->fDummySignal, false);
PDMR3ThreadSuspend(pThis->pAsyncIOThread);
return true;
}
}
/**
* @copydoc FNPDMDRVPOWEROFF
*/
static DECLCALLBACK(void) drvscsiPowerOff(PPDMDRVINS pDrvIns)
{
drvscsiR3ResetOrSuspendOrPowerOff(pDrvIns, drvscsiIsAsyncSuspendOrPowerOffDone);
}
/**
* @copydoc FNPDMDRVSUSPEND
*/
static DECLCALLBACK(void) drvscsiSuspend(PPDMDRVINS pDrvIns)
{
drvscsiR3ResetOrSuspendOrPowerOff(pDrvIns, drvscsiIsAsyncSuspendOrPowerOffDone);
}
/**
* Callback employed by drvscsiReset.
*
* @returns true if we've quiesced, false if we're still working.
* @param pDrvIns The driver instance.
*/
static DECLCALLBACK(bool) drvscsiIsAsyncResetDone(PPDMDRVINS pDrvIns)
{
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
if (pThis->pDrvBlockAsync)
{
if (pThis->StatIoDepth > 0)
return false;
else
return true;
}
else
{
if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/))
return false;
ASMAtomicWriteBool(&pThis->fDummySignal, false);
return true;
}
}
/**
* @copydoc FNPDMDRVRESET
*/
static DECLCALLBACK(void) drvscsiReset(PPDMDRVINS pDrvIns)
{
drvscsiR3ResetOrSuspendOrPowerOff(pDrvIns, drvscsiIsAsyncResetDone);
}
/**
* Destruct a driver instance.
*
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
* resources can be freed correctly.
*
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) drvscsiDestruct(PPDMDRVINS pDrvIns)
{
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
if (pThis->hQueueRequests != NIL_RTREQQUEUE)
{
if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 100 /*ms*/))
LogRel(("drvscsiDestruct#%u: previous dummy request is still pending\n", pDrvIns->iInstance));
int rc = RTReqQueueDestroy(pThis->hQueueRequests);
AssertMsgRC(rc, ("Failed to destroy queue rc=%Rrc\n", rc));
pThis->hQueueRequests = NIL_RTREQQUEUE;
}
/* Free the VSCSI device and LUN handle. */
if (pThis->hVScsiDevice)
{
VSCSILUN hVScsiLun;
int rc = VSCSIDeviceLunDetach(pThis->hVScsiDevice, 0, &hVScsiLun);
AssertRC(rc);
Assert(hVScsiLun == pThis->hVScsiLun);
rc = VSCSILunDestroy(hVScsiLun);
AssertRC(rc);
rc = VSCSIDeviceDestroy(pThis->hVScsiDevice);
AssertRC(rc);
pThis->hVScsiDevice = NULL;
pThis->hVScsiLun = NULL;
}
}
/**
* Construct a block driver instance.
*
* @copydoc FNPDMDRVCONSTRUCT
*/
static DECLCALLBACK(int) drvscsiConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
{
int rc = VINF_SUCCESS;
PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
LogFlowFunc(("pDrvIns=%#p pCfg=%#p\n", pDrvIns, pCfg));
PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
/*
* Initialize the instance data.
*/
pThis->pDrvIns = pDrvIns;
pThis->ISCSIConnector.pfnSCSIRequestSend = drvscsiRequestSend;
pDrvIns->IBase.pfnQueryInterface = drvscsiQueryInterface;
pThis->IMountNotify.pfnMountNotify = drvscsiMountNotify;
pThis->IMountNotify.pfnUnmountNotify = drvscsiUnmountNotify;
pThis->IPort.pfnQueryDeviceLocation = drvscsiQueryDeviceLocation;
pThis->IPortAsync.pfnTransferCompleteNotify = drvscsiTransferCompleteNotify;
pThis->hQueueRequests = NIL_RTREQQUEUE;
/* Query the SCSI port interface above. */
pThis->pDevScsiPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMISCSIPORT);
AssertMsgReturn(pThis->pDevScsiPort, ("Missing SCSI port interface above\n"), VERR_PDM_MISSING_INTERFACE);
/* Query the optional LED interface above. */
pThis->pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
if (pThis->pLedPort != NULL)
{
/* Get The Led. */
rc = pThis->pLedPort->pfnQueryStatusLed(pThis->pLedPort, 0, &pThis->pLed);
if (RT_FAILURE(rc))
pThis->pLed = &pThis->Led;
}
else
pThis->pLed = &pThis->Led;
/*
* Validate and read configuration.
*/
if (!CFGMR3AreValuesValid(pCfg, "NonRotationalMedium\0Readonly\0"))
return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
N_("SCSI configuration error: unknown option specified"));
rc = CFGMR3QueryBoolDef(pCfg, "NonRotationalMedium", &pThis->fNonRotational, false);
if (RT_FAILURE(rc))
return PDMDRV_SET_ERROR(pDrvIns, rc,
N_("SCSI configuration error: failed to read \"NonRotationalMedium\" as boolean"));
rc = CFGMR3QueryBoolDef(pCfg, "Readonly", &pThis->fReadonly, false);
if (RT_FAILURE(rc))
return PDMDRV_SET_ERROR(pDrvIns, rc,
N_("SCSI configuration error: failed to read \"Readonly\" as boolean"));
/*
* Try attach driver below and query it's block interface.
*/
rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pThis->pDrvBase);
AssertMsgReturn(RT_SUCCESS(rc), ("Attaching driver below failed rc=%Rrc\n", rc), rc);
/*
* Query the block and blockbios interfaces.
*/
pThis->pDrvBlock = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCK);
if (!pThis->pDrvBlock)
{
AssertMsgFailed(("Configuration error: No block interface!\n"));
return VERR_PDM_MISSING_INTERFACE;
}
pThis->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCKBIOS);
if (!pThis->pDrvBlockBios)
{
AssertMsgFailed(("Configuration error: No block BIOS interface!\n"));
return VERR_PDM_MISSING_INTERFACE;
}
pThis->pDrvMount = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIMOUNT);
/* Try to get the optional async block interface. */
pThis->pDrvBlockAsync = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCKASYNC);
PDMBLOCKTYPE enmType = pThis->pDrvBlock->pfnGetType(pThis->pDrvBlock);
VSCSILUNTYPE enmLunType;
switch (enmType)
{
case PDMBLOCKTYPE_HARD_DISK:
enmLunType = VSCSILUNTYPE_SBC;
break;
case PDMBLOCKTYPE_CDROM:
case PDMBLOCKTYPE_DVD:
enmLunType = VSCSILUNTYPE_MMC;
break;
default:
return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_UNSUPPORTED_BLOCK_TYPE, RT_SRC_POS,
N_("Only hard disks and CD/DVD-ROMs are currently supported as SCSI devices (enmType=%d)"),
enmType);
}
if ( ( enmType == PDMBLOCKTYPE_DVD
|| enmType == PDMBLOCKTYPE_CDROM)
&& !pThis->pDrvMount)
{
AssertMsgFailed(("Internal error: cdrom without a mountable interface\n"));
return VERR_INTERNAL_ERROR;
}
/* Create VSCSI device and LUN. */
pThis->VScsiIoCallbacks.pfnVScsiLunMediumGetSize = drvscsiGetSize;
pThis->VScsiIoCallbacks.pfnVScsiLunMediumGetSectorSize = drvscsiGetSectorSize;
pThis->VScsiIoCallbacks.pfnVScsiLunReqTransferEnqueue = drvscsiReqTransferEnqueue;
pThis->VScsiIoCallbacks.pfnVScsiLunGetFeatureFlags = drvscsiGetFeatureFlags;
pThis->VScsiIoCallbacks.pfnVScsiLunMediumSetLock = drvscsiSetLock;
rc = VSCSIDeviceCreate(&pThis->hVScsiDevice, drvscsiVScsiReqCompleted, pThis);
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create VSCSI device rc=%Rrc\n"), rc);
rc = VSCSILunCreate(&pThis->hVScsiLun, enmLunType, &pThis->VScsiIoCallbacks,
pThis);
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create VSCSI LUN rc=%Rrc\n"), rc);
rc = VSCSIDeviceLunAttach(pThis->hVScsiDevice, pThis->hVScsiLun, 0);
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to attached the LUN to the SCSI device\n"), rc);
//@todo: This is a very hacky way of telling the LUN whether a medium was mounted.
// The mount/unmount interface doesn't work in a very sensible manner!
if (pThis->pDrvMount)
{
if (pThis->pDrvBlock->pfnGetSize(pThis->pDrvBlock))
{
rc = VINF_SUCCESS; VSCSILunMountNotify(pThis->hVScsiLun);
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to notify the LUN of media being mounted\n"), rc);
}
else
{
rc = VINF_SUCCESS; VSCSILunUnmountNotify(pThis->hVScsiLun);
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to notify the LUN of media being unmounted\n"), rc);
}
}
/* Register statistics counter. */
/** @todo aeichner: Find a way to put the instance number of the attached
* controller device when we support more than one controller of the same type.
* At the moment we have the 0 hardcoded. */
PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,
"Amount of data read.", "/Devices/SCSI0/%d/ReadBytes", pDrvIns->iInstance);
PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,
"Amount of data written.", "/Devices/SCSI0/%d/WrittenBytes", pDrvIns->iInstance);
pThis->StatIoDepth = 0;
PDMDrvHlpSTAMRegisterF(pDrvIns, (void *)&pThis->StatIoDepth, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
"Number of active tasks.", "/Devices/SCSI0/%d/IoDepth", pDrvIns->iInstance);
if (!pThis->pDrvBlockAsync)
{
/* Create request queue. */
rc = RTReqQueueCreate(&pThis->hQueueRequests);
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create request queue rc=%Rrc\n"), rc);
/* Create I/O thread. */
rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pAsyncIOThread, pThis, drvscsiAsyncIOLoop,
drvscsiAsyncIOLoopWakeup, 0, RTTHREADTYPE_IO, "SCSI async IO");
AssertMsgReturn(RT_SUCCESS(rc), ("Failed to create async I/O thread rc=%Rrc\n"), rc);
LogRel(("SCSI#%d: using normal I/O\n", pDrvIns->iInstance));
}
else
LogRel(("SCSI#%d: using async I/O\n", pDrvIns->iInstance));
if ( pThis->pDrvBlock->pfnDiscard
|| ( pThis->pDrvBlockAsync
&& pThis->pDrvBlockAsync->pfnStartDiscard))
LogRel(("SCSI#%d: Enabled UNMAP support\n"));
return VINF_SUCCESS;
}
/**
* SCSI driver registration record.
*/
const PDMDRVREG g_DrvSCSI =
{
/* u32Version */
PDM_DRVREG_VERSION,
/* szName */
"SCSI",
/* szRCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"Generic SCSI driver.",
/* fFlags */
PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
/* fClass. */
PDM_DRVREG_CLASS_SCSI,
/* cMaxInstances */
~0U,
/* cbInstance */
sizeof(DRVSCSI),
/* pfnConstruct */
drvscsiConstruct,
/* pfnDestruct */
drvscsiDestruct,
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
drvscsiReset,
/* pfnSuspend */
drvscsiSuspend,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
drvscsiPowerOff,
/* pfnSoftReset */
NULL,
/* u32EndVersion */
PDM_DRVREG_VERSION
};
|