linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: look up block device path in sysfs
@ 2008-01-26  5:04 Dan Williams
  2008-01-26 20:22 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2008-01-26  5:04 UTC (permalink / raw)
  To: akpm, jens.axboe; +Cc: neilb, kay.sievers, linux-kernel

Given an fd on a block device, returns a string like

	/block/sda/sda1

which can be used to find related information in /sys.

Ideally we should have an ioctl that works on char devices as well,
but that seems far from trivial, so it seems reasonable to have
this until the latter can be implemented.

Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Neil Brown <neilb@suse.de>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Things have been quiet since this was posted about a month ago, and I am
hoping to see this in 2.6.25.  It is based on Neil's BLKGETNAME patch
and is updated with Kay's comments.

Regards,
Dan

 block/compat_ioctl.c |    1 +
 block/ioctl.c        |   28 ++++++++++++++++++++++++++++
 include/linux/fs.h   |    1 +
 3 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index cae0a85..d71d287 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -784,6 +784,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 	switch (cmd) {
 	case HDIO_GETGEO:
 		return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
+	case BLKGETDEVPATH:
 	case BLKFLSBUF:
 	case BLKROSET:
 	/*
diff --git a/block/ioctl.c b/block/ioctl.c
index 52d6385..d048ae4 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -229,6 +229,34 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
 	int ret, n;
 
 	switch(cmd) {
+	case BLKGETDEVPATH: {
+		char *path;
+		char b[BDEVNAME_SIZE];
+		size_t len;
+
+		path = kobject_get_path(&disk->kobj, GFP_KERNEL);
+
+		if (!path)
+			return -ENOMEM;
+
+		len = strlen(path);
+		if (copy_to_user((char __user *)arg, path, len + 1)) {
+			kfree(path);
+			return -EFAULT;
+		}
+		kfree(path);
+
+		if (bdev->bd_contains == bdev)
+			return 0;
+
+		bdevname(bdev, b);
+		if (copy_to_user((char __user *)arg + len, "/", 2))
+			return -EFAULT;
+		if (copy_to_user((char __user *)arg + len + 1, b,
+				 strlen(b) + 1))
+			return -EFAULT;
+		return 0;
+	}
 	case BLKFLSBUF:
 		if (!capable(CAP_SYS_ADMIN))
 			return -EACCES;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b3ec4a4..b4cf8f3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -217,6 +217,7 @@ extern int dir_notify_enable;
 #define BLKTRACESTART _IO(0x12,116)
 #define BLKTRACESTOP _IO(0x12,117)
 #define BLKTRACETEARDOWN _IO(0x12,118)
+#define BLKGETDEVPATH _IOR(0x12, 119, char [1024])
 
 #define BMAP_IOCTL 1		/* obsolete - kept for compatibility */
 #define FIBMAP	   _IO(0x00,1)	/* bmap access */


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

* Re: [PATCH] block: look up block device path in sysfs
  2008-01-26  5:04 [PATCH] block: look up block device path in sysfs Dan Williams
@ 2008-01-26 20:22 ` Christoph Hellwig
  2008-01-28 18:43   ` Dan Williams
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2008-01-26 20:22 UTC (permalink / raw)
  To: Dan Williams; +Cc: akpm, jens.axboe, neilb, kay.sievers, linux-kernel, viro

On Fri, Jan 25, 2008 at 10:04:51PM -0700, Dan Williams wrote:
> Given an fd on a block device, returns a string like
> 
> 	/block/sda/sda1
> 
> which can be used to find related information in /sys.
> 
> Ideally we should have an ioctl that works on char devices as well,
> but that seems far from trivial, so it seems reasonable to have
> this until the latter can be implemented.

What did you do to address Viro's reasonable rejection of this when
it came up last time?


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

* Re: [PATCH] block: look up block device path in sysfs
  2008-01-26 20:22 ` Christoph Hellwig
@ 2008-01-28 18:43   ` Dan Williams
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Williams @ 2008-01-28 18:43 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: akpm, jens.axboe, neilb, kay.sievers, linux-kernel, viro

On Sat, 2008-01-26 at 13:22 -0700, Christoph Hellwig wrote:
> On Fri, Jan 25, 2008 at 10:04:51PM -0700, Dan Williams wrote:
> > Given an fd on a block device, returns a string like
> >
> >       /block/sda/sda1
> >
> > which can be used to find related information in /sys.
> >
> > Ideally we should have an ioctl that works on char devices as well,
> > but that seems far from trivial, so it seems reasonable to have
> > this until the latter can be implemented.
> 
> What did you do to address Viro's reasonable rejection of this when
> it came up last time?

What was the objection?

My search only came up with a discussion about possibly making this a
generic capability for all devices:
http://marc.info/?t=118646704500006&r=1&w=2

Regards,
Dan


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

end of thread, other threads:[~2008-01-28 18:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-26  5:04 [PATCH] block: look up block device path in sysfs Dan Williams
2008-01-26 20:22 ` Christoph Hellwig
2008-01-28 18:43   ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).