Nir Soffer
2018-Dec-07 17:55 UTC
[Libguestfs] [PATCH] v2v: -o rhv-upload: Fix emulated zero
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
Richard W.M. Jones
2018-Dec-07 18:50 UTC
Re: [Libguestfs] [PATCH] v2v: -o rhv-upload: Fix emulated zero
On Fri, Dec 07, 2018 at 07:55:28PM +0200, Nir Soffer wrote:> 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.Thanks - I pushed both. I wonder how the pread method worked before? That's on the main path I think. Rich.> 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-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Nir Soffer
2018-Dec-07 19:09 UTC
Re: [Libguestfs] [PATCH] v2v: -o rhv-upload: Fix emulated zero
On Fri, Dec 7, 2018 at 8:50 PM Richard W.M. Jones <rjones@redhat.com> wrote:> On Fri, Dec 07, 2018 at 07:55:28PM +0200, Nir Soffer wrote: > > 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. > > Thanks - I pushed both. > > I wonder how the pread method worked before? That's on the main path > I think. >I never seen a READ request on imageio log, so it seems that qemu-img convert never read from the destination. Nir
Maybe Matching Threads
- [PATCH] v2v: -o rhv-upload: Fix emulated zero
- Re: [PATCH] v2v: -o rhv-upload: Fix upload when using https
- Re: [PATCH] v2v: -o rhv-upload: Fix emulated zero
- [PATCH] v2v: -o rhv-upload: Fix upload when using https
- Re: [PATCH] v2v: -o rhv-upload: Optimize http request sending