From: Luis Chamberlain <mcgrof@kernel.org>
To: kdevops@lists.linux.dev
Cc: Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 4/5] gen_nodes: move drive generation for guestfs to macros
Date: Wed, 6 Mar 2024 16:14:25 -0800 [thread overview]
Message-ID: <20240307001426.565390-5-mcgrof@kernel.org> (raw)
In-Reply-To: <20240307001426.565390-1-mcgrof@kernel.org>
Make the guestfs template easier to read by using macros for
the different types of drive generation methods. This will also
let us scale this to more easily support other architectures with
as much shared code as possible later.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
playbooks/roles/gen_nodes/templates/drives.j2 | 76 +++++++++++++++++++
.../gen_nodes/templates/guestfs_q35.j2.xml | 59 +++++++-------
2 files changed, 104 insertions(+), 31 deletions(-)
create mode 100644 playbooks/roles/gen_nodes/templates/drives.j2
diff --git a/playbooks/roles/gen_nodes/templates/drives.j2 b/playbooks/roles/gen_nodes/templates/drives.j2
new file mode 100644
index 00000000..4878cff9
--- /dev/null
+++ b/playbooks/roles/gen_nodes/templates/drives.j2
@@ -0,0 +1,76 @@
+{#
+This is a collection of macros to generate extra drives used by guestfs,
+the drives can vary by type, so we have one macro by type of drive.
+#}
+{%- macro gen_drive_ide(num_drives,
+ kdevops_storage_pool_path,
+ hostname,
+ libvirt_extra_drive_format,
+ libvirt_extra_storage_aio_mode,
+ libvirt_extra_storage_aio_cache_mode) -%}
+<!-- We generated {{ num_drives }} ide dives -->
+{% for n in range(0,num_drives) %}
+ <!-- This is IDE drive # {{ n + 1 }} -->
+ <qemu:arg value='-drive'/>
+ <qemu:arg value='file={{ kdevops_storage_pool_path }}/guestfs/{{ hostname }}/extra{{ n }}.{{ libvirt_extra_drive_format }},format={{ libvirt_extra_drive_format }},aio={{ libvirt_extra_storage_aio_mode }},cache={{ libvirt_extra_storage_aio_cache_mode }},if=none,id=drv{{ n }}'/>
+ <qemu:arg value='-device'/>
+ <qemu:arg value="ide-hd,drive=drv{{ n }},bus=ide.{{ n }},serial=kdevops{{ n }}"/>
+{% endfor %}
+<!-- End of ide drives-->
+{%- endmacro -%}
+{%- macro gen_drive_virtio(num_drives,
+ kdevops_storage_pool_path,
+ hostname,
+ libvirt_extra_drive_format,
+ libvirt_extra_storage_aio_mode,
+ libvirt_extra_storage_aio_cache_mode,
+ libvirt_extra_storage_virtio_logical_block_size,
+ libvirt_extra_storage_virtio_physical_block_size) -%}
+<!-- We generated {{ num_drives }} virtio dives -->
+{% for n in range(0,num_drives) %}
+ <!-- This is virtio drive # {{ n + 1 }} -->
+ <qemu:arg value='-device'/>
+ <qemu:arg value='pcie-root-port,id=pcie-port-for-virtio-{{ n }},multifunction=on,bus=pcie.1,addr=0x{{ "%0x" | format( n | int) }},chassis=5{{ n }}'/>
+ <qemu:arg value="-object"/>
+ <qemu:arg value="iothread,id=kdevops-virtio-iothread-{{ n }}"/>
+ <qemu:arg value="-drive"/>
+ <qemu:arg value="file={{ kdevops_storage_pool_path }}/guestfs/{{ hostname }}/extra{{ n }}.{{ libvirt_extra_drive_format }},format={{ libvirt_extra_drive_format }},if=none,aio={{ libvirt_extra_storage_aio_mode }},cache={{ libvirt_extra_storage_aio_cache_mode }},id=drv{{ n }}"/>
+ <qemu:arg value="-device"/>
+ <qemu:arg value="virtio-blk-pci,scsi=off,drive=drv{{ n }},id=virtio-drv{{ n }},serial=kdevops{{ n }},bus=pcie-port-for-virtio-{{ n }},addr=0x0,iothread=kdevops-virtio-iothread-{{ n }},logical_block_size={{ libvirt_extra_storage_virtio_logical_block_size }},physical_block_size={{ libvirt_extra_storage_virtio_physical_block_size }}"/>
+{% endfor %}
+<!-- End of virtio drives-->
+{%- endmacro -%}
+{%- macro gen_drive_nvme(num_drives,
+ kdevops_storage_pool_path,
+ hostname,
+ libvirt_extra_drive_format,
+ libvirt_extra_storage_aio_mode,
+ libvirt_extra_storage_aio_cache_mode,
+ libvirt_extra_storage_nvme_logical_block_size) -%}
+<!-- We generated {{ num_drives }} NVMe dives -->
+{% for n in range(0,num_drives) %}
+ <!-- This is NVMe drive # {{ n + 1 }} -->
+ <qemu:arg value='-device'/>
+ <qemu:arg value='pcie-root-port,id=pcie-port-for-nvme-{{ n }},multifunction=on,bus=pcie.1,addr=0x{{ "%0x" | format( n | int) }},chassis=5{{ n }}'/>
+ <qemu:arg value='-drive'/>
+ <qemu:arg value='file={{ kdevops_storage_pool_path }}/guestfs/{{ hostname }}/extra{{ n }}.{{ libvirt_extra_drive_format }},format={{ libvirt_extra_drive_format }},if=none,id=drv{{ n }}'/>
+ <qemu:arg value='-device'/>
+ <qemu:arg value='nvme,id=nvme{{ n }},serial=kdevops{{ n }},bus=pcie-port-for-nvme-{{ n }},addr=0x0'/>
+ <qemu:arg value='-device'/>
+ <qemu:arg value='nvme-ns,drive=drv{{ n }},bus=nvme{{ n }},nsid=1,logical_block_size={{ libvirt_extra_storage_nvme_logical_block_size }},physical_block_size={{ libvirt_extra_storage_nvme_logical_block_size }}'/>
+{% endfor %}
+<!-- End of NVMe drives-->
+{%- endmacro -%}
+{% macro gen_9p_mount(bootlinux_9p_driver,
+ bootlinux_9p_fsdev,
+ bootlinux_9p_host_path,
+ bootlinux_9p_mount_tag,
+ bootlinux_9p_security_model,
+ pcie_addr) %}
+<!-- This is a 9p mounted drive -->
+ <qemu:arg value='-device'/>
+ <qemu:arg value='{{ bootlinux_9p_driver }},fsdev={{ bootlinux_9p_fsdev }},mount_tag={{ bootlinux_9p_mount_tag }},bus=pcie.0,addr=0x{{ pcie_addr }}'/>
+ <qemu:arg value='-fsdev'/>
+ <qemu:arg value='local,id={{ bootlinux_9p_fsdev }},path={{ bootlinux_9p_host_path }},security_model={{ bootlinux_9p_security_model }}'/>
+<!-- End of 9p mount -->
+{% endmacro %}
diff --git a/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml b/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
index 266ced32..16364ea2 100644
--- a/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
+++ b/playbooks/roles/gen_nodes/templates/guestfs_q35.j2.xml
@@ -1,3 +1,4 @@
+{% import './templates/drives.j2' as drives %}
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>{{ hostname }}</name>
<memory unit='MiB'>{{ libvirt_mem_mb }}</memory>
@@ -178,41 +179,37 @@
<qemu:arg value='-device'/>
<qemu:arg value='pxb-pcie,id=pcie.1,bus_nr=32,bus=pcie.0,addr=0x8'/>
{% if libvirt_extra_storage_drive_ide %}
-{% for n in range(0,4) %}
- <qemu:arg value='-drive'/>
- <qemu:arg value='file={{ kdevops_storage_pool_path }}/guestfs/{{ hostname }}/extra{{ n }}.{{ libvirt_extra_drive_format }},format={{ libvirt_extra_drive_format }},aio={{ libvirt_extra_storage_aio_mode }},cache={{ libvirt_extra_storage_aio_cache_mode }},if=none,id=drv{{ n }}'/>
- <qemu:arg value='-device'/>
- <qemu:arg value="ide-hd,drive=drv{{ n }},bus=ide.{{ n }},serial=kdevops{{ n }}"/>
-{% endfor %}
+{{ drives.gen_drive_ide(4,
+ kdevops_storage_pool_path,
+ hostname,
+ libvirt_extra_drive_format,
+ libvirt_extra_storage_aio_mode,
+ libvirt_extra_storage_aio_cache_mode) }}
{% elif libvirt_extra_storage_drive_virtio %}
-{% for n in range(0,4) %}
- <qemu:arg value='-device'/>
- <qemu:arg value='pcie-root-port,id=pcie-port-for-virtio-{{ n }},multifunction=on,bus=pcie.1,addr=0x{{ "%0x" | format( n | int) }},chassis=5{{ n }}'/>
- <qemu:arg value="-object"/>
- <qemu:arg value="iothread,id=kdevops-virtio-iothread-{{ n }}"/>
- <qemu:arg value="-drive"/>
- <qemu:arg value="file={{ kdevops_storage_pool_path }}/guestfs/{{ hostname }}/extra{{ n }}.{{ libvirt_extra_drive_format }},format={{ libvirt_extra_drive_format }},if=none,aio={{ libvirt_extra_storage_aio_mode }},cache={{ libvirt_extra_storage_aio_cache_mode }},id=drv{{ n }}"/>
- <qemu:arg value="-device"/>
- <qemu:arg value="virtio-blk-pci,scsi=off,drive=drv{{ n }},id=virtio-drv{{ n }},serial=kdevops{{ n }},bus=pcie-port-for-virtio-{{ n }},addr=0x0,iothread=kdevops-virtio-iothread-{{ n }},logical_block_size={{ libvirt_extra_storage_virtio_logical_block_size }},physical_block_size={{ libvirt_extra_storage_virtio_physical_block_size }}"/>
-{% endfor %}
+{{ drives.gen_drive_virtio(4,
+ kdevops_storage_pool_path,
+ hostname,
+ libvirt_extra_drive_format,
+ libvirt_extra_storage_aio_mode,
+ libvirt_extra_storage_aio_cache_mode,
+ libvirt_extra_storage_virtio_logical_block_size,
+ libvirt_extra_storage_virtio_physical_block_size) }}
{% elif libvirt_extra_storage_drive_nvme %}
-{% for n in range(0,4) %}
- <qemu:arg value='-device'/>
- <qemu:arg value='pcie-root-port,id=pcie-port-for-nvme-{{ n }},multifunction=on,bus=pcie.1,addr=0x{{ "%0x" | format( n | int) }},chassis=5{{ n }}'/>
- <qemu:arg value='-drive'/>
- <qemu:arg value='file={{ kdevops_storage_pool_path }}/guestfs/{{ hostname }}/extra{{ n }}.{{ libvirt_extra_drive_format }},format={{ libvirt_extra_drive_format }},if=none,id=drv{{ n }}'/>
- <qemu:arg value='-device'/>
- <qemu:arg value='nvme,id=nvme{{ n }},serial=kdevops{{ n }},bus=pcie-port-for-nvme-{{ n }},addr=0x0'/>
- <qemu:arg value='-device'/>
- <qemu:arg value='nvme-ns,drive=drv{{ n }},bus=nvme{{ n }},nsid=1,logical_block_size={{ libvirt_extra_storage_nvme_logical_block_size }},physical_block_size={{ libvirt_extra_storage_nvme_logical_block_size }}'/>
-{% endfor %}
+{{ drives.gen_drive_nvme(4,
+ kdevops_storage_pool_path,
+ hostname,
+ libvirt_extra_drive_format,
+ libvirt_extra_storage_aio_mode,
+ libvirt_extra_storage_aio_cache_mode,
+ libvirt_extra_storage_nvme_logical_block_size) }}
{% endif %}
{% if bootlinux_9p %}
- <qemu:arg value='-device'/>
- <qemu:arg value='{{ bootlinux_9p_driver }},fsdev={{ bootlinux_9p_fsdev }},mount_tag={{ bootlinux_9p_mount_tag }},bus=pcie.0,addr=0x10'/>
- <qemu:arg value='-fsdev'/>
- <qemu:arg value='local,id={{ bootlinux_9p_fsdev }},path={{ bootlinux_9p_host_path }},security_model={{ bootlinux_9p_security_model }}'/>
+ {{ drives.gen_9p_mount(bootlinux_9p_driver,
+ bootlinux_9p_fsdev,
+ bootlinux_9p_host_path,
+ bootlinux_9p_mount_tag,
+ bootlinux_9p_security_model,
+ 10) }}
{% endif %}
</qemu:commandline>
</domain>
-
--
2.43.0
next prev parent reply other threads:[~2024-03-07 0:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 0:14 [PATCH 0/5] guestfs: start moving guest data to macros Luis Chamberlain
2024-03-07 0:14 ` [PATCH 1/5] bringup_guestfs.sh: use bash as the default shell Luis Chamberlain
2024-03-07 0:14 ` [PATCH 2/5] guestfs_q35: use hex for pci addr Luis Chamberlain
2024-03-07 0:14 ` [PATCH 3/5] guestfs_q35: use libvirt_extra_storage_nvme_logical_block_size Luis Chamberlain
2024-03-07 0:14 ` Luis Chamberlain [this message]
2024-03-07 0:14 ` [PATCH 5/5] guestfs: add large IO support Luis Chamberlain
2024-03-07 18:43 ` [PATCH 0/5] guestfs: start moving guest data to macros Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240307001426.565390-5-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=kdevops@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox