提交 efe538b7 编写于 作者: M Mark McLoughlin

Fri Feb 23 09:00:13 IST 2007 Mark McLoughlin <markmc@redhat.com>

        * qemud/protocol.h: add the (domain/network)(Get/Set)Autostart
        requests and replies to the protocol.

        * src/qemu_internal.c: hookup the qemu driver autostart
        methods

        * qemud/dispatch.c, qemud/driver.[ch], internal.h: add
        the daemon side, but just set an in-memory autostart
        flag for now.
上级 55868d76
Fri Feb 23 09:00:13 IST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/protocol.h: add the (domain/network)(Get/Set)Autostart
requests and replies to the protocol.
* src/qemu_internal.c: hookup the qemu driver autostart
methods
* qemud/dispatch.c, qemud/driver.[ch], internal.h: add
the daemon side, but just set an in-memory autostart
flag for now.
Fri Feb 23 08:51:05 IST 2007 Mark McLoughlin <markmc@redhat.com> Fri Feb 23 08:51:05 IST 2007 Mark McLoughlin <markmc@redhat.com>
* src/virsh.c: add "autostart" and "net-autostart" commands * src/virsh.c: add "autostart" and "net-autostart" commands
......
...@@ -717,6 +717,97 @@ static int qemudDispatchNetworkGetBridgeName(struct qemud_server *server, struct ...@@ -717,6 +717,97 @@ static int qemudDispatchNetworkGetBridgeName(struct qemud_server *server, struct
return 0; return 0;
} }
static int qemudDispatchDomainGetAutostart(struct qemud_server *server, struct qemud_client *client,
struct qemud_packet *in, struct qemud_packet *out)
{
int ret;
int autostart;
if (in->header.dataSize != sizeof(in->data.domainGetAutostartRequest))
return -1;
autostart = 0;
ret = qemudDomainGetAutostart(server,
in->data.domainGetAutostartRequest.uuid,
&autostart);
if (ret < 0) {
if (qemudDispatchFailure(server, client, out) < 0)
return -1;
} else {
out->header.type = QEMUD_PKT_DOMAIN_GET_AUTOSTART;
out->header.dataSize = sizeof(out->data.networkGetAutostartReply);
out->data.networkGetAutostartReply.autostart = (autostart != 0);
}
return 0;
}
static int qemudDispatchDomainSetAutostart(struct qemud_server *server, struct qemud_client *client,
struct qemud_packet *in, struct qemud_packet *out)
{
int ret;
if (in->header.dataSize != sizeof(in->data.domainSetAutostartRequest))
return -1;
ret = qemudDomainSetAutostart(server,
in->data.domainGetAutostartRequest.uuid,
in->data.domainSetAutostartRequest.autostart);
if (ret < 0) {
if (qemudDispatchFailure(server, client, out) < 0)
return -1;
} else {
out->header.type = QEMUD_PKT_DOMAIN_SET_AUTOSTART;
out->header.dataSize = 0;
}
return 0;
}
static int qemudDispatchNetworkGetAutostart(struct qemud_server *server, struct qemud_client *client,
struct qemud_packet *in, struct qemud_packet *out)
{
int ret;
int autostart;
if (in->header.dataSize != sizeof(in->data.networkGetAutostartRequest))
return -1;
autostart = 0;
ret = qemudNetworkGetAutostart(server,
in->data.networkGetAutostartRequest.uuid,
&autostart);
if (ret < 0) {
if (qemudDispatchFailure(server, client, out) < 0)
return -1;
} else {
out->header.type = QEMUD_PKT_NETWORK_GET_AUTOSTART;
out->header.dataSize = sizeof(out->data.networkGetAutostartReply);
out->data.networkGetAutostartReply.autostart = (autostart != 0);
}
return 0;
}
static int qemudDispatchNetworkSetAutostart(struct qemud_server *server, struct qemud_client *client,
struct qemud_packet *in, struct qemud_packet *out)
{
int ret;
if (in->header.dataSize != sizeof(in->data.networkSetAutostartRequest))
return -1;
ret = qemudNetworkSetAutostart(server,
in->data.networkGetAutostartRequest.uuid,
in->data.networkSetAutostartRequest.autostart);
if (ret < 0) {
if (qemudDispatchFailure(server, client, out) < 0)
return -1;
} else {
out->header.type = QEMUD_PKT_NETWORK_SET_AUTOSTART;
out->header.dataSize = 0;
}
return 0;
}
typedef int (*clientFunc)(struct qemud_server *server, struct qemud_client *client, typedef int (*clientFunc)(struct qemud_server *server, struct qemud_client *client,
struct qemud_packet *in, struct qemud_packet *out); struct qemud_packet *in, struct qemud_packet *out);
...@@ -759,6 +850,10 @@ clientFunc funcsTransmitRW[QEMUD_PKT_MAX] = { ...@@ -759,6 +850,10 @@ clientFunc funcsTransmitRW[QEMUD_PKT_MAX] = {
qemudDispatchNetworkDestroy, qemudDispatchNetworkDestroy,
qemudDispatchNetworkDumpXML, qemudDispatchNetworkDumpXML,
qemudDispatchNetworkGetBridgeName, qemudDispatchNetworkGetBridgeName,
qemudDispatchDomainGetAutostart,
qemudDispatchDomainSetAutostart,
qemudDispatchNetworkGetAutostart,
qemudDispatchNetworkSetAutostart,
}; };
clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = { clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = {
...@@ -796,6 +891,10 @@ clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = { ...@@ -796,6 +891,10 @@ clientFunc funcsTransmitRO[QEMUD_PKT_MAX] = {
NULL, NULL,
qemudDispatchNetworkDumpXML, qemudDispatchNetworkDumpXML,
qemudDispatchNetworkGetBridgeName, qemudDispatchNetworkGetBridgeName,
qemudDispatchDomainGetAutostart,
NULL,
qemudDispatchNetworkGetAutostart,
NULL,
}; };
/* /*
......
...@@ -509,6 +509,41 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid) ...@@ -509,6 +509,41 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid)
return 0; return 0;
} }
int qemudDomainGetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int *autostart) {
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1;
}
*autostart = vm->autostart;
return 0;
}
int qemudDomainSetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int autostart) {
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
if (!vm) {
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
return -1;
}
autostart = (autostart != 0);
if (vm->autostart == autostart)
return 0;
vm->autostart = autostart;
return 0;
}
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server, struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
const unsigned char *uuid) { const unsigned char *uuid) {
struct qemud_network *network = server->networks; struct qemud_network *network = server->networks;
...@@ -685,6 +720,41 @@ int qemudNetworkGetBridgeName(struct qemud_server *server, const unsigned char * ...@@ -685,6 +720,41 @@ int qemudNetworkGetBridgeName(struct qemud_server *server, const unsigned char *
return 0; return 0;
} }
int qemudNetworkGetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int *autostart) {
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
return -1;
}
*autostart = network->autostart;
return 0;
}
int qemudNetworkSetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int autostart) {
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
if (!network) {
qemudReportError(server, VIR_ERR_INVALID_NETWORK, "no network with matching uuid");
return -1;
}
autostart = (autostart != 0);
if (network->autostart == autostart)
return 0;
network->autostart = autostart;
return 0;
}
/* /*
* Local variables: * Local variables:
* indent-tabs-mode: nil * indent-tabs-mode: nil
......
...@@ -85,6 +85,12 @@ struct qemud_vm *qemudDomainDefine(struct qemud_server *server, ...@@ -85,6 +85,12 @@ struct qemud_vm *qemudDomainDefine(struct qemud_server *server,
const char *xml); const char *xml);
int qemudDomainUndefine(struct qemud_server *server, int qemudDomainUndefine(struct qemud_server *server,
const unsigned char *uuid); const unsigned char *uuid);
int qemudDomainGetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int *autostart);
int qemudDomainSetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int autostart);
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server, struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
const unsigned char *uuid); const unsigned char *uuid);
...@@ -117,6 +123,12 @@ int qemudNetworkGetBridgeName(struct qemud_server *server, ...@@ -117,6 +123,12 @@ int qemudNetworkGetBridgeName(struct qemud_server *server,
const unsigned char *uuid, const unsigned char *uuid,
char *ifname, char *ifname,
int ifnamelen); int ifnamelen);
int qemudNetworkGetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int *autostart);
int qemudNetworkSetAutostart(struct qemud_server *server,
const unsigned char *uuid,
int autostart);
#endif #endif
......
...@@ -209,6 +209,8 @@ struct qemud_vm { ...@@ -209,6 +209,8 @@ struct qemud_vm {
struct qemud_vm_def *def; /* The current definition */ struct qemud_vm_def *def; /* The current definition */
struct qemud_vm_def *newDef; /* New definition to activate at shutdown */ struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
unsigned int autostart : 1;
struct qemud_vm *next; struct qemud_vm *next;
}; };
...@@ -247,6 +249,7 @@ struct qemud_network { ...@@ -247,6 +249,7 @@ struct qemud_network {
int dnsmasqPid; int dnsmasqPid;
unsigned int active : 1; unsigned int active : 1;
unsigned int autostart : 1;
struct qemud_network *next; struct qemud_network *next;
}; };
......
...@@ -64,6 +64,10 @@ enum { ...@@ -64,6 +64,10 @@ enum {
QEMUD_PKT_NETWORK_DESTROY, QEMUD_PKT_NETWORK_DESTROY,
QEMUD_PKT_NETWORK_DUMP_XML, QEMUD_PKT_NETWORK_DUMP_XML,
QEMUD_PKT_NETWORK_GET_BRIDGE_NAME, QEMUD_PKT_NETWORK_GET_BRIDGE_NAME,
QEMUD_PKT_DOMAIN_GET_AUTOSTART,
QEMUD_PKT_DOMAIN_SET_AUTOSTART,
QEMUD_PKT_NETWORK_GET_AUTOSTART,
QEMUD_PKT_NETWORK_SET_AUTOSTART,
QEMUD_PKT_MAX, QEMUD_PKT_MAX,
} qemud_packet_type; } qemud_packet_type;
...@@ -279,6 +283,26 @@ union qemud_packet_data { ...@@ -279,6 +283,26 @@ union qemud_packet_data {
struct { struct {
char ifname[QEMUD_MAX_IFNAME_LEN]; char ifname[QEMUD_MAX_IFNAME_LEN];
} networkGetBridgeNameReply; } networkGetBridgeNameReply;
struct {
unsigned char uuid[QEMUD_UUID_RAW_LEN];
} domainGetAutostartRequest;
struct {
int autostart;
} domainGetAutostartReply;
struct {
unsigned char uuid[QEMUD_UUID_RAW_LEN];
unsigned int autostart : 1;
} domainSetAutostartRequest;
struct {
unsigned char uuid[QEMUD_UUID_RAW_LEN];
} networkGetAutostartRequest;
struct {
unsigned int autostart : 1;
} networkGetAutostartReply;
struct {
unsigned char uuid[QEMUD_UUID_RAW_LEN];
unsigned int autostart : 1;
} networkSetAutostartRequest;
}; };
/* Each packet has header & data */ /* Each packet has header & data */
......
...@@ -806,6 +806,39 @@ static int qemuUndefine(virDomainPtr dom) { ...@@ -806,6 +806,39 @@ static int qemuUndefine(virDomainPtr dom) {
return ret; return ret;
} }
static int qemuDomainGetAutostart(virDomainPtr dom,
int *autostart) {
struct qemud_packet req, reply;
req.header.type = QEMUD_PKT_DOMAIN_GET_AUTOSTART;
req.header.dataSize = sizeof(req.data.domainGetAutostartRequest);
memmove(req.data.domainGetAutostartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) {
return -1;
}
*autostart = reply.data.domainGetAutostartReply.autostart;
return 0;
}
static int qemuDomainSetAutostart(virDomainPtr dom,
int autostart) {
struct qemud_packet req, reply;
req.header.type = QEMUD_PKT_DOMAIN_SET_AUTOSTART;
req.header.dataSize = sizeof(req.data.domainSetAutostartRequest);
req.data.domainSetAutostartRequest.autostart = (autostart != 0);
memmove(req.data.domainSetAutostartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) {
return -1;
}
return 0;
}
static int qemuNetworkOpen(virConnectPtr conn, static int qemuNetworkOpen(virConnectPtr conn,
const char *name, const char *name,
int flags) { int flags) {
...@@ -1093,6 +1126,39 @@ static char * qemuNetworkGetBridgeName(virNetworkPtr network) { ...@@ -1093,6 +1126,39 @@ static char * qemuNetworkGetBridgeName(virNetworkPtr network) {
return strdup(reply.data.networkGetBridgeNameReply.ifname); return strdup(reply.data.networkGetBridgeNameReply.ifname);
} }
static int qemuNetworkGetAutostart(virNetworkPtr network,
int *autostart) {
struct qemud_packet req, reply;
req.header.type = QEMUD_PKT_NETWORK_GET_AUTOSTART;
req.header.dataSize = sizeof(req.data.networkGetAutostartRequest);
memmove(req.data.networkGetAutostartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
return -1;
}
*autostart = reply.data.networkGetAutostartReply.autostart;
return 0;
}
static int qemuNetworkSetAutostart(virNetworkPtr network,
int autostart) {
struct qemud_packet req, reply;
req.header.type = QEMUD_PKT_NETWORK_SET_AUTOSTART;
req.header.dataSize = sizeof(req.data.networkSetAutostartRequest);
req.data.networkSetAutostartRequest.autostart = (autostart != 0);
memmove(req.data.networkSetAutostartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN);
if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) {
return -1;
}
return 0;
}
static virDriver qemuDriver = { static virDriver qemuDriver = {
VIR_DRV_QEMU, VIR_DRV_QEMU,
"QEMU", "QEMU",
...@@ -1132,8 +1198,8 @@ static virDriver qemuDriver = { ...@@ -1132,8 +1198,8 @@ static virDriver qemuDriver = {
qemuUndefine, /* domainUndefine */ qemuUndefine, /* domainUndefine */
NULL, /* domainAttachDevice */ NULL, /* domainAttachDevice */
NULL, /* domainDetachDevice */ NULL, /* domainDetachDevice */
NULL, /* domainGetAutostart */ qemuDomainGetAutostart, /* domainGetAutostart */
NULL, /* domainSetAutostart */ qemuDomainSetAutostart, /* domainSetAutostart */
}; };
static virNetworkDriver qemuNetworkDriver = { static virNetworkDriver qemuNetworkDriver = {
...@@ -1152,8 +1218,8 @@ static virNetworkDriver qemuNetworkDriver = { ...@@ -1152,8 +1218,8 @@ static virNetworkDriver qemuNetworkDriver = {
qemuNetworkDestroy, /* networkDestroy */ qemuNetworkDestroy, /* networkDestroy */
qemuNetworkDumpXML, /* networkDumpXML */ qemuNetworkDumpXML, /* networkDumpXML */
qemuNetworkGetBridgeName, /* networkGetBridgeName */ qemuNetworkGetBridgeName, /* networkGetBridgeName */
NULL, /* networkGetAutostart */ qemuNetworkGetAutostart, /* networkGetAutostart */
NULL, /* networkSetAutostart */ qemuNetworkSetAutostart, /* networkSetAutostart */
}; };
void qemuRegister(void) { void qemuRegister(void) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册