[haiku-development] Re: file modification watching

> Now my question to the experts. I thought about to add a table of 
> open  
> nodes in the vfs. When opening a file in the vfs using file_open a 
> node ->  
> path pair could be stored in a hash table. When file_close is called 
> the  
> entry has to be removed again. When sending a stat or attr changed  
> notifications this information could be used to add an entry_ref to 
> the  
> outgoing message. This could be done optional when the user adds an  
> additional flag in watch_node.

While that could be done, you have to take into account that the node -
> path pair is not just a pair, but each node can have any number of 
> paths. For the problem you are trying to solve, this is not really 
important though. Furthermore, a path can change at any time, which 
makes it quite annoying to keep up.

But for that particular problem, it's also not needed to go this route. 
For one, BFS always knows the parent of an inode (as it doesn't support 
hard links, and needs this feature for queries to work), so it wouldn't 
be needed to store the data twice in that case, anyway.

But since this would only work for BFS, one could also just allow root 
to open any known node_ref, just like every directory can be opened via 
a node_ref. The vnode will be in the VFS anyway while the file is open, 
and even if you're not fast enough, and didn't open it in time, chances 
are very good that the vnode is still around afterwards. You could even 
make it 100% reliable with a callback mechanism if needed.

> Is file_close also called when a team exit and the user forgot to 
> close  
> files?

Of course, the kernel must not leak any of its resources.

> A further optimization would be to optional only send out 
> notifications  
> when a file is closing.

That's already in place; while you write to a file you only get 
notifications if you requested them, and they will be tagged with 
B_STAT_INTERIM_UPDATE.

> Another not directly related question, why the fs and not the vfs is  
> responsible to send out notifications? At least for most 
> notifications it  
> seams possible to me that the vfs has all needed information and can 
> send  
> the message.

I have a faint memory that there was a good reason (like a network file 
system is a good reason, as the VFS would only know the things that it 
did itself), but I don't remember it right away (I think there was 
something else), and have no time right now -- maybe Ingo can chime in 
though ;-)

Bye,
   Axel.


Other related posts: