From nobody Thu Nov 14 07:03:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1621521388; cv=pass; d=zohomail.com; s=zohoarc; b=M3TltobkiYRjN2H7iQd1iRqB0wPS060PDia/tNxeb6JujnKuSLA3by7lVHvuTV64AZkOgqLUj/UxdhDEueQOt2zEIcXg6mUyCkHovAlfC+CEU83vhQ2Pa52tBrrOwwC7jbUNQbP7UjjBmMuFljEJflFETiJG4hQeV6Hz1Xnx/j0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621521388; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Wju+SfsauUACenJq2OTqYcEloKj+ejuPkMRtJMC1fkM=; b=KWr485plLseY/V2sKZJbPs5mq9/qiFEWVHLFT25I2xQhQzOi2RHt1uF7Lqqjq4F0GgYFKwD9a8ogQgsQSbHfagGj8NWO3ezy+HBKY01BHjQC8OL1L3CS/O2JrtF0gvd0X17RCnmsUbcuIo6GIirFLMr12oYe3fWjBU1H7UdfsxQ= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621521388706913.113044947588; Thu, 20 May 2021 07:36:28 -0700 (PDT) Received: from localhost ([::1]:53864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljjml-0000pm-BS for importer@patchew.org; Thu, 20 May 2021 10:36:27 -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 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 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 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; 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> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 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?B?VE5ZYmd4RUlmRHBUZ0VvTktPQzI5ajQwYmdLT2hmV1JtbExoWWxpRWlMeFVl?= =?utf-8?B?N00yQ3ozd2hFNnE0TVdRblVGTkVDS2lkUzY1YVNQSFMxY25KZDg5V0tr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zL2NxZEs1L05FMklrSUlSMktCYlBPSVg1?= =?utf-8?B?SVBkVWV3d0FiSVl0ZGgxaDFUbVNFTThVaDQ2UmFKcmdhWE5vcmhEZkNmaXZE?= =?utf-8?B?MTNnMWIzQlhIbmRTdytxZWFWWVR4Q1lvOUphSTlJeHlKVlczdEhSWjZKZVlX?= =?utf-8?B?SHFWZ0t4aU1PR255YjlZNGdQTHFSK2JqbXVMelh6VjhiaHBmaHJXSk54VjRW?= =?utf-8?B?ekY0R3pITDVvOE16NGZDU1QrUVdGcnN1d1dIRnU4bVlOOE9CSHNjVGlRbWR6?= =?utf-8?B?Vk9qZjBhSmFTV21NUHJ6SWZEQXk5RXN1Unh1cnpNc0NrVFJuNHE5U3BHeHVN?= =?utf-8?B?MnFCT0FFYWN2YnB1T1JoNXlhekI5Um9zaCt3OHZaazVmSk9OOVVmZG4zT0Rw?= =?utf-8?B?bjBieFVWSHRxQVFuZmpES0l5ZitraVFhbHF0MUtTUksyOFBlbWN0WjlOMzIx?= =?utf-8?B?bHVnM1dYZnc2TWhaclNTd2RjOVNUTlNidEdPcDdJYUdWeTZJelJhYkIvTHdR?= =?utf-8?B?YjhudXI2NEpkMGtRSlZjMXlGd0NhVmJNWEhNem11bHhWdFFYd3A4THl1ajda?= =?utf-8?B?U0VOcE9SUStrVEZwNVJ3SWthbzRZTFlyejg5cTZlQk1ZYm52cUNjUzRFczhO?= =?utf-8?B?VlpuclBJS1A3U2JKVkhUTllGUVZRSU9TY3ZwaXo5aWVFbk1LWWRrVGtPNGRF?= =?utf-8?B?TUkzeGw1OHJiWENQclA3anFWUVV0Rm54UDNZQ1poYU05cFFGa3BaTHREcko3?= =?utf-8?Q?Wr804BAQUeGoGbWiGZracS339bSBWyA0gdL2R7/?= 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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) 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=E2=80=99s 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-sys= tem.c index 2760c21f11..e71f5d64d1 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -36,11 +36,11 @@ =20 static bool check_prop_still_unset(Object *obj, const char *name, const void *old_val, const char *new_va= l, - Error **errp) + bool allow_override, Error **errp) { const GlobalProperty *prop =3D qdev_find_global_prop(obj, name); =20 - if (!old_val) { + if (!old_val || (!prop && allow_override)) { return true; } =20 @@ -93,16 +93,34 @@ static void set_drive_helper(Object *obj, Visitor *v, c= onst char *name, BlockBackend *blk; bool blk_created =3D false; int ret; + BlockDriverState *bs; + AioContext *ctx; =20 if (!visit_type_str(v, name, &str, errp)) { return; } =20 - /* - * 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 =3D *ptr; + ctx =3D blk_get_aio_context(blk); + bs =3D bdrv_lookup_bs(NULL, str, errp); + if (!bs) { + return; + } + + if (ctx !=3D bdrv_get_aio_context(bs)) { + error_setg(errp, "Different aio context is not supported for n= ew " + "node"); + } + + aio_context_acquire(ctx); + blk_replace_bs(blk, bs, errp); + aio_context_release(ctx); return; } =20 @@ -114,7 +132,7 @@ static void set_drive_helper(Object *obj, Visitor *v, c= onst char *name, =20 blk =3D blk_by_name(str); if (!blk) { - BlockDriverState *bs =3D bdrv_lookup_bs(NULL, str, NULL); + bs =3D 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, c= onst char *name, * aware of iothreads require their BlockBackends to be in the= main * AioContext. */ - AioContext *ctx =3D iothread ? bdrv_get_aio_context(bs) : - qemu_get_aio_context(); + ctx =3D iothread ? bdrv_get_aio_context(bs) : qemu_get_aio_con= text(); blk =3D blk_new(ctx, 0, BLK_PERM_ALL); blk_created =3D true; =20 @@ -196,6 +213,7 @@ static void release_drive(Object *obj, const char *name= , void *opaque) const PropertyInfo qdev_prop_drive =3D { .name =3D "str", .description =3D "Node name or ID of a block device to use as a backen= d", + .realized_set_allowed =3D true, .get =3D get_drive, .set =3D set_drive, .release =3D release_drive, @@ -204,6 +222,7 @@ const PropertyInfo qdev_prop_drive =3D { const PropertyInfo qdev_prop_drive_iothread =3D { .name =3D "str", .description =3D "Node name or ID of a block device to use as a backen= d", + .realized_set_allowed =3D true, .get =3D get_drive, .set =3D set_drive_iothread, .release =3D 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; } =20 @@ -408,7 +427,7 @@ static void set_netdev(Object *obj, Visitor *v, const c= har *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; } =20 --=20 2.29.2