Re: [libvirt] [PATCH v5 7/9] domain_conf: Read and Write quorum config
On Tue, May 12, 2015 at 5:04 PM, Peter Krempa pkre...@redhat.com wrote: On Thu, Apr 23, 2015 at 14:41:19 +0200, Matthias Gatto wrote: Add the capabiltty to libvirt to parse and format the quorum syntax as described here: http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/domain_conf.c | 164 +++-- 1 file changed, 119 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3a6c13..ec93b6f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5952,20 +5952,56 @@ virDomainDiskSourceParse(xmlNodePtr node, } +static bool +virDomainDiskThresholdParse(virStorageSourcePtr src, +xmlNodePtr node) +{ +char *threshold = virXMLPropString(node, threshold); +int ret; + +if (!threshold) { +virReportError(VIR_ERR_XML_ERROR, + %s, _(missing threshold in quorum)); +return false; +} +ret = virStrToLong_ul(threshold, NULL, 10, src-threshold); +if (ret 0 || src-threshold 2) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unexpected threshold %s), + threshold must be a decimal number superior to 2 + and inferior to the number of children); +VIR_FREE(threshold); +return false; +} +VIR_FREE(threshold); +return true; +} + + static int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, - virStorageSourcePtr src) + virStorageSourcePtr src, + xmlNodePtr node, + size_t pos) { virStorageSourcePtr backingStore = NULL; xmlNodePtr save_ctxt = ctxt-node; -xmlNodePtr source; +xmlNodePtr source = NULL; char *type = NULL; char *format = NULL; int ret = -1; -if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { -ret = 0; -goto cleanup; +if (src-type == VIR_STORAGE_TYPE_QUORUM) { +if (!node) { +ret = 0; +goto cleanup; +} +ctxt-node = node; +} else { +if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { +ret = 0; +goto cleanup; +} } if (VIR_ALLOC(backingStore) 0) @@ -5997,6 +6033,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, goto cleanup; } +if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) { +xmlNodePtr cur = NULL; + +if (!virDomainDiskThresholdParse(backingStore, node)) +goto cleanup; + +for (cur = node-children; cur != NULL; cur = cur-next) { +if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if ((virDomainDiskBackingStoreParse(ctxt, +backingStore, +cur, + backingStore-nBackingStores) 0)) { +goto cleanup; +} +} +} +goto exit; +} + if (!(source = virXPathNode(./source, ctxt))) { virReportError(VIR_ERR_XML_ERROR, %s, _(missing disk backing store source)); @@ -6004,10 +6059,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, } if (virDomainDiskSourceParse(source, ctxt, backingStore) 0 || -virDomainDiskBackingStoreParse(ctxt, backingStore) 0) +virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0) 0) goto cleanup; -if (!virStorageSourceSetBackingStore(src, backingStore, 0)) + exit: +if (!virStorageSourceSetBackingStore(src, backingStore, pos)) goto cleanup; ret = 0; @@ -6020,7 +6076,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, return ret; } - #define VENDOR_LEN 8 #define PRODUCT_LEN 16 @@ -6518,6 +6573,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } else if (xmlStrEqual(cur-name, BAD_CAST boot)) { /* boot is parsed as part of virDomainDeviceInfoParseXML */ +} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if (virDomainDiskBackingStoreParse(ctxt, def-src, cur, + def-src-nBackingStores) 0) +goto error; } } cur = cur-next; @@ -6541,12 +6600,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def-device = VIR_DOMAIN_DISK_DEVICE_DISK; } +if (def-src-type == VIR_STORAGE_TYPE_QUORUM +!virDomainDiskThresholdParse(def-src, node)) +
Re: [libvirt] [PATCH v5 7/9] domain_conf: Read and Write quorum config
On Thu, Apr 23, 2015 at 14:41:19 +0200, Matthias Gatto wrote: Add the capabiltty to libvirt to parse and format the quorum syntax as described here: http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/domain_conf.c | 164 +++-- 1 file changed, 119 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3a6c13..ec93b6f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5952,20 +5952,56 @@ virDomainDiskSourceParse(xmlNodePtr node, } +static bool +virDomainDiskThresholdParse(virStorageSourcePtr src, +xmlNodePtr node) +{ +char *threshold = virXMLPropString(node, threshold); +int ret; + +if (!threshold) { +virReportError(VIR_ERR_XML_ERROR, + %s, _(missing threshold in quorum)); +return false; +} +ret = virStrToLong_ul(threshold, NULL, 10, src-threshold); +if (ret 0 || src-threshold 2) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unexpected threshold %s), + threshold must be a decimal number superior to 2 + and inferior to the number of children); +VIR_FREE(threshold); +return false; +} +VIR_FREE(threshold); +return true; +} + + static int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, - virStorageSourcePtr src) + virStorageSourcePtr src, + xmlNodePtr node, + size_t pos) { virStorageSourcePtr backingStore = NULL; xmlNodePtr save_ctxt = ctxt-node; -xmlNodePtr source; +xmlNodePtr source = NULL; char *type = NULL; char *format = NULL; int ret = -1; -if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { -ret = 0; -goto cleanup; +if (src-type == VIR_STORAGE_TYPE_QUORUM) { +if (!node) { +ret = 0; +goto cleanup; +} +ctxt-node = node; +} else { +if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { +ret = 0; +goto cleanup; +} } if (VIR_ALLOC(backingStore) 0) @@ -5997,6 +6033,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, goto cleanup; } +if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) { +xmlNodePtr cur = NULL; + +if (!virDomainDiskThresholdParse(backingStore, node)) +goto cleanup; + +for (cur = node-children; cur != NULL; cur = cur-next) { +if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if ((virDomainDiskBackingStoreParse(ctxt, +backingStore, +cur, + backingStore-nBackingStores) 0)) { +goto cleanup; +} +} +} +goto exit; +} + if (!(source = virXPathNode(./source, ctxt))) { virReportError(VIR_ERR_XML_ERROR, %s, _(missing disk backing store source)); @@ -6004,10 +6059,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, } if (virDomainDiskSourceParse(source, ctxt, backingStore) 0 || -virDomainDiskBackingStoreParse(ctxt, backingStore) 0) +virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0) 0) goto cleanup; -if (!virStorageSourceSetBackingStore(src, backingStore, 0)) + exit: +if (!virStorageSourceSetBackingStore(src, backingStore, pos)) goto cleanup; ret = 0; @@ -6020,7 +6076,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, return ret; } - #define VENDOR_LEN 8 #define PRODUCT_LEN 16 @@ -6518,6 +6573,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } else if (xmlStrEqual(cur-name, BAD_CAST boot)) { /* boot is parsed as part of virDomainDeviceInfoParseXML */ +} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if (virDomainDiskBackingStoreParse(ctxt, def-src, cur, + def-src-nBackingStores) 0) +goto error; } } cur = cur-next; @@ -6541,12 +6600,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def-device = VIR_DOMAIN_DISK_DEVICE_DISK; } +if (def-src-type == VIR_STORAGE_TYPE_QUORUM +!virDomainDiskThresholdParse(def-src, node)) +goto error; + +snapshot =
[libvirt] [PATCH v5 7/9] domain_conf: Read and Write quorum config
Add the capabiltty to libvirt to parse and format the quorum syntax as described here: http://www.redhat.com/archives/libvir-list/2014-May/msg00533.html Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/domain_conf.c | 164 +++-- 1 file changed, 119 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3a6c13..ec93b6f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5952,20 +5952,56 @@ virDomainDiskSourceParse(xmlNodePtr node, } +static bool +virDomainDiskThresholdParse(virStorageSourcePtr src, +xmlNodePtr node) +{ +char *threshold = virXMLPropString(node, threshold); +int ret; + +if (!threshold) { +virReportError(VIR_ERR_XML_ERROR, + %s, _(missing threshold in quorum)); +return false; +} +ret = virStrToLong_ul(threshold, NULL, 10, src-threshold); +if (ret 0 || src-threshold 2) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(unexpected threshold %s), + threshold must be a decimal number superior to 2 + and inferior to the number of children); +VIR_FREE(threshold); +return false; +} +VIR_FREE(threshold); +return true; +} + + static int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, - virStorageSourcePtr src) + virStorageSourcePtr src, + xmlNodePtr node, + size_t pos) { virStorageSourcePtr backingStore = NULL; xmlNodePtr save_ctxt = ctxt-node; -xmlNodePtr source; +xmlNodePtr source = NULL; char *type = NULL; char *format = NULL; int ret = -1; -if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { -ret = 0; -goto cleanup; +if (src-type == VIR_STORAGE_TYPE_QUORUM) { +if (!node) { +ret = 0; +goto cleanup; +} +ctxt-node = node; +} else { +if (!(ctxt-node = virXPathNode(./backingStore[*], ctxt))) { +ret = 0; +goto cleanup; +} } if (VIR_ALLOC(backingStore) 0) @@ -5997,6 +6033,25 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, goto cleanup; } +if (backingStore-type == VIR_STORAGE_TYPE_QUORUM) { +xmlNodePtr cur = NULL; + +if (!virDomainDiskThresholdParse(backingStore, node)) +goto cleanup; + +for (cur = node-children; cur != NULL; cur = cur-next) { +if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if ((virDomainDiskBackingStoreParse(ctxt, +backingStore, +cur, + backingStore-nBackingStores) 0)) { +goto cleanup; +} +} +} +goto exit; +} + if (!(source = virXPathNode(./source, ctxt))) { virReportError(VIR_ERR_XML_ERROR, %s, _(missing disk backing store source)); @@ -6004,10 +6059,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, } if (virDomainDiskSourceParse(source, ctxt, backingStore) 0 || -virDomainDiskBackingStoreParse(ctxt, backingStore) 0) +virDomainDiskBackingStoreParse(ctxt, backingStore, NULL, 0) 0) goto cleanup; -if (!virStorageSourceSetBackingStore(src, backingStore, 0)) + exit: +if (!virStorageSourceSetBackingStore(src, backingStore, pos)) goto cleanup; ret = 0; @@ -6020,7 +6076,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, return ret; } - #define VENDOR_LEN 8 #define PRODUCT_LEN 16 @@ -6518,6 +6573,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } else if (xmlStrEqual(cur-name, BAD_CAST boot)) { /* boot is parsed as part of virDomainDeviceInfoParseXML */ +} else if (xmlStrEqual(cur-name, BAD_CAST backingStore)) { +if (virDomainDiskBackingStoreParse(ctxt, def-src, cur, + def-src-nBackingStores) 0) +goto error; } } cur = cur-next; @@ -6541,12 +6600,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def-device = VIR_DOMAIN_DISK_DEVICE_DISK; } +if (def-src-type == VIR_STORAGE_TYPE_QUORUM +!virDomainDiskThresholdParse(def-src, node)) +goto error; + +snapshot = virXMLPropString(node, snapshot); + /* Only CDROM and Floppy devices are allowed missing source path * to indicate no media present. LUN is for raw access CD-ROMs * that are not attached to a physical device