From d692ea652dc17e15a90ea2ae7dff517b2db43f14 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 22 Jul 2011 19:50:30 -0400 Subject: [PATCH] create: Make sure 'customize' respects already allocated disk paths Going create->customize->addhw->storage->default storage would reuse the storage path allocated in the create wizard. Coordinate with virtinst's dup functions to avoid this problem. --- src/virtManager/addhardware.py | 4 +++- src/virtManager/util.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/virtManager/addhardware.py b/src/virtManager/addhardware.py index e2b23f909..8f1ec56ac 100644 --- a/src/virtManager/addhardware.py +++ b/src/virtManager/addhardware.py @@ -571,8 +571,10 @@ class vmmAddHardware(vmmGObjectUI): sparse = not self.widget("config-storage-nosparse").get_active() if self.is_default_storage(): + pathlist = map(lambda d: d.path, self.vm.get_disk_devices()) path = util.get_default_path(self.conn, - self.vm.get_name()) + self.vm.get_name(), + collidelist=pathlist) logging.debug("Default storage path is: %s" % path) else: path = self.widget("config-storage-entry").get_text() diff --git a/src/virtManager/util.py b/src/virtManager/util.py index 85cba76e1..cec882f51 100644 --- a/src/virtManager/util.py +++ b/src/virtManager/util.py @@ -96,31 +96,42 @@ def get_default_dir(conn): else: return running_config.get_default_image_dir(conn) -def get_default_path(conn, name): +def get_default_path(conn, name, collidelist=None): + collidelist = collidelist or [] pool = get_default_pool(conn) default_dir = get_default_dir(conn) + def path_exists(p): + return os.path.exists(p) or p in collidelist + if not pool: # Use old generating method origf = os.path.join(default_dir, name + ".img") f = origf n = 1 - while os.path.exists(f) and n < 100: + while path_exists(f) and n < 100: f = os.path.join(default_dir, name + "-" + str(n) + ".img") n += 1 - if os.path.exists(f): + if path_exists(f): f = origf path = f else: target, ignore, suffix = get_ideal_path_info(conn, name) + # Sanitize collidelist to work with the collision checker + for c in collidelist[:]: + collidelist.remove(c) + if os.path.dirname(c) == pool.get_target_path(): + collidelist.append(os.path.basename(c)) + path = virtinst.Storage.StorageVolume.find_free_name(name, - pool_object=pool.pool, suffix=suffix) + pool_object=pool.pool, suffix=suffix, + collidelist=collidelist) path = os.path.join(target, path)