Comment 0 for bug 1977868

Revision history for this message
norman shen (jshen28) wrote :

hello,

I am reading cinder source code got confused on creating volume from an image. The problem I am seeing is the image is fetched.

The first time is here

            if not cloned:
                try:
                    with image_utils.TemporaryImages.fetch(
                            image_service, context, image_id,
                            backend_name) as tmp_image:
                        if CONF.verify_glance_signatures != 'disabled':
                            # Verify image signature via reading content from
                            # temp image, and store the verification flag if
                            # required.
                            verified = \
                                image_utils.verify_glance_image_signature(
                                    context, image_service,
                                    image_id, tmp_image)
                            self.db.volume_glance_metadata_bulk_create(
                                context, volume.id,
                                {'signature_verified': verified})
                        # Try to create the volume as the minimal size,
                        # then we can extend once the image has been
                        # downloaded.
                        data = image_utils.qemu_img_info(tmp_image)

                        virtual_size = image_utils.check_virtual_size(
                            data.virtual_size, volume.size, image_id)

                        if should_create_cache_entry:
                            if virtual_size and virtual_size != original_size:
                                volume.size = virtual_size
                                volume.save()
                        model_update = self._create_from_image_download(
                            context,
                            volume,
                            image_location,
                            image_meta,
                            image_service

and the second time is here

    def _copy_image_to_volume(self,
                              context: context.RequestContext,
                              volume: Volume,
                              image_service: Any,
                              image_id: str,
                              encrypted: bool = False) -> None:

        tmp_dir = volume_utils.image_conversion_dir()

        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
            image_utils.fetch_to_raw(context, image_service, image_id,
                                     tmp.name,
                                     self.configuration.volume_dd_blocksize,
                                     size=volume.size)

            if encrypted:
                self._encrypt_image(context, volume, tmp_dir, tmp.name)

            @utils.retry(exception.VolumeIsBusy,
                         self.configuration.rados_connection_interval,
                         self.configuration.rados_connection_retries)
            def _delete_volume(volume: Volume) -> None:
                self.delete_volume(volume)

            _delete_volume(volume)

IMO downloading image two times is not very efficient especially the image type is raw and original size is huge.