fcntl.2 (2011 03)

f
fcntl(2) fcntl(2)
The structure oplock describes the details of the lock being requested on the opened file descriptor. If
the command succeeds, it also contains the owner ID (
o_owner) of the process as well as the type of
oplock (
o_type) being requested. The o_sysid
can also be specified. The process ID (o_pid) is the
requesting process with which to associate the oplock. Optional flags
o_flags, o_timeout, and signal
value (
o_sig_val) can also be specified.
The only field in this structure which must be assigned is
o_type. The other fields are either optional or
not used and should be initialized to zero (0).
The fields in the
oplock structure are described here:
o_owner Owner type. Any integer; however, 0x8000 is reserved.
o_member_id Member ID. Any unique integer of type
sysid_t.
o_type Type of oplock. o_type
is one of these values:
VFS_OPLOCK_NONE
Removes an oplock.
VFS_OPLOCK_SHARED
Request a shared oplock.
VFS_OPLOCK_EXCLUSIVE
Request an exclusive oplock.
VFS_OPLOCK_BATCH
Request a batch oplock. (Requires CIFS
stacked file system support)
o_sysid The system ID of the locking process. o_sysid is an optional value.
o_pid The process ID of the process that owns the oplock. The process ID does not
need to be filled in by the application, because
fcntl() does this internally.
o_flags This field is not currently used and is here for future needs. HP recommends
that this field be initialized to zero (0).
o_retry This field is the number of retries to gracefully request that an oplock be bro-
ken. After the number of retries are exhausted, then the oplock will be
removed without acknowledgment from the process that owns it.
o_timeout This value represents the wait time in seconds that the kernel will wait before
re-sending the oplock break signal. The total time that an application can
wait for an oplock is (
o_retry+1) multiplied by o_timeout seconds.
o_sig_val A value to be sent with signal to a process upon an oplock being broken.
Application Usage
Because in the future the external variable
errno will be set to [EAGAIN] rather than [EACCES] when
a section of a file is already locked by another process, portable application programs should expect and
test for either value. For example:
flk->l_type = F_RDLCK;
if (fcntl(fd, F_SETLK, flk) == -1)
if ((errno == EACCES) || (errno == EAGAIN))
/*
* section locked by another process,
* check for either EAGAIN or EACCES
* due to different implementations
*/
else if ...
/*
* check for other errors
*/
NETWORKING FEATURES
NFS
The advisory record-locking capabilities of fcntl() are implemented throughout the network by the
"network lock daemon" (see lockd (1M)). If the file server crashes and is rebooted, the lock daemon
attempts to recover all locks associated with the crashed server. If a lock cannot be reclaimed, the pro-
cess that held the lock is issued a SIGLOST signal.
Record locking, as implemented for NFS files, is only advisory.
HP-UX 11i Version 3: March 2011 5 Hewlett-Packard Company 5