提交 b4be2933 编写于 作者: P Peter Krempa

conf: Refactor virDomainDiskDefMirrorParse

Now that the mirror parsing code is not crammed in the main disk parser
we can employ better coding style.
上级 109fe3fe
...@@ -6758,41 +6758,44 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, ...@@ -6758,41 +6758,44 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
xmlNodePtr cur, xmlNodePtr cur,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr mirrorNode;
char *mirrorFormat = NULL; char *mirrorFormat = NULL;
char *mirrorType = NULL; char *mirrorType = NULL;
char *ready; char *ready = NULL;
char *blockJob; char *blockJob = NULL;
int ret = -1; int ret = -1;
if (VIR_ALLOC(def->mirror) < 0) if (VIR_ALLOC(def->mirror) < 0)
goto cleanup; goto cleanup;
blockJob = virXMLPropString(cur, "job"); if ((blockJob = virXMLPropString(cur, "job"))) {
if (blockJob) { if ((def->mirrorJob = virDomainBlockJobTypeFromString(blockJob)) <= 0) {
def->mirrorJob = virDomainBlockJobTypeFromString(blockJob);
if (def->mirrorJob <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown mirror job type '%s'"), _("unknown mirror job type '%s'"), blockJob);
blockJob);
VIR_FREE(blockJob);
goto cleanup; goto cleanup;
} }
VIR_FREE(blockJob);
} else { } else {
def->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; def->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
} }
mirrorType = virXMLPropString(cur, "type"); if ((mirrorType = virXMLPropString(cur, "type"))) {
if (mirrorType) { if ((def->mirror->type = virStorageTypeFromString(mirrorType)) <= 0) {
def->mirror->type = virStorageTypeFromString(mirrorType);
if (def->mirror->type <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown mirror backing store " _("unknown mirror backing store type '%s'"),
"type '%s'"), mirrorType); mirrorType);
goto cleanup; goto cleanup;
} }
mirrorFormat = virXPathString("string(./mirror/format/@type)",
ctxt); mirrorFormat = virXPathString("string(./mirror/format/@type)", ctxt);
if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("mirror requires source element"));
goto cleanup;
}
if (virDomainDiskSourceParse(mirrorNode, ctxt, def->mirror) < 0)
goto cleanup;
} else { } else {
/* For back-compat reasons, we handle a file name /* For back-compat reasons, we handle a file name
* encoded as attributes, even though we prefer * encoded as attributes, even though we prefer
...@@ -6812,44 +6815,28 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, ...@@ -6812,44 +6815,28 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
} }
mirrorFormat = virXMLPropString(cur, "format"); mirrorFormat = virXMLPropString(cur, "format");
} }
if (mirrorFormat) { if (mirrorFormat) {
def->mirror->format = def->mirror->format = virStorageFileFormatTypeFromString(mirrorFormat);
virStorageFileFormatTypeFromString(mirrorFormat);
if (def->mirror->format <= 0) { if (def->mirror->format <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown mirror format value '%s'"), _("unknown mirror format value '%s'"), mirrorFormat);
mirrorFormat);
goto cleanup; goto cleanup;
} }
} }
if (mirrorType) {
xmlNodePtr mirrorNode;
if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) { if ((ready = virXMLPropString(cur, "ready")) &&
virReportError(VIR_ERR_XML_ERROR, "%s", (def->mirrorState = virDomainDiskMirrorStateTypeFromString(ready)) < 0) {
_("mirror requires source element")); virReportError(VIR_ERR_XML_ERROR,
goto cleanup; _("unknown mirror ready state %s"), ready);
} goto cleanup;
if (virDomainDiskSourceParse(mirrorNode, ctxt,
def->mirror) < 0)
goto cleanup;
}
ready = virXMLPropString(cur, "ready");
if (ready) {
if ((def->mirrorState =
virDomainDiskMirrorStateTypeFromString(ready)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown mirror ready state %s"),
ready);
VIR_FREE(ready);
goto cleanup;
}
VIR_FREE(ready);
} }
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(ready);
VIR_FREE(blockJob);
VIR_FREE(mirrorType); VIR_FREE(mirrorType);
VIR_FREE(mirrorFormat); VIR_FREE(mirrorFormat);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册