From patchwork Thu Sep 3 10:05:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11752999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D680739 for ; Thu, 3 Sep 2020 10:07:19 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB88420767 for ; Thu, 3 Sep 2020 10:07:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="ZasX1IGS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB88420767 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kDm7s-0000zA-DM; Thu, 03 Sep 2020 10:05:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kDm7q-0000xt-Ct for xen-devel@lists.xenproject.org; Thu, 03 Sep 2020 10:05:50 +0000 X-Inumbo-ID: ef668fae-544b-4d19-89d7-f8f985b47645 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ef668fae-544b-4d19-89d7-f8f985b47645; Thu, 03 Sep 2020 10:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=/vJWDGDhMNKnK2icTtRJOoh810jE4F8SY8ycjNLUV20=; b=ZasX1IGSD5+s230ycwOgQpK46o 6ADneBA2HVYR105S3VmN+Yg7Wwqh/Id1Sysw/mHuCk0q3ohkdEwOJ0UGTMXxK7zFK9KIf0pxbg5oX VjHb84Txh180unY/4Q0dHd7HfFopP51IgTpE+Th77Xi+KrPz4Bhwbqae6P8FU90FkSCE=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kDm7g-0005aw-2p; Thu, 03 Sep 2020 10:05:40 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDm7f-0007WE-Ow; Thu, 03 Sep 2020 10:05:39 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 1/2] xl: implement documented --force option for block-detach Date: Thu, 3 Sep 2020 11:05:36 +0100 Message-Id: <20200903100537.1337-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903100537.1337-1-paul@xen.org> References: <20200903100537.1337-1-paul@xen.org> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Durrant The manpage for 'xl' documents an option to force a block device to be released even if the domain to which it is attached does not co-operate. This option, however, is not implemented. This patch implements the option. NOTE: The documentation is also adjusted since the normal positioning of options is before compulsory parameters. It is also noted that use of the --force option may lead to a guest crash. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- docs/man/xl.1.pod.in | 4 ++-- tools/xl/xl_block.c | 21 ++++++++++++++++----- tools/xl/xl_cmdtable.c | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index 52a47a6fbd..5f7d3a7134 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -1389,7 +1389,7 @@ Note that only PV block devices are supported by block-attach. Requests to attach emulated devices (eg, vdev=hdc) will result in only the PV view being available to the guest. -=item B I I [I] +=item B [I] I I Detach a domain's virtual block device. I may be the symbolic name or the numeric device id given to the device by domain 0. You @@ -1406,7 +1406,7 @@ B =item B<--force> If this parameter is specified the device will be forcefully detached, which -may cause IO errors in the domain. +may cause IO errors in the domain and possibly a guest crash =back diff --git a/tools/xl/xl_block.c b/tools/xl/xl_block.c index acaf9b96b8..05696643bf 100644 --- a/tools/xl/xl_block.c +++ b/tools/xl/xl_block.c @@ -96,12 +96,21 @@ int main_blocklist(int argc, char **argv) int main_blockdetach(int argc, char **argv) { + static struct option opts[] = { + {"force", 0, 0, 'f'}, + COMMON_LONG_OPTS + }; uint32_t domid; int opt, rc = 0; libxl_device_disk disk; - - SWITCH_FOREACH_OPT(opt, "", NULL, "block-detach", 2) { - /* No options */ + bool force = false; + + SWITCH_FOREACH_OPT(opt, "f", opts, "block-detach", 2) { + case 'f': + force = true; + break; + default: + break; } domid = find_domain(argv[optind]); @@ -110,9 +119,11 @@ int main_blockdetach(int argc, char **argv) fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); return 1; } - rc = libxl_device_disk_remove(ctx, domid, &disk, 0); + rc = !force ? libxl_device_disk_remove(ctx, domid, &disk, 0) : + libxl_device_disk_destroy(ctx, domid, &disk, 0); if (rc) { - fprintf(stderr, "libxl_device_disk_remove failed.\n"); + fprintf(stderr, "libxl_device_disk_%s failed.\n", + !force ? "remove" : "destroy"); return 1; } libxl_device_disk_dispose(&disk); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 2b8e1b321a..7da6c1b927 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -368,7 +368,8 @@ struct cmd_spec cmd_table[] = { { "block-detach", &main_blockdetach, 0, 1, "Destroy a domain's virtual block device", - " ", + "[option] ", + "-f, --force do not wait for the domain to release the device" }, { "vtpm-attach", &main_vtpmattach, 1, 1, From patchwork Thu Sep 3 10:05:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11752997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29194109B for ; Thu, 3 Sep 2020 10:07:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 010FF207EA for ; Thu, 3 Sep 2020 10:07:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="IncWCt6u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 010FF207EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kDm7n-0000yH-3X; Thu, 03 Sep 2020 10:05:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kDm7l-0000xt-Cm for xen-devel@lists.xenproject.org; Thu, 03 Sep 2020 10:05:45 +0000 X-Inumbo-ID: 60b0fc1e-eacb-467d-b6a8-20b92b3dc9c3 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 60b0fc1e-eacb-467d-b6a8-20b92b3dc9c3; Thu, 03 Sep 2020 10:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=DPBUlM35jhYlf960TGWbjpD76dUBghbgq1ala0F7pCc=; b=IncWCt6ubITXyNjv8DHCyDfKkO g1W68Sk12Cro7FDApSiiXjkSw63RYultcM1dLis3fPtG/Fdh8PDktWoIo6L4zPmN9JSZq4RvFXQQM piHw1KFlQ0BQkDAULS8neNFxVrxvrwBx5iD2SPRvRmFr9ypnUuQldLl3ZlQeCcVySU9k=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kDm7h-0005b0-1b; Thu, 03 Sep 2020 10:05:41 +0000 Received: from host86-176-94-160.range86-176.btcentralplus.com ([86.176.94.160] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDm7g-0007WE-P7; Thu, 03 Sep 2020 10:05:40 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 2/2] libxl: do not automatically force detach of block devices Date: Thu, 3 Sep 2020 11:05:37 +0100 Message-Id: <20200903100537.1337-3-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903100537.1337-1-paul@xen.org> References: <20200903100537.1337-1-paul@xen.org> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Paul Durrant The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- tools/libxl/libxl_device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 0381c5d509..d17ca78848 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -1092,7 +1092,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, if (rc == ERROR_TIMEDOUT && aodev->action == LIBXL__DEVICE_ACTION_REMOVE && - !aodev->force) { + !aodev->force && + aodev->dev->kind != LIBXL__DEVICE_KIND_VBD) { LOGD(DEBUG, aodev->dev->domid, "Timeout reached, initiating forced remove"); aodev->force = 1; libxl__initiate_device_generic_remove(egc, aodev); @@ -1103,7 +1104,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, LOGD(ERROR, aodev->dev->domid, "unable to %s device with path %s", libxl__device_action_to_string(aodev->action), libxl__device_backend_path(gc, aodev->dev)); - goto out; + if (!aodev->force) + goto out; } device_hotplug(egc, aodev); @@ -1319,7 +1321,8 @@ static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev) device_hotplug_clean(gc, aodev); /* Clean xenstore if it's a disconnection */ - if (aodev->action == LIBXL__DEVICE_ACTION_REMOVE) { + if (aodev->action == LIBXL__DEVICE_ACTION_REMOVE && + (aodev->force || !aodev->rc)) { rc = libxl__device_destroy(gc, aodev->dev); if (!aodev->rc) aodev->rc = rc;