git: db860eb348ad - main - umass: Document the ideal that it's better to fail bad commands

From: Warner Losh <imp_at_FreeBSD.org>
Date: Wed, 07 May 2025 21:37:06 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=db860eb348ad20e4c4be09c9b65cdf0a3b1b57c2

commit db860eb348ad20e4c4be09c9b65cdf0a3b1b57c2
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2025-05-07 16:07:11 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-05-07 21:36:54 +0000

    umass: Document the ideal that it's better to fail bad commands
    
    Generally, lying to the periph drivers about commands working is a bad
    idea. They cannot get a global insight into the actual capacities of
    the device when commands just work. There's good reason to intercept
    bad commands at times, and to prevent the device from being exposed to
    commands that, for example, hand the device. However, upper layer
    periph drivers is the better place to cope with devices that don't
    support the commands since it can make other inferences about the
    device when it has wider knowledge.
    
    But this represents a change in philosphy, so document that as
    well. This shift happened for some commands a while ago. Many of the
    quirks existed only to avoid whining errors on boot that were benign
    and were a big burden. So da and cd slowly stopped the whining. Except
    in cases where the command hangs the drive, we should limit new quirks
    and avoid overly broad quirks (things work, but are less performant or
    reliable, again mostly to avoid harmless errors that are no longer
    printed).
    
    Other sims will likely need some help with this.
    
    Differential Revision:  https://reviews.freebsd.org/D49467
    Sponsored by:           Netflix
---
 sys/dev/usb/storage/umass.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sys/dev/usb/storage/umass.c b/sys/dev/usb/storage/umass.c
index 0a62e97a07fe..8922b3770e6a 100644
--- a/sys/dev/usb/storage/umass.c
+++ b/sys/dev/usb/storage/umass.c
@@ -2230,6 +2230,13 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
 			 * command format needed by the specific command set
 			 * and return the converted command in
 			 * "sc->sc_transfer.cmd_data"
+			 *
+			 * For commands we know the device doesn't support, we
+			 * either complete them with an illegal request, or fake
+			 * the completion, based on what upper layers tolerate.
+			 * Ideally, we'd let the periph drivers know and not
+			 * fake things up, but some periphs fall short of the
+			 * ideal.
 			 */
 			if (umass_std_transform(sc, ccb, cmd, ccb->csio.cdb_len)) {
 				if (sc->sc_transfer.cmd_data[0] == INQUIRY) {