hotplug event on fdisk?
Hi,
I noticed that /sbin/hotplug is called by the kernel when I am doing
fdisk -l /dev/hda
to do a "remove" and then do "add" again:
~ # fdisk -l /dev/hdakobject_hotplugkobject_hotplug: /sbin/hotplug block seq=574 HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin ACTION=remove DEVPATH=/block/hda/hda1 SUBSYSTEM=block
hda: hda1kobject_hotplugkobject_hotplug: /sbin/hotplug block seq=575 HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin ACTION=add DEVPATH=/block/hda/hda1 SUBSYSTEM=block
Disk /dev/hda: 512 MB, 512483328 bytes
16 heads, 63 sectors/track, 993 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System/dev/hda1 * 1 993 500440+ 6 FAT16
Why is it so? And what is the system suposed to do? Actually remove the device?
--
Steven
Quoted 21 lines · On Tue, 12 Jul 2005 17:57:52 +0200 Steven Scholz wrote:
I noticed that
/sbin/hotplugis called by the kernel when I am doingfdisk -l
/dev/hdato do a "remove" and then do "add" again:
~ # fdisk -l
/dev/hdakobject_hotplugkobject_hotplug:/sbin/hotplugblock seq=574 HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin ACTION=remove DEVPATH=/block/hda/hda1 SUBSYSTEM=block
hda: hda1kobject_hotplugkobject_hotplug:/sbin/hotplugblock seq=575 HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin ACTION=add DEVPATH=/block/hda/hda1 SUBSYSTEM=blockDisk
/dev/hda: 512 MB, 512483328 bytes
16 heads, 63 sectors/track, 993 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Quoted 6 lines
Device Boot Start End Blocks Id System
/dev/hda1* 1 993 500440+ 6 FAT16Why is it so? And what is the system suposed to do? Actually remove the device?
Looking at the size of your device (512 MB), I guess that it is some king of flash drive. Such devices pretend to be removable hard disks - and here the "removable" bit causes trouble.
ide-disk.c:idedisk_open() has this code:
if (drive->removable && drive->usage == 1) {
... unrelated code for door locking ...
check_disk_change(inode->i_bdev);
...This code detects the opening of a previously unused removable device and checks if the disk was changed. check_disk_change() applied to an IDE disk device used idedisk_media_changed() to find out if the disk really was changed; this function is rather simple:
static int idedisk_media_changed(struct gendisk *disk)
{
struct ide_disk_obj *idkp = ide_disk_g(disk);
ide_drive_t *drive = idkp->drive;
/* do not scan partitions twice if this is a removable device */
if (drive->attach) {
drive->attach = 0;
return 0;
}
/* if removable, always assume it was changed */
return drive->removable;
}Seems that either IDE does not have a command to check for disk change, or such command is unreliable on many devices, or maybe the needed code is simply not implemented. Anyway, the end result is that every open of an otherwise unused removable IDE disk results in invalidation of the partition table - therefore you see all that hotplug events.
BTW, such behavior of the kernel also causes problems with, e.g., HAL (when HAL tries to look at the CompactFlash drive to find out what partitions does it contain, this results in hotplug events for all partitions; with some HAL versions and configurations this can result in an endless loop).
One possible workaround is to consider flash drives as non-removable in idedisk_media_changed(). For typical CompactFlash drives used with ide-cs, this is actually correct - the actual media is not removable from such drive, the IDE _controller_ is added and removed instead. However, I'm not sure if this would be correct for all possible configurations.
Anyway, here is the patch with such workaround for CompactFlash (against the current git tree, but it should also apply to earlier kernels with some fuzz).
---
Subject: [PATCH] Avoid superfluous rechecking of partitions for IDE flash drives
For some reason, IDE flash drives report that they have removable media, which is not really correct - the drive as a whole is removed, therefore rescanning of the partition table on the first open of such devices is just a waste of time.
drivers/ide/ide-disk.c +8 -0
@@ -1174,6 +1174,14 @@ static int idedisk_media_changed(structstruct ide_disk_obj *idkp =ide_disk_g (disk);ide_drive_t *drive = idkp->drive; +/* +* PCMCIA flash drives report themselves as removable, but can be +* treated as fixed - when such device is removed, its IDE controller +* also disappears. +*/ +if (drive->is_flash) +return 0 ; +/* do not scan partitions twice if this is a removable device */ if (drive->attach) { drive->attach =0 ;
Sergey,
Quoted 8 lines
Quoted 3 lines
...
Why is it so? And what is the system suposed to do? Actually remove the device?Looking at the size of your device (512 MB), I guess that it is some king of flash drive. Such devices pretend to be removable hard disks - and here the "removable" bit causes trouble.
Indeed I was talking about a CF Flash Card in a CF socket.
Quoted 23 lines
...
Anyway, here is the patch with such workaround for CompactFlash (against the current git tree, but it should also apply to earlier kernels with some fuzz).---
Subject: [PATCH] Avoid superfluous rechecking of partitions for IDE flash drivesFor some reason, IDE flash drives report that they have removable media, which is not really correct - the drive as a whole is removed, therefore rescanning of the partition table on the first open of such devices is just a waste of time.
Signed-off-by Sergey Vlasov <[email protected]>drivers/ide/ide-disk.c +1
-0@@ -1174,6 +1174,14 @@ static int idedisk_media_changed(structstruct ide_disk_obj *idkp =ide_disk_g (disk);ide_drive_t *drive = idkp->drive; +/*
drivers/ide/ide-disk.c static int idedisk_media_changed(struct · line 1187
Quoted 10 lines
drivers/ide/ide-disk.c +7
-0+* PCMCIA flash drives report themselves as removable, but can be +* treated as fixed - when such device is removed, its IDE controller +* also disappears. +*/ +if (drive->is_flash) +return 0 ; +/* do not scan partitions twice if this is a removable device */ if (drive->attach) { drive->attach =0 ;
Is "drive->is_flash" set for mechanical PCMCIA hard disk drives (like Microdrives) as well?
Signature · 1 line
Steven