linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Vlasov <vsu@altlinux.ru>
To: Steven Scholz <steven.scholz@imc-berlin.de>
Cc: linux-ide@vger.kernel.org
Subject: Re: hotplug event on fdisk?
Date: Sat, 16 Jul 2005 21:24:52 +0400	[thread overview]
Message-ID: <20050716212452.531e0a84.vsu@altlinux.ru> (raw)
In-Reply-To: <42D3E880.6060902@imc-berlin.de>

[-- 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 --]

  reply	other threads:[~2005-07-16 17:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-12 15:57 hotplug event on fdisk? Steven Scholz
2005-07-16 17:24 ` Sergey Vlasov [this message]
2005-07-18  6:49   ` Steven Scholz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050716212452.531e0a84.vsu@altlinux.ru \
    --to=vsu@altlinux.ru \
    --cc=linux-ide@vger.kernel.org \
    --cc=steven.scholz@imc-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).