]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.10.30/dm-space-map-metadata-fix-bug-in-resizing-of-thin-metadata.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.10.30 / dm-space-map-metadata-fix-bug-in-resizing-of-thin-metadata.patch
1 From fca028438fb903852beaf7c3fe1cd326651af57d Mon Sep 17 00:00:00 2001
2 From: Joe Thornber <ejt@redhat.com>
3 Date: Tue, 21 Jan 2014 11:07:32 +0000
4 Subject: dm space map metadata: fix bug in resizing of thin metadata
5
6 From: Joe Thornber <ejt@redhat.com>
7
8 commit fca028438fb903852beaf7c3fe1cd326651af57d upstream.
9
10 This bug was introduced in commit 7e664b3dec431e ("dm space map metadata:
11 fix extending the space map").
12
13 When extending a dm-thin metadata volume we:
14
15 - Switch the space map into a simple bootstrap mode, which allocates
16 all space linearly from the newly added space.
17 - Add new bitmap entries for the new space
18 - Increment the reference counts for those newly allocated bitmap
19 entries
20 - Commit changes to disk
21 - Switch back out of bootstrap mode.
22
23 But, the disk commit may allocate space itself, if so this fact will be
24 lost when switching out of bootstrap mode.
25
26 The bug exhibited itself as an error when the bitmap_root, with an
27 erroneous ref count of 0, was subsequently decremented as part of a
28 later disk commit. This would cause the disk commit to fail, and thinp
29 to enter read_only mode. The metadata was not damaged (thin_check
30 passed).
31
32 The fix is to put the increments + commit into a loop, running until
33 the commit has not allocated extra space. In practise this loop only
34 runs twice.
35
36 With this fix the following device mapper testsuite test passes:
37 dmtest run --suite thin-provisioning -n thin_remove_works_after_resize
38
39 Signed-off-by: Joe Thornber <ejt@redhat.com>
40 Signed-off-by: Mike Snitzer <snitzer@redhat.com>
41 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
42
43 ---
44 drivers/md/persistent-data/dm-space-map-metadata.c | 18 ++++++++++++++----
45 1 file changed, 14 insertions(+), 4 deletions(-)
46
47 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
48 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
49 @@ -617,13 +617,23 @@ static int sm_metadata_extend(struct dm_
50 if (r)
51 goto out;
52
53 - for (i = old_len; !r && i < smm->begin; i++) {
54 - r = sm_ll_inc(&smm->ll, i, &ev);
55 + /*
56 + * We repeatedly increment then commit until the commit doesn't
57 + * allocate any new blocks.
58 + */
59 + do {
60 + for (i = old_len; !r && i < smm->begin; i++) {
61 + r = sm_ll_inc(&smm->ll, i, &ev);
62 + if (r)
63 + goto out;
64 + }
65 + old_len = smm->begin;
66 +
67 + r = sm_ll_commit(&smm->ll);
68 if (r)
69 goto out;
70 - }
71
72 - r = sm_metadata_commit(sm);
73 + } while (old_len != smm->begin);
74
75 out:
76 /*