VirtualBox

Changeset 31456 in vbox


Ignore:
Timestamp:
Aug 8, 2010 1:46:41 PM (14 years ago)
Author:
vboxsync
Message:

VBoxHDD: Make the non blocking read/write socket APIs available in the VDTCPNET interface

Location:
trunk
Files:
3 edited

Legend:

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

    r31185 r31456  
    11411141
    11421142    /**
     1143     * Receive data from a socket - not blocking.
     1144     *
     1145     * @return  iprt status code.
     1146     * @param   Sock        Socket descriptor.
     1147     * @param   pvBuffer    Where to put the data we read.
     1148     * @param   cbBuffer    Read buffer size.
     1149     * @param   pcbRead     Number of bytes read.
     1150     */
     1151    DECLR3CALLBACKMEMBER(int, pfnReadNB, (VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead));
     1152
     1153    /**
     1154     * Send data to a socket - not blocking.
     1155     *
     1156     * @return  iprt status code.
     1157     * @param   Sock        Socket descriptor.
     1158     * @param   pvBuffer    Buffer to write data to socket.
     1159     * @param   cbBuffer    How much to write.
     1160     * @param   pcbWritten  Number of bytes written.
     1161     */
     1162    DECLR3CALLBACKMEMBER(int, pfnWriteNB, (VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten));
     1163
     1164    /**
     1165     * Send data from scatter/gather buffer to a socket - not blocking.
     1166     *
     1167     * @return  iprt status code.
     1168     * @param   Sock        Socket descriptor.
     1169     * @param   pSgBuf      Scatter/gather buffer to write data to socket.
     1170     * @param   pcbWritten  Number of bytes written.
     1171     */
     1172    DECLR3CALLBACKMEMBER(int, pfnSgWriteNB, (VDSOCKET Sock, PRTSGBUF pSgBuf, size_t *pcbWritten));
     1173
     1174    /**
    11431175     * Flush socket write buffers.
    11441176     *
     
    11821214     * @retval  VERR_INTERRUPTED if the thread was woken up by a pfnPoke call.
    11831215     * @param   Sock        Socket descriptor.
     1216     * @param   fEvents     Mask of events to wait for.
    11841217     * @param   pfEvents    Where to store the received events.
    11851218     * @param   cMillies    Number of milliseconds to wait for the socket.
    11861219     *                      Use RT_INDEFINITE_WAIT to wait for ever.
    11871220     */
    1188     DECLR3CALLBACKMEMBER(int, pfnSelectOneEx, (VDSOCKET Sock, uint32_t *pfEvents, RTMSINTERVAL cMillies));
     1221    DECLR3CALLBACKMEMBER(int, pfnSelectOneEx, (VDSOCKET Sock, uint32_t fEvents,
     1222                                               uint32_t *pfEvents, RTMSINTERVAL cMillies));
    11891223
    11901224    /**
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r31186 r31456  
    910910
    911911/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
    912 static DECLCALLBACK(int) drvvdINIPSelectOneEx(VDSOCKET Sock, uint32_t *pfEvents, RTMSINTERVAL cMillies)
     912static DECLCALLBACK(int) drvvdINIPSelectOneEx(VDSOCKET Sock, uint32_t fEvents, uint32_t *pfEvents, RTMSINTERVAL cMillies)
    913913{
    914914    AssertMsgFailed(("Not supported!\n"));
     
    947947    /** Flag whether the thread is waiting in the select call. */
    948948    volatile bool fWaiting;
     949    /** Old event mask. */
     950    uint32_t      fEventsOld;
    949951} VDSOCKETINT, *PVDSOCKETINT;
    950952
     
    10501052        if (pSockInt->hPollSet != NIL_RTPOLLSET)
    10511053        {
     1054            pSockInt->fEventsOld = RTPOLL_EVT_READ | RTPOLL_EVT_WRITE | RTPOLL_EVT_ERROR;
     1055
    10521056            rc = RTPollSetAddSocket(pSockInt->hPollSet, pSockInt->hSocket,
    1053                                     RTPOLL_EVT_READ | /*RTPOLL_EVT_WRITE |*/ RTPOLL_EVT_ERROR,
    1054                                     VDSOCKET_POLL_ID_SOCKET);
     1057                                    pSockInt->fEventsOld, VDSOCKET_POLL_ID_SOCKET);
    10551058
    10561059            if (RT_SUCCESS(rc))
     
    11221125}
    11231126
     1127/** @copydoc VDINTERFACETCPNET::pfnReadNB */
     1128static DECLCALLBACK(int) drvvdTcpReadNB(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead)
     1129{
     1130    PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
     1131
     1132    return RTTcpReadNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbRead);
     1133}
     1134
     1135/** @copydoc VDINTERFACETCPNET::pfnWriteNB */
     1136static DECLCALLBACK(int) drvvdTcpWriteNB(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer, size_t *pcbWritten)
     1137{
     1138    PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
     1139
     1140    return RTTcpWriteNB(pSockInt->hSocket, pvBuffer, cbBuffer, pcbWritten);
     1141}
     1142
     1143/** @copydoc VDINTERFACETCPNET::pfnSgWriteNB */
     1144static DECLCALLBACK(int) drvvdTcpSgWriteNB(VDSOCKET Sock, PRTSGBUF pSgBuf, size_t *pcbWritten)
     1145{
     1146    PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
     1147
     1148    return RTTcpSgWriteNB(pSockInt->hSocket, pSgBuf, pcbWritten);
     1149}
     1150
    11241151/** @copydoc VDINTERFACETCPNET::pfnFlush */
    11251152static DECLCALLBACK(int) drvvdTcpFlush(VDSOCKET Sock)
     
    11551182
    11561183/** @copydoc VDINTERFACETCPNET::pfnSelectOneEx */
    1157 static DECLCALLBACK(int) drvvdTcpSelectOneEx(VDSOCKET Sock, uint32_t *pfEvents, RTMSINTERVAL cMillies)
     1184static DECLCALLBACK(int) drvvdTcpSelectOneEx(VDSOCKET Sock, uint32_t fEvents,
     1185                                             uint32_t *pfEvents, RTMSINTERVAL cMillies)
    11581186{
    11591187    int rc = VINF_SUCCESS;
    11601188    uint32_t id = 0;
    1161     uint32_t fEvents = 0;
     1189    uint32_t fEventsRecv = 0;
    11621190    PVDSOCKETINT pSockInt = (PVDSOCKETINT)Sock;
    11631191
    11641192    *pfEvents = 0;
     1193
     1194    if (pSockInt->fEventsOld != fEvents)
     1195    {
     1196        uint32_t fPollEvents = 0;
     1197
     1198        if (fEvents & VD_INTERFACETCPNET_EVT_READ)
     1199            fPollEvents |= RTPOLL_EVT_READ;
     1200        if (fEvents & VD_INTERFACETCPNET_EVT_WRITE)
     1201            fPollEvents |= RTPOLL_EVT_WRITE;
     1202        if (fEvents & VD_INTERFACETCPNET_EVT_ERROR)
     1203            fPollEvents |= RTPOLL_EVT_ERROR;
     1204
     1205        rc = RTPollSetEventsChange(pSockInt->hPollSet, VDSOCKET_POLL_ID_SOCKET, fPollEvents);
     1206        if (RT_FAILURE(rc))
     1207            return rc;
     1208
     1209        pSockInt->fEventsOld = fEvents;
     1210    }
    11651211
    11661212    ASMAtomicXchgBool(&pSockInt->fWaiting, true);
     
    11711217    }
    11721218
    1173     rc = RTPoll(pSockInt->hPollSet, cMillies, &fEvents, &id);
     1219    rc = RTPoll(pSockInt->hPollSet, cMillies, &fEventsRecv, &id);
    11741220    Assert(RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
    11751221
     
    11801226        if (id == VDSOCKET_POLL_ID_SOCKET)
    11811227        {
    1182             fEvents &= RTPOLL_EVT_VALID_MASK;
    1183 
    1184             if (fEvents & RTPOLL_EVT_READ)
     1228            fEventsRecv &= RTPOLL_EVT_VALID_MASK;
     1229
     1230            if (fEventsRecv & RTPOLL_EVT_READ)
    11851231                *pfEvents |= VD_INTERFACETCPNET_EVT_READ;
    1186             if (fEvents & RTPOLL_EVT_WRITE)
     1232            if (fEventsRecv & RTPOLL_EVT_WRITE)
    11871233                *pfEvents |= VD_INTERFACETCPNET_EVT_WRITE;
    1188             if (fEvents & RTPOLL_EVT_ERROR)
     1234            if (fEventsRecv & RTPOLL_EVT_ERROR)
    11891235                *pfEvents |= VD_INTERFACETCPNET_EVT_ERROR;
    11901236        }
     
    18381884            pThis->VDITcpNetCallbacks.pfnWrite = drvvdTcpWrite;
    18391885            pThis->VDITcpNetCallbacks.pfnSgWrite = drvvdTcpSgWrite;
     1886            pThis->VDITcpNetCallbacks.pfnReadNB = drvvdTcpReadNB;
     1887            pThis->VDITcpNetCallbacks.pfnWriteNB = drvvdTcpWriteNB;
     1888            pThis->VDITcpNetCallbacks.pfnSgWriteNB = drvvdTcpSgWriteNB;
    18401889            pThis->VDITcpNetCallbacks.pfnFlush = drvvdTcpFlush;
    18411890            pThis->VDITcpNetCallbacks.pfnSetSendCoalescing = drvvdTcpSetSendCoalescing;
  • trunk/src/VBox/Devices/Storage/ISCSIHDDCore.cpp

    r31243 r31456  
    476476    /** Config interface callback table. */
    477477    PVDINTERFACECONFIG  pInterfaceConfigCallbacks;
     478    /** I/O interface. */
     479    PVDINTERFACE        pInterfaceIo;
     480    /** I/O interface callback table. */
     481    PVDINTERFACEIO      pInterfaceIoCallbacks;
    478482    /** Image open flags. */
    479483    unsigned            uOpenFlags;
     
    540544    /** Flag whether extended select is supported. */
    541545    bool                fExtendedSelectSupported;
     546    /** Padding used for aligning the PDUs. */
     547    uint8_t             aPadding[4];
     548    /** Socket events to poll for. */
     549    uint32_t            fPollEvents;
    542550} ISCSIIMAGE, *PISCSIIMAGE;
    543551
     
    588596static int iscsiSendPDU(PISCSIIMAGE pImage, PISCSIREQ paReq, uint32_t cnReq, uint32_t uFlags);
    589597static int iscsiRecvPDU(PISCSIIMAGE pImage, uint32_t itt, PISCSIRES paRes, uint32_t cnRes, bool fSelect);
    590 static int drvISCSIValidatePDU(PISCSIRES paRes, uint32_t cnRes);
     598static int iscsiValidatePDU(PISCSIRES paRes, uint32_t cnRes);
    591599static int iscsiTextAddKeyValue(uint8_t *pbBuf, size_t cbBuf, size_t *pcbBufCurr, const char *pcszKey, const char *pcszValue, size_t cbValue);
    592600static int iscsiTextGetKeyValue(const uint8_t *pbBuf, size_t cbBuf, const char *pcszKey, const char **ppcszValue);
     
    18811889            /* Check whether the received PDU is valid, and update the internal state of
    18821890             * the iSCSI connection/session. */
    1883             rc = drvISCSIValidatePDU(&aResBuf, 1);
     1891            rc = iscsiValidatePDU(&aResBuf, 1);
    18841892            if (RT_FAILURE(rc))
    18851893                continue;
     
    20022010 * @param   cnRes       Number of valid iSCSI response sections in the array.
    20032011 */
    2004 static int drvISCSIValidatePDU(PISCSIRES paRes, uint32_t cnRes)
     2012static int iscsiValidatePDU(PISCSIRES paRes, uint32_t cnRes)
    20052013{
    20062014    const uint32_t *pcrgResBHS;
     
    23732381 * Internal. - Wrapper around the extended select callback of the net interface.
    23742382 */
    2375 DECLINLINE(int) iscsiIoThreadWait(PISCSIIMAGE pImage, RTMSINTERVAL cMillies, uint32_t *pfEvents)
    2376 {
    2377     return pImage->pInterfaceNetCallbacks->pfnSelectOneEx(pImage->Socket, pfEvents, cMillies);
     2383DECLINLINE(int) iscsiIoThreadWait(PISCSIIMAGE pImage, RTMSINTERVAL cMillies, uint32_t fEvents, uint32_t *pfEvents)
     2384{
     2385    return pImage->pInterfaceNetCallbacks->pfnSelectOneEx(pImage->Socket, fEvents, pfEvents, cMillies);
    23782386}
    23792387
     
    24722480    PISCSIIMAGE pImage = (PISCSIIMAGE)pvUser;
    24732481
     2482    /* Initialise the initial event mask. */
     2483    pImage->fPollEvents = VD_INTERFACETCPNET_EVT_READ | VD_INTERFACETCPNET_EVT_ERROR;
     2484
    24742485    while (pImage->fRunning)
    24752486    {
     
    24782489
    24792490        /* Wait for work or for data from the target. */
    2480         rc = iscsiIoThreadWait(pImage, RT_INDEFINITE_WAIT, &fEvents);
     2491        rc = iscsiIoThreadWait(pImage, RT_INDEFINITE_WAIT, pImage->fPollEvents, &fEvents);
    24812492        if (rc == VERR_INTERRUPTED)
    24822493        {
     
    27642775        rc = iscsiError(pImage, VERR_VD_ISCSI_UNKNOWN_INTERFACE,
    27652776                        RT_SRC_POS, N_("iSCSI: configuration interface missing"));
     2777        goto out;
     2778    }
     2779
     2780    /* Get I/O interface. */
     2781    pImage->pInterfaceIo = VDInterfaceGet(pImage->pVDIfsImage, VDINTERFACETYPE_IO);
     2782    if (pImage->pInterfaceIo)
     2783        pImage->pInterfaceIoCallbacks = VDGetInterfaceIO(pImage->pInterfaceIo);
     2784    else
     2785    {
     2786        rc = iscsiError(pImage, VERR_VD_ISCSI_UNKNOWN_INTERFACE,
     2787                        RT_SRC_POS, N_("iSCSI: I/O interface missing"));
    27662788        goto out;
    27672789    }
     
    41974219
    41984220    return rc;
     4221}
     4222
     4223static bool iscsiIsAsyncIOSupported(void *pvBackendData)
     4224{
     4225    return false;
     4226}
     4227
     4228static int iscsiAsyncRead(void *pvBackendData, uint64_t uOffset, size_t cbRead,
     4229                          PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
     4230{
     4231    PISCSIIMAGE pImage = (PISCSIIMAGE)pvBackendData;
     4232    int rc = VERR_NOT_SUPPORTED;
     4233
     4234    LogFlowFunc(("pBackendData=%p uOffset=%#llx pIoCtx=%#p cbRead=%u pcbActuallyRead=%p\n",
     4235                     pvBackendData, uOffset, pIoCtx, cbRead, pcbActuallyRead));
     4236
     4237    if (uOffset + cbRead > pImage->cbSize)
     4238        return VERR_INVALID_PARAMETER;
     4239
     4240    LogFlowFunc(("returns rc=%Rrc\n", rc));
     4241    return rc;
     4242}
     4243
     4244static int iscsiAsyncWrite(void *pvBackendData, uint64_t uOffset, size_t cbWrite,
     4245                           PVDIOCTX pIoCtx,
     4246                           size_t *pcbWriteProcess, size_t *pcbPreRead,
     4247                           size_t *pcbPostRead, unsigned fWrite)
     4248{
     4249    PISCSIIMAGE pImage = (PISCSIIMAGE)pvBackendData;
     4250    int rc = VERR_NOT_SUPPORTED;
     4251
     4252    LogFlowFunc(("pBackendData=%p uOffset=%llu pIoCtx=%#p cbWrite=%u pcbWriteProcess=%p pcbPreRead=%p pcbPostRead=%p fWrite=%u\n",
     4253                 pvBackendData, uOffset, pIoCtx, cbWrite, pcbWriteProcess, pcbPreRead, pcbPostRead, fWrite));
     4254
     4255    AssertPtr(pImage);
     4256    Assert(uOffset % 512 == 0);
     4257    Assert(cbWrite % 512 == 0);
     4258
     4259    if (uOffset + cbWrite > pImage->cbSize)
     4260        return VERR_INVALID_PARAMETER;
     4261
     4262    return rc;
     4263}
     4264
     4265static int iscsiAsyncFlush(void *pvBackendData, PVDIOCTX pIoCtx)
     4266{
     4267    PISCSIIMAGE pImage = (PISCSIIMAGE)pvBackendData;
     4268
     4269    return VERR_NOT_SUPPORTED;
    41994270}
    42004271
     
    42834354    iscsiSetParentFilename,
    42844355    /* pfnIsAsyncIOSupported */
    4285     NULL,
     4356    iscsiIsAsyncIOSupported,
    42864357    /* pfnAsyncRead */
    4287     NULL,
     4358    iscsiAsyncRead,
    42884359    /* pfnAsyncWrite */
    4289     NULL,
     4360    iscsiAsyncWrite,
    42904361    /* pfnAsyncFlush */
    4291     NULL,
     4362    iscsiAsyncFlush,
    42924363    /* pfnComposeLocation */
    42934364    iscsiComposeLocation,
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