From patchwork Tue Mar 1 08:09:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 8462901 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 2BF89C0553 for ; Tue, 1 Mar 2016 08:12:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 210B1201BB for ; Tue, 1 Mar 2016 08:12:41 +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 1685F2013D for ; Tue, 1 Mar 2016 08:12:40 +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 1aafOE-0006w1-Lc; Tue, 01 Mar 2016 08:10:42 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aafOD-0006vL-G9 for xen-devel@lists.xen.org; Tue, 01 Mar 2016 08:10:41 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 46/D8-04050-08E45D65; Tue, 01 Mar 2016 08:10:40 +0000 X-Env-Sender: cyliu@suse.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1456819838!16311178!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 33270 invoked from network); 1 Mar 2016 08:10:39 -0000 Received: from prv3-mh.provo.novell.com (HELO prv3-mh.provo.novell.com) (137.65.250.26) by server-4.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Mar 2016 08:10:39 -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); Tue, 01 Mar 2016 01:10:21 -0700 From: Chunyan Liu To: xen-devel@lists.xen.org Date: Tue, 1 Mar 2016 16:09:44 +0800 Message-Id: <1456819787-11568-4-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456819787-11568-1-git-send-email-cyliu@suse.com> References: <1456819787-11568-1-git-send-email-cyliu@suse.com> Cc: jgross@suse.com, 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 V15 3/6] refactor DEFINE_DEVICE_REMOVE to fit for more device types 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: , MIME-Version: 1.0 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 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 --- 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 2ac9c0f..2ab5ad3 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -3134,7 +3134,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; } @@ -4103,7 +4103,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) \ @@ -4123,13 +4123,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 */ @@ -4158,6 +4164,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 /******************************************************************************/ @@ -4362,7 +4370,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 21b9b8c..404ce7e 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