Lines Matching refs:tbl

27 static void nfs4_init_slot_table(struct nfs4_slot_table *tbl, const char *queue)
29 tbl->highest_used_slotid = NFS4_NO_SLOT;
30 spin_lock_init(&tbl->slot_tbl_lock);
31 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, queue);
32 init_waitqueue_head(&tbl->slot_waitq);
33 init_completion(&tbl->complete);
39 static void nfs4_shrink_slot_table(struct nfs4_slot_table *tbl, u32 newsize)
42 if (newsize >= tbl->max_slots)
45 p = &tbl->slots;
53 tbl->max_slots--;
59 * @tbl: controlling slot table
62 void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl)
64 if (nfs4_slot_tbl_draining(tbl))
65 complete(&tbl->complete);
81 * Must be called while holding tbl->slot_tbl_lock
83 void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot)
88 __clear_bit(slotid, tbl->used_slots);
91 if (slotid == tbl->highest_used_slotid) {
92 u32 new_max = find_last_bit(tbl->used_slots, slotid);
94 tbl->highest_used_slotid = new_max;
96 tbl->highest_used_slotid = NFS4_NO_SLOT;
97 nfs4_slot_tbl_drain_complete(tbl);
101 slotid, tbl->highest_used_slotid);
104 static struct nfs4_slot *nfs4_new_slot(struct nfs4_slot_table *tbl,
111 slot->table = tbl;
120 static struct nfs4_slot *nfs4_find_or_create_slot(struct nfs4_slot_table *tbl,
125 p = &tbl->slots;
128 *p = nfs4_new_slot(tbl, tbl->max_slots,
132 tbl->max_slots++;
142 static void nfs4_lock_slot(struct nfs4_slot_table *tbl,
147 __set_bit(slotid, tbl->used_slots);
148 if (slotid > tbl->highest_used_slotid ||
149 tbl->highest_used_slotid == NFS4_NO_SLOT)
150 tbl->highest_used_slotid = slotid;
151 slot->generation = tbl->generation;
159 bool nfs4_try_to_lock_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot)
161 if (nfs4_test_locked_slot(tbl, slot->slot_nr))
163 nfs4_lock_slot(tbl, slot);
172 struct nfs4_slot *nfs4_lookup_slot(struct nfs4_slot_table *tbl, u32 slotid)
174 if (slotid <= tbl->max_slotid)
175 return nfs4_find_or_create_slot(tbl, slotid, 0, GFP_NOWAIT);
179 static int nfs4_slot_get_seqid(struct nfs4_slot_table *tbl, u32 slotid,
181 __must_hold(&tbl->slot_tbl_lock)
186 slot = nfs4_lookup_slot(tbl, slotid);
201 static bool nfs4_slot_seqid_in_use(struct nfs4_slot_table *tbl,
207 spin_lock(&tbl->slot_tbl_lock);
208 if (nfs4_slot_get_seqid(tbl, slotid, &cur_seq) == 0 &&
209 cur_seq == seq_nr && test_bit(slotid, tbl->used_slots))
211 spin_unlock(&tbl->slot_tbl_lock);
222 int nfs4_slot_wait_on_seqid(struct nfs4_slot_table *tbl,
226 if (wait_event_timeout(tbl->slot_waitq,
227 !nfs4_slot_seqid_in_use(tbl, slotid, seq_nr),
242 struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl)
248 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
249 tbl->max_slotid + 1);
250 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slotid + 1);
251 if (slotid <= tbl->max_slotid) {
252 ret = nfs4_find_or_create_slot(tbl, slotid, 1, GFP_NOWAIT);
254 nfs4_lock_slot(tbl, ret);
257 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
262 static int nfs4_grow_slot_table(struct nfs4_slot_table *tbl,
265 if (max_reqs <= tbl->max_slots)
267 if (!IS_ERR(nfs4_find_or_create_slot(tbl, max_reqs - 1, ivalue, GFP_NOFS)))
272 static void nfs4_reset_slot_table(struct nfs4_slot_table *tbl,
278 nfs4_shrink_slot_table(tbl, server_highest_slotid + 1);
279 p = &tbl->slots;
286 tbl->highest_used_slotid = NFS4_NO_SLOT;
287 tbl->target_highest_slotid = server_highest_slotid;
288 tbl->server_highest_slotid = server_highest_slotid;
289 tbl->d_target_highest_slotid = 0;
290 tbl->d2_target_highest_slotid = 0;
291 tbl->max_slotid = server_highest_slotid;
297 static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl,
302 dprintk("--> %s: max_reqs=%u, tbl->max_slots %u\n", __func__,
303 max_reqs, tbl->max_slots);
308 ret = nfs4_grow_slot_table(tbl, max_reqs, ivalue);
312 spin_lock(&tbl->slot_tbl_lock);
313 nfs4_reset_slot_table(tbl, max_reqs - 1, ivalue);
314 spin_unlock(&tbl->slot_tbl_lock);
316 dprintk("%s: tbl=%p slots=%p max_slots=%u\n", __func__,
317 tbl, tbl->slots, tbl->max_slots);
326 static void nfs4_release_slot_table(struct nfs4_slot_table *tbl)
328 nfs4_shrink_slot_table(tbl, 0);
333 * @tbl: slot table to shut down
336 void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl)
338 nfs4_release_slot_table(tbl);
339 rpc_destroy_wait_queue(&tbl->slot_tbl_waitq);
344 * @tbl: slot table to set up
350 int nfs4_setup_slot_table(struct nfs4_slot_table *tbl, unsigned int max_reqs,
353 nfs4_init_slot_table(tbl, queue);
354 return nfs4_realloc_slot_table(tbl, max_reqs, 0);
362 struct nfs4_slot_table *tbl = slot->table;
364 if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged)
366 slot->generation = tbl->generation;
375 static bool __nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
378 if (rpc_wake_up_first(&tbl->slot_tbl_waitq, nfs41_assign_slot, slot))
383 bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
386 if (slot->slot_nr > tbl->max_slotid)
388 return __nfs41_wake_and_assign_slot(tbl, slot);
391 static bool nfs41_try_wake_next_slot_table_entry(struct nfs4_slot_table *tbl)
393 struct nfs4_slot *slot = nfs4_alloc_slot(tbl);
395 bool ret = __nfs41_wake_and_assign_slot(tbl, slot);
398 nfs4_free_slot(tbl, slot);
403 void nfs41_wake_slot_table(struct nfs4_slot_table *tbl)
406 if (!nfs41_try_wake_next_slot_table_entry(tbl))
413 static void nfs41_set_max_slotid_locked(struct nfs4_slot_table *tbl,
419 if (max_slotid > tbl->server_highest_slotid)
420 max_slotid = tbl->server_highest_slotid;
421 if (max_slotid > tbl->target_highest_slotid)
422 max_slotid = tbl->target_highest_slotid;
423 tbl->max_slotid = max_slotid;
424 nfs41_wake_slot_table(tbl);
428 static void nfs41_set_target_slotid_locked(struct nfs4_slot_table *tbl,
431 if (tbl->target_highest_slotid == target_highest_slotid)
433 tbl->target_highest_slotid = target_highest_slotid;
434 tbl->generation++;
437 void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
440 spin_lock(&tbl->slot_tbl_lock);
441 nfs41_set_target_slotid_locked(tbl, target_highest_slotid);
442 tbl->d_target_highest_slotid = 0;
443 tbl->d2_target_highest_slotid = 0;
444 nfs41_set_max_slotid_locked(tbl, target_highest_slotid);
445 spin_unlock(&tbl->slot_tbl_lock);
448 static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl,
451 if (tbl->server_highest_slotid == highest_slotid)
453 if (tbl->highest_used_slotid > highest_slotid)
456 nfs4_shrink_slot_table(tbl, highest_slotid + 1);
457 tbl->server_highest_slotid = highest_slotid;
489 static bool nfs41_is_outlier_target_slotid(struct nfs4_slot_table *tbl,
496 tbl->target_highest_slotid);
498 tbl->d_target_highest_slotid);
500 if (nfs41_same_sign_or_zero_s32(d_target, tbl->d_target_highest_slotid))
503 if (nfs41_same_sign_or_zero_s32(d2_target, tbl->d2_target_highest_slotid))
505 tbl->d_target_highest_slotid = d_target;
506 tbl->d2_target_highest_slotid = d2_target;
510 void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
518 spin_lock(&tbl->slot_tbl_lock);
519 if (!nfs41_is_outlier_target_slotid(tbl, target_highest_slotid))
520 nfs41_set_target_slotid_locked(tbl, target_highest_slotid);
521 if (tbl->generation == slot->generation)
522 nfs41_set_server_slotid_locked(tbl, highest_slotid);
523 nfs41_set_max_slotid_locked(tbl, target_highest_slotid);
524 spin_unlock(&tbl->slot_tbl_lock);
538 struct nfs4_slot_table *tbl;
543 tbl = &ses->fc_slot_table;
544 tbl->session = ses;
545 status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1);
549 tbl = &ses->bc_slot_table;
550 tbl->session = ses;
551 status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0);
552 if (status && tbl->slots == NULL)