VirtualBox

Changeset 3113 in vbox for trunk/src


Ignore:
Timestamp:
Jun 14, 2007 6:29:54 PM (18 years ago)
Author:
vboxsync
Message:

Implement virtual paperclip (forced unmounting of media, currently
unused) and non-fatal error when media is not available on powerup.

Location:
trunk/src/VBox
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevATA.cpp

    r2981 r3113  
    25262526                        PVMREQ pReq;
    25272527                        rc = VMR3ReqCall(PDMDevHlpGetVM(pDevIns), &pReq, RT_INDEFINITE_WAIT,
    2528                                          (PFNRT)s->pDrvMount->pfnUnmount, 1, s->pDrvMount);
     2528                                         (PFNRT)s->pDrvMount->pfnUnmount, 2, s->pDrvMount, false);
    25292529                        AssertReleaseRC(rc);
    25302530                        VMR3ReqFree(pReq);
  • trunk/src/VBox/Devices/Storage/DrvBlock.cpp

    r2981 r3113  
    509509
    510510/** @copydoc PDMIMOUNT::pfnUnmount */
    511 static DECLCALLBACK(int) drvblockUnmount(PPDMIMOUNT pInterface)
     511static DECLCALLBACK(int) drvblockUnmount(PPDMIMOUNT pInterface, bool fForce)
    512512{
    513513    PDRVBLOCK pData = PDMIMOUNT_2_DRVBLOCK(pInterface);
     
    521521        return VERR_PDM_MEDIA_NOT_MOUNTED;
    522522    }
    523     if (pData->fLocked)
     523    if (pData->fLocked && !fForce)
    524524    {
    525525        Log(("drvblockUmount: Locked\n"));
    526526        return VERR_PDM_MEDIA_LOCKED;
    527527    }
     528
     529    /* Media is no longer locked even if it was previously. */
     530    pData->fLocked = false;
    528531
    529532    /*
  • trunk/src/VBox/Devices/Storage/DrvHostBase.cpp

    r2981 r3113  
    457457
    458458/** @copydoc PDMIMOUNT::pfnUnmount */
    459 static DECLCALLBACK(int) drvHostBaseUnmount(PPDMIMOUNT pInterface)
     459static DECLCALLBACK(int) drvHostBaseUnmount(PPDMIMOUNT pInterface, bool fForce)
    460460{
    461461     LogFlow(("drvHostBaseUnmount: returns VERR_NOT_SUPPORTED\n"));
     
    567567/**
    568568 * Gets the BSD Name (/dev/disc[0-9]+) for the service.
    569  * 
    570  * This is done by recursing down the I/O registry until we hit upon an entry 
    571  * with a BSD Name. Usually we find it two levels down. (Further down under 
     569 *
     570 * This is done by recursing down the I/O registry until we hit upon an entry
     571 * with a BSD Name. Usually we find it two levels down. (Further down under
    572572 * the IOCDPartitionScheme, the volume (slices) BSD Name is found. We don't
    573573 * seem to have to go this far fortunately.)
    574  * 
     574 *
    575575 * @return  VINF_SUCCESS if found, VERR_FILE_NOT_FOUND otherwise.
    576576 * @param   Entry       The current I/O registry entry reference.
    577577 * @param   pszName     Where to store the name. 128 bytes.
    578  * @param   cRecursions Number of recursions. This is used as an precation 
     578 * @param   cRecursions Number of recursions. This is used as an precation
    579579 *                      just to limit the depth and avoid blowing the stack
    580580 *                      should we hit a bug or something.
     
    610610
    611611
    612 /** 
     612/**
    613613 * Callback notifying us that the async DADiskClaim()/DADiskUnmount call has completed.
    614  * 
     614 *
    615615 * @param   DiskRef         The disk that was attempted claimed / unmounted.
    616616 * @param   DissenterRef    NULL on success, contains details on failure.
     
    630630/**
    631631 * Obtain exclusive access to the DVD device, umount it if necessary.
    632  * 
     632 *
    633633 * @return  VBox status code.
    634634 * @param   pThis       The driver instance.
     
    644644        if (irc == kIOReturnSuccess)
    645645        {
    646             /* 
     646            /*
    647647             * This is a bit weird, but if we unmounted the DVD drive we also need to
    648648             * unlock it afterwards or the guest won't be able to eject it later on.
     
    661661        if (irc == kIOReturnExclusiveAccess)
    662662            return VERR_SHARING_VIOLATION;      /* already used exclusivly. */
    663         if (irc != kIOReturnBusy) 
     663        if (irc != kIOReturnBusy)
    664664            return VERR_GENERAL_FAILURE;        /* not mounted */
    665665
    666666        /*
    667667         * Attempt to the unmount all volumes of the device.
    668          * It seems we can can do this all in one go without having to enumerate the 
    669          * volumes (sessions) and deal with them one by one. This is very fortuitous 
     668         * It seems we can can do this all in one go without having to enumerate the
     669         * volumes (sessions) and deal with them one by one. This is very fortuitous
    670670         * as the disk arbitration API is a bit cumbersome to deal with.
    671671         */
     
    683683                if (pThis->pDADisk)
    684684                {
    685                     /* 
     685                    /*
    686686                     * Try claim the device.
    687687                     */
     
    717717                    else
    718718                        Log(("%s-%d: claim => rc32=%d & rcDA=%#x\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc32, rcDA));
    719                    
     719
    720720                    CFRelease(pThis->pDADisk);
    721721                    pThis->pDADisk = NULL;
     
    15011501
    15021502#ifdef __DARWIN__
    1503     /* 
    1504      * The unclaiming doesn't seem to mean much, the DVD is actaully 
     1503    /*
     1504     * The unclaiming doesn't seem to mean much, the DVD is actaully
    15051505     * remounted when we release exclusive access. I'm not quite sure
    15061506     * if I should put the unclaim first or not...
     
    15631563    }
    15641564
    1565     if (RTCritSectIsInitialized(&pThis->CritSect))
     1565    /* Forget about the notifications. */
     1566    pThis->pDrvMountNotify = NULL;
     1567
     1568    /* Leave the instance operational if this is just a cleanup of the state
     1569     * after an attach error happened. So don't destry the critsect then. */
     1570    if (!pThis->fKeepInstance && RTCritSectIsInitialized(&pThis->CritSect))
    15661571        RTCritSectDelete(&pThis->CritSect);
    15671572    LogFlow(("%s-%d: drvHostBaseDestruct completed\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
     
    15911596     */
    15921597    pThis->pDrvIns                          = pDrvIns;
     1598    pThis->fKeepInstance                    = false;
    15931599    pThis->ThreadPoller                     = NIL_RTTHREAD;
    15941600#ifdef __DARWIN__
     
    17221728    }
    17231729
     1730    /* Define whether attach failure is an error (default) or not. */
     1731    bool fAttachFailError;
     1732    rc = CFGMR3QueryBool(pCfgHandle, "AttachFailError", &fAttachFailError);
     1733    if (VBOX_FAILURE(rc))
     1734        fAttachFailError = true;
     1735    pThis->fAttachFailError = fAttachFailError;
     1736
    17241737    /* name to open & watch for */
    17251738#ifdef __WIN__
     
    17541767int DRVHostBaseInitFinish(PDRVHOSTBASE pThis)
    17551768{
     1769    int src = VINF_SUCCESS;
    17561770    PPDMDRVINS pDrvIns = pThis->pDrvIns;
    17571771
     
    18511865                       pszDevice);
    18521866            default:
    1853                 return rc;
     1867                if (pThis->fAttachFailError)
     1868                    return rc;
     1869                else
     1870                {
     1871                    int erc = PDMDrvHlpVMSetRuntimeError(pDrvIns,
     1872                                                         false, "DrvHost_MOUNTFAIL",
     1873                                                         N_("Cannot attach to host device '%s'"), pszDevice);
     1874                    AssertRC(erc);
     1875                    src = rc;
     1876                }
    18541877        }
    18551878    }
    18561879#ifdef __WIN__
    1857     DRVHostBaseMediaPresent(pThis);
     1880    if (VBOX_SUCCESS(src))
     1881        DRVHostBaseMediaPresent(pThis);
    18581882#endif
    18591883
     
    18731897
    18741898#ifndef __WIN__
    1875     /*
    1876      * Create the event semaphore which the poller thread will wait on.
    1877      */
    1878     rc = RTSemEventCreate(&pThis->EventPoller);
    1879     if (VBOX_FAILURE(rc))
    1880         return rc;
     1899    if (VBOX_SUCCESS(src))
     1900    {
     1901        /*
     1902         * Create the event semaphore which the poller thread will wait on.
     1903         */
     1904        rc = RTSemEventCreate(&pThis->EventPoller);
     1905        if (VBOX_FAILURE(rc))
     1906            return rc;
     1907    }
    18811908#endif
    18821909
     
    18881915        return rc;
    18891916
    1890     /*
    1891      * Start the thread which will poll for the media.
    1892      */
    1893     rc = RTThreadCreate(&pThis->ThreadPoller, drvHostBaseMediaThread, pThis, 0,
    1894                         RTTHREADTYPE_INFREQUENT_POLLER, RTTHREADFLAGS_WAITABLE, "DVDMEDIA");
    1895     if (VBOX_FAILURE(rc))
    1896     {
    1897         AssertMsgFailed(("Failed to create poller thread. rc=%Vrc\n", rc));
     1917    if (VBOX_SUCCESS(src))
     1918    {
     1919        /*
     1920         * Start the thread which will poll for the media.
     1921         */
     1922        rc = RTThreadCreate(&pThis->ThreadPoller, drvHostBaseMediaThread, pThis, 0,
     1923                            RTTHREADTYPE_INFREQUENT_POLLER, RTTHREADFLAGS_WAITABLE, "DVDMEDIA");
     1924        if (VBOX_FAILURE(rc))
     1925        {
     1926            AssertMsgFailed(("Failed to create poller thread. rc=%Vrc\n", rc));
     1927            return rc;
     1928        }
     1929
     1930        /*
     1931         * Wait for the thread to start up (!w32:) and do one detection loop.
     1932         */
     1933        rc = RTThreadUserWait(pThis->ThreadPoller, 10000);
     1934        AssertRC(rc);
     1935#ifdef __WIN__
     1936        if (!pThis->hwndDeviceChange)
     1937            return VERR_GENERAL_FAILURE;
     1938#endif
     1939    }
     1940
     1941    if (VBOX_FAILURE(src))
     1942        return src;
     1943    else
    18981944        return rc;
    1899     }
    1900 
    1901     /*
    1902      * Wait for the thread to start up (!w32:) and do one detection loop.
    1903      */
    1904     rc = RTThreadUserWait(pThis->ThreadPoller, 10000);
    1905     AssertRC(rc);
    1906 #ifdef __WIN__
    1907     if (!pThis->hwndDeviceChange)
    1908         return VERR_GENERAL_FAILURE;
    1909 #endif
    1910 
    1911     return rc;
    1912 }
    1913 
     1945}
     1946
  • trunk/src/VBox/Devices/Storage/DrvHostBase.h

    r2981 r3113  
    4949    /** The current readonly status. */
    5050    bool                    fReadOnly;
     51    /** Flag whether failure to attach is an error or not. */
     52    bool                    fAttachFailError;
     53    /** Flag whether to keep instance working (as unmounted though). */
     54    bool                    fKeepInstance;
    5155    /** Device name (MMHeap). */
    5256    char                   *pszDevice;
  • trunk/src/VBox/Devices/Storage/DrvHostDVD.cpp

    r2981 r3113  
    8181
    8282
     83/* Forward declarations. */
     84
     85static DECLCALLBACK(int) drvHostDvdDoLock(PDRVHOSTBASE pThis, bool fLock);
    8386
    8487
    8588/** @copydoc PDMIMOUNT::pfnUnmount */
    86 static DECLCALLBACK(int) drvHostDvdUnmount(PPDMIMOUNT pInterface)
     89static DECLCALLBACK(int) drvHostDvdUnmount(PPDMIMOUNT pInterface, bool fForce)
    8790{
    8891     PDRVHOSTBASE pThis = PDMIMOUNT_2_DRVHOSTBASE(pInterface);
     
    9396      */
    9497     int rc = VINF_SUCCESS;
    95      if (!pThis->fLocked)
     98     if (!pThis->fLocked || fForce)
    9699     {
     100        /* Unlock drive if necessary. */
     101        if (pThis->fLocked)
     102            drvHostDvdDoLock(pThis, false);
     103
    97104         /*
    98105          * Eject the disc.
     
    498505     * Validate configuration.
    499506     */
    500     if (!CFGMR3AreValuesValid(pCfgHandle, "Path\0Interval\0Locked\0BIOSVisible\0Passthrough\0"))
     507    if (!CFGMR3AreValuesValid(pCfgHandle, "Path\0Interval\0Locked\0BIOSVisible\0AttachFailError\0Passthrough\0"))
    501508        return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
    502509
     
    539546         */
    540547        rc = DRVHostBaseInitFinish(pThis);
    541         if (VBOX_SUCCESS(rc))
     548    }
     549
     550    if (VBOX_FAILURE(rc))
     551    {
     552        if (!pThis->fAttachFailError)
    542553        {
    543             LogFlow(("drvHostDvdConstruct: return %Vrc\n", rc));
    544             return rc;
     554            /* Suppressing the attach failure error must not affect the normal
     555             * DRVHostBaseDestruct, so reset this flag below before leaving. */
     556            pThis->fKeepInstance = true;
     557            rc = VINF_SUCCESS;
    545558        }
    546     }
    547     DRVHostBaseDestruct(pDrvIns);
     559        DRVHostBaseDestruct(pDrvIns);
     560        pThis->fKeepInstance = false;
     561    }
    548562
    549563    LogFlow(("drvHostDvdConstruct: returns %Vrc\n", rc));
  • trunk/src/VBox/Devices/Storage/DrvHostFloppy.cpp

    r2981 r3113  
    181181         */
    182182        rc = DRVHostBaseInitFinish(&pThis->Base);
    183         if (VBOX_SUCCESS(rc))
     183    }
     184    if (VBOX_FAILURE(rc))
     185    {
     186        if (!pThis->Base.fAttachFailError)
    184187        {
    185             LogFlow(("drvHostFloppyConstruct: return %Vrc\n", rc));
    186             return rc;
     188            /* Suppressing the attach failure error must not affect the normal
     189             * DRVHostBaseDestruct, so reset this flag below before leaving. */
     190            pThis->Base.fKeepInstance = true;
     191            rc = VINF_SUCCESS;
    187192        }
    188     }
    189     DRVHostBaseDestruct(pDrvIns);
     193        DRVHostBaseDestruct(pDrvIns);
     194        pThis->Base.fKeepInstance = false;
     195    }
    190196
    191197    LogFlow(("drvHostFloppyConstruct: returns %Vrc\n", rc));
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r3086 r3113  
    28392839                 * Unmount the media.
    28402840                 */
    2841                 rc = pIMount->pfnUnmount (pIMount);
     2841                rc = pIMount->pfnUnmount (pIMount, false);
    28422842                if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
    28432843                    rc = VINF_SUCCESS;
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