Commit c2cc47a449c3e16f7dd4d19a536c649ec56a9ac9

Authored by Markus Armbruster
Committed by Anthony Liguori
1 parent 1f5f6638

Support addr=... in option argument of -drive if=virtio

Make drive_init() accept addr=, put the value into struct DriveInfo.
Use it in all the places that create virtio-blk-pci devices:
pc_init1(), bamboo_init(), mpc8544ds_init().

Don't support addr= in third argument of monitor command pci_add and
second argument of drive_add, because that clashes with their first
arguments.  Admittedly unelegant.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
@@ -848,6 +848,7 @@ static void pc_init1(ram_addr_t ram_size, @@ -848,6 +848,7 @@ static void pc_init1(ram_addr_t ram_size,
848 ram_addr_t below_4g_mem_size, above_4g_mem_size = 0; 848 ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
849 int bios_size, isa_bios_size, oprom_area_size; 849 int bios_size, isa_bios_size, oprom_area_size;
850 PCIBus *pci_bus; 850 PCIBus *pci_bus;
  851 + PCIDevice *pci_dev;
851 int piix3_devfn = -1; 852 int piix3_devfn = -1;
852 CPUState *env; 853 CPUState *env;
853 qemu_irq *cpu_irq; 854 qemu_irq *cpu_irq;
@@ -1161,7 +1162,9 @@ static void pc_init1(ram_addr_t ram_size, @@ -1161,7 +1162,9 @@ static void pc_init1(ram_addr_t ram_size,
1161 int unit_id = 0; 1162 int unit_id = 0;
1162 1163
1163 while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { 1164 while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
1164 - pci_create_simple(pci_bus, -1, "virtio-blk-pci"); 1165 + pci_dev = pci_create("virtio-blk-pci",
  1166 + drives_table[index].devaddr);
  1167 + qdev_init(&pci_dev->qdev);
1165 unit_id++; 1168 unit_id++;
1166 } 1169 }
1167 } 1170 }
hw/pci-hotplug.c
@@ -70,6 +70,10 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts) @@ -70,6 +70,10 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
70 drive_idx = add_init_drive(opts); 70 drive_idx = add_init_drive(opts);
71 if (drive_idx < 0) 71 if (drive_idx < 0)
72 return; 72 return;
  73 + if (drives_table[drive_idx].devaddr) {
  74 + monitor_printf(mon, "Parameter addr not supported\n");
  75 + return;
  76 + }
73 type = drives_table[drive_idx].type; 77 type = drives_table[drive_idx].type;
74 bus = drive_get_max_bus (type); 78 bus = drive_get_max_bus (type);
75 79
@@ -116,6 +120,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, @@ -116,6 +120,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
116 drive_idx = add_init_drive(opts); 120 drive_idx = add_init_drive(opts);
117 if (drive_idx < 0) 121 if (drive_idx < 0)
118 return NULL; 122 return NULL;
  123 + if (drives_table[drive_idx].devaddr) {
  124 + monitor_printf(mon, "Parameter addr not supported\n");
  125 + return NULL;
  126 + }
119 } else if (type == IF_VIRTIO) { 127 } else if (type == IF_VIRTIO) {
120 monitor_printf(mon, "virtio requires a backing file/device.\n"); 128 monitor_printf(mon, "virtio requires a backing file/device.\n");
121 return NULL; 129 return NULL;
hw/ppc440_bamboo.c
@@ -90,6 +90,7 @@ static void bamboo_init(ram_addr_t ram_size, @@ -90,6 +90,7 @@ static void bamboo_init(ram_addr_t ram_size,
90 { 90 {
91 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 }; 91 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
92 PCIBus *pcibus; 92 PCIBus *pcibus;
  93 + PCIDevice *pci_dev;
93 CPUState *env; 94 CPUState *env;
94 uint64_t elf_entry; 95 uint64_t elf_entry;
95 uint64_t elf_lowaddr; 96 uint64_t elf_lowaddr;
@@ -110,7 +111,8 @@ static void bamboo_init(ram_addr_t ram_size, @@ -110,7 +111,8 @@ static void bamboo_init(ram_addr_t ram_size,
110 111
111 /* Add virtio block devices. */ 112 /* Add virtio block devices. */
112 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { 113 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
113 - pci_create_simple(pcibus, -1, "virtio-blk-pci"); 114 + pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
  115 + qdev_init(&pci_dev->qdev);
114 unit_id++; 116 unit_id++;
115 } 117 }
116 118
hw/ppce500_mpc8544ds.c
@@ -157,6 +157,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, @@ -157,6 +157,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
157 const char *cpu_model) 157 const char *cpu_model)
158 { 158 {
159 PCIBus *pci_bus; 159 PCIBus *pci_bus;
  160 + PCIDevice *pci_dev;
160 CPUState *env; 161 CPUState *env;
161 uint64_t elf_entry; 162 uint64_t elf_entry;
162 uint64_t elf_lowaddr; 163 uint64_t elf_lowaddr;
@@ -219,7 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size, @@ -219,7 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size,
219 220
220 /* Add virtio block devices. */ 221 /* Add virtio block devices. */
221 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { 222 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
222 - pci_create_simple(pci_bus, -1, "virtio-blk-pci"); 223 + pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
  224 + qdev_init(&pci_dev->qdev);
223 unit_id++; 225 unit_id++;
224 } 226 }
225 227
qemu-options.hx
@@ -92,6 +92,7 @@ DEF(&quot;drive&quot;, HAS_ARG, QEMU_OPTION_drive, @@ -92,6 +92,7 @@ DEF(&quot;drive&quot;, HAS_ARG, QEMU_OPTION_drive,
92 "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" 92 "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
93 " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" 93 " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
94 " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n" 94 " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n"
  95 + " [,addr=A]\n"
95 " use 'file' as a drive image\n") 96 " use 'file' as a drive image\n")
96 STEXI 97 STEXI
97 @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] 98 @item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
@@ -126,6 +127,8 @@ the format. Can be used to specifiy format=raw to avoid interpreting @@ -126,6 +127,8 @@ the format. Can be used to specifiy format=raw to avoid interpreting
126 an untrusted format header. 127 an untrusted format header.
127 @item serial=@var{serial} 128 @item serial=@var{serial}
128 This option specifies the serial number to assign to the device. 129 This option specifies the serial number to assign to the device.
  130 +@item addr=@var{addr}
  131 +Specify the controller's PCI address (if=virtio only).
129 @end table 132 @end table
130 133
131 By default, writethrough caching is used for all block device. This means that 134 By default, writethrough caching is used for all block device. This means that
sysemu.h
@@ -156,6 +156,7 @@ typedef enum { @@ -156,6 +156,7 @@ typedef enum {
156 156
157 typedef struct DriveInfo { 157 typedef struct DriveInfo {
158 BlockDriverState *bdrv; 158 BlockDriverState *bdrv;
  159 + const char *devaddr;
159 BlockInterfaceType type; 160 BlockInterfaceType type;
160 int bus; 161 int bus;
161 int unit; 162 int unit;
@@ -2209,12 +2209,14 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2209,12 +2209,14 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2209 int index; 2209 int index;
2210 int cache; 2210 int cache;
2211 int bdrv_flags, onerror; 2211 int bdrv_flags, onerror;
  2212 + const char *devaddr;
2212 int drives_table_idx; 2213 int drives_table_idx;
2213 char *str = arg->opt; 2214 char *str = arg->opt;
2214 static const char * const params[] = { "bus", "unit", "if", "index", 2215 static const char * const params[] = { "bus", "unit", "if", "index",
2215 "cyls", "heads", "secs", "trans", 2216 "cyls", "heads", "secs", "trans",
2216 "media", "snapshot", "file", 2217 "media", "snapshot", "file",
2217 - "cache", "format", "serial", "werror", 2218 + "cache", "format", "serial",
  2219 + "werror", "addr",
2218 NULL }; 2220 NULL };
2219 2221
2220 if (check_params(buf, sizeof(buf), params, str) < 0) { 2222 if (check_params(buf, sizeof(buf), params, str) < 0) {
@@ -2428,6 +2430,15 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2428,6 +2430,15 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2428 } 2430 }
2429 } 2431 }
2430 2432
  2433 + devaddr = NULL;
  2434 + if (get_param_value(buf, sizeof(buf), "addr", str)) {
  2435 + if (type != IF_VIRTIO) {
  2436 + fprintf(stderr, "addr is not supported by in '%s'\n", str);
  2437 + return -1;
  2438 + }
  2439 + devaddr = strdup(buf);
  2440 + }
  2441 +
2431 /* compute bus and unit according index */ 2442 /* compute bus and unit according index */
2432 2443
2433 if (index != -1) { 2444 if (index != -1) {
@@ -2489,6 +2500,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2489,6 +2500,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2489 bdrv = bdrv_new(buf); 2500 bdrv = bdrv_new(buf);
2490 drives_table_idx = drive_get_free_idx(); 2501 drives_table_idx = drive_get_free_idx();
2491 drives_table[drives_table_idx].bdrv = bdrv; 2502 drives_table[drives_table_idx].bdrv = bdrv;
  2503 + drives_table[drives_table_idx].devaddr = devaddr;
2492 drives_table[drives_table_idx].type = type; 2504 drives_table[drives_table_idx].type = type;
2493 drives_table[drives_table_idx].bus = bus_id; 2505 drives_table[drives_table_idx].bus = bus_id;
2494 drives_table[drives_table_idx].unit = unit_id; 2506 drives_table[drives_table_idx].unit = unit_id;