VirtualDisk: Handle the blktap default

And cache the blktap lookup once for the localhost
This commit is contained in:
Cole Robinson 2013-10-06 13:17:35 -04:00
parent ef878a5d49
commit 3f532fe263
5 changed files with 27 additions and 26 deletions

View File

@ -27,7 +27,6 @@ from gi.repository import Gdk
# pylint: enable=E0611
import virtinst
from virtinst import util
from virtinst import (VirtualChannelDevice, VirtualParallelDevice,
VirtualSerialDevice, VirtualConsoleDevice,
VirtualVideoDevice, VirtualWatchdog,
@ -1374,7 +1373,7 @@ class vmmAddHardware(vmmGObjectUI):
def validate(self, page_num):
ret = self._validate(page_num)
if ret is not False and self._dev:
self._dev.set_defaults()
self._dev.set_defaults(self.vm.get_xmlobj())
self._dev.validate()
return ret
@ -1413,7 +1412,8 @@ class vmmAddHardware(vmmGObjectUI):
disk.bus = bus
disk.set_create_storage(size=disksize, sparse=sparse,
fmt=fmt or None)
disk.driver_cache = cache
if cache:
disk.driver_cache = cache
if not fmt:
fmt = self.conn.get_default_storage_format()
@ -1422,11 +1422,6 @@ class vmmAddHardware(vmmGObjectUI):
fmt in disk.get_vol_install().list_formats()):
logging.debug("Setting disk format from prefs: %s", fmt)
disk.get_vol_install().format = fmt
if (disk.type == virtinst.VirtualDisk.TYPE_FILE and
not self.vm.is_hvm() and
util.is_blktap_capable(self.conn.get_backend())):
disk.driver_name = virtinst.VirtualDisk.DRIVER_TAP
except Exception, e:
return self.err.val_err(_("Storage parameter error."), e)

View File

@ -744,10 +744,16 @@ class VirtualDisk(VirtualDevice):
if volobj:
self._change_backend(None, volobj)
def set_defaults(self):
def set_defaults(self, guest):
if self.is_cdrom():
self.read_only = True
if (guest.os.is_xenpv() and
self.type == VirtualDisk.TYPE_FILE and
self.driver_name is None and
util.is_blktap_capable(self.conn)):
self.driver_name = VirtualDisk.DRIVER_TAP
if not self.conn.is_qemu():
return
if not self.is_disk():

View File

@ -30,7 +30,6 @@ import virtinst
from virtinst import util
from virtinst import support
from virtinst import OSXML
from virtinst import VirtualDisk
from virtinst import VirtualDevice
from virtinst import Clock
from virtinst import Seclabel
@ -209,7 +208,6 @@ class Guest(XMLBuilder):
Add the passed device to the guest's device list.
@param dev: VirtualDevice instance to attach to guest
@param set_defaults: Whether to set defaults for the device
"""
self._add_child(dev)
@ -605,7 +603,7 @@ class Guest(XMLBuilder):
self._set_feature_defaults()
for dev in self.get_all_devices():
dev.set_defaults()
dev.set_defaults(self)
self._add_implied_controllers()
self._check_address_multi()
self._set_disk_defaults()
@ -790,13 +788,6 @@ class Guest(XMLBuilder):
if not disk.bus:
set_disk_bus(disk)
# Default file backed PV guests to tap driver
if (self.os.is_xenpv() and
disk.type == VirtualDisk.TYPE_FILE and
disk.driver_name is None and
util.is_blktap_capable(self.conn)):
disk.driver_name = VirtualDisk.DRIVER_TAP
# Generate disk targets
if disk.target:
used_targets.append(disk.target)

View File

@ -28,6 +28,9 @@ import libvirt
import libxml2
_host_blktap_capable = None
def listify(l):
if l is None:
return []
@ -348,13 +351,19 @@ def is_blktap_capable(conn):
if conn.is_remote():
return False
f = open("/proc/modules")
lines = f.readlines()
f.close()
global _host_blktap_capable
if _host_blktap_capable is not None:
return _host_blktap_capable
lines = file("/proc/modules").readlines()
for line in lines:
if line.startswith("blktap ") or line.startswith("xenblktap "):
return True
return False
_host_blktap_capable = True
break
if not _host_blktap_capable:
_host_blktap_capable = False
return _host_blktap_capable
def randomUUID(conn):

View File

@ -864,11 +864,11 @@ class XMLBuilder(object):
"""
pass
def set_defaults(self):
def set_defaults(self, guest):
"""
Encode any default values if needed
"""
pass
ignore = guest
###################