提交 96f0a17e 编写于 作者: P Peter Krempa

util: storage: Fix parsing of 'exportname' from legacy NBD strings

If the nbd export name contains a colon, our parser would not parse it
properly as we split the string by colons. Modify the code to look up
the exportname and copy any trailing characters as the export name is
supposed to be at the end of the string.

https://bugzilla.redhat.com/show_bug.cgi?id=1733044Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJiri Denemark <jdenemar@redhat.com>
上级 5726e472
...@@ -2928,6 +2928,7 @@ virStorageSourceParseNBDColonString(const char *nbdstr, ...@@ -2928,6 +2928,7 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
virStorageSourcePtr src) virStorageSourcePtr src)
{ {
VIR_AUTOSTRINGLIST backing = NULL; VIR_AUTOSTRINGLIST backing = NULL;
const char *exportname;
if (!(backing = virStringSplit(nbdstr, ":", 0))) if (!(backing = virStringSplit(nbdstr, ":", 0)))
return -1; return -1;
...@@ -2975,8 +2976,9 @@ virStorageSourceParseNBDColonString(const char *nbdstr, ...@@ -2975,8 +2976,9 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
return -1; return -1;
} }
if (backing[3] && STRPREFIX(backing[3], "exportname=")) { if ((exportname = strstr(nbdstr, "exportname="))) {
if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0) exportname += strlen("exportname=");
if (VIR_STRDUP(src->path, exportname) < 0)
return -1; return -1;
} }
......
...@@ -1262,6 +1262,14 @@ mymain(void) ...@@ -1262,6 +1262,14 @@ mymain(void)
"<source protocol='nbd' name='blah'>\n" "<source protocol='nbd' name='blah'>\n"
" <host name='example.org' port='6000'/>\n" " <host name='example.org' port='6000'/>\n"
"</source>\n"); "</source>\n");
TEST_BACKING_PARSE("nbd:example.org:6000:exportname=:",
"<source protocol='nbd' name=':'>\n"
" <host name='example.org' port='6000'/>\n"
"</source>\n");
TEST_BACKING_PARSE("nbd:example.org:6000:exportname=:test",
"<source protocol='nbd' name=':test'>\n"
" <host name='example.org' port='6000'/>\n"
"</source>\n");
TEST_BACKING_PARSE("nbd://example.org:1234", TEST_BACKING_PARSE("nbd://example.org:1234",
"<source protocol='nbd'>\n" "<source protocol='nbd'>\n"
" <host name='example.org' port='1234'/>\n" " <host name='example.org' port='1234'/>\n"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册