[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] rpc: Don't close connection if program is unknown



In case we add a new program in the future (we did that in the past and
we are going to do it again soon) current daemon will behave badly with
new client that wants to use the new program. Before the RPC rewrite we
used to just sent an error reply to any request with unknown program.
With the RPC rewrite in 0.9.3 the daemon just closes the connection
through which such request was sent. This patch fixes this regression.
---
 src/rpc/virnetserver.c        |   18 +++++++++---------
 src/rpc/virnetserverprogram.c |   36 ++++++++++++++++++++++++++++++------
 src/rpc/virnetserverprogram.h |    4 ++++
 3 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 1a49dbb..fd8781d 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -143,10 +143,12 @@ static void virNetServerHandleJob(void *jobOpaque, void *opaque)
     }
 
     if (!prog) {
-        VIR_DEBUG("Cannot find program %d version %d",
-                  job->msg->header.prog,
-                  job->msg->header.vers);
-        goto error;
+        if (virNetServerProgramUnknownError(job->client,
+                                            job->msg,
+                                            &job->msg->header) < 0)
+            goto error;
+        else
+            goto cleanup;
     }
 
     virNetServerProgramRef(prog);
@@ -159,20 +161,18 @@ static void virNetServerHandleJob(void *jobOpaque, void *opaque)
         goto error;
 
     virNetServerLock(srv);
+
+cleanup:
     virNetServerProgramFree(prog);
     virNetServerUnlock(srv);
     virNetServerClientFree(job->client);
-
     VIR_FREE(job);
     return;
 
 error:
-    virNetServerUnlock(srv);
-    virNetServerProgramFree(prog);
     virNetMessageFree(job->msg);
     virNetServerClientClose(job->client);
-    virNetServerClientFree(job->client);
-    VIR_FREE(job);
+    goto cleanup;
 }
 
 
diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c
index ca80ae0..ac3f0fd 100644
--- a/src/rpc/virnetserverprogram.c
+++ b/src/rpc/virnetserverprogram.c
@@ -110,7 +110,8 @@ static virNetServerProgramProcPtr virNetServerProgramGetProc(virNetServerProgram
 
 
 static int
-virNetServerProgramSendError(virNetServerProgramPtr prog,
+virNetServerProgramSendError(unsigned program,
+                             unsigned version,
                              virNetServerClientPtr client,
                              virNetMessagePtr msg,
                              virNetMessageErrorPtr rerr,
@@ -119,13 +120,13 @@ virNetServerProgramSendError(virNetServerProgramPtr prog,
                              int serial)
 {
     VIR_DEBUG("prog=%d ver=%d proc=%d type=%d serial=%d msg=%p rerr=%p",
-              prog->program, prog->version, procedure, type, serial, msg, rerr);
+              program, version, procedure, type, serial, msg, rerr);
 
     virNetMessageSaveError(rerr);
 
     /* Return header. */
-    msg->header.prog = prog->program;
-    msg->header.vers = prog->version;
+    msg->header.prog = program;
+    msg->header.vers = version;
     msg->header.proc = procedure;
     msg->header.type = type;
     msg->header.serial = serial;
@@ -170,7 +171,8 @@ virNetServerProgramSendReplyError(virNetServerProgramPtr prog,
      * For data streams, errors are sent back as data streams
      * For method calls, errors are sent back as method replies
      */
-    return virNetServerProgramSendError(prog,
+    return virNetServerProgramSendError(prog->program,
+                                        prog->version,
                                         client,
                                         msg,
                                         rerr,
@@ -187,7 +189,8 @@ int virNetServerProgramSendStreamError(virNetServerProgramPtr prog,
                                        int procedure,
                                        int serial)
 {
-    return virNetServerProgramSendError(prog,
+    return virNetServerProgramSendError(prog->program,
+                                        prog->version,
                                         client,
                                         msg,
                                         rerr,
@@ -197,6 +200,27 @@ int virNetServerProgramSendStreamError(virNetServerProgramPtr prog,
 }
 
 
+int virNetServerProgramUnknownError(virNetServerClientPtr client,
+                                    virNetMessagePtr msg,
+                                    virNetMessageHeaderPtr req)
+{
+    virNetMessageError rerr;
+
+    virNetError(VIR_ERR_RPC,
+                _("Cannot find program %d version %d"), req->prog, req->vers);
+
+    memset(&rerr, 0, sizeof(rerr));
+    return virNetServerProgramSendError(req->prog,
+                                        req->vers,
+                                        client,
+                                        msg,
+                                        &rerr,
+                                        req->proc,
+                                        VIR_NET_REPLY,
+                                        req->serial);
+}
+
+
 static int
 virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
                                 virNetServerPtr server,
diff --git a/src/rpc/virnetserverprogram.h b/src/rpc/virnetserverprogram.h
index ca31b7e..06b16d7 100644
--- a/src/rpc/virnetserverprogram.h
+++ b/src/rpc/virnetserverprogram.h
@@ -86,6 +86,10 @@ int virNetServerProgramSendStreamError(virNetServerProgramPtr prog,
                                        int procedure,
                                        int serial);
 
+int virNetServerProgramUnknownError(virNetServerClientPtr client,
+                                    virNetMessagePtr msg,
+                                    virNetMessageHeaderPtr req);
+
 int virNetServerProgramSendStreamData(virNetServerProgramPtr prog,
                                       virNetServerClientPtr client,
                                       virNetMessagePtr msg,
-- 
1.7.6.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]