On Thu, Apr 23, 2020 at 10:03:45AM +0100, Richard W.M. Jones wrote:
On Tue, Apr 21, 2020 at 05:07:43PM +0100, Daniel P. Berrangé wrote:
> On Tue, Apr 21, 2020 at 11:44:59AM +0100, Richard W.M. Jones wrote:
> > Thanks: Dan Berrangé
> >
> > XXX UNFINISHED:
> >
> > - Is using uintptr for the handle a good idea? Plugins must return
> > something != 0. In other languages we would allow plugins to
> > return an arbitrary object here, but this is not possible in golang
> > because of lack of GC roots.
>
> Yeah, this is the bit that looks wierd to me when thinking about this
> from a Go dev POV. You asked me on IRC whether we should have a separate
> interface for a connection object, and this makes me think that we should
> indeed do that.
...
This is what the patch looks like with a separate connection object.
It appears to work.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
From a929cff8745f21df913ea3230741dc7f2a1c016e Mon Sep 17 00:00:00
2001
From: "Richard W.M. Jones" <rjones(a)redhat.com>
Date: Thu, 9 Apr 2020 12:45:10 +0100
Subject: [PATCH] Add the ability to write plugins in golang.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Thanks: Dan Berrangé
XXX UNFINISHED:
- Default can_* methods are hard to implement. Ideally we would be
able to test if a user plugin implements a particular callback
(eg. TestPlugin.PWrite) or else defaults to the default callback,
but even with reflection I don't think this is possible in golang.
[Discussed on IRC: We decided the only option was to go for
nbdkit-sh-plugin style can_* methods]
- Write wrappers etc for all the other methods.
- Write documentation.
---
plugins/golang/nbdkit-golang-plugin.pod | 34 +++
configure.ac | 32 +++
plugins/golang/Makefile.am | 80 ++++++
.../src/libguestfs.org/nbdkit/wrappers.h | 41 +++
plugins/golang/config-test.go | 38 +++
.../src/libguestfs.org/nbdkit/nbdkit.go | 270 ++++++++++++++++++
.../golang/src/libguestfs.org/nbdkit/utils.go | 75 +++++
.../src/libguestfs.org/nbdkit/wrappers.go | 102 +++++++
plugins/golang/test/run-test.sh | 42 +++
plugins/golang/test/test.go | 119 ++++++++
.gitignore | 2 +
README | 4 +
12 files changed, 839 insertions(+)
create mode 100644 plugins/golang/nbdkit-golang-plugin.pod
create mode 100644 plugins/golang/Makefile.am
create mode 100644
plugins/golang/src/libguestfs.org/nbdkit/wrappers.h
create mode 100644 plugins/golang/config-test.go
create mode 100644
plugins/golang/src/libguestfs.org/nbdkit/nbdkit.go
create mode 100644
plugins/golang/src/libguestfs.org/nbdkit/utils.go
create mode 100644
plugins/golang/src/libguestfs.org/nbdkit/wrappers.go
create mode 100755 plugins/golang/test/run-test.sh
create mode 100644 plugins/golang/test/test.go
I think this design with two interfaces looks pretty nice from the
Go plugin implementors POV now.
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 :|