sheepdog: Report errors in pseudo-filename more usefully
Errors in the pseudo-filename are all reported with the same laconic "Can't parse filename" message. Add real error reporting, such as: $ qemu-system-x86_64 --drive driver=sheepdog,filename=sheepdog:/// qemu-system-x86_64: --drive driver=sheepdog,filename=sheepdog:///: missing file path in URI $ qemu-system-x86_64 --drive driver=sheepdog,filename=sheepgod:///vdi qemu-system-x86_64: --drive driver=sheepdog,filename=sheepgod:///vdi: URI scheme must be 'sheepdog', 'sheepdog+tcp', or 'sheepdog+unix' $ qemu-system-x86_64 --drive driver=sheepdog,filename=sheepdog+unix:///vdi?socke=sheepdog.sock qemu-system-x86_64: --drive driver=sheepdog,filename=sheepdog+unix:///vdi?socke=sheepdog.sock: unexpected query parameters The code to translate legacy syntax to URI fails to escape URI meta-characters. The new error messages are misleading then. Replace them by the old "Can't parse filename" message. "Internal error" would be more honest. Anyway, no worse than before. Also add a FIXME comment. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
daa0b0d4b1
commit
36bcac16fd
|
@ -957,16 +957,18 @@ static bool sd_parse_snapid_or_tag(const char *str,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sd_parse_uri(BDRVSheepdogState *s, const char *filename,
|
static void sd_parse_uri(BDRVSheepdogState *s, const char *filename,
|
||||||
char *vdi, uint32_t *snapid, char *tag)
|
char *vdi, uint32_t *snapid, char *tag,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
Error *err = NULL;
|
||||||
URI *uri;
|
URI *uri;
|
||||||
QueryParams *qp = NULL;
|
QueryParams *qp = NULL;
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
uri = uri_parse(filename);
|
uri = uri_parse(filename);
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
return -EINVAL;
|
error_setg(&err, "invalid URI");
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* transport */
|
/* transport */
|
||||||
|
@ -977,34 +979,46 @@ static int sd_parse_uri(BDRVSheepdogState *s, const char *filename,
|
||||||
} else if (!strcmp(uri->scheme, "sheepdog+unix")) {
|
} else if (!strcmp(uri->scheme, "sheepdog+unix")) {
|
||||||
s->is_unix = true;
|
s->is_unix = true;
|
||||||
} else {
|
} else {
|
||||||
ret = -EINVAL;
|
error_setg(&err, "URI scheme must be 'sheepdog', 'sheepdog+tcp',"
|
||||||
|
" or 'sheepdog+unix'");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri->path == NULL || !strcmp(uri->path, "/")) {
|
if (uri->path == NULL || !strcmp(uri->path, "/")) {
|
||||||
ret = -EINVAL;
|
error_setg(&err, "missing file path in URI");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (g_strlcpy(vdi, uri->path + 1, SD_MAX_VDI_LEN) >= SD_MAX_VDI_LEN) {
|
if (g_strlcpy(vdi, uri->path + 1, SD_MAX_VDI_LEN) >= SD_MAX_VDI_LEN) {
|
||||||
ret = -EINVAL;
|
error_setg(&err, "VDI name is too long");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
qp = query_params_parse(uri->query);
|
qp = query_params_parse(uri->query);
|
||||||
if (qp->n > 1 || (s->is_unix && !qp->n) || (!s->is_unix && qp->n)) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->is_unix) {
|
if (s->is_unix) {
|
||||||
/* sheepdog+unix:///vdiname?socket=path */
|
/* sheepdog+unix:///vdiname?socket=path */
|
||||||
if (uri->server || uri->port || strcmp(qp->p[0].name, "socket")) {
|
if (uri->server || uri->port) {
|
||||||
ret = -EINVAL;
|
error_setg(&err, "URI scheme %s doesn't accept a server address",
|
||||||
|
uri->scheme);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (!qp->n) {
|
||||||
|
error_setg(&err,
|
||||||
|
"URI scheme %s requires query parameter 'socket'",
|
||||||
|
uri->scheme);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (qp->n != 1 || strcmp(qp->p[0].name, "socket")) {
|
||||||
|
error_setg(&err, "unexpected query parameters");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
s->host_spec = g_strdup(qp->p[0].value);
|
s->host_spec = g_strdup(qp->p[0].value);
|
||||||
} else {
|
} else {
|
||||||
/* sheepdog[+tcp]://[host:port]/vdiname */
|
/* sheepdog[+tcp]://[host:port]/vdiname */
|
||||||
|
if (qp->n) {
|
||||||
|
error_setg(&err, "unexpected query parameters");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
s->host_spec = g_strdup_printf("%s:%d", uri->server ?: SD_DEFAULT_ADDR,
|
s->host_spec = g_strdup_printf("%s:%d", uri->server ?: SD_DEFAULT_ADDR,
|
||||||
uri->port ?: SD_DEFAULT_PORT);
|
uri->port ?: SD_DEFAULT_PORT);
|
||||||
}
|
}
|
||||||
|
@ -1012,7 +1026,8 @@ static int sd_parse_uri(BDRVSheepdogState *s, const char *filename,
|
||||||
/* snapshot tag */
|
/* snapshot tag */
|
||||||
if (uri->fragment) {
|
if (uri->fragment) {
|
||||||
if (!sd_parse_snapid_or_tag(uri->fragment, snapid, tag)) {
|
if (!sd_parse_snapid_or_tag(uri->fragment, snapid, tag)) {
|
||||||
ret = -EINVAL;
|
error_setg(&err, "'%s' is not a valid snapshot ID",
|
||||||
|
uri->fragment);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1020,11 +1035,11 @@ static int sd_parse_uri(BDRVSheepdogState *s, const char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
error_propagate(errp, err);
|
||||||
if (qp) {
|
if (qp) {
|
||||||
query_params_free(qp);
|
query_params_free(qp);
|
||||||
}
|
}
|
||||||
uri_free(uri);
|
uri_free(uri);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1044,12 +1059,14 @@ out:
|
||||||
* You can run VMs outside the Sheepdog cluster by specifying
|
* You can run VMs outside the Sheepdog cluster by specifying
|
||||||
* `hostname' and `port' (experimental).
|
* `hostname' and `port' (experimental).
|
||||||
*/
|
*/
|
||||||
static int parse_vdiname(BDRVSheepdogState *s, const char *filename,
|
static void parse_vdiname(BDRVSheepdogState *s, const char *filename,
|
||||||
char *vdi, uint32_t *snapid, char *tag)
|
char *vdi, uint32_t *snapid, char *tag,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
Error *err = NULL;
|
||||||
char *p, *q, *uri;
|
char *p, *q, *uri;
|
||||||
const char *host_spec, *vdi_spec;
|
const char *host_spec, *vdi_spec;
|
||||||
int nr_sep, ret;
|
int nr_sep;
|
||||||
|
|
||||||
strstart(filename, "sheepdog:", &filename);
|
strstart(filename, "sheepdog:", &filename);
|
||||||
p = q = g_strdup(filename);
|
p = q = g_strdup(filename);
|
||||||
|
@ -1084,12 +1101,23 @@ static int parse_vdiname(BDRVSheepdogState *s, const char *filename,
|
||||||
|
|
||||||
uri = g_strdup_printf("sheepdog://%s/%s", host_spec, vdi_spec);
|
uri = g_strdup_printf("sheepdog://%s/%s", host_spec, vdi_spec);
|
||||||
|
|
||||||
ret = sd_parse_uri(s, uri, vdi, snapid, tag);
|
/*
|
||||||
|
* FIXME We to escape URI meta-characters, e.g. "x?y=z"
|
||||||
|
* produces "sheepdog://x?y=z". Because of that ...
|
||||||
|
*/
|
||||||
|
sd_parse_uri(s, uri, vdi, snapid, tag, &err);
|
||||||
|
if (err) {
|
||||||
|
/*
|
||||||
|
* ... this can fail, but the error message is misleading.
|
||||||
|
* Replace it by the traditional useless one until the
|
||||||
|
* escaping is fixed.
|
||||||
|
*/
|
||||||
|
error_free(err);
|
||||||
|
error_setg(errp, "Can't parse filename");
|
||||||
|
}
|
||||||
|
|
||||||
g_free(q);
|
g_free(q);
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_vdi_name(BDRVSheepdogState *s, const char *filename,
|
static int find_vdi_name(BDRVSheepdogState *s, const char *filename,
|
||||||
|
@ -1452,12 +1480,13 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
memset(tag, 0, sizeof(tag));
|
memset(tag, 0, sizeof(tag));
|
||||||
|
|
||||||
if (strstr(filename, "://")) {
|
if (strstr(filename, "://")) {
|
||||||
ret = sd_parse_uri(s, filename, vdi, &snapid, tag);
|
sd_parse_uri(s, filename, vdi, &snapid, tag, &local_err);
|
||||||
} else {
|
} else {
|
||||||
ret = parse_vdiname(s, filename, vdi, &snapid, tag);
|
parse_vdiname(s, filename, vdi, &snapid, tag, &local_err);
|
||||||
}
|
}
|
||||||
if (ret < 0) {
|
if (local_err) {
|
||||||
error_setg(errp, "Can't parse filename");
|
error_propagate(errp, local_err);
|
||||||
|
ret = -EINVAL;
|
||||||
goto err_no_fd;
|
goto err_no_fd;
|
||||||
}
|
}
|
||||||
s->fd = get_sheep_fd(s, errp);
|
s->fd = get_sheep_fd(s, errp);
|
||||||
|
@ -1785,6 +1814,7 @@ static int parse_block_size_shift(BDRVSheepdogState *s, QemuOpts *opt)
|
||||||
static int sd_create(const char *filename, QemuOpts *opts,
|
static int sd_create(const char *filename, QemuOpts *opts,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
Error *err = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint32_t vid = 0;
|
uint32_t vid = 0;
|
||||||
char *backing_file = NULL;
|
char *backing_file = NULL;
|
||||||
|
@ -1799,12 +1829,12 @@ static int sd_create(const char *filename, QemuOpts *opts,
|
||||||
|
|
||||||
memset(tag, 0, sizeof(tag));
|
memset(tag, 0, sizeof(tag));
|
||||||
if (strstr(filename, "://")) {
|
if (strstr(filename, "://")) {
|
||||||
ret = sd_parse_uri(s, filename, s->name, &snapid, tag);
|
sd_parse_uri(s, filename, s->name, &snapid, tag, &err);
|
||||||
} else {
|
} else {
|
||||||
ret = parse_vdiname(s, filename, s->name, &snapid, tag);
|
parse_vdiname(s, filename, s->name, &snapid, tag, &err);
|
||||||
}
|
}
|
||||||
if (ret < 0) {
|
if (err) {
|
||||||
error_setg(errp, "Can't parse filename");
|
error_propagate(errp, err);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue