[Kimchi-devel] [PATCHv4 3/4] Add volume ref_cnt: Add model and mockmodel implementation

Ramon Medeiros ramonn at linux.vnet.ibm.com
Mon Mar 3 17:57:08 UTC 2014


On 02/27/2014 06:49 AM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at 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 at 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 at br.ibm.com>
> +        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):


-- 
Ramon Nunes Medeiros
Software Engineer - Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
ramonn at br.ibm.com




More information about the Kimchi-devel mailing list