public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@us.ibm.com>
To: dm-devel@redhat.com, Chris McDermott <lcm@us.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] Support HDIO_GETGEO on device-mapper volumes
Date: Thu, 09 Feb 2006 17:35:12 -0800	[thread overview]
Message-ID: <43EBEDD0.60608@us.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1370 bytes --]

Hi again,

I'm trying to install grub on a device-mapper RAID1 array that I set up 
via dmraid (in other words, a bootable software fakeraid).  Since dm 
doesn't implement the HDIO_GETGEO ioctl, grub assumes that the CHS 
geometry is 620/128/63, which makes it impossible to configure it to 
boot a filesystem that lives beyond the 2GB mark, even if the system 
BIOS supports that.

The attached patch implements a simple ioctl handler that supplies a 
compatible geometry when HDIO_GETGEO is called against a device-mapper 
device.  Its behavior is somewhat similar to what sd_mod does if the 
scsi controller doesn't provide its own geometry.  Granted, the notion 
of cylinders, heads and sectors is silly on a RAID array, but with this 
patch, interested programs can obtain CHS data that's somewhat close to 
correct; this seems to be a better option than having each program make 
up its own potentially different geometry, or making an arbitrary guess. 
  Assuming that all of the programs that need to know CHS geometry will 
query the kernel via HDIO_GETGEO, this patch makes it so that all of 
those programs end up using the same geometry.

The patch applies cleanly against 2.6.15.3; if there aren't any 
objections then I'm submitting this for upstream.  However, I'm all ears 
for suggestions.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>

--Darrick

[-- Attachment #2: dm-getgeo_1.patch --]
[-- Type: text/x-patch, Size: 1751 bytes --]

diff -Naurp a/drivers/md/dm.c b/drivers/md/dm.c
--- a/drivers/md/dm.c	2006-01-14 22:16:02.000000000 -0800
+++ b/drivers/md/dm.c	2006-02-09 14:05:18.000000000 -0800
@@ -17,6 +17,7 @@
 #include <linux/mempool.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
+#include <linux/hdreg.h>
 
 static const char *_name = DM_NAME;
 
@@ -223,6 +224,47 @@ static int dm_blk_close(struct inode *in
 	return 0;
 }
 
+static int dm_blk_ioctl(struct inode * inode, struct file * filp,
+			unsigned int cmd, unsigned long arg)
+{
+	struct block_device *bdev = inode->i_bdev;
+	struct hd_geometry __user *loc = (void __user *)arg;
+	struct mapped_device *md;
+	int diskinfo[4];
+
+	if (cmd == HDIO_GETGEO) {
+		if (!arg)
+			return -EINVAL;
+
+		/* Make up some fake geometry. */
+		md = bdev->bd_disk->private_data;
+		diskinfo[0] = 0x40;	/* 1 << 6 */
+		diskinfo[1] = 0x20;	/* 1 << 5 */
+		diskinfo[2] = md->disk->capacity >> 11;
+		diskinfo[3] = 0;
+
+		/* cylinder count too big? */
+		if (diskinfo[2] > 65536) {
+			diskinfo[0] = 255;
+			diskinfo[1] = 63;
+			diskinfo[2] = md->disk->capacity / 16065; /* 255*63 */
+		}
+
+		if (put_user(diskinfo[0], &loc->heads))
+			return -EFAULT;
+		if (put_user(diskinfo[1], &loc->sectors))
+			return -EFAULT;
+		if (put_user(diskinfo[2], &loc->cylinders))
+			return -EFAULT;
+		if (put_user(diskinfo[3], &loc->start))
+			return -EFAULT;
+
+		return 0;
+	}
+
+	return -ENOTTY;
+}
+
 static inline struct dm_io *alloc_io(struct mapped_device *md)
 {
 	return mempool_alloc(md->io_pool, GFP_NOIO);
@@ -1179,6 +1221,7 @@ int dm_suspended(struct mapped_device *m
 static struct block_device_operations dm_blk_dops = {
 	.open = dm_blk_open,
 	.release = dm_blk_close,
+	.ioctl = dm_blk_ioctl,
 	.owner = THIS_MODULE
 };
 

             reply	other threads:[~2006-02-10  1:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-10  1:35 Darrick J. Wong [this message]
2006-02-10  2:58 ` [PATCH] Support HDIO_GETGEO on device-mapper volumes Andrew Morton
2006-02-10  5:15 ` Phillip Susi
2006-02-10  8:14   ` Darrick J. Wong
2006-02-10 15:14     ` Phillip Susi
2006-02-10 14:53 ` Alasdair G Kergon
2006-02-10 15:12   ` Phillip Susi
2006-02-10 20:27     ` Molle Bestefich
2006-02-10 21:21       ` Phillip Susi
2006-02-20 18:09         ` Molle Bestefich
2006-02-20 21:30           ` Phillip Susi
2006-02-21 13:30             ` Molle Bestefich
2006-02-21 16:02               ` Phillip Susi
2006-02-10 15:13   ` [PATCH] " Alasdair G Kergon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43EBEDD0.60608@us.ibm.com \
    --to=djwong@us.ibm.com \
    --cc=dm-devel@redhat.com \
    --cc=lcm@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox