Question

I am writing a C program for Linux that reads and writes to files on an NFS server. The share is mounted hard; attempts to access it will block indefinitely until they work. Having my program block indefinitely is bad; it is still capable of doing useful work even if the files are unavailable. Remounting the share soft is not an option.

Having two processes, one of which does work and won't block, and another that handles file IO and might block is an option, but would constitute a Major Change. I'd like to avoid that. Really, I want to say, "I know that you're hard mounted so that naive programs can pretend you're a highly reliable local disk. But I know better and I am prepared to cope with any access failing, similar to the behavior if you were soft mounted." So:

In C, how can I access files on a hard-mounted NFS share, getting errors if the server is unavailable instead of blocking indefinitely?

I can run as root if necessary, but would prefer not. Using root to remount the share is right out. I can potentially rely on new features, but the further back support goes the better.

My research suggests the answer is that it's just not possible, but perhaps I've missed something.

Was it helpful?

Solution

You've not missed anything, you will never receive server unavailable errors because the kernel will never deliver them on hard mounted nfs mount points.

Because the hard option is a property of the mount point, you can't have applications that pick and choose because the kernel isn't set out to behave in that manner.

However, you do mention that you can run the application as root. Why not mount the file system somewhere else soft, and then get your anticipated behaviour?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top