I would like to use an application API that is not "crash safe"; in other words, there is a high likelihood of the data file being corrupt and unreadable if the application crashes.
The file itself is a "metadata file" and should not get very big: few 100s of MB maximum.
What I want to do is:
- Force the application to access the file in "direct mode" (no OS caching).
- Pause updates at regular "checkpoint" intervals
- Perform a flush() (some data probably got flushed automatically)
- Now that I know the file is consistent, clone it.
- If there is an "old clone" delete it.
- Resume doing changes to the original file.
Could I use a special-purpose file system that makes some kind of "zero copy" of the file, combined with copy-on-write of the modified sectors of the original file, to get the clone "almost free" (with minimum disk IO)?
Also, can I do the "clone" without having to fork a process? (I don't know if the Linux file API offers a "cp" system-call).