From nobody Fri Nov 14 18:23:11 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=1761926536; cv=none; d=zohomail.com; s=zohoarc; b=LYDunb9wRjlkS8v8k/P2mNQ9LSIudZhDj9ZtFw9AD0EOzrk1dHD7d82g7RY7/M7ESnzbNSbzajJ0gqPF5UTPi5eTelk523i1hkIEz+1vp68n7W4LLUFRsFZGZK0n6Gb7d4+Nknb4d6Os0dv6oqLbT06N9znb+z0lV1uVhtmK7XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761926536; h=Content-Type: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=K896VjWcrOPIeJ05AQfDV1xDA9uM8UKPhfeRgDqDo1E=; b=d3hJ+PR2w1Kx0GGhG9beX3Te5BFaIuGHkDxvZ20zm8zo+FJ4914+Amw/cLYa96MW2IQt/pTb7f6ppYok4Rds/6siCQ5txQMl1kZtph6JvsSy+zB9wCVedbhpcs6y4+jUqHX/PezCCbDuWSJRJU4QnHbit3+P0T4FFaKyv+XhaiY= 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 1761926536687383.2764794525042; Fri, 31 Oct 2025 09:02:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vErXd-0007Ac-1s; Fri, 31 Oct 2025 11:59:54 -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 1vErXN-00076V-Bo for qemu-devel@nongnu.org; Fri, 31 Oct 2025 11:59:37 -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 1vErXG-0005zy-3Z for qemu-devel@nongnu.org; Fri, 31 Oct 2025 11:59:37 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 14EF28088A; Fri, 31 Oct 2025 18:59:24 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:546::1:17]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id Fxip9o0FqiE0-bF6TNGtS; Fri, 31 Oct 2025 18:59:23 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761926363; bh=K896VjWcrOPIeJ05AQfDV1xDA9uM8UKPhfeRgDqDo1E=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=TovYVN1YSWFtnx8HZ+/ALzZ2+Ye/bQ1/EvHSVOTCGrhGtYskXuF/kxnKmR0AJ/2dF r9uWSZOpFWiAFRPB3NNF0eJflxiHPXx+1QCQYVPMsZT+XKZSjNyrC0X/6aM/+XSXs5 XITv8Lv1POGl3EkEGEWGJHtDYqE5pdnGlcr41LoY= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.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 v5 5/7] chardev/char: introduce .init() + .connect() initialization interface Date: Fri, 31 Oct 2025 18:59:12 +0300 Message-ID: <20251031155914.189112-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251031155914.189112-1-vsementsov@yandex-team.ru> References: <20251031155914.189112-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: 1761926539863154100 We'll need a possibility to postpone connect step to later point in time to implement backend-transfer migration feature for vhost-user-blk in further commits. Let's start with new char interface for backends. .init() takes QAPI parameters and should parse them, called early .connect() should actually establish a connection, and postponed to the point of attaching to frontend. Called at later point, either at time of attaching frontend, or from qemu_chr_wait_connected(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Marc-Andr=C3=A9 Lureau --- chardev/char-fe.c | 4 ++++ chardev/char.c | 39 +++++++++++++++++++++++++++++++++++++-- include/chardev/char.h | 30 +++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 34b83fc1c4..c67b4d640f 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -193,6 +193,10 @@ bool qemu_chr_fe_init(CharFrontend *c, Chardev *s, Err= or **errp) { unsigned int tag =3D 0; =20 + if (!qemu_chr_connect(s, errp)) { + return false; + } + if (s) { if (CHARDEV_IS_MUX(s)) { MuxChardev *d =3D MUX_CHARDEV(s); diff --git a/chardev/char.c b/chardev/char.c index 7a029b0eb9..33eba0cdc0 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -33,6 +33,7 @@ #include "qapi/error.h" #include "qapi/qapi-commands-char.h" #include "qapi/qmp/qerror.h" +#include "qom/object.h" #include "system/replay.h" #include "qemu/help_option.h" #include "qemu/module.h" @@ -338,10 +339,29 @@ static bool qemu_chr_is_busy(Chardev *s) } } =20 +bool qemu_chr_connect(Chardev *chr, Error **errp) +{ + ChardevClass *cc =3D CHARDEV_GET_CLASS(chr); + + if (chr->connect_postponed) { + assert(cc->connect); + chr->connect_postponed =3D false; + if (!cc->connect(chr, errp)) { + return false; + } + } + + return true; +} + int qemu_chr_wait_connected(Chardev *chr, Error **errp) { ChardevClass *cc =3D CHARDEV_GET_CLASS(chr); =20 + if (!qemu_chr_connect(chr, errp)) { + return -1; + } + if (cc->chr_wait_connected) { return cc->chr_wait_connected(chr, errp); } @@ -1030,6 +1050,7 @@ static Chardev *chardev_new(const char *id, const cha= r *typename, { Object *obj; Chardev *chr =3D NULL; + ChardevClass *cc; =20 assert(g_str_has_prefix(typename, "chardev-")); assert(id); @@ -1044,8 +1065,22 @@ static Chardev *chardev_new(const char *id, const ch= ar *typename, goto fail; } =20 - if (!qemu_char_open(chr, backend, typename + 8, errp)) { - goto fail; + cc =3D CHARDEV_GET_CLASS(chr); + + if (cc->init) { + assert(!cc->open); + assert(cc->connect); + + if (!cc->init(chr, backend, errp)) { + goto fail; + } + assert(chr->filename); + + chr->connect_postponed =3D true; + } else { + if (!qemu_char_open(chr, backend, typename + 8, errp)) { + goto fail; + } } =20 return chr; diff --git a/include/chardev/char.h b/include/chardev/char.h index b65e9981c1..24c449b07b 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -63,6 +63,7 @@ struct Chardev { CharFrontend *fe; char *label; char *filename; + bool connect_postponed; int logfd; int be_open; /* used to coordinate the chardev-change special-case: */ @@ -225,6 +226,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label, cons= t char *filename, bool permit_mux_mon); int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all= ); #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true) +bool qemu_chr_connect(Chardev *chr, Error **errp); int qemu_chr_wait_connected(Chardev *chr, Error **errp); =20 #define TYPE_CHARDEV "chardev" @@ -259,7 +261,33 @@ struct ChardevClass { /* parse command line options and populate QAPI @backend */ void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); =20 - /* called after construction, open/starts the backend */ + /* + * Called after construction, create the backend, mutually exclusive + * with @open, and should be followed by @connect(). + * Must set the Chardev's chr->filename on success. + */ + bool (*init)(Chardev *chr, ChardevBackend *backend, + Error **errp); + + /* + * Called after @init(), starts the backend, mutually exclusive + * with @open. Should care to send CHR_EVENT_OPENED when connected + * (this may happen asynchronously after .connect() call alredy + * returned). + */ + bool (*connect)(Chardev *chr, Error **errp); + + /* + * Called after construction, an alternative to @init + @connect + * and should do the work for both: create and start the backend. + * Mutually exclusive with @init and @connect. + * + * May not set the Chardev's chr->filename (generic code will care), + * and may not send CHR_EVENT_OPENED when connected (@be_opened + * should not be touched in this case, to signal the generic code + * to care about CHR_EVENT_OPENED). If the backend cares about + * CHR_EVENT_OPENED, it should set @be_opened to false. + */ void (*open)(Chardev *chr, ChardevBackend *backend, bool *be_opened, Error **errp); =20 --=20 2.48.1