]> git.proxmox.com Git - qemu.git/blobdiff - block/raw.c
block: Open the underlying image file in generic code
[qemu.git] / block / raw.c
index 953e2858af257053deddccc6716b63d27cda1a86..4406b8c06b8dbe2bdf6aefaa0f958d5dc4cf85ce 100644 (file)
@@ -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,