From d4d34b0d3f5af5c8e09980da0de2eebe9a27dc71 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:46 +0200 Subject: qdev: Collect private helpers in one place Just code motion, with one long line wrapped to keep checkpatch.pl happy. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/qdev-properties.c | 144 +++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'hw/qdev-properties.c') diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 0b894620c9..002c7f9726 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -10,6 +10,78 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) return ptr; } +static void get_pointer(Object *obj, Visitor *v, Property *prop, + const char *(*print)(void *ptr), + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + void **ptr = qdev_get_prop_ptr(dev, prop); + char *p; + + p = (char *) (*ptr ? print(*ptr) : ""); + visit_type_str(v, &p, name, errp); +} + +static void set_pointer(Object *obj, Visitor *v, Property *prop, + int (*parse)(DeviceState *dev, const char *str, + void **ptr), + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Error *local_err = NULL; + void **ptr = qdev_get_prop_ptr(dev, prop); + char *str; + int ret; + + if (dev->state != DEV_STATE_CREATED) { + error_set(errp, QERR_PERMISSION_DENIED); + return; + } + + visit_type_str(v, &str, name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + if (!*str) { + g_free(str); + *ptr = NULL; + return; + } + ret = parse(dev, str, ptr); + error_set_from_qdev_prop_error(errp, ret, dev, prop, str); + g_free(str); +} + +static void get_enum(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + int *ptr = qdev_get_prop_ptr(dev, prop); + + visit_type_enum(v, ptr, prop->info->enum_table, + prop->info->name, prop->name, errp); +} + +static void set_enum(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + int *ptr = qdev_get_prop_ptr(dev, prop); + + if (dev->state != DEV_STATE_CREATED) { + error_set(errp, QERR_PERMISSION_DENIED); + return; + } + + visit_type_enum(v, ptr, prop->info->enum_table, + prop->info->name, prop->name, errp); +} + +/* Bit */ + static uint32_t qdev_get_prop_mask(Property *prop) { assert(prop->info == &qdev_prop_bit); @@ -26,8 +98,6 @@ static void bit_prop_set(DeviceState *dev, Property *props, bool val) *p &= ~mask; } -/* Bit */ - static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len) { uint32_t *p = qdev_get_prop_ptr(dev, prop); @@ -435,48 +505,6 @@ static const char *print_drive(void *ptr) return bdrv_get_device_name(ptr); } -static void get_pointer(Object *obj, Visitor *v, Property *prop, - const char *(*print)(void *ptr), - const char *name, Error **errp) -{ - DeviceState *dev = DEVICE(obj); - void **ptr = qdev_get_prop_ptr(dev, prop); - char *p; - - p = (char *) (*ptr ? print(*ptr) : ""); - visit_type_str(v, &p, name, errp); -} - -static void set_pointer(Object *obj, Visitor *v, Property *prop, - int (*parse)(DeviceState *dev, const char *str, void **ptr), - const char *name, Error **errp) -{ - DeviceState *dev = DEVICE(obj); - Error *local_err = NULL; - void **ptr = qdev_get_prop_ptr(dev, prop); - char *str; - int ret; - - if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); - return; - } - - visit_type_str(v, &str, name, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - if (!*str) { - g_free(str); - *ptr = NULL; - return; - } - ret = parse(dev, str, ptr); - error_set_from_qdev_prop_error(errp, ret, dev, prop, str); - g_free(str); -} - static void get_drive(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { @@ -735,7 +763,6 @@ PropertyInfo qdev_prop_macaddr = { .set = set_mac, }; - /* --- lost tick policy --- */ static const char *lost_tick_policy_table[LOST_TICK_MAX+1] = { @@ -748,33 +775,6 @@ static const char *lost_tick_policy_table[LOST_TICK_MAX+1] = { QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int)); -static void get_enum(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - DeviceState *dev = DEVICE(obj); - Property *prop = opaque; - int *ptr = qdev_get_prop_ptr(dev, prop); - - visit_type_enum(v, ptr, prop->info->enum_table, - prop->info->name, prop->name, errp); -} - -static void set_enum(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) -{ - DeviceState *dev = DEVICE(obj); - Property *prop = opaque; - int *ptr = qdev_get_prop_ptr(dev, prop); - - if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); - return; - } - - visit_type_enum(v, ptr, prop->info->enum_table, - prop->info->name, prop->name, errp); -} - PropertyInfo qdev_prop_losttickpolicy = { .name = "LostTickPolicy", .enum_table = lost_tick_policy_table, -- cgit 1.4.1 From 8cd41745fbe4ebbc7adff247cf2955765f7eb5e2 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:47 +0200 Subject: qdev: New property type chs-translation Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/qdev-properties.c | 15 +++++++++++++++ hw/qdev.h | 3 +++ 2 files changed, 18 insertions(+) (limited to 'hw/qdev-properties.c') diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 002c7f9726..0b18f8c330 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -782,6 +782,21 @@ PropertyInfo qdev_prop_losttickpolicy = { .set = set_enum, }; +/* --- BIOS CHS translation */ + +static const char *bios_chs_trans_table[] = { + [BIOS_ATA_TRANSLATION_AUTO] = "auto", + [BIOS_ATA_TRANSLATION_NONE] = "none", + [BIOS_ATA_TRANSLATION_LBA] = "lba", +}; + +PropertyInfo qdev_prop_bios_chs_trans = { + .name = "bios-chs-trans", + .enum_table = bios_chs_trans_table, + .get = get_enum, + .set = set_enum, +}; + /* --- pci address --- */ /* diff --git a/hw/qdev.h b/hw/qdev.h index f4683dc771..9be35d47e5 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -232,6 +232,7 @@ extern PropertyInfo qdev_prop_chr; extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; extern PropertyInfo qdev_prop_losttickpolicy; +extern PropertyInfo qdev_prop_bios_chs_trans; extern PropertyInfo qdev_prop_drive; extern PropertyInfo qdev_prop_netdev; extern PropertyInfo qdev_prop_vlan; @@ -299,6 +300,8 @@ extern PropertyInfo qdev_prop_pci_host_devaddr; #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy) +#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \ + DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int) #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \ -- cgit 1.4.1 From 2b584959ed300ddff4acba0d7554becad5f274fd Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:50 +0200 Subject: block: Geometry and translation hints are now useless, purge them There are two producers of these hints: drive_init() on behalf of -drive, and hd_geometry_guess(). The only consumer of the hint is hd_geometry_guess(). The callers of hd_geometry_guess() call it only when drive_init() didn't set the hints. Therefore, drive_init()'s hints are never used. Thus, hd_geometry_guess() only ever sees hints it produced itself in a prior call. Only the first call computes something, subsequent calls just repeat the first call's results. However, hd_geometry_guess() is never called more than once: the device models don't, and the block device is destroyed on unplug. Thus, dropping the repeat feature doesn't break anything now. If a block device wasn't destroyed on unplug and could be reused with a new device, then repeating old results would be wrong. Thus, dropping the repeat feature prevents future breakage. This renders the hints unused. Purge them from the block layer. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- block.c | 32 -------------------------------- block.h | 12 ------------ block_int.h | 1 - blockdev.c | 14 ++------------ hw/block-common.h | 6 ++++++ hw/hd-geometry.c | 20 +------------------- hw/pc.c | 1 + hw/qdev-properties.c | 1 + vl.c | 2 +- 9 files changed, 12 insertions(+), 77 deletions(-) (limited to 'hw/qdev-properties.c') diff --git a/block.c b/block.c index 06323cfe53..ce7eb8f79b 100644 --- a/block.c +++ b/block.c @@ -996,12 +996,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest, bs_dest->block_timer = bs_src->block_timer; bs_dest->io_limits_enabled = bs_src->io_limits_enabled; - /* geometry */ - bs_dest->cyls = bs_src->cyls; - bs_dest->heads = bs_src->heads; - bs_dest->secs = bs_src->secs; - bs_dest->translation = bs_src->translation; - /* r/w error */ bs_dest->on_read_error = bs_src->on_read_error; bs_dest->on_write_error = bs_src->on_write_error; @@ -2132,27 +2126,6 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) *nb_sectors_ptr = length; } -void bdrv_set_geometry_hint(BlockDriverState *bs, - int cyls, int heads, int secs) -{ - bs->cyls = cyls; - bs->heads = heads; - bs->secs = secs; -} - -void bdrv_set_translation_hint(BlockDriverState *bs, int translation) -{ - bs->translation = translation; -} - -void bdrv_get_geometry_hint(BlockDriverState *bs, - int *pcyls, int *pheads, int *psecs) -{ - *pcyls = bs->cyls; - *pheads = bs->heads; - *psecs = bs->secs; -} - /* throttling disk io limits */ void bdrv_set_io_limits(BlockDriverState *bs, BlockIOLimit *io_limits) @@ -2161,11 +2134,6 @@ void bdrv_set_io_limits(BlockDriverState *bs, bs->io_limits_enabled = bdrv_io_limits_enabled(bs); } -int bdrv_get_translation_hint(BlockDriverState *bs) -{ - return bs->translation; -} - void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error) { diff --git a/block.h b/block.h index 1cd8a01c75..29c5eabf6e 100644 --- a/block.h +++ b/block.h @@ -257,18 +257,6 @@ int bdrv_has_zero_init(BlockDriverState *bs); int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); -#define BIOS_ATA_TRANSLATION_AUTO 0 -#define BIOS_ATA_TRANSLATION_NONE 1 -#define BIOS_ATA_TRANSLATION_LBA 2 -#define BIOS_ATA_TRANSLATION_LARGE 3 -#define BIOS_ATA_TRANSLATION_RECHS 4 - -void bdrv_set_geometry_hint(BlockDriverState *bs, - int cyls, int heads, int secs); -void bdrv_set_translation_hint(BlockDriverState *bs, int translation); -void bdrv_get_geometry_hint(BlockDriverState *bs, - int *pcyls, int *pheads, int *psecs); -int bdrv_get_translation_hint(BlockDriverState *bs); void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error); BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read); diff --git a/block_int.h b/block_int.h index 1fb5352d0e..d72317fbe3 100644 --- a/block_int.h +++ b/block_int.h @@ -320,7 +320,6 @@ struct BlockDriverState { /* NOTE: the following infos are only hints for real hardware drivers. They are not used by the block driver */ - int cyls, heads, secs, translation; BlockErrorAction on_read_error, on_write_error; bool iostatus_enabled; BlockDeviceIoStatus iostatus; diff --git a/blockdev.c b/blockdev.c index 161985b1e5..06c997e864 100644 --- a/blockdev.c +++ b/blockdev.c @@ -7,8 +7,8 @@ * later. See the COPYING file in the top-level directory. */ -#include "block.h" #include "blockdev.h" +#include "hw/block-common.h" #include "monitor.h" #include "qerror.h" #include "qemu-option.h" @@ -551,17 +551,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) case IF_SCSI: case IF_XEN: case IF_NONE: - switch(media) { - case MEDIA_DISK: - if (cyls != 0) { - bdrv_set_geometry_hint(dinfo->bdrv, cyls, heads, secs); - bdrv_set_translation_hint(dinfo->bdrv, translation); - } - break; - case MEDIA_CDROM: - dinfo->media_cd = 1; - break; - } + dinfo->media_cd = media == MEDIA_CDROM; break; case IF_SD: case IF_FLOPPY: diff --git a/hw/block-common.h b/hw/block-common.h index 2f651867d2..ec7810d7d4 100644 --- a/hw/block-common.h +++ b/hw/block-common.h @@ -15,6 +15,12 @@ /* Hard disk geometry */ +#define BIOS_ATA_TRANSLATION_AUTO 0 +#define BIOS_ATA_TRANSLATION_NONE 1 +#define BIOS_ATA_TRANSLATION_LBA 2 +#define BIOS_ATA_TRANSLATION_LARGE 3 +#define BIOS_ATA_TRANSLATION_RECHS 4 + void hd_geometry_guess(BlockDriverState *bs, uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, int *ptrans); diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c index 7626cbbe9c..74678a656b 100644 --- a/hw/hd-geometry.c +++ b/hw/hd-geometry.c @@ -122,25 +122,10 @@ void hd_geometry_guess(BlockDriverState *bs, { int cylinders, heads, secs, translation; - bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs); - translation = bdrv_get_translation_hint(bs); - - if (cylinders != 0) { - /* already got a geometry hint: use it */ - *pcyls = cylinders; - *pheads = heads; - *psecs = secs; - if (ptrans) { - *ptrans = translation; - } - return; - } - - assert(translation == BIOS_ATA_TRANSLATION_AUTO); - if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) { /* no LCHS guess: use a standard physical disk geometry */ guess_chs_for_size(bs, pcyls, pheads, psecs); + translation = BIOS_ATA_TRANSLATION_AUTO; } else if (heads > 16) { /* LCHS guess with heads > 16 means that a BIOS LBA translation was active, so a standard physical disk @@ -149,7 +134,6 @@ void hd_geometry_guess(BlockDriverState *bs, translation = *pcyls * *pheads <= 131072 ? BIOS_ATA_TRANSLATION_LARGE : BIOS_ATA_TRANSLATION_LBA; - bdrv_set_translation_hint(bs, translation); } else { /* LCHS guess with heads <= 16: use as physical geometry */ *pcyls = cylinders; @@ -158,11 +142,9 @@ void hd_geometry_guess(BlockDriverState *bs, /* disable any translation to be in sync with the logical geometry */ translation = BIOS_ATA_TRANSLATION_NONE; - bdrv_set_translation_hint(bs, translation); } if (ptrans) { *ptrans = translation; } - bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs); trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation); } diff --git a/hw/pc.c b/hw/pc.c index 89a0c661db..77b12b4c11 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -44,6 +44,7 @@ #include "kvm.h" #include "xen.h" #include "blockdev.h" +#include "hw/block-common.h" #include "ui/qemu-spice.h" #include "memory.h" #include "exec-memory.h" diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 0b18f8c330..01c378f534 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -2,6 +2,7 @@ #include "qdev.h" #include "qerror.h" #include "blockdev.h" +#include "hw/block-common.h" void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) { diff --git a/vl.c b/vl.c index 46248b9c1c..8904db1a33 100644 --- a/vl.c +++ b/vl.c @@ -130,8 +130,8 @@ int main(int argc, char **argv) #include "qemu-timer.h" #include "qemu-char.h" #include "cache-utils.h" -#include "block.h" #include "blockdev.h" +#include "hw/block-common.h" #include "block-migration.h" #include "dma.h" #include "audio/audio.h" -- cgit 1.4.1