blkdev_ioctl--->blk_ioctl_discard(BLKDISCARD or BLKSECDISCARD).
If cmd is BLKSECDISCARD and device does not support this cmd,
we will drop page cache(should not be dropped) and return
EOPNOTSUPP to caller. This patch fixes that.

Fixes: 351499a172c0 ("block: Invalidate cache on discard v2")
Signed-off-by: zhengbin <[email protected]>
---
 block/ioctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/ioctl.c b/block/ioctl.c
index 4825c78..ee3a6af 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -212,6 +212,11 @@ static int blk_ioctl_discard(struct block_device *bdev, 
fmode_t mode,
        if (!blk_queue_discard(q))
                return -EOPNOTSUPP;

+       if (flags & BLKDEV_DISCARD_SECURE) {
+               if (!blk_queue_secure_erase(q))
+                       return -EOPNOTSUPP;
+       }
+
        if (copy_from_user(range, (void __user *)arg, sizeof(range)))
                return -EFAULT;

--
2.7.4

Reply via email to