[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/13] block/nbd: auto-ify URI parsing variables
From: |
Marc-André Lureau |
Subject: |
[PATCH 02/13] block/nbd: auto-ify URI parsing variables |
Date: |
Thu, 9 Jul 2020 23:42:23 +0400 |
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
block/nbd.c | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index eed160c5cda..faadcab442b 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -1516,10 +1516,9 @@ static int nbd_client_connect(BlockDriverState *bs,
Error **errp)
static int nbd_parse_uri(const char *filename, QDict *options)
{
- URI *uri;
+ g_autoptr(URI) uri = NULL;
+ g_autoptr(QueryParams) qp = NULL;
const char *p;
- QueryParams *qp = NULL;
- int ret = 0;
bool is_unix;
uri = uri_parse(filename);
@@ -1535,8 +1534,7 @@ static int nbd_parse_uri(const char *filename, QDict
*options)
} else if (!g_strcmp0(uri->scheme, "nbd+unix")) {
is_unix = true;
} else {
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
p = uri->path ? uri->path : "";
@@ -1549,26 +1547,23 @@ static int nbd_parse_uri(const char *filename, QDict
*options)
qp = query_params_parse(uri->query);
if (qp->n > 1 || (is_unix && !qp->n) || (!is_unix && qp->n)) {
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
if (is_unix) {
/* nbd+unix:///export?socket=path */
if (uri->server || uri->port || strcmp(qp->p[0].name, "socket")) {
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
qdict_put_str(options, "server.type", "unix");
qdict_put_str(options, "server.path", qp->p[0].value);
} else {
QString *host;
- char *port_str;
+ g_autofree char *port_str = NULL;
/* nbd[+tcp]://host[:port]/export */
if (!uri->server) {
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
/* strip braces from literal IPv6 address */
@@ -1584,15 +1579,9 @@ static int nbd_parse_uri(const char *filename, QDict
*options)
port_str = g_strdup_printf("%d", uri->port ?: NBD_DEFAULT_PORT);
qdict_put_str(options, "server.port", port_str);
- g_free(port_str);
}
-out:
- if (qp) {
- query_params_free(qp);
- }
- uri_free(uri);
- return ret;
+ return 0;
}
static bool nbd_has_filename_options_conflict(QDict *options, Error **errp)
--
2.27.0.221.ga08a83db2b
- [PATCH 00/13] RFC: use upcoming GUri for URI handling, Marc-André Lureau, 2020/07/09
- [PATCH 01/13] uri: add g_auto macros for URI & QueryParams, Marc-André Lureau, 2020/07/09
- [PATCH 02/13] block/nbd: auto-ify URI parsing variables,
Marc-André Lureau <=
- [PATCH 03/13] block/vxhs: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 04/13] block/sheepdog: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 05/13] block/ssh: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 06/13] block/nfs: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 07/13] block/gluster: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 08/13] build-sys: add HAVE_GLIB_GURI, Marc-André Lureau, 2020/07/09
- [PATCH 09/13] nbd: add GUri-based URI parsing version, Marc-André Lureau, 2020/07/09
- [PATCH 10/13] sheepdog: add GUri-based URI parsing, Marc-André Lureau, 2020/07/09