From: "Denis V. Lunev" <den@openvz.org>
To: svt-core@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, den@openvz.org
Subject: [PATCH hci-8.0 v2 1/3] chardev: implement cpr_claim_fds() in the base class #VSTOR-148304
Date: Mon, 5 Oct 2026 11:26:33 +0200 [thread overview]
Message-ID: <20261005092635.3564485-2-den@openvz.org> (raw)
In-Reply-To: <20261005092635.3564485-1-den@openvz.org>
From: Denis V. Lunev <den@openvz.org>
Give TYPE_CHARDEV an empty cpr_claim_fds() and make the file, pty and
socket backends chain to their parent's. Every chardev class then has
the hook, so qmp_chardev_change() calls it without a NULL check, and
state owned by the base class can be re-claimed there as well.
No functional change.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
chardev/char-file.c | 3 +++
chardev/char-pty.c | 3 +++
chardev/char-socket.c | 3 +++
chardev/char.c | 13 +++++++------
include/chardev/char.h | 5 ++++-
5 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/chardev/char-file.c b/chardev/char-file.c
index a90f4a77e13..89011f52e3e 100644
--- a/chardev/char-file.c
+++ b/chardev/char-file.c
@@ -124,7 +124,10 @@ out_close:
static void char_file_cpr_claim_fds(Chardev *chr)
{
FDChardev *s = FD_CHARDEV(chr);
+ ChardevClass *pc = CHARDEV_CLASS(
+ object_class_get_parent(object_class_by_name(TYPE_CHARDEV_FILE)));
+ pc->cpr_claim_fds(chr);
if (s->ioc_out) {
cpr_delete_fd(chr->label, 0);
cpr_save_fd(chr->label, 0, QIO_CHANNEL_FILE(s->ioc_out)->fd);
diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index a0090e4c3d1..8058da92bb4 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -403,7 +403,10 @@ static void char_pty_open(Chardev *chr,
static void char_pty_cpr_claim_fds(Chardev *chr)
{
PtyChardev *s = PTY_CHARDEV(chr);
+ ChardevClass *pc = CHARDEV_CLASS(
+ object_class_get_parent(object_class_by_name(TYPE_CHARDEV_PTY)));
+ pc->cpr_claim_fds(chr);
if (s->ioc) {
cpr_delete_fd(chr->label, 0);
cpr_save_fd(chr->label, 0, QIO_CHANNEL_FILE(s->ioc)->fd);
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index d20aea764f9..c73a3dd0f7a 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -1681,7 +1681,10 @@ char_socket_get_connected(Object *obj, Error **errp)
static void char_socket_cpr_claim_fds(Chardev *chr)
{
SocketChardev *s = SOCKET_CHARDEV(chr);
+ ChardevClass *pc = CHARDEV_CLASS(
+ object_class_get_parent(object_class_by_name(TYPE_CHARDEV_SOCKET)));
+ pc->cpr_claim_fds(chr);
if (s->sioc) {
cpr_delete_fd(chr->label, CPR_CONNSOCK_ID);
cpr_save_fd(chr->label, CPR_CONNSOCK_ID, s->sioc->fd);
diff --git a/chardev/char.c b/chardev/char.c
index 87f40d0137e..b64767f574e 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -295,12 +295,17 @@ static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
return len;
}
+static void char_cpr_claim_fds(Chardev *chr)
+{
+}
+
static void char_class_init(ObjectClass *oc, const void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->chr_write = null_chr_write;
cc->chr_be_event = chr_be_event;
+ cc->cpr_claim_fds = char_cpr_claim_fds;
}
static void char_finalize(Object *obj)
@@ -1164,9 +1169,7 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
backend, chr->gcontext, handover_yank_instance, errp);
if (!chr_new) {
/* the failed replacement's open() may have displaced our cpr fds */
- if (cc->cpr_claim_fds) {
- cc->cpr_claim_fds(chr);
- }
+ cc->cpr_claim_fds(chr);
return NULL;
}
@@ -1186,9 +1189,7 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
qemu_chr_be_event(chr, CHR_EVENT_OPENED);
}
/* chr_new's open() may have displaced our cpr fds; re-claim them */
- if (cc->cpr_claim_fds) {
- cc->cpr_claim_fds(chr);
- }
+ cc->cpr_claim_fds(chr);
object_unref(OBJECT(chr_new));
return NULL;
}
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 431d07ad3c6..968766fd5d5 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -305,7 +305,10 @@ struct ChardevClass {
/* notify the backend of frontend open state */
void (*chr_set_fe_open)(Chardev *chr, int fe_open);
- /* (re-)register the backend's CPR fds, e.g. on a failed chardev-change */
+ /*
+ * (re-)register CPR fds, e.g. on a failed chardev-change; an override
+ * must call the parent's hook first
+ */
void (*cpr_claim_fds)(Chardev *chr);
/* handle various events */
--
2.53.0
next prev parent reply other threads:[~2026-10-05 9:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 9:26 [PATCH hci-8.0 v2 0/3] chardev: fix qemu-update destroying VMs with a console log #VSTOR-148304 Denis V. Lunev
2026-10-05 9:26 ` Denis V. Lunev [this message]
2026-10-05 9:28 ` [PATCH hci-8.0 v2 1/3] chardev: implement cpr_claim_fds() in the base class #VSTOR-148304 no-reply
2026-10-05 9:26 ` [PATCH hci-8.0 v2 2/3] chardev: preserve the logfile fd across cpr-exec #VSTOR-148304 Denis V. Lunev
2026-10-05 9:30 ` no-reply
2026-10-05 9:26 ` [PATCH hci-8.0 v2 3/3] iotests/migrate-cpr-exec: cover chardevs with logfile= #VSTOR-148304 Denis V. Lunev
2026-10-05 9:35 ` no-reply
2026-10-05 9:47 ` [PATCH hci-8.0 v2 0/3] chardev: fix qemu-update destroying VMs with a console log #VSTOR-148304 Andrey Drobyshev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261005092635.3564485-2-den@openvz.org \
--to=den@openvz.org \
--cc=andrey.drobyshev@virtuozzo.com \
--cc=svt-core@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox