<commit_before><domain type="xen">
    {% block basic %}
        <name>{{ vm.name }}</name>
        <uuid>{{ vm.uuid }}</uuid>
        {% if ((vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list)
            or vm.maxmem == 0) -%}
            <memory unit="MiB">{{ vm.memory }}</memory>
        {% else -%}
            <memory unit="MiB">{{ vm.maxmem }}</memory>
        {% endif -%}
        <currentMemory unit="MiB">{{ vm.memory }}</currentMemory>
        <vcpu placement="static">{{ vm.vcpus }}</vcpu>
    {% endblock %}
    {% block cpu %}
    {% if vm.virt_mode != 'pv' %}
        <cpu mode='host-passthrough'>
            <!-- disable nested HVM -->
            <feature name='vmx' policy='disable'/>
            <feature name='svm' policy='disable'/>
            {% if vm.app.host.cpu_family_model in [(6, 58), (6, 62)] -%}
                <feature name='rdrand' policy='disable'/>
            {% endif -%}
        </cpu>
    {% endif %}
    {% endblock %}
    <os>
        {% block os %}
            {% if vm.virt_mode == 'hvm' %}
                <type arch="x86_64" machine="xenfv">hvm</type>
                <!--
                     For the libxl backend libvirt switches between OVMF (UEFI)
                     and SeaBIOS based on the loader type. This has nothing to
                     do with the hvmloader binary.
                -->
                <loader type="{{ "pflash" if vm.features.check_with_template('uefi', False) else "rom" }}">hvmloader</loader>
                <boot dev="cdrom" />
                <boot dev="hd" />
            {% else %}
                {% if vm.virt_mode == 'pvh' %}
                    <type arch="x86_64" machine="xenpvh">xenpvh</type>
                {% else %}
                    <type arch="x86_64" machine="xenpv">linux</type>
                {% endif %}
                <kernel>{{ vm.storage.kernels_dir }}/vmlinuz</kernel>
                <initrd>{{ vm.storage.kernels_dir }}/initramfs</initrd>
            {% endif %}
            {% if vm.kernel %}
                {% if vm.features.check_with_template('no-default-kernelopts', False) -%}
                <cmdline>{{ vm.kernelopts }}</cmdline>
                {% elif vm.features.check_with_template('apparmor', '0') == '1' -%}
                <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }} apparmor=1 security=apparmor</cmdline>
                {% else -%}
                <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}</cmdline>
                {% endif -%}
            {% endif %}
        {% endblock %}
    </os>

    <features>
        {% block features %}
            {% if vm.virt_mode != 'pv' %}
                <pae/>
                <acpi/>
                <apic/>
                <viridian/>
            {% endif %}

            {% if vm.devices['pci'].persistent() | list
                    and vm.features.get('pci-e820-host', True) %}
                <xen>
                    <e820_host state="on"/>
                </xen>
            {% endif %}
        {% endblock %}
    </features>

    {% block clock %}
        {% if vm.virt_mode == 'hvm' %}
            {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
            {% if timezone == 'localtime' %}
                <clock offset="variable" adjustment="0" basis="localtime" />
            {% elif timezone.isdigit() %}
                <clock offset="variable" adjustment="{{ timezone }}" basis="utc" />
            {% else %}
                <clock offset="variable" adjustment="0" basis="utc" />
            {% endif %}
        {% else %}
            <clock offset='utc' adjustment='reset'>
                <timer name="tsc" mode="native"/>
            </clock>
        {% endif %}
    {% endblock %}

    {% block on %}
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>destroy</on_reboot>
        <on_crash>destroy</on_crash>
    {% endblock %}

    <devices>
        {% block devices %}
            {#
                HACK: The letter counter is implemented in this way because
                Jinja does not allow you to increment variables in a loop
                anymore. As of Jinja 2.10, we will be able to replace this
                with:
                {% set counter = namespace(i=0) %}
                {% set counter.i = counter.i + 1 %}
            #}
            {% set counter = {'i': 0} %}
            {# TODO Allow more volumes out of the box #}
            {% set dd = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y']
            %}
            {% for device in vm.block_devices %}
                <disk type="block" device="{{ device.devtype }}">
                    <driver name="phy" />
                    <source dev="{{ device.path }}" />
                    {% if device.name == 'root' %}
                        <target dev="xvda" />
                    {% elif device.name == 'private' %}
                        <target dev="xvdb" />
                    {% elif device.name == 'volatile' %}
                        <target dev="xvdc" />
                    {% elif device.name == 'kernel' %}
                        <target dev="xvdd" />
                    {% else %}
                        <target dev="xvd{{dd[counter.i]}}" />
                        {% if counter.update({'i': counter.i + 1}) %}{% endif %}
                    {% endif %}

                    {% if not device.rw %}
                        <readonly />
                    {% endif %}

                    {% if device.domain %}
                        <backenddomain name="{{ device.domain }}" />
                    {% endif %}

                    {% if device.script %}
                        <script path="{{ device.script }}" />
                    {% endif %}
                </disk>
            {% endfor %}

            {# start external devices from xvdi #}
            {% set counter = {'i': 4} %}
            {% for assignment in vm.devices.block.assignments(True) %}
                {% set device = assignment.device %}
                {% set options = assignment.options %}
                {% include 'libvirt/devices/block.xml' %}
            {% endfor %}

            {% if vm.netvm %}
                {% include 'libvirt/devices/net.xml' with context %}
            {% endif %}

            {% for assignment in vm.devices.pci.assignments(True) %}
                {% set device = assignment.device %}
                {% set options = assignment.options %}
                {% include 'libvirt/devices/pci.xml' %}
            {% endfor %}

            {% if vm.virt_mode == 'hvm' %}
                <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
                <emulator
                    {% if vm.features.check_with_template('linux-stubdom', True) %}
                        type="stubdom-linux"
                    {% else %}
                        type="stubdom"
                    {% endif %}
                    {% if vm.netvm %}
                      {% if vm.features.check_with_template('linux-stubdom', True) %}
                        cmdline="-qubes-net:client_ip={{ vm.ip -}}
                            ,dns_0={{ vm.dns[0] -}}
                            ,dns_1={{ vm.dns[1] -}}
                            ,gw={{ vm.netvm.gateway -}}
                            ,netmask={{ vm.netmask }}"
                      {% else %}
                        cmdline="-net lwip,client_ip={{ vm.ip -}}
                            ,server_ip={{ vm.dns[1] -}}
                            ,dns={{ vm.dns[0] -}}
                            ,gw={{ vm.netvm.gateway -}}
                            ,netmask={{ vm.netmask }}"
                      {% endif %}
                    {% endif %}
                    {% if vm.stubdom_mem %}
                        memory="{{ vm.stubdom_mem * 1024 -}}"
                    {% endif %}
                    />
                <input type="tablet" bus="usb"/>
                {% if vm.features.check_with_template('audio-model', False) %}
                    <sound model="{{ vm.features.check_with_template('audio-model', False) }}"/>
                {% endif %}
                {% if vm.features.check_with_template('video-model', 'vga') != 'none' %}
                    <video>
                        <model type="{{ vm.features.check_with_template('video-model', 'vga') }}"/>
                    </video>
                    {% if vm.features.check_with_template('linux-stubdom', True) %}
                        {# TODO only add qubes gui if gui-agent is not installed in HVM #}
                        <graphics type="qubes"/>
                    {% endif %}
                {% endif %}
            {% endif %}
                <console type="pty">
                    <target type="xen" port="0"/>
                </console>
        {% endblock %}
    </devices>
</domain>

<!-- vim: set ft=jinja ts=4 sts=4 sw=4 et tw=80 : --><commit_msg>winusb: Replace minimal stubomain' kernel and ramdisk<commit_after><domain type="xen">
    {% block basic %}
        <name>{{ vm.name }}</name>
        <uuid>{{ vm.uuid }}</uuid>
        {% if ((vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list)
            or vm.maxmem == 0) -%}
            <memory unit="MiB">{{ vm.memory }}</memory>
        {% else -%}
            <memory unit="MiB">{{ vm.maxmem }}</memory>
        {% endif -%}
        <currentMemory unit="MiB">{{ vm.memory }}</currentMemory>
        <vcpu placement="static">{{ vm.vcpus }}</vcpu>
    {% endblock %}
    {% block cpu %}
    {% if vm.virt_mode != 'pv' %}
        <cpu mode='host-passthrough'>
            <!-- disable nested HVM -->
            <feature name='vmx' policy='disable'/>
            <feature name='svm' policy='disable'/>
            {% if vm.app.host.cpu_family_model in [(6, 58), (6, 62)] -%}
                <feature name='rdrand' policy='disable'/>
            {% endif -%}
        </cpu>
    {% endif %}
    {% endblock %}
    <os>
        {% block os %}
            {% if vm.virt_mode == 'hvm' %}
                <type arch="x86_64" machine="xenfv">hvm</type>
                <!--
                     For the libxl backend libvirt switches between OVMF (UEFI)
                     and SeaBIOS based on the loader type. This has nothing to
                     do with the hvmloader binary.
                -->
                <loader type="{{ "pflash" if vm.features.check_with_template('uefi', False) else "rom" }}">hvmloader</loader>
                <boot dev="cdrom" />
                <boot dev="hd" />
            {% else %}
                {% if vm.virt_mode == 'pvh' %}
                    <type arch="x86_64" machine="xenpvh">xenpvh</type>
                {% else %}
                    <type arch="x86_64" machine="xenpv">linux</type>
                {% endif %}
                <kernel>{{ vm.storage.kernels_dir }}/vmlinuz</kernel>
                <initrd>{{ vm.storage.kernels_dir }}/initramfs</initrd>
            {% endif %}
            {% if vm.kernel %}
                {% if vm.features.check_with_template('no-default-kernelopts', False) -%}
                <cmdline>{{ vm.kernelopts }}</cmdline>
                {% elif vm.features.check_with_template('apparmor', '0') == '1' -%}
                <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }} apparmor=1 security=apparmor</cmdline>
                {% else -%}
                <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}</cmdline>
                {% endif -%}
            {% endif %}
        {% endblock %}
    </os>

    <features>
        {% block features %}
            {% if vm.virt_mode != 'pv' %}
                <pae/>
                <acpi/>
                <apic/>
                <viridian/>
            {% endif %}

            {% if vm.devices['pci'].persistent() | list
                    and vm.features.get('pci-e820-host', True) %}
                <xen>
                    <e820_host state="on"/>
                </xen>
            {% endif %}
        {% endblock %}
    </features>

    {% block clock %}
        {% if vm.virt_mode == 'hvm' %}
            {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
            {% if timezone == 'localtime' %}
                <clock offset="variable" adjustment="0" basis="localtime" />
            {% elif timezone.isdigit() %}
                <clock offset="variable" adjustment="{{ timezone }}" basis="utc" />
            {% else %}
                <clock offset="variable" adjustment="0" basis="utc" />
            {% endif %}
        {% else %}
            <clock offset='utc' adjustment='reset'>
                <timer name="tsc" mode="native"/>
            </clock>
        {% endif %}
    {% endblock %}

    {% block on %}
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>destroy</on_reboot>
        <on_crash>destroy</on_crash>
    {% endblock %}

    <devices>
        {% block devices %}
            {#
                HACK: The letter counter is implemented in this way because
                Jinja does not allow you to increment variables in a loop
                anymore. As of Jinja 2.10, we will be able to replace this
                with:
                {% set counter = namespace(i=0) %}
                {% set counter.i = counter.i + 1 %}
            #}
            {% set counter = {'i': 0} %}
            {# TODO Allow more volumes out of the box #}
            {% set dd = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y']
            %}
            {% for device in vm.block_devices %}
                <disk type="block" device="{{ device.devtype }}">
                    <driver name="phy" />
                    <source dev="{{ device.path }}" />
                    {% if device.name == 'root' %}
                        <target dev="xvda" />
                    {% elif device.name == 'private' %}
                        <target dev="xvdb" />
                    {% elif device.name == 'volatile' %}
                        <target dev="xvdc" />
                    {% elif device.name == 'kernel' %}
                        <target dev="xvdd" />
                    {% else %}
                        <target dev="xvd{{dd[counter.i]}}" />
                        {% if counter.update({'i': counter.i + 1}) %}{% endif %}
                    {% endif %}

                    {% if not device.rw %}
                        <readonly />
                    {% endif %}

                    {% if device.domain %}
                        <backenddomain name="{{ device.domain }}" />
                    {% endif %}

                    {% if device.script %}
                        <script path="{{ device.script }}" />
                    {% endif %}
                </disk>
            {% endfor %}

            {# start external devices from xvdi #}
            {% set counter = {'i': 4} %}
            {% for assignment in vm.devices.block.assignments(True) %}
                {% set device = assignment.device %}
                {% set options = assignment.options %}
                {% include 'libvirt/devices/block.xml' %}
            {% endfor %}

            {% if vm.netvm %}
                {% include 'libvirt/devices/net.xml' with context %}
            {% endif %}

            {% for assignment in vm.devices.pci.assignments(True) %}
                {% set device = assignment.device %}
                {% set options = assignment.options %}
                {% include 'libvirt/devices/pci.xml' %}
            {% endfor %}

            {% if vm.virt_mode == 'hvm' %}
                <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
                <emulator
                    {% if vm.features.check_with_template('linux-stubdom', True) %}
                        type="stubdom-linux"
                    {% else %}
                        type="stubdom"
                    {% endif %}
                    {% if vm.netvm %}
                      {% if vm.features.check_with_template('linux-stubdom', True) %}
                        cmdline="-qubes-net:client_ip={{ vm.ip -}}
                            ,dns_0={{ vm.dns[0] -}}
                            ,dns_1={{ vm.dns[1] -}}
                            ,gw={{ vm.netvm.gateway -}}
                            ,netmask={{ vm.netmask }}"
                      {% else %}
                        cmdline="-net lwip,client_ip={{ vm.ip -}}
                            ,server_ip={{ vm.dns[1] -}}
                            ,dns={{ vm.dns[0] -}}
                            ,gw={{ vm.netvm.gateway -}}
                            ,netmask={{ vm.netmask }}"
                      {% endif %}
                    {% endif %}
                    {% if vm.stubdom_mem %}
                        memory="{{ vm.stubdom_mem * 1024 -}}"
                    {% endif %}
                    {% if vm.features.check_with_template('audio-model', False)
                    or vm.features.check_with_template('stubdom_qrexec', False) %}
                        kernel="/usr/libexec/xen/boot/qemu-stubdom-linux-full-kernel"
                        ramdisk="/usr/libexec/xen/boot/qemu-stubdom-linux-full-rootfs"
                    {% endif %}
                    />
                <input type="tablet" bus="usb"/>
                {% if vm.features.check_with_template('audio-model', False) %}
                    <sound model="{{ vm.features.check_with_template('audio-model', False) }}"/>
                {% endif %}
                {% if vm.features.check_with_template('video-model', 'vga') != 'none' %}
                    <video>
                        <model type="{{ vm.features.check_with_template('video-model', 'vga') }}"/>
                    </video>
                    {% if vm.features.check_with_template('linux-stubdom', True) %}
                        {# TODO only add qubes gui if gui-agent is not installed in HVM #}
                        <graphics type="qubes"/>
                    {% endif %}
                {% endif %}
            {% endif %}
                <console type="pty">
                    <target type="xen" port="0"/>
                </console>
        {% endblock %}
    </devices>
</domain>

<!-- vim: set ft=jinja ts=4 sts=4 sw=4 et tw=80 : -->
{'fraction_non_alphanumeric': 0.15945739812595336, 'fraction_numerical': 0.005883634778818915, 'mean_word_length': 1.228602646594634, 'pattern_counts': {'":': 0, '<': 183, '<?xml version=': 0, '>': 183, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6687188', 'n_tokens_mistral': 5629, 'n_tokens_neox': 4907, 'n_words': 1069}