Please, do not post to several libvirt lists at once.
I am writing a code using libvirt API to migrate VM between two
physical
hosts *(QEMU/KVM) , *say some *n *number of times.
*1)* I am using right now* virDomainPtr virDomainMigrate (.......) *and to
calculate the total migration time I am using something like this:
*clock_gettime(CLOCK_MONOTONIC_RAW,&begin); *
*migrate*(domainToMigrate,nodeToMigrate);
*clock_gettime(CLOCK_MONOTONIC_RAW,&end);*
*Total Migration Time = end.tv_sec-begin.tv_sec*
Is this correct way to calculate total migration time. And is there some
way to calculate the downtime (not how to set it)?
Well, just call virDomainGetJobStats and you will get both total time
and downtime and many more.
Yes, this is the right API to get all the statistics you want. It
returns a list of (key, type, value) entires in params. The keys are
VIR_DOMAIN_JOB_* (see
http://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_JOB_AUTO_C...
and a lot of other VIR_DOMAIN_JOB_* macros following this one for
details). You can look at
http://libvirt.org/git/?p=libvirt.git;a=blob;f=tools/virsh-domain.c;h=935...
In short, just call
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DOWNTIME,
&value)
to fetch downtime from params into value if it was present there (check
return value of the API). The exact API to call is different for each
type, although all migration statistics are unsigned long long so this
one is all you need.
BTW, you can call virDomainGetJobStats anytime while migration is
running to monitor its progress. To check statistics of a completed
migration it's easier to just register a callback for
VIR_DOMAIN_EVENT_ID_JOB_COMPLETED event. See
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/object-events/eve...
for an example.
Jirka