Bug 7838
Summary: | Missing important feature: libata bus shutdown and device shutdown | ||
---|---|---|---|
Product: | IO/Storage | Reporter: | Henrique de Moraes Holschuh (hmh) |
Component: | Serial ATA | Assignee: | Tejun Heo (htejun) |
Status: | CLOSED CODE_FIX | ||
Severity: | normal | CC: | htejun, kernel-NTEO |
Priority: | P2 | ||
Hardware: | i386 | ||
OS: | Linux | ||
Kernel Version: | 2.6.x mainline | Subsystem: | |
Regression: | --- | Bisected commit-id: | |
Attachments: | implement-sd-stop-on-shutdown |
Description
Henrique de Moraes Holschuh
2007-01-16 17:27:56 UTC
Cache *is* synchronized prior to shutting down. It happens via sd->shutdown issuing SCSI SYNCHRONIZE_CACHE which gets translated into ATA_CMD_FLUSH[_EXT] as appropriate. Heads are unloaded properly on sleep to memory too. IIRC, sd_shutdown used to issue SCSI START_STOP command to stop (unload) drives. The command is translated into ATA_STANDBY which unloads the head. However, this behavior changed because of multipath SCSI devices. SCSI devices can be connected to multiple hosts and unloading heads when one host is going down causes problems to other hosts. I'll think about how to solve this. So, THERE IS *NO* DATA LOSS. CACHE IS *ALWAYS* SYNCHRONIZED BEFORE SHUTTING DOWN. I am *very* happy to hear this, and I apologise for the "lack of sync cache" misreport. I screwed up and paid too much attention to the libata side of things, and failed to check the scsi infrastructure properly, thus missing sd.c. I can also definately verify that indeed heads are being unloaded on S3. I assumed the ACPI BIOS was doing this, as S4 and S5 are not being properly handled [from a non-multipath device point of view]... another one to apologise for, I should never "assume" anything. The other points still stand, though: it would be nice to special case commands that unload heads/spin down devices/detach(ATA sleep) devices, so that we avoid spinning up devices to issue these commands, or worse, doing full EH and a ATA bus reset to wake up a detached/sleeping drive only to issue a unload head/spin down/sleep command to it... Also, doing a head unload on reboot would not be nice, as minimizing head unloads will increase device lifespan (especially on desktop drives), therefore whatever is done to fix the need for head unloads on poweroff issue should not cause head unloads or platter spindown on system restart, just on power off/halt. Indeed multipath causes several problems for the above. I'd say the only way to deal with multipath sanely would be to always assume a single path by default for the purposes of the above problems, and to have userspace interfaces capable of telling the kernel that a device is multipath, all the local paths (so that the kernel knows that all disc-specific device state for these paths is shared, even if bus states are not), and whether there are external paths or not. For all I know, most of this is already done by the multipath suite (I have no experience with multipath). Still, for the issues related to this bug report, multipath devices without external paths should probably have all the handling of a single path device, except that the kernel would need to avoid issuing the same set of commands to the device over the other local paths. It would be also EXTREMELY nice to know from userspace whether we need to attempt to issue cache flushes and disk standby commands on the halt(8) command or not (because the running kernel will do it). I'd would *very* much like to remove the utter gross crap in halt.c that deals with it in two or three years... is there a way to query the kernel, directly or indirectly, for this capability? My memory about sd used to stopping disks seems to be fabricated. I'm probably confusing with a discussion thread on linux-scsi. Anyways, I'm attaching a patch. It's against 2.6.20-rc5 but should also work with 2.6.19. The followings are added by the patch. * /sys/module/sd_mod/parameters/stop_on_shutdown_default * /sys/class/scsi_disk/h:c:i:l/stop_on_shutdown stop_on_shutdown_default defaults to zero and stop_on_shutdown's are initialized from it. To enable stop_on_shutdown globally, you first set stop_on_shutdown_default to 1 then set all present stop_on_shutdown to 1. If stop_on_shutdown for a disk is 1, sd will issue SCSI START_STOP command with START_VALID and START == 0 which tells the disk to stop on shutdown except for restart. As before, SYNCHRONIZE_CACHE is issued unconditionally which does not usually cause spinup on a spun down device. Would this be enough? If you ACK this, I'll try to push this mainline. Thanks. Created attachment 10122 [details]
implement-sd-stop-on-shutdown
Yes, it is enough. I would still prefer to have /sys/module/sd_mod/parameters/stop_on_shutdown_default set to 1 by default, as multipath is the less common setup (it is, in fact, rare when compared with non-multipath setups now that scsi also means SATA, and soon, PATA), and stop_on_shutdown_default=1 is the correct configuration for anything *but* multi-host multipath setups. But we can certainly set /sys/module/sd_mod/parameters/stop_on_shutdown_default properly in userspace, and it is *extremely* better than what we have now. Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> BTW: Thank you very much for the fast response to this bug :-) You're welcome. :-) I agree that it would be nicer to have 1 as the default 'default' value but I'm afraid we can't do that as that would change kernel behavior which userland might be relying on. Well, it's not like configuring this during boot is difficult. I'll submit the patch. Thanks. Oh.. BTW, s/multipath/multi initiator/. One question: What happened to this patch? I have a T60 here (AHCI) and needed to include this patch manually to be able to switch the device off cleanly (without SMART values disk_shift and power-off_retract_count increased). SCSI part is committed into mainline. libata part is still pending. This can appear in mainline 2.6.22 at the earliest. Thanks for your quick answer. Hope I don't bother you if I ask: I use linux-2.6.21-rc6-git4 here and had to apply the scsi part manually. When will this patch be applied to the source code (I know that I don't know the exact procedure for patch inclusion - sorry for that) It's in scsi-misc-2.6 tree that the SCSI maintainer maintains. It was late for 2.6.21 inclusion and will be merged into mainline during 2.6.22-rc1 cycle. This issue has been dealt with for a long time now. Any remaining fallout is being tracked separately on its own bug entries, so I am marking this bug closed. |