提交 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;
virNetServerServiceGetPort;
virNetServerServiceGetTLSContext;
virNetServerServiceIsReadonly;
virNetServerServiceNewFD;
virNetServerServiceNewTCP;
virNetServerServiceNewUNIX;
virNetServerServiceSetDispatcher;
......@@ -1592,6 +1593,7 @@ virNetSocketNewConnectExternal;
virNetSocketNewConnectSSH;
virNetSocketNewConnectTCP;
virNetSocketNewConnectUNIX;
virNetSocketNewListenFD;
virNetSocketNewListenTCP;
virNetSocketNewListenUNIX;
virNetSocketRead;
......
......@@ -200,6 +200,55 @@ error:
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)
{
......
......@@ -50,6 +50,11 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
bool readonly,
size_t nrequests_client_max,
virNetTLSContextPtr tls);
virNetServerServicePtr virNetServerServiceNewFD(int fd,
int auth,
bool readonly,
size_t nrequests_client_max,
virNetTLSContextPtr tls);
int virNetServerServiceGetPort(virNetServerServicePtr svc);
......
......@@ -399,6 +399,26 @@ int virNetSocketNewListenUNIX(const char *path ATTRIBUTE_UNUSED,
}
#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,
const char *service,
......
......@@ -52,6 +52,9 @@ int virNetSocketNewListenUNIX(const char *path,
gid_t grp,
virNetSocketPtr *addr);
int virNetSocketNewListenFD(int fd,
virNetSocketPtr *addr);
int virNetSocketNewConnectTCP(const char *nodename,
const char *service,
virNetSocketPtr *addr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册