Lines Matching defs:nf
123 struct nfsd_file *nf = container_of(rcu, struct nfsd_file, nf_rcu);
125 put_cred(nf->nf_cred);
126 kmem_cache_free(nfsd_file_slab, nf);
214 struct nfsd_file *nf;
216 nf = kmem_cache_alloc(nfsd_file_slab, GFP_KERNEL);
217 if (unlikely(!nf))
221 INIT_LIST_HEAD(&nf->nf_lru);
222 INIT_LIST_HEAD(&nf->nf_gc);
223 nf->nf_birthtime = ktime_get();
224 nf->nf_file = NULL;
225 nf->nf_cred = get_current_cred();
226 nf->nf_net = net;
227 nf->nf_flags = want_gc ?
230 nf->nf_inode = inode;
231 refcount_set(&nf->nf_ref, 1);
232 nf->nf_may = need;
233 nf->nf_mark = NULL;
234 return nf;
239 * @nf: nfsd_file to check for writeback errors
245 nfsd_file_check_write_error(struct nfsd_file *nf)
247 struct file *file = nf->nf_file;
251 nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
255 nfsd_file_hash_remove(struct nfsd_file *nf)
257 trace_nfsd_file_unhash(nf);
258 rhltable_remove(&nfsd_file_rhltable, &nf->nf_rlist,
263 nfsd_file_unhash(struct nfsd_file *nf)
265 if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
266 nfsd_file_hash_remove(nf);
273 nfsd_file_free(struct nfsd_file *nf)
275 s64 age = ktime_to_ms(ktime_sub(ktime_get(), nf->nf_birthtime));
277 trace_nfsd_file_free(nf);
282 nfsd_file_unhash(nf);
283 if (nf->nf_mark)
284 nfsd_file_mark_put(nf->nf_mark);
285 if (nf->nf_file) {
286 nfsd_file_check_write_error(nf);
287 nfsd_filp_close(nf->nf_file);
294 if (WARN_ON_ONCE(!list_empty(&nf->nf_lru)))
297 call_rcu(&nf->nf_rcu, nfsd_file_slab_free);
301 nfsd_file_check_writeback(struct nfsd_file *nf)
303 struct file *file = nf->nf_file;
322 static void nfsd_file_lru_add(struct nfsd_file *nf)
324 refcount_inc(&nf->nf_ref);
325 if (list_lru_add_obj(&nfsd_file_lru, &nf->nf_lru))
326 trace_nfsd_file_lru_add(nf);
332 static bool nfsd_file_lru_remove(struct nfsd_file *nf)
334 if (list_lru_del_obj(&nfsd_file_lru, &nf->nf_lru)) {
335 trace_nfsd_file_lru_del(nf);
342 nfsd_file_get(struct nfsd_file *nf)
344 if (nf && refcount_inc_not_zero(&nf->nf_ref))
345 return nf;
351 * @nf: nfsd_file of which to put the reference
358 nfsd_file_put(struct nfsd_file *nf)
361 trace_nfsd_file_put(nf);
363 if (test_bit(NFSD_FILE_GC, &nf->nf_flags) &&
364 test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
365 set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);
366 set_bit(NFSD_FILE_RECENT, &nf->nf_flags);
369 if (refcount_dec_and_test(&nf->nf_ref))
370 nfsd_file_free(nf);
375 * @nf: nfsd_file of which to put the reference
383 struct nfsd_file *nf;
386 nf = unrcu_pointer(xchg(pnf, NULL));
387 if (nf) {
388 net = nf->nf_net;
389 nfsd_file_put(nf);
396 * @nf: nfsd_file of which to put the reference
398 * Get reference to both the nfsd_file and nf->nf_net.
401 nfsd_file_get_local(struct nfsd_file *nf)
403 struct net *net = nf->nf_net;
406 nf = nfsd_file_get(nf);
407 if (!nf)
410 nf = NULL;
412 return nf;
417 * @nf: nfsd_file of which to access the backing file.
419 * Return backing file for @nf.
422 nfsd_file_file(struct nfsd_file *nf)
424 return nf->nf_file;
430 struct nfsd_file *nf;
433 nf = list_first_entry(dispose, struct nfsd_file, nf_gc);
434 list_del_init(&nf->nf_gc);
435 nfsd_file_free(nf);
450 struct nfsd_file *nf = list_first_entry(dispose,
452 struct nfsd_net *nn = net_generic(nf->nf_net, nfsd_net_id);
457 list_move_tail(&nf->nf_gc, &l->freeme);
517 struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru);
520 WARN_ON_ONCE(!test_bit(NFSD_FILE_GC, &nf->nf_flags));
526 if (nfsd_file_check_writeback(nf)) {
527 trace_nfsd_file_gc_writeback(nf);
532 if (test_and_clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags)) {
533 trace_nfsd_file_gc_referenced(nf);
541 if (!refcount_dec_if_one(&nf->nf_ref)) {
542 trace_nfsd_file_gc_in_use(nf);
547 nfsd_file_unhash(nf);
548 list_lru_isolate(lru, &nf->nf_lru);
549 list_add(&nf->nf_gc, head);
551 trace_nfsd_file_gc_disposed(nf);
559 struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru);
561 if (test_and_clear_bit(NFSD_FILE_RECENT, &nf->nf_flags)) {
566 clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);
567 trace_nfsd_file_gc_aged(nf);
642 * @nf: nfsd_file to attempt to queue
649 nfsd_file_cond_queue(struct nfsd_file *nf, struct list_head *dispose)
655 if (!nfsd_file_unhash(nf))
659 if (!nfsd_file_get(nf))
663 if (nfsd_file_lru_remove(nf))
667 if (refcount_sub_and_test(decrement, &nf->nf_ref)) {
668 list_add(&nf->nf_gc, dispose);
669 trace_nfsd_file_closing(nf);
693 struct nfsd_file *nf;
698 rhl_for_each_entry_rcu(nf, tmp, list, nf_rlist) {
699 if (!test_bit(NFSD_FILE_GC, &nf->nf_flags))
701 nfsd_file_cond_queue(nf, dispose);
886 struct nfsd_file *nf;
901 nf = rhashtable_walk_next(&iter);
902 while (!IS_ERR_OR_NULL(nf)) {
903 if (!net || nf->nf_net == net)
904 nfsd_file_cond_queue(nf, &dispose);
905 nf = rhashtable_walk_next(&iter);
909 } while (nf == ERR_PTR(-EAGAIN));
1017 struct nfsd_file *nf;
1021 rhl_for_each_entry_rcu(nf, tmp, list, nf_rlist) {
1022 if (nf->nf_may != need)
1024 if (nf->nf_net != net)
1026 if (!nfsd_match_cred(nf->nf_cred, cred))
1028 if (test_bit(NFSD_FILE_GC, &nf->nf_flags) != want_gc)
1030 if (test_bit(NFSD_FILE_HASHED, &nf->nf_flags) == 0)
1033 if (!nfsd_file_get(nf))
1035 return nf;
1055 struct nfsd_file *nf;
1061 rhl_for_each_entry_rcu(nf, tmp, list, nf_rlist)
1062 if (test_bit(NFSD_FILE_GC, &nf->nf_flags)) {
1081 struct nfsd_file *new, *nf;
1101 nf = nfsd_file_lookup_locked(net, current_cred(), inode, need, want_gc);
1104 if (nf)
1115 nf = nfsd_file_lookup_locked(net, current_cred(), inode, need, want_gc);
1116 if (unlikely(nf)) {
1122 nf = new;
1123 ret = rhltable_insert(&nfsd_file_rhltable, &nf->nf_rlist,
1135 wait_on_bit(&nf->nf_flags, NFSD_FILE_PENDING, TASK_UNINTERRUPTIBLE);
1138 if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
1139 trace_nfsd_file_cons_err(rqstp, inode, may_flags, nf);
1144 nfsd_file_put(nf);
1151 status = nfserrno(nfsd_open_break_lease(file_inode(nf->nf_file), may_flags));
1153 nfsd_file_put(nf);
1154 nf = NULL;
1160 nfsd_file_check_write_error(nf);
1161 *pnf = nf;
1163 trace_nfsd_file_acquire(rqstp, inode, may_flags, nf, status);
1167 trace_nfsd_file_alloc(nf);
1168 nf->nf_mark = nfsd_file_mark_find_or_create(inode);
1169 if (nf->nf_mark) {
1172 nf->nf_file = file;
1174 trace_nfsd_file_opened(nf, status);
1176 ret = nfsd_open_verified(fhp, may_flags, &nf->nf_file);
1179 nfsd_file_unhash(nf);
1181 &nf->nf_flags);
1182 if (refcount_dec_and_test(&nf->nf_ref))
1183 nfsd_file_free(nf);
1184 nf = NULL;
1189 trace_nfsd_file_open(nf, status);
1198 nfsd_file_unhash(nf);
1200 nfsd_file_lru_add(nf);
1202 clear_and_wake_up_bit(NFSD_FILE_PENDING, &nf->nf_flags);
1207 if (refcount_dec_and_test(&nf->nf_ref))
1208 nfsd_file_free(nf);
1209 nf = NULL;