All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Eric Blake" <eblake@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
	"Peter Lieven" <pl@kamp.de>,
	"Richard W.M. Jones" <rjones@redhat.com>,
	qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Konstantin Kostiuk" <kkostiuk@redhat.com>,
	qemu-block@nongnu.org
Subject: [PATCH for-9.1 5/9] block/gluster: Use URI parsing code from glib
Date: Thu, 28 Mar 2024 15:06:02 +0100	[thread overview]
Message-ID: <20240328140607.2433889-6-thuth@redhat.com> (raw)
In-Reply-To: <20240328140607.2433889-1-thuth@redhat.com>

Since version 2.66, glib has useful URI parsing functions, too.
Use those instead of the QEMU-internal ones to be finally able
to get rid of the latter.

Cc: integration@gluster.org
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 block/gluster.c | 63 +++++++++++++++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 26 deletions(-)

diff --git a/block/gluster.c b/block/gluster.c
index cc74af06dc..f4cb95360e 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -17,7 +17,6 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qerror.h"
-#include "qemu/uri.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
@@ -289,9 +288,9 @@ static void glfs_clear_preopened(glfs_t *fs)
     }
 }
 
-static int parse_volume_options(BlockdevOptionsGluster *gconf, char *path)
+static int parse_volume_options(BlockdevOptionsGluster *gconf, const char *path)
 {
-    char *p, *q;
+    const char *p, *q;
 
     if (!path) {
         return -EINVAL;
@@ -350,12 +349,15 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
                                   const char *filename)
 {
     SocketAddress *gsconf;
-    URI *uri;
-    QueryParams *qp = NULL;
+    GUri *uri;
+    GHashTable *qp = NULL;
+    int qp_n;
     bool is_unix = false;
     int ret = 0;
+    const char *uri_scheme, *uri_query, *uri_server;
+    int uri_port;
 
-    uri = uri_parse(filename);
+    uri = g_uri_parse(filename, G_URI_FLAGS_NONE, NULL);
     if (!uri) {
         return -EINVAL;
     }
@@ -364,14 +366,15 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
     QAPI_LIST_PREPEND(gconf->server, gsconf);
 
     /* transport */
-    if (!uri->scheme || !strcmp(uri->scheme, "gluster")) {
+    uri_scheme = g_uri_get_scheme(uri);
+    if (!uri_scheme || !strcmp(uri_scheme, "gluster")) {
         gsconf->type = SOCKET_ADDRESS_TYPE_INET;
-    } else if (!strcmp(uri->scheme, "gluster+tcp")) {
+    } else if (!strcmp(uri_scheme, "gluster+tcp")) {
         gsconf->type = SOCKET_ADDRESS_TYPE_INET;
-    } else if (!strcmp(uri->scheme, "gluster+unix")) {
+    } else if (!strcmp(uri_scheme, "gluster+unix")) {
         gsconf->type = SOCKET_ADDRESS_TYPE_UNIX;
         is_unix = true;
-    } else if (!strcmp(uri->scheme, "gluster+rdma")) {
+    } else if (!strcmp(uri_scheme, "gluster+rdma")) {
         gsconf->type = SOCKET_ADDRESS_TYPE_INET;
         warn_report("rdma feature is not supported, falling back to tcp");
     } else {
@@ -379,31 +382,39 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
         goto out;
     }
 
-    ret = parse_volume_options(gconf, uri->path);
+    ret = parse_volume_options(gconf, g_uri_get_path(uri));
     if (ret < 0) {
         goto out;
     }
 
-    qp = query_params_parse(uri->query);
-    if (qp->n > 1 || (is_unix && !qp->n) || (!is_unix && qp->n)) {
-        ret = -EINVAL;
-        goto out;
-    }
-
-    if (is_unix) {
-        if (uri->server || uri->port) {
+    uri_query = g_uri_get_query(uri);
+    if (uri_query) {
+        qp = g_uri_parse_params(uri_query, -1, "&", G_URI_PARAMS_NONE, NULL);
+        if (!qp) {
+            ret = -EINVAL;
+            goto out;
+        }
+        qp_n = g_hash_table_size(qp);
+        if (qp_n > 1 || (is_unix && !qp_n) || (!is_unix && qp_n)) {
             ret = -EINVAL;
             goto out;
         }
-        if (strcmp(qp->p[0].name, "socket")) {
+    }
+
+    uri_server = g_uri_get_host(uri);
+    uri_port = g_uri_get_port(uri);
+
+    if (is_unix) {
+        char *uri_socket = g_hash_table_lookup(qp, "socket");
+        if (uri_server || uri_port != -1 || !uri_socket) {
             ret = -EINVAL;
             goto out;
         }
-        gsconf->u.q_unix.path = g_strdup(qp->p[0].value);
+        gsconf->u.q_unix.path = g_strdup(uri_socket);
     } else {
-        gsconf->u.inet.host = g_strdup(uri->server ? uri->server : "localhost");
-        if (uri->port) {
-            gsconf->u.inet.port = g_strdup_printf("%d", uri->port);
+        gsconf->u.inet.host = g_strdup(uri_server ? uri_server : "localhost");
+        if (uri_port != -1) {
+            gsconf->u.inet.port = g_strdup_printf("%d", uri_port);
         } else {
             gsconf->u.inet.port = g_strdup_printf("%d", GLUSTER_DEFAULT_PORT);
         }
@@ -411,9 +422,9 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf,
 
 out:
     if (qp) {
-        query_params_free(qp);
+        g_hash_table_destroy(qp);
     }
-    uri_free(uri);
+    g_uri_unref(uri);
     return ret;
 }
 
-- 
2.44.0



  parent reply	other threads:[~2024-03-28 14:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 14:05 [PATCH for-9.1 0/9] Switch to glib URI parsing code Thomas Huth
2024-03-28 14:05 ` [PATCH for-9.1 1/9] tests: Remove Ubuntu 20.04 container Thomas Huth
2024-03-28 14:05 ` [PATCH for-9.1 2/9] tests/lcitool/libvirt-ci: Update to the latest master branch Thomas Huth
2024-03-28 14:06 ` [PATCH for-9.1 3/9] tests: Update our CI to use CentOS Stream 9 instead of 8 Thomas Huth
2024-03-28 14:06 ` [PATCH for-9.1 4/9] Bump minimum glib version to v2.66 Thomas Huth
2024-04-12 10:16   ` Paolo Bonzini
2024-04-12 10:58     ` Thomas Huth
2024-04-12 12:01       ` Paolo Bonzini
2024-03-28 14:06 ` Thomas Huth [this message]
2024-03-28 14:06 ` [PATCH for-9.1 6/9] block/nbd: Use URI parsing code from glib Thomas Huth
2024-03-28 14:13   ` Richard W.M. Jones
2024-03-28 15:06     ` Eric Blake
2024-03-28 16:40       ` Richard W.M. Jones
2024-04-04  9:47         ` Richard W.M. Jones
2024-03-28 14:54   ` Eric Blake
2024-03-28 14:59     ` Daniel P. Berrangé
2024-03-28 15:34       ` Thomas Huth
2024-03-28 14:06 ` [PATCH for-9.1 7/9] block/nfs: " Thomas Huth
2024-03-28 14:06 ` [PATCH for-9.1 8/9] block/ssh: " Thomas Huth
2024-03-28 14:15   ` Richard W.M. Jones
2024-03-28 14:06 ` [PATCH for-9.1 9/9] util/uri: Remove the old URI parsing code Thomas Huth
2024-04-15 14:16 ` MAINTAINERS tweak [was: [PATCH for-9.1 0/9] Switch to glib URI parsing code] Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240328140607.2433889-6-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    --cc=vsementsov@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.