Commit 5efa9d5a8b18841c9c62208a494d7f519238979a

Authored by Anthony Liguori
1 parent 0bfe3ca5

Convert block infrastructure to use new module init functionality

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
block-bochs.c
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 */ 24 */
25 #include "qemu-common.h" 25 #include "qemu-common.h"
26 #include "block_int.h" 26 #include "block_int.h"
  27 +#include "module.h"
27 28
28 /**************************************************************/ 29 /**************************************************************/
29 30
@@ -241,7 +242,7 @@ static void bochs_close(BlockDriverState *bs) @@ -241,7 +242,7 @@ static void bochs_close(BlockDriverState *bs)
241 close(s->fd); 242 close(s->fd);
242 } 243 }
243 244
244 -BlockDriver bdrv_bochs = { 245 +static BlockDriver bdrv_bochs = {
245 .format_name = "bochs", 246 .format_name = "bochs",
246 .instance_size = sizeof(BDRVBochsState), 247 .instance_size = sizeof(BDRVBochsState),
247 .bdrv_probe = bochs_probe, 248 .bdrv_probe = bochs_probe,
@@ -249,3 +250,10 @@ BlockDriver bdrv_bochs = { @@ -249,3 +250,10 @@ BlockDriver bdrv_bochs = {
249 .bdrv_read = bochs_read, 250 .bdrv_read = bochs_read,
250 .bdrv_close = bochs_close, 251 .bdrv_close = bochs_close,
251 }; 252 };
  253 +
  254 +static void bdrv_bochs_init(void)
  255 +{
  256 + bdrv_register(&bdrv_bochs);
  257 +}
  258 +
  259 +block_init(bdrv_bochs_init);
block-cloop.c
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 */ 23 */
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "block_int.h" 25 #include "block_int.h"
  26 +#include "module.h"
26 #include <zlib.h> 27 #include <zlib.h>
27 28
28 typedef struct BDRVCloopState { 29 typedef struct BDRVCloopState {
@@ -153,7 +154,7 @@ static void cloop_close(BlockDriverState *bs) @@ -153,7 +154,7 @@ static void cloop_close(BlockDriverState *bs)
153 inflateEnd(&s->zstream); 154 inflateEnd(&s->zstream);
154 } 155 }
155 156
156 -BlockDriver bdrv_cloop = { 157 +static BlockDriver bdrv_cloop = {
157 .format_name = "cloop", 158 .format_name = "cloop",
158 .instance_size = sizeof(BDRVCloopState), 159 .instance_size = sizeof(BDRVCloopState),
159 .bdrv_probe = cloop_probe, 160 .bdrv_probe = cloop_probe,
@@ -161,3 +162,10 @@ BlockDriver bdrv_cloop = { @@ -161,3 +162,10 @@ BlockDriver bdrv_cloop = {
161 .bdrv_read = cloop_read, 162 .bdrv_read = cloop_read,
162 .bdrv_close = cloop_close, 163 .bdrv_close = cloop_close,
163 }; 164 };
  165 +
  166 +static void bdrv_cloop_init(void)
  167 +{
  168 + bdrv_register(&bdrv_cloop);
  169 +}
  170 +
  171 +block_init(bdrv_cloop_init);
block-cow.c
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 #ifndef _WIN32 24 #ifndef _WIN32
25 #include "qemu-common.h" 25 #include "qemu-common.h"
26 #include "block_int.h" 26 #include "block_int.h"
  27 +#include "module.h"
27 #include <sys/mman.h> 28 #include <sys/mman.h>
28 29
29 /**************************************************************/ 30 /**************************************************************/
@@ -252,7 +253,7 @@ static void cow_flush(BlockDriverState *bs) @@ -252,7 +253,7 @@ static void cow_flush(BlockDriverState *bs)
252 fsync(s->fd); 253 fsync(s->fd);
253 } 254 }
254 255
255 -BlockDriver bdrv_cow = { 256 +static BlockDriver bdrv_cow = {
256 .format_name = "cow", 257 .format_name = "cow",
257 .instance_size = sizeof(BDRVCowState), 258 .instance_size = sizeof(BDRVCowState),
258 .bdrv_probe = cow_probe, 259 .bdrv_probe = cow_probe,
@@ -264,4 +265,11 @@ BlockDriver bdrv_cow = { @@ -264,4 +265,11 @@ BlockDriver bdrv_cow = {
264 .bdrv_flush = cow_flush, 265 .bdrv_flush = cow_flush,
265 .bdrv_is_allocated = cow_is_allocated, 266 .bdrv_is_allocated = cow_is_allocated,
266 }; 267 };
  268 +
  269 +static void bdrv_cow_init(void)
  270 +{
  271 + bdrv_register(&bdrv_cow);
  272 +}
  273 +
  274 +block_init(bdrv_cow_init);
267 #endif 275 #endif
block-dmg.c
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "block_int.h" 25 #include "block_int.h"
26 #include "bswap.h" 26 #include "bswap.h"
  27 +#include "module.h"
27 #include <zlib.h> 28 #include <zlib.h>
28 29
29 typedef struct BDRVDMGState { 30 typedef struct BDRVDMGState {
@@ -92,7 +93,7 @@ static int dmg_open(BlockDriverState *bs, const char *filename, int flags) @@ -92,7 +93,7 @@ static int dmg_open(BlockDriverState *bs, const char *filename, int flags)
92 dmg_close: 93 dmg_close:
93 close(s->fd); 94 close(s->fd);
94 /* open raw instead */ 95 /* open raw instead */
95 - bs->drv=&bdrv_raw; 96 + bs->drv=bdrv_find_format("raw");
96 return bs->drv->bdrv_open(bs, filename, flags); 97 return bs->drv->bdrv_open(bs, filename, flags);
97 } 98 }
98 info_begin=read_off(s->fd); 99 info_begin=read_off(s->fd);
@@ -283,7 +284,7 @@ static void dmg_close(BlockDriverState *bs) @@ -283,7 +284,7 @@ static void dmg_close(BlockDriverState *bs)
283 inflateEnd(&s->zstream); 284 inflateEnd(&s->zstream);
284 } 285 }
285 286
286 -BlockDriver bdrv_dmg = { 287 +static BlockDriver bdrv_dmg = {
287 .format_name = "dmg", 288 .format_name = "dmg",
288 .instance_size = sizeof(BDRVDMGState), 289 .instance_size = sizeof(BDRVDMGState),
289 .bdrv_probe = dmg_probe, 290 .bdrv_probe = dmg_probe,
@@ -291,3 +292,10 @@ BlockDriver bdrv_dmg = { @@ -291,3 +292,10 @@ BlockDriver bdrv_dmg = {
291 .bdrv_read = dmg_read, 292 .bdrv_read = dmg_read,
292 .bdrv_close = dmg_close, 293 .bdrv_close = dmg_close,
293 }; 294 };
  295 +
  296 +static void bdrv_dmg_init(void)
  297 +{
  298 + bdrv_register(&bdrv_dmg);
  299 +}
  300 +
  301 +block_init(bdrv_dmg_init);
block-nbd.c
@@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
28 28
29 #include "qemu-common.h" 29 #include "qemu-common.h"
30 #include "nbd.h" 30 #include "nbd.h"
  31 +#include "module.h"
31 32
32 #include <sys/types.h> 33 #include <sys/types.h>
33 #include <unistd.h> 34 #include <unistd.h>
@@ -176,7 +177,7 @@ static int64_t nbd_getlength(BlockDriverState *bs) @@ -176,7 +177,7 @@ static int64_t nbd_getlength(BlockDriverState *bs)
176 return s->size; 177 return s->size;
177 } 178 }
178 179
179 -BlockDriver bdrv_nbd = { 180 +static BlockDriver bdrv_nbd = {
180 .format_name = "nbd", 181 .format_name = "nbd",
181 .instance_size = sizeof(BDRVNBDState), 182 .instance_size = sizeof(BDRVNBDState),
182 .bdrv_open = nbd_open, 183 .bdrv_open = nbd_open,
@@ -186,3 +187,10 @@ BlockDriver bdrv_nbd = { @@ -186,3 +187,10 @@ BlockDriver bdrv_nbd = {
186 .bdrv_getlength = nbd_getlength, 187 .bdrv_getlength = nbd_getlength,
187 .protocol_name = "nbd", 188 .protocol_name = "nbd",
188 }; 189 };
  190 +
  191 +static void bdrv_nbd_init(void)
  192 +{
  193 + bdrv_register(&bdrv_nbd);
  194 +}
  195 +
  196 +block_init(bdrv_nbd_init);
block-parallels.c
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 */ 25 */
26 #include "qemu-common.h" 26 #include "qemu-common.h"
27 #include "block_int.h" 27 #include "block_int.h"
  28 +#include "module.h"
28 29
29 /**************************************************************/ 30 /**************************************************************/
30 31
@@ -163,7 +164,7 @@ static void parallels_close(BlockDriverState *bs) @@ -163,7 +164,7 @@ static void parallels_close(BlockDriverState *bs)
163 close(s->fd); 164 close(s->fd);
164 } 165 }
165 166
166 -BlockDriver bdrv_parallels = { 167 +static BlockDriver bdrv_parallels = {
167 .format_name = "parallels", 168 .format_name = "parallels",
168 .instance_size = sizeof(BDRVParallelsState), 169 .instance_size = sizeof(BDRVParallelsState),
169 .bdrv_probe = parallels_probe, 170 .bdrv_probe = parallels_probe,
@@ -171,3 +172,10 @@ BlockDriver bdrv_parallels = { @@ -171,3 +172,10 @@ BlockDriver bdrv_parallels = {
171 .bdrv_read = parallels_read, 172 .bdrv_read = parallels_read,
172 .bdrv_close = parallels_close, 173 .bdrv_close = parallels_close,
173 }; 174 };
  175 +
  176 +static void bdrv_parallels_init(void)
  177 +{
  178 + bdrv_register(&bdrv_parallels);
  179 +}
  180 +
  181 +block_init(bdrv_parallels_init);
block-qcow.c
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 */ 23 */
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "block_int.h" 25 #include "block_int.h"
  26 +#include "module.h"
26 #include <zlib.h> 27 #include <zlib.h>
27 #include "aes.h" 28 #include "aes.h"
28 29
@@ -917,7 +918,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) @@ -917,7 +918,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
917 return 0; 918 return 0;
918 } 919 }
919 920
920 -BlockDriver bdrv_qcow = { 921 +static BlockDriver bdrv_qcow = {
921 .format_name = "qcow", 922 .format_name = "qcow",
922 .instance_size = sizeof(BDRVQcowState), 923 .instance_size = sizeof(BDRVQcowState),
923 .bdrv_probe = qcow_probe, 924 .bdrv_probe = qcow_probe,
@@ -935,3 +936,10 @@ BlockDriver bdrv_qcow = { @@ -935,3 +936,10 @@ BlockDriver bdrv_qcow = {
935 .bdrv_write_compressed = qcow_write_compressed, 936 .bdrv_write_compressed = qcow_write_compressed,
936 .bdrv_get_info = qcow_get_info, 937 .bdrv_get_info = qcow_get_info,
937 }; 938 };
  939 +
  940 +static void bdrv_qcow_init(void)
  941 +{
  942 + bdrv_register(&bdrv_qcow);
  943 +}
  944 +
  945 +block_init(bdrv_qcow_init);
block-qcow2.c
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 */ 23 */
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "block_int.h" 25 #include "block_int.h"
  26 +#include "module.h"
26 #include <zlib.h> 27 #include <zlib.h>
27 #include "aes.h" 28 #include "aes.h"
28 29
@@ -2891,7 +2892,7 @@ static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf, @@ -2891,7 +2892,7 @@ static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf,
2891 return ret; 2892 return ret;
2892 } 2893 }
2893 2894
2894 -BlockDriver bdrv_qcow2 = { 2895 +static BlockDriver bdrv_qcow2 = {
2895 .format_name = "qcow2", 2896 .format_name = "qcow2",
2896 .instance_size = sizeof(BDRVQcowState), 2897 .instance_size = sizeof(BDRVQcowState),
2897 .bdrv_probe = qcow_probe, 2898 .bdrv_probe = qcow_probe,
@@ -2921,3 +2922,10 @@ BlockDriver bdrv_qcow2 = { @@ -2921,3 +2922,10 @@ BlockDriver bdrv_qcow2 = {
2921 .bdrv_create2 = qcow_create2, 2922 .bdrv_create2 = qcow_create2,
2922 .bdrv_check = qcow_check, 2923 .bdrv_check = qcow_check,
2923 }; 2924 };
  2925 +
  2926 +static void bdrv_qcow2_init(void)
  2927 +{
  2928 + bdrv_register(&bdrv_qcow2);
  2929 +}
  2930 +
  2931 +block_init(bdrv_qcow2_init);
block-raw-posix.c
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 #include "qemu-timer.h" 25 #include "qemu-timer.h"
26 #include "qemu-char.h" 26 #include "qemu-char.h"
27 #include "block_int.h" 27 #include "block_int.h"
  28 +#include "module.h"
28 #ifdef CONFIG_AIO 29 #ifdef CONFIG_AIO
29 #include "posix-aio-compat.h" 30 #include "posix-aio-compat.h"
30 #endif 31 #endif
@@ -845,7 +846,7 @@ static void raw_flush(BlockDriverState *bs) @@ -845,7 +846,7 @@ static void raw_flush(BlockDriverState *bs)
845 fsync(s->fd); 846 fsync(s->fd);
846 } 847 }
847 848
848 -BlockDriver bdrv_raw = { 849 +static BlockDriver bdrv_raw = {
849 .format_name = "raw", 850 .format_name = "raw",
850 .instance_size = sizeof(BDRVRawState), 851 .instance_size = sizeof(BDRVRawState),
851 .bdrv_probe = NULL, /* no probe for protocols */ 852 .bdrv_probe = NULL, /* no probe for protocols */
@@ -1397,7 +1398,7 @@ static int hdev_create(const char *filename, int64_t total_size, @@ -1397,7 +1398,7 @@ static int hdev_create(const char *filename, int64_t total_size,
1397 } 1398 }
1398 #endif 1399 #endif
1399 1400
1400 -BlockDriver bdrv_host_device = { 1401 +static BlockDriver bdrv_host_device = {
1401 .format_name = "host_device", 1402 .format_name = "host_device",
1402 .instance_size = sizeof(BDRVRawState), 1403 .instance_size = sizeof(BDRVRawState),
1403 .bdrv_open = hdev_open, 1404 .bdrv_open = hdev_open,
@@ -1427,3 +1428,11 @@ BlockDriver bdrv_host_device = { @@ -1427,3 +1428,11 @@ BlockDriver bdrv_host_device = {
1427 .bdrv_aio_ioctl = raw_aio_ioctl, 1428 .bdrv_aio_ioctl = raw_aio_ioctl,
1428 #endif 1429 #endif
1429 }; 1430 };
  1431 +
  1432 +static void bdrv_raw_init(void)
  1433 +{
  1434 + bdrv_register(&bdrv_raw);
  1435 + bdrv_register(&bdrv_host_device);
  1436 +}
  1437 +
  1438 +block_init(bdrv_raw_init);
block-raw-win32.c
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 #include "qemu-common.h" 24 #include "qemu-common.h"
25 #include "qemu-timer.h" 25 #include "qemu-timer.h"
26 #include "block_int.h" 26 #include "block_int.h"
  27 +#include "module.h"
27 #include <windows.h> 28 #include <windows.h>
28 #include <winioctl.h> 29 #include <winioctl.h>
29 30
@@ -227,7 +228,7 @@ static int raw_create(const char *filename, int64_t total_size, @@ -227,7 +228,7 @@ static int raw_create(const char *filename, int64_t total_size,
227 return 0; 228 return 0;
228 } 229 }
229 230
230 -BlockDriver bdrv_raw = { 231 +static BlockDriver bdrv_raw = {
231 .format_name = "raw", 232 .format_name = "raw",
232 .instance_size = sizeof(BDRVRawState), 233 .instance_size = sizeof(BDRVRawState),
233 .bdrv_open = raw_open, 234 .bdrv_open = raw_open,
@@ -371,7 +372,7 @@ static int raw_set_locked(BlockDriverState *bs, int locked) @@ -371,7 +372,7 @@ static int raw_set_locked(BlockDriverState *bs, int locked)
371 } 372 }
372 #endif 373 #endif
373 374
374 -BlockDriver bdrv_host_device = { 375 +static BlockDriver bdrv_host_device = {
375 .format_name = "host_device", 376 .format_name = "host_device",
376 .instance_size = sizeof(BDRVRawState), 377 .instance_size = sizeof(BDRVRawState),
377 .bdrv_open = hdev_open, 378 .bdrv_open = hdev_open,
@@ -382,3 +383,11 @@ BlockDriver bdrv_host_device = { @@ -382,3 +383,11 @@ BlockDriver bdrv_host_device = {
382 .bdrv_write = raw_write, 383 .bdrv_write = raw_write,
383 .bdrv_getlength = raw_getlength, 384 .bdrv_getlength = raw_getlength,
384 }; 385 };
  386 +
  387 +static void bdrv_raw_init(void)
  388 +{
  389 + bdrv_register(&bdrv_raw);
  390 + bdrv_register(&bdrv_host_device);
  391 +}
  392 +
  393 +block_init(bdrv_raw_init);
block-vmdk.c
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 25
26 #include "qemu-common.h" 26 #include "qemu-common.h"
27 #include "block_int.h" 27 #include "block_int.h"
  28 +#include "module.h"
28 29
29 #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D') 30 #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
30 #define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V') 31 #define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
@@ -811,7 +812,7 @@ static void vmdk_flush(BlockDriverState *bs) @@ -811,7 +812,7 @@ static void vmdk_flush(BlockDriverState *bs)
811 bdrv_flush(s->hd); 812 bdrv_flush(s->hd);
812 } 813 }
813 814
814 -BlockDriver bdrv_vmdk = { 815 +static BlockDriver bdrv_vmdk = {
815 .format_name = "vmdk", 816 .format_name = "vmdk",
816 .instance_size = sizeof(BDRVVmdkState), 817 .instance_size = sizeof(BDRVVmdkState),
817 .bdrv_probe = vmdk_probe, 818 .bdrv_probe = vmdk_probe,
@@ -823,3 +824,10 @@ BlockDriver bdrv_vmdk = { @@ -823,3 +824,10 @@ BlockDriver bdrv_vmdk = {
823 .bdrv_flush = vmdk_flush, 824 .bdrv_flush = vmdk_flush,
824 .bdrv_is_allocated = vmdk_is_allocated, 825 .bdrv_is_allocated = vmdk_is_allocated,
825 }; 826 };
  827 +
  828 +static void bdrv_vmdk_init(void)
  829 +{
  830 + bdrv_register(&bdrv_vmdk);
  831 +}
  832 +
  833 +block_init(bdrv_vmdk_init);
block-vpc.c
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 */ 24 */
25 #include "qemu-common.h" 25 #include "qemu-common.h"
26 #include "block_int.h" 26 #include "block_int.h"
  27 +#include "module.h"
27 28
28 /**************************************************************/ 29 /**************************************************************/
29 30
@@ -586,7 +587,7 @@ static void vpc_close(BlockDriverState *bs) @@ -586,7 +587,7 @@ static void vpc_close(BlockDriverState *bs)
586 bdrv_delete(s->hd); 587 bdrv_delete(s->hd);
587 } 588 }
588 589
589 -BlockDriver bdrv_vpc = { 590 +static BlockDriver bdrv_vpc = {
590 .format_name = "vpc", 591 .format_name = "vpc",
591 .instance_size = sizeof(BDRVVPCState), 592 .instance_size = sizeof(BDRVVPCState),
592 .bdrv_probe = vpc_probe, 593 .bdrv_probe = vpc_probe,
@@ -596,3 +597,10 @@ BlockDriver bdrv_vpc = { @@ -596,3 +597,10 @@ BlockDriver bdrv_vpc = {
596 .bdrv_close = vpc_close, 597 .bdrv_close = vpc_close,
597 .bdrv_create = vpc_create, 598 .bdrv_create = vpc_create,
598 }; 599 };
  600 +
  601 +static void bdrv_vpc_init(void)
  602 +{
  603 + bdrv_register(&bdrv_vpc);
  604 +}
  605 +
  606 +block_init(bdrv_vpc_init);
block-vvfat.c
@@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
26 #include <dirent.h> 26 #include <dirent.h>
27 #include "qemu-common.h" 27 #include "qemu-common.h"
28 #include "block_int.h" 28 #include "block_int.h"
  29 +#include "module.h"
29 30
30 #ifndef S_IWGRP 31 #ifndef S_IWGRP
31 #define S_IWGRP 0 32 #define S_IWGRP 0
@@ -2776,7 +2777,7 @@ static int enable_write_target(BDRVVVFATState *s) @@ -2776,7 +2777,7 @@ static int enable_write_target(BDRVVVFATState *s)
2776 2777
2777 s->qcow_filename = qemu_malloc(1024); 2778 s->qcow_filename = qemu_malloc(1024);
2778 get_tmp_filename(s->qcow_filename, 1024); 2779 get_tmp_filename(s->qcow_filename, 1024);
2779 - if (bdrv_create(&bdrv_qcow, 2780 + if (bdrv_create(bdrv_find_format("qcow"),
2780 s->qcow_filename, s->sector_count, "fat:", 0) < 0) 2781 s->qcow_filename, s->sector_count, "fat:", 0) < 0)
2781 return -1; 2782 return -1;
2782 s->qcow = bdrv_new(""); 2783 s->qcow = bdrv_new("");
@@ -2806,7 +2807,7 @@ static void vvfat_close(BlockDriverState *bs) @@ -2806,7 +2807,7 @@ static void vvfat_close(BlockDriverState *bs)
2806 free(s->cluster_buffer); 2807 free(s->cluster_buffer);
2807 } 2808 }
2808 2809
2809 -BlockDriver bdrv_vvfat = { 2810 +static BlockDriver bdrv_vvfat = {
2810 .format_name = "vvfat", 2811 .format_name = "vvfat",
2811 .instance_size = sizeof(BDRVVVFATState), 2812 .instance_size = sizeof(BDRVVVFATState),
2812 .bdrv_open = vvfat_open, 2813 .bdrv_open = vvfat_open,
@@ -2817,6 +2818,13 @@ BlockDriver bdrv_vvfat = { @@ -2817,6 +2818,13 @@ BlockDriver bdrv_vvfat = {
2817 .protocol_name = "fat", 2818 .protocol_name = "fat",
2818 }; 2819 };
2819 2820
  2821 +static void bdrv_vvfat_init(void)
  2822 +{
  2823 + bdrv_register(&bdrv_vvfat);
  2824 +}
  2825 +
  2826 +block_init(bdrv_vvfat_init);
  2827 +
2820 #ifdef DEBUG 2828 #ifdef DEBUG
2821 static void checkpoint(void) { 2829 static void checkpoint(void) {
2822 assert(((mapping_t*)array_get(&(vvv->mapping), 0))->end == 2); 2830 assert(((mapping_t*)array_get(&(vvv->mapping), 0))->end == 2);
@@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
30 #include "qemu-common.h" 30 #include "qemu-common.h"
31 #include "monitor.h" 31 #include "monitor.h"
32 #include "block_int.h" 32 #include "block_int.h"
  33 +#include "module.h"
33 34
34 #ifdef HOST_BSD 35 #ifdef HOST_BSD
35 #include <sys/types.h> 36 #include <sys/types.h>
@@ -138,7 +139,7 @@ void path_combine(char *dest, int dest_size, @@ -138,7 +139,7 @@ void path_combine(char *dest, int dest_size,
138 } 139 }
139 140
140 141
141 -static void bdrv_register(BlockDriver *bdrv) 142 +void bdrv_register(BlockDriver *bdrv)
142 { 143 {
143 if (!bdrv->bdrv_aio_readv) { 144 if (!bdrv->bdrv_aio_readv) {
144 /* add AIO emulation layer */ 145 /* add AIO emulation layer */
@@ -259,11 +260,11 @@ static BlockDriver *find_protocol(const char *filename) @@ -259,11 +260,11 @@ static BlockDriver *find_protocol(const char *filename)
259 #ifdef _WIN32 260 #ifdef _WIN32
260 if (is_windows_drive(filename) || 261 if (is_windows_drive(filename) ||
261 is_windows_drive_prefix(filename)) 262 is_windows_drive_prefix(filename))
262 - return &bdrv_raw; 263 + return bdrv_find_format("raw");
263 #endif 264 #endif
264 p = strchr(filename, ':'); 265 p = strchr(filename, ':');
265 if (!p) 266 if (!p)
266 - return &bdrv_raw; 267 + return bdrv_find_format("raw");
267 len = p - filename; 268 len = p - filename;
268 if (len > sizeof(protocol) - 1) 269 if (len > sizeof(protocol) - 1)
269 len = sizeof(protocol) - 1; 270 len = sizeof(protocol) - 1;
@@ -289,23 +290,23 @@ static BlockDriver *find_image_format(const char *filename) @@ -289,23 +290,23 @@ static BlockDriver *find_image_format(const char *filename)
289 /* detect host devices. By convention, /dev/cdrom[N] is always 290 /* detect host devices. By convention, /dev/cdrom[N] is always
290 recognized as a host CDROM */ 291 recognized as a host CDROM */
291 if (strstart(filename, "/dev/cdrom", NULL)) 292 if (strstart(filename, "/dev/cdrom", NULL))
292 - return &bdrv_host_device; 293 + return bdrv_find_format("host_device");
293 #ifdef _WIN32 294 #ifdef _WIN32
294 if (is_windows_drive(filename)) 295 if (is_windows_drive(filename))
295 - return &bdrv_host_device; 296 + return bdrv_find_format("host_device");
296 #else 297 #else
297 { 298 {
298 struct stat st; 299 struct stat st;
299 if (stat(filename, &st) >= 0 && 300 if (stat(filename, &st) >= 0 &&
300 (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) { 301 (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
301 - return &bdrv_host_device; 302 + return bdrv_find_format("host_device");
302 } 303 }
303 } 304 }
304 #endif 305 #endif
305 306
306 drv = find_protocol(filename); 307 drv = find_protocol(filename);
307 /* no need to test disk image formats for vvfat */ 308 /* no need to test disk image formats for vvfat */
308 - if (drv == &bdrv_vvfat) 309 + if (strcmp(drv->format_name, "vvfat") == 0)
309 return drv; 310 return drv;
310 311
311 ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY); 312 ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
@@ -396,14 +397,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, @@ -396,14 +397,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
396 else 397 else
397 realpath(filename, backing_filename); 398 realpath(filename, backing_filename);
398 399
399 - ret = bdrv_create2(&bdrv_qcow2, tmp_filename, 400 + ret = bdrv_create2(bdrv_find_format("qcow2"), tmp_filename,
400 total_size, backing_filename, 401 total_size, backing_filename,
401 (drv ? drv->format_name : NULL), 0); 402 (drv ? drv->format_name : NULL), 0);
402 if (ret < 0) { 403 if (ret < 0) {
403 return ret; 404 return ret;
404 } 405 }
405 filename = tmp_filename; 406 filename = tmp_filename;
406 - drv = &bdrv_qcow2; 407 + drv = bdrv_find_format("qcow2");
407 bs->is_temporary = 1; 408 bs->is_temporary = 1;
408 } 409 }
409 410
@@ -1494,21 +1495,7 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num, @@ -1494,21 +1495,7 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
1494 1495
1495 void bdrv_init(void) 1496 void bdrv_init(void)
1496 { 1497 {
1497 - bdrv_register(&bdrv_raw);  
1498 - bdrv_register(&bdrv_host_device);  
1499 -#ifndef _WIN32  
1500 - bdrv_register(&bdrv_cow);  
1501 -#endif  
1502 - bdrv_register(&bdrv_qcow);  
1503 - bdrv_register(&bdrv_vmdk);  
1504 - bdrv_register(&bdrv_cloop);  
1505 - bdrv_register(&bdrv_dmg);  
1506 - bdrv_register(&bdrv_bochs);  
1507 - bdrv_register(&bdrv_vpc);  
1508 - bdrv_register(&bdrv_vvfat);  
1509 - bdrv_register(&bdrv_qcow2);  
1510 - bdrv_register(&bdrv_parallels);  
1511 - bdrv_register(&bdrv_nbd); 1498 + module_call_init(MODULE_INIT_BLOCK);
1512 } 1499 }
1513 1500
1514 void aio_pool_init(AIOPool *pool, int aiocb_size, 1501 void aio_pool_init(AIOPool *pool, int aiocb_size,
@@ -7,20 +7,6 @@ @@ -7,20 +7,6 @@
7 /* block.c */ 7 /* block.c */
8 typedef struct BlockDriver BlockDriver; 8 typedef struct BlockDriver BlockDriver;
9 9
10 -extern BlockDriver bdrv_raw;  
11 -extern BlockDriver bdrv_host_device;  
12 -extern BlockDriver bdrv_cow;  
13 -extern BlockDriver bdrv_qcow;  
14 -extern BlockDriver bdrv_vmdk;  
15 -extern BlockDriver bdrv_cloop;  
16 -extern BlockDriver bdrv_dmg;  
17 -extern BlockDriver bdrv_bochs;  
18 -extern BlockDriver bdrv_vpc;  
19 -extern BlockDriver bdrv_vvfat;  
20 -extern BlockDriver bdrv_qcow2;  
21 -extern BlockDriver bdrv_parallels;  
22 -extern BlockDriver bdrv_nbd;  
23 -  
24 typedef struct BlockDriverInfo { 10 typedef struct BlockDriverInfo {
25 /* in bytes, 0 if irrelevant */ 11 /* in bytes, 0 if irrelevant */
26 int cluster_size; 12 int cluster_size;
@@ -87,6 +73,8 @@ int64_t bdrv_getlength(BlockDriverState *bs); @@ -87,6 +73,8 @@ int64_t bdrv_getlength(BlockDriverState *bs);
87 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); 73 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
88 void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs); 74 void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
89 int bdrv_commit(BlockDriverState *bs); 75 int bdrv_commit(BlockDriverState *bs);
  76 +void bdrv_register(BlockDriver *bdrv);
  77 +
90 /* async block I/O */ 78 /* async block I/O */
91 typedef struct BlockDriverAIOCB BlockDriverAIOCB; 79 typedef struct BlockDriverAIOCB BlockDriverAIOCB;
92 typedef void BlockDriverCompletionFunc(void *opaque, int ret); 80 typedef void BlockDriverCompletionFunc(void *opaque, int ret);
qemu-img.c
@@ -542,11 +542,11 @@ static int img_convert(int argc, char **argv) @@ -542,11 +542,11 @@ static int img_convert(int argc, char **argv)
542 drv = bdrv_find_format(out_fmt); 542 drv = bdrv_find_format(out_fmt);
543 if (!drv) 543 if (!drv)
544 error("Unknown file format '%s'", out_fmt); 544 error("Unknown file format '%s'", out_fmt);
545 - if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2) 545 + if (flags & BLOCK_FLAG_COMPRESS && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2"))
546 error("Compression not supported for this file format"); 546 error("Compression not supported for this file format");
547 - if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2) 547 + if (flags & BLOCK_FLAG_ENCRYPT && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2"))
548 error("Encryption not supported for this file format"); 548 error("Encryption not supported for this file format");
549 - if (flags & BLOCK_FLAG_COMPAT6 && drv != &bdrv_vmdk) 549 + if (flags & BLOCK_FLAG_COMPAT6 && strcmp(drv->format_name, "vmdk"))
550 error("Alternative compatibility level not supported for this file format"); 550 error("Alternative compatibility level not supported for this file format");
551 if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) 551 if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS)
552 error("Compression and encryption not supported at the same time"); 552 error("Compression and encryption not supported at the same time");
@@ -655,7 +655,7 @@ static int img_convert(int argc, char **argv) @@ -655,7 +655,7 @@ static int img_convert(int argc, char **argv)
655 if (n > bs_offset + bs_sectors - sector_num) 655 if (n > bs_offset + bs_sectors - sector_num)
656 n = bs_offset + bs_sectors - sector_num; 656 n = bs_offset + bs_sectors - sector_num;
657 657
658 - if (drv != &bdrv_host_device) { 658 + if (strcmp(drv->format_name, "host_device")) {
659 if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, 659 if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
660 n, &n1)) { 660 n, &n1)) {
661 sector_num += n1; 661 sector_num += n1;
@@ -682,7 +682,7 @@ static int img_convert(int argc, char **argv) @@ -682,7 +682,7 @@ static int img_convert(int argc, char **argv)
682 If the output is to a host device, we also write out 682 If the output is to a host device, we also write out
683 sectors that are entirely 0, since whatever data was 683 sectors that are entirely 0, since whatever data was
684 already there is garbage, not 0s. */ 684 already there is garbage, not 0s. */
685 - if (drv == &bdrv_host_device || out_baseimg || 685 + if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg ||
686 is_allocated_sectors(buf1, n, &n1)) { 686 is_allocated_sectors(buf1, n, &n1)) {
687 if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) 687 if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
688 error("error while writing"); 688 error("error while writing");