Package: util-linux
Version: 2.38.1-5+b1
Severity: normal
Tags: upstream

Many devices has maximum discard size, DISC-MAX in `lsblk --discard` output.
However, blkdiscard by default is doing full-device discard, which is also
specified in its manual page.  This results in errors and some drivers turning
discard support off.  For example:

# cat 
/sys/devices/pci0000:00/0000:00:02.1/0000:01:00.0/usb2/2-4/2-4:1.0/host6/target6:0:0/6:0:0:0/scsi_disk/6:0:0:0/provisioning_mode
unmap
# lsblk --discard
NAME        DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                0      512B       4G         0

# blkdiscard -f -l 4G /dev/sda
blkdiscard: Operation forced, data will be lost!
#### this works

# blkdiscard -f -l 5G /dev/sda
blkdiscard: /dev/sda: BLKDISCARD ioctl failed: Remote I/O error

# cat 
/sys/devices/pci0000:00/0000:00:02.1/0000:01:00.0/usb2/2-4/2-4:1.0/host6/target6:0:0/6:0:0:0/scsi_disk/6:0:0:0/provisioning_mode
disabled

Kernel log:

[217264.437619] sd 6:0:0:0: [sda] tag#8 FAILED Result: hostbyte=DID_OK 
driverbyte=DRIVER_OK cmd_age=0s
[217264.437632] sd 6:0:0:0: [sda] tag#8 Sense Key : Illegal Request [current] 
[217264.437638] sd 6:0:0:0: [sda] tag#8 Add. Sense: Invalid field in cdb
[217264.437645] sd 6:0:0:0: [sda] tag#8 CDB: Unmap/Read sub-channel 42 00 00 00 
00 00 00 00 18 00
[217264.437648] critical target error, dev sda, sector 134217728 op 
0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 2

Having said this, I'm not really sure who's in charge here.
Maybe it is the kernel driver who should split the large request into smaller 
parts.

But the end result is that whole thing stops working (and some devices even fall
off the usb bus and needs to be re-set).  And for quite some times I was sure
discard/trim is not supported on USB-connected devices at all, just because this
quick blkdiscard test always fails like this, - and I thought it is the command
which is illegal, not its parameter.

Reply via email to