Commit 5391ebf8 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Implement virDomainGetVcpus binding

parent 30b6a8ec
......@@ -938,10 +938,12 @@ migrate(dom, destcon, flags, dname, uri, bandwidth)
const char *dname;
const char *uri;
unsigned long bandwidth;
PPCODE:
CODE:
if ((RETVAL = virDomainMigrate(dom, destcon, flags, dname, uri, bandwidth)) == NULL) {
_croak_error(virConnGetLastError(virDomainGetConnect(dom)));
}
OUTPUT:
RETVAL
void
attach_device(dom, xml)
......@@ -1061,6 +1063,49 @@ get_security_label(dom)
RETVAL
void
get_vcpu_info(dom)
virDomainPtr dom;
PREINIT:
virVcpuInfoPtr info;
unsigned char *cpumaps;
int maplen;
virNodeInfo nodeinfo;
virDomainInfo dominfo;
int nvCpus;
int i;
PPCODE:
if (virNodeGetInfo(virDomainGetConnect(dom), &nodeinfo) < 0) {
_croak_error(virConnGetLastError(virDomainGetConnect(dom)));
}
if (virDomainGetInfo(dom, &dominfo) < 0) {
_croak_error(virConnGetLastError(virDomainGetConnect(dom)));
}
Newx(info, dominfo.nrVirtCpu, virVcpuInfo);
maplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
Newx(cpumaps, dominfo.nrVirtCpu * maplen, unsigned char);
if ((nvCpus = virDomainGetVcpus(dom, info, dominfo.nrVirtCpu, cpumaps, maplen)) < 0) {
Safefree(info);
Safefree(cpumaps);
_croak_error(virConnGetLastError(virDomainGetConnect(dom)));
}
EXTEND(SP, nvCpus);
for (i = 0 ; i < nvCpus ; i++) {
HV *rec = newHV();
(void)hv_store(rec, "number", 6, newSViv(info[i].number), 0);
(void)hv_store(rec, "state", 5, newSViv(info[i].state), 0);
(void)hv_store(rec, "cpuTime", 7, newSViv(info[i].cpuTime), 0);
(void)hv_store(rec, "cpu", 3, newSViv(info[i].cpu), 0);
(void)hv_store(rec, "affinity", 8, newSVpvn((char*)cpumaps + (i *maplen), maplen), 0);
PUSHs(newRV_noinc((SV *)rec));
}
Safefree(info);
Safefree(cpumaps);
void
destroy(dom_rv)
SV *dom_rv;
......
# -*- perl -*-
use strict;
use warnings;
use Sys::Virt;
my $addr = @ARGV ? shift @ARGV : "";
print "Addr $addr\n";
my $con = Sys::Virt->new(address => $addr, readonly => 1);
print "VMM type: ", $con->get_type(), "\n";
foreach my $dom (sort { $a->get_id <=> $b->get_id } $con->list_domains) {
print "Domain: {\n";
print " ID: ", $dom->get_id(), " '" , $dom->get_name(), "'\n";
print " UUID: ", $dom->get_uuid_string(), "\n";
my $nodeinfo = $con->get_node_info;
my @info = $dom->get_vcpu_info;
foreach my $info (@info) {
print " VCPU: {\n";
foreach (sort { $a cmp $b } keys %{$info}) {
if ($_ eq "affinity") {
print " ", $_, ": ";
my @mask = split //, $info->{$_};
for (my $p = 0 ; $p < $nodeinfo->{cpus} ; $p++) {
print ((ord($mask[$p/8]) & (1 << ($p % 8))) ? 1 : 0);
}
print "\n";
} else {
print " ", $_, ": ", $info->{$_}, "\n";
}
}
print " }\n";
}
print "}\n";
}
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