@@ -633,7 +633,7 @@ BlockDriver *bdrv_find_protocol(const char *filename,
633633 }
634634
635635 if (!path_has_protocol (filename ) || !allow_protocol_prefix ) {
636- return bdrv_find_format ( "file" ) ;
636+ return & bdrv_file ;
637637 }
638638
639639 p = strchr (filename , ':' );
@@ -662,12 +662,7 @@ static int find_image_format(BlockDriverState *bs, const char *filename,
662662
663663 /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
664664 if (bs -> sg || !bdrv_is_inserted (bs ) || bdrv_getlength (bs ) == 0 ) {
665- drv = bdrv_find_format ("raw" );
666- if (!drv ) {
667- error_setg (errp , "Could not find raw image format" );
668- ret = - ENOENT ;
669- }
670- * pdrv = drv ;
665+ * pdrv = & bdrv_raw ;
671666 return ret ;
672667 }
673668
@@ -1182,7 +1177,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
11821177{
11831178 char * backing_filename = g_malloc0 (PATH_MAX );
11841179 int ret = 0 ;
1185- BlockDriver * back_drv = NULL ;
11861180 BlockDriverState * backing_hd ;
11871181 Error * local_err = NULL ;
11881182
@@ -1215,14 +1209,14 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
12151209
12161210 backing_hd = bdrv_new ("" , errp );
12171211
1218- if (bs -> backing_format [0 ] != '\0' ) {
1219- back_drv = bdrv_find_format (bs -> backing_format );
1212+ if (bs -> backing_format [0 ] != '\0' && ! qdict_haskey ( options , "driver" ) ) {
1213+ qdict_put ( options , "driver" , qstring_from_str (bs -> backing_format ) );
12201214 }
12211215
12221216 assert (bs -> backing_hd == NULL );
12231217 ret = bdrv_open (& backing_hd ,
12241218 * backing_filename ? backing_filename : NULL , NULL , options ,
1225- bdrv_backing_flags (bs -> open_flags ), back_drv , & local_err );
1219+ bdrv_backing_flags (bs -> open_flags ), NULL , & local_err );
12261220 if (ret < 0 ) {
12271221 bdrv_unref (backing_hd );
12281222 backing_hd = NULL ;
@@ -1296,7 +1290,6 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
12961290 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
12971291 char * tmp_filename = g_malloc0 (PATH_MAX + 1 );
12981292 int64_t total_size ;
1299- BlockDriver * bdrv_qcow2 ;
13001293 QemuOpts * opts = NULL ;
13011294 QDict * snapshot_options ;
13021295 BlockDriverState * bs_snapshot ;
@@ -1322,11 +1315,10 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
13221315 goto out ;
13231316 }
13241317
1325- bdrv_qcow2 = bdrv_find_format ("qcow2" );
1326- opts = qemu_opts_create (bdrv_qcow2 -> create_opts , NULL , 0 ,
1318+ opts = qemu_opts_create (bdrv_qcow2 .create_opts , NULL , 0 ,
13271319 & error_abort );
13281320 qemu_opt_set_number (opts , BLOCK_OPT_SIZE , total_size );
1329- ret = bdrv_create (bdrv_qcow2 , tmp_filename , opts , & local_err );
1321+ ret = bdrv_create (& bdrv_qcow2 , tmp_filename , opts , & local_err );
13301322 qemu_opts_del (opts );
13311323 if (ret < 0 ) {
13321324 error_setg_errno (errp , - ret , "Could not create temporary overlay "
@@ -1346,7 +1338,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
13461338 bs_snapshot = bdrv_new ("" , & error_abort );
13471339
13481340 ret = bdrv_open (& bs_snapshot , NULL , NULL , snapshot_options ,
1349- flags , bdrv_qcow2 , & local_err );
1341+ flags , & bdrv_qcow2 , & local_err );
13501342 if (ret < 0 ) {
13511343 error_propagate (errp , local_err );
13521344 goto out ;
@@ -5535,6 +5527,18 @@ void bdrv_img_create(const char *filename, const char *fmt,
55355527 return ;
55365528 }
55375529
5530+ if (!drv -> create_opts ) {
5531+ error_setg (errp , "Format driver '%s' does not support image creation" ,
5532+ drv -> format_name );
5533+ return ;
5534+ }
5535+
5536+ if (!proto_drv -> create_opts ) {
5537+ error_setg (errp , "Protocol driver '%s' does not support image creation" ,
5538+ proto_drv -> format_name );
5539+ return ;
5540+ }
5541+
55385542 create_opts = qemu_opts_append (create_opts , drv -> create_opts );
55395543 create_opts = qemu_opts_append (create_opts , proto_drv -> create_opts );
55405544
0 commit comments