On Wed, Aug 02, 2023 at 08:50:26PM -0500, Eric Blake wrote: > See the earlier commit "Add Extent64 arg type" for rationale in > supporting a new generator arg type. This patch adds the Go bindings > for use of Extent64, which required adding a counterpart Go type and > introducing a helper function for copying from the C array to an > actual Go object, very similar to the existing copy_uint32_array > helper for 32-bit extents. > > Signed-off-by: Eric Blake <ebl...@redhat.com> > --- > > v4: split out of larger patch [Laszlo], avoid awkward slice since we > can't use copy() anyway [Laszlo] > --- > generator/GoLang.ml | 23 +++++++++++++++++++++++ > golang/handle.go | 6 ++++++ > 2 files changed, 29 insertions(+) > > diff --git a/generator/GoLang.ml b/generator/GoLang.ml > index cc7d78b6..7a516366 100644 > --- a/generator/GoLang.ml > +++ b/generator/GoLang.ml > @@ -528,6 +528,21 @@ let > } > return ret > } > + > +func copy_extent_array(entries *C.nbd_extent, count C.size_t) []LibnbdExtent > { > + if (uint64(count) > 64*1024*1024) { > + panic(\"violation of state machine guarantee\") > + }
Same comment about the internal error as for previous commit. > + ret := make([]LibnbdExtent, count) > + addr := uintptr(unsafe.Pointer(entries)) > + for i := 0; i < int(count); i++ { > + ptr := (*C.nbd_extent)(unsafe.Pointer(addr)) > + ret[i].Length = uint64((*ptr).length) > + ret[i].Flags = uint64((*ptr).flags) > + addr += unsafe.Sizeof(*ptr) > + } > + return ret > +} > "; > > List.iter ( > @@ -542,6 +557,8 @@ let > match cbarg with > | CBArrayAndLen (UInt32 n, _) -> > pr "%s []uint32" n; > + | CBArrayAndLen (Extent64 n, _) -> > + pr "%s []LibnbdExtent" n; > | CBBytesIn (n, len) -> > pr "%s []byte" n; > | CBInt n -> > @@ -568,6 +585,8 @@ let > match cbarg with > | CBArrayAndLen (UInt32 n, count) -> > pr "%s *C.uint32_t, %s C.size_t" n count > + | CBArrayAndLen (Extent64 n, count) -> > + pr "%s *C.nbd_extent, %s C.size_t" n count > | CBBytesIn (n, len) -> > pr "%s unsafe.Pointer, %s C.size_t" n len > | CBInt n -> > @@ -610,6 +629,8 @@ let > match cbarg with > | CBArrayAndLen (UInt32 n, count) -> > pr "copy_uint32_array(%s, %s)" n count > + | CBArrayAndLen (Extent64 n, count) -> > + pr "copy_extent_array(%s, %s)" n count > | CBBytesIn (n, len) -> > pr "C.GoBytes(%s, C.int(%s))" n len > | CBInt n -> > @@ -760,6 +781,8 @@ let > match cbarg with > | CBArrayAndLen (UInt32 n, count) -> > pr "uint32_t *%s, size_t %s" n count > + | CBArrayAndLen (Extent64 n, count) -> > + pr "nbd_extent *%s, size_t %s" n count > | CBBytesIn (n, len) -> > pr "void *%s, size_t %s" n len > | CBInt n -> > diff --git a/golang/handle.go b/golang/handle.go > index 5fe4ed4f..2b0ee6d5 100644 > --- a/golang/handle.go > +++ b/golang/handle.go > @@ -58,6 +58,12 @@ func (h *Libnbd) String() string { > return "&Libnbd{}" > } > > +/* Used for block status callback. */ > +type LibnbdExtent struct { > + Length uint64 // length of the extent > + Flags uint64 // flags describing properties of the extent > +} > + > /* All functions (except Close) return ([result,] LibnbdError). */ > type LibnbdError struct { > Op string // operation which failed > -- Reviewed-by: Richard W.M. Jones <rjo...@redhat.com> 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 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs