Richard W.M. Jones
2020-Mar-25 10:01 UTC
Re: [Libguestfs] [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
On Wed, Mar 25, 2020 at 09:48:02AM +0000, Daniel P. Berrangé wrote:> On Wed, Mar 25, 2020 at 09:42:19AM +0000, Richard W.M. Jones wrote: > > Now runs a complete set of tests, notably including the AIO test. > > > > File descriptors are passed in and out as plain ints (instead of > > *os.File) for a couple of reasons: (1) We have to pass the plain int > > to syscall.Select. (2) Turning an fd into an os.File causes golang to > > set the blocking flag which is deeply unhelpful. > > FWIW, using non-blocking FDs and syscall.Select is not normal best > practice for Go, where the expected model would be to use goroutines > with the file in blocking mode.Right, however I couldn't find any documentation about how to integrate a C library with that mechanism. Does libvirt-go do anything like this? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Daniel P. Berrangé
2020-Mar-25 10:14 UTC
Re: [Libguestfs] [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
On Wed, Mar 25, 2020 at 10:01:02AM +0000, Richard W.M. Jones wrote:> On Wed, Mar 25, 2020 at 09:48:02AM +0000, Daniel P. Berrangé wrote: > > On Wed, Mar 25, 2020 at 09:42:19AM +0000, Richard W.M. Jones wrote: > > > Now runs a complete set of tests, notably including the AIO test. > > > > > > File descriptors are passed in and out as plain ints (instead of > > > *os.File) for a couple of reasons: (1) We have to pass the plain int > > > to syscall.Select. (2) Turning an fd into an os.File causes golang to > > > set the blocking flag which is deeply unhelpful. > > > > FWIW, using non-blocking FDs and syscall.Select is not normal best > > practice for Go, where the expected model would be to use goroutines > > with the file in blocking mode. > > Right, however I couldn't find any documentation about how to > integrate a C library with that mechanism. Does libvirt-go do > anything like this?What's the intended usage of the FD ? I was thinking it was just for doing plain read/write I/O from Go, but now I'm thinking this was wrong interpretation Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Richard W.M. Jones
2020-Mar-25 10:23 UTC
Re: [Libguestfs] [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
On Wed, Mar 25, 2020 at 10:14:30AM +0000, Daniel P. Berrangé wrote:> On Wed, Mar 25, 2020 at 10:01:02AM +0000, Richard W.M. Jones wrote: > > On Wed, Mar 25, 2020 at 09:48:02AM +0000, Daniel P. Berrangé wrote: > > > On Wed, Mar 25, 2020 at 09:42:19AM +0000, Richard W.M. Jones wrote: > > > > Now runs a complete set of tests, notably including the AIO test. > > > > > > > > File descriptors are passed in and out as plain ints (instead of > > > > *os.File) for a couple of reasons: (1) We have to pass the plain int > > > > to syscall.Select. (2) Turning an fd into an os.File causes golang to > > > > set the blocking flag which is deeply unhelpful. > > > > > > FWIW, using non-blocking FDs and syscall.Select is not normal best > > > practice for Go, where the expected model would be to use goroutines > > > with the file in blocking mode. > > > > Right, however I couldn't find any documentation about how to > > integrate a C library with that mechanism. Does libvirt-go do > > anything like this? > > What's the intended usage of the FD ? I was thinking it was just for > doing plain read/write I/O from Go, but now I'm thinking this was wrong > interpretationhttp://libguestfs.org/libnbd.3.html#Socket-and-direction For example here's how it's integrated with glib: https://github.com/libguestfs/libnbd/blob/master/examples/glib-main-loop.c Integration with poll(2): https://github.com/libguestfs/libnbd/blob/a5fe64ab5323d649d348e61c9126ef7e7234c145/examples/batched-read-write.c#L69 It currently works from golang too, but it seems likely that synchronous calls like nbd_pread are blocking the golang main loop (because we make our own call to poll(2)). The asynch stuff also works (see libnbd_590_aio_copy_test.go in the attached patch) but it's rather awkward. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Maybe Matching Threads
- Re: [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
- Re: [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
- Re: [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
- [PATCH libnbd v4] Add Go language bindings (golang) (RHBZ#1814538).
- [PATCH libnbd v3] Add Go language bindings (golang) (RHBZ#1814538).