提交 56a14938 编写于 作者: G Gerd Hoffmann 提交者: Anthony Liguori

drive cleanup fixes.

Changes:
  * drive_uninit() wants a DriveInfo now.
  * drive_uninit() also calls bdrv_delete(),
    so callers don't need to do that.
  * drive_uninit() calls are moved over to the ->exit()
    callbacks, destroy_bdrvs() is zapped.
  * setting bdrv->private is not needed any more as the
    only user (destroy_bdrvs) is gone.
  * usb-storage needs no drive_uninit, scsi-disk will
    handle that.
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 3f84865a
...@@ -62,21 +62,3 @@ void destroy_nic(dev_match_fn *match_fn, void *arg) ...@@ -62,21 +62,3 @@ void destroy_nic(dev_match_fn *match_fn, void *arg)
} }
} }
} }
void destroy_bdrvs(dev_match_fn *match_fn, void *arg)
{
DriveInfo *dinfo;
struct BlockDriverState *bs;
QTAILQ_FOREACH(dinfo, &drives, next) {
bs = dinfo->bdrv;
if (bs) {
if (bs->private && match_fn(bs->private, arg)) {
drive_uninit(bs);
bdrv_delete(bs);
}
}
}
}
...@@ -234,9 +234,6 @@ void pci_device_hot_remove_success(PCIDevice *d) ...@@ -234,9 +234,6 @@ void pci_device_hot_remove_success(PCIDevice *d)
class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1); class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1);
switch(class_code) { switch(class_code) {
case PCI_BASE_CLASS_STORAGE:
destroy_bdrvs(pci_match_fn, d);
break;
case PCI_BASE_CLASS_NETWORK: case PCI_BASE_CLASS_NETWORK:
destroy_nic(pci_match_fn, d); destroy_nic(pci_match_fn, d);
break; break;
......
...@@ -936,6 +936,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, ...@@ -936,6 +936,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
} }
} }
static void scsi_destroy(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
drive_uninit(s->dinfo);
}
static int scsi_disk_initfn(SCSIDevice *dev) static int scsi_disk_initfn(SCSIDevice *dev)
{ {
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
...@@ -969,6 +976,7 @@ static SCSIDeviceInfo scsi_disk_info = { ...@@ -969,6 +976,7 @@ static SCSIDeviceInfo scsi_disk_info = {
.qdev.desc = "virtual scsi disk or cdrom", .qdev.desc = "virtual scsi disk or cdrom",
.qdev.size = sizeof(SCSIDiskState), .qdev.size = sizeof(SCSIDiskState),
.init = scsi_disk_initfn, .init = scsi_disk_initfn,
.destroy = scsi_destroy,
.send_command = scsi_send_command, .send_command = scsi_send_command,
.read_data = scsi_read_data, .read_data = scsi_read_data,
.write_data = scsi_write_data, .write_data = scsi_write_data,
......
...@@ -668,6 +668,8 @@ static void scsi_destroy(SCSIDevice *d) ...@@ -668,6 +668,8 @@ static void scsi_destroy(SCSIDevice *d)
qemu_free(r); qemu_free(r);
r = n; r = n;
} }
drive_uninit(s->dinfo);
} }
static int scsi_generic_initfn(SCSIDevice *dev) static int scsi_generic_initfn(SCSIDevice *dev)
......
...@@ -508,13 +508,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) ...@@ -508,13 +508,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
return ret; return ret;
} }
static void usb_msd_handle_destroy(USBDevice *dev)
{
MSDState *s = (MSDState *)dev;
drive_uninit(s->dinfo->bdrv);
}
static int usb_msd_initfn(USBDevice *dev) static int usb_msd_initfn(USBDevice *dev)
{ {
MSDState *s = DO_UPCAST(MSDState, dev, dev); MSDState *s = DO_UPCAST(MSDState, dev, dev);
...@@ -599,7 +592,6 @@ static struct USBDeviceInfo msd_info = { ...@@ -599,7 +592,6 @@ static struct USBDeviceInfo msd_info = {
.handle_reset = usb_msd_handle_reset, .handle_reset = usb_msd_handle_reset,
.handle_control = usb_msd_handle_control, .handle_control = usb_msd_handle_control,
.handle_data = usb_msd_handle_data, .handle_data = usb_msd_handle_data,
.handle_destroy = usb_msd_handle_destroy,
.qdev.props = (Property[]) { .qdev.props = (Property[]) {
DEFINE_PROP_DRIVE("drive", MSDState, dinfo), DEFINE_PROP_DRIVE("drive", MSDState, dinfo),
DEFINE_PROP_END_OF_LIST(), DEFINE_PROP_END_OF_LIST(),
......
...@@ -504,7 +504,6 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo) ...@@ -504,7 +504,6 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo)
strncpy(s->serial_str, ps, sizeof(s->serial_str)); strncpy(s->serial_str, ps, sizeof(s->serial_str));
else else
snprintf(s->serial_str, sizeof(s->serial_str), "0"); snprintf(s->serial_str, sizeof(s->serial_str), "0");
s->bs->private = dev;
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
bdrv_set_geometry_hint(s->bs, cylinders, heads, secs); bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
......
...@@ -458,6 +458,14 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev) ...@@ -458,6 +458,14 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
return 0; return 0;
} }
static int virtio_blk_exit_pci(PCIDevice *pci_dev)
{
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
drive_uninit(proxy->dinfo);
return 0;
}
static int virtio_console_init_pci(PCIDevice *pci_dev) static int virtio_console_init_pci(PCIDevice *pci_dev)
{ {
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
...@@ -519,6 +527,7 @@ static PCIDeviceInfo virtio_info[] = { ...@@ -519,6 +527,7 @@ static PCIDeviceInfo virtio_info[] = {
.qdev.name = "virtio-blk-pci", .qdev.name = "virtio-blk-pci",
.qdev.size = sizeof(VirtIOPCIProxy), .qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_blk_init_pci, .init = virtio_blk_init_pci,
.exit = virtio_blk_exit_pci,
.qdev.props = (Property[]) { .qdev.props = (Property[]) {
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo), DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo),
......
...@@ -190,7 +190,7 @@ extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts; ...@@ -190,7 +190,7 @@ extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit); extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
extern DriveInfo *drive_get_by_id(const char *id); extern DriveInfo *drive_get_by_id(const char *id);
extern int drive_get_max_bus(BlockInterfaceType type); extern int drive_get_max_bus(BlockInterfaceType type);
extern void drive_uninit(BlockDriverState *bdrv); extern void drive_uninit(DriveInfo *dinfo);
extern const char *drive_get_serial(BlockDriverState *bdrv); extern const char *drive_get_serial(BlockDriverState *bdrv);
extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv); extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
...@@ -205,7 +205,6 @@ typedef int (dev_match_fn)(void *dev_private, void *arg); ...@@ -205,7 +205,6 @@ typedef int (dev_match_fn)(void *dev_private, void *arg);
DriveInfo *add_init_drive(const char *opts); DriveInfo *add_init_drive(const char *opts);
void destroy_nic(dev_match_fn *match_fn, void *arg); void destroy_nic(dev_match_fn *match_fn, void *arg);
void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
/* pci-hotplug */ /* pci-hotplug */
void pci_device_hot_add(Monitor *mon, const QDict *qdict); void pci_device_hot_add(Monitor *mon, const QDict *qdict);
......
...@@ -1979,18 +1979,12 @@ static void bdrv_format_print(void *opaque, const char *name) ...@@ -1979,18 +1979,12 @@ static void bdrv_format_print(void *opaque, const char *name)
fprintf(stderr, " %s", name); fprintf(stderr, " %s", name);
} }
void drive_uninit(BlockDriverState *bdrv) void drive_uninit(DriveInfo *dinfo)
{ {
DriveInfo *dinfo;
QTAILQ_FOREACH(dinfo, &drives, next) {
if (dinfo->bdrv != bdrv)
continue;
qemu_opts_del(dinfo->opts); qemu_opts_del(dinfo->opts);
bdrv_delete(dinfo->bdrv);
QTAILQ_REMOVE(&drives, dinfo, next); QTAILQ_REMOVE(&drives, dinfo, next);
qemu_free(dinfo); qemu_free(dinfo);
break;
}
} }
DriveInfo *drive_init(QemuOpts *opts, void *opaque, DriveInfo *drive_init(QemuOpts *opts, void *opaque,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册