* [Qemu-devel] [PATCH 2/4] curl: Remove broken parsing of options from url
2014-05-14 23:28 [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available Matthew Booth
@ 2014-05-14 23:28 ` Matthew Booth
2014-05-14 23:28 ` [Qemu-devel] [PATCH 3/4] curl: Add sslverify option Matthew Booth
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Matthew Booth @ 2014-05-14 23:28 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
The block layer now supports a generic json syntax for passing option parameters
explicitly, making parsing of options from the url redundant.
Signed-off-by: Matthew Booth <mbooth@redhat.com>
---
block/curl.c | 52 ++++++++++------------------------------------------
1 file changed, 10 insertions(+), 42 deletions(-)
diff --git a/block/curl.c b/block/curl.c
index f3c797a..1b9f2f2 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -61,12 +61,15 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
#define CURL_NUM_STATES 8
#define CURL_NUM_ACB 8
#define SECTOR_SIZE 512
-#define READ_AHEAD_SIZE (256 * 1024)
+#define READ_AHEAD_DEFAULT (256 * 1024)
#define FIND_RET_NONE 0
#define FIND_RET_OK 1
#define FIND_RET_WAIT 2
+#define CURL_BLOCK_OPT_URL "url"
+#define CURL_BLOCK_OPT_READAHEAD "readahead"
+
struct BDRVCURLState;
typedef struct CURLAIOCB {
@@ -411,43 +414,7 @@ static void curl_clean_state(CURLState *s)
static void curl_parse_filename(const char *filename, QDict *options,
Error **errp)
{
-
- #define RA_OPTSTR ":readahead="
- char *file;
- char *ra;
- const char *ra_val;
- int parse_state = 0;
-
- file = g_strdup(filename);
-
- /* Parse a trailing ":readahead=#:" param, if present. */
- ra = file + strlen(file) - 1;
- while (ra >= file) {
- if (parse_state == 0) {
- if (*ra == ':') {
- parse_state++;
- } else {
- break;
- }
- } else if (parse_state == 1) {
- if (*ra > '9' || *ra < '0') {
- char *opt_start = ra - strlen(RA_OPTSTR) + 1;
- if (opt_start > file &&
- strncmp(opt_start, RA_OPTSTR, strlen(RA_OPTSTR)) == 0) {
- ra_val = ra + 1;
- ra -= strlen(RA_OPTSTR) - 1;
- *ra = '\0';
- qdict_put(options, "readahead", qstring_from_str(ra_val));
- }
- break;
- }
- }
- ra--;
- }
-
- qdict_put(options, "url", qstring_from_str(file));
-
- g_free(file);
+ qdict_put(options, CURL_BLOCK_OPT_URL, qstring_from_str(filename));
}
static QemuOptsList runtime_opts = {
@@ -455,12 +422,12 @@ static QemuOptsList runtime_opts = {
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
.desc = {
{
- .name = "url",
+ .name = CURL_BLOCK_OPT_URL,
.type = QEMU_OPT_STRING,
.help = "URL to open",
},
{
- .name = "readahead",
+ .name = CURL_BLOCK_OPT_READAHEAD,
.type = QEMU_OPT_SIZE,
.help = "Readahead size",
},
@@ -492,14 +459,15 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
goto out_noclean;
}
- s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
+ s->readahead_size = qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD,
+ READ_AHEAD_DEFAULT);
if ((s->readahead_size & 0x1ff) != 0) {
error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512",
s->readahead_size);
goto out_noclean;
}
- file = qemu_opt_get(opts, "url");
+ file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
if (file == NULL) {
error_setg(errp, "curl block driver requires an 'url' option");
goto out_noclean;
--
1.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/4] curl: Add sslverify option
2014-05-14 23:28 [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available Matthew Booth
2014-05-14 23:28 ` [Qemu-devel] [PATCH 2/4] curl: Remove broken parsing of options from url Matthew Booth
@ 2014-05-14 23:28 ` Matthew Booth
2014-05-15 11:33 ` Kevin Wolf
2014-05-14 23:28 ` [Qemu-devel] [PATCH 4/4] curl: Add usage documentation Matthew Booth
2014-05-15 11:35 ` [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available Kevin Wolf
3 siblings, 1 reply; 6+ messages in thread
From: Matthew Booth @ 2014-05-14 23:28 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
This allows qemu to use images over https with a self-signed certificate. It
defaults to verifying the certificate.
Signed-off-by: Matthew Booth <mbooth@redhat.com>
---
block/curl.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/block/curl.c b/block/curl.c
index 1b9f2f2..43d6646 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -23,6 +23,7 @@
*/
#include "qemu-common.h"
#include "block/block_int.h"
+#include "qapi/qmp/qbool.h"
#include <curl/curl.h>
// #define DEBUG
@@ -69,6 +70,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
#define CURL_BLOCK_OPT_URL "url"
#define CURL_BLOCK_OPT_READAHEAD "readahead"
+#define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
struct BDRVCURLState;
@@ -106,6 +108,7 @@ typedef struct BDRVCURLState {
CURLState states[CURL_NUM_STATES];
char *url;
size_t readahead_size;
+ bool sslverify;
bool accept_range;
} BDRVCURLState;
@@ -372,6 +375,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)
return NULL;
}
curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
+ curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER, s->sslverify);
curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
(void *)curl_read_cb);
@@ -431,6 +435,11 @@ static QemuOptsList runtime_opts = {
.type = QEMU_OPT_SIZE,
.help = "Readahead size",
},
+ {
+ .name = CURL_BLOCK_OPT_SSLVERIFY,
+ .type = QEMU_OPT_BOOL,
+ .help = "Verify SSL certificate"
+ },
{ /* end of list */ }
},
};
@@ -467,6 +476,8 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
goto out_noclean;
}
+ s->sslverify = qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, true);
+
file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
if (file == NULL) {
error_setg(errp, "curl block driver requires an 'url' option");
--
1.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 3/4] curl: Add sslverify option
2014-05-14 23:28 ` [Qemu-devel] [PATCH 3/4] curl: Add sslverify option Matthew Booth
@ 2014-05-15 11:33 ` Kevin Wolf
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2014-05-15 11:33 UTC (permalink / raw)
To: Matthew Booth; +Cc: qemu-devel
Am 15.05.2014 um 01:28 hat Matthew Booth geschrieben:
> This allows qemu to use images over https with a self-signed certificate. It
> defaults to verifying the certificate.
>
> Signed-off-by: Matthew Booth <mbooth@redhat.com>
> ---
> block/curl.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/block/curl.c b/block/curl.c
> index 1b9f2f2..43d6646 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -23,6 +23,7 @@
> */
> #include "qemu-common.h"
> #include "block/block_int.h"
> +#include "qapi/qmp/qbool.h"
> #include <curl/curl.h>
>
> // #define DEBUG
> @@ -69,6 +70,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
>
> #define CURL_BLOCK_OPT_URL "url"
> #define CURL_BLOCK_OPT_READAHEAD "readahead"
> +#define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
>
> struct BDRVCURLState;
>
> @@ -106,6 +108,7 @@ typedef struct BDRVCURLState {
> CURLState states[CURL_NUM_STATES];
> char *url;
> size_t readahead_size;
> + bool sslverify;
> bool accept_range;
> } BDRVCURLState;
>
> @@ -372,6 +375,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)
> return NULL;
> }
> curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
> + curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER, s->sslverify);
block/curl.c: In function 'curl_init_state':
block/curl.c:378:1043: error: call to '_curl_easy_setopt_err_long' declared with attribute warning: curl_easy_setopt expects a long argument for this option [-Werror]
curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER, s->sslverify);
Squashing in this hunk:
--- a/block/curl.c
+++ b/block/curl.c
@@ -375,7 +375,8 @@ static CURLState *curl_init_state(BDRVCURLState *s)
return NULL;
}
curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
- curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER, s->sslverify);
+ curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER,
+ (long) s->sslverify);
curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
(void *)curl_read_cb);
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 4/4] curl: Add usage documentation
2014-05-14 23:28 [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available Matthew Booth
2014-05-14 23:28 ` [Qemu-devel] [PATCH 2/4] curl: Remove broken parsing of options from url Matthew Booth
2014-05-14 23:28 ` [Qemu-devel] [PATCH 3/4] curl: Add sslverify option Matthew Booth
@ 2014-05-14 23:28 ` Matthew Booth
2014-05-15 11:35 ` [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available Kevin Wolf
3 siblings, 0 replies; 6+ messages in thread
From: Matthew Booth @ 2014-05-14 23:28 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf
Signed-off-by: Matthew Booth <mbooth@redhat.com>
---
qemu-options.hx | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/qemu-options.hx b/qemu-options.hx
index 781af14..7587bce 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2191,6 +2191,74 @@ qemu-system-x86_64 --drive file=gluster://192.0.2.1/testvol/a.img
@end example
See also @url{http://www.gluster.org}.
+
+@item HTTP/HTTPS/FTP/FTPS/TFTP
+QEMU supports read-only access to files accessed over http(s), ftp(s) and tftp.
+
+Syntax using a single filename:
+@example
+<protocol>://[<username>[:<password>]@@]<host>/<path>
+@end example
+
+where:
+@table @option
+@item protocol
+'http', 'https', 'ftp', 'ftps', or 'tftp'.
+
+@item username
+Optional username for authentication to the remote server.
+
+@item password
+Optional password for authentication to the remote server.
+
+@item host
+Address of the remote server.
+
+@item path
+Path on the remote server, including any query string.
+@end table
+
+The following options are also supported:
+@table @option
+@item url
+The full URL when passing options to the driver explicitly.
+
+@item readahead
+The amount of data to read ahead with each range request to the remote server.
+This value may optionally have the suffix 'T', 'G', 'M', 'K', 'k' or 'b'. If it
+does not have a suffix, it will be assumed to be in bytes. The value must be a
+multiple of 512 bytes. It defaults to 256k.
+
+@item sslverify
+Whether to verify the remote server's certificate when connecting over SSL. It
+can have the value 'on' or 'off'. It defaults to 'on'.
+@end table
+
+Note that when passing options to qemu explicitly, @option{driver} is the value
+of <protocol>.
+
+Example: boot from a remote Fedora 20 live ISO image
+@example
+qemu-system-x86_64 --drive media=cdrom,file=http://dl.fedoraproject.org/pub/fedora/linux/releases/20/Live/x86_64/Fedora-Live-Desktop-x86_64-20-1.iso,readonly
+
+qemu-system-x86_64 --drive media=cdrom,file.driver=http,file.url=http://dl.fedoraproject.org/pub/fedora/linux/releases/20/Live/x86_64/Fedora-Live-Desktop-x86_64-20-1.iso,readonly
+@end example
+
+Example: boot from a remote Fedora 20 cloud image using a local overlay for
+writes, copy-on-read, and a readahead of 64k
+@example
+qemu-img create -f qcow2 -o backing_file='json:@{"file.driver":"http",, "file.url":"https://dl.fedoraproject.org/pub/fedora/linux/releases/20/Images/x86_64/Fedora-x86_64-20-20131211.1-sda.qcow2",, "file.readahead":"64k"@}' /tmp/Fedora-x86_64-20-20131211.1-sda.qcow2
+
+qemu-system-x86_64 -drive file=/tmp/Fedora-x86_64-20-20131211.1-sda.qcow2,copy-on-read=on
+@end example
+
+Example: boot from an image stored on a VMware vSphere server with a self-signed
+certificate using a local overlay for writes and a readahead of 64k
+@example
+qemu-img create -f qcow2 -o backing_file='json:@{"file.driver":"https",, "file.url":"https://user:password@@vsphere.example.com/folder/test/test-flat.vmdk?dcPath=Datacenter&dsName=datastore1",, "file.sslverify":"off",, "file.readahead":"64k"@}' /tmp/test.qcow2
+
+qemu-system-x86_64 -drive file=/tmp/test.qcow2
+@end example
ETEXI
STEXI
--
1.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available
2014-05-14 23:28 [Qemu-devel] [PATCH 1/4] curl: Fix build when curl_multi_socket_action isn't available Matthew Booth
` (2 preceding siblings ...)
2014-05-14 23:28 ` [Qemu-devel] [PATCH 4/4] curl: Add usage documentation Matthew Booth
@ 2014-05-15 11:35 ` Kevin Wolf
3 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2014-05-15 11:35 UTC (permalink / raw)
To: Matthew Booth; +Cc: qemu-devel
Am 15.05.2014 um 01:28 hat Matthew Booth geschrieben:
> Signed-off-by: Matthew Booth <mbooth@redhat.com>
> ---
> block/curl.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
Thanks, applied all to the block branch (with patch 3 fixed as commented
there).
Please don't forget --cover-letter and --subject-prefix="PATCH v2" next
time, that makes it easier to reply to the whole series and to keep
track of the current version.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread