]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.19.2/dm-io-reject-unsupported-discard-requests-with-eopnotsupp.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.19.2 / dm-io-reject-unsupported-discard-requests-with-eopnotsupp.patch
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
5
6 From: "Darrick J. Wong" <darrick.wong@oracle.com>
7
8 commit 37527b869207ad4c208b1e13967d69b8bba1fbf9 upstream.
9
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
12 dm configuration:
13
14 # echo '0 2048 mirror core 1 512 2 /dev/sda 0 /dev/sdb 0' | dmsetup create moo
15 # lsblk -D
16 NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
17 sda 0 4K 1G 0
18 `-moo (dm-0) 0 4K 1G 0
19 sdb 0 0B 0B 0
20 `-moo (dm-0) 0 4K 1G 0
21
22 Notice that the mirror device /dev/mapper/moo advertises DISCARD
23 support even though one of the mirror halves doesn't.
24
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.
31
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
34 the mirror device.
35
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.
38
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>
43
44 ---
45 drivers/md/dm-io.c | 6 ++++++
46 1 file changed, 6 insertions(+)
47
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);
52 sector_t num_sectors;
53
54 + /* Reject unsupported discard requests */
55 + if ((rw & REQ_DISCARD) && !blk_queue_discard(q)) {
56 + dec_count(io, region, -EOPNOTSUPP);
57 + return;
58 + }
59 +
60 /*
61 * where->count may be zero if rw holds a flush and we need to
62 * send a zero-sized flush.