From 1d446bd4650bd4fa71c0fdafb2b7fc811f1899bf Mon Sep 17 00:00:00 2001 From: Brian Turek Date: Thu, 8 Oct 2020 15:32:24 +0100 Subject: [PATCH] qemu: add 'fmode' and 'dmode' options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Ján Tomko Reviewed-by: Ján Tomko --- 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 a62a598568..97fa873977 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -26,6 +26,12 @@ + + + 0[0-7]{3}|[0-7]{1,3} + + + @@ -2746,6 +2752,16 @@ + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b47f43afd9..7696b12ef9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 170fc73af9..8a487e9de3 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 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + +
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + +
+ + + 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 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + +
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 44ac9fbce7..0e9f88788c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -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: