On Thu, May 26, 2022 at 09:16:18AM +0100, Richard W.M. Jones wrote: ...
But Python already has a handy way to convert any object that supports the buffer interface into a bytearray. Using it, we can now support many more parameters; passing in b"1"*9 now correctly creates a 9-byte buffer rather than failing. And the error message for a non-buffer also improves:
$ ./run nbdsh -c 'nbd.Buffer.from_bytearray(h)' Traceback (most recent call last): ... File "/home/eblake/libnbd/python/nbd.py", line 132, in from_bytearray o = libnbdmod.aio_buffer_from_bytearray(ba) TypeError: cannot convert 'NBD' object to bytearray
(A reliable TypeError is always better than an unexpected MemoryError or segfault). ---
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Thanks!
Now in as commit d477f7c, after also adjusting python unit test 580 to cover some of the now-permitted cases. There's still probably some efficiency gains to be had by reworking our aio buffers to use Python's memoryview objects for zero-copy where possible (similar to the work we did for Go in 7f5767e3), but that will require a Python API change and more work, so I'm not tackling it in the short term. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org