Skip to content

Commit 61537e9

Browse files
committed
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 <[email protected]>
1 parent eb4dfde commit 61537e9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

xmlutils/disk.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Project Kimchi
33
#
4-
# Copyright IBM Corp, 2015-2016
4+
# Copyright IBM Corp, 2015-2017
55
#
66
# This library is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU Lesser General Public
@@ -17,6 +17,7 @@
1717
# License along with this library; if not, write to the Free Software
1818
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919

20+
import errno
2021
import lxml.etree as ET
2122
import os
2223
import socket
@@ -28,7 +29,7 @@
2829

2930
from wok.exception import InvalidParameter, NotFoundError
3031
from wok.plugins.kimchi.utils import check_url_path
31-
32+
from wok.utils import wok_log
3233

3334
BUS_TO_DEV_MAP = {'ide': 'hd', 'virtio': 'vd', 'scsi': 'sd'}
3435
DEV_TYPE_SRC_ATTR_MAP = {'file': 'file', 'block': 'dev'}
@@ -51,11 +52,22 @@ def get_disk_xml(params):
5152
disk_type = _get_disk_type(path) if len(path) > 0 else 'file'
5253
disk = E.disk(type=disk_type, device=params['type'])
5354
driver = E.driver(name='qemu', type=params['format'])
54-
if params['type'] != 'cdrom':
55-
driver.set('cache', 'none')
55+
try:
56+
fd = os.open(path, os.O_RDONLY | os.O_DIRECT)
57+
os.close(fd)
58+
wok_log.debug("Disk '%s' supports direct I/O. Setting cache=none"
59+
"to enable live migration" % path)
60+
except OSError, e:
61+
if e.errno == errno.EINVAL:
62+
wok_log.debug("Disk '%s' does not support direct I/O: "
63+
"'%s'. Let libvirt sets the default cache mode." %
64+
(path, e.message))
65+
else:
66+
if params['type'] != 'cdrom':
67+
driver.set('cache', 'none')
5668

57-
if params.get('pool_type') == "netfs":
58-
driver.set("io", "native")
69+
if params.get('pool_type') == "netfs":
70+
driver.set("io", "native")
5971

6072
disk.append(driver)
6173

0 commit comments

Comments
 (0)