From nobody Fri Nov 14 21:05:52 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=1760615366; cv=none; d=zohomail.com; s=zohoarc; b=EAC9NIIIljJs2ss8OTfiQs54zBUaG93Ke0bVxGSKiWaA4zvYWaies8RUXkL/u0odmzXH33hKfiein0tdesOiN1SgVllmR70fqJzEFpJQy9RC5mZ2/Kx7dMaF8XENk8W26jUvbAleSXP4yi2ffJX/4beU8Zt6SXL4Yifo9jJ2oLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760615366; 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=HFE8QjC8Rnlm0okx70mpoOdoiRgantXWnrfbocdxBfk=; b=d4uHH3aP4NE5n8iSuQ3OunXLxMFyBJuY8WR12vbsHqtXLrg66GkGSnvB3Zcgd43jW9YmKSI7JIsfSWXFqAcTHRIHEe3AQVZEL4cGIL2srZsZbZsLav3LWAaHSJNEZyQGn28UJ0ncmva93h31JcyAhvkKduGdXlAJR+040tTyUr4= 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 1760615366031668.1884414015091; Thu, 16 Oct 2025 04:49:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v9MNf-0007WI-A7; Thu, 16 Oct 2025 07:42:51 -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 1v9MN0-0007B8-52; Thu, 16 Oct 2025 07:42:14 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v9MMt-0003Wb-ER; Thu, 16 Oct 2025 07:42:07 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 5E24BC01E8; Thu, 16 Oct 2025 14:41:43 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a8c::1:19]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id LfP2M73FEmI0-j6aB0vES; Thu, 16 Oct 2025 14:41:42 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760614902; bh=HFE8QjC8Rnlm0okx70mpoOdoiRgantXWnrfbocdxBfk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=VESwroG5eUtyHBICBfrKSGq1v/Rn3VzMJ/Pp3J6IPMXgIaOi+1wk74VRaDGHio6FQ QxsMo4VjTPaTLrSZdkCfKFbQhks+uWPIjSwEpyTA3VWk4o7rt0prp/ipJuiltADLE4 abzylGXg0AXjCKTLzHF+rm0SgdMh6B3aS14vSjbY= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: raphael@enfabrica.net, pbonzini@redhat.com, farosas@suse.de Cc: mst@redhat.com, sgarzare@redhat.com, marcandre.lureau@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, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, jasowang@redhat.com Subject: [PATCH v2 25/25] tests/functional: add test_x86_64_vhost_user_blk_fd_migration.py Date: Thu, 16 Oct 2025 14:41:02 +0300 Message-ID: <20251016114104.1384675-26-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251016114104.1384675-1-vsementsov@yandex-team.ru> References: <20251016114104.1384675-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1760615369295158500 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 | 307 ++++++++++++++++++ 1 file changed, 307 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..0523a71f15 --- /dev/null +++ b/tests/functional/test_x86_64_vhost_user_blk_fd_migration.py @@ -0,0 +1,307 @@ +#!/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/releases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/" + "pub/archive/fedora/linux/releases" + "/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_procs =3D [] + + def tearDown(self): + # Cleanup vhost-user server processes + for proc in self.vhost_procs: + if proc: + try: + proc.terminate() + proc.wait(timeout=3D5) + except subprocess.TimeoutExpired: + proc.kill() + 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)}') + proc =3D subprocess.Popen( + cmd, stderr=3Dsubprocess.PIPE, text=3DTrue, preexec_fn=3Dos.se= tsid + ) + self.vhost_procs.append(proc) + + # Wait for socket to be created + for _ in range(100): # 10 seconds timeout + time.sleep(0.1) + + # Check if process is still running + if proc.poll() is not None: + self.fail(f"vhost-user server failed: {proc.stderr}") + + 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, + use_backend_transfer=3DTrue, + ): + 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, use_backend_transfer) + self.add_vhost_user_blk_device(vm, vhost_socket) + + def add_vhost_user_blk_device(self, vm, socket_path): + # 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, + }, + }, + } + + 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", + } + + vm.cmd("device_add", device_params) + + def set_migration_capabilities(self, vm, use_backend_transfer=3DTrue): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + ] + + if use_backend_transfer: + capabilities.append( + {"capability": "local-vhost-user-blk", "state": True} + ) + + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + + def do_test_vhost_user_blk_fd_migration(self, use_backend_transfer=3DT= rue): + 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) + + if not use_backend_transfer: + target_vhost_socket =3D os.path.join( + socket_dir.name, "vhost-user-blk-target.sock" + ) + self.start_vhost_user_server(target_vhost_socket, img_path) + else: + target_vhost_socket =3D vhost_socket + + self.prepare_and_launch_vm( + shm_path, vhost_socket, use_backend_transfer=3Duse_backend_tra= nsfer + ) + 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, + target_vhost_socket, + incoming=3DTrue, + vm=3Dtarget_vm, + use_backend_transfer=3Duse_backend_transfer, + ) + + 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() + + def test_vhost_user_blk_fd_migration_backend_transfer(self): + """Test vhost-user-blk migration with backend-transfer (fd passing= )""" + self.do_test_vhost_user_blk_fd_migration(use_backend_transfer=3DTr= ue) + + def test_vhost_user_blk_fd_migration_regular(self): + """Test vhost-user-blk migration without backend-transfer""" + self.do_test_vhost_user_blk_fd_migration(use_backend_transfer=3DFa= lse) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1