Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions kconfigs/Kconfig.libvirt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions playbooks/roles/gen_nodes/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions playbooks/roles/gen_nodes/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
4 changes: 4 additions & 0 deletions playbooks/roles/gen_nodes/templates/guestfs_virt.j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
13 changes: 13 additions & 0 deletions scripts/get_gdb_base_port.sh
Original file line number Diff line number Diff line change
@@ -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