dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

XSLT for virtio-fs #990

Open polhaghverdian opened 1 year ago

polhaghverdian commented 1 year ago
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="node()|@*">
      <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
   </xsl:template>

  <xsl:template match="/domain">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
            <xsl:element name ="memoryBacking">
                <xsl:element name="source">
                    <xsl:attribute name="type">memfd</xsl:attribute>
                </xsl:element>
                <xsl:element name="access">
                    <xsl:attribute name="mode">shared</xsl:attribute>
                </xsl:element>
            </xsl:element>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="/domain/devices">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
            <xsl:element name ="filesystem">
                <xsl:attribute name="type">mount</xsl:attribute>
                <xsl:attribute name="accessmode">passthrough</xsl:attribute>
                <xsl:element name="driver">
                    <xsl:attribute name="type">virtiofs</xsl:attribute>
                </xsl:element>
                <xsl:element name="source">
                    <xsl:attribute name="dir">/directory/shared/with/guest</xsl:attribute>
                </xsl:element>
                <xsl:element name="target">
                    <xsl:attribute name="dir">shared-from-host</xsl:attribute>
                </xsl:element>
                <xsl:element name="address">
                    <xsl:attribute name="type">pci</xsl:attribute>
                    <xsl:attribute name="domain">0x0000</xsl:attribute>
                    <xsl:attribute name="bus">0x07</xsl:attribute>
                    <xsl:attribute name="slot">0x01</xsl:attribute>
                    <xsl:attribute name="function">0x0</xsl:attribute>
                </xsl:element>
            </xsl:element>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
polhaghverdian commented 1 year ago

I wanted to put this out here if anyone wants to use Virtio-fs instead of virtio-9p.

dmacvicar commented 1 year ago

I'd like to make sure this works out of the box. Can you enlighten me what does the XSLT fix?

The provider supports the filesystem option. Is is just about the default driver?

polhaghverdian commented 1 year ago

@dmacvicar As far as I know, the provider has no support for Virtio-fs. So the only option is virtio-9p when you want to share a directory between libvirt host and guest. That's why I created this XSLT.

Of course, you still need to edit the attribute in the source element to whatever directory you want to pass to the guest and perhaps the target element attribute if you don't like the name "shared-from-host."

                <xsl:element name="source">
                    <xsl:attribute name="dir">**/directory/shared/with/guest**</xsl:attribute>
                </xsl:element>
                <xsl:element name="target">
                    <xsl:attribute name="dir">**shared-from-host**</xsl:attribute>
                </xsl:element>