Commit 751c6a17042b5d011013d6963c0505d671cf708e

Authored by Gerd Hoffmann
Committed by Anthony Liguori
1 parent 8a14daa5

kill drives_table

First step cleaning up the drives handling.  This one does nothing but
removing drives_table[], still it became seriously big.

drive_get_index() is gone and is replaced by drives_get() which hands
out DriveInfo pointers instead of a table index.  This needs adaption in
*tons* of places all over.

The drives are now maintained as linked list.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/device-hotplug.c
@@ -28,22 +28,23 @@ @@ -28,22 +28,23 @@
28 #include "block_int.h" 28 #include "block_int.h"
29 #include "sysemu.h" 29 #include "sysemu.h"
30 30
31 -int add_init_drive(const char *opts) 31 +DriveInfo *add_init_drive(const char *opts)
32 { 32 {
33 - int drive_opt_idx, drive_idx;  
34 - int ret = -1; 33 + int drive_opt_idx;
  34 + int fatal_error;
  35 + DriveInfo *dinfo;
35 36
36 drive_opt_idx = drive_add(NULL, "%s", opts); 37 drive_opt_idx = drive_add(NULL, "%s", opts);
37 if (!drive_opt_idx) 38 if (!drive_opt_idx)
38 - return ret; 39 + return NULL;
39 40
40 - drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine);  
41 - if (drive_idx == -1) { 41 + dinfo = drive_init(&drives_opt[drive_opt_idx], 0, current_machine, &fatal_error);
  42 + if (!dinfo) {
42 drive_remove(drive_opt_idx); 43 drive_remove(drive_opt_idx);
43 - return ret; 44 + return NULL;
44 } 45 }
45 46
46 - return drive_idx; 47 + return dinfo;
47 } 48 }
48 49
49 void destroy_nic(dev_match_fn *match_fn, void *arg) 50 void destroy_nic(dev_match_fn *match_fn, void *arg)
@@ -64,11 +65,11 @@ void destroy_nic(dev_match_fn *match_fn, void *arg) @@ -64,11 +65,11 @@ void destroy_nic(dev_match_fn *match_fn, void *arg)
64 65
65 void destroy_bdrvs(dev_match_fn *match_fn, void *arg) 66 void destroy_bdrvs(dev_match_fn *match_fn, void *arg)
66 { 67 {
67 - int i; 68 + DriveInfo *dinfo;
68 struct BlockDriverState *bs; 69 struct BlockDriverState *bs;
69 70
70 - for (i = 0; i <= MAX_DRIVES; i++) {  
71 - bs = drives_table[i].bdrv; 71 + TAILQ_FOREACH(dinfo, &drives, next) {
  72 + bs = dinfo->bdrv;
72 if (bs) { 73 if (bs) {
73 if (bs->private && match_fn(bs->private, arg)) { 74 if (bs->private && match_fn(bs->private, arg)) {
74 drive_uninit(bs); 75 drive_uninit(bs);
hw/etraxfs.c
@@ -55,6 +55,7 @@ void bareetraxfs_init (ram_addr_t ram_size, @@ -55,6 +55,7 @@ void bareetraxfs_init (ram_addr_t ram_size,
55 void *etraxfs_dmac; 55 void *etraxfs_dmac;
56 struct etraxfs_dma_client *eth[2] = {NULL, NULL}; 56 struct etraxfs_dma_client *eth[2] = {NULL, NULL};
57 int kernel_size; 57 int kernel_size;
  58 + DriveInfo *dinfo;
58 int i; 59 int i;
59 ram_addr_t phys_ram; 60 ram_addr_t phys_ram;
60 ram_addr_t phys_flash; 61 ram_addr_t phys_flash;
@@ -79,9 +80,9 @@ void bareetraxfs_init (ram_addr_t ram_size, @@ -79,9 +80,9 @@ void bareetraxfs_init (ram_addr_t ram_size,
79 80
80 81
81 phys_flash = qemu_ram_alloc(FLASH_SIZE); 82 phys_flash = qemu_ram_alloc(FLASH_SIZE);
82 - i = drive_get_index(IF_PFLASH, 0, 0); 83 + dinfo = drive_get(IF_PFLASH, 0, 0);
83 pflash_cfi02_register(0x0, phys_flash, 84 pflash_cfi02_register(0x0, phys_flash,
84 - i != -1 ? drives_table[i].bdrv : NULL, (64 * 1024), 85 + dinfo ? dinfo->bdrv : NULL, (64 * 1024),
85 FLASH_SIZE >> 16, 86 FLASH_SIZE >> 16,
86 1, 2, 0x0000, 0x0000, 0x0000, 0x0000, 87 1, 2, 0x0000, 0x0000, 0x0000, 0x0000,
87 0x555, 0x2aa); 88 0x555, 0x2aa);
hw/gumstix.c
@@ -47,22 +47,22 @@ static void connex_init(ram_addr_t ram_size, @@ -47,22 +47,22 @@ static void connex_init(ram_addr_t ram_size,
47 const char *initrd_filename, const char *cpu_model) 47 const char *initrd_filename, const char *cpu_model)
48 { 48 {
49 PXA2xxState *cpu; 49 PXA2xxState *cpu;
50 - int index; 50 + DriveInfo *dinfo;
51 51
52 uint32_t connex_rom = 0x01000000; 52 uint32_t connex_rom = 0x01000000;
53 uint32_t connex_ram = 0x04000000; 53 uint32_t connex_ram = 0x04000000;
54 54
55 cpu = pxa255_init(connex_ram); 55 cpu = pxa255_init(connex_ram);
56 56
57 - index = drive_get_index(IF_PFLASH, 0, 0);  
58 - if (index == -1) { 57 + dinfo = drive_get(IF_PFLASH, 0, 0);
  58 + if (!dinfo) {
59 fprintf(stderr, "A flash image must be given with the " 59 fprintf(stderr, "A flash image must be given with the "
60 "'pflash' parameter\n"); 60 "'pflash' parameter\n");
61 exit(1); 61 exit(1);
62 } 62 }
63 63
64 if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(connex_rom), 64 if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(connex_rom),
65 - drives_table[index].bdrv, sector_len, connex_rom / sector_len, 65 + dinfo->bdrv, sector_len, connex_rom / sector_len,
66 2, 0, 0, 0, 0)) { 66 2, 0, 0, 0, 0)) {
67 fprintf(stderr, "qemu: Error registering flash memory.\n"); 67 fprintf(stderr, "qemu: Error registering flash memory.\n");
68 exit(1); 68 exit(1);
@@ -81,22 +81,22 @@ static void verdex_init(ram_addr_t ram_size, @@ -81,22 +81,22 @@ static void verdex_init(ram_addr_t ram_size,
81 const char *initrd_filename, const char *cpu_model) 81 const char *initrd_filename, const char *cpu_model)
82 { 82 {
83 PXA2xxState *cpu; 83 PXA2xxState *cpu;
84 - int index; 84 + DriveInfo *dinfo;
85 85
86 uint32_t verdex_rom = 0x02000000; 86 uint32_t verdex_rom = 0x02000000;
87 uint32_t verdex_ram = 0x10000000; 87 uint32_t verdex_ram = 0x10000000;
88 88
89 cpu = pxa270_init(verdex_ram, cpu_model ?: "pxa270-c0"); 89 cpu = pxa270_init(verdex_ram, cpu_model ?: "pxa270-c0");
90 90
91 - index = drive_get_index(IF_PFLASH, 0, 0);  
92 - if (index == -1) { 91 + dinfo = drive_get(IF_PFLASH, 0, 0);
  92 + if (!dinfo) {
93 fprintf(stderr, "A flash image must be given with the " 93 fprintf(stderr, "A flash image must be given with the "
94 "'pflash' parameter\n"); 94 "'pflash' parameter\n");
95 exit(1); 95 exit(1);
96 } 96 }
97 97
98 if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(verdex_rom), 98 if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(verdex_rom),
99 - drives_table[index].bdrv, sector_len, verdex_rom / sector_len, 99 + dinfo->bdrv, sector_len, verdex_rom / sector_len,
100 2, 0, 0, 0, 0)) { 100 2, 0, 0, 0, 0)) {
101 fprintf(stderr, "qemu: Error registering flash memory.\n"); 101 fprintf(stderr, "qemu: Error registering flash memory.\n");
102 exit(1); 102 exit(1);
hw/mainstone.c
@@ -77,7 +77,8 @@ static void mainstone_common_init(ram_addr_t ram_size, @@ -77,7 +77,8 @@ static void mainstone_common_init(ram_addr_t ram_size,
77 target_phys_addr_t mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 }; 77 target_phys_addr_t mainstone_flash_base[] = { MST_FLASH_0, MST_FLASH_1 };
78 PXA2xxState *cpu; 78 PXA2xxState *cpu;
79 qemu_irq *mst_irq; 79 qemu_irq *mst_irq;
80 - int i, index; 80 + DriveInfo *dinfo;
  81 + int i;
81 82
82 if (!cpu_model) 83 if (!cpu_model)
83 cpu_model = "pxa270-c5"; 84 cpu_model = "pxa270-c5";
@@ -92,8 +93,8 @@ static void mainstone_common_init(ram_addr_t ram_size, @@ -92,8 +93,8 @@ static void mainstone_common_init(ram_addr_t ram_size,
92 93
93 /* There are two 32MiB flash devices on the board */ 94 /* There are two 32MiB flash devices on the board */
94 for (i = 0; i < 2; i ++) { 95 for (i = 0; i < 2; i ++) {
95 - index = drive_get_index(IF_PFLASH, 0, i);  
96 - if (index == -1) { 96 + dinfo = drive_get(IF_PFLASH, 0, i);
  97 + if (!dinfo) {
97 fprintf(stderr, "Two flash images must be given with the " 98 fprintf(stderr, "Two flash images must be given with the "
98 "'pflash' parameter\n"); 99 "'pflash' parameter\n");
99 exit(1); 100 exit(1);
@@ -101,7 +102,7 @@ static void mainstone_common_init(ram_addr_t ram_size, @@ -101,7 +102,7 @@ static void mainstone_common_init(ram_addr_t ram_size,
101 102
102 if (!pflash_cfi01_register(mainstone_flash_base[i], 103 if (!pflash_cfi01_register(mainstone_flash_base[i],
103 qemu_ram_alloc(MAINSTONE_FLASH), 104 qemu_ram_alloc(MAINSTONE_FLASH),
104 - drives_table[index].bdrv, sector_len, 105 + dinfo->bdrv, sector_len,
105 MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0)) { 106 MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0)) {
106 fprintf(stderr, "qemu: Error registering flash memory.\n"); 107 fprintf(stderr, "qemu: Error registering flash memory.\n");
107 exit(1); 108 exit(1);
hw/mips_jazz.c
@@ -235,11 +235,8 @@ void mips_jazz_init (ram_addr_t ram_size, @@ -235,11 +235,8 @@ void mips_jazz_init (ram_addr_t ram_size,
235 exit(1); 235 exit(1);
236 } 236 }
237 for (n = 0; n < MAX_FD; n++) { 237 for (n = 0; n < MAX_FD; n++) {
238 - int fd = drive_get_index(IF_FLOPPY, 0, n);  
239 - if (fd != -1)  
240 - fds[n] = drives_table[fd].bdrv;  
241 - else  
242 - fds[n] = NULL; 238 + DriveInfo *dinfo = drive_get(IF_FLOPPY, 0, n);
  239 + fds[n] = dinfo ? dinfo->bdrv : NULL;
243 } 240 }
244 fdctrl_init(rc4030[1], 0, 1, 0x80003000, fds); 241 fdctrl_init(rc4030[1], 0, 1, 0x80003000, fds);
245 242
hw/mips_malta.c
@@ -773,7 +773,7 @@ void mips_malta_init (ram_addr_t ram_size, @@ -773,7 +773,7 @@ void mips_malta_init (ram_addr_t ram_size,
773 uint8_t *eeprom_buf; 773 uint8_t *eeprom_buf;
774 i2c_bus *smbus; 774 i2c_bus *smbus;
775 int i; 775 int i;
776 - int index; 776 + DriveInfo *dinfo;
777 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 777 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
778 BlockDriverState *fd[MAX_FD]; 778 BlockDriverState *fd[MAX_FD];
779 int fl_idx = 0; 779 int fl_idx = 0;
@@ -827,8 +827,8 @@ void mips_malta_init (ram_addr_t ram_size, @@ -827,8 +827,8 @@ void mips_malta_init (ram_addr_t ram_size,
827 env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL)); 827 env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
828 write_bootloader(env, qemu_get_ram_ptr(bios_offset), kernel_entry); 828 write_bootloader(env, qemu_get_ram_ptr(bios_offset), kernel_entry);
829 } else { 829 } else {
830 - index = drive_get_index(IF_PFLASH, 0, fl_idx);  
831 - if (index != -1) { 830 + dinfo = drive_get(IF_PFLASH, 0, fl_idx);
  831 + if (dinfo) {
832 /* Load firmware from flash. */ 832 /* Load firmware from flash. */
833 bios_size = 0x400000; 833 bios_size = 0x400000;
834 fl_sectors = bios_size >> 16; 834 fl_sectors = bios_size >> 16;
@@ -836,10 +836,10 @@ void mips_malta_init (ram_addr_t ram_size, @@ -836,10 +836,10 @@ void mips_malta_init (ram_addr_t ram_size,
836 printf("Register parallel flash %d size " TARGET_FMT_lx " at " 836 printf("Register parallel flash %d size " TARGET_FMT_lx " at "
837 "offset %08lx addr %08llx '%s' %x\n", 837 "offset %08lx addr %08llx '%s' %x\n",
838 fl_idx, bios_size, bios_offset, 0x1e000000LL, 838 fl_idx, bios_size, bios_offset, 0x1e000000LL,
839 - bdrv_get_device_name(drives_table[index].bdrv), fl_sectors); 839 + bdrv_get_device_name(dinfo->bdrv), fl_sectors);
840 #endif 840 #endif
841 pflash_cfi01_register(0x1e000000LL, bios_offset, 841 pflash_cfi01_register(0x1e000000LL, bios_offset,
842 - drives_table[index].bdrv, 65536, fl_sectors, 842 + dinfo->bdrv, 65536, fl_sectors,
843 4, 0x0000, 0x0000, 0x0000, 0x0000); 843 4, 0x0000, 0x0000, 0x0000, 0x0000);
844 fl_idx++; 844 fl_idx++;
845 } else { 845 } else {
@@ -898,11 +898,8 @@ void mips_malta_init (ram_addr_t ram_size, @@ -898,11 +898,8 @@ void mips_malta_init (ram_addr_t ram_size,
898 } 898 }
899 899
900 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { 900 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
901 - index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);  
902 - if (index != -1)  
903 - hd[i] = drives_table[index].bdrv;  
904 - else  
905 - hd[i] = NULL; 901 + dinfo = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
  902 + hd[i] = dinfo ? dinfo->bdrv : NULL;
906 } 903 }
907 904
908 piix4_devfn = piix4_init(pci_bus, 80); 905 piix4_devfn = piix4_init(pci_bus, 80);
@@ -929,11 +926,8 @@ void mips_malta_init (ram_addr_t ram_size, @@ -929,11 +926,8 @@ void mips_malta_init (ram_addr_t ram_size,
929 if (parallel_hds[0]) 926 if (parallel_hds[0])
930 parallel_init(0x378, i8259[7], parallel_hds[0]); 927 parallel_init(0x378, i8259[7], parallel_hds[0]);
931 for(i = 0; i < MAX_FD; i++) { 928 for(i = 0; i < MAX_FD; i++) {
932 - index = drive_get_index(IF_FLOPPY, 0, i);  
933 - if (index != -1)  
934 - fd[i] = drives_table[index].bdrv;  
935 - else  
936 - fd[i] = NULL; 929 + dinfo = drive_get(IF_FLOPPY, 0, i);
  930 + fd[i] = dinfo ? dinfo->bdrv : NULL;
937 } 931 }
938 floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd); 932 floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
939 933
hw/mips_r4k.c
@@ -155,8 +155,8 @@ void mips_r4k_init (ram_addr_t ram_size, @@ -155,8 +155,8 @@ void mips_r4k_init (ram_addr_t ram_size,
155 RTCState *rtc_state; 155 RTCState *rtc_state;
156 int i; 156 int i;
157 qemu_irq *i8259; 157 qemu_irq *i8259;
158 - int index;  
159 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 158 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
  159 + DriveInfo *dinfo;
160 160
161 /* init CPUs */ 161 /* init CPUs */
162 if (cpu_model == NULL) { 162 if (cpu_model == NULL) {
@@ -208,11 +208,11 @@ void mips_r4k_init (ram_addr_t ram_size, @@ -208,11 +208,11 @@ void mips_r4k_init (ram_addr_t ram_size,
208 bios_offset | IO_MEM_ROM); 208 bios_offset | IO_MEM_ROM);
209 209
210 load_image_targphys(filename, 0x1fc00000, BIOS_SIZE); 210 load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
211 - } else if ((index = drive_get_index(IF_PFLASH, 0, 0)) > -1) { 211 + } else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
212 uint32_t mips_rom = 0x00400000; 212 uint32_t mips_rom = 0x00400000;
213 bios_offset = qemu_ram_alloc(mips_rom); 213 bios_offset = qemu_ram_alloc(mips_rom);
214 if (!pflash_cfi01_register(0x1fc00000, bios_offset, 214 if (!pflash_cfi01_register(0x1fc00000, bios_offset,
215 - drives_table[index].bdrv, sector_len, mips_rom / sector_len, 215 + dinfo->bdrv, sector_len, mips_rom / sector_len,
216 4, 0, 0, 0, 0)) { 216 4, 0, 0, 0, 0)) {
217 fprintf(stderr, "qemu: Error registering flash memory.\n"); 217 fprintf(stderr, "qemu: Error registering flash memory.\n");
218 } 218 }
@@ -267,11 +267,8 @@ void mips_r4k_init (ram_addr_t ram_size, @@ -267,11 +267,8 @@ void mips_r4k_init (ram_addr_t ram_size,
267 } 267 }
268 268
269 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { 269 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
270 - index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);  
271 - if (index != -1)  
272 - hd[i] = drives_table[index].bdrv;  
273 - else  
274 - hd[i] = NULL; 270 + dinfo = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
  271 + hd[i] = dinfo ? dinfo->bdrv : NULL;
275 } 272 }
276 273
277 for(i = 0; i < MAX_IDE_BUS; i++) 274 for(i = 0; i < MAX_IDE_BUS; i++)
hw/musicpal.c
@@ -1512,8 +1512,8 @@ static void musicpal_init(ram_addr_t ram_size, @@ -1512,8 +1512,8 @@ static void musicpal_init(ram_addr_t ram_size,
1512 qemu_irq pic[32]; 1512 qemu_irq pic[32];
1513 DeviceState *dev; 1513 DeviceState *dev;
1514 int i; 1514 int i;
1515 - int index;  
1516 unsigned long flash_size; 1515 unsigned long flash_size;
  1516 + DriveInfo *dinfo;
1517 1517
1518 if (!cpu_model) 1518 if (!cpu_model)
1519 cpu_model = "arm926"; 1519 cpu_model = "arm926";
@@ -1549,9 +1549,9 @@ static void musicpal_init(ram_addr_t ram_size, @@ -1549,9 +1549,9 @@ static void musicpal_init(ram_addr_t ram_size,
1549 serial_hds[1], 1); 1549 serial_hds[1], 1);
1550 1550
1551 /* Register flash */ 1551 /* Register flash */
1552 - index = drive_get_index(IF_PFLASH, 0, 0);  
1553 - if (index != -1) {  
1554 - flash_size = bdrv_getlength(drives_table[index].bdrv); 1552 + dinfo = drive_get(IF_PFLASH, 0, 0);
  1553 + if (dinfo) {
  1554 + flash_size = bdrv_getlength(dinfo->bdrv);
1555 if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 && 1555 if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 &&
1556 flash_size != 32*1024*1024) { 1556 flash_size != 32*1024*1024) {
1557 fprintf(stderr, "Invalid flash image size\n"); 1557 fprintf(stderr, "Invalid flash image size\n");
@@ -1564,7 +1564,7 @@ static void musicpal_init(ram_addr_t ram_size, @@ -1564,7 +1564,7 @@ static void musicpal_init(ram_addr_t ram_size,
1564 * image is smaller than 32 MB. 1564 * image is smaller than 32 MB.
1565 */ 1565 */
1566 pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size), 1566 pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size),
1567 - drives_table[index].bdrv, 0x10000, 1567 + dinfo->bdrv, 0x10000,
1568 (flash_size + 0xffff) >> 16, 1568 (flash_size + 0xffff) >> 16,
1569 MP_FLASH_SIZE_MAX / flash_size, 1569 MP_FLASH_SIZE_MAX / flash_size,
1570 2, 0x00BF, 0x236D, 0x0000, 0x0000, 1570 2, 0x00BF, 0x236D, 0x0000, 0x0000,
hw/nand.c
@@ -442,16 +442,16 @@ NANDFlashState *nand_init(int manf_id, int chip_id) @@ -442,16 +442,16 @@ NANDFlashState *nand_init(int manf_id, int chip_id)
442 { 442 {
443 int pagesize; 443 int pagesize;
444 NANDFlashState *s; 444 NANDFlashState *s;
445 - int index; 445 + DriveInfo *dinfo;
446 446
447 if (nand_flash_ids[chip_id].size == 0) { 447 if (nand_flash_ids[chip_id].size == 0) {
448 hw_error("%s: Unsupported NAND chip ID.\n", __FUNCTION__); 448 hw_error("%s: Unsupported NAND chip ID.\n", __FUNCTION__);
449 } 449 }
450 450
451 s = (NANDFlashState *) qemu_mallocz(sizeof(NANDFlashState)); 451 s = (NANDFlashState *) qemu_mallocz(sizeof(NANDFlashState));
452 - index = drive_get_index(IF_MTD, 0, 0);  
453 - if (index != -1)  
454 - s->bdrv = drives_table[index].bdrv; 452 + dinfo = drive_get(IF_MTD, 0, 0);
  453 + if (dinfo)
  454 + s->bdrv = dinfo->bdrv;
455 s->manf_id = manf_id; 455 s->manf_id = manf_id;
456 s->chip_id = chip_id; 456 s->chip_id = chip_id;
457 s->size = nand_flash_ids[s->chip_id].size << 20; 457 s->size = nand_flash_ids[s->chip_id].size << 20;
hw/omap1.c
@@ -4628,7 +4628,7 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size, @@ -4628,7 +4628,7 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
4628 ram_addr_t imif_base, emiff_base; 4628 ram_addr_t imif_base, emiff_base;
4629 qemu_irq *cpu_irq; 4629 qemu_irq *cpu_irq;
4630 qemu_irq dma_irqs[6]; 4630 qemu_irq dma_irqs[6];
4631 - int sdindex; 4631 + DriveInfo *dinfo;
4632 4632
4633 if (!core) 4633 if (!core)
4634 core = "ti925t"; 4634 core = "ti925t";
@@ -4740,12 +4740,12 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size, @@ -4740,12 +4740,12 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,
4740 omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2")); 4740 omap_dpll_init(&s->dpll[1], 0xfffed000, omap_findclk(s, "dpll2"));
4741 omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3")); 4741 omap_dpll_init(&s->dpll[2], 0xfffed100, omap_findclk(s, "dpll3"));
4742 4742
4743 - sdindex = drive_get_index(IF_SD, 0, 0);  
4744 - if (sdindex == -1) { 4743 + dinfo = drive_get(IF_SD, 0, 0);
  4744 + if (!dinfo) {
4745 fprintf(stderr, "qemu: missing SecureDigital device\n"); 4745 fprintf(stderr, "qemu: missing SecureDigital device\n");
4746 exit(1); 4746 exit(1);
4747 } 4747 }
4748 - s->mmc = omap_mmc_init(0xfffb7800, drives_table[sdindex].bdrv, 4748 + s->mmc = omap_mmc_init(0xfffb7800, dinfo->bdrv,
4749 s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX], 4749 s->irq[1][OMAP_INT_OQN], &s->drq[OMAP_DMA_MMC_TX],
4750 omap_findclk(s, "mmc_ck")); 4750 omap_findclk(s, "mmc_ck"));
4751 4751
hw/omap2.c
@@ -4496,7 +4496,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size, @@ -4496,7 +4496,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,
4496 qemu_irq *cpu_irq; 4496 qemu_irq *cpu_irq;
4497 qemu_irq dma_irqs[4]; 4497 qemu_irq dma_irqs[4];
4498 omap_clk gpio_clks[4]; 4498 omap_clk gpio_clks[4];
4499 - int sdindex; 4499 + DriveInfo *dinfo;
4500 int i; 4500 int i;
4501 4501
4502 /* Core */ 4502 /* Core */
@@ -4645,12 +4645,12 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size, @@ -4645,12 +4645,12 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,
4645 s->sdrc = omap_sdrc_init(0x68009000); 4645 s->sdrc = omap_sdrc_init(0x68009000);
4646 s->gpmc = omap_gpmc_init(0x6800a000, s->irq[0][OMAP_INT_24XX_GPMC_IRQ]); 4646 s->gpmc = omap_gpmc_init(0x6800a000, s->irq[0][OMAP_INT_24XX_GPMC_IRQ]);
4647 4647
4648 - sdindex = drive_get_index(IF_SD, 0, 0);  
4649 - if (sdindex == -1) { 4648 + dinfo = drive_get(IF_SD, 0, 0);
  4649 + if (!dinfo) {
4650 fprintf(stderr, "qemu: missing SecureDigital device\n"); 4650 fprintf(stderr, "qemu: missing SecureDigital device\n");
4651 exit(1); 4651 exit(1);
4652 } 4652 }
4653 - s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), drives_table[sdindex].bdrv, 4653 + s->mmc = omap2_mmc_init(omap_l4tao(s->l4, 9), dinfo->bdrv,
4654 s->irq[0][OMAP_INT_24XX_MMC_IRQ], 4654 s->irq[0][OMAP_INT_24XX_MMC_IRQ],
4655 &s->drq[OMAP24XX_DMA_MMC1_TX], 4655 &s->drq[OMAP24XX_DMA_MMC1_TX],
4656 omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk")); 4656 omap_findclk(s, "mmc_fclk"), omap_findclk(s, "mmc_iclk"));
hw/omap_sx1.c
@@ -127,7 +127,7 @@ static void sx1_init(ram_addr_t ram_size, @@ -127,7 +127,7 @@ static void sx1_init(ram_addr_t ram_size,
127 static uint32_t cs2val = 0x00001139; 127 static uint32_t cs2val = 0x00001139;
128 static uint32_t cs3val = 0x00001139; 128 static uint32_t cs3val = 0x00001139;
129 ram_addr_t phys_flash; 129 ram_addr_t phys_flash;
130 - int index; 130 + DriveInfo *dinfo;
131 int fl_idx; 131 int fl_idx;
132 uint32_t flash_size = flash0_size; 132 uint32_t flash_size = flash0_size;
133 133
@@ -151,9 +151,9 @@ static void sx1_init(ram_addr_t ram_size, @@ -151,9 +151,9 @@ static void sx1_init(ram_addr_t ram_size,
151 151
152 fl_idx = 0; 152 fl_idx = 0;
153 153
154 - if ((index = drive_get_index(IF_PFLASH, 0, fl_idx)) > -1) { 154 + if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
155 if (!pflash_cfi01_register(OMAP_CS0_BASE, qemu_ram_alloc(flash_size), 155 if (!pflash_cfi01_register(OMAP_CS0_BASE, qemu_ram_alloc(flash_size),
156 - drives_table[index].bdrv, sector_size, flash_size / sector_size, 156 + dinfo->bdrv, sector_size, flash_size / sector_size,
157 4, 0, 0, 0, 0)) { 157 4, 0, 0, 0, 0)) {
158 fprintf(stderr, "qemu: Error registering flash memory %d.\n", 158 fprintf(stderr, "qemu: Error registering flash memory %d.\n",
159 fl_idx); 159 fl_idx);
@@ -162,7 +162,7 @@ static void sx1_init(ram_addr_t ram_size, @@ -162,7 +162,7 @@ static void sx1_init(ram_addr_t ram_size,
162 } 162 }
163 163
164 if ((version == 1) && 164 if ((version == 1) &&
165 - (index = drive_get_index(IF_PFLASH, 0, fl_idx)) > -1) { 165 + (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
166 cpu_register_physical_memory(OMAP_CS1_BASE, flash1_size, 166 cpu_register_physical_memory(OMAP_CS1_BASE, flash1_size,
167 (phys_flash = qemu_ram_alloc(flash1_size)) | 167 (phys_flash = qemu_ram_alloc(flash1_size)) |
168 IO_MEM_ROM); 168 IO_MEM_ROM);
@@ -171,7 +171,7 @@ static void sx1_init(ram_addr_t ram_size, @@ -171,7 +171,7 @@ static void sx1_init(ram_addr_t ram_size,
171 OMAP_CS1_SIZE - flash1_size, io); 171 OMAP_CS1_SIZE - flash1_size, io);
172 172
173 if (!pflash_cfi01_register(OMAP_CS1_BASE, qemu_ram_alloc(flash1_size), 173 if (!pflash_cfi01_register(OMAP_CS1_BASE, qemu_ram_alloc(flash1_size),
174 - drives_table[index].bdrv, sector_size, flash1_size / sector_size, 174 + dinfo->bdrv, sector_size, flash1_size / sector_size,
175 4, 0, 0, 0, 0)) { 175 4, 0, 0, 0, 0)) {
176 fprintf(stderr, "qemu: Error registering flash memory %d.\n", 176 fprintf(stderr, "qemu: Error registering flash memory %d.\n",
177 fl_idx); 177 fl_idx);
hw/onenand.c
@@ -618,7 +618,7 @@ static CPUWriteMemoryFunc *onenand_writefn[] = { @@ -618,7 +618,7 @@ static CPUWriteMemoryFunc *onenand_writefn[] = {
618 void *onenand_init(uint32_t id, int regshift, qemu_irq irq) 618 void *onenand_init(uint32_t id, int regshift, qemu_irq irq)
619 { 619 {
620 OneNANDState *s = (OneNANDState *) qemu_mallocz(sizeof(*s)); 620 OneNANDState *s = (OneNANDState *) qemu_mallocz(sizeof(*s));
621 - int bdrv_index = drive_get_index(IF_MTD, 0, 0); 621 + DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
622 uint32_t size = 1 << (24 + ((id >> 12) & 7)); 622 uint32_t size = 1 << (24 + ((id >> 12) & 7));
623 void *ram; 623 void *ram;
624 624
@@ -632,11 +632,11 @@ void *onenand_init(uint32_t id, int regshift, qemu_irq irq) @@ -632,11 +632,11 @@ void *onenand_init(uint32_t id, int regshift, qemu_irq irq)
632 s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0; 632 s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0;
633 s->iomemtype = cpu_register_io_memory(onenand_readfn, 633 s->iomemtype = cpu_register_io_memory(onenand_readfn,
634 onenand_writefn, s); 634 onenand_writefn, s);
635 - if (bdrv_index == -1) 635 + if (!dinfo)
636 s->image = memset(qemu_malloc(size + (size >> 5)), 636 s->image = memset(qemu_malloc(size + (size >> 5)),
637 0xff, size + (size >> 5)); 637 0xff, size + (size >> 5));
638 else 638 else
639 - s->bdrv = drives_table[bdrv_index].bdrv; 639 + s->bdrv = dinfo->bdrv;
640 s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT), 640 s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT),
641 0xff, (64 + 2) << PAGE_SHIFT); 641 0xff, (64 + 2) << PAGE_SHIFT);
642 s->ram = qemu_ram_alloc(0xc000 << s->shift); 642 s->ram = qemu_ram_alloc(0xc000 << s->shift);
@@ -1126,7 +1126,7 @@ static void pc_init1(ram_addr_t ram_size, @@ -1126,7 +1126,7 @@ static void pc_init1(ram_addr_t ram_size,
1126 CPUState *env; 1126 CPUState *env;
1127 qemu_irq *cpu_irq; 1127 qemu_irq *cpu_irq;
1128 qemu_irq *i8259; 1128 qemu_irq *i8259;
1129 - int index; 1129 + DriveInfo *dinfo;
1130 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 1130 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
1131 BlockDriverState *fd[MAX_FD]; 1131 BlockDriverState *fd[MAX_FD];
1132 int using_vga = cirrus_vga_enabled || std_vga_enabled || vmsvga_enabled; 1132 int using_vga = cirrus_vga_enabled || std_vga_enabled || vmsvga_enabled;
@@ -1356,11 +1356,8 @@ static void pc_init1(ram_addr_t ram_size, @@ -1356,11 +1356,8 @@ static void pc_init1(ram_addr_t ram_size,
1356 } 1356 }
1357 1357
1358 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { 1358 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
1359 - index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);  
1360 - if (index != -1)  
1361 - hd[i] = drives_table[index].bdrv;  
1362 - else  
1363 - hd[i] = NULL; 1359 + dinfo = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
  1360 + hd[i] = dinfo ? dinfo->bdrv : NULL;
1364 } 1361 }
1365 1362
1366 if (pci_enabled) { 1363 if (pci_enabled) {
@@ -1379,11 +1376,8 @@ static void pc_init1(ram_addr_t ram_size, @@ -1379,11 +1376,8 @@ static void pc_init1(ram_addr_t ram_size,
1379 #endif 1376 #endif
1380 1377
1381 for(i = 0; i < MAX_FD; i++) { 1378 for(i = 0; i < MAX_FD; i++) {
1382 - index = drive_get_index(IF_FLOPPY, 0, i);  
1383 - if (index != -1)  
1384 - fd[i] = drives_table[index].bdrv;  
1385 - else  
1386 - fd[i] = NULL; 1379 + dinfo = drive_get(IF_FLOPPY, 0, i);
  1380 + fd[i] = dinfo ? dinfo->bdrv : NULL;
1387 } 1381 }
1388 floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd); 1382 floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
1389 1383
@@ -1437,12 +1431,11 @@ static void pc_init1(ram_addr_t ram_size, @@ -1437,12 +1431,11 @@ static void pc_init1(ram_addr_t ram_size,
1437 1431
1438 /* Add virtio block devices */ 1432 /* Add virtio block devices */
1439 if (pci_enabled) { 1433 if (pci_enabled) {
1440 - int index;  
1441 int unit_id = 0; 1434 int unit_id = 0;
1442 1435
1443 - while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { 1436 + while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
1444 pci_dev = pci_create(virtio_blk_name, 1437 pci_dev = pci_create(virtio_blk_name,
1445 - drives_table[index].devaddr); 1438 + dinfo->devaddr);
1446 qdev_init(&pci_dev->qdev); 1439 qdev_init(&pci_dev->qdev);
1447 unit_id++; 1440 unit_id++;
1448 } 1441 }
hw/pci-hotplug.c
@@ -52,9 +52,10 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts) @@ -52,9 +52,10 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
52 { 52 {
53 int dom, pci_bus; 53 int dom, pci_bus;
54 unsigned slot; 54 unsigned slot;
55 - int drive_idx, type, bus; 55 + int type, bus;
56 int success = 0; 56 int success = 0;
57 PCIDevice *dev; 57 PCIDevice *dev;
  58 + DriveInfo *dinfo;
58 59
59 if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) { 60 if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
60 return; 61 return;
@@ -66,21 +67,21 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts) @@ -66,21 +67,21 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
66 return; 67 return;
67 } 68 }
68 69
69 - drive_idx = add_init_drive(opts);  
70 - if (drive_idx < 0) 70 + dinfo = add_init_drive(opts);
  71 + if (!dinfo)
71 return; 72 return;
72 - if (drives_table[drive_idx].devaddr) { 73 + if (dinfo->devaddr) {
73 monitor_printf(mon, "Parameter addr not supported\n"); 74 monitor_printf(mon, "Parameter addr not supported\n");
74 return; 75 return;
75 } 76 }
76 - type = drives_table[drive_idx].type; 77 + type = dinfo->type;
77 bus = drive_get_max_bus (type); 78 bus = drive_get_max_bus (type);
78 79
79 switch (type) { 80 switch (type) {
80 case IF_SCSI: 81 case IF_SCSI:
81 success = 1; 82 success = 1;
82 - lsi_scsi_attach(&dev->qdev, drives_table[drive_idx].bdrv,  
83 - drives_table[drive_idx].unit); 83 + lsi_scsi_attach(&dev->qdev, dinfo->bdrv,
  84 + dinfo->unit);
84 break; 85 break;
85 default: 86 default:
86 monitor_printf(mon, "Can't hot-add drive to type %d\n", type); 87 monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
@@ -88,8 +89,8 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts) @@ -88,8 +89,8 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
88 89
89 if (success) 90 if (success)
90 monitor_printf(mon, "OK bus %d, unit %d\n", 91 monitor_printf(mon, "OK bus %d, unit %d\n",
91 - drives_table[drive_idx].bus,  
92 - drives_table[drive_idx].unit); 92 + dinfo->bus,
  93 + dinfo->unit);
93 return; 94 return;
94 } 95 }
95 96
@@ -98,7 +99,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, @@ -98,7 +99,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
98 const char *opts) 99 const char *opts)
99 { 100 {
100 PCIDevice *dev; 101 PCIDevice *dev;
101 - int type = -1, drive_idx = -1; 102 + DriveInfo *dinfo;
  103 + int type = -1;
102 char buf[128]; 104 char buf[128];
103 105
104 if (get_param_value(buf, sizeof(buf), "if", opts)) { 106 if (get_param_value(buf, sizeof(buf), "if", opts)) {
@@ -116,10 +118,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, @@ -116,10 +118,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
116 } 118 }
117 119
118 if (get_param_value(buf, sizeof(buf), "file", opts)) { 120 if (get_param_value(buf, sizeof(buf), "file", opts)) {
119 - drive_idx = add_init_drive(opts);  
120 - if (drive_idx < 0) 121 + dinfo = add_init_drive(opts);
  122 + if (!dinfo)
121 return NULL; 123 return NULL;
122 - if (drives_table[drive_idx].devaddr) { 124 + if (dinfo->devaddr) {
123 monitor_printf(mon, "Parameter addr not supported\n"); 125 monitor_printf(mon, "Parameter addr not supported\n");
124 return NULL; 126 return NULL;
125 } 127 }
hw/petalogix_s3adsp1800_mmu.c
@@ -106,6 +106,7 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size, @@ -106,6 +106,7 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
106 DeviceState *dev; 106 DeviceState *dev;
107 CPUState *env; 107 CPUState *env;
108 int kernel_size; 108 int kernel_size;
  109 + DriveInfo *dinfo;
109 int i; 110 int i;
110 target_phys_addr_t ddr_base = 0x90000000; 111 target_phys_addr_t ddr_base = 0x90000000;
111 ram_addr_t phys_lmb_bram; 112 ram_addr_t phys_lmb_bram;
@@ -131,9 +132,9 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size, @@ -131,9 +132,9 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
131 cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM); 132 cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM);
132 133
133 phys_flash = qemu_ram_alloc(FLASH_SIZE); 134 phys_flash = qemu_ram_alloc(FLASH_SIZE);
134 - i = drive_get_index(IF_PFLASH, 0, 0); 135 + dinfo = drive_get(IF_PFLASH, 0, 0);
135 pflash_cfi02_register(0xa0000000, phys_flash, 136 pflash_cfi02_register(0xa0000000, phys_flash,
136 - i != -1 ? drives_table[i].bdrv : NULL, (64 * 1024), 137 + dinfo ? dinfo->bdrv : NULL, (64 * 1024),
137 FLASH_SIZE >> 16, 138 FLASH_SIZE >> 16,
138 1, 1, 0x0000, 0x0000, 0x0000, 0x0000, 139 1, 1, 0x0000, 0x0000, 0x0000, 0x0000,
139 0x555, 0x2aa); 140 0x555, 0x2aa);
hw/ppc405_boards.c
@@ -188,7 +188,7 @@ static void ref405ep_init (ram_addr_t ram_size, @@ -188,7 +188,7 @@ static void ref405ep_init (ram_addr_t ram_size,
188 int linux_boot; 188 int linux_boot;
189 int fl_idx, fl_sectors, len; 189 int fl_idx, fl_sectors, len;
190 int ppc_boot_device = boot_device[0]; 190 int ppc_boot_device = boot_device[0];
191 - int index; 191 + DriveInfo *dinfo;
192 192
193 /* XXX: fix this */ 193 /* XXX: fix this */
194 ram_bases[0] = qemu_ram_alloc(0x08000000); 194 ram_bases[0] = qemu_ram_alloc(0x08000000);
@@ -215,19 +215,19 @@ static void ref405ep_init (ram_addr_t ram_size, @@ -215,19 +215,19 @@ static void ref405ep_init (ram_addr_t ram_size,
215 #endif 215 #endif
216 fl_idx = 0; 216 fl_idx = 0;
217 #ifdef USE_FLASH_BIOS 217 #ifdef USE_FLASH_BIOS
218 - index = drive_get_index(IF_PFLASH, 0, fl_idx);  
219 - if (index != -1) {  
220 - bios_size = bdrv_getlength(drives_table[index].bdrv); 218 + dinfo = drive_get(IF_PFLASH, 0, fl_idx);
  219 + if (dinfo) {
  220 + bios_size = bdrv_getlength(dinfo->bdrv);
221 bios_offset = qemu_ram_alloc(bios_size); 221 bios_offset = qemu_ram_alloc(bios_size);
222 fl_sectors = (bios_size + 65535) >> 16; 222 fl_sectors = (bios_size + 65535) >> 16;
223 #ifdef DEBUG_BOARD_INIT 223 #ifdef DEBUG_BOARD_INIT
224 printf("Register parallel flash %d size " ADDRX " at offset %08lx " 224 printf("Register parallel flash %d size " ADDRX " at offset %08lx "
225 " addr " ADDRX " '%s' %d\n", 225 " addr " ADDRX " '%s' %d\n",
226 fl_idx, bios_size, bios_offset, -bios_size, 226 fl_idx, bios_size, bios_offset, -bios_size,
227 - bdrv_get_device_name(drives_table[index].bdrv), fl_sectors); 227 + bdrv_get_device_name(dinfo->bdrv), fl_sectors);
228 #endif 228 #endif
229 pflash_cfi02_register((uint32_t)(-bios_size), bios_offset, 229 pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
230 - drives_table[index].bdrv, 65536, fl_sectors, 1, 230 + dinfo->bdrv, 65536, fl_sectors, 1,
231 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); 231 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
232 fl_idx++; 232 fl_idx++;
233 } else 233 } else
@@ -509,7 +509,7 @@ static void taihu_405ep_init(ram_addr_t ram_size, @@ -509,7 +509,7 @@ static void taihu_405ep_init(ram_addr_t ram_size,
509 int linux_boot; 509 int linux_boot;
510 int fl_idx, fl_sectors; 510 int fl_idx, fl_sectors;
511 int ppc_boot_device = boot_device[0]; 511 int ppc_boot_device = boot_device[0];
512 - int index; 512 + DriveInfo *dinfo;
513 513
514 /* RAM is soldered to the board so the size cannot be changed */ 514 /* RAM is soldered to the board so the size cannot be changed */
515 ram_bases[0] = qemu_ram_alloc(0x04000000); 515 ram_bases[0] = qemu_ram_alloc(0x04000000);
@@ -528,9 +528,9 @@ static void taihu_405ep_init(ram_addr_t ram_size, @@ -528,9 +528,9 @@ static void taihu_405ep_init(ram_addr_t ram_size,
528 #endif 528 #endif
529 fl_idx = 0; 529 fl_idx = 0;
530 #if defined(USE_FLASH_BIOS) 530 #if defined(USE_FLASH_BIOS)
531 - index = drive_get_index(IF_PFLASH, 0, fl_idx);  
532 - if (index != -1) {  
533 - bios_size = bdrv_getlength(drives_table[index].bdrv); 531 + dinfo = drive_get(IF_PFLASH, 0, fl_idx);
  532 + if (dinfo) {
  533 + bios_size = bdrv_getlength(dinfo->bdrv);
534 /* XXX: should check that size is 2MB */ 534 /* XXX: should check that size is 2MB */
535 // bios_size = 2 * 1024 * 1024; 535 // bios_size = 2 * 1024 * 1024;
536 fl_sectors = (bios_size + 65535) >> 16; 536 fl_sectors = (bios_size + 65535) >> 16;
@@ -539,10 +539,10 @@ static void taihu_405ep_init(ram_addr_t ram_size, @@ -539,10 +539,10 @@ static void taihu_405ep_init(ram_addr_t ram_size,
539 printf("Register parallel flash %d size " ADDRX " at offset %08lx " 539 printf("Register parallel flash %d size " ADDRX " at offset %08lx "
540 " addr " ADDRX " '%s' %d\n", 540 " addr " ADDRX " '%s' %d\n",
541 fl_idx, bios_size, bios_offset, -bios_size, 541 fl_idx, bios_size, bios_offset, -bios_size,
542 - bdrv_get_device_name(drives_table[index].bdrv), fl_sectors); 542 + bdrv_get_device_name(dinfo->bdrv), fl_sectors);
543 #endif 543 #endif
544 pflash_cfi02_register((uint32_t)(-bios_size), bios_offset, 544 pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
545 - drives_table[index].bdrv, 65536, fl_sectors, 1, 545 + dinfo->bdrv, 65536, fl_sectors, 1,
546 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); 546 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
547 fl_idx++; 547 fl_idx++;
548 } else 548 } else
@@ -570,9 +570,9 @@ static void taihu_405ep_init(ram_addr_t ram_size, @@ -570,9 +570,9 @@ static void taihu_405ep_init(ram_addr_t ram_size,
570 bios_size, bios_offset | IO_MEM_ROM); 570 bios_size, bios_offset | IO_MEM_ROM);
571 } 571 }
572 /* Register Linux flash */ 572 /* Register Linux flash */
573 - index = drive_get_index(IF_PFLASH, 0, fl_idx);  
574 - if (index != -1) {  
575 - bios_size = bdrv_getlength(drives_table[index].bdrv); 573 + dinfo = drive_get(IF_PFLASH, 0, fl_idx);
  574 + if (dinfo) {
  575 + bios_size = bdrv_getlength(dinfo->bdrv);
576 /* XXX: should check that size is 32MB */ 576 /* XXX: should check that size is 32MB */
577 bios_size = 32 * 1024 * 1024; 577 bios_size = 32 * 1024 * 1024;
578 fl_sectors = (bios_size + 65535) >> 16; 578 fl_sectors = (bios_size + 65535) >> 16;
@@ -580,11 +580,11 @@ static void taihu_405ep_init(ram_addr_t ram_size, @@ -580,11 +580,11 @@ static void taihu_405ep_init(ram_addr_t ram_size,
580 printf("Register parallel flash %d size " ADDRX " at offset %08lx " 580 printf("Register parallel flash %d size " ADDRX " at offset %08lx "
581 " addr " ADDRX " '%s'\n", 581 " addr " ADDRX " '%s'\n",
582 fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000, 582 fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000,
583 - bdrv_get_device_name(drives_table[index].bdrv)); 583 + bdrv_get_device_name(dinfo->bdrv));
584 #endif 584 #endif
585 bios_offset = qemu_ram_alloc(bios_size); 585 bios_offset = qemu_ram_alloc(bios_size);
586 pflash_cfi02_register(0xfc000000, bios_offset, 586 pflash_cfi02_register(0xfc000000, bios_offset,
587 - drives_table[index].bdrv, 65536, fl_sectors, 1, 587 + dinfo->bdrv, 65536, fl_sectors, 1,
588 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); 588 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
589 fl_idx++; 589 fl_idx++;
590 } 590 }
hw/ppc440_bamboo.c
@@ -102,6 +102,7 @@ static void bamboo_init(ram_addr_t ram_size, @@ -102,6 +102,7 @@ static void bamboo_init(ram_addr_t ram_size,
102 target_ulong dt_base = 0; 102 target_ulong dt_base = 0;
103 void *fdt; 103 void *fdt;
104 int i; 104 int i;
  105 + DriveInfo *dinfo;
105 106
106 /* Setup CPU. */ 107 /* Setup CPU. */
107 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model); 108 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
@@ -110,8 +111,8 @@ static void bamboo_init(ram_addr_t ram_size, @@ -110,8 +111,8 @@ static void bamboo_init(ram_addr_t ram_size,
110 int unit_id = 0; 111 int unit_id = 0;
111 112
112 /* Add virtio block devices. */ 113 /* Add virtio block devices. */
113 - while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {  
114 - pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr); 114 + while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
  115 + pci_dev = pci_create("virtio-blk-pci", dinfo->devaddr);
115 qdev_init(&pci_dev->qdev); 116 qdev_init(&pci_dev->qdev);
116 unit_id++; 117 unit_id++;
117 } 118 }
hw/ppc_newworld.c
@@ -106,7 +106,7 @@ static void ppc_core99_init (ram_addr_t ram_size, @@ -106,7 +106,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
106 qemu_irq *dummy_irq; 106 qemu_irq *dummy_irq;
107 int pic_mem_index, dbdma_mem_index, cuda_mem_index, escc_mem_index; 107 int pic_mem_index, dbdma_mem_index, cuda_mem_index, escc_mem_index;
108 int ppc_boot_device; 108 int ppc_boot_device;
109 - int index; 109 + DriveInfo *dinfo;
110 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 110 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
111 void *fw_cfg; 111 void *fw_cfg;
112 void *dbdma; 112 void *dbdma;
@@ -315,11 +315,8 @@ static void ppc_core99_init (ram_addr_t ram_size, @@ -315,11 +315,8 @@ static void ppc_core99_init (ram_addr_t ram_size,
315 exit(1); 315 exit(1);
316 } 316 }
317 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { 317 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
318 - index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);  
319 - if (index != -1)  
320 - hd[i] = drives_table[index].bdrv;  
321 - else  
322 - hd[i] = NULL; 318 + dinfo = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
  319 + hd[i] = dinfo ? dinfo->bdrv : NULL;
323 } 320 }
324 dbdma = DBDMA_init(&dbdma_mem_index); 321 dbdma = DBDMA_init(&dbdma_mem_index);
325 pci_cmd646_ide_init(pci_bus, hd, 0); 322 pci_cmd646_ide_init(pci_bus, hd, 0);
hw/ppc_oldworld.c
@@ -135,7 +135,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size, @@ -135,7 +135,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
135 int escc_mem_index, ide_mem_index[2]; 135 int escc_mem_index, ide_mem_index[2];
136 uint16_t ppc_boot_device; 136 uint16_t ppc_boot_device;
137 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 137 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
138 - int index; 138 + DriveInfo *dinfo;
139 void *fw_cfg; 139 void *fw_cfg;
140 void *dbdma; 140 void *dbdma;
141 uint8_t *vga_bios_ptr; 141 uint8_t *vga_bios_ptr;
@@ -328,31 +328,19 @@ static void ppc_heathrow_init (ram_addr_t ram_size, @@ -328,31 +328,19 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
328 } 328 }
329 329
330 /* First IDE channel is a MAC IDE on the MacIO bus */ 330 /* First IDE channel is a MAC IDE on the MacIO bus */
331 - index = drive_get_index(IF_IDE, 0, 0);  
332 - if (index == -1)  
333 - hd[0] = NULL;  
334 - else  
335 - hd[0] = drives_table[index].bdrv;  
336 - index = drive_get_index(IF_IDE, 0, 1);  
337 - if (index == -1)  
338 - hd[1] = NULL;  
339 - else  
340 - hd[1] = drives_table[index].bdrv; 331 + dinfo = drive_get(IF_IDE, 0, 0);
  332 + hd[0] = dinfo ? dinfo->bdrv : NULL;
  333 + dinfo = drive_get(IF_IDE, 0, 1);
  334 + hd[1] = dinfo ? dinfo->bdrv : NULL;
341 dbdma = DBDMA_init(&dbdma_mem_index); 335 dbdma = DBDMA_init(&dbdma_mem_index);
342 ide_mem_index[0] = -1; 336 ide_mem_index[0] = -1;
343 ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D], dbdma, 0x16, pic[0x02]); 337 ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D], dbdma, 0x16, pic[0x02]);
344 338
345 /* Second IDE channel is a CMD646 on the PCI bus */ 339 /* Second IDE channel is a CMD646 on the PCI bus */
346 - index = drive_get_index(IF_IDE, 1, 0);  
347 - if (index == -1)  
348 - hd[0] = NULL;  
349 - else  
350 - hd[0] = drives_table[index].bdrv;  
351 - index = drive_get_index(IF_IDE, 1, 1);  
352 - if (index == -1)  
353 - hd[1] = NULL;  
354 - else  
355 - hd[1] = drives_table[index].bdrv; 340 + dinfo = drive_get(IF_IDE, 1, 0);
  341 + hd[0] = dinfo ? dinfo->bdrv : NULL;
  342 + dinfo = drive_get(IF_IDE, 1, 1);
  343 + hd[1] = dinfo ? dinfo->bdrv : NULL;
356 hd[3] = hd[2] = NULL; 344 hd[3] = hd[2] = NULL;
357 pci_cmd646_ide_init(pci_bus, hd, 0); 345 pci_cmd646_ide_init(pci_bus, hd, 0);
358 346
hw/ppc_prep.c
@@ -550,7 +550,7 @@ static void ppc_prep_init (ram_addr_t ram_size, @@ -550,7 +550,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
550 PCIBus *pci_bus; 550 PCIBus *pci_bus;
551 qemu_irq *i8259; 551 qemu_irq *i8259;
552 int ppc_boot_device; 552 int ppc_boot_device;
553 - int index; 553 + DriveInfo *dinfo;
554 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 554 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
555 BlockDriverState *fd[MAX_FD]; 555 BlockDriverState *fd[MAX_FD];
556 556
@@ -691,11 +691,8 @@ static void ppc_prep_init (ram_addr_t ram_size, @@ -691,11 +691,8 @@ static void ppc_prep_init (ram_addr_t ram_size,
691 } 691 }
692 692
693 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { 693 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
694 - index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);  
695 - if (index != -1)  
696 - hd[i] = drives_table[index].bdrv;  
697 - else  
698 - hd[i] = NULL; 694 + dinfo = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
  695 + hd[i] = dinfo ? dinfo->bdrv : NULL;
699 } 696 }
700 697
701 for(i = 0; i < MAX_IDE_BUS; i++) { 698 for(i = 0; i < MAX_IDE_BUS; i++) {
@@ -708,11 +705,8 @@ static void ppc_prep_init (ram_addr_t ram_size, @@ -708,11 +705,8 @@ static void ppc_prep_init (ram_addr_t ram_size,
708 // SB16_init(); 705 // SB16_init();
709 706
710 for(i = 0; i < MAX_FD; i++) { 707 for(i = 0; i < MAX_FD; i++) {
711 - index = drive_get_index(IF_FLOPPY, 0, i);  
712 - if (index != -1)  
713 - fd[i] = drives_table[index].bdrv;  
714 - else  
715 - fd[i] = NULL; 708 + dinfo = drive_get(IF_FLOPPY, 0, i);
  709 + fd[i] = dinfo ? dinfo->bdrv : NULL;
716 } 710 }
717 fdctrl_init(i8259[6], 2, 0, 0x3f0, fd); 711 fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
718 712
hw/ppce500_mpc8544ds.c
@@ -172,6 +172,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, @@ -172,6 +172,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
172 unsigned int pci_irq_nrs[4] = {1, 2, 3, 4}; 172 unsigned int pci_irq_nrs[4] = {1, 2, 3, 4};
173 qemu_irq *irqs, *mpic, *pci_irqs; 173 qemu_irq *irqs, *mpic, *pci_irqs;
174 SerialState * serial[2]; 174 SerialState * serial[2];
  175 + DriveInfo *dinfo;
175 176
176 /* Setup CPU */ 177 /* Setup CPU */
177 env = cpu_ppc_init("e500v2_v30"); 178 env = cpu_ppc_init("e500v2_v30");
@@ -219,8 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size, @@ -219,8 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size,
219 int unit_id = 0; 220 int unit_id = 0;
220 221
221 /* Add virtio block devices. */ 222 /* Add virtio block devices. */
222 - while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {  
223 - pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr); 223 + while ((dinfo = drive_get(IF_VIRTIO, 0, unit_id)) != NULL) {
  224 + pci_dev = pci_create("virtio-blk-pci", dinfo->devaddr);
224 qdev_init(&pci_dev->qdev); 225 qdev_init(&pci_dev->qdev);
225 unit_id++; 226 unit_id++;
226 } 227 }
hw/pxa2xx.c
@@ -2034,7 +2034,7 @@ PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision) @@ -2034,7 +2034,7 @@ PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision)
2034 { 2034 {
2035 PXA2xxState *s; 2035 PXA2xxState *s;
2036 int iomemtype, i; 2036 int iomemtype, i;
2037 - int index; 2037 + DriveInfo *dinfo;
2038 s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState)); 2038 s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState));
2039 2039
2040 if (revision && strncmp(revision, "pxa27", 5)) { 2040 if (revision && strncmp(revision, "pxa27", 5)) {
@@ -2066,12 +2066,12 @@ PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision) @@ -2066,12 +2066,12 @@ PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision)
2066 2066
2067 s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 121); 2067 s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 121);
2068 2068
2069 - index = drive_get_index(IF_SD, 0, 0);  
2070 - if (index == -1) { 2069 + dinfo = drive_get(IF_SD, 0, 0);
  2070 + if (!dinfo) {
2071 fprintf(stderr, "qemu: missing SecureDigital device\n"); 2071 fprintf(stderr, "qemu: missing SecureDigital device\n");
2072 exit(1); 2072 exit(1);
2073 } 2073 }
2074 - s->mmc = pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv, 2074 + s->mmc = pxa2xx_mmci_init(0x41100000, dinfo->bdrv,
2075 s->pic[PXA2XX_PIC_MMC], s->dma); 2075 s->pic[PXA2XX_PIC_MMC], s->dma);
2076 2076
2077 for (i = 0; pxa270_serial[i].io_base; i ++) 2077 for (i = 0; pxa270_serial[i].io_base; i ++)
@@ -2153,7 +2153,7 @@ PXA2xxState *pxa255_init(unsigned int sdram_size) @@ -2153,7 +2153,7 @@ PXA2xxState *pxa255_init(unsigned int sdram_size)
2153 { 2153 {
2154 PXA2xxState *s; 2154 PXA2xxState *s;
2155 int iomemtype, i; 2155 int iomemtype, i;
2156 - int index; 2156 + DriveInfo *dinfo;
2157 2157
2158 s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState)); 2158 s = (PXA2xxState *) qemu_mallocz(sizeof(PXA2xxState));
2159 2159
@@ -2178,12 +2178,12 @@ PXA2xxState *pxa255_init(unsigned int sdram_size) @@ -2178,12 +2178,12 @@ PXA2xxState *pxa255_init(unsigned int sdram_size)
2178 2178
2179 s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 85); 2179 s->gpio = pxa2xx_gpio_init(0x40e00000, s->env, s->pic, 85);
2180 2180
2181 - index = drive_get_index(IF_SD, 0, 0);  
2182 - if (index == -1) { 2181 + dinfo = drive_get(IF_SD, 0, 0);
  2182 + if (!dinfo) {
2183 fprintf(stderr, "qemu: missing SecureDigital device\n"); 2183 fprintf(stderr, "qemu: missing SecureDigital device\n");
2184 exit(1); 2184 exit(1);
2185 } 2185 }
2186 - s->mmc = pxa2xx_mmci_init(0x41100000, drives_table[index].bdrv, 2186 + s->mmc = pxa2xx_mmci_init(0x41100000, dinfo->bdrv,
2187 s->pic[PXA2XX_PIC_MMC], s->dma); 2187 s->pic[PXA2XX_PIC_MMC], s->dma);
2188 2188
2189 for (i = 0; pxa255_serial[i].io_base; i ++) 2189 for (i = 0; pxa255_serial[i].io_base; i ++)
hw/qdev.c
@@ -267,13 +267,10 @@ static int next_block_unit[IF_COUNT]; @@ -267,13 +267,10 @@ static int next_block_unit[IF_COUNT];
267 BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type) 267 BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type)
268 { 268 {
269 int unit = next_block_unit[type]++; 269 int unit = next_block_unit[type]++;
270 - int index; 270 + DriveInfo *dinfo;
271 271
272 - index = drive_get_index(type, 0, unit);  
273 - if (index == -1) {  
274 - return NULL;  
275 - }  
276 - return drives_table[index].bdrv; 272 + dinfo = drive_get(type, 0, unit);
  273 + return dinfo ? dinfo->bdrv : NULL;
277 } 274 }
278 275
279 BusState *qdev_get_child_bus(DeviceState *dev, const char *name) 276 BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
@@ -296,14 +293,14 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach) @@ -296,14 +293,14 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
296 { 293 {
297 int bus = next_scsi_bus++; 294 int bus = next_scsi_bus++;
298 int unit; 295 int unit;
299 - int index; 296 + DriveInfo *dinfo;
300 297
301 for (unit = 0; unit < MAX_SCSI_DEVS; unit++) { 298 for (unit = 0; unit < MAX_SCSI_DEVS; unit++) {
302 - index = drive_get_index(IF_SCSI, bus, unit);  
303 - if (index == -1) { 299 + dinfo = drive_get(IF_SCSI, bus, unit);
  300 + if (!dinfo) {
304 continue; 301 continue;
305 } 302 }
306 - attach(host, drives_table[index].bdrv, unit); 303 + attach(host, dinfo->bdrv, unit);
307 } 304 }
308 } 305 }
309 306
hw/r2d.c
@@ -203,6 +203,7 @@ static void r2d_init(ram_addr_t ram_size, @@ -203,6 +203,7 @@ static void r2d_init(ram_addr_t ram_size,
203 ram_addr_t sdram_addr; 203 ram_addr_t sdram_addr;
204 qemu_irq *irq; 204 qemu_irq *irq;
205 PCIBus *pci; 205 PCIBus *pci;
  206 + DriveInfo *dinfo;
206 int i; 207 int i;
207 208
208 if (!cpu_model) 209 if (!cpu_model)
@@ -225,9 +226,9 @@ static void r2d_init(ram_addr_t ram_size, @@ -225,9 +226,9 @@ static void r2d_init(ram_addr_t ram_size,
225 sm501_init(0x10000000, SM501_VRAM_SIZE, irq[SM501], serial_hds[2]); 226 sm501_init(0x10000000, SM501_VRAM_SIZE, irq[SM501], serial_hds[2]);
226 227
227 /* onboard CF (True IDE mode, Master only). */ 228 /* onboard CF (True IDE mode, Master only). */
228 - if ((i = drive_get_index(IF_IDE, 0, 0)) != -1) 229 + if ((dinfo = drive_get(IF_IDE, 0, 0)) != NULL)
229 mmio_ide_init(0x14001000, 0x1400080c, irq[CF_IDE], 1, 230 mmio_ide_init(0x14001000, 0x1400080c, irq[CF_IDE], 1,
230 - drives_table[i].bdrv, NULL); 231 + dinfo->bdrv, NULL);
231 232
232 /* NIC: rtl8139 on-board, and 2 slots. */ 233 /* NIC: rtl8139 on-board, and 2 slots. */
233 for (i = 0; i < nb_nics; i++) 234 for (i = 0; i < nb_nics; i++)
hw/spitz.c
@@ -744,13 +744,13 @@ static void spitz_ssp_attach(PXA2xxState *cpu) @@ -744,13 +744,13 @@ static void spitz_ssp_attach(PXA2xxState *cpu)
744 static void spitz_microdrive_attach(PXA2xxState *cpu, int slot) 744 static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
745 { 745 {
746 PCMCIACardState *md; 746 PCMCIACardState *md;
747 - int index;  
748 BlockDriverState *bs; 747 BlockDriverState *bs;
  748 + DriveInfo *dinfo;
749 749
750 - index = drive_get_index(IF_IDE, 0, 0);  
751 - if (index == -1) 750 + dinfo = drive_get(IF_IDE, 0, 0);
  751 + if (!dinfo)
752 return; 752 return;
753 - bs = drives_table[index].bdrv; 753 + bs = dinfo->bdrv;
754 if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) { 754 if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
755 md = dscm1xxxx_init(bs); 755 md = dscm1xxxx_init(bs);
756 pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md); 756 pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
hw/sun4m.c
@@ -581,9 +581,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, @@ -581,9 +581,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
581 qemu_irq *cpu_halt; 581 qemu_irq *cpu_halt;
582 unsigned long kernel_size; 582 unsigned long kernel_size;
583 BlockDriverState *fd[MAX_FD]; 583 BlockDriverState *fd[MAX_FD];
584 - int drive_index;  
585 void *fw_cfg; 584 void *fw_cfg;
586 DeviceState *dev; 585 DeviceState *dev;
  586 + DriveInfo *dinfo;
587 587
588 /* init CPUs */ 588 /* init CPUs */
589 if (!cpu_model) 589 if (!cpu_model)
@@ -662,9 +662,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, @@ -662,9 +662,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
662 if (hwdef->fd_base) { 662 if (hwdef->fd_base) {
663 /* there is zero or one floppy drive */ 663 /* there is zero or one floppy drive */
664 memset(fd, 0, sizeof(fd)); 664 memset(fd, 0, sizeof(fd));
665 - drive_index = drive_get_index(IF_FLOPPY, 0, 0);  
666 - if (drive_index != -1)  
667 - fd[0] = drives_table[drive_index].bdrv; 665 + dinfo = drive_get(IF_FLOPPY, 0, 0);
  666 + if (dinfo)
  667 + fd[0] = dinfo->bdrv;
668 668
669 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd, 669 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
670 &fdc_tc); 670 &fdc_tc);
@@ -1507,10 +1507,10 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, @@ -1507,10 +1507,10 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1507 qemu_irq fdc_tc; 1507 qemu_irq fdc_tc;
1508 unsigned long kernel_size; 1508 unsigned long kernel_size;
1509 BlockDriverState *fd[MAX_FD]; 1509 BlockDriverState *fd[MAX_FD];
1510 - int drive_index;  
1511 void *fw_cfg; 1510 void *fw_cfg;
1512 DeviceState *dev; 1511 DeviceState *dev;
1513 unsigned int i; 1512 unsigned int i;
  1513 + DriveInfo *dinfo;
1514 1514
1515 /* init CPU */ 1515 /* init CPU */
1516 if (!cpu_model) 1516 if (!cpu_model)
@@ -1565,9 +1565,9 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, @@ -1565,9 +1565,9 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1565 if (hwdef->fd_base != (target_phys_addr_t)-1) { 1565 if (hwdef->fd_base != (target_phys_addr_t)-1) {
1566 /* there is zero or one floppy drive */ 1566 /* there is zero or one floppy drive */
1567 memset(fd, 0, sizeof(fd)); 1567 memset(fd, 0, sizeof(fd));
1568 - drive_index = drive_get_index(IF_FLOPPY, 0, 0);  
1569 - if (drive_index != -1)  
1570 - fd[0] = drives_table[drive_index].bdrv; 1568 + dinfo = drive_get(IF_FLOPPY, 0, 0);
  1569 + if (dinfo)
  1570 + fd[0] = dinfo->bdrv;
1571 1571
1572 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd, 1572 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
1573 &fdc_tc); 1573 &fdc_tc);
hw/sun4u.c
@@ -557,10 +557,10 @@ static void sun4uv_init(ram_addr_t RAM_size, @@ -557,10 +557,10 @@ static void sun4uv_init(ram_addr_t RAM_size,
557 long initrd_size, kernel_size; 557 long initrd_size, kernel_size;
558 PCIBus *pci_bus, *pci_bus2, *pci_bus3; 558 PCIBus *pci_bus, *pci_bus2, *pci_bus3;
559 qemu_irq *irq; 559 qemu_irq *irq;
560 - int drive_index;  
561 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 560 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
562 BlockDriverState *fd[MAX_FD]; 561 BlockDriverState *fd[MAX_FD];
563 void *fw_cfg; 562 void *fw_cfg;
  563 + DriveInfo *dinfo;
564 564
565 /* init CPUs */ 565 /* init CPUs */
566 env = cpu_devinit(cpu_model, hwdef); 566 env = cpu_devinit(cpu_model, hwdef);
@@ -608,12 +608,9 @@ static void sun4uv_init(ram_addr_t RAM_size, @@ -608,12 +608,9 @@ static void sun4uv_init(ram_addr_t RAM_size,
608 exit(1); 608 exit(1);
609 } 609 }
610 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { 610 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
611 - drive_index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS,  
612 - i % MAX_IDE_DEVS);  
613 - if (drive_index != -1)  
614 - hd[i] = drives_table[drive_index].bdrv;  
615 - else  
616 - hd[i] = NULL; 611 + dinfo = drive_get(IF_IDE, i / MAX_IDE_DEVS,
  612 + i % MAX_IDE_DEVS);
  613 + hd[i] = dinfo ? dinfo->bdrv : NULL;
617 } 614 }
618 615
619 pci_cmd646_ide_init(pci_bus, hd, 1); 616 pci_cmd646_ide_init(pci_bus, hd, 1);
@@ -621,11 +618,8 @@ static void sun4uv_init(ram_addr_t RAM_size, @@ -621,11 +618,8 @@ static void sun4uv_init(ram_addr_t RAM_size,
621 /* FIXME: wire up interrupts. */ 618 /* FIXME: wire up interrupts. */
622 i8042_init(NULL/*1*/, NULL/*12*/, 0x60); 619 i8042_init(NULL/*1*/, NULL/*12*/, 0x60);
623 for(i = 0; i < MAX_FD; i++) { 620 for(i = 0; i < MAX_FD; i++) {
624 - drive_index = drive_get_index(IF_FLOPPY, 0, i);  
625 - if (drive_index != -1)  
626 - fd[i] = drives_table[drive_index].bdrv;  
627 - else  
628 - fd[i] = NULL; 621 + dinfo = drive_get(IF_FLOPPY, 0, i);
  622 + fd[i] = dinfo ? dinfo->bdrv : NULL;
629 } 623 }
630 floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd); 624 floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd);
631 nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59); 625 nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59);
hw/tosa.c
@@ -49,13 +49,13 @@ @@ -49,13 +49,13 @@
49 static void tosa_microdrive_attach(PXA2xxState *cpu) 49 static void tosa_microdrive_attach(PXA2xxState *cpu)
50 { 50 {
51 PCMCIACardState *md; 51 PCMCIACardState *md;
52 - int index;  
53 BlockDriverState *bs; 52 BlockDriverState *bs;
  53 + DriveInfo *dinfo;
54 54
55 - index = drive_get_index(IF_IDE, 0, 0);  
56 - if (index == -1) 55 + dinfo = drive_get(IF_IDE, 0, 0);
  56 + if (!dinfo)
57 return; 57 return;
58 - bs = drives_table[index].bdrv; 58 + bs = dinfo->bdrv;
59 if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) { 59 if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
60 md = dscm1xxxx_init(bs); 60 md = dscm1xxxx_init(bs);
61 pxa2xx_pcmcia_attach(cpu->pcmcia[0], md); 61 pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
hw/xen_disk.c
@@ -107,7 +107,7 @@ struct XenBlkDev { @@ -107,7 +107,7 @@ struct XenBlkDev {
107 int requests_finished; 107 int requests_finished;
108 108
109 /* qemu block driver */ 109 /* qemu block driver */
110 - int index; 110 + DriveInfo *dinfo;
111 BlockDriverState *bs; 111 BlockDriverState *bs;
112 QEMUBH *bh; 112 QEMUBH *bh;
113 }; 113 };
@@ -575,7 +575,7 @@ static void blk_alloc(struct XenDevice *xendev) @@ -575,7 +575,7 @@ static void blk_alloc(struct XenDevice *xendev)
575 static int blk_init(struct XenDevice *xendev) 575 static int blk_init(struct XenDevice *xendev)
576 { 576 {
577 struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); 577 struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
578 - int mode, qflags, have_barriers, info = 0; 578 + int index, mode, qflags, have_barriers, info = 0;
579 char *h; 579 char *h;
580 580
581 /* read xenstore entries */ 581 /* read xenstore entries */
@@ -622,9 +622,9 @@ static int blk_init(struct XenDevice *xendev) @@ -622,9 +622,9 @@ static int blk_init(struct XenDevice *xendev)
622 info |= VDISK_CDROM; 622 info |= VDISK_CDROM;
623 623
624 /* init qemu block driver */ 624 /* init qemu block driver */
625 - blkdev->index = (blkdev->xendev.dev - 202 * 256) / 16;  
626 - blkdev->index = drive_get_index(IF_XEN, 0, blkdev->index);  
627 - if (blkdev->index == -1) { 625 + index = (blkdev->xendev.dev - 202 * 256) / 16;
  626 + blkdev->dinfo = drive_get(IF_XEN, 0, index);
  627 + if (!blkdev->dinfo) {
628 /* setup via xenbus -> create new block driver instance */ 628 /* setup via xenbus -> create new block driver instance */
629 xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n"); 629 xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
630 blkdev->bs = bdrv_new(blkdev->dev); 630 blkdev->bs = bdrv_new(blkdev->dev);
@@ -640,7 +640,7 @@ static int blk_init(struct XenDevice *xendev) @@ -640,7 +640,7 @@ static int blk_init(struct XenDevice *xendev)
640 } else { 640 } else {
641 /* setup via qemu cmdline -> already setup for us */ 641 /* setup via qemu cmdline -> already setup for us */
642 xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n"); 642 xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
643 - blkdev->bs = drives_table[blkdev->index].bdrv; 643 + blkdev->bs = blkdev->dinfo->bdrv;
644 } 644 }
645 blkdev->file_blk = BLOCK_SIZE; 645 blkdev->file_blk = BLOCK_SIZE;
646 blkdev->file_size = bdrv_getlength(blkdev->bs); 646 blkdev->file_size = bdrv_getlength(blkdev->bs);
@@ -729,7 +729,7 @@ static void blk_disconnect(struct XenDevice *xendev) @@ -729,7 +729,7 @@ static void blk_disconnect(struct XenDevice *xendev)
729 struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); 729 struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
730 730
731 if (blkdev->bs) { 731 if (blkdev->bs) {
732 - if (blkdev->index == -1) { 732 + if (!blkdev->dinfo) {
733 /* close/delete only if we created it ourself */ 733 /* close/delete only if we created it ourself */
734 bdrv_close(blkdev->bs); 734 bdrv_close(blkdev->bs);
735 bdrv_delete(blkdev->bs); 735 bdrv_delete(blkdev->bs);
hw/xen_machine_pv.c
@@ -40,7 +40,8 @@ static void xen_init_pv(ram_addr_t ram_size, @@ -40,7 +40,8 @@ static void xen_init_pv(ram_addr_t ram_size,
40 const char *cpu_model) 40 const char *cpu_model)
41 { 41 {
42 CPUState *env; 42 CPUState *env;
43 - int i, index; 43 + DriveInfo *dinfo;
  44 + int i;
44 45
45 /* Initialize a dummy CPU */ 46 /* Initialize a dummy CPU */
46 if (cpu_model == NULL) { 47 if (cpu_model == NULL) {
@@ -90,10 +91,10 @@ static void xen_init_pv(ram_addr_t ram_size, @@ -90,10 +91,10 @@ static void xen_init_pv(ram_addr_t ram_size,
90 91
91 /* configure disks */ 92 /* configure disks */
92 for (i = 0; i < 16; i++) { 93 for (i = 0; i < 16; i++) {
93 - index = drive_get_index(IF_XEN, 0, i);  
94 - if (index == -1) 94 + dinfo = drive_get(IF_XEN, 0, i);
  95 + if (!dinfo)
95 continue; 96 continue;
96 - xen_config_dev_blk(drives_table + index); 97 + xen_config_dev_blk(dinfo);
97 } 98 }
98 99
99 /* configure nics */ 100 /* configure nics */
monitor.c
@@ -253,13 +253,15 @@ static void help_cmd(Monitor *mon, const char *name) @@ -253,13 +253,15 @@ static void help_cmd(Monitor *mon, const char *name)
253 253
254 static void do_commit(Monitor *mon, const char *device) 254 static void do_commit(Monitor *mon, const char *device)
255 { 255 {
256 - int i, all_devices; 256 + int all_devices;
  257 + DriveInfo *dinfo;
257 258
258 all_devices = !strcmp(device, "all"); 259 all_devices = !strcmp(device, "all");
259 - for (i = 0; i < nb_drives; i++) {  
260 - if (all_devices ||  
261 - !strcmp(bdrv_get_device_name(drives_table[i].bdrv), device))  
262 - bdrv_commit(drives_table[i].bdrv); 260 + TAILQ_FOREACH(dinfo, &drives, next) {
  261 + if (!all_devices)
  262 + if (!strcmp(bdrv_get_device_name(dinfo->bdrv), device))
  263 + continue;
  264 + bdrv_commit(dinfo->bdrv);
263 } 265 }
264 } 266 }
265 267
qemu-char.c
@@ -350,9 +350,9 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch) @@ -350,9 +350,9 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch)
350 } 350 }
351 case 's': 351 case 's':
352 { 352 {
353 - int i;  
354 - for (i = 0; i < nb_drives; i++) {  
355 - bdrv_commit(drives_table[i].bdrv); 353 + DriveInfo *dinfo;
  354 + TAILQ_FOREACH(dinfo, &drives, next) {
  355 + bdrv_commit(dinfo->bdrv);
356 } 356 }
357 } 357 }
358 break; 358 break;
savevm.c
@@ -1011,12 +1011,12 @@ static int bdrv_has_snapshot(BlockDriverState *bs) @@ -1011,12 +1011,12 @@ static int bdrv_has_snapshot(BlockDriverState *bs)
1011 static BlockDriverState *get_bs_snapshots(void) 1011 static BlockDriverState *get_bs_snapshots(void)
1012 { 1012 {
1013 BlockDriverState *bs; 1013 BlockDriverState *bs;
1014 - int i; 1014 + DriveInfo *dinfo;
1015 1015
1016 if (bs_snapshots) 1016 if (bs_snapshots)
1017 return bs_snapshots; 1017 return bs_snapshots;
1018 - for(i = 0; i <= nb_drives; i++) {  
1019 - bs = drives_table[i].bdrv; 1018 + TAILQ_FOREACH(dinfo, &drives, next) {
  1019 + bs = dinfo->bdrv;
1020 if (bdrv_can_snapshot(bs)) 1020 if (bdrv_can_snapshot(bs))
1021 goto ok; 1021 goto ok;
1022 } 1022 }
@@ -1050,9 +1050,10 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, @@ -1050,9 +1050,10 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
1050 1050
1051 void do_savevm(Monitor *mon, const char *name) 1051 void do_savevm(Monitor *mon, const char *name)
1052 { 1052 {
  1053 + DriveInfo *dinfo;
1053 BlockDriverState *bs, *bs1; 1054 BlockDriverState *bs, *bs1;
1054 QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; 1055 QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
1055 - int must_delete, ret, i; 1056 + int must_delete, ret;
1056 QEMUFile *f; 1057 QEMUFile *f;
1057 int saved_vm_running; 1058 int saved_vm_running;
1058 uint32_t vm_state_size; 1059 uint32_t vm_state_size;
@@ -1118,8 +1119,8 @@ void do_savevm(Monitor *mon, const char *name) @@ -1118,8 +1119,8 @@ void do_savevm(Monitor *mon, const char *name)
1118 1119
1119 /* create the snapshots */ 1120 /* create the snapshots */
1120 1121
1121 - for(i = 0; i < nb_drives; i++) {  
1122 - bs1 = drives_table[i].bdrv; 1122 + TAILQ_FOREACH(dinfo, &drives, next) {
  1123 + bs1 = dinfo->bdrv;
1123 if (bdrv_has_snapshot(bs1)) { 1124 if (bdrv_has_snapshot(bs1)) {
1124 if (must_delete) { 1125 if (must_delete) {
1125 ret = bdrv_snapshot_delete(bs1, old_sn->id_str); 1126 ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
@@ -1146,10 +1147,11 @@ void do_savevm(Monitor *mon, const char *name) @@ -1146,10 +1147,11 @@ void do_savevm(Monitor *mon, const char *name)
1146 1147
1147 void do_loadvm(Monitor *mon, const char *name) 1148 void do_loadvm(Monitor *mon, const char *name)
1148 { 1149 {
  1150 + DriveInfo *dinfo;
1149 BlockDriverState *bs, *bs1; 1151 BlockDriverState *bs, *bs1;
1150 QEMUSnapshotInfo sn; 1152 QEMUSnapshotInfo sn;
1151 QEMUFile *f; 1153 QEMUFile *f;
1152 - int i, ret; 1154 + int ret;
1153 int saved_vm_running; 1155 int saved_vm_running;
1154 1156
1155 bs = get_bs_snapshots(); 1157 bs = get_bs_snapshots();
@@ -1164,8 +1166,8 @@ void do_loadvm(Monitor *mon, const char *name) @@ -1164,8 +1166,8 @@ void do_loadvm(Monitor *mon, const char *name)
1164 saved_vm_running = vm_running; 1166 saved_vm_running = vm_running;
1165 vm_stop(0); 1167 vm_stop(0);
1166 1168
1167 - for(i = 0; i <= nb_drives; i++) {  
1168 - bs1 = drives_table[i].bdrv; 1169 + TAILQ_FOREACH(dinfo, &drives, next) {
  1170 + bs1 = dinfo->bdrv;
1169 if (bdrv_has_snapshot(bs1)) { 1171 if (bdrv_has_snapshot(bs1)) {
1170 ret = bdrv_snapshot_goto(bs1, name); 1172 ret = bdrv_snapshot_goto(bs1, name);
1171 if (ret < 0) { 1173 if (ret < 0) {
@@ -1217,8 +1219,9 @@ void do_loadvm(Monitor *mon, const char *name) @@ -1217,8 +1219,9 @@ void do_loadvm(Monitor *mon, const char *name)
1217 1219
1218 void do_delvm(Monitor *mon, const char *name) 1220 void do_delvm(Monitor *mon, const char *name)
1219 { 1221 {
  1222 + DriveInfo *dinfo;
1220 BlockDriverState *bs, *bs1; 1223 BlockDriverState *bs, *bs1;
1221 - int i, ret; 1224 + int ret;
1222 1225
1223 bs = get_bs_snapshots(); 1226 bs = get_bs_snapshots();
1224 if (!bs) { 1227 if (!bs) {
@@ -1226,8 +1229,8 @@ void do_delvm(Monitor *mon, const char *name) @@ -1226,8 +1229,8 @@ void do_delvm(Monitor *mon, const char *name)
1226 return; 1229 return;
1227 } 1230 }
1228 1231
1229 - for(i = 0; i <= nb_drives; i++) {  
1230 - bs1 = drives_table[i].bdrv; 1232 + TAILQ_FOREACH(dinfo, &drives, next) {
  1233 + bs1 = dinfo->bdrv;
1231 if (bdrv_has_snapshot(bs1)) { 1234 if (bdrv_has_snapshot(bs1)) {
1232 ret = bdrv_snapshot_delete(bs1, name); 1235 ret = bdrv_snapshot_delete(bs1, name);
1233 if (ret < 0) { 1236 if (ret < 0) {
@@ -1245,6 +1248,7 @@ void do_delvm(Monitor *mon, const char *name) @@ -1245,6 +1248,7 @@ void do_delvm(Monitor *mon, const char *name)
1245 1248
1246 void do_info_snapshots(Monitor *mon) 1249 void do_info_snapshots(Monitor *mon)
1247 { 1250 {
  1251 + DriveInfo *dinfo;
1248 BlockDriverState *bs, *bs1; 1252 BlockDriverState *bs, *bs1;
1249 QEMUSnapshotInfo *sn_tab, *sn; 1253 QEMUSnapshotInfo *sn_tab, *sn;
1250 int nb_sns, i; 1254 int nb_sns, i;
@@ -1256,8 +1260,8 @@ void do_info_snapshots(Monitor *mon) @@ -1256,8 +1260,8 @@ void do_info_snapshots(Monitor *mon)
1256 return; 1260 return;
1257 } 1261 }
1258 monitor_printf(mon, "Snapshot devices:"); 1262 monitor_printf(mon, "Snapshot devices:");
1259 - for(i = 0; i <= nb_drives; i++) {  
1260 - bs1 = drives_table[i].bdrv; 1263 + TAILQ_FOREACH(dinfo, &drives, next) {
  1264 + bs1 = dinfo->bdrv;
1261 if (bdrv_has_snapshot(bs1)) { 1265 if (bdrv_has_snapshot(bs1)) {
1262 if (bs == bs1) 1266 if (bs == bs1)
1263 monitor_printf(mon, " %s", bdrv_get_device_name(bs1)); 1267 monitor_printf(mon, " %s", bdrv_get_device_name(bs1));
sysemu.h
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 /* Misc. things related to the system emulator. */ 3 /* Misc. things related to the system emulator. */
4 4
5 #include "qemu-common.h" 5 #include "qemu-common.h"
  6 +#include "sys-queue.h"
6 7
7 #ifdef _WIN32 8 #ifdef _WIN32
8 #include <windows.h> 9 #include <windows.h>
@@ -164,20 +165,19 @@ typedef struct DriveInfo { @@ -164,20 +165,19 @@ typedef struct DriveInfo {
164 BlockInterfaceType type; 165 BlockInterfaceType type;
165 int bus; 166 int bus;
166 int unit; 167 int unit;
167 - int used;  
168 int drive_opt_idx; 168 int drive_opt_idx;
169 BlockInterfaceErrorAction onerror; 169 BlockInterfaceErrorAction onerror;
170 char serial[BLOCK_SERIAL_STRLEN + 1]; 170 char serial[BLOCK_SERIAL_STRLEN + 1];
  171 + TAILQ_ENTRY(DriveInfo) next;
171 } DriveInfo; 172 } DriveInfo;
172 173
173 #define MAX_IDE_DEVS 2 174 #define MAX_IDE_DEVS 2
174 #define MAX_SCSI_DEVS 7 175 #define MAX_SCSI_DEVS 7
175 #define MAX_DRIVES 32 176 #define MAX_DRIVES 32
176 177
177 -extern int nb_drives;  
178 -extern DriveInfo drives_table[MAX_DRIVES+1]; 178 +extern TAILQ_HEAD(drivelist, DriveInfo) drives;
179 179
180 -extern int drive_get_index(BlockInterfaceType type, int bus, int unit); 180 +extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
181 extern int drive_get_max_bus(BlockInterfaceType type); 181 extern int drive_get_max_bus(BlockInterfaceType type);
182 extern void drive_uninit(BlockDriverState *bdrv); 182 extern void drive_uninit(BlockDriverState *bdrv);
183 extern void drive_remove(int index); 183 extern void drive_remove(int index);
@@ -196,7 +196,8 @@ extern struct drive_opt drives_opt[MAX_DRIVES]; @@ -196,7 +196,8 @@ extern struct drive_opt drives_opt[MAX_DRIVES];
196 extern int nb_drives_opt; 196 extern int nb_drives_opt;
197 197
198 extern int drive_add(const char *file, const char *fmt, ...); 198 extern int drive_add(const char *file, const char *fmt, ...);
199 -extern int drive_init(struct drive_opt *arg, int snapshot, void *machine); 199 +extern DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *machine,
  200 + int *fatal_error);
200 201
201 /* acpi */ 202 /* acpi */
202 typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state); 203 typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state);
@@ -207,7 +208,7 @@ void qemu_system_device_hot_add(int pcibus, int slot, int state); @@ -207,7 +208,7 @@ void qemu_system_device_hot_add(int pcibus, int slot, int state);
207 208
208 typedef int (dev_match_fn)(void *dev_private, void *arg); 209 typedef int (dev_match_fn)(void *dev_private, void *arg);
209 210
210 -int add_init_drive(const char *opts); 211 +DriveInfo *add_init_drive(const char *opts);
211 void destroy_nic(dev_match_fn *match_fn, void *arg); 212 void destroy_nic(dev_match_fn *match_fn, void *arg);
212 void destroy_bdrvs(dev_match_fn *match_fn, void *arg); 213 void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
213 214
@@ -180,8 +180,7 @@ static const char *data_dir; @@ -180,8 +180,7 @@ static const char *data_dir;
180 const char *bios_name = NULL; 180 const char *bios_name = NULL;
181 /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available 181 /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
182 to store the VM snapshots */ 182 to store the VM snapshots */
183 -DriveInfo drives_table[MAX_DRIVES+1];  
184 -int nb_drives; 183 +struct drivelist drives = TAILQ_HEAD_INITIALIZER(drives);
185 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; 184 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
186 static DisplayState *display_state; 185 static DisplayState *display_state;
187 DisplayType display_type = DT_DEFAULT; 186 DisplayType display_type = DT_DEFAULT;
@@ -1879,19 +1878,6 @@ static int drive_opt_get_free_idx(void) @@ -1879,19 +1878,6 @@ static int drive_opt_get_free_idx(void)
1879 return -1; 1878 return -1;
1880 } 1879 }
1881 1880
1882 -static int drive_get_free_idx(void)  
1883 -{  
1884 - int index;  
1885 -  
1886 - for (index = 0; index < MAX_DRIVES; index++)  
1887 - if (!drives_table[index].used) {  
1888 - drives_table[index].used = 1;  
1889 - return index;  
1890 - }  
1891 -  
1892 - return -1;  
1893 -}  
1894 -  
1895 int drive_add(const char *file, const char *fmt, ...) 1881 int drive_add(const char *file, const char *fmt, ...)
1896 { 1882 {
1897 va_list ap; 1883 va_list ap;
@@ -1918,54 +1904,56 @@ void drive_remove(int index) @@ -1918,54 +1904,56 @@ void drive_remove(int index)
1918 nb_drives_opt--; 1904 nb_drives_opt--;
1919 } 1905 }
1920 1906
1921 -int drive_get_index(BlockInterfaceType type, int bus, int unit) 1907 +DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
1922 { 1908 {
1923 - int index; 1909 + DriveInfo *dinfo;
1924 1910
1925 /* seek interface, bus and unit */ 1911 /* seek interface, bus and unit */
1926 1912
1927 - for (index = 0; index < MAX_DRIVES; index++)  
1928 - if (drives_table[index].type == type &&  
1929 - drives_table[index].bus == bus &&  
1930 - drives_table[index].unit == unit &&  
1931 - drives_table[index].used)  
1932 - return index; 1913 + TAILQ_FOREACH(dinfo, &drives, next) {
  1914 + if (dinfo->type == type &&
  1915 + dinfo->bus == bus &&
  1916 + dinfo->unit == unit)
  1917 + return dinfo;
  1918 + }
1933 1919
1934 - return -1; 1920 + return NULL;
1935 } 1921 }
1936 1922
1937 int drive_get_max_bus(BlockInterfaceType type) 1923 int drive_get_max_bus(BlockInterfaceType type)
1938 { 1924 {
1939 int max_bus; 1925 int max_bus;
1940 - int index; 1926 + DriveInfo *dinfo;
1941 1927
1942 max_bus = -1; 1928 max_bus = -1;
1943 - for (index = 0; index < nb_drives; index++) {  
1944 - if(drives_table[index].type == type &&  
1945 - drives_table[index].bus > max_bus)  
1946 - max_bus = drives_table[index].bus; 1929 + TAILQ_FOREACH(dinfo, &drives, next) {
  1930 + if(dinfo->type == type &&
  1931 + dinfo->bus > max_bus)
  1932 + max_bus = dinfo->bus;
1947 } 1933 }
1948 return max_bus; 1934 return max_bus;
1949 } 1935 }
1950 1936
1951 const char *drive_get_serial(BlockDriverState *bdrv) 1937 const char *drive_get_serial(BlockDriverState *bdrv)
1952 { 1938 {
1953 - int index; 1939 + DriveInfo *dinfo;
1954 1940
1955 - for (index = 0; index < nb_drives; index++)  
1956 - if (drives_table[index].bdrv == bdrv)  
1957 - return drives_table[index].serial; 1941 + TAILQ_FOREACH(dinfo, &drives, next) {
  1942 + if (dinfo->bdrv == bdrv)
  1943 + return dinfo->serial;
  1944 + }
1958 1945
1959 return "\0"; 1946 return "\0";
1960 } 1947 }
1961 1948
1962 BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv) 1949 BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv)
1963 { 1950 {
1964 - int index; 1951 + DriveInfo *dinfo;
1965 1952
1966 - for (index = 0; index < nb_drives; index++)  
1967 - if (drives_table[index].bdrv == bdrv)  
1968 - return drives_table[index].onerror; 1953 + TAILQ_FOREACH(dinfo, &drives, next) {
  1954 + if (dinfo->bdrv == bdrv)
  1955 + return dinfo->onerror;
  1956 + }
1969 1957
1970 return BLOCK_ERR_STOP_ENOSPC; 1958 return BLOCK_ERR_STOP_ENOSPC;
1971 } 1959 }
@@ -1977,19 +1965,20 @@ static void bdrv_format_print(void *opaque, const char *name) @@ -1977,19 +1965,20 @@ static void bdrv_format_print(void *opaque, const char *name)
1977 1965
1978 void drive_uninit(BlockDriverState *bdrv) 1966 void drive_uninit(BlockDriverState *bdrv)
1979 { 1967 {
1980 - int i; 1968 + DriveInfo *dinfo;
1981 1969
1982 - for (i = 0; i < MAX_DRIVES; i++)  
1983 - if (drives_table[i].bdrv == bdrv) {  
1984 - drives_table[i].bdrv = NULL;  
1985 - drives_table[i].used = 0;  
1986 - drive_remove(drives_table[i].drive_opt_idx);  
1987 - nb_drives--;  
1988 - break;  
1989 - } 1970 + TAILQ_FOREACH(dinfo, &drives, next) {
  1971 + if (dinfo->bdrv != bdrv)
  1972 + continue;
  1973 + drive_remove(dinfo->drive_opt_idx);
  1974 + TAILQ_REMOVE(&drives, dinfo, next);
  1975 + qemu_free(dinfo);
  1976 + break;
  1977 + }
1990 } 1978 }
1991 1979
1992 -int drive_init(struct drive_opt *arg, int snapshot, void *opaque) 1980 +DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
  1981 + int *fatal_error)
1993 { 1982 {
1994 char buf[128]; 1983 char buf[128];
1995 char file[1024]; 1984 char file[1024];
@@ -2008,7 +1997,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2008,7 +1997,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2008 int cache; 1997 int cache;
2009 int bdrv_flags, onerror; 1998 int bdrv_flags, onerror;
2010 const char *devaddr; 1999 const char *devaddr;
2011 - int drives_table_idx; 2000 + DriveInfo *dinfo;
2012 char *str = arg->opt; 2001 char *str = arg->opt;
2013 static const char * const params[] = { "bus", "unit", "if", "index", 2002 static const char * const params[] = { "bus", "unit", "if", "index",
2014 "cyls", "heads", "secs", "trans", 2003 "cyls", "heads", "secs", "trans",
@@ -2016,11 +2005,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2016,11 +2005,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2016 "cache", "format", "serial", 2005 "cache", "format", "serial",
2017 "werror", "addr", 2006 "werror", "addr",
2018 NULL }; 2007 NULL };
  2008 + *fatal_error = 1;
2019 2009
2020 if (check_params(buf, sizeof(buf), params, str) < 0) { 2010 if (check_params(buf, sizeof(buf), params, str) < 0) {
2021 fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n", 2011 fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n",
2022 buf, str); 2012 buf, str);
2023 - return -1; 2013 + return NULL;
2024 } 2014 }
2025 2015
2026 file[0] = 0; 2016 file[0] = 0;
@@ -2048,7 +2038,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2048,7 +2038,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2048 bus_id = strtol(buf, NULL, 0); 2038 bus_id = strtol(buf, NULL, 0);
2049 if (bus_id < 0) { 2039 if (bus_id < 0) {
2050 fprintf(stderr, "qemu: '%s' invalid bus id\n", str); 2040 fprintf(stderr, "qemu: '%s' invalid bus id\n", str);
2051 - return -1; 2041 + return NULL;
2052 } 2042 }
2053 } 2043 }
2054 2044
@@ -2056,7 +2046,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2056,7 +2046,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2056 unit_id = strtol(buf, NULL, 0); 2046 unit_id = strtol(buf, NULL, 0);
2057 if (unit_id < 0) { 2047 if (unit_id < 0) {
2058 fprintf(stderr, "qemu: '%s' invalid unit id\n", str); 2048 fprintf(stderr, "qemu: '%s' invalid unit id\n", str);
2059 - return -1; 2049 + return NULL;
2060 } 2050 }
2061 } 2051 }
2062 2052
@@ -2088,7 +2078,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2088,7 +2078,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2088 max_devs = 0; 2078 max_devs = 0;
2089 } else { 2079 } else {
2090 fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf); 2080 fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf);
2091 - return -1; 2081 + return NULL;
2092 } 2082 }
2093 } 2083 }
2094 2084
@@ -2096,7 +2086,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2096,7 +2086,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2096 index = strtol(buf, NULL, 0); 2086 index = strtol(buf, NULL, 0);
2097 if (index < 0) { 2087 if (index < 0) {
2098 fprintf(stderr, "qemu: '%s' invalid index\n", str); 2088 fprintf(stderr, "qemu: '%s' invalid index\n", str);
2099 - return -1; 2089 + return NULL;
2100 } 2090 }
2101 } 2091 }
2102 2092
@@ -2115,15 +2105,15 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2115,15 +2105,15 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2115 if (cyls || heads || secs) { 2105 if (cyls || heads || secs) {
2116 if (cyls < 1 || cyls > 16383) { 2106 if (cyls < 1 || cyls > 16383) {
2117 fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str); 2107 fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str);
2118 - return -1; 2108 + return NULL;
2119 } 2109 }
2120 if (heads < 1 || heads > 16) { 2110 if (heads < 1 || heads > 16) {
2121 fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str); 2111 fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str);
2122 - return -1; 2112 + return NULL;
2123 } 2113 }
2124 if (secs < 1 || secs > 63) { 2114 if (secs < 1 || secs > 63) {
2125 fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str); 2115 fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str);
2126 - return -1; 2116 + return NULL;
2127 } 2117 }
2128 } 2118 }
2129 2119
@@ -2132,7 +2122,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2132,7 +2122,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2132 fprintf(stderr, 2122 fprintf(stderr,
2133 "qemu: '%s' trans must be used with cyls,heads and secs\n", 2123 "qemu: '%s' trans must be used with cyls,heads and secs\n",
2134 str); 2124 str);
2135 - return -1; 2125 + return NULL;
2136 } 2126 }
2137 if (!strcmp(buf, "none")) 2127 if (!strcmp(buf, "none"))
2138 translation = BIOS_ATA_TRANSLATION_NONE; 2128 translation = BIOS_ATA_TRANSLATION_NONE;
@@ -2142,7 +2132,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2142,7 +2132,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2142 translation = BIOS_ATA_TRANSLATION_AUTO; 2132 translation = BIOS_ATA_TRANSLATION_AUTO;
2143 else { 2133 else {
2144 fprintf(stderr, "qemu: '%s' invalid translation type\n", str); 2134 fprintf(stderr, "qemu: '%s' invalid translation type\n", str);
2145 - return -1; 2135 + return NULL;
2146 } 2136 }
2147 } 2137 }
2148 2138
@@ -2153,12 +2143,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2153,12 +2143,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2153 if (cyls || secs || heads) { 2143 if (cyls || secs || heads) {
2154 fprintf(stderr, 2144 fprintf(stderr,
2155 "qemu: '%s' invalid physical CHS format\n", str); 2145 "qemu: '%s' invalid physical CHS format\n", str);
2156 - return -1; 2146 + return NULL;
2157 } 2147 }
2158 media = MEDIA_CDROM; 2148 media = MEDIA_CDROM;
2159 } else { 2149 } else {
2160 fprintf(stderr, "qemu: '%s' invalid media\n", str); 2150 fprintf(stderr, "qemu: '%s' invalid media\n", str);
2161 - return -1; 2151 + return NULL;
2162 } 2152 }
2163 } 2153 }
2164 2154
@@ -2169,7 +2159,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2169,7 +2159,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2169 snapshot = 0; 2159 snapshot = 0;
2170 else { 2160 else {
2171 fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str); 2161 fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str);
2172 - return -1; 2162 + return NULL;
2173 } 2163 }
2174 } 2164 }
2175 2165
@@ -2182,7 +2172,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2182,7 +2172,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2182 cache = 2; 2172 cache = 2;
2183 else { 2173 else {
2184 fprintf(stderr, "qemu: invalid cache option\n"); 2174 fprintf(stderr, "qemu: invalid cache option\n");
2185 - return -1; 2175 + return NULL;
2186 } 2176 }
2187 } 2177 }
2188 2178
@@ -2191,12 +2181,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2191,12 +2181,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2191 fprintf(stderr, "qemu: Supported formats:"); 2181 fprintf(stderr, "qemu: Supported formats:");
2192 bdrv_iterate_format(bdrv_format_print, NULL); 2182 bdrv_iterate_format(bdrv_format_print, NULL);
2193 fprintf(stderr, "\n"); 2183 fprintf(stderr, "\n");
2194 - return -1; 2184 + return NULL;
2195 } 2185 }
2196 drv = bdrv_find_format(buf); 2186 drv = bdrv_find_format(buf);
2197 if (!drv) { 2187 if (!drv) {
2198 fprintf(stderr, "qemu: '%s' invalid format\n", buf); 2188 fprintf(stderr, "qemu: '%s' invalid format\n", buf);
2199 - return -1; 2189 + return NULL;
2200 } 2190 }
2201 } 2191 }
2202 2192
@@ -2212,7 +2202,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2212,7 +2202,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2212 if (get_param_value(buf, sizeof(serial), "werror", str)) { 2202 if (get_param_value(buf, sizeof(serial), "werror", str)) {
2213 if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { 2203 if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) {
2214 fprintf(stderr, "werror is no supported by this format\n"); 2204 fprintf(stderr, "werror is no supported by this format\n");
2215 - return -1; 2205 + return NULL;
2216 } 2206 }
2217 if (!strcmp(buf, "ignore")) 2207 if (!strcmp(buf, "ignore"))
2218 onerror = BLOCK_ERR_IGNORE; 2208 onerror = BLOCK_ERR_IGNORE;
@@ -2224,7 +2214,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2224,7 +2214,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2224 onerror = BLOCK_ERR_REPORT; 2214 onerror = BLOCK_ERR_REPORT;
2225 else { 2215 else {
2226 fprintf(stderr, "qemu: '%s' invalid write error action\n", buf); 2216 fprintf(stderr, "qemu: '%s' invalid write error action\n", buf);
2227 - return -1; 2217 + return NULL;
2228 } 2218 }
2229 } 2219 }
2230 2220
@@ -2232,7 +2222,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2232,7 +2222,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2232 if (get_param_value(buf, sizeof(buf), "addr", str)) { 2222 if (get_param_value(buf, sizeof(buf), "addr", str)) {
2233 if (type != IF_VIRTIO) { 2223 if (type != IF_VIRTIO) {
2234 fprintf(stderr, "addr is not supported by in '%s'\n", str); 2224 fprintf(stderr, "addr is not supported by in '%s'\n", str);
2235 - return -1; 2225 + return NULL;
2236 } 2226 }
2237 devaddr = strdup(buf); 2227 devaddr = strdup(buf);
2238 } 2228 }
@@ -2243,7 +2233,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2243,7 +2233,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2243 if (bus_id != 0 || unit_id != -1) { 2233 if (bus_id != 0 || unit_id != -1) {
2244 fprintf(stderr, 2234 fprintf(stderr,
2245 "qemu: '%s' index cannot be used with bus and unit\n", str); 2235 "qemu: '%s' index cannot be used with bus and unit\n", str);
2246 - return -1; 2236 + return NULL;
2247 } 2237 }
2248 if (max_devs == 0) 2238 if (max_devs == 0)
2249 { 2239 {
@@ -2261,7 +2251,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2261,7 +2251,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2261 2251
2262 if (unit_id == -1) { 2252 if (unit_id == -1) {
2263 unit_id = 0; 2253 unit_id = 0;
2264 - while (drive_get_index(type, bus_id, unit_id) != -1) { 2254 + while (drive_get(type, bus_id, unit_id) != NULL) {
2265 unit_id++; 2255 unit_id++;
2266 if (max_devs && unit_id >= max_devs) { 2256 if (max_devs && unit_id >= max_devs) {
2267 unit_id -= max_devs; 2257 unit_id -= max_devs;
@@ -2275,15 +2265,17 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2275,15 +2265,17 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2275 if (max_devs && unit_id >= max_devs) { 2265 if (max_devs && unit_id >= max_devs) {
2276 fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n", 2266 fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n",
2277 str, unit_id, max_devs - 1); 2267 str, unit_id, max_devs - 1);
2278 - return -1; 2268 + return NULL;
2279 } 2269 }
2280 2270
2281 /* 2271 /*
2282 * ignore multiple definitions 2272 * ignore multiple definitions
2283 */ 2273 */
2284 2274
2285 - if (drive_get_index(type, bus_id, unit_id) != -1)  
2286 - return -2; 2275 + if (drive_get(type, bus_id, unit_id) != NULL) {
  2276 + *fatal_error = 0;
  2277 + return NULL;
  2278 + }
2287 2279
2288 /* init */ 2280 /* init */
2289 2281
@@ -2296,16 +2288,16 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2296,16 +2288,16 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2296 snprintf(buf, sizeof(buf), "%s%s%i", 2288 snprintf(buf, sizeof(buf), "%s%s%i",
2297 devname, mediastr, unit_id); 2289 devname, mediastr, unit_id);
2298 bdrv = bdrv_new(buf); 2290 bdrv = bdrv_new(buf);
2299 - drives_table_idx = drive_get_free_idx();  
2300 - drives_table[drives_table_idx].bdrv = bdrv;  
2301 - drives_table[drives_table_idx].devaddr = devaddr;  
2302 - drives_table[drives_table_idx].type = type;  
2303 - drives_table[drives_table_idx].bus = bus_id;  
2304 - drives_table[drives_table_idx].unit = unit_id;  
2305 - drives_table[drives_table_idx].onerror = onerror;  
2306 - drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt;  
2307 - strncpy(drives_table[drives_table_idx].serial, serial, sizeof(serial));  
2308 - nb_drives++; 2291 + dinfo = qemu_mallocz(sizeof(*dinfo));
  2292 + dinfo->bdrv = bdrv;
  2293 + dinfo->devaddr = devaddr;
  2294 + dinfo->type = type;
  2295 + dinfo->bus = bus_id;
  2296 + dinfo->unit = unit_id;
  2297 + dinfo->onerror = onerror;
  2298 + dinfo->drive_opt_idx = arg - drives_opt;
  2299 + strncpy(dinfo->serial, serial, sizeof(serial));
  2300 + TAILQ_INSERT_TAIL(&drives, dinfo, next);
2309 2301
2310 switch(type) { 2302 switch(type) {
2311 case IF_IDE: 2303 case IF_IDE:
@@ -2336,8 +2328,10 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2336,8 +2328,10 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2336 case IF_COUNT: 2328 case IF_COUNT:
2337 abort(); 2329 abort();
2338 } 2330 }
2339 - if (!file[0])  
2340 - return -2; 2331 + if (!file[0]) {
  2332 + *fatal_error = 0;
  2333 + return NULL;
  2334 + }
2341 bdrv_flags = 0; 2335 bdrv_flags = 0;
2342 if (snapshot) { 2336 if (snapshot) {
2343 bdrv_flags |= BDRV_O_SNAPSHOT; 2337 bdrv_flags |= BDRV_O_SNAPSHOT;
@@ -2350,11 +2344,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2350,11 +2344,12 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2350 if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) { 2344 if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
2351 fprintf(stderr, "qemu: could not open disk image %s\n", 2345 fprintf(stderr, "qemu: could not open disk image %s\n",
2352 file); 2346 file);
2353 - return -1; 2347 + return NULL;
2354 } 2348 }
2355 if (bdrv_key_required(bdrv)) 2349 if (bdrv_key_required(bdrv))
2356 autostart = 0; 2350 autostart = 0;
2357 - return drives_table_idx; 2351 + *fatal_error = 0;
  2352 + return dinfo;
2358 } 2353 }
2359 2354
2360 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) 2355 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
@@ -4981,7 +4976,6 @@ int main(int argc, char **argv, char **envp) @@ -4981,7 +4976,6 @@ int main(int argc, char **argv, char **envp)
4981 } 4976 }
4982 4977
4983 nb_net_clients = 0; 4978 nb_net_clients = 0;
4984 - nb_drives = 0;  
4985 nb_drives_opt = 0; 4979 nb_drives_opt = 0;
4986 nb_numa_nodes = 0; 4980 nb_numa_nodes = 0;
4987 hda_index = -1; 4981 hda_index = -1;
@@ -5854,9 +5848,12 @@ int main(int argc, char **argv, char **envp) @@ -5854,9 +5848,12 @@ int main(int argc, char **argv, char **envp)
5854 5848
5855 /* open the virtual block devices */ 5849 /* open the virtual block devices */
5856 5850
5857 - for(i = 0; i < nb_drives_opt; i++)  
5858 - if (drive_init(&drives_opt[i], snapshot, machine) == -1)  
5859 - exit(1); 5851 + for(i = 0; i < nb_drives_opt; i++) {
  5852 + int fatal_error;
  5853 + if (drive_init(&drives_opt[i], snapshot, machine, &fatal_error) == NULL)
  5854 + if (fatal_error)
  5855 + exit(1);
  5856 + }
5860 5857
5861 register_savevm("timer", 0, 2, timer_save, timer_load, NULL); 5858 register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
5862 register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL); 5859 register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);