VirtualBox

Changeset 75803 in vbox


Ignore:
Timestamp:
Nov 29, 2018 2:22:10 AM (6 years ago)
Author:
vboxsync
Message:

VBoxService: Started using the new PEEK and GET message functions. bugref:9313

Location:
trunk/src/VBox/Additions/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp

    r75798 r75803  
    195195    } while (rc == VERR_INTERRUPTED);
    196196
    197     LogRel2(("vbglR3GuestCtrlDetectPeekGetCancelSupport: rc=%Rrc %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x\n",
     197    LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: rc=%Rrc %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x\n",
    198198             rc, PeekCall.idMsg.u.value32,     PeekCall.cParams.u.value32,
    199199             PeekCall.acbParams[ 0].u.value32, PeekCall.acbParams[ 1].u.value32,
     
    205205             PeekCall.acbParams[12].u.value32, PeekCall.acbParams[13].u.value32));
    206206
    207 #if 0 /* enable after testing. */
    208207    /*
    209208     * VERR_TRY_AGAIN is likely and easy.
     
    241240        return true;
    242241    }
    243 #endif
    244242
    245243    /*
    246      * If we get an invalid handle status, we can't really tell.
     244     * Okay, pretty sure it's not supported then.
    247245     */
    248     if (rc != VERR_INVALID_HANDLE)
    249     {
    250         LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Not supported (#3)\n"));
    251         g_fVbglR3GuestCtrlHavePeekGetCancel = 0;
    252     }
    253     else
    254         LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Jury is still out (#4)\n"));
     246    LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Not supported (#3)\n"));
     247    g_fVbglR3GuestCtrlHavePeekGetCancel = 0;
    255248    return false;
    256249}
     
    336329     * Fallback if host < v6.0.
    337330     */
    338     return vbglR3GuestCtrlMsgWaitFor(idClient, pidMsg, pcParameters);
     331    rc = vbglR3GuestCtrlMsgWaitFor(idClient, pidMsg, pcParameters);
     332    if (rc == VERR_TOO_MUCH_DATA)
     333        rc = VINF_SUCCESS;
     334    return rc;
    339335}
    340336
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp

    r75798 r75803  
    7777static uint64_t             g_idControlSession;
    7878/** The guest control service client ID. */
    79 static uint32_t             g_uControlSvcClientID = 0;
     79static uint32_t             g_idControlSvcClient = 0;
    8080#if 0 /** @todo process limit */
    8181/** How many started guest processes are kept into memory for supplying
     
    194194
    195195    if (RT_SUCCESS(rc))
    196         rc = VbglR3GuestCtrlConnect(&g_uControlSvcClientID);
     196        rc = VbglR3GuestCtrlConnect(&g_idControlSvcClient);
    197197    if (RT_SUCCESS(rc))
    198198    {
    199         VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_uControlSvcClientID);
     199        VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_idControlSvcClient);
    200200
    201201        /* Init session thread list. */
     
    230230     */
    231231    RTThreadUserSignal(RTThreadSelf());
    232     Assert(g_uControlSvcClientID > 0);
    233 
    234     int rc = VINF_SUCCESS;
     232    Assert(g_idControlSvcClient > 0);
    235233
    236234    /* Allocate a scratch buffer for commands which also send
     
    241239    AssertReturn(pvScratchBuf, VERR_NO_MEMORY);
    242240
    243     VBGLR3GUESTCTRLCMDCTX ctxHost = { g_uControlSvcClientID };
     241    VBGLR3GUESTCTRLCMDCTX ctxHost = { g_idControlSvcClient };
    244242    /* Set default protocol version to 1. */
    245243    ctxHost.uProtocol = 1;
    246244
    247     int cRetrievalFailed = 0; /* Number of failed message retrievals in a row. */
    248     for (;;)
     245    int rc = VINF_SUCCESS;      /* (shut up compiler warnings) */
     246    int cRetrievalFailed = 0;   /* Number of failed message retrievals in a row. */
     247    while (!*pfShutdown)
    249248    {
    250249        VGSvcVerbose(3, "GstCtrl: Waiting for host msg ...\n");
    251         uint32_t uMsg = 0;
     250        uint32_t idMsg = 0;
    252251        uint32_t cParms = 0;
    253         rc = VbglR3GuestCtrlMsgPeekWait(g_uControlSvcClientID, &uMsg, &cParms);
    254         if (rc == VERR_TOO_MUCH_DATA)
     252        rc = VbglR3GuestCtrlMsgPeekWait(g_idControlSvcClient, &idMsg, &cParms);
     253        if (RT_SUCCESS(rc))
    255254        {
    256 #ifdef DEBUG
    257             VGSvcVerbose(4, "Message requires %u parameters, but only 2 supplied -- retrying request (no error!)...\n",
    258                          cParms);
    259 #endif
    260             rc = VINF_SUCCESS; /* Try to get "real" message in next block below. */
    261         }
    262         else if (RT_FAILURE(rc))
    263         {
    264             /* Note: VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
    265             VGSvcError("GstCtrl: Getting host message failed with %Rrc\n", rc);
    266 
    267             /* Check for VM session change. */
     255            cRetrievalFailed = 0; /* Reset failed retrieval count. */
     256            VGSvcVerbose(4, "idMsg=%RU32 (%s) (%RU32 parms) retrieved\n", idMsg, GstCtrlHostFnName((eHostFn)idMsg), cParms);
     257
     258            /*
     259             * Close all open guest sessions if the VM was restored (all context IDs,
     260             * sessions, etc. are now invalid).
     261             *
     262             * Note! This will suck performance wise if we get a lot of messages thru here.
     263             *       What about the service returning a HOST_MSG_RESTORED message?
     264             */
    268265            uint64_t idNewSession = g_idControlSession;
    269266            int rc2 = VbglR3GetSessionId(&idNewSession);
    270267            if (   RT_SUCCESS(rc2)
    271                 && (idNewSession != g_idControlSession))
     268                && idNewSession != g_idControlSession)
    272269            {
    273                 VGSvcVerbose(1, "GstCtrl: The VM session ID changed\n");
     270                VGSvcVerbose(1, "The VM session ID changed (i.e. restored).\n");
    274271                g_idControlSession = idNewSession;
    275 
    276                 /* Close all opened guest sessions -- all context IDs, sessions etc.
    277                  * are now invalid. */
    278                 rc2 = VGSvcGstCtrlSessionClose(&g_Session);
    279                 AssertRC(rc2);
    280 
    281                 /* Do a reconnect. */
    282                 VGSvcVerbose(1, "Reconnecting to HGCM service ...\n");
    283                 rc2 = VbglR3GuestCtrlConnect(&g_uControlSvcClientID);
    284                 if (RT_SUCCESS(rc2))
    285                 {
    286                     VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_uControlSvcClientID);
    287                     cRetrievalFailed = 0;
    288                     continue; /* Skip waiting. */
    289                 }
    290                 VGSvcError("Unable to re-connect to HGCM service, rc=%Rrc, bailing out\n", rc);
    291                 break;
    292             }
    293 
    294             if (rc == VERR_INTERRUPTED)
    295                 RTThreadYield();        /* To be on the safe side... */
    296             else if (++cRetrievalFailed <= 16) /** @todo Make this configurable? */
    297                 RTThreadSleep(1000);    /* Wait a bit before retrying. */
    298             else
    299             {
    300                 VGSvcError("Too many failed attempts in a row to get next message, bailing out\n");
    301                 break;
    302             }
    303         }
    304 
    305         if (RT_SUCCESS(rc))
    306         {
    307             VGSvcVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);
    308             cRetrievalFailed = 0; /* Reset failed retrieval count. */
    309 
    310             /* Set number of parameters for current host context. */
    311             ctxHost.uNumParms = cParms;
    312 
    313             /* Check for VM session change. */
    314             uint64_t idNewSession = g_idControlSession;
    315             int rc2 = VbglR3GetSessionId(&idNewSession);
    316             if (   RT_SUCCESS(rc2)
    317                 && (idNewSession != g_idControlSession))
    318             {
    319                 VGSvcVerbose(1, "The VM session ID changed\n");
    320                 g_idControlSession = idNewSession;
    321 
    322                 /* Close all opened guest sessions -- all context IDs, sessions etc.
    323                  * are now invalid. */
    324272                rc2 = VGSvcGstCtrlSessionClose(&g_Session);
    325273                AssertRC(rc2);
    326274            }
    327275
    328             switch (uMsg)
     276            /*
     277             * Handle the host message.
     278             */
     279            ctxHost.uNumParms = cParms;
     280            switch (idMsg)
    329281            {
    330282                case HOST_CANCEL_PENDING_WAITS:
     
    353305                     */
    354306                    if (ctxHost.uProtocol == 1)
    355                         rc = VGSvcGstCtrlSessionHandler(&g_Session, uMsg, &ctxHost, pvScratchBuf, cbScratchBuf, pfShutdown);
     307                        rc = VGSvcGstCtrlSessionHandler(&g_Session, idMsg, &ctxHost, pvScratchBuf, cbScratchBuf, pfShutdown);
    356308                    else
    357309                    {
     
    361313                         * skip all not wanted messages here.
    362314                         */
    363                         rc = VbglR3GuestCtrlMsgSkipOld(g_uControlSvcClientID);
    364                         VGSvcVerbose(3, "Skipping uMsg=%RU32, cParms=%RU32, rc=%Rrc\n", uMsg, cParms, rc);
     315                        rc = VbglR3GuestCtrlMsgSkipOld(g_idControlSvcClient);
     316                        VGSvcVerbose(3, "Skipping idMsg=%RU32, cParms=%RU32, rc=%Rrc\n", idMsg, cParms, rc);
    365317                    }
    366318                    break;
    367319                }
    368320            }
     321
     322            /* Do we need to shutdown? */
     323            if (idMsg == HOST_CANCEL_PENDING_WAITS)
     324                break;
     325
     326            /* Let's sleep for a bit and let others run ... */
     327            RTThreadYield();
    369328        }
    370 
    371         /* Do we need to shutdown? */
    372         if (   *pfShutdown
    373             || (RT_SUCCESS(rc) && uMsg == HOST_CANCEL_PENDING_WAITS))
     329        else
    374330        {
    375             break;
     331            /* Note: VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
     332            /** @todo r=bird: Above comment makes no sense.  How can you get a timeout in a blocking HGCM call? */
     333            VGSvcError("GstCtrl: Getting host message failed with %Rrc\n", rc);
     334
     335            /* Check for VM session change. */
     336            uint64_t idNewSession = g_idControlSession;
     337            int rc2 = VbglR3GetSessionId(&idNewSession);
     338            if (   RT_SUCCESS(rc2)
     339                && (idNewSession != g_idControlSession))
     340            {
     341                VGSvcVerbose(1, "GstCtrl: The VM session ID changed\n");
     342                g_idControlSession = idNewSession;
     343
     344                /* Close all opened guest sessions -- all context IDs, sessions etc.
     345                 * are now invalid. */
     346                rc2 = VGSvcGstCtrlSessionClose(&g_Session);
     347                AssertRC(rc2);
     348
     349                /* Do a reconnect. */
     350                VGSvcVerbose(1, "Reconnecting to HGCM service ...\n");
     351                rc2 = VbglR3GuestCtrlConnect(&g_idControlSvcClient);
     352                if (RT_SUCCESS(rc2))
     353                {
     354                    VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_idControlSvcClient);
     355                    cRetrievalFailed = 0;
     356                    continue; /* Skip waiting. */
     357                }
     358                VGSvcError("Unable to re-connect to HGCM service, rc=%Rrc, bailing out\n", rc);
     359                break;
     360            }
     361
     362            if (rc == VERR_INTERRUPTED)
     363                RTThreadYield();        /* To be on the safe side... */
     364            else if (++cRetrievalFailed <= 16) /** @todo Make this configurable? */
     365                RTThreadSleep(1000);    /* Wait a bit before retrying. */
     366            else
     367            {
     368                VGSvcError("Too many failed attempts in a row to get next message, bailing out\n");
     369                break;
     370            }
    376371        }
    377 
    378         /* Let's sleep for a bit and let others run ... */
    379         RTThreadYield();
    380372    }
    381373
     
    486478     * control thread so that we can shutdown properly here.
    487479     */
    488     if (g_uControlSvcClientID)
     480    if (g_idControlSvcClient)
    489481    {
    490482        VGSvcVerbose(3, "Cancelling pending waits (client ID=%u) ...\n",
    491                            g_uControlSvcClientID);
    492 
    493         int rc = VbglR3GuestCtrlCancelPendingWaits(g_uControlSvcClientID);
     483                           g_idControlSvcClient);
     484
     485        int rc = VbglR3GuestCtrlCancelPendingWaits(g_idControlSvcClient);
    494486        if (RT_FAILURE(rc))
    495487            VGSvcError("Cancelling pending waits failed; rc=%Rrc\n", rc);
     
    526518    vgsvcGstCtrlShutdown();
    527519
    528     VGSvcVerbose(3, "Disconnecting client ID=%u ...\n", g_uControlSvcClientID);
    529     VbglR3GuestCtrlDisconnect(g_uControlSvcClientID);
    530     g_uControlSvcClientID = 0;
     520    VGSvcVerbose(3, "Disconnecting client ID=%u ...\n", g_idControlSvcClient);
     521    VbglR3GuestCtrlDisconnect(g_idControlSvcClient);
     522    g_idControlSvcClient = 0;
    531523
    532524    if (g_hControlEvent != NIL_RTSEMEVENTMULTI)
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