MCPcopy Create free account
hub / github.com/F-Stack/f-stack / lf_activate_lock

Function lf_activate_lock

freebsd/kern/kern_lockf.c:1213–1320  ·  view source on GitHub ↗

* Add a lock to the active list, updating or removing any current * locks owned by the same owner and processing any pending locks that * become unblocked as a result. This code is also used for unlock * since the logic for updating existing locks is identical. * * As a result of processing the new lock, we may unblock existing * pending locks as a result of downgrading/unlocking. We simply

Source from the content-addressed store, hash-verified

1211 * not a real problem.
1212 */
1213static void
1214lf_activate_lock(struct lockf *state, struct lockf_entry *lock)
1215{
1216 struct lockf_entry *overlap, *lf;
1217 struct lockf_entry_list granted;
1218 int ovcase;
1219
1220 LIST_INIT(&granted);
1221 LIST_INSERT_HEAD(&granted, lock, lf_link);
1222
1223 while (!LIST_EMPTY(&granted)) {
1224 lock = LIST_FIRST(&granted);
1225 LIST_REMOVE(lock, lf_link);
1226
1227 /*
1228 * Skip over locks owned by other processes. Handle
1229 * any locks that overlap and are owned by ourselves.
1230 */
1231 overlap = LIST_FIRST(&state->ls_active);
1232 for (;;) {
1233 ovcase = lf_findoverlap(&overlap, lock, SELF);
1234
1235#ifdef LOCKF_DEBUG
1236 if (ovcase && (lockf_debug & 2)) {
1237 printf("lf_setlock: overlap %d", ovcase);
1238 lf_print("", overlap);
1239 }
1240#endif
1241 /*
1242 * Six cases:
1243 * 0) no overlap
1244 * 1) overlap == lock
1245 * 2) overlap contains lock
1246 * 3) lock contains overlap
1247 * 4) overlap starts before lock
1248 * 5) overlap ends after lock
1249 */
1250 switch (ovcase) {
1251 case 0: /* no overlap */
1252 break;
1253
1254 case 1: /* overlap == lock */
1255 /*
1256 * We have already setup the
1257 * dependants for the new lock, taking
1258 * into account a possible downgrade
1259 * or unlock. Remove the old lock.
1260 */
1261 LIST_REMOVE(overlap, lf_link);
1262 lf_update_dependancies(state, overlap, TRUE,
1263 &granted);
1264 lf_free_lock(overlap);
1265 break;
1266
1267 case 2: /* overlap contains lock */
1268 /*
1269 * Just split the existing lock.
1270 */

Callers 3

lf_cancel_lockFunction · 0.85
lf_setlockFunction · 0.85
lf_clearlockFunction · 0.85

Calls 10

lf_findoverlapFunction · 0.85
lf_printFunction · 0.85
lf_update_dependanciesFunction · 0.85
lf_free_lockFunction · 0.85
lf_splitFunction · 0.85
lf_set_endFunction · 0.85
lf_set_startFunction · 0.85
lf_printlistFunction · 0.85
lf_insert_lockFunction · 0.85
printfFunction · 0.70

Tested by

no test coverage detected