hd-geometry: Cut out block layer translation middleman

hd_geometry_guess() picks geometry and translation.  Callers can get
the geometry directly, via parameters, but for translation they need
to go through the block layer.

Add a parameter for translation, so it can optionally be gotten just
like geometry.  In preparation of purging translation from the block
layer, which will happen later in this series.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Markus Armbruster 2012-07-10 11:12:37 +02:00 committed by Kevin Wolf
parent dc28c0cd30
commit e2f3dc2b6a
5 changed files with 20 additions and 11 deletions

View File

@ -16,6 +16,7 @@
/* Hard disk geometry */ /* Hard disk geometry */
void hd_geometry_guess(BlockDriverState *bs, void hd_geometry_guess(BlockDriverState *bs,
int *pcyls, int *pheads, int *psecs); int *pcyls, int *pheads, int *psecs,
int *ptrans);
#endif #endif

View File

@ -117,7 +117,8 @@ static void guess_chs_for_size(BlockDriverState *bs,
} }
void hd_geometry_guess(BlockDriverState *bs, void hd_geometry_guess(BlockDriverState *bs,
int *pcyls, int *pheads, int *psecs) int *pcyls, int *pheads, int *psecs,
int *ptrans)
{ {
int cylinders, heads, secs, translation; int cylinders, heads, secs, translation;
@ -129,6 +130,9 @@ void hd_geometry_guess(BlockDriverState *bs,
*pcyls = cylinders; *pcyls = cylinders;
*pheads = heads; *pheads = heads;
*psecs = secs; *psecs = secs;
if (ptrans) {
*ptrans = translation;
}
return; return;
} }
@ -142,10 +146,10 @@ void hd_geometry_guess(BlockDriverState *bs,
translation was active, so a standard physical disk translation was active, so a standard physical disk
geometry is OK */ geometry is OK */
guess_chs_for_size(bs, pcyls, pheads, psecs); guess_chs_for_size(bs, pcyls, pheads, psecs);
bdrv_set_translation_hint(bs, translation = *pcyls * *pheads <= 131072
*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;
@ -153,7 +157,11 @@ void hd_geometry_guess(BlockDriverState *bs,
*psecs = secs; *psecs = secs;
/* disable any translation to be in sync with /* disable any translation to be in sync with
the logical geometry */ the logical geometry */
bdrv_set_translation_hint(bs, BIOS_ATA_TRANSLATION_NONE); translation = BIOS_ATA_TRANSLATION_NONE;
bdrv_set_translation_hint(bs, translation);
}
if (ptrans) {
*ptrans = translation;
} }
bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs); 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);

View File

@ -1934,7 +1934,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
s->drive_kind = kind; s->drive_kind = kind;
bdrv_get_geometry(bs, &nb_sectors); bdrv_get_geometry(bs, &nb_sectors);
hd_geometry_guess(bs, &cylinders, &heads, &secs); hd_geometry_guess(bs, &cylinders, &heads, &secs, NULL);
if (cylinders < 1 || cylinders > 16383) { if (cylinders < 1 || cylinders > 16383) {
error_report("cyls must be between 1 and 16383"); error_report("cyls must be between 1 and 16383");
return -1; return -1;

View File

@ -990,7 +990,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
break; break;
} }
/* if a geometry hint is available, use it */ /* if a geometry hint is available, use it */
hd_geometry_guess(bdrv, &cylinders, &heads, &secs); hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL);
p[2] = (cylinders >> 16) & 0xff; p[2] = (cylinders >> 16) & 0xff;
p[3] = (cylinders >> 8) & 0xff; p[3] = (cylinders >> 8) & 0xff;
p[4] = cylinders & 0xff; p[4] = cylinders & 0xff;
@ -1024,7 +1024,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
p[2] = 5000 >> 8; p[2] = 5000 >> 8;
p[3] = 5000 & 0xff; p[3] = 5000 & 0xff;
/* if a geometry hint is available, use it */ /* if a geometry hint is available, use it */
hd_geometry_guess(bdrv, &cylinders, &heads, &secs); hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL);
p[4] = heads & 0xff; p[4] = heads & 0xff;
p[5] = secs & 0xff; p[5] = secs & 0xff;
p[6] = s->qdev.blocksize >> 8; p[6] = s->qdev.blocksize >> 8;

View File

@ -623,7 +623,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
s->blk = blk; s->blk = blk;
s->rq = NULL; s->rq = NULL;
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
hd_geometry_guess(s->bs, &cylinders, &heads, &secs); hd_geometry_guess(s->bs, &cylinders, &heads, &secs, NULL);
s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);