diff -r 13f57e3de09e qemud/dispatch.c --- a/qemud/dispatch.c Sun Jun 17 16:30:02 2007 -0400 +++ b/qemud/dispatch.c Sun Jun 17 16:46:32 2007 -0400 @@ -28,14 +28,12 @@ #include #include #include -#include #include #include "internal.h" #include "driver.h" #include "dispatch.h" #include "conf.h" -#include "buf.h" static int qemudDispatchFailure(struct qemud_server *server ATTRIBUTE_UNUSED, @@ -63,32 +61,21 @@ static int qemudDispatchGetVersion(struc static int qemudDispatchGetNodeInfo(struct qemud_server *server, struct qemud_client *client, struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) { - struct utsname info; - - if (uname(&info) < 0) { + if (qemudGetNodeInfo(&out->qemud_packet_server_data_u.getNodeInfoReply.memory, + out->qemud_packet_server_data_u.getNodeInfoReply.model, + sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model), + &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(server, client, out) < 0) return -1; return 0; } - if (qemudGetCPUInfo(&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(server, client, out) < 0) - return -1; - return 0; - } - if (qemudGetMemInfo(&out->qemud_packet_server_data_u.getNodeInfoReply.memory) < 0) { - if (qemudDispatchFailure(server, client, out) < 0) - return -1; - return 0; - } - out->type = QEMUD_SERVER_PKT_GET_NODEINFO; - strncpy(out->qemud_packet_server_data_u.getNodeInfoReply.model, info.machine, sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model)); out->qemud_packet_server_data_u.getNodeInfoReply.model[sizeof(out->qemud_packet_server_data_u.getNodeInfoReply.model)-1] = '\0'; return 0; @@ -100,166 +87,18 @@ qemudDispatchGetCapabilities (struct qem struct qemud_packet_client_data *in ATTRIBUTE_UNUSED, struct qemud_packet_server_data *out) { - struct utsname utsname; - int i, j, r; - int have_kqemu = 0; - int have_kvm = 0; - bufferPtr xml; - int len; - - /* Really, this never fails - look at the man-page. */ - uname (&utsname); - - have_kqemu = access ("/dev/kqemu", F_OK) == 0; - have_kvm = access ("/dev/kvm", F_OK) == 0; - - /* Construct the XML. */ - xml = bufferNew (1024); - if (!xml) { - qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); - qemudDispatchFailure (server, client, out); - return 0; - } - - r = bufferVSprintf (xml, - "\ -\n\ - \n\ - \n\ - %s\n\ - \n\ - \n", - utsname.machine); - if (r == -1) { - vir_buffer_failed: - bufferFree (xml); - qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); - qemudDispatchFailure (server, client, out); - return 0; - } - - i = -1; - if (strcmp (utsname.machine, "i686") == 0) i = 0; - else if (strcmp (utsname.machine, "x86_64") == 0) i = 1; - if (i >= 0) { - /* For the default (PC-like) guest, qemudArchs[0] or [1]. */ - r = bufferVSprintf (xml, - "\ -\n\ - \n\ - hvm\n\ - \n\ - %d\n\ - /usr/bin/%s\n\ - \n", - qemudArchs[i].arch, - qemudArchs[i].wordsize, - qemudArchs[i].binary); - if (r == -1) goto vir_buffer_failed; - - for (j = 0; qemudArchs[i].machines[j]; ++j) { - r = bufferVSprintf (xml, - "\ - %s\n", - qemudArchs[i].machines[j]); - if (r == -1) goto vir_buffer_failed; - } - - if (have_kqemu) { - r = bufferAdd (xml, - "\ - \n", -1); - if (r == -1) goto vir_buffer_failed; - } - if (have_kvm) { - r = bufferAdd (xml, - "\ - \n\ - /usr/bin/qemu-kvm\n\ - \n", -1); - if (r == -1) goto vir_buffer_failed; - } - r = bufferAdd (xml, - "\ - \n\ - \n", -1); - if (r == -1) goto vir_buffer_failed; - - /* The "other" PC architecture needs emulation. */ - i = i ^ 1; - r = bufferVSprintf (xml, - "\ -\n\ - \n\ - hvm\n\ - \n\ - %d\n\ - /usr/bin/%s\n\ - \n", - qemudArchs[i].arch, - qemudArchs[i].wordsize, - qemudArchs[i].binary); - if (r == -1) goto vir_buffer_failed; - for (j = 0; qemudArchs[i].machines[j]; ++j) { - r = bufferVSprintf (xml, - "\ - %s\n", - qemudArchs[i].machines[j]); - if (r == -1) goto vir_buffer_failed; - } - r = bufferAdd (xml, - "\ - \n\ - \n", -1); - if (r == -1) goto vir_buffer_failed; - } - - /* The non-PC architectures, qemudArchs[>=2]. */ - for (i = 2; qemudArchs[i].arch; ++i) { - r = bufferVSprintf (xml, - "\ -\n\ - \n\ - hvm\n\ - \n\ - %d\n\ - /usr/bin/%s\n\ - \n", - qemudArchs[i].arch, - qemudArchs[i].wordsize, - qemudArchs[i].binary); - if (r == -1) goto vir_buffer_failed; - for (j = 0; qemudArchs[i].machines[j]; ++j) { - r = bufferVSprintf (xml, - "\ - %s\n", - qemudArchs[i].machines[j]); - if (r == -1) goto vir_buffer_failed; - } - r = bufferAdd (xml, - "\ - \n\ - \n", -1); - if (r == -1) goto vir_buffer_failed; - } - - /* Finish off. */ - r = bufferAdd (xml, - "\ -\n", -1); - if (r == -1) goto vir_buffer_failed; - - /* Copy the XML into the outgoing packet, assuming it's not too large. */ - len = strlen (xml->content); - if (len > QEMUD_MAX_XML_LEN) { - bufferFree (xml); + char *xml = qemudGetCapabilities(server); + + if (strlen(xml) > QEMUD_MAX_XML_LEN) { qemudReportError (server, VIR_ERR_XML_ERROR, NULL); qemudDispatchFailure (server, client, out); + free(xml); return 0; } + out->type = QEMUD_SERVER_PKT_GET_CAPABILITIES; - strcpy (out->qemud_packet_server_data_u.getCapabilitiesReply.xml, xml->content); - bufferFree (xml); + strcpy (out->qemud_packet_server_data_u.getCapabilitiesReply.xml, xml); + free(xml); return 0; } diff -r 13f57e3de09e qemud/driver.c --- a/qemud/driver.c Sun Jun 17 16:30:02 2007 -0400 +++ b/qemud/driver.c Sun Jun 17 16:45:46 2007 -0400 @@ -34,9 +34,11 @@ #include #include #include +#include #include +#include "buf.h" #include "internal.h" #include "driver.h" #include "conf.h" @@ -119,7 +121,8 @@ int qemudMonitorCommand(struct qemud_ser return 0; } -int qemudGetMemInfo(unsigned int *memory) { + +static int qemudGetMemInfo(unsigned int *memory) { FILE *meminfo = fopen("/proc/meminfo", "r"); char line[1024]; @@ -139,9 +142,9 @@ int qemudGetMemInfo(unsigned int *memory return 0; } -int qemudGetCPUInfo(unsigned int *cpus, unsigned int *mhz, - unsigned int *nodes, unsigned int *sockets, - unsigned int *cores, unsigned int *threads) { +static int qemudGetCPUInfo(unsigned int *cpus, unsigned int *mhz, + unsigned int *nodes, unsigned int *sockets, + unsigned int *cores, unsigned int *threads) { FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); char line[1024]; @@ -194,6 +197,179 @@ int qemudGetCPUInfo(unsigned int *cpus, return 0; } +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) { + struct utsname info; + + if (uname(&info) < 0) + return -1; + + strncpy(cpuModel, info.machine, cpuModelLength-1); + cpuModel[cpuModelLength-1] = '\0'; + + if (qemudGetMemInfo(memory) < 0) + return -1; + + if (qemudGetCPUInfo(cpus, mhz, nodes, sockets, cores, threads) < 0) + return -1; + return 0; +} + +char *qemudGetCapabilities(struct qemud_server *server) { + struct utsname utsname; + int i, j, r; + int have_kqemu = 0; + int have_kvm = 0; + bufferPtr xml; + + /* Really, this never fails - look at the man-page. */ + uname (&utsname); + + have_kqemu = access ("/dev/kqemu", F_OK) == 0; + have_kvm = access ("/dev/kvm", F_OK) == 0; + + /* Construct the XML. */ + xml = bufferNew (1024); + if (!xml) { + qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); + return NULL; + } + + r = bufferVSprintf (xml, + "\ +\n\ + \n\ + \n\ + %s\n\ + \n\ + \n", + utsname.machine); + if (r == -1) { + vir_buffer_failed: + bufferFree (xml); + qemudReportError (server, VIR_ERR_NO_MEMORY, NULL); + return NULL; + } + + i = -1; + if (strcmp (utsname.machine, "i686") == 0) i = 0; + else if (strcmp (utsname.machine, "x86_64") == 0) i = 1; + if (i >= 0) { + /* For the default (PC-like) guest, qemudArchs[0] or [1]. */ + r = bufferVSprintf (xml, + "\ +\n\ + \n\ + hvm\n\ + \n\ + %d\n\ + /usr/bin/%s\n\ + \n", + qemudArchs[i].arch, + qemudArchs[i].wordsize, + qemudArchs[i].binary); + if (r == -1) goto vir_buffer_failed; + + for (j = 0; qemudArchs[i].machines[j]; ++j) { + r = bufferVSprintf (xml, + "\ + %s\n", + qemudArchs[i].machines[j]); + if (r == -1) goto vir_buffer_failed; + } + + if (have_kqemu) { + r = bufferAdd (xml, + "\ + \n", -1); + if (r == -1) goto vir_buffer_failed; + } + if (have_kvm) { + r = bufferAdd (xml, + "\ + \n\ + /usr/bin/qemu-kvm\n\ + \n", -1); + if (r == -1) goto vir_buffer_failed; + } + r = bufferAdd (xml, + "\ + \n\ + \n", -1); + if (r == -1) goto vir_buffer_failed; + + /* The "other" PC architecture needs emulation. */ + i = i ^ 1; + r = bufferVSprintf (xml, + "\ +\n\ + \n\ + hvm\n\ + \n\ + %d\n\ + /usr/bin/%s\n\ + \n", + qemudArchs[i].arch, + qemudArchs[i].wordsize, + qemudArchs[i].binary); + if (r == -1) goto vir_buffer_failed; + for (j = 0; qemudArchs[i].machines[j]; ++j) { + r = bufferVSprintf (xml, + "\ + %s\n", + qemudArchs[i].machines[j]); + if (r == -1) goto vir_buffer_failed; + } + r = bufferAdd (xml, + "\ + \n\ + \n", -1); + if (r == -1) goto vir_buffer_failed; + } + + /* The non-PC architectures, qemudArchs[>=2]. */ + for (i = 2; qemudArchs[i].arch; ++i) { + r = bufferVSprintf (xml, + "\ +\n\ + \n\ + hvm\n\ + \n\ + %d\n\ + /usr/bin/%s\n\ + \n", + qemudArchs[i].arch, + qemudArchs[i].wordsize, + qemudArchs[i].binary); + if (r == -1) goto vir_buffer_failed; + for (j = 0; qemudArchs[i].machines[j]; ++j) { + r = bufferVSprintf (xml, + "\ + %s\n", + qemudArchs[i].machines[j]); + if (r == -1) goto vir_buffer_failed; + } + r = bufferAdd (xml, + "\ + \n\ + \n", -1); + if (r == -1) goto vir_buffer_failed; + } + + /* Finish off. */ + r = bufferAdd (xml, + "\ +\n", -1); + if (r == -1) goto vir_buffer_failed; + + return bufferContentAndFree(xml); +} + + + static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) { char proc[PATH_MAX]; FILE *pidinfo; diff -r 13f57e3de09e qemud/driver.h --- a/qemud/driver.h Sun Jun 17 16:30:02 2007 -0400 +++ b/qemud/driver.h Sun Jun 17 16:44:34 2007 -0400 @@ -31,10 +31,13 @@ void qemudReportError(struct qemud_serve int code, const char *fmt, ...) ATTRIBUTE_FORMAT(printf,3,4); -int qemudGetCPUInfo(unsigned int *cpus, unsigned int *mhz, - unsigned int *nodes, unsigned int *sockets, - unsigned int *cores, unsigned int *threads); -int qemudGetMemInfo(unsigned int *memory); +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_server *server); int qemudMonitorCommand(struct qemud_server *server, struct qemud_vm *vm, const char *cmd,