Skip to content

Commit 8c39825

Browse files
committed
block/qdev: Allow configuring rerror/werror with qdev properties
The rerror/werror policies are implemented in the devices, so that's where they should be configured. In comparison to the old options in -drive, the qdev properties are only added to those devices that actually support them. If the option isn't given (or "auto" is specified), the setting of the BlockBackend is used for compatibility with the old options. For block jobs, "auto" is the same as "enospc". Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
1 parent 1e8fb7f commit 8c39825

File tree

10 files changed

+45
-1
lines changed

10 files changed

+45
-1
lines changed

block/block-backend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
11731173
return BLOCK_ERROR_ACTION_REPORT;
11741174
case BLOCKDEV_ON_ERROR_IGNORE:
11751175
return BLOCK_ERROR_ACTION_IGNORE;
1176+
case BLOCKDEV_ON_ERROR_AUTO:
11761177
default:
11771178
abort();
11781179
}

blockjob.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
553553

554554
switch (on_err) {
555555
case BLOCKDEV_ON_ERROR_ENOSPC:
556+
case BLOCKDEV_ON_ERROR_AUTO:
556557
action = (error == ENOSPC) ?
557558
BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT;
558559
break;

hw/block/block.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void blkconf_blocksizes(BlockConf *conf)
5454
void blkconf_apply_backend_options(BlockConf *conf)
5555
{
5656
BlockBackend *blk = conf->blk;
57+
BlockdevOnError rerror, werror;
5758
bool wce;
5859

5960
switch (conf->wce) {
@@ -64,7 +65,18 @@ void blkconf_apply_backend_options(BlockConf *conf)
6465
abort();
6566
}
6667

68+
rerror = conf->rerror;
69+
if (rerror == BLOCKDEV_ON_ERROR_AUTO) {
70+
rerror = blk_get_on_error(blk, true);
71+
}
72+
73+
werror = conf->werror;
74+
if (werror == BLOCKDEV_ON_ERROR_AUTO) {
75+
werror = blk_get_on_error(blk, false);
76+
}
77+
6778
blk_set_enable_write_cache(blk, wce);
79+
blk_set_on_error(blk, rerror, werror);
6880
}
6981

7082
void blkconf_geometry(BlockConf *conf, int *ptrans,

hw/block/virtio-blk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ static void virtio_blk_instance_init(Object *obj)
960960

961961
static Property virtio_blk_properties[] = {
962962
DEFINE_BLOCK_PROPERTIES(VirtIOBlock, conf.conf),
963+
DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf),
963964
DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf),
964965
DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial),
965966
DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true),

hw/core/qdev-properties.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,19 @@ PropertyInfo qdev_prop_losttickpolicy = {
539539
.set = set_enum,
540540
};
541541

542+
/* --- Block device error handling policy --- */
543+
544+
QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError) != sizeof(int));
545+
546+
PropertyInfo qdev_prop_blockdev_on_error = {
547+
.name = "BlockdevOnError",
548+
.description = "Error handling policy, "
549+
"report/ignore/enospc/stop/auto",
550+
.enum_table = BlockdevOnError_lookup,
551+
.get = get_enum,
552+
.set = set_enum,
553+
};
554+
542555
/* --- BIOS CHS translation */
543556

544557
QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation) != sizeof(int));

hw/ide/qdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ static int ide_drive_initfn(IDEDevice *dev)
264264

265265
#define DEFINE_IDE_DEV_PROPERTIES() \
266266
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
267+
DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
267268
DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
268269
DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
269270
DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\

hw/scsi/scsi-disk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,6 +2849,7 @@ static const TypeInfo scsi_disk_base_info = {
28492849

28502850
#define DEFINE_SCSI_DISK_PROPERTIES() \
28512851
DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \
2852+
DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \
28522853
DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
28532854
DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \
28542855
DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \

include/hw/block/block.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ typedef struct BlockConf {
2626
/* geometry, not all devices use this */
2727
uint32_t cyls, heads, secs;
2828
OnOffAuto wce;
29+
BlockdevOnError rerror;
30+
BlockdevOnError werror;
2931
} BlockConf;
3032

3133
static inline unsigned int get_physical_block_exp(BlockConf *conf)
@@ -58,6 +60,12 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
5860
DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \
5961
DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0)
6062

63+
#define DEFINE_BLOCK_ERROR_PROPERTIES(_state, _conf) \
64+
DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \
65+
BLOCKDEV_ON_ERROR_AUTO), \
66+
DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \
67+
BLOCKDEV_ON_ERROR_AUTO)
68+
6169
/* Configuration helpers */
6270

6371
void blkconf_serial(BlockConf *conf, char **serial);

include/hw/qdev-properties.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern PropertyInfo qdev_prop_ptr;
2020
extern PropertyInfo qdev_prop_macaddr;
2121
extern PropertyInfo qdev_prop_on_off_auto;
2222
extern PropertyInfo qdev_prop_losttickpolicy;
23+
extern PropertyInfo qdev_prop_blockdev_on_error;
2324
extern PropertyInfo qdev_prop_bios_chs_trans;
2425
extern PropertyInfo qdev_prop_fdc_drive_type;
2526
extern PropertyInfo qdev_prop_drive;
@@ -161,6 +162,9 @@ extern PropertyInfo qdev_prop_arraylen;
161162
#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
162163
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
163164
LostTickPolicy)
165+
#define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
166+
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
167+
BlockdevOnError)
164168
#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
165169
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
166170
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \

qapi/block-core.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,12 @@
664664
# @stop: for guest operations, stop the virtual machine;
665665
# for jobs, pause the job
666666
#
667+
# @auto: inherit the error handling policy of the backend (since: 2.7)
668+
#
667669
# Since: 1.3
668670
##
669671
{ 'enum': 'BlockdevOnError',
670-
'data': ['report', 'ignore', 'enospc', 'stop'] }
672+
'data': ['report', 'ignore', 'enospc', 'stop', 'auto'] }
671673

672674
##
673675
# @MirrorSyncMode:

0 commit comments

Comments
 (0)