Skip to contentSkip to conversation

2.6.x libata bug fix

PATCH In review Jeff Garzik 2 participants 4 messages Oct 26, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.6.x libata bug fix

When I added ioctl handling, I returned EOPNOTSUPP for the "I didn't recognize that ioctl you wanted to execute" return code.

The block layer will execute certain ioctl operations IFF the low-level driver returns ENOTTY, signalling to the block layer that that driver does not support the specified ioctl.

The net effect of libata returning EOPNOTSUPP was such that it __broke__ BLSFLSBUF ioctl, simply by implementing ->ioctl.

So, we return the proper return code, and ioctls we don't handle start to work again. Overall, though, this is a fragile way to do things in the block layer, IMHO.

Please do a

bk pull bk://gkernel.bkbits.net/libata-2.6

This will update the following files:

 drivers/scsi/libata-scsi.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

through these ChangeSets:

<[email protected]> (04/10/26 1.2068)
[libata] return ENOTTY rather than EOPNOTSUPP for unknown-ioctl

drivers/scsi/libata-scsi.c +1 -1
diff -Nru a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
@@ -97,7 +97,7 @@
 		return 0;
 
 	default:
-		rc = -EOPNOTSUPP;
+		rc = -ENOTTY;
 		break;
 	}
 
#1 lore raw
Quoted 8 lines · Jeff Garzik

When I added ioctl handling, I returned EOPNOTSUPP for the "I didn't recognize that ioctl you wanted to execute" return code.

The block layer will execute certain ioctl operations IFF the low-level driver returns ENOTTY, signalling to the block layer that that driver does not support the specified ioctl.

Quoted 6 lines

The net effect of libata returning EOPNOTSUPP was such that it __broke__ BLSFLSBUF ioctl, simply by implementing ->ioctl.

So, we return the proper return code, and ioctls we don't handle start to work again. Overall, though, this is a fragile way to do things in the block layer, IMHO.

Well, it's pretty much the universally accepted way of signalling this information, I'm not sure I agree. The crappy part is that EINVAL is so wide spread as well.

And EOPNOTSUPP just shows you are a networking whore as well :-)

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 9 lines · Jens Axboe
Quoted 3 lines · Jeff Garzik

So, we return the proper return code, and ioctls we don't handle start to work again. Overall, though, this is a fragile way to do things in the block layer, IMHO.

Well, it's pretty much the universally accepted way of signalling this information, I'm not sure I agree. The crappy part is that EINVAL is so wide spread as well.

My point is that most Linux APIs don't apply default behavior by means of a magic return code.

Each block/scsi/etc. driver should provide their own ioctl handler as the highest-level callback. Then, each individual driver decides its fallback strategy for unknown ioctls -- in most cases, by calling "libata_ioctl" or "scsi_ioctl" or "block_ioctl".

In this manner, ioctl handling cascades naturally up through the layers, without magic return codes.

The current "top-down" ioctl handling implementation leads to the current situation: a bunch of ->ioctl() callsites scattered through the generic block ioctl handling code.

Jeff

#3 lore raw
Quoted 15 lines · Jeff Garzik
Quoted 9 lines · Jens Axboe
Quoted 3 lines · Jeff Garzik

So, we return the proper return code, and ioctls we don't handle start to work again. Overall, though, this is a fragile way to do things in the block layer, IMHO.

Well, it's pretty much the universally accepted way of signalling this information, I'm not sure I agree. The crappy part is that EINVAL is so wide spread as well.

My point is that most Linux APIs don't apply default behavior by means of a magic return code.

Quoted 7 lines

Each block/scsi/etc. driver should provide their own ioctl handler as the highest-level callback. Then, each individual driver decides its fallback strategy for unknown ioctls -- in most cases, by calling "libata_ioctl" or "scsi_ioctl" or "block_ioctl".

In this manner, ioctl handling cascades naturally up through the layers, without magic return codes.

But it doesn't quite work so well if you are a device/driver that needs to call several of these functions - you get the same problem, you need to know when it was accepted or when to pass it on. Or you need to know every single ioctl. Maybe you can kill it in the driver, but you need it at least some place in the stack.

Quoted 3 lines

The current "top-down" ioctl handling implementation leads to the current situation: a bunch of ->ioctl() callsites scattered through the generic block ioctl handling code.

It is a bit messy in places, I agree. But I don't think this has anything to do with it using -ENOTTY as a special magic "I dunno what you are talking about", rather it just needs a little cleanup action.

Honestly, I don't think -ENOTTY is so nasty. It's been described a number of times in various places, it should be common knowledge for anyone doing a linux/unix driver.

Signature · 1 line
Jens Axboe