mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
rpc: allow creating RPC service from an array of FDs
The virNetServerServiceNewFD API only accepts a single FD, but it is easily changed to allow for an array of FDs to be passed in. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
3b6bfde089
commit
9f3d1c5c8f
@ -202,8 +202,8 @@ virNetServerServiceGetMaxRequests;
|
||||
virNetServerServiceGetPort;
|
||||
virNetServerServiceGetTLSContext;
|
||||
virNetServerServiceIsReadonly;
|
||||
virNetServerServiceNewFD;
|
||||
virNetServerServiceNewFDOrUNIX;
|
||||
virNetServerServiceNewFDs;
|
||||
virNetServerServiceNewPostExecRestart;
|
||||
virNetServerServiceNewTCP;
|
||||
virNetServerServiceNewUNIX;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user