5252from cinder .i18n import _
5353from cinder .image import accelerator
5454from cinder .image import glance
55- import cinder .privsep .format_inspector
5655from cinder import utils
5756from cinder .volume import throttling
5857from cinder .volume import volume_utils
@@ -154,26 +153,11 @@ def from_qemu_img_disk_format(disk_format: str) -> str:
154153 return QEMU_IMG_FORMAT_MAP_INV .get (disk_format , disk_format )
155154
156155
157- def qemu_img_info (
158- path : str ,
159- run_as_root : bool = True ,
160- force_share : bool = False ,
161- allow_qcow2_backing_file : bool = False ) -> imageutils .QemuImgInfo :
156+ def qemu_img_info (path : str ,
157+ run_as_root : bool = True ,
158+ force_share : bool = False ) -> imageutils .QemuImgInfo :
162159 """Return an object containing the parsed output from qemu-img info."""
163-
164- format_name = cinder .privsep .format_inspector .get_format_if_safe (
165- path = path ,
166- allow_qcow2_backing_file = allow_qcow2_backing_file )
167- if format_name is None :
168- LOG .warning ('Image/Volume %s failed safety check' , path )
169- # NOTE(danms): This is the same exception as would be raised
170- # by qemu_img_info() if the disk format was unreadable or
171- # otherwise unsuitable.
172- raise exception .Invalid (
173- reason = _ ('Image/Volume failed safety check' ))
174-
175- cmd = ['env' , 'LC_ALL=C' , 'qemu-img' , 'info' ,
176- '-f' , format_name , '--output=json' ]
160+ cmd = ['env' , 'LC_ALL=C' , 'qemu-img' , 'info' , '--output=json' ]
177161 if force_share :
178162 if qemu_img_supports_force_share ():
179163 cmd .append ('--force-share' )
@@ -189,32 +173,8 @@ def qemu_img_info(
189173 prlimit = QEMU_IMG_LIMITS )
190174 info = imageutils .QemuImgInfo (out , format = 'json' )
191175
192- # FIXME: figure out a more elegant way to do this
193- if info .file_format == 'raw' :
194- # The format_inspector will detect a luks image as 'raw', and then when
195- # we call qemu-img info -f raw above, we don't get any of the luks
196- # format-specific info (some of which is used in the create_volume
197- # flow). So we need to check if this is really a luks container.
198- # (We didn't have to do this in the past because we called
199- # qemu-img info without -f.)
200- cmd = ['env' , 'LC_ALL=C' , 'qemu-img' , 'info' ,
201- '-f' , 'luks' , '--output=json' ]
202- if force_share :
203- cmd .append ('--force-share' )
204- cmd .append (path )
205- if os .name == 'nt' :
206- cmd = cmd [2 :]
207- try :
208- out , _err = utils .execute (* cmd , run_as_root = run_as_root ,
209- prlimit = QEMU_IMG_LIMITS )
210- info = imageutils .QemuImgInfo (out , format = 'json' )
211- except processutils .ProcessExecutionError :
212- # we'll just use the info object we already got earlier
213- pass
214-
215176 # From Cinder's point of view, any 'luks' formatted images
216- # should be treated as 'raw'. (This changes the file_format, but
217- # not any of the format-specific information.)
177+ # should be treated as 'raw'.
218178 if info .file_format == 'luks' :
219179 info .file_format = 'raw'
220180
@@ -720,35 +680,6 @@ def get_qemu_data(image_id: str,
720680 return data
721681
722682
723- def check_qcow2_image (image_id : str , data : imageutils .QemuImgInfo ) -> None :
724- """Check some rules about qcow2 images.
725-
726- Does not check for a backing_file, because cinder has some legitimate
727- use cases for qcow2 backing files.
728-
729- Makes sure the image:
730-
731- - does not have a data_file
732-
733- :param image_id: the image id
734- :param data: an imageutils.QemuImgInfo object
735- :raises ImageUnacceptable: when the image fails the check
736- """
737- try :
738- data_file = data .format_specific ['data' ].get ('data-file' )
739- except (KeyError , TypeError ):
740- LOG .debug ('Unexpected response from qemu-img info when processing '
741- 'image %s: missing format-specific info for a qcow2 image' ,
742- image_id )
743- msg = _ ('Cannot determine format-specific information' )
744- raise exception .ImageUnacceptable (image_id = image_id , reason = msg )
745- if data_file :
746- LOG .warning ("Refusing to process qcow2 file with data-file '%s'" ,
747- data_file )
748- msg = _ ('A qcow2 format image is not allowed to have a data file' )
749- raise exception .ImageUnacceptable (image_id = image_id , reason = msg )
750-
751-
752683def check_vmdk_image (image_id : str , data : imageutils .QemuImgInfo ) -> None :
753684 """Check some rules about VMDK images.
754685
@@ -839,8 +770,6 @@ def check_image_format(source: str,
839770
840771 if data .file_format == 'vmdk' :
841772 check_vmdk_image (image_id , data )
842- if data .file_format == 'qcow2' :
843- check_qcow2_image (image_id , data )
844773
845774
846775def fetch_verify_image (context : context .RequestContext ,
@@ -883,11 +812,6 @@ def fetch_verify_image(context: context.RequestContext,
883812 if fmt == 'vmdk' :
884813 check_vmdk_image (image_id , data )
885814
886- # Bug #2059809: a qcow2 can have a data file that's similar
887- # to a backing file and is also unacceptable
888- if fmt == 'qcow2' :
889- check_qcow2_image (image_id , data )
890-
891815
892816def fetch_to_vhd (context : context .RequestContext ,
893817 image_service : glance .GlanceImageService ,
0 commit comments