From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11023123.outbound.protection.outlook.com [52.101.72.123]) by lore.virtuozzo.com (Postfix) with ESMTPS id F2211802A5 for ; Mon, 5 Oct 2026 09:26:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xdDQozwhlZMR+BAgqB5jHywClwsh/d6g35aO6UsCVBfgnFXyds63d/ViZbfjGA9qIk5DwjEkAkctMhWyi4BekKQ7YWvU90d9aSR9znOh2L7B+GwmV3ZBuyhlp3u6Hwc578iS3bXAGRaA3lTSk18tJCjLFcsXYWRBuL5R5nHO4cilsJz3k2s2PfINAyuT0ezxEinz1SCGWMTWWWxhNOZHzk/+n5I2f2IlN3zSVFU1wqVuFM3xQU8tCEafy2kvbW9VQPrScpWSZOP200qoxLBfiH8WfpPvC60hfbB7JwNd8tX3TPEF5Iq2IFfg2FYVCyKh7p8wtCbTxGfH5RFe/W3pDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TunHiV5/ITLXHc31LwzXfvg/y5P22sIiJqUeKuVkV7Q=; b=HUSqmML22TvW1idrd5RFfcUZwg7LbhUA2Ns5tGVnI4Ut+UDY8gHG4CTW+a4Zalu8ki8pgzhMAqISU8pWUNNbcAooIsA3ol7Gfm4KqNnKMTzyzhVZRVJ1vW1MP4e46lowQiviOdnitEqBK/Zr5LTBnBwqYdgS9RNuqkfRN7tjxvn6e7YOR41DCGhQQ1JGu3tcExc7NaMSjz4VfT3Yq+CeLnh4UgoRc/2q9n52gXxe/A6VnCLWlfN8mlqhx+gC2tarqfuEndt9DZNRqV20TVPpLMr7PtJaef+8LVfujFxknXNnObfCvCLrOavGwEGb321XAG2+c5T2mW+fkJiOSOpemQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 2a00:1450:4864:20::436) smtp.rcpttodomain=virtuozzo.com smtp.mailfrom=openvz.org; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=openvz.org; dkim=pass (signature was verified) header.d=openvz.org; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.onmicrosoft.com; s=selector2-virtuozzo-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TunHiV5/ITLXHc31LwzXfvg/y5P22sIiJqUeKuVkV7Q=; b=T7/lnAqs+2bYQy0qZVVFl4Qtt62R4p+DK6C6vBqpicg+CMK+QbZ/Im76lKbd9Fwp4NC+bhEr5A63wWF6bgrWTWFPEdiAgeOb5N/hvrZXyAiATytMYJMwnGwCQSzRXyuTdUan7Mqbn/3CFKyd3wSNYM0G3fJm54mah/jSxsZY4IM= Received: from PR1P264CA0105.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:2cf::18) by AS4PR08MB7880.eurprd08.prod.outlook.com (2603:10a6:20b:51f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.472.18; Mon, 5 Oct 2026 09:26:44 +0000 Received: from MI3PEPF00008555.eurprd05.prod.outlook.com (2603:10a6:102:2cf:cafe::64) by PR1P264CA0105.outlook.office365.com (2603:10a6:102:2cf::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.472.20 via Frontend Transport; Mon, 5 Oct 2026 09:26:42 +0000 Authentication-Results: spf=pass (sender IP is 2a00:1450:4864:20::436) smtp.mailfrom=openvz.org; dkim=pass (signature was verified) header.d=openvz.org;dmarc=pass action=none header.from=openvz.org; Received-SPF: Pass (protection.outlook.com: domain of openvz.org designates 2a00:1450:4864:20::436 as permitted sender) receiver=protection.outlook.com; client-ip=2a00:1450:4864:20::436; helo=mail-wr1-x436.google.com; pr=C Received: from mail-wr1-x436.google.com (2a00:1450:4864:20::436) by MI3PEPF00008555.mail.protection.outlook.com (2603:10a6:298:1::89) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.472.14 via Frontend Transport; Mon, 5 Oct 2026 09:26:41 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-48b02a2359aso847274f8f.0 for ; Mon, 05 Oct 2026 02:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1791192400; x=1791797200; darn=virtuozzo.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TunHiV5/ITLXHc31LwzXfvg/y5P22sIiJqUeKuVkV7Q=; b=nmoSK8G3OeshC1c7uaNC57T1CRO9qbevaa1aZf00rCWEqfy81FNEElPt039xi+AUmn 4l4G2Be16lqrwV28OfK+UikbUepUZzlWRT0MdmwSqLvD6Lg/DhtrWntdSpcgslM8qOTg 21biwzkJ5TqjXFQk/uNYPoj/oc30nw9y+hb9cLeEGS0b7wXhaPpeNaqyzOi8R6ta/HRo o0wnuNTDHEvKR4V0Su7B/30ohcQJWkp46pnHY5c++iG+OcSGvc+P8LrZxXXiUGayh4gx XWgZUhsWQ9WpzYfEDlTaMiSIJhLjwKAaGNyx4yeMTgn7l9u411H3aD53oiS8y3WKZK5A cMxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791192400; x=1791797200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TunHiV5/ITLXHc31LwzXfvg/y5P22sIiJqUeKuVkV7Q=;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c47fce097mr13252893f8f.7.1791192400318; Mon, 05 Oct 2026 02:26:40 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:bff9:47a9:54d2:1c0b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c62270739sm2434715f8f.11.2026.10.05.02.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2026 02:26:39 -0700 (PDT) From: "Denis V. Lunev" To: svt-core@virtuozzo.com Cc: andrey.drobyshev@virtuozzo.com, den@openvz.org Subject: [PATCH hci-8.0 v2 2/3] chardev: preserve the logfile fd across cpr-exec #VSTOR-148304 Date: Mon, 5 Oct 2026 11:26:34 +0200 Message-ID: <20261005092635.3564485-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261005092635.3564485-1-den@openvz.org> References: <20261005092635.3564485-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-EOPTenantAttributedMessage: 0bc7f26d-0264-416e-a6fc-8352af79c58f:0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MI3PEPF00008555:EE_|AS4PR08MB7880:EE_ X-MS-Office365-Filtering-Correlation-Id: 325f367c-d3ac-44c6-4b2d-08df22c2c3bc X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 0 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|9140799003|376014|82310400026|61400799027|48200799018|6059299003|43022699015|3023799007|10067099003|5063699009|56012099006|16102099003|22082099003|18002099003|55112099003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DKrN8dF/FhhiYJbsrOshVZILVjRzqzp81ApVA78S5Co3eruMUE2VujGjxTT8?= =?us-ascii?Q?g7zEQcxvkVyYHvrI9fdg/CgjgRmGSglSLIdK9XOEQg/NrrUYcMw2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gML4BtDq6qaTda0ZbqfBmrRDLw=3D?= X-Forefront-Antispam-Report: CIP:2a00:1450:4864:20::436;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail-wr1-x436.google.com;PTR:mail-wr1-x436.google.com;CAT:NONE;SFS:(13230040)(9140799003)(376014)(82310400026)(61400799027)(48200799018)(6059299003)(43022699015)(3023799007)(10067099003)(5063699009)(56012099006)(16102099003)(22082099003)(18002099003)(55112099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0HKkPzkKIua+4UgUYwMiftCagMJxqgQRKbapywJT621pps03e8X4k8xFbiTpbEAyeo+P3ohQqQoK8r55ob55LLrY7SfJMK5dgOlFfdRVi2AWyg/ENLbXwCwu8tNCDD3qcUSOczujgWqwpbdQCTvcFfohzMPk+C4MvQk8BD2w7Ge8r17IXDR9G7hr7FuZx//e1L4zka7C2ABZ2gsVCco/5QqCwZoA6+Fn6pSI/58WmyoI0hD1yfHhFGMzSiqEhPFumGQdsWvhpSZPMwNGlRhmPlgOHDu7WxkSUVmuFYfO1P0J6zQsqGEuepsJlKJ8jU9w/T6cvSWTwM9jrz0tOcFNR55Z7gcghcxOlXQ/9zAaDgnf/oeB7hlw6B3E73tW61vWCHIFjF5TKMzP65N/LL0K435lN7X4/mSjwFgco/j9ZuFCyrfVRiDWVmEEgjN3plHx X-ExternalRecipientOutboundConnectors: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-Auto-Response-Suppress: DR, OOF, AutoReply X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2026 09:26:41.1734 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 325f367c-d3ac-44c6-4b2d-08df22c2c3bc X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-AuthSource: MI3PEPF00008555.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7880 List-Id: From: Denis V. Lunev A chardev with logfile= opens the log in qemu_char_open() on every start, including the start of the new QEMU after cpr-exec. The backend fds are taken from the cpr fd registry there, the log fd is not, so the new process reopens the path itself. libvirt normally opens the log through virtlogd and passes a pipe in an fdset. The qemu-update command line cannot carry that fdset, so it names the log file path. The exec'd QEMU, running as the qemu user, then fails to create a log it has no write access to, e.g. a nova console.log on node-local storage: qemu-kvm: -chardev pty,id=charserial0,logfile=.../console.log, logappend=on: Could not create '.../console.log': Permission denied and the VM is destroyed. Where the open succeeds, the new QEMU writes the file directly, behind virtlogd's back. Save the log fd in the cpr registry under the chardev label and take it from there on cpr-exec incoming, as the backends do. The logfile path is not opened at all then. If the source did not save it, run without a log rather than reopen the path. A failed chardev-change re-claims the log through the base class cpr_claim_fds(), since the replacement's log has displaced the entry. Signed-off-by: Denis V. Lunev Reviewed-by: Andrey Drobyshev --- chardev/char.c | 30 +++++++++++++++++++++++++----- include/migration/cpr.h | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index b64767f574e..c037d2e7730 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -40,6 +40,7 @@ #include "qemu/id.h" #include "qemu/coroutine.h" #include "qemu/yank.h" +#include "migration/cpr.h" #include "chardev-internal.h" @@ -261,9 +262,21 @@ static void qemu_char_open(Chardev *chr, ChardevBackend *backend, } else { flags |= O_TRUNC; } - chr->logfd = qemu_create(common->logfile, flags, 0666, errp); - if (chr->logfd < 0) { - return; + if (cpr_exec_is_incoming()) { + chr->logfd = cpr_find_fd(chr->label, CPR_CHARDEV_LOG_ID); + if (chr->logfd < 0) { + warn_report("chardev '%s': log file was not preserved, " + "continuing without it", chr->label); + } + } else { + chr->logfd = qemu_create(common->logfile, flags, 0666, errp); + if (chr->logfd < 0) { + return; + } + if (!cpr_is_incoming()) { + cpr_delete_fd(chr->label, CPR_CHARDEV_LOG_ID); + cpr_save_fd(chr->label, CPR_CHARDEV_LOG_ID, chr->logfd); + } } } @@ -297,6 +310,10 @@ static int null_chr_write(Chardev *chr, const uint8_t *buf, int len) static void char_cpr_claim_fds(Chardev *chr) { + if (chr->logfd >= 0) { + cpr_delete_fd(chr->label, CPR_CHARDEV_LOG_ID); + cpr_save_fd(chr->label, CPR_CHARDEV_LOG_ID, chr->logfd); + } } static void char_class_init(ObjectClass *oc, const void *data) @@ -315,11 +332,14 @@ static void char_finalize(Object *obj) if (chr->be) { chr->be->chr = NULL; } - g_free(chr->filename); - g_free(chr->label); if (chr->logfd != -1) { + if (cpr_find_fd(chr->label, CPR_CHARDEV_LOG_ID) == chr->logfd) { + cpr_delete_fd(chr->label, CPR_CHARDEV_LOG_ID); + } close(chr->logfd); } + g_free(chr->filename); + g_free(chr->label); qemu_mutex_destroy(&chr->chr_write_lock); } diff --git a/include/migration/cpr.h b/include/migration/cpr.h index d74ff1ea602..8fb79eb0a28 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -15,6 +15,7 @@ #define CPR_LISTENSOCK_ID 0 #define CPR_CONNSOCK_ID 1 +#define CPR_CHARDEV_LOG_ID 2 #define QEMU_CPR_FILE_MAGIC 0x51435052 #define QEMU_CPR_FILE_VERSION 0x00000001 -- 2.53.0