VirtualBox

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

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

Very rudimentary SCSI MMC implementation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: VSCSILun.cpp 38844 2011-09-23 12:25:21Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: LUN handling
4 */
5
6/*
7 * Copyright (C) 2006-2010 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
32/**
33 * Array of supported SCSI LUN types.
34 */
35static PVSCSILUNDESC g_aVScsiLunTypesSupported[] =
36{
37 &g_VScsiLunTypeSbc,
38 &g_VScsiLunTypeMmc,
39};
40
41VBOXDDU_DECL(int) VSCSILunCreate(PVSCSILUN phVScsiLun, VSCSILUNTYPE enmLunType,
42 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks,
43 void *pvVScsiLunUser)
44{
45 PVSCSILUNINT pVScsiLun = NULL;
46 PVSCSILUNDESC pVScsiLunDesc = NULL;
47
48 AssertPtrReturn(phVScsiLun, VERR_INVALID_POINTER);
49 AssertReturn( enmLunType > VSCSILUNTYPE_INVALID
50 && enmLunType < VSCSILUNTYPE_LAST, VERR_INVALID_PARAMETER);
51 AssertPtrReturn(pVScsiLunIoCallbacks, VERR_INVALID_PARAMETER);
52
53 for (unsigned idxLunType = 0; idxLunType < RT_ELEMENTS(g_aVScsiLunTypesSupported); idxLunType++)
54 {
55 if (g_aVScsiLunTypesSupported[idxLunType]->enmLunType == enmLunType)
56 {
57 pVScsiLunDesc = g_aVScsiLunTypesSupported[idxLunType];
58 break;
59 }
60 }
61
62 if (!pVScsiLunDesc)
63 return VERR_VSCSI_LUN_TYPE_NOT_SUPPORTED;
64
65 pVScsiLun = (PVSCSILUNINT)RTMemAllocZ(pVScsiLunDesc->cbLun);
66 if (!pVScsiLun)
67 return VERR_NO_MEMORY;
68
69 pVScsiLun->pVScsiDevice = NULL;
70 pVScsiLun->pvVScsiLunUser = pvVScsiLunUser;
71 pVScsiLun->pVScsiLunIoCallbacks = pVScsiLunIoCallbacks;
72 pVScsiLun->pVScsiLunDesc = pVScsiLunDesc;
73
74 int rc = vscsiLunGetFeatureFlags(pVScsiLun, &pVScsiLun->fFeatures);
75 if (RT_SUCCESS(rc))
76 {
77 rc = pVScsiLunDesc->pfnVScsiLunInit(pVScsiLun);
78 if (RT_SUCCESS(rc))
79 {
80 *phVScsiLun = pVScsiLun;
81 return VINF_SUCCESS;
82 }
83 }
84
85 RTMemFree(pVScsiLun);
86
87 return rc;
88}
89
90/**
91 * Destroy virtual SCSI LUN.
92 *
93 * @returns VBox status code.
94 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
95 */
96VBOXDDU_DECL(int) VSCSILunDestroy(VSCSILUN hVScsiLun)
97{
98 PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
99
100 AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
101 AssertReturn(!pVScsiLun->pVScsiDevice, VERR_VSCSI_LUN_ATTACHED_TO_DEVICE);
102 AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
103
104 int rc = pVScsiLun->pVScsiLunDesc->pfnVScsiLunDestroy(pVScsiLun);
105 if (RT_FAILURE(rc))
106 return rc;
107
108 /* Make LUN invalid */
109 pVScsiLun->pvVScsiLunUser = NULL;
110 pVScsiLun->pVScsiLunIoCallbacks = NULL;
111 pVScsiLun->pVScsiLunDesc = NULL;
112
113 RTMemFree(pVScsiLun);
114
115 return VINF_SUCCESS;
116}
117
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