[Kimchi-devel] [PATCH 1/2] bug fix: Update storage volume ref_cnt when VM is deleted

Aline Manera alinefm at linux.vnet.ibm.com
Fri Nov 14 15:51:39 UTC 2014


As we only allow user to attach a free volume to a VM we need to make
sure this information is always valid.
So update the ref_cnt when deleting a VM.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/kimchi/model/vms.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index 7ea948f..7acdf4a 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -773,9 +773,23 @@ class VMModel(object):
                 pool_type = xpath_get_text(xml, "/pool/@type")[0]
                 if pool_type not in READONLY_POOL_TYPE:
                     vol.delete(0)
-            except Exception as e:
+                    # Update objstore to remove the volume
+                    with self.objstore as session:
+                        session.delete('storagevolume', path,
+                                       ignore_missing=True)
+            except libvirt.libvirtError as e:
                 kimchi_log.error('Unable to get storage volume by path: %s' %
                                  e.message)
+            except Exception as e:
+                raise OperationFailed('KCHVOL0017E', {'err': e.message})
+
+            try:
+                with self.objstore as session:
+                    if path in session.get_list('storagevolume'):
+                        n = session.get('storagevolume', path)['ref_cnt']
+                        session.store('storagevolume', path, {'ref_cnt': n-1})
+            except Exception as e:
+                raise OperationFailed('KCHVOL0017E', {'err': e.message})
 
         try:
             with self.objstore as session:
-- 
1.9.3




More information about the Kimchi-devel mailing list