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

dm exception store: fix misordered writes

We must zero the next chunk on disk *before* writing out the current chunk, not
after. Otherwise if the machine crashes at the wrong time, the "end of metadata"
marker may be missing.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Cc: stable@kernel.org

authored by

Mikulas Patocka and committed by
Alasdair G Kergon
7acedc5b 7c9e6c17

+8 -3
+8 -3
drivers/md/dm-exception-store.c
··· 611 611 return; 612 612 613 613 /* 614 + * If we completely filled the current area, then wipe the next one. 615 + */ 616 + if ((ps->current_committed == ps->exceptions_per_area) && 617 + zero_disk_area(ps, ps->current_area + 1)) 618 + ps->valid = 0; 619 + 620 + /* 614 621 * Commit exceptions to disk. 615 622 */ 616 - if (area_io(ps, WRITE)) 623 + if (ps->valid && area_io(ps, WRITE)) 617 624 ps->valid = 0; 618 625 619 626 /* 620 627 * Advance to the next area if this one is full. 621 628 */ 622 629 if (ps->current_committed == ps->exceptions_per_area) { 623 - if (zero_disk_area(ps, ps->current_area + 1)) 624 - ps->valid = 0; 625 630 ps->current_committed = 0; 626 631 ps->current_area++; 627 632 zero_memory_area(ps);