This is NOT a bug - it's a feature. The problem is that NFS simply cannot
guarantee cache coherency, so either you have to disable caching
altogether, or you accept the fact that NFS has these surprising features.
The reason that Linux _does_ seem to work if the size has changed is that
there is a simple and stupid check that tries to avoid _most_ cases with
old caches. It simply notices that "uhhuh, the server has another size
than the one we've cached - better invalidate our cache".
There is also a timeout for the cache (default 30 seconds, if I remember
correctly, and you can set it by hand with a mount parameter), so the
update _will_ be seen eventually, but 30 seconds can be a longish time.
Now, I'm not saying that this is good behaviour, but on the whole it's a lot
better than not caching. I'd be happy to try to make the heuristic for cache
invalidates a bit better - one suggestion has been to make the timeout
shorter if the file has been modified recently (dynamic timeouts: if the
file hasn't been modified in the last month we use long timeouts, if it
has changed within the last few minutes we use a timeout of just a second
ot something like that).
So instead of the patch you sent (which looks fine, but it's a bit more
brute-force than I'd like), maybe you could look into the file "file.c"
and the "revalidate_inode()" function?
Linus