From patchwork Mon Feb 7 16:37:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 924D6C433EF for ; Mon, 7 Feb 2022 17:26:19 +0000 (UTC) Received: from localhost ([::1]:49992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7mM-0004bw-77 for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:26:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71R-0001h9-LG; Mon, 07 Feb 2022 11:37:50 -0500 Received: from [2a01:111:f400:7e1b::708] (port=37729 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71O-0005HI-De; Mon, 07 Feb 2022 11:37:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PttscNq2ksNsRd6ktHYXslpkog4B1QYbPSpYgc5SZ/5vR9Hc4m1j166ekmvHXHMUeqUnoR8RKt3D6CodWv2oKAzPh8e2WlO3SAnJ5yCXOXSE7jLA+122aMtp/pXH/yUzqIRk11aJZLaN6H0+hNcUSX+m7FfcHjtYkmWRRrHlVRLRrFPhEhdtsg5YCYZK5aD8vfEp8RZbPDKVZHILcQIE0cZOW3MenBwkF5g1iFIYOrsYkEk5XkeKXIewCUJXbNQixMK79CFR8aWDD8pOgEZxT71ksnAlQNmQUcVYre6XiqjwTzP5UB14bEg3mfEhbjwcF49HMk6dYt7azXiek0PoyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tty7PQs0d6d2+Pp2OIMA28yZITQC7+ncWsCZ99J+230=; b=nVgDticqcXo5qpC2JVzyByQCw4xP43k2SNgVD7LiQ/T54K/ph31Us1uFGwfy3gHAdEoKEDbBqq2cf/KTGnMYSxGY7GPNsd6/4GE3tiF/KINWrAo8QKQDioUKoZs+7ZmM1GT+U7v/2bwdaM4sagD1hnn/0J3dcvwenbt8ArLx2d6U1Wfcw6OgjvBhamAR8v6IryWfJ7UTsnAXNbj5xpZ+gqwiZU3/xKqQUH1rZESFkPAwHKY/UnFG2rK8Fuf4RgTRZCaRiciv//xBrWKgYBU821qmAv9Tfo36mRB0IwbcDnmFChiiKrm4YpU/9EJMciVfJ4vvHSfqNjqRYxchzXL+fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tty7PQs0d6d2+Pp2OIMA28yZITQC7+ncWsCZ99J+230=; b=GVv8SreobHgNioF9F7yZmG+Ra3OsKe2y3Nw6LjswRu0IcgqbDRAjRcyvUAkeb7GZLruQE/erWJEINFWnpv7dT2bqXyln7yUKdXf5ZZWNk2QCtr9wt+4SRnnPeQngtJGAxKn8EFtFLkCjRyU8wEDXx8j4EoF13m0MoFFZyl4xVGI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:38 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:38 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 01/14] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child Date: Mon, 7 Feb 2022 17:37:15 +0100 Message-Id: <20220207163728.30362-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b865726-760a-4d00-fc0e-08d9ea582719 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lpglF3myqrPerKPInCO6oLXgurd8R2bvSwxPX3pSGVWZdAfDVszqgTnnKx79RIeOmk4cybGA/pNKcJ5biqwbQgtm43BSJc+kHLPuAyPZBka8r04iTgwmj5AT62inG62CHFDte/sLQ39Kaw5UKEkCYF1+srvSCvmFj3yHgj0syGR8mlD1qMIujmiy+DssxQGrKkIFA6EQj8P9Xy7NaTkBZL+ubHeNzE1o4ftFl6QjAEmOwH2Kz4e/C6TqIYyEYuuz9UhkwG/sJVTg6qXq6EiutbJrqZYamjjlj1W9RNdg9AZaqSdbckz18fy6WZOI94DYHq8XyoVaH99rAoB8VirL/e+dob5wiUwIMHOPCNlXaiTHxbRv/nu9/lAa1kBqgCRmiVlM/MDPVgsWJj95f8xrAwzN+WAyXcAuQAHM9MLDDKRblzYNe4raU9G31eUGx6mdRAohl9/1zA1/Br9fbz7ffgK0D1UCmifwLMcfwDkHODgmrN60zFD7AHPWBfJEjRNNwD/l8sIlHikUTPP85VD3d1rE59aPL1UsiSM0vNEu0jqakB3yjM9vDqAv1E1AEqqJ3ZUJQCmbq7eS+lYZfWy1JnKU3+uy6k06iGMQ8b9zEe0pFFVo44kH2a/dQIOmLK6TeNWIA7PxgG1F7lm1hALiVit7yNz/yw1aOMAW9jlJuFcQ61ZlafMstA6YjcjK2gfY4Ke2bKMF+oqKVCAvIQtzVA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0fvZJXApnRH3+QIwIq96XS6wtPGV1EzyF2AbJAkmpfUno3p8JvMCEogh740ejko9eJYrQfVZ6Vbx0ykOpJuFcPOY/h8/+8/9KVFEFdgzvvoInhbwkauNiRwitWyHkC5SeHadWVJyYgXAOu5ZmwlMMv2SUqMESJjqlsEIpNwpUisBb5OWH16Qb+6pZLwuMoyuVEzCo1+Zfk11kw2+HSAPUGpI0D775niDsQqJZFoIIGt8ZWIEx3tzdO51le8kAHkBtznl9D8sJEYFNJlUPX1pt9sI1Oqsaj1qgAlkyiLDqjoDlI8xhXtmcYBCCmXZmbGLr+TU7mJqKu90uIak8j2wR4y66s0ML0jzA0OqAX2HtmwyGd/fomdUV9wQaAVo87pW9ZTTEZaLEMXOj3jHFf5gil6RbV/ixN4wM0jtFK2B07zl5ILRaA5brx3Fwj+Jk0acJXR7ngoJNZkKDRcb3mWXsuZJfcYPuQ5t20sN4Miei/+owBxR7JVSmQunypszQtO2E9VFysnIBX6aUty+1DlZp0dGRa8mSfndR4a7si02bAP0ugRo+RklkNvfbLeInOsC4CN2duUf1P7fTAK6vxvbzlqCjcK4CVGUdTcmLhrfNKQTi9fYvryNSg75U6iXwabecrjDWqjS5uL67D7h7ibaYaPWHI19ncS6tri0a/Q14pcvC9tDuqbiA10TkzjA+REBc21F2f+AYPntgJfWqMG2dVGOIAeiQLssifokdIfslSvN/2JjkNi3pM9iM0vkEgVOgZXBI2M3JJiVNRdwTbFLUMAwLHLg4AgJpviKAyzhWEEUq4ZKAPmriiURGANCyGaGa0YZqNdXYrytDSuhk3fGTtNha5hPXRXPqgC7rrn/hoYLhs3vj0fS5nyR502qLwEoo5k9O7/NFl1N9GSR7SLxlWDOnjufbiPLDN4pCgMsMSGcxANurwGK9vY2KqNEd5MbKhREryr/BmBszQzMZqpiwZ+KObxa64erPGdmf30Y3tv9RBANsdeYN84i4GYOrkgzze4x0iO+iwHFUFn6oGNDl523nV6dAezAwsPh4c9Zli9D+bXAZx1xK+Iw11C/0bXQPM1w0QYKNY7ny36n/v+2mzrYtp6ZQ7iLVdfkdMSqof+0FlGP20jVgzr7kPOuef9gdgJ7j3anpqC2Pzox9xxgWa0W28GoHZ7w6IrNIV4uyukp0AzRcTWCqghz7uqtOK9MnCYVo+szOsS0mcNJXN78jA8Jsyj3jBccZhtOhvkvFnXA8j1CWzIWS9GGFxcgI5yKSQDcs+8XvEnqtU7mzDHISex5JqpGt2YBvx7vA+sOifmEhzZ8wMKBy8PAveXMNlQkowwAyk8znZV4Na2sQo7mMUvF8l4AxGZ09c7vFMsamYktonFrMJ8fNI1ao3iB4TmRMddkB+m+IRZKAwTkYLqxfV6oZIferrUKItDmEYBxGWMIeSxa7y+AHNw21g94iuxX01K/ZOfNKkJLvb+w710xOTLz+fOh+qSRNX4/OzbFeRgK7D08CN/Y0q1Iw9l/JmoEBdSEizpHksFJtxc2+Ax3ZYPad1Ed9K8UN/4OffV1ERDkdPnXq/GmfwZyZ2Pa0/C7Id1Bm6fgoE8knWYQ338SW1lK5Fyip8ORJS3+DwDI4x8pviI+yQDZmUVpnnhs23vrjWcJfuZiXO6hAbcR4nG0mQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b865726-760a-4d00-fc0e-08d9ea582719 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:38.4934 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uzywADXqGDrskqoEasn6VeKZJYU6/7jnRUVhVuHXWc7S9EKINCCX5b5ffoXP10VuW2xqw9ixewtbks/kqaMmSd8afbdJGgY3TtmxmEXmXU0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::708 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::708; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Now the function can remove any child, so give it more common name. Drop assertions and drop bs argument which becomes unused. Function would be reused in a further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index 0fddb57e78..d852daf7c8 100644 --- a/block.c +++ b/block.c @@ -89,9 +89,7 @@ static bool bdrv_recurse_has_child(BlockDriverState *bs, static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs); -static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, - BdrvChild *child, - Transaction *tran); +static void bdrv_remove_child(BdrvChild *child, Transaction *tran); static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, Transaction *tran); @@ -3236,7 +3234,7 @@ static int bdrv_set_file_or_backing_noperm(BlockDriverState *parent_bs, if (child) { bdrv_unset_inherits_from(parent_bs, child, tran); - bdrv_remove_file_or_backing_child(parent_bs, child, tran); + bdrv_remove_child(child, tran); } if (!child_bs) { @@ -4891,25 +4889,21 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to) return ret; } -static void bdrv_remove_filter_or_cow_child_commit(void *opaque) +static void bdrv_remove_child_commit(void *opaque) { bdrv_child_free(opaque); } -static TransactionActionDrv bdrv_remove_filter_or_cow_child_drv = { - .commit = bdrv_remove_filter_or_cow_child_commit, +static TransactionActionDrv bdrv_remove_child_drv = { + .commit = bdrv_remove_child_commit, }; /* * A function to remove backing or file child of @bs. * Function doesn't update permissions, caller is responsible for this. */ -static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, - BdrvChild *child, - Transaction *tran) +static void bdrv_remove_child(BdrvChild *child, Transaction *tran) { - assert(child == bs->backing || child == bs->file); - if (!child) { return; } @@ -4918,7 +4912,7 @@ static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, bdrv_replace_child_tran(child, NULL, tran); } - tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, child); + tran_add(tran, &bdrv_remove_child_drv, child); } /* @@ -4929,7 +4923,7 @@ static void bdrv_remove_file_or_backing_child(BlockDriverState *bs, static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs, Transaction *tran) { - bdrv_remove_file_or_backing_child(bs, bdrv_filter_or_cow_child(bs), tran); + bdrv_remove_child(bdrv_filter_or_cow_child(bs), tran); } static int bdrv_replace_node_noperm(BlockDriverState *from, From patchwork Mon Feb 7 16:37:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D23A1C433F5 for ; Mon, 7 Feb 2022 17:20:01 +0000 (UTC) Received: from localhost ([::1]:42744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7gG-0007kh-Ky for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:20:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71Q-0001h7-J1; Mon, 07 Feb 2022 11:37:48 -0500 Received: from mail-am6eur05on2101.outbound.protection.outlook.com ([40.107.22.101]:1216 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71M-0005Gz-Fn; Mon, 07 Feb 2022 11:37:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SKgILKGqp1PSJ9faRXHfKOA8taDgf/pshek8mmabOv6ZDJsQDu5hBWT1Wh76qcM10JneskmRcav9jRYR77IUSumQxIQ6fDJj9Ox89aY3rF1ZgLbr/+VKo3+XEVcWKWNsUXWyxMXG9mSHD0O9romH68Fr7DbrcRCa7uybA5MXgZITqFefM2wHN/1V54w0xk+cduebxWTfwBlmbfO1Pu03ztM/eDGau+F5AV8lrIR5NYiubCoKBfD2PRPWBNsk7un3GE0GT+Q0aEled74jjKh3krn5Lc/FofvnZXW/zQ31dIuryfJ5bUwQ1ne4PbFvTsYnpscZiZKyMU8sC7zxAseteQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O6EErcn9fPaTCAN1xOePdKnlFzFGd9xI+8zfpXeWa7k=; b=eWBMFBmxNIEP/3F5rxpXODaxxoPNXX5ZJ+M7f8/2VdFzBKRviDp3FeFB1eo3nEqeph6vNHjcoEDGEy215V9SWOtimk/KkXy5B/ABDsN+se4wO8tT1mUV606J0lTrEYE2BwJ3pvvSyUZkj3Z4DD6fjZO6+wi24Cya2JjH1gh7+z7Yu1Cqgp+kqBLsoHgPgenzdO+ZY8e4Fb3Lj5yg16uROAUB8fbK+Y8pnQtyUKvBfRRrSvT86mdd6HUT5VTO59o5bNbYISIpmzB/hbun0w92aVlbsKkuL/Gf4lS4C3pL53Eb7nIgdFrhhkhiJhqsCkfrHRnHsPSrdMVOoF6KV9RYEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O6EErcn9fPaTCAN1xOePdKnlFzFGd9xI+8zfpXeWa7k=; b=jCT9ylAMut42B9xj19EzbJK5/EO3xg1CijdZp+6OnBOYIUX4tyzsTLEDaXLtlzSNgl+uc1uhmzIAGKvEKIkV40EwRaSIbccbOqZWZYfIf5cuyX5e5hNAIXGU/2twkMPYaIU3E0Dt0kq21jzfZEBHLFfZmWnng38HPwCE4AC3Bhc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:39 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:39 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 02/14] block: drop bdrv_detach_child() Date: Mon, 7 Feb 2022 17:37:16 +0100 Message-Id: <20220207163728.30362-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebbee222-966f-4303-4fe2-08d9ea58275f X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kLYPg+nvqKnJS8MQ/LtFVoB9aUgcIrsfZAQaEVegzKHot1YnzAbF2qNRRuDxW1X1p84nbWn6VbPdA/rzhBASrxN/fCV5GTEqoZQkUr3OYP9hhRmFXHM0t5k2PxVoRqBkIYDY+ceBBeAmvqdeUYBNR2AuIvVDUI2ksW9Ga7iUZfK+u8lfiTP1GK32d+AW5XO5TIftG85E7N/4J0Z+QxqiLNTbvGmIY8Sw2P+NQtLwUqQ+J7iTn+3jAdqW0F6eHXnSiK8/5GB5a6IwudgKZNTmjllowy5xCwAMvwiF70LztgecEdOkt5b7yAxhIcv0bs/9j5b0CwQaBUEiBOtzVv3Br4WKevZwL5S9lWnRZZzE9/M1gi9zePaHrTnnbQ2vnjMVCbD+nfdzNIec6hbyRae05LgxUlspaSoiCKXU+UgA51yXMcQ21C3HJ4+64Ol+9mZcUyP+OcjW6ru78erEVYzd9i9on+A+gY+yGM5LnOZkKlo0Y9h3M8hQkEEAVzXaoIRbc7iu6d0/1EqLrvSXxBHxngxgHkUt242n6hyUDPrC+yoii2fs19BvjYZppupFW+H/9XF8pcS62aZi7Vm+KPPDVPY4OYbzmY4Bhe6ktc0Vo/+IZwa9aX3Ms7jEQhiB/jPHTX3y4HLK2BqxvS3wUiuPqOSSsAEMFPmd9iaGtOmhPRQ1J0zApPtcI5bcpc4bp7zvZde3qRzKbkH80BAhLBj//g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CZODEPAB2xQO3f6/qOQhvPzTNpSiS6NF/MnxZZEKIFWG16nvKlsyMOtuwTgly/7BiqHyWYpSDV2cKZrl5NpXfSg9kVGSVr7CI8H6NOvSREmEWihMuNKGuvlpAIYygW7q4+83lTptEPg6JoYLG4zIqfKJBFKMM610FrbmycNSof4HKFHMooczHcGLafJ9WwH/gSwYM1TV/cpW7NowDJ0X3zwpLisASq3rKMQT4mF4Wm+i7IeRdnmQ5ogxVNEeO11382O/wCdieVY43En7Gg/lyo5HqkryKEFeHz2AimEmxGTr8VTt+s9UOFjDnyQNUghEHhptZgHFUiIUNJ/aBB7du5fto23+XcYf75J1INpNrLXC+GS/HV4NtW9N2x0nj7pqhn/CgViylX05NSQix5RRMTRZuxyJSESleW6dPzO51aYoDwfHvXfzYS2a/V9C7GKT7uC6AAvSDB/TE1oMcKXZ7J6jHIpg3oplm/1ZkeWkPTST7UzhCNpGBJuaRyvZuwNlhMxum2ZuBudyXDhE1SruiIyMoQXBVwola3kQzGLWs4X7N2J7MzWxENLsi7svAxBVSuuS4r6X6QZWE34KbSc4spAo55IpPfbwbrE53JxD2b2/EUn61GOmc8ZQGbaTgc+XC/+BMtNLYiI3Z+01Z3LSxWQlmN6CxG7VtKhmPT7XGQE21aHhZEAFKOkj17SGNBeIL6nQpMNFt73cOHisLm4ap+LeAwW2QftIOV02++P4S40MZiNbIuYpdSsm7muVlW1IU77yU4wckKFYgK133gBhm1C+medsDpILmkA2AJRBQz99JGJlnKPVAX9tMIQLsnDMgOSagkT66slNqk2SDf378UzUefMbAJJAbzuVwLFeKgjf+QP7MDGtgbz49x8FbVVrQIDEmEUT3RtjmAa/bVJPyjCgdlGTd6sBwwDNQmLFC1YXshYEyUoVSKaHFmtoNpZI0E1pjlqaxt8T83GEe4/ZODmgBANs9jVCCv2akNUjMMgWt6AwLonljXdkS14yn4Ar/MFCltSaic/3NiVRg+eYa8Oko4n4EbzLPIJjjyRuascbI54PMho4g7BzjBvHFPi9DEGDfqtUYn5xkvmI6VuIRFEC/X8xBeUYjfl0D70/NqdsV2uJlJkLj3xhe+l5ohSihyaFBw+6EOsllmBqLmNHBYbK9exx9MLMyPdrSIPiggHIXefzYfB2VGBYVZjOupxlozxmlJIJrPJIqCOQvLW5JlbRbacjc9MYbttxcWEVb8w8la+JZMR1X024QDjdV8/aBJXQ0ZekjODzqDqLyAvnlFeG651qTNdEzV6VCQ/Oz6AWPylni9t2sKc/0Y6ydQBWJXIp1xae6GCGtryhRKrzoSHXRDHHL8X2moO4LGHeRBh/jo7yCxnHlWIdGhSYRxvYyJ7SwT4usjh6cWvzuSkuocugn2FWPiVbcrCilDnsh/5ljWOsjbfs6GQEBsMhbxsALpKiIQn8k418o3+BQTMgfBUsE+90SFGLzHcmgdoAVpdYjqcc+UmpeC9BAG0Clq3eYrQ5iw8V4Mk8ZhBJF9j+Lj0AUQEMUXAgI9G8FGn+UBv1fa2VB0FFZqisInpqAx3JgZ1IefAqRIKt3yeoUMuv9nJBVHoCrfItkQzQE9jk5RtZZMvvHpwo90Gd1JKRz8Pz+ALicez+PdZDLtYXgkg/PQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebbee222-966f-4303-4fe2-08d9ea58275f X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:38.8996 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dKC6DCEDHynVbfQmGV383CZ3Cib6lwTUIsiqcGubdyx795ty0M5Ty5tSjnL2RtA4LE+wRNRZgGfVmBGlsuvynttWz3hkzGlN6SJ9lVQUpBk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 Received-SPF: pass client-ip=40.107.22.101; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The only caller is bdrv_root_unref_child(), let's just do the logic directly in it. It simplifies further convertion of bdrv_root_unref_child() to transaction action. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/block.c b/block.c index d852daf7c8..378841a546 100644 --- a/block.c +++ b/block.c @@ -2948,29 +2948,6 @@ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs, return 0; } -static void bdrv_detach_child(BdrvChild *child) -{ - BlockDriverState *old_bs = child->bs; - - bdrv_replace_child_noperm(child, NULL); - bdrv_child_free(child); - - if (old_bs) { - /* - * Update permissions for old node. We're just taking a parent away, so - * we're loosening restrictions. Errors of permission update are not - * fatal in this case, ignore them. - */ - bdrv_refresh_perms(old_bs, NULL); - - /* - * When the parent requiring a non-default AioContext is removed, the - * node moves back to the main AioContext - */ - bdrv_try_set_aio_context(old_bs, qemu_get_aio_context(), NULL); - } -} - /* * This function steals the reference to child_bs from the caller. * That reference is later dropped by bdrv_root_unref_child(). @@ -3053,10 +3030,26 @@ out: /* Callers must ensure that child->frozen is false. */ void bdrv_root_unref_child(BdrvChild *child) { - BlockDriverState *child_bs; + BlockDriverState *child_bs = child->bs; + + bdrv_replace_child_noperm(child, NULL); + bdrv_child_free(child); + + if (child_bs) { + /* + * Update permissions for old node. We're just taking a parent away, so + * we're loosening restrictions. Errors of permission update are not + * fatal in this case, ignore them. + */ + bdrv_refresh_perms(child_bs, NULL); + + /* + * When the parent requiring a non-default AioContext is removed, the + * node moves back to the main AioContext + */ + bdrv_try_set_aio_context(child_bs, qemu_get_aio_context(), NULL); + } - child_bs = child->bs; - bdrv_detach_child(child); bdrv_unref(child_bs); } From patchwork Mon Feb 7 16:37:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2FACEC433EF for ; Mon, 7 Feb 2022 16:49:58 +0000 (UTC) Received: from localhost ([::1]:59604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7DA-0004EK-VX for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 11:49:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71W-0001uj-V6; Mon, 07 Feb 2022 11:37:55 -0500 Received: from mail-am6eur05on2101.outbound.protection.outlook.com ([40.107.22.101]:1216 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71R-0005Gz-1S; Mon, 07 Feb 2022 11:37:54 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eLzMV2jWpX9n8Xt/xEIrlqQ0b/RKk4fbSwkSRMEcmoXl1WxG50WNj/PYql3rFO1xHSh8SaIlhCncibjPyTTB58/cNxeTygn2d4l3Juz97rTtu5i8CMwGNp+Q+lKFh9rn11o/MYJH3vmcjFAQmaX0LyuvQSak8lJDJWtr0KkL09kCNaQLbRSUrJxuJ7Qy3BI0mbOcAfUmVfSrTK5aYAaAdFvSuslshT1hCBt/Sqm+6V9mGvv/1DpEvwFQA27QbGGWLeuP+mSKqRXNq/F0jObRDTkgw5hWtP54R9Rnr1Vf4pyTB521wAS3zKFY0BIP0dekuFrwJ35j/tYfmIV1eClkXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HieOdbkksE1iny0YXh1qWbUuWw+LwUAx3dDPEYDN6vo=; b=eLKQwCSUT/z7fwG/4R+kQ81rc/vwQ9M/pyTelK5gKO9LxuZhAsps7BY0TP3+nRJAe0hM03dDgDKz6x1yAiWJcxA8gSOikvTMyDwn6SrfXU7OBodEOo0fVYSoRKuQKFFfqIUNfQYh7ke+uAnDn/6l213lw9gI8a/+7ue8TdtAkAh0sRcsUbW921RJaVVXY0VTMOJNOMFmMWoz0Ia6UODAH2pC2nQvLP0FYnHyC35ZYofCCIMXJZMRES67Qyg8zhqacQJ7d2KT1Dpdt9RRZ6ldhYj4bVZyJQ/HNhiRtXCBmNlAdosto9S20mS8NBC5ZHU2jDlwwWhp+Td2FsEl43pQVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HieOdbkksE1iny0YXh1qWbUuWw+LwUAx3dDPEYDN6vo=; b=V8n7y3sAbGRrYD6/WLsj2YBGXCVTCXLHCudqgKJ8vocjN1hjLosG/ZCNR1ljHrDNsJE3r0sZ3VcJSuMmRXp9Ef2+GBVZc5Wri+8S/KOQBuCW1HfayAaO6G4UNROqbndiplq3RNpzCxSIkcp8FGaK9pYslij+v3WQgk1e/vrNqQM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:39 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:39 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 03/14] block: bdrv_refresh_perms(): allow external tran Date: Mon, 7 Feb 2022 17:37:17 +0100 Message-Id: <20220207163728.30362-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd1b0d81-fc74-44b1-fa40-08d9ea58279c X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yxdNlglfe8D1E7LMsX3LGlYAPfbplA5Ggd07jBYIgksrGpXUNEZGtf684CWgKv5ICGDzWUK6MsnjEN2XXAUmuXc4eXHC56fofxcMZULUuqjsOf6SeewK6jHf6tcpaNF1OH2tGfwO2ovU5wHqH8GCdKO9yUxBHZ8H3gNTaKrXv9VtO13lfr+juydgvYWWX8DebMNpLok8Qj0HR+O2wBnD9WGZmLKvUpqe7szux1Zkl/Sfl0FvPR4TJjlBbOL5UjAxIMuMe2xH7M5nrHKHdO4DdqDsMvdMgrcy36dVO/wv4Ykwx50h6huqDTAbPUaW6j54Jmu2yAHcAgVPybYHkS305f1mAjVJv/B303fhaaikJ34PSAxY5ev/XyjEDLx6dENMQSY2oJg5OVlARe3oy1zYAmKYskMJ/qdbqkgh4V85Ts3V4yymyQMu6j9q/+6IUXwMVF7qcOlUQm/TktvqF9LA7SpV3b4TrFHCJoVnYFnGSGVY/rOhJ1AQeSVIPVPpVUxcpYuT5SJ2HNQ5mrFhES0jUQ1jWA1NoHGrHQ8yzWGmDrkkMRMmYg8V9kksHp2bCk7fUIAVuotLd4q589Y+pbybcWvJB7bx/emCmWZON83nAbM3hPD8EBJ2Bp8pn//Vm17JbAkswl4oKgUVyEpbNrxKTvushyD5ED9LeBAUFIcsTE/6WQNSZnJWg+tI5q0RwgQWqu9dHDv6XEQfoGfsCaI9Ew== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QefhUzMB5+my2LDaYXzMPal73xDWGZbpCYlIIWqbnl/LJplZvRnqXL29mzSj55lax9DmHdtTsniCMNLhbT7HIQCV7AK9N2DfMB4azE15d0Ccy5FlWiU1qVsrJgu0upgU/R2HTuy9xt6oJkyaMgVH7sGisE3QDSFZqCjjog8D0bkPvO8+vQky/pNesNyz/ccBpLOTxq+SMnfWfzh5rWHZcaxRcpXP2bN4TW21MYqqiOoWEXEuAAo8TTeQRrTJT+4e65LL7zUvMfVEwSQjsTA08Q491fY4kTb9/MeO5ck9JqO0B+bhOflwga4ZY/xW0cJukJUk6EN1d7YrxNKkbkWDhF8C+GMGMWz2bfaYYvZlpSOXkvpJDFmCY8fLULDyJ94zEZWCFlEpLMkwi1MhUMdc0/bLfY8PMntvMKBxwKAHUg6BAVcXe6ut07aSQeMkAP6mKR0MP7G9fhjk2UvJdoAhzEGQjyB73c8mmFnJH4DO66It4JRv11ZMWgTsCfvVEa4wy189p6bq/FEfA4MFJs+ei9AZC7gsk/GteUExreH1v6CsaKjDYrnz+MyY8guKVSxaloR+SgoVinb7+54G+XaGWmn0cjU+3sOuAZtwOOKo9jU8PeAQphEJaNCBKEY0BPSlXtVKDDY0MDgG6DWY1MIIP4EBg1VrMUskvlmC+P7yC6n+1cA2VQNWJMroa9pGDLO18cvLjvkPFt3zTb2vDQMP1kPKf0N3DFlpJAeaV3ALpDkXdGN5BfzINJfIOkFG4aE99kfNgBjC/e0nAZ+Dz8aQO64E4jEowe0of+Oz9snKX9jn+FQY4SsFx0xTSJNR/t5Ap/rvA7cjp31smt9t38z2NjO3+oogUHXsL2VaSkKeZD1RyKx+TtPUdvA4uPW4nYOPpMqby0Uz9hv/kTjdk5bKE7unNYYi0kUHQuNSVi6XoXhLUfV0lDBH8P67XEfmlN7WGaTsAC/bYTF3ms4ArMprZZ18UxENj+bBXkOywIEBnV5+f/vxcWHuewQIlp3kRoEWnUJ+sGPy0QdLYv/WIp6xzCWya/zTM1meTfrlZfujmYmxGDEADtCMNnSiVzLH0hj/pZ36lvvuRjcYNzl76XCo4d/cXZVLB6aHxXuTdENb+5iwEOB0akd46j+S7rINkfzlcLdMUN/IgwoOaG5EQVDGR89MIO6JmcLxpQHfTJECrHo3ucPsu+u533v88XI6qkq6Uu+rm9gDVLaKlUjwvrl55kUVnDeIN0TGsEIE4bLuDvCN4+9p0zgg1JBmjWXAlst+AZlbsEEO2PPdNMMIX397EdWVV30/X3UZDGcUa8kK2JixAGfflTqvmsDhTdTVa9/Wc7ZCi/kuntqUl+tsILGb6pRez0zL1fne8sxqGmkmUI7i7nfCeDS5w+7qe/7D036l3+uZX7BIGclzpaKtu0KMBNuj/KjlwjUvqdI2oDXfgvJngov9SFW7ZSjdfHkrC/cQXz2f8ctTq46ZSJPgNMoxe+VmIZz0nn1o+Adu9rb9JtF5Hd5BGIoqOBp+KtJUquqGIwd42acZ9Cy17dM436+YaRUGRbAt2d493s6FFAu7EC/Fe+jRnLbUmcQtRta/QEFk48/J6M8iq/Vj4evMhppt6Cn/VbAZokXp68DVY+iOcBm79dAIlp6QIRUc6hjcFKU3lzGM+6KUrY83mmYMEsMoew== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd1b0d81-fc74-44b1-fa40-08d9ea58279c X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:39.3037 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rGKHQLc72v4gZDXjCtnuq9DUAIkp1z7AoqIzTj1yVaAJGR2Q1wP+mrJy/QrevRpSZiOOE/vQr7IJ0EaMdkqCLjiKLFu3YTDGs7sPqdveygU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 Received-SPF: pass client-ip=40.107.22.101; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Allow passing external Transaction pointer, stop creating extra Transaction objects. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index 378841a546..7b65c7c5c0 100644 --- a/block.c +++ b/block.c @@ -2475,14 +2475,23 @@ char *bdrv_perm_names(uint64_t perm) } -static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) +/* @tran is allowed to be NULL. In this case no rollback is possible */ +static int bdrv_refresh_perms(BlockDriverState *bs, Transaction *tran, + Error **errp) { int ret; - Transaction *tran = tran_new(); + Transaction *local_tran = NULL; g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs); + if (!tran) { + tran = local_tran = tran_new(); + } + ret = bdrv_list_refresh_perms(list, NULL, tran, errp); - tran_finalize(tran, ret); + + if (local_tran) { + tran_finalize(local_tran, ret); + } return ret; } @@ -2496,7 +2505,7 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, bdrv_child_set_perm(c, perm, shared, tran); - ret = bdrv_refresh_perms(c->bs, &local_err); + ret = bdrv_refresh_perms(c->bs, tran, &local_err); tran_finalize(tran, ret); @@ -2976,7 +2985,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, goto out; } - ret = bdrv_refresh_perms(child_bs, errp); + ret = bdrv_refresh_perms(child_bs, tran, errp); out: tran_finalize(tran, ret); @@ -3014,7 +3023,7 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, goto out; } - ret = bdrv_refresh_perms(parent_bs, errp); + ret = bdrv_refresh_perms(parent_bs, tran, errp); if (ret < 0) { goto out; } @@ -3041,7 +3050,7 @@ void bdrv_root_unref_child(BdrvChild *child) * we're loosening restrictions. Errors of permission update are not * fatal in this case, ignore them. */ - bdrv_refresh_perms(child_bs, NULL); + bdrv_refresh_perms(child_bs, NULL, NULL); /* * When the parent requiring a non-default AioContext is removed, the @@ -3277,7 +3286,7 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, goto out; } - ret = bdrv_refresh_perms(bs, errp); + ret = bdrv_refresh_perms(bs, tran, errp); out: tran_finalize(tran, ret); @@ -5067,7 +5076,7 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, goto out; } - ret = bdrv_refresh_perms(bs_new, errp); + ret = bdrv_refresh_perms(bs_new, tran, errp); out: tran_finalize(tran, ret); @@ -6297,7 +6306,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) */ if (bs->open_flags & BDRV_O_INACTIVE) { bs->open_flags &= ~BDRV_O_INACTIVE; - ret = bdrv_refresh_perms(bs, errp); + ret = bdrv_refresh_perms(bs, NULL, errp); if (ret < 0) { bs->open_flags |= BDRV_O_INACTIVE; return ret; @@ -6422,7 +6431,7 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) * We only tried to loosen restrictions, so errors are not fatal, ignore * them. */ - bdrv_refresh_perms(bs, NULL); + bdrv_refresh_perms(bs, NULL, NULL); /* Recursively inactivate children */ QLIST_FOREACH(child, &bs->children, next) { From patchwork Mon Feb 7 16:37:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E44EC433F5 for ; Mon, 7 Feb 2022 17:31:35 +0000 (UTC) Received: from localhost ([::1]:58258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7rS-0001zE-1D for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:31:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71T-0001mA-76; Mon, 07 Feb 2022 11:37:51 -0500 Received: from [2a01:111:f400:7e1b::708] (port=37729 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71R-0005HI-01; Mon, 07 Feb 2022 11:37:50 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AnzdDe8qoIC9Et1m4XnrnrQ56BZK8ZyGAItfQXJ2MNwgTJWzBDrT7Z17fdsVFZDYcudpF4idbtyVN2zzJRzGwEZZPh9iPze/EV1rJ6YG0Ugpvuht6Rg0We1lT/o4EAZNs2bO3WfvRRgJu/swBN/NB2mj4c8It1TRromBk55an/ueJaBl1CaMbj9XCtKllgLCXY+sGjyxtQ9aIfv7UlIEh2OWkKBA+dbjh0+nDl+Io3DnyheGXL1i7cOThQ1t7Lx+49k5O5BiWnmZ9eQqzk1GZryIQeayS4TfJgbdyr+67CnLTRQqxcvBjfJj4NAawgGSIVg4flpE6Po3pzcqe8ho8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s7GFdhK9WnFzKeTGkO6aPU0eFbuWIrLwLe2fmSJOgXY=; b=et9p7xv82GBpnfeaBOs+peKBnPBlg0IFgYMRsORq7z+eFNxO+nYtFlXcUiObFcLnWj8d7iCTG6asOzUxHNvNcDUKfmaC5MV0K50oDp7tTubqKT2i6L/h7Y6diucwHsybOGC8L+yGOEZ8QU54tDmRt8c36l5hJud35eORRWvpzVR65fNx9H4AaEvBKsHlgR56E4SzHJ6ceprb3zTBEx23ggI+Wly+TWXVPiKFyQJ9rJXD9JjtoIPUqdpsMVvTq9fG+j89bBaJlooCHn+qqhYAdE5HEoNfjhJAEeJDTZvelxocWAIb9vqk9zzLHj0mSg5B9OYSy7uglW6xcZzKkPropA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s7GFdhK9WnFzKeTGkO6aPU0eFbuWIrLwLe2fmSJOgXY=; b=P8FTCcfd+C+d6437sHuvWQcJvkWh56RkQRgoUo8SzLSRP3Q+VFYxUeI9PBUnamti6RsDEOhQchcdQWTP44SmFMDlhFTTUXCAHqgu280mIPm1GslGtaD1/m++5N1E85qCJrFYuxjm4AxwWH4jxaNC8h1+nHlMkb1J7dqD784KmF8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:40 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:40 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 04/14] block: add bdrv_try_set_aio_context_tran transaction action Date: Mon, 7 Feb 2022 17:37:18 +0100 Message-Id: <20220207163728.30362-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b1f7695-2840-4329-f471-08d9ea5827da X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:14; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B9mpEobuZjif9iXzTtc6Lh7ND8+8FIaMgJ9ljyZ0f42559Lcew8eZUC0btaMuoLYsnnt43yxlrtcFtfxG8RmaEVU0JcMt2+8IJGsEJotHRzj5iqwOzkhaOpPDdp3bbl3jHBKPxphRe+uP0RPhcGVRqtJ1CiihxYTJ1tm50Q/TRPX9cd2WXzB2PobP5mgyXc8h2DyhJVxeCeuAYyEQzNMUzPKDGEjrMNIH+MB8uPCza9cT+beAwK9DYXXErYTbQJebaBr0J3LzkgRAXuPKqg/xYnXXB1j2q/RJ6hye4JblSfKsycOwLb2W17ncwJMx2OJJKxTCiEMgNqC3lN6mgdH50aNAWr9EIhZZaDFIUcsUBu9yNDdhM3lsIwz+h+169yh1P3IWgyxnhC2/dgtmVnBt4G2NRJ0BXdUbeCOEEpy4YkkNxJ/SSTQZkGX/RF9TGWwTPCrTDdgwy06IpCbqo2Y619OP/lkCDj2Z6QgufkK/yD1eSsOWrsfFwRyFXSfsYb3CwJ4Qlzr1WicfiFYYXI2ve8N4z28tuTYTLLYblIcvPB9uQRFg1eB41x3OIMSYeUMh8zO1ECrKSsFl182kLNCvxJCBhpGR7jlmNOYHuohGHzHIp1dHpZjgy9zY3/JmKtzJjU0C1OGqROV6QPZLUxXS1Rai2ezTAyIQhLc5fHrV3n2Sqk26VgWoOmF/QTHDvyy7DvlQHPuahjU497h85xjWQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kny8ZL1UyAsR7Y21+34fncLDnw4oE9Qg435xOnPZd1tX9NdLQp/qRVArVuHRrDpRB6OWtysUChkF5Rmusgh0woH6+M/ddjDWPTBoIXt8vGljwBT30d/Bp6IdcyGEUDE7Ia1iX8JtryoqjEqbWZehmamn4ebh2TztN7jrgj4AjouFrNRPzVZo4GiKNTWmZpA/tfDq8VjvTY921/u/Ny2x2i8VUaa13FyhRRdNeB7AgTqa/6md3ln5wo19MNVp7ksKlX/JjDOftLf6ekk7shTr/1nRgywYD5Ih5I8gsOVghPc+QWQt+Ya4ZeU+vYgkKeri8K6qgSSE+nj4PVaBlHOO95qfaqt/eeswRZGUHC6fJkzhPpWqLNZ66YQhUr6uiXVn/qvXEObU+ghWx9BoJahovJoZ/gDJf75CA0Zx9oNUtwK/KJ00E9ErhV2cYI1dy8QrHk4zsIIyMqGPSCH/hsUQy9zneyzuvL00tB2VhSs0k5d+W2/0vWeYeGhH63irGPsMUEVxaEikiwgr9r8jJiBYyJR7wqoYfxEPwbAtBhJChUAV+PMu+6mpdMe3JCk+qB5RN4kUIWXGXgHKCMKCtzbRfY18A05T0stdZGaI6TZvrpYg8tTU8z6PDho8v3VxDaV5RfTSi70EQ4r/gPDazVWJqOomRIpIyqDDD7LZZtpfa2Vq/bhnosWh6pZpDdvQDfD0z7S17QA28qQGeajKhjvtLQ46bWLeXGoga76gCJkj3Jeim5ftGKyYckFrcj3A1BnMGtQxBfiyouc7gjLoeR8VNfJKU6G0dBwyzFB7w/u2sCje11pocYtNu3OQR0TAfCea2GAQTqe4Z/shtpE51zeam3NqPUi8QErRpKLRMI8ewmESD9/gI0hcatynoZ/VsQoDv51BqyW21sNiEl7GfmVA6/69KJw2Da9sB8ScKQX9093SYhC9XbfCM027yYE1Pr/eu5o4hhPJbzw3jI+U5NmHz4HYFFXLhygR3lERO22PANtngmlc5tS0KBviFeasNfSBxx3fWnOZPpqoJs7YZwpWWs+Jn5dHJb6GQQJZVhVNsEZUlPneMtpfwGLxryvcHUZCACK/Ails1qSK7MIviN3KLsGKOSYOETKcNAK7UDTVRAxXVYshQVd8XjgsuCtidWtzqu9mv2k07l6HDcHvx8WueYN97aod8duAS7I1iJ1sFnyANZCmgT9LqxCInolqOifA28vpxjndv8loTJse+H7eilWaGNUrBPnqb6mqG5hyhpAvr3CRR+Ai9/0UtY42zofJeLkjPCYMl/Dyvy0F5zDIegokctDOi7/ijHHJkOIOhzPCQlMEuuP5SLbu07k/1oGPe/NUzX5q9xudf93Cb7E9RsWfTAuJWW5/OZ5xJu/KVvedrKo/LHs3nV+HeHj4uX30D2I6+la4SHqNrcE4fs3YMlHzVqIe2vKqE6tPOFSstTrnnHfSB6BQx3hFMDHGe1FhekYkWiw6vyOTNjTtJiloq3AKUveiCOBX/jEY1J1QNutAyfgmuENhxYUacX6u3XZqsTZ9PVNu6/jjPmOPtOzczMpCJJsjyYoM92wc6uB5C79Wj71kas1QyCz/cYJdv6OlBFJm3RXs42Sfv70qpFsTg6fY6LqMRQhUYc0VzWmNpA4yCOmXt+ypOiU4LyF+7Y+TJFM+/A/PCrNYJexWkuIp8A== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b1f7695-2840-4329-f471-08d9ea5827da X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:39.7880 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: A0gYkYvSFGd/qBG0yjOoS/qq96hpD6kN0/3fuZf5s7IvWn0vZ2Gjg7PLqwsEg77glpm+O+htXdf3EMcz75qhGzSCQ7OmsVKW/ThiYDoWBHE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::708 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::708; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To be used in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/block.c b/block.c index 7b65c7c5c0..82fbf81a3c 100644 --- a/block.c +++ b/block.c @@ -2791,6 +2791,54 @@ static void bdrv_child_free(BdrvChild *child) g_free(child); } +typedef struct BdrvTrySetAioContextState { + BlockDriverState *bs; + AioContext *old_ctx; +} BdrvTrySetAioContextState; + +static void bdrv_try_set_aio_context_abort(void *opaque) +{ + BdrvTrySetAioContextState *s = opaque; + + if (bdrv_get_aio_context(s->bs) != s->old_ctx) { + bdrv_try_set_aio_context(s->bs, s->old_ctx, &error_abort); + } +} + +static TransactionActionDrv bdrv_try_set_aio_context_drv = { + .abort = bdrv_try_set_aio_context_abort, + .clean = g_free, +}; + +__attribute__((unused)) +static int bdrv_try_set_aio_context_tran(BlockDriverState *bs, + AioContext *new_ctx, + Transaction *tran, + Error **errp) +{ + AioContext *old_ctx = bdrv_get_aio_context(bs); + BdrvTrySetAioContextState *s; + int ret; + + if (old_ctx == new_ctx) { + return 0; + } + + ret = bdrv_try_set_aio_context(bs, new_ctx, errp); + if (ret < 0) { + return ret; + } + + s = g_new(BdrvTrySetAioContextState, 1); + *s = (BdrvTrySetAioContextState) { + .bs = bs, + .old_ctx = old_ctx, + }; + tran_add(tran, &bdrv_try_set_aio_context_drv, s); + + return 0; +} + typedef struct BdrvAttachChildCommonState { BdrvChild *child; AioContext *old_parent_ctx; From patchwork Mon Feb 7 16:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2AC6CC433F5 for ; Mon, 7 Feb 2022 17:48:48 +0000 (UTC) Received: from localhost ([::1]:58058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH886-0005JE-Q6 for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:48:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71X-0001vj-PB; Mon, 07 Feb 2022 11:37:58 -0500 Received: from [2a01:111:f400:7e1b::708] (port=37729 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71T-0005HI-PS; Mon, 07 Feb 2022 11:37:55 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=duumjSqhp1sHb2kGrm8wDbknwnrOqn8n37m4SZeq3fHgrdMMnC7yF3rgSExH+5xs3XvL7Kc5ajgt+yKBu/QB0i3G3VOIDt8XGiON77xC1IOgBB2XDp7GhMpaO/uMvF0WqJA6L9ub89xTULyvxFinmwJzk+n3hZ3bCd6v7RSoJamQspDrm5eRFTBw5aAwijZxHDdpy79CYJgfyJVWPweAwrz+sOODCkpLE0PhRACcG1IMsgnH0vvizUzBTp+2lG4kpcLTYaOV2mizSuXJgvPzVa2UcE/K6X1umqePnzbxs5JbQH0ho3IBIvwTii+4RbL5DF5NUvbZFqbRX36Gnf/ovQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LBf9Wv2yMBcKq8er3VGGXeluEAn9O2+bmsEL+pVKm+4=; b=ftdX8nqwBqGAU95rrCOX5p5nvVqso1c2jB6tWYc47cdXTf+sLLp2ln+IWUyNALjSkjqtTU1ylrU3zkRRvkxD79CB+oxf1/aeflev/wWe/7HZKr2ztWV5vd6ZJp0wIgd08i9i/uTHKL89LRhERlfNIBT9sbkV8PopGc84Yh1IaeqmGPJkS3S0fU6Wn+N9xapHCN8vJ2NiKkmM1+DfRvyaimut0NA0uCrLOF6lk73oUVt3XfmoeJx0nJO7II21BPSgRgcyakLS+0jLjaD+LacQGWkAUH4vt1a60j2S0vB/MtNGp7Dbg4G3yeI4wWh8vLlH+z6PKaH0pQgfYzUCfvaBcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LBf9Wv2yMBcKq8er3VGGXeluEAn9O2+bmsEL+pVKm+4=; b=tGdGtjz3cj/TBcLQGDkWauGcoNA4F3rcMukhn/ERPM2IU/P7U//wH0VMtLcrGRT/g43V+UX5AkhV778acpB+s1bsGgmXCeHaNcQdFkbdhpzBU8hwVu5hTwpBz254y1drRlaBTrFseKnOrjmXafi1i0ca6ZnIaK9+5GbPa0p3wDs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:40 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:40 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 05/14] block: merge bdrv_delete and bdrv_close Date: Mon, 7 Feb 2022 17:37:19 +0100 Message-Id: <20220207163728.30362-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: abfa54af-e0f1-48ce-00a3-08d9ea58282c X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:245; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jgpaCF7naCPGMogWEEXsdkeh5mIeY6weWSPQPFcymVQ+4AgwDytKjVzmXyH2XfYSncgU2K/CJnluDUsUvLA435Xt8IzHvi7Z/1og8J+rsZNG3/RQ7lKBzyKOrFYFve5X5k3e7mPrrEj/Wnss9KSLmnQuEb1JN3eUfqEYHYuoUvYNy0HFbm5zN/gOQ63Z/5UlkvwWfeGsMCblGNVzXDimK/tEhewzntXnNaj/U/cIqkwevW6ch1eMd4NIoHQ8dOPtroBUbJFjKNJiYYqlDvFTAx+Y2Oz3AEvfNx9ZLN/yM5q9oSHi1ig6OB0RkmVv9Dlrpwqh2vPCx7Q6ZZAKwoj/cQqQIbLNW468aX5KzFwCqB93nExwcD/M+QHpVBV8rWMjUtV79YTr/JTI3hsoq4HcPsLWaLGz569E9u3OEKH/yBhUNxPg2oZq/OVlelr2l9O7CslLQtJhGiFk9YlNiJdTOD+kFKLDfMTFoZLVjFk1fBxQBmkOPQC/AeSy3RoFQud0bLUmkjRgu8XvsUDTEJdRzzmEoj8XqYm2/a8B9DJgG1QLuLJEgf2tnVFoaaYebuSc5BJPVtZd5RuLd7MzQCy7liIc35FHzgek8yJluXA3CHMU4Y1APnPzTdeR7lrDrAEkO2IGv7hr00bhdNrsJ9BOPk8hrA8pV3q/06GSUmnBfpveKNSzbsbK/tvp/OXhalKk6gXgd2Gq5LCyuZS5iA1fZQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t2BbtW4OqRu8MURJx0oQBWq8CcawPbtdgzK2FMI0wAbIAbOO4rcuxI/yhMDNKzVgHrv8ddF/EcXPY7G34FoTCbUV5sd+NBUbo14ctNOGQfydWJxrSY+SqRLIC7cZzFkT9Y2zl2Sh3Sk+vWB4v97UNrw7+YXkbIM2Vk+Al3XmSU/17Kr9sNP/lIkq2v8RDVdh+iS2IRtdcVViwJiiisI43rhkAZzUyJV3+Hi+wklh6F8cQ7AL0R5rCQTGcV9ef7r1YOzhju7P88pt6xOBlNM7jaFi+Xh88LihpUBmZjnDXTV9P7DkWLwECC0VBbGuCnEx4anjqZLdDLD2ZnuSQ4ONqKySgj/U+Z8Zn2f2qaYeSTBOioMkNKshmEVk+8nYUDNqOTMgsnafLszC/knxYCjUkTHfmhthG9pv7iDkbCPNboDJ0n4O3uaY3CAjWT6RrDipyeaqLOcrKi3WwswRISzhc7XDzRU6UgQL4bRg5oeqyQRnzZ/77ua0e6530pkP3ZOD0pkZ0qRBLL+DhmUBzwZh97pAxHlPmGXmUs9yt8IJYxN7Z73HXgIuSXkZqIOYkKyqAXP1S6PFT5JdMfP0AdAbQChLaPPTLkTUAskbSTvpt81RNSQlNIF6ysAo3itmYXr8Bh2Bl+nRyPi1HZ9z4i+WDsMDtzn/j4VZHNDHz8GgGoKcbstLzJ9nWLEr1GL1137T9UFrxn3BuEIbllaiCLvP8iL0lYo2YeJUGGihyvJAvDjBzkWqCvUJunbir7u+xwlZlqulxNrqpXVhSAbutCLwYgS0t82jZKrCCSW4NKH5uICQwlGLo0jDigsPrpGRSdWsTFzmz1DET4pU2lIhIYsHOrIE4oVolgj5yU7HXQX7OF2tehe8MDDamVxG/xBB/eTDFOr9hY6uY8c1qWDAvIh4bocV1PuGwri7aadl5lkxJBGhTKIgLb8mvk8amguZlXbH690FsmyLTDE8RemYuUFQwZBz7kLx3ytho5PPUHklPFbn2pAuCsSeWKJ6OliZvg9FF3RxS8npBa4c43z923aUa8mS1KR/9Kp45Ufcl1/kF2hN94FCIRFL0x/JW24x6dbPljqkjC2qnMr1ZXCTbpmdEyi7WFTLL6F0g8LAvqUAtQ3Div6hjuNp/tVIZlh8TxlQaeCz/x4GCvCXcrl8EOhDecHb8kCNb7a9eJdLbD4CmC50Q9sxdSIo7evdqUrD28cot4J7d43GllYziUqvyJyRdyCGP4w2pfmSPLveUHW1XLlIifXPdI/BWSKJy89m3HuGHqG6sRIp/EVrAp6CMJOqvksfP7R6bpxAJXXX38PYWQuGlOp8GlOlb+FvfFwYb3uljJFbAvdX3jEsRYic6T7X6ymEjJmQjLfg1S+SXrbZPWKUzhrgkIK6R31ZVYzZHyGZCR+FgOkztMTgLgYM9QQKA4hg5dgfPNLxA5Mbo5v8nhIZV2dXlVApypoYYFnz6CHUrzpObDgx24wABdqOanG3S3xOmwSfa7CAaBOGa3FwH/Mg+bpKr8zEwSfahi/eqG7PJtZTlsVQCaYz7imdDXaGVDD3TIjsAsVlHMVmYtvakrwSHhtJPwSUTzi57MlOD2E8cI81jeVhotVB74jUW/Q6wrPuJRl5b7mZDwYRWroXLZcJ3SwrKr3GKLgFBwA9ms+2ReOi7MZBta8r4NC91FHatw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: abfa54af-e0f1-48ce-00a3-08d9ea58282c X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:40.2723 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9jjTs2BeCSZ/0/3+VK9xzZsGxlc2HEKftuhWGyOMAysZ4UIGXlrUHtiWtzSEyWrvgkf/LCQEkWktPN6UbkbhIgI7GZ78SG73dfPh+14cTAY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::708 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::708; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" bdrv_delete() is the only caller of bdrv_close(). Let's merge them to simplify further commits. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index 82fbf81a3c..71a5aec24c 100644 --- a/block.c +++ b/block.c @@ -4785,12 +4785,19 @@ static void bdrv_reopen_abort(BDRVReopenState *reopen_state) } -static void bdrv_close(BlockDriverState *bs) +static void bdrv_delete(BlockDriverState *bs) { BdrvAioNotifier *ban, *ban_next; BdrvChild *child, *next; assert(!bs->refcnt); + assert(bdrv_op_blocker_is_empty(bs)); + + /* remove from list, if necessary */ + if (bs->node_name[0] != '\0') { + QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list); + } + QTAILQ_REMOVE(&all_bdrv_states, bs, bs_list); bdrv_drained_begin(bs); /* complete I/O */ bdrv_flush(bs); @@ -4844,6 +4851,8 @@ static void bdrv_close(BlockDriverState *bs) if (bs->quiesce_counter) { bdrv_drain_all_end_quiesce(bs); } + + g_free(bs); } void bdrv_close_all(void) @@ -5164,22 +5173,6 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs, return ret; } -static void bdrv_delete(BlockDriverState *bs) -{ - assert(bdrv_op_blocker_is_empty(bs)); - assert(!bs->refcnt); - - /* remove from list, if necessary */ - if (bs->node_name[0] != '\0') { - QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list); - } - QTAILQ_REMOVE(&all_bdrv_states, bs, bs_list); - - bdrv_close(bs); - - g_free(bs); -} - /* * Replace @bs by newly created block node. From patchwork Mon Feb 7 16:37:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B34EDC433F5 for ; Mon, 7 Feb 2022 16:46:23 +0000 (UTC) Received: from localhost ([::1]:53444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH79i-0008Ao-Gv for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 11:46:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71Z-0001vx-9Q; Mon, 07 Feb 2022 11:38:00 -0500 Received: from [2a01:111:f400:7e1b::716] (port=32353 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71W-0005Iz-EX; Mon, 07 Feb 2022 11:37:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RXZB2o1g7LOm1EJVZq9Sv/jz2WiztmgTrvX0+jbnR3knSEqFouNwFrjVVrxyHMmyfCUX40CCeNrG6YzX1noluQptFiYm7wwaC0S5NVIrwJp3D+d1sKoiuUw31JyFOf0vGpcW23H8h2IAs9i8TigYRE5ipFfJS7Ri746kCx77xmnVwVkYEghoMIvdV8/rZFmWJQvq8GDcHL2H/bpihlXgEP57vLf7U08o9KABoYDUDqkoiAbc8MS6WODsQjxkIwDBxYjucyODOyV7tMhO08PfEr4ckSjFaZKOLfwDhnIe5fgL/Md5F6T9Ij7WqlcFWYQlNlqdEgrQg/F5lCTRYHGPQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7lnFpgIVdxs1RZImj/ndhVyBDbT/WqjtFKU9MRx1YOA=; b=C3CZHvbyx5BMGzm8KQ+HuxHf1vX6T6XZS893+XF2W30VYUf1oqaDyyiumTs8GX3SfzwDwKAB5UYftp5boL0yOhdNWl97e/9EcY75fSOoYUcNF8ds+8odqJV3IIZBEuQPZ8vQT5pmTA2Pd4JWkb2S3ET/KG2FaSNu3FTXzphF/XDs2GA4/8PaeUuaImaTqqsNzQ6fPofsTYErGAWwxT8B0hn8+OAYuKOlfc0ekZ2v1YBonE8xpWr2NshHGta82s1DyQdjyloPI9+B1eai4bOmR97lSp47kp09QP2eL4ftkQnBPyrDJliEUMrQqO0hflRciw20ebN3D7EqSlUxUNlVOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7lnFpgIVdxs1RZImj/ndhVyBDbT/WqjtFKU9MRx1YOA=; b=dsT6rtRRFMb4Jk+wURCy9UtfTsbtdFN6rcEmgiQf50P8ctTrl3UHw5ZDS3VLwQzKuMLHt9w46QHkr0g/B2gDhmzS7foJEBI081/ayl8yLvOsfKPjHcZL3LzFjsfSahU4IQfcKisStDfric7G+RyMmcN2K2uaKns9ienEGgQ2J9s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:41 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:41 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 06/14] block: bdrv_delete(): drop unnecessary zeroing Date: Mon, 7 Feb 2022 17:37:20 +0100 Message-Id: <20220207163728.30362-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d2432d3f-dc8c-465c-50dc-08d9ea582871 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:130; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MiE1jCEH3forBYdKmuT/SpUAYbvZGLhgMJl7a+yPupNthj5dWwqcQAdb1NEW87948azTClFmkBoLOVgGVNLv5+bmXLqLZAzQfzFW8Fd0BQG8NkMSTUSKXN6XC8C2BeYDLPVxwEw8NbXq2LuWltS6ZS0/nT6spq9Il/tFK25ykdczU+DDYAPoJr5cNzQKUshCphjcYSUGtns71l+qGbCL2jXzgiQ0yRYeA2O3sdDhiIoszPWI/XNfj4Rb21wDE7kEkIXW8SZ7QfjlDIj8upV4xmExltRUd1+eW76GfhtzQ7UQnQdMftBedspyRvhPFwnnY6t5NhmhDHmPbtQjfLTY4HhniO+R61v0uOLdueS36cKZogdn9Hx+jYWP3uCiYNfm0TM/ty/Pg3zWQQvu9mmHxv8+GE9ZShua9Y/JFy3eMQqH/YpcsDpfyR0f6/O1aaCkdD5o/PCTozne0C5aXYqfawJIbYDEXCrLQgM8eEzI2J9KKUGfQrdLPx+ZZgUclUH4xNHiFX6Ik1SsitdhMjM7bL6b9gCWshfNPUAqt1ExbIaaYhjiPBV6u9Aud/5LCWVbwr9POi9ehIim3BXec+oBIPiLuBLAPscZd3gmdI2iGd94fNobFeFqGAzDmUaAwsm6q5wFfdHVJ/YW5DyKF8D1tqVIJtjQwfqCAjfToc8W9CGnjCDBTzR0qt6O3EbHXH822xWPfYpcrJUFCY6Jof8Fhw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wQln8QkBIfUPx5Gk043bhlQnOZ3S0OZBd3nYyojlo5A/CQ/R6q7dqCVwRMa5sJonpvUbrC5QdhvjhBIt+fq9OpvhtB8+TC4skmZ+6baEd5FvGIYMAFUGyCjZmBNz6rCZEA56knePX1SuQed3Wr31T8ozPsVgZkKzRzn/Q+OGi128jJ0G5HMbwd8i2bMSOA375YjqxK77sSSVFuxiSIyLtTBQgvIt8PvRGVxKv7rzKLHtlaHA/+ZYOBoalyr74yxii2zs9qvZczYXgbwARq7U2FA4uIl57lY5ps/OO/ha30NLNoJRyUBRfqD5Ye412TVnZyzvNvwpYtRTxuAmF2bBwGGJMuqxWZB/EVIXOQyuyt2Xahhsk0NCvbu2ZhQ4W/LbP1rcCnN6Yd7JZphBto9ZhUYtcivIwJuRJ9NSiexnMgpL5RJtEZ9pKzQp2UKxo3iTlRo7QpDx2gTo3VbCrSFTvvD5jGmOr2dI01x/j4br7uv4N07GOGtbbq+iJi0NR5vyrppn7IF4Sd9RQ/Q4snzn0FDSbZd9rZY91p5apTBb0Hz8VsVeXFGgjj2Gd9HB5lnI5z3ZbVT3ZRU7MB40H+WNQ13kYaTb1qqEbOyiexTUOKlm7233dlUyd8TubgjnCwVqK1QgKx+BIcsW6VN7dpB4akbzwHMdPDgErwJfdhOHnNBKIT4YQFm4vRUYDiZXyeDfSnOZNuCp1yr2ohUa8alPzOw5HOJCQSQmMzGFMCm7vZ6WkaqhEU4OIJ183HBI2+d/1rEjbxLjzlv/qhr34m3PXOwBKFsdnXIzlXXnWUVjbkHMScsymhAGG5pOkYCtEPvvQvqOfxeJCeDnGRGUsde+z1/CxlOiom1sKcphg+cALVIwOQbh1vucZTXfjzCbzWp921AABQSXV6Ui61iFSvqL26gKFZLZ6l+vRr44bkz/QRy+SPVJbnNSgv33gZlTYCvxWk9bWldCMzGnGL917IuiMwzK1z9RDR6CjWyms/BCdx1aDT0U5+l5yzMvpskedEcSUszF6aycz6aBuHbVr470ozPJ+mNQBIvtb4mgOIDH1oqaJNF9QRs3IODpREx++novSUtvRGLp9APBOXosVpUENk+Kf1PQhgD5cnakYJfW87v64V/BatjXokGKuZ12Puj/1Ntc0C0gjXMqtwCXTQ+BDSMnmn3la9LKSVakcrUsOWvYGUC/Tcqh0l/KNAkzHs9dGsqKDmAk1n5rcD3hUSacUx3isIgop4VPyZswc3ZV6I8TFokecrzrpyNTEFbYiqXs8WoCxWJpkiotM98Y8uMS3VlBLX3WykWyVCXM+13KeTDdkrFg4FbHZ7mKYFvZDqV2H+MtsPRn7mVpgKP105b8C0ucWUunvi7Fmu5dxw5hCPV3iQyJsEi/5+YtpKvlGOdknMjgNCILoAkW/FbWjcBihZ9OImDivISiQX8fBZUkEIjd0pP6nBcnJ80Oof2c3UBiD6oSGksZEeR3oF1iGXgLDyAdglL6g0p2BxV7r1AQhzoA30TpAtrMvviYt7/uw0GNJxEhwmcfpD6C6Srcra8ta/8dCGJZsVWWS+sGO4np1MXYbaQ22Mtgm7q0hXadFa5MV5mHeFIBZ7nc+IEbLd6TybGkDJuPFXDv1efUtkhjzZTNHKywtEXNpa1FXVoqzTfjOdy3UVKdq6PvtzcObPBSjA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2432d3f-dc8c-465c-50dc-08d9ea582871 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:40.7422 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: M7bskBH/JhSYg/xSG1mU6FoLP3nrCya4qS3ocmtHrUyeTrxOLYXPXcYVm3TLVaU8CplQxBo4kN2Fq8CdIZxqXJ9hYhy++DqOAq+/rQ4HxSM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::716 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::716; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" No need to zero all these things before g_free(bs). Move memory freeing to the end of the function to simplify further conversion to transaction action. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/block.c b/block.c index 71a5aec24c..231d1fc3ea 100644 --- a/block.c +++ b/block.c @@ -4815,32 +4815,6 @@ static void bdrv_delete(BlockDriverState *bs) bdrv_unref_child(bs, child); } - assert(!bs->backing); - assert(!bs->file); - g_free(bs->opaque); - bs->opaque = NULL; - qatomic_set(&bs->copy_on_read, 0); - bs->backing_file[0] = '\0'; - bs->backing_format[0] = '\0'; - bs->total_sectors = 0; - bs->encrypted = false; - bs->sg = false; - qobject_unref(bs->options); - qobject_unref(bs->explicit_options); - bs->options = NULL; - bs->explicit_options = NULL; - qobject_unref(bs->full_open_options); - bs->full_open_options = NULL; - g_free(bs->block_status_cache); - bs->block_status_cache = NULL; - - bdrv_release_named_dirty_bitmaps(bs); - assert(QLIST_EMPTY(&bs->dirty_bitmaps)); - - QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) { - g_free(ban); - } - QLIST_INIT(&bs->aio_notifiers); bdrv_drained_end(bs); /* @@ -4852,6 +4826,20 @@ static void bdrv_delete(BlockDriverState *bs) bdrv_drain_all_end_quiesce(bs); } + /* Free memory */ + g_free(bs->opaque); + qobject_unref(bs->options); + qobject_unref(bs->explicit_options); + qobject_unref(bs->full_open_options); + g_free(bs->block_status_cache); + + bdrv_release_named_dirty_bitmaps(bs); + assert(QLIST_EMPTY(&bs->dirty_bitmaps)); + + QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) { + g_free(ban); + } + g_free(bs); } From patchwork Mon Feb 7 16:37:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C77ADC433F5 for ; Mon, 7 Feb 2022 16:52:25 +0000 (UTC) Received: from localhost ([::1]:34880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7FY-0006oX-S8 for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 11:52:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71a-0001w6-Fc; Mon, 07 Feb 2022 11:38:01 -0500 Received: from mail-am6eur05on2101.outbound.protection.outlook.com ([40.107.22.101]:1216 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71X-0005Gz-MY; Mon, 07 Feb 2022 11:37:58 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MOP9ZDK98txgaxSWM+CVEoI0KFCWzWiGF72zuk6dXE22zd4QX9/a1BeMQcLNO0dEfni3StqB8iPch8W2RSZykyBkMnTEUc0Fv6N73WD8zzlvWA4kDpN8W9JHyf9EZC3VSqSRT97qqxsN906AUV0lqhOKr+mrWfUks0pvt16FbTs03MNWyJBOjLsuGMKccN1wuoAog5eD9y/TouQOD2rihha5f9xyEO2WW6CpYNIEBIwx4Q54/oIwf3xKyKwF4TlzAZp3V7i20tRyIJb4Y6pPP+ygJrH3GtzEBmslzm6tsHl8xgD/cFI6wtZPI51fyvOqhEM/KLhBw6SXC53R39JvaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QqxVebqERuPjgngu+3mg08lAPznmZ3tXdJj5+2tXJqM=; b=VXb4iqfhsxToEaL16GaXzEztuEAvxJr7QRziLNk4ZlyXzVgo98uy0aRjnSCD0SEkJPnZ2dsBMrPtkbdBHt3wXVspYQau49TPHEUBJ5xcB34SsLudX91RNyV2DWXYkeIEkFMtQpbBshwH/xQXE4d1QM4rFuP+bXUJjh3eoIT2M+BLWR4ssnykaF+f/yS/ixoBfL3//iRoXApPpRCMX5FtHiqgKJQ4+xIKfRTBy/uRR7ss1L52n3Po+qGJj04jZfP2pnT8TzESM43dtPL1agWKzMu6YT8lym5jXERRm0Qqq7I3U85jMofY3hNLkEFLvTYL/rsUfiKi/a6X/5AyPt3DlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QqxVebqERuPjgngu+3mg08lAPznmZ3tXdJj5+2tXJqM=; b=g7FtQGpyT9ttZW59MskNNp2judKFB2+jr89fbjhnbV2U/23B+om2VMumaoBmrT0ykYQaiLT1MkC4tO+IVlBOUllS1wHgn9FGne+6FrMgoQBxXc1r7Q5o2vBnE5C7RcZ3rhyOUbz/0xMXxVE+xFGfwcfjTt73iN81IWh6oSuKR/U= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:41 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:41 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 07/14] block: implemet bdrv_try_unref() Date: Mon, 7 Feb 2022 17:37:21 +0100 Message-Id: <20220207163728.30362-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b2d607b-1e7c-497e-0f86-08d9ea5828b4 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:156; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SXEtA5qzRVORQj1iCl/DFeuDIl40ABZ+6RBO825kDh+phNahzJ7xkYUsCTi7aDc773+OyEtoBuu9lISkXp4uaDcomOUsTJ25m8dPCnT+1YvZ/gEEv9aLEPxVEtvD71MFsMbnR3MH2pQhTC8ECfrKtjQs6JEHDrThtBT5Ylvz06ErMe9LfHbXK0OXxWPWEEC0Fqs3Tbk571tD4HgWT/xRpl0qv8mmGFi+Lj1m5NDIgIzNnZlrdMOIjHStz6vH8ch7yBC6TTKy+yLJDJXM21zwB4F3TVNl1SdbfO9YXGnrCSZdn+dz/F2JIrA3IbpR4CwYaI8hmK6V7BIyYlFWdyNDBcolLuPZ715kUxQOHT7p9mXtYX0b7qWySEdBz/cOPqsSsAhEhgTud4FmL4WZAnTaXYM5+l3tuSmOWVRUXYT3gJ/fR8S/iFaPVBBb0tLJBqFJXz5E3Ex2VGUsWrN79FwLMo0Q2GRgqtUyJyctyHQ4FvtRNFzny+2R4SWWK0PztqHLq3YZLJREuYNy1R2a1K1pixbVlZX7T+xQjgOzQhrwIPn/7RRN2C4Rprew1fxj91X3oHvvpmIMy90EI/io21zP7GjnuFAcIzxzjRHJVz9Ool4bmXRHd3JYorjlI7lr+fyVqUDLVdn6IQ/U+WcnC4+Er1izpuVdLyj81jiqcj9bIrH3sUJ4JeDgpY3pPZu2eFOmsK+ya1AOMBDxaf+qoNWuBQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TXVSckxz1orleZqwwDwFXIh3y9ot3xla/vthFMrj3XyMcl9ZDsPuPRY5/lOJrT45o3m/D2YuZxsxsbvQT/2MCg8ovm+qdawBt+Y0piJxiZ9DNH36xZ3Kz3TbLWVan5uFuY2SO8Y+SEiOOjeQf1dm0MbYPmhzHBJEMMlvKeoViwF73t/QmAtH2oemHN+7luSCr0+WP0aZryLH2M8viuONZt4lQCraRSYRKhKGBGvvLsQU8ops9qsm8zXhY5xY2oR424BallIIU0JHyBrO33ZlkqI5eLUOzC/JvcPSREWNhYb266L43sLpPYOLQ/fFNRmm1JF2e95E4u5e2qPWsdNHYM+PW3way2K/VmMVwCehAzlEvmH4P4so3FLG3cFCHd+qrj1Ca+GSc1cZRMZW3G9amtFT3TZ8ZHp1dnNftuv9Ti1MQbL8LlKxwHs9VxItD5n/w14adwAtD+Qv9vN27A96YjYdpzMXgAHo8lb5Py1OMKSazS+xnb0kkT17mg83TAE4tbqbITrQdz7rOgWV+9VxmLJ6/IG0RrvWscshYOfBz5khXLyJpgTSEmnQd4/5p+KlpcUOSQtGe5p0E0qFuedDlkEifD49GK9/8N3TCEseOOIadbizBNnFjQxGMFp9b8mMBDS+XERrGeMdR3+vBybLxDw2DYxztTPKznfzBrQZO/jRWDD893estMWO0J+5RCMcSoSgL0gVouxcAjfGW8C2ryulYsJDuSeraEW4x1GT8pP6w7q4BVpU764n5GGHBQu1uQxW1vX5lqtj5lh1jFctDHQIXcGhwphW87Vuv48cHnr0kwyeeHPwQNFctEJmqhJDfXew5gIFbFUTBjy39jd+XQNi1NKBCDxT1aZEcmlFB9PEc+DEpQHJjU+qKTEt9dKCib595wpw3/4wKbEh1+o+jVuUcmYK8PNdf/jG/MOmWKo/YPKGepvDsAdYmPzqP2UQVNB/uKRYr/N1xyfZn3bp8S0hsHLErRojZXClVmgHLLZmlGuJWJ8ubmtTW5fqZOZT0hAExq8A/fvrQgVPKUCgdS/4+RCED5Vj1zVsA88XmR2kl5c5Hx28IzJheVMl/e5HcZ5U6fwy1JEYLwTYsB/jh0UF5sXUokSF7BPwKGhXdNuXtAVLsusgptW59wDnIxMT90qsS1D2SZo5lWTZ1o8x6SA1jlaecUTnO86ixRCyYrLPSAm27TYaFuzfu0tgdnJNGJ9DlCWXF2TBb3aVjD6km+/KtxoZTVKF7hS+COI/jvNavfE1Ypn7ZPtsDTDsl3cn0ebK6jtQ1bLBHmwvnrQvv+0bZqiccNVgDUU7NiRUG1SqONbTayaRNv3Lpt9aD3ht9tZAwzYWeaLbqQ67loh4rK96zRAF4A5qsp8+0oIUpC35692STRHmhI7LwGK5Ku2xPHOPO5/ORX/+H2ujpTxUboOuYb41a7z8ctvhfzkQZ17XQH8BZFZ2XemV38hokiNuxtodW2/AHM9W0/MxteQS6k6LqDwEE9taFQlMdZiJd3hQMMBA2xLci1heHR14zDjLW37QH5Yy61/iOHBij27b3o91OwOTw2r5M9y/v/wzU5YpaHZMeTPJJylnNKjeZbnAnuL8bWBdiNYBP0t7fFWuT+L6pA0/wIwnxFAeZciS/9fIcx9Fssu0V3HltEFFNjwEj3YmHEKktUg6s8/YoHS3EA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b2d607b-1e7c-497e-0f86-08d9ea5828b4 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:41.1952 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Zp9qvz7m+KtQsoO/g5gNfCmi8AxErKAtXVGIp8Kanhr9saj0NGvuwULljD+da11XZx4n/12MsK7S3EIsIAZ6TZDbQdGJBD7S769Jf5Jy5Iw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 Received-SPF: pass client-ip=40.107.22.101; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Make a version of bdrv_unref() that honestly report any failure. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block.h | 1 + include/block/block_int.h | 2 + block.c | 247 +++++++++++++++++++++++++++++++------- 3 files changed, 208 insertions(+), 42 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 768273b2db..42d78a7a31 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -672,6 +672,7 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs); void bdrv_ref(BlockDriverState *bs); void bdrv_unref(BlockDriverState *bs); void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child); +int bdrv_try_unref(BlockDriverState *bs, Error **errp); BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, const char *child_name, diff --git a/include/block/block_int.h b/include/block/block_int.h index 767825aec4..3126868633 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -188,6 +188,8 @@ struct BlockDriver { int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, Error **errp); void (*bdrv_close)(BlockDriverState *bs); + int (*bdrv_close_safe)(BlockDriverState *bs, Transaction *tran, + Error **errp); int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts, diff --git a/block.c b/block.c index 231d1fc3ea..187732c6f8 100644 --- a/block.c +++ b/block.c @@ -101,6 +101,9 @@ static void bdrv_reopen_abort(BDRVReopenState *reopen_state); static bool bdrv_backing_overridden(BlockDriverState *bs); +static int bdrv_unref_safe(BlockDriverState *bs, Transaction *tran, + Error **errp); + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; @@ -3084,30 +3087,60 @@ out: return ret < 0 ? NULL : child; } -/* Callers must ensure that child->frozen is false. */ -void bdrv_root_unref_child(BdrvChild *child) +/* + * When @tran is NULL, function never fail and returns 0. Still, some states + * may not be saved correctly. + * + * When @tran is not NULL, first failure is returned and the action may be + * rolled back. + */ +static int bdrv_root_unref_child_safe(BdrvChild *child, Transaction *tran, + Error **errp) { + int ret; BlockDriverState *child_bs = child->bs; - bdrv_replace_child_noperm(child, NULL); - bdrv_child_free(child); + if (tran) { + bdrv_remove_child(child, tran); + } else { + bdrv_replace_child_noperm(child, NULL); + bdrv_child_free(child); + } if (child_bs) { /* * Update permissions for old node. We're just taking a parent away, so * we're loosening restrictions. Errors of permission update are not - * fatal in this case, ignore them. + * fatal in this case, ignore them when tran is NULL. */ - bdrv_refresh_perms(child_bs, NULL, NULL); + ret = bdrv_refresh_perms(child_bs, tran, tran ? errp : NULL); + if (tran && ret < 0) { + return ret; + } /* * When the parent requiring a non-default AioContext is removed, the * node moves back to the main AioContext */ - bdrv_try_set_aio_context(child_bs, qemu_get_aio_context(), NULL); + if (tran) { + ret = bdrv_try_set_aio_context_tran(child_bs, + qemu_get_aio_context(), + tran, errp); + if (ret < 0) { + return ret; + } + } else { + bdrv_try_set_aio_context(child_bs, qemu_get_aio_context(), NULL); + } } - bdrv_unref(child_bs); + return bdrv_unref_safe(child_bs, tran, errp); +} + +/* Callers must ensure that child->frozen is false. */ +void bdrv_root_unref_child(BdrvChild *child) +{ + bdrv_root_unref_child_safe(child, NULL, &error_abort); } typedef struct BdrvSetInheritsFrom { @@ -3176,15 +3209,28 @@ static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child, } } +/* + * When @tran is NULL, function never fail and returns 0. Still, some states + * may not be saved correctly. + * + * When @tran is not NULL, first failure is returned and the action may be + * rolled back. + */ +static int bdrv_unref_child_safe(BlockDriverState *parent, BdrvChild *child, + Transaction *tran, Error **errp) +{ + if (child == NULL) { + return 0; + } + + bdrv_unset_inherits_from(parent, child, tran); + return bdrv_root_unref_child_safe(child, tran, errp); +} + /* Callers must ensure that child->frozen is false. */ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child) { - if (child == NULL) { - return; - } - - bdrv_unset_inherits_from(parent, child, NULL); - bdrv_root_unref_child(child); + bdrv_unref_child_safe(parent, child, NULL, &error_abort); } @@ -4784,14 +4830,17 @@ static void bdrv_reopen_abort(BDRVReopenState *reopen_state) } } +static void bdrv_delete_abort(void *opaque) +{ + BlockDriverState *bs = opaque; -static void bdrv_delete(BlockDriverState *bs) + bdrv_drained_end(bs); +} + +static void bdrv_delete_commit(void *opaque) { BdrvAioNotifier *ban, *ban_next; - BdrvChild *child, *next; - - assert(!bs->refcnt); - assert(bdrv_op_blocker_is_empty(bs)); + BlockDriverState *bs = opaque; /* remove from list, if necessary */ if (bs->node_name[0] != '\0') { @@ -4799,22 +4848,6 @@ static void bdrv_delete(BlockDriverState *bs) } QTAILQ_REMOVE(&all_bdrv_states, bs, bs_list); - bdrv_drained_begin(bs); /* complete I/O */ - bdrv_flush(bs); - bdrv_drain(bs); /* in case flush left pending I/O */ - - if (bs->drv) { - if (bs->drv->bdrv_close) { - /* Must unfreeze all children, so bdrv_unref_child() works */ - bs->drv->bdrv_close(bs); - } - bs->drv = NULL; - } - - QLIST_FOREACH_SAFE(child, &bs->children, next, next) { - bdrv_unref_child(bs, child); - } - bdrv_drained_end(bs); /* @@ -4843,6 +4876,88 @@ static void bdrv_delete(BlockDriverState *bs) g_free(bs); } +static TransactionActionDrv bdrv_delete_drv = { + .commit = bdrv_delete_commit, + .abort = bdrv_delete_abort, +}; + +/* + * When @tran is NULL, function never fail and returns 0. Still, some states + * may not be saved correctly. + * + * When @tran is not NULL, first failure is returned and the action may be + * rolled back. + */ +static int bdrv_delete(BlockDriverState *bs, Transaction *tran, Error **errp) +{ + int ret; + BdrvChild *child, *next; + + assert(!bs->refcnt); + assert(bdrv_op_blocker_is_empty(bs)); + + assert(!(bs->drv && bs->drv->bdrv_close_safe && bs->drv->bdrv_close)); + + if (tran && bs->drv && bs->drv->bdrv_close) { + /* .bdrv_close() is unsafe handler */ + error_setg(errp, "Node '%s'(%s) doesn't support safe removing", + bdrv_get_node_name(bs), bdrv_get_format_name(bs)); + return -EINVAL; + } + + if (tran && !bs->drv) { + /* Node without driver is a sign of something wrong */ + error_setg(errp, "Node '%s' is broken", bdrv_get_node_name(bs)); + return -EINVAL; + } + + /* complete I/O */ + bdrv_drained_begin(bs); + if (tran) { + /* Add it now, as we want bdrv_drained_end() on abort */ + tran_add(tran, &bdrv_delete_drv, bs); + } + + ret = bdrv_flush(bs); + if (ret < 0 && tran) { + error_setg(errp, "Failed to flush node '%s'", bdrv_get_node_name(bs)); + return ret; + } + + bdrv_drain(bs); /* in case flush left pending I/O */ + + /* + * .bdrv_close[_safe] Must unfreeze all children, so bdrv_unref_child() + * works. + */ + if (bs->drv) { + if (bs->drv->bdrv_close) { + assert(!tran); + bs->drv->bdrv_close(bs); + } else if (bs->drv->bdrv_close_safe) { + ret = bs->drv->bdrv_close_safe(bs, tran, errp); + if (ret < 0) { + assert(tran); + return ret; + } + } + } + + QLIST_FOREACH_SAFE(child, &bs->children, next, next) { + ret = bdrv_unref_child_safe(bs, child, tran, errp); + if (ret < 0) { + assert(tran); + return ret; + } + } + + if (!tran) { + bdrv_delete_commit(bs); + } + + return 0; +} + void bdrv_close_all(void) { assert(job_next(NULL) == NULL); @@ -6571,18 +6686,66 @@ void bdrv_ref(BlockDriverState *bs) bs->refcnt++; } +static void bdrv_unref_safe_abort(void *opaque) +{ + bdrv_ref(opaque); +} + +static TransactionActionDrv bdrv_unref_safe_drv = { + .abort = bdrv_unref_safe_abort, +}; + +/* + * When @tran is NULL, function never fail and returns 0. Still, some states + * may not be saved correctly. + * + * When @tran is not NULL, first failure is returned and the action may be + * rolled back. + */ +static int bdrv_unref_safe(BlockDriverState *bs, Transaction *tran, + Error **errp) +{ + if (!bs) { + return 0; + } + + assert(bs->refcnt > 0); + + if (tran) { + tran_add(tran, &bdrv_unref_safe_drv, bs); + } + + if (--bs->refcnt == 0) { + return bdrv_delete(bs, tran, errp); + } + + return 0; +} + /* Release a previously grabbed reference to bs. * If after releasing, reference count is zero, the BlockDriverState is * deleted. */ void bdrv_unref(BlockDriverState *bs) { - if (!bs) { - return; - } - assert(bs->refcnt > 0); - if (--bs->refcnt == 0) { - bdrv_delete(bs); - } + bdrv_unref_safe(bs, NULL, &error_abort); +} + +/* + * Like bdrv_unref(), but don't ignore errors: + * On success, if node (nodes) were removed, it's guaranteed that all states + * are stored correctly (for example, metadata caches, persistent dirty + * bitmaps). + * On failure every change is rolled back, node is not unref'ed. + */ +int bdrv_try_unref(BlockDriverState *bs, Error **errp) +{ + int ret; + Transaction *tran = tran_new(); + + ret = bdrv_unref_safe(bs, tran, errp); + tran_finalize(tran, ret); + + return ret; } struct BdrvOpBlocker { From patchwork Mon Feb 7 16:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7583BC433F5 for ; Mon, 7 Feb 2022 16:56:07 +0000 (UTC) Received: from localhost ([::1]:40708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7J8-0002Nw-Ca for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 11:56:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71c-0001wP-Ea; Mon, 07 Feb 2022 11:38:01 -0500 Received: from [2a01:111:f400:7e1b::708] (port=37729 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71Z-0005HI-2X; Mon, 07 Feb 2022 11:38:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kZJD8vqfJHxTx6IQYGExJ+RhEbAvqTMcm7VKO79GrICFIlRU2/eeZ5MGO/mICCm8Hms3ftiui1FoO+KGoH3sU8muMX4RgU23sFgAoylJA1CSxfgteDb+Hq96QcBWIovUjVEn45073nQ533msh4C/b+zfa4M5gYgloiA5d6Q3zK8xQy6/WEfGVvJtr0odA9jeueBj+6cBh4Rj3eF5uQA7QC4M18XSb3LVenI4OvQkNcYukWdzTa256UVkxU3+UeluFzrrxAolc5LUNxjYHTvrIiCTnVaxxcm2LibrDjWcIAeX/+tqaWX/c3B2iPwmUvv3unvdddUzDgo98gQXU5b9RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f/qrTksJY1xRlLtzEuVEraV2yLKM3ZHATY/b1TP3yJo=; b=JYCjgbZkrGby2oXrpWIrRVcB/LgkT6fLbGMI/e2aQhj2WQJRaJuhEZq1+uVAAWDsZcnH+P2VK6fVECHwx1JCQaj4v/lGXIGdC1gYzrcGlBrkBBku+L+UoRruEt8+T2pAzWyDUpTRyh886Vok3itCe04XyVgBaVqL7zo424UkQO1vSK6fz77JVYKpFNvDJbVvRw6D2hUHtTmjIC7LnLNq8XJKOT1+v7dofAYfb442eLHSfIkIvIVS7ICc96r71WvsUNX61bDVNbPBQR3c6FPzMCxORX8vZl5W697lOGC7YalMLV6pi36sonPm2MISKyCk8tpK7c95R0O62fyW/4hr3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f/qrTksJY1xRlLtzEuVEraV2yLKM3ZHATY/b1TP3yJo=; b=Ai2drIpo4uk646tCNXtzwVBCYkKOmSScMFeLccLiFMJ6VYkgVK4y4Jnhj7zKUTpF1eZDixYkDtMNNwrct4+JTjA1kf54dlvCeYRxd9e+nco5XjmEoVqP2NsXIhL86AQQUS+2JzLwXXIEVZYtJIqeqZ5Hw8dDR8Xxz4ntnmByqlw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:42 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:42 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 08/14] qapi/block-core: add 'force' argument to blockdev-del Date: Mon, 7 Feb 2022 17:37:22 +0100 Message-Id: <20220207163728.30362-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34ed3fd8-3e46-479d-f500-08d9ea5828fd X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1332; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Adgm7Ecb52sKHyKvloS5hOKb2Tb9NS4LkhRPej4qeWipZzvuFJwrCqiyZY7LPC/e+XM5PwGKL0PBGrNCL8Mkxn1dTInoWtgljZhtZn2uhuM2DA2eWql12ktjsMgDCLYAsHAIwLfHIu+HUilGLsNUtpLEza5gm56gy+ChzXmb0rU+WYN9Q68fOJ5iQ+b3mZmdsPv8BcK6eIUd5qc8mGvIwW+EkJLdgbCqXxcrMScgykxllJPJ5xGbH7egj2S6xiwZ7sQXg8sfnjgwbkIcsUNk3Bv+5wyVDjeweuCyXoOEjQOsz9jrPYWYDMEHjBJvCwhRwrw/CbabTL+iwTxwowxU1t81nLBTbrSZzSl/aV/Ps+QeZhbPbgh55TiVaGuAk1Ugkn7zJpTs2PM+Utq8wCR8cGpR+hMCB4cu5qev8AbCinyOmbfaUgXs4aem+1FyUaAX5oEQZlhIHbEhoihCdVfREOoYfWr8wBgSK6IDnElwGobnjq7iNNFyv16+KqP0GVdJNP1F5ZfaKUZU50aG1SFktmg3WJBGQDgsYWXT/OMINw0j+Xbwp9LX5AODXFDXOrsH5NeIHEXTYYnVUnzN3MiSM8QA+si3UiP2ovK0swmov8xLb1p8HvBVuog1+sa8jNHc6IGlPrZJWxKRCFbpXy8Adq8i4x7arZHcAYcNxahX5zbXAZHTYa8g70IaYfgHwQpxUOwbAuH1G2YzIp1N0Kl8GA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Kt4f1kMd+KOtnWHM20zWITE+UxL9w2jmBDUA3TGB5lSyeLVjul9LG3jh/jD51nvFk5C19bE/i9YcDpSLCb6rZVMubDiTCGtK7NFMOgWKDj+BWjUc2EzacO7p/hFZP3yJRgnRHOQA2Mqi+pYgrCCSErcptCtmd8au6QNVIPccKj1UsJ88EDwFkaAKqXrLQrBXF/efzOYvhY1IgQXzb/CANmcYmT4QW7ISHZrXPl6uhnsvfod1sIMU5msgbBJofUIk5B7vz5mREuvJGspAYVEatWbNYUNnq/Ejd5mUHEXDlNX5DD69h+BZMBG1xUSacw2F3AgN+raSNxOhqakTNssg1KxI7xOdr9zxt05x39E0bHjTa0KOhjKmqa/fEdxEwsH3QSbfyHsbZMlaXrZxiZdscsNC6RX5uHHgtVKEMnqKfPYKcMUv13Jq8ev+PL0gmJttbagWw+edCKBQXqBPLLrEvFNeUdt4s4+RY/XKov9wjDbQBXWDszN1NcM+L8Hg6nCnV01RkU+C/g39UsO0c/1dUh+qBrapJ6hLDe1sHk1WhpTWG3uP5/m97GyaV1Xm7Ok6NvD5j/AhWN/pqOnPFliA81CuKayv5YSh1erKX+ChaAD/YbjEY0SwhMu1iD69bIGLNxXReQ0b2okRKYvF86tikb/LwHbQ0f8dbugNVzyW5nIdS/Vtyd6sfORtZw4v1OQoXc7NtVtg44qSyOTQ6dJD1YEIu10Ick4Le96ApNo0bGsqqyJR8E05Ssuy5+/CWSXQYwbSXjVVDaoUP1DZO3f+PxUO68+JM+1Tf+m4lzVGvZzcgW67bLOfDjPRHpGTo+tvjd5BmMfQC8e8jsexU39wwz+J9gR0FMkUt0O/qsx7aGZYQEjUyM8ckKOkayRW2+ww11LqVPK2ua2NWFCbsk1SmiTJYqUHazKYg1ddSRUx9vJjHQhtreUZ6hr5EtiDoJAa8A/9FjtbyCqDJk7kPGJRPbcqnBrgVOfaLr6U6EK3lU555kyBA6Re0Paa+WYyyLCJsO56lD4ZLbxGzWulHwi6h4y/6RCgc+15XFlpuklcR2/PgTpi5ZQpfB/cvXlVEN9K6m68xVb8bxJQ3yXAjcEteHQrFMHoJWxH1p5fzH4baP9DY3vxzVzpseRu4TnJDsUo7OPN1cnUA900pmKBbvVLpl8susyiACiujLhULWQAUngbffy7bAqEuz8VtUjcmsoSRitgm25u5QpykwyUbDEP2kilRWl5F0X9qTG3Tosxyspp7rruVShLLssEPCMEEHUvw++rJ3oDEB7iTHkji3PkqQxXDgfp+XsodO1xWfp/j6fkQZ493v5qnqBzZeygO1U9QS0KaGUfr0+Blbk47JWeLEZZftWaVK5IPbIUbM05CbN6+jqY+vpy7sUXmfPVg9gxryNaXT0WZoVVj81iByALkTA//FIlk2ZCWn3mWwxYQPYlmAqYVlCbf3nMUY7nJovqmKP78ZjC+PKCQ7kVSFXSMqjXNioQFvKDUozvmNYt5PLYdlOAJZGA0JjrN5KeCDkAYQNHIhu3oSIeMNcs7VlTiKp/OZeUmJ31sRQvLtQ3WLHHJeuRsJ5Lcj7NBv8wG/p0lWB5eovxz9unCfapMszgmrXvwl+E/ovRN6Iugk8/1QtUfdI2D7BYEXt5R9KBYLkINQP4e0IDvW245pBrvGqYzw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34ed3fd8-3e46-479d-f500-08d9ea5828fd X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:41.6482 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nlU5HDiD2+G3SrQIEFlaViC+xk6xNn6T23NKYfL75GekZJL+xRtBYjhSpelMSd1gsaR1tcc9unbM+rKC5GkM9lrjgcuewyhU7p214lUeAfM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::708 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::708; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Default behavior is force=true and it's unchanged. New behavior is force=false, which makes it possible to be sure that node removal is done successfully with no error and all metadata is stored and flushed successfully. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 6 +++++- block/monitor/block-hmp-cmds.c | 2 +- blockdev.c | 17 +++++++++++++++-- hw/block/xen-block.c | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 9a5a3641d0..b37d195772 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4403,6 +4403,9 @@ # # @node-name: Name of the graph node to delete. # +# @force: Ignore failures when closing block-nodes, like failed IO +# when try to store metadata. Default true. (Since 7.0) +# # Since: 2.9 # # Example: @@ -4425,7 +4428,8 @@ # <- { "return": {} } # ## -{ 'command': 'blockdev-del', 'data': { 'node-name': 'str' } } +{ 'command': 'blockdev-del', + 'data': { 'node-name': 'str', '*force': 'bool' } } ## # @BlockdevCreateOptionsFile: diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index bfb3c043a0..1c35aa2d6f 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -145,7 +145,7 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) bs = bdrv_find_node(id); if (bs) { - qmp_blockdev_del(id, &local_err); + qmp_blockdev_del(id, true, true, &local_err); if (local_err) { error_report_err(local_err); } diff --git a/blockdev.c b/blockdev.c index 8197165bb5..34a195b592 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3582,11 +3582,17 @@ fail: g_slist_free_full(drained, (GDestroyNotify) bdrv_subtree_drained_end); } -void qmp_blockdev_del(const char *node_name, Error **errp) +void qmp_blockdev_del(const char *node_name, bool has_force, + bool force, Error **errp) { AioContext *aio_context; BlockDriverState *bs; + if (!has_force) { + /* Historical default is force remove */ + force = true; + } + bs = bdrv_find_node(node_name); if (!bs) { error_setg(errp, "Failed to find node with node-name='%s'", node_name); @@ -3616,7 +3622,14 @@ void qmp_blockdev_del(const char *node_name, Error **errp) } QTAILQ_REMOVE(&monitor_bdrv_states, bs, monitor_list); - bdrv_unref(bs); + if (force) { + bdrv_unref(bs); + } else { + int ret = bdrv_try_unref(bs, errp); + if (ret < 0) { + bdrv_set_monitor_owned(bs); + } + } out: aio_context_release(aio_context); diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 674953f1ad..0ac9b599c0 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -649,7 +649,7 @@ static void xen_block_blockdev_del(const char *node_name, Error **errp) { trace_xen_block_blockdev_del(node_name); - qmp_blockdev_del(node_name, errp); + qmp_blockdev_del(node_name, true, true, errp); } static char *xen_block_blockdev_add(const char *id, QDict *qdict, From patchwork Mon Feb 7 16:37:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF2F1C433F5 for ; Mon, 7 Feb 2022 17:06:05 +0000 (UTC) Received: from localhost ([::1]:51686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7Sm-0002CB-T2 for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:06:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71g-0001zf-Qr; Mon, 07 Feb 2022 11:38:06 -0500 Received: from [2a01:111:f400:7e1b::708] (port=37729 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71d-0005HI-2l; Mon, 07 Feb 2022 11:38:04 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aVqlVtQ5OF42sdmHE/XVWBeGXS74cBHjN/+gIH3l+ht/i4EmJL4Z7SOEzHWjrZFWHypw856/dvgZg95Cp8hy429wtt2d0MHPXeXbh1ticvSpelc7wKHdqlHz80wP39ygAtD+DNiKYg00DZOVcZfHmkRWFl3ywtHsW6na1U95HYu065lpq+iv/8Gr1458vCtUf+if5W/dpdwOJjL3lSiWBscVHdviK1z2oSGvikb+LtFNy/NtERuI+Uj+jzINrM8JMJ8PgKxNK2JhvWM9ktTmSzzPONlO7jEICc8e/j+yvyVpeuodLNTx13wFiWhoiBvc6eDW13yyYA4yaouV63OGCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QzqYMs72nxr/rvULzlYntudxsUVjUT8tEEdz91HA9NE=; b=NUEJcQJNHwzG9YLk4tOYM454l3RfQBajNNtgNb05yVIXx0WJ8rvaj26dGUjtgTJL4e64pNRNPw0PbnhLaPyART81gJNpvPz76VE43nyTp/RqwtPOvWTgMB87cTlwKK4unfjFjCocUQMqJxQHduTkeFAsSf+I968Z1Psg1+kTMGwJ0y1YA9w59QMx0o4L8EtI9kQLEcWBNyviUDfKFknU06yeOlagOcOF/LQ4q/U19euEYm/zMeKmAmSblGwVmSI9k3aQMiTb3EmHhfuCSQU+kGAtaOA9wui9oB4gWRkUxkta5rrxKH3N9699ZPH8wK4l2EWVOnXuNyVz5K37tlmHPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QzqYMs72nxr/rvULzlYntudxsUVjUT8tEEdz91HA9NE=; b=KTeQ5M1fD2f2YYtIfCnJ/z6vGHxdH6XMwC/DXRW1ybdVp7vApH0yb06qTFPqntHloEGYIBk29zUPvHcq4QqFDuyFkjzSSqBMinnpmhxc7zu3aPwdEPl4Syl8nAKZxGTSDhF7xrGx2z0B0qPB0RNfRABy9/fqBfAEXTJItm1Z4aw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:42 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:42 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 09/14] qcow2: qcow2_inactivate(): use qcow2_flush_caches() Date: Mon, 7 Feb 2022 17:37:23 +0100 Message-Id: <20220207163728.30362-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78ec8d04-27b4-4b9a-15f1-08d9ea582943 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:45; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YiHE7Q7MrJtgCldW6dg/1Bg0J36iHLV7oUFnGT4zuz8/URS9H3BtH8WPz6g9XwFicux8SsbC6UIoJJq3wPECvpVZhTvQmeUNdAg72hKhbeBUOPAOYFoEtvRFy8Z1q8Z3Siwr2h3i048/po81TgdB6ZAQxlXcyI5JqMTrSYjUKfQGJVLm3JshaL4pemmrWYT/OpqvNSBl8WPr6X1rEsMfopTrnqGe3CazqCUOZcw3s3sv/Km/Bz4jVAOjf0eyRBa5oH4vFADQSVQcb+XIVgfyrMK3oewNpNXlpOLhsQ2Pz1jcLmcY2AP6AwKlAb6+VuzEwYV7CI1nwdpSpDcbZ95pxK6I3FbEhVGLS8KihRfY6sKDZ4pRGd0dXOEy5dNzIsMT9JKpghehMmhnWxi6mzps0uiQr8F94vZ0YyJil1eYZwWCcIDytTKU47LR7GSP0W7TSj7tIkhy3sc2TKdxdTmqsZtK7I179z27LJ1UCSzTudghspStf+eetikYAgii7duklSNtaIqG7A398AgQADQZ07ZBgeFeIqU2Hj1+nkz7KaS6QGWIbMitq3VgOpnk1aSYIbvUUC8XKdLj6brUM2MYuQQlzMIZfIGUIA+daM6sh//oqVxIoF+rD+/N1B8UVQxgnNsNGlvKnWBQVOzNYsjsgpOzljmsVKCRHZDs7m12HQTBeNVAtrtgs034j2Fwkj6vBdc2yN4RPeeDAQJqFaGkQQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(30864003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 50sCjicGNYAlENjCjaKDEk0z8cEPI5dDMAdJ2i2wk65z0rqDxLy8VGKFeo6nTgUNohdpaX/ecnzMg/3MPTgNpYdsdRY8MNphibbhEvNPClx/SA5EgXXAo/OTRHQEoz02TseNup7Hk8mj7A2gg84LylvBxQ2aTtg98rGooRXIXlCDrFiqcoaDChRhqMqiQ6QFVU13YZgmNJK64X2Of/ndpSgBmkuqbIjig8PYs+z/ofd3icqKo6mm6uULZDWqnQGFq+0w4vj21XOEHuTp+MVOa4TAnVZfEqYUzjo7lUX2XThQ1WyDrI/pjuV8JvvbSuCawbTyTANiTSlZAUymlSp5+/B3nY+dbspCWykFVp9Ds45PjDpaoQw6NCEQsFE6QL8D83dPQ/bUoOPLS/y4Zahjh8kvmvXRgLL5KjJEBgm+q3GV2WAW9+s0Qg/Co0A7/VUOrjTmLxrdik4X48a9YaqH0zAHRyVbgvXZvIdKglCUdS5qZiPPIkZQv7fn/g4V2AAxQN2i/XSdsbFiqLz4JAfsBHoF2GDyRAcMWsiTlUHE8pKVgG9NetUYYyD3asyjS6s8utIgHARc1DEAM61q+n+569wwIh36esrkMjBNUyqeHfC2kixyT++d0TVH+rAEtchJjS3OMmb+jp4bIXE54UoGzbbo53TqHTaHCH5YeZTeIu+64zmv2hKx+ohtOlKYGfk/NzWlKkFWK+IAW+VI8Ylh7S/2HyhhFvrEfFB44cd/9O3UcJJQ5jw7Gl5TTASuoWDvdYbIYQzkxicSPkNJGd8KCuty2S9VKj0YUqbRLzor/Od3Sx1J6i0couK3n0RSyqzpFzOD7/8TVgVosNzdTN4vxlEPQoihNgvHI1YECDDEK+/xZqLxkkiY4of6AT/vzfYFEU50Ffcsgg+YwTOjFTSJ3K78k3W4y/eMY5uwCgExroaYW2c4gXt1GIERp6+NPkCOxPLp/Em4xS8l5xarRibj/JNxszL7utPIjVl7HsjrO9jMEQnqiLPQDfJUID1ywBR+iRz/hrnxW2J4Q0rZ0xdFXFlPmK0lTrxcs+0kWd1xGzyGyrUUfxjqflZcdJI6QlImwcmhAur7bMZ8iCQAr5BRRR3TsHfPgWlfB2Nta6w9/JdTASr4SC7/Np9UJO4BHgxwkX7BNR+S65f/Mxwinz44dViwXV0WRzqKdrcEhbXtYqeYLh6I9A/uv3UUYk+Z2ByMK5r2Ng4e7tboPjRg+2ym5AkJu724j0z1LDDHj8Svo0Qn2oEgU3H15NRHRfxNL9VpwZWBUdVXb5vdb5qwwT8HF7z4GFWv8jefVBXKL5JqNIkKLnQYHz+bPGQnRHjRbUCqITncNmzUS9SN+EaDTY+r4JWucjzqnB/cioXGfPQv+Yd0NJJYBx6Miu3vE6MFgOXxjiBZ8bdzHAr5JhKYoHXVGxNRvs6kqz7cFGv2W+Xcq5bb8opeewldYCld3KphI4RUbKQ+SWDblrtA0OvotmVlDS/8tLFZ9GAxBnllGUxJXvpOooS3P5vFwVA9kWTw/iXg1qStgNqlMzzfgMUji+P3eXl75MY4ibI6sQAtj1mYmr19UdwgbWnKJnwy+mmjZ23vYpROrQPVtQWRO25Dz3ZsaqPXp3RpInqOj6RBD9o4tZTMt+MR0pacqsKGf2eUGxzfRsOe2PN0y1wx4dOTljUlwg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78ec8d04-27b4-4b9a-15f1-08d9ea582943 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:42.1482 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: W6gaeMQYVWOQpEwyWIRNwM47rZwkJ/XziGlXDysCzpknqeq0WVcisRXmEfAnXa+1oqWbV892vLBDnP2QTplWsB6uSQN7PvPAUOVtMx7KmVM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::708 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::708; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Maintaining similar logic of flushing caches in both qcow2_inactivate() and in qcow2_flush_caches() is not good. Let's refactor things to use qcow2_flush_caches() directly from qcow2_inactivate(). For this we need two things: textual error messages (add Error **) and possibility to unconditionally flush refcounts (add force_refcounts argument). Iotests output updated correspondingly. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 6 +- block/qcow2-bitmap.c | 2 +- block/qcow2-refcount.c | 22 +++++-- block/qcow2.c | 25 +++----- tests/qemu-iotests/026.out | 126 +++++++++++++------------------------ tests/qemu-iotests/071.out | 3 +- tests/qemu-iotests/080.out | 4 +- 7 files changed, 76 insertions(+), 112 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index fd48a89d45..a83183d533 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -874,8 +874,10 @@ void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry, int qcow2_update_snapshot_refcount(BlockDriverState *bs, int64_t l1_table_offset, int l1_size, int addend); -int coroutine_fn qcow2_flush_caches(BlockDriverState *bs); -int coroutine_fn qcow2_write_caches(BlockDriverState *bs); +int coroutine_fn qcow2_flush_caches(BlockDriverState *bs, bool force_refcounts, + Error **errp); +int coroutine_fn qcow2_write_caches(BlockDriverState *bs, bool force_refcounts, + Error **errp); int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 8fb4731551..0f463ced4e 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -899,7 +899,7 @@ static int update_ext_header_and_dir(BlockDriverState *bs, return ret; } - ret = qcow2_flush_caches(bs); + ret = qcow2_flush_caches(bs, false, NULL); if (ret < 0) { goto fail; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 4614572252..c8251412ce 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1203,19 +1203,23 @@ void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry, } } -int coroutine_fn qcow2_write_caches(BlockDriverState *bs) +int coroutine_fn qcow2_write_caches(BlockDriverState *bs, bool force_refcounts, + Error **errp) { BDRVQcow2State *s = bs->opaque; int ret; ret = qcow2_cache_write(bs, s->l2_table_cache); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write the L2 table cache"); return ret; } - if (qcow2_need_accurate_refcounts(s)) { + if (force_refcounts || qcow2_need_accurate_refcounts(s)) { ret = qcow2_cache_write(bs, s->refcount_block_cache); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed to write the refcount block cache"); return ret; } } @@ -1223,14 +1227,22 @@ int coroutine_fn qcow2_write_caches(BlockDriverState *bs) return 0; } -int coroutine_fn qcow2_flush_caches(BlockDriverState *bs) +int coroutine_fn qcow2_flush_caches(BlockDriverState *bs, bool force_refcounts, + Error **errp) { - int ret = qcow2_write_caches(bs); + int ret = qcow2_write_caches(bs, force_refcounts, errp); if (ret < 0) { return ret; } - return bdrv_flush(bs->file->bs); + ret = bdrv_flush(bs->file->bs); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed to flush after writing caches"); + return ret; + } + + return 0; } /*********************************************************/ diff --git a/block/qcow2.c b/block/qcow2.c index 614df0307f..04994df240 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -544,7 +544,7 @@ static int qcow2_mark_clean(BlockDriverState *bs) s->incompatible_features &= ~QCOW2_INCOMPAT_DIRTY; - ret = qcow2_flush_caches(bs); + ret = qcow2_flush_caches(bs, false, NULL); if (ret < 0) { return ret; } @@ -574,7 +574,7 @@ int qcow2_mark_consistent(BlockDriverState *bs) BDRVQcow2State *s = bs->opaque; if (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT) { - int ret = qcow2_flush_caches(bs); + int ret = qcow2_flush_caches(bs, false, NULL); if (ret < 0) { return ret; } @@ -2680,7 +2680,6 @@ fail_nometa: static int qcow2_inactivate(BlockDriverState *bs) { - BDRVQcow2State *s = bs->opaque; int ret, result = 0; Error *local_err = NULL; @@ -2690,20 +2689,14 @@ static int qcow2_inactivate(BlockDriverState *bs) error_reportf_err(local_err, "Lost persistent bitmaps during " "inactivation of node '%s': ", bdrv_get_device_or_node_name(bs)); + local_err = NULL; } - ret = qcow2_cache_flush(bs, s->l2_table_cache); - if (ret) { + ret = qcow2_flush_caches(bs, true, &local_err); + if (ret < 0) { result = ret; - error_report("Failed to flush the L2 table cache: %s", - strerror(-ret)); - } - - ret = qcow2_cache_flush(bs, s->refcount_block_cache); - if (ret) { - result = ret; - error_report("Failed to flush the refcount block cache: %s", - strerror(-ret)); + error_report_err(local_err); + local_err = NULL; } if (result == 0) { @@ -4517,7 +4510,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { /* Flush metadata before actually changing the image size */ - ret = qcow2_write_caches(bs); + ret = qcow2_write_caches(bs, false, NULL); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to flush the preallocated area to disk"); @@ -4936,7 +4929,7 @@ static coroutine_fn int qcow2_co_flush_to_os(BlockDriverState *bs) int ret; qemu_co_mutex_lock(&s->lock); - ret = qcow2_write_caches(bs); + ret = qcow2_write_caches(bs, false, NULL); qemu_co_mutex_unlock(&s->lock); return ret; diff --git a/tests/qemu-iotests/026.out b/tests/qemu-iotests/026.out index 83989996ff..cdc1ed2748 100644 --- a/tests/qemu-iotests/026.out +++ b/tests/qemu-iotests/026.out @@ -14,15 +14,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_update; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_update; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -38,15 +36,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_update; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_update; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -126,15 +122,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_update; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the L2 table cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_update; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the L2 table cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -150,15 +144,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_update; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_update; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -174,15 +166,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_alloc_write; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_alloc_write; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -198,15 +188,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_alloc_write; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l2_alloc_write; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -222,15 +210,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: write_aio; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: write_aio; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -246,15 +232,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: write_aio; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: write_aio; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -270,15 +254,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_load; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_load; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -294,15 +276,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_load; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_load; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -318,15 +298,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_update_part; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_update_part; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -342,15 +320,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_update_part; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_update_part; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -366,15 +342,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc; errno: 5; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc; errno: 5; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -390,15 +364,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -457,15 +429,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_hookup; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_hookup; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -481,15 +451,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_write; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_write; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -505,15 +473,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_write_blocks; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_write_blocks; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -529,15 +495,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_write_table; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_write_table; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -553,15 +517,13 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_switch_table; errno: 28; imm: off; once: off; write -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: refblock_alloc_switch_table; errno: 28; imm: off; once: off; write -b -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the L2 table cache: No space left on device write failed: No space left on device No errors were found on the image. @@ -595,8 +557,7 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_grow_write_table; errno: 5; imm: off; once: off -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -607,8 +568,7 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_grow_write_table; errno: 28; imm: off; once: off -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -619,8 +579,7 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_grow_activate_table; errno: 5; imm: off; once: off -qemu-io: Failed to flush the L2 table cache: Input/output error -qemu-io: Failed to flush the refcount block cache: Input/output error +qemu-io: Failed to write the refcount block cache: Input/output error write failed: Input/output error No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 @@ -631,8 +590,7 @@ No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 Event: l1_grow_activate_table; errno: 28; imm: off; once: off -qemu-io: Failed to flush the L2 table cache: No space left on device -qemu-io: Failed to flush the refcount block cache: No space left on device +qemu-io: Failed to write the refcount block cache: No space left on device write failed: No space left on device No errors were found on the image. diff --git a/tests/qemu-iotests/071.out b/tests/qemu-iotests/071.out index bca0c02f5c..de1c59154d 100644 --- a/tests/qemu-iotests/071.out +++ b/tests/qemu-iotests/071.out @@ -86,7 +86,6 @@ read failed: Input/output error {"return": ""} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} -QEMU_PROG: Failed to flush the L2 table cache: Input/output error -QEMU_PROG: Failed to flush the refcount block cache: Input/output error +QEMU_PROG: Failed to flush after writing caches: Input/output error *** done diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index 45ab01db8e..860228f93b 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -66,7 +66,7 @@ wrote 512/512 bytes at offset 0 qemu-img: Failed to load snapshot: Snapshot L1 table offset invalid qemu-img: Snapshot L1 table offset invalid qemu-img: Failed to turn zero into data clusters: Invalid argument -qemu-io: Failed to flush the refcount block cache: Invalid argument +qemu-io: Failed to write the refcount block cache: Invalid argument write failed: Invalid argument qemu-img: Snapshot L1 table offset invalid qemu-img: Could not apply snapshot 'test': Failed to load snapshot: Invalid argument @@ -89,7 +89,7 @@ wrote 512/512 bytes at offset 0 qemu-img: Failed to load snapshot: Snapshot L1 table too large qemu-img: Snapshot L1 table too large qemu-img: Failed to turn zero into data clusters: File too large -qemu-io: Failed to flush the refcount block cache: File too large +qemu-io: Failed to write the refcount block cache: File too large write failed: File too large qemu-img: Snapshot L1 table too large qemu-img: Could not apply snapshot 'test': Failed to load snapshot: File too large From patchwork Mon Feb 7 16:37:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2FBE5C433EF for ; Mon, 7 Feb 2022 17:43:19 +0000 (UTC) Received: from localhost ([::1]:50580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH82o-0008J9-3L for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:43:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71c-0001wQ-II; Mon, 07 Feb 2022 11:38:01 -0500 Received: from [2a01:111:f400:7e1b::716] (port=32353 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71Z-0005Iz-Rm; Mon, 07 Feb 2022 11:38:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RYVUqFAE4RROaJdbOnrU1zaHP3j3ZWu63NXCUmP9Bzz83CHv05kfVtjAgfivQmZg7cRr/FSjxnGX9I9QfpT5CuNLhXYPWN1gVzqp5pLcgI6gh0wTP2G0ihMyrFU0gbutAU7Dc3soHVxptG7IcCOmel1A/3jA+VC+Cxd3Y363s9OERtx/fQ+nbe1lXOkkqWNo4eWjsKlC0XkqkpCgEohTI9udKCY/0VqSPjER3Or0PCfWc9J0XQQmf+rUQQVXZ7EMho1/v2ym8udGtU7LqcLyg3HBIjZbl1KcloAMQPIoYG4naDM1pz4PRRFrKkZv/GO03L3EdC3iFIXmDwALfd3Ceg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/qgBjLGqaRpQxkoNuZY6HzxzJBR8Z9gINVDxuoPbiF8=; b=DfmlI+Hki5ebmUQWDHI4ANLUgSyNsmBhUv7kNIqXoTg6PWqocNnSEdtJCpFeonT+Dy74XX2OD9OulPgHCp6NW7l5ODErqu3qAWo4LMjPOQ4D8piNTpXklR81TZ9GIrOWhS3QTn0/ylmG+cFYgW3Ag6ZUvKKoPZ3U9gAcvVvJXJ3RqmUAAukQdemWsBirq6ACy3ilMTbT2UpdpUGwjYon40dyY7ThlbOrfn+Sg0G+H5IaIlKqYzWcRUDHDiH/wmO4E7waOGihMTqEY0RMpdFAv13Jo54Vf6cXYdFWle/vf9LjSaFFzg3Fv8Gjn3JSU0yMjJ6/kfMQitxUA98GvKc7yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/qgBjLGqaRpQxkoNuZY6HzxzJBR8Z9gINVDxuoPbiF8=; b=MLuqLF+XBQlKGASTCxtlsLalCfI1uTVs/knf4JJ4tXOCUXYSePQQ7N60F6RmEaV7LmEt/+/7el98YUW9dfbxA1XgEaLPJM+XKQxCvsmWdog7M2QEBpyQq6vnTrxyFS9GBig0VRCh+NpHr1A5g3CreSvzY6wtZv2aO1zxSm1I4DA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:43 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:43 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 10/14] qcow2: qcow2_inactivate(): don't call qcow2_mark_clean() when RO Date: Mon, 7 Feb 2022 17:37:24 +0100 Message-Id: <20220207163728.30362-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea0ea432-c4a2-46c8-991f-08d9ea58298a X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:220; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eU7G27XAXA/KdSOqzX1lw/7BTFW1w+i8EwZnQz7rCaO69KDtnpSj1erM2u+cWx9iJGzIj57eWjy5LOqvlWzhIFrnebcVAdRQWq9Tt8PRXtVe67ZG6E/d4sF+V0bYb6eE/NHQKH3OvKZ13Xv/CIhDaaA6Md+44KkxgKHk2A2BegoHppIHtXNRWw9DxUjeNtkKE6YAgG909hYu+erp16NpbpGQkcsACI/Tx/691O3CeXSpM6zO9SFQL4XP97vgZhtXeg4yfowmWyjXqSKu8+miQDKQgg7tkcl/07pn9fmOFpkJZ470V+ESARxXF7q7x4CBWT77+P2Hn57SSzz+WjgitnpgxNYwVWGLDxGLrlN5u04IZtwmrxX9zTbUw0TiwZotu+UeG6r44gClgYjRM5Q7z1xx4mcKDHsgbtirOxtwBPLplbqUY7PRONzuhxfj5P0lYtoXQTxJGR/ovHy4zMG32IUbtvP/AsIJuf7pPRbzjCHlHofXjln1HaG32RvzfGhaHa7LN3NhCanK+GHc3YZc8V48IklUaZlHVpNgEU5JnuuQ0cos16Rh1tXzxmc8s2o+zCssDMLQTXU7JFJkOdkAZ9SjWbA9t6uqgSPPebPXL34TEWTdJlO8Re5xuB09sUCiqBiiRysklU6mSR3cmxWWD9fPQpyMCrfcDMfXfkU83mOjFXVA4e8U10uuxJzCTqeGPkkaakKcAlkJmQ24qkwmyw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(4744005)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K37W0busVPuxsp/snNQSVv7O/JWCa9MrfrBI1FjV45awX9q6peypWOSjMLQxwUAksi9KFYqsJeh8ey/Km2Y7X+RhiEZ2R8JhJG30YMdVBwqUABAm6KqyuJ+obRD//beXF18tJXkNcRcARgtVtBu6t6OQiBcEUd4qit1q3enQbZ8lv8dS9BnTZFj68WmgZ200I/qQvR2KvWJ1/Ii1vBjOCAcclXxAlHm+YPX4d3vzJSZDJd/HdnWy9kIxALA9Il9pUwQMjGNMuXXqHNeq893gW8PipHzlCBVEtdSgvpeqE1WaUv2wdS/phOAP3nr6mC+E3aV+0YBx4jENt9QDYuC2ifmAxKcROGYpjTrpwE8dLt0FzVBJlloWprAPXNuinDu765U+qEBpwq2c0nALQBbPf6ehvEmT992Tx23V92HCc3mVf9z0pkKk6R9nlbqNCHv45QT9SWqfHCqY3izp7gWeKQspW6G9pWop1sHeayCGPvkjDJoWI6P3C4K2hfgtJDywfw3epd+AGyTIdfrZtFkvwuyGaKwjacMG/1IiqK6GD0BBH5f1dMMtFytGXPYeWDew/HAKjtdt+uGqnU3DAZZFDMNX2mgReQew1MBaD41srQsrAizgzeLeTK4Dn6y+Q3RZ3afpnEODkDqILLcN2y5ydFji4RGufTi2Nrz5jTTIZueXqMfDXBOb3ckOsLDSwvrO4bhU/fZizIemPpQDnGjJS/Zi7BW18biOzkNejpXpQr0T2awbB40UXJ2Wi6XqigaXTtwEMhnE0YSQHQwo1hXxeJ1ItknIVMcBySh4oPhUlRsEZSsUj8E8DGsorzo4x1/P5gLCbxf9ayTJjqOzAr4atIr91mNKfWgCflW4shrQ/tjFoQwvRjbfIszCn9Ote34YjDiOAAjPx5m7ijE8Ovm0aRCAkt1vf34Gno8LUUHdLaeTBBh+qzrEyQVfyL0KqCkkz+1WUDgAe91bb3btgEqOy3VyqbiNby0DFuwb/SU2MCcDYcuGn/5dZG2umbRdMuTv46CiIg342YvEZfUm0m9EvXHsDjRFonZAQFsSZwbK1a2NRs+VFft9Nd8S50Bi+MWs+IP6LAUN95RBCYnhdhLpAqGnNjfdUAeZ8QMhLHYWIm9thT/kfYpA96QaPj0nRdaTKQIz88piotRYDqNvSuRjqyfAbiRV1UzsS7IoDHziIjBUvb+wf6tk6WpZ7/tZsRNmocZsoibnUzyyGqgsyUSrf0ThxjM8KalhYLhVD6Yvgy1DyAllGrDAUpHsgMb7l2BlGeX6QC7zc830btZxt8wEoGObg8P1ybM/RRrXnlsw/PR9E9SpXT1HRdaKbXZjF73QNukIoiRo/9pDgSZ5zwQ8MkdYFOiJJmgH6PgxeXUU//cThBjXhg6VD6BDqeqxzOtsC8dAJJeS/bjOk3n2GNzbGDuhdvV36b6WYoZbmqcoI72pIdCdBukkPiljpnEaQMmnUeq9Ybb20SwrgWU+3WHWhgDHqG6RKTb5PwRnrVIS7IEcuVsH0J6dQb8c9qfDERQufMr9EmrZWghIpDnjfr/2+XaYJG1aYGFIG8PvSQNMQIn/flY9koh8VE2/fch5F1om+Kj6qvVwCahB7H6Zm28ejEUSEGVyLP3Jpnuq490eRWGxhX3BxlcJN8S6V8aply7TtZkOm4P+dsnRbWmY9oNsgA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea0ea432-c4a2-46c8-991f-08d9ea58298a X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:42.5869 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: a2m9EzHYqnq3zKoZNE/UnGMBbBlWwCVcGcNxRwO0nyzclFh28M69C1AOpvyJ1j6w3jQT/OCvEIS0g3jweGCI+I1gROIbMJA2HE9/t228tIM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::716 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::716; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" qcow2_inactivate() prints errors on different failures, let's not exclude qcow2_mark_clean() call. Still, if image is read-only, no reason to report failed write and no reason even to try write. Write failure is possible when we open dirty image for check in read-only mode. Let's not do it. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 04994df240..ccfcd0db05 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2699,8 +2699,12 @@ static int qcow2_inactivate(BlockDriverState *bs) local_err = NULL; } - if (result == 0) { - qcow2_mark_clean(bs); + if (result == 0 && bdrv_is_writable(bs)) { + ret = qcow2_mark_clean(bs); + if (ret < 0) { + error_report("Failed to mark qcow2 node '%s' clean", + bdrv_get_device_or_node_name(bs)); + } } return result; From patchwork Mon Feb 7 16:37:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 776A4C433EF for ; Mon, 7 Feb 2022 17:02:38 +0000 (UTC) Received: from localhost ([::1]:48476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7PR-0008CE-0X for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:02:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71d-0001y0-TP; Mon, 07 Feb 2022 11:38:03 -0500 Received: from mail-am6eur05on2101.outbound.protection.outlook.com ([40.107.22.101]:1216 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71b-0005Gz-3B; Mon, 07 Feb 2022 11:38:01 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gcIn10nWh7WwWH7NQeKIWMA3FjjF+yCZcqp43jtiSap2vVA5IKheZq/vOBBtTaP4YXSDp/R8nNC0CURuqWMPVrSJ9H1X/1+0izpLWS8Csoy/CmwQWx5EnrfxKlFt7+Mf97h2lNF2Jqfz51j7+IYTYLULmW5ncfGnXB1XO2Kq5GO5U13gnjXemY0p450CRZuDVrcW5Sk7U5Ymm6mpbhRhHjJqp7pOv+/G/JMAW67V1JSXtmRTvVVXRvrw9DAm3+UyJ3+0n0fo/46ismRq/bcnU/KekDfCWcNfJp9cYlCTLZLI8QVIDCicUEcsFf1YBB5ooO9sETmtGvkGB0qH6vvsSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=teNNot30Je7QmN/Gb8CSjZ1foW65qEOEJ6yy/d50Eho=; b=d9y407Qe8LV1hLYg0eDmXkZqUf16/y8kTkTCDXYkq55wGdJla1i+mEEvHROVAaFMzchTz4dM0NLxfhD91YjZb63MqImh7bDuwTNZXIYl4bwCCWT5kOLzqVfwNwBSCYvoVuvpLer1Md5uOmHA60wvMTOddJ5U4v6SvIzHi/Ta0hJDe4w52tC/odTKN8c2cLsiUAgdzddMU8+sBIfYZkpxEcdlQwjc3JQJDmg6uJIQRRVaaRJUoKXShSKJ5g5XqehIakwCqizoC3TDCNOiAPRx1hfJKID3hNVLr6lmnVvwAbKf0ELNfb5l9Km4GtO6+i0CGyu1mGIHToANGI55hHW3LQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=teNNot30Je7QmN/Gb8CSjZ1foW65qEOEJ6yy/d50Eho=; b=ZlPvjwpKo+bD4YPzJ4gbj9uIPUqSLuqKUpbIVx+Ck3P/ExHxcLYol4h18Uja/mIRbA8azdTQniyKt9mrT3z+hFodEE4ouGPpXiXTltEvUhKZXIbW57fmmBDgkd5KuQ65q5ZMQdG/jyqjQjZHS5C8942ybuDvXXb8w9Wn7DqnSp4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:44 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:44 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 11/14] qcow2: refactor qcow2_inactivate Date: Mon, 7 Feb 2022 17:37:25 +0100 Message-Id: <20220207163728.30362-12-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6084d552-2fb9-4cfe-84bd-08d9ea5829d2 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:26; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YtxZ3gBOjQDrJS8dl6zKNAQkq6o6Nzr2bvfs7nNuv9hiiqiHx2njWpJDbG2Gk4jhhT16E6oz/oannwncMtbAfFNi2S7GSz6BL/Ri5DjElJiPzJLcrlwkr8QawlIpIcxvWjz6C76P0EPxOGUzl2IR1NU0MEkjFGQ60RCdwKFs6jYmI2tTxzVSzpEPBbH7+GNn1+BuyIytmPGzFRlpM/YSdh4BGBwCxt2DbK0IRa6Qqhh/bTE2RNO8Op2Ivjs3dwx+xlYYy817Gli15n7I6+XWj+91C5SSeT6GAYGGmvQfyNnHsI2WjJvrOBlG3anBHumCmsRRGpVxbxdDks0L9dtssK29hy2yzwnypu85/yHWu0FTBZYE6BN2M1ATrSLrV49jRFWX0WKv5R9aIgOydusvBDWDnVYpFRoh88+k//gPOrj4XKnomv0sUMBVJK9Zhyh4NnArLpfEiSIHVXh+yv1gORPptOOSQhgwdmUhgEJKkvbhO80lHV+6idd5Kqx5Yb8xFRG9OqT1rty6U3A/QBz9d8xUtVzGiqMoXTQFKpJ3OpbzNUG3tm0IT+DkPrnkrwe0jaa2PcWthu4EwR57OYn1CcJn69wTsAvqQJv2/qVqaW+zm0whA0QBRudlKnDvcXx6rt0h8+Kio61qT6mm2cPEoMMbOmBoRuBVFns1qgZxDuUO1AOBzjvGVAxZCoqwLg8YihgvK7GxXtj9OUKZ752WWA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kRtsmRdMhzgCbQQuFVyHJDZqZ26HT5cai30+aACnddCt3cHXDbtggNY1dx/47fssGPYkqhOPO/j/90+Z3aFgCg5okIg7nhSJ8opug9S2oAb6l6CvcMGDYXfcWcqknVjGXcIlGF+Hfblb5LtBpuMUmXWPU8Rn6/rpfY6WFei6K24gAhPvFGdfwIybDD+W7rwd0U5h1808z4zoNznStF2IbIW+lBkxY0SKCri1rCFKBowRgXTOq27ZzzZ/JVfsAKyI7jTGvTOI74UIftHRLoDKeNMjiOjhDzVEZ13lluML/S34kQYR+Ohett4/LnY1i2A1s6sSIwPUT6o9m8ZNPbgT+UMPKEE6PtdeJoQI+wFOG2CZWG37oQdVocGoG0J+LUtSclpi72vKB10kMVPQAviv10qd4kTg21yUB9D8mBWxRtBcDROZaCHgc96BLGElrUTGxDyL1n4ICx/gYxx0Ak5SaMppSTu/k7EpbPVgC1Gi7ztNW7DKGvEHsMxVn/X2PayQPc/eF7+HRZaCQy4tlMssY2aF9qvyf0j4h6D1wsv123W7CrGKW1+KJqvXdTHBJwGMLpLg2x4QtyjUIlgzEL8cucxXXlF14yR00ciAh1zOUeBoQske4foSfftg3A1RR5Jyw5zzfIuKkbjQEklXs2Wt7WxgqHPWth95xLmpzJidP7J9GT6ihlnNVB7OgTWTxO1mXzLvrijztNjhGU+QMUT9n6HwD11PTD2J4vleLJ9Il0Ogu0KYRtocEU4tdwdPM6gaTq4Gs8dbbnE8fopvRRh0Cr5ll4RFWRgNE1Z21UUoy2V220djYz3+Yjgbo/XEAEhI57CYQbRkC3Xd6quOwJeUhGU5vLp72W+uao35ZM+jpECvhfZU87R72iC+CSbjNcPn088di/uH90fENdXQ0sGPucBkVgrB4Oe0nVS9WRW+NTvTjUUrR7f57ZrYbNCZONr87fYAJqGbTmkeNkzLpXTag8+UbwwJBEGsONDXuRMDRKsndZV6ABwWmP/lKeQSsLUasFEiInahP4jfyyUO3io54vtnJKrPi9Y8+NGzA0W4AOHfLsI7C/oBpPj68T8kSPJf069SQIAUfbMa9PDcM4BfKBxBrhwnrIKBAOaZBHswDsqPMhO8QrSIhk0VLnT12DIryI3+r0utYmFiR6IJNAsYBeaXwxr8F/aZBo55qR8fFI2JAC4lluCpAxevlwlBwLCOq0roKpL+TlUgVzmt4a6D+9EmiKXITusHjXzzBQsAQLYukk0qO2AtbK+bPk04p5/5obEBPU2oJqs71HnIj9VENwyj7J9mq+pAFRIZDX9Vg3UpiZ7JdTyl0/D3HntVPu1G1GM4jSlNHcTrHZr7ljQMLKfqloPXYM199xBaDO9ZdxqfyYZYMt4b5FfKcYYLhRcnhWRvN8MBJduiz9tnMnYeMMFAuAdas01yQ3rbu3yg/MHonf1SvlmNn3VbjWDW9nCEGpVZfR4P6rnC+uO8ZEbocU8Qd7ArJxLMOXI9QEh+NGzGl+Ez1pWKJlVn7wJ2I41ZG/jEVhDcF8lgy4+6IZVP+Moxo3/rGH12zBHnYGx3Nn3t71ygndYYd+bIioGj18PM+tMYf8cOoH63FIaxcOIs98ADhHBRkWajbGAklw7eGG9HalECbznKR8DZe25MipPmgovPXLFXwB+VvtCrmaUHUw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6084d552-2fb9-4cfe-84bd-08d9ea5829d2 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:43.0413 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f6RxjeoywL4P8T5KBo2iYOM9DhUq4Th6EQO3z41nUFuwyeYdAkJob2QPMwnG28h6YCvOc+X+7RSgbLZjLRsWKq20DjmQQ03Yunp5yKpF03U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 Received-SPF: pass client-ip=40.107.22.101; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add a possibility for safe behavior: stop on first error end report in in errp. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index ccfcd0db05..8ad555feb7 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2678,13 +2678,29 @@ fail_nometa: return ret; } -static int qcow2_inactivate(BlockDriverState *bs) +/* + * With force=true, ignore failures and just print them. Don't set errp, but + * still return a value < 0 in case when something failed. + * + * With force=false, return error < 0 and set errp on first failure. Nothing is + * printed. + */ +static int qcow2_do_inactivate(BlockDriverState *bs, bool force, Error **errp) { int ret, result = 0; + bool ok; Error *local_err = NULL; - qcow2_store_persistent_dirty_bitmaps(bs, true, &local_err); - if (local_err != NULL) { + if (force) { + errp = &local_err; + } + + ok = qcow2_store_persistent_dirty_bitmaps(bs, true, errp); + if (!ok) { + if (!force) { + return -EINVAL; + } + assert(local_err); result = -EINVAL; error_reportf_err(local_err, "Lost persistent bitmaps during " "inactivation of node '%s': ", @@ -2692,8 +2708,11 @@ static int qcow2_inactivate(BlockDriverState *bs) local_err = NULL; } - ret = qcow2_flush_caches(bs, true, &local_err); + ret = qcow2_flush_caches(bs, true, errp); if (ret < 0) { + if (!force) { + return ret; + } result = ret; error_report_err(local_err); local_err = NULL; @@ -2702,14 +2721,25 @@ static int qcow2_inactivate(BlockDriverState *bs) if (result == 0 && bdrv_is_writable(bs)) { ret = qcow2_mark_clean(bs); if (ret < 0) { - error_report("Failed to mark qcow2 node '%s' clean", - bdrv_get_device_or_node_name(bs)); + error_setg(errp, "Failed to mark qcow2 node '%s' clean", + bdrv_get_device_or_node_name(bs)); + if (!force) { + return ret; + } + result = ret; + error_report_err(local_err); + local_err = NULL; } } return result; } +static int qcow2_inactivate(BlockDriverState *bs) +{ + return qcow2_do_inactivate(bs, true, &error_abort); +} + static void qcow2_close(BlockDriverState *bs) { BDRVQcow2State *s = bs->opaque; From patchwork Mon Feb 7 16:37:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A11FCC433EF for ; Mon, 7 Feb 2022 16:57:55 +0000 (UTC) Received: from localhost ([::1]:43646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7Ks-0004nz-1C for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 11:57:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71f-0001yF-Bs; Mon, 07 Feb 2022 11:38:03 -0500 Received: from [2a01:111:f400:7e1b::716] (port=32353 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71d-0005Iz-6j; Mon, 07 Feb 2022 11:38:03 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gs44eXXSp9S8imgjU8cSJioaQW3GQ58czbg+RZ2ge+hvNje6cHrjWfjJyAnOLookbtqwZ5KnLCdBp7zg96Tl2CuGPEvLJzuCM5SlT1vGHI520u+vQVq4a2u5RJw9tL2wN612+lQmzthzm4MO3fD7XgsXmhiwUT7THWSHJK+tLQvy89zS7spnqQW5LSis756yzDYz7Yz1IASLAAiQr9DawwFQTr9/6EIlUBYS0QbfhLdNctIJmCiVPi36Eu8TG0FhPAX/ylUGBdhYQzidt+cAa46/pJujM2V/GxaeXMKrFdNy/z++Oc5DW49PHa2iweLDX8kcKgHftZ+vamBkjuwEEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H1OlxZzs7F0wEu/bdT7/ECBbghpOwnIpR9VbwgCczCQ=; b=nUyJWUh7K/H7P217eu7sWkzpqK50hnPb9e3+mM6UCHJaKXhT7DvbCiskcEkuuT3AXdKnmeD7tfOs0lM4Ki9dtcI7CPVSykyaP6xibOHRwCuKBFUtDiJOm06zTaAmTrmjUDzQ3yrnf3NyvxzLDfSOqzlVuyOBolMrp6mwDOj+3aIHA32R1VjJ4VKX9Yr/PJs+sk5LNMGUWkFccDYtXcj1derg88vjU4at6Zgw0T/ck6bKQQBZLDDpMHRv2V7ImjZfP2YPtuf1ay3AHTkMbShslWGjIdGJNcG1W2c7Gjz/BaehCDf9d/aIvSTBSwlhUxmQRX69WcvBZfxByzWuB2dw2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H1OlxZzs7F0wEu/bdT7/ECBbghpOwnIpR9VbwgCczCQ=; b=ibhR/3ogQmjeYGckIVuG1UplcvK9wOOgWLazG58eXGPYnKHhKxjxAVqNqy1N2EUkTQcKTWXB5rcNcJKuWxKme+nL08qoC/JgPPvj+jjxtO+tpN2ABJ4S5vyHkJ+BWM3VMQS30fYkWrN0BYFVMHlEEv26wla+gDtnvNvub92M1Eo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VI1PR0802MB2288.eurprd08.prod.outlook.com (2603:10a6:800:a6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Mon, 7 Feb 2022 16:37:44 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:44 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 12/14] qcow2: implement .bdrv_close_safe Date: Mon, 7 Feb 2022 17:37:26 +0100 Message-Id: <20220207163728.30362-13-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0c082e7-cde5-41fe-4375-08d9ea582a15 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2288:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:117; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e+/v9d7A04cY4zRG6VZ/dNO2hhoZfl5wpG5UrqUqlsJGA5giiqNTz7sN+50oCWOPPLikESH2DmvfLyBs/8UpDfGClswqWUw7jSXJ8WWEqKvztafiEQDxCmVunRGoJk+8By4Q++pHqK2sMbFMnJitdvBO8BukRfZjkYdUwsUHnppJIwSaiTmIZHtO4agmjE9+0z29j69gJSNfzzMMFzuVxKSf2Y3pk/cFqruP3mSNYJ2fGaivdc9koIJ3hLQnrzmqXb8zWXGiAsn60fTsUHdE3UakASxbg/GKIoe5jPxgX+46FH8tJo0ciOJYdhCe5s3lfAIF5UI+KvyOtgou0b8mT+UTMy53tgWfeCdUnDAB1S8h7E0vETHfnb60iROlQRekkJGcrQDYSl86Pa98sjP5q3wcVw134SKM1aBNH/qdUgzq23WyeEhn37feotqxUVWyEtxhPhC/Qij2a+uGOs1/gwp67WZXVEnQjQKeFrncAmVmMrMHn1fQfaWWK4B/UaJtxxVp30xlOYmDyJ9Q683HYbRMg+3t9OFxuobqo8W2DXNB1zuxvFH1H+d/6SbVKfytXnZ6bJBF0shtK2NrJqCeFWUaal+P7nythfctUeod/HXvD1fCKV1TPivYFYjUHe/OTa6SEu2p8KBZnAK+WG42BRphxgZsgrcsvDxQmgDOJozT/3ePG6i4Adi5C+58Nm23iid2EtRdadPcT6AVI5MH9+eTyrUbzvzkutSilsmS/3U= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(66946007)(66556008)(8936002)(8676002)(38100700002)(83380400001)(66476007)(5660300002)(6916009)(4326008)(2906002)(508600001)(26005)(1076003)(186003)(86362001)(6486002)(38350700002)(2616005)(107886003)(6512007)(6506007)(6666004)(316002)(52116002)(142923001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 31FlC5QHCmg2MFsj4H0pZab3ChbaMSlo3G/C6x8aoO90xYvj06AmqvqdShBpd7EjF8fLkSoDhnmDcgJ8Q6zJmaVBzRqncvthNRQvk0sXK5mQ914oF0ZolGDP03EHn2ePMG7nJ10R57EZZDcUAyb+bmBEnYUUX66YBBn53nKTtIq0AZha+p924uBWw3pXkGmU1dGA5XoZ/axQYAX9uI6Sge3GMVVCffGRNEzxoJxlIj7fWtD94N6DvQDcJ7SlL4XgfzmTdrjVIHYz5jRnBMsb8JZTenJPYL6x1wVx8H+3c9fJmucI9qQNt7XMSrqoO5NJCtcbdW1wnIKwmdkbpZ8We2IWbjrVIEDg+FJCmbIE5UtPaeYd+Sjb4q3CyHsNt9KxJBH6OSKGnjRpfkAxhzUquIj6UR8d3LX0+xjSkKNpiVIVFWOgEqheSP0jI3+pJiB63S/odBlz+u7IM0RhUDhAhGaq3l9aRZN66nf6kZMKvZQejSyWvaafEyI2kmY8a/sSxhuM5ycblLydPaUamu9SgmoSfFMDSkJZblgHz6Yh0w6JMJPa3VQ3IovezKs3rSHGq9N4nmEB/5p58vtbm4KmdXxDMwgFTOYMXMVeRJXp6DpRTNPZqF5/sY5EK7vvNON/uwjbGfQRvy04UJ2gMvhqiBYx148hYI6/u8cHHe7cKCyYOdfdkIOGNzNg3E8nGe5G+EGY2Ge4hSdMrva1dGxQFL+AkHQxvxzOo9UyRpZiIhwaA1F27V8vRvc2Jgr8PmU2jM7PsV3o2XXxdP/aNuAeIQIcA6ONCCXj3XgUGXpAZJAHOCooceuUihVbp0ndegyhmlH/F3IAg5zIwSfZ++dsKdp/H1jPBTUnwIMkda1CdGCuqznfekjQ7YUJ1qs0lVXaVLsWmwvjRy7N+4BGQ1/UeNz7sNfM3Gj5oHhxlzhqRSW2gdoBd+MSaaeAYHcECUCgZy0By296TazwdpYSIoyJTiG85rneDKUJ82smsTXay41+79GBl9dz1heXi9g5cYknsfLNt5BphfOGk2OPP65N/DfN79Nl4nX3Dh+WLQ4bWa3fCTxn7/Pr26EDn0ev8PLX5TwO852SjjpXPCwUOdErpmxcV9n4HqwNURvN1YHWcccguIwqDRbzjLccJr0LYMl2VANgfx7WJVFfWIYfvdl2Z2J64RYcVDIAA5q6iBg91dmei901lWswkq2XleOjD0kg4P+eqK5xWa4mVe3ySTi+80GNQxA6Qqm3P7FwRHHguzlLzAOMPKdvXzwv9HCEeaNOn5h8GII06fL/9eEwvqC5fwbxkgtcKA0WV/AO+kwJLHOlPWmJITfVG3pWBkKaCCjWDRny+BXgeR7zNazCiUBUGgTRTkIrTSqgoZE9f8SXXM4AXJ3lgSsJTz5mB0iwvRwizy9y3i9BTCqmNWfX2oIRiuqgCSoAXLtRmadYhvlV5EiAQm1ig6fOUorwo4dC91vTEMxMS5MdEpC0FITosAW1n2nBfFW/hY6jZGNQc68CRWbe8pFN78Bl2UE9EQPk3+6RbsbLjHo2GcYNT33vEcZWYxQgJdynOOZuxUv8FOLA8PJ7TETgM99qQsEUDkl0d/AceZI17ak1JtQLYov3R3KOok2SQRd0rcmtOcC+o/q1bucJXXZVVUfY+wG2rXeiitHdzntfnj4/qoddWEdfa62ksA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0c082e7-cde5-41fe-4375-08d9ea582a15 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:43.4318 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2wpt49Lp9pGhe2SnRzAWczdKmkcInfO0+FGd3utki7E3xHkpc8ARNBSuUIwOx9C0akl+zR+Hnf3xn4Jsj0d9vZ7lBIjpVHWeo2PwkRxBtB0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2288 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7e1b::716 (failed) Received-SPF: pass client-ip=2a01:111:f400:7e1b::716; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement new API, so that qcow2 supports blockdev-del with force=false. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block.h | 2 + block.c | 4 +- block/qcow2.c | 85 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 42d78a7a31..fbb5f3ff6d 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -672,6 +672,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs); void bdrv_ref(BlockDriverState *bs); void bdrv_unref(BlockDriverState *bs); void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child); +int bdrv_unref_child_safe(BlockDriverState *parent, BdrvChild *child, + Transaction *tran, Error **errp); int bdrv_try_unref(BlockDriverState *bs, Error **errp); BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, diff --git a/block.c b/block.c index 187732c6f8..dd2ddedc86 100644 --- a/block.c +++ b/block.c @@ -3216,8 +3216,8 @@ static void bdrv_unset_inherits_from(BlockDriverState *root, BdrvChild *child, * When @tran is not NULL, first failure is returned and the action may be * rolled back. */ -static int bdrv_unref_child_safe(BlockDriverState *parent, BdrvChild *child, - Transaction *tran, Error **errp) +int bdrv_unref_child_safe(BlockDriverState *parent, BdrvChild *child, + Transaction *tran, Error **errp) { if (child == NULL) { return 0; diff --git a/block/qcow2.c b/block/qcow2.c index 8ad555feb7..a8f891ee34 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2740,23 +2740,24 @@ static int qcow2_inactivate(BlockDriverState *bs) return qcow2_do_inactivate(bs, true, &error_abort); } -static void qcow2_close(BlockDriverState *bs) -{ - BDRVQcow2State *s = bs->opaque; - qemu_vfree(s->l1_table); - /* else pre-write overlap checks in cache_destroy may crash */ - s->l1_table = NULL; +typedef struct Qcow2CloseState { + BlockDriverState *bs; + void *old_l1_table; +} Qcow2CloseState; - if (!(s->flags & BDRV_O_INACTIVE)) { - qcow2_inactivate(bs); - } +static void qcow2_close_commit(void *opaque) +{ + Qcow2CloseState *cs = opaque; + BlockDriverState *bs = cs->bs; + BDRVQcow2State *s = bs->opaque; + + qemu_vfree(cs->old_l1_table); cache_clean_timer_del(bs); qcow2_cache_destroy(s->l2_table_cache); qcow2_cache_destroy(s->refcount_block_cache); qcrypto_block_free(s->crypto); - s->crypto = NULL; qapi_free_QCryptoBlockOpenOptions(s->crypto_opts); g_free(s->unknown_header_fields); @@ -2766,15 +2767,65 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); - if (has_data_file(bs)) { - bdrv_unref_child(bs, s->data_file); - s->data_file = NULL; - } - qcow2_refcount_close(bs); qcow2_free_snapshots(bs); } +static void qcow2_close_abort(void *opaque) +{ + Qcow2CloseState *cs = opaque; + BlockDriverState *bs = cs->bs; + BDRVQcow2State *s = bs->opaque; + + s->l1_table = cs->old_l1_table; +} + +static TransactionActionDrv qcow2_close_drv = { + .commit = qcow2_close_commit, + .abort = qcow2_close_abort, + .clean = g_free, +}; + +static int qcow2_close_safe(BlockDriverState *bs, Transaction *tran, + Error **errp) +{ + BDRVQcow2State *s = bs->opaque; + int ret; + Qcow2CloseState *cs = g_new(Qcow2CloseState, 1); + + *cs = (Qcow2CloseState) { + .bs = bs, + .old_l1_table = s->l1_table, + }; + + /* else pre-write overlap checks in cache_destroy may crash */ + s->l1_table = NULL; + if (tran) { + tran_add(tran, &qcow2_close_drv, cs); + } + + if (!(s->flags & BDRV_O_INACTIVE)) { + ret = qcow2_do_inactivate(bs, !tran, errp); + if (ret < 0 && tran) { + return ret; + } + } + + if (has_data_file(bs)) { + ret = bdrv_unref_child_safe(bs, s->data_file, tran, errp); + if (ret < 0 && tran) { + return ret; + } + } + + if (!tran) { + qcow2_close_commit(cs); + g_free(cs); + } + + return 0; +} + static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, Error **errp) { @@ -2793,7 +2844,7 @@ static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, crypto = s->crypto; s->crypto = NULL; - qcow2_close(bs); + qcow2_close_safe(bs, NULL, &error_abort); memset(s, 0, sizeof(BDRVQcow2State)); options = qdict_clone_shallow(bs->options); @@ -6043,7 +6094,7 @@ BlockDriver bdrv_qcow2 = { .instance_size = sizeof(BDRVQcow2State), .bdrv_probe = qcow2_probe, .bdrv_open = qcow2_open, - .bdrv_close = qcow2_close, + .bdrv_close_safe = qcow2_close_safe, .bdrv_reopen_prepare = qcow2_reopen_prepare, .bdrv_reopen_commit = qcow2_reopen_commit, .bdrv_reopen_commit_post = qcow2_reopen_commit_post, From patchwork Mon Feb 7 16:37:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65589C433EF for ; Mon, 7 Feb 2022 16:52:16 +0000 (UTC) Received: from localhost ([::1]:34080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7FP-0006FS-5o for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 11:52:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71X-0001vV-Gw; Mon, 07 Feb 2022 11:37:55 -0500 Received: from mail-db8eur05on2129.outbound.protection.outlook.com ([40.107.20.129]:2208 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71S-0005Ix-F4; Mon, 07 Feb 2022 11:37:55 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wi+xvJy7VR36YukFCkevHEehmhYKEp0Avn0ziBotL0KY1DMg06O6WMuGT4U6rH/MQd/fGn8vKFMPEj0Ck2GSZeKdEA9zOP4YSjUdpl+9vXQtrD4fmrBO61JDtxaGCtW60yI7eH7LSTmf12zF1n7BuUPZbWKevzL6vO3p1K7LdiFh4AtTj5aHuuJQ/QTZHVdxQobq8SimN2aJ6d9OEFXcBaa+8W1bd2z1HvEdRpL+6i5lAS9ku0zP9KCXGnVRHoann+fniCIUv0EAMIDVSwgaRImH0QHqrapc0SN1yrfkGKrvLrWc5yTIerB1HvdnIyEB2N9oBVT0WE5ySVUnL97a2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=e2lcUxEp6by0XL8MDp2pEofILUfI9zC3aZyHKMkrhHM=; b=ALa3okq9vF0J1w0bcEzPNVA/zqYEmXrdvdRMdCaH4Dt9kJQ2iabypgGcr0fDtSW1ZioSRPHkfEqAI9R6YIuRcreh18ckhWfpsF/SX090Ilfmo5m1Uvu72nNd5vqGA1Do2k87PK+q4hZRBVjcUKVoPcIfRpp71nQlzw6geldVSWyL3Rj1LJ6ye1T3SRp7riDtsZEJBuC/o25T4c5RdjB8Hi9D/WhCcGAsW2PDPRaOc8k31C5IzJ0yPefumRAuYqb7eWosw77O2PzvFt6Vz9uApsC83XykT8WNqRAyGtTNd6crpLeEvy/LFxEfp7vZOPKBGBeFx+odg6h3vLRheRR3Nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e2lcUxEp6by0XL8MDp2pEofILUfI9zC3aZyHKMkrhHM=; b=lj7UfGFvonIbdXXH1Z7l65/qblXQm1VVZT1QS3KxfmK5nEbKXsPGOZD3Ef54hpp/X1PIoL/qE01HYtRwaE7z5OjzqrcpgEuAyJrZwmabmOCdVhimg7r96J2Q8jIildNl81WjLubLt3n9DpbZuNFeTjWd/GXixsf9dtt+h7dHN5E= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VE1PR08MB5085.eurprd08.prod.outlook.com (2603:10a6:803:106::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.16; Mon, 7 Feb 2022 16:37:45 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:44 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 13/14] block/file-posix: implement .bdrv_close_safe Date: Mon, 7 Feb 2022 17:37:27 +0100 Message-Id: <20220207163728.30362-14-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df1fb12b-0b45-4e11-023f-08d9ea582a58 X-MS-TrafficTypeDiagnostic: VE1PR08MB5085:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:103; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /fzcsa4mokcZHCLO5oKi9gDh5DZlrLTqK/pstvxIHgRNoeMMZFQgQXzpWCMAuqe8JvpuzJKMv6inaxZnBwvm7EoGrOSU+HtH2MAuaBtuIFxrMTGhn4OH0hY+MF6sJi3/y1i1dkYB96WMawelRKgh8soGTbObxJWv1DkwOrVfuiafR5uT/F/5bQDVFFPFJAktU8I6LM3EyfW7MU4Q1vVftpvj6dTBiPdAzzjQfEbjD9vcuTLkF2Tziu6Yaa26SknBA13XYK6Wl0MvIoU4s0sXeWN0f1v7iH8IdgHPTsm58IXifv6V25nVMq1QSMjw++J7Hy8uO93XOoj0BCVv7bX8jTzlQp8ILxgOakhQqQLImPw5WoCofUGoWhO4n3h92DRPZO7a4bZnL2oEw1N0Ju+Jdrjka3VrGbC6OaSc+bWN/YiIPu/XkboVEHNde8oCpBQkZjp3NxQvuS7CItyxiV6ca/Nx93w5xT7TW7cN1QiLHdxbx1VEd9+cEgj6TXi55eh4y3NiIepG1QPfExpoALVor6oHMwM0fe0vuHPGoSxllvXumsie2k6nOyX1Q3no5zmY8pGwnxdsB2BgmxBdK5Ee474vkLKouS6T++iV88/OidNBkyaKvSdSVl6lqT3WpFDgbC87l9p6blF40l+BZUWjNFQt4wZqMqo5IiMqIkjqi3w7rVwpphzdBX1HeeWs8hB/MP8REQkEPz2BxD6Wn7ajpwpW840wUdO0T3SRvUyfXNzdxW2+t70Gy5Qa1ht6cPCM4xjPDmr1Eizvzl1ZTgQ0Ug== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(6916009)(38100700002)(316002)(8676002)(5660300002)(38350700002)(86362001)(2906002)(4326008)(1076003)(66476007)(66946007)(66556008)(107886003)(6486002)(52116002)(508600001)(2616005)(83380400001)(36756003)(8936002)(186003)(26005)(6512007)(6506007)(6666004)(142923001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ixcOhuqtezyXRB96vHWYH6r7v/C788s833ilR7Y7qqFqsCS+oPgnNN20kpz+Es3YIFiVa7SrpPH9hWDyICfrpvyRHu+sPMz+8ST9u+WGd9EANB3M/z5KpelCsrQ2lNulRhFLxwze+VanDlRJP3Xra+XiNinJDGasInf+AN/5iVfAgD2n4oSPPi0AklBKfgDphSA640+dn3nlJvvdpi0YfFvwROZwMCpiJo7+1s24T8uOZIGV9K9xXGTX/Z3YapxlOWMYYBR7TVj/W9+FkvG09EbfIwWdKmVczPjU93Cwa+Ho9xGl7fdfKNCWcRFqzzmgy8EXP5AiP2WSMuD+5LagMcPV94+XRWZ0nFgJ+/8nzOMbJT1zIzYUm9/iuMQptfOGP8nhCRCChWpZClIQHYvKMPfWCjDIi7hmWKcG8B7Q6o0o/wLKgdYUhUcAynImcMfz0VBE9r6ZV9TgNVBghp2QkPw2YVDBqQHb4sdmhWdc8gvO9H0MFDIR50iHwUtS0V19ts1pfytHq20/PVsb7cruUQI9r4D0IU9MfuMXKz5/w6z+hUJNsJLLRzm8b0e4DD0vmLvWyf6TUs2wijTZflxlfpgI8spSoY6P/LAVtKGD3uDRqjMBFuLwcshOELjFGBg5sxA8wUybSEseFziyu48Mo8yuERgykLHXjVHmtmBjYDU77fIqJqiw5b4i6QDAWsirkIyvAF0ZtqEuF0JBbwydthbjVPDje2cb/yMj5UAsDyzxEwmp3CX5HQqBxypQxZmM7TtUvipyFmILe6l7cTKKn7QzhRaY4CR9gSyNcuazs1odwnWRp4Q57efX1/znsQmYMyWqRB8ACZ2Jf4cK10vAgDx9cqCARuYSDMaYNrfxqvo7oMrVkB6nlFJGmq5mAz9VAKEcOPM7vrHduJsic99plbTTQryE58Fi8ToV+9IOVLpi/CLfBDSbSr4AnTzx8WTQhWs4gpjedB+HNZewUC382g3RKPuzpOMBBxZAKKK8YvptArO4komATcTOI6z1H/VdbCrbsEDAtR2/QS9EEJVUbTM6I2FNLLhRhFtzKNIgYvIOkKovW8F7ALmovas20IrLoKu5DEsDaycluoS0AbV8pSMA3k4COehEZ+p27uEQWfLsCSAaGautCOe6H58QWNLuH/Am7K45/dBJzlwwyUmpPieVvDqaCumRNigJB7wxlBdOFuToTi0JwWvARqC1j8cnTyZUgQQ+e61JYDwjC7/ha+n3bMlvdw76REaH7CTUoO53JzBiBZRg5yxf968ns7L90zcRdIVe3D7K5QUPOezzL2wM9XFGuqoa3AWgM9UOAQSaOqe5N33QZtZx4rX+Yp4LIz1FIGmxYHH0Gb2KjsekjY2FKIUoNXVycMVzyw9Kuo9xk8kTLvSTRefb3qUtHf2hZTvniiR0VMpMoMPwDfFP3Y2XCbs3q87sRa8zx9NggS55GMw9OkwptyReo2cZEfHxbt6eFl7bYvGapV5cH7njdgj94Tmvqf6kp8ymWN+jo4UsBbTOH057yhYPRKBiyVnPuLYXReTLlADppf5Fxu287yXTU11DnFafg1Gr2rNp3/FRowG3Po9URnYG6UhHknRx5bWHVmvUWJ0tEsh/y7HSMkkIu7XLQV3qOsEkYDzmiJUWddjBkMxiAGnfSKaWlsrMh0NjCrym2ROawvMmwKGxTg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: df1fb12b-0b45-4e11-023f-08d9ea582a58 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:43.8849 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PnbA7TsucSjXTTryUkRDonwjuOqXpZT+Cyu2lQ2cP9dowYq2kGSWBAlcLeApZgc+MnPVsvr/UafKep/WusIsqj6nQKxzxtNQKaEQgnQ7qlo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5085 Received-SPF: pass client-ip=40.107.20.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Implement new close API for 'file' driver, so that we now have the minimal set working: qcow2 + file. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/file-posix.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 1f1756e192..90642d8185 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2195,14 +2195,38 @@ static void raw_aio_attach_aio_context(BlockDriverState *bs, #endif } -static void raw_close(BlockDriverState *bs) +static void raw_close_commit(void *opaque) +{ + BDRVRawState *s = opaque; + + if (s->fd >= 0) { + /* + * Closing fd is unrecoverable action, that's why it is in .commit. + * So, yes, it may fail, but we ignore the failure. + */ + qemu_close(s->fd); + s->fd = -1; + } +} + +TransactionActionDrv raw_close_drv = { + .commit = raw_close_commit, +}; + +static int raw_close_safe(BlockDriverState *bs, Transaction *tran, + Error **errp) { BDRVRawState *s = bs->opaque; if (s->fd >= 0) { - qemu_close(s->fd); - s->fd = -1; + if (tran) { + tran_add(tran, &raw_close_drv, s); + } else { + raw_close_commit(s); + } } + + return 0; } /** @@ -3278,7 +3302,7 @@ BlockDriver bdrv_file = { .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, - .bdrv_close = raw_close, + .bdrv_close_safe = raw_close_safe, .bdrv_co_create = raw_co_create, .bdrv_co_create_opts = raw_co_create_opts, .bdrv_has_zero_init = bdrv_has_zero_init_1, @@ -3643,7 +3667,7 @@ static BlockDriver bdrv_host_device = { .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = hdev_parse_filename, .bdrv_file_open = hdev_open, - .bdrv_close = raw_close, + .bdrv_close_safe = raw_close_safe, .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, @@ -3771,7 +3795,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_probe_device = cdrom_probe_device, .bdrv_parse_filename = cdrom_parse_filename, .bdrv_file_open = cdrom_open, - .bdrv_close = raw_close, + .bdrv_close_safe = raw_close_safe, .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, @@ -3902,7 +3926,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_probe_device = cdrom_probe_device, .bdrv_parse_filename = cdrom_parse_filename, .bdrv_file_open = cdrom_open, - .bdrv_close = raw_close, + .bdrv_close_safe = raw_close_safe, .bdrv_reopen_prepare = raw_reopen_prepare, .bdrv_reopen_commit = raw_reopen_commit, .bdrv_reopen_abort = raw_reopen_abort, From patchwork Mon Feb 7 16:37:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12737780 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DAA8C433F5 for ; Mon, 7 Feb 2022 17:37:01 +0000 (UTC) Received: from localhost ([::1]:41808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH7wi-0001gG-5l for qemu-devel@archiver.kernel.org; Mon, 07 Feb 2022 12:37:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71a-0001wC-Nq; Mon, 07 Feb 2022 11:38:01 -0500 Received: from mail-db8eur05on2129.outbound.protection.outlook.com ([40.107.20.129]:2208 helo=EUR05-DB8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH71Z-0005Ix-2I; Mon, 07 Feb 2022 11:37:58 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j/zNg4+g6TCZx0qhQh/u7wj9YxjUVmRs/e0KCKA9IYQJP0VJkVLEFRtGhIxyx2NRHvZtzZj5yimoOIohYAdW5f6UkO1bm4jHf3+02Ef3C79gY8jhv1BQH7j9TIIDz0BNOUWvSA0DbGOz4nvQub7ZC1O3Qrw742QMUpxE7BdEjli6adUrHfRHdc7mAR1Y36wb2L9qd/XZU+fKIbtEYgGM6GOYbO2Hi6RE+LlggmDsk/HdBlKTI+p7Jq7Bph6E8R5ApDxPjdrapwmtqIEK+vxAzhSTh+gDG38yPqkNM9isrzsdsyNhQBdBzPeoMWo2fOYa/xym1OnwLqooeN60CIUDzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p6N2areXa5/PvBykciQCdMGLPxqi17k9S4yCirRbb3A=; b=OgiAkCAkA6otDuHZWz9KxLWOaI7diYkaeGmVbvzMS344B8G/J6CGYWEmGtI/IDl1GAJiKfax2cq7M3XYugjduakBPTylek8VnDrIcfpAzma/Kpcct7Yx6GTvW8pv0bO9J40zPoNZWe2102XuCH3kpSMg15UOWIMGEYAkzniDas1yuN4+9+GuAY6MTaxmgyATtFbS2VeBFSjv/JA48fxgsQ5SZ4NKlCEGU4W4Pb2gs3EII1Nc/+OM6W5fQwhbkkvO9nvSG5uNSDMqht4JwdmWmpzJKG53VxccWgtuyfd3c+wdKGUddtpxWV77q+PCDjIvOXatQp+tKQZu2flcAh/S6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p6N2areXa5/PvBykciQCdMGLPxqi17k9S4yCirRbb3A=; b=EG7aMV5HB3uBGTvk0D1LyIkrAsVwBr4wCZWyGmQ5COId+Om1/15gYhAy6LMrlq9NZ/WcYBRtZew9PJyqPp6Ea/iLRJyVhLjuC9RfInC8bxz7bfD+z20Nr6Kd5ycxznYd5rOUS0WAmYYVwqMZedkR1tpaQhbt1leB+Hk6dmdxTUo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by VE1PR08MB5085.eurprd08.prod.outlook.com (2603:10a6:803:106::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.16; Mon, 7 Feb 2022 16:37:45 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::49c:67e9:3e24:8714%4]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 16:37:45 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 14/14] iotests: add test for blockdev-del(force=false) Date: Mon, 7 Feb 2022 17:37:28 +0100 Message-Id: <20220207163728.30362-15-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220207163728.30362-1-vsementsov@virtuozzo.com> References: <20220207163728.30362-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0126.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::31) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab80776c-0f18-4ce5-9b5e-08d9ea582a9a X-MS-TrafficTypeDiagnostic: VE1PR08MB5085:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WpEl7amz3XF23hIofcy14Wngh+e7fOhGvJK/zWDc8q8d7hC0VxN/AoypYFFIqW90pZOlYWEgwkE0k7+MOWLx4KfMl6RP4Dmt4JO5cG20bZHNjGiUUHocJMxPJl2qEEhG9bz4kq8vLWn8kHIm3rqdAhGvN8ySot67IVEG+/LjTSp+7bANHLNN1fzAgzuloHNxesllyTMDOy4u6P1+WKPsa8ohjQdkEpuptzjluQkhubqLwj1GT/ZACMnZWgL1VLaMFufZMer2krF1Md1VgKM2b92aFAQe5V6kYzeo3P/rXA9G0LxUUsVjytIDUX3qAbBUURCB38RcqyGxq15n8FherQbn/YvOm5YGXrAX1i1UsU6SXH2dgVZhginHrBFhbSutzJ+qEdZhIe8ARsvM0s9aFpkMqT7PQ0P9U3K106AnQdhTeGLWohnYYTH6BnWGyZjfylIKmi77e/2qM18onOkvmJV5I2rPoTf3ifJhtWk7n0ldCX9komaNQClUJkr53lBDeMGu4KbGrWd68L5dvXrkl1JJg2Z5WwRJc1S8t92Y1DyWbLpRUoaxAy8Wz633jlTO5ZJb6sCf/rQEeRl05jzEhAM9216p3k41jr8LpdjHMgNKVaFwox3YSSoktalyJqBvkdii08UtWWVz/7HmUXPQwE2SekcGqyXQKfctZ+F7m9Bc9899Ul0qCwSBdqbir20+8c79t84F4fpPxqv6UT8IIzwZ8kwzZo06vCYQCVP/gQUII7orqxS5k0UJvpj9Ku1+hcLaDXYMq3lLLVSgXmCeULD/w++VqobFq9hfHXQltDV1nQnp2PAqVC1nxcv/dhQKV/4Na1uyEYfZ6xmJgeiHpIVq7fEQOSbSeXeDJE12kQM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(6916009)(38100700002)(316002)(8676002)(5660300002)(38350700002)(86362001)(2906002)(4326008)(1076003)(66476007)(66946007)(66556008)(107886003)(6486002)(52116002)(508600001)(2616005)(83380400001)(36756003)(8936002)(186003)(26005)(6512007)(6506007)(6666004)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UOLRvQ7DIrnXS8oC9opsA6WyG+uUETcVfPQFwqNHEtJj5JJV4VpFcddpFwWjuKfE2SjowgmNY5EFQ1Z1CNvMHiggm8quDKQLW0zy/ihd8AHOqMZJY//SyGzp4Eiro85oVJDXqVadZ1M/b8DoDGbq/6itdT7z2vybaM5T4IFrYNAc/SysIP9fAKkcXgKYxuwffABZQbWGJ5iAdtEbYhpwit77+vP26bVvZ8RjoCbeysd9PTAeJ5FuOgnBRmgiBPvfT8bboyKPiCNjxDlbgFeCT4JF4fwdxa7WAL1rM2ZPA4vicssP2djOvqYpIjjgt0hVmUhWvEDVG2nmr09GgSzcF380p43whk/X9R6p5QqsXSqrYJ5mQf87sKBgLB72MhoDLbTdAUustv5jVMVtGVVm3f6+nRuwOC3dvsIKJEdiLGMn7lyjCedwnmeAsSwLjpsLYYRHox09f2uv5nhz4cEGmBwbG1gaqU83nQC2r3XNNSgvzOr+TX4DaV4obQJxatl8HTu+V5gT5sEcHfPsIiiTzl5r1QWiWH9TwfOC0/MUZeXVfd3pKTtve6cAj4KrQ6VI7swTg/1E1nVMNWyOyjfE+7C0PCsCKLZ08jJK+aqY1+WAwAvIVftd+qT+jeOC3sK8vGs7JIdZ4V4kRtwg/VBrzHru6+RKlGEdOL/CcOd8XIM40qvUYTl06NWJaFFv32lyenZR+GXuNlqB4Ohn+TKDvOmYoX+iUhogvU7ZU1h9lpeUm93BcR4L23l/L5ov17xzyQjR4P7TCf6gcenod2S2lpupwo3+kQbmJI+Lq+4k4VFD2BDsUEdZSv+1415iboLyR4QAdjzWNQVO7ZerGDiTs/qjXtrNEKLUWFkD7H+3V+U2z1bougJvDyyuq9zneIBIEjxc5siFkR/mJvCQK0OZZDwKc94nVsFqVZoLB1X0wJUlrjXvCILSeMjdBqE2ARS9uszDDe9iaCtcbnlXZDgrfrXlortf4+v062XnemjGBjATWtn6OpDe3pi3REb/wO3vX5hy8vb20Ml2Ez8ps8t6ytuRigB0uJepPm/kqJ+/5Koi4QtIuC0MCRrf5Ji5y2W+CZfZa0sQK5gplWBYFkuXA9j+YF0FXXPOTlQKOaziA+BczejU3u2+KJV+ERqxdlmxC0FD/wq06yk6ateoN6s/JumPtAomAUyVL7A2eepaUM6ReKHKlbZQqV2R7VtdwRCLdQbjqQILR9+2J8QBVyN2/ZUWwfelj7f0dY5m/uILuiWQmGm9FoszCJV+1XV60qNTV5ou7EGS+JpjcRNftux5MJYy2iogcAu0BWXMstrWC5jDOZzaT5xueL80mK1mptx2Y61hZ5qkCDJBVOaE8JK7PUMpJAuwDEsxvj31ocJC68bmiAAiVvNK7B7ZDkqFxWUA2kWtdKsNZ67Uz6z8Kew7046B0npikUi7NpSjWnsfkFbCqyjHyiGI2IYmggFha4Bpn4SQi3V4zAxYMCE9i6jnMV/ApsaOZlkbfTJJc5VuqwjYd3Teg9Ru+Urc+zpBu0OYMoChCiTgU11QtHhpwPukkMBa1HOiP0eEIJYR4vsAbb98oPpjCLwk5nOvesu/sQUm4lBze+UuyMuIfB2qdsvRyEGPIgDep7mczwYp2sy0xNTsNfxEEoqxi7oT1Q5eJ67ywO5dwgEfKnGo43dj5MmSag== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab80776c-0f18-4ce5-9b5e-08d9ea582a9a X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:37:44.3682 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SQYCI0EJV/CkahowXjxTukK0zCJG3UJhNApy90dewX5dMebb5kOAOWqouzvY66ovps6HaY+rS+BtF/9XejhfO8g3f2LJAHgK2MUhrz/tFAY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5085 Received-SPF: pass client-ip=40.107.20.129; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Test for new option: use NBD server killing to simulate failure on file close. Signed-off-by: Vladimir Sementsov-Ogievskiy --- .../tests/blockdev-del-close-failure | 54 +++++++++++++++++++ .../tests/blockdev-del-close-failure.out | 4 ++ 2 files changed, 58 insertions(+) create mode 100755 tests/qemu-iotests/tests/blockdev-del-close-failure create mode 100644 tests/qemu-iotests/tests/blockdev-del-close-failure.out diff --git a/tests/qemu-iotests/tests/blockdev-del-close-failure b/tests/qemu-iotests/tests/blockdev-del-close-failure new file mode 100755 index 0000000000..12b442f43f --- /dev/null +++ b/tests/qemu-iotests/tests/blockdev-del-close-failure @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# +# Test blockdev-add force=false +# +# Copyright (c) 2022 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests +from iotests import qemu_img_create, qemu_img, qemu_nbd_popen, qemu_img_pipe + +iotests.script_initialize(supported_fmts=['qcow2'], + unsupported_imgopts=['compat']) + +disk, nbd_sock = iotests.file_path('disk', 'nbd-sock') +size = '1M' + +assert qemu_img_create('-f', iotests.imgfmt, disk, size) == 0 +assert qemu_img('bitmap', '--add', disk, 'bitmap0') == 0 +assert 'bitmaps' in qemu_img_pipe('info', disk) + +vm = iotests.VM() +vm.launch() + +with qemu_nbd_popen('-k', nbd_sock, '-f', 'raw', disk): + result = vm.qmp('blockdev-add', { + 'node-name': 'disk0', + 'driver': 'qcow2', + 'file': { + 'driver': 'nbd', + 'server': { + 'type': 'unix', + 'path': nbd_sock + } + } + }) + assert result == {'return': {}} + +# Now bitmap is loaded and marked IN_USE in the image, but connection is lost +# Bitmap can't be saved and blockdev-del(force=false) should fail +vm.qmp_log('blockdev-del', node_name='disk0', force=False) +vm.shutdown() diff --git a/tests/qemu-iotests/tests/blockdev-del-close-failure.out b/tests/qemu-iotests/tests/blockdev-del-close-failure.out new file mode 100644 index 0000000000..4a4776cc98 --- /dev/null +++ b/tests/qemu-iotests/tests/blockdev-del-close-failure.out @@ -0,0 +1,4 @@ +Start NBD server +Kill NBD server +{"execute": "blockdev-del", "arguments": {"force": false, "node-name": "disk0"}} +{"error": {"class": "GenericError", "desc": "Failed to flush node 'disk0'"}}