[PATCH 04/23] Change interaction when accepting new RPC client connections

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Currently the virNetServerServicePtr is responsible for
creating the virNetServerClientPtr instance when accepting
a new connection. Change this so that the virNetServerServicePtr
merely gives virNetServerPtr a virNetSocketPtr instance. The
virNetServerPtr can then create the virNetServerClientPtr
as it desires

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/libvirt_private.syms      |  4 ++--
 src/rpc/virnetserver.c        | 14 ++++++++++++--
 src/rpc/virnetserverclient.c  |  4 +---
 src/rpc/virnetserverservice.c | 38 +++++++++++++++-----------------------
 src/rpc/virnetserverservice.h |  4 +++-
 5 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3a23fe6..e3d31dc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1487,8 +1487,6 @@ virNetServerKeepAliveRequired;
 virNetServerNew;
 virNetServerQuit;
 virNetServerRun;
-virNetServerServiceNewTCP;
-virNetServerServiceNewUNIX;
 virNetServerSetTLSContext;
 virNetServerUpdateServices;
 
@@ -1553,7 +1551,9 @@ virNetServerProgramUnknownError;
 # virnetserverservice.h
 virNetServerServiceClose;
 virNetServerServiceGetAuth;
+virNetServerServiceGetMaxRequests;
 virNetServerServiceGetPort;
+virNetServerServiceGetTLSContext;
 virNetServerServiceIsReadonly;
 virNetServerServiceNewTCP;
 virNetServerServiceNewUNIX;
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 15abb56..c3eb2e5 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -261,11 +261,12 @@ cleanup:
 }
 
 
-static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UNUSED,
-                                         virNetServerClientPtr client,
+static int virNetServerDispatchNewClient(virNetServerServicePtr svc,
+                                         virNetSocketPtr clientsock,
                                          void *opaque)
 {
     virNetServerPtr srv = opaque;
+    virNetServerClientPtr client = NULL;
 
     virNetServerLock(srv);
 
@@ -276,6 +277,13 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UN
         goto error;
     }
 
+    if (!(client = virNetServerClientNew(clientsock,
+                                         virNetServerServiceGetAuth(svc),
+                                         virNetServerServiceIsReadonly(svc),
+                                         virNetServerServiceGetMaxRequests(svc),
+                                         virNetServerServiceGetTLSContext(svc))))
+        goto error;
+
     if (virNetServerClientInit(client) < 0)
         goto error;
 
@@ -301,6 +309,8 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UN
     return 0;
 
 error:
+    virNetServerClientClose(client);
+    virObjectUnref(client);
     virNetServerUnlock(srv);
     return -1;
 }
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index d135b0f..9f033c8 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -357,7 +357,7 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
         return NULL;
     }
 
-    client->sock = sock;
+    client->sock = virObjectRef(sock);
     client->auth = auth;
     client->readonly = readonly;
     client->tlsCtxt = virObjectRef(tls);
@@ -385,8 +385,6 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
     return client;
 
 error:
-    /* XXX ref counting is better than this */
-    client->sock = NULL; /* Caller owns 'sock' upon failure */
     virObjectUnref(client);
     return NULL;
 }
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index 000b5b6..eda5ef9 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -69,40 +69,21 @@ static void virNetServerServiceAccept(virNetSocketPtr sock,
                                       void *opaque)
 {
     virNetServerServicePtr svc = opaque;
-    virNetServerClientPtr client = NULL;
     virNetSocketPtr clientsock = NULL;
 
     if (virNetSocketAccept(sock, &clientsock) < 0)
-        goto error;
+        goto cleanup;
 
     if (!clientsock) /* Connection already went away */
         goto cleanup;
 
-    if (!(client = virNetServerClientNew(clientsock,
-                                         svc->auth,
-                                         svc->readonly,
-                                         svc->nrequests_client_max,
-                                         svc->tls)))
-        goto error;
-
     if (!svc->dispatchFunc)
-        goto error;
-
-    if (svc->dispatchFunc(svc, client, svc->dispatchOpaque) < 0)
-        virNetServerClientClose(client);
+        goto cleanup;
 
-    virObjectUnref(client);
+    svc->dispatchFunc(svc, clientsock, svc->dispatchOpaque);
 
 cleanup:
-    return;
-
-error:
-    if (client) {
-        virNetServerClientClose(client);
-        virObjectUnref(client);
-    } else {
-        virObjectUnref(clientsock);
-    }
+    virObjectUnref(clientsock);
 }
 
 
@@ -240,6 +221,17 @@ bool virNetServerServiceIsReadonly(virNetServerServicePtr svc)
 }
 
 
+size_t virNetServerServiceGetMaxRequests(virNetServerServicePtr svc)
+{
+    return svc->nrequests_client_max;
+}
+
+virNetTLSContextPtr virNetServerServiceGetTLSContext(virNetServerServicePtr svc)
+{
+    return svc->tls;
+}
+
+
 void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
                                       virNetServerServiceDispatchFunc func,
                                       void *opaque)
diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h
index 98fd396..cb18e2d 100644
--- a/src/rpc/virnetserverservice.h
+++ b/src/rpc/virnetserverservice.h
@@ -34,7 +34,7 @@ enum {
 };
 
 typedef int (*virNetServerServiceDispatchFunc)(virNetServerServicePtr svc,
-                                               virNetServerClientPtr client,
+                                               virNetSocketPtr sock,
                                                void *opaque);
 
 virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
@@ -55,6 +55,8 @@ int virNetServerServiceGetPort(virNetServerServicePtr svc);
 
 int virNetServerServiceGetAuth(virNetServerServicePtr svc);
 bool virNetServerServiceIsReadonly(virNetServerServicePtr svc);
+size_t virNetServerServiceGetMaxRequests(virNetServerServicePtr svc);
+virNetTLSContextPtr virNetServerServiceGetTLSContext(virNetServerServicePtr svc);
 
 void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
                                       virNetServerServiceDispatchFunc func,
-- 
1.7.11.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]