mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-29 17:33:09 +00:00
Update to comply with internal driver API
This commit is contained in:
parent
2f02d292da
commit
a041de159f
@ -1,3 +1,9 @@
|
|||||||
|
Tue Jun 26 18:35:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* qemud/conf.c, qemud/dispatch.c, qemud/driver.c, qemud/driver.h
|
||||||
|
Change API contract of all driver methods to make official
|
||||||
|
internal driver API.
|
||||||
|
|
||||||
Tue Jun 26 18:30:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
Tue Jun 26 18:30:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* qemud/buf.c, qemud/buf.h: Remove obsolete files
|
* qemud/buf.c, qemud/buf.h: Remove obsolete files
|
||||||
|
@ -1610,7 +1610,7 @@ qemudAssignVMDef(struct qemud_driver *driver,
|
|||||||
vm->monitor = -1;
|
vm->monitor = -1;
|
||||||
vm->pid = -1;
|
vm->pid = -1;
|
||||||
vm->id = -1;
|
vm->id = -1;
|
||||||
vm->state = QEMUD_STATE_STOPPED;
|
vm->state = VIR_DOMAIN_SHUTOFF;
|
||||||
vm->def = def;
|
vm->def = def;
|
||||||
vm->next = driver->vms;
|
vm->next = driver->vms;
|
||||||
|
|
||||||
|
409
qemud/dispatch.c
409
qemud/dispatch.c
@ -37,22 +37,34 @@
|
|||||||
extern struct qemud_driver *qemu_driver;
|
extern struct qemud_driver *qemu_driver;
|
||||||
|
|
||||||
|
|
||||||
|
static virConnect conn;
|
||||||
|
|
||||||
static int qemudDispatchFailure(struct qemud_packet_server_data *out) {
|
static int qemudDispatchFailure(struct qemud_packet_server_data *out) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
|
if (!err)
|
||||||
|
err = virConnGetLastError(&conn);
|
||||||
|
|
||||||
out->type = QEMUD_SERVER_PKT_FAILURE;
|
out->type = QEMUD_SERVER_PKT_FAILURE;
|
||||||
|
|
||||||
|
if (err) {
|
||||||
out->qemud_packet_server_data_u.failureReply.code = err->code;
|
out->qemud_packet_server_data_u.failureReply.code = err->code;
|
||||||
strncpy(out->qemud_packet_server_data_u.failureReply.message,
|
strncpy(out->qemud_packet_server_data_u.failureReply.message,
|
||||||
err->message, QEMUD_MAX_ERROR_LEN-1);
|
err->message, QEMUD_MAX_ERROR_LEN-1);
|
||||||
out->qemud_packet_server_data_u.failureReply.message[QEMUD_MAX_ERROR_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.failureReply.message[QEMUD_MAX_ERROR_LEN-1] = '\0';
|
||||||
|
} else {
|
||||||
|
out->qemud_packet_server_data_u.failureReply.code = VIR_ERR_INTERNAL_ERROR;
|
||||||
|
strcpy(out->qemud_packet_server_data_u.failureReply.message,
|
||||||
|
"Unknown error");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int qemudDispatchGetVersion(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchGetVersion(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
int version = qemudGetVersion(qemu_driver);
|
int ret;
|
||||||
if (version < 0) {
|
unsigned long version;
|
||||||
|
ret = qemudGetVersion(&conn, &version);
|
||||||
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -63,21 +75,25 @@ static int qemudDispatchGetVersion(struct qemud_packet_client_data *in ATTRIBUTE
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchGetNodeInfo(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchGetNodeInfo(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
if (qemudGetNodeInfo(&out->qemud_packet_server_data_u.getNodeInfoReply.memory,
|
virNodeInfo info;
|
||||||
out->qemud_packet_server_data_u.getNodeInfoReply.model,
|
if (qemudGetNodeInfo(&conn,
|
||||||
sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model),
|
&info) < 0) {
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.cpus,
|
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.mhz,
|
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.nodes,
|
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.sockets,
|
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.cores,
|
|
||||||
&out->qemud_packet_server_data_u.getNodeInfoReply.threads) < 0) {
|
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.memory = info.memory;
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.cpus = info.cpus;
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.mhz = info.mhz;
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.nodes = info.nodes;
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.sockets = info.sockets;
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.cores = info.cores;
|
||||||
|
out->qemud_packet_server_data_u.getNodeInfoReply.threads = info.threads;
|
||||||
|
|
||||||
out->type = QEMUD_SERVER_PKT_GET_NODEINFO;
|
out->type = QEMUD_SERVER_PKT_GET_NODEINFO;
|
||||||
|
strncpy(out->qemud_packet_server_data_u.getNodeInfoReply.model, info.model,
|
||||||
|
sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model)-1);
|
||||||
out->qemud_packet_server_data_u.getNodeInfoReply.model[sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model)-1] = '\0';
|
out->qemud_packet_server_data_u.getNodeInfoReply.model[sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model)-1] = '\0';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -87,10 +103,10 @@ static int
|
|||||||
qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUSED,
|
qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUSED,
|
||||||
struct qemud_packet_server_data *out)
|
struct qemud_packet_server_data *out)
|
||||||
{
|
{
|
||||||
char *xml = qemudGetCapabilities(qemu_driver);
|
char *xml = qemudGetCapabilities(&conn);
|
||||||
|
|
||||||
if (strlen(xml) > QEMUD_MAX_XML_LEN) {
|
if (strlen(xml) > QEMUD_MAX_XML_LEN) {
|
||||||
qemudReportError(NULL, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
qemudReportError(&conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
|
||||||
qemudDispatchFailure(out);
|
qemudDispatchFailure(out);
|
||||||
free(xml);
|
free(xml);
|
||||||
return 0;
|
return 0;
|
||||||
@ -105,7 +121,7 @@ qemudDispatchGetCapabilities (struct qemud_packet_client_data *in ATTRIBUTE_UNUS
|
|||||||
static int qemudDispatchListDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchListDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
int i, ndomains, domains[QEMUD_MAX_NUM_DOMAINS];
|
int i, ndomains, domains[QEMUD_MAX_NUM_DOMAINS];
|
||||||
|
|
||||||
ndomains = qemudListDomains(qemu_driver,
|
ndomains = qemudListDomains(&conn,
|
||||||
domains,
|
domains,
|
||||||
QEMUD_MAX_NUM_DOMAINS);
|
QEMUD_MAX_NUM_DOMAINS);
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
@ -122,7 +138,7 @@ static int qemudDispatchListDomains(struct qemud_packet_client_data *in ATTRIBUT
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNumDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
int ndomains = qemudNumDomains(qemu_driver);
|
int ndomains = qemudNumDomains(&conn);
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -136,44 +152,47 @@ static int qemudDispatchNumDomains(struct qemud_packet_client_data *in ATTRIBUTE
|
|||||||
static int qemudDispatchDomainCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
in->qemud_packet_client_data_u.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_vm *vm = qemudDomainCreate(qemu_driver, in->qemud_packet_client_data_u.domainCreateRequest.xml);
|
virDomainPtr dom = qemudDomainCreate(&conn, in->qemud_packet_client_data_u.domainCreateRequest.xml, 0);
|
||||||
if (!vm) {
|
if (!dom) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_CREATE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_CREATE;
|
||||||
out->qemud_packet_server_data_u.domainCreateReply.id = vm->id;
|
out->qemud_packet_server_data_u.domainCreateReply.id = dom->id;
|
||||||
memcpy(out->qemud_packet_server_data_u.domainCreateReply.uuid, vm->def->uuid, QEMUD_UUID_RAW_LEN);
|
memcpy(out->qemud_packet_server_data_u.domainCreateReply.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
|
||||||
strncpy(out->qemud_packet_server_data_u.domainCreateReply.name, vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
strncpy(out->qemud_packet_server_data_u.domainCreateReply.name, dom->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
out->qemud_packet_server_data_u.domainCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.domainCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
free(dom);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainLookupByID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainLookupByID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_vm *vm = qemudFindVMByID(qemu_driver, in->qemud_packet_client_data_u.domainLookupByIDRequest.id);
|
virDomainPtr dom = qemudDomainLookupByID(&conn, in->qemud_packet_client_data_u.domainLookupByIDRequest.id);
|
||||||
if (!vm) {
|
if (!dom) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_ID;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_ID;
|
||||||
memcpy(out->qemud_packet_server_data_u.domainLookupByIDReply.uuid, vm->def->uuid, QEMUD_UUID_RAW_LEN);
|
memcpy(out->qemud_packet_server_data_u.domainLookupByIDReply.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
|
||||||
strncpy(out->qemud_packet_server_data_u.domainLookupByIDReply.name, vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
strncpy(out->qemud_packet_server_data_u.domainLookupByIDReply.name, dom->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
out->qemud_packet_server_data_u.domainLookupByIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.domainLookupByIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
free(dom);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainLookupByUUID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainLookupByUUID(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_vm *vm = qemudFindVMByUUID(qemu_driver, in->qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid);
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid);
|
||||||
if (!vm) {
|
if (!dom) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_UUID;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_UUID;
|
||||||
out->qemud_packet_server_data_u.domainLookupByUUIDReply.id = vm->id;
|
out->qemud_packet_server_data_u.domainLookupByUUIDReply.id = dom->id;
|
||||||
strncpy(out->qemud_packet_server_data_u.domainLookupByUUIDReply.name, vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
strncpy(out->qemud_packet_server_data_u.domainLookupByUUIDReply.name, dom->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
out->qemud_packet_server_data_u.domainLookupByUUIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.domainLookupByUUIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
free(dom);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -181,20 +200,30 @@ static int qemudDispatchDomainLookupByUUID(struct qemud_packet_client_data *in,
|
|||||||
static int qemudDispatchDomainLookupByName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainLookupByName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
/* Paranoia NULL termination */
|
/* Paranoia NULL termination */
|
||||||
in->qemud_packet_client_data_u.domainLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
in->qemud_packet_client_data_u.domainLookupByNameRequest.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
struct qemud_vm *vm = qemudFindVMByName(qemu_driver, in->qemud_packet_client_data_u.domainLookupByNameRequest.name);
|
virDomainPtr dom = qemudDomainLookupByName(&conn, in->qemud_packet_client_data_u.domainLookupByNameRequest.name);
|
||||||
if (!vm) {
|
if (!dom) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_NAME;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_LOOKUP_BY_NAME;
|
||||||
out->qemud_packet_server_data_u.domainLookupByNameReply.id = vm->id;
|
out->qemud_packet_server_data_u.domainLookupByNameReply.id = dom->id;
|
||||||
memcpy(out->qemud_packet_server_data_u.domainLookupByNameReply.uuid, vm->def->uuid, QEMUD_UUID_RAW_LEN);
|
memcpy(out->qemud_packet_server_data_u.domainLookupByNameReply.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
|
||||||
|
free(dom);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainSuspend(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainSuspend(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret = qemudDomainSuspend(qemu_driver, in->qemud_packet_client_data_u.domainSuspendRequest.id);
|
virDomainPtr dom = qemudDomainLookupByID(&conn, in->qemud_packet_client_data_u.domainSuspendRequest.id);
|
||||||
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudDomainSuspend(dom);
|
||||||
|
free(dom);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -205,7 +234,16 @@ static int qemudDispatchDomainSuspend(struct qemud_packet_client_data *in, struc
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainResume(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainResume(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret = qemudDomainResume(qemu_driver, in->qemud_packet_client_data_u.domainResumeRequest.id);
|
virDomainPtr dom = qemudDomainLookupByID(&conn, in->qemud_packet_client_data_u.domainResumeRequest.id);
|
||||||
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudDomainResume(dom);
|
||||||
|
free(dom);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -216,7 +254,17 @@ static int qemudDispatchDomainResume(struct qemud_packet_client_data *in, struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
if (qemudDomainDestroy(qemu_driver, in->qemud_packet_client_data_u.domainDestroyRequest.id) < 0) {
|
virDomainPtr dom = qemudDomainLookupByID(&conn, in->qemud_packet_client_data_u.domainDestroyRequest.id);
|
||||||
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudDomainDestroy(dom);
|
||||||
|
free(dom);
|
||||||
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -226,39 +274,44 @@ static int qemudDispatchDomainDestroy(struct qemud_packet_client_data *in, struc
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainGetInfo(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainGetInfo(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int runstate;
|
virDomainInfo info;
|
||||||
unsigned long long cpuTime;
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainGetInfoRequest.uuid);
|
||||||
unsigned long memory;
|
|
||||||
unsigned long maxmem;
|
|
||||||
unsigned int nrVirtCpu;
|
|
||||||
|
|
||||||
int ret = qemudDomainGetInfo(qemu_driver, in->qemud_packet_client_data_u.domainGetInfoRequest.uuid,
|
if (!dom) {
|
||||||
&runstate,
|
if (qemudDispatchFailure(out) < 0)
|
||||||
&cpuTime,
|
return -1;
|
||||||
&maxmem,
|
return 0;
|
||||||
&memory,
|
}
|
||||||
&nrVirtCpu);
|
|
||||||
if (ret < 0) {
|
if (qemudDomainGetInfo(dom, &info) < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_GET_INFO;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_GET_INFO;
|
||||||
out->qemud_packet_server_data_u.domainGetInfoReply.runstate = runstate;
|
out->qemud_packet_server_data_u.domainGetInfoReply.runstate = info.state;
|
||||||
out->qemud_packet_server_data_u.domainGetInfoReply.cpuTime = cpuTime;
|
out->qemud_packet_server_data_u.domainGetInfoReply.cpuTime = info.cpuTime;
|
||||||
out->qemud_packet_server_data_u.domainGetInfoReply.maxmem = maxmem;
|
out->qemud_packet_server_data_u.domainGetInfoReply.maxmem = info.maxMem;
|
||||||
out->qemud_packet_server_data_u.domainGetInfoReply.memory = memory;
|
out->qemud_packet_server_data_u.domainGetInfoReply.memory = info.memory;
|
||||||
out->qemud_packet_server_data_u.domainGetInfoReply.nrVirtCpu = nrVirtCpu;
|
out->qemud_packet_server_data_u.domainGetInfoReply.nrVirtCpu = info.nrVirtCpu;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainSave(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainSave(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
|
virDomainPtr dom = qemudDomainLookupByID(&conn, in->qemud_packet_client_data_u.domainSaveRequest.id);
|
||||||
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Paranoia NULL termination */
|
/* Paranoia NULL termination */
|
||||||
in->qemud_packet_client_data_u.domainSaveRequest.file[PATH_MAX-1] ='\0';
|
in->qemud_packet_client_data_u.domainSaveRequest.file[PATH_MAX-1] ='\0';
|
||||||
|
|
||||||
int ret = qemudDomainSave(qemu_driver,
|
ret = qemudDomainSave(dom,
|
||||||
in->qemud_packet_client_data_u.domainSaveRequest.id,
|
|
||||||
in->qemud_packet_client_data_u.domainSaveRequest.file);
|
in->qemud_packet_client_data_u.domainSaveRequest.file);
|
||||||
|
free(dom);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -269,33 +322,42 @@ static int qemudDispatchDomainSave(struct qemud_packet_client_data *in, struct q
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainRestore(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainRestore(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int id;
|
int ret;
|
||||||
|
|
||||||
/* Paranoia null termination */
|
/* Paranoia null termination */
|
||||||
in->qemud_packet_client_data_u.domainRestoreRequest.file[PATH_MAX-1] ='\0';
|
in->qemud_packet_client_data_u.domainRestoreRequest.file[PATH_MAX-1] ='\0';
|
||||||
|
|
||||||
id = qemudDomainRestore(qemu_driver, in->qemud_packet_client_data_u.domainRestoreRequest.file);
|
ret = qemudDomainRestore(&conn, in->qemud_packet_client_data_u.domainRestoreRequest.file);
|
||||||
if (id < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_RESTORE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_RESTORE;
|
||||||
out->qemud_packet_server_data_u.domainRestoreReply.id = id;
|
out->qemud_packet_server_data_u.domainRestoreReply.id = ret;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret;
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainDumpXMLRequest.uuid);
|
||||||
ret = qemudDomainDumpXML(qemu_driver,
|
char *ret;
|
||||||
in->qemud_packet_client_data_u.domainDumpXMLRequest.uuid,
|
if (!dom) {
|
||||||
out->qemud_packet_server_data_u.domainDumpXMLReply.xml,
|
if (qemudDispatchFailure(out) < 0)
|
||||||
QEMUD_MAX_XML_LEN);
|
return -1;
|
||||||
if (ret < 0) {
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudDomainDumpXML(dom, 0);
|
||||||
|
free(dom);
|
||||||
|
if (!ret) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DUMP_XML;
|
out->type = QEMUD_SERVER_PKT_DUMP_XML;
|
||||||
|
strncpy(out->qemud_packet_server_data_u.domainDumpXMLReply.xml,
|
||||||
|
ret, QEMUD_MAX_XML_LEN-1);
|
||||||
|
out->qemud_packet_server_data_u.domainDumpXMLReply.xml[QEMUD_MAX_XML_LEN-1] = '\0';
|
||||||
|
free(ret);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -307,13 +369,16 @@ static int qemudDispatchListDefinedDomains(struct qemud_packet_client_data *in A
|
|||||||
if (!(names = malloc(sizeof(char *)*QEMUD_MAX_NUM_DOMAINS)))
|
if (!(names = malloc(sizeof(char *)*QEMUD_MAX_NUM_DOMAINS)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0 ; i < QEMUD_MAX_NUM_DOMAINS ; i++) {
|
ndomains = qemudListDefinedDomains(&conn,
|
||||||
names[i] = &out->qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN];
|
|
||||||
}
|
|
||||||
|
|
||||||
ndomains = qemudListDefinedDomains(qemu_driver,
|
|
||||||
names,
|
names,
|
||||||
QEMUD_MAX_NUM_DOMAINS);
|
QEMUD_MAX_NUM_DOMAINS);
|
||||||
|
for (i = 0 ; i < ndomains ; i++) {
|
||||||
|
strncpy(&out->qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN],
|
||||||
|
names[i],
|
||||||
|
QEMUD_MAX_NAME_LEN);
|
||||||
|
free(names[i]);
|
||||||
|
}
|
||||||
|
|
||||||
free(names);
|
free(names);
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
@ -322,15 +387,11 @@ static int qemudDispatchListDefinedDomains(struct qemud_packet_client_data *in A
|
|||||||
out->type = QEMUD_SERVER_PKT_LIST_DEFINED_DOMAINS;
|
out->type = QEMUD_SERVER_PKT_LIST_DEFINED_DOMAINS;
|
||||||
out->qemud_packet_server_data_u.listDefinedDomainsReply.numDomains = ndomains;
|
out->qemud_packet_server_data_u.listDefinedDomainsReply.numDomains = ndomains;
|
||||||
}
|
}
|
||||||
printf("%d %d\n", out->type, out->qemud_packet_server_data_u.listDefinedDomainsReply.numDomains);
|
|
||||||
for (i = 0 ; i < ndomains;i++) {
|
|
||||||
printf("[%s]\n", &out->qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN]);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumDefinedDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNumDefinedDomains(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
int ndomains = qemudNumDefinedDomains(qemu_driver);
|
int ndomains = qemudNumDefinedDomains(&conn);
|
||||||
if (ndomains < 0) {
|
if (ndomains < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -342,14 +403,22 @@ static int qemudDispatchNumDefinedDomains(struct qemud_packet_client_data *in AT
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_vm *vm;
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainStartRequest.uuid);
|
||||||
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(vm = qemudDomainStart(qemu_driver, in->qemud_packet_client_data_u.domainStartRequest.uuid))) {
|
ret = qemudDomainStart(dom);
|
||||||
|
free(dom);
|
||||||
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_START;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_START;
|
||||||
out->qemud_packet_server_data_u.domainStartReply.id = vm->id;
|
out->qemud_packet_server_data_u.domainStartReply.id = dom->id;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -357,21 +426,29 @@ static int qemudDispatchDomainStart(struct qemud_packet_client_data *in, struct
|
|||||||
static int qemudDispatchDomainDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
in->qemud_packet_client_data_u.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_vm *vm = qemudDomainDefine(qemu_driver, in->qemud_packet_client_data_u.domainDefineRequest.xml);
|
virDomainPtr dom = qemudDomainDefine(&conn, in->qemud_packet_client_data_u.domainDefineRequest.xml);
|
||||||
if (!vm) {
|
if (!dom) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_DOMAIN_DEFINE;
|
out->type = QEMUD_SERVER_PKT_DOMAIN_DEFINE;
|
||||||
memcpy(out->qemud_packet_server_data_u.domainDefineReply.uuid, vm->def->uuid, QEMUD_UUID_RAW_LEN);
|
memcpy(out->qemud_packet_server_data_u.domainDefineReply.uuid, dom->uuid, QEMUD_UUID_RAW_LEN);
|
||||||
strncpy(out->qemud_packet_server_data_u.domainDefineReply.name, vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
strncpy(out->qemud_packet_server_data_u.domainDefineReply.name, dom->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
out->qemud_packet_server_data_u.domainDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.domainDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchDomainUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret = qemudDomainUndefine(qemu_driver, in->qemud_packet_client_data_u.domainUndefineRequest.uuid);
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainUndefineRequest.uuid);
|
||||||
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ret = qemudDomainUndefine(dom);
|
||||||
|
free(dom);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -382,7 +459,7 @@ static int qemudDispatchDomainUndefine(struct qemud_packet_client_data *in, stru
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNumNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
int nnetworks = qemudNumNetworks(qemu_driver);
|
int nnetworks = qemudNumNetworks(&conn);
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -400,13 +477,15 @@ static int qemudDispatchListNetworks(struct qemud_packet_client_data *in ATTRIBU
|
|||||||
if (!(names = malloc(sizeof(char *)*QEMUD_MAX_NUM_NETWORKS)))
|
if (!(names = malloc(sizeof(char *)*QEMUD_MAX_NUM_NETWORKS)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0 ; i < QEMUD_MAX_NUM_NETWORKS ; i++) {
|
int nnetworks = qemudListNetworks(&conn,
|
||||||
names[i] = &out->qemud_packet_server_data_u.listNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
|
|
||||||
}
|
|
||||||
|
|
||||||
int nnetworks = qemudListNetworks(qemu_driver,
|
|
||||||
names,
|
names,
|
||||||
QEMUD_MAX_NUM_NETWORKS);
|
QEMUD_MAX_NUM_NETWORKS);
|
||||||
|
for (i = 0 ; i < nnetworks ; i++) {
|
||||||
|
strncpy(&out->qemud_packet_server_data_u.listNetworksReply.networks[i*QEMUD_MAX_NAME_LEN],
|
||||||
|
names[i],
|
||||||
|
QEMUD_MAX_NAME_LEN);
|
||||||
|
free(names[i]);
|
||||||
|
}
|
||||||
free(names);
|
free(names);
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
@ -419,7 +498,7 @@ static int qemudDispatchListNetworks(struct qemud_packet_client_data *in ATTRIBU
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNumDefinedNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNumDefinedNetworks(struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) {
|
||||||
int nnetworks = qemudNumDefinedNetworks(qemu_driver);
|
int nnetworks = qemudNumDefinedNetworks(&conn);
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -437,13 +516,16 @@ static int qemudDispatchListDefinedNetworks(struct qemud_packet_client_data *in
|
|||||||
if (!(names = malloc(sizeof(char *)*QEMUD_MAX_NUM_NETWORKS)))
|
if (!(names = malloc(sizeof(char *)*QEMUD_MAX_NUM_NETWORKS)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0 ; i < QEMUD_MAX_NUM_NETWORKS ; i++) {
|
int nnetworks = qemudListDefinedNetworks(&conn,
|
||||||
names[i] = &out->qemud_packet_server_data_u.listDefinedNetworksReply.networks[i*QEMUD_MAX_NAME_LEN];
|
|
||||||
}
|
|
||||||
|
|
||||||
int nnetworks = qemudListDefinedNetworks(qemu_driver,
|
|
||||||
names,
|
names,
|
||||||
QEMUD_MAX_NUM_NETWORKS);
|
QEMUD_MAX_NUM_NETWORKS);
|
||||||
|
|
||||||
|
for (i = 0 ; i < nnetworks ; i++) {
|
||||||
|
strncpy(&out->qemud_packet_server_data_u.listDefinedNetworksReply.networks[i*QEMUD_MAX_NAME_LEN],
|
||||||
|
names[i],
|
||||||
|
QEMUD_MAX_NAME_LEN);
|
||||||
|
free(names[i]);
|
||||||
|
}
|
||||||
free(names);
|
free(names);
|
||||||
if (nnetworks < 0) {
|
if (nnetworks < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
@ -485,15 +567,16 @@ static int qemudDispatchNetworkLookupByUUID(struct qemud_packet_client_data *in,
|
|||||||
static int qemudDispatchNetworkCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkCreate(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
in->qemud_packet_client_data_u.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_network *network = qemudNetworkCreate(qemu_driver, in->qemud_packet_client_data_u.networkCreateRequest.xml);
|
virNetworkPtr net = qemudNetworkCreate(&conn, in->qemud_packet_client_data_u.networkCreateRequest.xml);
|
||||||
if (!network) {
|
if (!net) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_CREATE;
|
out->type = QEMUD_SERVER_PKT_NETWORK_CREATE;
|
||||||
memcpy(out->qemud_packet_server_data_u.networkCreateReply.uuid, network->def->uuid, QEMUD_UUID_RAW_LEN);
|
memcpy(out->qemud_packet_server_data_u.networkCreateReply.uuid, net->uuid, QEMUD_UUID_RAW_LEN);
|
||||||
strncpy(out->qemud_packet_server_data_u.networkCreateReply.name, network->def->name, QEMUD_MAX_NAME_LEN-1);
|
strncpy(out->qemud_packet_server_data_u.networkCreateReply.name, net->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
out->qemud_packet_server_data_u.networkCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.networkCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
free(net);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -501,21 +584,30 @@ static int qemudDispatchNetworkCreate(struct qemud_packet_client_data *in, struc
|
|||||||
static int qemudDispatchNetworkDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkDefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
in->qemud_packet_client_data_u.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
in->qemud_packet_client_data_u.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] ='\0';
|
||||||
|
|
||||||
struct qemud_network *network = qemudNetworkDefine(qemu_driver, in->qemud_packet_client_data_u.networkDefineRequest.xml);
|
virNetworkPtr net = qemudNetworkDefine(&conn, in->qemud_packet_client_data_u.networkDefineRequest.xml);
|
||||||
if (!network) {
|
if (!net) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_DEFINE;
|
out->type = QEMUD_SERVER_PKT_NETWORK_DEFINE;
|
||||||
memcpy(out->qemud_packet_server_data_u.networkDefineReply.uuid, network->def->uuid, QEMUD_UUID_RAW_LEN);
|
memcpy(out->qemud_packet_server_data_u.networkDefineReply.uuid, net->uuid, QEMUD_UUID_RAW_LEN);
|
||||||
strncpy(out->qemud_packet_server_data_u.networkDefineReply.name, network->def->name, QEMUD_MAX_NAME_LEN-1);
|
strncpy(out->qemud_packet_server_data_u.networkDefineReply.name, net->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
out->qemud_packet_server_data_u.networkDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
out->qemud_packet_server_data_u.networkDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
free(net);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkUndefine(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret = qemudNetworkUndefine(qemu_driver, in->qemud_packet_client_data_u.networkUndefineRequest.uuid);
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkUndefineRequest.uuid);
|
||||||
|
int ret;
|
||||||
|
if (!net) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudNetworkUndefine(net);
|
||||||
|
free(net);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -526,9 +618,16 @@ static int qemudDispatchNetworkUndefine(struct qemud_packet_client_data *in, str
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkStart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
struct qemud_network *network;
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkStartRequest.uuid);
|
||||||
|
int ret;
|
||||||
|
if (!net) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(network = qemudNetworkStart(qemu_driver, in->qemud_packet_client_data_u.networkStartRequest.uuid))) {
|
ret = qemudNetworkStart(net);
|
||||||
|
free(net);
|
||||||
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -538,7 +637,16 @@ static int qemudDispatchNetworkStart(struct qemud_packet_client_data *in, struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkDestroy(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
if (qemudNetworkDestroy(qemu_driver, in->qemud_packet_client_data_u.networkDestroyRequest.uuid) < 0) {
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkDestroyRequest.uuid);
|
||||||
|
int ret;
|
||||||
|
if (!net) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudNetworkDestroy(net);
|
||||||
|
free(net);
|
||||||
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -548,41 +656,64 @@ static int qemudDispatchNetworkDestroy(struct qemud_packet_client_data *in, stru
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkDumpXML(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret = qemudNetworkDumpXML(qemu_driver,
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid);
|
||||||
in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
|
char *ret;
|
||||||
out->qemud_packet_server_data_u.networkDumpXMLReply.xml, QEMUD_MAX_XML_LEN);
|
if (!net) {
|
||||||
if (ret < 0) {
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudNetworkDumpXML(net, 0);
|
||||||
|
free(net);
|
||||||
|
if (!ret) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_DUMP_XML;
|
out->type = QEMUD_SERVER_PKT_NETWORK_DUMP_XML;
|
||||||
|
strncpy(out->qemud_packet_server_data_u.networkDumpXMLReply.xml, ret, QEMUD_MAX_XML_LEN-1);
|
||||||
|
out->qemud_packet_server_data_u.networkDumpXMLReply.xml[QEMUD_MAX_XML_LEN-1] = '\0';
|
||||||
|
free(ret);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkGetBridgeName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
static int qemudDispatchNetworkGetBridgeName(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
int ret = qemudNetworkGetBridgeName(qemu_driver,
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid);
|
||||||
in->qemud_packet_client_data_u.networkDumpXMLRequest.uuid,
|
char *ret;
|
||||||
out->qemud_packet_server_data_u.networkGetBridgeNameReply.ifname, QEMUD_MAX_IFNAME_LEN);
|
if (!net) {
|
||||||
if (ret < 0) {
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemudNetworkGetBridgeName(net);
|
||||||
|
free(net);
|
||||||
|
if (!ret) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
out->type = QEMUD_SERVER_PKT_NETWORK_GET_BRIDGE_NAME;
|
out->type = QEMUD_SERVER_PKT_NETWORK_GET_BRIDGE_NAME;
|
||||||
|
strncpy(out->qemud_packet_server_data_u.networkGetBridgeNameReply.ifname, ret, QEMUD_MAX_IFNAME_LEN-1);
|
||||||
|
out->qemud_packet_server_data_u.networkGetBridgeNameReply.ifname[QEMUD_MAX_IFNAME_LEN-1] = '\0';
|
||||||
|
free(ret);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
static int qemudDispatchDomainGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
{
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid);
|
||||||
int ret;
|
int ret;
|
||||||
int autostart;
|
int autostart;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
autostart = 0;
|
autostart = 0;
|
||||||
|
|
||||||
ret = qemudDomainGetAutostart(qemu_driver,
|
ret = qemudDomainGetAutostart(dom,
|
||||||
in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
|
|
||||||
&autostart);
|
&autostart);
|
||||||
|
free(dom);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -593,13 +724,18 @@ static int qemudDispatchDomainGetAutostart(struct qemud_packet_client_data *in,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchDomainSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
static int qemudDispatchDomainSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
{
|
virDomainPtr dom = qemudDomainLookupByUUID(&conn, in->qemud_packet_client_data_u.domainSetAutostartRequest.uuid);
|
||||||
int ret;
|
int ret;
|
||||||
|
if (!dom) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ret = qemudDomainSetAutostart(qemu_driver,
|
ret = qemudDomainSetAutostart(dom,
|
||||||
in->qemud_packet_client_data_u.domainGetAutostartRequest.uuid,
|
|
||||||
in->qemud_packet_client_data_u.domainSetAutostartRequest.autostart);
|
in->qemud_packet_client_data_u.domainSetAutostartRequest.autostart);
|
||||||
|
free(dom);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -609,16 +745,20 @@ static int qemudDispatchDomainSetAutostart(struct qemud_packet_client_data *in,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
static int qemudDispatchNetworkGetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
{
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid);
|
||||||
int ret;
|
int ret;
|
||||||
int autostart;
|
int autostart;
|
||||||
|
if (!net) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
autostart = 0;
|
autostart = 0;
|
||||||
|
|
||||||
ret = qemudNetworkGetAutostart(qemu_driver,
|
ret = qemudNetworkGetAutostart(net,
|
||||||
in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
|
|
||||||
&autostart);
|
&autostart);
|
||||||
|
free(net);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -629,13 +769,17 @@ static int qemudDispatchNetworkGetAutostart(struct qemud_packet_client_data *in,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDispatchNetworkSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out)
|
static int qemudDispatchNetworkSetAutostart(struct qemud_packet_client_data *in, struct qemud_packet_server_data *out) {
|
||||||
{
|
virNetworkPtr net = qemudNetworkLookupByUUID(&conn, in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid);
|
||||||
int ret;
|
int ret;
|
||||||
|
if (!net) {
|
||||||
|
if (qemudDispatchFailure(out) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
ret = qemudNetworkSetAutostart(qemu_driver,
|
ret = qemudNetworkSetAutostart(net,
|
||||||
in->qemud_packet_client_data_u.networkGetAutostartRequest.uuid,
|
|
||||||
in->qemud_packet_client_data_u.networkSetAutostartRequest.autostart);
|
in->qemud_packet_client_data_u.networkSetAutostartRequest.autostart);
|
||||||
|
free(net);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (qemudDispatchFailure(out) < 0)
|
if (qemudDispatchFailure(out) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -750,7 +894,12 @@ int qemudDispatch(struct qemud_server *server ATTRIBUTE_UNUSED,
|
|||||||
qemudDebug("> Dispatching request type %d, readonly ? %d",
|
qemudDebug("> Dispatching request type %d, readonly ? %d",
|
||||||
in->type, client->readonly);
|
in->type, client->readonly);
|
||||||
|
|
||||||
|
if (!conn.magic) {
|
||||||
|
qemudOpen(&conn, "qemu:///session", 0);
|
||||||
|
conn.magic = 1;
|
||||||
|
}
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
virConnResetLastError(&conn);
|
||||||
|
|
||||||
memset(out, 0, sizeof(*out));
|
memset(out, 0, sizeof(*out));
|
||||||
|
|
||||||
|
688
qemud/driver.c
688
qemud/driver.c
File diff suppressed because it is too large
Load Diff
133
qemud/driver.h
133
qemud/driver.h
@ -26,6 +26,7 @@
|
|||||||
#define QEMUD_DRIVER_H
|
#define QEMUD_DRIVER_H
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "../src/internal.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
int qemudStartVMDaemon(struct qemud_driver *driver,
|
int qemudStartVMDaemon(struct qemud_driver *driver,
|
||||||
@ -44,96 +45,82 @@ int qemudStartup(void);
|
|||||||
void qemudReload(void);
|
void qemudReload(void);
|
||||||
void qemudShutdown(void);
|
void qemudShutdown(void);
|
||||||
|
|
||||||
int qemudGetNodeInfo(unsigned int *memory,
|
|
||||||
char *cpuModel, int cpuModelLength,
|
|
||||||
unsigned int *cpus, unsigned int *mhz,
|
|
||||||
unsigned int *nodes, unsigned int *sockets,
|
|
||||||
unsigned int *cores, unsigned int *threads);
|
|
||||||
|
|
||||||
char *qemudGetCapabilities(struct qemud_driver *driver);
|
virDrvOpenStatus qemudOpen(virConnectPtr conn,
|
||||||
int qemudMonitorCommand(struct qemud_driver *driver,
|
const char *name,
|
||||||
struct qemud_vm *vm,
|
int flags);
|
||||||
const char *cmd,
|
|
||||||
char **reply);
|
|
||||||
|
|
||||||
int qemudGetVersion(struct qemud_driver *driver);
|
int qemudGetNodeInfo(virConnectPtr conn,
|
||||||
int qemudListDomains(struct qemud_driver *driver,
|
virNodeInfoPtr info);
|
||||||
|
|
||||||
|
char *qemudGetCapabilities(virConnectPtr conn);
|
||||||
|
|
||||||
|
virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
|
||||||
|
int id);
|
||||||
|
virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
|
||||||
|
const unsigned char *uuid);
|
||||||
|
virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
int qemudGetVersion(virConnectPtr conn, unsigned long *version);
|
||||||
|
int qemudListDomains(virConnectPtr conn,
|
||||||
int *ids,
|
int *ids,
|
||||||
int nids);
|
int nids);
|
||||||
int qemudNumDomains(struct qemud_driver *driver);
|
int qemudNumDomains(virConnectPtr conn);
|
||||||
struct qemud_vm *qemudDomainCreate(struct qemud_driver *driver,
|
virDomainPtr qemudDomainCreate(virConnectPtr conn,
|
||||||
const char *xml);
|
const char *xml,
|
||||||
int qemudDomainSuspend(struct qemud_driver *driver,
|
unsigned int flags);
|
||||||
int id);
|
int qemudDomainSuspend(virDomainPtr dom);
|
||||||
int qemudDomainResume(struct qemud_driver *driver,
|
int qemudDomainResume(virDomainPtr dom);
|
||||||
int id);
|
int qemudDomainDestroy(virDomainPtr dom);
|
||||||
int qemudDomainDestroy(struct qemud_driver *driver,
|
int qemudDomainGetInfo(virDomainPtr dom,
|
||||||
int id);
|
virDomainInfoPtr info);
|
||||||
int qemudDomainGetInfo(struct qemud_driver *driver,
|
int qemudDomainSave(virDomainPtr dom,
|
||||||
const unsigned char *uuid,
|
|
||||||
int *runstate,
|
|
||||||
unsigned long long *cputime,
|
|
||||||
unsigned long *maxmem,
|
|
||||||
unsigned long *memory,
|
|
||||||
unsigned int *nrVirtCpu);
|
|
||||||
int qemudDomainSave(struct qemud_driver *driver,
|
|
||||||
int id,
|
|
||||||
const char *path);
|
const char *path);
|
||||||
int qemudDomainRestore(struct qemud_driver *driver,
|
int qemudDomainRestore(virConnectPtr conn,
|
||||||
const char *path);
|
const char *path);
|
||||||
int qemudDomainDumpXML(struct qemud_driver *driver,
|
char *qemudDomainDumpXML(virDomainPtr dom,
|
||||||
const unsigned char *uuid,
|
int flags);
|
||||||
char *xml,
|
int qemudListDefinedDomains(virConnectPtr conn,
|
||||||
int xmllen);
|
char **const names,
|
||||||
int qemudListDefinedDomains(struct qemud_driver *driver,
|
|
||||||
char *const*names,
|
|
||||||
int nnames);
|
int nnames);
|
||||||
int qemudNumDefinedDomains(struct qemud_driver *driver);
|
int qemudNumDefinedDomains(virConnectPtr conn);
|
||||||
struct qemud_vm *qemudDomainStart(struct qemud_driver *driver,
|
int qemudDomainStart(virDomainPtr dom);
|
||||||
const unsigned char *uuid);
|
virDomainPtr qemudDomainDefine(virConnectPtr conn,
|
||||||
struct qemud_vm *qemudDomainDefine(struct qemud_driver *driver,
|
|
||||||
const char *xml);
|
const char *xml);
|
||||||
int qemudDomainUndefine(struct qemud_driver *driver,
|
int qemudDomainUndefine(virDomainPtr dom);
|
||||||
const unsigned char *uuid);
|
int qemudDomainGetAutostart(virDomainPtr dom,
|
||||||
int qemudDomainGetAutostart(struct qemud_driver *driver,
|
|
||||||
const unsigned char *uuid,
|
|
||||||
int *autostart);
|
int *autostart);
|
||||||
int qemudDomainSetAutostart(struct qemud_driver *driver,
|
int qemudDomainSetAutostart(virDomainPtr dom,
|
||||||
const unsigned char *uuid,
|
|
||||||
int autostart);
|
int autostart);
|
||||||
|
|
||||||
|
|
||||||
int qemudNumNetworks(struct qemud_driver *driver);
|
virNetworkPtr qemudNetworkLookupByUUID(virConnectPtr conn,
|
||||||
int qemudListNetworks(struct qemud_driver *driver,
|
const unsigned char *uuid);
|
||||||
char *const*names,
|
virNetworkPtr qemudNetworkLookupByName(virConnectPtr conn,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
int qemudNumNetworks(virConnectPtr conn);
|
||||||
|
int qemudListNetworks(virConnectPtr conn,
|
||||||
|
char **const names,
|
||||||
int nnames);
|
int nnames);
|
||||||
int qemudNumDefinedNetworks(struct qemud_driver *driver);
|
int qemudNumDefinedNetworks(virConnectPtr conn);
|
||||||
int qemudListDefinedNetworks(struct qemud_driver *driver,
|
int qemudListDefinedNetworks(virConnectPtr conn,
|
||||||
char *const*names,
|
char **const names,
|
||||||
int nnames);
|
int nnames);
|
||||||
struct qemud_network *qemudNetworkCreate(struct qemud_driver *driver,
|
virNetworkPtr qemudNetworkCreate(virConnectPtr conn,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
struct qemud_network *qemudNetworkDefine(struct qemud_driver *driver,
|
virNetworkPtr qemudNetworkDefine(virConnectPtr conn,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
struct qemud_network *qemudNetworkStart(struct qemud_driver *driver,
|
int qemudNetworkStart(virNetworkPtr net);
|
||||||
const unsigned char *uuid);
|
int qemudNetworkUndefine(virNetworkPtr net);
|
||||||
int qemudNetworkUndefine(struct qemud_driver *driver,
|
int qemudNetworkDestroy(virNetworkPtr net);
|
||||||
const unsigned char *uuid);
|
char *qemudNetworkDumpXML(virNetworkPtr net,
|
||||||
int qemudNetworkDestroy(struct qemud_driver *driver,
|
int flags);
|
||||||
const unsigned char *uuid);
|
char *qemudNetworkGetBridgeName(virNetworkPtr net);
|
||||||
int qemudNetworkDumpXML(struct qemud_driver *driver,
|
int qemudNetworkGetAutostart(virNetworkPtr net,
|
||||||
const unsigned char *uuid,
|
|
||||||
char *xml,
|
|
||||||
int xmllen);
|
|
||||||
int qemudNetworkGetBridgeName(struct qemud_driver *driver,
|
|
||||||
const unsigned char *uuid,
|
|
||||||
char *ifname,
|
|
||||||
int ifnamelen);
|
|
||||||
int qemudNetworkGetAutostart(struct qemud_driver *driver,
|
|
||||||
const unsigned char *uuid,
|
|
||||||
int *autostart);
|
int *autostart);
|
||||||
int qemudNetworkSetAutostart(struct qemud_driver *driver,
|
int qemudNetworkSetAutostart(virNetworkPtr net,
|
||||||
const unsigned char *uuid,
|
|
||||||
int autostart);
|
int autostart);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user