diff options
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -44,6 +44,7 @@ #include <windows.h> #endif +static void bdrv_dev_change_cb(BlockDriverState *bs, int reason); static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); @@ -688,10 +689,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, } if (!bdrv_key_required(bs)) { - /* call the change callback */ bs->media_changed = 1; - if (bs->change_cb) - bs->change_cb(bs->change_opaque, CHANGE_MEDIA); + bdrv_dev_change_cb(bs, CHANGE_MEDIA); } return 0; @@ -727,10 +726,8 @@ void bdrv_close(BlockDriverState *bs) bdrv_close(bs->file); } - /* call the change callback */ bs->media_changed = 1; - if (bs->change_cb) - bs->change_cb(bs->change_opaque, CHANGE_MEDIA); + bdrv_dev_change_cb(bs, CHANGE_MEDIA); } } @@ -792,8 +789,8 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev) { assert(bs->dev == dev); bs->dev = NULL; - bs->change_cb = NULL; - bs->change_opaque = NULL; + bs->dev_ops = NULL; + bs->dev_opaque = NULL; } /* TODO change to return DeviceState * when all users are qdevified */ @@ -802,6 +799,20 @@ void *bdrv_get_attached_dev(BlockDriverState *bs) return bs->dev; } +void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, + void *opaque) +{ + bs->dev_ops = ops; + bs->dev_opaque = opaque; +} + +static void bdrv_dev_change_cb(BlockDriverState *bs, int reason) +{ + if (bs->dev_ops && bs->dev_ops->change_cb) { + bs->dev_ops->change_cb(bs->dev_opaque, reason); + } +} + /* * Run consistency checks on an image * @@ -1272,9 +1283,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) ret = drv->bdrv_truncate(bs, offset); if (ret == 0) { ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); - if (bs->change_cb) { - bs->change_cb(bs->change_opaque, CHANGE_SIZE); - } + bdrv_dev_change_cb(bs, CHANGE_SIZE); } return ret; } @@ -1612,15 +1621,6 @@ int bdrv_enable_write_cache(BlockDriverState *bs) return bs->enable_write_cache; } -/* XXX: no longer used */ -void bdrv_set_change_cb(BlockDriverState *bs, - void (*change_cb)(void *opaque, int reason), - void *opaque) -{ - bs->change_cb = change_cb; - bs->change_opaque = opaque; -} - int bdrv_is_encrypted(BlockDriverState *bs) { if (bs->backing_hd && bs->backing_hd->encrypted) @@ -1659,8 +1659,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) bs->valid_key = 1; /* call the change callback now, we skipped it on open */ bs->media_changed = 1; - if (bs->change_cb) - bs->change_cb(bs->change_opaque, CHANGE_MEDIA); + bdrv_dev_change_cb(bs, CHANGE_MEDIA); } return ret; } |