Skip to contentSkip to conversation

blkfront: ioctls/geometry, 2.6

PATCH In review Pascal Bouchareine 2 participants 4 messages May 15, 2006 – May 16, 2006 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blkfront: ioctls/geometry, 2.6

Hi,

Adds HDIO_GETGEO, BLKGETSIZE, BLKGETSIZE64 support to blkfront.

An attempt to merge in the following sent previously by Ian Pratt :
http://lists.xensource.com/archives/html/xen-devel/2005-01/msg00659.html

Taking into account the block_device_operations for get_geom.

Regards,
Pascal

Signature · 2 lines
\o/   Pascal Bouchareine - Gandi 
 g    0170393757           15, place de la Nation - 75011 Paris      
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +31 -5
diff -ru xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c xen-unstable.hg.new/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
@@ -424,7 +424,6 @@
 	return 0;
 }
 
-
 int blkif_release(struct inode *inode, struct file *filep)
 {
 	struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
@@ -442,19 +441,46 @@
 	return 0;
 }
 
+int blkif_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+	struct gendisk *gd;
+	struct hd_struct *part;
+	int    dpart;
+
+	DPRINTK_IOCTL("blkif ioctl(HDIO_GETGEO)\n");
+	gd = bdev->bd_disk;
+
+	geo->start = 0x00;
+	geo->heads = 0xff;
+	geo->sectors = 0x3f;
+	geo->cylinders = (gd->capacity >> 14) + (geo->heads + geo->sectors + 1);
+		
+	return 0;
+}
 
 int blkif_ioctl(struct inode *inode, struct file *filep,
                 unsigned command, unsigned long argument)
 {
-	int i;
+	dev_t dev = inode->i_rdev;
+	struct gendisk *gd;
+	struct hd_struct *part;
+	int i, num, dpart;
 
 	DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n",
 		      command, (long)argument, inode->i_rdev);
 
+	gd = get_gendisk(dev, &dpart);
+	part = gd->part[MINOR(dev)];
+
 	switch (command) {
-	case HDIO_GETGEO:
-		/* return ENOSYS to use defaults */
-		return -ENOSYS;
+	case BLKGETSIZE:
+		DPRINTK_IOCTL(" BLKGETSIZE: %x %lx\n", BLKGETSIZE, part->nr_sects);
+		return put_user(part->nr_sects, (unsigned long *) argument);
+
+	case BLKGETSIZE64:
+		DPRINTK_IOCTL(" BLKGETSIZE64: %x %lx\n", BLKGETSIZE64, 
+			(u64)part->nr_sects * 512);
+		return put_user((u64)part->nr_sects * 512, (u64 *) argument);
 
 	case CDROMMULTISESSION:
 		DPRINTK("FIXME: support multisession CDs later\n");
linux-2.6-xen-sparse/drivers/xen/blkfront/block.h +1 -0
diff -ru xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h xen-unstable.hg.new/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h
@@ -138,6 +138,7 @@
 
 extern int blkif_open(struct inode *inode, struct file *filep);
 extern int blkif_release(struct inode *inode, struct file *filep);
+extern int blkif_getgeo(struct block_device *bdev, struct hd_geometry *geo);
 extern int blkif_ioctl(struct inode *inode, struct file *filep,
                        unsigned command, unsigned long argument);
 extern int blkif_check(dev_t dev);
linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c +1 -0
diff -ru xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c xen-unstable.hg.new/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c
@@ -91,6 +91,7 @@
 	.open = blkif_open,
 	.release = blkif_release,
 	.ioctl  = blkif_ioctl,
+	.getgeo  = blkif_getgeo,
 };
 
 spinlock_t blkif_io_lock = SPIN_LOCK_UNLOCKED;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

We did a similar patch recently here (not submitted, yet) - so I immediately see some concerns with your patch:

- Why do you need to add BLKGETSIZE and BLKGETSIZE64? block/ioctl.c is already taking care of those, they should never arrive at the driver.
- The calculation of the cylinder value seems odd to me. Why don't you use sector_div() here?
- There is an apparently unused variable 'dpart' left in blkif_getgeo().

Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Pascal Bouchareine <[email protected]> 15.05.06 20:15 >>>

Hi,

Adds HDIO_GETGEO, BLKGETSIZE, BLKGETSIZE64 support to blkfront.

An attempt to merge in the following sent previously by Ian Pratt :
http://lists.xensource.com/archives/html/xen-devel/2005-01/msg00659.html

Taking into account the block_device_operations for get_geom.

Regards,
Pascal

Signature · 2 lines
\o/   Pascal Bouchareine - Gandi 
 g    0170393757           15, place de la Nation - 75011 Paris      
#2 lore raw
Quoted 1 line · Jan Beulich

We did a similar patch recently here (not submitted, yet) - so I immediately see some concerns with your patch:

Thanks for your reply. When do you plan to submit the said patch ?

Understood for the 3 cons, I can remove the odd calls if required, just let me know if a modified patch is needed.

Regards,
Pascal

Signature · 2 lines
\o/   Pascal Bouchareine - Gandi 
 g    0170393757           15, place de la Nation - 75011 Paris      
#3 lore raw

Attaching our patch. Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Pascal Bouchareine <[email protected]> 16.05.06 09:35 >>>

Quoted 1 line · Jan Beulich

We did a similar patch recently here (not submitted, yet) - so I immediately see some concerns with your patch:

Thanks for your reply. When do you plan to submit the said patch ?

Understood for the 3 cons, I can remove the odd calls if required, just let me know if a modified patch is needed.

Regards,
Pascal

Signature · 2 lines
\o/   Pascal Bouchareine - Gandi 
 g    0170393757           15, place de la Nation - 75011 Paris      

Add backing support for HDIO_GETGEO ioctl to blkfront.

Inspired by an earlier patch from Charles Coffing.

drivers/xen/blkfront/blkfront.c +17 -4
Index: head-2006-05-11/drivers/xen/blkfront/blkfront.c
===================================================================
@@ -452,10 +452,6 @@ int blkif_ioctl(struct inode *inode, str
 		      command, (long)argument, inode->i_rdev);
 
 	switch (command) {
-	case HDIO_GETGEO:
-		/* return ENOSYS to use defaults */
-		return -ENOSYS;
-
 	case CDROMMULTISESSION:
 		DPRINTK("FIXME: support multisession CDs later\n");
 		for (i = 0; i < sizeof(struct cdrom_multisession); i++)
@@ -473,6 +469,23 @@ int blkif_ioctl(struct inode *inode, str
 }
 
 
+int blkif_getgeo(struct block_device *bd, struct hd_geometry *hg)
+{
+	/* We don't have real geometry info, but let's at least return
+	   values consistent with the size of the device */
+	sector_t nsect = get_capacity(bd->bd_disk);
+	sector_t cylinders = nsect;
+
+	hg->heads = 0xff;
+	hg->sectors = 0x3f;
+	sector_div(cylinders, hg->heads * hg->sectors);
+	hg->cylinders = cylinders;
+	if ((sector_t)(hg->cylinders + 1) * hg->heads * hg->sectors < nsect)
+		hg->cylinders = 0xffff;
+	return 0;
+}
+
+
 /*
  * blkif_queue_request
  *
drivers/xen/blkfront/block.h +1 -0
Index: head-2006-05-11/drivers/xen/blkfront/block.h
===================================================================
@@ -140,6 +140,7 @@ extern int blkif_open(struct inode *inod
 extern int blkif_release(struct inode *inode, struct file *filep);
 extern int blkif_ioctl(struct inode *inode, struct file *filep,
                        unsigned command, unsigned long argument);
+extern int blkif_getgeo(struct block_device *, struct hd_geometry *);
 extern int blkif_check(dev_t dev);
 extern int blkif_revalidate(dev_t dev);
 extern void do_blkif_request (request_queue_t *rq);
drivers/xen/blkfront/vbd.c +1 -0
Index: head-2006-05-11/drivers/xen/blkfront/vbd.c
===================================================================
@@ -91,6 +91,7 @@ static struct block_device_operations xl
 	.open = blkif_open,
 	.release = blkif_release,
 	.ioctl  = blkif_ioctl,
+	.getgeo = blkif_getgeo
 };
 
 spinlock_t blkif_io_lock = SPIN_LOCK_UNLOCKED;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel