From patchwork Fri Feb 19 10:39:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 8359391 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 7859F9F372 for ; Fri, 19 Feb 2016 10:43:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8AC5E2041B for ; Fri, 19 Feb 2016 10:43:31 +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 74C89203B5 for ; Fri, 19 Feb 2016 10:43:30 +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 1aWiUU-0002JZ-5i; Fri, 19 Feb 2016 10:40:50 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWiUS-0002IL-I5 for xen-devel@lists.xen.org; Fri, 19 Feb 2016 10:40:48 +0000 Received: from [193.109.254.147] by server-11.bemta-14.messagelabs.com id FA/6E-28228-F21F6C65; Fri, 19 Feb 2016 10:40:47 +0000 X-Env-Sender: cyliu@suse.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1455878445!21334647!1 X-Originating-IP: [137.65.250.26] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29040 invoked from network); 19 Feb 2016 10:40:46 -0000 Received: from victor.provo.novell.com (HELO prv3-mh.provo.novell.com) (137.65.250.26) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Feb 2016 10:40:46 -0000 Received: from linux-3hvf.site (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Fri, 19 Feb 2016 03:40:34 -0700 From: Chunyan Liu To: xen-devel@lists.xen.org Date: Fri, 19 Feb 2016 18:39:50 +0800 Message-Id: <1455878393-31807-4-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455878393-31807-1-git-send-email-cyliu@suse.com> References: <1455878393-31807-1-git-send-email-cyliu@suse.com> Cc: jgross@suse.com, olaf@aepfle.de, wei.liu2@citrix.com, ian.campbell@citrix.com, george.dunlap@eu.citrix.com, Ian.Jackson@eu.citrix.com, Chunyan Liu , George Dunlap , jfehlig@suse.com Subject: [Xen-devel] [PATCH V14 3/6] refactor DEFINE_DEVICE_REMOVE to fit for more device types 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: , MIME-Version: 1.0 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 For some device type, device removal operation needs to be handled specially, like usbctrl, it needs to remove all usb devices under it first, then remove usbctrl. Extend DEFINE_DEVICE_REMOVE to support generic and custom way For those need to be handled specially, call DEFINE_DEVICE_REMOVE_CUSTOM, it requires user defined libxl__initiate_device_##type##_remove. Otherwise, just call DEFINE_DEVICE_REMOVE as before. Signed-off-by: George Dunlap Signed-off-by: Chunyan Liu --- Address Olaf's suggestion: * split from "libxl: add pvusb API" patch, since it is common refactor work, not pvusb specific. tools/libxl/libxl.c | 18 +++++++++++++----- tools/libxl/libxl_device.c | 10 +++++----- tools/libxl/libxl_internal.h | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 98743cd..f385134 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -3199,7 +3199,7 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc, aodev->dev = device; aodev->callback = local_device_detach_cb; aodev->force = 0; - libxl__initiate_device_remove(egc, aodev); + libxl__initiate_device_generic_remove(egc, aodev); return; } @@ -4168,7 +4168,7 @@ out: * libxl_device_vfb_remove * libxl_device_vfb_destroy */ -#define DEFINE_DEVICE_REMOVE(type, removedestroy, f) \ +#define DEFINE_DEVICE_REMOVE_EXT(type, remtype, removedestroy, f) \ int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ uint32_t domid, libxl_device_##type *type, \ const libxl_asyncop_how *ao_how) \ @@ -4188,13 +4188,19 @@ out: aodev->dev = device; \ aodev->callback = device_addrm_aocomplete; \ aodev->force = f; \ - libxl__initiate_device_remove(egc, aodev); \ + libxl__initiate_device_##remtype##_remove(egc, aodev); \ \ out: \ - if (rc) return AO_CREATE_FAIL(rc); \ + if (rc) return AO_CREATE_FAIL(rc); \ return AO_INPROGRESS; \ } +#define DEFINE_DEVICE_REMOVE(type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, generic, removedestroy, f) + +#define DEFINE_DEVICE_REMOVE_CUSTOM(type, removedestroy, f) \ + DEFINE_DEVICE_REMOVE_EXT(type, type, removedestroy, f) + /* Define all remove/destroy functions and undef the macro */ /* disk */ @@ -4223,6 +4229,8 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) * 2. dynamically add/remove qemu chardevs via qmp messages. */ #undef DEFINE_DEVICE_REMOVE +#undef DEFINE_DEVICE_REMOVE_CUSTOM +#undef DEFINE_DEVICE_REMOVE_EXT /******************************************************************************/ @@ -4427,7 +4435,7 @@ static int remove_device(libxl__egc *egc, libxl__ao *ao, aodev->dev = dev; aodev->action = LIBXL__DEVICE_ACTION_REMOVE; aodev->callback = device_complete; - libxl__initiate_device_remove(egc, aodev); + libxl__initiate_device_generic_remove(egc, aodev); break; case LIBXL__DEVICE_KIND_QDISK: if (--dguest->num_qdisks == 0) { diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 8bb5e93..a356e2a 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -676,7 +676,7 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) aodev->action = LIBXL__DEVICE_ACTION_REMOVE; aodev->dev = dev; aodev->force = drs->force; - libxl__initiate_device_remove(egc, aodev); + libxl__initiate_device_generic_remove(egc, aodev); } } } @@ -775,8 +775,8 @@ out: return; } -void libxl__initiate_device_remove(libxl__egc *egc, - libxl__ao_device *aodev) +void libxl__initiate_device_generic_remove(libxl__egc *egc, + libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); xs_transaction_t t = 0; @@ -806,7 +806,7 @@ void libxl__initiate_device_remove(libxl__egc *egc, (info.paused || info.dying || info.shutdown)) { /* * TODO: 4.2 Bodge due to QEMU, see comment on top of - * libxl__initiate_device_remove in libxl_internal.h + * libxl__initiate_device_generic_remove in libxl_internal.h */ rc = libxl__ev_time_register_rel(ao, &aodev->timeout, device_qemu_timeout, @@ -942,7 +942,7 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, !aodev->force) { LOG(DEBUG, "Timeout reached, initiating forced remove"); aodev->force = 1; - libxl__initiate_device_remove(egc, aodev); + libxl__initiate_device_generic_remove(egc, aodev); return; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 10eb9fd..dd8a681 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2616,8 +2616,8 @@ _hidden void libxl__wait_device_connection(libxl__egc*, * * Once finished, aodev->callback will be executed. */ -_hidden void libxl__initiate_device_remove(libxl__egc *egc, - libxl__ao_device *aodev); +_hidden void libxl__initiate_device_generic_remove(libxl__egc *egc, + libxl__ao_device *aodev); /* * libxl__get_hotplug_script_info returns the args and env that should