xen.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <domain type="xen">
  2. {% block basic %}
  3. <name>{{ vm.name }}</name>
  4. <uuid>{{ vm.uuid }}</uuid>
  5. {% if ((vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list)
  6. or vm.maxmem == 0) -%}
  7. <memory unit="MiB">{{ vm.memory }}</memory>
  8. {% else -%}
  9. <memory unit="MiB">{{ vm.maxmem }}</memory>
  10. {% endif -%}
  11. <currentMemory unit="MiB">{{ vm.memory }}</currentMemory>
  12. <vcpu placement="static">{{ vm.vcpus }}</vcpu>
  13. {% endblock %}
  14. {% block cpu %}
  15. {% if vm.virt_mode != 'pv' %}
  16. <cpu mode='host-passthrough'>
  17. <!-- disable nested HVM -->
  18. <feature name='vmx' policy='disable'/>
  19. <feature name='svm' policy='disable'/>
  20. <!-- disable SMAP inside VM, because of Linux bug -->
  21. <feature name='smap' policy='disable'/>
  22. {% if vm.app.host.cpu_family_model in [(6, 58), (6, 62)] -%}
  23. <feature name='rdrand' policy='disable'/>
  24. {% endif -%}
  25. </cpu>
  26. {% endif %}
  27. {% endblock %}
  28. <os>
  29. {% block os %}
  30. {% if vm.virt_mode == 'hvm' %}
  31. <type arch="x86_64" machine="xenfv">hvm</type>
  32. <!--
  33. For the libxl backend libvirt switches between OVMF (UEFI)
  34. and SeaBIOS based on the loader type. This has nothing to
  35. do with the hvmloader binary.
  36. -->
  37. <loader type="{{ "pflash" if vm.features.check_with_template('uefi', False) else "rom" }}">hvmloader</loader>
  38. <boot dev="cdrom" />
  39. <boot dev="hd" />
  40. {% else %}
  41. {% if vm.virt_mode == 'pvh' %}
  42. <type arch="x86_64" machine="xenpvh">xenpvh</type>
  43. {% else %}
  44. <type arch="x86_64" machine="xenpv">linux</type>
  45. {% endif %}
  46. <kernel>{{ vm.storage.kernels_dir }}/vmlinuz</kernel>
  47. <initrd>{{ vm.storage.kernels_dir }}/initramfs</initrd>
  48. {% endif %}
  49. {% if vm.kernel %}
  50. {% if vm.features.check_with_template('no-default-kernelopts', False) -%}
  51. <cmdline>{{ vm.kernelopts }}</cmdline>
  52. {% else -%}
  53. <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}</cmdline>
  54. {% endif -%}
  55. {% endif %}
  56. {% endblock %}
  57. </os>
  58. <features>
  59. {% block features %}
  60. {% if vm.virt_mode != 'pv' %}
  61. <pae/>
  62. <acpi/>
  63. <apic/>
  64. <viridian/>
  65. {% endif %}
  66. <xen>
  67. {% if vm.devices['pci'].persistent() | list
  68. and vm.features.get('pci-e820-host', True) %}
  69. <e820_host state="on"/>
  70. {% endif %}
  71. {% if vm.features.check_with_template('gfx-passthru', False) %}
  72. <gfx_passthru state="on"/>
  73. {% endif %}
  74. </xen>
  75. {% endblock %}
  76. </features>
  77. {% block clock %}
  78. {% if vm.virt_mode == 'hvm' %}
  79. {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
  80. {% if timezone == 'localtime' %}
  81. <clock offset="variable" adjustment="0" basis="localtime" />
  82. {% elif timezone.isdigit() %}
  83. <clock offset="variable" adjustment="{{ timezone }}" basis="utc" />
  84. {% else %}
  85. <clock offset="variable" adjustment="0" basis="utc" />
  86. {% endif %}
  87. {% else %}
  88. <clock offset='utc' adjustment='reset'>
  89. <timer name="tsc" mode="native"/>
  90. </clock>
  91. {% endif %}
  92. {% endblock %}
  93. {% block on %}
  94. <on_poweroff>destroy</on_poweroff>
  95. <on_reboot>destroy</on_reboot>
  96. <on_crash>destroy</on_crash>
  97. {% endblock %}
  98. <devices>
  99. {% block devices %}
  100. {#
  101. HACK: The letter counter is implemented in this way because
  102. Jinja does not allow you to increment variables in a loop
  103. anymore. As of Jinja 2.10, we will be able to replace this
  104. with:
  105. {% set counter = namespace(i=0) %}
  106. {% set counter.i = counter.i + 1 %}
  107. #}
  108. {% set counter = {'i': 0} %}
  109. {# TODO Allow more volumes out of the box #}
  110. {% set dd = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  111. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y']
  112. %}
  113. {% for device in vm.block_devices %}
  114. <disk type="block" device="{{ device.devtype }}">
  115. <driver name="phy" />
  116. <source dev="{{ device.path }}" />
  117. {% if device.name == 'root' %}
  118. <target dev="xvda" />
  119. {% elif device.name == 'private' %}
  120. <target dev="xvdb" />
  121. {% elif device.name == 'volatile' %}
  122. <target dev="xvdc" />
  123. {% elif device.name == 'kernel' %}
  124. <target dev="xvdd" />
  125. {% else %}
  126. <target dev="xvd{{dd[counter.i]}}" />
  127. {% if counter.update({'i': counter.i + 1}) %}{% endif %}
  128. {% endif %}
  129. {% if not device.rw %}
  130. <readonly />
  131. {% endif %}
  132. {% if device.domain %}
  133. <backenddomain name="{{ device.domain }}" />
  134. {% endif %}
  135. {% if device.script %}
  136. <script path="{{ device.script }}" />
  137. {% endif %}
  138. </disk>
  139. {% endfor %}
  140. {# start external devices from xvdi #}
  141. {% set counter = {'i': 4} %}
  142. {% for assignment in vm.devices.block.assignments(True) %}
  143. {% set device = assignment.device %}
  144. {% set options = assignment.options %}
  145. {% include 'libvirt/devices/block.xml' %}
  146. {% endfor %}
  147. {% if vm.netvm %}
  148. {% include 'libvirt/devices/net.xml' with context %}
  149. {% endif %}
  150. {% for assignment in vm.devices.pci.assignments(True) %}
  151. {% set device = assignment.device %}
  152. {% set options = assignment.options %}
  153. {% include 'libvirt/devices/pci.xml' %}
  154. {% endfor %}
  155. {% if vm.virt_mode == 'hvm' %}
  156. <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
  157. <emulator
  158. {% if vm.features.check_with_template('linux-stubdom', True) %}
  159. type="stubdom-linux"
  160. {% else %}
  161. type="stubdom"
  162. {% endif %}
  163. {% if vm.netvm %}
  164. {% if vm.features.check_with_template('linux-stubdom', True) %}
  165. cmdline="-qubes-net:client_ip={{ vm.ip -}}
  166. ,dns_0={{ vm.dns[0] -}}
  167. ,dns_1={{ vm.dns[1] -}}
  168. ,gw={{ vm.netvm.gateway -}}
  169. ,netmask={{ vm.netmask }}"
  170. {% else %}
  171. cmdline="-net lwip,client_ip={{ vm.ip -}}
  172. ,server_ip={{ vm.dns[1] -}}
  173. ,dns={{ vm.dns[0] -}}
  174. ,gw={{ vm.netvm.gateway -}}
  175. ,netmask={{ vm.netmask }}"
  176. {% endif %}
  177. {% endif %}
  178. {% if vm.stubdom_mem %}
  179. memory="{{ vm.stubdom_mem * 1024 -}}"
  180. {% endif %}
  181. />
  182. <input type="tablet" bus="usb"/>
  183. {% if vm.features.check_with_template('video-model', 'vga') != 'none' %}
  184. <video>
  185. <model type="{{ vm.features.check_with_template('video-model', 'vga') }}"/>
  186. </video>
  187. {% if vm.features.check_with_template('linux-stubdom', True) %}
  188. {# TODO only add qubes gui if gui-agent is not installed in HVM #}
  189. <graphics type="qubes"/>
  190. {% endif %}
  191. {% endif %}
  192. {% endif %}
  193. <console type="pty">
  194. <target type="xen" port="0"/>
  195. </console>
  196. {% endblock %}
  197. </devices>
  198. </domain>
  199. <!-- vim: set ft=jinja ts=4 sts=4 sw=4 et tw=80 : -->