libvirt/daemon/libvirtd.h

314 lines
7.5 KiB
C
Raw Normal View History

2007-02-14 09:40:09 +08:00
/*
* libvirtd.h: daemon data structure definitions
2007-02-14 09:40:09 +08:00
*
* Copyright (C) 2006-2009 Red Hat, Inc.
2007-02-14 09:40:09 +08: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
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef QEMUD_INTERNAL_H__
#define QEMUD_INTERNAL_H__
#include <config.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include "gnutls_1_0_compat.h"
#if HAVE_SASL
#include <sasl/sasl.h>
#endif
2007-02-14 09:40:09 +08:00
#if HAVE_POLKIT0
2007-12-06 02:21:27 +08:00
#include <dbus/dbus.h>
#endif
#ifdef HAVE_SYS_SYSLIMITS_H
#include <sys/syslimits.h>
#endif
#include <rpc/types.h>
#include <rpc/xdr.h>
#include "remote_protocol.h"
#include "logging.h"
2009-01-16 03:56:05 +08:00
#include "threads.h"
2007-02-14 09:40:09 +08:00
#ifdef __GNUC__
#ifdef HAVE_ANSIDECL_H
#include <ansidecl.h>
#endif
#ifndef __GNUC_PREREQ
#if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define __GNUC_PREREQ(maj,min) 0
#endif
#endif
/**
* ATTRIBUTE_UNUSED:
*
* Macro to flag conciously unused parameters to functions
*/
2007-02-14 09:40:09 +08:00
#ifndef ATTRIBUTE_UNUSED
#define ATTRIBUTE_UNUSED __attribute__((__unused__))
2007-02-14 09:40:09 +08:00
#endif
/**
* ATTRIBUTE_FMT_PRINTF
*
* Macro used to check printf like functions, if compiling
* with gcc.
*
* We use gnulib which guarentees we always have GNU style
* printf format specifiers even on broken Win32 platforms
* hence we have to force 'gnu_printf' for new GCC
*/
#ifndef ATTRIBUTE_FMT_PRINTF
#if __GNUC_PREREQ (4, 4)
#define ATTRIBUTE_FMT_PRINTF(fmtpos,argpos) __attribute__((__format__ (gnu_printf, fmtpos,argpos)))
#else
#define ATTRIBUTE_FMT_PRINTF(fmtpos,argpos) __attribute__((__format__ (printf, fmtpos,argpos)))
#endif
#endif
#ifndef ATTRIBUTE_RETURN_CHECK
#if __GNUC_PREREQ (3, 4)
#define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
2007-02-14 09:40:09 +08:00
#else
#define ATTRIBUTE_RETURN_CHECK
#endif
#endif
#else
#ifndef ATTRIBUTE_UNUSED
2007-02-14 09:40:09 +08:00
#define ATTRIBUTE_UNUSED
#endif
#ifndef ATTRIBUTE_FMT_PRINTF
#define ATTRIBUTE_FMT_PRINTF(...)
#endif
#ifndef ATTRIBUTE_RETURN_CHECK
#define ATTRIBUTE_RETURN_CHECK
#endif
2007-02-14 09:40:09 +08:00
#endif
#define qemudDebug DEBUG
/* Whether we're passing reads & writes through a sasl SSF */
enum qemud_sasl_ssf {
QEMUD_SASL_SSF_NONE = 0,
QEMUD_SASL_SSF_READ = 1,
QEMUD_SASL_SSF_WRITE = 2,
};
enum qemud_sock_type {
QEMUD_SOCK_TYPE_UNIX = 0,
QEMUD_SOCK_TYPE_TCP = 1,
QEMUD_SOCK_TYPE_TLS = 2,
};
struct qemud_client_message {
char buffer [REMOTE_MESSAGE_MAX + REMOTE_MESSAGE_HEADER_XDR_LEN];
unsigned int bufferLength;
unsigned int bufferOffset;
Helper functions for processing data streams in libvirtd Defines the extensions to the remote protocol for generic data streams. Adds a bunch of helper code to the libvirtd daemon for working with data streams. * daemon/Makefile.am: Add stream.c/stream.h to build * daemon/stream.c, qemud/stream.h: Generic helper functions for creating new streams, associating streams with clients, finding existing streams for a client and removing/deleting streams. * src/remote/remote_protocol.x: Add a new 'REMOTE_STREAM' constant for the 'enum remote_message_type' for encoding stream data in wire messages. Add a new 'REMOTE_CONTINUE' constant to 'enum remote_message_status' to indicate further data stream messsages are expected to follow. Document how the remote_message_header is used to encode data streams * src/remote/remote_protocol.h: Regenerate * daemon/dispatch.c: Remove assumption that a error message sent to client is always type=REMOTE_REPLY. It may now also be type=REMOTE_STREAM. Add convenient method for sending outgoing stream data packets. Log and ignore non-filtered incoming stream packets. Add a method for serializing a stream error message * daemon/dispatch.h: Add API for serializing stream errors and sending stream data packets * daemon/qemud.h: Add struct qemud_client_stream for tracking active data streams for clients. Tweak filter function operation so that it accepts a client object too. * daemon/qemud.c: Refactor code for free'ing message objects which have been fully transmitted into separate method. Release all active streams when client shuts down. Change filter function to be responsible for queueing the message
2009-07-10 20:06:36 +08:00
unsigned int async : 1;
unsigned int streamTX : 1;
remote_message_header hdr;
struct qemud_client_message *next;
};
Helper functions for processing data streams in libvirtd Defines the extensions to the remote protocol for generic data streams. Adds a bunch of helper code to the libvirtd daemon for working with data streams. * daemon/Makefile.am: Add stream.c/stream.h to build * daemon/stream.c, qemud/stream.h: Generic helper functions for creating new streams, associating streams with clients, finding existing streams for a client and removing/deleting streams. * src/remote/remote_protocol.x: Add a new 'REMOTE_STREAM' constant for the 'enum remote_message_type' for encoding stream data in wire messages. Add a new 'REMOTE_CONTINUE' constant to 'enum remote_message_status' to indicate further data stream messsages are expected to follow. Document how the remote_message_header is used to encode data streams * src/remote/remote_protocol.h: Regenerate * daemon/dispatch.c: Remove assumption that a error message sent to client is always type=REMOTE_REPLY. It may now also be type=REMOTE_STREAM. Add convenient method for sending outgoing stream data packets. Log and ignore non-filtered incoming stream packets. Add a method for serializing a stream error message * daemon/dispatch.h: Add API for serializing stream errors and sending stream data packets * daemon/qemud.h: Add struct qemud_client_stream for tracking active data streams for clients. Tweak filter function operation so that it accepts a client object too. * daemon/qemud.c: Refactor code for free'ing message objects which have been fully transmitted into separate method. Release all active streams when client shuts down. Change filter function to be responsible for queueing the message
2009-07-10 20:06:36 +08:00
struct qemud_client;
/* Allow for filtering of incoming messages to a custom
* dispatch processing queue, instead of client->dx.
*/
Helper functions for processing data streams in libvirtd Defines the extensions to the remote protocol for generic data streams. Adds a bunch of helper code to the libvirtd daemon for working with data streams. * daemon/Makefile.am: Add stream.c/stream.h to build * daemon/stream.c, qemud/stream.h: Generic helper functions for creating new streams, associating streams with clients, finding existing streams for a client and removing/deleting streams. * src/remote/remote_protocol.x: Add a new 'REMOTE_STREAM' constant for the 'enum remote_message_type' for encoding stream data in wire messages. Add a new 'REMOTE_CONTINUE' constant to 'enum remote_message_status' to indicate further data stream messsages are expected to follow. Document how the remote_message_header is used to encode data streams * src/remote/remote_protocol.h: Regenerate * daemon/dispatch.c: Remove assumption that a error message sent to client is always type=REMOTE_REPLY. It may now also be type=REMOTE_STREAM. Add convenient method for sending outgoing stream data packets. Log and ignore non-filtered incoming stream packets. Add a method for serializing a stream error message * daemon/dispatch.h: Add API for serializing stream errors and sending stream data packets * daemon/qemud.h: Add struct qemud_client_stream for tracking active data streams for clients. Tweak filter function operation so that it accepts a client object too. * daemon/qemud.c: Refactor code for free'ing message objects which have been fully transmitted into separate method. Release all active streams when client shuts down. Change filter function to be responsible for queueing the message
2009-07-10 20:06:36 +08:00
typedef int (*qemud_client_filter_func)(struct qemud_client *client,
struct qemud_client_message *msg, void *opaque);
struct qemud_client_filter {
qemud_client_filter_func query;
void *opaque;
struct qemud_client_filter *next;
};
Helper functions for processing data streams in libvirtd Defines the extensions to the remote protocol for generic data streams. Adds a bunch of helper code to the libvirtd daemon for working with data streams. * daemon/Makefile.am: Add stream.c/stream.h to build * daemon/stream.c, qemud/stream.h: Generic helper functions for creating new streams, associating streams with clients, finding existing streams for a client and removing/deleting streams. * src/remote/remote_protocol.x: Add a new 'REMOTE_STREAM' constant for the 'enum remote_message_type' for encoding stream data in wire messages. Add a new 'REMOTE_CONTINUE' constant to 'enum remote_message_status' to indicate further data stream messsages are expected to follow. Document how the remote_message_header is used to encode data streams * src/remote/remote_protocol.h: Regenerate * daemon/dispatch.c: Remove assumption that a error message sent to client is always type=REMOTE_REPLY. It may now also be type=REMOTE_STREAM. Add convenient method for sending outgoing stream data packets. Log and ignore non-filtered incoming stream packets. Add a method for serializing a stream error message * daemon/dispatch.h: Add API for serializing stream errors and sending stream data packets * daemon/qemud.h: Add struct qemud_client_stream for tracking active data streams for clients. Tweak filter function operation so that it accepts a client object too. * daemon/qemud.c: Refactor code for free'ing message objects which have been fully transmitted into separate method. Release all active streams when client shuts down. Change filter function to be responsible for queueing the message
2009-07-10 20:06:36 +08:00
struct qemud_client_stream {
virStreamPtr st;
int procedure;
int serial;
unsigned int recvEOF : 1;
unsigned int closed : 1;
struct qemud_client_filter filter;
struct qemud_client_message *rx;
int tx;
struct qemud_client_stream *next;
};
2007-02-14 09:40:09 +08:00
/* Stores the per-client connection state */
struct qemud_client {
2009-01-16 03:56:05 +08:00
virMutex lock;
2008-12-05 06:16:40 +08:00
int magic;
2007-02-14 09:40:09 +08:00
int fd;
int watch;
unsigned int readonly :1;
unsigned int closing :1;
unsigned int domain_events_registered :1;
struct sockaddr_storage addr;
socklen_t addrlen;
int type; /* qemud_sock_type */
gnutls_session_t tlssession;
int auth;
unsigned int handshake :1; /* If we're in progress for TLS handshake */
#if HAVE_SASL
sasl_conn_t *saslconn;
int saslSSF;
const char *saslDecoded;
unsigned int saslDecodedLength;
unsigned int saslDecodedOffset;
const char *saslEncoded;
unsigned int saslEncodedLength;
unsigned int saslEncodedOffset;
char *saslUsername;
#endif
/* Count of meages in 'dx' or 'tx' queue
* ie RPC calls in progress. Does not count
* async events which are not used for
* throttling calculations */
int nrequests;
/* Zero or one messages being received. Zero if
* nrequests >= max_clients and throttling */
struct qemud_client_message *rx;
/* Zero or many messages waiting for a worker
* to process them */
struct qemud_client_message *dx;
/* Zero or many messages waiting for transmit
* back to client, including async events */
struct qemud_client_message *tx;
/* Filters to capture messages that would otherwise
* end up on the 'dx' queue */
struct qemud_client_filter *filters;
Helper functions for processing data streams in libvirtd Defines the extensions to the remote protocol for generic data streams. Adds a bunch of helper code to the libvirtd daemon for working with data streams. * daemon/Makefile.am: Add stream.c/stream.h to build * daemon/stream.c, qemud/stream.h: Generic helper functions for creating new streams, associating streams with clients, finding existing streams for a client and removing/deleting streams. * src/remote/remote_protocol.x: Add a new 'REMOTE_STREAM' constant for the 'enum remote_message_type' for encoding stream data in wire messages. Add a new 'REMOTE_CONTINUE' constant to 'enum remote_message_status' to indicate further data stream messsages are expected to follow. Document how the remote_message_header is used to encode data streams * src/remote/remote_protocol.h: Regenerate * daemon/dispatch.c: Remove assumption that a error message sent to client is always type=REMOTE_REPLY. It may now also be type=REMOTE_STREAM. Add convenient method for sending outgoing stream data packets. Log and ignore non-filtered incoming stream packets. Add a method for serializing a stream error message * daemon/dispatch.h: Add API for serializing stream errors and sending stream data packets * daemon/qemud.h: Add struct qemud_client_stream for tracking active data streams for clients. Tweak filter function operation so that it accepts a client object too. * daemon/qemud.c: Refactor code for free'ing message objects which have been fully transmitted into separate method. Release all active streams when client shuts down. Change filter function to be responsible for queueing the message
2009-07-10 20:06:36 +08:00
/* Data streams */
struct qemud_client_stream *streams;
/* This is only valid if a remote open call has been made on this
* connection, otherwise it will be NULL. Also if remote close is
* called, it will be set back to NULL if that succeeds.
*/
virConnectPtr conn;
2008-12-05 06:16:40 +08:00
int refs;
2007-02-14 09:40:09 +08:00
};
#define QEMUD_CLIENT_MAGIC 0x7788aaee
2007-02-14 09:40:09 +08:00
struct qemud_socket {
int fd;
int watch;
2007-02-14 09:40:09 +08:00
int readonly;
int type; /* qemud_sock_type */
int auth;
int port;
2007-02-14 09:40:09 +08:00
struct qemud_socket *next;
};
struct qemud_worker {
pthread_t thread;
unsigned int hasThread :1;
unsigned int processingCall :1;
unsigned int quitRequest :1;
/* back-pointer to our server */
struct qemud_server *server;
};
2007-02-14 09:40:09 +08:00
/* Main server state */
struct qemud_server {
2009-01-16 03:56:05 +08:00
virMutex lock;
virCond job;
2008-12-05 06:16:40 +08:00
int privileged;
2008-12-05 06:16:40 +08:00
int nworkers;
int nactiveworkers;
struct qemud_worker *workers;
2007-02-14 09:40:09 +08:00
int nsockets;
struct qemud_socket *sockets;
int nclients;
struct qemud_client **clients;
2008-12-05 06:16:40 +08:00
int sigread;
int sigwrite;
char *logDir;
pthread_t eventThread;
unsigned int hasEventThread :1;
unsigned int quitEventThread :1;
#ifdef HAVE_AVAHI
struct libvirtd_mdns *mdns;
#endif
#if HAVE_SASL
char **saslUsernameWhitelist;
#endif
#if HAVE_POLKIT0
2007-12-06 02:21:27 +08:00
DBusConnection *sysbus;
#endif
2007-02-14 09:40:09 +08:00
};
void qemudLog(int priority, const char *fmt, ...)
ATTRIBUTE_FMT_PRINTF(2,3);
int qemudRegisterClientEvent(struct qemud_server *server,
struct qemud_client *client);
void qemudUpdateClientEvent(struct qemud_client *client);
void qemudDispatchClientFailure(struct qemud_client *client);
void
qemudClientMessageQueuePush(struct qemud_client_message **queue,
struct qemud_client_message *msg);
struct qemud_client_message *
qemudClientMessageQueueServe(struct qemud_client_message **queue);
Helper functions for processing data streams in libvirtd Defines the extensions to the remote protocol for generic data streams. Adds a bunch of helper code to the libvirtd daemon for working with data streams. * daemon/Makefile.am: Add stream.c/stream.h to build * daemon/stream.c, qemud/stream.h: Generic helper functions for creating new streams, associating streams with clients, finding existing streams for a client and removing/deleting streams. * src/remote/remote_protocol.x: Add a new 'REMOTE_STREAM' constant for the 'enum remote_message_type' for encoding stream data in wire messages. Add a new 'REMOTE_CONTINUE' constant to 'enum remote_message_status' to indicate further data stream messsages are expected to follow. Document how the remote_message_header is used to encode data streams * src/remote/remote_protocol.h: Regenerate * daemon/dispatch.c: Remove assumption that a error message sent to client is always type=REMOTE_REPLY. It may now also be type=REMOTE_STREAM. Add convenient method for sending outgoing stream data packets. Log and ignore non-filtered incoming stream packets. Add a method for serializing a stream error message * daemon/dispatch.h: Add API for serializing stream errors and sending stream data packets * daemon/qemud.h: Add struct qemud_client_stream for tracking active data streams for clients. Tweak filter function operation so that it accepts a client object too. * daemon/qemud.c: Refactor code for free'ing message objects which have been fully transmitted into separate method. Release all active streams when client shuts down. Change filter function to be responsible for queueing the message
2009-07-10 20:06:36 +08:00
void
qemudClientMessageRelease(struct qemud_client *client,
struct qemud_client_message *msg);
#if HAVE_POLKIT
int qemudGetSocketIdentity(int fd, uid_t *uid, pid_t *pid);
#endif
2007-02-14 09:40:09 +08:00
#endif