FreeBSD kernel kern code
kern_lockf.c File Reference
#include <sys/cdefs.h>
#include "opt_debug_lockf.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/hash.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
#include <sys/fcntl.h>
#include <sys/lockf.h>
#include <sys/taskqueue.h>
Include dependency graph for kern_lockf.c:

Go to the source code of this file.

Data Structures

struct  lock_owner
 
struct  owner_edge
 
struct  owner_vertex
 
struct  owner_graph
 
struct  lockdesc
 

Macros

#define NOLOCKF   (struct lockf_entry *)0
 
#define SELF   0x1
 
#define OTHERS   0x2
 
#define LOCK_OWNER_HASH_SIZE   256
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_LOCKF,"lockf","Byte-range locking structures")
 
static void lf_init (void *)
 
static int lf_hash_owner (caddr_t, struct flock *, int)
 
static int lf_owner_matches (struct lock_owner *, caddr_t, struct flock *, int)
 
static struct lockf_entry * lf_alloc_lock (struct lock_owner *)
 
static int lf_free_lock (struct lockf_entry *)
 
static int lf_clearlock (struct lockf *, struct lockf_entry *)
 
static int lf_overlaps (struct lockf_entry *, struct lockf_entry *)
 
static int lf_blocks (struct lockf_entry *, struct lockf_entry *)
 
static void lf_free_edge (struct lockf_edge *)
 
static struct lockf_edge * lf_alloc_edge (void)
 
static void lf_alloc_vertex (struct lockf_entry *)
 
static int lf_add_edge (struct lockf_entry *, struct lockf_entry *)
 
static void lf_remove_edge (struct lockf_edge *)
 
static void lf_remove_outgoing (struct lockf_entry *)
 
static void lf_remove_incoming (struct lockf_entry *)
 
static int lf_add_outgoing (struct lockf *, struct lockf_entry *)
 
static int lf_add_incoming (struct lockf *, struct lockf_entry *)
 
static int lf_findoverlap (struct lockf_entry **, struct lockf_entry *, int)
 
static struct lockf_entry * lf_getblock (struct lockf *, struct lockf_entry *)
 
static int lf_getlock (struct lockf *, struct lockf_entry *, struct flock *)
 
static void lf_insert_lock (struct lockf *, struct lockf_entry *)
 
static void lf_wakeup_lock (struct lockf *, struct lockf_entry *)
 
static void lf_update_dependancies (struct lockf *, struct lockf_entry *, int all, struct lockf_entry_list *)
 
static void lf_set_start (struct lockf *, struct lockf_entry *, off_t, struct lockf_entry_list *)
 
static void lf_set_end (struct lockf *, struct lockf_entry *, off_t, struct lockf_entry_list *)
 
static int lf_setlock (struct lockf *, struct lockf_entry *, struct vnode *, void **cookiep)
 
static int lf_cancel (struct lockf *, struct lockf_entry *, void *)
 
static void lf_split (struct lockf *, struct lockf_entry *, struct lockf_entry *, struct lockf_entry_list *)
 
static int graph_delta_forward (struct owner_graph *g, struct owner_vertex *x, struct owner_vertex *y, struct owner_vertex_list *delta)
 
static int graph_delta_backward (struct owner_graph *g, struct owner_vertex *x, struct owner_vertex *y, struct owner_vertex_list *delta)
 
static int graph_add_indices (int *indices, int n, struct owner_vertex_list *set)
 
static int graph_assign_indices (struct owner_graph *g, int *indices, int nextunused, struct owner_vertex_list *set)
 
static int graph_add_edge (struct owner_graph *g, struct owner_vertex *x, struct owner_vertex *y)
 
static void graph_remove_edge (struct owner_graph *g, struct owner_vertex *x, struct owner_vertex *y)
 
static struct owner_vertexgraph_alloc_vertex (struct owner_graph *g, struct lock_owner *lo)
 
static void graph_free_vertex (struct owner_graph *g, struct owner_vertex *v)
 
static struct owner_graphgraph_init (struct owner_graph *g)
 
 LIST_HEAD (lock_owner_list, lock_owner)
 
 LIST_HEAD (owner_edge_list, owner_edge)
 
 TAILQ_HEAD (owner_vertex_list, owner_vertex)
 
 SYSINIT (lf_init, SI_SUB_LOCK, SI_ORDER_FIRST, lf_init, NULL)
 
int lf_advlockasync (struct vop_advlockasync_args *ap, struct lockf **statep, u_quad_t size)
 
int lf_advlock (struct vop_advlock_args *ap, struct lockf **statep, u_quad_t size)
 
void lf_purgelocks (struct vnode *vp, struct lockf **statep)
 
static void lf_activate_lock (struct lockf *state, struct lockf_entry *lock)
 
static void lf_cancel_lock (struct lockf *state, struct lockf_entry *lock)
 
 STAILQ_HEAD (lockdesclist, lockdesc)
 
int lf_iteratelocks_sysid (int sysid, lf_iterator *fn, void *arg)
 
int lf_iteratelocks_vnode (struct vnode *vp, lf_iterator *fn, void *arg)
 
static int lf_clearremotesys_iterator (struct vnode *vp, struct flock *fl, void *arg)
 
void lf_clearremotesys (int sysid)
 
int lf_countlocks (int sysid)
 

Variables

static struct sx lf_lock_states_lock
 
static struct lockf_list lf_lock_states
 
static struct sx lf_lock_owners_lock
 
static struct lock_owner_list lf_lock_owners [LOCK_OWNER_HASH_SIZE]
 
static struct sx lf_owner_graph_lock
 
static struct owner_graph lf_owner_graph
 

Macro Definition Documentation

#define LOCK_OWNER_HASH_SIZE   256

Definition at line 191 of file kern_lockf.c.

Referenced by lf_countlocks(), lf_hash_owner(), and lf_init().

#define NOLOCKF   (struct lockf_entry *)0

Definition at line 100 of file kern_lockf.c.

Referenced by lf_clearlock(), lf_findoverlap(), and lf_getblock().

#define OTHERS   0x2

Definition at line 102 of file kern_lockf.c.

Referenced by lf_findoverlap().

#define SELF   0x1

Definition at line 101 of file kern_lockf.c.

Referenced by lf_activate_lock(), and lf_findoverlap().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static int graph_add_edge ( struct owner_graph g,
struct owner_vertex x,
struct owner_vertex y 
)
static

Definition at line 2229 of file kern_lockf.c.

References owner_graph::g_gen, owner_graph::g_indexbuf, owner_graph::g_size, owner_graph::g_vertices, graph_add_indices(), graph_assign_indices(), graph_delta_backward(), graph_delta_forward(), lf_owner_graph_lock, malloc(), and printf().

Referenced by lf_add_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

static int graph_add_indices ( int *  indices,
int  n,
struct owner_vertex_list *  set 
)
static

Definition at line 2189 of file kern_lockf.c.

Referenced by graph_add_edge().

Here is the caller graph for this function:

static struct owner_vertex * graph_alloc_vertex ( struct owner_graph g,
struct lock_owner lo 
)
static

Definition at line 2403 of file kern_lockf.c.

References free(), owner_graph::g_gen, owner_graph::g_indexbuf, owner_graph::g_size, owner_graph::g_space, owner_graph::g_vertices, lf_owner_graph_lock, malloc(), and realloc().

Referenced by lf_alloc_vertex().

Here is the call graph for this function:

Here is the caller graph for this function:

static int graph_assign_indices ( struct owner_graph g,
int *  indices,
int  nextunused,
struct owner_vertex_list *  set 
)
static

Definition at line 2208 of file kern_lockf.c.

References owner_graph::g_vertices.

Referenced by graph_add_edge().

Here is the caller graph for this function:

static int graph_delta_backward ( struct owner_graph g,
struct owner_vertex x,
struct owner_vertex y,
struct owner_vertex_list *  delta 
)
static

Definition at line 2154 of file kern_lockf.c.

References owner_graph::g_gen.

Referenced by graph_add_edge().

Here is the caller graph for this function:

static int graph_delta_forward ( struct owner_graph g,
struct owner_vertex x,
struct owner_vertex y,
struct owner_vertex_list *  delta 
)
static

Definition at line 2112 of file kern_lockf.c.

References owner_graph::g_gen.

Referenced by graph_add_edge().

Here is the caller graph for this function:

static void graph_free_vertex ( struct owner_graph g,
struct owner_vertex v 
)
static

Definition at line 2432 of file kern_lockf.c.

References free(), owner_graph::g_size, owner_graph::g_vertices, and lf_owner_graph_lock.

Referenced by lf_free_lock().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct owner_graph * graph_init ( struct owner_graph g)
static

Definition at line 2457 of file kern_lockf.c.

References owner_graph::g_gen, owner_graph::g_indexbuf, owner_graph::g_size, owner_graph::g_space, owner_graph::g_vertices, and malloc().

Referenced by lf_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static void graph_remove_edge ( struct owner_graph g,
struct owner_vertex x,
struct owner_vertex y 
)
static

Definition at line 2368 of file kern_lockf.c.

References free(), lf_owner_graph_lock, and printf().

Referenced by lf_remove_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_activate_lock ( struct lockf *  state,
struct lockf_entry *  lock 
)
static

Definition at line 1212 of file kern_lockf.c.

References lf_findoverlap(), lf_free_lock(), lf_insert_lock(), lf_set_end(), lf_set_start(), lf_split(), lf_update_dependancies(), printf(), and SELF.

Referenced by lf_cancel_lock(), lf_clearlock(), and lf_setlock().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_add_edge ( struct lockf_entry *  x,
struct lockf_entry *  y 
)
static

Definition at line 911 of file kern_lockf.c.

References graph_add_edge(), lf_alloc_edge(), lf_alloc_vertex(), and lf_owner_graph.

Referenced by lf_add_incoming(), and lf_add_outgoing().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_add_incoming ( struct lockf *  state,
struct lockf_entry *  lock 
)
static

Definition at line 1059 of file kern_lockf.c.

References lf_add_edge(), lf_blocks(), and lf_remove_incoming().

Referenced by lf_setlock(), and lf_split().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_add_outgoing ( struct lockf *  state,
struct lockf_entry *  lock 
)
static

Definition at line 991 of file kern_lockf.c.

References lf_add_edge(), lf_blocks(), and lf_remove_outgoing().

Referenced by lf_setlock().

Here is the call graph for this function:

Here is the caller graph for this function:

int lf_advlock ( struct vop_advlock_args *  ap,
struct lockf **  statep,
u_quad_t  size 
)

Definition at line 759 of file kern_lockf.c.

References lf_advlockasync().

Referenced by vop_stdadvlock().

Here is the call graph for this function:

Here is the caller graph for this function:

int lf_advlockasync ( struct vop_advlockasync_args *  ap,
struct lockf **  statep,
u_quad_t  size 
)
static struct lockf_edge * lf_alloc_edge ( void  )
static

Definition at line 875 of file kern_lockf.c.

References malloc().

Referenced by lf_add_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct lockf_entry * lf_alloc_lock ( struct lock_owner lo)
static

Definition at line 330 of file kern_lockf.c.

References lf_lock_owners_lock, malloc(), and printf().

Referenced by lf_advlockasync(), and lf_split().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_alloc_vertex ( struct lockf_entry *  lock)
static

Definition at line 897 of file kern_lockf.c.

References graph_alloc_vertex(), and lf_owner_graph.

Referenced by lf_add_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_blocks ( struct lockf_entry *  x,
struct lockf_entry *  y 
)
static

Definition at line 863 of file kern_lockf.c.

References lf_overlaps().

Referenced by lf_add_incoming(), lf_add_outgoing(), lf_advlockasync(), lf_getblock(), and lf_update_dependancies().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_cancel ( struct lockf *  state,
struct lockf_entry *  lock,
void *  cookie 
)
static

Definition at line 1602 of file kern_lockf.c.

References lf_cancel_lock().

Referenced by lf_advlockasync().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_cancel_lock ( struct lockf *  state,
struct lockf_entry *  lock 
)
static

Definition at line 1325 of file kern_lockf.c.

References lf_activate_lock(), lf_free_lock(), lf_owner_graph_lock, lf_remove_outgoing(), and lf_update_dependancies().

Referenced by lf_cancel(), and lf_setlock().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_clearlock ( struct lockf *  state,
struct lockf_entry *  unlock 
)
static

Definition at line 1548 of file kern_lockf.c.

References lf_activate_lock(), NOLOCKF, and panic().

Referenced by lf_advlockasync().

Here is the call graph for this function:

Here is the caller graph for this function:

void lf_clearremotesys ( int  sysid)

Definition at line 2007 of file kern_lockf.c.

References lf_clearremotesys_iterator(), and lf_iteratelocks_sysid().

Referenced by lf_advlockasync().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_clearremotesys_iterator ( struct vnode *  vp,
struct flock *  fl,
void *  arg 
)
static

Definition at line 1999 of file kern_lockf.c.

Referenced by lf_clearremotesys().

Here is the caller graph for this function:

int lf_countlocks ( int  sysid)

Definition at line 2015 of file kern_lockf.c.

References count, lf_lock_owners, lf_lock_owners_lock, and LOCK_OWNER_HASH_SIZE.

static int lf_findoverlap ( struct lockf_entry **  overlap,
struct lockf_entry *  lock,
int  type 
)
static

Definition at line 1699 of file kern_lockf.c.

References NOLOCKF, OTHERS, panic(), printf(), SELF, and start.

Referenced by lf_activate_lock().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_free_edge ( struct lockf_edge *  e)
static

Definition at line 885 of file kern_lockf.c.

References free().

Referenced by lf_remove_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_free_lock ( struct lockf_entry *  lock)
static

Definition at line 351 of file kern_lockf.c.

References free(), graph_free_vertex(), lf_lock_owners_lock, lf_owner_graph, lf_owner_graph_lock, printf(), and vrele().

Referenced by lf_activate_lock(), lf_advlockasync(), lf_cancel_lock(), lf_purgelocks(), and lf_setlock().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct lockf_entry * lf_getblock ( struct lockf *  state,
struct lockf_entry *  lock 
)
static

Definition at line 1655 of file kern_lockf.c.

References lf_blocks(), and NOLOCKF.

Referenced by lf_getlock(), and lf_setlock().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_getlock ( struct lockf *  state,
struct lockf_entry *  lock,
struct flock *  fl 
)
static

Definition at line 1573 of file kern_lockf.c.

References lf_getblock().

Referenced by lf_advlockasync().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_hash_owner ( caddr_t  id,
struct flock *  fl,
int  flags 
)
static

Definition at line 295 of file kern_lockf.c.

References LOCK_OWNER_HASH_SIZE.

Referenced by lf_advlockasync().

Here is the caller graph for this function:

static void lf_init ( void *  dummy)
static

Definition at line 275 of file kern_lockf.c.

References graph_init(), lf_lock_owners, lf_lock_owners_lock, lf_lock_states, lf_lock_states_lock, lf_owner_graph, lf_owner_graph_lock, and LOCK_OWNER_HASH_SIZE.

Here is the call graph for this function:

static void lf_insert_lock ( struct lockf *  state,
struct lockf_entry *  lock 
)
static

Definition at line 1092 of file kern_lockf.c.

Referenced by lf_activate_lock(), lf_set_start(), and lf_split().

Here is the caller graph for this function:

int lf_iteratelocks_sysid ( int  sysid,
lf_iterator *  fn,
void *  arg 
)

Definition at line 1869 of file kern_lockf.c.

References free(), lf_lock_states, lf_lock_states_lock, malloc(), vref(), and vrele().

Referenced by lf_clearremotesys().

Here is the call graph for this function:

Here is the caller graph for this function:

int lf_iteratelocks_vnode ( struct vnode *  vp,
lf_iterator *  fn,
void *  arg 
)

Definition at line 1931 of file kern_lockf.c.

References free(), malloc(), vref(), vrele(), and wakeup().

Here is the call graph for this function:

static int lf_overlaps ( struct lockf_entry *  x,
struct lockf_entry *  y 
)
static

Definition at line 853 of file kern_lockf.c.

Referenced by lf_advlockasync(), and lf_blocks().

Here is the caller graph for this function:

static int lf_owner_matches ( struct lock_owner lo,
caddr_t  id,
struct flock *  fl,
int  flags 
)
static

Definition at line 318 of file kern_lockf.c.

Referenced by lf_advlockasync().

Here is the caller graph for this function:

void lf_purgelocks ( struct vnode *  vp,
struct lockf **  statep 
)

Definition at line 775 of file kern_lockf.c.

References free(), lf_free_lock(), lf_lock_states_lock, lf_owner_graph_lock, lf_remove_incoming(), lf_remove_outgoing(), sx_destroy(), and wakeup().

Referenced by vop_stdadvlockpurge().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_remove_edge ( struct lockf_edge *  e)
static

Definition at line 946 of file kern_lockf.c.

References graph_remove_edge(), lf_free_edge(), and lf_owner_graph.

Referenced by lf_remove_incoming(), lf_remove_outgoing(), and lf_update_dependancies().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_remove_incoming ( struct lockf_entry *  x)
static

Definition at line 977 of file kern_lockf.c.

References lf_remove_edge().

Referenced by lf_add_incoming(), and lf_purgelocks().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_remove_outgoing ( struct lockf_entry *  x)
static

Definition at line 964 of file kern_lockf.c.

References lf_remove_edge().

Referenced by lf_add_outgoing(), lf_cancel_lock(), and lf_purgelocks().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_set_end ( struct lockf *  state,
struct lockf_entry *  lock,
off_t  new_end,
struct lockf_entry_list *  granted 
)
static

Definition at line 1187 of file kern_lockf.c.

References lf_update_dependancies().

Referenced by lf_activate_lock(), and lf_split().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_set_start ( struct lockf *  state,
struct lockf_entry *  lock,
off_t  new_start,
struct lockf_entry_list *  granted 
)
static

Definition at line 1171 of file kern_lockf.c.

References lf_insert_lock(), and lf_update_dependancies().

Referenced by lf_activate_lock(), and lf_split().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lf_setlock ( struct lockf *  state,
struct lockf_entry *  lock,
struct vnode *  vp,
void **  cookiep 
)
static

Definition at line 1376 of file kern_lockf.c.

References lf_activate_lock(), lf_add_incoming(), lf_add_outgoing(), lf_cancel_lock(), lf_free_lock(), lf_getblock(), lf_owner_graph_lock, and priority.

Referenced by lf_advlockasync().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_split ( struct lockf *  state,
struct lockf_entry *  lock1,
struct lockf_entry *  lock2,
struct lockf_entry_list *  granted 
)
static

Definition at line 1807 of file kern_lockf.c.

References lf_add_incoming(), lf_alloc_lock(), lf_insert_lock(), lf_owner_graph_lock, lf_set_end(), lf_set_start(), and vref().

Referenced by lf_activate_lock().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_update_dependancies ( struct lockf *  state,
struct lockf_entry *  lock,
int  all,
struct lockf_entry_list *  granted 
)
static

Definition at line 1146 of file kern_lockf.c.

References lf_blocks(), lf_owner_graph_lock, lf_remove_edge(), and lf_wakeup_lock().

Referenced by lf_activate_lock(), lf_cancel_lock(), lf_set_end(), and lf_set_start().

Here is the call graph for this function:

Here is the caller graph for this function:

static void lf_wakeup_lock ( struct lockf *  state,
struct lockf_entry *  wakelock 
)
static

Definition at line 1119 of file kern_lockf.c.

References taskqueue_enqueue(), and wakeup().

Referenced by lf_update_dependancies().

Here is the call graph for this function:

Here is the caller graph for this function:

LIST_HEAD ( lock_owner_list  ,
lock_owner   
)
LIST_HEAD ( owner_edge_list  ,
owner_edge   
)
static MALLOC_DEFINE ( M_LOCKF  ,
"lockf"  ,
"Byte-range locking structures"   
)
static
STAILQ_HEAD ( lockdesclist  ,
lockdesc   
)
SYSINIT ( lf_init  ,
SI_SUB_LOCK  ,
SI_ORDER_FIRST  ,
lf_init  ,
NULL   
)
TAILQ_HEAD ( owner_vertex_list  ,
owner_vertex   
)

Variable Documentation

struct lock_owner_list lf_lock_owners[LOCK_OWNER_HASH_SIZE]
static

Definition at line 208 of file kern_lockf.c.

Referenced by lf_advlockasync(), lf_countlocks(), and lf_init().

struct sx lf_lock_owners_lock
static

Definition at line 207 of file kern_lockf.c.

Referenced by lf_advlockasync(), lf_alloc_lock(), lf_countlocks(), lf_free_lock(), and lf_init().

struct lockf_list lf_lock_states
static

Definition at line 206 of file kern_lockf.c.

Referenced by lf_advlockasync(), lf_init(), and lf_iteratelocks_sysid().

struct sx lf_lock_states_lock
static

Definition at line 205 of file kern_lockf.c.

Referenced by lf_advlockasync(), lf_init(), lf_iteratelocks_sysid(), and lf_purgelocks().

struct owner_graph lf_owner_graph
static

Definition at line 269 of file kern_lockf.c.

Referenced by lf_add_edge(), lf_alloc_vertex(), lf_free_lock(), lf_init(), and lf_remove_edge().