VirtualBox

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

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

VSCSI+DrvSCSI: Add support for the UNMAP command if discarding is enabled

  • 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 38680 2011-09-08 07:52:08Z 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 */
30//extern PVSCSILUNDESC g_pVScsiLunTypeMmc;
31
32/**
33 * Array of supported SCSI LUN types.
34 */
35static PVSCSILUNDESC g_aVScsiLunTypesSupported[] =
36{
37 &g_VScsiLunTypeSbc
38};
39
40VBOXDDU_DECL(int) VSCSILunCreate(PVSCSILUN phVScsiLun, VSCSILUNTYPE enmLunType,
41 PVSCSILUNIOCALLBACKS pVScsiLunIoCallbacks,
42 void *pvVScsiLunUser)
43{
44 PVSCSILUNINT pVScsiLun = NULL;
45 PVSCSILUNDESC pVScsiLunDesc = NULL;
46
47 AssertPtrReturn(phVScsiLun, VERR_INVALID_POINTER);
48 AssertReturn( enmLunType > VSCSILUNTYPE_INVALID
49 && enmLunType < VSCSILUNTYPE_LAST, VERR_INVALID_PARAMETER);
50 AssertPtrReturn(pVScsiLunIoCallbacks, VERR_INVALID_PARAMETER);
51
52 for (unsigned idxLunType = 0; idxLunType < RT_ELEMENTS(g_aVScsiLunTypesSupported); idxLunType++)
53 {
54 if (g_aVScsiLunTypesSupported[idxLunType]->enmLunType == enmLunType)
55 {
56 pVScsiLunDesc = g_aVScsiLunTypesSupported[idxLunType];
57 break;
58 }
59 }
60
61 if (!pVScsiLunDesc)
62 return VERR_VSCSI_LUN_TYPE_NOT_SUPPORTED;
63
64 pVScsiLun = (PVSCSILUNINT)RTMemAllocZ(pVScsiLunDesc->cbLun);
65 if (!pVScsiLun)
66 return VERR_NO_MEMORY;
67
68 pVScsiLun->pVScsiDevice = NULL;
69 pVScsiLun->pvVScsiLunUser = pvVScsiLunUser;
70 pVScsiLun->pVScsiLunIoCallbacks = pVScsiLunIoCallbacks;
71 pVScsiLun->pVScsiLunDesc = pVScsiLunDesc;
72
73 int rc = vscsiLunGetFeatureFlags(pVScsiLun, &pVScsiLun->fFeatures);
74 if (RT_SUCCESS(rc))
75 {
76 rc = pVScsiLunDesc->pfnVScsiLunInit(pVScsiLun);
77 if (RT_SUCCESS(rc))
78 {
79 *phVScsiLun = pVScsiLun;
80 return VINF_SUCCESS;
81 }
82 }
83
84 RTMemFree(pVScsiLun);
85
86 return rc;
87}
88
89/**
90 * Destroy virtual SCSI LUN.
91 *
92 * @returns VBox status code.
93 * @param hVScsiLun The virtual SCSI LUN handle to destroy.
94 */
95VBOXDDU_DECL(int) VSCSILunDestroy(VSCSILUN hVScsiLun)
96{
97 PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
98
99 AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
100 AssertReturn(!pVScsiLun->pVScsiDevice, VERR_VSCSI_LUN_ATTACHED_TO_DEVICE);
101 AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
102
103 int rc = pVScsiLun->pVScsiLunDesc->pfnVScsiLunDestroy(pVScsiLun);
104 if (RT_FAILURE(rc))
105 return rc;
106
107 /* Make LUN invalid */
108 pVScsiLun->pvVScsiLunUser = NULL;
109 pVScsiLun->pVScsiLunIoCallbacks = NULL;
110 pVScsiLun->pVScsiLunDesc = NULL;
111
112 RTMemFree(pVScsiLun);
113
114 return VINF_SUCCESS;
115}
116
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