Next | Prev | Up | Top | Contents | Index

Terminology

Before discussing record locking mechanisms, first consider a few terms.


Record

A record is any contiguous sequence of bytes in a file. The UNIX operating system does not impose any record structure on files. The boundaries of records are defined by the programs that use the files. Within a single file, a record as defined by one process can overlap partially or completely on a record as defined by some other process.


Cooperating Processes

Cooperating processes work together in a well-defined fashion to accomplish the tasks at hand. Processes can coordinate their use of resources of different types in many ways, including semaphores in shared memory. Processes that share files must request permission to access the files before using them. File access permissions must be carefully set to prevent noncooperating processes from accessing those files. The term "process" is used interchangeably with "cooperating process" to refer to a task obeying such protocols.


Read (Shared) Lock

A read lock keeps a record from changing while one or more processes read the data. If a process holds a read lock, it may assume that no other process will be writing or updating that record at the same time. When a read lock is in place on a record, other processes may also read-lock that record or a record that overlaps the locked record. No other process, however, may have or obtain a write lock on that record or an overlapping record.


Write (Exclusive) Lock

A write lock is used to gain complete control over a record. When a write lock is in place on a record, no other process may read- or write-lock that record or a record that overlaps it. If a process holds a write lock it may assume that no other process will be reading or writing that record at the same time.


Advisory Locking

Advisory locking has no effect on the file I/O subsystem functions or the processes that use them. File I/O functions include the creat(), open(), read(), and write() calls.

Advisory control is accomplished by requiring all cooperating processes to make an appropriate record lock request before performing any I/O operation. When all processes use advisory locking, the accessibility of the file is controlled by the interaction of these requests. Advisory locking depends on the individual processes to enforce the record locking protocol; it is not enforced by the file I/O subsystem.


Mandatory Locking

Mandatory record locking is enforced by the file I/O subsystem and so is effective on unrelated processes that may not be part of the cooperating group. Access to locked records is enforced by the creat(), open(), read(), and write() system calls. When a record is locked, access to that record by any other process is restricted according to the type of lock on the record. Cooperating processes should still request an appropriate record lock before an I/O operation, but an additional check is made by IRIX before each I/O operation to ensure the record locking protocol is being honored. Mandatory locking offers security against unplanned file use by unrelated programs, but it imposes additional system overhead on access to the controlled files.


Lock Promotion and Demotion

Promoting a read lock to write-lock status is permitted if no other process is holding a read lock in the same record. If processes exist with pending write locks that are waiting for the same record, the lock promotion succeeds and the other (sleeping) processes wait. Promoting (or demoting) a write lock to a read lock carries no restrictions. In either case, the lock is reset with the new lock type.

Because the lockf() function does not support read locks, lock promotion is not applicable to locks set with that call.


Next | Prev | Up | Top | Contents | Index