For future reuse in the snapshot XML. --- src/conf/storage_conf.c | 16 ++-------------- src/util/virstoragefile.c | 29 +++++++++++++++++++++++++++++ src/util/virstoragefile.h | 1 + 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index ee3019a..2c34394 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1372,20 +1372,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, } ret->target.compat = virXPathString("string(./target/compat)", ctxt); - if (ret->target.compat) { - char **version = virStringSplit(ret->target.compat, ".", 2); - unsigned int result; - - if (!version || !version[1] || - virStrToLong_ui(version[0], NULL, 10, &result) < 0 || - virStrToLong_ui(version[1], NULL, 10, &result) < 0) { - virStringFreeList(version); - virReportError(VIR_ERR_XML_ERROR, "%s", - _("forbidden characters in 'compat' attribute")); - goto error; - } - virStringFreeList(version); - } + if (!virStorageFileCheckCompat(ret->target.compat)) + goto error; if (virXPathNode("./target/nocow", ctxt)) ret->target.nocow = true; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 96be02e..c1246e7 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2873,3 +2873,32 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top, VIR_FREE(tmp); return ret; } + + +/* + * virStorageFileCheckCompat + */ +bool +virStorageFileCheckCompat(const char *compat) +{ + char **version; + unsigned int result; + bool ret; + + if (!compat) + return true; + + version = virStringSplit(compat, ".", 2); + if (!version || !version[1] || + virStrToLong_ui(version[0], NULL, 10, &result) < 0 || + virStrToLong_ui(version[1], NULL, 10, &result) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("forbidden characters in 'compat' attribute")); + goto cleanup; + } + ret = true; + + cleanup: + virStringFreeList(version); + return ret; +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b4c3808..ed90774 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -384,4 +384,5 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from, char **relpath) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +bool virStorageFileCheckCompat(const char *compat); #endif /* __VIR_STORAGE_FILE_H__ */ -- 2.0.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list