| 1294 | } |
| 1295 | |
| 1296 | int |
| 1297 | __lockmgr_args(struct lock *lk, u_int flags, struct lock_object *ilk, |
| 1298 | const char *wmesg, int pri, int timo, const char *file, int line) |
| 1299 | { |
| 1300 | GIANT_DECLARE; |
| 1301 | struct lockmgr_wait lwa; |
| 1302 | struct lock_class *class; |
| 1303 | const char *iwmesg; |
| 1304 | uintptr_t tid, v, x; |
| 1305 | u_int op, realexslp; |
| 1306 | int error, ipri, itimo, queue, wakeup_swapper; |
| 1307 | #ifdef LOCK_PROFILING |
| 1308 | uint64_t waittime = 0; |
| 1309 | int contested = 0; |
| 1310 | #endif |
| 1311 | |
| 1312 | if (KERNEL_PANICKED()) |
| 1313 | return (0); |
| 1314 | |
| 1315 | error = 0; |
| 1316 | tid = (uintptr_t)curthread; |
| 1317 | op = (flags & LK_TYPE_MASK); |
| 1318 | iwmesg = (wmesg == LK_WMESG_DEFAULT) ? lk->lock_object.lo_name : wmesg; |
| 1319 | ipri = (pri == LK_PRIO_DEFAULT) ? lk->lk_pri : pri; |
| 1320 | itimo = (timo == LK_TIMO_DEFAULT) ? lk->lk_timo : timo; |
| 1321 | |
| 1322 | lwa.iwmesg = iwmesg; |
| 1323 | lwa.ipri = ipri; |
| 1324 | lwa.itimo = itimo; |
| 1325 | |
| 1326 | MPASS((flags & ~LK_TOTAL_MASK) == 0); |
| 1327 | KASSERT((op & (op - 1)) == 0, |
| 1328 | ("%s: Invalid requested operation @ %s:%d", __func__, file, line)); |
| 1329 | KASSERT((flags & (LK_NOWAIT | LK_SLEEPFAIL)) == 0 || |
| 1330 | (op != LK_DOWNGRADE && op != LK_RELEASE), |
| 1331 | ("%s: Invalid flags in regard of the operation desired @ %s:%d", |
| 1332 | __func__, file, line)); |
| 1333 | KASSERT((flags & LK_INTERLOCK) == 0 || ilk != NULL, |
| 1334 | ("%s: LK_INTERLOCK passed without valid interlock @ %s:%d", |
| 1335 | __func__, file, line)); |
| 1336 | KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), |
| 1337 | ("%s: idle thread %p on lockmgr %s @ %s:%d", __func__, curthread, |
| 1338 | lk->lock_object.lo_name, file, line)); |
| 1339 | |
| 1340 | class = (flags & LK_INTERLOCK) ? LOCK_CLASS(ilk) : NULL; |
| 1341 | |
| 1342 | if (lk->lock_object.lo_flags & LK_NOSHARE) { |
| 1343 | switch (op) { |
| 1344 | case LK_SHARED: |
| 1345 | op = LK_EXCLUSIVE; |
| 1346 | break; |
| 1347 | case LK_UPGRADE: |
| 1348 | case LK_TRYUPGRADE: |
| 1349 | case LK_DOWNGRADE: |
| 1350 | _lockmgr_assert(lk, KA_XLOCKED | KA_NOTRECURSED, |
| 1351 | file, line); |
| 1352 | if (flags & LK_INTERLOCK) |
| 1353 | class->lc_unlock(ilk); |
no test coverage detected