Move queuing of RPC replies into dispatch code

This removes an assumption from qemudWorker() code that every
incoming message will generate a reply.

* qemud/dispatch.c: remoteDispatchClientRequest now has responsibility
  for queuing the reply message to the RPC call
* qemud/qemud.c: Do not queue the RPC call reply in qemudWorker(),
  allowing remoteDispatchClientRequest() to take care of it
This commit is contained in:
Daniel P. Berrange 2009-07-10 12:45:37 +01:00
parent aa23d432cd
commit c40e14b4be
2 changed files with 11 additions and 11 deletions

View File

@ -387,6 +387,12 @@ rpc_error:
msg->bufferLength = len;
msg->bufferOffset = 0;
/* Put reply on end of tx queue to send out */
qemudClientMessageQueuePush(&client->tx, msg);
if (qemudRegisterClientEvent(server, client, 1) < 0)
qemudDispatchClientFailure(client);
return 0;
fatal_error:

View File

@ -1431,7 +1431,7 @@ static void *qemudWorker(void *data)
while (1) {
struct qemud_client *client = NULL;
struct qemud_client_message *reply;
struct qemud_client_message *msg;
virMutexLock(&server->lock);
while (((client = qemudPendingJob(server)) == NULL) &&
@ -1454,25 +1454,19 @@ static void *qemudWorker(void *data)
client->refs++;
/* Remove our message from dispatch queue while we use it */
reply = qemudClientMessageQueueServe(&client->dx);
msg = qemudClientMessageQueueServe(&client->dx);
/* This function drops the lock during dispatch,
* and re-acquires it before returning */
if (remoteDecodeClientMessageHeader(reply) < 0 ||
remoteDispatchClientRequest (server, client, reply) < 0) {
VIR_FREE(reply);
if (remoteDecodeClientMessageHeader(msg) < 0 ||
remoteDispatchClientRequest (server, client, msg) < 0) {
VIR_FREE(msg);
qemudDispatchClientFailure(client);
client->refs--;
virMutexUnlock(&client->lock);
continue;
}
/* Put reply on end of tx queue to send out */
qemudClientMessageQueuePush(&client->tx, reply);
if (qemudRegisterClientEvent(server, client, 1) < 0)
qemudDispatchClientFailure(client);
client->refs--;
virMutexUnlock(&client->lock);