[PATCH v3 2/9] remote: create virNetServerServiceNewFDOrUNIX() wrapper

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

 



It's just a wrapper around NewFD and NewUNIX that selects the right
option and increments the number of used FDs.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/libvirt_remote.syms       |  1 +
 src/rpc/virnetserverservice.c | 50 ++++++++++++++++++++++++++++++++++++++++++-
 src/rpc/virnetserverservice.h | 14 +++++++++++-
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index d482a55..6b520b5 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -159,6 +159,7 @@ virNetServerServiceGetMaxRequests;
 virNetServerServiceGetPort;
 virNetServerServiceIsReadonly;
 virNetServerServiceNewFD;
+virNetServerServiceNewFDOrUNIX;
 virNetServerServiceNewPostExecRestart;
 virNetServerServiceNewTCP;
 virNetServerServiceNewUNIX;
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index 320a02c..e85889b 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -1,7 +1,7 @@
 /*
  * virnetserverservice.c: generic network RPC server service
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2012, 2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -25,6 +25,8 @@

 #include "virnetserverservice.h"

+#include <unistd.h>
+
 #include "viralloc.h"
 #include "virerror.h"
 #include "virthread.h"
@@ -90,6 +92,52 @@ static void virNetServerServiceAccept(virNetSocketPtr sock,
 }


+virNetServerServicePtr
+virNetServerServiceNewFDOrUNIX(const char *path,
+                               mode_t mask,
+                               gid_t grp,
+                               int auth,
+#if WITH_GNUTLS
+                               virNetTLSContextPtr tls,
+#endif
+                               bool readonly,
+                               size_t max_queued_clients,
+                               size_t nrequests_client_max,
+                               unsigned int nfds,
+                               unsigned int *cur_fd)
+{
+    if (*cur_fd - STDERR_FILENO > nfds) {
+        /*
+         * There are no more file descriptors to use, so we have to
+         * fallback to UNIX socket.
+         */
+        return virNetServerServiceNewUNIX(path,
+                                          mask,
+                                          grp,
+                                          auth,
+#if WITH_GNUTLS
+                                          tls,
+#endif
+                                          readonly,
+                                          max_queued_clients,
+                                          nrequests_client_max);
+
+    } else {
+        /*
+         * There's still enough file descriptors.  In this case we'll
+         * use the current one and increment it afterwards.
+         */
+        return virNetServerServiceNewFD(*cur_fd++,
+                                        auth,
+#if WITH_GNUTLS
+                                        tls,
+#endif
+                                        readonly,
+                                        nrequests_client_max);
+    }
+}
+
+
 virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
                                                  const char *service,
                                                  int auth,
diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h
index eb31abf..a1c8960 100644
--- a/src/rpc/virnetserverservice.h
+++ b/src/rpc/virnetserverservice.h
@@ -1,7 +1,7 @@
 /*
  * virnetserverservice.h: generic network RPC server service
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2011, 2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -37,6 +37,18 @@ typedef int (*virNetServerServiceDispatchFunc)(virNetServerServicePtr svc,
                                                virNetSocketPtr sock,
                                                void *opaque);

+virNetServerServicePtr virNetServerServiceNewFDOrUNIX(const char *path,
+                                                      mode_t mask,
+                                                      gid_t grp,
+                                                      int auth,
+# if WITH_GNUTLS
+                                                      virNetTLSContextPtr tls,
+# endif
+                                                      bool readonly,
+                                                      size_t max_queued_clients,
+                                                      size_t nrequests_client_max,
+                                                      unsigned int nfds,
+                                                      unsigned int *cur_fd);
 virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
                                                  const char *service,
                                                  int auth,
-- 
2.0.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]