VirtualBox

Ignore:
Timestamp:
Jun 14, 2007 6:29:54 PM (17 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
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