[PATCH 3/4] golang/xenlight: add DevicePciAdd/Remove wrappers

Nick Rosbrook posted 4 patches 5 years, 10 months ago
Maintainers: Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wl@xen.org>, George Dunlap <george.dunlap@citrix.com>
There is a newer version of this series
[PATCH 3/4] golang/xenlight: add DevicePciAdd/Remove wrappers
Posted by Nick Rosbrook 5 years, 10 months ago
Add DevicePciAdd and DevicePciRemove as wrappers for
libxl_device_pci_add and libxl_device_pci remove.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
 tools/golang/xenlight/xenlight.go | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index a56f913b81..c94b046667 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1102,3 +1102,37 @@ func (Ctx *Context) DeviceNicRemove(domid Domid, nic *DeviceNic) error {
 
 	return nil
 }
+
+// DevicePciAdd is used to passthrough a PCI device to a domain.
+func (Ctx *Context) DevicePciAdd(domid Domid, pci *DevicePci) error {
+	var cpci C.libxl_device_pci
+
+	if err := pci.toC(&cpci); err != nil {
+		return err
+	}
+	defer C.libxl_device_pci_dispose(&cpci)
+
+	ret := C.libxl_device_pci_add(Ctx.ctx, C.uint32_t(domid), &cpci, nil)
+	if ret != 0 {
+		return Error(ret)
+	}
+
+	return nil
+}
+
+// DevicePciRemove removes a PCI device from a domain.
+func (Ctx *Context) DevicePciRemove(domid Domid, pci *DevicePci) error {
+	var cpci C.libxl_device_pci
+
+	if err := pci.toC(&cpci); err != nil {
+		return err
+	}
+	defer C.libxl_device_pci_dispose(&cpci)
+
+	ret := C.libxl_device_pci_remove(Ctx.ctx, C.uint32_t(domid), &cpci, nil)
+	if ret != 0 {
+		return Error(ret)
+	}
+
+	return nil
+}
-- 
2.17.1


Re: [PATCH 3/4] golang/xenlight: add DevicePciAdd/Remove wrappers
Posted by George Dunlap 5 years, 9 months ago

> On Apr 12, 2020, at 11:02 PM, Nick Rosbrook <rosbrookn@gmail.com> wrote:
> 
> Add DevicePciAdd and DevicePciRemove as wrappers for
> libxl_device_pci_add and libxl_device_pci remove.
> 
> Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>

For 4.14, we should really look at adding functions to the IDL so that all this can be auto-generated.

Reviewed-by: George Dunlap <george.dunlap@citrix.com>


Re: [PATCH 3/4] golang/xenlight: add DevicePciAdd/Remove wrappers
Posted by Nick Rosbrook 5 years, 9 months ago
On Thu, Apr 23, 2020 at 6:22 AM George Dunlap <George.Dunlap@citrix.com> wrote:
>
>
>
> > On Apr 12, 2020, at 11:02 PM, Nick Rosbrook <rosbrookn@gmail.com> wrote:
> >
> > Add DevicePciAdd and DevicePciRemove as wrappers for
> > libxl_device_pci_add and libxl_device_pci remove.
> >
> > Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
>
> For 4.14, we should really look at adding functions to the IDL so that all this can be auto-generated.

Agreed, there is obvious repetition here.

> Reviewed-by: George Dunlap <george.dunlap@citrix.com>

Thanks!

-NR