From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 04 Nov 2004 02:44:28 +0000 Subject: add the physical device and the bus to the hotplug environment Message-Id: <20041104024428.GA17927@vrfy.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org Add the sysfs path of the physical device to the hotplug event of class and block devices. This should solve the userspace issue not to know if the device is a virtual one and the "device" symlink will never be created, but we sit there and wait for it to show up not knowing when we should give up. Also the bus name is added to the hotplug event, so we don't need to reverse lookup in the /sys/bus/* directory which bus our physical device belongs to. This is e.g. the value matched against the BUS=3D key, that may be used in an udev rule. This is a PCI network card: ACTION=ADd SUBSYSTEM=3Dnet DEVPATH=3D/class/net/eth0 PHYSDEVPATH=3D/devices/pci0000:00/0000:00:1e.0/0000:02:01.0 PHYSDEVBUS=3Dpci INTERFACE=3Deth0 SEQNUM=827 PATH=3D/sbin:/bin:/usr/sbin:/usr/bin HOME=3D/ This is a IDE CDROM: ACTION=ADd SUBSYSTEM=3Dblock DEVPATH=3D/block/hdc PHYSDEVPATH=3D/devices/pci0000:00/0000:00:1f.1/ide1/1.0 PHYSDEVBUS=3Dide SEQNUM=1017 PATH=3D/sbin:/bin:/usr/sbin:/usr/bin HOME=3D/ This is an USB-stick partition: ACTION=ADd SUBSYSTEM=3Dblock DEVPATH=3D/block/sda/sda1 PHYSDEVPATH=3D/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/host1/tar= get1:0:0/1:0:0:0 PHYSDEVBUS=3Dscsi SEQNUM=1032 PATH=3D/sbin:/bin:/usr/sbin:/usr/bin HOME=3D/ Signed-off-by: Kay Sievers =3D=3D=3D drivers/base/class.c 1.54 vs edited =3D=3D--- 1.54/drivers/base/c= lass.c 2004-10-08 20:32:52 +02:00 +++ edited/drivers/base/class.c 2004-11-04 01:57:19 +01:00 @@ -283,8 +283,34 @@ static int class_hotplug(struct kset *ks { struct class_device *class_dev =3D to_class_dev(kobj); int retval =3D 0; + int i =3D 0; + int length =3D 0; =20 pr_debug("%s - name =3D %s\n", __FUNCTION__, class_dev->class_id); + + if (class_dev->dev) { + /* add physical device, backing this device */ + struct device *dev =3D class_dev->dev; + char *path =3D kobject_get_path(&dev->kobj, GFP_KERNEL); + + add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, + &length, "PHYSDEVPATH=3D%s", path); + kfree(path); + + /* add bus name of physical device */ + if (dev->bus) + add_hotplug_env_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "PHYSDEVBUS=3D%s", dev->bus->name); + + /* terminate, set to next free slot, shrink available space */ + envp[i] =3D NULL; + envp =3D &envp[i]; + num_envp -=3D i; + buffer =3D &buffer[length]; + buffer_size -=3D length; + } + if (class_dev->class->hotplug) { /* have the bus specific function add its stuff */ retval =3D class_dev->class->hotplug (class_dev, envp, num_envp, =3D=3D=3D drivers/block/genhd.c 1.104 vs edited =3D=3D--- 1.104/drivers/blo= ck/genhd.c 2004-09-22 22:35:24 +02:00 +++ edited/drivers/block/genhd.c 2004-11-04 02:53:28 +01:00 @@ -438,8 +438,46 @@ static int block_hotplug_filter(struct k return ((ktype =3D &ktype_block) || (ktype =3D &ktype_part)); } =20 +static int block_hotplug(struct kset *kset, struct kobject *kobj, char **e= nvp, + int num_envp, char *buffer, int buffer_size) +{ + struct device *dev =3D NULL; + struct kobj_type *ktype =3D get_ktype(kobj); + int length =3D 0; + int i =3D 0; + + /* get physical device backing disk or partition */ + if (ktype =3D &ktype_block) { + struct gendisk *disk =3D container_of(kobj, struct gendisk, kobj); + dev =3D disk->driverfs_dev; + } else if (ktype =3D &ktype_part) { + struct gendisk *disk =3D container_of(kobj->parent, struct gendisk, kobj= ); + dev =3D disk->driverfs_dev; + } + + if (dev) { + /* add physical device, backing this device */ + char *path =3D kobject_get_path(&dev->kobj, GFP_KERNEL); + + add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, + &length, "PHYSDEVPATH=3D%s", path); + kfree(path); + + /* add bus name of physical device */ + if (dev->bus) + add_hotplug_env_var(envp, num_envp, &i, + buffer, buffer_size, &length, + "PHYSDEVBUS=3D%s", dev->bus->name); + + envp[i] =3D NULL; + } + + return 0; +} + static struct kset_hotplug_ops block_hotplug_ops =3D { - .filter =3D block_hotplug_filter, + .filter =3D block_hotplug_filter, + .hotplug =3D block_hotplug, }; =20 /* declare block_subsys. */ ------------------------------------------------------- This SF.Net email is sponsored by: Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux. http://ads.osdn.com/?ad_idU88&alloc_id=12065&op=3Dclick _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel