VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VSCSI/VSCSIInternal.h@ 104932

Last change on this file since 104932 was 104221, checked in by vboxsync, 8 months ago

Devices/Storage/VSCSI: Be more strict when it comes to CDB lengths for individual commands, bugref:10613

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.2 KB
Line 
1/* $Id: VSCSIInternal.h 104221 2024-04-08 10:18:11Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: Internal defines
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28#ifndef VBOX_INCLUDED_SRC_Storage_VSCSI_VSCSIInternal_h
29#define VBOX_INCLUDED_SRC_Storage_VSCSI_VSCSIInternal_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/vscsi.h>
35#include <VBox/scsi.h>
36#include <VBox/scsiinline.h>
37#include <iprt/err.h>
38#include <iprt/memcache.h>
39#include <iprt/sg.h>
40#include <iprt/list.h>
41
42#include "VSCSIVpdPages.h"
43
44/** Pointer to an internal virtual SCSI device. */
45typedef VSCSIDEVICEINT *PVSCSIDEVICEINT;
46/** Pointer to an internal virtual SCSI device LUN. */
47typedef VSCSILUNINT *PVSCSILUNINT;
48/** Pointer to an internal virtual SCSI device LUN pointer. */
49typedef PVSCSILUNINT *PPVSCSILUNINT;
50/** Pointer to a virtual SCSI LUN descriptor. */
51typedef struct VSCSILUNDESC *PVSCSILUNDESC;
52/** Pointer to a virtual SCSI request. */
53typedef VSCSIREQINT *PVSCSIREQINT;
54/** Pointer to a virtual SCSI I/O request. */
55typedef VSCSIIOREQINT *PVSCSIIOREQINT;
56/** Pointer to virtual SCSI sense data state. */
57typedef struct VSCSISENSE *PVSCSISENSE;
58
59/**
60 * Virtual SCSI sense data handling.
61 */
62typedef struct VSCSISENSE
63{
64 /** Buffer holding the sense data. */
65 uint8_t abSenseBuf[32];
66} VSCSISENSE;
67
68/**
69 * Virtual SCSI device.
70 */
71typedef struct VSCSIDEVICEINT
72{
73 /** Request completion callback */
74 PFNVSCSIREQCOMPLETED pfnVScsiReqCompleted;
75 /** Opaque user data. */
76 void *pvVScsiDeviceUser;
77 /** Number of LUNs currently attached. */
78 uint32_t cLunsAttached;
79 /** How many LUNs are fitting in the array. */
80 uint32_t cLunsMax;
81 /** Request cache */
82 RTMEMCACHE hCacheReq;
83 /** Sense data handling. */
84 VSCSISENSE VScsiSense;
85 /** Pointer to the array of LUN handles.
86 * The index is the LUN id. */
87 PPVSCSILUNINT papVScsiLun;
88} VSCSIDEVICEINT;
89
90/**
91 * Virtual SCSI device LUN.
92 */
93typedef struct VSCSILUNINT
94{
95 /** Pointer to the parent SCSI device. */
96 PVSCSIDEVICEINT pVScsiDevice;
97 /** Opaque user data */
98 void *pvVScsiLunUser;
99 /** I/O callback table */
100 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks;
101 /** Pointer to the LUN type descriptor. */
102 PVSCSILUNDESC pVScsiLunDesc;
103 /** Flag indicating whether LUN is ready. */
104 bool fReady;
105 /** Flag indicating media presence in LUN. */
106 bool fMediaPresent;
107 /** Flags of supported features. */
108 uint64_t fFeatures;
109 /** I/O request processing data */
110 struct
111 {
112 /** Number of outstanding tasks on this LUN. */
113 volatile uint32_t cReqOutstanding;
114 } IoReq;
115} VSCSILUNINT;
116
117/**
118 * Virtual SCSI request.
119 */
120typedef struct VSCSIREQINT
121{
122 /** The LUN the request is for. */
123 uint32_t iLun;
124 /** The CDB */
125 uint8_t *pbCDB;
126 /** Size of the CDB */
127 size_t cbCDB;
128 /** S/G buffer. */
129 RTSGBUF SgBuf;
130 /** Pointer to the sense buffer. */
131 uint8_t *pbSense;
132 /** Size of the sense buffer */
133 size_t cbSense;
134 /** Opaque user data associated with this request */
135 void *pvVScsiReqUser;
136 /** Transfer size determined from the CDB. */
137 size_t cbXfer;
138 /** Number of bytes of sense data written. */
139 size_t cbSenseWritten;
140 /** Transfer direction as indicated by the CDB. */
141 VSCSIXFERDIR enmXferDir;
142 /** Pointer to the opaque data which may be allocated by the LUN
143 * the request is for. */
144 void *pvLun;
145} VSCSIREQINT;
146
147/**
148 * Virtual SCSI I/O request.
149 */
150typedef struct VSCSIIOREQINT
151{
152 /** The associated request. */
153 PVSCSIREQINT pVScsiReq;
154 /** Lun for this I/O request. */
155 PVSCSILUNINT pVScsiLun;
156 /** Transfer direction */
157 VSCSIIOREQTXDIR enmTxDir;
158 /** Direction dependent data. */
159 union
160 {
161 /** Read/Write request. */
162 struct
163 {
164 /** Start offset */
165 uint64_t uOffset;
166 /** Number of bytes to transfer */
167 size_t cbTransfer;
168 /** Number of bytes the S/G list holds */
169 size_t cbSeg;
170 /** Number of segments. */
171 unsigned cSeg;
172 /** Segment array. */
173 PCRTSGSEG paSeg;
174 } Io;
175 /** Unmap request. */
176 struct
177 {
178 /** Array of ranges to unmap. */
179 PRTRANGE paRanges;
180 /** Number of ranges. */
181 unsigned cRanges;
182 } Unmap;
183 } u;
184} VSCSIIOREQINT;
185
186/**
187 * VPD page pool.
188 */
189typedef struct VSCSIVPDPOOL
190{
191 /** List of registered pages (VSCSIVPDPAGE). */
192 RTLISTANCHOR ListPages;
193} VSCSIVPDPOOL;
194/** Pointer to the VSCSI VPD page pool. */
195typedef VSCSIVPDPOOL *PVSCSIVPDPOOL;
196
197/**
198 * Supported operation code information entry.
199 */
200typedef struct VSCSILUNSUPOPC
201{
202 /** The operation code. */
203 uint8_t u8Opc;
204 /** Service action code if required as indicated by
205 * VSCSI_LUN_SUP_OPC_SVC_ACTION_REQUIRED */
206 uint16_t u16SvcAction;
207 /** Flags. */
208 uint32_t fFlags;
209 /** Readable description for the op code. */
210 const char *pszOpc;
211 /** The length of the CDB for this operation code. */
212 uint8_t cbCdb;
213 /** Pointer to the CDB usage data. */
214 uint8_t *pbCdbUsage;
215 /* The operation specific valuefor the timeout descriptor. */
216 uint8_t u8OpcTimeoutSpec;
217 /** The nominal processing timeout in seconds. */
218 uint16_t cNominalProcessingTimeout;
219 /** The recommend timeout in seconds. */
220 uint16_t cRecommendTimeout;
221} VSCSILUNSUPOPC;
222/** Pointer to a operation code information entry. */
223typedef VSCSILUNSUPOPC *PVSCSILUNSUPOPC;
224/** Pointer to a const operation code information entry. */
225typedef const VSCSILUNSUPOPC *PCVSCSILUNSUPOPC;
226
227/** @name Flags for the supported operation code infromation entries.
228 * @{ */
229/** Flag indicating wheter the service action member is valid and should be
230 * evaluated to find the desired opcode information. */
231#define VSCSI_LUN_SUP_OPC_SVC_ACTION_REQUIRED RT_BIT_32(0)
232/** Flag whether the values for the timeout descriptor are valid. */
233#define VSCSI_LUN_SUP_OPC_TIMEOUT_DESC_VALID RT_BIT_32(1)
234/** @} */
235
236/** @name Support macros to create supported operation code information entries.
237 * @{ */
238#define VSCSI_LUN_SUP_OPC(a_u8Opc, a_pszOpc, a_cbCdb, a_pbCdbUsage) \
239 { a_u8Opc, 0, 0, a_pszOpc, a_cbCdb, a_pbCdbUsage, 0, 0, 0}
240#define VSCSI_LUN_SUP_OPC_SVC(a_u8Opc, a_u16SvcAction, a_pszOpc, a_cbCdb, a_pbCdbUsage) \
241 { a_u8Opc, a_u16SvcAction, VSCSI_LUN_SUP_OPC_SVC_ACTION_REQUIRED, a_pszOpc, a_cbCdb, a_pbCdbUsage, 0, 0, 0}
242/** @} */
243
244/** @name Helper macros to specify a range of not supported CDB opcodes for the entries pointed
245 * to by VSCSILUNDESC::pacbCdbOpc.
246 * @{ */
247#define VSCSI_LUN_CDB_SZ_INVALID 0
248#define VSCSI_LUN_CDB_SZ_INVALID_X2 \
249 VSCSI_LUN_CDB_SZ_INVALID, \
250 VSCSI_LUN_CDB_SZ_INVALID
251#define VSCSI_LUN_CDB_SZ_INVALID_X4 \
252 VSCSI_LUN_CDB_SZ_INVALID_X2, \
253 VSCSI_LUN_CDB_SZ_INVALID_X2
254#define VSCSI_LUN_CDB_SZ_INVALID_X8 \
255 VSCSI_LUN_CDB_SZ_INVALID_X4, \
256 VSCSI_LUN_CDB_SZ_INVALID_X4
257#define VSCSI_LUN_CDB_SZ_INVALID_X16 \
258 VSCSI_LUN_CDB_SZ_INVALID_X8, \
259 VSCSI_LUN_CDB_SZ_INVALID_X8
260/** @} */
261
262
263/**
264 * Virtual SCSI LUN descriptor.
265 */
266typedef struct VSCSILUNDESC
267{
268 /** Device type this descriptor emulates. */
269 VSCSILUNTYPE enmLunType;
270 /** Descriptor name */
271 const char *pcszDescName;
272 /** LUN type size */
273 size_t cbLun;
274 /** Pointer to the array holding the CDB length indexed by the opcode.
275 * A 0 entry means opcode not supported (CDB must be at least 1 byte big). */
276 const uint8_t *pacbCdbOpc;
277 /** Number of entries in the supported operation codes array. */
278 uint32_t cSupOpcInfo;
279 /** Pointer to the array of supported operation codes for the
280 * REPORT RUPPORTED OPERATION CODES command handled by the generic
281 * device driver - optional.
282 */
283 PCVSCSILUNSUPOPC paSupOpcInfo;
284
285 /**
286 * Initialise a Lun instance.
287 *
288 * @returns VBox status code.
289 * @param pVScsiLun The SCSI LUN instance.
290 */
291 DECLR3CALLBACKMEMBER(int, pfnVScsiLunInit, (PVSCSILUNINT pVScsiLun));
292
293 /**
294 * Destroy a Lun instance.
295 *
296 * @returns VBox status code.
297 * @param pVScsiLun The SCSI LUN instance.
298 */
299 DECLR3CALLBACKMEMBER(int, pfnVScsiLunDestroy, (PVSCSILUNINT pVScsiLun));
300
301 /**
302 * Processes a SCSI request.
303 *
304 * @returns VBox status code.
305 * @param pVScsiLun The SCSI LUN instance.
306 * @param pVScsiReq The SCSi request to process.
307 */
308 DECLR3CALLBACKMEMBER(int, pfnVScsiLunReqProcess, (PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq));
309
310 /**
311 * Frees additional allocated resources for the given request if it was allocated before.
312 *
313 * @returns void.
314 * @param pVScsiLun The SCSI LUN instance.
315 * @param pVScsiReq The SCSI request.
316 * @param pvScsiReqLun The opaque data allocated previously.
317 */
318 DECLR3CALLBACKMEMBER(void, pfnVScsiLunReqFree, (PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
319 void *pvScsiReqLun));
320
321 /**
322 * Informs about a medium being inserted - optional.
323 *
324 * @returns VBox status code.
325 * @param pVScsiLun The SCSI LUN instance.
326 */
327 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumInserted, (PVSCSILUNINT pVScsiLun));
328
329 /**
330 * Informs about a medium being removed - optional.
331 *
332 * @returns VBox status code.
333 * @param pVScsiLun The SCSI LUN instance.
334 */
335 DECLR3CALLBACKMEMBER(int, pfnVScsiLunMediumRemoved, (PVSCSILUNINT pVScsiLun));
336
337} VSCSILUNDESC;
338
339/** Maximum number of LUNs a device can have. */
340#define VSCSI_DEVICE_LUN_MAX 128
341
342/**
343 * Completes a SCSI request and calls the completion handler.
344 *
345 * @param pVScsiDevice The virtual SCSI device.
346 * @param pVScsiReq The request which completed.
347 * @param rcScsiCode The status code
348 * One of the SCSI_STATUS_* #defines.
349 * @param fRedoPossible Flag whether redo is possible.
350 * @param rcReq Informational return code of the request.
351 */
352void vscsiDeviceReqComplete(PVSCSIDEVICEINT pVScsiDevice, PVSCSIREQINT pVScsiReq,
353 int rcScsiCode, bool fRedoPossible, int rcReq);
354
355/**
356 * Init the sense data state.
357 *
358 * @param pVScsiSense The SCSI sense data state to init.
359 */
360void vscsiSenseInit(PVSCSISENSE pVScsiSense);
361
362/**
363 * Sets a ok sense code.
364 *
365 * @returns SCSI status code.
366 * @param pVScsiSense The SCSI sense state to use.
367 * @param pVScsiReq The SCSI request.
368 */
369int vscsiReqSenseOkSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq);
370
371/**
372 * Sets an error sense code.
373 *
374 * @returns SCSI status code.
375 * @param pVScsiSense The SCSI sense state to use.
376 * @param pVScsiReq The SCSI request.
377 * @param uSCSISenseKey The SCSI sense key to set.
378 * @param uSCSIASC The ASC value.
379 * @param uSCSIASC The ASCQ value.
380 */
381int vscsiReqSenseErrorSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey,
382 uint8_t uSCSIASC, uint8_t uSCSIASCQ);
383
384/**
385 * Sets an error sense code with additional information.
386 *
387 * @returns SCSI status code.
388 * @param pVScsiSense The SCSI sense state to use.
389 * @param pVScsiReq The SCSI request.
390 * @param uSCSISenseKey The SCSI sense key to set.
391 * @param uSCSIASC The ASC value.
392 * @param uSCSIASC The ASCQ value.
393 * @param uInfo The 32-bit sense information.
394 */
395int vscsiReqSenseErrorInfoSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey,
396 uint8_t uSCSIASC, uint8_t uSCSIASCQ, uint32_t uInfo);
397
398/**
399 * Process a request sense command.
400 *
401 * @returns SCSI status code.
402 * @param pVScsiSense The SCSI sense state to use.
403 * @param pVScsiReq The SCSI request.
404 */
405int vscsiReqSenseCmd(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq);
406
407/**
408 * Inits the VPD page pool.
409 *
410 * @returns VBox status code.
411 * @param pVScsiVpdPool The VPD page pool to initialize.
412 */
413int vscsiVpdPagePoolInit(PVSCSIVPDPOOL pVScsiVpdPool);
414
415/**
416 * Destroys the given VPD page pool freeing all pages in it.
417 *
418 * @param pVScsiVpdPool The VPD page pool to destroy.
419 */
420void vscsiVpdPagePoolDestroy(PVSCSIVPDPOOL pVScsiVpdPool);
421
422/**
423 * Allocates a new page in the VPD page pool with the given number.
424 *
425 * @returns VBox status code.
426 * @retval VERR_ALREADY_EXIST if the page number is in use.
427 * @param pVScsiVpdPool The VPD page pool the page will belong to.
428 * @param uPage The page number, must be unique.
429 * @param cbPage Size of the page in bytes.
430 * @param ppbPage Where to store the pointer to the raw page data on success.
431 */
432int vscsiVpdPagePoolAllocNewPage(PVSCSIVPDPOOL pVScsiVpdPool, uint8_t uPage, size_t cbPage, uint8_t **ppbPage);
433
434/**
435 * Queries the given page from the pool and cpies it to the buffer given
436 * by the SCSI request.
437 *
438 * @returns VBox status code.
439 * @retval VERR_NOT_FOUND if the page is not in the pool.
440 * @param pVScsiVpdPool The VPD page pool to use.
441 * @param pVScsiReq The SCSI request.
442 * @param uPage Page to query.
443 */
444int vscsiVpdPagePoolQueryPage(PVSCSIVPDPOOL pVScsiVpdPool, PVSCSIREQINT pVScsiReq, uint8_t uPage);
445
446/**
447 * Inits the I/O request related state for the LUN.
448 *
449 * @returns VBox status code.
450 * @param pVScsiLun The LUN instance.
451 */
452int vscsiIoReqInit(PVSCSILUNINT pVScsiLun);
453
454/**
455 * Enqueues a new flush request
456 *
457 * @returns VBox status code.
458 * @param pVScsiLun The LUN instance which issued the request.
459 * @param pVScsiReq The virtual SCSI request associated with the flush.
460 */
461int vscsiIoReqFlushEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq);
462
463/**
464 * Enqueue a new data transfer request.
465 *
466 * @returns VBox status code.
467 * @param pVScsiLun The LUN instance which issued the request.
468 * @param pVScsiReq The virtual SCSI request associated with the transfer.
469 * @param enmTxDir Transfer direction.
470 * @param uOffset Start offset of the transfer.
471 * @param cbTransfer Number of bytes to transfer.
472 */
473int vscsiIoReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
474 VSCSIIOREQTXDIR enmTxDir, uint64_t uOffset,
475 size_t cbTransfer);
476
477/**
478 * Enqueue a new data transfer request - extended variant.
479 *
480 * @returns VBox status code.
481 * @param pVScsiLun The LUN instance which issued the request.
482 * @param pVScsiReq The virtual SCSI request associated with the transfer.
483 * @param enmTxDir Transfer direction.
484 * @param uOffset Start offset of the transfer.
485 * @param paSegs Pointer to the array holding the memory buffer segments.
486 * @param cSegs Number of segments in the array.
487 * @param cbTransfer Number of bytes to transfer.
488 */
489int vscsiIoReqTransferEnqueueEx(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
490 VSCSIIOREQTXDIR enmTxDir, uint64_t uOffset,
491 PCRTSGSEG paSegs, unsigned cSegs, size_t cbTransfer);
492
493/**
494 * Enqueue a new unmap request.
495 *
496 * @returns VBox status code.
497 * @param pVScsiLun The LUN instance which issued the request.
498 * @param pVScsiReq The virtual SCSI request associated with the transfer.
499 * @param paRanges The array of ranges to unmap.
500 * @param cRanges Number of ranges in the array.
501 */
502int vscsiIoReqUnmapEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
503 PRTRANGE paRanges, unsigned cRanges);
504
505/**
506 * Returns the current number of outstanding tasks on the given LUN.
507 *
508 * @returns Number of outstanding tasks.
509 * @param pVScsiLun The LUN to check.
510 */
511uint32_t vscsiIoReqOutstandingCountGet(PVSCSILUNINT pVScsiLun);
512
513/**
514 * Sets the transfer size for the given request.
515 *
516 * @param pVScsiReq The SCSI request.
517 * @param cbXfer The transfer size for the request.
518 */
519DECLINLINE(void) vscsiReqSetXferSize(PVSCSIREQINT pVScsiReq, size_t cbXfer)
520{
521 pVScsiReq->cbXfer = cbXfer;
522}
523
524/**
525 * Sets the transfer direction for the given request.
526 *
527 * @param pVScsiReq The SCSI request.
528 * @param cbXfer The transfer size for the request.
529 */
530DECLINLINE(void) vscsiReqSetXferDir(PVSCSIREQINT pVScsiReq, VSCSIXFERDIR enmXferDir)
531{
532 pVScsiReq->enmXferDir = enmXferDir;
533}
534
535/**
536 * Wrapper for the set I/O request allocation size I/O callback.
537 *
538 * @returns VBox status code.
539 * @param pVScsiLun The LUN.
540 * @param cbVScsiIoReqAlloc The additional size for the request to allocate.
541 */
542DECLINLINE(int) vscsiLunReqAllocSizeSet(PVSCSILUNINT pVScsiLun, size_t cbVScsiIoReqAlloc)
543{
544 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqAllocSizeSet(pVScsiLun,
545 pVScsiLun->pvVScsiLunUser,
546 cbVScsiIoReqAlloc);
547}
548
549/**
550 * Wrapper for the allocate I/O request I/O callback.
551 *
552 * @returns VBox status code.
553 * @param pVScsiLun The LUN.
554 * @param u64Tag A unique tag to assign to the request.
555 * @param ppVScsiIoReq Where to store the pointer to the request on success.
556 */
557DECLINLINE(int) vscsiLunReqAlloc(PVSCSILUNINT pVScsiLun, uint64_t u64Tag, PVSCSIIOREQINT *ppVScsiIoReq)
558{
559 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqAlloc(pVScsiLun,
560 pVScsiLun->pvVScsiLunUser,
561 u64Tag, ppVScsiIoReq);
562}
563
564/**
565 * Wrapper for the free I/O request I/O callback.
566 *
567 * @returns VBox status code.
568 * @param pVScsiLun The LUN.
569 * @param pVScsiIoReq The request to free.
570 */
571DECLINLINE(int) vscsiLunReqFree(PVSCSILUNINT pVScsiLun, PVSCSIIOREQINT pVScsiIoReq)
572{
573 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqFree(pVScsiLun,
574 pVScsiLun->pvVScsiLunUser,
575 pVScsiIoReq);
576}
577
578/**
579 * Wrapper for the get medium region count I/O callback.
580 *
581 * @returns Number of regions for the underlying medium.
582 * @param pVScsiLun The LUN.
583 */
584DECLINLINE(uint32_t) vscsiLunMediumGetRegionCount(PVSCSILUNINT pVScsiLun)
585{
586 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumGetRegionCount(pVScsiLun,
587 pVScsiLun->pvVScsiLunUser);
588}
589
590/**
591 * Wrapper for the query medium region properties I/O callback.
592 *
593 * @returns VBox status code.
594 * @param pVScsiLun The LUN.
595 * @param uRegion The region index to query the properties of.
596 * @param pu64LbaStart Where to store the starting LBA for the region on success.
597 * @param pcBlocks Where to store the number of blocks for the region on success.
598 * @param pcbBlock Where to store the size of one block in bytes on success.
599 * @param penmDataForm WHere to store the data form for the region on success.
600 */
601DECLINLINE(int) vscsiLunMediumQueryRegionProperties(PVSCSILUNINT pVScsiLun, uint32_t uRegion,
602 uint64_t *pu64LbaStart, uint64_t *pcBlocks,
603 uint64_t *pcbBlock, PVDREGIONDATAFORM penmDataForm)
604{
605 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumQueryRegionProperties(pVScsiLun,
606 pVScsiLun->pvVScsiLunUser,
607 uRegion, pu64LbaStart,
608 pcBlocks, pcbBlock,
609 penmDataForm);
610}
611
612/**
613 * Wrapper for the query medium region properties for LBA I/O callback.
614 *
615 * @returns VBox status code.
616 * @param pVScsiLun The LUN.
617 * @param uRegion The region index to query the properties of.
618 * @param pu64LbaStart Where to store the starting LBA for the region on success.
619 * @param pcBlocks Where to store the number of blocks for the region on success.
620 * @param pcbBlock Where to store the size of one block in bytes on success.
621 * @param penmDataForm WHere to store the data form for the region on success.
622 */
623DECLINLINE(int) vscsiLunMediumQueryRegionPropertiesForLba(PVSCSILUNINT pVScsiLun, uint64_t u64LbaStart, uint32_t *puRegion,
624 uint64_t *pcBlocks, uint64_t *pcbBlock,
625 PVDREGIONDATAFORM penmDataForm)
626{
627 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumQueryRegionPropertiesForLba(pVScsiLun,
628 pVScsiLun->pvVScsiLunUser,
629 u64LbaStart, puRegion,
630 pcBlocks, pcbBlock,
631 penmDataForm);
632}
633
634/**
635 * Wrapper for the get medium lock/unlock I/O callback.
636 *
637 * @returns VBox status code.
638 * @param pVScsiLun The LUN.
639 * @param bool The new medium lock state.
640 */
641DECLINLINE(int) vscsiLunMediumSetLock(PVSCSILUNINT pVScsiLun, bool fLocked)
642{
643 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumSetLock(pVScsiLun,
644 pVScsiLun->pvVScsiLunUser,
645 fLocked);
646}
647
648/**
649 * Wrapper for the eject medium I/O callback.
650 *
651 * @returns VBox status code.
652 * @param pVScsiLun The LUN.
653 */
654DECLINLINE(int) vscsiLunMediumEject(PVSCSILUNINT pVScsiLun)
655{
656 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunMediumEject(pVScsiLun,
657 pVScsiLun->pvVScsiLunUser);
658}
659
660/**
661 * Wrapper for the I/O request enqueue I/O callback.
662 *
663 * @returns VBox status code.
664 * @param pVScsiLun The LUN.
665 * @param pVScsiIoReq The I/O request to enqueue.
666 */
667DECLINLINE(int) vscsiLunReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIIOREQINT pVScsiIoReq)
668{
669 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunReqTransferEnqueue(pVScsiLun,
670 pVScsiLun->pvVScsiLunUser,
671 pVScsiIoReq);
672}
673
674/**
675 * Wrapper for the get feature flags I/O callback.
676 *
677 * @returns VBox status code.
678 * @param pVScsiLun The LUN.
679 * @param pfFeatures Where to sthre supported flags on success.
680 */
681DECLINLINE(int) vscsiLunGetFeatureFlags(PVSCSILUNINT pVScsiLun, uint64_t *pfFeatures)
682{
683 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunGetFeatureFlags(pVScsiLun,
684 pVScsiLun->pvVScsiLunUser,
685 pfFeatures);
686}
687
688/**
689 * Wrapper for the query INQUIRY strings I/O callback.
690 *
691 * @returns VBox status code.
692 * @param pVScsiLun The LUN.
693 * @param ppszVendorId Where to store the pointer to the vendor ID string to report.
694 * @param ppszProductId Where to store the pointer to the product ID string to report.
695 * @param ppszProductLevel Where to store the pointer to the revision string to report.
696 */
697DECLINLINE(int) vscsiLunQueryInqStrings(PVSCSILUNINT pVScsiLun, const char **ppszVendorId,
698 const char **ppszProductId, const char **ppszProductLevel)
699{
700 if (pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunQueryInqStrings)
701 {
702 return pVScsiLun->pVScsiLunIoCallbacks->pfnVScsiLunQueryInqStrings(pVScsiLun,
703 pVScsiLun->pvVScsiLunUser,
704 ppszVendorId, ppszProductId,
705 ppszProductLevel);
706 }
707
708 return VERR_NOT_FOUND;
709}
710
711/**
712 * Wrapper around vscsiReqSenseOkSet()
713 */
714DECLINLINE(int) vscsiLunReqSenseOkSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq)
715{
716 return vscsiReqSenseOkSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq);
717}
718
719/**
720 * Wrapper around vscsiReqSenseErrorSet()
721 */
722DECLINLINE(int) vscsiLunReqSenseErrorSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ)
723{
724 return vscsiReqSenseErrorSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq, uSCSISenseKey, uSCSIASC, uSCSIASCQ);
725}
726
727/**
728 * Wrapper around vscsiReqSenseErrorInfoSet()
729 */
730DECLINLINE(int) vscsiLunReqSenseErrorInfoSet(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ, uint32_t uInfo)
731{
732 return vscsiReqSenseErrorInfoSet(&pVScsiLun->pVScsiDevice->VScsiSense, pVScsiReq, uSCSISenseKey, uSCSIASC, uSCSIASCQ, uInfo);
733}
734
735#endif /* !VBOX_INCLUDED_SRC_Storage_VSCSI_VSCSIInternal_h */
736
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