still nfs problems [Was: Linux 2.6.37-rc8]
Subsystems (2)
Quoted 9 lines
Uncached_readdiris not really a problem. The real problem is filesystems that generate "infinite directories" by producing looping combinations of cookies.IOW: I've seen servers that generate cookies in a sequence of a form vaguely resembling
1 2 3 4 5 6 7 8 9 10 11 12 3...
Quoted 8 lines
(with possibly a thousand or so entries between the first and second copy of '3')
The kernel won't loop forever with something like that (because eventually
filldir()will declare it is out of buffer space), but userland has a halting problem: it needs to detect that everysys_getdents()call it is making is generating another copy of the sequence associated with '4 5 6 7 8 9 10 11 12 3'...
Huh? This is not only an easy problem, it's a well-known problem.
http://en.wikipedia.org/wiki/Cycle_detection
Here's Brent's algorithm:
n = 0;
saved_cookie = <invalid>
For each cookie {
if (n && cookie == saved_cookie)
die("Loop detected!");
if (++n is a power of 2)
saved_cookie = cookie;
}You can tweak the performance with other exponentially-growing functions, saving k > 1 old cookies for comparison, etc., but the above will work very well.
Quoted 32 lines · George Spelvin
Quoted 9 lines
Uncached_readdiris not really a problem. The real problem is filesystems that generate "infinite directories" by producing looping combinations of cookies.IOW: I've seen servers that generate cookies in a sequence of a form vaguely resembling
1 2 3 4 5 6 7 8 9 10 11 12 3...
Quoted 8 lines
(with possibly a thousand or so entries between the first and second copy of '3')
The kernel won't loop forever with something like that (because eventually
filldir()will declare it is out of buffer space), but userland has a halting problem: it needs to detect that everysys_getdents()call it is making is generating another copy of the sequence associated with '4 5 6 7 8 9 10 11 12 3'...Huh? This is not only an easy problem, it's a well-known problem.
http://en.wikipedia.org/wiki/Cycle_detectionHere's Brent's algorithm: n = 0; saved_cookie = <invalid> For each cookie { if (n && cookie == saved_cookie) die("Loop detected!"); if (++n is a power of 2) saved_cookie = cookie; }
Quoted 3 lines
You can tweak the performance with other exponentially-growing functions, saving k > 1 old cookies for comparison, etc., but the above will work very well.
...and your point would be that an exponentially increasing addition to the existing number of tests is an acceptable tradeoff in a situation where the >99.999999999999999% case is that of sane servers with no looping? I don't think so...
Trond
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 4 lines
...and your point would be that an exponentially increasing addition to the existing number of tests is an acceptable tradeoff in a situation where the >99.999999999999999% case is that of sane servers with no looping? I don't think so...
1) Look again; it's O(1) work per entry, or O(n) work for an n-entry directory. And O(1) space. With very small constant factors, and very little code. The only thing exponentially increasing is the interval at which you save the current cookie for future comparison.
2) You said it *was* a problem, so it seemed worth presenting a practical solution. If you don't think it's worth it, I'm not going to disagree. But it's not impossible, or even difficult.
Quoted 5 lines · George Spelvin
Quoted 4 lines
...and your point would be that an exponentially increasing addition to the existing number of tests is an acceptable tradeoff in a situation where the >99.999999999999999% case is that of sane servers with no looping? I don't think so...
Quoted 7 lines
1) Look again; it's O(1) work per entry, or O(n) work for an n-entry directory. And O(1) space. With very small constant factors, and very little code. The only thing exponentially increasing is the interval at which you save the current cookie for future comparison.
2) You said it *was* a problem, so it seemed worth presenting a practical solution. If you don't think it's worth it, I'm not going to disagree. But it's not impossible, or even difficult.
Yes. I was thinking about it this morning (after coffee).
One variant on those algorithms that might make sense here is to save the current cookie each time we see that the result of a cookie search is a filp->f_pos offset < the current filp->f_pos offset. That means we will in general only detect the loop after going through an entire cycle, but that should be sufficient...
Trond
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 4 lines
Quoted 2 lines
1) Look again; it's O(1) work per entry, or O(n) work for an n-entry directory. And O(1) space. With very small constant factors,
Yes. I was thinking about it this morning (after coffee).
Thank you for the second look.
Quoted 5 lines
One variant on those algorithms that might make sense here is to save the current cookie each time we see that the result of a cookie search is a
filp->f_posoffset < the currentfilp->f_posoffset. That means we will in general only detect the loop after going through an entire cycle, but that should be sufficient...
All of these low-overhead algorithms can take a couple of loop iterations before they detect it; their job is to achieve a reasonably low constant factor in time using O(1) space.
The worst case for the power-of-two algorithm is when the loop is n = 2^k+1 items long. When you get to item 2^(k+1), you'll be comparing to item 2^k, which is a mismatch. Then you'll save the cookie from 2^(k+1) and have to go to 2^(k+1) + 2^k + 1, or about 3*n, before detecting it.
I don't consider this a problem, because it wastes a few seconds of computer time, to be followed by wasting a few hours trying to pass a bug report upstream about the broken NFS server...
I don't quite follow how your proposed variant works. Pardon my ignorance of NFS, but is the f->pos something that comes from the server, or something that is synthesized locally? Obviously, if you keep a record of all the server cookies, you can detect loops quite easily.
If it comes from the server, there's a risk that there might be two backward jumps in the cycle, and thus you'll never notice it.