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 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-06 17:03:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_NET_MESSAGE_H__
|
|
|
|
# define __VIR_NET_MESSAGE_H__
|
|
|
|
|
|
|
|
# include "virnetprotocol.h"
|
|
|
|
|
|
|
|
typedef struct virNetMessageHeader *virNetMessageHeaderPtr;
|
|
|
|
typedef struct virNetMessageError *virNetMessageErrorPtr;
|
|
|
|
|
|
|
|
typedef struct _virNetMessage virNetMessage;
|
|
|
|
typedef virNetMessage *virNetMessagePtr;
|
|
|
|
|
2011-05-16 17:13:11 +00:00
|
|
|
typedef void (*virNetMessageFreeCallback)(virNetMessagePtr msg, void *opaque);
|
|
|
|
|
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 16:42:58 +00:00
|
|
|
bool tracked;
|
|
|
|
|
2012-04-26 15:21:24 +00:00
|
|
|
char *buffer; /* Typically 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 17:13:11 +00:00
|
|
|
virNetMessageFreeCallback cb;
|
|
|
|
void *opaque;
|
|
|
|
|
2011-10-21 10:30:12 +00:00
|
|
|
size_t nfds;
|
|
|
|
int *fds;
|
2011-11-04 16:02:14 +00:00
|
|
|
size_t donefds;
|
2011-10-21 10:30:12 +00:00
|
|
|
|
2010-12-06 17:03:22 +00:00
|
|
|
virNetMessagePtr next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
virNetMessagePtr virNetMessageNew(bool tracked);
|
|
|
|
|
|
|
|
void virNetMessageClear(virNetMessagePtr);
|
2010-12-06 17:03:22 +00:00
|
|
|
|
|
|
|
void virNetMessageFree(virNetMessagePtr msg);
|
|
|
|
|
|
|
|
virNetMessagePtr virNetMessageQueueServe(virNetMessagePtr *queue)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
void virNetMessageQueuePush(virNetMessagePtr *queue,
|
|
|
|
virNetMessagePtr msg)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
|
|
|
|
int virNetMessageEncodeHeader(virNetMessagePtr msg)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virNetMessageDecodeLength(virNetMessagePtr msg)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virNetMessageDecodeHeader(virNetMessagePtr msg)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
|
|
|
int virNetMessageEncodePayload(virNetMessagePtr msg,
|
|
|
|
xdrproc_t filter,
|
|
|
|
void *data)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
int virNetMessageDecodePayload(virNetMessagePtr msg,
|
|
|
|
xdrproc_t filter,
|
|
|
|
void *data)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2011-10-21 10:30:12 +00:00
|
|
|
int virNetMessageEncodeNumFDs(virNetMessagePtr msg);
|
|
|
|
int virNetMessageDecodeNumFDs(virNetMessagePtr msg);
|
|
|
|
|
2010-12-06 17:03:22 +00:00
|
|
|
int virNetMessageEncodePayloadRaw(virNetMessagePtr msg,
|
|
|
|
const char *buf,
|
|
|
|
size_t len)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
2011-06-28 16:42:06 +00:00
|
|
|
int virNetMessageEncodePayloadEmpty(virNetMessagePtr msg)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
2010-12-06 17:03:22 +00:00
|
|
|
|
|
|
|
void virNetMessageSaveError(virNetMessageErrorPtr rerr)
|
|
|
|
ATTRIBUTE_NONNULL(1);
|
|
|
|
|
2011-10-21 10:30:12 +00:00
|
|
|
int virNetMessageDupFD(virNetMessagePtr msg,
|
|
|
|
size_t slot);
|
|
|
|
|
2010-12-06 17:03:22 +00:00
|
|
|
#endif /* __VIR_NET_MESSAGE_H__ */
|