From patchwork Thu Mar 31 15:09:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 8714301 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 93F8D9F30C for ; Thu, 31 Mar 2016 15:14:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 97D9120272 for ; Thu, 31 Mar 2016 15:14:55 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 194C2202A1 for ; Thu, 31 Mar 2016 15:14:54 +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 1aleGy-0006yr-O0; Thu, 31 Mar 2016 15:12:36 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aleGx-0006yO-Rw for xen-devel@lists.xenproject.org; Thu, 31 Mar 2016 15:12:35 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 7C/2A-07924-36E3DF65; Thu, 31 Mar 2016 15:12:35 +0000 X-Env-Sender: prvs=8914c038b=roger.pau@citrix.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1459437149!6112105!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3294 invoked from network); 31 Mar 2016 15:12:34 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 31 Mar 2016 15:12:34 -0000 X-IronPort-AV: E=Sophos;i="5.24,422,1454976000"; d="scan'208";a="343781167" From: Roger Pau Monne To: Date: Thu, 31 Mar 2016 17:09:34 +0200 Message-ID: <1459436979-7475-4-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 2.6.4 (Apple Git-63) In-Reply-To: <1459436979-7475-1-git-send-email-roger.pau@citrix.com> References: <1459436979-7475-1-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Wei Liu , Ian Jackson , Roger Pau Monne Subject: [Xen-devel] [PATCH v3 3/8] libxl: refactor the FreeBSD hotplug script code 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-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 This factors out the nic hotplug specific code from the common code path in order to make it easier to add support for disk hotplug scripts. It shouldn't include any functional change. Signed-off-by: Roger Pau Monné Acked-by: Ian Jackson --- Cc: Ian Jackson Cc: Wei Liu --- Changes since v2: - Split the refactoring code out of the hotplug disk addition change. --- tools/libxl/libxl_freebsd.c | 76 +++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/tools/libxl/libxl_freebsd.c b/tools/libxl/libxl_freebsd.c index 47c3391..54db3d5 100644 --- a/tools/libxl/libxl_freebsd.c +++ b/tools/libxl/libxl_freebsd.c @@ -59,14 +59,36 @@ static int libxl__hotplug_env_nic(libxl__gc *gc, libxl__device *dev, char ***env return 0; } -static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, char ***args, - libxl__device_action action) +static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, + char ***args, char ***env, + libxl__device_action action, + int num_exec) { + libxl_nic_type nictype; char *be_path = libxl__device_backend_path(gc, dev); char *script; - int nr = 0, rc = 0, arraysize = 4; + int nr = 0, rc; - assert(dev->backend_kind == LIBXL__DEVICE_KIND_VIF); + rc = libxl__nic_type(gc, dev, &nictype); + if (rc) { + LOG(ERROR, "error when fetching nic type"); + rc = ERROR_FAIL; + goto out; + } + + /* + * For PV domains only one pass is needed (because there's no emulated + * interface). For HVM domains two passes are needed in order to add + * both the PV and the tap interfaces to the bridge. + */ + if (nictype == LIBXL_NIC_TYPE_VIF && num_exec != 0) { + rc = 0; + goto out; + } + + rc = libxl__hotplug_env_nic(gc, dev, env, num_exec); + if (rc) + goto out; script = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/%s", be_path, "script")); @@ -76,13 +98,14 @@ static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, char ***args, goto out; } + const int arraysize = 4; GCNEW_ARRAY(*args, arraysize); (*args)[nr++] = script; (*args)[nr++] = be_path; - (*args)[nr++] = GCSPRINTF("%s", action == LIBXL__DEVICE_ACTION_ADD ? - "add" : "remove"); + (*args)[nr++] = (char *) libxl__device_action_to_string(action); (*args)[nr++] = NULL; assert(nr == arraysize); + rc = 1; out: return rc; @@ -93,36 +116,27 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev, libxl__device_action action, int num_exec) { - libxl_nic_type nictype; int rc; - if (dev->backend_kind != LIBXL__DEVICE_KIND_VIF || num_exec == 2) - return 0; - - rc = libxl__nic_type(gc, dev, &nictype); - if (rc) { - LOG(ERROR, "error when fetching nic type"); - rc = ERROR_FAIL; - goto out; - } - - /* - * For PV domains only one pass is needed (because there's no emulated - * interface). For HVM domains two passes are needed in order to add - * both the PV and the tap interfaces to the bridge. - */ - if (nictype == LIBXL_NIC_TYPE_VIF && num_exec != 0) { + switch (dev->backend_kind) { + case LIBXL__DEVICE_KIND_VIF: + /* + * If domain has a stubdom we don't have to execute hotplug scripts + * for emulated interfaces + */ + if ((num_exec > 1) || + (libxl_get_stubdom_id(CTX, dev->domid) && num_exec)) { + rc = 0; + goto out; + } + rc = libxl__hotplug_nic(gc, dev, args, env, action, num_exec); + break; + default: + /* No need to execute any hotplug scripts */ rc = 0; - goto out; + break; } - rc = libxl__hotplug_env_nic(gc, dev, env, num_exec); - if (rc) - goto out; - - rc = libxl__hotplug_nic(gc, dev, args, action); - if (!rc) rc = 1; - out: return rc; }