VirtualBox

Changeset 38621 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Sep 4, 2011 4:56:56 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73828
Message:

VD: Initial support to discard unused blocks in an image + support for VDI images

Location:
trunk/include/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/err.h

    r37794 r38621  
    13341334/** The cache is not up to date with the image. */
    13351335#define VERR_VD_CACHE_NOT_UP_TO_DATE                (-3276)
     1336/** The given range does not meet the required alignment. */
     1337#define VERR_VD_DISCARD_ALIGNMENT_NOT_MET           (-3277)
     1338/** The discard operation is not supported for this image. */
     1339#define VERR_VD_DISCARD_NOT_SUPPORTED               (-3278)
    13361340/** @} */
    13371341
  • trunk/include/VBox/vd-plugin.h

    r38469 r38621  
    44
    55/*
    6  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2011 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4040/** @}*/
    4141
     42/** @name VBox HDD backend discard flags
     43 * @{
     44 */
     45/** Don't discard block but mark the given range as unused
     46 * (usually by writing 0's to it).
     47 * This doesn't require the range to be aligned on a block boundary but
     48 * the image size might not be decreased. */
     49#define VD_DISCARD_MARK_UNUSED RT_BIT(0)
     50/** @}*/
     51
    4252
    4353/**
     
    540550     *
    541551     * @returns VBox status code.
    542      * @returns VERR_NOT_SUPPORTED if this image cannot be compacted yet.
     552     * @returns VERR_NOT_SUPPORTED if this image cannot be resized yet.
    543553     * @param   pBackendData    Opaque state data for this image.
    544554     * @param   cbSize          New size of the image.
     
    559569                                          PVDINTERFACE pVDIfsImage,
    560570                                          PVDINTERFACE pVDIfsOperation));
     571
     572    /**
     573     * Discards the given amount of bytes decreasing the size of the image if possible.
     574     *
     575     * @returns VBox status code.
     576     * @retval  VERR_VD_DISCARD_ALIGNMENT_NOT_MET if the range doesn't meet the required alignment
     577     *          for the discard.
     578     * @param   pBackendData         Opaque state data for this image.
     579     * @param   uOffset              The offset of the first byte to discard.
     580     * @param   cbDiscard            How many bytes to discard.
     581     * @param   pcbPreAllocated      Pointer to the returned amount of bytes that must
     582     *                               be discarded before the range to perform a full
     583     *                               block discard.
     584     * @param   pcbPostAllocated     Pointer to the returned amount of bytes that must
     585     *                               be discarded after the range to perform a full
     586     *                               block discard.
     587     * @param   pcbActuallyDiscarded Pointer to the returned amount of bytes which
     588     *                               could be actually discarded.
     589     * @param   ppbmAllocationBitmap Where to store the pointer to the allocation bitmap
     590     *                               if VERR_VD_DISCARD_ALIGNMENT_NOT_MET is returned or NULL
     591     *                               if the allocation bitmap should be returned.
     592     * @param   fDiscard             Flags which affect discard behavior. Combination
     593     *                               of the VD_DISCARD_* flags.
     594     */
     595    DECLR3CALLBACKMEMBER(int, pfnDiscard, (void *pBackendData,
     596                                           uint64_t uOffset, size_t cbDiscard,
     597                                           size_t *pcbPreAllocated,
     598                                           size_t *pcbPostAllocated,
     599                                           size_t *pcbActuallyDiscarded,
     600                                           void   **ppbmAllocationBitmap,
     601                                           unsigned fDiscard));
    561602
    562603} VBOXHDDBACKEND;
  • trunk/include/VBox/vd.h

    r38469 r38621  
    44
    55/*
    6  * Copyright (C) 2006-2010 Oracle Corporation
     6 * Copyright (C) 2006-2011 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    180180 * will not fail if it cannot do this, the flag will be simply ignored. */
    181181#define VD_OPEN_FLAGS_SEQUENTIAL    RT_BIT(6)
     182/** Allow the discard operation if supported. Only available if VD_CAP_DISCARD
     183 * is set. VDOpen fails with VERR_VD_DISCARD_NOT_SUPPORTED if discarding is not
     184 * supported. */
     185#define VD_OPEN_FLAGS_DISCARD       RT_BIT(7)
    182186/** Mask of valid flags. */
    183 #define VD_OPEN_FLAGS_MASK          (VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_HONOR_ZEROES | VD_OPEN_FLAGS_HONOR_SAME | VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE | VD_OPEN_FLAGS_SEQUENTIAL)
     187#define VD_OPEN_FLAGS_MASK          (VD_OPEN_FLAGS_NORMAL | VD_OPEN_FLAGS_READONLY | VD_OPEN_FLAGS_HONOR_ZEROES | VD_OPEN_FLAGS_HONOR_SAME | VD_OPEN_FLAGS_INFO | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_DISCARD)
    184188/** @}*/
    185189
     
    249253 * VDINTERFACEIO exclusively for all file operations. */
    250254#define VD_CAP_VFS                  RT_BIT(9)
     255/** The backend supports the discard operation. */
     256#define VD_CAP_DISCARD              RT_BIT(10)
    251257/** @}*/
    252258
     
    392398
    393399/**
     400 * VD range descriptor.
     401 */
     402typedef struct VDRANGE
     403{
     404    /** Start offset in bytes, multiple of 512. */
     405    uint64_t    offStart;
     406    /** Amount of bytes described by this range, multiple of 512. */
     407    size_t      cbRange;
     408} VDRANGE;
     409
     410/** Pointer to a range descriptor. */
     411typedef VDRANGE *PVDRANGE;
     412/** Pointer to a constant range descriptor. */
     413typedef const VDRANGE *PCVDRANGE;
     414
     415/**
    394416 * VBox HDD Container main structure.
    395417 */
     
    10901112
    10911113/**
     1114 * Discards unused ranges given as a list.
     1115 *
     1116 * @return  VBox status code.
     1117 * @param   pDisk           Pointer to HDD container.
     1118 * @param   paRanges        The array of ranges to discard.
     1119 * @param   cRanges         Number of entries in the array.
     1120 *
     1121 * @note In contrast to VDCompact() the ranges are always discarded even if they
     1122 *       appear to contain data. This method is mainly used to implement TRIM support.
     1123 */
     1124VBOXDDU_DECL(int) VDDiscardRanges(PVBOXHDD pDisk, PCVDRANGE paRanges, unsigned cRanges);
     1125
     1126
     1127/**
    10921128 * Start an asynchronous read request.
    10931129 *
Note: See TracChangeset for help on using the changeset viewer.

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