Commit 069e16fc authored by Daniel P. Berrange's avatar Daniel P. Berrange

Add API for bulk domain stats listing

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 032d5693
This diff is collapsed.
......@@ -1182,7 +1182,7 @@ func (d *Domain) GetCPUStats(startCpu int, nCpus uint, flags uint32) ([]DomainCP
offset := i * int(nparams)
info := getCPUStatsFieldInfo(&stats[i])
cparamscpu := cparams[offset : offset+int(ret)]
err := typedParamsUnpack(cparamscpu, info)
_, err := typedParamsUnpack(cparamscpu, info)
if err != nil {
return []DomainCPUStats{}, err
}
......@@ -1261,7 +1261,7 @@ func (d *Domain) GetInterfaceParameters(device string, flags uint32) (*DomainInt
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -1593,7 +1593,7 @@ func (d *Domain) BlockStatsFlags(disk string, flags uint32) (*DomainBlockStats,
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -2446,7 +2446,7 @@ func (d *Domain) GetBlkioParameters(flags DomainModificationImpact) (*DomainBlki
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -2625,7 +2625,7 @@ func (d *Domain) GetBlockIoTune(disk string, flags DomainModificationImpact) (*D
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -2981,7 +2981,7 @@ func (d *Domain) GetJobStats(flags DomainGetJobStatsFlags) (*DomainJobInfo, erro
params := DomainJobInfo{}
info := getDomainJobInfoFieldInfo(&params)
err := typedParamsUnpackLen(cparams, int(nparams), info)
_, err := typedParamsUnpackLen(cparams, int(nparams), info)
if err != nil {
return nil, GetLastError()
}
......@@ -3068,7 +3068,7 @@ func (d *Domain) GetMemoryParameters(flags DomainModificationImpact) (*DomainMem
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -3142,7 +3142,7 @@ func (d *Domain) GetNumaParameters(flags DomainModificationImpact) (*DomainNumaP
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -3241,7 +3241,7 @@ func (d *Domain) GetPerfEvents(flags DomainModificationImpact) (*DomainPerfEvent
defer C.virTypedParamsFree(cparams, nparams)
err := typedParamsUnpackLen(cparams, int(nparams), info)
_, err := typedParamsUnpackLen(cparams, int(nparams), info)
if err != nil {
return nil, err
}
......@@ -3388,7 +3388,7 @@ func (d *Domain) GetSchedulerParameters() (*DomainSchedulerParameters, error) {
}
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -3420,7 +3420,7 @@ func (d *Domain) GetSchedulerParametersFlags(flags DomainModificationImpact) (*D
}
defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
err := typedParamsUnpack(cparams, info)
_, err := typedParamsUnpack(cparams, info)
if err != nil {
return nil, err
}
......@@ -4099,7 +4099,7 @@ func (d *Domain) GetGuestVcpus(flags uint32) (*DomainGuestVcpus, error) {
defer C.virTypedParamsFree(cparams, C.int(nparams))
err := typedParamsUnpackLen(cparams, int(nparams), info)
_, err := typedParamsUnpackLen(cparams, int(nparams), info)
if err != nil {
return nil, err
}
......
......@@ -1281,3 +1281,25 @@ func TestDomainListAllInterfaceAddresses(t *testing.T) {
t.Fatal("should have 0 interfaces", len(ifaces))
}
}
func TestDomainGetAllStats(t *testing.T) {
dom, conn := buildTestQEMUDomain()
defer func() {
dom.Free()
if res, _ := conn.CloseConnection(); res != 0 {
t.Errorf("CloseConnection() == %d, expected 0", res)
}
}()
if err := dom.Create(); err != nil {
t.Error(err)
return
}
defer dom.Destroy()
_, err := conn.GetAllDomainStats([]*Domain{}, DOMAIN_STATS_STATE|DOMAIN_STATS_CPU_TOTAL|DOMAIN_STATS_INTERFACE|DOMAIN_STATS_BALLOON|DOMAIN_STATS_BLOCK|DOMAIN_STATS_PERF|DOMAIN_STATS_VCPU, 0)
if err != nil {
t.Error(err)
return
}
}
......@@ -26,49 +26,54 @@ type typedParamsFieldInfo struct {
sl *[]string
}
func typedParamsUnpackLen(cparams *C.virTypedParameter, nparams int, infomap map[string]typedParamsFieldInfo) error {
func typedParamsUnpackLen(cparams *C.virTypedParameter, nparams int, infomap map[string]typedParamsFieldInfo) (uint, error) {
count := uint(0)
for i := 0; i < nparams; i++ {
var cparam *C.virTypedParameter
cparam = (*C.virTypedParameter)(unsafe.Pointer(uintptr(unsafe.Pointer(cparams)) + unsafe.Sizeof(*cparam)*uintptr(i)))
name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
info, ok := infomap[name]
if !ok {
// Ignore unknown keys so that we don't break if
// run against a newer libvirt that returns more
// parameters than we currently have code to
// consume
continue
}
switch cparam._type {
case C.VIR_TYPED_PARAM_INT:
if info.i == nil {
return fmt.Errorf("field %s expects an int", name)
return 0, fmt.Errorf("field %s expects an int", name)
}
*info.i = int(*(*C.int)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_UINT:
if info.ui == nil {
return fmt.Errorf("field %s expects a uint", name)
return 0, fmt.Errorf("field %s expects a uint", name)
}
*info.ui = uint(*(*C.uint)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_LLONG:
if info.l == nil {
return fmt.Errorf("field %s expects an int64", name)
return 0, fmt.Errorf("field %s expects an int64", name)
}
*info.l = int64(*(*C.longlong)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_ULLONG:
if info.ul == nil {
return fmt.Errorf("field %s expects a uint64", name)
return 0, fmt.Errorf("field %s expects a uint64", name)
}
*info.ul = uint64(*(*C.ulonglong)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_DOUBLE:
if info.d == nil {
return fmt.Errorf("field %s expects a float64", name)
return 0, fmt.Errorf("field %s expects a float64", name)
}
*info.d = float64(*(*C.double)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_BOOLEAN:
if info.b == nil {
return fmt.Errorf("field %s expects a bool", name)
return 0, fmt.Errorf("field %s expects a bool", name)
}
*info.b = *(*C.char)(unsafe.Pointer(&cparam.value)) == 1
*info.set = true
......@@ -80,15 +85,16 @@ func typedParamsUnpackLen(cparams *C.virTypedParameter, nparams int, infomap map
*info.sl = append(*info.sl, C.GoString(*(**C.char)(unsafe.Pointer(&cparam.value))))
*info.set = true
} else {
return fmt.Errorf("field %s expects a string/string list", name)
return 0, fmt.Errorf("field %s expects a string/string list", name)
}
}
count++
}
return nil
return count, nil
}
func typedParamsUnpack(cparams []C.virTypedParameter, infomap map[string]typedParamsFieldInfo) error {
func typedParamsUnpack(cparams []C.virTypedParameter, infomap map[string]typedParamsFieldInfo) (uint, error) {
return typedParamsUnpackLen(&cparams[0], len(cparams), infomap)
}
......@@ -101,6 +107,10 @@ func typedParamsPackLen(cparams *C.virTypedParameter, nparams int, infomap map[s
name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
info, ok := infomap[name]
if !ok {
// Ignore unknown keys so that we don't break if
// run against a newer libvirt that returns more
// parameters than we currently have code to
// consume
continue
}
if !*info.set {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment