8000 minix/minix/servers/vfs/README at v3.3.0 · kishoredbn/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
699 lines (652 loc) · 44.7 KB

README

File metadata and controls

699 lines (652 loc) · 44.7 KB
=== Filp (file position) locking ===
## 4.7 Filp (file position) locking
The main fields of a filp object that are shared between various processes
(and by extension threads), and that can change after object creation,
are filp_count and filp_pos. Writes to and reads from filp object must be
mutually exclusive, as all system calls have to use the latest version. For
example, a read(2) call changes the file position (i.e., filp_pos), so two
concurrent reads must obtain exclusive access. Consequently, as even read
operations require exclusive access, filp object don't use three-level locks,
but only mutexes.
System calls that involve a file descriptor often access both the filp and
the corresponding vnode. The locking order requires us to first lock the
vnode and then the filp. This is taken care of at the filp level. Whenever
a filp is locked, a lock on the vnode is acquired first. Conversely, when
a filp is unlocked, the corresponding vnode is also unlocked. A convenient
consequence is that whenever a vnode is locked exclusively (VNODE_WRITE),
all corresponding filps are implicitly locked. This is of particular use
when multiple filps must be locked at the same time:
* When opening a named pipe, VFS must make sure that there is at most one filp for the reader end and one filp for the writer end.
* Pipe readers and writers must be suspended in the absence of (respectively) writers and readers.
Because both filps are linked to the same vnode object (they are for the same
pipe), it suffices to exclusively lock that vnode instead of both filp objects.
In some cases it can happen that a function that operates on a locked filp,
calls another function that triggers another lock on a different filp for
the same vnode. For example, close_filp. At some point, close_filp() calls
release() which in turn will loop through the filp table looking for pipes
being select(2)ed on. If there are, the select code will lock the filp and do
operations on it. This works fine when doing a select(2) call, but conflicts
with close(2) or exit(2). Lock_filp() makes an exception for this situation;
if you've already locked a vnode with VNODE_OPCL or VNODE_WRITE when locking
a filp, you obtain a "soft lock" on the vnode for this filp. This means
that lock_filp won't actually try to lock the vnode (which wouldn't work),
but flags the vnode as "skip unlock_vnode upon unlock_filp." Upon unlocking
the filp, the vnode remains locked, the soft lock is removed, and the filp
mutex is released. Note that this scheme does not violate the locking order;
the vnode is (already) locked before the filp.
A similar problem arises with create_pipe. In this case we obtain a new vnode
object, lock it, and obtain two new, locked, filp objects. If everything works
out and the filp objects are linked to the same vnode, we run into trouble
when unlocking both filps. The first filp being unlocked would work; the
second filp doesn't have an associated vnode that's locked anymore. Therefore
we introduced a plural unlock_filps(filp1, filp2) that can unlock two filps
that both point to the same vnode.
=== Lock characteristics per request type ===
## 4.8 Lock characteristics per request type
For File Servers that support concurrent requests, it's useful to know which
locking guarantees VFS provides for vmnts and vnodes, so it can take that
into account when protecting internal data structures. READ = TLL_READ,
READSER = TLL_READSER, WRITE = TLL_WRITE. The vnode locks applies to the
'''inode''' field in requests, unless the notes say otherwise.
{{{
------------------------------------------------------------------------------
| request | vmnt | vnode | notes |
+--------------+---------+---------+-----------------------------------------+
| REQ_BREAD | | READ | VFS serializes reads from and writes to |
| | | | block special files |
+--------------+---------+---------+-----------------------------------------+
| REQ_BWRITE | | WRITE | VFS serializes reads from and writes to |
| | | | block special files |
+--------------+---------+---------+-----------------------------------------+
| REQ_CHMOD | READ | WRITE | vmnt is only locked if file is not |
| | | | already opened |
+--------------+---------+---------+-----------------------------------------+
| REQ_CHOWN | READ | WRITE | vmnt is only locked if file is not |
| | | | already opened |
+--------------+---------+---------+-----------------------------------------+
| REQ_CREATE | WRITE | WRITE | The directory in which the file is |
| | | | created is write locked |
+--------------+---------+---------+-----------------------------------------+
| REQ_FLUSH | | | Mutually exclusive to REQ_BREAD and |
| | | | REQ_BWRITE |
+--------------+---------+---------+-----------------------------------------+
| REQ_FTRUNC | READ | WRITE | vmnt is only locked if file is not |
| | | | already opened |
+--------------+---------+---------+-----------------------------------------+
| REQ_GETDENTS | READ | READ | vmnt is only locked if file is not |
| | | | already opened |
+--------------+---------+---------+-----------------------------------------+
| REQ_INHIBREAD| | READ | |
+--------------+---------+---------+-----------------------------------------+
| REQ_LINK | READSER | WRITE | vfs_fs_link.inode is locked READ |
| | | | vfs_fs_link.dir_ino is locked WRITE |
+--------------+---------+---------+-----------------------------------------+
| REQ_LOOKUP | READSER | | |
+--------------+---------+---------+-----------------------------------------+
| REQ_MKDIR | READSER | WRITE | |
+--------------+---------+---------+-----------------------------------------+
| REQ_MKNOD | READSER | WRITE | |
+--------------+---------+---------+-----------------------------------------+
|REQ_MOUNTPOINT| WRITE | WRITE | |
+--------------+---------+---------+-----------------------------------------+
|REQ_NEW_DRIVER| | | |
+--------------+---------+---------+-----------------------------------------+
| REQ_NEWNODE | | | Only sent to PFS |
+--------------+---------+---------+-----------------------------------------+
| REQ_PUTNODE | | READSER | READSER when dropping all but one |
| | | or WRITE| references. WRITE when final reference |
| | | | is dropped (i.e., no longer in use) |
+--------------+---------+---------+-----------------------------------------+
| REQ_RDLINK | READ | READ | In some circumstances stricter locking |
| | | | might be applied, but not guaranteed |
+--------------+---------+---------+-----------------------------------------+
| REQ_READ | | READ | |
+--------------+---------+---------+-----------------------------------------+
|REQ_READSUPER | WRITE | | |
+--------------+---------+---------+-----------------------------------------+
| REQ_RENAME | WRITE | WRITE | |
+--------------+---------+---------+-----------------------------------------+
| REQ_RMDIR | WRITE | WRITE | |
+--------------+---------+---------+-----------------------------------------+
| REQ_SLINK | READSER | READ | |
+--------------+---------+---------+-----------------------------------------+
| REQ_STAT | READ | READ | vmnt is only locked if file is not |
| | | | already opened |
+--------------+---------+---------+-----------------------------------------+
| REQ_STATVFS | READ | READ | vmnt is only locked if file is not |
| | | | already opened |
+--------------+---------+---------+-----------------------------------------+
| REQ_SYNC | READ | | |
+--------------+---------+---------+-----------------------------------------+
| REQ_UNLINK | WRITE | WRITE | |
+--------------+---------+---------+-----------------------------------------+
| REQ_UNMOUNT | WRITE | | |
+--------------+---------+---------+-----------------------------------------+
| REQ_UTIME | READ | READ | |
+--------------+---------+---------+-----------------------------------------+
| REQ_WRITE | | WRITE | |
-----------------------------------------------------------------------------+
}}}
Table 7: VFS-FS requests locking guarantees
== Recovery from driver crashes ==
## 5 Recovery from driver crashes
VFS can recover from block special file and character special file driver
crashes. It can recover to some degree from a crashed File Server (which we
can regard as a driver).
=== Recovery from block drivers crashes ===
## 5.1 Recovery from block drivers crashes
When reading or writing, VFS doesn't communicate with block drivers directly,
but always through a File Server (the root File Server being default). If the
block driver crashes, the File Server does most of the work of the recovery
procedure. VFS loops through all open files for block special files that
were handled by this driver and reopens them. After that it sends the new
endpoint to the File Server so it can finish the recover procedure. Finally,
the File Server will retry pending requests if possible. However, reopening
files can cause the block driver to crash again. When that happens, VFS will
stop the recovery. A driver can return ERESTART to VFS to tell it to retry
a request. VFS does this with an arbitrary maximum of 5 attempts.
=== Recovery from character driver crashes ===
## 5.2 Recovery from character driver crashes
While VFS used to support minimal recovery from character driver crashes, the
added complexity has so far proven to outweigh the benefits, especially since
such crash recovery can never be fully transparent: it depends entirely on the
character device as to whether repeating an I/O request makes sense at all.
Currently, all operations except close(2) on a file descriptor that identifies
a device on a crashed character driver, will result in an EIO error. It is up
to the application to reopen the character device and retry whatever it was
doing in the appropriate manner. In the future, automatic reopen and I/O
restart may be reintroduced for a limited subset of character drivers.
=== Recovery from File Server crashes ===
## 5.3 Recovery from File Server crashes
At the time of writing we cannot recover from crashed File Servers. When
VFS detects it has to clean up the remnants of a File Server process (i.e.,
through an exit(2)), it marks all associated file descriptors as invalid
and cancels ongoing and pending requests to that File Server. Resources that
were in use by the File Server are cleaned up.
[0] http://wiki.minix3.org/en/DevelopersGuide/VfsFsProtocol
[1] http://www.cs.vu.nl/~dcvmoole/minix/blockchar.txt
[2] http://www.minix3.org/theses/moolenbroek-multimedia-support.pdf
0