Commit c2cc47a449c3e16f7dd4d19a536c649ec56a9ac9
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>
Showing
7 changed files
with
35 additions
and
4 deletions
hw/pc.c
... | ... | @@ -848,6 +848,7 @@ static void pc_init1(ram_addr_t ram_size, |
848 | 848 | ram_addr_t below_4g_mem_size, above_4g_mem_size = 0; |
849 | 849 | int bios_size, isa_bios_size, oprom_area_size; |
850 | 850 | PCIBus *pci_bus; |
851 | + PCIDevice *pci_dev; | |
851 | 852 | int piix3_devfn = -1; |
852 | 853 | CPUState *env; |
853 | 854 | qemu_irq *cpu_irq; |
... | ... | @@ -1161,7 +1162,9 @@ static void pc_init1(ram_addr_t ram_size, |
1161 | 1162 | int unit_id = 0; |
1162 | 1163 | |
1163 | 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 | 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 | 70 | drive_idx = add_init_drive(opts); |
71 | 71 | if (drive_idx < 0) |
72 | 72 | return; |
73 | + if (drives_table[drive_idx].devaddr) { | |
74 | + monitor_printf(mon, "Parameter addr not supported\n"); | |
75 | + return; | |
76 | + } | |
73 | 77 | type = drives_table[drive_idx].type; |
74 | 78 | bus = drive_get_max_bus (type); |
75 | 79 | |
... | ... | @@ -116,6 +120,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, |
116 | 120 | drive_idx = add_init_drive(opts); |
117 | 121 | if (drive_idx < 0) |
118 | 122 | return NULL; |
123 | + if (drives_table[drive_idx].devaddr) { | |
124 | + monitor_printf(mon, "Parameter addr not supported\n"); | |
125 | + return NULL; | |
126 | + } | |
119 | 127 | } else if (type == IF_VIRTIO) { |
120 | 128 | monitor_printf(mon, "virtio requires a backing file/device.\n"); |
121 | 129 | return NULL; | ... | ... |
hw/ppc440_bamboo.c
... | ... | @@ -90,6 +90,7 @@ static void bamboo_init(ram_addr_t ram_size, |
90 | 90 | { |
91 | 91 | unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 }; |
92 | 92 | PCIBus *pcibus; |
93 | + PCIDevice *pci_dev; | |
93 | 94 | CPUState *env; |
94 | 95 | uint64_t elf_entry; |
95 | 96 | uint64_t elf_lowaddr; |
... | ... | @@ -110,7 +111,8 @@ static void bamboo_init(ram_addr_t ram_size, |
110 | 111 | |
111 | 112 | /* Add virtio block devices. */ |
112 | 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 | 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 | 157 | const char *cpu_model) |
158 | 158 | { |
159 | 159 | PCIBus *pci_bus; |
160 | + PCIDevice *pci_dev; | |
160 | 161 | CPUState *env; |
161 | 162 | uint64_t elf_entry; |
162 | 163 | uint64_t elf_lowaddr; |
... | ... | @@ -219,7 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size, |
219 | 220 | |
220 | 221 | /* Add virtio block devices. */ |
221 | 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 | 225 | unit_id++; |
224 | 226 | } |
225 | 227 | ... | ... |
qemu-options.hx
... | ... | @@ -92,6 +92,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, |
92 | 92 | "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" |
93 | 93 | " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" |
94 | 94 | " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n" |
95 | + " [,addr=A]\n" | |
95 | 96 | " use 'file' as a drive image\n") |
96 | 97 | STEXI |
97 | 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 | 127 | an untrusted format header. |
127 | 128 | @item serial=@var{serial} |
128 | 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 | 132 | @end table |
130 | 133 | |
131 | 134 | By default, writethrough caching is used for all block device. This means that | ... | ... |
sysemu.h
vl.c
... | ... | @@ -2209,12 +2209,14 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) |
2209 | 2209 | int index; |
2210 | 2210 | int cache; |
2211 | 2211 | int bdrv_flags, onerror; |
2212 | + const char *devaddr; | |
2212 | 2213 | int drives_table_idx; |
2213 | 2214 | char *str = arg->opt; |
2214 | 2215 | static const char * const params[] = { "bus", "unit", "if", "index", |
2215 | 2216 | "cyls", "heads", "secs", "trans", |
2216 | 2217 | "media", "snapshot", "file", |
2217 | - "cache", "format", "serial", "werror", | |
2218 | + "cache", "format", "serial", | |
2219 | + "werror", "addr", | |
2218 | 2220 | NULL }; |
2219 | 2221 | |
2220 | 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 | 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 | 2442 | /* compute bus and unit according index */ |
2432 | 2443 | |
2433 | 2444 | if (index != -1) { |
... | ... | @@ -2489,6 +2500,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) |
2489 | 2500 | bdrv = bdrv_new(buf); |
2490 | 2501 | drives_table_idx = drive_get_free_idx(); |
2491 | 2502 | drives_table[drives_table_idx].bdrv = bdrv; |
2503 | + drives_table[drives_table_idx].devaddr = devaddr; | |
2492 | 2504 | drives_table[drives_table_idx].type = type; |
2493 | 2505 | drives_table[drives_table_idx].bus = bus_id; |
2494 | 2506 | drives_table[drives_table_idx].unit = unit_id; | ... | ... |