VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VSCSI/VSCSIIoReq.cpp@ 28065

Last change on this file since 28065 was 28065, checked in by vboxsync, 15 years ago

Storage: Convert from PDMDATASEG to RTSGSEG to avoid casting between those two in VBoxHDD and more async I/O updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: VSCSIIoReq.cpp 28065 2010-04-07 20:54:34Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: I/O request handling.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
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/assert.h>
27#include <iprt/mem.h>
28#include <iprt/asm.h>
29
30#include "VSCSIInternal.h"
31
32int vscsiIoReqFlushEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq)
33{
34 int rc = VINF_SUCCESS;
35 PVSCSIIOREQINT pVScsiIoReq = NULL;
36
37 pVScsiIoReq = (PVSCSIIOREQINT)RTMemAllocZ(sizeof(VSCSIIOREQINT));
38 if (!pVScsiIoReq)
39 return VERR_NO_MEMORY;
40
41 pVScsiIoReq->pVScsiReq = pVScsiReq;
42 pVScsiIoReq->pVScsiLun = pVScsiLun;
43 pVScsiIoReq->enmTxDir = VSCSIIOREQTXDIR_FLUSH;
44
45 ASMAtomicIncU32(&pVScsiLun->IoReq.cReqOutstanding);
46
47 rc = vscsiLunReqTransferEnqueue(pVScsiLun, pVScsiIoReq);
48 if (RT_FAILURE(rc))
49 {
50 ASMAtomicDecU32(&pVScsiLun->IoReq.cReqOutstanding);
51 RTMemFree(pVScsiIoReq);
52 }
53
54 return rc;
55}
56
57
58int vscsiIoReqTransferEnqueue(PVSCSILUNINT pVScsiLun, PVSCSIREQINT pVScsiReq,
59 VSCSIIOREQTXDIR enmTxDir, uint64_t uOffset,
60 size_t cbTransfer)
61{
62 int rc = VINF_SUCCESS;
63 PVSCSIIOREQINT pVScsiIoReq = NULL;
64
65 LogFlowFunc(("pVScsiLun=%#p pVScsiReq=%#p enmTxDir=%u uOffset=%llu cbTransfer=%u\n",
66 pVScsiLun, pVScsiReq, enmTxDir, uOffset, cbTransfer));
67
68 pVScsiIoReq = (PVSCSIIOREQINT)RTMemAllocZ(sizeof(VSCSIIOREQINT));
69 if (!pVScsiIoReq)
70 return VERR_NO_MEMORY;
71
72 pVScsiIoReq->pVScsiReq = pVScsiReq;
73 pVScsiIoReq->pVScsiLun = pVScsiLun;
74 pVScsiIoReq->enmTxDir = enmTxDir;
75 pVScsiIoReq->uOffset = uOffset;
76 pVScsiIoReq->cbTransfer = cbTransfer;
77 pVScsiIoReq->paSeg = pVScsiReq->IoMemCtx.paDataSeg;
78 pVScsiIoReq->cSeg = pVScsiReq->IoMemCtx.cSegments;
79
80 ASMAtomicIncU32(&pVScsiLun->IoReq.cReqOutstanding);
81
82 rc = vscsiLunReqTransferEnqueue(pVScsiLun, pVScsiIoReq);
83 if (RT_FAILURE(rc))
84 {
85 ASMAtomicDecU32(&pVScsiLun->IoReq.cReqOutstanding);
86 RTMemFree(pVScsiIoReq);
87 }
88
89 return rc;
90}
91
92
93uint32_t vscsiIoReqOutstandingCountGet(PVSCSILUNINT pVScsiLun)
94{
95 return ASMAtomicReadU32(&pVScsiLun->IoReq.cReqOutstanding);
96}
97
98
99VBOXDDU_DECL(int) VSCSIIoReqCompleted(VSCSIIOREQ hVScsiIoReq, int rcIoReq)
100{
101 PVSCSIIOREQINT pVScsiIoReq = hVScsiIoReq;
102 PVSCSILUNINT pVScsiLun;
103 PVSCSIREQINT pVScsiReq;
104 int rcReq = SCSI_STATUS_OK;
105
106 AssertPtrReturn(pVScsiIoReq, VERR_INVALID_HANDLE);
107
108 LogFlowFunc(("hVScsiIoReq=%#p rcIoReq=%Rrc\n", hVScsiIoReq, rcIoReq));
109
110 pVScsiLun = pVScsiIoReq->pVScsiLun;
111 pVScsiReq = pVScsiIoReq->pVScsiReq;
112
113 AssertMsg(pVScsiLun->IoReq.cReqOutstanding > 0,
114 ("Unregistered I/O request completed\n"));
115
116 ASMAtomicDecU32(&pVScsiLun->IoReq.cReqOutstanding);
117
118 /** @todo error reporting */
119 if (RT_SUCCESS(rcIoReq))
120 rcReq = vscsiReqSenseOkSet(pVScsiReq);
121
122 /* Free the I/O request */
123 RTMemFree(pVScsiIoReq);
124
125 /* Notify completion of the SCSI request. */
126 vscsiDeviceReqComplete(pVScsiLun->pVScsiDevice, pVScsiReq, rcReq);
127
128 return VINF_SUCCESS;
129}
130
131
132VBOXDDU_DECL(VSCSIIOREQTXDIR) VSCSIIoReqTxDirGet(VSCSIIOREQ hVScsiIoReq)
133{
134 PVSCSIIOREQINT pVScsiIoReq = hVScsiIoReq;
135
136 AssertPtrReturn(pVScsiIoReq, VSCSIIOREQTXDIR_INVALID);
137
138 return pVScsiIoReq->enmTxDir;
139}
140
141
142VBOXDDU_DECL(int) VSCSIIoReqParamsGet(VSCSIIOREQ hVScsiIoReq, uint64_t *puOffset,
143 size_t *pcbTransfer, unsigned *pcSeg,
144 size_t *pcbSeg, PCRTSGSEG *ppaSeg)
145{
146 PVSCSIIOREQINT pVScsiIoReq = hVScsiIoReq;
147
148 AssertPtrReturn(pVScsiIoReq, VERR_INVALID_HANDLE);
149 AssertReturn(pVScsiIoReq->enmTxDir != VSCSIIOREQTXDIR_FLUSH, VERR_NOT_SUPPORTED);
150
151 *puOffset = pVScsiIoReq->uOffset;
152 *pcbTransfer = pVScsiIoReq->cbTransfer;
153 *pcSeg = pVScsiIoReq->cSeg;
154 *pcbSeg = pVScsiIoReq->cbSeg;
155 *ppaSeg = pVScsiIoReq->paSeg;
156
157 return VINF_SUCCESS;
158}
159
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