Skip to contentSkip to conversation

virtio_blk: provide getgeo

PATCH In review Christian Borntraeger 2 participants 2 messages Jan 23, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_blk: provide getgeo

Rusty,

I currently try to make my guest boot from an virtio root device without having an external kernel. Some of the tools that I tried expect HDIO_GETGEO to work. The most interesting value is likely the geo.start value to get the offset of a partition. This value is filled by block/ioctl.c if fops->getgeo is set. This patch also fills in some standard values for heads, sectors and cylinders.

Makes sense?

---
 drivers/block/virtio_blk.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +13 -2
Index: kvm/drivers/block/virtio_blk.c
===================================================================
@@ -154,9 +154,20 @@ static int virtblk_ioctl(struct inode *i
 			      (void __user *)data);
 }
 
+/* We provide getgeo only to please some old bootloader/partitioning tools */
+static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
+{
+	/* some standard values, similar to sd */
+	geo->heads = 1 << 6;
+	geo->sectors = 1 << 5;
+	geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+	return 0;
+}
+
 static struct block_device_operations virtblk_fops = {
-	.ioctl = virtblk_ioctl,
-	.owner = THIS_MODULE,
+	.ioctl  = virtblk_ioctl,
+	.owner  = THIS_MODULE,
+	.getgeo = virtblk_getgeo,
 };
 
 static int virtblk_probe(struct virtio_device *vdev)
#1 lore raw
Quoted 10 lines · On Thursday 24 January 2008 03:56:50 Christian Borntraeger wrote:

Rusty,

I currently try to make my guest boot from an virtio root device without having an external kernel. Some of the tools that I tried expect HDIO_GETGEO to work. The most interesting value is likely the geo.start value to get the offset of a partition. This value is filled by block/ioctl.c if fops->getgeo is set. This patch also fills in some standard values for heads, sectors and cylinders.

Makes sense?

Perfect sense, applied.

I wonder if there's a standard helper for this?

drivers/block/virtio_blk.c static int virtblk_ioctl(struct inode *i · line 165

Quoted 9 lines

+/* We provide getgeo only to please some old bootloader/partitioning tools */ +static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) +{

drivers/block/virtio_blk.c +6 -0
+	/* some standard values, similar to sd */
+	geo->heads = 1 << 6;
+	geo->sectors = 1 << 5;
+	geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+	return 0;
+}

Thanks,
Rusty.