Skip to content

Commit 263756e

Browse files
kaysieversgregkh
authored andcommitted
[PATCH] ide: MODALIAS support for autoloading of ide-cd, ide-disk, ...
IDE: MODALIAS support for autoloading of ide-cd, ide-disk, ... Add MODULE_ALIAS to IDE midlayer modules: ide-disk, ide-cd, ide-floppy and ide-tape, to autoload these modules depending on the probed media type of the IDE device. It is used by udev and replaces the former agent shell script of the hotplug package, which was required to lookup the media type in the proc filesystem. Using proc was racy, cause the media file is created after the hotplug event is sent out. The module autoloading does not take any effect, until something like the following udev rule is configured: SUBSYSTEM=="ide", ACTION=="add", ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe $env{MODALIAS}" The module ide-scsi will not be autoloaded, cause it requires manual configuration. It can't be, and never was supported for automatic setup in the hotplug package. Adding a MODULE_ALIAS to ide-scsi for all supported media types, would just lead to a default blacklist entry anyway. $ modinfo ide-disk filename: /lib/modules/2.6.15-rc4-g1b0997f5/kernel/drivers/ide/ide-disk.ko description: ATA DISK Driver alias: ide:*m-disk* license: GPL ... $ modprobe -vn ide:m-disk insmod /lib/modules/2.6.15-rc4-g1b0997f5/kernel/drivers/ide/ide-disk.ko $ cat /sys/bus/ide/devices/0.0/modalias ide:m-disk It also adds attributes to the IDE device: $ tree /sys/bus/ide/devices/0.0/ /sys/bus/ide/devices/0.0/ |-- bus -> ../../../../../../../bus/ide |-- drivename |-- media |-- modalias |-- power | |-- state | `-- wakeup `-- uevent $ cat /sys/bus/ide/devices/0.0/{modalias,drivename,media} ide:m-disk hda disk Signed-off-by: Kay Sievers <kay.sievers@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent f743ca5 commit 263756e

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

drivers/ide/ide-cd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,7 @@ static int __init ide_cdrom_init(void)
35093509
return driver_register(&ide_cdrom_driver.gen_driver);
35103510
}
35113511

3512+
MODULE_ALIAS("ide:*m-cdrom*");
35123513
module_init(ide_cdrom_init);
35133514
module_exit(ide_cdrom_exit);
35143515
MODULE_LICENSE("GPL");

drivers/ide/ide-disk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ static int __init idedisk_init(void)
12711271
return driver_register(&idedisk_driver.gen_driver);
12721272
}
12731273

1274+
MODULE_ALIAS("ide:*m-disk*");
12741275
module_init(idedisk_init);
12751276
module_exit(idedisk_exit);
12761277
MODULE_LICENSE("GPL");

drivers/ide/ide-floppy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,7 @@ static int __init idefloppy_init(void)
21972197
return driver_register(&idefloppy_driver.gen_driver);
21982198
}
21992199

2200+
MODULE_ALIAS("ide:*m-floppy*");
22002201
module_init(idefloppy_init);
22012202
module_exit(idefloppy_exit);
22022203
MODULE_LICENSE("GPL");

drivers/ide/ide-tape.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4947,6 +4947,7 @@ static int __init idetape_init(void)
49474947
return error;
49484948
}
49494949

4950+
MODULE_ALIAS("ide:*m-tape*");
49504951
module_init(idetape_init);
49514952
module_exit(idetape_exit);
49524953
MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR);

drivers/ide/ide.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,9 +1904,69 @@ static int ide_bus_match(struct device *dev, struct device_driver *drv)
19041904
return 1;
19051905
}
19061906

1907+
static char *media_string(ide_drive_t *drive)
1908+
{
1909+
switch (drive->media) {
1910+
case ide_disk:
1911+
return "disk";
1912+
case ide_cdrom:
1913+
return "cdrom";
1914+
case ide_tape:
1915+
return "tape";
1916+
case ide_floppy:
1917+
return "floppy";
1918+
default:
1919+
return "UNKNOWN";
1920+
}
1921+
}
1922+
1923+
static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
1924+
{
1925+
ide_drive_t *drive = to_ide_device(dev);
1926+
return sprintf(buf, "%s\n", media_string(drive));
1927+
}
1928+
1929+
static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
1930+
{
1931+
ide_drive_t *drive = to_ide_device(dev);
1932+
return sprintf(buf, "%s\n", drive->name);
1933+
}
1934+
1935+
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
1936+
{
1937+
ide_drive_t *drive = to_ide_device(dev);
1938+
return sprintf(buf, "ide:m-%s\n", media_string(drive));
1939+
}
1940+
1941+
static struct device_attribute ide_dev_attrs[] = {
1942+
__ATTR_RO(media),
1943+
__ATTR_RO(drivename),
1944+
__ATTR_RO(modalias),
1945+
__ATTR_NULL
1946+
};
1947+
1948+
static int ide_uevent(struct device *dev, char **envp, int num_envp,
1949+
char *buffer, int buffer_size)
1950+
{
1951+
ide_drive_t *drive = to_ide_device(dev);
1952+
int i = 0;
1953+
int length = 0;
1954+
1955+
add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
1956+
"MEDIA=%s", media_string(drive));
1957+
add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
1958+
"DRIVENAME=%s", drive->name);
1959+
add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
1960+
"MODALIAS=ide:m-%s", media_string(drive));
1961+
envp[i] = NULL;
1962+
return 0;
1963+
}
1964+
19071965
struct bus_type ide_bus_type = {
19081966
.name = "ide",
19091967
.match = ide_bus_match,
1968+
.uevent = ide_uevent,
1969+
.dev_attrs = ide_dev_attrs,
19101970
.suspend = generic_ide_suspend,
19111971
.resume = generic_ide_resume,
19121972
};

0 commit comments

Comments
 (0)