From patchwork Thu May 20 14:21:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12270577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C91E0C433B4 for ; Thu, 20 May 2021 14:36:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2512661184 for ; Thu, 20 May 2021 14:36:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2512661184 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljjmR-0000pm-W9 for qemu-devel@archiver.kernel.org; Thu, 20 May 2021 10:36:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljjZU-0005fI-EA; Thu, 20 May 2021 10:22:44 -0400 Received: from mail-vi1eur05on2115.outbound.protection.outlook.com ([40.107.21.115]:23648 helo=EUR05-VI1-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 1ljjZR-0005Yx-C1; Thu, 20 May 2021 10:22:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mR+5MCTXH/dP46CLPRV8CtBvp1sdU+eE7zxNwUKMXrRVHhc9sfEZGiZoWk2qQSN5VR4KyjEI+GoRFBDzZlelZ4U8c4ydZ8fILkN+FssnxzbDkPgHUeyEE7dZfaSzEq6k61QUh6/CHLk78/Q3sx3eQmJZAXQPCIW6k+ARYUtaCRBWjvYIsrn0e3BUOVwinVVFb7o/ML7+4Qf1uvPWJbg9xegM64cDchUzbkFxSk6jbtPH6BZbhMVIWbvvIs0q2fX8UHKSmuDVPfn8zhRh1oS1r2HzrAdNJecBG3VgQpUNWhZ+xxoanq2hbayvmtbgIfBXea8/yknQljovcunjx8/XuA== 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-SenderADCheck; bh=Wju+SfsauUACenJq2OTqYcEloKj+ejuPkMRtJMC1fkM=; b=m+/P933C4VB9FCv2gyVHmT6HvW/uMVZHXBd1aEyMqVR1WUVziaegSp0x6f/05f6iBXq17+n/2a+Pv9jqnCBujO8EeXEWFL8WU3DsJd2nXOubwEIS38I5muocTgzHrC0IZIJ3ebc8zRf0wjBo0WTBT/1sOYp00cFRk+uqcJqPEZPZYkX4Bh6t6yUvJGIsQCZOuNyFK3wnTT24XZmq5QRgiRG+nE5n4Op9MKUHBQ3W5OJp5BoySaW21nAJtE6BKVR7UFp4vagbCZveVBeaI2MkfEu6FP0XvoOnOzvnqHI24Lf6VfLzGdCW+vi4iCrXF4C4Ru0+82D1I9LzPBt13o1Xhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; 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=Wju+SfsauUACenJq2OTqYcEloKj+ejuPkMRtJMC1fkM=; b=Lqqv42GjnkJXe3TqbrXJZMpvidBO+nhLW6+Lz9Yj6u68HAWu/SO1F43i7ZhJa3e/+2i5cBn20smf98vtfhu2pApGMNHSY6Nntfs5c/ZDCMrbPJRftyMvyyxc6BR5sc0fvl9qbZ7PqogpaU9wXfxvrzpqHoTmBJq5u3FE8laK/XQ= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AS8PR08MB7009.eurprd08.prod.outlook.com (2603:10a6:20b:34c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.26; Thu, 20 May 2021 14:22:31 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b403:c1a9:6bb7:133%7]) with mapi id 15.20.4129.033; Thu, 20 May 2021 14:22:31 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, armbru@redhat.com, crosa@redhat.com, ehabkost@redhat.com, berrange@redhat.com, pbonzini@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, mreitz@redhat.com, kwolf@redhat.com, den@openvz.org Subject: [PATCH v2 06/33] qdev: allow setting drive property for realized device Date: Thu, 20 May 2021 17:21:38 +0300 Message-Id: <20210520142205.607501-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210520142205.607501-1-vsementsov@virtuozzo.com> References: <20210520142205.607501-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.197] X-ClientProxiedBy: HE1P190CA0034.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::23) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.197) by HE1P190CA0034.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23 via Frontend Transport; Thu, 20 May 2021 14:22:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 866ab2d6-75e3-4296-2257-08d91b9ab400 X-MS-TrafficTypeDiagnostic: AS8PR08MB7009: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W2FhE+xw9RqIj54NvDZL1ehZH3w6yhaJSS0Ci+fOogYeE61ETeBbq8ZXPho24a8JVeWrdrp8kXI5Uv+6SG1IXqnUyeerswWiHnKZLckb8F8REI4nnn5f55mMAXD90391LWIGqUSC1bL+UNNkCVvXiB/ydZlT+xdHEmI0nRUdCd13QLdINXUH+pdsik4Y9ffI5bkoRYyWZTz5yGnOGNywTM2crPZWW2ISrwlK6UFgJx+N/YUfxT6usVvDx7D5rIRYTT1x95CvDQhH5Xe5bLmA5TJcL5bnX0dKo9XK0kcxyQBmQfE6YBfIN3rXSUhhVqGR91wdQEapiiffjuZJRNyvGO8JWTviCvybbiVAXiGm4VgOcma9g3noHjmennRxQt/S/AyhqGgihTkf5sGbURmEypw0yX1svz8PpNc9Rx5DgpMcUHAZmZXtBb7cVmhOB0ZstKPv5q9PIWYVwQO0I76Q1av/V+zgStFX9IyBuoBNb/jFk4/QHFFOCh7ajcUT/kZig2SQdExKpvEmCAJxEFhMXGn4WC09D1fDN9a48sM1zfcTB9HkH+vV0wAqs+D+AAoEL0hp+uLog7rlPYxFrHeM+y2t4domvnxz5fyHVIkrGBwrmqYEbiLE9EOHsmLW7pzwbalv/p/4ia2ghrlHYrFyag== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(39840400004)(376002)(346002)(366004)(38100700002)(38350700002)(478600001)(86362001)(6916009)(6486002)(36756003)(83380400001)(107886003)(8676002)(186003)(6666004)(4326008)(16526019)(316002)(1076003)(5660300002)(8936002)(26005)(6506007)(7416002)(66556008)(66476007)(66946007)(2906002)(956004)(2616005)(6512007)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?TNYbgxEIfDpTgEoNKOC29j40bgKOhf?= =?utf-8?q?WRmlLhYliEiLxUe7M2Cz3whE6q4MWQnUFNECKidS65aSPHS1cnJd89WKkqCgME5dM?= =?utf-8?q?lJ5qywjIFxghHf3UhGA+RtDDuFM+y7XdVM6V3wu1yU/r3YE727yEUL8LgnPLBhSw8?= =?utf-8?q?95Y98xljri+yZBSiqyToiwpeg+M15nd7b97xVKz9aNoJ84ervumFAewVVZ8V9kaxP?= =?utf-8?q?3bl/5y0h10y4As93trF0Qu0jhPahA/Vb9Z684nhU9OBxS+w8Nqa7WUzBydFMkYEeT?= =?utf-8?q?T2fVYKuP+NHkDWDaH4p3cQCwOePX8egOIetK8zmNOUtZbhEmRXoxfEpCXC6Wajh24?= =?utf-8?q?Jg/FoJRQsJ50B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VQUtFnxP3YCZhaM9pQFkpZLtDrJ7Wr804BAQUeGoGbWiGZracS339?= =?utf-8?q?bSBWyA0gdL2R7/?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 866ab2d6-75e3-4296-2257-08d91b9ab400 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2021 14:22:30.9681 (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: DV1wP2xHSxyrOB7q1WxYOa2FxQC6yO0ayegFpW9AzDQF1NRE8A8LPYUhSQ0IZ686ejRz05AIFGlu2GBOINZycqcM3Cp9SZLGqGql3Iujyew= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7009 Received-SPF: pass client-ip=40.107.21.115; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" We need an ability to insert filters above top block node, attached to block device. It can't be achieved with blockdev-reopen command. So, we want do it with help of qom-set. Intended usage: Assume there is a node A that is attached to some guest device. 1. blockdev-add to create a filter node B that has A as its child. 2. qom-set to change the node attached to the guest device’s BlockBackend from A to B. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- hw/core/qdev-properties-system.c | 43 +++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 2760c21f11..e71f5d64d1 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -36,11 +36,11 @@ static bool check_prop_still_unset(Object *obj, const char *name, const void *old_val, const char *new_val, - Error **errp) + bool allow_override, Error **errp) { const GlobalProperty *prop = qdev_find_global_prop(obj, name); - if (!old_val) { + if (!old_val || (!prop && allow_override)) { return true; } @@ -93,16 +93,34 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name, BlockBackend *blk; bool blk_created = false; int ret; + BlockDriverState *bs; + AioContext *ctx; if (!visit_type_str(v, name, &str, errp)) { return; } - /* - * TODO Should this really be an error? If no, the old value - * needs to be released before we store the new one. - */ - if (!check_prop_still_unset(obj, name, *ptr, str, errp)) { + if (!check_prop_still_unset(obj, name, *ptr, str, true, errp)) { + return; + } + + if (*ptr) { + /* BlockBackend alread exists. So, we want to change attached node */ + blk = *ptr; + ctx = blk_get_aio_context(blk); + bs = bdrv_lookup_bs(NULL, str, errp); + if (!bs) { + return; + } + + if (ctx != bdrv_get_aio_context(bs)) { + error_setg(errp, "Different aio context is not supported for new " + "node"); + } + + aio_context_acquire(ctx); + blk_replace_bs(blk, bs, errp); + aio_context_release(ctx); return; } @@ -114,7 +132,7 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name, blk = blk_by_name(str); if (!blk) { - BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL); + bs = bdrv_lookup_bs(NULL, str, NULL); if (bs) { /* * If the device supports iothreads, it will make sure to move the @@ -123,8 +141,7 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name, * aware of iothreads require their BlockBackends to be in the main * AioContext. */ - AioContext *ctx = iothread ? bdrv_get_aio_context(bs) : - qemu_get_aio_context(); + ctx = iothread ? bdrv_get_aio_context(bs) : qemu_get_aio_context(); blk = blk_new(ctx, 0, BLK_PERM_ALL); blk_created = true; @@ -196,6 +213,7 @@ static void release_drive(Object *obj, const char *name, void *opaque) const PropertyInfo qdev_prop_drive = { .name = "str", .description = "Node name or ID of a block device to use as a backend", + .realized_set_allowed = true, .get = get_drive, .set = set_drive, .release = release_drive, @@ -204,6 +222,7 @@ const PropertyInfo qdev_prop_drive = { const PropertyInfo qdev_prop_drive_iothread = { .name = "str", .description = "Node name or ID of a block device to use as a backend", + .realized_set_allowed = true, .get = get_drive, .set = set_drive_iothread, .release = release_drive, @@ -238,7 +257,7 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque, * TODO Should this really be an error? If no, the old value * needs to be released before we store the new one. */ - if (!check_prop_still_unset(obj, name, be->chr, str, errp)) { + if (!check_prop_still_unset(obj, name, be->chr, str, false, errp)) { return; } @@ -408,7 +427,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name, * TODO Should this really be an error? If no, the old value * needs to be released before we store the new one. */ - if (!check_prop_still_unset(obj, name, ncs[i], str, errp)) { + if (!check_prop_still_unset(obj, name, ncs[i], str, false, errp)) { goto out; }