Search This Blog

Wednesday, July 27, 2011

E-sata, solid, and udisks (part 2)


In my first post about e-sata, solid and udisks I wrote about how to hack udisks to inform solid that a disk attached to a specified sata port is actually a removable disk. Udisks-1.0.3 includes a modified patch that allows to do that without applying the patch ourselves. We still need to add the udev rule to indicate which sata port is to be considered "non system internal". The udev rules is slightly diferent from the one I wrote about in my last Solid post:

File /etc/udev/rules.d/99-esata.rules
DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"

Change the DEVPATH to match your e-sata port. You can find it using the command:

Code
evolucao ~ # find /sys/devices/ -name sdb
/sys/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdb


Then reload udev rules after creating/editing the file above: udevadm control --reload-rules

Now the bad news: udisks includes several attributes to a disk, among then are "system internal" and "removable". Removable means removable media (like optical discs, card readers, etc). System internal means the device is "fixed" to the computer, it cannot be removed without turning the computer off, like sata disks. E-sata is in between those two, for sure it is not system internal and technically it is not removable media according to udisks criteria too.

Currently Solid uses udisks' eject command to eject e-sata disks but since an e-sata disk is not removable media and the disk has not actually been removed (detached from the e-sata port) udisks signals that a new disk is available and kded remounts the disk right after the eject command succeeds (bug #277517).


We could use udisks' detach command instead of eject, but udisks seems to refuse to use it with devices with removable flag set to false, which is the case for e-sata disks. Anyway, sometimes we just want to unmount the partition but not turn the disk off, in that case udisks' detach command is inadequate since you will need to turn the disk off and on to use it again.

I think:  1. Solid should stop using udisks' eject command for e-sata partitions (/dev/sdb1, /dev/sdb2, etc) and use the umount command instead. 2. For the entire e-sata disk (/dev/sdb) we should use udisks' detach command, but that will only work when 3. someone fixes udisks to allow executing the detach command for all non system internal devices and not only for the removable ones.

We can do #1 right now. #2 requires some GUI to call the detach command, something that can be used in device notifier plasmoid. #3 is upstream bug :-/

When I have more time I will try to solve this, but for now I am busy and with a dead line approaching, so if someone wants to take the task to fix this problem feel free to do it.

12 comments:

Anonymous said...

I agree that a solution is needed, but how is sata not a removable media? It is hot-plug, so you can add/remove disks to your hearts content.

Just because people consider a (sata)disk internal/fixed doesn't mean that it is...

Lamarque said...

Sata is not removable, removable media, nor hotpluggable. E-sata is hotpluggable and removable, but not removable media.

Take card readers as example, some of them are pci based and as so they are not hotpluggable (the reader, not the card), but they are removable media because you can insert and remove the media (the card) to/from them. They can be removable or not depending on if they are soldered to the motherboard or not.

Some card readers are USB based and as so they are hotpluggable, removable and removable media at the same time.

E-sata is not removable media (you cannot remove the internal disks) but is hotpluggable and removable (you can remove the entire device).

Have you seen the difference between removable and removable media?

Tecnhically flash drives are also non removable media, but most device drivers consider them as so. Udisks could consider e-sata as removable media too, that would let's us detach e-sata disks.

Lamarque said...

Oops, I forget that in some cases you cannot remove the USB card readers physically, just hot unplug them from the USB bus. So USB card readers can also be not removable, actually several laptops' card readers are like that.

Anonymous said...

by wiki (don't have time to do serious research):

"[...] both SATA and eSATA support hot-swapping by design. However, this feature requires proper support at the host, device (drive), and operating-system level. In general, all SATA devices (drives) support hot-swapping (due to the requirements on the device-side), also most SATA host adapters support this command [...]"

Lamarque said...

Ok, maybe technically sata supports hotplugging but most people do not use it like that.

vivo said...

what are the costs in considering all devices as removable?

Lamarque said...

@vivo, the user could accidentally detach the disk where the root partition resides. The computer would crash and data loss could happen too.

Anonymous said...

It is not expedient to distinguish SATA and eSATA. Both are hotpluggable like USB and should be handled like USB.

Also the discussion "internal vs. external" is senseless. There are also internal USB devices and no way to detect them (worse: you can detach them and then there is no way to reconnect them without a power cycle). Hotswapping SATA drives using mobile racks is daily business for many people.

Some misguided developers want to treat (e)SATA like the old PATA. This is plain wrong. Ask the SATA controller if he supports hotplug/hotswap and then mark all its devices as detachable. Period.

BTW: You can have the root partition on a detachable disk by just booting from USB. The right way to solve this, is not detaching disks with busy mounted partitions. Marking them as "fixed" by the interface type is wrong.

Lamarque said...

@Anonymous, it is not me that treats e-sata as non-removable and create the distinguis between "internal" and "external", udisks does. If you disagree you should talk to udisks' developers, I cannot do much about it.

My proposal is to treat e-sata like USB. But unlike USB devices, e-sata devices supports the detach command, which should be used instead of the eject command used in USB disks because of the problem I described in my post.

"Some misguided developers want to treat (e)SATA like the old PATA. This is plain wrong. Ask the SATA controller if he supports hotplug/hotswap and then mark all its devices as detachable. Period."

That does not always work and by the time I created the post not even the Linux kernel supported the "e-sata" bit to indicate the port is e-sata.

"BTW: You can have the root partition on a detachable disk by just booting from USB. The right way to solve this, is not detaching disks with busy mounted partitions. Marking them as "fixed" by the interface type is wrong."

Again: talk to udisks' developers, it is not me that is doing that. I am just trying to overcome a problem using what I have.

cyberbeat said...

Why does windows handle this right?
With windows-7 my e-sata disk is handled like an usb disk, without manually setting such flags as "removable/internal/..".

Lamarque said...

@cyberbeat, it is not Windows that handles this right. The e-sata controller manufacturers create the device drivers so that the driver indicates that the port is e-sata capable, so this is transparent to anyone who uses that driver. As everybody knows most manufacturers still do not botter to implement descent drivers for Linux. Until the kernel developers implement that support in kernel the only solution is set the flag manually, which the system internal flag is all about.

Jean-Marc Ranger said...

Works perfectly for my ExpressCard CompactFlash adapter, for which I had a hal fix similar to yours that no longer work on Debian Wheezy. I posted some details in Debian bug 635756.

Thank you !