From nobody Fri Nov 14 21:04:56 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=1760362798; cv=none; d=zohomail.com; s=zohoarc; b=kg//y7CnttbbxmMpWAAxmYk+XxBcoy+9gIrFbzDV8FaTPsoKIYCCEYSxWg0Mg1rVciz5WqXiee8iPvWWBLndy8dS85QhsQGq4BlLoxdcH3p0FTwdNT+VvUq1sNGBMkGkfyLSghO20BtC+pP9oCAg4zTmaQEOWHbWZCSwkrum/NY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760362798; 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=gGtQ/UnrHXk+W76Hl4SsEutQEnTKqDNL1Q6CcvGaUIY=; b=T/EEWd0NP+YYYNagAnXHENp0nK49wvbuVsbjVyqfhSFAhNWxl8HqmUfqtVjAdUip4IWQpWLovUv2mHjesU+2/3J9UM5V8fLhbuenXWgA+zENgZGL60KB08BdE4bJQq6Cn/J+G3X1cmanc5vGREQ0ETF/mlAx7dVWQLk2u566WN8= 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 1760362798034242.9502218685659; Mon, 13 Oct 2025 06:39:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v8IlO-0006fW-AB; Mon, 13 Oct 2025 09:38:58 -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 1v8IlI-0006dB-Kj for qemu-devel@nongnu.org; Mon, 13 Oct 2025 09:38:52 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1v8IlC-0006au-Ga for qemu-devel@nongnu.org; Mon, 13 Oct 2025 09:38:52 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:65a0:0:640:e1de:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 1010680859; Mon, 13 Oct 2025 16:38:44 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a50::1:2a]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ccOm1D2F0Cg0-QxzBLNKH; Mon, 13 Oct 2025 16:38:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760362723; bh=gGtQ/UnrHXk+W76Hl4SsEutQEnTKqDNL1Q6CcvGaUIY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=IqyxXYHo9C/bPmKjukby+OUSBpqEcfFmLT7YD9mUCiqrF/bsBPNi//6EGeaa/GPx3 EP9GqrvK7GlK/8uA2JmNJHmLE9AkUxNLzOrHSoW2y7sIVO2eM2v41rUR+JlJGG8wn2 7fOCIRcTSdPKV2C13+Vwo5anASJbA9ePnoNH1x5U= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.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 v2 5/7] chardev/char: introduce .init() + .connect() initialization interface Date: Mon, 13 Oct 2025 16:38:34 +0300 Message-ID: <20251013133836.852018-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251013133836.852018-1-vsementsov@yandex-team.ru> References: <20251013133836.852018-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:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: 1760362800417154100 Content-Type: text/plain; charset="utf-8" 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, either 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 | 40 +++++++++++++++++++++++++++++++++++++--- include/chardev/char.h | 22 +++++++++++++++++++++- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 158a5f4f55..973fed5bea 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -193,6 +193,10 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Erro= r **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 6498d53daa..01ffe37acf 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); } @@ -1029,7 +1049,7 @@ static Chardev *chardev_new(const char *id, const cha= r *typename, { Object *obj; Chardev *chr =3D NULL; - Error *local_err =3D NULL; + ChardevClass *cc; =20 assert(g_str_has_prefix(typename, "chardev-")); assert(id); @@ -1044,8 +1064,22 @@ static Chardev *chardev_new(const char *id, const ch= ar *typename, goto fail; } =20 - if (!qemu_char_open(chr, backend, typename + 8, &local_err)) { - 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 429852f8d9..ebadaf3482 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -63,6 +63,7 @@ struct Chardev { CharBackend *be; 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,10 +261,28 @@ 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 and open/starts the backend, + * mutual exclusive with .init. .connect must not be defined when + * .open is defined. + */ void (*open)(Chardev *chr, ChardevBackend *backend, bool *be_opened, Error **errp); =20 + /* + * Called after construction, create the backend, mutual exclusive + * with .open, and must be accompanied by .connect. + * Must set chr-filename. + */ + bool (*init)(Chardev *chr, ChardevBackend *backend, + Error **errp); + + /* + * Called after .init(), open/starts the backend, mutual exclusive + * with .open. Must send CHR_EVENT_OPENED. + */ + bool (*connect)(Chardev *chr, Error **errp); + /* write buf to the backend */ int (*chr_write)(Chardev *s, const uint8_t *buf, int len); =20 --=20 2.48.1