2010-12-06 17:03:22 +00:00
|
|
|
/*
|
|
|
|
* virnetmessage.h: basic RPC message encoding/decoding
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 18:06:23 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-06 17:03:22 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 11:12:39 -05:00
|
|
|
#pragma once
|
2010-12-06 17:03:22 +00:00
|
|
|
|
2019-06-18 11:12:39 -05:00
|
|
|
#include "virnetprotocol.h"
|
2010-12-06 17:03:22 +00:00
|
|
|
|
|
|
|
typedef struct _virNetMessage virNetMessage;
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
typedef void (*virNetMessageFreeCallback)(virNetMessage *msg, void *opaque);
|
2011-05-16 18:13:11 +01:00
|
|
|
|
2010-12-06 17:03:22 +00:00
|
|
|
struct _virNetMessage {
|
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 17:42:58 +01:00
|
|
|
bool tracked;
|
|
|
|
|
2013-05-07 13:22:00 +02:00
|
|
|
char *buffer; /* Initially VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX */
|
|
|
|
/* Maximum VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX */
|
2010-12-06 17:03:22 +00:00
|
|
|
size_t bufferLength;
|
|
|
|
size_t bufferOffset;
|
|
|
|
|
|
|
|
virNetMessageHeader header;
|
|
|
|
|
2011-05-16 18:13:11 +01:00
|
|
|
virNetMessageFreeCallback cb;
|
|
|
|
void *opaque;
|
|
|
|
|
2011-10-21 11:30:12 +01:00
|
|
|
size_t nfds;
|
|
|
|
int *fds;
|
2011-11-04 16:02:14 +00:00
|
|
|
size_t donefds;
|
2011-10-21 11:30:12 +01:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virNetMessage *next;
|
2010-12-06 17:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virNetMessage *virNetMessageNew(bool tracked);
|
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 17:42:58 +01:00
|
|
|
|
2022-02-17 17:07:39 +01:00
|
|
|
void virNetMessageClearFDs(virNetMessage *msg);
|
2021-03-11 08:16:13 +01:00
|
|
|
void virNetMessageClearPayload(virNetMessage *msg);
|
2016-04-27 18:02:22 -04:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
void virNetMessageClear(virNetMessage *);
|
2010-12-06 17:03:22 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
void virNetMessageFree(virNetMessage *msg);
|
2010-12-06 17:03:22 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
virNetMessage *virNetMessageQueueServe(virNetMessage **queue)
|
2010-12-06 17:03:22 +00:00
|
|
|
ATTRIBUTE_NONNULL(1);
|
2021-03-11 08:16:13 +01:00
|
|
|
void virNetMessageQueuePush(virNetMessage **queue,
|
|
|
|
virNetMessage *msg)
|
2010-12-06 17:03:22 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageEncodeHeader(virNetMessage *msg)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageDecodeLength(virNetMessage *msg)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageDecodeHeader(virNetMessage *msg)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2010-12-06 17:03:22 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageEncodePayload(virNetMessage *msg,
|
2010-12-06 17:03:22 +00:00
|
|
|
xdrproc_t filter,
|
|
|
|
void *data)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageDecodePayload(virNetMessage *msg,
|
2010-12-06 17:03:22 +00:00
|
|
|
xdrproc_t filter,
|
|
|
|
void *data)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2010-12-06 17:03:22 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageEncodeNumFDs(virNetMessage *msg);
|
|
|
|
int virNetMessageDecodeNumFDs(virNetMessage *msg);
|
2011-10-21 11:30:12 +01:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageEncodePayloadRaw(virNetMessage *msg,
|
2010-12-06 17:03:22 +00:00
|
|
|
const char *buf,
|
|
|
|
size_t len)
|
2019-10-14 14:25:14 +02:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2010-12-06 17:03:22 +00:00
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
void virNetMessageSaveError(struct virNetMessageError *rerr)
|
2010-12-06 17:03:22 +00:00
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageDupFD(virNetMessage *msg,
|
2011-10-21 11:30:12 +01:00
|
|
|
size_t slot);
|
|
|
|
|
2021-03-11 08:16:13 +01:00
|
|
|
int virNetMessageAddFD(virNetMessage *msg,
|
2014-08-25 18:55:20 +02:00
|
|
|
int fd);
|