2010-12-01 16:36:40 +00:00
|
|
|
/*
|
|
|
|
* virnetserverclient.c: generic network RPC server client
|
|
|
|
*
|
2014-03-18 08:14:54 +00:00
|
|
|
* Copyright (C) 2006-2014 Red Hat, Inc.
|
2010-12-01 16:36:40 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-01 16:36:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2013-05-29 19:57:01 +00:00
|
|
|
#include "internal.h"
|
2012-09-20 11:58:29 +00:00
|
|
|
#if WITH_SASL
|
2010-12-01 16:36:40 +00:00
|
|
|
# include <sasl/sasl.h>
|
|
|
|
#endif
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
#include "virnetserver.h"
|
2010-12-01 16:36:40 +00:00
|
|
|
#include "virnetserverclient.h"
|
|
|
|
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 15:49:48 +00:00
|
|
|
#include "virthread.h"
|
2011-08-24 13:33:34 +00:00
|
|
|
#include "virkeepalive.h"
|
2014-02-27 13:41:11 +00:00
|
|
|
#include "virprobe.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
|
|
|
#include "virutil.h"
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("rpc.netserverclient");
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
/* Allow for filtering of incoming messages to a custom
|
|
|
|
* dispatch processing queue, instead of the workers.
|
|
|
|
* This allows for certain types of messages to be handled
|
|
|
|
* strictly "in order"
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _virNetServerClientFilter virNetServerClientFilter;
|
|
|
|
typedef virNetServerClientFilter *virNetServerClientFilterPtr;
|
|
|
|
|
|
|
|
struct _virNetServerClientFilter {
|
|
|
|
int id;
|
|
|
|
virNetServerClientFilterFunc func;
|
|
|
|
void *opaque;
|
|
|
|
|
|
|
|
virNetServerClientFilterPtr next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct _virNetServerClient
|
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLockable parent;
|
2012-07-11 13:35:52 +00:00
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
unsigned long long id;
|
2010-12-01 16:36:40 +00:00
|
|
|
bool wantClose;
|
2011-07-08 11:54:29 +00:00
|
|
|
bool delayedClose;
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetSocketPtr sock;
|
|
|
|
int auth;
|
2017-12-21 14:29:05 +00:00
|
|
|
bool auth_pending;
|
2010-12-01 16:36:40 +00:00
|
|
|
bool readonly;
|
|
|
|
virNetTLSContextPtr tlsCtxt;
|
|
|
|
virNetTLSSessionPtr tls;
|
2012-09-20 11:58:29 +00:00
|
|
|
#if WITH_SASL
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetSASLSessionPtr sasl;
|
|
|
|
#endif
|
2011-11-01 13:14:54 +00:00
|
|
|
int sockTimer; /* Timer to be fired upon cached data,
|
|
|
|
* so we jump out from poll() immediately */
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-01-23 15:05:01 +00:00
|
|
|
|
|
|
|
virIdentityPtr identity;
|
|
|
|
|
2016-04-12 17:21:43 +00:00
|
|
|
/* Connection timestamp, i.e. when a client connected to the daemon (UTC).
|
|
|
|
* For old clients restored by post-exec-restart, which did not have this
|
|
|
|
* attribute, value of 0 (epoch time) is used to indicate we have no
|
|
|
|
* information about their connection time.
|
|
|
|
*/
|
2016-05-05 07:07:50 +00:00
|
|
|
long long conn_time;
|
2016-04-12 17:21:43 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
/* Count of messages in the 'tx' queue,
|
|
|
|
* and the server worker pool queue
|
|
|
|
* ie RPC calls in progress. Does not count
|
|
|
|
* async events which are not used for
|
|
|
|
* throttling calculations */
|
|
|
|
size_t nrequests;
|
|
|
|
size_t nrequests_max;
|
|
|
|
/* Zero or one messages being received. Zero if
|
|
|
|
* nrequests >= max_clients and throttling */
|
|
|
|
virNetMessagePtr rx;
|
|
|
|
/* Zero or many messages waiting for transmit
|
|
|
|
* back to client, including async events */
|
|
|
|
virNetMessagePtr tx;
|
|
|
|
|
|
|
|
/* Filters to capture messages that would otherwise
|
|
|
|
* end up on the 'dx' queue */
|
|
|
|
virNetServerClientFilterPtr filters;
|
|
|
|
int nextFilterID;
|
|
|
|
|
|
|
|
virNetServerClientDispatchFunc dispatchFunc;
|
|
|
|
void *dispatchOpaque;
|
|
|
|
|
|
|
|
void *privateData;
|
2012-08-09 11:31:34 +00:00
|
|
|
virFreeCallback privateDataFreeFunc;
|
2012-08-09 11:54:54 +00:00
|
|
|
virNetServerClientPrivPreExecRestart privateDataPreExecRestart;
|
2011-08-14 22:44:45 +00:00
|
|
|
virNetServerClientCloseFunc privateDataCloseFunc;
|
2011-08-24 13:33:34 +00:00
|
|
|
|
|
|
|
virKeepAlivePtr keepalive;
|
2010-12-01 16:36:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
static virClassPtr virNetServerClientClass;
|
|
|
|
static void virNetServerClientDispose(void *obj);
|
|
|
|
|
|
|
|
static int virNetServerClientOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virNetServerClient, virClassForObjectLockable()))
|
2012-07-11 13:35:52 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virNetServerClient);
|
2012-07-11 13:35:52 +00:00
|
|
|
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
static void virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque);
|
|
|
|
static void virNetServerClientUpdateEvent(virNetServerClientPtr client);
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
static virNetMessagePtr virNetServerClientDispatchRead(virNetServerClientPtr client);
|
2012-06-12 07:01:49 +00:00
|
|
|
static int virNetServerClientSendMessageLocked(virNetServerClientPtr client,
|
|
|
|
virNetMessagePtr msg);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @client: a locked client object
|
|
|
|
*/
|
|
|
|
static int
|
2014-03-18 08:14:54 +00:00
|
|
|
virNetServerClientCalculateHandleMode(virNetServerClientPtr client)
|
|
|
|
{
|
2010-12-01 16:36:40 +00:00
|
|
|
int mode = 0;
|
|
|
|
|
|
|
|
|
|
|
|
VIR_DEBUG("tls=%p hs=%d, rx=%p tx=%p",
|
|
|
|
client->tls,
|
|
|
|
client->tls ? virNetTLSSessionGetHandshakeStatus(client->tls) : -1,
|
|
|
|
client->rx,
|
|
|
|
client->tx);
|
|
|
|
if (!client->sock || client->wantClose)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (client->tls) {
|
|
|
|
switch (virNetTLSSessionGetHandshakeStatus(client->tls)) {
|
|
|
|
case VIR_NET_TLS_HANDSHAKE_RECVING:
|
|
|
|
mode |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
break;
|
|
|
|
case VIR_NET_TLS_HANDSHAKE_SENDING:
|
|
|
|
mode |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case VIR_NET_TLS_HANDSHAKE_COMPLETE:
|
|
|
|
if (client->rx)
|
|
|
|
mode |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
if (client->tx)
|
|
|
|
mode |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-18 15:48:24 +00:00
|
|
|
/* If there is a message on the rx queue, and
|
|
|
|
* we're not in middle of a delayedClose, then
|
2010-12-01 16:36:40 +00:00
|
|
|
* we're wanting more input */
|
2012-07-18 15:48:24 +00:00
|
|
|
if (client->rx && !client->delayedClose)
|
2010-12-01 16:36:40 +00:00
|
|
|
mode |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
|
|
|
|
/* If there are one or more messages to send back to client,
|
|
|
|
then monitor for writability on socket */
|
|
|
|
if (client->tx)
|
|
|
|
mode |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
2017-09-25 10:43:33 +00:00
|
|
|
VIR_DEBUG("mode=0%o", mode);
|
2010-12-01 16:36:40 +00:00
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @server: a locked or unlocked server object
|
|
|
|
* @client: a locked client object
|
|
|
|
*/
|
|
|
|
static int virNetServerClientRegisterEvent(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
int mode = virNetServerClientCalculateHandleMode(client);
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
if (!client->sock)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virObjectRef(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
VIR_DEBUG("Registering client event callback %d", mode);
|
2012-07-11 13:35:52 +00:00
|
|
|
if (virNetSocketAddIOCallback(client->sock,
|
2010-12-01 16:36:40 +00:00
|
|
|
mode,
|
|
|
|
virNetServerClientDispatchEvent,
|
2011-07-19 13:11:33 +00:00
|
|
|
client,
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectFreeCallback) < 0) {
|
|
|
|
virObjectUnref(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return -1;
|
2011-07-19 13:11:33 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @client: a locked client object
|
|
|
|
*/
|
|
|
|
static void virNetServerClientUpdateEvent(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
if (!client->sock)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mode = virNetServerClientCalculateHandleMode(client);
|
|
|
|
|
|
|
|
virNetSocketUpdateIOCallback(client->sock, mode);
|
2011-11-01 13:14:54 +00:00
|
|
|
|
|
|
|
if (client->rx && virNetSocketHasCachedData(client->sock))
|
|
|
|
virEventUpdateTimeout(client->sockTimer, 0);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-12 07:02:38 +00:00
|
|
|
int virNetServerClientAddFilter(virNetServerClientPtr client,
|
|
|
|
virNetServerClientFilterFunc func,
|
|
|
|
void *opaque)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
virNetServerClientFilterPtr filter;
|
2011-08-24 13:33:34 +00:00
|
|
|
virNetServerClientFilterPtr *place;
|
2012-06-12 07:02:38 +00:00
|
|
|
int ret;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2020-09-24 18:58:46 +00:00
|
|
|
filter = g_new0(virNetServerClientFilter, 1);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-06-12 07:02:38 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
filter->id = client->nextFilterID++;
|
|
|
|
filter->func = func;
|
|
|
|
filter->opaque = opaque;
|
|
|
|
|
2011-08-24 13:33:34 +00:00
|
|
|
place = &client->filters;
|
|
|
|
while (*place)
|
|
|
|
place = &(*place)->next;
|
|
|
|
*place = filter;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
ret = filter->id;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2012-06-12 07:02:38 +00:00
|
|
|
|
2011-08-24 13:33:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-12 07:02:38 +00:00
|
|
|
void virNetServerClientRemoveFilter(virNetServerClientPtr client,
|
|
|
|
int filterID)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
virNetServerClientFilterPtr tmp, prev;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-06-12 07:02:38 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
prev = NULL;
|
|
|
|
tmp = client->filters;
|
|
|
|
while (tmp) {
|
|
|
|
if (tmp->id == filterID) {
|
|
|
|
if (prev)
|
|
|
|
prev->next = tmp->next;
|
|
|
|
else
|
|
|
|
client->filters = tmp->next;
|
|
|
|
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
break;
|
|
|
|
}
|
2011-07-04 01:45:21 +00:00
|
|
|
prev = tmp;
|
2010-12-01 16:36:40 +00:00
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Check the client's access. */
|
|
|
|
static int
|
|
|
|
virNetServerClientCheckAccess(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virNetMessagePtr confirm;
|
|
|
|
|
|
|
|
/* Verify client certificate. */
|
|
|
|
if (virNetTLSContextCheckCertificate(client->tlsCtxt, client->tls) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (client->tx) {
|
|
|
|
VIR_DEBUG("client had unexpected data pending tx after access check");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Fix tracking of RPC messages wrt streams
Commit 2c85644b0b51fbe5b6244e6773531af29933a727 attempted to
fix a problem with tracking RPC messages from streams by doing
- if (msg->header.type == VIR_NET_REPLY) {
+ if (msg->header.type == VIR_NET_REPLY ||
+ (msg->header.type == VIR_NET_STREAM &&
+ msg->header.status != VIR_NET_CONTINUE)) {
client->nrequests--;
In other words any stream packet, with status NET_OK or NET_ERROR
would cause nrequests to be decremented. This is great if the
packet from from a synchronous virStreamFinish or virStreamAbort
API call, but wildly wrong if from a server initiated abort.
The latter resulted in 'nrequests' being decremented below zero.
This then causes all I/O for that client to be stopped.
Instead of trying to infer whether we need to decrement the
nrequests field, from the message type/status, introduce an
explicit 'bool tracked' field to mark whether the virNetMessagePtr
object is subject to tracking.
Also add a virNetMessageClear function to allow a message
contents to be cleared out, without adversely impacting the
'tracked' field as a naive memset() would do
* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add
a 'bool tracked' field and virNetMessageClear() API
* daemon/remote.c, daemon/stream.c, src/rpc/virnetclientprogram.c,
src/rpc/virnetclientstream.c, src/rpc/virnetserverclient.c,
src/rpc/virnetserverprogram.c: Switch over to use
virNetMessageClear() and pass in the 'bool tracked' value
when creating messages.
2011-08-31 16:42:58 +00:00
|
|
|
if (!(confirm = virNetMessageNew(false)))
|
2010-12-01 16:36:40 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Checks have succeeded. Write a '\1' byte back to the client to
|
|
|
|
* indicate this (otherwise the socket is abruptly closed).
|
|
|
|
* (NB. The '\1' byte is sent in an encrypted record).
|
|
|
|
*/
|
|
|
|
confirm->bufferLength = 1;
|
2020-09-24 18:58:46 +00:00
|
|
|
confirm->buffer = g_new0(char, confirm->bufferLength);
|
2010-12-01 16:36:40 +00:00
|
|
|
confirm->bufferOffset = 0;
|
|
|
|
confirm->buffer[0] = '\1';
|
|
|
|
|
|
|
|
client->tx = confirm;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-06-04 09:12:29 +00:00
|
|
|
|
2013-01-07 14:54:18 +00:00
|
|
|
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
static void virNetServerClientDispatchMessage(virNetServerClientPtr client,
|
|
|
|
virNetMessagePtr msg)
|
|
|
|
{
|
|
|
|
virObjectLock(client);
|
|
|
|
if (!client->dispatchFunc) {
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
client->wantClose = true;
|
|
|
|
virObjectUnlock(client);
|
|
|
|
} else {
|
|
|
|
virObjectUnlock(client);
|
|
|
|
/* Accessing 'client' is safe, because virNetServerClientSetDispatcher
|
|
|
|
* only permits setting 'dispatchFunc' once, so if non-NULL, it will
|
|
|
|
* never change again
|
|
|
|
*/
|
|
|
|
client->dispatchFunc(client, msg, client->dispatchOpaque);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2011-11-01 13:14:54 +00:00
|
|
|
static void virNetServerClientSockTimerFunc(int timer,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virNetServerClientPtr client = opaque;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
virNetMessagePtr msg = NULL;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2011-11-01 13:14:54 +00:00
|
|
|
virEventUpdateTimeout(timer, -1);
|
|
|
|
/* Although client->rx != NULL when this timer is enabled, it might have
|
|
|
|
* changed since the client was unlocked in the meantime. */
|
|
|
|
if (client->rx)
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
msg = virNetServerClientDispatchRead(client);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
|
|
|
|
if (msg)
|
|
|
|
virNetServerClientDispatchMessage(client, msg);
|
2011-11-01 13:14:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2017-12-21 14:29:02 +00:00
|
|
|
/**
|
|
|
|
* virNetServerClientAuthMethodImpliesAuthenticated:
|
|
|
|
* @auth: authentication method to check
|
|
|
|
*
|
|
|
|
* Check if the passed authentication method implies that a client is
|
|
|
|
* automatically authenticated.
|
|
|
|
*
|
|
|
|
* Returns true if @auth implies that a client is automatically
|
|
|
|
* authenticated, otherwise false.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
virNetServerClientAuthMethodImpliesAuthenticated(int auth)
|
|
|
|
{
|
|
|
|
return auth == VIR_NET_SERVER_SERVICE_AUTH_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-09 11:52:48 +00:00
|
|
|
static virNetServerClientPtr
|
2016-04-13 18:54:40 +00:00
|
|
|
virNetServerClientNewInternal(unsigned long long id,
|
|
|
|
virNetSocketPtr sock,
|
2012-08-09 11:52:48 +00:00
|
|
|
int auth,
|
2017-12-21 14:29:05 +00:00
|
|
|
bool auth_pending,
|
2013-01-07 14:54:18 +00:00
|
|
|
virNetTLSContextPtr tls,
|
2012-08-09 11:52:48 +00:00
|
|
|
bool readonly,
|
2016-04-12 17:21:43 +00:00
|
|
|
size_t nrequests_max,
|
2016-05-05 07:07:50 +00:00
|
|
|
long long timestamp)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
virNetServerClientPtr client;
|
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
if (virNetServerClientInitialize() < 0)
|
2010-12-01 16:36:40 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
if (!(client = virObjectLockableNew(virNetServerClientClass)))
|
2012-07-11 13:35:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
client->id = id;
|
2012-08-09 11:06:45 +00:00
|
|
|
client->sock = virObjectRef(sock);
|
2010-12-01 16:36:40 +00:00
|
|
|
client->auth = auth;
|
2017-12-21 14:29:05 +00:00
|
|
|
client->auth_pending = auth_pending;
|
2010-12-01 16:36:40 +00:00
|
|
|
client->readonly = readonly;
|
2012-07-11 13:35:48 +00:00
|
|
|
client->tlsCtxt = virObjectRef(tls);
|
2011-06-30 10:45:55 +00:00
|
|
|
client->nrequests_max = nrequests_max;
|
2016-04-12 17:21:43 +00:00
|
|
|
client->conn_time = timestamp;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2011-11-01 13:14:54 +00:00
|
|
|
client->sockTimer = virEventAddTimeout(-1, virNetServerClientSockTimerFunc,
|
|
|
|
client, NULL);
|
|
|
|
if (client->sockTimer < 0)
|
|
|
|
goto error;
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
/* Prepare one for packet receive */
|
Fix tracking of RPC messages wrt streams
Commit 2c85644b0b51fbe5b6244e6773531af29933a727 attempted to
fix a problem with tracking RPC messages from streams by doing
- if (msg->header.type == VIR_NET_REPLY) {
+ if (msg->header.type == VIR_NET_REPLY ||
+ (msg->header.type == VIR_NET_STREAM &&
+ msg->header.status != VIR_NET_CONTINUE)) {
client->nrequests--;
In other words any stream packet, with status NET_OK or NET_ERROR
would cause nrequests to be decremented. This is great if the
packet from from a synchronous virStreamFinish or virStreamAbort
API call, but wildly wrong if from a server initiated abort.
The latter resulted in 'nrequests' being decremented below zero.
This then causes all I/O for that client to be stopped.
Instead of trying to infer whether we need to decrement the
nrequests field, from the message type/status, introduce an
explicit 'bool tracked' field to mark whether the virNetMessagePtr
object is subject to tracking.
Also add a virNetMessageClear function to allow a message
contents to be cleared out, without adversely impacting the
'tracked' field as a naive memset() would do
* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add
a 'bool tracked' field and virNetMessageClear() API
* daemon/remote.c, daemon/stream.c, src/rpc/virnetclientprogram.c,
src/rpc/virnetclientstream.c, src/rpc/virnetserverclient.c,
src/rpc/virnetserverprogram.c: Switch over to use
virNetMessageClear() and pass in the 'bool tracked' value
when creating messages.
2011-08-31 16:42:58 +00:00
|
|
|
if (!(client->rx = virNetMessageNew(true)))
|
2010-12-01 16:36:40 +00:00
|
|
|
goto error;
|
|
|
|
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
|
2020-09-24 18:58:46 +00:00
|
|
|
client->rx->buffer = g_new0(char, client->rx->bufferLength);
|
2010-12-01 16:36:40 +00:00
|
|
|
client->nrequests = 1;
|
|
|
|
|
Rewrite all the DTrace/SystemTAP probing
The libvirtd daemon had a few crude system tap probes. Some of
these were broken during the RPC rewrite. The new modular RPC
code is structured in a way that allows much more effective
tracing. Instead of trying to hook up the original probes,
define a new set of probes for the RPC and event code.
The master probes file is now src/probes.d. This contains
probes for virNetServerClientPtr, virNetClientPtr, virSocketPtr
virNetTLSContextPtr and virNetTLSSessionPtr modules. Also add
probes for the poll event loop.
The src/dtrace2systemtap.pl script can convert the probes.d
file into a libvirt_probes.stp file to make use from systemtap
much simpler.
The src/rpc/gensystemtap.pl script can generate a set of
systemtap functions for translating RPC enum values into
printable strings. This works for all RPC header enums (program,
type, status, procedure) and also the authentication enum
The PROBE macro will automatically generate a VIR_DEBUG
statement, so any place with a PROBE can remove any existing
manual DEBUG statements.
* daemon/libvirtd.stp, daemon/probes.d: Remove obsolete probing
* daemon/libvirtd.h: Remove probe macros
* daemon/Makefile.am: Remove all probe buildings/install
* daemon/remote.c: Update authentication probes
* src/dtrace2systemtap.pl, src/rpc/gensystemtap.pl: Scripts
to generate STP files
* src/internal.h: Add probe macros
* src/probes.d: Master list of probes
* src/rpc/virnetclient.c, src/rpc/virnetserverclient.c,
src/rpc/virnetsocket.c, src/rpc/virnettlscontext.c,
src/util/event_poll.c: Insert probe points, removing any
DEBUG statements that duplicate the info
2011-09-30 13:40:23 +00:00
|
|
|
PROBE(RPC_SERVER_CLIENT_NEW,
|
2012-07-11 13:35:52 +00:00
|
|
|
"client=%p sock=%p",
|
|
|
|
client, client->sock);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
return client;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
virNetServerClientPtr virNetServerClientNew(unsigned long long id,
|
|
|
|
virNetSocketPtr sock,
|
2012-08-09 11:52:48 +00:00
|
|
|
int auth,
|
|
|
|
bool readonly,
|
|
|
|
size_t nrequests_max,
|
|
|
|
virNetTLSContextPtr tls,
|
|
|
|
virNetServerClientPrivNew privNew,
|
2012-08-09 11:54:54 +00:00
|
|
|
virNetServerClientPrivPreExecRestart privPreExecRestart,
|
2012-08-09 11:52:48 +00:00
|
|
|
virFreeCallback privFree,
|
|
|
|
void *privOpaque)
|
|
|
|
{
|
|
|
|
virNetServerClientPtr client;
|
2016-04-12 17:21:43 +00:00
|
|
|
time_t now;
|
2017-12-21 14:29:05 +00:00
|
|
|
bool auth_pending = !virNetServerClientAuthMethodImpliesAuthenticated(auth);
|
2012-08-09 11:52:48 +00:00
|
|
|
|
2018-06-04 09:12:29 +00:00
|
|
|
VIR_DEBUG("sock=%p auth=%d tls=%p", sock, auth, tls);
|
2012-08-09 11:52:48 +00:00
|
|
|
|
2018-04-25 12:42:34 +00:00
|
|
|
if ((now = time(NULL)) == (time_t)-1) {
|
2016-04-12 17:21:43 +00:00
|
|
|
virReportSystemError(errno, "%s", _("failed to get current time"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-21 14:29:05 +00:00
|
|
|
if (!(client = virNetServerClientNewInternal(id, sock, auth, auth_pending,
|
2018-06-04 09:12:29 +00:00
|
|
|
tls, readonly, nrequests_max,
|
2016-04-12 17:21:43 +00:00
|
|
|
now)))
|
2012-08-09 11:52:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
2018-02-01 15:34:06 +00:00
|
|
|
if (!(client->privateData = privNew(client, privOpaque))) {
|
|
|
|
virObjectUnref(client);
|
|
|
|
return NULL;
|
2012-08-09 11:52:48 +00:00
|
|
|
}
|
2018-02-01 15:34:06 +00:00
|
|
|
client->privateDataFreeFunc = privFree;
|
|
|
|
client->privateDataPreExecRestart = privPreExecRestart;
|
2012-08-09 11:52:48 +00:00
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-19 17:41:13 +00:00
|
|
|
virNetServerClientPtr virNetServerClientNewPostExecRestart(virNetServerPtr srv,
|
|
|
|
virJSONValuePtr object,
|
2012-08-09 11:54:54 +00:00
|
|
|
virNetServerClientPrivNewPostExecRestart privNew,
|
|
|
|
virNetServerClientPrivPreExecRestart privPreExecRestart,
|
|
|
|
virFreeCallback privFree,
|
2018-01-19 17:41:13 +00:00
|
|
|
void *privOpaque)
|
2012-08-09 11:54:54 +00:00
|
|
|
{
|
|
|
|
virJSONValuePtr child;
|
|
|
|
virNetServerClientPtr client = NULL;
|
|
|
|
virNetSocketPtr sock;
|
|
|
|
int auth;
|
2017-12-21 14:29:05 +00:00
|
|
|
bool readonly, auth_pending;
|
2012-08-09 11:54:54 +00:00
|
|
|
unsigned int nrequests_max;
|
2016-04-13 18:54:40 +00:00
|
|
|
unsigned long long id;
|
2016-05-05 07:07:50 +00:00
|
|
|
long long timestamp;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(object, "auth", &auth) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing auth field in JSON state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-21 14:29:05 +00:00
|
|
|
|
|
|
|
if (!virJSONValueObjectHasKey(object, "auth_pending")) {
|
|
|
|
auth_pending = !virNetServerClientAuthMethodImpliesAuthenticated(auth);
|
|
|
|
} else {
|
|
|
|
if (virJSONValueObjectGetBoolean(object, "auth_pending", &auth_pending) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Malformed auth_pending field in JSON state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the used authentication method implies that the new
|
|
|
|
* client is automatically authenticated, the authentication
|
|
|
|
* cannot be pending */
|
|
|
|
if (auth_pending && virNetServerClientAuthMethodImpliesAuthenticated(auth)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Invalid auth_pending and auth combination in JSON state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
if (virJSONValueObjectGetBoolean(object, "readonly", &readonly) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing readonly field in JSON state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetNumberUint(object, "nrequests_max",
|
2016-05-05 06:42:50 +00:00
|
|
|
&nrequests_max) < 0) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing nrequests_client_max field in JSON state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(child = virJSONValueObjectGet(object, "sock"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing sock field in JSON state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
if (!virJSONValueObjectHasKey(object, "id")) {
|
|
|
|
/* no ID found in, a new one must be generated */
|
2018-01-19 17:41:13 +00:00
|
|
|
id = virNetServerNextClientID(srv);
|
2016-04-13 18:54:40 +00:00
|
|
|
} else {
|
2016-05-05 06:42:50 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(object, "id", &id) < 0) {
|
2018-01-19 17:41:13 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Malformed id field in JSON state document"));
|
|
|
|
return NULL;
|
2016-04-13 18:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 17:21:43 +00:00
|
|
|
if (!virJSONValueObjectHasKey(object, "conn_time")) {
|
|
|
|
timestamp = 0;
|
|
|
|
} else {
|
2016-05-05 07:07:50 +00:00
|
|
|
if (virJSONValueObjectGetNumberLong(object, "conn_time", ×tamp) < 0) {
|
2016-04-12 17:21:43 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Malformed conn_time field in JSON "
|
|
|
|
"state document"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
if (!(sock = virNetSocketNewPostExecRestart(child))) {
|
|
|
|
virObjectUnref(sock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
if (!(client = virNetServerClientNewInternal(id,
|
|
|
|
sock,
|
2012-08-09 11:54:54 +00:00
|
|
|
auth,
|
2017-12-21 14:29:05 +00:00
|
|
|
auth_pending,
|
2013-01-07 14:54:18 +00:00
|
|
|
NULL,
|
2012-08-09 11:54:54 +00:00
|
|
|
readonly,
|
2016-04-12 17:21:43 +00:00
|
|
|
nrequests_max,
|
|
|
|
timestamp))) {
|
2012-08-09 11:54:54 +00:00
|
|
|
virObjectUnref(sock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
virObjectUnref(sock);
|
|
|
|
|
2018-02-01 15:34:06 +00:00
|
|
|
if (!(child = virJSONValueObjectGet(object, "privateData"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing privateData field in JSON state document"));
|
|
|
|
goto error;
|
2012-08-09 11:54:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 15:34:06 +00:00
|
|
|
if (!(client->privateData = privNew(client, child, privOpaque)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
client->privateDataFreeFunc = privFree;
|
|
|
|
client->privateDataPreExecRestart = privPreExecRestart;
|
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
|
|
|
|
return client;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2012-08-09 11:54:54 +00:00
|
|
|
virObjectUnref(client);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virJSONValuePtr object = virJSONValueNewObject();
|
|
|
|
virJSONValuePtr child;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
if (virJSONValueObjectAppendNumberUlong(object, "id",
|
|
|
|
client->id) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < 0)
|
|
|
|
goto error;
|
2017-12-21 14:29:05 +00:00
|
|
|
if (virJSONValueObjectAppendBoolean(object, "auth_pending", client->auth_pending) < 0)
|
|
|
|
goto error;
|
2012-08-09 11:54:54 +00:00
|
|
|
if (virJSONValueObjectAppendBoolean(object, "readonly", client->readonly) < 0)
|
|
|
|
goto error;
|
|
|
|
if (virJSONValueObjectAppendNumberUint(object, "nrequests_max", client->nrequests_max) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2016-04-12 17:21:43 +00:00
|
|
|
if (client->conn_time &&
|
|
|
|
virJSONValueObjectAppendNumberLong(object, "conn_time",
|
|
|
|
client->conn_time) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-08-09 11:54:54 +00:00
|
|
|
if (!(child = virNetSocketPreExecRestart(client->sock)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppend(object, "sock", child) < 0) {
|
|
|
|
virJSONValueFree(child);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:34:06 +00:00
|
|
|
if (!(child = client->privateDataPreExecRestart(client, client->privateData)))
|
|
|
|
goto error;
|
2012-08-09 11:54:54 +00:00
|
|
|
|
2018-02-01 15:34:06 +00:00
|
|
|
if (virJSONValueObjectAppend(object, "privateData", child) < 0) {
|
|
|
|
virJSONValueFree(child);
|
|
|
|
goto error;
|
2012-08-09 11:54:54 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2012-08-09 11:54:54 +00:00
|
|
|
return object;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2012-08-09 11:54:54 +00:00
|
|
|
virJSONValueFree(object);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
int virNetServerClientGetAuth(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
int auth;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
auth = client->auth;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return auth;
|
|
|
|
}
|
|
|
|
|
2017-12-21 14:29:04 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
virNetServerClientSetAuthLocked(virNetServerClientPtr client,
|
|
|
|
int auth)
|
2012-01-20 16:56:31 +00:00
|
|
|
{
|
|
|
|
client->auth = auth;
|
|
|
|
}
|
|
|
|
|
2017-12-21 14:29:04 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
bool virNetServerClientGetReadonly(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
bool readonly;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
readonly = client->readonly;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return readonly;
|
|
|
|
}
|
|
|
|
|
2017-12-13 13:39:40 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
virNetServerClientSetReadonly(virNetServerClientPtr client,
|
|
|
|
bool readonly)
|
|
|
|
{
|
|
|
|
virObjectLock(client);
|
|
|
|
client->readonly = readonly;
|
|
|
|
virObjectUnlock(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
unsigned long long virNetServerClientGetID(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
return client->id;
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2016-04-12 17:21:43 +00:00
|
|
|
long long virNetServerClientGetTimestamp(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
return client->conn_time;
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
bool virNetServerClientHasTLSSession(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
bool has;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
has = client->tls ? true : false;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return has;
|
|
|
|
}
|
|
|
|
|
2012-01-20 17:18:28 +00:00
|
|
|
|
|
|
|
virNetTLSSessionPtr virNetServerClientGetTLSSession(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virNetTLSSessionPtr tls;
|
|
|
|
virObjectLock(client);
|
|
|
|
tls = client->tls;
|
|
|
|
virObjectUnlock(client);
|
|
|
|
return tls;
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
int virNetServerClientGetTLSKeySize(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
int size = 0;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (client->tls)
|
|
|
|
size = virNetTLSSessionGetKeySize(client->tls);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virNetServerClientGetFD(virNetServerClientPtr client)
|
|
|
|
{
|
2011-08-01 19:41:38 +00:00
|
|
|
int fd = -1;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2011-08-01 19:41:38 +00:00
|
|
|
if (client->sock)
|
|
|
|
fd = virNetSocketGetFD(client->sock);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2012-01-20 17:18:28 +00:00
|
|
|
|
|
|
|
bool virNetServerClientIsLocal(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
bool local = false;
|
|
|
|
virObjectLock(client);
|
|
|
|
if (client->sock)
|
|
|
|
local = virNetSocketIsLocal(client->sock);
|
|
|
|
virObjectUnlock(client);
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-18 17:41:36 +00:00
|
|
|
int virNetServerClientGetUNIXIdentity(virNetServerClientPtr client,
|
2013-04-25 16:05:00 +00:00
|
|
|
uid_t *uid, gid_t *gid, pid_t *pid,
|
|
|
|
unsigned long long *timestamp)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2011-08-01 19:41:38 +00:00
|
|
|
int ret = -1;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2011-08-01 19:41:38 +00:00
|
|
|
if (client->sock)
|
2013-04-25 16:05:00 +00:00
|
|
|
ret = virNetSocketGetUNIXIdentity(client->sock,
|
|
|
|
uid, gid, pid,
|
|
|
|
timestamp);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-20 17:18:28 +00:00
|
|
|
|
2012-01-23 15:05:01 +00:00
|
|
|
static virIdentityPtr
|
|
|
|
virNetServerClientCreateIdentity(virNetServerClientPtr client)
|
|
|
|
{
|
2019-10-01 14:37:09 +00:00
|
|
|
g_autofree char *username = NULL;
|
|
|
|
g_autofree char *groupname = NULL;
|
|
|
|
g_autofree char *seccontext = NULL;
|
|
|
|
g_autoptr(virIdentity) ret = NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
|
2013-08-22 15:58:58 +00:00
|
|
|
if (!(ret = virIdentityNew()))
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2013-08-22 15:58:58 +00:00
|
|
|
|
2012-01-23 15:05:01 +00:00
|
|
|
if (client->sock && virNetSocketIsLocal(client->sock)) {
|
|
|
|
gid_t gid;
|
|
|
|
uid_t uid;
|
|
|
|
pid_t pid;
|
2013-04-25 16:05:00 +00:00
|
|
|
unsigned long long timestamp;
|
|
|
|
if (virNetSocketGetUNIXIdentity(client->sock,
|
|
|
|
&uid, &gid, &pid,
|
|
|
|
×tamp) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
|
|
|
|
if (!(username = virGetUserName(uid)))
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2019-07-26 10:59:15 +00:00
|
|
|
if (virIdentitySetUserName(ret, username) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2013-08-22 15:58:58 +00:00
|
|
|
if (virIdentitySetUNIXUserID(ret, uid) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2013-08-22 15:58:58 +00:00
|
|
|
|
2012-01-23 15:05:01 +00:00
|
|
|
if (!(groupname = virGetGroupName(gid)))
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2019-07-26 10:59:15 +00:00
|
|
|
if (virIdentitySetGroupName(ret, groupname) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2013-08-22 15:58:58 +00:00
|
|
|
if (virIdentitySetUNIXGroupID(ret, gid) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2013-08-22 15:58:58 +00:00
|
|
|
|
2019-07-26 10:59:15 +00:00
|
|
|
if (virIdentitySetProcessID(ret, pid) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2019-07-26 10:59:15 +00:00
|
|
|
if (virIdentitySetProcessTime(ret, timestamp) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if WITH_SASL
|
|
|
|
if (client->sasl) {
|
|
|
|
const char *identity = virNetSASLSessionGetIdentity(client->sasl);
|
2013-08-22 15:58:58 +00:00
|
|
|
if (virIdentitySetSASLUserName(ret, identity) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (client->tls) {
|
|
|
|
const char *identity = virNetTLSSessionGetX509DName(client->tls);
|
2013-08-22 15:58:58 +00:00
|
|
|
if (virIdentitySetX509DName(ret, identity) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (client->sock &&
|
2013-04-25 10:33:43 +00:00
|
|
|
virNetSocketGetSELinuxContext(client->sock, &seccontext) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
if (seccontext &&
|
2013-08-22 15:58:58 +00:00
|
|
|
virIdentitySetSELinuxContext(ret, seccontext) < 0)
|
2019-10-01 14:37:09 +00:00
|
|
|
return NULL;
|
2012-01-23 15:05:01 +00:00
|
|
|
|
2019-10-01 14:37:09 +00:00
|
|
|
return g_steal_pointer(&ret);
|
2012-01-23 15:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virIdentityPtr virNetServerClientGetIdentity(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virIdentityPtr ret = NULL;
|
|
|
|
virObjectLock(client);
|
|
|
|
if (!client->identity)
|
|
|
|
client->identity = virNetServerClientCreateIdentity(client);
|
|
|
|
if (client->identity)
|
2019-09-19 14:38:03 +00:00
|
|
|
ret = g_object_ref(client->identity);
|
2012-01-23 15:05:01 +00:00
|
|
|
virObjectUnlock(client);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-26 15:34:15 +00:00
|
|
|
void virNetServerClientSetIdentity(virNetServerClientPtr client,
|
|
|
|
virIdentityPtr identity)
|
|
|
|
{
|
|
|
|
virObjectLock(client);
|
2019-09-19 14:38:03 +00:00
|
|
|
g_clear_object(&client->identity);
|
2019-07-26 15:34:15 +00:00
|
|
|
client->identity = identity;
|
|
|
|
if (client->identity)
|
2019-09-19 14:38:03 +00:00
|
|
|
g_object_ref(client->identity);
|
2019-07-26 15:34:15 +00:00
|
|
|
virObjectUnlock(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 10:33:43 +00:00
|
|
|
int virNetServerClientGetSELinuxContext(virNetServerClientPtr client,
|
|
|
|
char **context)
|
2012-01-20 17:18:28 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
*context = NULL;
|
|
|
|
virObjectLock(client);
|
|
|
|
if (client->sock)
|
2013-04-25 10:33:43 +00:00
|
|
|
ret = virNetSocketGetSELinuxContext(client->sock, context);
|
2012-01-20 17:18:28 +00:00
|
|
|
virObjectUnlock(client);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
bool virNetServerClientIsSecure(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
bool secure = false;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (client->tls)
|
|
|
|
secure = true;
|
2012-09-20 11:58:29 +00:00
|
|
|
#if WITH_SASL
|
2010-12-01 16:36:40 +00:00
|
|
|
if (client->sasl)
|
|
|
|
secure = true;
|
|
|
|
#endif
|
2011-08-01 19:41:38 +00:00
|
|
|
if (client->sock && virNetSocketIsLocal(client->sock))
|
2010-12-01 16:36:40 +00:00
|
|
|
secure = true;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return secure;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-20 11:58:29 +00:00
|
|
|
#if WITH_SASL
|
2010-12-01 16:36:40 +00:00
|
|
|
void virNetServerClientSetSASLSession(virNetServerClientPtr client,
|
|
|
|
virNetSASLSessionPtr sasl)
|
|
|
|
{
|
|
|
|
/* We don't set the sasl session on the socket here
|
|
|
|
* because we need to send out the auth confirmation
|
|
|
|
* in the clear. Only once we complete the next 'tx'
|
|
|
|
* operation do we switch to SASL mode
|
|
|
|
*/
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-07-11 13:35:49 +00:00
|
|
|
client->sasl = virObjectRef(sasl);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
2012-01-20 17:18:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
virNetSASLSessionPtr virNetServerClientGetSASLSession(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virNetSASLSessionPtr sasl;
|
|
|
|
virObjectLock(client);
|
|
|
|
sasl = client->sasl;
|
|
|
|
virObjectUnlock(client);
|
|
|
|
return sasl;
|
|
|
|
}
|
2016-04-22 10:54:26 +00:00
|
|
|
|
|
|
|
bool virNetServerClientHasSASLSession(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
bool has = false;
|
|
|
|
virObjectLock(client);
|
|
|
|
has = !!client->sasl;
|
|
|
|
virObjectUnlock(client);
|
|
|
|
return has;
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void *virNetServerClientGetPrivateData(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
void *data;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
data = client->privateData;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-14 22:44:45 +00:00
|
|
|
void virNetServerClientSetCloseHook(virNetServerClientPtr client,
|
|
|
|
virNetServerClientCloseFunc cf)
|
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2011-08-14 22:44:45 +00:00
|
|
|
client->privateDataCloseFunc = cf;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2011-08-14 22:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
void virNetServerClientSetDispatcher(virNetServerClientPtr client,
|
|
|
|
virNetServerClientDispatchFunc func,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
/* Only set dispatcher if not already set, to avoid race
|
|
|
|
* with dispatch code that runs without locks held
|
|
|
|
*/
|
|
|
|
if (!client->dispatchFunc) {
|
|
|
|
client->dispatchFunc = func;
|
|
|
|
client->dispatchOpaque = opaque;
|
|
|
|
}
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-20 14:04:49 +00:00
|
|
|
const char *virNetServerClientLocalAddrStringSASL(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2011-08-01 19:41:38 +00:00
|
|
|
if (!client->sock)
|
|
|
|
return NULL;
|
2016-06-20 14:01:50 +00:00
|
|
|
return virNetSocketLocalAddrStringSASL(client->sock);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-20 14:04:49 +00:00
|
|
|
const char *virNetServerClientRemoteAddrStringSASL(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2011-08-01 19:41:38 +00:00
|
|
|
if (!client->sock)
|
|
|
|
return NULL;
|
2016-06-20 14:01:50 +00:00
|
|
|
return virNetSocketRemoteAddrStringSASL(client->sock);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
2016-06-20 13:51:18 +00:00
|
|
|
const char *virNetServerClientRemoteAddrStringURI(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
if (!client->sock)
|
|
|
|
return NULL;
|
|
|
|
return virNetSocketRemoteAddrStringURI(client->sock);
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
void virNetServerClientDispose(void *obj)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2012-07-11 13:35:52 +00:00
|
|
|
virNetServerClientPtr client = obj;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-03-13 19:17:32 +00:00
|
|
|
PROBE(RPC_SERVER_CLIENT_DISPOSE,
|
|
|
|
"client=%p", client);
|
|
|
|
|
2018-02-01 15:34:06 +00:00
|
|
|
if (client->privateData)
|
2010-12-01 16:36:40 +00:00
|
|
|
client->privateDataFreeFunc(client->privateData);
|
|
|
|
|
2019-09-19 14:38:03 +00:00
|
|
|
g_clear_object(&client->identity);
|
rpc: Don't unref identity object while callbacks still can be executed
While this thread is cleaning up the client and connection objects:
#2 virFileReadAll (path=0x7f28780012b0 "/proc/1319/stat", maxlen=maxlen@entry=1024, buf=buf@entry=0x7f289c60fc40) at util/virfile.c:1287
#3 0x00007f28adbb1539 in virProcessGetStartTime (pid=<optimized out>, timestamp=timestamp@entry=0x7f289c60fc98) at util/virprocess.c:838
#4 0x00007f28adb91981 in virIdentityGetSystem () at util/viridentity.c:151
#5 0x00007f28ae73f17c in remoteClientFreeFunc (data=<optimized out>) at remote.c:1131
#6 0x00007f28adcb7f33 in virNetServerClientDispose (obj=0x7f28aecad180) at rpc/virnetserverclient.c:858
#7 0x00007f28adba8eeb in virObjectUnref (anyobj=<optimized out>) at util/virobject.c:265
#8 0x00007f28ae74ad05 in virNetServerHandleJob (jobOpaque=<optimized out>, opaque=0x7f28aec93ff0) at rpc/virnetserver.c:205
#9 0x00007f28adbbef4e in virThreadPoolWorker (opaque=opaque@entry=0x7f28aec88030) at util/virthreadpool.c:145
In stack frame #6 the client->identity object got unref'd, but the code
that removes the event callbacks in frame #5 did not run yet as we are
trying to obtain the system identity (frames #4, #3, #2).
In other thead:
#0 virObjectUnref (anyobj=anyobj@entry=0x7f288c162c60) at util/virobject.c:264
klass = 0xdeadbeef
obj = 0x7f288c162c60
#1 0x00007f28ae71c709 in remoteRelayDomainEventCheckACL (client=<optimized out>, conn=<optimized out>, dom=dom@entry=0x7f28aecaafc0) at remote.c:164
#2 0x00007f28ae71fc83 in remoteRelayDomainEventTrayChange (conn=<optimized out>, dom=0x7f28aecaafc0, ... ) at remote.c:717
#3 0x00007f28adc04e53 in virDomainEventDispatchDefaultFunc (conn=0x7f287c0009a0, event=0x7f28aecab1a0, ...) at conf/domain_event.c:1455
#4 0x00007f28adc03831 in virObjectEventStateDispatchCallbacks (callbacks=<optimized out>, ....) at conf/object_event.c:724
#5 virObjectEventStateQueueDispatch (callbacks=0x7f288c083730, queue=0x7fff51f90030, state=0x7f288c18da20) at conf/object_event.c:738
#6 virObjectEventStateFlush (state=0x7f288c18da20) at conf/object_event.c:816
#7 virObjectEventTimer (timer=<optimized out>, opaque=0x7f288c18da20) at conf/object_event.c:562
#8 0x00007f28adb859cd in virEventPollDispatchTimeouts () at util/vireventpoll.c:459
Frame #0 is unrefing an invalid identity object while frame #2 hints
that the client is still dispatching the event.
For untrimmed backtrace see the bugzilla attachment.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1203030
2015-03-25 07:56:07 +00:00
|
|
|
|
2012-09-20 11:58:29 +00:00
|
|
|
#if WITH_SASL
|
2012-07-11 13:35:49 +00:00
|
|
|
virObjectUnref(client->sasl);
|
2010-12-01 16:36:40 +00:00
|
|
|
#endif
|
2011-11-01 13:14:54 +00:00
|
|
|
if (client->sockTimer > 0)
|
|
|
|
virEventRemoveTimeout(client->sockTimer);
|
2012-07-11 13:35:48 +00:00
|
|
|
virObjectUnref(client->tls);
|
|
|
|
virObjectUnref(client->tlsCtxt);
|
2012-07-11 13:35:51 +00:00
|
|
|
virObjectUnref(client->sock);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* We don't free stuff here, merely disconnect the client's
|
|
|
|
* network socket & resources.
|
|
|
|
*
|
|
|
|
* Full free of the client is done later in a safe point
|
|
|
|
* where it can be guaranteed it is no longer in use
|
|
|
|
*/
|
2017-12-21 14:29:03 +00:00
|
|
|
void
|
|
|
|
virNetServerClientCloseLocked(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2011-08-14 22:44:45 +00:00
|
|
|
virNetServerClientCloseFunc cf;
|
2011-08-24 13:33:34 +00:00
|
|
|
virKeepAlivePtr ka;
|
2011-08-14 22:44:45 +00:00
|
|
|
|
2012-07-11 13:35:52 +00:00
|
|
|
VIR_DEBUG("client=%p", client);
|
2017-12-21 14:29:03 +00:00
|
|
|
if (!client->sock)
|
2010-12-01 16:36:40 +00:00
|
|
|
return;
|
|
|
|
|
2011-08-24 13:33:34 +00:00
|
|
|
if (client->keepalive) {
|
|
|
|
virKeepAliveStop(client->keepalive);
|
|
|
|
ka = client->keepalive;
|
|
|
|
client->keepalive = NULL;
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectRef(client);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2012-07-11 13:35:50 +00:00
|
|
|
virObjectUnref(ka);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(client);
|
2011-08-24 13:33:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-14 22:44:45 +00:00
|
|
|
if (client->privateDataCloseFunc) {
|
|
|
|
cf = client->privateDataCloseFunc;
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectRef(client);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2011-08-14 22:44:45 +00:00
|
|
|
(cf)(client);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(client);
|
2011-08-14 22:44:45 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
/* Do now, even though we don't close the socket
|
|
|
|
* until end, to ensure we don't get invoked
|
|
|
|
* again due to tls shutdown */
|
|
|
|
if (client->sock)
|
|
|
|
virNetSocketRemoveIOCallback(client->sock);
|
|
|
|
|
|
|
|
if (client->tls) {
|
2012-07-11 13:35:48 +00:00
|
|
|
virObjectUnref(client->tls);
|
2010-12-01 16:36:40 +00:00
|
|
|
client->tls = NULL;
|
|
|
|
}
|
2011-08-01 19:41:38 +00:00
|
|
|
client->wantClose = true;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
while (client->rx) {
|
|
|
|
virNetMessagePtr msg
|
|
|
|
= virNetMessageQueueServe(&client->rx);
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
}
|
|
|
|
while (client->tx) {
|
|
|
|
virNetMessagePtr msg
|
|
|
|
= virNetMessageQueueServe(&client->tx);
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
}
|
|
|
|
|
2011-08-01 19:41:38 +00:00
|
|
|
if (client->sock) {
|
2012-07-11 13:35:51 +00:00
|
|
|
virObjectUnref(client->sock);
|
2011-08-01 19:41:38 +00:00
|
|
|
client->sock = NULL;
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-21 14:29:03 +00:00
|
|
|
void
|
|
|
|
virNetServerClientClose(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2017-12-21 14:29:03 +00:00
|
|
|
virNetServerClientCloseLocked(client);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 14:29:03 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
virNetServerClientIsClosedLocked(virNetServerClientPtr client)
|
|
|
|
{
|
2018-01-04 13:22:11 +00:00
|
|
|
return client->sock == NULL;
|
2017-12-21 14:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-08 11:54:29 +00:00
|
|
|
void virNetServerClientDelayedClose(virNetServerClientPtr client)
|
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2011-07-08 11:54:29 +00:00
|
|
|
client->delayedClose = true;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2011-07-08 11:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void virNetServerClientImmediateClose(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
client->wantClose = true;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 14:29:03 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
virNetServerClientWantCloseLocked(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2017-12-21 14:29:03 +00:00
|
|
|
return client->wantClose;
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int virNetServerClientInit(virNetServerClientPtr client)
|
|
|
|
{
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
if (!client->tlsCtxt) {
|
|
|
|
/* Plain socket, so prepare to read first message */
|
|
|
|
if (virNetServerClientRegisterEvent(client) < 0)
|
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(client->tls = virNetTLSSessionNew(client->tlsCtxt,
|
|
|
|
NULL)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
virNetSocketSetTLSSession(client->sock,
|
|
|
|
client->tls);
|
|
|
|
|
|
|
|
/* Begin the TLS handshake. */
|
2020-03-07 11:31:01 +00:00
|
|
|
virObjectLock(client->tlsCtxt);
|
2010-12-01 16:36:40 +00:00
|
|
|
ret = virNetTLSSessionHandshake(client->tls);
|
2020-03-07 11:31:01 +00:00
|
|
|
virObjectUnlock(client->tlsCtxt);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
/* Unlikely, but ... Next step is to check the certificate. */
|
|
|
|
if (virNetServerClientCheckAccess(client) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Handshake & cert check OK, so prepare to read first message */
|
|
|
|
if (virNetServerClientRegisterEvent(client) < 0)
|
|
|
|
goto error;
|
|
|
|
} else if (ret > 0) {
|
|
|
|
/* Most likely, need to do more handshake data */
|
|
|
|
if (virNetServerClientRegisterEvent(client) < 0)
|
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
error:
|
2010-12-01 16:36:40 +00:00
|
|
|
client->wantClose = true;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read data into buffer using wire decoding (plain or TLS)
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* -1 on error or EOF
|
|
|
|
* 0 on EAGAIN
|
|
|
|
* n number of bytes
|
|
|
|
*/
|
|
|
|
static ssize_t virNetServerClientRead(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
if (client->rx->bufferLength <= client->rx->bufferOffset) {
|
2012-07-18 10:41:47 +00:00
|
|
|
virReportError(VIR_ERR_RPC,
|
|
|
|
_("unexpected zero/negative length request %lld"),
|
|
|
|
(long long int)(client->rx->bufferLength - client->rx->bufferOffset));
|
2010-12-01 16:36:40 +00:00
|
|
|
client->wantClose = true;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virNetSocketRead(client->sock,
|
|
|
|
client->rx->buffer + client->rx->bufferOffset,
|
|
|
|
client->rx->bufferLength - client->rx->bufferOffset);
|
|
|
|
|
|
|
|
if (ret <= 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
client->rx->bufferOffset += ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
* Read data until we get a complete message to process.
|
|
|
|
* If a complete message is available, it will be returned
|
|
|
|
* from this method, for dispatch by the caller.
|
|
|
|
*
|
|
|
|
* Returns a complete message for dispatch, or NULL if none is
|
|
|
|
* yet available, or an error occurred. On error, the wantClose
|
|
|
|
* flag will be set.
|
2010-12-01 16:36:40 +00:00
|
|
|
*/
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
static virNetMessagePtr virNetServerClientDispatchRead(virNetServerClientPtr client)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
2014-03-25 06:52:31 +00:00
|
|
|
readmore:
|
2011-11-04 16:02:14 +00:00
|
|
|
if (client->rx->nfds == 0) {
|
|
|
|
if (virNetServerClientRead(client) < 0) {
|
|
|
|
client->wantClose = true;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL; /* Error */
|
2011-11-04 16:02:14 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (client->rx->bufferOffset < client->rx->bufferLength)
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL; /* Still not read enough */
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
/* Either done with length word header */
|
|
|
|
if (client->rx->bufferLength == VIR_NET_MESSAGE_LEN_MAX) {
|
2011-07-08 11:37:22 +00:00
|
|
|
if (virNetMessageDecodeLength(client->rx) < 0) {
|
|
|
|
client->wantClose = true;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL;
|
2011-07-08 11:37:22 +00:00
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
virNetServerClientUpdateEvent(client);
|
|
|
|
|
|
|
|
/* Try and read payload immediately instead of going back
|
|
|
|
into poll() because chances are the data is already
|
|
|
|
waiting for us */
|
|
|
|
goto readmore;
|
|
|
|
} else {
|
|
|
|
/* Grab the completed message */
|
2011-11-04 16:02:14 +00:00
|
|
|
virNetMessagePtr msg = client->rx;
|
2012-06-12 07:01:49 +00:00
|
|
|
virNetMessagePtr response = NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetServerClientFilterPtr filter;
|
2011-10-21 11:12:28 +00:00
|
|
|
size_t i;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
/* Decode the header so we can use it for routing decisions */
|
|
|
|
if (virNetMessageDecodeHeader(msg) < 0) {
|
2013-01-04 15:15:04 +00:00
|
|
|
virNetMessageQueueServe(&client->rx);
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetMessageFree(msg);
|
|
|
|
client->wantClose = true;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 16:02:14 +00:00
|
|
|
/* Now figure out if we need to read more data to get some
|
|
|
|
* file descriptors */
|
2015-11-26 16:10:40 +00:00
|
|
|
if (msg->header.type == VIR_NET_CALL_WITH_FDS) {
|
2017-09-26 14:47:20 +00:00
|
|
|
if (virNetMessageDecodeNumFDs(msg) < 0) {
|
2013-01-04 15:15:04 +00:00
|
|
|
virNetMessageQueueServe(&client->rx);
|
2011-10-21 11:12:28 +00:00
|
|
|
virNetMessageFree(msg);
|
|
|
|
client->wantClose = true;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL; /* Error */
|
2011-10-21 11:12:28 +00:00
|
|
|
}
|
2011-11-04 16:02:14 +00:00
|
|
|
|
2015-11-26 16:10:40 +00:00
|
|
|
/* Try getting the file descriptors (may fail if blocking) */
|
|
|
|
for (i = msg->donefds; i < msg->nfds; i++) {
|
|
|
|
int rv;
|
|
|
|
if ((rv = virNetSocketRecvFD(client->sock, &(msg->fds[i]))) < 0) {
|
|
|
|
virNetMessageQueueServe(&client->rx);
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
client->wantClose = true;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL;
|
2015-11-26 16:10:40 +00:00
|
|
|
}
|
|
|
|
if (rv == 0) /* Blocking */
|
|
|
|
break;
|
|
|
|
msg->donefds++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to poll() until FDs arrive */
|
|
|
|
if (msg->donefds < msg->nfds) {
|
|
|
|
/* Because DecodeHeader/NumFDs reset bufferOffset, we
|
|
|
|
* put it back to what it was, so everything works
|
|
|
|
* again next time we run this method
|
|
|
|
*/
|
|
|
|
client->rx->bufferOffset = client->rx->bufferLength;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
return NULL;
|
2015-11-26 16:10:40 +00:00
|
|
|
}
|
2011-10-21 11:12:28 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 16:02:14 +00:00
|
|
|
/* Definitely finished reading, so remove from queue */
|
|
|
|
virNetMessageQueueServe(&client->rx);
|
Rewrite all the DTrace/SystemTAP probing
The libvirtd daemon had a few crude system tap probes. Some of
these were broken during the RPC rewrite. The new modular RPC
code is structured in a way that allows much more effective
tracing. Instead of trying to hook up the original probes,
define a new set of probes for the RPC and event code.
The master probes file is now src/probes.d. This contains
probes for virNetServerClientPtr, virNetClientPtr, virSocketPtr
virNetTLSContextPtr and virNetTLSSessionPtr modules. Also add
probes for the poll event loop.
The src/dtrace2systemtap.pl script can convert the probes.d
file into a libvirt_probes.stp file to make use from systemtap
much simpler.
The src/rpc/gensystemtap.pl script can generate a set of
systemtap functions for translating RPC enum values into
printable strings. This works for all RPC header enums (program,
type, status, procedure) and also the authentication enum
The PROBE macro will automatically generate a VIR_DEBUG
statement, so any place with a PROBE can remove any existing
manual DEBUG statements.
* daemon/libvirtd.stp, daemon/probes.d: Remove obsolete probing
* daemon/libvirtd.h: Remove probe macros
* daemon/Makefile.am: Remove all probe buildings/install
* daemon/remote.c: Update authentication probes
* src/dtrace2systemtap.pl, src/rpc/gensystemtap.pl: Scripts
to generate STP files
* src/internal.h: Add probe macros
* src/probes.d: Master list of probes
* src/rpc/virnetclient.c, src/rpc/virnetserverclient.c,
src/rpc/virnetsocket.c, src/rpc/virnettlscontext.c,
src/util/event_poll.c: Insert probe points, removing any
DEBUG statements that duplicate the info
2011-09-30 13:40:23 +00:00
|
|
|
PROBE(RPC_SERVER_CLIENT_MSG_RX,
|
|
|
|
"client=%p len=%zu prog=%u vers=%u proc=%u type=%u status=%u serial=%u",
|
|
|
|
client, msg->bufferLength,
|
|
|
|
msg->header.prog, msg->header.vers, msg->header.proc,
|
|
|
|
msg->header.type, msg->header.status, msg->header.serial);
|
|
|
|
|
2012-06-12 07:01:49 +00:00
|
|
|
if (virKeepAliveCheckMessage(client->keepalive, msg, &response)) {
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
client->nrequests--;
|
|
|
|
msg = NULL;
|
|
|
|
|
|
|
|
if (response &&
|
|
|
|
virNetServerClientSendMessageLocked(client, response) < 0)
|
|
|
|
virNetMessageFree(response);
|
|
|
|
}
|
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
/* Maybe send off for queue against a filter */
|
2012-06-12 07:01:49 +00:00
|
|
|
if (msg) {
|
|
|
|
filter = client->filters;
|
|
|
|
while (filter) {
|
|
|
|
int ret = filter->func(client, msg, filter->opaque);
|
|
|
|
if (ret < 0) {
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
msg = NULL;
|
2018-11-14 17:49:00 +00:00
|
|
|
client->wantClose = true;
|
2012-06-12 07:01:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret > 0) {
|
|
|
|
msg = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2012-06-12 07:01:49 +00:00
|
|
|
filter = filter->next;
|
|
|
|
}
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Possibly need to create another receive buffer */
|
|
|
|
if (client->nrequests < client->nrequests_max) {
|
Fix tracking of RPC messages wrt streams
Commit 2c85644b0b51fbe5b6244e6773531af29933a727 attempted to
fix a problem with tracking RPC messages from streams by doing
- if (msg->header.type == VIR_NET_REPLY) {
+ if (msg->header.type == VIR_NET_REPLY ||
+ (msg->header.type == VIR_NET_STREAM &&
+ msg->header.status != VIR_NET_CONTINUE)) {
client->nrequests--;
In other words any stream packet, with status NET_OK or NET_ERROR
would cause nrequests to be decremented. This is great if the
packet from from a synchronous virStreamFinish or virStreamAbort
API call, but wildly wrong if from a server initiated abort.
The latter resulted in 'nrequests' being decremented below zero.
This then causes all I/O for that client to be stopped.
Instead of trying to infer whether we need to decrement the
nrequests field, from the message type/status, introduce an
explicit 'bool tracked' field to mark whether the virNetMessagePtr
object is subject to tracking.
Also add a virNetMessageClear function to allow a message
contents to be cleared out, without adversely impacting the
'tracked' field as a naive memset() would do
* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add
a 'bool tracked' field and virNetMessageClear() API
* daemon/remote.c, daemon/stream.c, src/rpc/virnetclientprogram.c,
src/rpc/virnetclientstream.c, src/rpc/virnetserverclient.c,
src/rpc/virnetserverprogram.c: Switch over to use
virNetMessageClear() and pass in the 'bool tracked' value
when creating messages.
2011-08-31 16:42:58 +00:00
|
|
|
if (!(client->rx = virNetMessageNew(true))) {
|
2010-12-01 16:36:40 +00:00
|
|
|
client->wantClose = true;
|
2011-08-02 21:57:19 +00:00
|
|
|
} else {
|
|
|
|
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
|
2020-09-24 18:58:46 +00:00
|
|
|
client->rx->buffer = g_new0(char, client->rx->bufferLength);
|
|
|
|
client->nrequests++;
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virNetServerClientUpdateEvent(client);
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
|
|
|
|
return msg;
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send client->tx using no encoding
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* -1 on error or EOF
|
|
|
|
* 0 on EAGAIN
|
|
|
|
* n number of bytes
|
|
|
|
*/
|
|
|
|
static ssize_t virNetServerClientWrite(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
if (client->tx->bufferLength < client->tx->bufferOffset) {
|
2012-07-18 10:41:47 +00:00
|
|
|
virReportError(VIR_ERR_RPC,
|
|
|
|
_("unexpected zero/negative length request %lld"),
|
|
|
|
(long long int)(client->tx->bufferLength - client->tx->bufferOffset));
|
2010-12-01 16:36:40 +00:00
|
|
|
client->wantClose = true;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client->tx->bufferLength == client->tx->bufferOffset)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
ret = virNetSocketWrite(client->sock,
|
|
|
|
client->tx->buffer + client->tx->bufferOffset,
|
|
|
|
client->tx->bufferLength - client->tx->bufferOffset);
|
|
|
|
if (ret <= 0)
|
|
|
|
return ret; /* -1 error, 0 = egain */
|
|
|
|
|
|
|
|
client->tx->bufferOffset += ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process all queued client->tx messages until
|
|
|
|
* we would block on I/O
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virNetServerClientDispatchWrite(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
while (client->tx) {
|
2011-11-04 16:02:14 +00:00
|
|
|
if (client->tx->bufferOffset < client->tx->bufferLength) {
|
|
|
|
ssize_t ret;
|
|
|
|
ret = virNetServerClientWrite(client);
|
|
|
|
if (ret < 0) {
|
|
|
|
client->wantClose = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ret == 0)
|
|
|
|
return; /* Would block on write EAGAIN */
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (client->tx->bufferOffset == client->tx->bufferLength) {
|
|
|
|
virNetMessagePtr msg;
|
2011-10-21 11:12:28 +00:00
|
|
|
size_t i;
|
|
|
|
|
2013-05-21 07:59:54 +00:00
|
|
|
for (i = client->tx->donefds; i < client->tx->nfds; i++) {
|
2011-11-04 16:02:14 +00:00
|
|
|
int rv;
|
|
|
|
if ((rv = virNetSocketSendFD(client->sock, client->tx->fds[i])) < 0) {
|
2011-10-21 11:12:28 +00:00
|
|
|
client->wantClose = true;
|
|
|
|
return;
|
|
|
|
}
|
2011-11-04 16:02:14 +00:00
|
|
|
if (rv == 0) /* Blocking */
|
|
|
|
return;
|
|
|
|
client->tx->donefds++;
|
2011-10-21 11:12:28 +00:00
|
|
|
}
|
|
|
|
|
2012-09-20 11:58:29 +00:00
|
|
|
#if WITH_SASL
|
2010-12-01 16:36:40 +00:00
|
|
|
/* Completed this 'tx' operation, so now read for all
|
|
|
|
* future rx/tx to be under a SASL SSF layer
|
|
|
|
*/
|
|
|
|
if (client->sasl) {
|
|
|
|
virNetSocketSetSASLSession(client->sock, client->sasl);
|
2012-07-11 13:35:49 +00:00
|
|
|
virObjectUnref(client->sasl);
|
2010-12-01 16:36:40 +00:00
|
|
|
client->sasl = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get finished msg from head of tx queue */
|
|
|
|
msg = virNetMessageQueueServe(&client->tx);
|
|
|
|
|
Fix tracking of RPC messages wrt streams
Commit 2c85644b0b51fbe5b6244e6773531af29933a727 attempted to
fix a problem with tracking RPC messages from streams by doing
- if (msg->header.type == VIR_NET_REPLY) {
+ if (msg->header.type == VIR_NET_REPLY ||
+ (msg->header.type == VIR_NET_STREAM &&
+ msg->header.status != VIR_NET_CONTINUE)) {
client->nrequests--;
In other words any stream packet, with status NET_OK or NET_ERROR
would cause nrequests to be decremented. This is great if the
packet from from a synchronous virStreamFinish or virStreamAbort
API call, but wildly wrong if from a server initiated abort.
The latter resulted in 'nrequests' being decremented below zero.
This then causes all I/O for that client to be stopped.
Instead of trying to infer whether we need to decrement the
nrequests field, from the message type/status, introduce an
explicit 'bool tracked' field to mark whether the virNetMessagePtr
object is subject to tracking.
Also add a virNetMessageClear function to allow a message
contents to be cleared out, without adversely impacting the
'tracked' field as a naive memset() would do
* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add
a 'bool tracked' field and virNetMessageClear() API
* daemon/remote.c, daemon/stream.c, src/rpc/virnetclientprogram.c,
src/rpc/virnetclientstream.c, src/rpc/virnetserverclient.c,
src/rpc/virnetserverprogram.c: Switch over to use
virNetMessageClear() and pass in the 'bool tracked' value
when creating messages.
2011-08-31 16:42:58 +00:00
|
|
|
if (msg->tracked) {
|
2010-12-01 16:36:40 +00:00
|
|
|
client->nrequests--;
|
|
|
|
/* See if the recv queue is currently throttled */
|
|
|
|
if (!client->rx &&
|
|
|
|
client->nrequests < client->nrequests_max) {
|
|
|
|
/* Ready to recv more messages */
|
Fix tracking of RPC messages wrt streams
Commit 2c85644b0b51fbe5b6244e6773531af29933a727 attempted to
fix a problem with tracking RPC messages from streams by doing
- if (msg->header.type == VIR_NET_REPLY) {
+ if (msg->header.type == VIR_NET_REPLY ||
+ (msg->header.type == VIR_NET_STREAM &&
+ msg->header.status != VIR_NET_CONTINUE)) {
client->nrequests--;
In other words any stream packet, with status NET_OK or NET_ERROR
would cause nrequests to be decremented. This is great if the
packet from from a synchronous virStreamFinish or virStreamAbort
API call, but wildly wrong if from a server initiated abort.
The latter resulted in 'nrequests' being decremented below zero.
This then causes all I/O for that client to be stopped.
Instead of trying to infer whether we need to decrement the
nrequests field, from the message type/status, introduce an
explicit 'bool tracked' field to mark whether the virNetMessagePtr
object is subject to tracking.
Also add a virNetMessageClear function to allow a message
contents to be cleared out, without adversely impacting the
'tracked' field as a naive memset() would do
* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add
a 'bool tracked' field and virNetMessageClear() API
* daemon/remote.c, daemon/stream.c, src/rpc/virnetclientprogram.c,
src/rpc/virnetclientstream.c, src/rpc/virnetserverclient.c,
src/rpc/virnetserverprogram.c: Switch over to use
virNetMessageClear() and pass in the 'bool tracked' value
when creating messages.
2011-08-31 16:42:58 +00:00
|
|
|
virNetMessageClear(msg);
|
2012-04-26 15:21:24 +00:00
|
|
|
msg->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
|
2020-09-24 18:58:46 +00:00
|
|
|
msg->buffer = g_new0(char, msg->bufferLength);
|
2010-12-01 16:36:40 +00:00
|
|
|
client->rx = msg;
|
|
|
|
msg = NULL;
|
|
|
|
client->nrequests++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virNetMessageFree(msg);
|
|
|
|
|
|
|
|
virNetServerClientUpdateEvent(client);
|
2011-07-08 11:54:29 +00:00
|
|
|
|
|
|
|
if (client->delayedClose)
|
|
|
|
client->wantClose = true;
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 14:54:18 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
static void
|
|
|
|
virNetServerClientDispatchHandshake(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
/* Continue the handshake. */
|
2020-03-07 11:31:01 +00:00
|
|
|
virObjectLock(client->tlsCtxt);
|
2010-12-01 16:36:40 +00:00
|
|
|
ret = virNetTLSSessionHandshake(client->tls);
|
2020-03-07 11:31:01 +00:00
|
|
|
virObjectUnlock(client->tlsCtxt);
|
2010-12-01 16:36:40 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
/* Finished. Next step is to check the certificate. */
|
|
|
|
if (virNetServerClientCheckAccess(client) < 0)
|
|
|
|
client->wantClose = true;
|
|
|
|
else
|
|
|
|
virNetServerClientUpdateEvent(client);
|
|
|
|
} else if (ret > 0) {
|
|
|
|
/* Carry on waiting for more handshake. Update
|
|
|
|
the events just in case handshake data flow
|
|
|
|
direction has changed */
|
2012-10-17 09:23:12 +00:00
|
|
|
virNetServerClientUpdateEvent(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
} else {
|
|
|
|
/* Fatal error in handshake */
|
|
|
|
client->wantClose = true;
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 09:12:29 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque)
|
|
|
|
{
|
|
|
|
virNetServerClientPtr client = opaque;
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
virNetMessagePtr msg = NULL;
|
2010-12-01 16:36:40 +00:00
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
|
|
|
|
if (client->sock != sock) {
|
|
|
|
virNetSocketRemoveIOCallback(sock);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & (VIR_EVENT_HANDLE_WRITABLE |
|
|
|
|
VIR_EVENT_HANDLE_READABLE)) {
|
|
|
|
if (client->tls &&
|
|
|
|
virNetTLSSessionGetHandshakeStatus(client->tls) !=
|
|
|
|
VIR_NET_TLS_HANDSHAKE_COMPLETE) {
|
|
|
|
virNetServerClientDispatchHandshake(client);
|
|
|
|
} else {
|
|
|
|
if (events & VIR_EVENT_HANDLE_WRITABLE)
|
|
|
|
virNetServerClientDispatchWrite(client);
|
2011-11-01 13:14:54 +00:00
|
|
|
if (events & VIR_EVENT_HANDLE_READABLE &&
|
|
|
|
client->rx)
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
msg = virNetServerClientDispatchRead(client);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NB, will get HANGUP + READABLE at same time upon
|
|
|
|
* disconnect */
|
|
|
|
if (events & (VIR_EVENT_HANDLE_ERROR |
|
|
|
|
VIR_EVENT_HANDLE_HANGUP))
|
|
|
|
client->wantClose = true;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
rpc: invoke the message dispatch callback with client unlocked
Currently if the virNetServer instance is created with max_workers==0 to
request a non-threaded dispatch process, we deadlock during dispatch
#0 0x00007fb845f6f42d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fb845f681d3 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x000055a6628bb305 in virMutexLock (m=<optimized out>) at util/virthread.c:89
#3 0x000055a6628a984b in virObjectLock (anyobj=<optimized out>) at util/virobject.c:435
#4 0x000055a66286fcde in virNetServerClientIsAuthenticated (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1565
#5 0x000055a66286cc17 in virNetServerProgramDispatchCall (msg=0x55a663a7bc50, client=0x55a663a7b960,
server=0x55a663a77550, prog=0x55a663a78020) at rpc/virnetserverprogram.c:407
#6 virNetServerProgramDispatch (prog=prog@entry=0x55a663a78020, server=server@entry=0x55a663a77550,
client=client@entry=0x55a663a7b960, msg=msg@entry=0x55a663a7bc50) at rpc/virnetserverprogram.c:307
#7 0x000055a662871d56 in virNetServerProcessMsg (msg=0x55a663a7bc50, prog=0x55a663a78020, client=0x55a663a7b960,
srv=0x55a663a77550) at rpc/virnetserver.c:148
#8 virNetServerDispatchNewMessage (client=0x55a663a7b960, msg=0x55a663a7bc50, opaque=0x55a663a77550)
at rpc/virnetserver.c:227
#9 0x000055a66286e4c0 in virNetServerClientDispatchRead (client=client@entry=0x55a663a7b960)
at rpc/virnetserverclient.c:1322
#10 0x000055a66286e813 in virNetServerClientDispatchEvent (sock=<optimized out>, events=1, opaque=0x55a663a7b960)
at rpc/virnetserverclient.c:1507
#11 0x000055a662899be0 in virEventPollDispatchHandles (fds=0x55a663a7bdc0, nfds=<optimized out>)
at util/vireventpoll.c:508
#12 virEventPollRunOnce () at util/vireventpoll.c:657
#13 0x000055a6628982f1 in virEventRunDefaultImpl () at util/virevent.c:327
#14 0x000055a6628716d5 in virNetDaemonRun (dmn=0x55a663a771b0) at rpc/virnetdaemon.c:858
#15 0x000055a662864c1d in main (argc=<optimized out>,
#argv=0x7ffd105b4838) at logging/log_daemon.c:1235
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-06 17:05:16 +00:00
|
|
|
|
|
|
|
if (msg)
|
|
|
|
virNetServerClientDispatchMessage(client, msg);
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-12 07:01:49 +00:00
|
|
|
static int
|
|
|
|
virNetServerClientSendMessageLocked(virNetServerClientPtr client,
|
|
|
|
virNetMessagePtr msg)
|
2010-12-01 16:36:40 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("msg=%p proc=%d len=%zu offset=%zu",
|
|
|
|
msg, msg->header.proc,
|
|
|
|
msg->bufferLength, msg->bufferOffset);
|
2011-08-24 13:33:34 +00:00
|
|
|
|
2011-11-04 16:02:14 +00:00
|
|
|
msg->donefds = 0;
|
2010-12-01 16:36:40 +00:00
|
|
|
if (client->sock && !client->wantClose) {
|
Rewrite all the DTrace/SystemTAP probing
The libvirtd daemon had a few crude system tap probes. Some of
these were broken during the RPC rewrite. The new modular RPC
code is structured in a way that allows much more effective
tracing. Instead of trying to hook up the original probes,
define a new set of probes for the RPC and event code.
The master probes file is now src/probes.d. This contains
probes for virNetServerClientPtr, virNetClientPtr, virSocketPtr
virNetTLSContextPtr and virNetTLSSessionPtr modules. Also add
probes for the poll event loop.
The src/dtrace2systemtap.pl script can convert the probes.d
file into a libvirt_probes.stp file to make use from systemtap
much simpler.
The src/rpc/gensystemtap.pl script can generate a set of
systemtap functions for translating RPC enum values into
printable strings. This works for all RPC header enums (program,
type, status, procedure) and also the authentication enum
The PROBE macro will automatically generate a VIR_DEBUG
statement, so any place with a PROBE can remove any existing
manual DEBUG statements.
* daemon/libvirtd.stp, daemon/probes.d: Remove obsolete probing
* daemon/libvirtd.h: Remove probe macros
* daemon/Makefile.am: Remove all probe buildings/install
* daemon/remote.c: Update authentication probes
* src/dtrace2systemtap.pl, src/rpc/gensystemtap.pl: Scripts
to generate STP files
* src/internal.h: Add probe macros
* src/probes.d: Master list of probes
* src/rpc/virnetclient.c, src/rpc/virnetserverclient.c,
src/rpc/virnetsocket.c, src/rpc/virnettlscontext.c,
src/util/event_poll.c: Insert probe points, removing any
DEBUG statements that duplicate the info
2011-09-30 13:40:23 +00:00
|
|
|
PROBE(RPC_SERVER_CLIENT_MSG_TX_QUEUE,
|
|
|
|
"client=%p len=%zu prog=%u vers=%u proc=%u type=%u status=%u serial=%u",
|
|
|
|
client, msg->bufferLength,
|
|
|
|
msg->header.prog, msg->header.vers, msg->header.proc,
|
|
|
|
msg->header.type, msg->header.status, msg->header.serial);
|
2010-12-01 16:36:40 +00:00
|
|
|
virNetMessageQueuePush(&client->tx, msg);
|
|
|
|
|
|
|
|
virNetServerClientUpdateEvent(client);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-12 07:01:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int virNetServerClientSendMessage(virNetServerClientPtr client,
|
|
|
|
virNetMessagePtr msg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2012-06-12 07:01:49 +00:00
|
|
|
ret = virNetServerClientSendMessageLocked(client, msg);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2011-08-24 13:33:34 +00:00
|
|
|
|
2010-12-01 16:36:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-21 14:29:00 +00:00
|
|
|
bool
|
2017-12-21 14:29:08 +00:00
|
|
|
virNetServerClientIsAuthenticated(virNetServerClientPtr client)
|
2017-12-21 14:29:00 +00:00
|
|
|
{
|
2017-12-21 14:29:08 +00:00
|
|
|
bool authenticated;
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2017-12-21 14:29:08 +00:00
|
|
|
authenticated = virNetServerClientAuthMethodImpliesAuthenticated(client->auth);
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2017-12-21 14:29:08 +00:00
|
|
|
return authenticated;
|
2010-12-01 16:36:40 +00:00
|
|
|
}
|
2011-08-24 13:33:34 +00:00
|
|
|
|
|
|
|
|
2017-12-21 14:29:05 +00:00
|
|
|
/* The caller must hold the lock for @client */
|
|
|
|
void
|
|
|
|
virNetServerClientSetAuthPendingLocked(virNetServerClientPtr client,
|
|
|
|
bool auth_pending)
|
|
|
|
{
|
|
|
|
client->auth_pending = auth_pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The caller must hold the lock for @client */
|
|
|
|
bool
|
|
|
|
virNetServerClientIsAuthPendingLocked(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
return client->auth_pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 13:33:34 +00:00
|
|
|
static void
|
|
|
|
virNetServerClientKeepAliveDeadCB(void *opaque)
|
|
|
|
{
|
|
|
|
virNetServerClientImmediateClose(opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNetServerClientKeepAliveSendCB(void *opaque,
|
|
|
|
virNetMessagePtr msg)
|
|
|
|
{
|
|
|
|
return virNetServerClientSendMessage(opaque, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virNetServerClientInitKeepAlive(virNetServerClientPtr client,
|
|
|
|
int interval,
|
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
virKeepAlivePtr ka;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2011-08-24 13:33:34 +00:00
|
|
|
|
|
|
|
if (!(ka = virKeepAliveNew(interval, count, client,
|
|
|
|
virNetServerClientKeepAliveSendCB,
|
|
|
|
virNetServerClientKeepAliveDeadCB,
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectFreeCallback)))
|
2011-08-24 13:33:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
/* keepalive object has a reference to client */
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectRef(client);
|
2011-08-24 13:33:34 +00:00
|
|
|
|
|
|
|
client->keepalive = ka;
|
2020-05-05 09:29:13 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:31 +00:00
|
|
|
cleanup:
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2011-08-24 13:33:34 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virNetServerClientStartKeepAlive(virNetServerClientPtr client)
|
|
|
|
{
|
2014-01-09 21:26:40 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectLock(client);
|
2014-01-09 21:26:40 +00:00
|
|
|
|
|
|
|
/* The connection might have been closed before we got here and thus the
|
|
|
|
* keepalive object could have been removed too.
|
|
|
|
*/
|
2014-01-13 14:46:24 +00:00
|
|
|
if (!client->keepalive) {
|
2014-01-09 21:26:40 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("connection not open"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:33:34 +00:00
|
|
|
ret = virKeepAliveStart(client->keepalive, 0, 0);
|
2014-01-09 21:26:40 +00:00
|
|
|
|
2014-03-25 06:52:31 +00:00
|
|
|
cleanup:
|
2013-01-09 21:27:28 +00:00
|
|
|
virObjectUnlock(client);
|
2011-08-24 13:33:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-04-14 22:25:04 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
virNetServerClientGetTransport(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virObjectLock(client);
|
|
|
|
|
|
|
|
if (client->sock && virNetSocketIsLocal(client->sock))
|
|
|
|
ret = VIR_CLIENT_TRANS_UNIX;
|
|
|
|
else
|
|
|
|
ret = VIR_CLIENT_TRANS_TCP;
|
|
|
|
|
|
|
|
if (client->tls)
|
|
|
|
ret = VIR_CLIENT_TRANS_TLS;
|
|
|
|
|
|
|
|
virObjectUnlock(client);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-22 11:08:10 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
virNetServerClientGetInfo(virNetServerClientPtr client,
|
2016-06-29 05:03:13 +00:00
|
|
|
bool *readonly, char **sock_addr,
|
2016-04-22 11:08:10 +00:00
|
|
|
virIdentityPtr *identity)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2016-06-29 05:03:13 +00:00
|
|
|
const char *addr;
|
2016-04-22 11:08:10 +00:00
|
|
|
|
|
|
|
virObjectLock(client);
|
|
|
|
*readonly = client->readonly;
|
|
|
|
|
2016-06-29 05:03:13 +00:00
|
|
|
if (!(addr = virNetServerClientRemoteAddrStringURI(client))) {
|
2016-04-22 11:08:10 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("No network socket associated with client"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
*sock_addr = g_strdup(addr);
|
2016-06-29 05:03:13 +00:00
|
|
|
|
2016-04-22 11:08:10 +00:00
|
|
|
if (!client->identity) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("No identity information available for client"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-09-19 14:38:03 +00:00
|
|
|
*identity = g_object_ref(client->identity);
|
2016-04-22 11:08:10 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(client);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-03-17 15:18:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNetServerClientSetQuietEOF:
|
|
|
|
*
|
|
|
|
* Don't report errors for protocols that close connection by hangup of the
|
|
|
|
* socket rather than calling an API to close it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
virNetServerClientSetQuietEOF(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virNetSocketSetQuietEOF(client->sock);
|
|
|
|
}
|