mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0025-v2v-rvh-upload-plugin-Always-read-the-response.patch

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