Errno Libretto

By Hal Stern, Unix Insider |  Operating Systems

#! /bin/sh
# fh2inode - convert NFS file handle to inode
fh=`echo $4 | tr [a-z] [A-Z]` 
echo "ibase=16;$fh" | bc

If the server exports more than one filesystem, you'll need to
find the volume associated with the stale handle. The first
value in the file handle is a filesystem ID; match it to
the mounted filesystem ID values in /etc/mnttab to locate
the volume on which you're experiencing an error.

As soon as you've found the process writing to a stale file handle,
clean up gently by polling the user, then killing or restarting the
process.

close() to the edge

Detecting errors while writing to a file is complex for both NFS and
local filesystems. Unix does asynchronous writes, that is, the writes
are stacked up by the operating system and flushed out periodically.
On local disks, the update daemon runs every 30 seconds
to force pending writes to disk. With NFS, the kernel threads (Solaris
2.x) or biod processes (SunOS 4.1.x) queue writes locally. What
happens if an error occurs during the completion of one of the
write() system calls? In short, the error is reported
back on the next write() system call or on the call to
close(). You're guaranteed to see any errors by the time
close() returns, because all pending writes are flushed
(converted to synchronous writes) when the file is closed.


How often does your code check the return value from
close()? Again, this is an issue for local disks and NFS
filesystems, although you're more likely to see problems with NFS
since most error checking is done by the server, after the request has
been buffered and subsequently flushed by the client. If you fill a
disk or exceed a quota, you run the risk of having an NFS write fail
undetected unless you check return and errno values from
write() and close().

The moral of the story is religious enforcement of standards for
system programming, paying particular attention to error checking. If
you want to become the patron saint of errno, here are some guiding
principles:

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness