From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A9F82E2F06 for ; Mon, 11 Aug 2025 22:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754951096; cv=none; b=Ainu1x+ilHCRu5eX3GiUYDFhKNzZ8kBQPfukNqme00d4TsstyQi8/aXyMtVBFEzSoLHc7cQB7ZIeGq1DwEOm8kyvvhy+6MdTX6h+qmwDwCjUxmoiUsZdg5rlHeAMwLJTNfKF8OjavclmJ0UEm/U+XZc6h9QnLbezcStY5Os6x0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754951096; c=relaxed/simple; bh=rbuKEmMBVvyftLbr7kYN1hr5YJLW9+Wv3sevwzvycg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J4cdJawwSntehdCyPiqzQ/5QVSVEYR5OA4NVglvFBbS96aQ0oJGjvQgI079HRQEQ6Mw3qlCS09FThOS4E/zAbDOyPCwOYiyTCkl2Fi2MXgPBX8uE8gLeZSrD+7+qJkRTN+BdH6oqdtt7hZn+mLF75scA6SxxNYDmDrJYFMr8fjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bEDRk3sP; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bEDRk3sP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=Avz8Qe7GLfI/zjTP7YqgVusKWE8liJ1U+576q96sa6w=; b=bEDRk3sPJLmNn2Aw6E+7laYsMU eh0aQW0M6cjYQm1pgozcf3YwebVuQfw2/Krg1p6mNU6rOKRL7mT6PkyjOr5IMqAyVDm0IGq7TLPpu b8VYWWAzcDWY/+QQo+KaefMALAQBVhlQwt8Qwtk/vclQ0qeozBhDTtJIJvPJG6DY8irZxDgtRN2tw zwaq2UwK25biV0CyyX4dEdaR00Vk+MaCLfztMWeSYNI5Q3CFXpvNpTu4UAIhDH8CgxFBKLGCMoKeV e7TZCHMTUmUyUh8/p2w9IIk2if2DWwwA0RTY/A4l7wiNdLYs39dbKO1OshMdI3bVW1WtE+DUsyOog qikFoCSA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1ulawn-00000009HkC-3GKf; Mon, 11 Aug 2025 22:24:53 +0000 From: Luis Chamberlain To: Chuck Lever , Daniel Gomez , kdevops@lists.linux.dev Cc: Luis Chamberlain Subject: [PATCH 17/23] reboot-limit: fix kexec and reboot connection handling Date: Mon, 11 Aug 2025 15:24:44 -0700 Message-ID: <20250811222452.2213071-18-mcgrof@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250811222452.2213071-1-mcgrof@kernel.org> References: <20250811222452.2213071-1-mcgrof@kernel.org> Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain Replace shell-based kexec implementation with proper Ansible tasks and fix connection handling for both systemctl reboot and kexec. For kexec: - Break down into discrete tasks to find kernel and initrd files - Use stat module to check multiple possible locations - Load kernel with kexec -l before executing systemctl kexec - Use async execution to avoid connection failures For both reboot types: - Use async: 1 and poll: 0 to fire-and-forget the reboot command - Add proper wait_for tasks to handle connection loss and recovery - Wait for system to go down then come back up This approach is more idiomatic Ansible and handles the SSH connection properly during system reboots. Generated-by: Claude AI Signed-off-by: Luis Chamberlain --- .../roles/reboot-limit/tasks/do-reboot.yml | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/playbooks/roles/reboot-limit/tasks/do-reboot.yml b/playbooks/roles/reboot-limit/tasks/do-reboot.yml index ec5c9fc8..1e5ba925 100644 --- a/playbooks/roles/reboot-limit/tasks/do-reboot.yml +++ b/playbooks/roles/reboot-limit/tasks/do-reboot.yml @@ -21,14 +21,140 @@ become: yes become_method: sudo command: "systemctl reboot" + async: 1 + poll: 0 when: - reboot_limit_test_type == "systemctl_reboot" tags: [ 'run_tests' ] +- name: Wait for system to go down for reboot + wait_for: + host: "{{ ansible_host }}" + port: 22 + state: stopped + delay: 5 + timeout: 60 + delegate_to: localhost + when: + - reboot_limit_test_type == "systemctl_reboot" + tags: [ 'run_tests' ] + +- name: Wait for system to come back after reboot + wait_for: + host: "{{ ansible_host }}" + port: 22 + state: started + delay: 10 + timeout: 300 + delegate_to: localhost + when: + - reboot_limit_test_type == "systemctl_reboot" + tags: [ 'run_tests' ] + +# kexec tasks - prepare the kernel for kexec before rebooting +- name: Get current kernel version for kexec + command: uname -r + register: current_kernel_version + when: + - reboot_limit_test_type == "systemctl_kexec" + tags: [ 'run_tests' ] + +- name: Check for kernel image locations for kexec + stat: + path: "{{ item }}" + register: kernel_stat + with_items: + - "/boot/vmlinuz-{{ current_kernel_version.stdout }}" + - "/boot/vmlinux-{{ current_kernel_version.stdout }}" + - "/boot/kernel-{{ current_kernel_version.stdout }}" + when: + - reboot_limit_test_type == "systemctl_kexec" + - current_kernel_version is defined + tags: [ 'run_tests' ] + +- name: Set kernel path for kexec + set_fact: + kexec_kernel_path: "{{ item.stat.path }}" + with_items: "{{ kernel_stat.results }}" + when: + - reboot_limit_test_type == "systemctl_kexec" + - item.stat.exists + tags: [ 'run_tests' ] + +- name: Check for initrd/initramfs locations for kexec + stat: + path: "{{ item }}" + register: initrd_stat + with_items: + - "/boot/initrd.img-{{ current_kernel_version.stdout }}" + - "/boot/initramfs-{{ current_kernel_version.stdout }}.img" + - "/boot/initrd-{{ current_kernel_version.stdout }}" + - "/boot/initrd-{{ current_kernel_version.stdout }}.img" + when: + - reboot_limit_test_type == "systemctl_kexec" + - current_kernel_version is defined + tags: [ 'run_tests' ] + +- name: Set initrd path for kexec + set_fact: + kexec_initrd_path: "{{ item.stat.path }}" + with_items: "{{ initrd_stat.results }}" + when: + - reboot_limit_test_type == "systemctl_kexec" + - item.stat.exists + tags: [ 'run_tests' ] + +- name: Read current kernel command line for kexec + slurp: + src: /proc/cmdline + register: cmdline_content + when: + - reboot_limit_test_type == "systemctl_kexec" + tags: [ 'run_tests' ] + +- name: Load kernel into kexec + become: yes + become_method: sudo + command: > + kexec -l {{ kexec_kernel_path }} + --initrd={{ kexec_initrd_path }} + --command-line="{{ cmdline_content.content | b64decode | trim }}" + when: + - reboot_limit_test_type == "systemctl_kexec" + - kexec_kernel_path is defined + - kexec_initrd_path is defined + tags: [ 'run_tests' ] + - name: Run the reboot test using systemctl kexec become: yes become_method: sudo command: "systemctl kexec" + async: 1 + poll: 0 + when: + - reboot_limit_test_type == "systemctl_kexec" + tags: [ 'run_tests' ] + +- name: Wait for system to go down for kexec + wait_for: + host: "{{ ansible_host }}" + port: 22 + state: stopped + delay: 5 + timeout: 60 + delegate_to: localhost + when: + - reboot_limit_test_type == "systemctl_kexec" + tags: [ 'run_tests' ] + +- name: Wait for system to come back after kexec + wait_for: + host: "{{ ansible_host }}" + port: 22 + state: started + delay: 10 + timeout: 300 + delegate_to: localhost when: - reboot_limit_test_type == "systemctl_kexec" tags: [ 'run_tests' ] -- 2.47.2