From nobody Fri Nov 14 19:46:57 2025 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760563321; cv=none; d=zohomail.com; s=zohoarc; b=oEybYVK69AZHP3aJI7un7W59jIj8fPYxMkP3Gak42uDr0mqh7zEP20xbZEj2MWKvUl6oPTIWe5h5W/P4otAlCWpMOa3Ex3uLazKzkynDDoUYPJ6XkLbCm8iN6Q5ZQG53nXlyEmzKmGrn7Ugg9liQE3LFixiEX3fpd1Q3ZCFHY/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760563321; 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=003dNG22PLuJugCgAsa9x9io4U8gRJHb4+EM5V2J578=; b=LEhv43SQW/HNEMfF7UCvaAehHXjre4qr/h/hzXJwHaU2zOBVAhOdtSYlE4DFiYOCNrzcnOGn9yr3ypMXQkM5mMFPTMc8KAnHRFFLdGQR/QcBY1nPhg6cFKwMbf3vbxEy5l7KAVBMaSwPbqAiQZjyv451vtulDtfO0l3u/+ASFsA= 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+importer=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 1760563320506906.7040134090578; Wed, 15 Oct 2025 14:22:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v98vn-0004aq-N9; Wed, 15 Oct 2025 17:21:11 -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 1v98vk-0004WV-R1 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 17:21:08 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1v98ve-00020Z-Co for qemu-devel@nongnu.org; Wed, 15 Oct 2025 17:21:08 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id D6A7188462; Thu, 16 Oct 2025 00:21:00 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id rKYpxt3F20U0-SfLtmZud; Thu, 16 Oct 2025 00:21: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=1760563260; bh=003dNG22PLuJugCgAsa9x9io4U8gRJHb4+EM5V2J578=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Xc0hQp/sdmb/kDlzRT7ycM5PPD/pQRsFm2NzJzpXn7Mp7YkOSSGFPt/5a+45y+IPW Qrmbv/4DCD8j7JhxXcxjuOqyfWo2DcP3ZtuutlmVTiqXBu14YeceJQxYNzj0gvtp6k geG6pZ3zTj1lJclET4CRq0NPCCJI8PA/LuU7Yiwk= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: marcandre.lureau@redhat.com Cc: pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, raphael@enfabrica.net, armbru@redhat.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH v4 7/7] chardev: introduce DEFINE_PROP_CHR_NO_CONNECT Date: Thu, 16 Oct 2025 00:20:51 +0300 Message-ID: <20251015212051.1156334-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015212051.1156334-1-vsementsov@yandex-team.ru> References: <20251015212051.1156334-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1760563326226158500 Content-Type: text/plain; charset="utf-8" For further vhost-user-blk backend-transfer migration realization we want to give it (vhost-user-blk) a possibility (and responsibility) to decide when do connect. For incoming migration we'll need to postpone connect at least until early stage of migrate-incoming command, when we already know all migration parameters and can decide, are we going to do incoming backend-transfer (and get chardev fd from incoming stream), or we finally need to connect. Signed-off-by: Vladimir Sementsov-Ogievskiy --- chardev/char-fe.c | 32 ++++++++++++++++++++++++----- hw/core/qdev-properties-system.c | 26 ++++++++++++++++++++--- include/chardev/char-fe.h | 6 +++++- include/hw/qdev-properties-system.h | 3 +++ 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 973fed5bea..d77d36960e 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -189,15 +189,26 @@ bool qemu_chr_fe_backend_open(CharBackend *be) return be->chr && be->chr->be_open; } =20 -bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) +bool qemu_chr_fe_init_ex(CharBackend *b, Chardev *s, bool connect, + Error **errp) { unsigned int tag =3D 0; =20 - if (!qemu_chr_connect(s, errp)) { - return false; - } - if (s) { + if (connect) { + if (!qemu_chr_connect(s, errp)) { + return false; + } + } else { + /* DEFINE_PROP_CHR_NO_CONNECT */ + if (!s->connect_postponed) { + error_setg(errp, + "Chardev %s does not support postponed connect", + s->label); + return false; + } + } + if (CHARDEV_IS_MUX(s)) { MuxChardev *d =3D MUX_CHARDEV(s); =20 @@ -210,6 +221,12 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Erro= r **errp) } else { s->be =3D b; } + } else { + /* + * connect=3Dfalse comes only from DEFINE_PROP_CHR_NO_CONNECT, + * through do_set_chr, which provides chardev ptr. + */ + assert(connect); } =20 b->fe_is_open =3D false; @@ -218,6 +235,11 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Erro= r **errp) return true; } =20 +bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) +{ + return qemu_chr_fe_init_ex(b, s, true, errp); +} + void qemu_chr_fe_deinit(CharBackend *b, bool del) { assert(b); diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 1f810b7ddf..6a0572ca03 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -266,8 +266,8 @@ static void get_chr(Object *obj, Visitor *v, const char= *name, void *opaque, g_free(p); } =20 -static void set_chr(Object *obj, Visitor *v, const char *name, void *opaqu= e, - Error **errp) +static void do_set_chr(Object *obj, Visitor *v, const char *name, void *op= aque, + bool connect, Error **errp) { ERRP_GUARD(); const Property *prop =3D opaque; @@ -297,13 +297,25 @@ static void set_chr(Object *obj, Visitor *v, const ch= ar *name, void *opaque, if (s =3D=3D NULL) { error_setg(errp, "Property '%s.%s' can't find value '%s'", object_get_typename(obj), name, str); - } else if (!qemu_chr_fe_init(be, s, errp)) { + } else if (!qemu_chr_fe_init_ex(be, s, connect, errp)) { error_prepend(errp, "Property '%s.%s' can't take value '%s': ", object_get_typename(obj), name, str); } g_free(str); } =20 +static void set_chr(Object *obj, Visitor *v, const char *name, void *opaqu= e, + Error **errp) +{ + do_set_chr(obj, v, name, opaque, true, errp); +} + +static void set_chr_no_connect(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + do_set_chr(obj, v, name, opaque, false, errp); +} + static void release_chr(Object *obj, const char *name, void *opaque) { const Property *prop =3D opaque; @@ -320,6 +332,14 @@ const PropertyInfo qdev_prop_chr =3D { .release =3D release_chr, }; =20 +const PropertyInfo qdev_prop_chr_no_connect =3D { + .type =3D "str", + .description =3D "ID of a chardev to use as a backend", + .get =3D get_chr, + .set =3D set_chr_no_connect, + .release =3D release_chr, +}; + /* --- mac address --- */ =20 /* diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index 8ef05b3dd0..32013623b3 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -25,15 +25,19 @@ struct CharBackend { }; =20 /** - * qemu_chr_fe_init: + * qemu_chr_fe_init(_ex): * * Initializes a front end for the given CharBackend and * Chardev. Call qemu_chr_fe_deinit() to remove the association and * release the driver. + * Call qemu_chr_connect(), except for the case when connect=3Dfalse + * parameter set for _ex() version. * * Returns: false on error. */ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp); +bool qemu_chr_fe_init_ex(CharBackend *b, Chardev *s, bool connect, + Error **errp); =20 /** * qemu_chr_fe_deinit: diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properti= es-system.h index 9601a11a09..41f68f60b9 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -7,6 +7,7 @@ bool qdev_prop_sanitize_s390x_loadparm(uint8_t *loadparm, c= onst char *str, Error **errp); =20 extern const PropertyInfo qdev_prop_chr; +extern const PropertyInfo qdev_prop_chr_no_connect; extern const PropertyInfo qdev_prop_macaddr; extern const PropertyInfo qdev_prop_reserved_region; extern const PropertyInfo qdev_prop_multifd_compression; @@ -39,6 +40,8 @@ extern const PropertyInfo qdev_prop_virtio_gpu_output_lis= t; =20 #define DEFINE_PROP_CHR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend) +#define DEFINE_PROP_CHR_NO_CONNECT(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_chr_no_connect, CharBackend) #define DEFINE_PROP_NETDEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ --=20 2.48.1