VirtualBox

source: vbox/trunk/src/VBox/Storage/VDInternal.h@ 93552

Last change on this file since 93552 was 93512, checked in by vboxsync, 3 years ago

Storage/VDPlugIn: Don't disable VBOX_HDD_NO_DYNAMIC_BACKENDS on non-x86 platforms. bugref:9898

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1/* $Id: VDInternal.h 93512 2022-01-31 20:48:00Z vboxsync $ */
2/** @file
3 * VD - Virtual Disk container implementation, internal header file.
4 */
5
6/*
7 * Copyright (C) 2017-2022 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
18/*********************************************************************************************************************************
19* Header Files *
20*********************************************************************************************************************************/
21
22#ifndef VBOX_INCLUDED_SRC_Storage_VDInternal_h
23#define VBOX_INCLUDED_SRC_Storage_VDInternal_h
24#ifndef RT_WITHOUT_PRAGMA_ONCE
25# pragma once
26#endif
27#include <VBox/vd.h>
28#include <VBox/vd-plugin.h>
29
30#include <iprt/avl.h>
31#include <iprt/list.h>
32#include <iprt/memcache.h>
33
34#if 0 /* bird: this is nonsense */
35/** Disable dynamic backends on non x86 architectures. This feature
36 * requires the SUPR3 library which is not available there.
37 */
38#if !defined(VBOX_HDD_NO_DYNAMIC_BACKENDS) && !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
39# define VBOX_HDD_NO_DYNAMIC_BACKENDS
40#endif
41#endif
42
43/** Magic number contained in the VDISK instance data, used for checking that the passed
44 * pointer contains a valid instance in debug builds. */
45#define VDISK_SIGNATURE 0x6f0e2a7d
46
47/**
48 * Structure containing everything I/O related
49 * for the image and cache descriptors.
50 */
51typedef struct VDIO
52{
53 /** I/O interface to the upper layer. */
54 PVDINTERFACEIO pInterfaceIo;
55
56 /** Per image internal I/O interface. */
57 VDINTERFACEIOINT VDIfIoInt;
58
59 /** Fallback I/O interface, only used if the caller doesn't provide it. */
60 VDINTERFACEIO VDIfIo;
61
62 /** Opaque backend data. */
63 void *pBackendData;
64 /** Disk this image is part of */
65 PVDISK pDisk;
66 /** Flag whether to ignore flush requests. */
67 bool fIgnoreFlush;
68} VDIO, *PVDIO;
69
70/** Forward declaration of an I/O task */
71typedef struct VDIOTASK *PVDIOTASK;
72
73/**
74 * Virtual disk container image descriptor.
75 */
76typedef struct VDIMAGE
77{
78 /** Link to parent image descriptor, if any. */
79 struct VDIMAGE *pPrev;
80 /** Link to child image descriptor, if any. */
81 struct VDIMAGE *pNext;
82 /** Cached image size. */
83 uint64_t cbImage;
84 /** Container base filename. (UTF-8) */
85 char *pszFilename;
86 /** Data managed by the backend which keeps the actual info. */
87 void *pBackendData;
88 /** Cached sanitized image flags. */
89 unsigned uImageFlags;
90 /** Image open flags (only those handled generically in this code and which
91 * the backends will never ever see). */
92 unsigned uOpenFlags;
93
94 /** Function pointers for the various backend methods. */
95 PCVDIMAGEBACKEND Backend;
96 /** Pointer to list of VD interfaces, per-image. */
97 PVDINTERFACE pVDIfsImage;
98 /** I/O related things. */
99 VDIO VDIo;
100} VDIMAGE, *PVDIMAGE;
101
102/** The special uninitialized size value for he image. */
103#define VD_IMAGE_SIZE_UNINITIALIZED UINT64_C(0)
104
105/**
106 * Virtual disk cache image descriptor.
107 */
108typedef struct VDCACHE
109{
110 /** Cache base filename. (UTF-8) */
111 char *pszFilename;
112 /** Data managed by the backend which keeps the actual info. */
113 void *pBackendData;
114 /** Cached sanitized image flags. */
115 unsigned uImageFlags;
116 /** Image open flags (only those handled generically in this code and which
117 * the backends will never ever see). */
118 unsigned uOpenFlags;
119
120 /** Function pointers for the various backend methods. */
121 PCVDCACHEBACKEND Backend;
122
123 /** Pointer to list of VD interfaces, per-cache. */
124 PVDINTERFACE pVDIfsCache;
125 /** I/O related things. */
126 VDIO VDIo;
127} VDCACHE, *PVDCACHE;
128
129/**
130 * A block waiting for a discard.
131 */
132typedef struct VDDISCARDBLOCK
133{
134 /** AVL core. */
135 AVLRU64NODECORE Core;
136 /** LRU list node. */
137 RTLISTNODE NodeLru;
138 /** Number of bytes to discard. */
139 size_t cbDiscard;
140 /** Bitmap of allocated sectors. */
141 void *pbmAllocated;
142} VDDISCARDBLOCK, *PVDDISCARDBLOCK;
143
144/**
145 * VD discard state.
146 */
147typedef struct VDDISCARDSTATE
148{
149 /** Number of bytes waiting for a discard. */
150 size_t cbDiscarding;
151 /** AVL tree with blocks waiting for a discard.
152 * The uOffset + cbDiscard range is the search key. */
153 PAVLRU64TREE pTreeBlocks;
154 /** LRU list of the least frequently discarded blocks.
155 * If there are to many blocks waiting the least frequently used
156 * will be removed and the range will be set to 0.
157 */
158 RTLISTNODE ListLru;
159} VDDISCARDSTATE, *PVDDISCARDSTATE;
160
161/**
162 * VD filter instance.
163 */
164typedef struct VDFILTER
165{
166 /** List node for the read filter chain. */
167 RTLISTNODE ListNodeChainRead;
168 /** List node for the write filter chain. */
169 RTLISTNODE ListNodeChainWrite;
170 /** Number of references to this filter. */
171 uint32_t cRefs;
172 /** Opaque VD filter backend instance data. */
173 void *pvBackendData;
174 /** Pointer to the filter backend interface. */
175 PCVDFILTERBACKEND pBackend;
176 /** Pointer to list of VD interfaces, per-filter. */
177 PVDINTERFACE pVDIfsFilter;
178 /** I/O related things. */
179 VDIO VDIo;
180} VDFILTER;
181/** Pointer to a VD filter instance. */
182typedef VDFILTER *PVDFILTER;
183
184/**
185 * Virtual disk container main structure, private part.
186 */
187struct VDISK
188{
189 /** Structure signature (VDISK_SIGNATURE). */
190 uint32_t u32Signature;
191
192 /** Image type. */
193 VDTYPE enmType;
194
195 /** Number of opened images. */
196 unsigned cImages;
197
198 /** Base image. */
199 PVDIMAGE pBase;
200
201 /** Last opened image in the chain.
202 * The same as pBase if only one image is used. */
203 PVDIMAGE pLast;
204
205 /** If a merge to one of the parents is running this may be non-NULL
206 * to indicate to what image the writes should be additionally relayed. */
207 PVDIMAGE pImageRelay;
208
209 /** Flags representing the modification state. */
210 unsigned uModified;
211
212 /** Cached size of this disk. */
213 uint64_t cbSize;
214 /** Cached PCHS geometry for this disk. */
215 VDGEOMETRY PCHSGeometry;
216 /** Cached LCHS geometry for this disk. */
217 VDGEOMETRY LCHSGeometry;
218
219 /** Pointer to list of VD interfaces, per-disk. */
220 PVDINTERFACE pVDIfsDisk;
221 /** Pointer to the common interface structure for error reporting. */
222 PVDINTERFACEERROR pInterfaceError;
223 /** Pointer to the optional thread synchronization callbacks. */
224 PVDINTERFACETHREADSYNC pInterfaceThreadSync;
225
226 /** Memory cache for I/O contexts */
227 RTMEMCACHE hMemCacheIoCtx;
228 /** Memory cache for I/O tasks. */
229 RTMEMCACHE hMemCacheIoTask;
230 /** An I/O context is currently using the disk structures
231 * Every I/O context must be placed on one of the lists below. */
232 volatile bool fLocked;
233 /** Head of pending I/O tasks waiting for completion - LIFO order. */
234 volatile PVDIOTASK pIoTasksPendingHead;
235 /** Head of newly queued I/O contexts - LIFO order. */
236 volatile PVDIOCTX pIoCtxHead;
237 /** Head of halted I/O contexts which are given back to generic
238 * disk framework by the backend. - LIFO order. */
239 volatile PVDIOCTX pIoCtxHaltedHead;
240
241 /** Head of blocked I/O contexts, processed only
242 * after pIoCtxLockOwner was freed - LIFO order. */
243 volatile PVDIOCTX pIoCtxBlockedHead;
244 /** I/O context which locked the disk for a growing write or flush request.
245 * Other flush or growing write requests need to wait until
246 * the current one completes. - NIL_VDIOCTX if unlocked. */
247 volatile PVDIOCTX pIoCtxLockOwner;
248 /** If the disk was locked by a growing write, flush or discard request this
249 * contains the start offset to check for interfering I/O while it is in progress. */
250 uint64_t uOffsetStartLocked;
251 /** If the disk was locked by a growing write, flush or discard request this contains
252 * the first non affected offset to check for interfering I/O while it is in progress. */
253 uint64_t uOffsetEndLocked;
254
255 /** Pointer to the L2 disk cache if any. */
256 PVDCACHE pCache;
257 /** Pointer to the discard state if any. */
258 PVDDISCARDSTATE pDiscard;
259
260 /** Read filter chain - PVDFILTER. */
261 RTLISTANCHOR ListFilterChainRead;
262 /** Write filter chain - PVDFILTER. */
263 RTLISTANCHOR ListFilterChainWrite;
264};
265
266
267DECLHIDDEN(int) vdPluginInit(void);
268DECLHIDDEN(int) vdPluginTerm(void);
269DECLHIDDEN(bool) vdPluginIsInitialized(void);
270DECLHIDDEN(int) vdPluginUnloadFromPath(const char *pszPath);
271DECLHIDDEN(int) vdPluginUnloadFromFilename(const char *pszFilename);
272DECLHIDDEN(int) vdPluginLoadFromPath(const char *pszPath);
273DECLHIDDEN(int) vdPluginLoadFromFilename(const char *pszFilename);
274
275DECLHIDDEN(uint32_t) vdGetImageBackendCount(void);
276DECLHIDDEN(int) vdQueryImageBackend(uint32_t idx, PCVDIMAGEBACKEND *ppBackend);
277DECLHIDDEN(int) vdFindImageBackend(const char *pszBackend, PCVDIMAGEBACKEND *ppBackend);
278DECLHIDDEN(uint32_t) vdGetCacheBackendCount(void);
279DECLHIDDEN(int) vdQueryCacheBackend(uint32_t idx, PCVDCACHEBACKEND *ppBackend);
280DECLHIDDEN(int) vdFindCacheBackend(const char *pszBackend, PCVDCACHEBACKEND *ppBackend);
281DECLHIDDEN(uint32_t) vdGetFilterBackendCount(void);
282DECLHIDDEN(int) vdQueryFilterBackend(uint32_t idx, PCVDFILTERBACKEND *ppBackend);
283DECLHIDDEN(int) vdFindFilterBackend(const char *pszFilter, PCVDFILTERBACKEND *ppBackend);
284
285DECLHIDDEN(int) vdIoIterQueryStartNext(VDIOITER hVdIoIter, uint64_t *pu64Start);
286DECLHIDDEN(int) vdIoIterQuerySegSizeByStart(VDIOITER hVdIoIter, uint64_t u64Start, size_t *pcRegSize);
287DECLHIDDEN(int) vdIoIterAdvance(VDIOITER hVdIoIter, uint64_t cBlocksOrBytes);
288
289#endif /* !VBOX_INCLUDED_SRC_Storage_VDInternal_h */
290
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