9ae3a8
From d935f2a3eafd649a2b40c27c8b6f8536a2e486e5 Mon Sep 17 00:00:00 2001
9ae3a8
From: Richard Jones <rjones@redhat.com>
9ae3a8
Date: Thu, 11 Jun 2015 11:40:20 +0200
9ae3a8
Subject: [PATCH 20/30] curl: Remove broken parsing of options from url
9ae3a8
9ae3a8
Message-id: <1434022828-13037-14-git-send-email-rjones@redhat.com>
9ae3a8
Patchwork-id: 65848
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm v3 PATCH 13/21] curl: Remove broken parsing of options from url
9ae3a8
Bugzilla: 1226684
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
From: Matthew Booth <mbooth@redhat.com>
9ae3a8
9ae3a8
The block layer now supports a generic json syntax for passing option parameters
9ae3a8
explicitly, making parsing of options from the url redundant.
9ae3a8
9ae3a8
Signed-off-by: Matthew Booth <mbooth@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
Upstream-status: e3542c67af4cb4fd90e3be912630be9acd97b9c0
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/curl.c | 52 ++++++++++------------------------------------------
9ae3a8
 1 file changed, 10 insertions(+), 42 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/curl.c b/block/curl.c
9ae3a8
index be2d3f4..67ea05f 100644
9ae3a8
--- a/block/curl.c
9ae3a8
+++ b/block/curl.c
9ae3a8
@@ -61,12 +61,15 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
9ae3a8
 #define CURL_NUM_STATES 8
9ae3a8
 #define CURL_NUM_ACB    8
9ae3a8
 #define SECTOR_SIZE     512
9ae3a8
-#define READ_AHEAD_SIZE (256 * 1024)
9ae3a8
+#define READ_AHEAD_DEFAULT (256 * 1024)
9ae3a8
 
9ae3a8
 #define FIND_RET_NONE   0
9ae3a8
 #define FIND_RET_OK     1
9ae3a8
 #define FIND_RET_WAIT   2
9ae3a8
 
9ae3a8
+#define CURL_BLOCK_OPT_URL       "url"
9ae3a8
+#define CURL_BLOCK_OPT_READAHEAD "readahead"
9ae3a8
+
9ae3a8
 struct BDRVCURLState;
9ae3a8
 
9ae3a8
 typedef struct CURLAIOCB {
9ae3a8
@@ -411,43 +414,7 @@ static void curl_clean_state(CURLState *s)
9ae3a8
 static void curl_parse_filename(const char *filename, QDict *options,
9ae3a8
                                 Error **errp)
9ae3a8
 {
9ae3a8
-
9ae3a8
-    #define RA_OPTSTR ":readahead="
9ae3a8
-    char *file;
9ae3a8
-    char *ra;
9ae3a8
-    const char *ra_val;
9ae3a8
-    int parse_state = 0;
9ae3a8
-
9ae3a8
-    file = g_strdup(filename);
9ae3a8
-
9ae3a8
-    /* Parse a trailing ":readahead=#:" param, if present. */
9ae3a8
-    ra = file + strlen(file) - 1;
9ae3a8
-    while (ra >= file) {
9ae3a8
-        if (parse_state == 0) {
9ae3a8
-            if (*ra == ':') {
9ae3a8
-                parse_state++;
9ae3a8
-            } else {
9ae3a8
-                break;
9ae3a8
-            }
9ae3a8
-        } else if (parse_state == 1) {
9ae3a8
-            if (*ra > '9' || *ra < '0') {
9ae3a8
-                char *opt_start = ra - strlen(RA_OPTSTR) + 1;
9ae3a8
-                if (opt_start > file &&
9ae3a8
-                    strncmp(opt_start, RA_OPTSTR, strlen(RA_OPTSTR)) == 0) {
9ae3a8
-                    ra_val = ra + 1;
9ae3a8
-                    ra -= strlen(RA_OPTSTR) - 1;
9ae3a8
-                    *ra = '\0';
9ae3a8
-                    qdict_put(options, "readahead", qstring_from_str(ra_val));
9ae3a8
-                }
9ae3a8
-                break;
9ae3a8
-            }
9ae3a8
-        }
9ae3a8
-        ra--;
9ae3a8
-    }
9ae3a8
-
9ae3a8
-    qdict_put(options, "url", qstring_from_str(file));
9ae3a8
-
9ae3a8
-    g_free(file);
9ae3a8
+    qdict_put(options, CURL_BLOCK_OPT_URL, qstring_from_str(filename));
9ae3a8
 }
9ae3a8
 
9ae3a8
 static QemuOptsList runtime_opts = {
9ae3a8
@@ -455,12 +422,12 @@ static QemuOptsList runtime_opts = {
9ae3a8
     .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
9ae3a8
     .desc = {
9ae3a8
         {
9ae3a8
-            .name = "url",
9ae3a8
+            .name = CURL_BLOCK_OPT_URL,
9ae3a8
             .type = QEMU_OPT_STRING,
9ae3a8
             .help = "URL to open",
9ae3a8
         },
9ae3a8
         {
9ae3a8
-            .name = "readahead",
9ae3a8
+            .name = CURL_BLOCK_OPT_READAHEAD,
9ae3a8
             .type = QEMU_OPT_SIZE,
9ae3a8
             .help = "Readahead size",
9ae3a8
         },
9ae3a8
@@ -488,14 +455,15 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
         goto out_noclean;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
9ae3a8
+    s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,
9ae3a8
+                                          READ_AHEAD_DEFAULT);
9ae3a8
     if ((s->readahead_size & 0x1ff) != 0) {
9ae3a8
         fprintf(stderr, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
9ae3a8
                 s->readahead_size);
9ae3a8
         goto out_noclean;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    file = qemu_opt_get(opts, "url");
9ae3a8
+    file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
9ae3a8
     if (file == NULL) {
9ae3a8
         qerror_report(ERROR_CLASS_GENERIC_ERROR, "curl block driver requires "
9ae3a8
                       "an 'url' option");
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8