diff options
-rw-r--r-- | block-bochs.c | 10 | ||||
-rw-r--r-- | block-cloop.c | 10 | ||||
-rw-r--r-- | block-cow.c | 10 | ||||
-rw-r--r-- | block-dmg.c | 12 | ||||
-rw-r--r-- | block-nbd.c | 10 | ||||
-rw-r--r-- | block-parallels.c | 10 | ||||
-rw-r--r-- | block-qcow.c | 10 | ||||
-rw-r--r-- | block-qcow2.c | 10 | ||||
-rw-r--r-- | block-raw-posix.c | 13 | ||||
-rw-r--r-- | block-raw-win32.c | 13 | ||||
-rw-r--r-- | block-vmdk.c | 10 | ||||
-rw-r--r-- | block-vpc.c | 10 | ||||
-rw-r--r-- | block-vvfat.c | 12 | ||||
-rw-r--r-- | block.c | 35 | ||||
-rw-r--r-- | block.h | 16 | ||||
-rw-r--r-- | qemu-img.c | 10 |
16 files changed, 141 insertions, 60 deletions
diff --git a/block-bochs.c b/block-bochs.c index 7a75412d84..bac81c42b7 100644 --- a/block-bochs.c +++ b/block-bochs.c @@ -24,6 +24,7 @@ */ #include "qemu-common.h" #include "block_int.h" +#include "module.h" /**************************************************************/ @@ -241,7 +242,7 @@ static void bochs_close(BlockDriverState *bs) close(s->fd); } -BlockDriver bdrv_bochs = { +static BlockDriver bdrv_bochs = { .format_name = "bochs", .instance_size = sizeof(BDRVBochsState), .bdrv_probe = bochs_probe, @@ -249,3 +250,10 @@ BlockDriver bdrv_bochs = { .bdrv_read = bochs_read, .bdrv_close = bochs_close, }; + +static void bdrv_bochs_init(void) +{ + bdrv_register(&bdrv_bochs); +} + +block_init(bdrv_bochs_init); diff --git a/block-cloop.c b/block-cloop.c index 9414d10156..06c687e690 100644 --- a/block-cloop.c +++ b/block-cloop.c @@ -23,6 +23,7 @@ */ #include "qemu-common.h" #include "block_int.h" +#include "module.h" #include <zlib.h> typedef struct BDRVCloopState { @@ -153,7 +154,7 @@ static void cloop_close(BlockDriverState *bs) inflateEnd(&s->zstream); } -BlockDriver bdrv_cloop = { +static BlockDriver bdrv_cloop = { .format_name = "cloop", .instance_size = sizeof(BDRVCloopState), .bdrv_probe = cloop_probe, @@ -161,3 +162,10 @@ BlockDriver bdrv_cloop = { .bdrv_read = cloop_read, .bdrv_close = cloop_close, }; + +static void bdrv_cloop_init(void) +{ + bdrv_register(&bdrv_cloop); +} + +block_init(bdrv_cloop_init); diff --git a/block-cow.c b/block-cow.c index 17e3292258..94b3549389 100644 --- a/block-cow.c +++ b/block-cow.c @@ -24,6 +24,7 @@ #ifndef _WIN32 #include "qemu-common.h" #include "block_int.h" +#include "module.h" #include <sys/mman.h> /**************************************************************/ @@ -252,7 +253,7 @@ static void cow_flush(BlockDriverState *bs) fsync(s->fd); } -BlockDriver bdrv_cow = { +static BlockDriver bdrv_cow = { .format_name = "cow", .instance_size = sizeof(BDRVCowState), .bdrv_probe = cow_probe, @@ -264,4 +265,11 @@ BlockDriver bdrv_cow = { .bdrv_flush = cow_flush, .bdrv_is_allocated = cow_is_allocated, }; + +static void bdrv_cow_init(void) +{ + bdrv_register(&bdrv_cow); +} + +block_init(bdrv_cow_init); #endif diff --git a/block-dmg.c b/block-dmg.c index 82f6de1946..262560ffd3 100644 --- a/block-dmg.c +++ b/block-dmg.c @@ -24,6 +24,7 @@ #include "qemu-common.h" #include "block_int.h" #include "bswap.h" +#include "module.h" #include <zlib.h> typedef struct BDRVDMGState { @@ -92,7 +93,7 @@ static int dmg_open(BlockDriverState *bs, const char *filename, int flags) dmg_close: close(s->fd); /* open raw instead */ - bs->drv=&bdrv_raw; + bs->drv=bdrv_find_format("raw"); return bs->drv->bdrv_open(bs, filename, flags); } info_begin=read_off(s->fd); @@ -283,7 +284,7 @@ static void dmg_close(BlockDriverState *bs) inflateEnd(&s->zstream); } -BlockDriver bdrv_dmg = { +static BlockDriver bdrv_dmg = { .format_name = "dmg", .instance_size = sizeof(BDRVDMGState), .bdrv_probe = dmg_probe, @@ -291,3 +292,10 @@ BlockDriver bdrv_dmg = { .bdrv_read = dmg_read, .bdrv_close = dmg_close, }; + +static void bdrv_dmg_init(void) +{ + bdrv_register(&bdrv_dmg); +} + +block_init(bdrv_dmg_init); diff --git a/block-nbd.c b/block-nbd.c index 632cb2dd2f..47d4778999 100644 --- a/block-nbd.c +++ b/block-nbd.c @@ -28,6 +28,7 @@ #include "qemu-common.h" #include "nbd.h" +#include "module.h" #include <sys/types.h> #include <unistd.h> @@ -176,7 +177,7 @@ static int64_t nbd_getlength(BlockDriverState *bs) return s->size; } -BlockDriver bdrv_nbd = { +static BlockDriver bdrv_nbd = { .format_name = "nbd", .instance_size = sizeof(BDRVNBDState), .bdrv_open = nbd_open, @@ -186,3 +187,10 @@ BlockDriver bdrv_nbd = { .bdrv_getlength = nbd_getlength, .protocol_name = "nbd", }; + +static void bdrv_nbd_init(void) +{ + bdrv_register(&bdrv_nbd); +} + +block_init(bdrv_nbd_init); diff --git a/block-parallels.c b/block-parallels.c index 18c3d834e7..0b64a5c625 100644 --- a/block-parallels.c +++ b/block-parallels.c @@ -25,6 +25,7 @@ */ #include "qemu-common.h" #include "block_int.h" +#include "module.h" /**************************************************************/ @@ -163,7 +164,7 @@ static void parallels_close(BlockDriverState *bs) close(s->fd); } -BlockDriver bdrv_parallels = { +static BlockDriver bdrv_parallels = { .format_name = "parallels", .instance_size = sizeof(BDRVParallelsState), .bdrv_probe = parallels_probe, @@ -171,3 +172,10 @@ BlockDriver bdrv_parallels = { .bdrv_read = parallels_read, .bdrv_close = parallels_close, }; + +static void bdrv_parallels_init(void) +{ + bdrv_register(&bdrv_parallels); +} + +block_init(bdrv_parallels_init); diff --git a/block-qcow.c b/block-qcow.c index fc6b809715..1cf7c3be77 100644 --- a/block-qcow.c +++ b/block-qcow.c @@ -23,6 +23,7 @@ */ #include "qemu-common.h" #include "block_int.h" +#include "module.h" #include <zlib.h> #include "aes.h" @@ -917,7 +918,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } -BlockDriver bdrv_qcow = { +static BlockDriver bdrv_qcow = { .format_name = "qcow", .instance_size = sizeof(BDRVQcowState), .bdrv_probe = qcow_probe, @@ -935,3 +936,10 @@ BlockDriver bdrv_qcow = { .bdrv_write_compressed = qcow_write_compressed, .bdrv_get_info = qcow_get_info, }; + +static void bdrv_qcow_init(void) +{ + bdrv_register(&bdrv_qcow); +} + +block_init(bdrv_qcow_init); diff --git a/block-qcow2.c b/block-qcow2.c index 2ad07250ef..a6de9b6919 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -23,6 +23,7 @@ */ #include "qemu-common.h" #include "block_int.h" +#include "module.h" #include <zlib.h> #include "aes.h" @@ -2891,7 +2892,7 @@ static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf, return ret; } -BlockDriver bdrv_qcow2 = { +static BlockDriver bdrv_qcow2 = { .format_name = "qcow2", .instance_size = sizeof(BDRVQcowState), .bdrv_probe = qcow_probe, @@ -2921,3 +2922,10 @@ BlockDriver bdrv_qcow2 = { .bdrv_create2 = qcow_create2, .bdrv_check = qcow_check, }; + +static void bdrv_qcow2_init(void) +{ + bdrv_register(&bdrv_qcow2); +} + +block_init(bdrv_qcow2_init); diff --git a/block-raw-posix.c b/block-raw-posix.c index 406ec7d04c..f3a9476b44 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -25,6 +25,7 @@ #include "qemu-timer.h" #include "qemu-char.h" #include "block_int.h" +#include "module.h" #ifdef CONFIG_AIO #include "posix-aio-compat.h" #endif @@ -845,7 +846,7 @@ static void raw_flush(BlockDriverState *bs) fsync(s->fd); } -BlockDriver bdrv_raw = { +static BlockDriver bdrv_raw = { .format_name = "raw", .instance_size = sizeof(BDRVRawState), .bdrv_probe = NULL, /* no probe for protocols */ @@ -1397,7 +1398,7 @@ static int hdev_create(const char *filename, int64_t total_size, } #endif -BlockDriver bdrv_host_device = { +static BlockDriver bdrv_host_device = { .format_name = "host_device", .instance_size = sizeof(BDRVRawState), .bdrv_open = hdev_open, @@ -1427,3 +1428,11 @@ BlockDriver bdrv_host_device = { .bdrv_aio_ioctl = raw_aio_ioctl, #endif }; + +static void bdrv_raw_init(void) +{ + bdrv_register(&bdrv_raw); + bdrv_register(&bdrv_host_device); +} + +block_init(bdrv_raw_init); diff --git a/block-raw-win32.c b/block-raw-win32.c index a998166a79..15f3ec4849 100644 --- a/block-raw-win32.c +++ b/block-raw-win32.c @@ -24,6 +24,7 @@ #include "qemu-common.h" #include "qemu-timer.h" #include "block_int.h" +#include "module.h" #include <windows.h> #include <winioctl.h> @@ -227,7 +228,7 @@ static int raw_create(const char *filename, int64_t total_size, return 0; } -BlockDriver bdrv_raw = { +static BlockDriver bdrv_raw = { .format_name = "raw", .instance_size = sizeof(BDRVRawState), .bdrv_open = raw_open, @@ -371,7 +372,7 @@ static int raw_set_locked(BlockDriverState *bs, int locked) } #endif -BlockDriver bdrv_host_device = { +static BlockDriver bdrv_host_device = { .format_name = "host_device", .instance_size = sizeof(BDRVRawState), .bdrv_open = hdev_open, @@ -382,3 +383,11 @@ BlockDriver bdrv_host_device = { .bdrv_write = raw_write, .bdrv_getlength = raw_getlength, }; + +static void bdrv_raw_init(void) +{ + bdrv_register(&bdrv_raw); + bdrv_register(&bdrv_host_device); +} + +block_init(bdrv_raw_init); diff --git a/block-vmdk.c b/block-vmdk.c index d47d4837a1..13866e9b06 100644 --- a/block-vmdk.c +++ b/block-vmdk.c @@ -25,6 +25,7 @@ #include "qemu-common.h" #include "block_int.h" +#include "module.h" #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D') #define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V') @@ -811,7 +812,7 @@ static void vmdk_flush(BlockDriverState *bs) bdrv_flush(s->hd); } -BlockDriver bdrv_vmdk = { +static BlockDriver bdrv_vmdk = { .format_name = "vmdk", .instance_size = sizeof(BDRVVmdkState), .bdrv_probe = vmdk_probe, @@ -823,3 +824,10 @@ BlockDriver bdrv_vmdk = { .bdrv_flush = vmdk_flush, .bdrv_is_allocated = vmdk_is_allocated, }; + +static void bdrv_vmdk_init(void) +{ + bdrv_register(&bdrv_vmdk); +} + +block_init(bdrv_vmdk_init); diff --git a/block-vpc.c b/block-vpc.c index 71a171d0eb..211ae5c72f 100644 --- a/block-vpc.c +++ b/block-vpc.c @@ -24,6 +24,7 @@ */ #include "qemu-common.h" #include "block_int.h" +#include "module.h" /**************************************************************/ @@ -586,7 +587,7 @@ static void vpc_close(BlockDriverState *bs) bdrv_delete(s->hd); } -BlockDriver bdrv_vpc = { +static BlockDriver bdrv_vpc = { .format_name = "vpc", .instance_size = sizeof(BDRVVPCState), .bdrv_probe = vpc_probe, @@ -596,3 +597,10 @@ BlockDriver bdrv_vpc = { .bdrv_close = vpc_close, .bdrv_create = vpc_create, }; + +static void bdrv_vpc_init(void) +{ + bdrv_register(&bdrv_vpc); +} + +block_init(bdrv_vpc_init); diff --git a/block-vvfat.c b/block-vvfat.c index 0f0760f90c..2a8feb38d8 100644 --- a/block-vvfat.c +++ b/block-vvfat.c @@ -26,6 +26,7 @@ #include <dirent.h> #include "qemu-common.h" #include "block_int.h" +#include "module.h" #ifndef S_IWGRP #define S_IWGRP 0 @@ -2776,7 +2777,7 @@ static int enable_write_target(BDRVVVFATState *s) s->qcow_filename = qemu_malloc(1024); get_tmp_filename(s->qcow_filename, 1024); - if (bdrv_create(&bdrv_qcow, + if (bdrv_create(bdrv_find_format("qcow"), s->qcow_filename, s->sector_count, "fat:", 0) < 0) return -1; s->qcow = bdrv_new(""); @@ -2806,7 +2807,7 @@ static void vvfat_close(BlockDriverState *bs) free(s->cluster_buffer); } -BlockDriver bdrv_vvfat = { +static BlockDriver bdrv_vvfat = { .format_name = "vvfat", .instance_size = sizeof(BDRVVVFATState), .bdrv_open = vvfat_open, @@ -2817,6 +2818,13 @@ BlockDriver bdrv_vvfat = { .protocol_name = "fat", }; +static void bdrv_vvfat_init(void) +{ + bdrv_register(&bdrv_vvfat); +} + +block_init(bdrv_vvfat_init); + #ifdef DEBUG static void checkpoint(void) { assert(((mapping_t*)array_get(&(vvv->mapping), 0))->end == 2); @@ -30,6 +30,7 @@ #include "qemu-common.h" #include "monitor.h" #include "block_int.h" +#include "module.h" #ifdef HOST_BSD #include <sys/types.h> @@ -138,7 +139,7 @@ void path_combine(char *dest, int dest_size, } -static void bdrv_register(BlockDriver *bdrv) +void bdrv_register(BlockDriver *bdrv) { if (!bdrv->bdrv_aio_readv) { /* add AIO emulation layer */ @@ -259,11 +260,11 @@ static BlockDriver *find_protocol(const char *filename) #ifdef _WIN32 if (is_windows_drive(filename) || is_windows_drive_prefix(filename)) - return &bdrv_raw; + return bdrv_find_format("raw"); #endif p = strchr(filename, ':'); if (!p) - return &bdrv_raw; + return bdrv_find_format("raw"); len = p - filename; if (len > sizeof(protocol) - 1) len = sizeof(protocol) - 1; @@ -289,23 +290,23 @@ static BlockDriver *find_image_format(const char *filename) /* detect host devices. By convention, /dev/cdrom[N] is always recognized as a host CDROM */ if (strstart(filename, "/dev/cdrom", NULL)) - return &bdrv_host_device; + return bdrv_find_format("host_device"); #ifdef _WIN32 if (is_windows_drive(filename)) - return &bdrv_host_device; + return bdrv_find_format("host_device"); #else { struct stat st; if (stat(filename, &st) >= 0 && (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) { - return &bdrv_host_device; + return bdrv_find_format("host_device"); } } #endif drv = find_protocol(filename); /* no need to test disk image formats for vvfat */ - if (drv == &bdrv_vvfat) + if (strcmp(drv->format_name, "vvfat") == 0) return drv; ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY); @@ -396,14 +397,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, else realpath(filename, backing_filename); - ret = bdrv_create2(&bdrv_qcow2, tmp_filename, + ret = bdrv_create2(bdrv_find_format("qcow2"), tmp_filename, total_size, backing_filename, (drv ? drv->format_name : NULL), 0); if (ret < 0) { return ret; } filename = tmp_filename; - drv = &bdrv_qcow2; + drv = bdrv_find_format("qcow2"); bs->is_temporary = 1; } @@ -1494,21 +1495,7 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num, void bdrv_init(void) { - bdrv_register(&bdrv_raw); - bdrv_register(&bdrv_host_device); -#ifndef _WIN32 - bdrv_register(&bdrv_cow); -#endif - bdrv_register(&bdrv_qcow); - bdrv_register(&bdrv_vmdk); - bdrv_register(&bdrv_cloop); - bdrv_register(&bdrv_dmg); - bdrv_register(&bdrv_bochs); - bdrv_register(&bdrv_vpc); - bdrv_register(&bdrv_vvfat); - bdrv_register(&bdrv_qcow2); - bdrv_register(&bdrv_parallels); - bdrv_register(&bdrv_nbd); + module_call_init(MODULE_INIT_BLOCK); } void aio_pool_init(AIOPool *pool, int aiocb_size, @@ -7,20 +7,6 @@ /* block.c */ typedef struct BlockDriver BlockDriver; -extern BlockDriver bdrv_raw; -extern BlockDriver bdrv_host_device; -extern BlockDriver bdrv_cow; -extern BlockDriver bdrv_qcow; -extern BlockDriver bdrv_vmdk; -extern BlockDriver bdrv_cloop; -extern BlockDriver bdrv_dmg; -extern BlockDriver bdrv_bochs; -extern BlockDriver bdrv_vpc; -extern BlockDriver bdrv_vvfat; -extern BlockDriver bdrv_qcow2; -extern BlockDriver bdrv_parallels; -extern BlockDriver bdrv_nbd; - typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; @@ -87,6 +73,8 @@ int64_t bdrv_getlength(BlockDriverState *bs); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs); int bdrv_commit(BlockDriverState *bs); +void bdrv_register(BlockDriver *bdrv); + /* async block I/O */ typedef struct BlockDriverAIOCB BlockDriverAIOCB; typedef void BlockDriverCompletionFunc(void *opaque, int ret); diff --git a/qemu-img.c b/qemu-img.c index 32c5b42008..a3d15e716b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -542,11 +542,11 @@ static int img_convert(int argc, char **argv) drv = bdrv_find_format(out_fmt); if (!drv) error("Unknown file format '%s'", out_fmt); - if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2) + if (flags & BLOCK_FLAG_COMPRESS && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2")) error("Compression not supported for this file format"); - if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2) + if (flags & BLOCK_FLAG_ENCRYPT && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2")) error("Encryption not supported for this file format"); - if (flags & BLOCK_FLAG_COMPAT6 && drv != &bdrv_vmdk) + if (flags & BLOCK_FLAG_COMPAT6 && strcmp(drv->format_name, "vmdk")) error("Alternative compatibility level not supported for this file format"); if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) error("Compression and encryption not supported at the same time"); @@ -655,7 +655,7 @@ static int img_convert(int argc, char **argv) if (n > bs_offset + bs_sectors - sector_num) n = bs_offset + bs_sectors - sector_num; - if (drv != &bdrv_host_device) { + if (strcmp(drv->format_name, "host_device")) { if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, n, &n1)) { sector_num += n1; @@ -682,7 +682,7 @@ static int img_convert(int argc, char **argv) If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ - if (drv == &bdrv_host_device || out_baseimg || + if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg || is_allocated_sectors(buf1, n, &n1)) { if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) error("error while writing"); |