|
Daniel P. Berrange |
511f6c |
From: Daniel Veillard <veillard@redhat.com>
|
|
Daniel P. Berrange |
511f6c |
Date: Thu, 12 Mar 2009 20:15:32 +0000 (+0000)
|
|
Daniel P. Berrange |
511f6c |
Subject: * src/storage_conf.c: fix storage pool mode parsing, and refactoring
|
|
Daniel P. Berrange |
511f6c |
X-Git-Url: http://git.et.redhat.com/?p=libvirt.git;a=commitdiff_plain;h=bc962f5d7c6e2c2cfc233ea6deea95dba2b7c6eb
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
* src/storage_conf.c: fix storage pool mode parsing, and refactoring
|
|
Daniel P. Berrange |
511f6c |
patch by Ryota Ozaki
|
|
Daniel P. Berrange |
511f6c |
Daniel
|
|
Daniel P. Berrange |
511f6c |
---
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
diff --git a/src/storage_conf.c b/src/storage_conf.c
|
|
Daniel P. Berrange |
511f6c |
index 9c13e07..1c9a4e5 100644
|
|
Daniel P. Berrange |
511f6c |
--- a/src/storage_conf.c
|
|
Daniel P. Berrange |
511f6c |
+++ b/src/storage_conf.c
|
|
Daniel P. Berrange |
511f6c |
@@ -371,15 +371,33 @@ virStoragePoolDefParseAuthChap(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
static int
|
|
Daniel P. Berrange |
511f6c |
-virStoragePoolDefParsePerms(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
- xmlXPathContextPtr ctxt,
|
|
Daniel P. Berrange |
511f6c |
- virStoragePermsPtr perms) {
|
|
Daniel P. Berrange |
511f6c |
+virStorageDefParsePerms(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
+ xmlXPathContextPtr ctxt,
|
|
Daniel P. Berrange |
511f6c |
+ virStoragePermsPtr perms,
|
|
Daniel P. Berrange |
511f6c |
+ const char *permxpath,
|
|
Daniel P. Berrange |
511f6c |
+ int defaultmode) {
|
|
Daniel P. Berrange |
511f6c |
char *mode;
|
|
Daniel P. Berrange |
511f6c |
long v;
|
|
Daniel P. Berrange |
511f6c |
+ int ret = -1;
|
|
Daniel P. Berrange |
511f6c |
+ xmlNodePtr relnode;
|
|
Daniel P. Berrange |
511f6c |
+ xmlNodePtr node;
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- mode = virXPathString(conn, "string(/pool/permissions/mode)", ctxt);
|
|
Daniel P. Berrange |
511f6c |
+ node = virXPathNode(conn, permxpath, ctxt);
|
|
Daniel P. Berrange |
511f6c |
+ if (node == NULL) {
|
|
Daniel P. Berrange |
511f6c |
+ /* Set default values if there is not <permissions> element */
|
|
Daniel P. Berrange |
511f6c |
+ perms->mode = defaultmode;
|
|
Daniel P. Berrange |
511f6c |
+ perms->uid = getuid();
|
|
Daniel P. Berrange |
511f6c |
+ perms->gid = getgid();
|
|
Daniel P. Berrange |
511f6c |
+ perms->label = NULL;
|
|
Daniel P. Berrange |
511f6c |
+ return 0;
|
|
Daniel P. Berrange |
511f6c |
+ }
|
|
Daniel P. Berrange |
511f6c |
+
|
|
Daniel P. Berrange |
511f6c |
+ relnode = ctxt->node;
|
|
Daniel P. Berrange |
511f6c |
+ ctxt->node = node;
|
|
Daniel P. Berrange |
511f6c |
+
|
|
Daniel P. Berrange |
511f6c |
+ mode = virXPathString(conn, "string(./mode)", ctxt);
|
|
Daniel P. Berrange |
511f6c |
if (!mode) {
|
|
Daniel P. Berrange |
511f6c |
- perms->mode = 0700;
|
|
Daniel P. Berrange |
511f6c |
+ perms->mode = defaultmode;
|
|
Daniel P. Berrange |
511f6c |
} else {
|
|
Daniel P. Berrange |
511f6c |
char *end = NULL;
|
|
Daniel P. Berrange |
511f6c |
perms->mode = strtol(mode, &end, 8);
|
|
Daniel P. Berrange |
511f6c |
@@ -387,36 +405,39 @@ virStoragePoolDefParsePerms(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
if (*end || perms->mode < 0 || perms->mode > 0777) {
|
|
Daniel P. Berrange |
511f6c |
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
Daniel P. Berrange |
511f6c |
"%s", _("malformed octal mode"));
|
|
Daniel P. Berrange |
511f6c |
- return -1;
|
|
Daniel P. Berrange |
511f6c |
+ goto error;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathNode(conn, "/pool/permissions/owner", ctxt) == NULL) {
|
|
Daniel P. Berrange |
511f6c |
+ if (virXPathNode(conn, "./owner", ctxt) == NULL) {
|
|
Daniel P. Berrange |
511f6c |
perms->uid = getuid();
|
|
Daniel P. Berrange |
511f6c |
} else {
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathLong(conn, "number(/pool/permissions/owner)", ctxt, &v) < 0) {
|
|
Daniel P. Berrange |
511f6c |
+ if (virXPathLong(conn, "number(./owner)", ctxt, &v) < 0) {
|
|
Daniel P. Berrange |
511f6c |
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
Daniel P. Berrange |
511f6c |
"%s", _("malformed owner element"));
|
|
Daniel P. Berrange |
511f6c |
- return -1;
|
|
Daniel P. Berrange |
511f6c |
+ goto error;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
perms->uid = (int)v;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathNode(conn, "/pool/permissions/group", ctxt) == NULL) {
|
|
Daniel P. Berrange |
511f6c |
+ if (virXPathNode(conn, "./group", ctxt) == NULL) {
|
|
Daniel P. Berrange |
511f6c |
perms->gid = getgid();
|
|
Daniel P. Berrange |
511f6c |
} else {
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathLong(conn, "number(/pool/permissions/group)", ctxt, &v) < 0) {
|
|
Daniel P. Berrange |
511f6c |
+ if (virXPathLong(conn, "number(./group)", ctxt, &v) < 0) {
|
|
Daniel P. Berrange |
511f6c |
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
Daniel P. Berrange |
511f6c |
"%s", _("malformed group element"));
|
|
Daniel P. Berrange |
511f6c |
- return -1;
|
|
Daniel P. Berrange |
511f6c |
+ goto error;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
perms->gid = (int)v;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
/* NB, we're ignoring missing labels here - they'll simply inherit */
|
|
Daniel P. Berrange |
511f6c |
- perms->label = virXPathString(conn, "string(/pool/permissions/label)", ctxt);
|
|
Daniel P. Berrange |
511f6c |
+ perms->label = virXPathString(conn, "string(./label)", ctxt);
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- return 0;
|
|
Daniel P. Berrange |
511f6c |
+ ret = 0;
|
|
Daniel P. Berrange |
511f6c |
+error:
|
|
Daniel P. Berrange |
511f6c |
+ ctxt->node = relnode;
|
|
Daniel P. Berrange |
511f6c |
+ return ret;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
@@ -579,7 +600,8 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
goto cleanup;
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- if (virStoragePoolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
|
|
Daniel P. Berrange |
511f6c |
+ if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
|
Daniel P. Berrange |
511f6c |
+ "/pool/target/permissions", 0700) < 0)
|
|
Daniel P. Berrange |
511f6c |
goto cleanup;
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
return ret;
|
|
Daniel P. Berrange |
511f6c |
@@ -801,55 +823,6 @@ virStoragePoolDefFormat(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
static int
|
|
Daniel P. Berrange |
511f6c |
-virStorageVolDefParsePerms(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
- xmlXPathContextPtr ctxt,
|
|
Daniel P. Berrange |
511f6c |
- virStoragePermsPtr perms) {
|
|
Daniel P. Berrange |
511f6c |
- char *mode;
|
|
Daniel P. Berrange |
511f6c |
- long v;
|
|
Daniel P. Berrange |
511f6c |
-
|
|
Daniel P. Berrange |
511f6c |
- mode = virXPathString(conn, "string(/volume/permissions/mode)", ctxt);
|
|
Daniel P. Berrange |
511f6c |
- if (!mode) {
|
|
Daniel P. Berrange |
511f6c |
- perms->mode = 0600;
|
|
Daniel P. Berrange |
511f6c |
- } else {
|
|
Daniel P. Berrange |
511f6c |
- char *end = NULL;
|
|
Daniel P. Berrange |
511f6c |
- perms->mode = strtol(mode, &end, 8);
|
|
Daniel P. Berrange |
511f6c |
- VIR_FREE(mode);
|
|
Daniel P. Berrange |
511f6c |
- if (*end || perms->mode < 0 || perms->mode > 0777) {
|
|
Daniel P. Berrange |
511f6c |
- virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
Daniel P. Berrange |
511f6c |
- "%s", _("malformed octal mode"));
|
|
Daniel P. Berrange |
511f6c |
- return -1;
|
|
Daniel P. Berrange |
511f6c |
- }
|
|
Daniel P. Berrange |
511f6c |
- }
|
|
Daniel P. Berrange |
511f6c |
-
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathNode(conn, "/volume/permissions/owner", ctxt) == NULL) {
|
|
Daniel P. Berrange |
511f6c |
- perms->uid = getuid();
|
|
Daniel P. Berrange |
511f6c |
- } else {
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathLong(conn, "number(/volume/permissions/owner)", ctxt, &v) < 0) {
|
|
Daniel P. Berrange |
511f6c |
- virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
Daniel P. Berrange |
511f6c |
- "%s", _("missing owner element"));
|
|
Daniel P. Berrange |
511f6c |
- return -1;
|
|
Daniel P. Berrange |
511f6c |
- }
|
|
Daniel P. Berrange |
511f6c |
- perms->uid = (int)v;
|
|
Daniel P. Berrange |
511f6c |
- }
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathNode(conn, "/volume/permissions/group", ctxt) == NULL) {
|
|
Daniel P. Berrange |
511f6c |
- perms->gid = getgid();
|
|
Daniel P. Berrange |
511f6c |
- } else {
|
|
Daniel P. Berrange |
511f6c |
- if (virXPathLong(conn, "number(/volume/permissions/group)", ctxt, &v) < 0) {
|
|
Daniel P. Berrange |
511f6c |
- virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
Daniel P. Berrange |
511f6c |
- "%s", _("missing group element"));
|
|
Daniel P. Berrange |
511f6c |
- return -1;
|
|
Daniel P. Berrange |
511f6c |
- }
|
|
Daniel P. Berrange |
511f6c |
- perms->gid = (int)v;
|
|
Daniel P. Berrange |
511f6c |
- }
|
|
Daniel P. Berrange |
511f6c |
-
|
|
Daniel P. Berrange |
511f6c |
- /* NB, we're ignoring missing labels here - they'll simply inherit */
|
|
Daniel P. Berrange |
511f6c |
- perms->label = virXPathString(conn, "string(/volume/permissions/label)", ctxt);
|
|
Daniel P. Berrange |
511f6c |
-
|
|
Daniel P. Berrange |
511f6c |
- return 0;
|
|
Daniel P. Berrange |
511f6c |
-}
|
|
Daniel P. Berrange |
511f6c |
-
|
|
Daniel P. Berrange |
511f6c |
-
|
|
Daniel P. Berrange |
511f6c |
-static int
|
|
Daniel P. Berrange |
511f6c |
virStorageSize(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
const char *unit,
|
|
Daniel P. Berrange |
511f6c |
const char *val,
|
|
Daniel P. Berrange |
511f6c |
@@ -997,7 +970,8 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
VIR_FREE(format);
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- if (virStorageVolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
|
|
Daniel P. Berrange |
511f6c |
+ if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
|
Daniel P. Berrange |
511f6c |
+ "/volume/target/permissions", 0600) < 0)
|
|
Daniel P. Berrange |
511f6c |
goto cleanup;
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
@@ -1019,7 +993,8 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|
Daniel P. Berrange |
511f6c |
VIR_FREE(format);
|
|
Daniel P. Berrange |
511f6c |
}
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
- if (virStorageVolDefParsePerms(conn, ctxt, &ret->backingStore.perms) < 0)
|
|
Daniel P. Berrange |
511f6c |
+ if (virStorageDefParsePerms(conn, ctxt, &ret->backingStore.perms,
|
|
Daniel P. Berrange |
511f6c |
+ "/volume/backingStore/permissions", 0600) < 0)
|
|
Daniel P. Berrange |
511f6c |
goto cleanup;
|
|
Daniel P. Berrange |
511f6c |
|
|
Daniel P. Berrange |
511f6c |
return ret;
|