Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the argument cpumaps and maplen in api virDomainGetVcpus of libvirt

I am trying to get the information of vcpus running on my machine and for the same I am using libvirt. I am not able to understand how to use the api virDomainGetVcpus which has arguments cpumaps and maplen.

I am using C. Please let me know if you have some insight.

Thanks.

like image 804
Walt Whitman Avatar asked Sep 16 '17 13:09

Walt Whitman


1 Answers

You need to use virDomainGetInfo and virNodeGetInfo to guest the number of guest CPUs and number of host CPUs. Then you can allocate a map of the right size. This code would do the trick:

 virNodeInfo nodeinfo;
 virDomainInfo dominfo;
 int nhostcpus;

 if (virNodeGetInfo(conn, &nodeinfo) < 0)
      return -1;

 nhostcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);

 if (virDomainGetInfo(dom, &dominfo) != 0)
      return -1;

 cpuinfo = malloc(sizeof(virVcpuInfo)*dominfo.nrVirtCpu);
 cpumaplen = VIR_CPU_MAPLEN(nhostcpu);
 cpumaps = vshMalloc(ctl, dominfo.nrVirtCpu * cpumaplen);

 if ((ncpus = virDomainGetVcpus(dom,
                                cpuinfo, dominfo.nrVirtCpu,
                                cpumaps, cpumaplen)) < 0)
     return -1;
like image 84
DanielB Avatar answered Jan 01 '23 20:01

DanielB