'Verify the cache volume of a bootable volume.
If the cache no longer has clone, it will be deleted.
There is a small lag between the time a clone is deleted and the number
of clones being updated accordingly. There is also a race condition
when multiple volumes (clones of a cache volume) are deleted at once,
leading to the number of clones reported incorrectly. The file lock is
here to avoid such issues.'

@utils.synchronized('zfssaiscsi', external=True)
def _check_origin(self, lun, volname):

    lcfg = self.configuration
    cache = lun['origin']
    numclones = (-1)
    if (cache['snapshot'].startswith('image-') and cache['share'].startswith('os-cache-vol')):
        try:
            numclones = self.zfssa.num_clones(lcfg.zfssa_pool, lcfg.zfssa_cache_project, cache['share'], cache['snapshot'])
        except Exception:
            LOG.debug('Cache    volume    is    already    deleted.')
            return
        LOG.debug('Checking    cache    volume    %(name)s,    numclones    =    %(clones)d', {'name': cache['share'], 'clones': numclones})
    if (numclones == 1):
        try:
            self.zfssa.get_lun(lcfg.zfssa_pool, lcfg.zfssa_project, volname)
            return
        except exception.VolumeNotFound:
            numclones = 0
    if (numclones == 0):
        try:
            self.zfssa.delete_lun(lcfg.zfssa_pool, lcfg.zfssa_cache_project, cache['share'])
        except exception.VolumeBackendAPIException:
            LOG.warning("Volume    %s    exists    but    can't    be    deleted.", cache['share'])
