Index: src/Makefile.am =================================================================== RCS file: /data/cvs/libvirt/src/Makefile.am,v retrieving revision 1.36 diff -u -p -u -p -r1.36 Makefile.am --- src/Makefile.am 15 Mar 2007 07:43:16 -0000 1.36 +++ src/Makefile.am 22 Mar 2007 19:47:12 -0000 @@ -30,7 +30,8 @@ libvirt_la_SOURCES = \ proxy_internal.c proxy_internal.h \ conf.c conf.h \ xm_internal.c xm_internal.h \ - qemu_internal.c qemu_internal.h + qemu_internal.c qemu_internal.h \ + protocol.c protocol.h bin_PROGRAMS = virsh @@ -40,6 +41,14 @@ virsh_DEPENDENCIES = $(DEPS) virsh_LDADD = $(LDADDS) $(VIRSH_LIBS) virsh_CFLAGS = $(COVERAGE_CFLAGS) +protocol.c: ../qemud/protocol.x + rm -f $@ + rpcgen -c -o $@ $< + +protocol.h: ../qemud/protocol.x + rm -f $@ + rpcgen -h -o $@ $< + # # target to ease building test programs # Index: src/internal.h =================================================================== RCS file: /data/cvs/libvirt/src/internal.h,v retrieving revision 1.36 diff -u -p -u -p -r1.36 internal.h --- src/internal.h 19 Mar 2007 14:18:05 -0000 1.36 +++ src/internal.h 22 Mar 2007 19:47:12 -0000 @@ -136,6 +136,8 @@ struct _virConnect { struct sockaddr_in addr_in; /* the inet address */ int qemud_fd; /* connection to qemud */ + unsigned int qemud_serial_out; + unsigned int qemud_serial_in; /* error stuff */ virError err; /* the last error */ Index: src/qemu_internal.c =================================================================== RCS file: /data/cvs/libvirt/src/qemu_internal.c,v retrieving revision 1.19 diff -u -p -u -p -r1.19 qemu_internal.c --- src/qemu_internal.c 15 Mar 2007 18:23:00 -0000 1.19 +++ src/qemu_internal.c 22 Mar 2007 19:47:12 -0000 @@ -66,28 +66,6 @@ qemuError(virConnectPtr con, errmsg, info, NULL, 0, 0, errmsg, info, 0); } -static void qemuPacketError(virConnectPtr con, - virDomainPtr dom, - struct qemud_packet *pkt) { - if (!pkt) { - qemuError(con, dom, VIR_ERR_INTERNAL_ERROR, "Malformed data packet"); - return; - } - if (pkt->header.type == QEMUD_PKT_FAILURE) { - /* Paranoia in case remote side didn't terminate it */ - if (pkt->data.failureReply.message[0]) - pkt->data.failureReply.message[QEMUD_MAX_ERROR_LEN-1] = '\0'; - - qemuError(con, - dom, - pkt->data.failureReply.code, - pkt->data.failureReply.message[0] ? - pkt->data.failureReply.message : NULL); - } else { - qemuError(con, dom, VIR_ERR_INTERNAL_ERROR, "Incorrect reply type"); - } -} - /** * qemuFindServerPath: @@ -251,76 +229,135 @@ qemuOpenClientUNIX(virConnectPtr conn, c } +static int qemudXdrWrite(virConnectPtr conn, char *buffer, int length) { + int done = 0; + + while (done < length) { + int ret = write(conn->qemud_fd, buffer+done, length-done); + if (ret <= 0) + return -1; + done += ret; + } + return done; +} + + +static int qemudXdrRead(virConnectPtr conn, char *buffer, int length) { + int done = 0; + + while (done < length) { + int ret = read(conn->qemud_fd, buffer+done, length-done); + if (ret <= 0) + return -1; + done += ret; + } + return done; +} + + + /* Takes a single request packet, does a blocking send on it. * then blocks until the complete reply has come back, or * connection closes. */ static int qemuProcessRequest(virConnectPtr conn, - virDomainPtr dom, - struct qemud_packet *req, - struct qemud_packet *reply) { - char *out = (char *)req; - int outDone = 0; - int outLeft = sizeof(struct qemud_packet_header) + req->header.dataSize; - char *in = (char *)reply; - int inGot = 0; - int inLeft = sizeof(struct qemud_packet_header); - - /* printf("Send request %d\n", req->header.type); */ - - /* Block sending entire outgoing packet */ - while (outLeft) { - int got = write(conn->qemud_fd, out+outDone, outLeft); - if (got < 0) { - return -1; - } - outDone += got; - outLeft -= got; + virDomainPtr dom, + qemud_packet_client *req, + qemud_packet_server *reply) { + XDR x; + char buffer[QEMUD_PKT_PACKET_XDR_LEN]; + qemud_packet_header h; + + req->serial = ++conn->qemud_serial_out; + + /* Encode the payload first, so we can work out the length */ + xdrmem_create(&x, buffer+QEMUD_PKT_HEADER_XDR_LEN, + QEMUD_PKT_PAYLOAD_XDR_LEN, XDR_ENCODE); + + if (!xdr_qemud_packet_client(&x, req)) { + fprintf(stderr, "Cannot encode client payload"); + return -1; } + printf("Client payload %d %d\n", req->data.type, xdr_getpos(&x)); + /* Now onto the header */ + h.magic = QEMUD_PKT_HEADER_MAGIC; + h.length = xdr_getpos(&x); - /* Block waiting for header to come back */ - while (inLeft) { - int done = read(conn->qemud_fd, in+inGot, inLeft); - if (done <= 0) { - return -1; - } - inGot += done; - inLeft -= done; + xdrmem_create(&x, buffer, QEMUD_PKT_HEADER_XDR_LEN, XDR_ENCODE); + + if (!xdr_qemud_packet_header(&x, &h)) { + fprintf(stderr, "Cannot encode client header"); + return -1; } - /* Validate header isn't bogus (bigger than - maximum defined packet size) */ - if (reply->header.dataSize > sizeof(union qemud_packet_data)) { - /* - printf("Got type %ds body %d (max %ld)\n", - reply->header.type, - reply->header.dataSize, - sizeof(union qemud_packet_data)); - printf("%ld == %ld + %ld\n", - sizeof(struct qemud_packet), - sizeof(struct qemud_packet_header), - sizeof(union qemud_packet_data)); - */ - qemuPacketError(conn, dom, NULL); + if (qemudXdrWrite(conn, buffer, QEMUD_PKT_HEADER_XDR_LEN + h.length) < 0) { + fprintf(stderr, "Cannot write client packet"); return -1; } - /* Now block reading in body */ - inLeft = reply->header.dataSize; - while (inLeft) { - int done = read(conn->qemud_fd, in+inGot, inLeft); - if (done <= 0) { - return -1; - } - inGot += done; - inLeft -= done; + if (qemudXdrRead(conn, buffer, QEMUD_PKT_HEADER_XDR_LEN) < 0) { + fprintf(stderr, "Cannot read server header"); + return -1; + } + + xdrmem_create(&x, buffer, QEMUD_PKT_HEADER_XDR_LEN, XDR_DECODE); + + if (!xdr_qemud_packet_header(&x, &h)) { + fprintf(stderr, "Cannot decode server header"); + return -1; } - if (reply->header.type != req->header.type) { - qemuPacketError(conn, dom, reply); + if (h.magic != QEMUD_PKT_HEADER_MAGIC) { + fprintf(stderr, "Server header magic %d does not match %d", + h.magic, QEMUD_PKT_HEADER_MAGIC); return -1; } + if (h.length > QEMUD_PKT_PAYLOAD_XDR_LEN) { + fprintf(stderr, "Server payload length %d is longer than max %d", + h.length, QEMUD_PKT_PAYLOAD_XDR_LEN); + return -1; + } + + printf("Server payload %d\n", h.length); + if (qemudXdrRead(conn, buffer, h.length) < 0) { + fprintf(stderr, "Cannot read server payload"); + return -1; + } + + xdrmem_create(&x, buffer, h.length, XDR_DECODE); + + if (!xdr_qemud_packet_server(&x, reply)) { + fprintf(stderr, "Cannot decode server payload"); + return -1; + } + + if (reply->serial != ++conn->qemud_serial_in) { + fprintf(stderr, "Server serial %d did not match expected %d", + reply->serial, conn->qemud_serial_in); + return -1; + } + if (reply->inReplyTo != req->serial) { + fprintf(stderr, "Server inReplyTo %d did not match expected %d", + reply->inReplyTo, conn->qemud_serial_out); + return -1; + } + + if (reply->data.type == QEMUD_SERVER_PKT_FAILURE) { + /* Paranoia in case remote side didn't terminate it */ + if (reply->data.qemud_packet_server_data_u.failureReply.message[0]) + reply->data.qemud_packet_server_data_u.failureReply.message[QEMUD_MAX_ERROR_LEN-1] = '\0'; + + qemuError(conn, + dom, + reply->data.qemud_packet_server_data_u.failureReply.code, + reply->data.qemud_packet_server_data_u.failureReply.message[0] ? + reply->data.qemud_packet_server_data_u.failureReply.message : NULL); + return -1; + } + + /* XXX validate type is what we expect */ + return 0; } @@ -415,39 +452,39 @@ static int qemuClose (virConnectPtr con static int qemuGetVersion(virConnectPtr conn, unsigned long *hvVer) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_GET_VERSION; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_GET_VERSION; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - *hvVer = reply.data.getVersionReply.version; + *hvVer = reply.data.qemud_packet_server_data_u.getVersionReply.versionNum; return 0; } static int qemuNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_GET_NODEINFO; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_GET_NODEINFO; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - info->cores = reply.data.getNodeInfoReply.cores; - info->threads = reply.data.getNodeInfoReply.threads; - info->sockets = reply.data.getNodeInfoReply.sockets; - info->nodes = reply.data.getNodeInfoReply.nodes; - strncpy(info->model, reply.data.getNodeInfoReply.model, sizeof(info->model)); - info->mhz = reply.data.getNodeInfoReply.mhz; - info->cpus = reply.data.getNodeInfoReply.cpus; - info->memory = reply.data.getNodeInfoReply.memory; + info->cores = reply.data.qemud_packet_server_data_u.getNodeInfoReply.cores; + info->threads = reply.data.qemud_packet_server_data_u.getNodeInfoReply.threads; + info->sockets = reply.data.qemud_packet_server_data_u.getNodeInfoReply.sockets; + info->nodes = reply.data.qemud_packet_server_data_u.getNodeInfoReply.nodes; + strncpy(info->model, reply.data.qemud_packet_server_data_u.getNodeInfoReply.model, sizeof(info->model)); + info->mhz = reply.data.qemud_packet_server_data_u.getNodeInfoReply.mhz; + info->cpus = reply.data.qemud_packet_server_data_u.getNodeInfoReply.cpus; + info->memory = reply.data.qemud_packet_server_data_u.getNodeInfoReply.memory; return 0; } @@ -455,22 +492,22 @@ static int qemuNodeGetInfo(virConnectPtr static char * qemuGetCapabilities (virConnectPtr conn) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; char *xml; /* Punt the request across to the daemon, because the daemon * has tables describing available architectures. */ - req.header.type = QEMUD_PKT_GET_CAPABILITIES; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_GET_CAPABILITIES; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.getCapabilitiesReply.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.getCapabilitiesReply.xml[QEMUD_MAX_XML_LEN-1] = '\0'; - xml = strdup (reply.data.getCapabilitiesReply.xml); + xml = strdup (reply.data.qemud_packet_server_data_u.getCapabilitiesReply.xml); if (!xml) { qemuError (conn, NULL, VIR_ERR_NO_MEMORY, NULL); return NULL; @@ -480,38 +517,38 @@ qemuGetCapabilities (virConnectPtr conn) } static int qemuNumOfDomains(virConnectPtr conn) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NUM_DOMAINS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_NUM_DOMAINS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - return reply.data.numDomainsReply.numDomains; + return reply.data.qemud_packet_server_data_u.numDomainsReply.numDomains; } static int qemuListDomains(virConnectPtr conn, int *ids, int maxids) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; int i, nDomains; - req.header.type = QEMUD_PKT_LIST_DOMAINS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_LIST_DOMAINS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - nDomains = reply.data.listDomainsReply.numDomains; + nDomains = reply.data.qemud_packet_server_data_u.listDomainsReply.numDomains; if (nDomains > maxids) nDomains = maxids; for (i = 0 ; i < nDomains ; i++) { - ids[i] = reply.data.listDomainsReply.domains[i]; + ids[i] = reply.data.qemud_packet_server_data_u.listDomainsReply.domains[i]; } return nDomains; @@ -521,7 +558,8 @@ static int qemuListDomains(virConnectPtr static virDomainPtr qemuDomainCreateLinux(virConnectPtr conn, const char *xmlDesc, unsigned int flags ATTRIBUTE_UNUSED) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virDomainPtr dom; int len = strlen(xmlDesc); @@ -529,45 +567,44 @@ qemuDomainCreateLinux(virConnectPtr conn return NULL; } - req.header.type = QEMUD_PKT_DOMAIN_CREATE; - req.header.dataSize = sizeof(req.data.domainCreateRequest); - strcpy(req.data.domainCreateRequest.xml, xmlDesc); - req.data.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_CREATE; + strcpy(req.data.qemud_packet_client_data_u.domainCreateRequest.xml, xmlDesc); + req.data.qemud_packet_client_data_u.domainCreateRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.domainCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.domainCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(dom = virGetDomain(conn, - reply.data.domainCreateReply.name, - reply.data.domainCreateReply.uuid))) + reply.data.qemud_packet_server_data_u.domainCreateReply.name, + reply.data.qemud_packet_server_data_u.domainCreateReply.uuid))) return NULL; - dom->id = reply.data.domainCreateReply.id; + dom->id = reply.data.qemud_packet_server_data_u.domainCreateReply.id; return dom; } static virDomainPtr qemuLookupDomainByID(virConnectPtr conn, int id) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virDomainPtr dom; - req.header.type = QEMUD_PKT_DOMAIN_LOOKUP_BY_ID; - req.header.dataSize = sizeof(req.data.domainLookupByIDRequest); - req.data.domainLookupByIDRequest.id = id; + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_LOOKUP_BY_ID; + req.data.qemud_packet_client_data_u.domainLookupByIDRequest.id = id; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.domainLookupByIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.domainLookupByIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(dom = virGetDomain(conn, - reply.data.domainLookupByIDReply.name, - reply.data.domainLookupByIDReply.uuid))) + reply.data.qemud_packet_server_data_u.domainLookupByIDReply.name, + reply.data.qemud_packet_server_data_u.domainLookupByIDReply.uuid))) return NULL; dom->id = id; @@ -577,40 +614,40 @@ static virDomainPtr qemuLookupDomainByID static virDomainPtr qemuLookupDomainByUUID(virConnectPtr conn, const unsigned char *uuid) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virDomainPtr dom; - req.header.type = QEMUD_PKT_DOMAIN_LOOKUP_BY_UUID; - req.header.dataSize = sizeof(req.data.domainLookupByUUIDRequest); - memmove(req.data.domainLookupByUUIDRequest.uuid, uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_LOOKUP_BY_UUID; + memmove(req.data.qemud_packet_client_data_u.domainLookupByUUIDRequest.uuid, uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.domainLookupByUUIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.domainLookupByUUIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(dom = virGetDomain(conn, - reply.data.domainLookupByUUIDReply.name, + reply.data.qemud_packet_server_data_u.domainLookupByUUIDReply.name, uuid))) return NULL; - dom->id = reply.data.domainLookupByUUIDReply.id; + dom->id = reply.data.qemud_packet_server_data_u.domainLookupByUUIDReply.id; return dom; } static virDomainPtr qemuLookupDomainByName(virConnectPtr conn, const char *name) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virDomainPtr dom; if (strlen(name) > (QEMUD_MAX_NAME_LEN-1)) return NULL; - req.header.type = QEMUD_PKT_DOMAIN_LOOKUP_BY_NAME; - req.header.dataSize = sizeof(req.data.domainLookupByNameRequest); - strcpy(req.data.domainLookupByNameRequest.name, name); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_LOOKUP_BY_NAME; + strcpy(req.data.qemud_packet_client_data_u.domainLookupByNameRequest.name, name); if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; @@ -618,19 +655,19 @@ static virDomainPtr qemuLookupDomainByNa if (!(dom = virGetDomain(conn, name, - reply.data.domainLookupByNameReply.uuid))) + reply.data.qemud_packet_server_data_u.domainLookupByNameReply.uuid))) return NULL; - dom->id = reply.data.domainLookupByNameReply.id; + dom->id = reply.data.qemud_packet_server_data_u.domainLookupByNameReply.id; return dom; } static int qemuDestroyDomain(virDomainPtr domain) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_DOMAIN_DESTROY; - req.header.dataSize = sizeof(req.data.domainDestroyRequest); - req.data.domainDestroyRequest.id = domain->id; + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_DESTROY; + req.data.qemud_packet_client_data_u.domainDestroyRequest.id = domain->id; if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) { return -1; @@ -644,11 +681,11 @@ static int qemuShutdownDomain(virDomainP } static int qemuResumeDomain(virDomainPtr domain ATTRIBUTE_UNUSED) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_DOMAIN_RESUME; - req.header.dataSize = sizeof(req.data.domainResumeRequest); - req.data.domainResumeRequest.id = domain->id; + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_RESUME; + req.data.qemud_packet_client_data_u.domainResumeRequest.id = domain->id; if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) { return -1; @@ -658,11 +695,11 @@ static int qemuResumeDomain(virDomainPtr } static int qemuPauseDomain(virDomainPtr domain ATTRIBUTE_UNUSED) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_DOMAIN_SUSPEND; - req.header.dataSize = sizeof(req.data.domainSuspendRequest); - req.data.domainSuspendRequest.id = domain->id; + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_SUSPEND; + req.data.qemud_packet_client_data_u.domainSuspendRequest.id = domain->id; if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) { return -1; @@ -673,18 +710,18 @@ static int qemuPauseDomain(virDomainPtr static int qemuGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_DOMAIN_GET_INFO; - req.header.dataSize = sizeof(req.data.domainGetInfoRequest); - memmove(req.data.domainGetInfoRequest.uuid, domain->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_GET_INFO; + memmove(req.data.qemud_packet_client_data_u.domainGetInfoRequest.uuid, domain->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) { return -1; } memset(info, 0, sizeof(virDomainInfo)); - switch (reply.data.domainGetInfoReply.runstate) { + switch (reply.data.qemud_packet_server_data_u.domainGetInfoReply.runstate) { case QEMUD_STATE_RUNNING: info->state = VIR_DOMAIN_RUNNING; break; @@ -700,28 +737,28 @@ static int qemuGetDomainInfo(virDomainPt default: return -1; } - info->maxMem = reply.data.domainGetInfoReply.maxmem; - info->memory = reply.data.domainGetInfoReply.memory; - info->nrVirtCpu = reply.data.domainGetInfoReply.nrVirtCpu; - info->cpuTime = reply.data.domainGetInfoReply.cpuTime; + info->maxMem = reply.data.qemud_packet_server_data_u.domainGetInfoReply.maxmem; + info->memory = reply.data.qemud_packet_server_data_u.domainGetInfoReply.memory; + info->nrVirtCpu = reply.data.qemud_packet_server_data_u.domainGetInfoReply.nrVirtCpu; + info->cpuTime = reply.data.qemud_packet_server_data_u.domainGetInfoReply.cpuTime; return 0; } static char *qemuDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_DUMP_XML; - req.header.dataSize = sizeof(req.data.domainDumpXMLRequest); - memmove(req.data.domainDumpXMLRequest.uuid, domain->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_DUMP_XML; + memmove(req.data.qemud_packet_client_data_u.domainDumpXMLRequest.uuid, domain->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(domain->conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.domainDumpXMLReply.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.domainDumpXMLReply.xml[QEMUD_MAX_XML_LEN-1] = '\0'; - return strdup(reply.data.domainDumpXMLReply.xml); + return strdup(reply.data.qemud_packet_server_data_u.domainDumpXMLReply.xml); } static int qemuSaveDomain(virDomainPtr domain ATTRIBUTE_UNUSED, const char *file ATTRIBUTE_UNUSED) { @@ -734,61 +771,62 @@ static int qemuRestoreDomain(virConnectP static int qemuNumOfDefinedDomains(virConnectPtr conn) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NUM_DEFINED_DOMAINS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_NUM_DEFINED_DOMAINS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - return reply.data.numDefinedDomainsReply.numDomains; + return reply.data.qemud_packet_server_data_u.numDefinedDomainsReply.numDomains; } static int qemuListDefinedDomains(virConnectPtr conn, char **const names, int maxnames){ - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; int i, nDomains; - req.header.type = QEMUD_PKT_LIST_DEFINED_DOMAINS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_LIST_DEFINED_DOMAINS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - nDomains = reply.data.listDefinedDomainsReply.numDomains; + nDomains = reply.data.qemud_packet_server_data_u.listDefinedDomainsReply.numDomains; if (nDomains > maxnames) nDomains = maxnames; for (i = 0 ; i < nDomains ; i++) { - reply.data.listDefinedDomainsReply.domains[i][QEMUD_MAX_NAME_LEN-1] = '\0'; - names[i] = strdup(reply.data.listDefinedDomainsReply.domains[i]); + reply.data.qemud_packet_server_data_u.listDefinedDomainsReply.domains[((i+1)*QEMUD_MAX_NAME_LEN)-1] = '\0'; + names[i] = strdup(&reply.data.qemud_packet_server_data_u.listDefinedDomainsReply.domains[i*QEMUD_MAX_NAME_LEN]); } return nDomains; } static int qemuDomainCreate(virDomainPtr dom) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_DOMAIN_START; - req.header.dataSize = sizeof(req.data.domainStartRequest); - memcpy(req.data.domainStartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_START; + memcpy(req.data.qemud_packet_client_data_u.domainStartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) { return -1; } - dom->id = reply.data.domainStartReply.id; + dom->id = reply.data.qemud_packet_server_data_u.domainStartReply.id; return 0; } static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virDomainPtr dom; int len = strlen(xml); @@ -796,20 +834,19 @@ static virDomainPtr qemuDomainDefineXML( return NULL; } - req.header.type = QEMUD_PKT_DOMAIN_DEFINE; - req.header.dataSize = sizeof(req.data.domainDefineRequest); - strcpy(req.data.domainDefineRequest.xml, xml); - req.data.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_DEFINE; + strcpy(req.data.qemud_packet_client_data_u.domainDefineRequest.xml, xml); + req.data.qemud_packet_client_data_u.domainDefineRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.domainDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.domainDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(dom = virGetDomain(conn, - reply.data.domainDefineReply.name, - reply.data.domainDefineReply.uuid))) + reply.data.qemud_packet_server_data_u.domainDefineReply.name, + reply.data.qemud_packet_server_data_u.domainDefineReply.uuid))) return NULL; dom->id = -1; @@ -817,12 +854,12 @@ static virDomainPtr qemuDomainDefineXML( } static int qemuUndefine(virDomainPtr dom) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; int ret = 0; - req.header.type = QEMUD_PKT_DOMAIN_UNDEFINE; - req.header.dataSize = sizeof(req.data.domainUndefineRequest); - memcpy(req.data.domainUndefineRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_UNDEFINE; + memcpy(req.data.qemud_packet_client_data_u.domainUndefineRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) { ret = -1; @@ -838,29 +875,29 @@ static int qemuUndefine(virDomainPtr dom static int qemuDomainGetAutostart(virDomainPtr dom, int *autostart) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server 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); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_GET_AUTOSTART; + memmove(req.data.qemud_packet_client_data_u.domainGetAutostartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) { return -1; } - *autostart = reply.data.domainGetAutostartReply.autostart; + *autostart = reply.data.qemud_packet_server_data_u.domainGetAutostartReply.autostart; return 0; } static int qemuDomainSetAutostart(virDomainPtr dom, int autostart) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server 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); + req.data.type = QEMUD_CLIENT_PKT_DOMAIN_SET_AUTOSTART; + req.data.qemud_packet_client_data_u.domainSetAutostartRequest.autostart = (autostart != 0); + memmove(req.data.qemud_packet_client_data_u.domainSetAutostartRequest.uuid, dom->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(dom->conn, NULL, &req, &reply) < 0) { return -1; @@ -895,76 +932,76 @@ static int qemuNetworkOpen(virConnectPtr } static int qemuNumOfNetworks(virConnectPtr conn) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NUM_NETWORKS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_NUM_NETWORKS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - return reply.data.numNetworksReply.numNetworks; + return reply.data.qemud_packet_server_data_u.numNetworksReply.numNetworks; } static int qemuListNetworks(virConnectPtr conn, char **const names, int maxnames) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; int i, nNetworks; - req.header.type = QEMUD_PKT_LIST_NETWORKS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_LIST_NETWORKS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - nNetworks = reply.data.listNetworksReply.numNetworks; + nNetworks = reply.data.qemud_packet_server_data_u.listNetworksReply.numNetworks; if (nNetworks > maxnames) return -1; for (i = 0 ; i < nNetworks ; i++) { - reply.data.listNetworksReply.networks[i][QEMUD_MAX_NAME_LEN-1] = '\0'; - names[i] = strdup(reply.data.listNetworksReply.networks[i]); + reply.data.qemud_packet_server_data_u.listNetworksReply.networks[((i+1)*QEMUD_MAX_NAME_LEN)-1] = '\0'; + names[i] = strdup(&reply.data.qemud_packet_server_data_u.listNetworksReply.networks[i*QEMUD_MAX_NAME_LEN]); } return nNetworks; } static int qemuNumOfDefinedNetworks(virConnectPtr conn) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NUM_DEFINED_NETWORKS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_NUM_DEFINED_NETWORKS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - return reply.data.numDefinedNetworksReply.numNetworks; + return reply.data.qemud_packet_server_data_u.numDefinedNetworksReply.numNetworks; } static int qemuListDefinedNetworks(virConnectPtr conn, char **const names, int maxnames) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; int i, nNetworks; - req.header.type = QEMUD_PKT_LIST_DEFINED_NETWORKS; - req.header.dataSize = 0; + req.data.type = QEMUD_CLIENT_PKT_LIST_DEFINED_NETWORKS; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return -1; } - nNetworks = reply.data.listDefinedNetworksReply.numNetworks; + nNetworks = reply.data.qemud_packet_server_data_u.listDefinedNetworksReply.numNetworks; if (nNetworks > maxnames) return -1; for (i = 0 ; i < nNetworks ; i++) { - reply.data.listDefinedNetworksReply.networks[i][QEMUD_MAX_NAME_LEN-1] = '\0'; - names[i] = strdup(reply.data.listDefinedNetworksReply.networks[i]); + reply.data.qemud_packet_server_data_u.listDefinedNetworksReply.networks[((i+1)*QEMUD_MAX_NAME_LEN)-1] = '\0'; + names[i] = strdup(&reply.data.qemud_packet_server_data_u.listDefinedNetworksReply.networks[i*QEMUD_MAX_NAME_LEN]); } return nNetworks; @@ -972,21 +1009,21 @@ static int qemuListDefinedNetworks(virCo static virNetworkPtr qemuNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virNetworkPtr network; - req.header.type = QEMUD_PKT_NETWORK_LOOKUP_BY_UUID; - req.header.dataSize = sizeof(req.data.networkLookupByUUIDRequest); - memmove(req.data.networkLookupByUUIDRequest.uuid, uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_LOOKUP_BY_UUID; + memmove(req.data.qemud_packet_client_data_u.networkLookupByUUIDRequest.uuid, uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.networkLookupByUUIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.networkLookupByUUIDReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(network = virGetNetwork(conn, - reply.data.networkLookupByUUIDReply.name, + reply.data.qemud_packet_server_data_u.networkLookupByUUIDReply.name, uuid))) return NULL; @@ -995,15 +1032,15 @@ static virNetworkPtr qemuNetworkLookupBy static virNetworkPtr qemuNetworkLookupByName(virConnectPtr conn, const char *name) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virNetworkPtr network; if (strlen(name) > (QEMUD_MAX_NAME_LEN-1)) return NULL; - req.header.type = QEMUD_PKT_NETWORK_LOOKUP_BY_NAME; - req.header.dataSize = sizeof(req.data.networkLookupByNameRequest); - strcpy(req.data.networkLookupByNameRequest.name, name); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_LOOKUP_BY_NAME; + strcpy(req.data.qemud_packet_client_data_u.networkLookupByNameRequest.name, name); if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; @@ -1011,7 +1048,7 @@ static virNetworkPtr qemuNetworkLookupBy if (!(network = virGetNetwork(conn, name, - reply.data.networkLookupByNameReply.uuid))) + reply.data.qemud_packet_server_data_u.networkLookupByNameReply.uuid))) return NULL; return network; @@ -1019,7 +1056,8 @@ static virNetworkPtr qemuNetworkLookupBy static virNetworkPtr qemuNetworkCreateXML(virConnectPtr conn, const char *xmlDesc) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virNetworkPtr network; int len = strlen(xmlDesc); @@ -1027,20 +1065,19 @@ static virNetworkPtr qemuNetworkCreateXM return NULL; } - req.header.type = QEMUD_PKT_NETWORK_CREATE; - req.header.dataSize = sizeof(req.data.networkCreateRequest); - strcpy(req.data.networkCreateRequest.xml, xmlDesc); - req.data.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + req.data.type = QEMUD_CLIENT_PKT_NETWORK_CREATE; + strcpy(req.data.qemud_packet_client_data_u.networkCreateRequest.xml, xmlDesc); + req.data.qemud_packet_client_data_u.networkCreateRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.networkCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.networkCreateReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(network = virGetNetwork(conn, - reply.data.networkCreateReply.name, - reply.data.networkCreateReply.uuid))) + reply.data.qemud_packet_server_data_u.networkCreateReply.name, + reply.data.qemud_packet_server_data_u.networkCreateReply.uuid))) return NULL; return network; @@ -1049,7 +1086,8 @@ static virNetworkPtr qemuNetworkCreateXM static virNetworkPtr qemuNetworkDefineXML(virConnectPtr conn, const char *xml) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; virNetworkPtr network; int len = strlen(xml); @@ -1057,32 +1095,31 @@ static virNetworkPtr qemuNetworkDefineXM return NULL; } - req.header.type = QEMUD_PKT_NETWORK_DEFINE; - req.header.dataSize = sizeof(req.data.networkDefineRequest); - strcpy(req.data.networkDefineRequest.xml, xml); - req.data.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + req.data.type = QEMUD_CLIENT_PKT_NETWORK_DEFINE; + strcpy(req.data.qemud_packet_client_data_u.networkDefineRequest.xml, xml); + req.data.qemud_packet_client_data_u.networkDefineRequest.xml[QEMUD_MAX_XML_LEN-1] = '\0'; if (qemuProcessRequest(conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.networkDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.networkDefineReply.name[QEMUD_MAX_NAME_LEN-1] = '\0'; if (!(network = virGetNetwork(conn, - reply.data.networkDefineReply.name, - reply.data.networkDefineReply.uuid))) + reply.data.qemud_packet_server_data_u.networkDefineReply.name, + reply.data.qemud_packet_server_data_u.networkDefineReply.uuid))) return NULL; return network; } static int qemuNetworkUndefine(virNetworkPtr network) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; int ret = 0; - req.header.type = QEMUD_PKT_NETWORK_UNDEFINE; - req.header.dataSize = sizeof(req.data.networkUndefineRequest); - memcpy(req.data.networkUndefineRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_UNDEFINE; + memcpy(req.data.qemud_packet_client_data_u.networkUndefineRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { ret = -1; @@ -1097,11 +1134,11 @@ static int qemuNetworkUndefine(virNetwor } static int qemuNetworkCreate(virNetworkPtr network) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NETWORK_START; - req.header.dataSize = sizeof(req.data.networkStartRequest); - memcpy(req.data.networkStartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_START; + memcpy(req.data.qemud_packet_client_data_u.networkStartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { return -1; @@ -1111,11 +1148,11 @@ static int qemuNetworkCreate(virNetworkP } static int qemuNetworkDestroy(virNetworkPtr network) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NETWORK_DESTROY; - req.header.dataSize = sizeof(req.data.networkDestroyRequest); - memcpy(req.data.networkDestroyRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_DESTROY; + memcpy(req.data.qemud_packet_client_data_u.networkDestroyRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { return -1; @@ -1125,62 +1162,62 @@ static int qemuNetworkDestroy(virNetwork } static char * qemuNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSED) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NETWORK_DUMP_XML; - req.header.dataSize = sizeof(req.data.networkDumpXMLRequest); - memmove(req.data.networkDumpXMLRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_DUMP_XML; + memmove(req.data.qemud_packet_client_data_u.networkDumpXMLRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.networkDumpXMLReply.xml[QEMUD_MAX_XML_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.networkDumpXMLReply.xml[QEMUD_MAX_XML_LEN-1] = '\0'; - return strdup(reply.data.networkDumpXMLReply.xml); + return strdup(reply.data.qemud_packet_server_data_u.networkDumpXMLReply.xml); } static char * qemuNetworkGetBridgeName(virNetworkPtr network) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server reply; - req.header.type = QEMUD_PKT_NETWORK_GET_BRIDGE_NAME; - req.header.dataSize = sizeof(req.data.networkGetBridgeNameRequest); - memmove(req.data.networkGetBridgeNameRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_GET_BRIDGE_NAME; + memmove(req.data.qemud_packet_client_data_u.networkGetBridgeNameRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { return NULL; } - reply.data.networkGetBridgeNameReply.ifname[QEMUD_MAX_IFNAME_LEN-1] = '\0'; + reply.data.qemud_packet_server_data_u.networkGetBridgeNameReply.ifname[QEMUD_MAX_IFNAME_LEN-1] = '\0'; - return strdup(reply.data.networkGetBridgeNameReply.ifname); + return strdup(reply.data.qemud_packet_server_data_u.networkGetBridgeNameReply.ifname); } static int qemuNetworkGetAutostart(virNetworkPtr network, int *autostart) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server 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); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_GET_AUTOSTART; + memmove(req.data.qemud_packet_client_data_u.networkGetAutostartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { return -1; } - *autostart = reply.data.networkGetAutostartReply.autostart; + *autostart = reply.data.qemud_packet_server_data_u.networkGetAutostartReply.autostart; return 0; } static int qemuNetworkSetAutostart(virNetworkPtr network, int autostart) { - struct qemud_packet req, reply; + qemud_packet_client req; + qemud_packet_server 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); + req.data.type = QEMUD_CLIENT_PKT_NETWORK_SET_AUTOSTART; + req.data.qemud_packet_client_data_u.networkSetAutostartRequest.autostart = (autostart != 0); + memmove(req.data.qemud_packet_client_data_u.networkSetAutostartRequest.uuid, network->uuid, QEMUD_UUID_RAW_LEN); if (qemuProcessRequest(network->conn, NULL, &req, &reply) < 0) { return -1;