From patchwork Fri Jul 18 08:49:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 33825 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 02695208CF for ; Fri, 18 Jul 2014 08:52:03 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id c9sf10255290qcz.6 for ; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:from:to:date:in-reply-to :references:organization:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=fahgxL7t0ae9sh0sjWl1A4gGSSVfmYr/D+WJU9pPysg=; b=H/+SEjeAiwykEpA4Ab14JvoJW8fdfIP+rWSEqiGkW8/f4buH0fW2BeFvFVmTOyJcej jwt3HMO8d8r2krScip8HeNB/2DLFmuqFkdY9hMT/a4+cbUxlvpvXlzcBOYnWvhfQoD9u mMYRbhTauad5S1rnlUPg78VQwtnjEUY6KtpgfNZTKt0jmddsO69cMZ15vKHsUK8rY88w qIqcrlfu+2BEVGner6bUdsjDRoRP0F6uNGS/JjViBgCeTEX2hRM2xt+gg3tWpJtJVdgx yoKz/7YBTUYn9DTYz8AxFuPaiAr8YjyKZPPDkJF19Irtnhh2fraHmxA45N97OXUzluo7 6sSg== X-Gm-Message-State: ALoCoQm+RqFrgPdEvFEZzp3ZLzgXJ7sQKENCgswxCSOEgdStVpbJbqd1dCfmcBcR92vrMXi3rMYL X-Received: by 10.224.171.130 with SMTP id h2mr1705151qaz.7.1405673523843; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.112 with SMTP id o103ls948103qgd.30.gmail; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) X-Received: by 10.221.34.13 with SMTP id sq13mr3488617vcb.16.1405673523742; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id py5si5013568vec.57.2014.07.18.01.52.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jul 2014 01:52:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so6855583vcb.39 for ; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) X-Received: by 10.52.37.81 with SMTP id w17mr995420vdj.95.1405673523600; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp103562vcb; Fri, 18 Jul 2014 01:52:03 -0700 (PDT) X-Received: by 10.52.249.83 with SMTP id ys19mr2641551vdc.77.1405673521952; Fri, 18 Jul 2014 01:52:01 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id u7si5011240ves.73.2014.07.18.01.52.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 18 Jul 2014 01:52:01 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X83rG-0006FI-Ea; Fri, 18 Jul 2014 08:49:38 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X83rF-0006FD-DN for xen-devel@lists.xen.org; Fri, 18 Jul 2014 08:49:37 +0000 Received: from [85.158.139.211:2649] by server-3.bemta-5.messagelabs.com id A5/98-23597-0AFD8C35; Fri, 18 Jul 2014 08:49:36 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1405673374!10932378!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23262 invoked from network); 18 Jul 2014 08:49:35 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 18 Jul 2014 08:49:35 -0000 X-IronPort-AV: E=Sophos;i="5.01,683,1400025600"; d="scan'208";a="153610175" Received: from accessns.citrite.net (HELO FTLPEX01CL02.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 18 Jul 2014 08:49:35 +0000 Received: from kazak.uk.xensource.com (10.80.2.80) by FTLPEX01CL02.citrite.net (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Fri, 18 Jul 2014 04:49:33 -0400 Message-ID: <1405673372.4823.8.camel@kazak.uk.xensource.com> From: Ian Campbell To: Wei Liu Date: Fri, 18 Jul 2014 09:49:32 +0100 In-Reply-To: <20140717141331.GN4913@zion.uk.xensource.com> References: <1405002745-5034-1-git-send-email-wei.liu2@citrix.com> <1405002745-5034-6-git-send-email-wei.liu2@citrix.com> <1405529339.1087.82.camel@kazak.uk.xensource.com> <20140716171217.GE4913@zion.uk.xensource.com> <1405597483.29996.17.camel@kazak.uk.xensource.com> <20140717141331.GN4913@zion.uk.xensource.com> Organization: Citrix Systems, Inc. X-Mailer: Evolution 3.12.2-1 MIME-Version: 1.0 X-Originating-IP: [10.80.2.80] X-DLP: MIA2 Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org Subject: Re: [Xen-devel] [PATCH v1 05/10] libxl: synchronise configuration when we hotplug a device X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: On Thu, 2014-07-17 at 15:13 +0100, Wei Liu wrote: > On Thu, Jul 17, 2014 at 12:44:43PM +0100, Ian Campbell wrote: > > On Wed, 2014-07-16 at 18:12 +0100, Wei Liu wrote: > > > > > As we don't have a JSON config file for libxl toolstack domain > > > > > (currently Dom0) we need to skip JSON manipulation for it. > > > > > > > > How hard would it be to create a stub/stunt JSON for dom0 when we notice > > > > it is missing? Or from e.g. xencommons perhaps? > > > > > > > > > > We need to determine: > > > 1. when / where to generate such thing (xencommons?) > > > 2. what to put in it > > > > > > I have yet had answers for #2. The simplest version can be "{}" I think. > > > That is an empty configuration that every fields gets the default value. > > > But we probably need more than that. > > > > I think you would want at least a name and perhaps a uuid? And cinfo > > type == PV. > > > > Device arrays are all empty at start of day. > > > > Some of the stuff about target and maxmem you could perhaps infer at > > start of day? > > > > UUID (Dom0 doesn't seem to have one), name and memory targets can all be > pulled from xenstore when they are required. > > And it occurs to me as I discovered Dom0 doesn't have UUID that we need > to special-case reading / writing of Dom0's JSON config. That's because > all other guests' JSON config are to be named with UUID and domain id. > How annoying. :-( Indeed. I think you could generate one on boot and set it with XEN_DOMCTL_setdomainhandle. It might be a bug that we don't do that today (that said I can't see any evidence that xend used to do differently). > I would like to put as few things as possible in the stub because there > doesn't seem to be a way to conveniently generate a valid JSON config > for Dom0. Will you be against the idea of having 'xl generate-dom0-json' > in xl to do that? Otherwise we have to basically generate a > semi-handcoded stub in xencommons, or even a hardcoded stub. I'm in favour of some sort of command to "initialise dom0". Either part of xl or a new helper app based on libxl. I had a similar (unposted I think) patch to add xl launch-dom0-qemu so that it could pick the correct arch (see below, warning: it's a bit skanky). If I were to do it again today I'd probably make a separate $libexec helper instead of bolting it into xl though. Probably it should subsume this bit of xencommons too: echo Setting domain 0 name and domid... ${BINDIR}/xenstore-write "/local/domain/0/name" "Domain-0" ${BINDIR}/xenstore-write "/local/domain/0/domid" 0 What do you think? > > > > > + DEVICE_ADD_JSON(vtpm, vtpms, num_vtpms, domid, &vtpm_saved, > > > > > > > > The second and third of these arguments could be derived from the first. > [...] > > > > How close to being possible is it to do this as a proper helper function > > > > which takes a size_t and a bunch of fn pointers with void where the type > > > > would be? > > > > > > > > > > We need to know the type of this structure otherwise we don't know what > > > *_copy function to call. Sadly there's no way to pass in type information > > > in C in runtime. > > > > You could pass a copyfn as a function pointer with a void * argument for > > the object to a helper function which doesn't need the specifics and > > then have a macro which simply defines the type safe wrappers around > > that. ISTR thinking that the helper would need a sizeof passing to it > > as well for the realloc. > > > > I see. I will try to go with this approach. I'd check with Ian J first, he might have some reason to prefer macros over void * + wrapper. Ian. commit 7b5d54c9a5d09c4138bec905c9accea34173ba77 Author: Ian Campbell Date: Wed May 15 16:34:55 2013 +0100 tools: build and launch correct qemu for architecture xl now provides a launch-dom0-qemu command which avoids the need to have the initscripts be aware of the specific qermu binary name, which differs by architecture and which also may have been specified by the user via the --with-system-qemu=PATH option to configure. Perhaps this should be a separate binary hidden in libexec? Signed-off-by: Ian Campbell diff --git a/config/arm32.mk b/config/arm32.mk index aa79d22..f3599a3 100644 --- a/config/arm32.mk +++ b/config/arm32.mk @@ -3,6 +3,8 @@ CONFIG_ARM_32 := y CONFIG_ARM_$(XEN_OS) := y CONFIG_XEN_INSTALL_SUFFIX := +CONFIG_QEMU_ARCH := arm +CONFIG_QEMU_TARGET := arm-softmmu # -march= -mcpu= diff --git a/config/arm64.mk b/config/arm64.mk index 15b57a4..4ff15e0 100644 --- a/config/arm64.mk +++ b/config/arm64.mk @@ -3,6 +3,8 @@ CONFIG_ARM_64 := y CONFIG_ARM_$(XEN_OS) := y CONFIG_XEN_INSTALL_SUFFIX := +CONFIG_QEMU_ARCH := aarch64 +CONFIG_QEMU_TARGET := arm-softmmu CFLAGS += #-marm -march= -mcpu= etc diff --git a/config/x86_32.mk b/config/x86_32.mk index 7f76b25..da3111d 100644 --- a/config/x86_32.mk +++ b/config/x86_32.mk @@ -2,6 +2,9 @@ CONFIG_X86 := y CONFIG_X86_32 := y CONFIG_X86_$(XEN_OS) := y +CONFIG_QEMU_ARCH := i386 +CONFIG_QEMU_TARGET := i386-softmmu + CONFIG_HVM := y CONFIG_MIGRATE := y CONFIG_XCUTILS := y diff --git a/config/x86_64.mk b/config/x86_64.mk index 11104bd..f59e36d 100644 --- a/config/x86_64.mk +++ b/config/x86_64.mk @@ -2,6 +2,9 @@ CONFIG_X86 := y CONFIG_X86_64 := y CONFIG_X86_$(XEN_OS) := y +CONFIG_QEMU_ARCH := x86_64 +CONFIG_QEMU_ARCH := i386-softmmu + CONFIG_COMPAT := y CONFIG_HVM := y CONFIG_MIGRATE := y diff --git a/tools/Makefile b/tools/Makefile index 00c69ee..250b931 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -107,7 +107,7 @@ distclean: subdirs-distclean config.cache autom4te.cache ifneq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH)) -IOEMU_CONFIGURE_CROSS ?= --cpu=$(XEN_TARGET_ARCH) \ +IOEMU_CONFIGURE_CROSS ?= --cpu=$(CONFIG_QEMU_ARCH) \ --cross-prefix=$(CROSS_COMPILE) \ --interp-prefix=$(CROSS_SYS_ROOT) endif @@ -186,8 +186,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find source=.; \ fi; \ cd qemu-xen-dir; \ - $$source/configure --enable-xen --target-list=i386-softmmu \ - $(QEMU_XEN_ENABLE_DEBUG) \ + $$source/configure --enable-xen --target-list=$(CONFIG_QEMU_TARGET) \ --prefix=$(PREFIX) \ --source-path=$$source \ --extra-cflags="-I$(XEN_ROOT)/tools/include \ diff --git a/tools/hotplug/Linux/init.d/xencommons b/tools/hotplug/Linux/init.d/xencommons index 4ebd636..f568085 100644 --- a/tools/hotplug/Linux/init.d/xencommons +++ b/tools/hotplug/Linux/init.d/xencommons @@ -116,11 +116,7 @@ do_start () { echo Starting xenconsoled... test -z "$XENCONSOLED_TRACE" || XENCONSOLED_ARGS=" --log=$XENCONSOLED_TRACE" ${SBINDIR}/xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_ARGS - echo Starting QEMU as disk backend for dom0 - test -z "$QEMU_XEN" && QEMU_XEN="${LIBEXEC}/qemu-system-i386" - $QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize \ - -monitor /dev/null -serial /dev/null -parallel /dev/null \ - -pidfile $QEMU_PIDFILE + xl launch-dom0-qemu $QEMU_XEN } do_stop () { echo Stopping xenconsoled diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index d8495bb..d8b6a5c 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -27,6 +27,7 @@ CFLAGS_LIBXL += $(CFLAGS_libxenguest) CFLAGS_LIBXL += $(CFLAGS_libxenstore) CFLAGS_LIBXL += $(CFLAGS_libblktapctl) CFLAGS_LIBXL += -Wshadow +CFLAGS_LIBXL += -DCONFIG_QEMU_ARCH=\"$(CONFIG_QEMU_ARCH)\" LIBXL_LIBS-$(CONFIG_ARM) += -lfdt diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 12d6c31..0287a35 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -605,6 +605,9 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger *lg); int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */); +/* exec's device model for dom0 and does not return. */ +void libxl_launch_dom0_qemu(libxl_ctx *ctx, const char *qemu_path, const char *pidfile); + /* domain related functions */ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index f6f7bbd..f0b13a9 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -38,7 +38,7 @@ static const char *qemu_xen_path(libxl__gc *gc) #ifdef QEMU_XEN_PATH return QEMU_XEN_PATH; #else - return libxl__abs_path(gc, "qemu-system-i386", libxl__libexec_path()); + return libxl__abs_path(gc, "qemu-system-" CONFIG_QEMU_ARCH, libxl__libexec_path()); #endif } @@ -1560,6 +1560,37 @@ out: return ret; } +void libxl_launch_dom0_qemu(libxl_ctx *ctx, const char *qemu_path, const char *pidfile) +{ + GC_INIT(ctx); + + flexarray_t *dm_args = flexarray_make(gc, 16, 1); + + if (qemu_path == NULL) + qemu_path = qemu_xen_path(gc); + + flexarray_vappend(dm_args, + "-xen-domid", "0", + "-xen-attach", + "-name", "dom0", + "-nographic", + "-M" "xenpv", + "-daemonize", + "-monitor", "/dev/null", + "-serial", "/dev/null", + "-parallel", "/dev/null", + NULL); + if (pidfile) + flexarray_append_pair(dm_args, "-pidfile", libxl__strdup(gc, pidfile)); + + libxl__exec(gc, -1, -1, -1, + qemu_path, (char **)flexarray_contents(dm_args), NULL); + + /* Shouldn't return */ + LOG(CRITICAL, "Failed to exec dom0 device model"); + GC_FREE; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h index c876a33..1d7602c 100644 --- a/tools/libxl/xl.h +++ b/tools/libxl/xl.h @@ -106,6 +106,7 @@ int main_setenforce(int argc, char **argv); int main_loadpolicy(int argc, char **argv); int main_remus(int argc, char **argv); int main_devd(int argc, char **argv); +int main_launch_dom0_qemu(int argc, char **argv); void help(const char *command); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index bd26bcc..108dfac 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -7313,6 +7313,31 @@ out: return ret; } +int main_launch_dom0_qemu(int argc, char **argv) +{ + int opt; + const char *qemu = NULL; + const char *pidfile = NULL; + + SWITCH_FOREACH_OPT(opt, "p:", NULL, "launch-dom-qemu", 0) { + case 'p': + pidfile = optarg; + break; + /* No options */ + } + if (optind < argc) + qemu = argv[optind]; + + fprintf(stderr, "argc %d\n", argc); + fprintf(stderr, "qemu = %s", qemu ? : ""); + + fprintf(stdout, "Starting QEMU as disk backend for dom0"); + + libxl_launch_dom0_qemu(ctx, qemu, pidfile); + + return 0; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index ebe0220..ab4d56c 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -494,6 +494,12 @@ struct cmd_spec cmd_table[] = { "[options]", "-F Run in the foreground", }, + { "launch-dom0-qemu", + &main_launch_dom0_qemu, 0, 1, + "Start qemu process to service dom0 disk backends", + "[options] [QEMU_PATH]", + "-p PIDFILE Write a PIDFILE\n", + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);