From patchwork Thu Jan 21 12:29:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 8080631 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C11169F744 for ; Thu, 21 Jan 2016 12:32:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0CC6D20585 for ; Thu, 21 Jan 2016 12:32:16 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A0AB20575 for ; Thu, 21 Jan 2016 12:32:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMEMr-0003Jh-EJ; Thu, 21 Jan 2016 12:29:37 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMEMo-0003JR-SH for xen-devel@lists.xen.org; Thu, 21 Jan 2016 12:29:35 +0000 Received: from [193.109.254.147] by server-5.bemta-14.messagelabs.com id 61/07-23366-E2FC0A65; Thu, 21 Jan 2016 12:29:34 +0000 X-Env-Sender: prvs=821970992=Ian.Campbell@citrix.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1453379372!18424691!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57810 invoked from network); 21 Jan 2016 12:29:33 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jan 2016 12:29:33 -0000 X-IronPort-AV: E=Sophos;i="5.22,325,1449532800"; d="scan'208";a="333016929" From: Ian Campbell To: , Jim Fehlig Date: Thu, 21 Jan 2016 12:29:29 +0000 Message-ID: <1453379369-32423-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Campbell , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH LIBVIRT v3] libxl: Support cmdline= in xl config files X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ... and consolidate the cmdline/extra/root parsing to facilitate doing so. The logic is the same as xl's parse_cmdline from the current xen.git master branch (e6f0e099d2c17de47fd86e817b1998db903cab61). On the formatting side switch to producing cmdline= instead of extra=. Update a few tests and add serveral more. - test-cmdline is added to test the exclusive use of cmdline. - test-fullvirt-direct-kernel-boot.cfg is updated due to the switch on the formatting side and now tests the exclusive use of cmdline=. - Tests are added for both paravirt and fullvirt where the .cfg uses extra= and (paravirt only) root=. These are format (xl->xml) only since the inverse will generate cmdline= hence is not a round trip (which was already true if using root=, which used to generate extra= on the way back). - Tests are added for both paravirt and fullvirt where the .cfg declares cmdline= as well as bogus extra= and (paravirt only) root= entries which should be ignored. Again these are format only tests since the inverse won't include the bogus lines. The last two bullets here required splitting the DO_TEST macro into two halves, as is done in the xmconfigtest.c case. In order to introduce a use of VIR_WARN for logging I had to add virerror.h and VIR_LOG_INIT. Signed-off-by: Ian Campbell --- v2: Use VIR_INFO (adding necessary infra) Don't initialise things to NULL when there is no need. v3: I know know the answer re VIR_FROM_THIS, because Jim fixed it. Initialise cmdline to NULL, since neither I nor gcc were smart enough to spot the uninitialised path I did this in preference to adding the else case, since that apparently won't be masking the compiler's ability to spot uninitialised vars in this function. Add tests Addjust xenFormatXLOS to produce cmdline= instead of extra=. --- src/xenconfig/xen_xl.c | 70 +++++++++++++--------- ...est-fullvirt-direct-kernel-boot-bogus-extra.cfg | 31 ++++++++++ ...est-fullvirt-direct-kernel-boot-bogus-extra.xml | 51 ++++++++++++++++ .../test-fullvirt-direct-kernel-boot-extra.cfg | 30 ++++++++++ .../test-fullvirt-direct-kernel-boot-extra.xml | 51 ++++++++++++++++ .../test-fullvirt-direct-kernel-boot.cfg | 2 +- .../test-paravirt-cmdline-bogus-extra-root.cfg | 13 ++++ .../test-paravirt-cmdline-bogus-extra-root.xml | 32 ++++++++++ .../test-paravirt-cmdline-extra-root.cfg | 15 +++++ .../test-paravirt-cmdline-extra-root.xml | 32 ++++++++++ tests/xlconfigdata/test-paravirt-cmdline.cfg | 14 +++++ tests/xlconfigdata/test-paravirt-cmdline.xml | 32 ++++++++++ tests/xlconfigtest.c | 24 ++++++-- 13 files changed, 365 insertions(+), 32 deletions(-) create mode 100644 tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.cfg create mode 100644 tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.xml create mode 100644 tests/xlconfigdata/test-fullvirt-direct-kernel-boot-extra.cfg create mode 100644 tests/xlconfigdata/test-fullvirt-direct-kernel-boot-extra.xml create mode 100644 tests/xlconfigdata/test-paravirt-cmdline-bogus-extra-root.cfg create mode 100644 tests/xlconfigdata/test-paravirt-cmdline-bogus-extra-root.xml create mode 100644 tests/xlconfigdata/test-paravirt-cmdline-extra-root.cfg create mode 100644 tests/xlconfigdata/test-paravirt-cmdline-extra-root.xml create mode 100644 tests/xlconfigdata/test-paravirt-cmdline.cfg create mode 100644 tests/xlconfigdata/test-paravirt-cmdline.xml diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 026cbcc..be194e3 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -27,6 +27,7 @@ #include "virconf.h" #include "virerror.h" +#include "virlog.h" #include "domain_conf.h" #include "viralloc.h" #include "virstring.h" @@ -35,6 +36,8 @@ #define VIR_FROM_THIS VIR_FROM_XENXL +VIR_LOG_INIT("xen.xen_xl"); + /* * Xen provides a libxl utility library, with several useful functions, * specifically xlu_disk_parse for parsing xl disk config strings. @@ -58,11 +61,46 @@ extern int xlu_disk_parse(XLU_Config *cfg, libxl_device_disk *disk); #endif +static int xenParseCmdline(virConfPtr conf, char **r_cmdline) +{ + char *cmdline = NULL; + const char *root, *extra, *buf; + + if (xenConfigGetString(conf, "cmdline", &buf, NULL) < 0) + return -1; + + if (xenConfigGetString(conf, "root", &root, NULL) < 0) + return -1; + + if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) + return -1; + + if (buf) { + if (VIR_STRDUP(cmdline, buf) < 0) + return -1; + if (root || extra) + VIR_WARN("ignoring root= and extra= in favour of cmdline="); + } else { + if (root && extra) { + if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0) + return -1; + } else if (root) { + if (virAsprintf(&cmdline, "root=%s", root) < 0) + return -1; + } else if (extra) { + if (VIR_STRDUP(cmdline, extra) < 0) + return -1; + } + } + + *r_cmdline = cmdline; + return 0; +} + static int xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) { size_t i; - const char *extra, *root; if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { const char *boot; @@ -84,19 +122,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; - if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) - return -1; - - if (xenConfigGetString(conf, "root", &root, NULL) < 0) + if (xenParseCmdline(conf, &def->os.cmdline) < 0) return -1; - - if (root) { - if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) - return -1; - } else { - if (VIR_STRDUP(def->os.cmdline, extra) < 0) - return -1; - } #endif if (xenConfigGetString(conf, "boot", &boot, "c") < 0) @@ -132,19 +159,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; - if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) - return -1; - - if (xenConfigGetString(conf, "root", &root, NULL) < 0) + if (xenParseCmdline(conf, &def->os.cmdline) < 0) return -1; - - if (root) { - if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) - return -1; - } else { - if (VIR_STRDUP(def->os.cmdline, extra) < 0) - return -1; - } } return 0; @@ -503,7 +519,7 @@ xenFormatXLOS(virConfPtr conf, virDomainDefPtr def) return -1; if (def->os.cmdline && - xenConfigSetString(conf, "extra", def->os.cmdline) < 0) + xenConfigSetString(conf, "cmdline", def->os.cmdline) < 0) return -1; #endif @@ -554,7 +570,7 @@ xenFormatXLOS(virConfPtr conf, virDomainDefPtr def) return -1; if (def->os.cmdline && - xenConfigSetString(conf, "extra", def->os.cmdline) < 0) + xenConfigSetString(conf, "cmdline", def->os.cmdline) < 0) return -1; } /* !hvm */ diff --git a/tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.cfg b/tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.cfg new file mode 100644 index 0000000..83ab975 --- /dev/null +++ b/tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.cfg @@ -0,0 +1,31 @@ +name = "XenGuest2" +uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" +maxmem = 579 +memory = 394 +vcpus = 1 +pae = 1 +acpi = 1 +apic = 1 +hap = 0 +viridian = 0 +rtc_timeoffset = 0 +localtime = 0 +on_poweroff = "destroy" +on_reboot = "restart" +on_crash = "restart" +device_model = "/usr/lib/xen/bin/qemu-system-i386" +sdl = 0 +vnc = 1 +vncunused = 1 +vnclisten = "127.0.0.1" +vncpasswd = "123poi" +vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000" ] +parallel = "none" +serial = "none" +builder = "hvm" +kernel = "/tmp/vmlinuz" +ramdisk = "/tmp/initrd" +cmdline = "ignore_loglvl" +extra = "SHOULD BE IGNORED" +boot = "d" +disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,backendtype=phy", "/root/boot.iso,raw,hdc,r,backendtype=qdisk,devtype=cdrom" ] diff --git a/tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.xml b/tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.xml new file mode 100644 index 0000000..f750e02 --- /dev/null +++ b/tests/xlconfigdata/test-fullvirt-direct-kernel-boot-bogus-extra.xml @@ -0,0 +1,51 @@ + + XenGuest2 + c7a5fdb2-cdaf-9455-926a-d65c16db1809 + 592896 + 403456 + 1 + + hvm + /usr/lib/xen/boot/hvmloader + /tmp/vmlinuz + /tmp/initrd + ignore_loglvl + + + + + + + + + destroy + restart + restart + + /usr/lib/xen/bin/qemu-system-i386 + + + + +
+ + + + + + +
+ + + + +