[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 3/3] v2v: rhv-upload-plugin: Remove unsafe highestwrite



We had a mechanism to ignore zero writes if the written area in the disk
was never written. This is safe when working sparse files which are
always zeroed. When working with block devices, we don't have any
guarantee on the contents of the device, so we should not skip zero
requests.

Signed-off-by: Nir Soffer <nsoffer redhat com>
---
 v2v/rhv-upload-plugin.py | 49 +++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index ad5642f9..e261dfdb 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -143,7 +143,6 @@ def open(readonly):
         'disk_id': disk.id,
         'transfer': transfer,
         'failed': False,
-        'highestwrite': 0,
         'http': http,
         'path': destination_url.path,
     }
@@ -212,7 +211,6 @@ def pwrite(h, buf, offset):
     http = h['http']
 
     count = len(buf)
-    h['highestwrite'] = max(h['highestwrite'], offset + count)
 
     http.putrequest("PUT", h['path'] + "?flush=n")
     # The oVirt server only uses the first part of the range, and the
@@ -269,33 +267,28 @@ def zero(h, count, offset, may_trim):
 def emulate_zero(h, count, offset):
     http = h['http']
 
-    # qemu-img convert starts by trying to zero/trim the whole device.
-    # Since we've just created a new disk it's safe to ignore these
-    # requests as long as they are smaller than the highest write seen.
-    # After that we must emulate them with writes.
-    if offset + count < h['highestwrite']:
-        http.putrequest("PUT", h['path'])
-        http.putheader("Content-Range",
-                       "bytes %d-%d/*" % (offset, offset + count - 1))
-        http.putheader("Content-Length", str(count))
-        http.endheaders()
+    http.putrequest("PUT", h['path'])
+    http.putheader("Content-Range",
+                   "bytes %d-%d/*" % (offset, offset + count - 1))
+    http.putheader("Content-Length", str(count))
+    http.endheaders()
 
-        try:
-            buf = bytearray(128 * 1024)
-            while count > len(buf):
-                http.send(buf)
-                count -= len(buf)
-            http.send(memoryview(buf)[:count])
-        except BrokenPipeError:
-            pass
-
-        r = http.getresponse()
-        if r.status != 200:
-            request_failed(r,
-                           "could not write zeroes offset %d size %d" %
-                           (offset, count))
-
-        r.read()
+    try:
+        buf = bytearray(128 * 1024)
+        while count > len(buf):
+            http.send(buf)
+            count -= len(buf)
+        http.send(memoryview(buf)[:count])
+    except BrokenPipeError:
+        pass
+
+    r = http.getresponse()
+    if r.status != 200:
+        request_failed(r,
+                       "could not write zeroes offset %d size %d" %
+                       (offset, count))
+
+    r.read()
 
 
 @failing
-- 
2.26.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]