block: Split change_cb() into change_media_cb(), resize_cb()

Multiplexing callbacks complicates matters needlessly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Markus Armbruster 2011-08-03 15:07:42 +02:00 committed by Kevin Wolf
parent 0e49de5232
commit 145feb176f
6 changed files with 33 additions and 29 deletions

23
block.c
View file

@ -44,7 +44,7 @@
#include <windows.h>
#endif
static void bdrv_dev_change_cb(BlockDriverState *bs, int reason);
static void bdrv_dev_change_media_cb(BlockDriverState *bs);
static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque);
@ -690,7 +690,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
if (!bdrv_key_required(bs)) {
bs->media_changed = 1;
bdrv_dev_change_cb(bs, CHANGE_MEDIA);
bdrv_dev_change_media_cb(bs);
}
return 0;
@ -727,7 +727,7 @@ void bdrv_close(BlockDriverState *bs)
}
bs->media_changed = 1;
bdrv_dev_change_cb(bs, CHANGE_MEDIA);
bdrv_dev_change_media_cb(bs);
}
}
@ -806,10 +806,17 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
bs->dev_opaque = opaque;
}
static void bdrv_dev_change_cb(BlockDriverState *bs, int reason)
static void bdrv_dev_change_media_cb(BlockDriverState *bs)
{
if (bs->dev_ops && bs->dev_ops->change_cb) {
bs->dev_ops->change_cb(bs->dev_opaque, reason);
if (bs->dev_ops && bs->dev_ops->change_media_cb) {
bs->dev_ops->change_media_cb(bs->dev_opaque);
}
}
static void bdrv_dev_resize_cb(BlockDriverState *bs)
{
if (bs->dev_ops && bs->dev_ops->resize_cb) {
bs->dev_ops->resize_cb(bs->dev_opaque);
}
}
@ -1283,7 +1290,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);
bdrv_dev_change_cb(bs, CHANGE_SIZE);
bdrv_dev_resize_cb(bs);
}
return ret;
}
@ -1659,7 +1666,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;
bdrv_dev_change_cb(bs, CHANGE_MEDIA);
bdrv_dev_change_media_cb(bs);
}
return ret;
}