|
|
97ae69 |
From 320ba554d11f75c4c2753968505a1d3308b64dda Mon Sep 17 00:00:00 2001
|
|
|
97ae69 |
From: Nir Soffer <nirsof@gmail.com>
|
|
|
97ae69 |
Date: Mon, 25 Jun 2018 19:22:13 +0300
|
|
|
97ae69 |
Subject: [PATCH] v2v: rvh-upload-plugin: Always read the response
|
|
|
97ae69 |
|
|
|
97ae69 |
Python manual warns[1]:
|
|
|
97ae69 |
|
|
|
97ae69 |
Note that you must have read the whole response before you can send
|
|
|
97ae69 |
a new request to the server.
|
|
|
97ae69 |
|
|
|
97ae69 |
The reason for this warning is exposed only when the server is using
|
|
|
97ae69 |
keep alive connections. When the response is not read, sending a new
|
|
|
97ae69 |
request will fail with:
|
|
|
97ae69 |
|
|
|
97ae69 |
httplib.ResponseNotReady
|
|
|
97ae69 |
|
|
|
97ae69 |
Even if Content-Length was 0 or the request has no content. The failure
|
|
|
97ae69 |
looks like this when using --verbose:
|
|
|
97ae69 |
|
|
|
97ae69 |
nbdkit: python[1]: debug: zero count=33554432 offset=0 may_trim=1 fua=0
|
|
|
97ae69 |
nbdkit: python[1]: debug: zero count=33554432 offset=33554432 may_trim=1 fua=0
|
|
|
97ae69 |
nbdkit: python[1]: error: /home/nsoffer/src/libguestfs/tmp/rhvupload.Au2B5I/rhv-upload-plugin.py: zero: error: Request-sent
|
|
|
97ae69 |
nbdkit: python[1]: debug: sending error reply: Input/output error
|
|
|
97ae69 |
qemu-img: error writing zeroes at offset 0: Input/output error
|
|
|
97ae69 |
|
|
|
97ae69 |
Change all requests to read the whole response.
|
|
|
97ae69 |
|
|
|
97ae69 |
Tested with imageio patch supporting keep alive connections:
|
|
|
97ae69 |
https://gerrit.ovirt.org/#/c/92296/
|
|
|
97ae69 |
|
|
|
97ae69 |
[1] https://docs.python.org/3.8/library/http.client.html#http.client.HTTPConnection.getresponse
|
|
|
97ae69 |
|
|
|
97ae69 |
(cherry picked from commit f4e0a8342dbeb2c779c76e1807a37b24a0c96feb)
|
|
|
97ae69 |
---
|
|
|
97ae69 |
v2v/rhv-upload-plugin.py | 15 ++++++++++++++-
|
|
|
97ae69 |
1 file changed, 14 insertions(+), 1 deletion(-)
|
|
|
97ae69 |
|
|
|
97ae69 |
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
|
|
|
97ae69 |
index 7c5084efd..2eec375f7 100644
|
|
|
97ae69 |
--- a/v2v/rhv-upload-plugin.py
|
|
|
97ae69 |
+++ b/v2v/rhv-upload-plugin.py
|
|
|
97ae69 |
@@ -197,11 +197,13 @@ def get_options(h):
|
|
|
97ae69 |
http.endheaders()
|
|
|
97ae69 |
|
|
|
97ae69 |
r = http.getresponse()
|
|
|
97ae69 |
+ data = r.read()
|
|
|
97ae69 |
+
|
|
|
97ae69 |
if r.status == 200:
|
|
|
97ae69 |
# New imageio never needs authentication.
|
|
|
97ae69 |
h['needs_auth'] = False
|
|
|
97ae69 |
|
|
|
97ae69 |
- j = json.loads(r.read())
|
|
|
97ae69 |
+ j = json.loads(data)
|
|
|
97ae69 |
h['can_zero'] = "zero" in j['features']
|
|
|
97ae69 |
h['can_trim'] = "trim" in j['features']
|
|
|
97ae69 |
h['can_flush'] = "flush" in j['features']
|
|
|
97ae69 |
@@ -276,6 +278,7 @@ def pread(h, count, offset):
|
|
|
97ae69 |
request_failed(h, r,
|
|
|
97ae69 |
"could not read sector offset %d size %d" %
|
|
|
97ae69 |
(offset, count))
|
|
|
97ae69 |
+
|
|
|
97ae69 |
return r.read()
|
|
|
97ae69 |
|
|
|
97ae69 |
def pwrite(h, buf, offset):
|
|
|
97ae69 |
@@ -302,6 +305,8 @@ def pwrite(h, buf, offset):
|
|
|
97ae69 |
"could not write sector offset %d size %d" %
|
|
|
97ae69 |
(offset, count))
|
|
|
97ae69 |
|
|
|
97ae69 |
+ r.read()
|
|
|
97ae69 |
+
|
|
|
97ae69 |
def zero(h, count, offset, may_trim):
|
|
|
97ae69 |
http = h['http']
|
|
|
97ae69 |
transfer = h['transfer']
|
|
|
97ae69 |
@@ -330,6 +335,8 @@ def zero(h, count, offset, may_trim):
|
|
|
97ae69 |
"could not zero sector offset %d size %d" %
|
|
|
97ae69 |
(offset, count))
|
|
|
97ae69 |
|
|
|
97ae69 |
+ r.read()
|
|
|
97ae69 |
+
|
|
|
97ae69 |
def emulate_zero(h, count, offset):
|
|
|
97ae69 |
# qemu-img convert starts by trying to zero/trim the whole device.
|
|
|
97ae69 |
# Since we've just created a new disk it's safe to ignore these
|
|
|
97ae69 |
@@ -357,6 +364,8 @@ def emulate_zero(h, count, offset):
|
|
|
97ae69 |
"could not write zeroes offset %d size %d" %
|
|
|
97ae69 |
(offset, count))
|
|
|
97ae69 |
|
|
|
97ae69 |
+ r.read()
|
|
|
97ae69 |
+
|
|
|
97ae69 |
def trim(h, count, offset):
|
|
|
97ae69 |
http = h['http']
|
|
|
97ae69 |
transfer = h['transfer']
|
|
|
97ae69 |
@@ -378,6 +387,8 @@ def trim(h, count, offset):
|
|
|
97ae69 |
"could not trim sector offset %d size %d" %
|
|
|
97ae69 |
(offset, count))
|
|
|
97ae69 |
|
|
|
97ae69 |
+ r.read()
|
|
|
97ae69 |
+
|
|
|
97ae69 |
def flush(h):
|
|
|
97ae69 |
http = h['http']
|
|
|
97ae69 |
transfer = h['transfer']
|
|
|
97ae69 |
@@ -394,6 +405,8 @@ def flush(h):
|
|
|
97ae69 |
if r.status != 200:
|
|
|
97ae69 |
request_failed(h, r, "could not flush")
|
|
|
97ae69 |
|
|
|
97ae69 |
+ r.read()
|
|
|
97ae69 |
+
|
|
|
97ae69 |
def delete_disk_on_failure(h):
|
|
|
97ae69 |
disk_service = h['disk_service']
|
|
|
97ae69 |
disk_service.remove()
|
|
|
97ae69 |
--
|
|
|
97ae69 |
2.17.1
|
|
|
97ae69 |
|