remounting r/o with mapped and deleted files
When a file is memory mapped into a process space (e.g. executable, library, data, etc), and deleted, the data blocks for that file must still remain reserved so they can be swapped in as needed. If the filesystem is then remounted r/o, there is a conflict. In ext2, this is resolved by disallowing the remount r/o in much the same way as disallowing an unmount when anything is mapped or open.
I find this doesn't happen with reiserfs. So I am concerned. What I'd like to know is whether or not reiserfs is really doing this because it can handle the situation correctly, or if this is a bug.
Consider the sequence of events:
1. A program maps in a dynamic library from a reiserfs filesystem 2. The filesystem is remounted read/only 3. The program exits leaving no more references to the deleted file 4. The filesystem remounted read/write
Is the space for the deleted file now available?
Consider a slightly different sequence of events:
4. The system is gracefully shutdown while that filesystem is read/only
Or consider even this slightly different sequence of events:
4. The system is hard reset while that filesystem is read/only
At some point, the data blocks for that deleted file must be recovered. In the third sequence, the most difficult, the only opportunity I see for this to happen is that during the original unlink when the on-disk reference count (not including in-kernel-only references, such as a process mapping), the fact of this delete was written into a special journal that would NOT be played out yet (because it's not yet time to actually clean out the blocks), but finally had to be played out later when the system comes back up and the filesystem is remounted.
So how does reiserfs do this?
Signature · 4 lines
----------------------------------------------------------------- | Phil Howard - KA9WGN | Dallas | http://linuxhomepage.com/ | | [email protected] | Texas, USA | http://phil.ipal.org/ | -----------------------------------------------------------------
Hello!
Quoted 10 lines · Phil Howard
When a file is memory mapped into a process space (e.g. executable, library, data, etc), and deleted, the data blocks for that file must still remain reserved so they can be swapped in as needed. If the filesystem is then remounted r/o, there is a conflict. In ext2, this is resolved by disallowing the remount r/o in much the same way as disallowing an unmount when anything is mapped or open.
I find this doesn't happen with reiserfs. So I am concerned. What I'd like to know is whether or not reiserfs is really doing this because it can handle the situation correctly, or if this is a bug.
reiserfs can handle this correctly as of version included into linux kernel version 2.4.16, we call this feature safelinks. (or savelinks sometimes).
Quoted 2 lines
Consider the sequence of events:
1. A program maps in a dynamic library from a reiserfs filesystem
I believe you missed one step here:
1.5 somebody deletes the dynamic library file.
Quoted 4 lines
2. The filesystem is remounted read/only 3. The program exits leaving no more references to the deleted file 4. The filesystem remounted read/writeIs the space for the deleted file now available?
Yes.
At 2.5 point fs driver creates special key that references deleted object as already deleted. Now we wait for "iput()" to be performed on deleted file and looking if nlink finally reached zero.
Once it is reached then deleted key and actual object is removed from the fs. But in this case, this does not happen, so the special key is still on the fs. On next rw remount this key is found and the deletion is finished.
Quoted 2 lines
Consider a slightly different sequence of events:
4. The system is gracefully shutdown while that filesystem is read/only
The absolutely same thing occurs, file is deleted on rw mount.
Quoted 2 lines
Or consider even this slightly different sequence of events:
4. The system is hard reset while that filesystem is read/only
Still the same.
Actually you even may not remount the fs, and just press the reset button, and the deletion (and truncates) would be completed after next rw mount.
Quoted 1 line
At some point, the data blocks for that deleted file must be recovered.
Sure.
Quoted 7 lines
In the third sequence, the most difficult, the only opportunity I see for this to happen is that during the original unlink when the on-disk reference count (not including in-kernel-only references, such as a process mapping), the fact of this delete was written into a special journal that would NOT be played out yet (because it's not yet time to actually clean out the blocks), but finally had to be played out later when the system comes back up and the filesystem is remounted.
We are doing something that is very close to what you describe.
Quoted 1 line
So how does reiserfs do this?
In the code you can look it up as
actual deletion on rw mount: super.c::finish_unfinished() Writing deletion marks waiting for last user of a file going away:super.c::add_save_link()
Bye,
Oleg