public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pass virtio disk geometry via config space
@ 2008-04-16 18:56 Ryan Harper
  2008-04-18 16:23 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Ryan Harper @ 2008-04-16 18:56 UTC (permalink / raw)
  To: kvm-devel; +Cc: Ryan Harper, Avi Kivity

From: Ryan Harper <ryanh@us.ibm.com>

Rather than faking up some geometry, allow the backend to push the disk
geometry via virtio pci config option.  Keep the old geo code around for
compatibility.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/qemu/hw/pc.c b/qemu/hw/pc.c
index ae87ab9..e78647a 100644
--- a/qemu/hw/pc.c
+++ b/qemu/hw/pc.c
@@ -1130,7 +1130,7 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
 	DriveInfo *info = &drives_table[extboot_drive];
 	int cyls, heads, secs;
 
-	if (info->type != IF_IDE) {
+	if (info->type != IF_IDE && info->type != IF_VIRTIO) {
 	    bdrv_guess_geometry(info->bdrv, &cyls, &heads, &secs);
 	    bdrv_set_geometry_hint(info->bdrv, cyls, heads, secs);
 	}
diff --git a/qemu/hw/virtio-blk.c b/qemu/hw/virtio-blk.c
index 492bd7f..d51501e 100644
--- a/qemu/hw/virtio-blk.c
+++ b/qemu/hw/virtio-blk.c
@@ -25,12 +25,16 @@
 #define VIRTIO_BLK_F_BARRIER	0	/* Does host support barriers? */
 #define VIRTIO_BLK_F_SIZE_MAX	1	/* Indicates maximum segment size */
 #define VIRTIO_BLK_F_SEG_MAX	2	/* Indicates maximum # of segments */
+#define VIRTIO_BLK_F_GEOMETRY	4	/* Indicates support of legacy geometry */
 
 struct virtio_blk_config
 {
     uint64_t capacity;
     uint32_t size_max;
     uint32_t seg_max;
+    uint16_t cylinders;
+    uint8_t heads;
+    uint8_t sectors;
 };
 
 /* These two define direction. */
@@ -132,32 +136,40 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
     VirtIOBlock *s = to_virtio_blk(vdev);
     struct virtio_blk_config blkcfg;
     int64_t capacity;
+    int cylinders, heads, secs;
 
     bdrv_get_geometry(s->bs, &capacity);
+    bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs);
     blkcfg.capacity = cpu_to_le64(capacity);
     blkcfg.seg_max = cpu_to_le32(128 - 2);
+    blkcfg.cylinders = cpu_to_le16(cylinders);
+    blkcfg.heads = heads;
+    blkcfg.sectors = secs;
     memcpy(config, &blkcfg, sizeof(blkcfg));
 }
 
 static uint32_t virtio_blk_get_features(VirtIODevice *vdev)
 {
-    return (1 << VIRTIO_BLK_F_SEG_MAX);
+    return (1 << VIRTIO_BLK_F_SEG_MAX | 1 << VIRTIO_BLK_F_GEOMETRY);
 }
 
 void *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device,
 		      BlockDriverState *bs)
 {
     VirtIOBlock *s;
+    int cylinders, heads, secs;
 
     s = (VirtIOBlock *)virtio_init_pci(bus, "virtio-blk", vendor, device,
 				       0, VIRTIO_ID_BLOCK,
 				       0x01, 0x80, 0x00,
-				       16, sizeof(VirtIOBlock));
+				       sizeof(struct virtio_blk_config), sizeof(VirtIOBlock));
 
     s->vdev.update_config = virtio_blk_update_config;
     s->vdev.get_features = virtio_blk_get_features;
     s->bs = bs;
     bs->devfn = s->vdev.pci_dev.devfn;
+    bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
+    bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
 
     virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
 

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-04-18 16:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-16 18:56 [PATCH] pass virtio disk geometry via config space Ryan Harper
2008-04-18 16:23 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox