Hi guys, I'm working on a pre migration checks implementation.
The patch files attached provide a framework to execute
pre-migration-checks before the domain migration.
================================================================
1 - FRAMEWORK OVERVIEW
================================================================
Pre-Migration-Checks are enabled by adding a "--pmc" option in
"virsh migrate" command
$ virsh migrate --pmc ...
In this way, before the execution of function virDomainMigrate(),
an array of "checks" are performed. Return value of every check
set if the migration will continue or not.
================================================================
2 - FRAMEWORK STRUCTURE
================================================================
Every check is defined in the file
libvirt/src/util/pmc.c
Check list is defined by object "chklist". This is a struct
defined as
static virPMCCheckList chklist = {
.count = 2,
.check = {&chk1,&chk2,NULL}
};
where "count" define the current array size, and "check" is an
array of pointer to virPMCCheck object.
virPMCCheck is a stuct defined as
struct _virPMCCheck
{
const char *name;
virPMCCheckRun run;
};
where "name" is the name of the check needed for debugging
messages, and "run" is a pointer to check function.
================================================================
3 - HOW TO ADD NEW CHECK
================================================================
Adding new check is very simple! You have to define a check
funcion as
static int
pmcCheckFooCheck(virDomainPtr domain,
virConnectPtr dconn)
{
/* do something */
return CHECK_SUCCESS
}
then you have to define a "check-hook" as
static virPMCCheck chk3 = {
.name = "this is fooCheck",
.run = pmcCheckFooCheck
};
and update the object "chklist"
static virPMCCheckList chklist = {
.count = 3, /* previous value was 2 */
.check = {&chk1,&chk2,&chk3,NULL} /* previous content not
* include a pointer to
* chk3 object
*/
};
================================================================
4 - POSSIBLE ENHANCHEMENT
================================================================
1. Adding infos in _virPMCCheck struct about check security level.
Example: if a check with level CRITICAL return CHECK_FAIL,
migration process is stopped,
2. Implementing framework not as util, but as driver. For example
this can permit to define new checks by xml file.
3. Define external checks loadable by shared library.
================================================================
5 - PATCH FILE DESCRIPTION
================================================================
file: datatypes.h.patch
desc: define new type virPMCCheckRun
define struct _virPMCCheck
define struct _virPMCCheckList
file: libvirt.c.patch
desc: impement public API virDomainMigratePMC()
file: libvirt.h.in.patch
desc: impement public API virDomainMigratePMC() prototype
define type virPMCCheck
define type virPMCCheckPtr
define type virPMCCheckList
define type virPMCCheckListPtr
define macro PMC_LIST_SIZE
file: libvirt_public.syms
desc: export public API virDomainMigratePMC()
file: pmc.c.patch, pmc.h.patch
desc: define and implements pre migration checks and some auxiliary
functions.
file: virsh.c.patch
desc: add option "pmc" to virsh migrate command
================================================================
6 - NOTES
================================================================
I start to implement this framework on git sources, but the
latest sources produce a regress on my code. For this reason
I applied my code on latest stable release of libvirt (0.8.1).
What do you think about that? Is this a good approach to implement pre
migration checks? Have you a suggestions? There is a possibility to
include this patch in future libvirt distributions?
Waiting for feedback...
Paolo Smiraglia
--
PAOLO SMIRAGLIA
http://portale.isf.polito.it/paolo-smiraglia