[Libguestfs] [PATCH] v2v: -o rhv-upload: Fix emulated zero

Nir Soffer nirsof at gmail.com
Fri Dec 7 17:55:28 UTC 2018


Replace python 2 only "buffer" with "memoryview".

Falling back to emulated zero would fail with:

    NameError: name 'buffer' is not defined

I did not test the changed code but it was not tested before so it is
unlikely to be worse.

Detected by pylint.
---
 v2v/rhv-upload-plugin.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 3272c3ce3..12d4e68f7 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -416,41 +416,41 @@ def emulate_zero(h, count, offset):
     transfer = h['transfer']
 
     # 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'])
         if h['needs_auth']:
             http.putheader("Authorization", transfer.signed_ticket)
         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(buffer(buf, 0, count))
+            http.send(memoryview(buf)[:count])
         except BrokenPipeError:
             pass
 
         r = http.getresponse()
         if r.status != 200:
             request_failed(h, r,
                            "could not write zeroes offset %d size %d" %
                            (offset, count))
 
         r.read()
 
 def trim(h, count, offset):
     http = h['http']
 
     # Construct the JSON request for trimming.
     buf = json.dumps({'op': "trim",
                       'offset': offset,
                       'size': count,
                       'flush': False}).encode()
 
-- 
2.17.2




More information about the Libguestfs mailing list