summaryrefslogtreecommitdiff
path: root/block.h
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2011-09-06 18:58:54 +0200
committerKevin Wolf <kwolf@redhat.com>2011-09-12 15:17:21 +0200
commitd1a0739de59501809ad5382030a0d0eba98b69b0 (patch)
tree64881cbcde20aaa04ea3b548a6c38380fbe3b890 /block.h
parente4def80b36231e161b91fa984cd0d73b45668f00 (diff)
downloadqemu-d1a0739de59501809ad5382030a0d0eba98b69b0.tar.gz
qemu-d1a0739de59501809ad5382030a0d0eba98b69b0.tar.bz2
qemu-d1a0739de59501809ad5382030a0d0eba98b69b0.zip
block: Move BlockConf & friends from block_int.h to block.h
It's convenience stuff for block device models, so block.h isn't the ideal home either, but better than block_int.h. Permits moving some #include "block_int.h" from device model .h into .c. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.h')
-rw-r--r--block.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/block.h b/block.h
index 9f6d02ccdb..6e0c4683b9 100644
--- a/block.h
+++ b/block.h
@@ -350,5 +350,43 @@ typedef enum {
#define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
+
+/* Convenience for block device models */
+
+typedef struct BlockConf {
+ BlockDriverState *bs;
+ 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;
+} 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) \
+ DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \
+ DEFINE_PROP_UINT16("logical_block_size", _state, \
+ _conf.logical_block_size, 512), \
+ DEFINE_PROP_UINT16("physical_block_size", _state, \
+ _conf.physical_block_size, 512), \
+ 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_INT32("bootindex", _state, _conf.bootindex, -1), \
+ DEFINE_PROP_UINT32("discard_granularity", _state, \
+ _conf.discard_granularity, 0)
+
#endif