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>
diff --git a/savevm.c b/savevm.c
index 181c088..0c0b49f 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1011,12 +1011,12 @@
 static BlockDriverState *get_bs_snapshots(void)
 {
     BlockDriverState *bs;
-    int i;
+    DriveInfo *dinfo;
 
     if (bs_snapshots)
         return bs_snapshots;
-    for(i = 0; i <= nb_drives; i++) {
-        bs = drives_table[i].bdrv;
+    TAILQ_FOREACH(dinfo, &drives, next) {
+        bs = dinfo->bdrv;
         if (bdrv_can_snapshot(bs))
             goto ok;
     }
@@ -1050,9 +1050,10 @@
 
 void do_savevm(Monitor *mon, const char *name)
 {
+    DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
     QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
-    int must_delete, ret, i;
+    int must_delete, ret;
     QEMUFile *f;
     int saved_vm_running;
     uint32_t vm_state_size;
@@ -1118,8 +1119,8 @@
 
     /* create the snapshots */
 
-    for(i = 0; i < nb_drives; i++) {
-        bs1 = drives_table[i].bdrv;
+    TAILQ_FOREACH(dinfo, &drives, next) {
+        bs1 = dinfo->bdrv;
         if (bdrv_has_snapshot(bs1)) {
             if (must_delete) {
                 ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
@@ -1146,10 +1147,11 @@
 
 void do_loadvm(Monitor *mon, const char *name)
 {
+    DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
     QEMUSnapshotInfo sn;
     QEMUFile *f;
-    int i, ret;
+    int ret;
     int saved_vm_running;
 
     bs = get_bs_snapshots();
@@ -1164,8 +1166,8 @@
     saved_vm_running = vm_running;
     vm_stop(0);
 
-    for(i = 0; i <= nb_drives; i++) {
-        bs1 = drives_table[i].bdrv;
+    TAILQ_FOREACH(dinfo, &drives, next) {
+        bs1 = dinfo->bdrv;
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_goto(bs1, name);
             if (ret < 0) {
@@ -1217,8 +1219,9 @@
 
 void do_delvm(Monitor *mon, const char *name)
 {
+    DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
-    int i, ret;
+    int ret;
 
     bs = get_bs_snapshots();
     if (!bs) {
@@ -1226,8 +1229,8 @@
         return;
     }
 
-    for(i = 0; i <= nb_drives; i++) {
-        bs1 = drives_table[i].bdrv;
+    TAILQ_FOREACH(dinfo, &drives, next) {
+        bs1 = dinfo->bdrv;
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_delete(bs1, name);
             if (ret < 0) {
@@ -1245,6 +1248,7 @@
 
 void do_info_snapshots(Monitor *mon)
 {
+    DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
     QEMUSnapshotInfo *sn_tab, *sn;
     int nb_sns, i;
@@ -1256,8 +1260,8 @@
         return;
     }
     monitor_printf(mon, "Snapshot devices:");
-    for(i = 0; i <= nb_drives; i++) {
-        bs1 = drives_table[i].bdrv;
+    TAILQ_FOREACH(dinfo, &drives, next) {
+        bs1 = dinfo->bdrv;
         if (bdrv_has_snapshot(bs1)) {
             if (bs == bs1)
                 monitor_printf(mon, " %s", bdrv_get_device_name(bs1));