@@ -272,7 +272,7 @@ static void bdrv_put_ref_bh_schedule(BlockDriverState *bs)
272
272
qemu_bh_schedule (s -> bh );
273
273
}
274
274
275
- static int parse_block_error_action (const char * buf , bool is_read )
275
+ static int parse_block_error_action (const char * buf , bool is_read , Error * * errp )
276
276
{
277
277
if (!strcmp (buf , "ignore" )) {
278
278
return BLOCKDEV_ON_ERROR_IGNORE ;
@@ -283,8 +283,8 @@ static int parse_block_error_action(const char *buf, bool is_read)
283
283
} else if (!strcmp (buf , "report" )) {
284
284
return BLOCKDEV_ON_ERROR_REPORT ;
285
285
} else {
286
- error_report ( "'%s' invalid %s error action" ,
287
- buf , is_read ? "read" : "write" );
286
+ error_setg ( errp , "'%s' invalid %s error action" ,
287
+ buf , is_read ? "read" : "write" );
288
288
return -1 ;
289
289
}
290
290
}
@@ -309,7 +309,8 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
309
309
310
310
/* Takes the ownership of bs_opts */
311
311
static DriveInfo * blockdev_init (QDict * bs_opts ,
312
- BlockInterfaceType type )
312
+ BlockInterfaceType type ,
313
+ Error * * errp )
313
314
{
314
315
const char * buf ;
315
316
const char * file = NULL ;
@@ -333,15 +334,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
333
334
id = qdict_get_try_str (bs_opts , "id" );
334
335
opts = qemu_opts_create (& qemu_common_drive_opts , id , 1 , & error );
335
336
if (error_is_set (& error )) {
336
- qerror_report_err (error );
337
- error_free (error );
337
+ error_propagate (errp , error );
338
338
return NULL ;
339
339
}
340
340
341
341
qemu_opts_absorb_qdict (opts , bs_opts , & error );
342
342
if (error_is_set (& error )) {
343
- qerror_report_err (error );
344
- error_free (error );
343
+ error_propagate (errp , error );
345
344
return NULL ;
346
345
}
347
346
@@ -361,7 +360,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
361
360
362
361
if ((buf = qemu_opt_get (opts , "discard" )) != NULL ) {
363
362
if (bdrv_parse_discard_flags (buf , & bdrv_flags ) != 0 ) {
364
- error_report ( "invalid discard option" );
363
+ error_setg ( errp , "invalid discard option" );
365
364
return NULL ;
366
365
}
367
366
}
@@ -383,7 +382,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
383
382
} else if (!strcmp (buf , "threads" )) {
384
383
/* this is the default */
385
384
} else {
386
- error_report ( "invalid aio option" );
385
+ error_setg ( errp , "invalid aio option" );
387
386
return NULL ;
388
387
}
389
388
}
@@ -399,7 +398,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
399
398
400
399
drv = bdrv_find_format (buf );
401
400
if (!drv ) {
402
- error_report ( "'%s' invalid format" , buf );
401
+ error_setg ( errp , "'%s' invalid format" , buf );
403
402
return NULL ;
404
403
}
405
404
}
@@ -435,20 +434,20 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
435
434
cfg .op_size = qemu_opt_get_number (opts , "throttling.iops-size" , 0 );
436
435
437
436
if (!check_throttle_config (& cfg , & error )) {
438
- error_report ("%s" , error_get_pretty (error ));
439
- error_free (error );
437
+ error_propagate (errp , error );
440
438
return NULL ;
441
439
}
442
440
443
441
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC ;
444
442
if ((buf = qemu_opt_get (opts , "werror" )) != NULL ) {
445
443
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE ) {
446
- error_report ( "werror is not supported by this bus type" );
444
+ error_setg ( errp , "werror is not supported by this bus type" );
447
445
return NULL ;
448
446
}
449
447
450
- on_write_error = parse_block_error_action (buf , 0 );
451
- if (on_write_error < 0 ) {
448
+ on_write_error = parse_block_error_action (buf , 0 , & error );
449
+ if (error_is_set (& error )) {
450
+ error_propagate (errp , error );
452
451
return NULL ;
453
452
}
454
453
}
@@ -460,8 +459,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
460
459
return NULL ;
461
460
}
462
461
463
- on_read_error = parse_block_error_action (buf , 1 );
464
- if (on_read_error < 0 ) {
462
+ on_read_error = parse_block_error_action (buf , 1 , & error );
463
+ if (error_is_set (& error )) {
464
+ error_propagate (errp , error );
465
465
return NULL ;
466
466
}
467
467
}
@@ -514,8 +514,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
514
514
ret = bdrv_open (dinfo -> bdrv , file , bs_opts , bdrv_flags , drv , & error );
515
515
516
516
if (ret < 0 ) {
517
- error_report ("could not open disk image %s: %s" ,
518
- file ?: dinfo -> id , error_get_pretty (error ));
517
+ error_setg (errp , "could not open disk image %s: %s" ,
518
+ file ?: dinfo -> id , error_get_pretty (error ));
519
+ error_free (error );
519
520
goto err ;
520
521
}
521
522
@@ -862,9 +863,15 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
862
863
}
863
864
864
865
/* Actual block device init: Functionality shared with blockdev-add */
865
- dinfo = blockdev_init (bs_opts , type );
866
+ dinfo = blockdev_init (bs_opts , type , & local_err );
866
867
if (dinfo == NULL ) {
868
+ if (error_is_set (& local_err )) {
869
+ qerror_report_err (local_err );
870
+ error_free (local_err );
871
+ }
867
872
goto fail ;
873
+ } else {
874
+ assert (!error_is_set (& local_err ));
868
875
}
869
876
870
877
/* Set legacy DriveInfo fields */
@@ -2155,7 +2162,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
2155
2162
QmpOutputVisitor * ov = qmp_output_visitor_new ();
2156
2163
QObject * obj ;
2157
2164
QDict * qdict ;
2158
- DriveInfo * dinfo ;
2159
2165
Error * local_err = NULL ;
2160
2166
2161
2167
/* Require an ID in the top level */
@@ -2189,9 +2195,9 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
2189
2195
2190
2196
qdict_flatten (qdict );
2191
2197
2192
- dinfo = blockdev_init (qdict , IF_NONE );
2193
- if (! dinfo ) {
2194
- error_setg (errp , "Could not open image" );
2198
+ blockdev_init (qdict , IF_NONE , & local_err );
2199
+ if (error_is_set ( & local_err ) ) {
2200
+ error_propagate (errp , local_err );
2195
2201
goto fail ;
2196
2202
}
2197
2203
0 commit comments