From patchwork Wed Jun 15 09:31:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9177919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F030960573 for ; Wed, 15 Jun 2016 09:34:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF6AA27EED for ; Wed, 15 Jun 2016 09:34:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D472C2830C; Wed, 15 Jun 2016 09:34:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 710F827EED for ; Wed, 15 Jun 2016 09:34:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bD7Au-0001s7-ML; Wed, 15 Jun 2016 09:31:52 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bD7Au-0001ri-Eh for xen-devel@lists.xenproject.org; Wed, 15 Jun 2016 09:31:52 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id DF/E0-23871-78021675; Wed, 15 Jun 2016 09:31:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42JxWrrBXrddITH cYP5DIYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePk5udMBXdFKv4tb2ZvYLwq0MXIwSEh4C/x sV+7i5GTg01AWeJnZy8biC0ioCfRdOA5I4jNLOAl8WLdPzBbGKj8/ONvrCA2i4CqxJWbu8Dqe QWcJe4fuwFmSwjISZw//pMZxOYUcJGYfeMlG8gqIaCaQ+tkQcJCAgoSHdOPMUG0CkqcnPmEBW KVhMTBFy+YIS7jlvjbbT+BkW8WkqpZSKoWMDKtYtQoTi0qSy3SNTTUSyrKTM8oyU3MzNE1NDD Wy00tLk5MT81JTCrWS87P3cQIDCcGINjBuPq30yFGSQ4mJVFeD7nEcCG+pPyUyozE4oz4otKc 1OJDjDIcHEoSvBPkgXKCRanpqRVpmTnAwIZJS3DwKInwaoCkeYsLEnOLM9MhUqcYFaXEeVNAE gIgiYzSPLg2WDRdYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkjDvCpApPJl5JXDTXwEtZgJabD M9HmRxSSJCSqqB0T/th3dK/VTOAOulcxqZnKPlFQwScpSf/MhdYi6Z1ra17pKI6WvDuT/fLyr Qe2PE+iw14Cjn3KfcnIqedhKPNVN+8j4uvnrZ8f36/BPPdivvm62lu9t2iYP5EaPLYlrzvmke mWD0anNWovETo0vzW/Y//Hiw8JvVm23cVlfcr/a8cxN+IOdTrMRSnJFoqMVcVJwIAOHOEHmhA gAA X-Env-Sender: prvs=967af9503=wei.liu2@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1465983104!19238295!2 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: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3522 invoked from network); 15 Jun 2016 09:31:50 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 15 Jun 2016 09:31:50 -0000 X-IronPort-AV: E=Sophos;i="5.26,475,1459814400"; d="scan'208";a="367406695" From: Wei Liu To: Xen-devel Date: Wed, 15 Jun 2016 10:31:38 +0100 Message-ID: <1465983102-19308-2-git-send-email-wei.liu2@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465983102-19308-1-git-send-email-wei.liu2@citrix.com> References: <1465983102-19308-1-git-send-email-wei.liu2@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v3 1/5] libxl: libxl_domain_need_memory shouldn't modify b_info X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This function is used to return the memory needed for a guest. It's not in a position to modify the b_info passed in (note the _setdefault function). Use a copy of b_info to do the calculation. Define a macro to mark the change in API. Signed-off-by: Wei Liu --- Cc: Ian Jackson v3: new Any suggestion on the macro name? This patch should not be backported because it changes API behaviour. --- tools/libxl/libxl.c | 17 +++++++++++------ tools/libxl/libxl.h | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 5ec4c80..65af9ee 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5123,20 +5123,24 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info, uint32_t *need_memkb) { GC_INIT(ctx); + libxl_domain_build_info tmp; int rc; - rc = libxl__domain_build_info_setdefault(gc, b_info); + libxl_domain_build_info_init(&tmp); + libxl_domain_build_info_copy(ctx, &tmp, b_info); + + rc = libxl__domain_build_info_setdefault(gc, &tmp); if (rc) goto out; - *need_memkb = b_info->target_memkb; - switch (b_info->type) { + *need_memkb = tmp.target_memkb; + switch (tmp.type) { case LIBXL_DOMAIN_TYPE_HVM: - *need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY; - if (libxl_defbool_val(b_info->device_model_stubdomain)) + *need_memkb += tmp.shadow_memkb + LIBXL_HVM_EXTRA_MEMORY; + if (libxl_defbool_val(tmp.device_model_stubdomain)) *need_memkb += 32 * 1024; break; case LIBXL_DOMAIN_TYPE_PV: - *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY; + *need_memkb += tmp.shadow_memkb + LIBXL_PV_EXTRA_MEMORY; break; default: rc = ERROR_INVAL; @@ -5146,6 +5150,7 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info, *need_memkb += (2 * 1024) - (*need_memkb % (2 * 1024)); rc = 0; out: + libxl_domain_build_info_dispose(&tmp); GC_FREE; return rc; diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 2c0f868..905852d 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -67,6 +67,13 @@ * the same $(XEN_VERSION) (e.g. throughout a major release). */ +/* LIBXL_HAVE_DOMAIN_NEED_MEMORY_V2 + * + * If this is defined, libxl_domain_need_memory no longer modifies + * passed in b_info. + */ +#define LIBXL_HAVE_DOMAIN_NEED_MEMORY_V2 + /* LIBXL_HAVE_VNUMA * * If this is defined the type libxl_vnode_info exists, and a