Loop devices under NTFS
On Tue, 27 Aug 2002, Christoph Hellwig:
Quoted 2 lines
Yes. Anything but the filesystem itself and the generic read/write path is not supposed to use address space operations directly.
Why?
According to linux-2.5.31/Documentation/Locking,
"->prepare_write(), ->commit_write(), ->sync_page() and ->readpage() may be called from the request handler (/dev/loop)."
Using the page cache in loop.c saves a copy when there is a
data transformation (such as encryption) involved, and that can be important for reducing the cost of privacy.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Note that there is a more severe bug in
loop.c: it's abuse ofdo_generic_file_read.Could you please elaborate on this and give an example where
it return incorrect data, deadlock, generate a kernel oops, etc.?Depending on the filesystem implementation _anything_ may happen. With current intree filesystems the only real life problem is that it doesn't work on certain filesystems.
Sorry for repeating myself here: If you're referring to the
stock loop.c not working with tmpfs because tmpfs lacks {prepare,commit}_write which my patch works around (based on Jari's patch before mine, and a patch by Andrew Morton as well). I have yet to hear a clear reason why any writable plain file on any given file system could not have {prepare,commit}_write operations available.
Quoted 2 lines
I think at least the network
filesystems might be oopsable with some preparation.
Please come up with a clear example. I'm not asking you for a
test case that can produce it, just some narrative of the problem occurring.
I am aware that you can get races if someone mounts a loop
device while accessing the underlying file by some other mechanism, but I believe that the only case where that would be done in practice is to change the encryption of a device, and, because of the read and write patterns involved in that, it should not be a problem.
Adam J. Richter __ ______________ 575 Oroville Road [email protected] \ / Milpitas, California 95035 +1 408 309-6081 | g g d r a s i l United States of America
"Free Software For The Rest Of Us."
Quoted 5 lines · Adam J. Richter
Why?
According to linux-2.5.31/Documentation/Locking,
"->prepare_write(), ->commit_write(), ->sync_page() and ->readpage() may be called from the request handler (/dev/loop)."
Just because it's present in current code it doesn't mean it's right. Calling aops directly from generic code is a layering violation and it will not survive 2.5.
Quoted 3 lines
Using the page cache in
loop.csaves a copy when there is a
data transformation (such as encryption) involved, and that can be important for reducing the cost of privacy.
Separating a stackalbe encryption block device from the loop driver is a good idea. The current loop code is a horrible mess because it tries to do the job of three drivers in one.
Quoted 10 lines
Quoted 3 lines
Depending on the filesystem implementation _anything_ may happen. With current intree filesystems the only real life problem is that it doesn't work on certain filesystems.
Sorry for repeating myself here: If you're referring to the
stockloop.cnot working with tmpfs because tmpfs lacks {prepare,commit}_write which my patch works around (based on Jari's patch before mine, and a patch by Andrew Morton as well). I have yet to hear a clear reason why any writable plain file on any given file system could not have {prepare,commit}_write operations available.
No, tmpfs also does not use generic_file_read but a sligh variation, calling do_generic_file_read on tmpfs inodes will not always works as expected. Don't do it.
Quoted 3 lines
Please come up with a clear example. I'm not asking you for a
test case that can produce it, just some narrative of the problem occurring.
loop on nfs, do_generic_file_read is called without the needed nfs_revalidate_inode, thus i_size is outdated, and loop might happily read out of the filesize.
Quoted 5 lines
I am aware that you can get races if someone mounts a loop
device while accessing the underlying file by some other mechanism, but I believe that the only case where that would be done in practice is to change the encryption of a device, and, because of the read and write patterns involved in that, it should not be a problem.
This is true for filesystems like nfs (above) that only revalidate and then call generic_file_read. For totally different implementations anything can happen. Even if it mostly works it's not the kind of design we want to have in the kernel.
Quoted 10 lines · Adam J. Richter
Quoted 3 lines
Depending on the filesystem implementation _anything_ may happen. With current intree filesystems the only real life problem is that it doesn't work on certain filesystems.
Sorry for repeating myself here: If you're referring to the
stockloop.cnot working with tmpfs because tmpfs lacks {prepare,commit}_write which my patch works around (based on Jari's patch before mine, and a patch by Andrew Morton as well). I have yet to hear a clear reason why any writable plain file on any given file system could not have {prepare,commit}_write operations available.
...
Quoted 3 lines
Please come up with a clear example. I'm not asking you for a
test case that can produce it, just some narrative of the problem occurring.
Not all filesystems use generic_read/generic_write. If they did we wouldn't need those calls in the fops structure.
Ofcourse the prepar_write/commit_write were introduced later on and perhaps it is possible to modify all filesystems to put all their custom functionality in these functions. Then we can simply remove the read and write (and mmap?) fops, i.e. force everyone to use the provided generic read/write functions.
But as long as a filesystem is allowed to provide it's own functions, any wrapper should never assume that generic operations will work.
The clear example you are looking for is probably Coda, most others filesystems simply wrap the generic_ function plus some minor functionality (like setting the ctime).
Jan