2012-07-10 13:12:31 +04:00
|
|
|
/*
|
|
|
|
* Common code for block device models
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or
|
|
|
|
* later. See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-06-29 11:12:57 +03:00
|
|
|
#ifndef HW_BLOCK_H
|
|
|
|
#define HW_BLOCK_H
|
2012-07-10 13:12:31 +04:00
|
|
|
|
|
|
|
#include "qemu-common.h"
|
|
|
|
|
2012-07-11 17:08:36 +04:00
|
|
|
/* Configuration */
|
|
|
|
|
|
|
|
typedef struct BlockConf {
|
2014-10-07 15:59:18 +04:00
|
|
|
BlockBackend *blk;
|
2012-07-11 17:08:36 +04:00
|
|
|
uint16_t physical_block_size;
|
|
|
|
uint16_t logical_block_size;
|
|
|
|
uint16_t min_io_size;
|
|
|
|
uint32_t opt_io_size;
|
|
|
|
int32_t bootindex;
|
|
|
|
uint32_t discard_granularity;
|
|
|
|
/* geometry, not all devices use this */
|
|
|
|
uint32_t cyls, heads, secs;
|
2016-06-23 16:12:35 +03:00
|
|
|
OnOffAuto wce;
|
2017-01-24 15:58:00 +03:00
|
|
|
bool share_rw;
|
2016-06-29 18:41:35 +03:00
|
|
|
BlockdevOnError rerror;
|
|
|
|
BlockdevOnError werror;
|
2012-07-11 17:08:36 +04:00
|
|
|
} BlockConf;
|
|
|
|
|
|
|
|
static inline unsigned int get_physical_block_exp(BlockConf *conf)
|
|
|
|
{
|
|
|
|
unsigned int exp = 0, size;
|
|
|
|
|
|
|
|
for (size = conf->physical_block_size;
|
|
|
|
size > conf->logical_block_size;
|
|
|
|
size >>= 1) {
|
|
|
|
exp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
|
2014-10-07 15:59:18 +04:00
|
|
|
DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \
|
2012-07-11 17:08:36 +04:00
|
|
|
DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
|
2015-02-16 14:47:58 +03:00
|
|
|
_conf.logical_block_size), \
|
2012-07-11 17:08:36 +04:00
|
|
|
DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
|
2015-02-16 14:47:58 +03:00
|
|
|
_conf.physical_block_size), \
|
2012-07-11 17:08:36 +04:00
|
|
|
DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \
|
|
|
|
DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \
|
|
|
|
DEFINE_PROP_UINT32("discard_granularity", _state, \
|
2016-06-23 16:12:35 +03:00
|
|
|
_conf.discard_granularity, -1), \
|
2017-01-24 15:58:00 +03:00
|
|
|
DEFINE_PROP_ON_OFF_AUTO("write-cache", _state, _conf.wce, \
|
|
|
|
ON_OFF_AUTO_AUTO), \
|
|
|
|
DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false)
|
2012-07-11 17:08:36 +04:00
|
|
|
|
|
|
|
#define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \
|
|
|
|
DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \
|
|
|
|
DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \
|
|
|
|
DEFINE_PROP_UINT32("secs", _state, _conf.secs, 0)
|
|
|
|
|
2016-06-29 18:41:35 +03:00
|
|
|
#define DEFINE_BLOCK_ERROR_PROPERTIES(_state, _conf) \
|
|
|
|
DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \
|
|
|
|
BLOCKDEV_ON_ERROR_AUTO), \
|
|
|
|
DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \
|
|
|
|
BLOCKDEV_ON_ERROR_AUTO)
|
|
|
|
|
2012-07-11 17:08:37 +04:00
|
|
|
/* Configuration helpers */
|
|
|
|
|
|
|
|
void blkconf_serial(BlockConf *conf, char **serial);
|
2014-08-12 06:12:54 +04:00
|
|
|
void blkconf_geometry(BlockConf *conf, int *trans,
|
|
|
|
unsigned cyls_max, unsigned heads_max, unsigned secs_max,
|
|
|
|
Error **errp);
|
2015-02-16 14:47:58 +03:00
|
|
|
void blkconf_blocksizes(BlockConf *conf);
|
2017-01-24 15:43:31 +03:00
|
|
|
void blkconf_apply_backend_options(BlockConf *conf, bool readonly,
|
|
|
|
bool resizable, Error **errp);
|
2012-07-11 17:08:36 +04:00
|
|
|
|
2012-07-10 13:12:31 +04:00
|
|
|
/* Hard disk geometry */
|
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
void hd_geometry_guess(BlockBackend *blk,
|
2012-07-10 13:12:41 +04:00
|
|
|
uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
|
2012-07-10 13:12:37 +04:00
|
|
|
int *ptrans);
|
2012-07-10 13:12:53 +04:00
|
|
|
int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs);
|
2012-07-10 13:12:31 +04:00
|
|
|
|
|
|
|
#endif
|