提交 2b584959 编写于 作者: M Markus Armbruster 提交者: Kevin Wolf

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: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 856dcba2
...@@ -996,12 +996,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest, ...@@ -996,12 +996,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
bs_dest->block_timer = bs_src->block_timer; bs_dest->block_timer = bs_src->block_timer;
bs_dest->io_limits_enabled = bs_src->io_limits_enabled; 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 */ /* r/w error */
bs_dest->on_read_error = bs_src->on_read_error; bs_dest->on_read_error = bs_src->on_read_error;
bs_dest->on_write_error = bs_src->on_write_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) ...@@ -2132,27 +2126,6 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
*nb_sectors_ptr = length; *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 */ /* throttling disk io limits */
void bdrv_set_io_limits(BlockDriverState *bs, void bdrv_set_io_limits(BlockDriverState *bs,
BlockIOLimit *io_limits) BlockIOLimit *io_limits)
...@@ -2161,11 +2134,6 @@ void bdrv_set_io_limits(BlockDriverState *bs, ...@@ -2161,11 +2134,6 @@ void bdrv_set_io_limits(BlockDriverState *bs,
bs->io_limits_enabled = bdrv_io_limits_enabled(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, void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
BlockErrorAction on_write_error) BlockErrorAction on_write_error)
{ {
......
...@@ -257,18 +257,6 @@ int bdrv_has_zero_init(BlockDriverState *bs); ...@@ -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 bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
int *pnum); 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, void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
BlockErrorAction on_write_error); BlockErrorAction on_write_error);
BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read); BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
......
...@@ -320,7 +320,6 @@ struct BlockDriverState { ...@@ -320,7 +320,6 @@ struct BlockDriverState {
/* NOTE: the following infos are only hints for real hardware /* NOTE: the following infos are only hints for real hardware
drivers. They are not used by the block driver */ drivers. They are not used by the block driver */
int cyls, heads, secs, translation;
BlockErrorAction on_read_error, on_write_error; BlockErrorAction on_read_error, on_write_error;
bool iostatus_enabled; bool iostatus_enabled;
BlockDeviceIoStatus iostatus; BlockDeviceIoStatus iostatus;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
* later. See the COPYING file in the top-level directory. * later. See the COPYING file in the top-level directory.
*/ */
#include "block.h"
#include "blockdev.h" #include "blockdev.h"
#include "hw/block-common.h"
#include "monitor.h" #include "monitor.h"
#include "qerror.h" #include "qerror.h"
#include "qemu-option.h" #include "qemu-option.h"
...@@ -551,17 +551,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) ...@@ -551,17 +551,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
case IF_SCSI: case IF_SCSI:
case IF_XEN: case IF_XEN:
case IF_NONE: case IF_NONE:
switch(media) { dinfo->media_cd = media == MEDIA_CDROM;
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;
}
break; break;
case IF_SD: case IF_SD:
case IF_FLOPPY: case IF_FLOPPY:
......
...@@ -15,6 +15,12 @@ ...@@ -15,6 +15,12 @@
/* Hard disk geometry */ /* 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, void hd_geometry_guess(BlockDriverState *bs,
uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
int *ptrans); int *ptrans);
......
...@@ -122,25 +122,10 @@ void hd_geometry_guess(BlockDriverState *bs, ...@@ -122,25 +122,10 @@ void hd_geometry_guess(BlockDriverState *bs,
{ {
int cylinders, heads, secs, translation; 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) { if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
/* no LCHS guess: use a standard physical disk geometry */ /* no LCHS guess: use a standard physical disk geometry */
guess_chs_for_size(bs, pcyls, pheads, psecs); guess_chs_for_size(bs, pcyls, pheads, psecs);
translation = BIOS_ATA_TRANSLATION_AUTO;
} else if (heads > 16) { } else if (heads > 16) {
/* LCHS guess with heads > 16 means that a BIOS LBA /* LCHS guess with heads > 16 means that a BIOS LBA
translation was active, so a standard physical disk translation was active, so a standard physical disk
...@@ -149,7 +134,6 @@ void hd_geometry_guess(BlockDriverState *bs, ...@@ -149,7 +134,6 @@ void hd_geometry_guess(BlockDriverState *bs,
translation = *pcyls * *pheads <= 131072 translation = *pcyls * *pheads <= 131072
? BIOS_ATA_TRANSLATION_LARGE ? BIOS_ATA_TRANSLATION_LARGE
: BIOS_ATA_TRANSLATION_LBA; : BIOS_ATA_TRANSLATION_LBA;
bdrv_set_translation_hint(bs, translation);
} else { } else {
/* LCHS guess with heads <= 16: use as physical geometry */ /* LCHS guess with heads <= 16: use as physical geometry */
*pcyls = cylinders; *pcyls = cylinders;
...@@ -158,11 +142,9 @@ void hd_geometry_guess(BlockDriverState *bs, ...@@ -158,11 +142,9 @@ void hd_geometry_guess(BlockDriverState *bs,
/* disable any translation to be in sync with /* disable any translation to be in sync with
the logical geometry */ the logical geometry */
translation = BIOS_ATA_TRANSLATION_NONE; translation = BIOS_ATA_TRANSLATION_NONE;
bdrv_set_translation_hint(bs, translation);
} }
if (ptrans) { if (ptrans) {
*ptrans = translation; *ptrans = translation;
} }
bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs);
trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation); trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation);
} }
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "kvm.h" #include "kvm.h"
#include "xen.h" #include "xen.h"
#include "blockdev.h" #include "blockdev.h"
#include "hw/block-common.h"
#include "ui/qemu-spice.h" #include "ui/qemu-spice.h"
#include "memory.h" #include "memory.h"
#include "exec-memory.h" #include "exec-memory.h"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "qdev.h" #include "qdev.h"
#include "qerror.h" #include "qerror.h"
#include "blockdev.h" #include "blockdev.h"
#include "hw/block-common.h"
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
{ {
......
...@@ -130,8 +130,8 @@ int main(int argc, char **argv) ...@@ -130,8 +130,8 @@ int main(int argc, char **argv)
#include "qemu-timer.h" #include "qemu-timer.h"
#include "qemu-char.h" #include "qemu-char.h"
#include "cache-utils.h" #include "cache-utils.h"
#include "block.h"
#include "blockdev.h" #include "blockdev.h"
#include "hw/block-common.h"
#include "block-migration.h" #include "block-migration.h"
#include "dma.h" #include "dma.h"
#include "audio/audio.h" #include "audio/audio.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册