提交 5435f17e 编写于 作者: D Daniel P. Berrange

Add support for creating sockets & RPC servers from a pre-opened fd

In order to support systemd socket based activation, it needs to
be possible to create virNetSocketPtr and virNetServerServicePtr
instance from a pre-opened file descriptor
上级 4eb6cae8
...@@ -1567,6 +1567,7 @@ virNetServerServiceGetMaxRequests; ...@@ -1567,6 +1567,7 @@ virNetServerServiceGetMaxRequests;
virNetServerServiceGetPort; virNetServerServiceGetPort;
virNetServerServiceGetTLSContext; virNetServerServiceGetTLSContext;
virNetServerServiceIsReadonly; virNetServerServiceIsReadonly;
virNetServerServiceNewFD;
virNetServerServiceNewTCP; virNetServerServiceNewTCP;
virNetServerServiceNewUNIX; virNetServerServiceNewUNIX;
virNetServerServiceSetDispatcher; virNetServerServiceSetDispatcher;
...@@ -1592,6 +1593,7 @@ virNetSocketNewConnectExternal; ...@@ -1592,6 +1593,7 @@ virNetSocketNewConnectExternal;
virNetSocketNewConnectSSH; virNetSocketNewConnectSSH;
virNetSocketNewConnectTCP; virNetSocketNewConnectTCP;
virNetSocketNewConnectUNIX; virNetSocketNewConnectUNIX;
virNetSocketNewListenFD;
virNetSocketNewListenTCP; virNetSocketNewListenTCP;
virNetSocketNewListenUNIX; virNetSocketNewListenUNIX;
virNetSocketRead; virNetSocketRead;
......
...@@ -200,6 +200,55 @@ error: ...@@ -200,6 +200,55 @@ error:
return NULL; return NULL;
} }
virNetServerServicePtr virNetServerServiceNewFD(int fd,
int auth,
bool readonly,
size_t nrequests_client_max,
virNetTLSContextPtr tls)
{
virNetServerServicePtr svc;
int i;
if (virNetServerServiceInitialize() < 0)
return NULL;
if (!(svc = virObjectNew(virNetServerServiceClass)))
return NULL;
svc->auth = auth;
svc->readonly = readonly;
svc->nrequests_client_max = nrequests_client_max;
svc->tls = virObjectRef(tls);
svc->nsocks = 1;
if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0)
goto no_memory;
if (virNetSocketNewListenFD(fd,
&svc->socks[0]) < 0)
goto error;
for (i = 0 ; i < svc->nsocks ; i++) {
/* IO callback is initially disabled, until we're ready
* to deal with incoming clients */
if (virNetSocketAddIOCallback(svc->socks[i],
0,
virNetServerServiceAccept,
svc,
virObjectFreeCallback) < 0)
goto error;
}
return svc;
no_memory:
virReportOOMError();
error:
virObjectUnref(svc);
return NULL;
}
int virNetServerServiceGetPort(virNetServerServicePtr svc) int virNetServerServiceGetPort(virNetServerServicePtr svc)
{ {
......
...@@ -50,6 +50,11 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path, ...@@ -50,6 +50,11 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
bool readonly, bool readonly,
size_t nrequests_client_max, size_t nrequests_client_max,
virNetTLSContextPtr tls); virNetTLSContextPtr tls);
virNetServerServicePtr virNetServerServiceNewFD(int fd,
int auth,
bool readonly,
size_t nrequests_client_max,
virNetTLSContextPtr tls);
int virNetServerServiceGetPort(virNetServerServicePtr svc); int virNetServerServiceGetPort(virNetServerServicePtr svc);
......
...@@ -399,6 +399,26 @@ int virNetSocketNewListenUNIX(const char *path ATTRIBUTE_UNUSED, ...@@ -399,6 +399,26 @@ int virNetSocketNewListenUNIX(const char *path ATTRIBUTE_UNUSED,
} }
#endif #endif
int virNetSocketNewListenFD(int fd,
virNetSocketPtr *retsock)
{
virSocketAddr addr;
*retsock = NULL;
memset(&addr, 0, sizeof(addr));
addr.len = sizeof(addr.data);
if (getsockname(fd, &addr.data.sa, &addr.len) < 0) {
virReportSystemError(errno, "%s", _("Unable to get local socket name"));
return -1;
}
if (!(*retsock = virNetSocketNew(&addr, NULL, false, fd, -1, 0)))
return -1;
return 0;
}
int virNetSocketNewConnectTCP(const char *nodename, int virNetSocketNewConnectTCP(const char *nodename,
const char *service, const char *service,
......
...@@ -52,6 +52,9 @@ int virNetSocketNewListenUNIX(const char *path, ...@@ -52,6 +52,9 @@ int virNetSocketNewListenUNIX(const char *path,
gid_t grp, gid_t grp,
virNetSocketPtr *addr); virNetSocketPtr *addr);
int virNetSocketNewListenFD(int fd,
virNetSocketPtr *addr);
int virNetSocketNewConnectTCP(const char *nodename, int virNetSocketNewConnectTCP(const char *nodename,
const char *service, const char *service,
virNetSocketPtr *addr); virNetSocketPtr *addr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册