blockdev: Move virtio-blk device creation to drive_init
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
		
							parent
							
								
									87a899c509
								
							
						
					
					
						commit
						394c7d4d6b
					
				
							
								
								
									
										54
									
								
								blockdev.c
								
								
								
								
							
							
						
						
									
										54
									
								
								blockdev.c
								
								
								
								
							| 
						 | 
					@ -318,7 +318,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
 | 
				
			||||||
    int ro = 0;
 | 
					    int ro = 0;
 | 
				
			||||||
    int bdrv_flags = 0;
 | 
					    int bdrv_flags = 0;
 | 
				
			||||||
    int on_read_error, on_write_error;
 | 
					    int on_read_error, on_write_error;
 | 
				
			||||||
    const char *devaddr;
 | 
					 | 
				
			||||||
    DriveInfo *dinfo;
 | 
					    DriveInfo *dinfo;
 | 
				
			||||||
    ThrottleConfig cfg;
 | 
					    ThrottleConfig cfg;
 | 
				
			||||||
    int snapshot = 0;
 | 
					    int snapshot = 0;
 | 
				
			||||||
| 
						 | 
					@ -468,20 +467,12 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((devaddr = qemu_opt_get(opts, "addr")) != NULL) {
 | 
					 | 
				
			||||||
        if (type != IF_VIRTIO) {
 | 
					 | 
				
			||||||
            error_report("addr is not supported by this bus type");
 | 
					 | 
				
			||||||
            return NULL;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* init */
 | 
					    /* init */
 | 
				
			||||||
    dinfo = g_malloc0(sizeof(*dinfo));
 | 
					    dinfo = g_malloc0(sizeof(*dinfo));
 | 
				
			||||||
    dinfo->id = g_strdup(qemu_opts_id(opts));
 | 
					    dinfo->id = g_strdup(qemu_opts_id(opts));
 | 
				
			||||||
    dinfo->bdrv = bdrv_new(dinfo->id);
 | 
					    dinfo->bdrv = bdrv_new(dinfo->id);
 | 
				
			||||||
    dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
 | 
					    dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
 | 
				
			||||||
    dinfo->bdrv->read_only = ro;
 | 
					    dinfo->bdrv->read_only = ro;
 | 
				
			||||||
    dinfo->devaddr = devaddr;
 | 
					 | 
				
			||||||
    dinfo->type = type;
 | 
					    dinfo->type = type;
 | 
				
			||||||
    dinfo->refcount = 1;
 | 
					    dinfo->refcount = 1;
 | 
				
			||||||
    if (serial != NULL) {
 | 
					    if (serial != NULL) {
 | 
				
			||||||
| 
						 | 
					@ -508,22 +499,8 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
 | 
				
			||||||
    case IF_FLOPPY:
 | 
					    case IF_FLOPPY:
 | 
				
			||||||
    case IF_PFLASH:
 | 
					    case IF_PFLASH:
 | 
				
			||||||
    case IF_MTD:
 | 
					    case IF_MTD:
 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
    case IF_VIRTIO:
 | 
					    case IF_VIRTIO:
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        /* add virtio block device */
 | 
					 | 
				
			||||||
        QemuOpts *devopts;
 | 
					 | 
				
			||||||
        devopts = qemu_opts_create_nofail(qemu_find_opts("device"));
 | 
					 | 
				
			||||||
        if (arch_type == QEMU_ARCH_S390X) {
 | 
					 | 
				
			||||||
            qemu_opt_set(devopts, "driver", "virtio-blk-s390");
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            qemu_opt_set(devopts, "driver", "virtio-blk-pci");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        qemu_opt_set(devopts, "drive", dinfo->id);
 | 
					 | 
				
			||||||
        if (devaddr)
 | 
					 | 
				
			||||||
            qemu_opt_set(devopts, "addr", devaddr);
 | 
					 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        abort();
 | 
					        abort();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -647,6 +624,10 @@ QemuOptsList qemu_legacy_drive_opts = {
 | 
				
			||||||
            .name = "boot",
 | 
					            .name = "boot",
 | 
				
			||||||
            .type = QEMU_OPT_BOOL,
 | 
					            .type = QEMU_OPT_BOOL,
 | 
				
			||||||
            .help = "(deprecated, ignored)",
 | 
					            .help = "(deprecated, ignored)",
 | 
				
			||||||
 | 
					        },{
 | 
				
			||||||
 | 
					            .name = "addr",
 | 
				
			||||||
 | 
					            .type = QEMU_OPT_STRING,
 | 
				
			||||||
 | 
					            .help = "pci address (virtio only)",
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        { /* end of list */ }
 | 
					        { /* end of list */ }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
| 
						 | 
					@ -662,6 +643,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 | 
				
			||||||
    BlockInterfaceType type;
 | 
					    BlockInterfaceType type;
 | 
				
			||||||
    int cyls, heads, secs, translation;
 | 
					    int cyls, heads, secs, translation;
 | 
				
			||||||
    int max_devs, bus_id, unit_id, index;
 | 
					    int max_devs, bus_id, unit_id, index;
 | 
				
			||||||
 | 
					    const char *devaddr;
 | 
				
			||||||
    Error *local_err = NULL;
 | 
					    Error *local_err = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Change legacy command line options into QMP ones */
 | 
					    /* Change legacy command line options into QMP ones */
 | 
				
			||||||
| 
						 | 
					@ -862,6 +844,27 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 | 
				
			||||||
        g_free(new_id);
 | 
					        g_free(new_id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Add virtio block device */
 | 
				
			||||||
 | 
					    devaddr = qemu_opt_get(legacy_opts, "addr");
 | 
				
			||||||
 | 
					    if (devaddr && type != IF_VIRTIO) {
 | 
				
			||||||
 | 
					        error_report("addr is not supported by this bus type");
 | 
				
			||||||
 | 
					        goto fail;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (type == IF_VIRTIO) {
 | 
				
			||||||
 | 
					        QemuOpts *devopts;
 | 
				
			||||||
 | 
					        devopts = qemu_opts_create_nofail(qemu_find_opts("device"));
 | 
				
			||||||
 | 
					        if (arch_type == QEMU_ARCH_S390X) {
 | 
				
			||||||
 | 
					            qemu_opt_set(devopts, "driver", "virtio-blk-s390");
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            qemu_opt_set(devopts, "driver", "virtio-blk-pci");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"));
 | 
				
			||||||
 | 
					        if (devaddr) {
 | 
				
			||||||
 | 
					            qemu_opt_set(devopts, "addr", devaddr);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Actual block device init: Functionality shared with blockdev-add */
 | 
					    /* Actual block device init: Functionality shared with blockdev-add */
 | 
				
			||||||
    dinfo = blockdev_init(bs_opts, type, media);
 | 
					    dinfo = blockdev_init(bs_opts, type, media);
 | 
				
			||||||
    if (dinfo == NULL) {
 | 
					    if (dinfo == NULL) {
 | 
				
			||||||
| 
						 | 
					@ -879,6 +882,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dinfo->bus = bus_id;
 | 
					    dinfo->bus = bus_id;
 | 
				
			||||||
    dinfo->unit = unit_id;
 | 
					    dinfo->unit = unit_id;
 | 
				
			||||||
 | 
					    dinfo->devaddr = devaddr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fail:
 | 
					fail:
 | 
				
			||||||
    qemu_opts_del(legacy_opts);
 | 
					    qemu_opts_del(legacy_opts);
 | 
				
			||||||
| 
						 | 
					@ -2258,10 +2262,6 @@ QemuOptsList qemu_common_drive_opts = {
 | 
				
			||||||
            .name = "werror",
 | 
					            .name = "werror",
 | 
				
			||||||
            .type = QEMU_OPT_STRING,
 | 
					            .type = QEMU_OPT_STRING,
 | 
				
			||||||
            .help = "write error action",
 | 
					            .help = "write error action",
 | 
				
			||||||
        },{
 | 
					 | 
				
			||||||
            .name = "addr",
 | 
					 | 
				
			||||||
            .type = QEMU_OPT_STRING,
 | 
					 | 
				
			||||||
            .help = "pci address (virtio only)",
 | 
					 | 
				
			||||||
        },{
 | 
					        },{
 | 
				
			||||||
            .name = "read-only",
 | 
					            .name = "read-only",
 | 
				
			||||||
            .type = QEMU_OPT_BOOL,
 | 
					            .type = QEMU_OPT_BOOL,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue