From nobody Fri Oct 18 05:23:15 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1719318015; cv=none; d=zohomail.com; s=zohoarc; b=KrHug2x5PleHvzQiAnBgXI9i+n2Jk+g8EDJRIeJvXo4wTvc9uRQ18scifGSCDOt5wln3Q/03wFVBXPQNbP84Lhc9stPpe6i7KN4eeaNpEgYdg4LevQMyBs4eE2RPfpmTwrS0ftLnlS/yvcsWfR6sfhsY+s386adxgbhJrEp2elI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719318015; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y0ZY0HL89ZQM1woEITh6SpFjHxY5Et82QworM2Q3QcM=; b=j4sRC4F0soPAcK2WjaDpqQ/hgRnw6ZKg3TeYdRd0dDWVKWeCHpm1O9CXwEW2QJFb0gjjC/rYIig1Zo4neeKhf7cytqiEFRIA82DW+5KGSb2SeQMZuEUdv3+ZPL/ytG2GsZTQ2+DQ/Qe2yPo0oyBi6BsHKEB+Ukac3lusgJjDnZU= ARC-Authentication-Results: i=1; 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719318015790460.47447877317256; Tue, 25 Jun 2024 05:20:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM58m-0003Ii-RH; Tue, 25 Jun 2024 08:19:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM58g-0003Gx-Ic; Tue, 25 Jun 2024 08:19:10 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM58c-0006eE-Af; Tue, 25 Jun 2024 08:19:10 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:6401:0:640:7e6f:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id ECE0C6115E; Tue, 25 Jun 2024 15:19:00 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b645::1:29]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id jIOnbJ0r9iE0-AcZRsO4j; Tue, 25 Jun 2024 15:19:00 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1719317940; bh=y0ZY0HL89ZQM1woEITh6SpFjHxY5Et82QworM2Q3QcM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Q24wLSGFL/BFbodf/yuk1elj6yk//urVGaLMQ9yygneRutdJ9eCdEr+FOzdSN+Ntx iVdhAdkvjP/gedWdQCczbsyOxn2c7Lp3960Z1UDXQrYZNauvSmdjiH/lre0EI/x3DG XpE7GkwcADFoGrsBtmyU8Lm/t0Hff4PwSvQcvb8I= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, raphael@enfabrica.net, mst@redhat.com Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru Subject: [PATCH v5 1/3] qdev-monitor: add option to report GenericError from find_device_state Date: Tue, 25 Jun 2024 15:18:41 +0300 Message-Id: <20240625121843.120035-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240625121843.120035-1-vsementsov@yandex-team.ru> References: <20240625121843.120035-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net 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_MSPIKE_H2=-0.001, SPF_HELO_NONE=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.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1719318017511100003 Content-Type: text/plain; charset="utf-8" Here we just prepare for the following patch, making possible to report GenericError as recommended. This patch doesn't aim to prevent further use of DeviceNotFound by future interfaces: - find_device_state() is used in blk_by_qdev_id() and qmp_get_blk() functions, which may lead to spread of DeviceNotFound anyway - also, nothing prevent simply copy-pasting find_device_state() calls with false argument Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz Reviewed-by: Markus Armbruster --- system/qdev-monitor.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 6af6ef7d66..264978aa40 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -879,13 +879,20 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,= Error **errp) object_unref(OBJECT(dev)); } =20 -static DeviceState *find_device_state(const char *id, Error **errp) +/* + * Note that creating new APIs using error classes other than GenericError= is + * not recommended. Set use_generic_error=3Dtrue for new interfaces. + */ +static DeviceState *find_device_state(const char *id, bool use_generic_err= or, + Error **errp) { Object *obj =3D object_resolve_path_at(qdev_get_peripheral(), id); DeviceState *dev; =20 if (!obj) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + error_set(errp, + (use_generic_error ? + ERROR_CLASS_GENERIC_ERROR : ERROR_CLASS_DEVICE_NOT_FOUN= D), "Device '%s' not found", id); return NULL; } @@ -950,7 +957,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) =20 void qmp_device_del(const char *id, Error **errp) { - DeviceState *dev =3D find_device_state(id, errp); + DeviceState *dev =3D find_device_state(id, false, errp); if (dev !=3D NULL) { if (dev->pending_deleted_event && (dev->pending_deleted_expires_ms =3D=3D 0 || @@ -1070,7 +1077,7 @@ BlockBackend *blk_by_qdev_id(const char *id, Error **= errp) =20 GLOBAL_STATE_CODE(); =20 - dev =3D find_device_state(id, errp); + dev =3D find_device_state(id, false, errp); if (dev =3D=3D NULL) { return NULL; } --=20 2.34.1 From nobody Fri Oct 18 05:23:15 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1719317993; cv=none; d=zohomail.com; s=zohoarc; b=fyl8fJQnw6cjmQp3gi6jgo5zBIWDZV3WcTxKrTPeUtxsuBEOuPBHVeABduA6d8O+saOf5T4XqzsJcPbi9NMFIWRX75ez+mn6u64By4sbi2iCly3pfJDzyIe/APqsaL7EXj0Rg9R+fJ9rWmaiF3fYX9vOpeywkaM7+NKf5WcQHho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719317993; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nE8KRYNH/UdPTwy4qr33SLrQDzML5H/fRCmZwPtMmDI=; b=N+JO+6K6JMEsj74YBw9DLbsasINqcdYsMTIZC6kYyQf5NzLcWzRSIUfF/0jGO/zIVIqLfMhD7n7mL0NyKrPtl8ptYFhqsorGghNRVDhobr72eunwjR1J6KYSb+9d2lPT3+ujQKI844HmCmK1UhV4WI2iyVxT9WtC1ErxlMNyXMg= ARC-Authentication-Results: i=1; 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719317993346787.0237359557724; Tue, 25 Jun 2024 05:19:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM58l-0003Hj-1V; Tue, 25 Jun 2024 08:19:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM58f-0003Ge-64; Tue, 25 Jun 2024 08:19:09 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM58c-0006eF-AZ; Tue, 25 Jun 2024 08:19:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:6401:0:640:7e6f:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id C3AAF608EC; Tue, 25 Jun 2024 15:19:01 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b645::1:29]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id jIOnbJ0r9iE0-kgF7JREr; Tue, 25 Jun 2024 15:19:01 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1719317941; bh=nE8KRYNH/UdPTwy4qr33SLrQDzML5H/fRCmZwPtMmDI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=fkmubWaZFTJrkggu15L/B1nBUHEWVX9WZv+DlU5kf74PLUyGps7eZ24IwGeWCym+F qDsqP6gmToOYa/8Vh4YsHCF+lWb4iQWTQjj9VqYeg8aU2xqXd7lOd0UOa0gE1c4zdE YuQCgf9VsjsHLC+87ytBVjTzVapfAPaVu27MrEj0= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, raphael@enfabrica.net, mst@redhat.com Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru Subject: [PATCH v5 2/3] vhost-user-blk: split vhost_user_blk_sync_config() Date: Tue, 25 Jun 2024 15:18:42 +0300 Message-Id: <20240625121843.120035-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240625121843.120035-1-vsementsov@yandex-team.ru> References: <20240625121843.120035-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net 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, SPF_HELO_NONE=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.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1719317995371100011 Content-Type: text/plain; charset="utf-8" Split vhost_user_blk_sync_config() out from vhost_user_blk_handle_config_change(), to be reused in the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 9e6bbc6950..091d2c6acf 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -88,27 +88,39 @@ static void vhost_user_blk_set_config(VirtIODevice *vde= v, const uint8_t *config) s->blkcfg.wce =3D blkcfg->wce; } =20 +static int vhost_user_blk_sync_config(DeviceState *dev, Error **errp) +{ + int ret; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + + ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, + vdev->config_len, errp); + if (ret < 0) { + return ret; + } + + memcpy(vdev->config, &s->blkcfg, vdev->config_len); + virtio_notify_config(vdev); + + return 0; +} + static int vhost_user_blk_handle_config_change(struct vhost_dev *dev) { int ret; - VirtIODevice *vdev =3D dev->vdev; - VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); Error *local_err =3D NULL; =20 if (!dev->started) { return 0; } =20 - ret =3D vhost_dev_get_config(dev, (uint8_t *)&s->blkcfg, - vdev->config_len, &local_err); + ret =3D vhost_user_blk_sync_config(DEVICE(dev->vdev), &local_err); if (ret < 0) { error_report_err(local_err); return ret; } =20 - memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); - virtio_notify_config(dev->vdev); - return 0; } =20 --=20 2.34.1 From nobody Fri Oct 18 05:23:15 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1719317990; cv=none; d=zohomail.com; s=zohoarc; b=ZZyVBNp/vjlPPPjZ2ht6J4ScDURDmoUssoujUBPnN+BTjpN2gIVJAqUm75GRicra4JqITQlxhT+y/ZRn0bZWkBgRMSUndFMBEid9M04pDfwEZRDSiuNGBu48ThQiKOzFo5P7ZG8fXgumiE7Yix1FZWgieKN4WTv8FToSJwHhHzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719317990; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YZu4KWgt1xJx0r1R/GrG6qSjpXE1sWThQoMb8vqBGFg=; b=H8UpY8mHFk9a98MGgqorIbW0boHXKs4roCErSTgU8j8VDZyrIwb/Gmz+DPwbqrEfUFQMshuxtwczV0IibcZVOOm+8RBbHZkVX/7FFa37O2EJmedEEUXQ/NdqLQfTOiib0dN0tRL+rQsyG9KhxavBd4RjC6gPF147c6a+La5chjs= ARC-Authentication-Results: i=1; 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719317989943768.5347869347437; Tue, 25 Jun 2024 05:19:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM58l-0003II-JM; Tue, 25 Jun 2024 08:19:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM58f-0003Gf-JP; Tue, 25 Jun 2024 08:19:09 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sM58c-0006eN-Bc; Tue, 25 Jun 2024 08:19:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:6401:0:640:7e6f:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id BDE79608ED; Tue, 25 Jun 2024 15:19:02 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b645::1:29]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id jIOnbJ0r9iE0-e5bHznxp; Tue, 25 Jun 2024 15:19:02 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1719317942; bh=YZu4KWgt1xJx0r1R/GrG6qSjpXE1sWThQoMb8vqBGFg=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=qRiBlcqs6NyhIf+BJDZghx8IqCQD/jYCUiHO836QzGoqPkxu3xKllEoMrSPtRWLYw KmHYlxbEdZIQyELJqy5ZGm2/pRSWUjjUyVJ8goNIPS4gXoX6g1MFGcD92wInYU+2ik 1KoJRh8RTF2ca0TPzUYERlGPZ3pqhCErZAI5aPCo= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, raphael@enfabrica.net, mst@redhat.com Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, yc-core@yandex-team.ru Subject: [PATCH v5 3/3] qapi: introduce device-sync-config Date: Tue, 25 Jun 2024 15:18:43 +0300 Message-Id: <20240625121843.120035-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240625121843.120035-1-vsementsov@yandex-team.ru> References: <20240625121843.120035-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net 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, SPF_HELO_NONE=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.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1719317992700100003 Content-Type: text/plain; charset="utf-8" Add command to sync config from vhost-user backend to the device. It may be helpful when VHOST_USER_SLAVE_CONFIG_CHANGE_MSG failed or not triggered interrupt to the guest or just not available (not supported by vhost-user server). Command result is racy if allow it during migration. Let's allow the sync only in RUNNING state. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 1 + hw/virtio/virtio-pci.c | 9 +++++++++ include/hw/qdev-core.h | 3 +++ qapi/qdev.json | 24 ++++++++++++++++++++++++ system/qdev-monitor.c | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 091d2c6acf..2f301f380c 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -588,6 +588,7 @@ static void vhost_user_blk_class_init(ObjectClass *klas= s, void *data) =20 device_class_set_props(dc, vhost_user_blk_properties); dc->vmsd =3D &vmstate_vhost_user_blk; + dc->sync_config =3D vhost_user_blk_sync_config; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); vdc->realize =3D vhost_user_blk_device_realize; vdc->unrealize =3D vhost_user_blk_device_unrealize; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b1d02f4b3d..0d91e8b5dc 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2351,6 +2351,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev,= Error **errp) vpciklass->parent_dc_realize(qdev, errp); } =20 +static int virtio_pci_sync_config(DeviceState *dev, Error **errp) +{ + VirtIOPCIProxy *proxy =3D VIRTIO_PCI(dev); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + + return qdev_sync_config(DEVICE(vdev), errp); +} + static void virtio_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -2367,6 +2375,7 @@ static void virtio_pci_class_init(ObjectClass *klass,= void *data) device_class_set_parent_realize(dc, virtio_pci_dc_realize, &vpciklass->parent_dc_realize); rc->phases.hold =3D virtio_pci_bus_reset_hold; + dc->sync_config =3D virtio_pci_sync_config; } =20 static const TypeInfo virtio_pci_info =3D { diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 5336728a23..f992061919 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -95,6 +95,7 @@ typedef void (*DeviceUnrealize)(DeviceState *dev); typedef void (*DeviceReset)(DeviceState *dev); typedef void (*BusRealize)(BusState *bus, Error **errp); typedef void (*BusUnrealize)(BusState *bus); +typedef int (*DeviceSyncConfig)(DeviceState *dev, Error **errp); =20 /** * struct DeviceClass - The base class for all devices. @@ -162,6 +163,7 @@ struct DeviceClass { DeviceReset reset; DeviceRealize realize; DeviceUnrealize unrealize; + DeviceSyncConfig sync_config; =20 /** * @vmsd: device state serialisation description for @@ -547,6 +549,7 @@ bool qdev_hotplug_allowed(DeviceState *dev, Error **err= p); */ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); void qdev_unplug(DeviceState *dev, Error **errp); +int qdev_sync_config(DeviceState *dev, Error **errp); void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void qdev_machine_creation_done(void); diff --git a/qapi/qdev.json b/qapi/qdev.json index facaa0bc6a..72e434bc45 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -161,3 +161,27 @@ ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @device-sync-config: +# +# Synchronize device configuration from host to guest part. First, +# copy the configuration from the host part (backend) to the guest +# part (frontend). Then notify guest software that device +# configuration changed. +# +# The command may be used to notify the guest about block device +# capcity change. Currently only vhost-user-blk device supports +# this. +# +# @id: the device's ID or QOM path +# +# Features: +# +# @unstable: The command is experimental. +# +# Since: 9.1 +## +{ 'command': 'device-sync-config', + 'features': [ 'unstable' ], + 'data': {'id': 'str'} } diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 264978aa40..1c29312b53 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -23,6 +23,7 @@ #include "monitor/monitor.h" #include "monitor/qdev.h" #include "sysemu/arch_init.h" +#include "sysemu/runstate.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" #include "qapi/qmp/dispatch.h" @@ -971,6 +972,43 @@ void qmp_device_del(const char *id, Error **errp) } } =20 +int qdev_sync_config(DeviceState *dev, Error **errp) +{ + DeviceClass *dc =3D DEVICE_GET_CLASS(dev); + + if (!dc->sync_config) { + error_setg(errp, "device-sync-config is not supported for '%s'", + object_get_typename(OBJECT(dev))); + return -ENOTSUP; + } + + return dc->sync_config(dev, errp); +} + +void qmp_device_sync_config(const char *id, Error **errp) +{ + DeviceState *dev; + + /* + * During migration there is a race between syncing`configuration + * and migrating it (if migrate first, that target would get + * outdated version), so let's just not allow it. + */ + + if (migration_is_running()) { + error_setg(errp, "Config synchronization is not allowed " + "during migration"); + return; + } + + dev =3D find_device_state(id, true, errp); + if (!dev) { + return; + } + + qdev_sync_config(dev, errp); +} + void hmp_device_add(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; --=20 2.34.1