From patchwork Wed Aug 22 12:32:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 179393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B3892C0081 for ; Thu, 23 Aug 2012 05:45:27 +1000 (EST) Received: from localhost ([::1]:46472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Grl-0005dd-9L for incoming@patchwork.ozlabs.org; Wed, 22 Aug 2012 15:45:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G5S-0003Gi-MC for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4G5L-0007kT-PM for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:55:30 -0400 Received: from smtp.citrix.com ([66.165.176.89]:13432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4G5L-0007FA-Gc for qemu-devel@nongnu.org; Wed, 22 Aug 2012 14:55:23 -0400 X-IronPort-AV: E=Sophos;i="4.80,809,1344225600"; d="scan'208";a="35484811" Received: from ftlpmailmx01.citrite.net ([10.13.107.65]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 22 Aug 2012 14:55:23 -0400 Received: from meteora.cam.xci-test.com (10.80.248.22) by smtprelay.citrix.com (10.13.107.65) with Microsoft SMTP Server id 8.3.213.0; Wed, 22 Aug 2012 14:55:22 -0400 From: Julien Grall To: qemu-devel@nongnu.org Date: Wed, 22 Aug 2012 13:32:00 +0100 Message-ID: <557fe87e4a6c0defdc6549e23e8e5e7b2ebb7a9f.1345552068.git.julien.grall@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: Julien Grall , christian.limpach@gmail.com, Stefano.Stabellini@eu.citrix.com, xen-devel@lists.xen.org Subject: [Qemu-devel] [XEN][RFC PATCH V2 14/17] xl-parsing: Parse new device_models option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add new option "device_models". The user can specify the capability of the QEMU (ui, vifs, ...). This option only works with QEMU upstream (qemu-xen). For instance: device_models= [ 'name=all,vifs=nic1', 'name=qvga,ui', 'name=qide,ide' ] Each device model can also take a path argument which override the default one. It's usefull for debugging. Signed-off-by: Julien Grall --- tools/libxl/Makefile | 2 +- tools/libxl/libxlu_dm.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxlutil.h | 5 ++ tools/libxl/xl_cmdimpl.c | 29 +++++++++++++- 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 tools/libxl/libxlu_dm.c diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 47fb110..2b58721 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -79,7 +79,7 @@ AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \ AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c AUTOSRCS += _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \ - libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o + libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o libxlu_dm.o $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h CLIENTS = xl testidl libxl-save-helper diff --git a/tools/libxl/libxlu_dm.c b/tools/libxl/libxlu_dm.c new file mode 100644 index 0000000..9f0a347 --- /dev/null +++ b/tools/libxl/libxlu_dm.c @@ -0,0 +1,96 @@ +#include "libxl_osdeps.h" /* must come before any other headers */ +#include +#include "libxlu_internal.h" +#include "libxlu_cfg_i.h" + +static void split_string_into_string_list(const char *str, + const char *delim, + libxl_string_list *psl) +{ + char *s, *saveptr; + const char *p; + libxl_string_list sl; + + int i = 0, nr = 0; + + s = strdup(str); + if (s == NULL) { + fprintf(stderr, "xlu_dm: unable to allocate memory\n"); + exit(-1); + } + + /* Count number of entries */ + p = strtok_r(s, delim, &saveptr); + do { + nr++; + } while ((p = strtok_r(NULL, delim, &saveptr))); + + free(s); + + s = strdup(str); + + sl = malloc((nr+1) * sizeof (char *)); + if (sl == NULL) { + fprintf(stderr, "xlu_dm: unable to allocate memory\n"); + exit(-1); + } + + p = strtok_r(s, delim, &saveptr); + do { + assert(i < nr); + // Skip blank + while (*p == ' ') + p++; + sl[i] = strdup(p); + i++; + } while ((p = strtok_r(NULL, delim, &saveptr))); + sl[i] = NULL; + + *psl = sl; + + free(s); +} + +int xlu_dm_parse(XLU_Config *cfg, const char *spec, + libxl_dm *dm) +{ + char *buf = strdup(spec); + char *p, *p2; + int rc = 0; + + p = strtok(buf, ","); + if (!p) + goto skip_dm; + do { + while (*p == ' ') + p++; + if ((p2 = strchr(p, '=')) == NULL) { + if (!strcmp(p, "ui")) + dm->capabilities |= LIBXL_DM_CAP_UI; + else if (!strcmp(p, "ide")) + dm->capabilities |= LIBXL_DM_CAP_IDE; + else if (!strcmp(p, "serial")) + dm->capabilities |= LIBXL_DM_CAP_SERIAL; + else if (!strcmp(p, "audio")) + dm->capabilities |= LIBXL_DM_CAP_AUDIO; + } else { + *p2 = '\0'; + if (!strcmp(p, "name")) + dm->name = strdup(p2 + 1); + else if (!strcmp(p, "path")) + dm->path = strdup(p2 + 1); + else if (!strcmp(p, "vifs")) + split_string_into_string_list(p2 + 1, ";", &dm->vifs); + } + } while ((p = strtok(NULL, ",")) != NULL); + + if (!dm->name && dm->path) + { + fprintf(stderr, "xl: Unable to parse device_deamon\n"); + exit(-ERROR_FAIL); + } +skip_dm: + free(buf); + + return rc; +} diff --git a/tools/libxl/libxlutil.h b/tools/libxl/libxlutil.h index 0333e55..db22715 100644 --- a/tools/libxl/libxlutil.h +++ b/tools/libxl/libxlutil.h @@ -93,6 +93,11 @@ int xlu_disk_parse(XLU_Config *cfg, int nspecs, const char *const *specs, */ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str); +/* + * Daemon specification parsing. + */ +int xlu_dm_parse(XLU_Config *cfg, const char *spec, + libxl_dm *dm); /* * Vif rate parsing. diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 138cd72..2a26fa4 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -561,7 +561,7 @@ static void parse_config_data(const char *config_source, const char *buf; long l; XLU_Config *config; - XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids; + XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *dms; int pci_power_mgmt = 0; int pci_msitranslate = 0; int pci_permissive = 0; @@ -995,6 +995,9 @@ static void parse_config_data(const char *config_source, } else if (!strcmp(p, "vifname")) { free(nic->ifname); nic->ifname = strdup(p2 + 1); + } else if (!strcmp(p, "id")) { + free(nic->id); + nic->id = strdup(p2 + 1); } else if (!strcmp(p, "backend")) { if(libxl_name_to_domid(ctx, (p2 + 1), &(nic->backend_domid))) { fprintf(stderr, "Specified backend domain does not exist, defaulting to Dom0\n"); @@ -1249,6 +1252,30 @@ skip_vfb: } } } + + d_config->num_dms = 0; + d_config->dms = NULL; + + if (b_info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN + && !xlu_cfg_get_list (config, "device_models", &dms, 0, 0)) { + while ((buf = xlu_cfg_get_listitem (dms, d_config->num_dms)) != NULL) { + libxl_dm *dm; + size_t size = sizeof (libxl_dm) * (d_config->num_dms + 1); + + d_config->dms = (libxl_dm *)realloc (d_config->dms, size); + if (!d_config->dms) { + fprintf(stderr, "Can't realloc d_config->dms\n"); + exit (1); + } + dm = d_config->dms + d_config->num_dms; + libxl_dm_init (dm); + if (xlu_dm_parse(config, buf, dm)) { + exit (-ERROR_FAIL); + } + d_config->num_dms++; + } + } + #define parse_extra_args(type) \ e = xlu_cfg_get_list_as_string_list(config, "device_model_args"#type, \ &b_info->extra##type, 0); \