From 9194feb1f52a300146c3aaa32e476b58df464b01 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 2 Oct 2013 15:17:15 -0400 Subject: [PATCH] virt-manager: Default to qcow2 on kvm qcow2 enables fancy features like snapshots and is generally more desktopy, which we purport to be. We only do this on not horribly old libvirt/qemu, and only on qemu connections. This may work for xen but I'm not going to turn it on until someone tests it. --- virtManager/addhardware.py | 2 +- virtManager/config.py | 4 ++-- virtManager/connection.py | 12 ++++++++++++ virtManager/create.py | 2 +- virtManager/createvol.py | 2 +- virtManager/preferences.py | 2 +- virtinst/support.py | 6 +++++- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index cf0f15a7a..beb152700 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -1346,7 +1346,7 @@ class vmmAddHardware(vmmGObjectUI): disk.driver_cache = cache if not fmt: - fmt = self.config.get_storage_format() + fmt = self.conn.get_default_storage_format() if (self.is_default_storage() and disk.get_vol_install() and fmt in disk.get_vol_install().list_formats()): diff --git a/virtManager/config.py b/virtManager/config.py index 3de48a0a8..83e6b7383 100644 --- a/virtManager/config.py +++ b/virtManager/config.py @@ -166,7 +166,7 @@ class vmmConfig(object): self.libvirt_packages = cliconfig.libvirt_packages self.askpass_package = cliconfig.askpass_package self.default_graphics_from_config = cliconfig.default_graphics - self.default_storage_format_from_config = "raw" + self.default_storage_format_from_config = "qcow2" self._objects = [] @@ -407,7 +407,7 @@ class vmmConfig(object): def set_graphics_type(self, gtype): self.conf.set("/new-vm/graphics-type", gtype.lower()) - def get_storage_format(self, raw=False): + def get_default_storage_format(self, raw=False): ret = self.conf.get("/new-vm/storage-format") if ret not in ["default", "raw", "qcow2"]: ret = "default" diff --git a/virtManager/connection.py b/virtManager/connection.py index 815499b52..5983fe38a 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -319,6 +319,18 @@ class vmmConnection(vmmGObject): os.mkdir(ret, 755) return ret + def get_default_storage_format(self): + raw = self.config.get_default_storage_format(raw=True) + if raw != "default": + return raw + + fmt = self.config.get_default_storage_format() + if fmt != "qcow2": + return + + if self.check_conn_support(self._backend.SUPPORT_CONN_DEFAULT_QCOW2): + return fmt + return None #################################### # Connection pretty print routines # diff --git a/virtManager/create.py b/virtManager/create.py index 4e0c1417c..bff4561fe 100644 --- a/virtManager/create.py +++ b/virtManager/create.py @@ -1805,7 +1805,7 @@ class vmmCreate(vmmGObjectUI): disk.path = diskpath disk.set_create_storage(size=disksize, sparse=sparse) - fmt = self.config.get_storage_format() + fmt = self.conn.get_default_storage_format() if (self.is_default_storage() and disk.get_vol_install() and fmt in disk.get_vol_install().list_formats()): diff --git a/virtManager/createvol.py b/virtManager/createvol.py index d959cced9..8b0ad879f 100644 --- a/virtManager/createvol.py +++ b/virtManager/createvol.py @@ -173,7 +173,7 @@ class vmmCreateVolume(vmmGObjectUI): if hasformat: # Select the default storage format self.widget("vol-format").set_active(0) - default = self.config.get_storage_format() + default = self.conn.get_default_storage_format() for row in self.widget("vol-format").get_model(): if row[0] == default: self.widget("vol-format").set_active_iter(row.iter) diff --git a/virtManager/preferences.py b/virtManager/preferences.py index 66b872526..096c1ef82 100644 --- a/virtManager/preferences.py +++ b/virtManager/preferences.py @@ -153,7 +153,7 @@ class vmmPreferences(vmmGObjectUI): def refresh_storage_format(self): combo = self.widget("prefs-storage-format") - val = self.config.get_storage_format(raw=True) + val = self.config.get_default_storage_format(raw=True) uihelpers.set_row_selection(combo, val) def refresh_disk_poll(self): diff --git a/virtinst/support.py b/virtinst/support.py index d3871bf1d..ce141a704 100644 --- a/virtinst/support.py +++ b/virtinst/support.py @@ -325,7 +325,11 @@ SUPPORT_CONN_LISTALLDEVICES = _make(function="virConnect.listAllDevices", SUPPORT_CONN_VIRTIO_MMIO = _make(version=1001002, drv_version=[("qemu", 1006000)]) SUPPORT_CONN_DISK_SD = _make(version=1001002) - +# This is an arbitrary check to say whether it's a good idea to +# default to qcow2. It might be fine for xen or qemu older than the versions +# here, but until someone tests things I'm going to be a bit conservative. +SUPPORT_CONN_DEFAULT_QCOW2 = _make( + version=8000, drv_version=[("qemu", 1002000), ("test", 0)]) # Domain checks SUPPORT_DOMAIN_GETVCPUS = _make(function="virDomain.vcpus", args=())