views:

185

answers:

3

What is the best(fastest) way to determine if a Samba mount point is dead on Linux? I need to do it in C. System calls like statfs(), statvfs() block for 30-40 sec when called on a stale mount, and they don't even return an error in this case. stat() seems to fail faster then others (about 10 sec) and returns an error. Mount point may go stale because the other host went down or Samba daemon there was killed. Any advice is appreciated..

+1  A: 

You could set an alarm (see alarm() and setitimer()) that times out after a few seconds.

Peter Eisentraut
A: 

Well, I don't know how to make a faster check, but I may suggest you to check all mount points at the same time, in parallel, so you will always have the same total time, even with many samba mounts.

eppesuig
A: 

I'm answering my own question. The goal was to minimize the time spent by several processes trying to access stale mountpoints. Normally, the system calls would complete in subsecond time. Blocking on stale shares for 10 sec, or even, say, 3 sec was not acceptable because these calls are done in several places, multiple times and the delay time accumulates. So, I ended up writing a monitoring process, which checks mounts every n seconds and unmounts them if they are inaccessible. I also read info from my configs saying which filesystems are supposed to be remote(mounted) and check mtab file - if they are not there, it's an error. Code checking mtab completes in a subsecond time. Took a day or two to implement, but works fine for me.

snovo