4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 #include <linux/sched.h>
35 #include <linux/kthread.h>
37 #include <linux/highmem.h>
38 #include <linux/pagemap.h>
40 #define DEBUG_SUBSYSTEM S_LLITE
42 #include <obd_support.h>
43 #include <lustre_dlm.h>
44 #include "llite_internal.h"
46 #define SA_OMITTED_ENTRY_MAX 8ULL
49 /** negative values are for error cases */
50 SA_ENTRY_INIT = 0, /** init entry */
51 SA_ENTRY_SUCC = 1, /** stat succeed */
52 SA_ENTRY_INVA = 2, /** invalid entry */
55 /* sa_entry is not refcounted: statahead thread allocates it and do async stat,
56 * and in async stat callback ll_statahead_interpret() will add it into
57 * sai_interim_entries, later statahead thread will call sa_handle_callback() to
58 * instantiate entry and move it into sai_entries, and then only scanner process
59 * can access and free it. */
61 /* link into sai_interim_entries or sai_entries */
62 struct list_head se_list;
63 /* link into sai hash table locally */
64 struct list_head se_hash;
65 /* entry index in the sai */
67 /* low layer ldlm lock handle */
71 /* entry size, contains name */
73 /* pointer to async getattr enqueue info */
74 struct md_enqueue_info *se_minfo;
75 /* pointer to the async getattr request */
76 struct ptlrpc_request *se_req;
77 /* pointer to the target inode */
78 struct inode *se_inode;
85 static unsigned int sai_generation = 0;
86 static DEFINE_SPINLOCK(sai_generation_lock);
88 static inline int sa_unhashed(struct sa_entry *entry)
90 return list_empty(&entry->se_hash);
93 /* sa_entry is ready to use */
94 static inline int sa_ready(struct sa_entry *entry)
97 return (entry->se_state != SA_ENTRY_INIT);
100 /* hash value to put in sai_cache */
101 static inline int sa_hash(int val)
103 return val & LL_SA_CACHE_MASK;
106 /* hash entry into sai_cache */
108 sa_rehash(struct ll_statahead_info *sai, struct sa_entry *entry)
110 int i = sa_hash(entry->se_qstr.hash);
112 spin_lock(&sai->sai_cache_lock[i]);
113 list_add_tail(&entry->se_hash, &sai->sai_cache[i]);
114 spin_unlock(&sai->sai_cache_lock[i]);
117 /* unhash entry from sai_cache */
119 sa_unhash(struct ll_statahead_info *sai, struct sa_entry *entry)
121 int i = sa_hash(entry->se_qstr.hash);
123 spin_lock(&sai->sai_cache_lock[i]);
124 list_del_init(&entry->se_hash);
125 spin_unlock(&sai->sai_cache_lock[i]);
128 static inline int agl_should_run(struct ll_statahead_info *sai,
131 return (inode != NULL && S_ISREG(inode->i_mode) && sai->sai_agl_valid);
134 static inline struct ll_inode_info *
135 agl_first_entry(struct ll_statahead_info *sai)
137 return list_entry(sai->sai_agls.next, struct ll_inode_info,
141 /* statahead window is full */
142 static inline int sa_sent_full(struct ll_statahead_info *sai)
144 return atomic_read(&sai->sai_cache_count) >= sai->sai_max;
147 /* got async stat replies */
148 static inline int sa_has_callback(struct ll_statahead_info *sai)
150 return !list_empty(&sai->sai_interim_entries);
153 static inline int agl_list_empty(struct ll_statahead_info *sai)
155 return list_empty(&sai->sai_agls);
159 * (1) hit ratio less than 80%
161 * (2) consecutive miss more than 8
162 * then means low hit.
164 static inline int sa_low_hit(struct ll_statahead_info *sai)
166 return ((sai->sai_hit > 7 && sai->sai_hit < 4 * sai->sai_miss) ||
167 (sai->sai_consecutive_miss > 8));
171 * if the given index is behind of statahead window more than
172 * SA_OMITTED_ENTRY_MAX, then it is old.
174 static inline int is_omitted_entry(struct ll_statahead_info *sai, __u64 index)
176 return ((__u64)sai->sai_max + index + SA_OMITTED_ENTRY_MAX <
180 /* allocate sa_entry and hash it to allow scanner process to find it */
181 static struct sa_entry *
182 sa_alloc(struct dentry *parent, struct ll_statahead_info *sai, __u64 index,
183 const char *name, int len, const struct lu_fid *fid)
185 struct ll_inode_info *lli;
186 struct sa_entry *entry;
191 entry_size = sizeof(struct sa_entry) + (len & ~3) + 4;
192 OBD_ALLOC(entry, entry_size);
193 if (unlikely(entry == NULL))
194 RETURN(ERR_PTR(-ENOMEM));
196 CDEBUG(D_READA, "alloc sa entry %.*s(%p) index %llu\n",
197 len, name, entry, index);
199 entry->se_index = index;
201 entry->se_state = SA_ENTRY_INIT;
202 entry->se_size = entry_size;
203 dname = (char *)entry + sizeof(struct sa_entry);
204 memcpy(dname, name, len);
206 entry->se_qstr.hash = ll_full_name_hash(parent, name, len);
207 entry->se_qstr.len = len;
208 entry->se_qstr.name = dname;
209 entry->se_fid = *fid;
211 lli = ll_i2info(sai->sai_dentry->d_inode);
213 spin_lock(&lli->lli_sa_lock);
214 INIT_LIST_HEAD(&entry->se_list);
215 sa_rehash(sai, entry);
216 spin_unlock(&lli->lli_sa_lock);
218 atomic_inc(&sai->sai_cache_count);
223 /* free sa_entry, which should have been unhashed and not in any list */
224 static void sa_free(struct ll_statahead_info *sai, struct sa_entry *entry)
226 CDEBUG(D_READA, "free sa entry %.*s(%p) index %llu\n",
227 entry->se_qstr.len, entry->se_qstr.name, entry,
230 LASSERT(list_empty(&entry->se_list));
231 LASSERT(sa_unhashed(entry));
233 OBD_FREE(entry, entry->se_size);
234 atomic_dec(&sai->sai_cache_count);
238 * find sa_entry by name, used by directory scanner, lock is not needed because
239 * only scanner can remove the entry from cache.
241 static struct sa_entry *
242 sa_get(struct ll_statahead_info *sai, const struct qstr *qstr)
244 struct sa_entry *entry;
245 int i = sa_hash(qstr->hash);
247 list_for_each_entry(entry, &sai->sai_cache[i], se_hash) {
248 if (entry->se_qstr.hash == qstr->hash &&
249 entry->se_qstr.len == qstr->len &&
250 memcmp(entry->se_qstr.name, qstr->name, qstr->len) == 0)
256 /* unhash and unlink sa_entry, and then free it */
258 sa_kill(struct ll_statahead_info *sai, struct sa_entry *entry)
260 struct ll_inode_info *lli = ll_i2info(sai->sai_dentry->d_inode);
262 LASSERT(!sa_unhashed(entry));
263 LASSERT(!list_empty(&entry->se_list));
264 LASSERT(sa_ready(entry));
266 sa_unhash(sai, entry);
268 spin_lock(&lli->lli_sa_lock);
269 list_del_init(&entry->se_list);
270 spin_unlock(&lli->lli_sa_lock);
272 if (entry->se_inode != NULL)
273 iput(entry->se_inode);
278 /* called by scanner after use, sa_entry will be killed */
280 sa_put(struct ll_statahead_info *sai, struct sa_entry *entry)
282 struct sa_entry *tmp, *next;
284 if (entry != NULL && entry->se_state == SA_ENTRY_SUCC) {
285 struct ll_sb_info *sbi = ll_i2sbi(sai->sai_dentry->d_inode);
288 sai->sai_consecutive_miss = 0;
289 sai->sai_max = min(2 * sai->sai_max, sbi->ll_sa_max);
292 sai->sai_consecutive_miss++;
298 /* kill old completed entries, only scanner process does this, no need
300 list_for_each_entry_safe(tmp, next, &sai->sai_entries, se_list) {
301 if (!is_omitted_entry(sai, tmp->se_index))
306 wake_up(&sai->sai_thread.t_ctl_waitq);
309 /* update state and sort add entry to sai_entries by index, return true if
310 * scanner is waiting on this entry. */
312 __sa_make_ready(struct ll_statahead_info *sai, struct sa_entry *entry, int ret)
315 struct list_head *pos = &sai->sai_entries;
316 __u64 index = entry->se_index;
318 LASSERT(!sa_ready(entry));
319 LASSERT(list_empty(&entry->se_list));
321 list_for_each_entry_reverse(se, &sai->sai_entries, se_list) {
322 if (se->se_index < entry->se_index) {
327 list_add(&entry->se_list, pos);
329 * LU-9210: ll_statahead_interpet must be able to see this before
332 smp_store_release(&entry->se_state, ret < 0 ? SA_ENTRY_INVA : SA_ENTRY_SUCC);
334 return (index == sai->sai_index_wait);
337 /* finish async stat RPC arguments */
338 static void sa_fini_data(struct md_enqueue_info *minfo)
340 ll_unlock_md_op_lsm(&minfo->mi_data);
345 static int ll_statahead_interpret(struct ptlrpc_request *req,
346 struct md_enqueue_info *minfo, int rc);
349 * prepare arguments for async stat RPC.
351 static struct md_enqueue_info *
352 sa_prep_data(struct inode *dir, struct inode *child, struct sa_entry *entry)
354 struct md_enqueue_info *minfo;
355 struct ldlm_enqueue_info *einfo;
356 struct md_op_data *op_data;
358 OBD_ALLOC_PTR(minfo);
360 return ERR_PTR(-ENOMEM);
362 op_data = ll_prep_md_op_data(&minfo->mi_data, dir, child,
363 entry->se_qstr.name, entry->se_qstr.len, 0,
364 LUSTRE_OPC_ANY, NULL);
365 if (IS_ERR(op_data)) {
367 return (struct md_enqueue_info *)op_data;
371 op_data->op_fid2 = entry->se_fid;
373 minfo->mi_it.it_op = IT_GETATTR;
374 minfo->mi_dir = igrab(dir);
375 minfo->mi_cb = ll_statahead_interpret;
376 minfo->mi_cbdata = entry;
378 einfo = &minfo->mi_einfo;
379 einfo->ei_type = LDLM_IBITS;
380 einfo->ei_mode = it_to_lock_mode(&minfo->mi_it);
381 einfo->ei_cb_bl = ll_md_blocking_ast;
382 einfo->ei_cb_cp = ldlm_completion_ast;
383 einfo->ei_cb_gl = NULL;
384 einfo->ei_cbdata = NULL;
390 * release resources used in async stat RPC, update entry state and wakeup if
391 * scanner process it waiting on this entry.
394 sa_make_ready(struct ll_statahead_info *sai, struct sa_entry *entry, int ret)
396 struct ll_inode_info *lli = ll_i2info(sai->sai_dentry->d_inode);
397 struct md_enqueue_info *minfo = entry->se_minfo;
398 struct ptlrpc_request *req = entry->se_req;
401 /* release resources used in RPC */
403 entry->se_minfo = NULL;
404 ll_intent_release(&minfo->mi_it);
409 entry->se_req = NULL;
410 ptlrpc_req_finished(req);
413 spin_lock(&lli->lli_sa_lock);
414 wakeup = __sa_make_ready(sai, entry, ret);
415 spin_unlock(&lli->lli_sa_lock);
418 wake_up(&sai->sai_waitq);
421 /* insert inode into the list of sai_agls */
422 static void ll_agl_add(struct ll_statahead_info *sai,
423 struct inode *inode, int index)
425 struct ll_inode_info *child = ll_i2info(inode);
426 struct ll_inode_info *parent = ll_i2info(sai->sai_dentry->d_inode);
429 spin_lock(&child->lli_agl_lock);
430 if (child->lli_agl_index == 0) {
431 child->lli_agl_index = index;
432 spin_unlock(&child->lli_agl_lock);
434 LASSERT(list_empty(&child->lli_agl_list));
437 spin_lock(&parent->lli_agl_lock);
438 if (agl_list_empty(sai))
440 list_add_tail(&child->lli_agl_list, &sai->sai_agls);
441 spin_unlock(&parent->lli_agl_lock);
443 spin_unlock(&child->lli_agl_lock);
447 wake_up(&sai->sai_agl_thread.t_ctl_waitq);
451 static struct ll_statahead_info *ll_sai_alloc(struct dentry *dentry)
453 struct ll_statahead_info *sai;
454 struct ll_inode_info *lli = ll_i2info(dentry->d_inode);
462 sai->sai_dentry = dget(dentry);
463 atomic_set(&sai->sai_refcount, 1);
464 sai->sai_max = LL_SA_RPC_MIN;
466 init_waitqueue_head(&sai->sai_waitq);
467 init_waitqueue_head(&sai->sai_thread.t_ctl_waitq);
468 init_waitqueue_head(&sai->sai_agl_thread.t_ctl_waitq);
470 INIT_LIST_HEAD(&sai->sai_interim_entries);
471 INIT_LIST_HEAD(&sai->sai_entries);
472 INIT_LIST_HEAD(&sai->sai_agls);
474 for (i = 0; i < LL_SA_CACHE_SIZE; i++) {
475 INIT_LIST_HEAD(&sai->sai_cache[i]);
476 spin_lock_init(&sai->sai_cache_lock[i]);
478 atomic_set(&sai->sai_cache_count, 0);
480 spin_lock(&sai_generation_lock);
481 lli->lli_sa_generation = ++sai_generation;
482 if (unlikely(sai_generation == 0))
483 lli->lli_sa_generation = ++sai_generation;
484 spin_unlock(&sai_generation_lock);
490 static inline void ll_sai_free(struct ll_statahead_info *sai)
492 LASSERT(sai->sai_dentry != NULL);
493 dput(sai->sai_dentry);
498 * take refcount of sai if sai for @dir exists, which means statahead is on for
501 static inline struct ll_statahead_info *ll_sai_get(struct inode *dir)
503 struct ll_inode_info *lli = ll_i2info(dir);
504 struct ll_statahead_info *sai = NULL;
506 spin_lock(&lli->lli_sa_lock);
509 atomic_inc(&sai->sai_refcount);
510 spin_unlock(&lli->lli_sa_lock);
516 * put sai refcount after use, if refcount reaches zero, free sai and sa_entries
519 static void ll_sai_put(struct ll_statahead_info *sai)
521 struct ll_inode_info *lli = ll_i2info(sai->sai_dentry->d_inode);
523 if (atomic_dec_and_lock(&sai->sai_refcount, &lli->lli_sa_lock)) {
524 struct sa_entry *entry, *next;
525 struct ll_sb_info *sbi = ll_i2sbi(sai->sai_dentry->d_inode);
528 spin_unlock(&lli->lli_sa_lock);
530 LASSERT(thread_is_stopped(&sai->sai_thread));
531 LASSERT(thread_is_stopped(&sai->sai_agl_thread));
532 LASSERT(sai->sai_sent == sai->sai_replied);
533 LASSERT(!sa_has_callback(sai));
535 list_for_each_entry_safe(entry, next, &sai->sai_entries,
539 LASSERT(atomic_read(&sai->sai_cache_count) == 0);
540 LASSERT(agl_list_empty(sai));
543 atomic_dec(&sbi->ll_sa_running);
547 /* Do NOT forget to drop inode refcount when into sai_agls. */
548 static void ll_agl_trigger(struct inode *inode, struct ll_statahead_info *sai)
550 struct ll_inode_info *lli = ll_i2info(inode);
551 u64 index = lli->lli_agl_index;
556 LASSERT(list_empty(&lli->lli_agl_list));
558 /* AGL maybe fall behind statahead with one entry */
559 if (is_omitted_entry(sai, index + 1)) {
560 lli->lli_agl_index = 0;
565 /* In case of restore, the MDT has the right size and has already
566 * sent it back without granting the layout lock, inode is up-to-date.
567 * Then AGL (async glimpse lock) is useless.
568 * Also to glimpse we need the layout, in case of a runninh restore
569 * the MDT holds the layout lock so the glimpse will block up to the
570 * end of restore (statahead/agl will block) */
571 if (ll_file_test_flag(lli, LLIF_FILE_RESTORING)) {
572 lli->lli_agl_index = 0;
577 /* Someone is in glimpse (sync or async), do nothing. */
578 rc = down_write_trylock(&lli->lli_glimpse_sem);
580 lli->lli_agl_index = 0;
586 * Someone triggered glimpse within 1 sec before.
587 * 1) The former glimpse succeeded with glimpse lock granted by OST, and
588 * if the lock is still cached on client, AGL needs to do nothing. If
589 * it is cancelled by other client, AGL maybe cannot obtaion new lock
590 * for no glimpse callback triggered by AGL.
591 * 2) The former glimpse succeeded, but OST did not grant glimpse lock.
592 * Under such case, it is quite possible that the OST will not grant
593 * glimpse lock for AGL also.
594 * 3) The former glimpse failed, compared with other two cases, it is
595 * relative rare. AGL can ignore such case, and it will not muchly
596 * affect the performance.
598 expire = ktime_sub_ns(ktime_get(), NSEC_PER_SEC);
599 if (ktime_to_ns(lli->lli_glimpse_time) &&
600 ktime_before(expire, lli->lli_glimpse_time)) {
601 up_write(&lli->lli_glimpse_sem);
602 lli->lli_agl_index = 0;
607 CDEBUG(D_READA, "Handling (init) async glimpse: inode = "
608 DFID", idx = %llu\n", PFID(&lli->lli_fid), index);
611 lli->lli_agl_index = 0;
612 lli->lli_glimpse_time = ktime_get();
613 up_write(&lli->lli_glimpse_sem);
615 CDEBUG(D_READA, "Handled (init) async glimpse: inode= "
616 DFID", idx = %llu, rc = %d\n",
617 PFID(&lli->lli_fid), index, rc);
625 * prepare inode for sa entry, add it into agl list, now sa_entry is ready
626 * to be used by scanner process.
628 static void sa_instantiate(struct ll_statahead_info *sai,
629 struct sa_entry *entry)
631 struct inode *dir = sai->sai_dentry->d_inode;
633 struct md_enqueue_info *minfo;
634 struct lookup_intent *it;
635 struct ptlrpc_request *req;
636 struct mdt_body *body;
640 LASSERT(entry->se_handle != 0);
642 minfo = entry->se_minfo;
645 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
647 GOTO(out, rc = -EFAULT);
649 child = entry->se_inode;
651 /* revalidate; unlinked and re-created with the same name */
652 if (unlikely(!lu_fid_eq(&minfo->mi_data.op_fid2,
654 entry->se_inode = NULL;
660 it->it_lock_handle = entry->se_handle;
661 rc = md_revalidate_lock(ll_i2mdexp(dir), it, ll_inode2fid(dir), NULL);
663 GOTO(out, rc = -EAGAIN);
665 rc = ll_prep_inode(&child, req, dir->i_sb, it);
669 CDEBUG(D_READA, "%s: setting %.*s"DFID" l_data to inode %p\n",
670 ll_i2sbi(dir)->ll_fsname, entry->se_qstr.len,
671 entry->se_qstr.name, PFID(ll_inode2fid(child)), child);
672 ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, child, it, NULL);
674 entry->se_inode = child;
676 if (agl_should_run(sai, child))
677 ll_agl_add(sai, child, entry->se_index);
682 /* sa_make_ready() will drop ldlm ibits lock refcount by calling
683 * ll_intent_drop_lock() in spite of failures. Do not worry about
684 * calling ll_intent_drop_lock() more than once. */
685 sa_make_ready(sai, entry, rc);
688 /* once there are async stat replies, instantiate sa_entry from replies */
689 static void sa_handle_callback(struct ll_statahead_info *sai)
691 struct ll_inode_info *lli;
693 lli = ll_i2info(sai->sai_dentry->d_inode);
695 while (sa_has_callback(sai)) {
696 struct sa_entry *entry;
698 spin_lock(&lli->lli_sa_lock);
699 if (unlikely(!sa_has_callback(sai))) {
700 spin_unlock(&lli->lli_sa_lock);
703 entry = list_entry(sai->sai_interim_entries.next,
704 struct sa_entry, se_list);
705 list_del_init(&entry->se_list);
706 spin_unlock(&lli->lli_sa_lock);
708 sa_instantiate(sai, entry);
713 * callback for async stat RPC, because this is called in ptlrpcd context, we
714 * only put sa_entry in sai_interim_entries, and wake up statahead thread to
715 * really prepare inode and instantiate sa_entry later.
717 static int ll_statahead_interpret(struct ptlrpc_request *req,
718 struct md_enqueue_info *minfo, int rc)
720 struct lookup_intent *it = &minfo->mi_it;
721 struct inode *dir = minfo->mi_dir;
722 struct ll_inode_info *lli = ll_i2info(dir);
723 struct ll_statahead_info *sai = lli->lli_sai;
724 struct sa_entry *entry = (struct sa_entry *)minfo->mi_cbdata;
726 wait_queue_head_t *waitq = NULL;
729 if (it_disposition(it, DISP_LOOKUP_NEG))
732 /* because statahead thread will wait for all inflight RPC to finish,
733 * sai should be always valid, no need to refcount */
734 LASSERT(sai != NULL);
735 LASSERT(!thread_is_stopped(&sai->sai_thread));
736 LASSERT(entry != NULL);
738 CDEBUG(D_READA, "sa_entry %.*s rc %d\n",
739 entry->se_qstr.len, entry->se_qstr.name, rc);
742 ll_intent_release(it);
745 /* release ibits lock ASAP to avoid deadlock when statahead
746 * thread enqueues lock on parent in readdir and another
747 * process enqueues lock on child with parent lock held, eg.
749 handle = it->it_lock_handle;
750 ll_intent_drop_lock(it);
751 ll_unlock_md_op_lsm(&minfo->mi_data);
754 spin_lock(&lli->lli_sa_lock);
756 if (__sa_make_ready(sai, entry, rc))
757 waitq = &sai->sai_waitq;
759 entry->se_minfo = minfo;
760 entry->se_req = ptlrpc_request_addref(req);
761 /* Release the async ibits lock ASAP to avoid deadlock
762 * when statahead thread tries to enqueue lock on parent
763 * for readpage and other tries to enqueue lock on child
764 * with parent's lock held, for example: unlink. */
765 entry->se_handle = handle;
766 if (!sa_has_callback(sai))
767 waitq = &sai->sai_thread.t_ctl_waitq;
769 list_add_tail(&entry->se_list, &sai->sai_interim_entries);
775 spin_unlock(&lli->lli_sa_lock);
780 /* async stat for file not found in dcache */
781 static int sa_lookup(struct inode *dir, struct sa_entry *entry)
783 struct md_enqueue_info *minfo;
787 minfo = sa_prep_data(dir, NULL, entry);
789 RETURN(PTR_ERR(minfo));
791 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo);
799 * async stat for file found in dcache, similar to .revalidate
801 * \retval 1 dentry valid, no RPC sent
802 * \retval 0 dentry invalid, will send async stat RPC
803 * \retval negative number upon error
805 static int sa_revalidate(struct inode *dir, struct sa_entry *entry,
806 struct dentry *dentry)
808 struct inode *inode = dentry->d_inode;
809 struct lookup_intent it = { .it_op = IT_GETATTR,
810 .it_lock_handle = 0 };
811 struct md_enqueue_info *minfo;
815 if (unlikely(inode == NULL))
818 if (d_mountpoint(dentry))
821 minfo = sa_prep_data(dir, inode, entry);
823 RETURN(PTR_ERR(minfo));
825 entry->se_inode = igrab(inode);
826 rc = md_revalidate_lock(ll_i2mdexp(dir), &it, ll_inode2fid(inode),
829 entry->se_handle = it.it_lock_handle;
830 ll_intent_release(&it);
835 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo);
837 entry->se_inode = NULL;
845 /* async stat for file with @name */
846 static void sa_statahead(struct dentry *parent, const char *name, int len,
847 const struct lu_fid *fid)
849 struct inode *dir = parent->d_inode;
850 struct ll_inode_info *lli = ll_i2info(dir);
851 struct ll_statahead_info *sai = lli->lli_sai;
852 struct dentry *dentry = NULL;
853 struct sa_entry *entry;
857 entry = sa_alloc(parent, sai, sai->sai_index, name, len, fid);
861 dentry = d_lookup(parent, &entry->se_qstr);
863 rc = sa_lookup(dir, entry);
865 rc = sa_revalidate(dir, entry, dentry);
866 if (rc == 1 && agl_should_run(sai, dentry->d_inode))
867 ll_agl_add(sai, dentry->d_inode, entry->se_index);
874 sa_make_ready(sai, entry, rc);
883 /* async glimpse (agl) thread main function */
884 static int ll_agl_thread(void *arg)
886 struct dentry *parent = (struct dentry *)arg;
887 struct inode *dir = parent->d_inode;
888 struct ll_inode_info *plli = ll_i2info(dir);
889 struct ll_inode_info *clli;
890 struct ll_sb_info *sbi = ll_i2sbi(dir);
891 struct ll_statahead_info *sai;
892 struct ptlrpc_thread *thread;
893 struct l_wait_info lwi = { 0 };
897 sai = ll_sai_get(dir);
898 thread = &sai->sai_agl_thread;
899 thread->t_pid = current_pid();
900 CDEBUG(D_READA, "agl thread started: sai %p, parent %.*s\n",
901 sai, parent->d_name.len, parent->d_name.name);
903 atomic_inc(&sbi->ll_agl_total);
904 spin_lock(&plli->lli_agl_lock);
905 sai->sai_agl_valid = 1;
906 if (thread_is_init(thread))
907 /* If someone else has changed the thread state
908 * (e.g. already changed to SVC_STOPPING), we can't just
909 * blindly overwrite that setting. */
910 thread_set_flags(thread, SVC_RUNNING);
911 spin_unlock(&plli->lli_agl_lock);
912 wake_up(&thread->t_ctl_waitq);
915 l_wait_event(thread->t_ctl_waitq,
916 !agl_list_empty(sai) ||
917 !thread_is_running(thread),
920 if (!thread_is_running(thread))
923 spin_lock(&plli->lli_agl_lock);
924 /* The statahead thread maybe help to process AGL entries,
925 * so check whether list empty again. */
926 if (!agl_list_empty(sai)) {
927 clli = agl_first_entry(sai);
928 list_del_init(&clli->lli_agl_list);
929 spin_unlock(&plli->lli_agl_lock);
930 ll_agl_trigger(&clli->lli_vfs_inode, sai);
933 spin_unlock(&plli->lli_agl_lock);
937 spin_lock(&plli->lli_agl_lock);
938 sai->sai_agl_valid = 0;
939 while (!agl_list_empty(sai)) {
940 clli = agl_first_entry(sai);
941 list_del_init(&clli->lli_agl_list);
942 spin_unlock(&plli->lli_agl_lock);
943 clli->lli_agl_index = 0;
944 iput(&clli->lli_vfs_inode);
945 spin_lock(&plli->lli_agl_lock);
947 thread_set_flags(thread, SVC_STOPPED);
948 spin_unlock(&plli->lli_agl_lock);
949 wake_up(&thread->t_ctl_waitq);
951 CDEBUG(D_READA, "agl thread stopped: sai %p, parent %.*s\n",
952 sai, parent->d_name.len, parent->d_name.name);
956 /* start agl thread */
957 static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai)
959 struct ptlrpc_thread *thread = &sai->sai_agl_thread;
960 struct l_wait_info lwi = { 0 };
961 struct ll_inode_info *plli;
962 struct task_struct *task;
965 CDEBUG(D_READA, "start agl thread: sai %p, parent %.*s\n",
966 sai, parent->d_name.len, parent->d_name.name);
968 plli = ll_i2info(parent->d_inode);
969 task = kthread_run(ll_agl_thread, parent,
970 "ll_agl_%u", plli->lli_opendir_pid);
972 CERROR("can't start ll_agl thread, rc: %ld\n", PTR_ERR(task));
973 thread_set_flags(thread, SVC_STOPPED);
977 l_wait_event(thread->t_ctl_waitq,
978 thread_is_running(thread) || thread_is_stopped(thread),
983 /* statahead thread main function */
984 static int ll_statahead_thread(void *arg)
986 struct dentry *parent = (struct dentry *)arg;
987 struct inode *dir = parent->d_inode;
988 struct ll_inode_info *lli = ll_i2info(dir);
989 struct ll_sb_info *sbi = ll_i2sbi(dir);
990 struct ll_statahead_info *sai;
991 struct ptlrpc_thread *sa_thread;
992 struct ptlrpc_thread *agl_thread;
994 struct md_op_data *op_data;
995 struct ll_dir_chain chain;
996 struct l_wait_info lwi = { 0 };
997 struct page *page = NULL;
1002 sai = ll_sai_get(dir);
1003 sa_thread = &sai->sai_thread;
1004 agl_thread = &sai->sai_agl_thread;
1005 sa_thread->t_pid = current_pid();
1006 CDEBUG(D_READA, "statahead thread starting: sai %p, parent %.*s\n",
1007 sai, parent->d_name.len, parent->d_name.name);
1009 OBD_ALLOC_PTR(op_data);
1010 if (IS_ERR(op_data))
1011 GOTO(out, rc = PTR_ERR(op_data));
1013 if (sbi->ll_flags & LL_SBI_AGL_ENABLED)
1014 ll_start_agl(parent, sai);
1016 atomic_inc(&sbi->ll_sa_total);
1017 spin_lock(&lli->lli_sa_lock);
1018 if (thread_is_init(sa_thread))
1019 /* If someone else has changed the thread state
1020 * (e.g. already changed to SVC_STOPPING), we can't just
1021 * blindly overwrite that setting. */
1022 thread_set_flags(sa_thread, SVC_RUNNING);
1023 spin_unlock(&lli->lli_sa_lock);
1024 wake_up(&sa_thread->t_ctl_waitq);
1026 ll_dir_chain_init(&chain);
1027 while (pos != MDS_DIR_END_OFF && thread_is_running(sa_thread)) {
1028 struct lu_dirpage *dp;
1029 struct lu_dirent *ent;
1031 op_data = ll_prep_md_op_data(op_data, dir, dir, NULL, 0, 0,
1032 LUSTRE_OPC_ANY, dir);
1033 if (IS_ERR(op_data)) {
1034 rc = PTR_ERR(op_data);
1038 sai->sai_in_readpage = 1;
1039 page = ll_get_dir_page(dir, op_data, pos, &chain);
1040 ll_unlock_md_op_lsm(op_data);
1041 sai->sai_in_readpage = 0;
1044 CDEBUG(D_READA, "error reading dir "DFID" at %llu"
1045 "/%llu opendir_pid = %u: rc = %d\n",
1046 PFID(ll_inode2fid(dir)), pos, sai->sai_index,
1047 lli->lli_opendir_pid, rc);
1051 dp = page_address(page);
1052 for (ent = lu_dirent_start(dp);
1053 ent != NULL && thread_is_running(sa_thread) &&
1055 ent = lu_dirent_next(ent)) {
1061 hash = le64_to_cpu(ent->lde_hash);
1062 if (unlikely(hash < pos))
1064 * Skip until we find target hash value.
1068 namelen = le16_to_cpu(ent->lde_namelen);
1069 if (unlikely(namelen == 0))
1071 * Skip dummy record.
1075 name = ent->lde_name;
1076 if (name[0] == '.') {
1082 } else if (name[1] == '.' && namelen == 2) {
1087 } else if (!sai->sai_ls_all) {
1089 * skip hidden files.
1091 sai->sai_skip_hidden++;
1097 * don't stat-ahead first entry.
1099 if (unlikely(++first == 1))
1102 fid_le_to_cpu(&fid, &ent->lde_fid);
1104 /* wait for spare statahead window */
1106 l_wait_event(sa_thread->t_ctl_waitq,
1107 !sa_sent_full(sai) ||
1108 sa_has_callback(sai) ||
1109 !agl_list_empty(sai) ||
1110 !thread_is_running(sa_thread),
1113 sa_handle_callback(sai);
1115 spin_lock(&lli->lli_agl_lock);
1116 while (sa_sent_full(sai) &&
1117 !agl_list_empty(sai)) {
1118 struct ll_inode_info *clli;
1120 clli = agl_first_entry(sai);
1121 list_del_init(&clli->lli_agl_list);
1122 spin_unlock(&lli->lli_agl_lock);
1124 ll_agl_trigger(&clli->lli_vfs_inode,
1127 spin_lock(&lli->lli_agl_lock);
1129 spin_unlock(&lli->lli_agl_lock);
1130 } while (sa_sent_full(sai) &&
1131 thread_is_running(sa_thread));
1133 sa_statahead(parent, name, namelen, &fid);
1136 pos = le64_to_cpu(dp->ldp_hash_end);
1137 ll_release_page(dir, page,
1138 le32_to_cpu(dp->ldp_flags) & LDF_COLLIDE);
1140 if (sa_low_hit(sai)) {
1142 atomic_inc(&sbi->ll_sa_wrong);
1143 CDEBUG(D_READA, "Statahead for dir "DFID" hit "
1144 "ratio too low: hit/miss %llu/%llu"
1145 ", sent/replied %llu/%llu, stopping "
1146 "statahead thread: pid %d\n",
1147 PFID(&lli->lli_fid), sai->sai_hit,
1148 sai->sai_miss, sai->sai_sent,
1149 sai->sai_replied, current_pid());
1153 ll_dir_chain_fini(&chain);
1154 ll_finish_md_op_data(op_data);
1157 spin_lock(&lli->lli_sa_lock);
1158 thread_set_flags(sa_thread, SVC_STOPPING);
1159 lli->lli_sa_enabled = 0;
1160 spin_unlock(&lli->lli_sa_lock);
1163 /* statahead is finished, but statahead entries need to be cached, wait
1164 * for file release to stop me. */
1165 while (thread_is_running(sa_thread)) {
1166 l_wait_event(sa_thread->t_ctl_waitq,
1167 sa_has_callback(sai) ||
1168 !thread_is_running(sa_thread),
1171 sa_handle_callback(sai);
1176 if (sai->sai_agl_valid) {
1177 spin_lock(&lli->lli_agl_lock);
1178 thread_set_flags(agl_thread, SVC_STOPPING);
1179 spin_unlock(&lli->lli_agl_lock);
1180 wake_up(&agl_thread->t_ctl_waitq);
1182 CDEBUG(D_READA, "stop agl thread: sai %p pid %u\n",
1183 sai, (unsigned int)agl_thread->t_pid);
1184 l_wait_event(agl_thread->t_ctl_waitq,
1185 thread_is_stopped(agl_thread),
1188 /* Set agl_thread flags anyway. */
1189 thread_set_flags(agl_thread, SVC_STOPPED);
1192 /* wait for inflight statahead RPCs to finish, and then we can free sai
1193 * safely because statahead RPC will access sai data */
1194 while (sai->sai_sent != sai->sai_replied) {
1195 /* in case we're not woken up, timeout wait */
1196 lwi = LWI_TIMEOUT(msecs_to_jiffies(MSEC_PER_SEC >> 3),
1198 l_wait_event(sa_thread->t_ctl_waitq,
1199 sai->sai_sent == sai->sai_replied, &lwi);
1202 /* release resources held by statahead RPCs */
1203 sa_handle_callback(sai);
1205 spin_lock(&lli->lli_sa_lock);
1206 thread_set_flags(sa_thread, SVC_STOPPED);
1207 spin_unlock(&lli->lli_sa_lock);
1209 CDEBUG(D_READA, "statahead thread stopped: sai %p, parent %.*s\n",
1210 sai, parent->d_name.len, parent->d_name.name);
1212 wake_up(&sai->sai_waitq);
1213 wake_up(&sa_thread->t_ctl_waitq);
1219 /* authorize opened dir handle @key to statahead */
1220 void ll_authorize_statahead(struct inode *dir, void *key)
1222 struct ll_inode_info *lli = ll_i2info(dir);
1224 spin_lock(&lli->lli_sa_lock);
1225 if (lli->lli_opendir_key == NULL && lli->lli_sai == NULL) {
1227 * if lli_sai is not NULL, it means previous statahead is not
1228 * finished yet, we'd better not start a new statahead for now.
1230 LASSERT(lli->lli_opendir_pid == 0);
1231 lli->lli_opendir_key = key;
1232 lli->lli_opendir_pid = current_pid();
1233 lli->lli_sa_enabled = 1;
1235 spin_unlock(&lli->lli_sa_lock);
1239 * deauthorize opened dir handle @key to statahead, and notify statahead thread
1240 * to quit if it's running.
1242 void ll_deauthorize_statahead(struct inode *dir, void *key)
1244 struct ll_inode_info *lli = ll_i2info(dir);
1245 struct ll_statahead_info *sai;
1247 LASSERT(lli->lli_opendir_key == key);
1248 LASSERT(lli->lli_opendir_pid != 0);
1250 CDEBUG(D_READA, "deauthorize statahead for "DFID"\n",
1251 PFID(&lli->lli_fid));
1253 spin_lock(&lli->lli_sa_lock);
1254 lli->lli_opendir_key = NULL;
1255 lli->lli_opendir_pid = 0;
1256 lli->lli_sa_enabled = 0;
1258 if (sai != NULL && thread_is_running(&sai->sai_thread)) {
1260 * statahead thread may not quit yet because it needs to cache
1261 * entries, now it's time to tell it to quit.
1263 * In case sai is released, wake_up() is called inside spinlock,
1264 * so we have to call smp_mb() explicitely to serialize ops.
1266 thread_set_flags(&sai->sai_thread, SVC_STOPPING);
1268 wake_up(&sai->sai_thread.t_ctl_waitq);
1270 spin_unlock(&lli->lli_sa_lock);
1275 * not first dirent, or is "."
1277 LS_NOT_FIRST_DE = 0,
1279 * the first non-hidden dirent
1283 * the first hidden dirent, that is "."
1288 /* file is first dirent under @dir */
1289 static int is_first_dirent(struct inode *dir, struct dentry *dentry)
1291 struct ll_dir_chain chain;
1292 struct qstr *target = &dentry->d_name;
1293 struct md_op_data *op_data;
1295 struct page *page = NULL;
1296 int rc = LS_NOT_FIRST_DE;
1300 op_data = ll_prep_md_op_data(NULL, dir, dir, NULL, 0, 0,
1301 LUSTRE_OPC_ANY, dir);
1302 if (IS_ERR(op_data))
1303 RETURN(PTR_ERR(op_data));
1305 *FIXME choose the start offset of the readdir
1308 ll_dir_chain_init(&chain);
1309 page = ll_get_dir_page(dir, op_data, 0, &chain);
1312 struct lu_dirpage *dp;
1313 struct lu_dirent *ent;
1316 struct ll_inode_info *lli = ll_i2info(dir);
1319 CERROR("%s: reading dir "DFID" at %llu"
1320 "opendir_pid = %u : rc = %d\n",
1321 ll_i2sbi(dir)->ll_fsname,
1322 PFID(ll_inode2fid(dir)), pos,
1323 lli->lli_opendir_pid, rc);
1327 dp = page_address(page);
1328 for (ent = lu_dirent_start(dp); ent != NULL;
1329 ent = lu_dirent_next(ent)) {
1334 hash = le64_to_cpu(ent->lde_hash);
1335 /* The ll_get_dir_page() can return any page containing
1336 * the given hash which may be not the start hash. */
1337 if (unlikely(hash < pos))
1340 namelen = le16_to_cpu(ent->lde_namelen);
1341 if (unlikely(namelen == 0))
1343 * skip dummy record.
1347 name = ent->lde_name;
1348 if (name[0] == '.') {
1354 else if (name[1] == '.' && namelen == 2)
1365 if (dot_de && target->name[0] != '.') {
1366 CDEBUG(D_READA, "%.*s skip hidden file %.*s\n",
1367 target->len, target->name,
1372 if (target->len != namelen ||
1373 memcmp(target->name, name, namelen) != 0)
1374 rc = LS_NOT_FIRST_DE;
1378 rc = LS_FIRST_DOT_DE;
1380 ll_release_page(dir, page, false);
1383 pos = le64_to_cpu(dp->ldp_hash_end);
1384 if (pos == MDS_DIR_END_OFF) {
1386 * End of directory reached.
1388 ll_release_page(dir, page, false);
1392 * chain is exhausted
1393 * Normal case: continue to the next page.
1395 ll_release_page(dir, page, le32_to_cpu(dp->ldp_flags) &
1397 page = ll_get_dir_page(dir, op_data, pos, &chain);
1402 ll_dir_chain_fini(&chain);
1403 ll_finish_md_op_data(op_data);
1408 * revalidate @dentryp from statahead cache
1410 * \param[in] dir parent directory
1411 * \param[in] sai sai structure
1412 * \param[out] dentryp pointer to dentry which will be revalidated
1413 * \param[in] unplug unplug statahead window only (normally for negative
1415 * \retval 1 on success, dentry is saved in @dentryp
1416 * \retval 0 if revalidation failed (no proper lock on client)
1417 * \retval negative number upon error
1419 static int revalidate_statahead_dentry(struct inode *dir,
1420 struct ll_statahead_info *sai,
1421 struct dentry **dentryp,
1424 struct sa_entry *entry = NULL;
1425 struct l_wait_info lwi = { 0 };
1426 struct ll_dentry_data *ldd;
1427 struct ll_inode_info *lli = ll_i2info(dir);
1431 if ((*dentryp)->d_name.name[0] == '.') {
1432 if (sai->sai_ls_all ||
1433 sai->sai_miss_hidden >= sai->sai_skip_hidden) {
1435 * Hidden dentry is the first one, or statahead
1436 * thread does not skip so many hidden dentries
1437 * before "sai_ls_all" enabled as below.
1440 if (!sai->sai_ls_all)
1442 * It maybe because hidden dentry is not
1443 * the first one, "sai_ls_all" was not
1444 * set, then "ls -al" missed. Enable
1445 * "sai_ls_all" for such case.
1447 sai->sai_ls_all = 1;
1450 * Such "getattr" has been skipped before
1451 * "sai_ls_all" enabled as above.
1453 sai->sai_miss_hidden++;
1461 entry = sa_get(sai, &(*dentryp)->d_name);
1463 GOTO(out, rc = -EAGAIN);
1465 /* if statahead is busy in readdir, help it do post-work */
1466 if (!sa_ready(entry) && sai->sai_in_readpage)
1467 sa_handle_callback(sai);
1469 if (!sa_ready(entry)) {
1470 spin_lock(&lli->lli_sa_lock);
1471 sai->sai_index_wait = entry->se_index;
1472 spin_unlock(&lli->lli_sa_lock);
1473 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(30), NULL,
1474 LWI_ON_SIGNAL_NOOP, NULL);
1475 rc = l_wait_event(sai->sai_waitq, sa_ready(entry), &lwi);
1478 * entry may not be ready, so it may be used by inflight
1479 * statahead RPC, don't free it.
1482 GOTO(out, rc = -EAGAIN);
1487 * We need to see the value that was set immediately before we
1490 if (smp_load_acquire(&entry->se_state) == SA_ENTRY_SUCC &&
1492 struct inode *inode = entry->se_inode;
1493 struct lookup_intent it = { .it_op = IT_GETATTR,
1498 rc = md_revalidate_lock(ll_i2mdexp(dir), &it,
1499 ll_inode2fid(inode), &bits);
1501 if ((*dentryp)->d_inode == NULL) {
1502 struct dentry *alias;
1504 alias = ll_splice_alias(inode, *dentryp);
1505 if (IS_ERR(alias)) {
1506 ll_intent_release(&it);
1507 GOTO(out, rc = PTR_ERR(alias));
1510 /* statahead prepared this inode, transfer inode
1511 * refcount from sa_entry to dentry */
1512 entry->se_inode = NULL;
1513 } else if ((*dentryp)->d_inode != inode) {
1514 /* revalidate, but inode is recreated */
1516 "%s: stale dentry %.*s inode "
1517 DFID", statahead inode "DFID
1519 ll_i2sbi(inode)->ll_fsname,
1520 (*dentryp)->d_name.len,
1521 (*dentryp)->d_name.name,
1522 PFID(ll_inode2fid((*dentryp)->d_inode)),
1523 PFID(ll_inode2fid(inode)));
1524 ll_intent_release(&it);
1525 GOTO(out, rc = -ESTALE);
1528 if ((bits & MDS_INODELOCK_LOOKUP) &&
1529 d_lustre_invalid(*dentryp))
1530 d_lustre_revalidate(*dentryp);
1531 ll_intent_release(&it);
1536 * statahead cached sa_entry can be used only once, and will be killed
1537 * right after use, so if lookup/revalidate accessed statahead cache,
1538 * set dentry ldd_sa_generation to parent lli_sa_generation, later if we
1539 * stat this file again, we know we've done statahead before, see
1540 * dentry_may_statahead().
1542 ldd = ll_d2d(*dentryp);
1543 /* ldd can be NULL if llite lookup failed. */
1545 ldd->lld_sa_generation = lli->lli_sa_generation;
1552 * start statahead thread
1554 * \param[in] dir parent directory
1555 * \param[in] dentry dentry that triggers statahead, normally the first
1557 * \retval -EAGAIN on success, because when this function is
1558 * called, it's already in lookup call, so client should
1559 * do it itself instead of waiting for statahead thread
1560 * to do it asynchronously.
1561 * \retval negative number upon error
1563 static int start_statahead_thread(struct inode *dir, struct dentry *dentry)
1565 struct ll_inode_info *lli = ll_i2info(dir);
1566 struct ll_statahead_info *sai = NULL;
1567 struct dentry *parent = dentry->d_parent;
1568 struct ptlrpc_thread *thread;
1569 struct l_wait_info lwi = { 0 };
1570 struct task_struct *task;
1571 struct ll_sb_info *sbi = ll_i2sbi(parent->d_inode);
1572 int first = LS_FIRST_DE;
1576 /* I am the "lli_opendir_pid" owner, only me can set "lli_sai". */
1577 first = is_first_dirent(dir, dentry);
1578 if (first == LS_NOT_FIRST_DE)
1579 /* It is not "ls -{a}l" operation, no need statahead for it. */
1580 GOTO(out, rc = -EFAULT);
1582 if (unlikely(atomic_inc_return(&sbi->ll_sa_running) >
1583 sbi->ll_sa_running_max)) {
1585 "Too many concurrent statahead instances, "
1586 "avoid new statahead instance temporarily.\n");
1587 GOTO(out, rc = -EMFILE);
1590 sai = ll_sai_alloc(parent);
1592 GOTO(out, rc = -ENOMEM);
1594 sai->sai_ls_all = (first == LS_FIRST_DOT_DE);
1596 /* if current lli_opendir_key was deauthorized, or dir re-opened by
1597 * another process, don't start statahead, otherwise the newly spawned
1598 * statahead thread won't be notified to quit. */
1599 spin_lock(&lli->lli_sa_lock);
1600 if (unlikely(lli->lli_sai != NULL ||
1601 lli->lli_opendir_key == NULL ||
1602 lli->lli_opendir_pid != current->pid)) {
1603 spin_unlock(&lli->lli_sa_lock);
1604 GOTO(out, rc = -EPERM);
1607 spin_unlock(&lli->lli_sa_lock);
1609 CDEBUG(D_READA, "start statahead thread: [pid %d] [parent %.*s]\n",
1610 current_pid(), parent->d_name.len, parent->d_name.name);
1612 task = kthread_run(ll_statahead_thread, parent, "ll_sa_%u",
1613 lli->lli_opendir_pid);
1614 thread = &sai->sai_thread;
1616 spin_lock(&lli->lli_sa_lock);
1617 lli->lli_sai = NULL;
1618 spin_unlock(&lli->lli_sa_lock);
1620 CERROR("can't start ll_sa thread, rc: %d\n", rc);
1624 l_wait_event(thread->t_ctl_waitq,
1625 thread_is_running(thread) || thread_is_stopped(thread),
1630 * We don't stat-ahead for the first dirent since we are already in
1636 /* once we start statahead thread failed, disable statahead so that
1637 * subsequent stat won't waste time to try it. */
1638 spin_lock(&lli->lli_sa_lock);
1639 if (lli->lli_opendir_pid == current->pid)
1640 lli->lli_sa_enabled = 0;
1641 spin_unlock(&lli->lli_sa_lock);
1645 if (first != LS_NOT_FIRST_DE)
1646 atomic_dec(&sbi->ll_sa_running);
1652 * statahead entry function, this is called when client getattr on a file, it
1653 * will start statahead thread if this is the first dir entry, else revalidate
1654 * dentry from statahead cache.
1656 * \param[in] dir parent directory
1657 * \param[out] dentryp dentry to getattr
1658 * \param[in] unplug unplug statahead window only (normally for negative
1660 * \retval 1 on success
1661 * \retval 0 revalidation from statahead cache failed, caller needs
1662 * to getattr from server directly
1663 * \retval negative number on error, caller often ignores this and
1664 * then getattr from server
1666 int ll_statahead(struct inode *dir, struct dentry **dentryp, bool unplug)
1668 struct ll_statahead_info *sai;
1670 sai = ll_sai_get(dir);
1674 rc = revalidate_statahead_dentry(dir, sai, dentryp, unplug);
1675 CDEBUG(D_READA, "revalidate statahead %.*s: %d.\n",
1676 (*dentryp)->d_name.len, (*dentryp)->d_name.name, rc);
1680 return start_statahead_thread(dir, *dentryp);