From: Klim Kireev <klim.kir...@virtuozzo.com> This commit adds bdrv_probe implementation. It checks the filename (it must be DiskDescriptor.xml). Then it checks correctness of the xml file using libxml2.
Signed-off-by: Klim Kireev <klim.kir...@virtuozzo.com> --- block/prl-xml.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/block/prl-xml.c b/block/prl-xml.c index 5ab32bb6ab..023651342c 100644 --- a/block/prl-xml.c +++ b/block/prl-xml.c @@ -467,6 +467,30 @@ fail: return ret; } +static int prl_probe_xml(const uint8_t *data, int buf_size, + const char *filename) +{ + xmlDoc *doc = NULL; + xmlNodePtr root; + + if (strcmp(basename(filename), PRL_XML_FILENAME) != 0) { + return 0; + } + + doc = xmlReadFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING); + if (doc == NULL) { + return 0; + } + + root = xmlDocGetRootElement(doc); + if (root == NULL) { + return 0; + } + + xmlFreeDoc(doc); + return 100; +} + static coroutine_fn int prl_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) @@ -499,6 +523,7 @@ static coroutine_fn int prl_co_flush_to_os(BlockDriverState *bs) static BlockDriver bdrv_prl_xml = { .format_name = "prl-xml", .instance_size = sizeof(BDRVPrlXmlState), + .bdrv_probe = prl_probe_xml, .bdrv_open = prl_open_xml, .bdrv_co_readv = prl_co_readv, .bdrv_co_writev = prl_co_writev, -- 2.21.3