2007-02-14 09:40:09 +08:00
|
|
|
/*
|
|
|
|
* internal.h: daemon data structure definitions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 2007 Red Hat, Inc.
|
|
|
|
* 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 <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include "protocol.h"
|
2007-02-15 00:02:40 +08:00
|
|
|
#include "bridge.h"
|
2007-02-15 00:26:42 +08:00
|
|
|
#include "iptables.h"
|
2007-02-14 09:40:09 +08:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifdef HAVE_ANSIDECL_H
|
|
|
|
#include <ansidecl.h>
|
|
|
|
#endif
|
|
|
|
#ifndef ATTRIBUTE_UNUSED
|
|
|
|
#define ATTRIBUTE_UNUSED __attribute__((unused))
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define ATTRIBUTE_UNUSED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define QEMUD_DEBUG(args...) fprintf(stderr, args)
|
|
|
|
#else
|
|
|
|
#define QEMUD_DEBUG(args...) do {} while(0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define UUID_LEN 16
|
|
|
|
|
|
|
|
/* Different types of QEMU acceleration possible */
|
|
|
|
enum qemud_vm_virt_type {
|
|
|
|
QEMUD_VIRT_QEMU,
|
|
|
|
QEMUD_VIRT_KQEMU,
|
|
|
|
QEMUD_VIRT_KVM,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Two types of disk backends */
|
|
|
|
enum qemud_vm_disk_type {
|
|
|
|
QEMUD_DISK_BLOCK,
|
|
|
|
QEMUD_DISK_FILE
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Three types of disk frontend */
|
|
|
|
enum qemud_vm_disk_device {
|
|
|
|
QEMUD_DISK_DISK,
|
|
|
|
QEMUD_DISK_CDROM,
|
|
|
|
QEMUD_DISK_FLOPPY,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Stores the virtual disk configuration */
|
|
|
|
struct qemud_vm_disk_def {
|
|
|
|
int type;
|
|
|
|
int device;
|
|
|
|
char src[PATH_MAX];
|
|
|
|
char dst[NAME_MAX];
|
|
|
|
int readonly;
|
|
|
|
|
|
|
|
struct qemud_vm_disk_def *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QEMUD_MAC_ADDRESS_LEN 6
|
|
|
|
#define QEMUD_OS_TYPE_MAX_LEN 10
|
|
|
|
#define QEMUD_OS_ARCH_MAX_LEN 10
|
|
|
|
#define QEMUD_OS_MACHINE_MAX_LEN 10
|
|
|
|
|
|
|
|
/* 5 different types of networking config */
|
|
|
|
enum qemud_vm_net_type {
|
|
|
|
QEMUD_NET_USER,
|
|
|
|
QEMUD_NET_TAP,
|
|
|
|
QEMUD_NET_SERVER,
|
|
|
|
QEMUD_NET_CLIENT,
|
|
|
|
QEMUD_NET_MCAST,
|
2007-02-15 00:09:37 +08:00
|
|
|
QEMUD_NET_NETWORK,
|
2007-02-14 09:40:09 +08:00
|
|
|
/* QEMUD_NET_VDE*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Stores the virtual network interface configuration */
|
|
|
|
struct qemud_vm_net_def {
|
|
|
|
int type;
|
|
|
|
int vlan;
|
|
|
|
unsigned char mac[QEMUD_MAC_ADDRESS_LEN];
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
char ifname[NAME_MAX];
|
|
|
|
char script[PATH_MAX];
|
|
|
|
} tap;
|
|
|
|
struct {
|
|
|
|
struct sockaddr_in listen;
|
|
|
|
int port;
|
|
|
|
} server;
|
|
|
|
struct {
|
|
|
|
struct sockaddr_in connect;
|
|
|
|
int port;
|
|
|
|
} client;
|
|
|
|
struct {
|
|
|
|
struct sockaddr_in group;
|
|
|
|
int port;
|
|
|
|
} mcast;
|
|
|
|
struct {
|
|
|
|
char vlan[PATH_MAX];
|
|
|
|
} vde;
|
2007-02-15 00:09:37 +08:00
|
|
|
struct {
|
|
|
|
char name[QEMUD_MAX_NAME_LEN];
|
|
|
|
char tapifname[BR_IFNAME_MAXLEN];
|
|
|
|
} network;
|
2007-02-14 09:40:09 +08:00
|
|
|
} dst;
|
|
|
|
|
|
|
|
struct qemud_vm_net_def *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QEMUD_MAX_BOOT_DEVS 4
|
|
|
|
|
|
|
|
/* 3 possible boot devices */
|
|
|
|
enum qemud_vm_boot_order {
|
|
|
|
QEMUD_BOOT_FLOPPY,
|
|
|
|
QEMUD_BOOT_CDROM,
|
|
|
|
QEMUD_BOOT_DISK,
|
|
|
|
QEMUD_BOOT_NET,
|
|
|
|
};
|
|
|
|
/* 3 possible graphics console modes */
|
|
|
|
enum qemud_vm_grapics_type {
|
|
|
|
QEMUD_GRAPHICS_NONE,
|
|
|
|
QEMUD_GRAPHICS_SDL,
|
|
|
|
QEMUD_GRAPHICS_VNC,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum qemud_vm_features {
|
|
|
|
QEMUD_FEATURE_ACPI = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Operating system configuration data & machine / arch */
|
|
|
|
struct qemud_vm_os_def {
|
|
|
|
char type[QEMUD_OS_TYPE_MAX_LEN];
|
|
|
|
char arch[QEMUD_OS_ARCH_MAX_LEN];
|
|
|
|
char machine[QEMUD_OS_MACHINE_MAX_LEN];
|
|
|
|
int nBootDevs;
|
|
|
|
int bootDevs[QEMUD_MAX_BOOT_DEVS];
|
|
|
|
char kernel[PATH_MAX];
|
|
|
|
char initrd[PATH_MAX];
|
|
|
|
char cmdline[PATH_MAX];
|
|
|
|
char binary[PATH_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Guest VM main configuration */
|
|
|
|
struct qemud_vm_def {
|
|
|
|
int virtType;
|
|
|
|
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
|
|
|
char name[QEMUD_MAX_NAME_LEN];
|
|
|
|
|
|
|
|
int memory;
|
|
|
|
int maxmem;
|
|
|
|
int vcpus;
|
|
|
|
|
|
|
|
struct qemud_vm_os_def os;
|
|
|
|
|
|
|
|
int features;
|
|
|
|
int graphicsType;
|
|
|
|
int vncPort;
|
|
|
|
int vncActivePort;
|
|
|
|
|
|
|
|
int ndisks;
|
|
|
|
struct qemud_vm_disk_def *disks;
|
|
|
|
|
|
|
|
int nnets;
|
|
|
|
struct qemud_vm_net_def *nets;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Guest VM runtime state */
|
|
|
|
struct qemud_vm {
|
|
|
|
int stdout;
|
|
|
|
int stderr;
|
|
|
|
int monitor;
|
|
|
|
int pid;
|
2007-02-15 01:05:55 +08:00
|
|
|
int id;
|
2007-02-14 09:40:09 +08:00
|
|
|
|
2007-02-15 00:09:37 +08:00
|
|
|
int *tapfds;
|
|
|
|
int ntapfds;
|
|
|
|
|
2007-02-14 09:40:09 +08:00
|
|
|
char configFile[PATH_MAX];
|
|
|
|
|
2007-02-15 01:05:55 +08:00
|
|
|
struct qemud_vm_def *def; /* The current definition */
|
|
|
|
struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
|
2007-02-14 09:40:09 +08:00
|
|
|
|
|
|
|
struct qemud_vm *next;
|
|
|
|
};
|
|
|
|
|
2007-02-15 00:05:29 +08:00
|
|
|
/* Store start and end addresses of a dhcp range */
|
|
|
|
struct qemud_dhcp_range_def {
|
|
|
|
char start[BR_INET_ADDR_MAXLEN];
|
|
|
|
char end[BR_INET_ADDR_MAXLEN];
|
|
|
|
|
|
|
|
struct qemud_dhcp_range_def *next;
|
|
|
|
};
|
|
|
|
|
2007-02-14 23:54:10 +08:00
|
|
|
/* Virtual Network main configuration */
|
|
|
|
struct qemud_network_def {
|
|
|
|
unsigned char uuid[QEMUD_UUID_RAW_LEN];
|
|
|
|
char name[QEMUD_MAX_NAME_LEN];
|
2007-02-15 00:02:40 +08:00
|
|
|
|
|
|
|
char bridge[BR_IFNAME_MAXLEN];
|
|
|
|
int disableSTP;
|
|
|
|
int forwardDelay;
|
|
|
|
|
|
|
|
char ipAddress[BR_INET_ADDR_MAXLEN];
|
|
|
|
char netmask[BR_INET_ADDR_MAXLEN];
|
2007-02-15 00:05:29 +08:00
|
|
|
|
|
|
|
int nranges;
|
|
|
|
struct qemud_dhcp_range_def *ranges;
|
2007-02-14 23:54:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Virtual Network runtime state */
|
|
|
|
struct qemud_network {
|
2007-02-14 23:58:06 +08:00
|
|
|
char configFile[PATH_MAX];
|
|
|
|
|
2007-02-16 00:00:16 +08:00
|
|
|
struct qemud_network_def *def; /* The current definition */
|
|
|
|
struct qemud_network_def *newDef; /* New definition to activate at shutdown */
|
2007-02-15 00:02:40 +08:00
|
|
|
|
|
|
|
char bridge[BR_IFNAME_MAXLEN];
|
2007-02-15 00:05:29 +08:00
|
|
|
int dnsmasqPid;
|
2007-02-15 00:02:40 +08:00
|
|
|
|
|
|
|
unsigned int active : 1;
|
|
|
|
|
2007-02-14 23:54:10 +08:00
|
|
|
struct qemud_network *next;
|
|
|
|
};
|
|
|
|
|
2007-02-14 09:40:09 +08:00
|
|
|
/* Stores the per-client connection state */
|
|
|
|
struct qemud_client {
|
|
|
|
int fd;
|
|
|
|
int readonly;
|
|
|
|
struct qemud_packet incoming;
|
|
|
|
unsigned int incomingReceived;
|
|
|
|
struct qemud_packet outgoing;
|
|
|
|
unsigned int outgoingSent;
|
|
|
|
int tx;
|
|
|
|
struct qemud_client *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct qemud_socket {
|
|
|
|
int fd;
|
|
|
|
int readonly;
|
|
|
|
struct qemud_socket *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Main server state */
|
|
|
|
struct qemud_server {
|
|
|
|
int nsockets;
|
|
|
|
struct qemud_socket *sockets;
|
|
|
|
int qemuVersion;
|
|
|
|
int nclients;
|
|
|
|
struct qemud_client *clients;
|
|
|
|
int nvmfds;
|
|
|
|
int nactivevms;
|
|
|
|
struct qemud_vm *activevms;
|
|
|
|
int ninactivevms;
|
|
|
|
struct qemud_vm *inactivevms;
|
|
|
|
int nextvmid;
|
2007-02-14 23:58:06 +08:00
|
|
|
int nactivenetworks;
|
|
|
|
struct qemud_network *activenetworks;
|
|
|
|
int ninactivenetworks;
|
|
|
|
struct qemud_network *inactivenetworks;
|
2007-02-15 00:02:40 +08:00
|
|
|
brControl *brctl;
|
2007-02-15 00:26:42 +08:00
|
|
|
iptablesContext *iptables;
|
2007-02-14 09:40:09 +08:00
|
|
|
char configDir[PATH_MAX];
|
2007-02-14 23:58:06 +08:00
|
|
|
char networkConfigDir[PATH_MAX];
|
2007-02-14 09:40:09 +08:00
|
|
|
char errorMessage[QEMUD_MAX_ERROR_LEN];
|
|
|
|
int errorCode;
|
|
|
|
};
|
|
|
|
|
|
|
|
int qemudStartVMDaemon(struct qemud_server *server,
|
|
|
|
struct qemud_vm *vm);
|
|
|
|
|
|
|
|
int qemudShutdownVMDaemon(struct qemud_server *server,
|
|
|
|
struct qemud_vm *vm);
|
|
|
|
|
2007-02-14 23:58:06 +08:00
|
|
|
int qemudStartNetworkDaemon(struct qemud_server *server,
|
|
|
|
struct qemud_network *network);
|
|
|
|
|
|
|
|
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
|
|
|
struct qemud_network *network);
|
|
|
|
|
|
|
|
|
2007-02-14 09:40:09 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* c-indent-level: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 4
|
|
|
|
* End:
|
|
|
|
*/
|