PATCH: fix block layer ioctl bug
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 13 lines · Alan Cox
The block layer checks for
-EINVALfrom block layer driver ioctls. This is wrong - ENOTTY is unknown and some drivers correctly use this. I suspect for an internal ioctl 2.7 should change to-ENOIOCTLCMDand bitch about old style returnsThis is conservative fix for the 2.6 case, it keeps the bogus
-EINVALto avoid breaking stuffdiff -u --new-file --recursive --exclude-from
/usr/src/excludelinux.vanilla-2.6.6/drivers/block/ioctl.clinux-2.6.6/drivers/block/ioctl.c
drivers/block/ioctl.c line 210
Quoted 9 lines
drivers/block/ioctl.c +2
-1@@ -203,7 +203,8 @@case BLKROSET :if (disk->fops->ioctl) { ret = disk->fops->ioctl (inode, file, cmd, arg); -if (ret != -EINVAL ) +/* -EINVAL to handle old uncorrected drivers */ +if (ret != -EINVAL && ret != -ENOTTY )return ret; }if (!capable (CAP_SYS_ADMIN ))
There's a case just above BLKROSET that seems to be in need of a similar change. In 2.6.8.1, on a BLKFLSBUF ioctl, if a driver returns -EINVAL, the block layer will call fsync_bdev, invalidate_bdev, and return 0. It only gets the default behavior if it's returning -EINVAL, though.
If returning -ENOTTY for unhandled ioctls is the correct thing for a driver to do, shouldn't the BLKFLSBUF ioctl sync the block device when the driver returns -ENOTTY?
If so, this patch follows the one above, supporting the drivers that return -ENOTTY correctly as well as the ones that still return -EINVAL, at least for now.
drivers/block/ioctl.c renamed from drivers/block/ioctl.c.20041001 +2 -1
@@ -192,11 +192,12 @@ int blkdev_ioctl(struct inode *inode, stcase BLKFLSBUF :if (!capable (CAP_SYS_ADMIN ))return -EACCES ;if (disk->fops->ioctl) { ret = disk->fops->ioctl (inode, file, cmd, arg); -if (ret != -EINVAL ) +/* -EINVAL to handle old uncorrected drivers */ +if (ret != -EINVAL && ret != -ENOTTY )return ret; }fsync_bdev (bdev);invalidate_bdev (bdev,0 );return 0 ;
Signature · 1 line
Ed L Cashin <[email protected]>