On 2014年03月04日 01:57, Ramon Medeiros wrote:
On 02/27/2014 06:49 AM, lvroyce(a)linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
>
> Set ref_cnt to 0 when new volume created,
> if the ref_cnt cannot be found,
> which means it is created outside of kimchi scope,
> report it when lookup storage volume,
> search info about storage volumes used by vms and count the ref_cnt.
>
> Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
> ---
> src/kimchi/mockmodel.py | 3 +++
> src/kimchi/model/storagevolumes.py | 31 +++++++++++++++++++++++++++++++
> 2 files changed, 34 insertions(+)
>
>
>
> + def _get_ref_cnt(self, pool, name, path):
i don't know the hole workflow of this function, but will be nice to
check if the parameters are valid.
If the function that calls this one already to that, consider my review:
Reviewed-By: Ramon Medeiros <ramonn(a)br.ibm.com>
For pool and name we validate
earlier, for path I took a look at
storagevolume libvirt implementation,
the path will not be none, so there won't be corner case violate this
function.
But thorough consideration of param passing is always helpful, thanks a
lot for your careful review!
> + vol_id = '%s:%s' % (pool, name)
> + with self.objstore as session:
> + try:
> + ref_cnt = session.get('storagevolume', vol_id)['ref_cnt']
> + except NotFoundError:
> + # Fix storage volume created outside kimchi scope
> + ref_cnt = 0
> + args = {'conn': self.conn, 'objstore': self.objstore}
> + # try to find this volume in exsisted vm
> + vms = VMsModel(**args).get_list()
> + for vm in vms:
> + storages = VMStoragesModel(**args).get_list(vm)
> + for disk in storages:
> + if path == VMStorageModel(**args).lookup(vm, disk)['path']:
> + ref_cnt = ref_cnt + 1
> + session.store('storagevolume', vol_id, {'ref_cnt': ref_cnt})
> +
> + return ref_cnt
> +
> def lookup(self, pool, name):
> vol = self._get_storagevolume(pool, name)
> path = vol.path()
> info = vol.info()
> xml = vol.XMLDesc(0)
> fmt = xmlutils.xpath_get_text(xml, "/volume/target/format/@type")[0]
> + ref_cnt = self._get_ref_cnt(pool, name, path)
> res = dict(type=VOLUME_TYPE_MAP[info[0]],
> capacity=info[1],
> allocation=info[2],
> path=path,
> + ref_cnt=ref_cnt,
> format=fmt)
> if fmt == 'iso':
> if os.path.islink(path):