From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 08/15] curl: Use bdrv_open options instead of filename
Date: Fri, 12 Apr 2013 22:48:01 +0200 [thread overview]
Message-ID: <1365799688-19918-9-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1365799688-19918-1-git-send-email-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/curl.c | 153 +++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 102 insertions(+), 51 deletions(-)
diff --git a/block/curl.c b/block/curl.c
index 186e3b0..61bc3db 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -335,12 +335,9 @@ static void curl_clean_state(CURLState *s)
s->in_use = 0;
}
-static int curl_open(BlockDriverState *bs, const char *filename,
- QDict *options, int flags)
+static void curl_parse_filename(const char *filename, QDict *options,
+ Error **errp)
{
- BDRVCURLState *s = bs->opaque;
- CURLState *state = NULL;
- double d;
#define RA_OPTSTR ":readahead="
char *file;
@@ -348,19 +345,17 @@ static int curl_open(BlockDriverState *bs, const char *filename,
const char *ra_val;
int parse_state = 0;
- static int inited = 0;
-
file = g_strdup(filename);
- s->readahead_size = READ_AHEAD_SIZE;
/* Parse a trailing ":readahead=#:" param, if present. */
ra = file + strlen(file) - 1;
while (ra >= file) {
if (parse_state == 0) {
- if (*ra == ':')
+ if (*ra == ':') {
parse_state++;
- else
+ } else {
break;
+ }
} else if (parse_state == 1) {
if (*ra > '9' || *ra < '0') {
char *opt_start = ra - strlen(RA_OPTSTR) + 1;
@@ -369,29 +364,78 @@ static int curl_open(BlockDriverState *bs, const char *filename,
ra_val = ra + 1;
ra -= strlen(RA_OPTSTR) - 1;
*ra = '\0';
- s->readahead_size = atoi(ra_val);
- break;
- } else {
- break;
+ qdict_put(options, "readahead", qstring_from_str(ra_val));
}
+ break;
}
}
ra--;
}
+ qdict_put(options, "url", qstring_from_str(file));
+
+ g_free(file);
+}
+
+static QemuOptsList runtime_opts = {
+ .name = "curl",
+ .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
+ .desc = {
+ {
+ .name = "url",
+ .type = QEMU_OPT_STRING,
+ .help = "URL to open",
+ },
+ {
+ .name = "readahead",
+ .type = QEMU_OPT_SIZE,
+ .help = "Readahead size",
+ },
+ { /* end of list */ }
+ },
+};
+
+static int curl_open(BlockDriverState *bs, const char *dummy,
+ QDict *options, int flags)
+{
+ BDRVCURLState *s = bs->opaque;
+ CURLState *state = NULL;
+ QemuOpts *opts;
+ Error *local_err = NULL;
+ const char *file;
+ double d;
+
+ static int inited = 0;
+
+ opts = qemu_opts_create_nofail(&runtime_opts);
+ qemu_opts_absorb_qdict(opts, options, &local_err);
+ if (error_is_set(&local_err)) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ goto out_noclean;
+ }
+
+ s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
if ((s->readahead_size & 0x1ff) != 0) {
fprintf(stderr, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
s->readahead_size);
goto out_noclean;
}
+ file = qemu_opt_get(opts, "url");
+ if (file == NULL) {
+ qerror_report(ERROR_CLASS_GENERIC_ERROR, "curl block driver requires "
+ "an 'url' option");
+ goto out_noclean;
+ }
+
if (!inited) {
curl_global_init(CURL_GLOBAL_ALL);
inited = 1;
}
DPRINTF("CURL: Opening %s\n", file);
- s->url = file;
+ s->url = g_strdup(file);
state = curl_init_state(s);
if (!state)
goto out_noclean;
@@ -423,6 +467,7 @@ static int curl_open(BlockDriverState *bs, const char *filename,
curl_multi_setopt( s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb );
curl_multi_do(s);
+ qemu_opts_del(opts);
return 0;
out:
@@ -430,7 +475,8 @@ out:
curl_easy_cleanup(state->curl);
state->curl = NULL;
out_noclean:
- g_free(file);
+ g_free(s->url);
+ qemu_opts_del(opts);
return -EINVAL;
}
@@ -568,63 +614,68 @@ static int64_t curl_getlength(BlockDriverState *bs)
}
static BlockDriver bdrv_http = {
- .format_name = "http",
- .protocol_name = "http",
+ .format_name = "http",
+ .protocol_name = "http",
- .instance_size = sizeof(BDRVCURLState),
- .bdrv_file_open = curl_open,
- .bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .instance_size = sizeof(BDRVCURLState),
+ .bdrv_parse_filename = curl_parse_filename,
+ .bdrv_file_open = curl_open,
+ .bdrv_close = curl_close,
+ .bdrv_getlength = curl_getlength,
- .bdrv_aio_readv = curl_aio_readv,
+ .bdrv_aio_readv = curl_aio_readv,
};
static BlockDriver bdrv_https = {
- .format_name = "https",
- .protocol_name = "https",
+ .format_name = "https",
+ .protocol_name = "https",
- .instance_size = sizeof(BDRVCURLState),
- .bdrv_file_open = curl_open,
- .bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .instance_size = sizeof(BDRVCURLState),
+ .bdrv_parse_filename = curl_parse_filename,
+ .bdrv_file_open = curl_open,
+ .bdrv_close = curl_close,
+ .bdrv_getlength = curl_getlength,
- .bdrv_aio_readv = curl_aio_readv,
+ .bdrv_aio_readv = curl_aio_readv,
};
static BlockDriver bdrv_ftp = {
- .format_name = "ftp",
- .protocol_name = "ftp",
+ .format_name = "ftp",
+ .protocol_name = "ftp",
- .instance_size = sizeof(BDRVCURLState),
- .bdrv_file_open = curl_open,
- .bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .instance_size = sizeof(BDRVCURLState),
+ .bdrv_parse_filename = curl_parse_filename,
+ .bdrv_file_open = curl_open,
+ .bdrv_close = curl_close,
+ .bdrv_getlength = curl_getlength,
- .bdrv_aio_readv = curl_aio_readv,
+ .bdrv_aio_readv = curl_aio_readv,
};
static BlockDriver bdrv_ftps = {
- .format_name = "ftps",
- .protocol_name = "ftps",
+ .format_name = "ftps",
+ .protocol_name = "ftps",
- .instance_size = sizeof(BDRVCURLState),
- .bdrv_file_open = curl_open,
- .bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .instance_size = sizeof(BDRVCURLState),
+ .bdrv_parse_filename = curl_parse_filename,
+ .bdrv_file_open = curl_open,
+ .bdrv_close = curl_close,
+ .bdrv_getlength = curl_getlength,
- .bdrv_aio_readv = curl_aio_readv,
+ .bdrv_aio_readv = curl_aio_readv,
};
static BlockDriver bdrv_tftp = {
- .format_name = "tftp",
- .protocol_name = "tftp",
+ .format_name = "tftp",
+ .protocol_name = "tftp",
- .instance_size = sizeof(BDRVCURLState),
- .bdrv_file_open = curl_open,
- .bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .instance_size = sizeof(BDRVCURLState),
+ .bdrv_parse_filename = curl_parse_filename,
+ .bdrv_file_open = curl_open,
+ .bdrv_close = curl_close,
+ .bdrv_getlength = curl_getlength,
- .bdrv_aio_readv = curl_aio_readv,
+ .bdrv_aio_readv = curl_aio_readv,
};
static void curl_block_init(void)
--
1.8.1.4
next prev parent reply other threads:[~2013-04-12 20:48 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-12 20:47 [Qemu-devel] [PATCH 00/15] block: Overriding the backing file with -drive Kevin Wolf
2013-04-12 20:47 ` [Qemu-devel] [PATCH 01/15] block: Fail gracefully when using a format driver on protocol level Kevin Wolf
2013-04-12 22:50 ` Eric Blake
2013-04-15 9:06 ` Kevin Wolf
2013-04-15 12:02 ` Markus Armbruster
2013-04-12 20:47 ` [Qemu-devel] [PATCH 02/15] block: Add driver-specific options for backing files Kevin Wolf
2013-04-15 17:38 ` Eric Blake
2013-04-12 20:47 ` [Qemu-devel] [PATCH 03/15] block: Enable filename option Kevin Wolf
2013-04-15 17:43 ` Eric Blake
2013-04-12 20:47 ` [Qemu-devel] [PATCH 04/15] raw-posix: Use bdrv_open options instead of filename Kevin Wolf
2013-04-15 17:52 ` Eric Blake
2013-04-12 20:47 ` [Qemu-devel] [PATCH 05/15] raw-win32: " Kevin Wolf
2013-04-15 19:16 ` Eric Blake
2013-04-12 20:47 ` [Qemu-devel] [PATCH 06/15] blkdebug: " Kevin Wolf
2013-04-15 19:43 ` Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 07/15] blkverify: " Kevin Wolf
2013-04-15 19:47 ` Eric Blake
2013-04-12 20:48 ` Kevin Wolf [this message]
2013-04-15 19:57 ` [Qemu-devel] [PATCH 08/15] curl: " Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 09/15] gluster: " Kevin Wolf
2013-04-15 20:07 ` Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 10/15] iscsi: " Kevin Wolf
2013-04-15 20:26 ` Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 11/15] rbd: " Kevin Wolf
2013-04-15 20:27 ` Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 12/15] sheepdog: " Kevin Wolf
2013-04-15 20:29 ` Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 13/15] vvfat: " Kevin Wolf
2013-04-15 20:44 ` Eric Blake
2013-04-12 20:48 ` [Qemu-devel] [PATCH 14/15] block: Remove filename parameter from .bdrv_file_open() Kevin Wolf
2013-04-15 20:47 ` Eric Blake
2013-04-22 9:41 ` [Qemu-devel] [PATCH v2 " Kevin Wolf
2013-04-12 20:48 ` [Qemu-devel] [PATCH 15/15] block: Allow overriding backing.file.filename Kevin Wolf
2013-04-15 21:03 ` Eric Blake
2013-04-18 11:42 ` [Qemu-devel] [PATCH 00/15] block: Overriding the backing file with -drive Stefan Hajnoczi
2013-04-18 13:34 ` Kevin Wolf
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=1365799688-19918-9-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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.