dm: add dm-power-fail target
Subsystems (4)
RFC PATCH 1/1 dm: add dm-power-fail target
Hello,
I'm hoping some FS guys can weigh in and verify my approach for testing power fail conditions, and the DM guys to of course verify I didn't completely fail at making a DM target. All suggestions welcome, I want to have a nice robust tool for testing power fail so we can be sure our fsync/commit code is all working properly. Thanks,
Josef
For power fail testing we want to be able to catch cases where the fs isn't waiting for IO to complete properly. This target aims to do this by creating a linear mapping on a device and keeping track of all WRITEs and FLUSH/FUA operations. Any WRITEs are added to a global list on completion, then when we submit a FLUSH this list is spliced onto the request and once that request completes then it marks those blocks as valid. FUA bypasses this logic altogether and is considered valid once it completes. There are two modes of operation here
1) Zero - any WRITE that wasn't flushed will return 0's when we try to read from it. This is meant for BTRFS (or any COW fs) where we only write blocks once, so if we try to read a block we didn't properly flush then we can just send back 0's.
2) Split - the device is split in half and written to alternating sides. This is for overwriting fs'es (ext*/xfs). Once a FLUSH occurs we walk all the completed WRITEs and set their mirror to whichever mirror they last wrote to. Anything that wasn't flushed properly will point to its previous mirror.
We then have 3 different power fail events we can do
1) DROP_WRITES - just drop all writes immediately, any new writes are immediately completed and outstanding ones are treated as if they never completed.
2) DROP_AFTER_FUA - this allows a FUA to go through, and as soon as it completes we drop all writes. This is meant to be really evil about making sure your commit code is doing the right thing by dropping at the worst possible moment.
3) DROP_AFTER_FLUSH - this allows a FLUSH to go through, and as soon as it completes we drop all writes. This can be good for testing fdatasync on overwrite fs'es that may only issue a FLUSH and not have to update metadata.
There is also an option to return -EIO as soon as we have our power fail event to make it easier to script stress tests.
The idea is to be as evil as possible wrt how a device's cache would react to a powerfail event. I had originally bolted this onto dm-flakey but it got complicated trying to work in these new options with its original behavior so I created a new target instead.
--- drivers/md/Kconfig | 14 + drivers/md/Makefile | 1 + drivers/md/dm-power-fail.c | 691 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 706 insertions(+) create mode 100644 drivers/md/dm-power-fail.c
drivers/md/Kconfig +14 -0
@@ -432,4 +432,18 @@ config DM_SWITCH If unsure, say N. +config DM_POWER_FAIL + tristate "Power fail target support" + depends on BLK_DEV_DM + ---help--- + This device-mapper target creates a device that can be used for + testing a file systems ability to survive power fails. There are + several modes of operation in order to test a variety of power fail + scenarios. + + To compile this code as a module, choos M here: the module will be + called dm-power-fail. + + If unsure, say N. + endif # MD
drivers/md/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_DM_CACHE) += dm-cache.o obj-$(CONFIG_DM_CACHE_MQ) += dm-cache-mq.o obj-$(CONFIG_DM_CACHE_CLEANER) += dm-cache-cleaner.o obj-$(CONFIG_DM_ERA) += dm-era.o +obj-$(CONFIG_DM_POWER_FAIL) += dm-power-fail.o ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o
drivers/md/dm-power-fail.c new file +691 -0
691 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 7 lines · Josef Bacik
Hello,
I'm hoping some FS guys can weigh in and verify my approach for testing power fail conditions, and the DM guys to of course verify I didn't completely fail at making a DM target. All suggestions welcome, I want to have a nice robust tool for testing power fail so we can be sure our fsync/commit code is all working properly. Thanks,
*All* suggestions welcome? OK, I'll put on my skeptic hat.
This implements a writeback cache in kernel data structures so that you can race to throw away cached blocks that haven't been flushed. How is that meaningfully different than using an actual writeback caching dm target and racing to invalidate it?
Using real caching dm target configurations would let you reuse their testing and corner case handling that is, presumably, already slightly more advanced than printk() swearing.
Implementation of this specific mechanism aside, the architectural observation is that device ram disappearing during a power interruption is just one, and possibly the most forgiving, outcome. Pulling the power out from under concurrnet cached writes can result in any combination of them being written, or not, or scrambled to the point of returning read errors.
If we were to justify developing a specific power failure target, I'd like to see something that tracks write history and can replay the history to offer a resonably exhaustive set of possible write results. Verify *those* and you have much more confidence that the file system can handle reading the results of its interrupted writes.
- z
Quoted 9 lines · Zach Brown
Quoted 7 lines · Josef Bacik
Hello,
I'm hoping some FS guys can weigh in and verify my approach for testing power fail conditions, and the DM guys to of course verify I didn't completely fail at making a DM target. All suggestions welcome, I want to have a nice robust tool for testing power fail so we can be sure our fsync/commit code is all working properly. Thanks,
Quoted 6 lines
*All* suggestions welcome? OK, I'll put on my skeptic hat.
This implements a writeback cache in kernel data structures so that you can race to throw away cached blocks that haven't been flushed. How is that meaningfully different than using an actual writeback caching dm target and racing to invalidate it?
I didn't think of the dm-cache target, but do we want to add data loss testing code to something people actually use in production? I feel like that's a recipe for disaster. I suppose it could work, but my target adds some specific scenarios like blow up after FUA/FLUSH to test for specific races.
Quoted 5 lines
Using real caching dm target configurations would let you reuse their testing and corner case handling that is, presumably, already slightly more advanced than
printk()swearing.
Well that's just an unfair jab, I missed _one_ debug printk.
Quoted 7 lines
Implementation of this specific mechanism aside, the architectural observation is that device ram disappearing during a power interruption is just one, and possibly the most forgiving, outcome. Pulling the power out from under concurrnet cached writes can result in any combination of them being written, or not, or scrambled to the point of returning read errors.
So that's what this target tries to get around, we don't care about what happens to the data that is outstanding, we act like it never happened, because if we are going to rely on reading that data at all then we've already lost. So simply acting like it disappeared is just as bad as it being garbage or returning an EIO (though returning an EIO would be pretty cool too and easily be added to the target).
Quoted 5 lines
If we were to justify developing a specific power failure target, I'd like to see something that tracks write history and can replay the history to offer a resonably exhaustive set of possible write results. Verify *those* and you have much more confidence that the file system can handle reading the results of its interrupted writes.
This sounds like a pretty cool idea, it would be weird trying to order everything out though to catch problems where we don't properly wait on IO to complete before we do flushing. You'd probably have to keep track of when things were submitted and when they completed in the log in order to replay them in a way to expose problems with the flushing. But you're right it would allow us to more exhaustively test all different scenarios. Thanks,
Josef
Quoted 10 lines
Quoted 4 lines
This implements a writeback cache in kernel data structures so that you can race to throw away cached blocks that haven't been flushed. How is that meaningfully different than using an actual writeback caching dm target and racing to invalidate it?
I didn't think of the dm-cache target, but do we want to add data loss testing code to something people actually use in production? I feel like that's a recipe for disaster. I suppose it could work, but my target adds some specific scenarios like blow up after FUA/FLUSH to test for specific races.
I don't know if we'd even need code changes. Can't you forcibly fiddle with the target tables to remove the caching target at any point? No hablo dm.
Quoted 6 lines
Quoted 4 lines
Using real caching dm target configurations would let you reuse their testing and corner case handling that is, presumably, already slightly more advanced than
printk()swearing.Well that's just an unfair jab, I missed _one_ debug printk.
And it was a hilarious printk :).
Quoted 6 lines
Quoted 5 lines
If we were to justify developing a specific power failure target, I'd like to see something that tracks write history and can replay the history to offer a resonably exhaustive set of possible write results. Verify *those* and you have much more confidence that the file system can handle reading the results of its interrupted writes.
Quoted 6 lines
This sounds like a pretty cool idea, it would be weird trying to order everything out though to catch problems where we don't properly wait on IO to complete before we do flushing. You'd probably have to keep track of when things were submitted and when they completed in the log in order to replay them in a way to expose problems with the flushing. But you're right it would allow us to more exhaustively test all different scenarios.
Well, I think it'd be more about tracking write submission and flush completion to maintain sets of writes that could have become persistent in any order. Then you provide an interface for iterating over devices that represent possible persistent outcomes.
Say you have a tree of flush events and each flush has a tree of blocks that were dirty at the time of the flush. After the flush you can walk the blocks and record their tree position (or maintain them with the _augmented callbacks.)
Then each device full of possible outcomes can be described by the flush event and a giant bitmap with a few bits { .written, .corrupt } for each block version in the flush. Satisfy reads of a block by walking back through the flushes. Blocks in the current flush look up their tree
position in the device state bitmap to find their fate. The most
recent dirty block in completed flushes is used, otherwise the backing device is used if you're building from an existing known state.
Iterate over possible device states of write outcomes by adding bits with carry in the giant bitmap. (complexity++ for using the bitmaps to represent which of multiple versions of one block should be used..)
Something like that, anyway. Email is easy :).
It'd be interesting to see how far a simple prototype could go that keeps everything in memory and has sane static limits on how much history it tracks.
- z
Quoted 59 lines · Zach Brown
Quoted 10 lines
Quoted 4 lines
This implements a writeback cache in kernel data structures so that you can race to throw away cached blocks that haven't been flushed. How is that meaningfully different than using an actual writeback caching dm target and racing to invalidate it?
I didn't think of the dm-cache target, but do we want to add data loss testing code to something people actually use in production? I feel like that's a recipe for disaster. I suppose it could work, but my target adds some specific scenarios like blow up after FUA/FLUSH to test for specific races.
I don't know if we'd even need code changes. Can't you forcibly fiddle with the target tables to remove the caching target at any point? No hablo dm.
Quoted 6 lines
Quoted 4 lines
Using real caching dm target configurations would let you reuse their testing and corner case handling that is, presumably, already slightly more advanced than
printk()swearing.Well that's just an unfair jab, I missed _one_ debug printk.
And it was a hilarious printk :).
Quoted 6 lines
Quoted 5 lines
If we were to justify developing a specific power failure target, I'd like to see something that tracks write history and can replay the history to offer a resonably exhaustive set of possible write results. Verify *those* and you have much more confidence that the file system can handle reading the results of its interrupted writes.
Quoted 6 lines
This sounds like a pretty cool idea, it would be weird trying to order everything out though to catch problems where we don't properly wait on IO to complete before we do flushing. You'd probably have to keep track of when things were submitted and when they completed in the log in order to replay them in a way to expose problems with the flushing. But you're right it would allow us to more exhaustively test all different scenarios.
Well, I think it'd be more about tracking write submission and flush completion to maintain sets of writes that could have become persistent in any order. Then you provide an interface for iterating over devices that represent possible persistent outcomes.
Say you have a tree of flush events and each flush has a tree of blocks that were dirty at the time of the flush. After the flush you can walk the blocks and record their tree position (or maintain them with the
_augmentedcallbacks.)Then each device full of possible outcomes can be described by the flush event and a giant bitmap with a few bits { .written, .corrupt } for each block version in the flush. Satisfy reads of a block by walking back through the flushes. Blocks in the current flush look up their tree
position in the device state bitmap to find their fate. The most
recent dirty block in completed flushes is used, otherwise the backing device is used if you're building from an existing known state.Iterate over possible device states of write outcomes by adding bits with carry in the giant bitmap. (complexity++ for using the bitmaps to represent which of multiple versions of one block should be used..)
Quoted 6 lines
Something like that, anyway. Email is easy :).
It'd be interesting to see how far a simple prototype could go that keeps everything in memory and has sane static limits on how much history it tracks.
That is way complicated, I was just going to take two devices, one that's a linear mapping and the other that's the log, and then write to the log the sector+data that was written in order that it completes, and then have userspace do the replay. So basically do the flush tracking like I am, then write out chunks to the log device to keep a semblance of how the flushing would have affected stuff, something like this
write a, write b, a complete, flush, b complete, flush complete
would log out
wrote a, flush, write b, <other writes>, <next flush>
and then we have a userspace thing that could do something like replay all writes to a flush, do fs consistency and data consistency checks, walk to the next flush, rinse repeat, and that way we could be sure that we always have a consistent fs. This would make it easier to check complex fs operations (like btrfs's balance) without having to come up with special hacks in those operations to check them. I like this better because it's less DM code which means less swearing printks, but whichever we think will be the best thing for this sort of testing. Thanks,
Josef
Quoted 11 lines · Josef Bacik
On 11/24/2014 02:57 PM, Zach Brown wrote:
That is way complicated, I was just going to take two devices, one that's a linear mapping and the other that's the log, and then write to the log the sector+data that was written in order that it completes, and then have userspace do the replay. So basically do the flush tracking like I am, then write out chunks to the log device to keep a semblance of how the flushing would have affected stuff, something like this
write a, write b, a complete, flush, b complete, flush complete
would log out
wrote a, flush, write b, <other writes>, <next flush>
and then we have a userspace thing that could do something like replay all writes to a flush, do fs consistency and data consistency checks, walk to the next flush, rinse repeat, and that way we could be sure that we always have a consistent fs. This would make it easier to check complex fs operations (like btrfs's balance) without having to come up with special hacks in those operations to check them. I like this better because it's less DM code which means less swearing printks, but whichever we think will be the best thing for this sort of testing. Thanks,
I vote for whatever is the easiest to fit in our little programmer brains. The more complex the tool, the less we'll trust it.
-chris
Quoted 76 lines · Josef Bacik
Quoted 59 lines · Zach Brown
Quoted 10 lines
Quoted 4 lines
This implements a writeback cache in kernel data structures so that you can race to throw away cached blocks that haven't been flushed. How is that meaningfully different than using an actual writeback caching dm target and racing to invalidate it?
I didn't think of the dm-cache target, but do we want to add data loss testing code to something people actually use in production? I feel like that's a recipe for disaster. I suppose it could work, but my target adds some specific scenarios like blow up after FUA/FLUSH to test for specific races.
I don't know if we'd even need code changes. Can't you forcibly fiddle with the target tables to remove the caching target at any point? No hablo dm.
Quoted 6 lines
Quoted 4 lines
Using real caching dm target configurations would let you reuse their testing and corner case handling that is, presumably, already slightly more advanced than
printk()swearing.Well that's just an unfair jab, I missed _one_ debug printk.
And it was a hilarious printk :).
Quoted 6 lines
Quoted 5 lines
If we were to justify developing a specific power failure target, I'd like to see something that tracks write history and can replay the history to offer a resonably exhaustive set of possible write results. Verify *those* and you have much more confidence that the file system can handle reading the results of its interrupted writes.
Quoted 6 lines
This sounds like a pretty cool idea, it would be weird trying to order everything out though to catch problems where we don't properly wait on IO to complete before we do flushing. You'd probably have to keep track of when things were submitted and when they completed in the log in order to replay them in a way to expose problems with the flushing. But you're right it would allow us to more exhaustively test all different scenarios.
Well, I think it'd be more about tracking write submission and flush completion to maintain sets of writes that could have become persistent in any order. Then you provide an interface for iterating over devices that represent possible persistent outcomes.
Say you have a tree of flush events and each flush has a tree of blocks that were dirty at the time of the flush. After the flush you can walk the blocks and record their tree position (or maintain them with the
_augmentedcallbacks.)Then each device full of possible outcomes can be described by the flush event and a giant bitmap with a few bits { .written, .corrupt } for each block version in the flush. Satisfy reads of a block by walking back through the flushes. Blocks in the current flush look up their tree
position in the device state bitmap to find their fate. The most
recent dirty block in completed flushes is used, otherwise the backing device is used if you're building from an existing known state.Iterate over possible device states of write outcomes by adding bits with carry in the giant bitmap. (complexity++ for using the bitmaps to represent which of multiple versions of one block should be used..)
Quoted 6 lines
Something like that, anyway. Email is easy :).
It'd be interesting to see how far a simple prototype could go that keeps everything in memory and has sane static limits on how much history it tracks.
That is way complicated, I was just going to take two devices, one that's a linear mapping and the other that's the log, and then write to the log the sector+data that was written in order that it completes, and then have userspace do the replay. So basically do the flush tracking like I am, then write out chunks to the log device to keep a semblance of how the flushing would have affected stuff, something like this
write a, write b, a complete, flush, b complete, flush complete
Quoted 8 lines
would log out
wrote a, flush, write b, <other writes>, <next flush>
and then we have a userspace thing that could do something like replay all writes to a flush, do fs consistency and data consistency checks, walk to the next flush, rinse repeat, and that way we could be sure that we always have a consistent fs.
I guess that'd be an ok start, but I don't think you need any clever kernel code to do that. I've hacked up something like this in bash with blktrace, loopback files, and dd :/.
What I'm trying to say with this thread is that I think that only testing persistence in the order of submission or completion, and especially only around flushes, makes life too easy for the fs. It doesn't reflect the real device state that users can be stuck with. For example, I think we should test only b being written in that first sequence you describe.
Maybe I'll throw something together to try and demonstrate what I'm on about.
- z
Quoted 81 lines · Zach Brown
Quoted 80 lines · Josef Bacik
Quoted 59 lines · Zach Brown
Quoted 10 lines
Quoted 4 lines
This implements a writeback cache in kernel data structures so that you can race to throw away cached blocks that haven't been flushed. How is that meaningfully different than using an actual writeback caching dm target and racing to invalidate it?
I didn't think of the dm-cache target, but do we want to add data loss testing code to something people actually use in production? I feel like that's a recipe for disaster. I suppose it could work, but my target adds some specific scenarios like blow up after FUA/FLUSH to test for specific races.
I don't know if we'd even need code changes. Can't you forcibly fiddle with the target tables to remove the caching target at any point? No hablo dm.
Quoted 6 lines
Quoted 4 lines
Using real caching dm target configurations would let you reuse their testing and corner case handling that is, presumably, already slightly more advanced than
printk()swearing.Well that's just an unfair jab, I missed _one_ debug printk.
And it was a hilarious printk :).
Quoted 6 lines
Quoted 5 lines
If we were to justify developing a specific power failure target, I'd like to see something that tracks write history and can replay the history to offer a resonably exhaustive set of possible write results. Verify *those* and you have much more confidence that the file system can handle reading the results of its interrupted writes.
Quoted 6 lines
This sounds like a pretty cool idea, it would be weird trying to order everything out though to catch problems where we don't properly wait on IO to complete before we do flushing. You'd probably have to keep track of when things were submitted and when they completed in the log in order to replay them in a way to expose problems with the flushing. But you're right it would allow us to more exhaustively test all different scenarios.
Well, I think it'd be more about tracking write submission and flush completion to maintain sets of writes that could have become persistent in any order. Then you provide an interface for iterating over devices that represent possible persistent outcomes.
Say you have a tree of flush events and each flush has a tree of blocks that were dirty at the time of the flush. After the flush you can walk the blocks and record their tree position (or maintain them with the
_augmentedcallbacks.)Then each device full of possible outcomes can be described by the flush event and a giant bitmap with a few bits { .written, .corrupt } for each block version in the flush. Satisfy reads of a block by walking back through the flushes. Blocks in the current flush look up their tree
position in the device state bitmap to find their fate. The most
recent dirty block in completed flushes is used, otherwise the backing device is used if you're building from an existing known state.Iterate over possible device states of write outcomes by adding bits with carry in the giant bitmap. (complexity++ for using the bitmaps to represent which of multiple versions of one block should be used..)
Quoted 6 lines
Something like that, anyway. Email is easy :).
It'd be interesting to see how far a simple prototype could go that keeps everything in memory and has sane static limits on how much history it tracks.
That is way complicated, I was just going to take two devices, one that's a linear mapping and the other that's the log, and then write to the log the sector+data that was written in order that it completes, and then have userspace do the replay. So basically do the flush tracking like I am, then write out chunks to the log device to keep a semblance of how the flushing would have affected stuff, something like this
write a, write b, a complete, flush, b complete, flush complete
would log out
wrote a, flush, write b, <other writes>, <next flush>
Quoted 8 lines
Quoted 4 lines
and then we have a userspace thing that could do something like replay all writes to a flush, do fs consistency and data consistency checks, walk to the next flush, rinse repeat, and that way we could be sure that we always have a consistent fs.
I guess that'd be an ok start, but I don't think you need any clever kernel code to do that. I've hacked up something like this in bash with blktrace, loopback files, and dd :/.
I don't think blktrace gives us the data being written though does it? If it does then hooray I'm done playing a device mapper developer.
Quoted 11 lines
What I'm trying to say with this thread is that I think that only testing persistence in the order of submission or completion, and especially only around flushes, makes life too easy for the fs. It doesn't reflect the real device state that users can be stuck with. For example, I think we should test only b being written in that first sequence you describe.
Maybe I'll throw something together to try and demonstrate what I'm on about.
Sure it's a really simple test, but what I currently have rigged up just does random writes+fsync and then uses the -EIO part of dm-power-fail. Then when my test gets an EIO it stops, saves the good file, unmounts and remounts the fs, and checks the good file against what is on the disk. Nobody passes this test. Btrfs, xfs and ext4 all fail at some point, takes an hour or two but eventually each one of them fall over. Now this could just be a bug in the test somewhere, but I'm pretty sure I've shaken all the bugs out.
With the logging approach then it is completely up to us how we replay the log, so we can always go back and do more horrible things with the replay, like replay for a while, skip a flush and write some of the next random crap and see what happens. Doing horrible things is awesome and that is what I want, but I also want to make sure we're not failing in the simple things too. Thanks,
Josef
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
That is way complicated, I was just going to take two devices, one that's a linear mapping and the other that's the log, and then write to the log the sector+data that was written in order that it completes, and then have userspace do the replay. So basically do the flush tracking like I am, then write out chunks to the log device to keep a semblance of how the flushing would have affected stuff, something like this
write a, write b, a complete, flush, b complete, flush complete
would log out
wrote a, flush, write b, <other writes>, <next flush>
and then we have a userspace thing that could do something like replay all writes to a flush, do fs consistency and data consistency checks, walk to the next flush, rinse repeat, and that way we could be sure that we always have a consistent fs.
Quoted 6 lines
Quoted 3 lines
I guess that'd be an ok start, but I don't think you need any clever kernel code to do that. I've hacked up something like this in bash with blktrace, loopback files, and dd :/.
I don't think blktrace gives us the data being written though does it? If it does then hooray I'm done playing a device mapper developer.
Right, that script was only working with the dumb simple case of using manual double buffering and simple test loads that wouldn't overwrite blocks.
Quoted 6 lines
With the logging approach then it is completely up to us how we replay the log, so we can always go back and do more horrible things with the replay, like replay for a while, skip a flush and write some of the next random crap and see what happens. Doing horrible things is awesome and that is what I want, but I also want to make sure we're not failing in the simple things too. Thanks,
Sure, that's fair. So maybe expand blktrace to include the data payloads? :).
- z