Am 16.03.21 um 17:26 schrieb Alan Stern:
On Tue, Mar 16, 2021 at 06:26:30AM +0100, Matthias Schwarzott wrote:
I implemented solution 3b. This is the pullrequest for udev (systemd
repository):

        https://github.com/systemd/systemd/pull/19002

Now Lennart asks if udev is the best place for such hacks/work-arounds?

Well, I implemented it as suggested by Alan (see above). This was the
simplest of the considered alternatives. Different quirks in kernel has been
considered, but are more effort to be implemented.

Lennart probably isn't aware how the usb-storage driver works.  It does
not create commands on its own; it merely sends the commands that it
gets from higher SCSI layers.

It may be possible to modify the SCSI core, to make it send a TEST UNIT
READY command immediately following any SYNCHRONIZE CACHE to a Kindle.

However, there may be an easier solution.  usb-storage does indeed send
a command of its own, REQUEST SENSE, to get error data when a command
fails.  The patch below will make it do the same thing whenever it sends
a SYNCHRONIZE CACHE to a Kindle, failure or not.

The only question is whether the Kindle will regard REQUEST SENSE as a
sufficient indication that it shouldn't do an eject.  The only way to
find out is by testing the patch.


The patch is a lot shorter than I expected it to be.

I tried it. The new udev-rule is commented, so polling interval is back at 2000 ms.

Testing it:
# cat /sys/block/sde/events_poll_msecs
-1
# cat /sys/module/block/parameters/events_dfl_poll_msecs
2000
# python -c "import time; import os; f = open('/dev/sde1', 'r+b'); os.fsync(f); time.sleep(4)"

This is wireshark output of the test:

85      4.701949        host    3.8.1   USBMS   95      SCSI: Test Unit Ready 
LUN: 0x00
86      4.701972        3.8.1   host    USB     64      URB_BULK out
87      4.701975        host    3.8.1   USB     64      URB_BULK in
88 4.702030 3.8.1 host USBMS 77 SCSI: Response LUN: 0x00 (Test Unit Ready) (Good) 89 4.702043 host 3.8.1 USBMS 95 SCSI: Prevent/Allow Medium Removal LUN: 0x00 PREVENT
90      4.702069        3.8.1   host    USB     64      URB_BULK out
91      4.702072        host    3.8.1   USB     64      URB_BULK in
92 4.703006 3.8.1 host USBMS 77 SCSI: Response LUN: 0x00 (Prevent/Allow Medium Removal) (Good)

93 4.703052 host 3.8.1 USBMS 95 SCSI: Synchronize Cache(10) LUN: 0x00 (LBA: 0x00000000, Len: 0)
94      4.703066        3.8.1   host    USB     64      URB_BULK out
95      4.703067        host    3.8.1   USB     64      URB_BULK in
96 4.704146 3.8.1 host USBMS 77 SCSI: Response LUN: 0x00 (Synchronize Cache(10)) (Good)
97      4.704149        host    3.8.1   USBMS   95      SCSI: Request Sense 
LUN: 0x00
98      4.704177        3.8.1   host    USB     64      URB_BULK out
99      4.704179        host    3.8.1   USB     64      URB_BULK in
100 4.705032 3.8.1 host USBMS 82 SCSI: Data In LUN: 0x00 (Request Sense Response Data)
101     4.705035        host    3.8.1   USB     64      URB_BULK in
102 4.705053 3.8.1 host USBMS 77 SCSI: Response LUN: 0x00 (Request Sense) (Good)
105     6.740272        host    3.8.1   USBMS   95      SCSI: Test Unit Ready 
LUN: 0x00
106     6.740323        3.8.1   host    USB     64      URB_BULK out
107     6.740326        host    3.8.1   USB     64      URB_BULK in
108 6.740410 3.8.1 host USBMS 77 SCSI: Response LUN: 0x00 (Test Unit Ready) (Good) 195 8.709417 host 3.8.1 USBMS 95 SCSI: Prevent/Allow Medium Removal LUN: 0x00 ALLOW
196     8.709441        3.8.1   host    USB     64      URB_BULK out
197     8.709445        host    3.8.1   USB     64      URB_BULK in
198 8.709645 3.8.1 host USBMS 77 SCSI: Response LUN: 0x00 (Prevent/Allow Medium Removal) (Good)

The patch indeed works. The kindle does not disconnect.
I also tried with a sync on a mounted filesystem. The effect is the same: No disconnect.

Calling "eject /dev/sde" still works as it should.

Tested-by: Matthias Schwarzott <z...@gentoo.org>

Regards
Matthias
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to