From patchwork Thu Feb 25 19:25:15 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: 8426131 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 276FEC0553 for ; Thu, 25 Feb 2016 19:28:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 476DD20263 for ; Thu, 25 Feb 2016 19:28:25 +0000 (UTC) Received: from lists.xen.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 46F0F2039D for ; Thu, 25 Feb 2016 19:28:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZ1Xf-00054o-F6; Thu, 25 Feb 2016 19:25:39 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZ1Xe-00054F-4a for xen-devel@lists.xenproject.org; Thu, 25 Feb 2016 19:25:38 +0000 Received: from [193.109.254.147] by server-7.bemta-14.messagelabs.com id F0/C8-04065-1355FC65; Thu, 25 Feb 2016 19:25:37 +0000 X-Env-Sender: prvs=856d7c560=roger.pau@citrix.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1456428330!18181714!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: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40875 invoked from network); 25 Feb 2016 19:25:36 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 25 Feb 2016 19:25:36 -0000 X-IronPort-AV: E=Sophos;i="5.22,498,1449532800"; d="scan'208";a="341174594" From: Roger Pau Monne To: Date: Thu, 25 Feb 2016 20:25:15 +0100 Message-ID: <1456428318-8318-5-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 2.5.4 (Apple Git-61) In-Reply-To: <1456428318-8318-1-git-send-email-roger.pau@citrix.com> References: <1456428318-8318-1-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Wei Liu , Ian Jackson , Ian Campbell , Roger Pau Monne Subject: [Xen-devel] [PATCH v2 4/7] libxl/FreeBSD: add support for disk hotplug scripts 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=-1.9 required=5.0 tests=BAYES_00, 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 Allow FreeBSD to execute hotplug scripts when attaching disk devices. Signed-off-by: Roger Pau Monné --- Cc: Ian Jackson Cc: Ian Campbell Cc: Wei Liu --- tools/libxl/libxl_freebsd.c | 114 ++++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 31 deletions(-) diff --git a/tools/libxl/libxl_freebsd.c b/tools/libxl/libxl_freebsd.c index 483f36e..8ad347e 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,53 +98,83 @@ 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; } +static int libxl__hotplug_disk(libxl__gc *gc, libxl__device *dev, + char ***args, char ***env, + libxl__device_action action) +{ + char *be_path = libxl__device_backend_path(gc, dev); + char *script; + int nr = 0, rc; + + script = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/%s", be_path, "script")); + if (!script) { + LOGEV(ERROR, errno, "unable to read script from %s", be_path); + rc = ERROR_FAIL; + goto error; + } + + const int arraysize = 4; + GCNEW_ARRAY(*args, arraysize); + (*args)[nr++] = script; + (*args)[nr++] = be_path; + (*args)[nr++] = (char *) libxl__device_action_to_string(action); + (*args)[nr++] = NULL; + assert(nr == arraysize); + + rc = 1; + +error: + return rc; +} + int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev, char ***args, char ***env, 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_VBD: + if (num_exec != 0) { + rc = 0; + goto out; + } + rc = libxl__hotplug_disk(gc, dev, args, env, action); + break; + 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; }