aboutsummaryrefslogtreecommitdiff
path: root/block/raw.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2010-04-14 14:17:38 +0200
committerKevin Wolf <kwolf@redhat.com>2010-05-03 10:07:30 +0200
commit66f82ceed6781261c09e65fb440ca76842fd0500 (patch)
tree138160d48093543a87d4db02b94267d564e2d258 /block/raw.c
parent579153325158d944be544ced96c6218e7d48802a (diff)
block: Open the underlying image file in generic code
Format drivers shouldn't need to bother with things like file names, but rather just get an open BlockDriverState for the underlying protocol. This patch introduces this behaviour for bdrv_open implementation. For protocols which need to access the filename to open their file/device/connection/... a new callback bdrv_file_open is introduced which doesn't get an underlying file opened. For now, also some of the more obscure formats use bdrv_file_open because they open() the file themselves instead of using the block.c functions. They need to be fixed in later patches. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/raw.c')
-rw-r--r--block/raw.c63
1 files changed, 18 insertions, 45 deletions
diff --git a/block/raw.c b/block/raw.c
index 953e2858af..4406b8c06b 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -3,84 +3,61 @@
#include "block_int.h"
#include "module.h"
-typedef struct RAWState {
- BlockDriverState *hd;
-} RAWState;
-
-static int raw_open(BlockDriverState *bs, const char *filename, int flags)
+static int raw_open(BlockDriverState *bs, int flags)
{
- RAWState *s = bs->opaque;
- int ret;
-
- ret = bdrv_file_open(&s->hd, filename, flags);
- if (!ret) {
- bs->sg = s->hd->sg;
- }
-
- return ret;
+ bs->sg = bs->file->sg;
+ return 0;
}
static int raw_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
- RAWState *s = bs->opaque;
- return bdrv_read(s->hd, sector_num, buf, nb_sectors);
+ return bdrv_read(bs->file, sector_num, buf, nb_sectors);
}
static int raw_write(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors)
{
- RAWState *s = bs->opaque;
- return bdrv_write(s->hd, sector_num, buf, nb_sectors);
+ return bdrv_write(bs->file, sector_num, buf, nb_sectors);
}
static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque)
{
- RAWState *s = bs->opaque;
-
- return bdrv_aio_readv(s->hd, sector_num, qiov, nb_sectors, cb, opaque);
+ return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
}
static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque)
{
- RAWState *s = bs->opaque;
-
- return bdrv_aio_writev(s->hd, sector_num, qiov, nb_sectors, cb, opaque);
+ return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
}
static void raw_close(BlockDriverState *bs)
{
- RAWState *s = bs->opaque;
- bdrv_delete(s->hd);
}
static void raw_flush(BlockDriverState *bs)
{
- RAWState *s = bs->opaque;
- bdrv_flush(s->hd);
+ bdrv_flush(bs->file);
}
static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
BlockDriverCompletionFunc *cb, void *opaque)
{
- RAWState *s = bs->opaque;
- return bdrv_aio_flush(s->hd, cb, opaque);
+ return bdrv_aio_flush(bs->file, cb, opaque);
}
static int64_t raw_getlength(BlockDriverState *bs)
{
- RAWState *s = bs->opaque;
- return bdrv_getlength(s->hd);
+ return bdrv_getlength(bs->file);
}
static int raw_truncate(BlockDriverState *bs, int64_t offset)
{
- RAWState *s = bs->opaque;
- return bdrv_truncate(s->hd, offset);
+ return bdrv_truncate(bs->file, offset);
}
static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
@@ -90,35 +67,30 @@ static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
static int raw_is_inserted(BlockDriverState *bs)
{
- RAWState *s = bs->opaque;
- return bdrv_is_inserted(s->hd);
+ return bdrv_is_inserted(bs->file);
}
static int raw_eject(BlockDriverState *bs, int eject_flag)
{
- RAWState *s = bs->opaque;
- return bdrv_eject(s->hd, eject_flag);
+ return bdrv_eject(bs->file, eject_flag);
}
static int raw_set_locked(BlockDriverState *bs, int locked)
{
- RAWState *s = bs->opaque;
- bdrv_set_locked(s->hd, locked);
+ bdrv_set_locked(bs->file, locked);
return 0;
}
static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
{
- RAWState *s = bs->opaque;
- return bdrv_ioctl(s->hd, req, buf);
+ return bdrv_ioctl(bs->file, req, buf);
}
static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
unsigned long int req, void *buf,
BlockDriverCompletionFunc *cb, void *opaque)
{
- RAWState *s = bs->opaque;
- return bdrv_aio_ioctl(s->hd, req, buf, cb, opaque);
+ return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
}
static int raw_create(const char *filename, QEMUOptionParameter *options)
@@ -138,7 +110,8 @@ static QEMUOptionParameter raw_create_options[] = {
static BlockDriver bdrv_raw = {
.format_name = "raw",
- .instance_size = sizeof(RAWState),
+ /* It's really 0, but we need to make qemu_malloc() happy */
+ .instance_size = 1,
.bdrv_open = raw_open,
.bdrv_close = raw_close,