* hotplug event on fdisk?
@ 2005-07-12 15:57 Steven Scholz
2005-07-16 17:24 ` Sergey Vlasov
0 siblings, 1 reply; 3+ messages in thread
From: Steven Scholz @ 2005-07-12 15:57 UTC (permalink / raw)
To: linux-ide
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/hda
kobject_hotplug
kobject_hotplug: /sbin/hotplug block seq=574 HOME=/
PATH=/sbin:/bin:/usr/sbin:/usr/bin ACTION=remove DEVPATH=/block/hda/hda1
SUBSYSTEM=block
hda: hda1
kobject_hotplug
kobject_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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: hotplug event on fdisk?
2005-07-12 15:57 hotplug event on fdisk? Steven Scholz
@ 2005-07-16 17:24 ` Sergey Vlasov
2005-07-18 6:49 ` Steven Scholz
0 siblings, 1 reply; 3+ messages in thread
From: Sergey Vlasov @ 2005-07-16 17:24 UTC (permalink / raw)
To: Steven Scholz; +Cc: linux-ide
[-- Attachment #1: Type: text/plain, Size: 4017 bytes --]
On Tue, 12 Jul 2005 17:57:52 +0200 Steven Scholz wrote:
> 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/hda
> kobject_hotplug
> kobject_hotplug: /sbin/hotplug block seq=574 HOME=/
> PATH=/sbin:/bin:/usr/sbin:/usr/bin ACTION=remove DEVPATH=/block/hda/hda1
> SUBSYSTEM=block
> hda: hda1
> kobject_hotplug
> kobject_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?
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.
Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -1174,6 +1174,14 @@ static int idedisk_media_changed(struct
struct 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;
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: hotplug event on fdisk?
2005-07-16 17:24 ` Sergey Vlasov
@ 2005-07-18 6:49 ` Steven Scholz
0 siblings, 0 replies; 3+ messages in thread
From: Steven Scholz @ 2005-07-18 6:49 UTC (permalink / raw)
To: Sergey Vlasov; +Cc: linux-ide
Sergey,
>> ...
>>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.
> ...
> 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.
>
> Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
>
> diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
> --- a/drivers/ide/ide-disk.c
> +++ b/drivers/ide/ide-disk.c
> @@ -1174,6 +1174,14 @@ static int idedisk_media_changed(struct
> struct 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;
Is "drive->is_flash" set for mechanical PCMCIA hard disk drives (like
Microdrives) as well?
--
Steven
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-07-18 6:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-12 15:57 hotplug event on fdisk? Steven Scholz
2005-07-16 17:24 ` Sergey Vlasov
2005-07-18 6:49 ` Steven Scholz
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).