[PATCH v2 04/19] rpc: allow creating RPC service from an array of FDs

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

 



The virNetServerServiceNewFD API only accepts a single FD, but it is
easily changed to allow for an array of FDs to be passed in.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/libvirt_remote.syms       |  2 +-
 src/locking/lock_daemon.c     |  9 ++++--
 src/logging/log_daemon.c      |  9 ++++--
 src/rpc/virnetserverservice.c | 53 +++++++++++++++++++++--------------
 src/rpc/virnetserverservice.h | 13 +++++----
 5 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index 99fe3dd07c..f05f1827f0 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -202,8 +202,8 @@ virNetServerServiceGetMaxRequests;
 virNetServerServiceGetPort;
 virNetServerServiceGetTLSContext;
 virNetServerServiceIsReadonly;
-virNetServerServiceNewFD;
 virNetServerServiceNewFDOrUNIX;
+virNetServerServiceNewFDs;
 virNetServerServiceNewPostExecRestart;
 virNetServerServiceNewTCP;
 virNetServerServiceNewUNIX;
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index bc2fb4a7fb..c10b2d383c 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -597,6 +597,7 @@ virLockDaemonSetupNetworkingSystemD(virNetServerPtr lockSrv, virNetServerPtr adm
         virNetServerServicePtr svc;
         char *path = virGetUNIXSocketPath(3 + i);
         virNetServerPtr srv;
+        int fds[] = { 3 + i };
 
         if (!path)
             return -1;
@@ -616,9 +617,11 @@ virLockDaemonSetupNetworkingSystemD(virNetServerPtr lockSrv, virNetServerPtr adm
 
         /* Systemd passes FDs, starting immediately after stderr,
          * so the first FD we'll get is '3'. */
-        if (!(svc = virNetServerServiceNewFD(3 + i, 0,
-                                             NULL,
-                                             false, 0, 1)))
+        if (!(svc = virNetServerServiceNewFDs(fds,
+                                              ARRAY_CARDINALITY(fds),
+                                              0,
+                                              NULL,
+                                              false, 0, 1)))
             return -1;
 
         if (virNetServerAddService(srv, svc) < 0) {
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 014596b280..6531999381 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -532,6 +532,7 @@ virLogDaemonSetupNetworkingSystemD(virNetServerPtr logSrv, virNetServerPtr admin
         virNetServerServicePtr svc;
         char *path = virGetUNIXSocketPath(3 + i);
         virNetServerPtr srv;
+        int fds[] = { 3 + i };
 
         if (!path)
             return -1;
@@ -551,9 +552,11 @@ virLogDaemonSetupNetworkingSystemD(virNetServerPtr logSrv, virNetServerPtr admin
 
         /* Systemd passes FDs, starting immediately after stderr,
          * so the first FD we'll get is '3'. */
-        if (!(svc = virNetServerServiceNewFD(3 + i, 0,
-                                             NULL,
-                                             false, 0, 1)))
+        if (!(svc = virNetServerServiceNewFDs(fds,
+                                              ARRAY_CARDINALITY(fds),
+                                              0,
+                                              NULL,
+                                              false, 0, 1)))
             return -1;
 
         if (virNetServerAddService(srv, svc) < 0) {
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index 69043ccc0e..0d2f264696 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -112,18 +112,20 @@ virNetServerServiceNewFDOrUNIX(const char *path,
                                           nrequests_client_max);
 
     } else {
+        int fds[] = {(*cur_fd)++};
         /*
          * There's still enough file descriptors.  In this case we'll
          * use the current one and increment it afterwards. Take care
          * with order of operation for pointer arithmetic and auto
          * increment on cur_fd - the parentheses are necessary.
          */
-        return virNetServerServiceNewFD((*cur_fd)++,
-                                        auth,
-                                        tls,
-                                        readonly,
-                                        max_queued_clients,
-                                        nrequests_client_max);
+        return virNetServerServiceNewFDs(fds,
+                                         ARRAY_CARDINALITY(fds),
+                                         auth,
+                                         tls,
+                                         readonly,
+                                         max_queued_clients,
+                                         nrequests_client_max);
     }
 }
 
@@ -253,30 +255,39 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
     return svc;
 }
 
-virNetServerServicePtr virNetServerServiceNewFD(int fd,
-                                                int auth,
-                                                virNetTLSContextPtr tls,
-                                                bool readonly,
-                                                size_t max_queued_clients,
-                                                size_t nrequests_client_max)
+virNetServerServicePtr virNetServerServiceNewFDs(int *fds,
+                                                 size_t nfds,
+                                                 int auth,
+                                                 virNetTLSContextPtr tls,
+                                                 bool readonly,
+                                                 size_t max_queued_clients,
+                                                 size_t nrequests_client_max)
 {
-    virNetServerServicePtr svc;
-    virNetSocketPtr sock;
+    virNetServerServicePtr svc = NULL;
+    virNetSocketPtr *socks;
+    size_t i;
 
-    if (virNetSocketNewListenFD(fd,
-                                &sock) < 0)
-        return NULL;
+    if (VIR_ALLOC_N(socks, nfds) < 0)
+        goto cleanup;
 
-    svc = virNetServerServiceNewSocket(&sock,
-                                       1,
+    for (i = 0; i < nfds; i++) {
+        if (virNetSocketNewListenFD(fds[i],
+                                    &socks[i]) < 0)
+            goto cleanup;
+    }
+
+    svc = virNetServerServiceNewSocket(socks,
+                                       nfds,
                                        auth,
                                        tls,
                                        readonly,
                                        max_queued_clients,
                                        nrequests_client_max);
 
-    virObjectUnref(sock);
-
+ cleanup:
+    for (i = 0; i < nfds && socks; i++)
+        virObjectUnref(socks[i]);
+    VIR_FREE(socks);
     return svc;
 }
 
diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h
index 5dd22bd929..59ee51e5ee 100644
--- a/src/rpc/virnetserverservice.h
+++ b/src/rpc/virnetserverservice.h
@@ -60,12 +60,13 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
                                                   bool readonly,
                                                   size_t max_queued_clients,
                                                   size_t nrequests_client_max);
-virNetServerServicePtr virNetServerServiceNewFD(int fd,
-                                                int auth,
-                                                virNetTLSContextPtr tls,
-                                                bool readonly,
-                                                size_t max_queued_clients,
-                                                size_t nrequests_client_max);
+virNetServerServicePtr virNetServerServiceNewFDs(int *fd,
+                                                 size_t nfds,
+                                                 int auth,
+                                                 virNetTLSContextPtr tls,
+                                                 bool readonly,
+                                                 size_t max_queued_clients,
+                                                 size_t nrequests_client_max);
 
 virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr object);
 
-- 
2.21.0

--
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]

  Powered by Linux