From nobody Sat Nov 15 07:45:57 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=1755103986; cv=none; d=zohomail.com; s=zohoarc; b=DcsgXxPAwTYW9lPrlq7u8ZwPvY76945FwcmRSEJWqhIax9RVZrhxMZDiU28guHe4ARxbB5TFopRahjAkbDGn/JyYiS8Ynwxu8VOsT0qmxAmRiNmId/95d/tboz/yDJAus1UTj6IsuGS2FV4uCg3+gMer845jH8ZmG5OYUsha55k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755103986; 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=MVoLubdqzGcXSWvpEh3P9dHap5qN9edhnyELjiDiIEM=; b=nw2XrNt9fjYsSKPP+soxtZqj4Wx3Dh0pLpoCjJGAcHDFPm58qp7FEpo93Z7pTiXAwfTX9ov3HHH+ENjPx+WgPLoFQqstT8d2HA/2Xc3NyQRjlfsP/3dh3Tx4dN4jPnSgGEYaBBVlfXaHisDFdDBuj4JGG6QKBIMEJapfEjh2JSY= 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 1755103986610846.4280163226886; Wed, 13 Aug 2025 09:53:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1umEgd-0003VG-Rz; Wed, 13 Aug 2025 12:50:52 -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 1umEfx-000316-KJ; Wed, 13 Aug 2025 12:50:09 -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 1umEfm-0007u1-Ox; Wed, 13 Aug 2025 12:50:09 -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:cf2d:0:640:140f:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B74EE81403; Wed, 13 Aug 2025 19:49:29 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:167::1:21]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id wmOQI00FoSw0-lo4XRzL4; Wed, 13 Aug 2025 19:49:28 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1755103769; bh=MVoLubdqzGcXSWvpEh3P9dHap5qN9edhnyELjiDiIEM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OwZLqwjTxqocR9E+ycF9qw1fU/pHgSsIS6/AVK77TT++Nm4/P5sBXhCAhrIc2uVEs +NCNwdP39H+AySl5gNl+k7F15yc9/GpT32H/fe2TvV+2rD4wnApKlSJbSN/uhYkqWd R0A6O4AI5vt2Zk/KyFiPzXQqq/cwokVTOonuMbl4= 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: mst@redhat.com, peterx@redhat.com, farosas@suse.de, raphael@enfabrica.net Cc: sgarzare@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, kwolf@redhat.com, hreitz@redhat.com, berrange@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, steven.sistare@oracle.com, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 33/33] tests/functional: add test_x86_64_vhost_user_blk_fd_migration.py Date: Wed, 13 Aug 2025 19:48:54 +0300 Message-ID: <20250813164856.950363-34-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250813164856.950363-1-vsementsov@yandex-team.ru> References: <20250813164856.950363-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=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_DNSWL_NONE=-0.0001, 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 Precedence: list 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: 1755103988684124100 Content-Type: text/plain; charset="utf-8" Introduce a simple test to check that local migration of vhost-user-blk device with passing open fds through unix socket works, and the disk is still working on target. Signed-off-by: Vladimir Sementsov-Ogievskiy --- ...test_x86_64_vhost_user_blk_fd_migration.py | 279 ++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 tests/functional/test_x86_64_vhost_user_blk_fd_migratio= n.py diff --git a/tests/functional/test_x86_64_vhost_user_blk_fd_migration.py b/= tests/functional/test_x86_64_vhost_user_blk_fd_migration.py new file mode 100644 index 0000000000..7ab3f61a5b --- /dev/null +++ b/tests/functional/test_x86_64_vhost_user_blk_fd_migration.py @@ -0,0 +1,279 @@ +#!/usr/bin/env python3 +# +# Functional test that tests vhost-user-blk local migration +# with fd passing +# +# Copyright (c) Yandex +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess + +from qemu_test import ( + LinuxKernelTest, + Asset, + exec_command_and_wait_for_pattern, +) + + +def wait_migration_finish(source_vm, target_vm): + migr_events =3D ( + ("MIGRATION", {"data": {"status": "completed"}}), + ("MIGRATION", {"data": {"status": "failed"}}), + ) + + source_e =3D source_vm.events_wait(migr_events)["data"] + target_e =3D target_vm.events_wait(migr_events)["data"] + + source_s =3D source_vm.cmd("query-status")["status"] + target_s =3D target_vm.cmd("query-status")["status"] + + assert ( + source_e["status"] =3D=3D "completed" + and target_e["status"] =3D=3D "completed" + and source_s =3D=3D "postmigrate" + and target_s =3D=3D "paused" + ), f"""Migration failed: + SRC status: {source_s} + SRC event: {source_e} + TGT status: {target_s} + TGT event:{target_e}""" + + +class VhostUserBlkFdMigration(LinuxKernelTest): + + ASSET_KERNEL =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/initrd.img" + ), + "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b", + ) + + DATA1 =3D "TEST_DATA_BEFORE_MIGRATION_12345" + DATA2 =3D "TEST_DATA_AFTER_MIGRATION_54321" + + def write_data(self, data, vm) -> None: + exec_command_and_wait_for_pattern( + self, + f'echo "{data}" | ' "dd of=3D/dev/vda bs=3D512 count=3D1 oflag= =3Ddirect", + "# ", + vm=3Dvm, + ) + + def read_data(self, data, vm) -> None: + exec_command_and_wait_for_pattern( + self, + "dd if=3D/dev/vda bs=3D512 count=3D1 iflag=3Ddirect 2>/dev/nul= l", + data, + vm=3Dvm, + ) + + def setUp(self): + super().setUp() + self.vhost_proc =3D None + + def tearDown(self): + # Cleanup vhost-user server process + if self.vhost_proc: + try: + self.vhost_proc.terminate() + self.vhost_proc.wait(timeout=3D5) + except subprocess.TimeoutExpired: + self.vhost_proc.kill() + self.vhost_proc.wait() + except: + pass + + super().tearDown() + + def create_test_image(self): + """Create a temporary test image for vhost-user-blk""" + img_path =3D self.scratch_file("disk.img") + + # Create 64MB image + with open(img_path, "wb") as f: + f.write(b"\0" * (64 * 1024 * 1024)) + + return img_path + + def start_vhost_user_server(self, socket_path, img_path): + """Start vhost-user-blk server using contrib/vhost-user-blk""" + # Find vhost-user-blk binary + vub_binary =3D self.build_file( + "contrib", "vhost-user-blk", "vhost-user-blk" + ) + + if not os.path.isfile(vub_binary) or not os.access(vub_binary, os.= X_OK): + self.skipTest("vhost-user-blk binary not found") + + # assert that our further waiting would be correct + self.assertFalse(os.path.exists(socket_path)) + + cmd =3D [vub_binary, "-s", socket_path, "-b", img_path] + self.log.info(f'Starting vhost-user server: {" ".join(cmd)}') + self.vhost_proc =3D subprocess.Popen( + cmd, stderr=3Dsubprocess.PIPE, text=3DTrue, preexec_fn=3Dos.se= tsid + ) + + # Wait for socket to be created + for _ in range(100): # 10 seconds timeout + time.sleep(0.1) + + # Check if process is still running + if self.vhost_proc.poll() is not None: + self.fail(f"vhost-user server failed: {self.vhost_proc.std= err}") + + if os.path.exists(socket_path): + return + + self.fail(f"vhost-user socket {socket_path} was not created") + + def setup_shared_memory(self): + shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(shm_path, "wb") as f: + f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB + except Exception as e: + self.fail(f"Failed to create shared memory file: {e}") + + return shm_path + + def prepare_and_launch_vm( + self, shm_path, vhost_socket, incoming=3DFalse, vm=3DNone + ): + if not vm: + vm =3D self.vm + + vm.add_args("-accel", "kvm") + vm.add_args("-device", "pcie-pci-bridge,id=3Dpci.1,bus=3Dpcie.0") + vm.add_args("-m", "1G") + vm.add_args("-append", "console=3DttyS0 rd.rescue") + + vm.add_args( + "-object", + f"memory-backend-file,id=3Dram0,size=3D1G,mem-path=3D{shm_path= },share=3Don", + ) + vm.add_args("-machine", "memory-backend=3Dram0") + + vm.add_args("-kernel", self.ASSET_KERNEL.fetch()) + vm.add_args("-initrd", self.ASSET_INITRD.fetch()) + + vm.add_args("-S") + + if incoming: + vm.add_args("-incoming", "defer") + + vm.set_console() + + vm_s =3D "target" if incoming else "source" + self.log.info(f"Launching {vm_s} VM") + vm.launch() + + self.set_migration_capabilities(vm) + self.add_vhost_user_blk_device(vm, vhost_socket, incoming) + + def add_vhost_user_blk_device(self, vm, socket_path, incoming=3DFalse): + # Add chardev + chardev_params =3D { + "id": "chardev-virtio-disk0", + "backend": { + "type": "socket", + "data": { + "addr": {"type": "unix", "data": {"path": socket_path}= }, + "server": False, + "reconnect-ms": 20, + "support-local-migration": True, + }, + }, + } + + if incoming: + chardev_params["backend"]["data"]["local-incoming"] =3D True + + vm.cmd("chardev-add", chardev_params) + + # Add device + device_params =3D { + "id": "virtio-disk0", + "driver": "vhost-user-blk-pci", + "chardev": "chardev-virtio-disk0", + "num-queues": 1, + "bus": "pci.1", + "config-wce": False, + "bootindex": 1, + "disable-legacy": "off", + } + + if incoming: + device_params["local-incoming"] =3D True + + vm.cmd("device_add", device_params) + + def set_migration_capabilities(self, vm): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + {"capability": "local-vhost-user-blk", "state": True}, + {"capability": "local-char-socket", "state": True}, + ] + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + + def test_vhost_user_blk_fd_migration(self): + self.require_accelerator("kvm") + self.set_machine("q35") + + socket_dir =3D self.socket_dir() + vhost_socket =3D os.path.join(socket_dir.name, "vhost-user-blk.soc= k") + migration_socket =3D os.path.join(socket_dir.name, "migration.sock= ") + + img_path =3D self.create_test_image() + shm_path =3D self.setup_shared_memory() + + self.start_vhost_user_server(vhost_socket, img_path) + + self.prepare_and_launch_vm(shm_path, vhost_socket) + self.vm.cmd("cont") + self.wait_for_console_pattern("Entering emergency mode.") + self.wait_for_console_pattern("# ") + + self.write_data(self.DATA1, self.vm) + self.read_data(self.DATA1, self.vm) + + target_vm =3D self.get_vm(name=3D"target") + self.prepare_and_launch_vm( + shm_path, vhost_socket, incoming=3DTrue, vm=3Dtarget_vm + ) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket= }"}) + + self.log.info("Starting migration") + self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"}) + + self.log.info("Waiting for migration completion") + wait_migration_finish(self.vm, target_vm) + + target_vm.cmd("cont") + self.vm.shutdown() + + self.log.info("Verifying disk on target VM after migration") + self.read_data(self.DATA1, target_vm) + self.write_data(self.DATA2, target_vm) + self.read_data(self.DATA2, target_vm) + + target_vm.shutdown() + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1