From 61537e959c416030946a51368de42f0cdee18327 Mon Sep 17 00:00:00 2001 From: Aline Manera Date: Mon, 6 Mar 2017 12:44:56 -0300 Subject: [PATCH] Bug fix #1107: Only set cache=none to disks that support direct IO ZFS volumes and GlusterFS does not support direct IO and setting cache=none will not allow the guest to start. So only set cache=none when direct IO is supported to avoid problems. Signed-off-by: Aline Manera --- xmlutils/disk.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/xmlutils/disk.py b/xmlutils/disk.py index 02d6811d1..97298c5bc 100644 --- a/xmlutils/disk.py +++ b/xmlutils/disk.py @@ -1,7 +1,7 @@ # # Project Kimchi # -# Copyright IBM Corp, 2015-2016 +# Copyright IBM Corp, 2015-2017 # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,6 +17,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +import errno import lxml.etree as ET import os import socket @@ -28,7 +29,7 @@ from wok.exception import InvalidParameter, NotFoundError from wok.plugins.kimchi.utils import check_url_path - +from wok.utils import wok_log BUS_TO_DEV_MAP = {'ide': 'hd', 'virtio': 'vd', 'scsi': 'sd'} DEV_TYPE_SRC_ATTR_MAP = {'file': 'file', 'block': 'dev'} @@ -51,11 +52,22 @@ def get_disk_xml(params): disk_type = _get_disk_type(path) if len(path) > 0 else 'file' disk = E.disk(type=disk_type, device=params['type']) driver = E.driver(name='qemu', type=params['format']) - if params['type'] != 'cdrom': - driver.set('cache', 'none') + try: + fd = os.open(path, os.O_RDONLY | os.O_DIRECT) + os.close(fd) + wok_log.debug("Disk '%s' supports direct I/O. Setting cache=none" + "to enable live migration" % path) + except OSError, e: + if e.errno == errno.EINVAL: + wok_log.debug("Disk '%s' does not support direct I/O: " + "'%s'. Let libvirt sets the default cache mode." % + (path, e.message)) + else: + if params['type'] != 'cdrom': + driver.set('cache', 'none') - if params.get('pool_type') == "netfs": - driver.set("io", "native") + if params.get('pool_type') == "netfs": + driver.set("io", "native") disk.append(driver)