Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm space map disk: fix some book keeping in the disk space map

When decrementing the reference count for a block, the free count wasn't
being updated if the reference count went to zero.

Cc: stable@vger.kernel.org
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Joe Thornber and committed by
Mike Snitzer
0377a07c 91bcdb92

+14 -1
+14 -1
drivers/md/persistent-data/dm-space-map-disk.c
··· 142 142 143 143 static int sm_disk_dec_block(struct dm_space_map *sm, dm_block_t b) 144 144 { 145 + int r; 146 + uint32_t old_count; 145 147 enum allocation_event ev; 146 148 struct sm_disk *smd = container_of(sm, struct sm_disk, sm); 147 149 148 - return sm_ll_dec(&smd->ll, b, &ev); 150 + r = sm_ll_dec(&smd->ll, b, &ev); 151 + if (!r && (ev == SM_FREE)) { 152 + /* 153 + * It's only free if it's also free in the last 154 + * transaction. 155 + */ 156 + r = sm_ll_lookup(&smd->old_ll, b, &old_count); 157 + if (!r && !old_count) 158 + smd->nr_allocated_this_transaction--; 159 + } 160 + 161 + return r; 149 162 } 150 163 151 164 static int sm_disk_new_block(struct dm_space_map *sm, dm_block_t *b)