Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!chuq From: chuq@Apple.COM (Chuq Von Rospach) Newsgroups: comp.protocols.nfs Subject: Re: what causes a stale file handle? Message-ID: <34618@apple.Apple.COM> Date: 10 Sep 89 02:58:43 GMT References: <89Sep9.212500edt.2173@neat.cs.toronto.edu> Organization: Life is just a Fantasy novel played for keeps Lines: 46 >Question: >Why is the stale NFS handle error returned? Any way to compensate within >the daemon apart from doing a close()/open() sequence? Any way to tell >that a read() will return ESTALE without actually doing the read() ? A stale file handle is reported when the Fhandle to the file in question becomes out of date. Every inode on an NFS-server has a generation count that is modified whenever that inode is re-used (or whenever fsirand is run, like when you run newfs). What's probably happening to you, since this is a news partition, is that expire is being run. As part of expire, a new active file is created, then there's a renaming of active to oactive and nactive to active. Your daemon now has an fhandle pointing to what is now oactive. Since NFS is stateless, the fhandle has a generation count to avoid the following scenario: o client opens server:/tmp/foo o server deletes /tmp/foo o server creates new file /tmp/financial_data (which happens to re-use the same inode) o client attempts to use the fhandle given it by /tmp/foo. Without the generation count, since the fhandle would point to an inode with a real file attached, the access would succeed, even though the file you opened has nothing to do with the data you are now playing with. Generally, you'll see stale fhandles under two circumstances: o the filesystem you have mounted gets restored from backup and you haven't umounted it. o the file you have open has been deleted and re-created. the stale message is a way of telling you that something has happened to the file since you opened it that makes the fhandle you have invalid, so you don't continue using an fhandle that may well be pointing to incorrect data. -- Chuq Von Rospach <+> Editor,OtherRealms <+> Member SFWA/ASFA chuq@apple.com <+> CI$: 73317,635 <+> AppleLink: CHUQ [This is myself speaking. No company can control my thoughts.] Perhaps I should say Dr. *Von* Rospach, Dr. Rospach? (Gasp)