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 Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/remote_internal.c | 60 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/remote_internal.c b/src/remote_internal.c index 4362521..eefead0 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -6943,7 +6943,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 * often want this allocated on the stack or else it contains strings @@ -6976,24 +6976,16 @@ error: * NB(5) Don't Panic! */ 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) +remoteIO(virConnectPtr conn, + struct private_data *priv, + int flags, + struct remote_thread_call *thiscall) { 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) { - virReportOOMError (flags & REMOTE_CALL_IN_OPEN ? NULL : conn); - return -1; - } + DEBUG("Do proc=%d serial=%d length=%d wait=%p", + thiscall->proc_nr, thiscall->serial, + thiscall->bufferLength, priv->waitDispatch); /* Check to see if another thread is dispatching */ if (priv->waitDispatch) { @@ -7010,7 +7002,7 @@ call (virConnectPtr conn, struct private_data *priv, /* Force other thread to wakup from poll */ 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... */ if (virCondWait(&thiscall->cond, &priv->lock) < 0) { if (priv->waitDispatch == thiscall) { @@ -7031,7 +7023,7 @@ call (virConnectPtr conn, struct private_data *priv, 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 * 1. Other thread has got our reply ready for us * 2. Other thread is all done, and it is our turn to @@ -7055,7 +7047,7 @@ call (virConnectPtr conn, struct private_data *priv, 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! * @@ -7086,7 +7078,7 @@ call (virConnectPtr conn, struct private_data *priv, } 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) { /* See if caller asked us to keep quiet about missing RPCs * eg for interop with older servers */ @@ -7110,6 +7102,34 @@ cleanup: 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 * -- 1.6.2.5 -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list