提交 75a6a9a8 编写于 作者: H Harsh Prateek Bora 提交者: Daniel Veillard

new attribute accessmode to filesystem element

This introduces new attribute to filesystem element
to support customizable access mode for mount type.
Valid accessmode are: passthrough, mapped and squash.

Usage:
        <filesystem type='mount' accessmode='passthrough'>
          <source dir='/export/to/guest'/>
          <target dir='mount_tag'/>
        </filesystem>

passthrough is the default model if not specified, that's
also the current behaviour.
上级 2b3df906
.gnulib @ 2bb63bfb
Subproject commit b6d1430494cdd252cd52eca6abf88b1a00f6c983 Subproject commit 2bb63bfb25474ea147ee9f1523c0337997359a4c
...@@ -794,6 +794,13 @@ ...@@ -794,6 +794,13 @@
</choice> </choice>
<optional> <optional>
<ref name="address"/> <ref name="address"/>
<attribute name="accessmode">
<choice>
<value>passthrough</value>
<value>mapped</value>
<value>squash</value>
</choice>
</attribute>
</optional> </optional>
</element> </element>
</define> </define>
......
...@@ -161,6 +161,12 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST, ...@@ -161,6 +161,12 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
"file", "file",
"template") "template")
VIR_ENUM_IMPL(virDomainFSAccessMode, VIR_DOMAIN_FS_ACCESSMODE_LAST,
"passthrough",
"mapped",
"squash")
VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST, VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST,
"user", "user",
"ethernet", "ethernet",
...@@ -1853,6 +1859,7 @@ virDomainFSDefParseXML(xmlNodePtr node, ...@@ -1853,6 +1859,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
char *type = NULL; char *type = NULL;
char *source = NULL; char *source = NULL;
char *target = NULL; char *target = NULL;
char *accessmode = NULL;
if (VIR_ALLOC(def) < 0) { if (VIR_ALLOC(def) < 0) {
virReportOOMError(); virReportOOMError();
...@@ -1870,6 +1877,17 @@ virDomainFSDefParseXML(xmlNodePtr node, ...@@ -1870,6 +1877,17 @@ virDomainFSDefParseXML(xmlNodePtr node,
def->type = VIR_DOMAIN_FS_TYPE_MOUNT; def->type = VIR_DOMAIN_FS_TYPE_MOUNT;
} }
accessmode = virXMLPropString(node, "accessmode");
if (accessmode) {
if ((def->accessmode = virDomainFSAccessModeTypeFromString(accessmode)) < 0) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown accessmode '%s'"), accessmode);
goto error;
}
} else {
def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
}
cur = node->children; cur = node->children;
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) { if (cur->type == XML_ELEMENT_NODE) {
...@@ -1918,6 +1936,7 @@ cleanup: ...@@ -1918,6 +1936,7 @@ cleanup:
VIR_FREE(type); VIR_FREE(type);
VIR_FREE(target); VIR_FREE(target);
VIR_FREE(source); VIR_FREE(source);
VIR_FREE(accessmode);
return def; return def;
...@@ -5625,6 +5644,7 @@ virDomainFSDefFormat(virBufferPtr buf, ...@@ -5625,6 +5644,7 @@ virDomainFSDefFormat(virBufferPtr buf,
int flags) int flags)
{ {
const char *type = virDomainFSTypeToString(def->type); const char *type = virDomainFSTypeToString(def->type);
const char *accessmode = virDomainFSAccessModeTypeToString(def->accessmode);
if (!type) { if (!type) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR, virDomainReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -5632,9 +5652,16 @@ virDomainFSDefFormat(virBufferPtr buf, ...@@ -5632,9 +5652,16 @@ virDomainFSDefFormat(virBufferPtr buf,
return -1; return -1;
} }
if (!accessmode) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected accessmode %d"), def->accessmode);
return -1;
}
virBufferVSprintf(buf, virBufferVSprintf(buf,
" <filesystem type='%s'>\n", " <filesystem type='%s' accessmode='%s'>\n",
type); type, accessmode);
if (def->src) { if (def->src) {
switch (def->type) { switch (def->type) {
......
...@@ -236,10 +236,20 @@ enum virDomainFSType { ...@@ -236,10 +236,20 @@ enum virDomainFSType {
VIR_DOMAIN_FS_TYPE_LAST VIR_DOMAIN_FS_TYPE_LAST
}; };
/* Filesystem mount access mode */
enum virDomainFSAccessMode {
VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH,
VIR_DOMAIN_FS_ACCESSMODE_MAPPED,
VIR_DOMAIN_FS_ACCESSMODE_SQUASH,
VIR_DOMAIN_FS_ACCESSMODE_LAST
};
typedef struct _virDomainFSDef virDomainFSDef; typedef struct _virDomainFSDef virDomainFSDef;
typedef virDomainFSDef *virDomainFSDefPtr; typedef virDomainFSDef *virDomainFSDefPtr;
struct _virDomainFSDef { struct _virDomainFSDef {
int type; int type;
int accessmode;
char *src; char *src;
char *dst; char *dst;
unsigned int readonly : 1; unsigned int readonly : 1;
...@@ -1175,6 +1185,7 @@ VIR_ENUM_DECL(virDomainDiskErrorPolicy) ...@@ -1175,6 +1185,7 @@ VIR_ENUM_DECL(virDomainDiskErrorPolicy)
VIR_ENUM_DECL(virDomainController) VIR_ENUM_DECL(virDomainController)
VIR_ENUM_DECL(virDomainControllerModel) VIR_ENUM_DECL(virDomainControllerModel)
VIR_ENUM_DECL(virDomainFS) VIR_ENUM_DECL(virDomainFS)
VIR_ENUM_DECL(virDomainFSAccessMode)
VIR_ENUM_DECL(virDomainNet) VIR_ENUM_DECL(virDomainNet)
VIR_ENUM_DECL(virDomainChrDevice) VIR_ENUM_DECL(virDomainChrDevice)
VIR_ENUM_DECL(virDomainChrChannelTarget) VIR_ENUM_DECL(virDomainChrChannelTarget)
......
...@@ -2789,11 +2789,18 @@ char *qemuBuildFSStr(virDomainFSDefPtr fs, ...@@ -2789,11 +2789,18 @@ char *qemuBuildFSStr(virDomainFSDefPtr fs,
if (fs->type != VIR_DOMAIN_FS_TYPE_MOUNT) { if (fs->type != VIR_DOMAIN_FS_TYPE_MOUNT) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("can only passthrough directories")); _("only supports mount filesystem type"));
goto error; goto error;
} }
virBufferAddLit(&opt, "local,security_model=passthrough"); virBufferAddLit(&opt, "local");
if (fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_MAPPED) {
virBufferAddLit(&opt, ",security_model=mapped");
} else if(fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) {
virBufferAddLit(&opt, ",security_model=passthrough");
} else if(fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_SQUASH) {
virBufferAddLit(&opt, ",security_model=none");
}
virBufferVSprintf(&opt, ",id=%s%s", QEMU_FSDEV_HOST_PREFIX, fs->info.alias); virBufferVSprintf(&opt, ",id=%s%s", QEMU_FSDEV_HOST_PREFIX, fs->info.alias);
virBufferVSprintf(&opt, ",path=%s", fs->src); virBufferVSprintf(&opt, ",path=%s", fs->src);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册