'Create a volume efficiently from an existing image.
Verify the image ID being used:
(1) If there is no existing cache volume, create one and transfer
image data to it. Take a snapshot.
(2) If a cache volume already exists, verify if it is either alternated
or updated. If so try to remove it, raise exception if removal fails.
Create a new cache volume as in (1).
Clone a volume from the cache volume and returns it to Cinder.
A file lock is placed on this method to prevent:
(a) a race condition when a cache volume has been verified, but then
gets deleted before it is cloned.
(b) failure of subsequent clone_image requests if the first request is
still pending.'

@utils.synchronized('zfssanfs', external=True)
def clone_image(self, context, volume, image_location, image_meta, image_service):

    LOG.debug('Cloning    image    %(image)s    to    volume    %(volume)s', {'image': image_meta['id'], 'volume': volume['name']})
    lcfg = self.configuration
    cachevol_size = 0
    if (not lcfg.zfssa_enable_local_cache):
        return (None, False)
    with image_utils.TemporaryImages.fetch(image_service, context, image_meta['id']) as tmp_image:
        info = image_utils.qemu_img_info(tmp_image)
        cachevol_size = int(math.ceil((float(info.virtual_size) / units.Gi)))
    if (cachevol_size > volume['size']):
        exception_msg = ('Image    size    %(img_size)dGB    is    larger    than    volume    size    %(vol_size)dGB.', {'img_size': cachevol_size, 'vol_size': volume['size']})
        LOG.error(exception_msg)
        return (None, False)
    updated_at = six.text_type(image_meta['updated_at'].isoformat())
    cachevol_props = {'id': image_meta['id'], 'size': cachevol_size, 'updated_at': updated_at, 'image_id': image_meta['id']}
    try:
        cachevol_name = self._verify_cache_volume(context, image_meta, image_service, cachevol_props)
        cache_vol = {'name': cachevol_name, 'size': cachevol_size, 'id': image_meta['id']}
        clone_vol = self.create_cloned_volume(volume, cache_vol)
        self._update_origin(volume['name'], cachevol_name)
    except exception.VolumeBackendAPIException as exc:
        exception_msg = ('Cannot    clone    image    %(image)s    to    volume    %(volume)s.    Error:    %(error)s.', {'volume': volume['name'], 'image': image_meta['id'], 'error': exc.msg})
        LOG.error(exception_msg)
        return (None, False)
    return (clone_vol, True)
