[libvirt] [PATCH 0/3] non-shared migration without target disk images

by now, if you want a non-shared migration, you have to create same files at target as source side, which seems intorlerable! this issue was reported by Reinier Schoof http://www.redhat.com/archives/libvir-list/2011-December/msg00451.html These patches try to let migrate --copy-storage-* work without pre-exist disk image files at target side. we may also hope qemu to aware of this issue hooks/qemu | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 3 ++ src/util/hooks.c | 2 +- 3 files changed, 59 insertions(+), 1 deletions(-)

this hook aimed at migration only, it supposed to be used as a helper of migrate --copy-storage-* features to remove the unreasonable limitation of pre-exist disk images at migration target. someone can add more functions to hook files. Signed-off-by: liguang <lig.fnst@cn.fujitsu.com> --- hooks/qemu | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) create mode 100755 hooks/qemu diff --git a/hooks/qemu b/hooks/qemu new file mode 100755 index 0000000..8b93668 --- /dev/null +++ b/hooks/qemu @@ -0,0 +1,55 @@ +#!/usr/bin/python -u + +import sys +import string +import os +import subprocess +from xml.etree import ElementTree as ET + +id, opstr, subopstr, extra = range(4) + +if __name__ == "__main__": + args = sys.argv[1:] + hook_log = "/var/log/libvirt/hooks.log" + redir_fp = open(hook_log, 'a') + sys.stdout = redir_fp + if args: + if args[opstr] == "migrate": + file_sz = "0xffffffff" + c = 0 + dom_xml = sys.stdin.read() + ntree = ET.fromstring(dom_xml) + disks = ntree.findall('.//disk/source') + if disks == None: + sys.exit(1) + file_fmt = ntree.findall('.//disk/driver') + if file_fmt == None: + sys.exit(1) + for i in disks: + image = i.get('file') + if image == None: + print 'No disk images' + sys.exit(1) + if os.path.isfile(image): + continue + if os.path.isdir(os.path.dirname(image)) != True: + try: + os.makedirs(os.path.dirname(image)) + except: + print 'Fail to create dir of disk images' + ff = file_fmt[c].get('type') + if ff == None: + ff = "raw" + try: + subprocess.Popen(['qemu-img', "create", "-f", ff, image, file_sz], + stdout = redir_fp) + except: + print 'Fail to create disk images' + sys.exit(1) + c = c+1 + print 'Created disk images for migration' + else: + print 'qemu <id> <ops> <subops> <extra>' + + sys.stdout.close() + -- 1.7.2.5

this usage was suggested by man-page of waitpid, returns true if the child terminated normally Signed-off-by: liguang <lig.fnst@cn.fujitsu.com> --- src/util/hooks.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/util/hooks.c b/src/util/hooks.c index f5890d2..55b98ca 100644 --- a/src/util/hooks.c +++ b/src/util/hooks.c @@ -280,7 +280,7 @@ virHookCall(int driver, virCommandSetOutputBuffer(cmd, output); ret = virCommandRun(cmd, &exitstatus); - if (ret == 0 && exitstatus != 0) { + if (ret == 0 && WIFEXITED(exitstatus) == 0) { virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, _("Hook script %s %s failed with error code %d"), path, drvstr, exitstatus); -- 1.7.2.5

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com> --- src/Makefile.am | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4ae741b..3c84bca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,6 +49,9 @@ augeas_DATA = augeastestdir = $(datadir)/augeas/lenses/tests augeastest_DATA = +driverhook_DATA = $(top_srcdir)/hooks/qemu +driverhookdir = $(sysconfdir)/libvirt/hooks + # These files are not related to driver APIs. Simply generic # helper APIs for various purposes UTIL_SOURCES = \ -- 1.7.2.5
participants (1)
-
liguang