From patchwork Wed Jan 20 12:05:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 8071521 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2208DBEEE5 for ; Wed, 20 Jan 2016 12:07:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E0BE203B1 for ; Wed, 20 Jan 2016 12:07:56 +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 371172026F for ; Wed, 20 Jan 2016 12:07:55 +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 1aLrWI-00031c-HF; Wed, 20 Jan 2016 12:05:50 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLrWH-00031W-Ri for xen-devel@lists.xen.org; Wed, 20 Jan 2016 12:05:49 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 4E/57-03066-D187F965; Wed, 20 Jan 2016 12:05:49 +0000 X-Env-Sender: prvs=820a2b0fb=Ian.Campbell@citrix.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1453291547!16985753!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 42425 invoked from network); 20 Jan 2016 12:05:48 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 20 Jan 2016 12:05:48 -0000 X-IronPort-AV: E=Sophos;i="5.22,320,1449532800"; d="scan'208";a="332684532" From: Ian Campbell To: , Jim Fehlig Date: Wed, 20 Jan 2016 12:05:44 +0000 Message-ID: <1453291544-29323-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Campbell , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH LIBVIRT v2] 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). 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 --- NB: I was unsure if I was supposed to change VIR_FROM_NONE into VIR_FROM_XEN, so I didn't (but will on advice). v2: Use VIR_INFO (adding necessary infra) Don't initialise things to NULL when there is no need. --- src/xenconfig/xen_xl.c | 66 +++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 91cdff6..3d820cc 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_NONE +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; + 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;