1 From 37527b869207ad4c208b1e13967d69b8bba1fbf9 Mon Sep 17 00:00:00 2001
2 From: "Darrick J. Wong" <darrick.wong@oracle.com>
3 Date: Fri, 13 Feb 2015 11:05:37 -0800
4 Subject: dm io: reject unsupported DISCARD requests with EOPNOTSUPP
6 From: "Darrick J. Wong" <darrick.wong@oracle.com>
8 commit 37527b869207ad4c208b1e13967d69b8bba1fbf9 upstream.
10 I created a dm-raid1 device backed by a device that supports DISCARD
11 and another device that does NOT support DISCARD with the following
14 # echo '0 2048 mirror core 1 512 2 /dev/sda 0 /dev/sdb 0' | dmsetup create moo
16 NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
18 `-moo (dm-0) 0 4K 1G 0
20 `-moo (dm-0) 0 4K 1G 0
22 Notice that the mirror device /dev/mapper/moo advertises DISCARD
23 support even though one of the mirror halves doesn't.
25 If I issue a DISCARD request (via fstrim, mount -o discard, or ioctl
26 BLKDISCARD) through the mirror, kmirrord gets stuck in an infinite
27 loop in do_region() when it tries to issue a DISCARD request to sdb.
28 The problem is that when we call do_region() against sdb, num_sectors
29 is set to zero because q->limits.max_discard_sectors is zero.
30 Therefore, "remaining" never decreases and the loop never terminates.
32 To fix this: before entering the loop, check for the combination of
33 REQ_DISCARD and no discard and return -EOPNOTSUPP to avoid hanging up
36 This bug was found by the unfortunate coincidence of pvmove and a
37 discard operation in the RHEL 6.5 kernel; upstream is also affected.
39 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
40 Acked-by: "Martin K. Petersen" <martin.petersen@oracle.com>
41 Signed-off-by: Mike Snitzer <snitzer@redhat.com>
42 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45 drivers/md/dm-io.c | 6 ++++++
46 1 file changed, 6 insertions(+)
48 --- a/drivers/md/dm-io.c
49 +++ b/drivers/md/dm-io.c
50 @@ -290,6 +290,12 @@ static void do_region(int rw, unsigned r
51 unsigned short logical_block_size = queue_logical_block_size(q);
54 + /* Reject unsupported discard requests */
55 + if ((rw & REQ_DISCARD) && !blk_queue_discard(q)) {
56 + dec_count(io, region, -EOPNOTSUPP);
61 * where->count may be zero if rw holds a flush and we need to
62 * send a zero-sized flush.