Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 14.3 RecordLocking 493


Figure14.8 shows the resulting data structures after both the parent and the child have
paused.

parent process table entry

...


fd1:
fd2:
fd3:

flagsfd pointerfile

child process table entry

...


fd1:
fd2:
fd3:

flagsfd pointerfile

file status flags
current file offset
v-node pointer

file status flags
current file offset
v-node pointer

file table entry

file table entry

v-node information
lockfpointer
v_data

i-node information
current file size
i_vnode

v-node table entry

i-node

lock header

lockf_entrylist

link
flags
starting offset
ending offset
lock_ownerpointer

link
flags
starting offset
ending offset
lock_ownerpointer

owner information

parent process ID

owner information

child process ID

struct lockf

struct lockf_entry struct lockf_entry

struct lock_owner struct lock_owner

Figure 14.8 The FreeBSD data structures for recordlocking

We’ve shown the data structures that result from theopen,fork,anddupcalls
earlier (Figures 3.9 and 8.2). What is new hereare thelockfstructures that arelinked
together from the i-node structure. Eachlockfstructuredescribes one locked region
(defined by an offset and length) for a given process. Weshow two of these structures:
one for the parent’s call towrite_lockand one for the child’s call toread_lock.
Each structurecontains the corresponding process ID.
In the parent, closing any one offd1,fd2,orfd3causes the parent’s lock to be
released. When any one of these three file descriptors is closed, the kernel goes through
Free download pdf