[libvirt PATCH v4 2/4] qemu: add 'fmode' and 'dmode' options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 docs/schemas/domaincommon.rng                 | 16 +++++
 src/conf/domain_conf.c                        | 29 +++++++++
 src/conf/domain_conf.h                        |  2 +
 .../qemuxml2argvdata/virtio-9p-createmode.xml | 58 ++++++++++++++++++
 .../virtio-9p-createmode.x86_64-latest.xml    | 61 +++++++++++++++++++
 tests/qemuxml2xmltest.c                       |  1 +
 6 files changed, 167 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/virtio-9p-createmode.xml
 create mode 100644 tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 7d4b105981..a0f0eb5a23 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -26,6 +26,12 @@
     </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
     -->
@@ -2736,6 +2742,16 @@
             </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/>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 51efeb0e42..57ca2152ea 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11471,6 +11471,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;
 
@@ -11499,6 +11501,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 ||
@@ -26133,6 +26155,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);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 450686dfb5..51f70f9dd4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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
index 0000000000..032b22a2da
--- /dev/null
+++ b/tests/qemuxml2argvdata/virtio-9p-createmode.xml
@@ -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
index 0000000000..7c374ca3a6
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/virtio-9p-createmode.x86_64-latest.xml
@@ -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>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2bf8dd5b14..17cbed97f9 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -1496,6 +1496,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:
-- 
2.25.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux