VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunSbc.cpp@ 38878

Last change on this file since 38878 was 38878, checked in by vboxsync, 13 years ago

PDM,Devices,Drivers: Add async discard API and make us of it

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.1 KB
Line 
1/* $Id: VSCSILunSbc.cpp 38878 2011-09-27 09:07:07Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: SBC LUN implementation (hard disks)
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_VSCSI
22#include <VBox/log.h>
23#include <VBox/err.h>
24#include <VBox/types.h>
25#include <VBox/vscsi.h>
26#include <iprt/cdefs.h>
27#include <iprt/asm.h>
28#include <iprt/assert.h>
29#include <iprt/mem.h>
30#include <iprt/string.h>
31
32#include "VSCSIInternal.h"
33
34/** Maximum of amount of LBAs to unmap with one command. */
35#define VSCSI_UNMAP_LBAS_MAX ((10*_1M) / 512)
36
37/**
38 * SBC LUN instance
39 */
40typedef struct VSCSILUNSBC
41{
42 /** Core LUN structure */
43 VSCSILUNINT Core;
44 /** Size of the virtual disk. */
45 uint64_t cSectors;
46 /** VPD page pool. */
47 VSCSIVPDPOOL VpdPagePool;
48} VSCSILUNSBC;
49/** Pointer to a SBC LUN instance */
50typedef VSCSILUNSBC *PVSCSILUNSBC;
51
52static int vscsiLunSbcInit(PVSCSILUNINT pVScsiLun)
53{
54 PVSCSILUNSBC pVScsiLunSbc = (PVSCSILUNSBC)pVScsiLun;
55 uint64_t cbDisk = 0;
56 int rc = VINF_SUCCESS;
57 int cVpdPages = 0;
58
59 rc = vscsiLunMediumGetSize(pVScsiLun, &cbDisk);
60 if (RT_SUCCESS(rc))
61 pVScsiLunSbc->cSectors = cbDisk / 512; /* Fixed sector size */
62
63 if (RT_SUCCESS(rc))
64 rc = vscsiVpdPagePoolInit(&pVScsiLunSbc->VpdPagePool);
65
66 /* Create device identification page - mandatory. */
67 if (RT_SUCCESS(rc))
68 {
69 PVSCSIVPDPAGEDEVID pDevIdPage;
70
71 rc = vscsiVpdPagePoolAllocNewPage(&pVScsiLunSbc->VpdPagePool, VSCSI_VPD_DEVID_NUMBER,
72 VSCSI_VPD_DEVID_SIZE, (uint8_t **)&pDevIdPage);
73 if (RT_SUCCESS(rc))
74 {
75 /** @todo: Not conforming to the SPC spec but Solaris needs at least a stub to work. */
76 pDevIdPage->u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
77 pDevIdPage->u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
78 pDevIdPage->u16PageLength = RT_H2BE_U16(0x0);
79 cVpdPages++;
80 }
81 }
82
83 if ( RT_SUCCESS(rc)
84 && (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_UNMAP))
85 {
86 PVSCSIVPDPAGEBLOCKLIMITS pBlkPage;
87 PVSCSIVPDPAGEBLOCKPROV pBlkProvPage;
88
89 /* Create the page and fill it. */
90 rc = vscsiVpdPagePoolAllocNewPage(&pVScsiLunSbc->VpdPagePool, VSCSI_VPD_BLOCK_LIMITS_NUMBER,
91 VSCSI_VPD_BLOCK_LIMITS_SIZE, (uint8_t **)&pBlkPage);
92 if (RT_SUCCESS(rc))
93 {
94 pBlkPage->u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
95 pBlkPage->u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
96 pBlkPage->u16PageLength = RT_H2BE_U16(0x3c);
97 pBlkPage->u8MaxCmpWriteLength = 0;
98 pBlkPage->u16OptTrfLengthGran = 0;
99 pBlkPage->u32MaxTrfLength = 0;
100 pBlkPage->u32OptTrfLength = 0;
101 pBlkPage->u32MaxPreXdTrfLength = 0;
102 pBlkPage->u32MaxUnmapLbaCount = RT_H2BE_U32(VSCSI_UNMAP_LBAS_MAX);
103 pBlkPage->u32MaxUnmapBlkDescCount = UINT32_C(0xffffffff);
104 pBlkPage->u32OptUnmapGranularity = 0;
105 pBlkPage->u32UnmapGranularityAlignment = 0;
106 cVpdPages++;
107 }
108
109 if (RT_SUCCESS(rc))
110 {
111 rc = vscsiVpdPagePoolAllocNewPage(&pVScsiLunSbc->VpdPagePool, VSCSI_VPD_BLOCK_PROV_NUMBER,
112 VSCSI_VPD_BLOCK_PROV_SIZE, (uint8_t **)&pBlkProvPage);
113 if (RT_SUCCESS(rc))
114 {
115 pBlkProvPage->u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
116 pBlkProvPage->u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
117 pBlkProvPage->u16PageLength = RT_H2BE_U16(0x4);
118 pBlkProvPage->u8ThresholdExponent = 1;
119 pBlkProvPage->fLBPU = true;
120 cVpdPages++;
121 }
122 }
123 }
124
125 if ( RT_SUCCESS(rc)
126 && (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_NON_ROTATIONAL))
127 {
128 PVSCSIVPDPAGEBLOCKCHARACTERISTICS pBlkPage;
129
130 /* Create the page and fill it. */
131 rc = vscsiVpdPagePoolAllocNewPage(&pVScsiLunSbc->VpdPagePool, VSCSI_VPD_BLOCK_CHARACTERISTICS_NUMBER,
132 VSCSI_VPD_BLOCK_CHARACTERISTICS_SIZE, (uint8_t **)&pBlkPage);
133 if (RT_SUCCESS(rc))
134 {
135 pBlkPage->u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
136 pBlkPage->u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
137 pBlkPage->u16PageLength = RT_H2BE_U16(0x3c);
138 pBlkPage->u16MediumRotationRate = RT_H2BE_U16(VSCSI_VPD_BLOCK_CHARACT_MEDIUM_ROTATION_RATE_NON_ROTATING);
139 cVpdPages++;
140 }
141 }
142
143 if ( RT_SUCCESS(rc)
144 && cVpdPages)
145 {
146 PVSCSIVPDPAGESUPPORTEDPAGES pVpdPages;
147
148 rc = vscsiVpdPagePoolAllocNewPage(&pVScsiLunSbc->VpdPagePool, VSCSI_VPD_SUPPORTED_PAGES_NUMBER,
149 VSCSI_VPD_SUPPORTED_PAGES_SIZE + cVpdPages, (uint8_t **)&pVpdPages);
150 if (RT_SUCCESS(rc))
151 {
152 unsigned idxVpdPage = 0;
153 pVpdPages->u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
154 pVpdPages->u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
155 pVpdPages->u16PageLength = RT_H2BE_U16(cVpdPages);
156
157 pVpdPages->abVpdPages[idxVpdPage++] = VSCSI_VPD_DEVID_NUMBER;
158
159 if (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_UNMAP)
160 {
161 pVpdPages->abVpdPages[idxVpdPage++] = VSCSI_VPD_BLOCK_LIMITS_NUMBER;
162 pVpdPages->abVpdPages[idxVpdPage++] = VSCSI_VPD_BLOCK_PROV_NUMBER;
163 }
164
165 if (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_NON_ROTATIONAL)
166 pVpdPages->abVpdPages[idxVpdPage++] = VSCSI_VPD_BLOCK_CHARACTERISTICS_NUMBER;
167 }
168 }
169
170 return rc;
171}
172
173static int vscsiLunSbcDestroy(PVSCSILUNINT pVScsiLun)
174{
175 PVSCSILUNSBC pVScsiLunSbc = (PVSCSILUNSBC)pVScsiLun;
176
177 vscsiVpdPagePoolDestroy(&pVScsiLunSbc->VpdPagePool);
178
179 return VINF_SUCCESS;
180}
181
182static int vscsiLunSbcReqProcess(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq)
183{
184 PVSCSILUNSBC pVScsiLunSbc = (PVSCSILUNSBC)pVScsiLun;
185 int rc = VINF_SUCCESS;
186 int rcReq = SCSI_STATUS_OK;
187 uint64_t uLbaStart = 0;
188 uint32_t cSectorTransfer = 0;
189 VSCSIIOREQTXDIR enmTxDir = VSCSIIOREQTXDIR_INVALID;
190
191 switch(pVScsiReq->pbCDB[0])
192 {
193 case SCSI_INQUIRY:
194 {
195 /* Check for EVPD bit. */
196 if (pVScsiReq->pbCDB[1] & 0x1)
197 {
198 rc = vscsiVpdPagePoolQueryPage(&pVScsiLunSbc->VpdPagePool, pVScsiReq, pVScsiReq->pbCDB[2]);
199 if (RT_UNLIKELY(rc == VERR_NOT_FOUND))
200 {
201 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST,
202 SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0x00);
203 rc = VINF_SUCCESS;
204 }
205 else
206 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
207 }
208 else if (pVScsiReq->pbCDB[2] != 0) /* A non zero page code is an error. */
209 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST,
210 SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0x00);
211 else
212 {
213 SCSIINQUIRYDATA ScsiInquiryReply;
214
215 memset(&ScsiInquiryReply, 0, sizeof(ScsiInquiryReply));
216
217 ScsiInquiryReply.cbAdditional = 31;
218 ScsiInquiryReply.u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS;
219 ScsiInquiryReply.u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_CONNECTED;
220 ScsiInquiryReply.u3AnsiVersion = 0x05; /* SPC-4 compliant */
221 ScsiInquiryReply.fCmdQue = 1; /* Command queuing supported. */
222 ScsiInquiryReply.fWBus16 = 1;
223 vscsiPadStr(ScsiInquiryReply.achVendorId, "VBOX", 8);
224 vscsiPadStr(ScsiInquiryReply.achProductId, "HARDDISK", 16);
225 vscsiPadStr(ScsiInquiryReply.achProductLevel, "1.0", 4);
226
227 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, (uint8_t *)&ScsiInquiryReply, sizeof(SCSIINQUIRYDATA));
228 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
229 }
230 break;
231 }
232 case SCSI_READ_CAPACITY:
233 {
234 uint8_t aReply[8];
235 memset(aReply, 0, sizeof(aReply));
236
237 /*
238 * If sector size exceeds the maximum value that is
239 * able to be stored in 4 bytes return 0xffffffff in this field
240 */
241 if (pVScsiLunSbc->cSectors > UINT32_C(0xffffffff))
242 vscsiH2BEU32(aReply, UINT32_C(0xffffffff));
243 else
244 vscsiH2BEU32(aReply, pVScsiLunSbc->cSectors - 1);
245 vscsiH2BEU32(&aReply[4], 512);
246 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, aReply, sizeof(aReply));
247 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
248 break;
249 }
250 case SCSI_MODE_SENSE_6:
251 {
252 uint8_t uModePage = pVScsiReq->pbCDB[2] & 0x3f;
253 uint8_t aReply[24];
254 uint8_t *pu8ReplyPos;
255
256 memset(aReply, 0, sizeof(aReply));
257 aReply[0] = 4; /* Reply length 4. */
258 aReply[1] = 0; /* Default media type. */
259 aReply[2] = RT_BIT(4); /* Caching supported. */
260 aReply[3] = 0; /* Block descriptor length. */
261
262 pu8ReplyPos = aReply + 4;
263
264 if ((uModePage == 0x08) || (uModePage == 0x3f))
265 {
266 memset(pu8ReplyPos, 0, 20);
267 *pu8ReplyPos++ = 0x08; /* Page code. */
268 *pu8ReplyPos++ = 0x12; /* Size of the page. */
269 *pu8ReplyPos++ = 0x4; /* Write cache enabled. */
270 }
271
272 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, aReply, sizeof(aReply));
273 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
274 break;
275 }
276 case SCSI_READ_6:
277 {
278 enmTxDir = VSCSIIOREQTXDIR_READ;
279 uLbaStart = ((uint64_t) pVScsiReq->pbCDB[3]
280 | (pVScsiReq->pbCDB[2] << 8)
281 | ((pVScsiReq->pbCDB[1] & 0x1f) << 16));
282 cSectorTransfer = pVScsiReq->pbCDB[4];
283 break;
284 }
285 case SCSI_READ_10:
286 {
287 enmTxDir = VSCSIIOREQTXDIR_READ;
288 uLbaStart = vscsiBE2HU32(&pVScsiReq->pbCDB[2]);
289 cSectorTransfer = vscsiBE2HU16(&pVScsiReq->pbCDB[7]);
290 break;
291 }
292 case SCSI_READ_12:
293 {
294 enmTxDir = VSCSIIOREQTXDIR_READ;
295 uLbaStart = vscsiBE2HU32(&pVScsiReq->pbCDB[2]);
296 cSectorTransfer = vscsiBE2HU32(&pVScsiReq->pbCDB[6]);
297 break;
298 }
299 case SCSI_READ_16:
300 {
301 enmTxDir = VSCSIIOREQTXDIR_READ;
302 uLbaStart = vscsiBE2HU64(&pVScsiReq->pbCDB[2]);
303 cSectorTransfer = vscsiBE2HU32(&pVScsiReq->pbCDB[10]);
304 break;
305 }
306 case SCSI_WRITE_6:
307 {
308 enmTxDir = VSCSIIOREQTXDIR_WRITE;
309 uLbaStart = ((uint64_t) pVScsiReq->pbCDB[3]
310 | (pVScsiReq->pbCDB[2] << 8)
311 | ((pVScsiReq->pbCDB[1] & 0x1f) << 16));
312 cSectorTransfer = pVScsiReq->pbCDB[4];
313 break;
314 }
315 case SCSI_WRITE_10:
316 {
317 enmTxDir = VSCSIIOREQTXDIR_WRITE;
318 uLbaStart = vscsiBE2HU32(&pVScsiReq->pbCDB[2]);
319 cSectorTransfer = vscsiBE2HU16(&pVScsiReq->pbCDB[7]);
320 break;
321 }
322 case SCSI_WRITE_12:
323 {
324 enmTxDir = VSCSIIOREQTXDIR_WRITE;
325 uLbaStart = vscsiBE2HU32(&pVScsiReq->pbCDB[2]);
326 cSectorTransfer = vscsiBE2HU32(&pVScsiReq->pbCDB[6]);
327 break;
328 }
329 case SCSI_WRITE_16:
330 {
331 enmTxDir = VSCSIIOREQTXDIR_WRITE;
332 uLbaStart = vscsiBE2HU64(&pVScsiReq->pbCDB[2]);
333 cSectorTransfer = vscsiBE2HU32(&pVScsiReq->pbCDB[10]);
334 break;
335 }
336 case SCSI_SYNCHRONIZE_CACHE:
337 {
338 break; /* Handled below */
339 }
340 case SCSI_READ_BUFFER:
341 {
342 uint8_t uDataMode = pVScsiReq->pbCDB[1] & 0x1f;
343
344 switch (uDataMode)
345 {
346 case 0x00:
347 case 0x01:
348 case 0x02:
349 case 0x03:
350 case 0x0a:
351 break;
352 case 0x0b:
353 {
354 uint8_t aReply[4];
355
356 /* We do not implement an echo buffer. */
357 memset(aReply, 0, sizeof(aReply));
358
359 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, aReply, sizeof(aReply));
360 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
361 break;
362 }
363 case 0x1a:
364 case 0x1c:
365 break;
366 default:
367 AssertMsgFailed(("Invalid data mode\n"));
368 }
369 break;
370 }
371 case SCSI_VERIFY_10:
372 case SCSI_START_STOP_UNIT:
373 {
374 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
375 break;
376 }
377 case SCSI_LOG_SENSE:
378 {
379 uint16_t cbMax = vscsiBE2HU16(&pVScsiReq->pbCDB[7]);
380 uint8_t uPageCode = pVScsiReq->pbCDB[2] & 0x3f;
381 uint8_t uSubPageCode = pVScsiReq->pbCDB[3];
382
383 switch (uPageCode)
384 {
385 case 0x00:
386 {
387 if (uSubPageCode == 0)
388 {
389 uint8_t aReply[4];
390
391 aReply[0] = 0;
392 aReply[1] = 0;
393 aReply[2] = 0;
394 aReply[3] = 0;
395 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, aReply, sizeof(aReply));
396 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
397 break;
398 }
399 }
400 default:
401 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0x00);
402 }
403 break;
404 }
405 case SCSI_SERVICE_ACTION_IN_16:
406 {
407 switch (pVScsiReq->pbCDB[1] & 0x1f)
408 {
409 case SCSI_SVC_ACTION_IN_READ_CAPACITY_16:
410 {
411 uint8_t aReply[32];
412
413 memset(aReply, 0, sizeof(aReply));
414 vscsiH2BEU64(aReply, pVScsiLunSbc->cSectors - 1);
415 vscsiH2BEU32(&aReply[8], 512);
416 if (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_UNMAP)
417 aReply[14] = 0x80; /* LPME enabled */
418 /* Leave the rest 0 */
419
420 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, aReply, sizeof(aReply));
421 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
422 break;
423 }
424 default:
425 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0x00); /* Don't know if this is correct */
426 }
427 break;
428 }
429 case SCSI_UNMAP:
430 {
431 if (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_UNMAP)
432 {
433 uint8_t abHdr[8];
434 size_t cbCopied;
435 size_t cbList = vscsiBE2HU16(&pVScsiReq->pbCDB[7]);
436
437 /* Copy the header. */
438 cbCopied = RTSgBufCopyToBuf(&pVScsiReq->SgBuf, &abHdr[0], sizeof(abHdr));
439
440 /* Using the anchor bit is not supported. */
441 if ( !(pVScsiReq->pbCDB[1] & 0x01)
442 && cbCopied == sizeof(abHdr)
443 && cbList >= 8)
444 {
445 size_t cBlkDesc = vscsiBE2HU16(&abHdr[2]) / 16;
446
447 if (cBlkDesc)
448 {
449 PRTRANGE paRanges;
450
451 paRanges = (PRTRANGE)RTMemAllocZ(cBlkDesc * sizeof(RTRANGE));
452 if (paRanges)
453 {
454 for (unsigned i = 0; i < cBlkDesc; i++)
455 {
456 uint8_t abBlkDesc[16];
457
458 cbCopied = RTSgBufCopyToBuf(&pVScsiReq->SgBuf, &abBlkDesc[0], sizeof(abBlkDesc));
459 if (RT_UNLIKELY(cbCopied != sizeof(abBlkDesc)))
460 {
461 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0x00);
462 break;
463 }
464
465 paRanges[i].offStart = vscsiBE2HU64(&abBlkDesc[0]) * 512;
466 paRanges[i].cbRange = vscsiBE2HU32(&abBlkDesc[8]) * 512;
467 }
468
469 if (rcReq == SCSI_STATUS_OK)
470 rc = vscsiIoReqUnmapEnqueue(pVScsiLun, pVScsiReq, paRanges, cBlkDesc);
471 }
472 else /* Out of memory. */
473 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_HARDWARE_ERROR, SCSI_ASC_SYSTEM_RESOURCE_FAILURE,
474 SCSI_ASCQ_SYSTEM_BUFFER_FULL);
475 }
476 else /* No block descriptors is not an error condition. */
477 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
478 }
479 else /* Invalid CDB. */
480 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET, 0x00);
481 }
482 else
483 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_ILLEGAL_OPCODE, 0x00);
484
485 break;
486 }
487 default:
488 //AssertMsgFailed(("Command %#x [%s] not implemented\n", pRequest->pbCDB[0], SCSICmdText(pRequest->pbCDB[0])));
489 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_ILLEGAL_OPCODE, 0x00);
490 }
491
492 if (enmTxDir != VSCSIIOREQTXDIR_INVALID)
493 {
494 LogFlow(("%s: uLbaStart=%llu cSectorTransfer=%u\n",
495 __FUNCTION__, uLbaStart, cSectorTransfer));
496
497 if (RT_UNLIKELY(uLbaStart + cSectorTransfer > pVScsiLunSbc->cSectors))
498 {
499 rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_LOGICAL_BLOCK_OOR, 0x00);
500 vscsiDeviceReqComplete(pVScsiLun->pVScsiDevice, pVScsiReq, rcReq, false, VINF_SUCCESS);
501 }
502 else if (!cSectorTransfer)
503 {
504 /* A 0 transfer length is not an error. */
505 rcReq = vscsiLunReqSenseOkSet(pVScsiLun, pVScsiReq);
506 vscsiDeviceReqComplete(pVScsiLun->pVScsiDevice, pVScsiReq, rcReq, false, VINF_SUCCESS);
507 }
508 else
509 {
510 /* Enqueue new I/O request */
511 rc = vscsiIoReqTransferEnqueue(pVScsiLun, pVScsiReq, enmTxDir,
512 uLbaStart * 512, cSectorTransfer * 512);
513 }
514 }
515 else if (pVScsiReq->pbCDB[0] == SCSI_SYNCHRONIZE_CACHE)
516 {
517 /* Enqueue flush */
518 rc = vscsiIoReqFlushEnqueue(pVScsiLun, pVScsiReq);
519 }
520 else if (pVScsiReq->pbCDB[0] != SCSI_UNMAP) /* Request completed */
521 vscsiDeviceReqComplete(pVScsiLun->pVScsiDevice, pVScsiReq, rcReq, false, VINF_SUCCESS);
522
523 return rc;
524}
525
526VSCSILUNDESC g_VScsiLunTypeSbc =
527{
528 /** enmLunType */
529 VSCSILUNTYPE_SBC,
530 /** pcszDescName */
531 "SBC",
532 /** cbLun */
533 sizeof(VSCSILUNSBC),
534 /** pfnVScsiLunInit */
535 vscsiLunSbcInit,
536 /** pfnVScsiLunDestroy */
537 vscsiLunSbcDestroy,
538 /** pfnVScsiLunReqProcess */
539 vscsiLunSbcReqProcess
540};
541
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette