]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: add 'fmode' and 'dmode' options
authorBrian Turek <brian.turek@gmail.com>
Thu, 8 Oct 2020 14:32:24 +0000 (15:32 +0100)
committerJán Tomko <jtomko@redhat.com>
Wed, 4 Nov 2020 17:25:55 +0000 (18:25 +0100)
Expose QEMU's 9pfs 'fmode' and 'dmode' options via attributes on the
'filesystem' node in the domain XML. These options control the creation
mode of files and directories, respectively, when using
accessmode=mapped.

Signed-off-by: Brian Turek <brian.turek@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
tests/qemuxml2argvdata/virtio-9p-createmode.xml [new file with mode: 0644]
tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c

index a62a598568ecfb49590f0ea8e1ebdc8cda18b6aa..97fa87397784565ba6d6358603f84eb8173a00cb 100644 (file)
     </element>
   </define>
 
+  <define name="createMode">
+    <data type="unsignedInt">
+      <param name="pattern">0[0-7]{3}|[0-7]{1,3}</param>
+    </data>
+  </define>
+
   <!--
       We handle only document defining a domain
     -->
             </choice>
           </attribute>
         </optional>
+        <optional>
+          <attribute name="fmode">
+            <ref name="createMode"/>
+          </attribute>
+        </optional>
+        <optional>
+          <attribute name="dmode">
+            <ref name="createMode"/>
+          </attribute>
+        </optional>
         <optional>
           <element name="readonly">
             <empty/>
index b47f43afd943023fcee7d8d9f2302986cc367c44..7696b12ef9dff2cba2d547d3e52419bb6c002ae0 100644 (file)
@@ -11476,6 +11476,8 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
     g_autofree char *units = NULL;
     g_autofree char *model = NULL;
     g_autofree char *multidevs = NULL;
+    g_autofree char *fmode = NULL;
+    g_autofree char *dmode = NULL;
 
     ctxt->node = node;
 
@@ -11504,6 +11506,26 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt,
         def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
     }
 
+    fmode = virXMLPropString(node, "fmode");
+    if (fmode) {
+        if ((virStrToLong_uip(fmode, NULL, 8, &def->fmode) < 0) ||
+            (def->fmode > 0777)) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("invalid fmode: '%s'"), fmode);
+            goto error;
+        }
+    }
+
+    dmode = virXMLPropString(node, "dmode");
+    if (dmode) {
+        if ((virStrToLong_uip(dmode, NULL, 8, &def->dmode) < 0) ||
+            (def->dmode > 0777)) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("invalid dmode: '%s'"), dmode);
+            goto error;
+        }
+    }
+
     model = virXMLPropString(node, "model");
     if (model) {
         if ((def->model = virDomainFSModelTypeFromString(model)) < 0 ||
@@ -26181,6 +26203,13 @@ virDomainFSDefFormat(virBufferPtr buf,
     }
     if (def->multidevs)
         virBufferAsprintf(buf, " multidevs='%s'", multidevs);
+
+    if (def->fmode)
+        virBufferAsprintf(buf, " fmode='%04o'", def->fmode);
+
+    if (def->dmode)
+        virBufferAsprintf(buf, " dmode='%04o'", def->dmode);
+
     virBufferAddLit(buf, ">\n");
 
     virBufferAdjustIndent(buf, 2);
index 170fc73af941615fab6647e1202c36b613a3dc18..8a487e9de390be1390e44c428c34d39dde8f4de1 100644 (file)
@@ -849,6 +849,8 @@ struct _virDomainFSDef {
     int wrpolicy; /* enum virDomainFSWrpolicy */
     int format; /* virStorageFileFormat */
     int model; /* virDomainFSModel */
+    unsigned int fmode;
+    unsigned int dmode;
     int multidevs; /* virDomainFSMultidevs */
     unsigned long long usage; /* in bytes */
     virStorageSourcePtr src;
diff --git a/tests/qemuxml2argvdata/virtio-9p-createmode.xml b/tests/qemuxml2argvdata/virtio-9p-createmode.xml
new file mode 100644 (file)
index 0000000..032b22a
--- /dev/null
@@ -0,0 +1,58 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <filesystem type='mount' accessmode='mapped' fmode='644'>
+      <source dir='/export/fs0'/>
+      <target dir='fs0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='mapped' dmode='755'>
+      <source dir='/export/fs1'/>
+      <target dir='fs1'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='mapped' fmode='0640' dmode='0750'>
+      <source dir='/export/fs2'/>
+      <target dir='fs2'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='mapped'>
+      <source dir='/export/fs3'/>
+      <target dir='fs3'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </filesystem>
+    <serial type='pty'>
+      <target type='isa-serial' port='0'>
+        <model name='isa-serial'/>
+      </target>
+    </serial>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml b/tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml
new file mode 100644 (file)
index 0000000..7c374ca
--- /dev/null
@@ -0,0 +1,61 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <cpu mode='custom' match='exact' check='none'>
+    <model fallback='forbid'>qemu64</model>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='usb' index='0' model='piix3-uhci'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <filesystem type='mount' accessmode='mapped' fmode='0644'>
+      <source dir='/export/fs0'/>
+      <target dir='fs0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='mapped' dmode='0755'>
+      <source dir='/export/fs1'/>
+      <target dir='fs1'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='mapped' fmode='0640' dmode='0750'>
+      <source dir='/export/fs2'/>
+      <target dir='fs2'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='mapped'>
+      <source dir='/export/fs3'/>
+      <target dir='fs3'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </filesystem>
+    <serial type='pty'>
+      <target type='isa-serial' port='0'>
+        <model name='isa-serial'/>
+      </target>
+    </serial>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
index 44ac9fbce7201e32b083ae85db216e43526e81b2..0e9f88788ca34e97f0308ef0d9d0720e384ca286 100644 (file)
@@ -1513,6 +1513,7 @@ mymain(void)
     DO_TEST_CAPS_ARCH_LATEST("x86_64-default-cpu-tcg-q35-4.2", "x86_64");
 
     DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
+    DO_TEST_CAPS_LATEST("virtio-9p-createmode");
     DO_TEST("downscript", NONE);
 
  cleanup: