From nobody Fri Nov 14 19:46:55 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=1760455770; cv=none; d=zohomail.com; s=zohoarc; b=nZpyRxeMl497HYuxFPwXfFPrYJszkZTzbwEvIhVFRK6cJE+B49gSkvhuhuN5ttjdOgPh90tvlB60qOxccqTqlBAKacjpRAf2hOtkV4Lp3/JGVlMGqQfZGwqgQTdtmOBwlUCjGid56r946YaDvsvPWfyfqDr/UC1otNvkN0MFGIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760455770; 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=e7yXNIFXohwZf1oeg5G5audWTehOW7zR4XPHuWfXKaU=; b=gYoMz0MZxSvVNv1LMIQS1npoc0Ip7NXg3S1cPPaKlUiglzTDBd27gg/7zn7zojMy4bTUWs1WNxQbYGFZ3/TOEIrOtzr1/XRzdJ1crbZcecxUFvqQrAnKpp0EM67JyKqRy2g6MMUcCGA0lIgMm1b1CNRI+kwnBkb3tbixv18uStI= 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 1760455770815457.35590334108485; Tue, 14 Oct 2025 08:29:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v8gvp-00070V-KO; Tue, 14 Oct 2025 11:27:21 -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 1v8gvm-0006yv-1Y for qemu-devel@nongnu.org; Tue, 14 Oct 2025 11:27:18 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v8gvj-0007gt-Sw for qemu-devel@nongnu.org; Tue, 14 Oct 2025 11:27:17 -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 0B198807DB; Tue, 14 Oct 2025 18:27:13 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a8a::1:35]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 7RRbiX2F1mI0-jNHSANgp; Tue, 14 Oct 2025 18:27:12 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760455632; bh=e7yXNIFXohwZf1oeg5G5audWTehOW7zR4XPHuWfXKaU=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=WV5e/Sb9Wp9A5HD5tPfeNne2HzEblegOj4LnA9dL5+bZLoHEBjk54/RrpbXdDqSKX ESfW5LT6h/0Y4hFhLYw6hAoM06lHJimu2GOwPJiZ2XAI8MsQx1ognQ7g7gqSllwajk hV5fD3JAa6ZAWezm3CDAav1GptMwDD1FV8+hBDC8= 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 v3 5/7] chardev/char: introduce .init() + .connect() initialization interface Date: Tue, 14 Oct 2025 18:26:42 +0300 Message-ID: <20251014152644.954762-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251014152644.954762-1-vsementsov@yandex-team.ru> References: <20251014152644.954762-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=178.154.239.200; 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+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: 1760455773686158500 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 | 39 +++++++++++++++++++++++++++++++++++++-- include/chardev/char.h | 22 +++++++++++++++++++++- 3 files changed, 62 insertions(+), 3 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 27290e26fb..409f3aac1c 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 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