On Mon, Aug 10, 2020 at 07:28:30PM +0300, Nir Soffer wrote:
On Mon, Aug 10, 2020 at 1:51 PM Richard W.M. Jones
<rjones(a)redhat.com> wrote:
> + def extents(h, count, offset, flags):
> + # return a list of (offset, length, type) tuples:
> + return [ (off1, len1, type1), (off2, len2, type2), ... ]
Better to accept an iterable of tuples. This allows the plugin to do:
def extents(h, count, offset, flags):
for extent in client.extents():
if extent.offset > offset:
return
yield extent.start, extent.length, type
The logic is just an example to illustrate the benefit of using
generators. The plugin does not have to build a list of extent,
and nbdkit also may not need this list. This may have performance
benefits, and may make the code nicer.
Yes, I think we should do this, and I believe the change is
backwards compatible too (just as well because I just pushed
this into RHEL ...)
...
> + /* We expect a list of extents to be returned. Each extent
is a
> + * tuple (offset, length, type).
> + */
> + if (!PyList_Check (r)) {
This will work only with the list. We want to check if we got a type
we can iterated on. I don't know the APi needed but I'm sure this is
supported by the C API.
I wonder how it works w.r.t. threads ... Does it use another thread
or does it just have some kind of suspension which is evaluated when
requested?
This seems to be the API so I'll have a play around with it:
https://docs.python.org/3/c-api/iter.html
Returning extent tuples looks much better than the C version in file
plugin.
Certainly easier to use :-/
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v