Is it safe to interrupt when “fallocate –dig-holes” is running?

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Is it safe to interrupt when “fallocate –dig-holes” is running? on this date .

I use fallocate --dig-holes on very large disk images to make it sparse in-place. I’m worried that this operation may not be atomic. My questions are,

  1. Is my data guaranteed to be safe (holes are either punched or not, but not in an inconsistent state) if I press Ctrl+C to stop it half way?

  2. What about a power failure? These files are on a journaling file system (ext4).

Answer

Yes, your data will be safe if the operation is interrupted, either with a Ctrl-C or a power failure. What fallocate –dig does is search the file for blocks that zero, and then calls the fallocate(2) system call with the PUNCH HOLE flag. This will deallocate the blocks that were all zeros. If this is interrupted, the file will only be partial processed, but the data will be left in a consistent state, since it is not changing any non-zero blocks.

If the ext4 journal is enabled, then metadata operations (including PUNCH HOLE) will either be commited — or not — but either way, the file system will be left in a consistent state after a power failure (assuming that the device is power-fail certified; some SSD’s which are not power fail certified, can have their flash translation layer — FTL — metadata get corrupted after a power failure, in which case the data stored on the SSD can get corrupted).

Leave a Reply

Your email address will not be published. Required fields are marked *