VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VSCSI/VSCSILun.cpp@ 52713

Last change on this file since 52713 was 52713, checked in by vboxsync, 10 years ago

BusLogic: Slightly enhanced debug info.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: VSCSILun.cpp 52713 2014-09-12 09:34:39Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: LUN handling
4 */
5
6/*
7 * Copyright (C) 2006-2012 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#define LOG_GROUP LOG_GROUP_VSCSI
18#include <VBox/log.h>
19#include <VBox/err.h>
20#include <VBox/types.h>
21#include <VBox/vscsi.h>
22#include <iprt/assert.h>
23#include <iprt/mem.h>
24
25#include "VSCSIInternal.h"
26
27/** SBC descriptor */
28extern VSCSILUNDESC g_VScsiLunTypeSbc;
29/** MMC descriptor */
30extern VSCSILUNDESC g_VScsiLunTypeMmc;
31/** SSC descriptor */
32extern VSCSILUNDESC g_VScsiLunTypeSsc;
33
34/**
35 * Array of supported SCSI LUN types.
36 */
37static PVSCSILUNDESC g_aVScsiLunTypesSupported[] =
38{
39 &g_VScsiLunTypeSbc,
40 &g_VScsiLunTypeMmc,
41 &g_VScsiLunTypeSsc,
42};
43
44VBOXDDU_DECL(int) VSCSILunCreate(PVSCSILUN phVScsiLun, VSCSILUNTYPE enmLunType,
45 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks,
46 void *pvVScsiLunUser)
47{
48 PVSCSILUNINT pVScsiLun = NULL;
49 PVSCSILUNDESC pVScsiLunDesc = NULL;
50
51 AssertPtrReturn(phVScsiLun, VERR_INVALID_POINTER);
52 AssertReturn( enmLunType > VSCSILUNTYPE_INVALID
53 && enmLunType < VSCSILUNTYPE_LAST, VERR_INVALID_PARAMETER);
54 AssertPtrReturn(pVScsiLunIoCallbacks, VERR_INVALID_PARAMETER);
55
56 for (unsigned idxLunType = 0; idxLunType < RT_ELEMENTS(g_aVScsiLunTypesSupported); idxLunType++)
57 {
58 if (g_aVScsiLunTypesSupported[idxLunType]->enmLunType == enmLunType)
59 {
60 pVScsiLunDesc = g_aVScsiLunTypesSupported[idxLunType];
61 break;
62 }
63 }
64
65 if (!pVScsiLunDesc)
66 return VERR_VSCSI_LUN_TYPE_NOT_SUPPORTED;
67
68 pVScsiLun = (PVSCSILUNINT)RTMemAllocZ(pVScsiLunDesc->cbLun);
69 if (!pVScsiLun)
70 return VERR_NO_MEMORY;
71
72 pVScsiLun->pVScsiDevice = NULL;
73 pVScsiLun->pvVScsiLunUser = pvVScsiLunUser;
74 pVScsiLun->pVScsiLunIoCallbacks = pVScsiLunIoCallbacks;
75 pVScsiLun->pVScsiLunDesc = pVScsiLunDesc;
76
77 int rc = vscsiLunGetFeatureFlags(pVScsiLun, &pVScsiLun->fFeatures);
78 if (RT_SUCCESS(rc))
79 {
80 rc = pVScsiLunDesc->pfnVScsiLunInit(pVScsiLun);
81 if (RT_SUCCESS(rc))
82 {
83 *phVScsiLun = pVScsiLun;
84 return VINF_SUCCESS;
85 }
86 }
87
88 RTMemFree(pVScsiLun);
89
90 return rc;
91}
92
93/**
94 * Destroy virtual SCSI LUN.
95 *
96 * @returns VBox status code.
97 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
98 */
99VBOXDDU_DECL(int) VSCSILunDestroy(VSCSILUN hVScsiLun)
100{
101 PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
102
103 AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
104 AssertReturn(!pVScsiLun->pVScsiDevice, VERR_VSCSI_LUN_ATTACHED_TO_DEVICE);
105 AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
106
107 int rc = pVScsiLun->pVScsiLunDesc->pfnVScsiLunDestroy(pVScsiLun);
108 if (RT_FAILURE(rc))
109 return rc;
110
111 /* Make LUN invalid */
112 pVScsiLun->pvVScsiLunUser = NULL;
113 pVScsiLun->pVScsiLunIoCallbacks = NULL;
114 pVScsiLun->pVScsiLunDesc = NULL;
115
116 RTMemFree(pVScsiLun);
117
118 return VINF_SUCCESS;
119}
120
121/**
122 * Notify virtual SCSI LUN of media being mounted.
123 *
124 * @returns VBox status code.
125 * @param hVScsiLun The virtual SCSI LUN
126 * mounting the medium.
127 */
128VBOXDDU_DECL(int) VSCSILunMountNotify(VSCSILUN hVScsiLun)
129{
130 PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
131
132 LogFlowFunc(("hVScsiLun=%p\n", hVScsiLun));
133 AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
134 AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
135
136 /* Mark the LUN as not ready so that LUN specific code can do its job. */
137 pVScsiLun->fReady = false;
138 pVScsiLun->fMediaPresent = true;
139
140 return VINF_SUCCESS;
141}
142
143/**
144 * Notify virtual SCSI LUN of media being unmounted.
145 *
146 * @returns VBox status code.
147 * @param hVScsiLun The virtual SCSI LUN
148 * mounting the medium.
149 */
150VBOXDDU_DECL(int) VSCSILunUnmountNotify(VSCSILUN hVScsiLun)
151{
152 PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
153
154 LogFlowFunc(("hVScsiLun=%p\n", hVScsiLun));
155 AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
156 AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
157
158 pVScsiLun->fReady = false;
159 pVScsiLun->fMediaPresent = false;
160
161 return VINF_SUCCESS;
162}
Note: See TracBrowser for help on using the repository browser.

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