login
Header Space

 
 

Re: What to do about the 2TB limit on HDIO_GETGEO ?

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: H. Peter Anvin <hpa@...>
Cc: Kay Sievers <kay.sievers@...>, Tejun Heo <htejun@...>, Mark Lord <lkml@...>, Greg KH <gregkh@...>, Jens Axboe <axboe@...>, Jeff Garzik <jgarzik@...>, Linus Torvalds <torvalds@...>, Andrew Morton <akpm@...>, Linux Kernel <linux-kernel@...>, IDE/ATA development list <linux-ide@...>, linux-scsi <linux-scsi@...>
Date: Friday, April 11, 2008 - 7:25 pm

On Thu, Mar 27, 2008 at 12:38 PM, H. Peter Anvin <hpa@zytor.com> wrote:

This thread fizzled out without a patch... here goes:

[ note: I'm replying via gmail, so if it has whitespace mangled the
patch please see the attachment ]

-----snip---->
sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor

From: Dan Williams <dan.j.williams@intel.com>

Why?:
There are occasions where userspace would like to access sysfs
attributes for a device but it may not know how sysfs has named the
device or the path.  For example what is the sysfs path for
/dev/disk/by-id/ata-ST3160827AS_5MT004CK?  With this change a call to
stat(2) returns the major:minor then userspace can see that
/sys/dev/block/8:32 links to /sys/block/sdc.

What are the alternatives?:
1/ Add an ioctl to return the path: Doable, but sysfs is meant to reduce
   the need to proliferate ioctl interfaces into the kernel, so this
   seems counter productive.

2/ Use udev to create these symlinks: Also doable, but it adds a
   udev dependency to utilities that might be running in a limited
   environment like an initramfs.

Cc: NeilBrown <neilb@suse.de>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Greg KH <gregkh@suse.de>
Cc: Mark Lord <lkml@rtr.ca>
Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---

 drivers/base/core.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)


diff --git a/drivers/base/core.c b/drivers/base/core.c
index 24198ad..de925f8 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -27,6 +27,9 @@

 int (*platform_notify)(struct device *dev) = NULL;
 int (*platform_notify_remove)(struct device *dev) = NULL;
+static struct kobject *dev_kobj;
+static struct kobject *char_kobj;
+static struct kobject *block_kobj;

 #ifdef CONFIG_BLOCK
 static inline int device_is_not_partition(struct device *dev)
@@ -759,6 +762,11 @@ static void device_remove_class_symlinks(struct
device *dev)
 	sysfs_remove_link(&dev->kobj, "subsystem");
 }

+static struct kobject *device_to_dev_kobj(struct device *dev)
+{
+	return dev->class == &block_class ? block_kobj : char_kobj;
+}
+
 /**
  * device_add - add device to device hierarchy.
  * @dev: device.
@@ -775,6 +783,7 @@ int device_add(struct device *dev)
 	struct device *parent = NULL;
 	struct class_interface *class_intf;
 	int error;
+	char devt_str[25];

 	dev = get_device(dev);
 	if (!dev || !strlen(dev->bus_id)) {
@@ -806,9 +815,16 @@ int device_add(struct device *dev)
 		goto attrError;

 	if (MAJOR(dev->devt)) {
+		struct kobject *kobj = device_to_dev_kobj(dev);
+
 		error = device_create_file(dev, &devt_attr);
 		if (error)
 			goto ueventattrError;
+
+		format_dev_t(devt_str, dev->devt);
+		error = sysfs_create_link(kobj, &dev->kobj, devt_str);
+		if (error)
+			goto devtattrError;
 	}

 	error = device_add_class_symlinks(dev);
@@ -854,6 +870,9 @@ int device_add(struct device *dev)
 	device_remove_class_symlinks(dev);
  SymlinkError:
 	if (MAJOR(dev->devt))
+		sysfs_remove_link(device_to_dev_kobj(dev), devt_str);
+ devtattrError:
+	if (MAJOR(dev->devt))
 		device_remove_file(dev, &devt_attr);
  ueventattrError:
 	device_remove_file(dev, &uevent_attr);
@@ -925,12 +944,16 @@ void device_del(struct device *dev)
 {
 	struct device *parent = dev->parent;
 	struct class_interface *class_intf;
+	char devt_str[25];

 	device_pm_remove(dev);
 	if (parent)
 		klist_del(&dev->knode_parent);
-	if (MAJOR(dev->devt))
+	if (MAJOR(dev->devt)) {
+		format_dev_t(devt_str, dev->devt);
+		sysfs_remove_link(device_to_dev_kobj(dev), devt_str);
 		device_remove_file(dev, &devt_attr);
+	}
 	if (dev->class) {
 		device_remove_class_symlinks(dev);

@@ -1055,6 +1078,15 @@ int __init devices_init(void)
 	devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
 	if (!devices_kset)
 		return -ENOMEM;
+	dev_kobj = kobject_create_and_add("dev", NULL);
+	if (!dev_kobj)
+		return -ENOMEM;
+	block_kobj = kobject_create_and_add("block", dev_kobj);
+	if (!block_kobj)
+		return -ENOMEM;
+	char_kobj = kobject_create_and_add("char", dev_kobj);
+	if (!char_kobj)
+		return -ENOMEM;
 	return 0;
 }

@@ -1380,4 +1412,7 @@ void device_shutdown(void)
 			dev->driver->shutdown(dev);
 		}
 	}
+	kobject_put(char_kobj);
+	kobject_put(block_kobj);
+	kobject_put(dev_kobj);
 }
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
What to do about the 2TB limit on HDIO_GETGEO ?, Mark Lord, (Tue Mar 25, 12:02 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, James Bottomley, (Tue Mar 25, 11:17 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Greg Freemyer, (Tue Mar 25, 1:45 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Matt Domsch, (Sun Mar 30, 12:28 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Randy Dunlap, (Tue Mar 25, 1:52 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Matthew Wilcox, (Tue Mar 25, 2:09 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Boaz Harrosh, (Wed Mar 26, 5:58 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Mark Lord, (Tue Mar 25, 1:31 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, James Bottomley, (Tue Mar 25, 3:32 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Tue Mar 25, 1:13 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Mark Lord, (Tue Mar 25, 9:37 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Tue Mar 25, 9:55 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Mark Lord, (Tue Mar 25, 1:37 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Mark Lord, (Tue Mar 25, 8:34 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Kay Sievers, (Thu Mar 27, 2:51 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Thu Mar 27, 2:55 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Kay Sievers, (Thu Mar 27, 3:03 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Tejun Heo, (Tue Mar 25, 8:54 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Kay Sievers, (Thu Mar 27, 3:29 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Thu Mar 27, 3:38 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Dan Williams, (Fri Apr 11, 7:25 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Andrew Morton, (Tue Apr 15, 3:18 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, James Bottomley, (Tue Apr 15, 10:20 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Tue Apr 15, 2:16 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Dan Williams, (Tue Apr 15, 7:43 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Mark Lord, (Tue Apr 15, 9:47 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Tejun Heo, (Wed Mar 26, 12:24 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Wed Mar 26, 2:04 am)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Randy Dunlap, (Tue Mar 25, 3:34 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Tue Mar 25, 4:36 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Tue Mar 25, 5:26 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Matthew Wilcox, (Thu Mar 27, 3:05 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, H. Peter Anvin, (Tue Mar 25, 7:05 pm)
Re: What to do about the 2TB limit on HDIO_GETGEO ?, Andrew Morton, (Tue Mar 25, 12:19 am)
speck-geostationary