* [PATCH] gen_node: add debugger support for guestfs libvirt guests
@ 2025-04-24 16:58 Swarna Prabhu
2025-04-24 17:28 ` Luis Chamberlain
0 siblings, 1 reply; 2+ messages in thread
From: Swarna Prabhu @ 2025-04-24 16:58 UTC (permalink / raw)
To: kdevops; +Cc: mcgrof, da.gomez, sw.prabhu6, Swarna Prabhu
The motivation behind enabling the support for the debugger is to
make kdevops user friendly for bug fixing and troubleshooting, thereby
saving the time needed to configure guest during bringup. When enabled,
libvirt_gdb_baseport is assigned with a base port number extracted
from the md5sum of the script get_gdb_base_port.sh to which we add an index
for every guest during gen_nodes bringup. The bringup is also modified
to verify that no port conflict exists and if does, will fail informing
the user to change the base port.
This feature is disabled by default as kdevops is heavily used
by CI where this support is not needed. However for folks relying
on kdevops for kernel development and testing, can now leverage this
option to help with debugging.
Signed-off-by: Swarna Prabhu <s.prabhu@samsung.com>
---
kconfigs/Kconfig.libvirt | 25 ++++++++++++++++++
playbooks/roles/gen_nodes/defaults/main.yml | 3 +++
playbooks/roles/gen_nodes/tasks/main.yml | 26 +++++++++++++++++++
.../gen_nodes/templates/guestfs_q35.j2.xml | 4 +++
.../gen_nodes/templates/guestfs_virt.j2.xml | 4 +++
scripts/get_gdb_base_port.sh | 13 ++++++++++
6 files changed, 75 insertions(+)
create mode 100755 scripts/get_gdb_base_port.sh
diff --git a/kconfigs/Kconfig.libvirt b/kconfigs/Kconfig.libvirt
index cba8abf..955399e 100644
--- a/kconfigs/Kconfig.libvirt
+++ b/kconfigs/Kconfig.libvirt
@@ -1104,6 +1104,31 @@ config LIBVIRT_STORAGE_POOL_NAME
For instance you may want to use a volume name of "data2" for a path
on a partition on /data2/ or something like that.
+config LIBVIRT_ENABLE_GDB
+ bool "Enable GDB debugging for the guest"
+ output yaml
+ help
+ Select this option if you want to enable debugging support for GDB.
+ By default , it is assumed that gdb is disabled since we dont want
+ to complicate this for the CI runs. If enabled then libvirt guest
+ xml for each guest will be configured to use gdb on a specific
+ tcp port.
+
+config LIBVIRT_GDB_BASEPORT
+ int
+ default $(shell, ./scripts/get_gdb_base_port.sh) if LIBVIRT
+ output yaml
+ depends on LIBVIRT_ENABLE_GDB
+ help
+ This option defines the base port to be used for the GDB.
+ Esentially we need to make QEMU listen for an incoming connection from
+ gdb on a TCP port. The default port is chosen to be 1234. However we
+ introduce variability for assigning the port to each guest by defining
+ a base port and adding an index to it based on the number of libvrt guest
+ nodes. Therefore the base port is extracted from the md5sum of the
+ /scripts/get_gdb_base_port.sh file and use the last 4 digits of the md5sum
+ of the file to assign to libvirt_gdb_baseport.
+
source "kconfigs/Kconfig.libvirt.zns"
source "kconfigs/Kconfig.libvirt.largeio"
source "kconfigs/Kconfig.libvirt.cxl"
diff --git a/playbooks/roles/gen_nodes/defaults/main.yml b/playbooks/roles/gen_nodes/defaults/main.yml
index 8ff9b87..6a899be 100644
--- a/playbooks/roles/gen_nodes/defaults/main.yml
+++ b/playbooks/roles/gen_nodes/defaults/main.yml
@@ -27,6 +27,9 @@ vagrant_box: "debian/testing64"
vagrant_box_version: ""
libvirt_vcpus_count: 8
libvirt_mem_mb: 4096
+gdb_port_conflict: False
+libvirt_enable_gdb: False
+libvirt_gdb_baseport: 1234
qemu_bin_path: "/usr/bin/qemu-system-x86_64"
extra_disk_path: ".vagrant/nvme_disks"
extra_disk_driver: "nvme"
diff --git a/playbooks/roles/gen_nodes/tasks/main.yml b/playbooks/roles/gen_nodes/tasks/main.yml
index d541dcb..9312fef 100644
--- a/playbooks/roles/gen_nodes/tasks/main.yml
+++ b/playbooks/roles/gen_nodes/tasks/main.yml
@@ -561,13 +561,39 @@
- kdevops_enable_guestfs|bool
- pcie_passthrough_enable|bool
+- name: Find if port conflict occur
+ ansible.builtin.shell: "ss -ltn | grep ':{{ (libvirt_gdb_baseport | int) + (idx | int) }} '"
+ register: gdb_port_reg
+ failed_when: false
+ changed_when: false
+ loop: "{{ guestfs_nodes }}"
+ loop_control:
+ index_var: idx
+ when:
+ - kdevops_enable_guestfs|bool
+
+- name: Set the conflict flag on if conflict occur
+ set_fact:
+ gdb_port_conflict: True
+ when: >
+ gdb_port_reg.results is defined and
+ gdb_port_reg.results | selectattr('rc', 'equalto', 0) | list | length > 0
+
+- name: Fail bringup if gdb port conflict occur
+ fail:
+ msg: "GDB port conflict occur, please check the base port number {{ libvirt_gdb_baseport }} and try with another"
+ when: gdb_port_conflict|bool
+
- name: Generate XML files for the libvirt guests
vars:
hostname: "{{ item.name }}"
+ guestidx: "{{ idx }}"
template:
src: "guestfs_{{ libvirt_machine_type }}.j2.xml"
dest: "{{ topdir_path }}/guestfs/{{ hostname }}/{{ hostname }}.xml"
force: yes
with_items: "{{ guestfs_nodes }}"
+ loop_control:
+ index_var: idx
when:
- kdevops_enable_guestfs|bool
diff --git a/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml b/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
index adaba91..698225d 100644
--- a/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
+++ b/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
@@ -184,6 +184,10 @@
<qemu:arg value='ICH9-LPC.disable_s4=0'/>
<qemu:arg value='-device'/>
<qemu:arg value='pxb-pcie,id=pcie.1,bus_nr=32,bus=pcie.0,addr=0x8'/>
+ {% if libvirt_enable_gdb %}
+ <qemu:arg value='-gdb'/>
+ <qemu:arg value='tcp::{{ libvirt_gdb_baseport + idx}}'/>
+ {% endif %}
{% include './templates/gen_drives.j2' %}
</qemu:commandline>
</domain>
diff --git a/playbooks/roles/gen_nodes/templates/guestfs_virt.j2.xml b/playbooks/roles/gen_nodes/templates/guestfs_virt.j2.xml
index 1061f2c..29818ea 100644
--- a/playbooks/roles/gen_nodes/templates/guestfs_virt.j2.xml
+++ b/playbooks/roles/gen_nodes/templates/guestfs_virt.j2.xml
@@ -173,6 +173,10 @@
<qemu:arg value='ICH9-LPC.disable_s4=0'/>
<qemu:arg value='-device'/>
<qemu:arg value='pxb-pcie,id=pcie.1,bus_nr=32,bus=pcie.0,addr=0x8'/>
+ {% if libvirt_enable_gdb %}
+ <qemu:arg value='-gdb'/>
+ <qemu:arg value='tcp::{{ libvirt_gdb_baseport + idx}}'/>
+ {% endif %}
{% include './templates/gen_drives.j2' %}
</qemu:commandline>
</domain>
diff --git a/scripts/get_gdb_base_port.sh b/scripts/get_gdb_base_port.sh
new file mode 100755
index 0000000..66f987c
--- /dev/null
+++ b/scripts/get_gdb_base_port.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# This script is used to get the base port for gdbserver
+
+# get the sha1sum of the script
+
+base_md5sum=$(md5sum "$0" | awk '{print $1}')
+digits_only=$(echo $base_md5sum | tr -cd '0-9')
+
+# extract the last 4 digits from md5sum
+
+base_port=${digits_only: -4}
+echo $base_port
--
2.47.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] gen_node: add debugger support for guestfs libvirt guests
2025-04-24 16:58 [PATCH] gen_node: add debugger support for guestfs libvirt guests Swarna Prabhu
@ 2025-04-24 17:28 ` Luis Chamberlain
0 siblings, 0 replies; 2+ messages in thread
From: Luis Chamberlain @ 2025-04-24 17:28 UTC (permalink / raw)
To: Swarna Prabhu; +Cc: kdevops, da.gomez, Swarna Prabhu
Nice!
On Thu, Apr 24, 2025 at 04:58:09PM +0000, Swarna Prabhu wrote:
> +config LIBVIRT_ENABLE_GDB
> + bool "Enable GDB debugging for the guest"
> + output yaml
> +- name: Find if port conflict occur
> + ansible.builtin.shell: "ss -ltn | grep ':{{ (libvirt_gdb_baseport | int) + (idx | int) }} '"
> + register: gdb_port_reg
> + failed_when: false
> + changed_when: false
> + loop: "{{ guestfs_nodes }}"
> + loop_control:
> + index_var: idx
> + when:
> + - kdevops_enable_guestfs|bool
This needs to be:
when:
- libvirt_enable_gdb|bool
- kdevops_enable_guestfs|bool
> +
> +- name: Set the conflict flag on if conflict occur
> + set_fact:
> + gdb_port_conflict: True
> + when: >
> + gdb_port_reg.results is defined and
> + gdb_port_reg.results | selectattr('rc', 'equalto', 0) | list | length > 0
Same here and we need to use a flat entry per line so
when:
- libvirt_enable_gdb|bool
- gdb_port_reg.results is defined
- gdb_port_reg.results | selectattr('rc', 'equalto', 0) | list | length > 0
> +- name: Fail bringup if gdb port conflict occur
> + fail:
> + msg: "GDB port conflict occur, please check the base port number {{ libvirt_gdb_baseport }} and try with another"
> + when: gdb_port_conflict|bool
And here.
I made those small changes to your patch and pushed to the test throw
away kdevops tree, kdevops-kpd, which let's us trigger tests on both
containers and bare metal. The results are ephemeral, in that we can
ignore these tests for production. The test has been scheduled:
https://github.com/linux-kdevops/kdevops-kpd/actions/runs/14647807925
If that passes then I'll merge this! Thanks!
Luis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-24 17:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-24 16:58 [PATCH] gen_node: add debugger support for guestfs libvirt guests Swarna Prabhu
2025-04-24 17:28 ` Luis Chamberlain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox