[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 47/59] libxl: Reorganize code
From: George Dunlap <george.dunlap@xxxxxxxxxx> Put all type and enumeration definitions at the top of the file, separated into "builtins" and "idl-generated". Also define Uuid as C.libxl_uud. (Not sure if this gives us the functionality we need without having to manually copy things in.) Finally, get rid of Bitmap.Alloc(). It's redundant now that Bitmap.Set() automatically extends the array. Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx> --- libxl.go | 189 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 102 insertions(+), 87 deletions(-) diff --git a/libxl.go b/libxl.go index 16f4645..e73c06b 100644 --- a/libxl.go +++ b/libxl.go @@ -39,10 +39,102 @@ import ( "time" ) +/* + * Types: Builtins + */ + +type Domid uint32 + +type MemKB uint64 + +// typedef struct { +// uint32_t size; /* number of bytes in map */ +// uint8_t *map; +// } libxl_bitmap; + +// Implement the Go bitmap type such that the underlying data can +// easily be copied in and out. NB that we still have to do copies +// both directions, because cgo runtime restrictions forbid passing to +// a C function a pointer to a Go-allocated structure which contains a +// pointer. +type Bitmap struct { + bitmap []C.uint8_t +} + type Context struct { ctx *C.libxl_ctx } +type Uuid C.libxl_uuid + +/* + * Types: IDL + * + * FIXME: Generate these automatically from the IDL + */ +type Dominfo struct { + Uuid Uuid + Domid Domid + Running bool + Blocked bool + Paused bool + Shutdown bool + Dying bool + Never_stop bool + + Shutdown_reason int32 // FIXME shutdown_reason enumeration + Outstanding_memkb MemKB + Current_memkb MemKB + Shared_memkb MemKB + Paged_memkb MemKB + Max_memkb MemKB + Cpu_time time.Duration + Vcpu_max_id uint32 + Vcpu_online uint32 + Cpupool uint32 + Domain_type int32 //FIXME libxl_domain_type enumeration + +} + +// # Consistent with values defined in domctl.h +// # Except unknown which we have made up +// libxl_scheduler = Enumeration("scheduler", [ +// (0, "unknown"), +// (4, "sedf"), +// (5, "credit"), +// (6, "credit2"), +// (7, "arinc653"), +// (8, "rtds"), +// ]) +type Scheduler int +var ( + SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN + SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF + SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT + SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 + SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 + SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS +) + +// libxl_cpupoolinfo = Struct("cpupoolinfo", [ +// ("poolid", uint32), +// ("pool_name", string), +// ("sched", libxl_scheduler), +// ("n_dom", uint32), +// ("cpumap", libxl_bitmap) +// ], dir=DIR_OUT) + +type CpupoolInfo struct { + Poolid uint32 + PoolName string + Scheduler Scheduler + DomainCount int + Cpumap Bitmap +} + +/* + * Context + */ var Ctx Context func (Ctx *Context) IsOpen() bool { @@ -72,43 +164,12 @@ func (Ctx *Context) Close() (err error) { return } -// Builtins -type Domid uint32 - -type MemKB uint64 - -// FIXME: Use the idl to generate types -type Dominfo struct { - // FIXME: uuid - Domid Domid - Running bool - Blocked bool - Paused bool - Shutdown bool - Dying bool - Never_stop bool - - Shutdown_reason int32 // FIXME shutdown_reason enumeration - Outstanding_memkb MemKB - Current_memkb MemKB - Shared_memkb MemKB - Paged_memkb MemKB - Max_memkb MemKB - Cpu_time time.Duration - Vcpu_max_id uint32 - Vcpu_online uint32 - Cpupool uint32 - Domain_type int32 //FIXME libxl_domain_type enumeration - -} - func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { if Ctx.ctx == nil { err = fmt.Errorf("Context not opened") return } - var cdi C.libxl_dominfo ret := C.libxl_domain_info(Ctx.ctx, unsafe.Pointer(&cdi), C.uint32_t(Id)) @@ -119,8 +180,12 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { return } - // FIXME -- use introspection to make this more robust + // We could consider having this boilerplate generated by the + // idl, in a function like this: + // + // di = translateCdomaininfoToGoDomaininfo(cdi) di = &Dominfo{} + di.Uuid = Uuid(cdi.uuid) di.Domid = Domid(cdi.domid) di.Running = bool(cdi.running) di.Blocked = bool(cdi.blocked) @@ -139,6 +204,7 @@ func (Ctx *Context) DomainInfo(Id Domid) (di *Dominfo, err error) { di.Vcpu_online = uint32(cdi.vcpu_online) di.Cpupool = uint32(cdi.cpupool) di.Domain_type = int32(cdi.domain_type) + return } @@ -156,30 +222,15 @@ func (Ctx *Context) DomainUnpause(Id Domid) (err error) { return } - -// typedef struct { -// uint32_t size; /* number of bytes in map */ -// uint8_t *map; -// } libxl_bitmap; - -// Implement the Go bitmap type such that the underlying data can -// easily be copied in and out. NB that we still have to do copies -// both directions, because cgo runtime restrictions forbid passing to -// a C function a pointer to a Go-allocated structure which contains a -// pointer. -type Bitmap struct { - bitmap []C.uint8_t -} - -func (bm *Bitmap) Alloc(max int) { - bm.bitmap = make([]C.uint8_t, (max + 7) / 8) -} +/* + * Bitmap operations + */ // Return a Go bitmap which is a copy of the referred C bitmap. func bitmapCToGo(cbm *C.libxl_bitmap) (gbm Bitmap) { // Alloc a Go slice for the bytes size := int(cbm.size) - gbm.Alloc(size*8) + gbm.bitmap = make([]C.uint8_t, size) // Make a slice pointing to the C array mapslice := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size] @@ -279,26 +330,6 @@ func (a Bitmap) And(b Bitmap) (c Bitmap) { return } -// # Consistent with values defined in domctl.h -// # Except unknown which we have made up -// libxl_scheduler = Enumeration("scheduler", [ -// (0, "unknown"), -// (4, "sedf"), -// (5, "credit"), -// (6, "credit2"), -// (7, "arinc653"), -// (8, "rtds"), -// ]) -type Scheduler int -var ( - SchedulerUnknown Scheduler = C.LIBXL_SCHEDULER_UNKNOWN - SchedulerSedf Scheduler = C.LIBXL_SCHEDULER_SEDF - SchedulerCredit Scheduler = C.LIBXL_SCHEDULER_CREDIT - SchedulerCredit2 Scheduler = C.LIBXL_SCHEDULER_CREDIT2 - SchedulerArinc653 Scheduler = C.LIBXL_SCHEDULER_ARINC653 - SchedulerRTDS Scheduler = C.LIBXL_SCHEDULER_RTDS -) - // const char *libxl_scheduler_to_string(libxl_scheduler p); // int libxl_scheduler_from_string(const char *s, libxl_scheduler *e); func (s Scheduler) String() (string) { @@ -325,22 +356,6 @@ func SchedulerFromString(name string) (s Scheduler, err error) { return } -// libxl_cpupoolinfo = Struct("cpupoolinfo", [ -// ("poolid", uint32), -// ("pool_name", string), -// ("sched", libxl_scheduler), -// ("n_dom", uint32), -// ("cpumap", libxl_bitmap) -// ], dir=DIR_OUT) - -type CpupoolInfo struct { - Poolid uint32 - PoolName string - Scheduler Scheduler - DomainCount int - Cpumap Bitmap -} - // libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool_out); // void libxl_cpupoolinfo_list_free(libxl_cpupoolinfo *list, int nb_pool); func (Ctx *Context) ListCpupool() (list []CpupoolInfo) { -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |