VirtualBox

Changeset 56967 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 17, 2015 1:07:09 PM (9 years ago)
Author:
vboxsync
Message:

Devices/Storage: Keep track of used host block devices and prevent the host from opening any device while it is still in use by VBox on OS X

Location:
trunk/src/VBox/Devices
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Makefile.kmk

    r56945 r56967  
    195195 endif
    196196
     197 ifn1of ($(KBUILD_TARGET), darwin)
     198  VBoxDD_SOURCES += Storage/HBDMgmt-generic.cpp
     199 endif
     200
     201 VBoxDD_SOURCES.darwin += Storage/HBDMgmt-darwin.cpp
     202
    197203 VBoxDD_LIBS             = # more later.
    198204 VBoxDD_LDFLAGS.darwin   = -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/VBoxDD.dylib \
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r55964 r56967  
    5252#endif /* VBOX_WITH_INIP */
    5353
     54#include "HBDMgmt.h"
     55
    5456#include "VBoxDD.h"
    5557
     
    187189    /** The block cache handle if configured. */
    188190    PPDMBLKCACHE             pBlkCache;
     191    /** Host block device manager. */
     192    HBDMGR                   hHbdMgr;
    189193
    190194    /** Cryptographic support
     
    350354{
    351355    PVBOXDISK pThis = (PVBOXDISK)pvUser;
    352     PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)RTMemAllocZ(sizeof(DRVVDSTORAGEBACKEND));
     356    PDRVVDSTORAGEBACKEND pStorageBackend = NULL;
    353357    int rc = VINF_SUCCESS;
    354358
     359    /*
     360     * Check whether the backend wants to open a block device and try to prepare it
     361     * if we didn't claim it yet.
     362     *
     363     * We only create a block device manager on demand to not waste any resources.
     364     */
     365    if (HBDMgrIsBlockDevice(pszLocation))
     366    {
     367        if (pThis->hHbdMgr == NIL_HBDMGR)
     368            rc = HBDMgrCreate(&pThis->hHbdMgr);
     369
     370        if (   RT_SUCCESS(rc)
     371            && !HBDMgrIsBlockDeviceClaimed(pThis->hHbdMgr, pszLocation))
     372            rc = HBDMgrClaimBlockDevice(pThis->hHbdMgr, pszLocation);
     373
     374        if (RT_FAILURE(rc))
     375            return rc;
     376    }
     377
     378    pStorageBackend = (PDRVVDSTORAGEBACKEND)RTMemAllocZ(sizeof(DRVVDSTORAGEBACKEND));
    355379    if (pStorageBackend)
    356380    {
     
    415439    PDRVVDSTORAGEBACKEND pStorageBackend = (PDRVVDSTORAGEBACKEND)pStorage;
    416440
     441    /*
     442     * We don't unclaim any block devices on purpose here because they
     443     * might get reopened shortly (switching to readonly during suspend)
     444     *
     445     * Block devices will get unclaimed during destruction of the driver.
     446     */
     447
    417448    PDMR3AsyncCompletionEpClose(pStorageBackend->pEndpoint);
    418449    PDMR3AsyncCompletionTemplateDestroy(pStorageBackend->pTemplate);
    419450    RTSemEventDestroy(pStorageBackend->EventSem);
    420451    RTMemFree(pStorageBackend);
    421 
    422452    return VINF_SUCCESS;;
    423453}
     
    25042534        pThis->pszBwGroup = NULL;
    25052535    }
     2536    if (pThis->hHbdMgr != NIL_HBDMGR)
     2537        HBDMgrDestroy(pThis->hHbdMgr);
    25062538}
    25072539
Note: See TracChangeset for help on using the changeset viewer.

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