DOCUMENT ID: 1493-02

SYNOPSIS:    A description of Mandatory Locking on Solaris 2.x

OS RELEASE:  Solaris 2.x

KEYWORDS:    mandatory lock file 

PRODUCT:


DESCRIPTION: 

A description of how Mandatory Locks are implemented with Solaris 2.x


SOLUTION:

                 Mandatory Locking on Solaris 2.x


Mandatory Locking:

As well as advisory locking, the system provides a mandatory locking
mechanism.  The only difference between the two is that for mandatory
locks the system enforces the record locking mechanisms on the
occurrence of each I/O operation on the file.  That is, if either read
or write system calls are made, and mandatory locks are enforced on the
file, the system first determines whether the process can access the
file according to the type of record lock set within it.  Therefore,
with mandatory locks, the system governs access to a locked record
according to the lock type at the time the I/O operation is performed,
whereas with advisory locks access is governed by cooperating processes
operating in user-mode using fcntl locking service. 

At the cost of additional overhead, mandatory locks provide an extra and
more secure form of synchronization.  However, if multiple processes are
expected to perform atomic reads or writes on a record within a file, it
is recommended that those processes are made to cooperate with each
other using advisory locks instead of depending on any mandatory locks
that may or may not be enforced.  The reasons for this will become
evident presently. 

As stated before, the system determines whether mandatory locks are
enforced on a file at the time an I/O operation is performed.  However,
the decision to enforce mandatory locking depends on the access
permissions set on the file.  For mandatory locks to be enforced, the
file must be a regular file with the ser-group-ID on execution bit ser
on, and the execute bit for the group must be turned off.  Note that all
these conditions must be met before mandatory locking is enforced,
otherwise record locks placed on the file will be advisory only.  To
change the modes of a file to enforce mandatory locking the program must
use the chmod system call.  The command chmod(1) can also be used to do
this:

 # ls -l creb
 -rw-r--r--     1 ayla  clan            12345 Feb 21 11:04 creb
 # chmod +1 creb
 # ls -l creb
 -rw-r-lr--     1 ayla  clan            12345 Feb 21 11:04 creb

Note that it is good practice to have execute permissions set on a file
that is also expected to have record locks set.  This is because the
system does not obey record locking set on a file while executing it. 


DATE APPROVED: 09/05/95