From 9db1c0f7a94c6382e2b3e1365566a9a8b8ae74c1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:31 +0200 Subject: hd-geometry: Move disk geometry guessing back from block.c Commit f3d54fc4 factored it out of hw/ide.c for reuse. Sensible, except it was put into block.c. Device-specific functionality should be kept in device code, not the block layer. Move it to hw/hd-geometry.c, and make stylistic changes required to keep checkpatch.pl happy. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'hw/scsi-disk.c') diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 34336b1b58..5339c2ef9d 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -34,6 +34,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0) #include "scsi-defs.h" #include "sysemu.h" #include "blockdev.h" +#include "hw/block-common.h" #include "dma.h" #ifdef __linux @@ -989,7 +990,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, break; } /* if a geometry hint is available, use it */ - bdrv_guess_geometry(bdrv, &cylinders, &heads, &secs); + hd_geometry_guess(bdrv, &cylinders, &heads, &secs); p[2] = (cylinders >> 16) & 0xff; p[3] = (cylinders >> 8) & 0xff; p[4] = cylinders & 0xff; @@ -1023,7 +1024,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, p[2] = 5000 >> 8; p[3] = 5000 & 0xff; /* if a geometry hint is available, use it */ - bdrv_guess_geometry(bdrv, &cylinders, &heads, &secs); + hd_geometry_guess(bdrv, &cylinders, &heads, &secs); p[4] = heads & 0xff; p[5] = secs & 0xff; p[6] = s->qdev.blocksize >> 8; -- cgit v1.2.3 From e2f3dc2b6a205cf969ba5d1307293db17fd9621f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:37 +0200 Subject: 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 Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw/scsi-disk.c') diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 5339c2ef9d..fc077f5951 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -990,7 +990,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, break; } /* 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[3] = (cylinders >> 8) & 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[3] = 5000 & 0xff; /* 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[5] = secs & 0xff; p[6] = s->qdev.blocksize >> 8; -- cgit v1.2.3 From 1f24d7b47e1f18b5e7f0f050f915a42e9aa645db Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:41 +0200 Subject: hd-geometry: Switch to uint32_t to match BlockConf Best to use the same type, to avoid unwanted truncation or sign extension. BlockConf can't use plain int for cyls, heads and secs, because integer properties require an exact width. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw/scsi-disk.c') diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index fc077f5951..c881acf011 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -968,7 +968,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, }; BlockDriverState *bdrv = s->qdev.conf.bs; - int cylinders, heads, secs; + uint32_t cylinders, heads, secs; uint8_t *p = *p_outbuf; if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) { -- cgit v1.2.3 From d252df489879ca3b128e080409b89305491d04cf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 10 Jul 2012 11:12:42 +0200 Subject: scsi-hd: qdev properties for disk geometry Geometry needs to be qdev properties, because it belongs to the disk's guest part. Maintain backward compatibility exactly like for serial: fall back to DriveInfo's geometry, set with -drive cyls=... Do this only for scsi-hd. scsi-disk is legacy. scsi-cd doesn't have a geometry. scsi-block should get geometry from the host disk. Bonus: info qtree now shows the geometry. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 69 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 23 deletions(-) (limited to 'hw/scsi-disk.c') diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index c881acf011..0a182f987e 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -966,9 +966,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, [MODE_PAGE_AUDIO_CTL] = (1 << TYPE_ROM), [MODE_PAGE_CAPABILITIES] = (1 << TYPE_ROM), }; - - BlockDriverState *bdrv = s->qdev.conf.bs; - uint32_t cylinders, heads, secs; uint8_t *p = *p_outbuf; if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) { @@ -990,19 +987,18 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, break; } /* if a geometry hint is available, use it */ - hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL); - p[2] = (cylinders >> 16) & 0xff; - p[3] = (cylinders >> 8) & 0xff; - p[4] = cylinders & 0xff; - p[5] = heads & 0xff; + p[2] = (s->qdev.conf.cyls >> 16) & 0xff; + p[3] = (s->qdev.conf.cyls >> 8) & 0xff; + p[4] = s->qdev.conf.cyls & 0xff; + p[5] = s->qdev.conf.heads & 0xff; /* Write precomp start cylinder, disabled */ - p[6] = (cylinders >> 16) & 0xff; - p[7] = (cylinders >> 8) & 0xff; - p[8] = cylinders & 0xff; + p[6] = (s->qdev.conf.cyls >> 16) & 0xff; + p[7] = (s->qdev.conf.cyls >> 8) & 0xff; + p[8] = s->qdev.conf.cyls & 0xff; /* Reduced current start cylinder, disabled */ - p[9] = (cylinders >> 16) & 0xff; - p[10] = (cylinders >> 8) & 0xff; - p[11] = cylinders & 0xff; + p[9] = (s->qdev.conf.cyls >> 16) & 0xff; + p[10] = (s->qdev.conf.cyls >> 8) & 0xff; + p[11] = s->qdev.conf.cyls & 0xff; /* Device step rate [ns], 200ns */ p[12] = 0; p[13] = 200; @@ -1024,18 +1020,17 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf, p[2] = 5000 >> 8; p[3] = 5000 & 0xff; /* if a geometry hint is available, use it */ - hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL); - p[4] = heads & 0xff; - p[5] = secs & 0xff; + p[4] = s->qdev.conf.heads & 0xff; + p[5] = s->qdev.conf.secs & 0xff; p[6] = s->qdev.blocksize >> 8; - p[8] = (cylinders >> 8) & 0xff; - p[9] = cylinders & 0xff; + p[8] = (s->qdev.conf.cyls >> 8) & 0xff; + p[9] = s->qdev.conf.cyls & 0xff; /* Write precomp start cylinder, disabled */ - p[10] = (cylinders >> 8) & 0xff; - p[11] = cylinders & 0xff; + p[10] = (s->qdev.conf.cyls >> 8) & 0xff; + p[11] = s->qdev.conf.cyls & 0xff; /* Reduced current start cylinder, disabled */ - p[12] = (cylinders >> 8) & 0xff; - p[13] = cylinders & 0xff; + p[12] = (s->qdev.conf.cyls >> 8) & 0xff; + p[13] = s->qdev.conf.cyls & 0xff; /* Device step rate [100us], 100us */ p[14] = 0; p[15] = 1; @@ -1755,6 +1750,33 @@ static int scsi_initfn(SCSIDevice *dev) return -1; } + if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) { + /* try to fall back to value set with legacy -drive cyls=... */ + dinfo = drive_get_by_blockdev(s->qdev.conf.bs); + dev->conf.cyls = dinfo->cyls; + dev->conf.heads = dinfo->heads; + dev->conf.secs = dinfo->secs; + } + if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) { + hd_geometry_guess(s->qdev.conf.bs, + &dev->conf.cyls, &dev->conf.heads, &dev->conf.secs, + NULL); + } + if (dev->conf.cyls || dev->conf.heads || dev->conf.secs) { + if (dev->conf.cyls < 1 || dev->conf.cyls > 65535) { + error_report("cyls must be between 1 and 65535"); + return -1; + } + if (dev->conf.heads < 1 || dev->conf.heads > 255) { + error_report("heads must be between 1 and 255"); + return -1; + } + if (dev->conf.secs < 1 || dev->conf.secs > 255) { + error_report("secs must be between 1 and 255"); + return -1; + } + } + if (!s->serial) { /* try to fall back to value set with legacy -drive serial=... */ dinfo = drive_get_by_blockdev(s->qdev.conf.bs); @@ -1975,6 +1997,7 @@ static Property scsi_hd_properties[] = { DEFINE_PROP_BIT("dpofua", SCSIDiskState, features, SCSI_DISK_F_DPOFUA, false), DEFINE_PROP_HEX64("wwn", SCSIDiskState, wwn, 0), + DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), }; -- cgit v1.2.3 From 911525dba9ecc21f97b05c0f09bf9319a9de3a7d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 11 Jul 2012 15:08:37 +0200 Subject: hw/block-common: Factor out fall back to legacy -drive serial=... Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'hw/scsi-disk.c') diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 0a182f987e..39a07d7579 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1777,13 +1777,7 @@ static int scsi_initfn(SCSIDevice *dev) } } - if (!s->serial) { - /* try to fall back to value set with legacy -drive serial=... */ - dinfo = drive_get_by_blockdev(s->qdev.conf.bs); - if (*dinfo->serial) { - s->serial = g_strdup(dinfo->serial); - } - } + blkconf_serial(&s->qdev.conf, &s->serial); if (!s->version) { s->version = g_strdup(qemu_get_version()); -- cgit v1.2.3 From b7eb0c9f95e50239ce5b5266373dc52c85e75299 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 11 Jul 2012 15:08:39 +0200 Subject: hw/block-common: Factor out fall back to legacy -drive cyls=... Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'hw/scsi-disk.c') diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 39a07d7579..525816cb76 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1737,7 +1737,6 @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev) static int scsi_initfn(SCSIDevice *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); - DriveInfo *dinfo; if (!s->qdev.conf.bs) { error_report("drive property not set"); @@ -1750,34 +1749,10 @@ static int scsi_initfn(SCSIDevice *dev) return -1; } - if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) { - /* try to fall back to value set with legacy -drive cyls=... */ - dinfo = drive_get_by_blockdev(s->qdev.conf.bs); - dev->conf.cyls = dinfo->cyls; - dev->conf.heads = dinfo->heads; - dev->conf.secs = dinfo->secs; - } - if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) { - hd_geometry_guess(s->qdev.conf.bs, - &dev->conf.cyls, &dev->conf.heads, &dev->conf.secs, - NULL); - } - if (dev->conf.cyls || dev->conf.heads || dev->conf.secs) { - if (dev->conf.cyls < 1 || dev->conf.cyls > 65535) { - error_report("cyls must be between 1 and 65535"); - return -1; - } - if (dev->conf.heads < 1 || dev->conf.heads > 255) { - error_report("heads must be between 1 and 255"); - return -1; - } - if (dev->conf.secs < 1 || dev->conf.secs > 255) { - error_report("secs must be between 1 and 255"); - return -1; - } - } - blkconf_serial(&s->qdev.conf, &s->serial); + if (blkconf_geometry(&dev->conf, NULL, 65535, 255, 255) < 0) { + return -1; + } if (!s->version) { s->version = g_strdup(qemu_get_version()); -- cgit v1.2.3