提交 9c9ed0f3 编写于 作者: D Daniel P. Berrange

Refactor message sending to allow code reuse for data streams

Splits up the 'call' method moving generic IO code out into
separate method to allow it to be easily reused for sending
data streams

* src/remote_internal.c: Split 'call' into two methods, the first
  with same name serializes a set of method arguments into a
  message, the second 'remoteIO' takes a pre-serialized messages,
  sends it and awaits a reply
上级 7a61c138
...@@ -6948,7 +6948,7 @@ error: ...@@ -6948,7 +6948,7 @@ error:
} }
/* /*
* This function performs a remote procedure call to procedure PROC_NR. * This function sends a message to remote server and awaits a reply
* *
* NB. This does not free the args structure (not desirable, since you * NB. This does not free the args structure (not desirable, since you
* often want this allocated on the stack or else it contains strings * often want this allocated on the stack or else it contains strings
...@@ -6981,24 +6981,16 @@ error: ...@@ -6981,24 +6981,16 @@ error:
* NB(5) Don't Panic! * NB(5) Don't Panic!
*/ */
static int static int
call (virConnectPtr conn, struct private_data *priv, remoteIO(virConnectPtr conn,
int flags /* if we are in virConnectOpen */, struct private_data *priv,
int proc_nr, int flags,
xdrproc_t args_filter, char *args, struct remote_thread_call *thiscall)
xdrproc_t ret_filter, char *ret)
{ {
int rv; int rv;
struct remote_thread_call *thiscall;
DEBUG("Doing call %d %p", proc_nr, priv->waitDispatch);
thiscall = prepareCall(conn, priv, flags, proc_nr,
args_filter, args,
ret_filter, ret);
if (!thiscall) { DEBUG("Do proc=%d serial=%d length=%d wait=%p",
virReportOOMError (flags & REMOTE_CALL_IN_OPEN ? NULL : conn); thiscall->proc_nr, thiscall->serial,
return -1; thiscall->bufferLength, priv->waitDispatch);
}
/* Check to see if another thread is dispatching */ /* Check to see if another thread is dispatching */
if (priv->waitDispatch) { if (priv->waitDispatch) {
...@@ -7015,7 +7007,7 @@ call (virConnectPtr conn, struct private_data *priv, ...@@ -7015,7 +7007,7 @@ call (virConnectPtr conn, struct private_data *priv,
/* Force other thread to wakup from poll */ /* Force other thread to wakup from poll */
safewrite(priv->wakeupSendFD, &ignore, sizeof(ignore)); safewrite(priv->wakeupSendFD, &ignore, sizeof(ignore));
DEBUG("Going to sleep %d %p %p", proc_nr, priv->waitDispatch, thiscall); DEBUG("Going to sleep %d %p %p", thiscall->proc_nr, priv->waitDispatch, thiscall);
/* Go to sleep while other thread is working... */ /* Go to sleep while other thread is working... */
if (virCondWait(&thiscall->cond, &priv->lock) < 0) { if (virCondWait(&thiscall->cond, &priv->lock) < 0) {
if (priv->waitDispatch == thiscall) { if (priv->waitDispatch == thiscall) {
...@@ -7036,7 +7028,7 @@ call (virConnectPtr conn, struct private_data *priv, ...@@ -7036,7 +7028,7 @@ call (virConnectPtr conn, struct private_data *priv,
return -1; return -1;
} }
DEBUG("Wokeup from sleep %d %p %p", proc_nr, priv->waitDispatch, thiscall); DEBUG("Wokeup from sleep %d %p %p", thiscall->proc_nr, priv->waitDispatch, thiscall);
/* Two reasons we can be woken up /* Two reasons we can be woken up
* 1. Other thread has got our reply ready for us * 1. Other thread has got our reply ready for us
* 2. Other thread is all done, and it is our turn to * 2. Other thread is all done, and it is our turn to
...@@ -7060,7 +7052,7 @@ call (virConnectPtr conn, struct private_data *priv, ...@@ -7060,7 +7052,7 @@ call (virConnectPtr conn, struct private_data *priv,
priv->waitDispatch = thiscall; priv->waitDispatch = thiscall;
} }
DEBUG("We have the buck %d %p %p", proc_nr, priv->waitDispatch, thiscall); DEBUG("We have the buck %d %p %p", thiscall->proc_nr, priv->waitDispatch, thiscall);
/* /*
* The buck stops here! * The buck stops here!
* *
...@@ -7091,7 +7083,7 @@ call (virConnectPtr conn, struct private_data *priv, ...@@ -7091,7 +7083,7 @@ call (virConnectPtr conn, struct private_data *priv,
} }
cleanup: cleanup:
DEBUG("All done with our call %d %p %p", proc_nr, priv->waitDispatch, thiscall); DEBUG("All done with our call %d %p %p", thiscall->proc_nr, priv->waitDispatch, thiscall);
if (thiscall->mode == REMOTE_MODE_ERROR) { if (thiscall->mode == REMOTE_MODE_ERROR) {
/* See if caller asked us to keep quiet about missing RPCs /* See if caller asked us to keep quiet about missing RPCs
* eg for interop with older servers */ * eg for interop with older servers */
...@@ -7115,6 +7107,34 @@ cleanup: ...@@ -7115,6 +7107,34 @@ cleanup:
return rv; return rv;
} }
/*
* Serial a set of arguments into a method call message,
* send that to the server and wait for reply
*/
static int
call (virConnectPtr conn, struct private_data *priv,
int flags /* if we are in virConnectOpen */,
int proc_nr,
xdrproc_t args_filter, char *args,
xdrproc_t ret_filter, char *ret)
{
struct remote_thread_call *thiscall;
thiscall = prepareCall(conn, priv, flags, proc_nr,
args_filter, args,
ret_filter, ret);
if (!thiscall) {
virReportOOMError (flags & REMOTE_CALL_IN_OPEN ? NULL : conn);
return -1;
}
return remoteIO(conn, priv, flags, thiscall);
}
/** /**
* remoteDomainReadEvent * remoteDomainReadEvent
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册