Skip to contentSkip to conversation

curl: Add override_accept_ranges flag to force sending range

PATCH New Richard W.M. Jones 5 participants 8 messages Aug 26, 2014 – Aug 27, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 curl: Add override_accept_ranges flag to force sending range

If you use this patch + Daniel Henrique Barboza's patch that adds a timeout, then you can access guest files on VMware ESX servers.

Rich.

#1 lore raw

PATCH 1/1 curl: Add override_accept_ranges flag to force sending range requests.

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

---
 block/curl.c    | 10 +++++++++-
 qemu-options.hx |  5 +++++
 2 files changed, 14 insertions(+), 1 deletion(-)
block/curl.c +9 -1
index 095b5a4..3905c6e 100644
@@ -71,6 +71,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"
+#define CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES "override_accept_ranges"
 
 struct BDRVCURLState;
 
@@ -489,6 +490,11 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_BOOL,
             .help = "Verify SSL certificate"
         },
+        {
+            .name = CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+            .type = QEMU_OPT_BOOL,
+            .help = "Server accepts range requests"
+        },
         { /* end of list */ }
     },
 };
@@ -547,7 +553,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
 
     // Get file size
 
-    s->accept_range = false;
+    s->accept_range =
+        qemu_opt_get_bool(opts, CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+                          false);
     curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
     curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
                      curl_header_cb);
qemu-options.hx +5 -0
index c573dd8..626ebb3 100644
@@ -2351,6 +2351,11 @@ 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'.
+
+@item override_accept_ranges
+Some servers (notably VMware ESX) accept range requests, but don't
+declare this fact in the headers that they return. Setting this option
+to 'on' forces CURL to use range requests. The default is 'off'.
 @end table
 
 Note that when passing options to qemu explicitly, @option{driver} is the value
Signature · 1 line
2.0.4
Reviewed-by on v1 1/1
#2 lore raw

Re: [Qemu-devel] [PATCH] curl: Add override_accept_ranges flag to force sending range requests.

Quoted 67 lines · Richard W.M. Jones

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

---
 block/curl.c    | 10 +++++++++-
 qemu-options.hx |  5 +++++
 2 files changed, 14 insertions(+), 1 deletion(-)
block/curl.c +9 -1
index 095b5a4..3905c6e 100644
@@ -71,6 +71,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"
+#define CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES "override_accept_ranges"
 
 struct BDRVCURLState;
 
@@ -489,6 +490,11 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_BOOL,
             .help = "Verify SSL certificate"
         },
+        {
+            .name = CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+            .type = QEMU_OPT_BOOL,
+            .help = "Server accepts range requests"
+        },
         { /* end of list */ }
     },
 };
@@ -547,7 +553,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
 
     // Get file size
 
-    s->accept_range = false;
+    s->accept_range =
+        qemu_opt_get_bool(opts, CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+                          false);
     curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
     curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
                      curl_header_cb);
qemu-options.hx +5 -0
index c573dd8..626ebb3 100644
@@ -2351,6 +2351,11 @@ 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'.
+
+@item override_accept_ranges
+Some servers (notably VMware ESX) accept range requests, but don't
+declare this fact in the headers that they return. Setting this option
+to 'on' forces CURL to use range requests. The default is 'off'.
 @end table
 
 Note that when passing options to qemu explicitly, @option{driver} is the value
Signature · 1 line
2.0.4
#3 lore raw

Re: [Qemu-devel] [PATCH] curl: Add override_accept_ranges flag to force sending range requests.

Quoted 6 lines · Fam Zheng
Quoted 5 lines · Richard W.M. Jones

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

Is this a case where we should be naming with dashes instead of underscores, as in override-accept-ranges?

Quoted 9 lines

block/curl.c static QemuOptsList runtime_opts = { · line 497

Quoted 9 lines
block/curl.c +5 -0
@@ -489,6 +490,11 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_BOOL,
             .help = "Verify SSL certificate"
         },
+        {
+            .name = CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+            .type = QEMU_OPT_BOOL,
+            .help = "Server accepts range requests"
+        },

It would be nice for someone to finally port the QAPI counterpart (BlockdevOptions) so that curl devices can be hotplugged via blockdev-add. But I guess that's a separate patch.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH] curl: Add override_accept_ranges flag to force sending range requests.

Quoted 10 lines · Eric Blake
Quoted 6 lines · Fam Zheng
Quoted 5 lines · Richard W.M. Jones

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

Is this a case where we should be naming with dashes instead of underscores, as in override-accept-ranges?

Yes.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
block/curl.c +1 -0
@@ -489,6 +490,11 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_BOOL,
             .help = "Verify SSL certificate"
         },
+        {
Quoted 8 lines
Quoted 4 lines

block/curl.c static QemuOptsList runtime_opts = { · line 497

Quoted 4 lines
block/curl.c +4 -0
+            .name = CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+            .type = QEMU_OPT_BOOL,
+            .help = "Server accepts range requests"
+        },

It would be nice for someone to finally port the QAPI counterpart (BlockdevOptions) so that curl devices can be hotplugged via blockdev-add. But I guess that's a separate patch.

Yes again.

#5 lore raw

Re: [Qemu-devel] [PATCH] curl: Add override_accept_ranges flag to force sending range requests.

Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Eric Blake
Quoted 4 lines · Fam Zheng
Quoted 3 lines · Richard W.M. Jones

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

Is this a case where we should be naming with dashes instead of underscores, as in override-accept-ranges?

Yes.

Thanks for reviewing. I'm actually going to drop this for a couple of reasons:

- VMware vSphere does send the header, only ESX doesn't.

- When you access ESX (using this patch) eventually the ESX web server crashes. In a sense ESX was correct that it doesn't support ranges -- because it's buggy.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
#6 lore raw

Re: [Qemu-devel] [PATCH] curl: Add override_accept_ranges flag to force sending range requests.

In reply to Eric Blake
Quoted 10 lines · Eric Blake
Quoted 6 lines · Fam Zheng
Quoted 5 lines · Richard W.M. Jones

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

Is this a case where we should be naming with dashes instead of underscores, as in override-accept-ranges?

Yes.

I'm not particularly happy with the long name either, but couldn't think of anything shorter.

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
Reviewed-by Tested-by on v1 1/1
#7 lore raw

Re: [Qemu-devel] [PATCH] curl: Add override_accept_ranges flag to force sending range requests.

In reply to Richard W.M. Jones
Quoted 53 lines · Richard W.M. Jones

Some servers (notably VMware ESX) accept range requests, but don't send back the Accept-Ranges: bytes header in their initial response.

For these servers you can set override_accept_ranges to 'on' which forces this block driver to send range requests anyway.

---
  block/curl.c    | 10 +++++++++-
  qemu-options.hx |  5 +++++
  2 files changed, 14 insertions(+), 1 deletion(-)
block/curl.c +9 -1
index 095b5a4..3905c6e 100644
@@ -71,6 +71,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"
+#define CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES "override_accept_ranges"
 
  struct BDRVCURLState;
 
@@ -489,6 +490,11 @@ static QemuOptsList runtime_opts = {
              .type = QEMU_OPT_BOOL,
              .help = "Verify SSL certificate"
          },
+        {
+            .name = CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+            .type = QEMU_OPT_BOOL,
+            .help = "Server accepts range requests"
+        },
          { /* end of list */ }
      },
  };
@@ -547,7 +553,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
 
      // Get file size
 
-    s->accept_range = false;
+    s->accept_range =
+        qemu_opt_get_bool(opts, CURL_BLOCK_OPT_OVERRIDE_ACCEPT_RANGES,
+                          false);
      curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
      curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
                       curl_header_cb);
qemu-options.hx +0 -0
index c573dd8..626ebb3 100644
@@ -2351,6 +2351,11 @@ multiple of 512 bytes. It defaults to 256k.
  @item sslverify

qemu-options.hx multiple of 512 bytes. It defaults to 256k. · line 2361

Quoted 10 lines
qemu-options.hx +5 -0
  Whether to verify the remote server's certificate when connecting over SSL. It
  can have the value 'on' or 'off'. It defaults to 'on'.
+
+@item override_accept_ranges
+Some servers (notably VMware ESX) accept range requests, but don't
+declare this fact in the headers that they return. Setting this option
+to 'on' forces CURL to use range requests. The default is 'off'.
  @end table
 
  Note that when passing options to qemu explicitly, @option{driver} is the value