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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 #include <linux/sched.h>
40 #include <linux/highmem.h>
41 #include <linux/pagemap.h>
43 #define DEBUG_SUBSYSTEM S_LLITE
45 #include <obd_support.h>
46 #include <lustre_dlm.h>
47 #include "llite_internal.h"
49 #define SA_OMITTED_ENTRY_MAX 8ULL
52 /** negative values are for error cases */
53 SA_ENTRY_INIT = 0, /** init entry */
54 SA_ENTRY_SUCC = 1, /** stat succeed */
55 SA_ENTRY_INVA = 2, /** invalid entry */
56 SA_ENTRY_DEST = 3, /** entry to be destroyed */
60 /* link into sai->sai_entries */
61 struct list_head se_link;
62 /* link into sai->sai_entries_{received,stated} */
63 struct list_head se_list;
64 /* link into sai hash table locally */
65 struct list_head se_hash;
66 /* entry reference count */
68 /* entry index in the sai */
70 /* low layer ldlm lock handle */
74 /* entry size, contains name */
76 /* pointer to async getattr enqueue info */
77 struct md_enqueue_info *se_minfo;
78 /* pointer to the async getattr request */
79 struct ptlrpc_request *se_req;
80 /* pointer to the target inode */
81 struct inode *se_inode;
86 static unsigned int sai_generation = 0;
87 static DEFINE_SPINLOCK(sai_generation_lock);
89 static inline int ll_sa_entry_unhashed(struct ll_sa_entry *entry)
91 return list_empty(&entry->se_hash);
95 * The entry only can be released by the caller, it is necessary to hold lock.
97 static inline int ll_sa_entry_stated(struct ll_sa_entry *entry)
100 return (entry->se_stat != SA_ENTRY_INIT);
103 static inline int ll_sa_entry_hash(int val)
105 return val & LL_SA_CACHE_MASK;
109 * Insert entry to hash SA table.
112 ll_sa_entry_enhash(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
114 int i = ll_sa_entry_hash(entry->se_qstr.hash);
116 spin_lock(&sai->sai_cache_lock[i]);
117 list_add_tail(&entry->se_hash, &sai->sai_cache[i]);
118 spin_unlock(&sai->sai_cache_lock[i]);
122 * Remove entry from SA table.
125 ll_sa_entry_unhash(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
127 int i = ll_sa_entry_hash(entry->se_qstr.hash);
129 spin_lock(&sai->sai_cache_lock[i]);
130 list_del_init(&entry->se_hash);
131 spin_unlock(&sai->sai_cache_lock[i]);
134 static inline int agl_should_run(struct ll_statahead_info *sai,
137 return (inode != NULL && S_ISREG(inode->i_mode) && sai->sai_agl_valid);
140 static inline struct ll_sa_entry *
141 sa_first_received_entry(struct ll_statahead_info *sai)
143 return list_entry(sai->sai_entries_received.next,
144 struct ll_sa_entry, se_list);
147 static inline struct ll_inode_info *
148 agl_first_entry(struct ll_statahead_info *sai)
150 return list_entry(sai->sai_entries_agl.next,
151 struct ll_inode_info, lli_agl_list);
154 static inline int sa_sent_full(struct ll_statahead_info *sai)
156 return atomic_read(&sai->sai_cache_count) >= sai->sai_max;
159 static inline int sa_received_empty(struct ll_statahead_info *sai)
161 return list_empty(&sai->sai_entries_received);
164 static inline int agl_list_empty(struct ll_statahead_info *sai)
166 return list_empty(&sai->sai_entries_agl);
170 * (1) hit ratio less than 80%
172 * (2) consecutive miss more than 8
173 * then means low hit.
175 static inline int sa_low_hit(struct ll_statahead_info *sai)
177 return ((sai->sai_hit > 7 && sai->sai_hit < 4 * sai->sai_miss) ||
178 (sai->sai_consecutive_miss > 8));
182 * If the given index is behind of statahead window more than
183 * SA_OMITTED_ENTRY_MAX, then it is old.
185 static inline int is_omitted_entry(struct ll_statahead_info *sai, __u64 index)
187 return ((__u64)sai->sai_max + index + SA_OMITTED_ENTRY_MAX <
192 * Insert it into sai_entries tail when init.
194 static struct ll_sa_entry *
195 ll_sa_entry_alloc(struct ll_statahead_info *sai, __u64 index, const char *name,
198 struct ll_inode_info *lli;
199 struct ll_sa_entry *entry;
204 entry_size = sizeof(struct ll_sa_entry) + (len & ~3) + 4;
205 OBD_ALLOC(entry, entry_size);
206 if (unlikely(entry == NULL))
207 RETURN(ERR_PTR(-ENOMEM));
209 CDEBUG(D_READA, "alloc sa entry %.*s(%p) index "LPU64"\n",
210 len, name, entry, index);
212 entry->se_index = index;
215 * Statahead entry reference rules:
217 * 1) When statahead entry is initialized, its reference is set as 2.
218 * One reference is used by the directory scanner. When the scanner
219 * searches the statahead cache for the given name, it can perform
220 * lockless hash lookup (only the scanner can remove entry from hash
221 * list), and once found, it needn't to call "atomic_inc()" for the
222 * entry reference. So the performance is improved. After using the
223 * statahead entry, the scanner will call "atomic_dec()" to drop the
224 * reference held when initialization. If it is the last reference,
225 * the statahead entry will be freed.
227 * 2) All other threads, including statahead thread and ptlrpcd thread,
228 * when they process the statahead entry, the reference for target
229 * should be held to guarantee the entry will not be released by the
230 * directory scanner. After processing the entry, these threads will
231 * drop the entry reference. If it is the last reference, the entry
234 * The second reference when initializes the statahead entry is used
235 * by the statahead thread, following the rule 2).
237 atomic_set(&entry->se_refcount, 2);
238 entry->se_stat = SA_ENTRY_INIT;
239 entry->se_size = entry_size;
240 dname = (char *)entry + sizeof(struct ll_sa_entry);
241 memcpy(dname, name, len);
243 entry->se_qstr.hash = full_name_hash(name, len);
244 entry->se_qstr.len = len;
245 entry->se_qstr.name = dname;
247 lli = ll_i2info(sai->sai_inode);
248 spin_lock(&lli->lli_sa_lock);
249 list_add_tail(&entry->se_link, &sai->sai_entries);
250 INIT_LIST_HEAD(&entry->se_list);
251 ll_sa_entry_enhash(sai, entry);
252 spin_unlock(&lli->lli_sa_lock);
254 atomic_inc(&sai->sai_cache_count);
260 * Used by the directory scanner to search entry with name.
262 * Only the caller can remove the entry from hash, so it is unnecessary to hold
263 * hash lock. It is caller's duty to release the init refcount on the entry, so
264 * it is also unnecessary to increase refcount on the entry.
266 static struct ll_sa_entry *
267 ll_sa_entry_get_byname(struct ll_statahead_info *sai, const struct qstr *qstr)
269 struct ll_sa_entry *entry;
270 int i = ll_sa_entry_hash(qstr->hash);
272 list_for_each_entry(entry, &sai->sai_cache[i], se_hash) {
273 if (entry->se_qstr.hash == qstr->hash &&
274 entry->se_qstr.len == qstr->len &&
275 memcmp(entry->se_qstr.name, qstr->name, qstr->len) == 0)
282 * Used by the async getattr request callback to find entry with index.
284 * Inside lli_sa_lock to prevent others to change the list during the search.
285 * It needs to increase entry refcount before returning to guarantee that the
286 * entry cannot be freed by others.
288 static struct ll_sa_entry *
289 ll_sa_entry_get_byindex(struct ll_statahead_info *sai, __u64 index)
291 struct ll_sa_entry *entry;
293 list_for_each_entry(entry, &sai->sai_entries, se_link) {
294 if (entry->se_index == index) {
295 LASSERT(atomic_read(&entry->se_refcount) > 0);
296 atomic_inc(&entry->se_refcount);
299 if (entry->se_index > index)
305 static void ll_sa_entry_put(struct ll_statahead_info *sai,
306 struct ll_sa_entry *entry)
308 if (atomic_dec_and_test(&entry->se_refcount)) {
309 CDEBUG(D_READA, "free sa entry %.*s(%p) index "LPU64"\n",
310 entry->se_qstr.len, entry->se_qstr.name, entry,
313 LASSERT(list_empty(&entry->se_link));
314 LASSERT(list_empty(&entry->se_list));
315 LASSERT(ll_sa_entry_unhashed(entry));
318 iput(entry->se_inode);
320 OBD_FREE(entry, entry->se_size);
321 atomic_dec(&sai->sai_cache_count);
326 do_sa_entry_fini(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
328 struct ll_inode_info *lli = ll_i2info(sai->sai_inode);
330 LASSERT(!ll_sa_entry_unhashed(entry));
331 LASSERT(!list_empty(&entry->se_link));
333 ll_sa_entry_unhash(sai, entry);
335 spin_lock(&lli->lli_sa_lock);
336 entry->se_stat = SA_ENTRY_DEST;
337 list_del_init(&entry->se_link);
338 if (likely(!list_empty(&entry->se_list)))
339 list_del_init(&entry->se_list);
340 spin_unlock(&lli->lli_sa_lock);
342 ll_sa_entry_put(sai, entry);
346 * Delete it from sai_entries_stated list when fini.
349 ll_sa_entry_fini(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
351 struct ll_sa_entry *pos, *next;
354 do_sa_entry_fini(sai, entry);
356 /* drop old entry, only 'scanner' process does this, no need to lock */
357 list_for_each_entry_safe(pos, next, &sai->sai_entries, se_link) {
358 if (!is_omitted_entry(sai, pos->se_index))
360 /* keep those whose statahead RPC not finished */
361 if (pos->se_stat == SA_ENTRY_SUCC ||
362 pos->se_stat == SA_ENTRY_INVA)
363 do_sa_entry_fini(sai, pos);
368 * Inside lli_sa_lock.
371 __sa_entry_post_stat(struct ll_statahead_info *sai, struct ll_sa_entry *entry,
374 struct ll_sa_entry *se;
375 struct list_head *pos = &sai->sai_entries_stated;
377 LASSERT(entry->se_stat == SA_ENTRY_INIT);
379 if (!list_empty(&entry->se_list))
380 list_del_init(&entry->se_list);
382 list_for_each_entry_reverse(se, &sai->sai_entries_stated, se_list) {
383 if (se->se_index < entry->se_index) {
389 list_add(&entry->se_list, pos);
390 entry->se_stat = stat;
394 * Move entry to sai_entries_stated and sort with the index.
395 * \retval 1 -- entry to be destroyed.
396 * \retval 0 -- entry is inserted into stated list.
399 sa_entry_post_stat(struct ll_statahead_info *sai, struct ll_sa_entry *entry,
402 struct ll_inode_info *lli = ll_i2info(sai->sai_inode);
403 struct md_enqueue_info *minfo = entry->se_minfo;
404 struct ptlrpc_request *req = entry->se_req;
406 /* release resources used in RPC */
408 entry->se_minfo = NULL;
409 ll_intent_release(&minfo->mi_it);
415 entry->se_req = NULL;
416 ptlrpc_req_finished(req);
419 spin_lock(&lli->lli_sa_lock);
420 __sa_entry_post_stat(sai, entry, stat);
421 spin_unlock(&lli->lli_sa_lock);
425 * Insert inode into the list of sai_entries_agl.
427 static void ll_agl_add(struct ll_statahead_info *sai,
428 struct inode *inode, int index)
430 struct ll_inode_info *child = ll_i2info(inode);
431 struct ll_inode_info *parent = ll_i2info(sai->sai_inode);
434 spin_lock(&child->lli_agl_lock);
435 if (child->lli_agl_index == 0) {
436 child->lli_agl_index = index;
437 spin_unlock(&child->lli_agl_lock);
439 LASSERT(list_empty(&child->lli_agl_list));
442 spin_lock(&parent->lli_agl_lock);
443 if (agl_list_empty(sai))
445 list_add_tail(&child->lli_agl_list, &sai->sai_entries_agl);
446 spin_unlock(&parent->lli_agl_lock);
448 spin_unlock(&child->lli_agl_lock);
452 wake_up(&sai->sai_agl_thread.t_ctl_waitq);
455 static struct ll_statahead_info *ll_sai_alloc(void)
457 struct ll_statahead_info *sai;
465 atomic_set(&sai->sai_refcount, 1);
467 spin_lock(&sai_generation_lock);
468 sai->sai_generation = ++sai_generation;
469 if (unlikely(sai_generation == 0))
470 sai->sai_generation = ++sai_generation;
471 spin_unlock(&sai_generation_lock);
473 sai->sai_max = LL_SA_RPC_MIN;
475 init_waitqueue_head(&sai->sai_waitq);
476 init_waitqueue_head(&sai->sai_thread.t_ctl_waitq);
477 init_waitqueue_head(&sai->sai_agl_thread.t_ctl_waitq);
479 INIT_LIST_HEAD(&sai->sai_entries);
480 INIT_LIST_HEAD(&sai->sai_entries_received);
481 INIT_LIST_HEAD(&sai->sai_entries_stated);
482 INIT_LIST_HEAD(&sai->sai_entries_agl);
484 for (i = 0; i < LL_SA_CACHE_SIZE; i++) {
485 INIT_LIST_HEAD(&sai->sai_cache[i]);
486 spin_lock_init(&sai->sai_cache_lock[i]);
488 atomic_set(&sai->sai_cache_count, 0);
493 static inline struct ll_statahead_info *ll_sai_get(struct inode *dir)
495 struct ll_inode_info *lli = ll_i2info(dir);
496 struct ll_statahead_info *sai = NULL;
498 spin_lock(&lli->lli_sa_lock);
501 atomic_inc(&sai->sai_refcount);
502 spin_unlock(&lli->lli_sa_lock);
507 static void ll_sai_put(struct ll_statahead_info *sai)
509 struct ll_inode_info *lli = ll_i2info(sai->sai_inode);
511 if (atomic_dec_and_lock(&sai->sai_refcount, &lli->lli_sa_lock)) {
512 struct ll_sa_entry *entry, *next;
513 struct ll_sb_info *sbi = ll_i2sbi(sai->sai_inode);
516 spin_unlock(&lli->lli_sa_lock);
518 LASSERT(thread_is_stopped(&sai->sai_thread));
519 LASSERT(thread_is_stopped(&sai->sai_agl_thread));
520 LASSERT(sai->sai_sent == sai->sai_replied);
522 list_for_each_entry_safe(entry, next, &sai->sai_entries,
524 do_sa_entry_fini(sai, entry);
526 LASSERT(atomic_read(&sai->sai_cache_count) == 0);
527 LASSERT(agl_list_empty(sai));
528 LASSERT(atomic_read(&sai->sai_refcount) == 0);
530 iput(sai->sai_inode);
532 atomic_dec(&sbi->ll_sa_running);
536 /* Do NOT forget to drop inode refcount when into sai_entries_agl. */
537 static void ll_agl_trigger(struct inode *inode, struct ll_statahead_info *sai)
539 struct ll_inode_info *lli = ll_i2info(inode);
540 __u64 index = lli->lli_agl_index;
544 LASSERT(list_empty(&lli->lli_agl_list));
546 /* AGL maybe fall behind statahead with one entry */
547 if (is_omitted_entry(sai, index + 1)) {
548 lli->lli_agl_index = 0;
553 /* Someone is in glimpse (sync or async), do nothing. */
554 rc = down_write_trylock(&lli->lli_glimpse_sem);
556 lli->lli_agl_index = 0;
562 * Someone triggered glimpse within 1 sec before.
563 * 1) The former glimpse succeeded with glimpse lock granted by OST, and
564 * if the lock is still cached on client, AGL needs to do nothing. If
565 * it is cancelled by other client, AGL maybe cannot obtaion new lock
566 * for no glimpse callback triggered by AGL.
567 * 2) The former glimpse succeeded, but OST did not grant glimpse lock.
568 * Under such case, it is quite possible that the OST will not grant
569 * glimpse lock for AGL also.
570 * 3) The former glimpse failed, compared with other two cases, it is
571 * relative rare. AGL can ignore such case, and it will not muchly
572 * affect the performance.
574 if (lli->lli_glimpse_time != 0 &&
575 cfs_time_before(cfs_time_shift(-1), lli->lli_glimpse_time)) {
576 up_write(&lli->lli_glimpse_sem);
577 lli->lli_agl_index = 0;
582 CDEBUG(D_READA, "Handling (init) async glimpse: inode = "
583 DFID", idx = "LPU64"\n", PFID(&lli->lli_fid), index);
586 lli->lli_agl_index = 0;
587 lli->lli_glimpse_time = cfs_time_current();
588 up_write(&lli->lli_glimpse_sem);
590 CDEBUG(D_READA, "Handled (init) async glimpse: inode= "
591 DFID", idx = "LPU64", rc = %d\n",
592 PFID(&lli->lli_fid), index, rc);
599 /* prepare inode for received statahead entry, and add it into agl list */
600 static void sa_post_one(struct ll_statahead_info *sai,
601 struct ll_sa_entry *entry)
603 struct inode *dir = sai->sai_inode;
605 struct md_enqueue_info *minfo;
606 struct lookup_intent *it;
607 struct ptlrpc_request *req;
608 struct mdt_body *body;
612 LASSERT(entry->se_handle != 0);
614 minfo = entry->se_minfo;
617 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
619 GOTO(out, rc = -EFAULT);
621 child = entry->se_inode;
626 LASSERT(fid_is_zero(&minfo->mi_data.op_fid2));
628 /* XXX: No fid in reply, this is probaly cross-ref case.
629 * SA can't handle it yet. */
630 if (body->mbo_valid & OBD_MD_MDS)
631 GOTO(out, rc = -EAGAIN);
636 /* unlinked and re-created with the same name */
637 if (unlikely(!lu_fid_eq(&minfo->mi_data.op_fid2,
639 entry->se_inode = NULL;
645 it->d.lustre.it_lock_handle = entry->se_handle;
646 rc = md_revalidate_lock(ll_i2mdexp(dir), it, ll_inode2fid(dir), NULL);
648 GOTO(out, rc = -EAGAIN);
650 rc = ll_prep_inode(&child, req, dir->i_sb, it);
654 CDEBUG(D_DLMTRACE, "%s: setting l_data to inode "DFID"(%p)\n",
655 ll_get_fsname(child->i_sb, NULL, 0),
656 PFID(ll_inode2fid(child)), child);
657 ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, child, it, NULL);
659 entry->se_inode = child;
661 if (agl_should_run(sai, child))
662 ll_agl_add(sai, child, entry->se_index);
667 /* The "sa_entry_post_stat()" will drop related ldlm ibits lock
668 * reference count by calling "ll_intent_drop_lock()" in spite of the
669 * above operations failed or not. Do not worry about calling
670 * "ll_intent_drop_lock()" more than once. */
671 sa_entry_post_stat(sai, entry, rc < 0 ? SA_ENTRY_INVA : SA_ENTRY_SUCC);
672 if (entry->se_index == sai->sai_index_wait)
673 wake_up(&sai->sai_waitq);
674 ll_sa_entry_put(sai, entry);
677 static void ll_post_statahead(struct ll_statahead_info *sai)
679 struct ll_inode_info *lli;
681 lli = ll_i2info(sai->sai_inode);
683 while (!sa_received_empty(sai)) {
684 struct ll_sa_entry *entry;
686 spin_lock(&lli->lli_sa_lock);
687 if (unlikely(sa_received_empty(sai))) {
688 spin_unlock(&lli->lli_sa_lock);
691 entry = sa_first_received_entry(sai);
692 atomic_inc(&entry->se_refcount);
693 list_del_init(&entry->se_list);
694 spin_unlock(&lli->lli_sa_lock);
696 sa_post_one(sai, entry);
699 spin_lock(&lli->lli_agl_lock);
700 while (!agl_list_empty(sai)) {
701 struct ll_inode_info *clli;
703 clli = agl_first_entry(sai);
704 list_del_init(&clli->lli_agl_list);
705 spin_unlock(&lli->lli_agl_lock);
707 ll_agl_trigger(&clli->lli_vfs_inode, sai);
709 spin_lock(&lli->lli_agl_lock);
711 spin_unlock(&lli->lli_agl_lock);
714 static int ll_statahead_interpret(struct ptlrpc_request *req,
715 struct md_enqueue_info *minfo, int rc)
717 struct lookup_intent *it = &minfo->mi_it;
718 struct inode *dir = minfo->mi_dir;
719 struct ll_inode_info *lli = ll_i2info(dir);
720 struct ll_statahead_info *sai;
721 struct ll_sa_entry *entry;
725 if (it_disposition(it, DISP_LOOKUP_NEG))
728 sai = ll_sai_get(dir);
729 LASSERT(sai != NULL);
730 LASSERT(!thread_is_stopped(&sai->sai_thread));
732 spin_lock(&lli->lli_sa_lock);
733 entry = ll_sa_entry_get_byindex(sai, minfo->mi_cbdata);
734 LASSERT(entry != NULL);
736 __sa_entry_post_stat(sai, entry, SA_ENTRY_INVA);
737 wakeup = (entry->se_index == sai->sai_index_wait);
739 entry->se_minfo = minfo;
740 entry->se_req = ptlrpc_request_addref(req);
741 /* Release the async ibits lock ASAP to avoid deadlock
742 * when statahead thread tries to enqueue lock on parent
743 * for readpage and other tries to enqueue lock on child
744 * with parent's lock held, for example: unlink. */
745 entry->se_handle = it->d.lustre.it_lock_handle;
746 ll_intent_drop_lock(it);
747 wakeup = sa_received_empty(sai);
748 list_add_tail(&entry->se_list, &sai->sai_entries_received);
751 spin_unlock(&lli->lli_sa_lock);
753 ll_sa_entry_put(sai, entry);
755 wake_up(&sai->sai_thread.t_ctl_waitq);
758 ll_intent_release(it);
766 static void sa_args_fini(struct md_enqueue_info *minfo,
767 struct ldlm_enqueue_info *einfo)
769 LASSERT(minfo && einfo);
771 capa_put(minfo->mi_data.op_capa1);
772 capa_put(minfo->mi_data.op_capa2);
778 * There is race condition between "capa_put" and "ll_statahead_interpret" for
779 * accessing "op_data.op_capa[1,2]" as following:
780 * "capa_put" releases "op_data.op_capa[1,2]"'s reference count after calling
781 * "md_intent_getattr_async". But "ll_statahead_interpret" maybe run first, and
782 * fill "op_data.op_capa[1,2]" as POISON, then cause "capa_put" access invalid
783 * "ocapa". So here reserve "op_data.op_capa[1,2]" in "pcapa" before calling
784 * "md_intent_getattr_async".
786 static int sa_args_init(struct inode *dir, struct inode *child,
787 struct ll_sa_entry *entry, struct md_enqueue_info **pmi,
788 struct ldlm_enqueue_info **pei,
789 struct obd_capa **pcapa)
791 struct qstr *qstr = &entry->se_qstr;
792 struct md_enqueue_info *minfo;
793 struct ldlm_enqueue_info *einfo;
794 struct md_op_data *op_data;
796 OBD_ALLOC_PTR(einfo);
800 OBD_ALLOC_PTR(minfo);
806 op_data = ll_prep_md_op_data(&minfo->mi_data, dir, child, qstr->name,
807 qstr->len, 0, LUSTRE_OPC_ANY, NULL);
808 if (IS_ERR(op_data)) {
811 return PTR_ERR(op_data);
814 minfo->mi_it.it_op = IT_GETATTR;
815 minfo->mi_dir = igrab(dir);
816 minfo->mi_cb = ll_statahead_interpret;
817 minfo->mi_cbdata = entry->se_index;
819 einfo->ei_type = LDLM_IBITS;
820 einfo->ei_mode = it_to_lock_mode(&minfo->mi_it);
821 einfo->ei_cb_bl = ll_md_blocking_ast;
822 einfo->ei_cb_cp = ldlm_completion_ast;
823 einfo->ei_cb_gl = NULL;
824 einfo->ei_cbdata = NULL;
828 pcapa[0] = op_data->op_capa1;
829 pcapa[1] = op_data->op_capa2;
834 static int do_sa_lookup(struct inode *dir, struct ll_sa_entry *entry)
836 struct md_enqueue_info *minfo;
837 struct ldlm_enqueue_info *einfo;
838 struct obd_capa *capas[2];
842 rc = sa_args_init(dir, NULL, entry, &minfo, &einfo, capas);
846 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo, einfo);
851 sa_args_fini(minfo, einfo);
858 * similar to ll_revalidate_it().
859 * \retval 1 -- dentry valid
860 * \retval 0 -- will send stat-ahead request
861 * \retval others -- prepare stat-ahead request failed
863 static int do_sa_revalidate(struct inode *dir, struct ll_sa_entry *entry,
864 struct dentry *dentry)
866 struct inode *inode = dentry->d_inode;
867 struct lookup_intent it = { .it_op = IT_GETATTR,
868 .d.lustre.it_lock_handle = 0 };
869 struct md_enqueue_info *minfo;
870 struct ldlm_enqueue_info *einfo;
871 struct obd_capa *capas[2];
875 if (unlikely(inode == NULL))
878 if (d_mountpoint(dentry))
881 entry->se_inode = igrab(inode);
882 rc = md_revalidate_lock(ll_i2mdexp(dir), &it, ll_inode2fid(inode),NULL);
884 entry->se_handle = it.d.lustre.it_lock_handle;
885 ll_intent_release(&it);
889 rc = sa_args_init(dir, inode, entry, &minfo, &einfo, capas);
891 entry->se_inode = NULL;
896 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo, einfo);
901 entry->se_inode = NULL;
903 sa_args_fini(minfo, einfo);
909 static void ll_statahead_one(struct dentry *parent, const char *name,
912 struct inode *dir = parent->d_inode;
913 struct ll_inode_info *lli = ll_i2info(dir);
914 struct ll_statahead_info *sai = lli->lli_sai;
915 struct dentry *dentry = NULL;
916 struct ll_sa_entry *entry;
920 entry = ll_sa_entry_alloc(sai, sai->sai_index, name,namelen);
924 dentry = d_lookup(parent, &entry->se_qstr);
926 rc = do_sa_lookup(dir, entry);
928 rc = do_sa_revalidate(dir, entry, dentry);
929 if (rc == 1 && agl_should_run(sai, dentry->d_inode))
930 ll_agl_add(sai, dentry->d_inode, entry->se_index);
937 sa_entry_post_stat(sai, entry,
938 rc < 0 ? SA_ENTRY_INVA : SA_ENTRY_SUCC);
939 if (entry->se_index == sai->sai_index_wait)
940 wake_up(&sai->sai_waitq);
946 /* drop one refcount on entry by ll_sa_entry_alloc */
947 ll_sa_entry_put(sai, entry);
952 static int ll_agl_thread(void *arg)
954 struct dentry *parent = (struct dentry *)arg;
955 struct inode *dir = parent->d_inode;
956 struct ll_inode_info *plli = ll_i2info(dir);
957 struct ll_inode_info *clli;
958 struct ll_sb_info *sbi = ll_i2sbi(dir);
959 struct ll_statahead_info *sai;
960 struct ptlrpc_thread *thread;
961 struct l_wait_info lwi = { 0 };
965 sai = ll_sai_get(dir);
966 thread = &sai->sai_agl_thread;
967 thread->t_pid = current_pid();
968 CDEBUG(D_READA, "agl thread started: sai %p, parent %.*s\n",
969 sai, parent->d_name.len, parent->d_name.name);
971 atomic_inc(&sbi->ll_agl_total);
972 spin_lock(&plli->lli_agl_lock);
973 sai->sai_agl_valid = 1;
974 if (thread_is_init(thread))
975 /* If someone else has changed the thread state
976 * (e.g. already changed to SVC_STOPPING), we can't just
977 * blindly overwrite that setting. */
978 thread_set_flags(thread, SVC_RUNNING);
979 spin_unlock(&plli->lli_agl_lock);
980 wake_up(&thread->t_ctl_waitq);
983 l_wait_event(thread->t_ctl_waitq,
984 !agl_list_empty(sai) ||
985 !thread_is_running(thread),
988 if (!thread_is_running(thread))
991 spin_lock(&plli->lli_agl_lock);
992 /* The statahead thread maybe help to process AGL entries,
993 * so check whether list empty again. */
994 if (!agl_list_empty(sai)) {
995 clli = agl_first_entry(sai);
996 list_del_init(&clli->lli_agl_list);
997 spin_unlock(&plli->lli_agl_lock);
998 ll_agl_trigger(&clli->lli_vfs_inode, sai);
1000 spin_unlock(&plli->lli_agl_lock);
1004 spin_lock(&plli->lli_agl_lock);
1005 sai->sai_agl_valid = 0;
1006 while (!agl_list_empty(sai)) {
1007 clli = agl_first_entry(sai);
1008 list_del_init(&clli->lli_agl_list);
1009 spin_unlock(&plli->lli_agl_lock);
1010 clli->lli_agl_index = 0;
1011 iput(&clli->lli_vfs_inode);
1012 spin_lock(&plli->lli_agl_lock);
1014 thread_set_flags(thread, SVC_STOPPED);
1015 spin_unlock(&plli->lli_agl_lock);
1016 wake_up(&thread->t_ctl_waitq);
1018 CDEBUG(D_READA, "agl thread stopped: sai %p, parent %.*s\n",
1019 sai, parent->d_name.len, parent->d_name.name);
1023 static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai)
1025 struct ptlrpc_thread *thread = &sai->sai_agl_thread;
1026 struct l_wait_info lwi = { 0 };
1027 struct ll_inode_info *plli;
1028 struct task_struct *task;
1031 CDEBUG(D_READA, "start agl thread: sai %p, parent %.*s\n",
1032 sai, parent->d_name.len, parent->d_name.name);
1034 plli = ll_i2info(parent->d_inode);
1035 task = kthread_run(ll_agl_thread, parent,
1036 "ll_agl_%u", plli->lli_opendir_pid);
1038 CERROR("can't start ll_agl thread, rc: %ld\n", PTR_ERR(task));
1039 thread_set_flags(thread, SVC_STOPPED);
1043 l_wait_event(thread->t_ctl_waitq,
1044 thread_is_running(thread) || thread_is_stopped(thread),
1049 static int ll_statahead_thread(void *arg)
1051 struct dentry *parent = (struct dentry *)arg;
1052 struct inode *dir = parent->d_inode;
1053 struct ll_inode_info *lli = ll_i2info(dir);
1054 struct ll_sb_info *sbi = ll_i2sbi(dir);
1055 struct ll_statahead_info *sai;
1056 struct ptlrpc_thread *thread;
1057 struct ptlrpc_thread *agl_thread;
1059 struct md_op_data *op_data;
1060 struct ll_dir_chain chain;
1061 struct l_wait_info lwi = { 0 };
1062 struct page *page = NULL;
1067 sai = ll_sai_get(dir);
1068 thread = &sai->sai_thread;
1069 agl_thread = &sai->sai_agl_thread;
1070 thread->t_pid = current_pid();
1071 CDEBUG(D_READA, "statahead thread starting: sai %p, parent %.*s\n",
1072 sai, parent->d_name.len, parent->d_name.name);
1074 op_data = ll_prep_md_op_data(NULL, dir, dir, NULL, 0, 0,
1075 LUSTRE_OPC_ANY, dir);
1076 if (IS_ERR(op_data))
1077 GOTO(out, rc = PTR_ERR(op_data));
1079 op_data->op_max_pages = ll_i2sbi(dir)->ll_md_brw_pages;
1081 if (sbi->ll_flags & LL_SBI_AGL_ENABLED)
1082 ll_start_agl(parent, sai);
1084 atomic_inc(&sbi->ll_sa_total);
1085 spin_lock(&lli->lli_sa_lock);
1086 if (thread_is_init(thread))
1087 /* If someone else has changed the thread state
1088 * (e.g. already changed to SVC_STOPPING), we can't just
1089 * blindly overwrite that setting. */
1090 thread_set_flags(thread, SVC_RUNNING);
1091 spin_unlock(&lli->lli_sa_lock);
1092 wake_up(&thread->t_ctl_waitq);
1094 ll_dir_chain_init(&chain);
1095 while (pos != MDS_DIR_END_OFF && thread_is_running(thread)) {
1096 struct lu_dirpage *dp;
1097 struct lu_dirent *ent;
1099 sai->sai_in_readpage = 1;
1100 page = ll_get_dir_page(dir, op_data, pos, &chain);
1101 sai->sai_in_readpage = 0;
1104 CDEBUG(D_READA, "error reading dir "DFID" at "LPU64
1105 "/"LPU64" opendir_pid = %u: rc = %d\n",
1106 PFID(ll_inode2fid(dir)), pos, sai->sai_index,
1107 lli->lli_opendir_pid, rc);
1111 dp = page_address(page);
1112 for (ent = lu_dirent_start(dp);
1113 ent != NULL && thread_is_running(thread) &&
1115 ent = lu_dirent_next(ent)) {
1120 hash = le64_to_cpu(ent->lde_hash);
1121 if (unlikely(hash < pos))
1123 * Skip until we find target hash value.
1127 namelen = le16_to_cpu(ent->lde_namelen);
1128 if (unlikely(namelen == 0))
1130 * Skip dummy record.
1134 name = ent->lde_name;
1135 if (name[0] == '.') {
1141 } else if (name[1] == '.' && namelen == 2) {
1146 } else if (!sai->sai_ls_all) {
1148 * skip hidden files.
1150 sai->sai_skip_hidden++;
1156 * don't stat-ahead first entry.
1158 if (unlikely(++first == 1))
1161 /* wait for spare statahead window */
1163 l_wait_event(thread->t_ctl_waitq,
1164 !sa_sent_full(sai) ||
1165 !sa_received_empty(sai) ||
1166 !agl_list_empty(sai) ||
1167 !thread_is_running(thread),
1170 ll_post_statahead(sai);
1171 } while (sa_sent_full(sai) &&
1172 thread_is_running(thread));
1174 ll_statahead_one(parent, name, namelen);
1177 pos = le64_to_cpu(dp->ldp_hash_end);
1178 ll_release_page(dir, page,
1179 le32_to_cpu(dp->ldp_flags) & LDF_COLLIDE);
1181 if (sa_low_hit(sai)) {
1183 atomic_inc(&sbi->ll_sa_wrong);
1184 CDEBUG(D_READA, "Statahead for dir "DFID" hit "
1185 "ratio too low: hit/miss "LPU64"/"LPU64
1186 ", sent/replied "LPU64"/"LPU64", stopping "
1187 "statahead thread: pid %d\n",
1188 PFID(&lli->lli_fid), sai->sai_hit,
1189 sai->sai_miss, sai->sai_sent,
1190 sai->sai_replied, current_pid());
1194 ll_dir_chain_fini(&chain);
1195 ll_finish_md_op_data(op_data);
1198 spin_lock(&lli->lli_sa_lock);
1199 thread_set_flags(thread, SVC_STOPPING);
1200 lli->lli_sa_enabled = 0;
1201 spin_unlock(&lli->lli_sa_lock);
1204 /* statahead is finished, but statahead entries need to be cached, wait
1205 * for file release to stop me. */
1206 while (thread_is_running(thread)) {
1207 l_wait_event(thread->t_ctl_waitq,
1208 !sa_received_empty(sai) ||
1209 !agl_list_empty(sai) ||
1210 !thread_is_running(thread),
1213 ll_post_statahead(sai);
1218 if (sai->sai_agl_valid) {
1219 spin_lock(&lli->lli_agl_lock);
1220 thread_set_flags(agl_thread, SVC_STOPPING);
1221 spin_unlock(&lli->lli_agl_lock);
1222 wake_up(&agl_thread->t_ctl_waitq);
1224 CDEBUG(D_READA, "stop agl thread: sai %p pid %u\n",
1225 sai, (unsigned int)agl_thread->t_pid);
1226 l_wait_event(agl_thread->t_ctl_waitq,
1227 thread_is_stopped(agl_thread),
1230 /* Set agl_thread flags anyway. */
1231 thread_set_flags(agl_thread, SVC_STOPPED);
1234 /* wait for inflight statahead RPCs to finish, and then we can free sai
1235 * safely because statahead RPC will access sai data */
1236 while (sai->sai_sent != sai->sai_replied) {
1237 /* in case we're not woken up, timeout wait */
1238 lwi = LWI_TIMEOUT(HZ >> 3, NULL, NULL);
1239 l_wait_event(thread->t_ctl_waitq,
1240 sai->sai_sent == sai->sai_replied, &lwi);
1243 /* release resources held by received entries. */
1244 ll_post_statahead(sai);
1246 spin_lock(&lli->lli_sa_lock);
1247 thread_set_flags(thread, SVC_STOPPED);
1248 spin_unlock(&lli->lli_sa_lock);
1250 wake_up(&sai->sai_waitq);
1251 wake_up(&thread->t_ctl_waitq);
1253 CDEBUG(D_READA, "statahead thread stopped: sai %p, parent %.*s\n",
1254 sai, parent->d_name.len, parent->d_name.name);
1259 /* authorize opened dir handle @key to statahead later */
1260 void ll_authorize_statahead(struct inode *dir, void *key)
1262 struct ll_inode_info *lli = ll_i2info(dir);
1264 spin_lock(&lli->lli_sa_lock);
1265 if (lli->lli_opendir_key == NULL && lli->lli_sai == NULL) {
1267 * if lli_sai is not NULL, it means previous statahead is not
1268 * finished yet, we'd better not start a new statahead for now.
1270 LASSERT(lli->lli_opendir_pid == 0);
1271 lli->lli_opendir_key = key;
1272 lli->lli_opendir_pid = current_pid();
1273 lli->lli_sa_enabled = 1;
1275 spin_unlock(&lli->lli_sa_lock);
1278 /* deauthorize opened dir handle @key to statahead, but statahead thread may
1279 * still be running, notify it to quit. */
1280 void ll_deauthorize_statahead(struct inode *dir, void *key)
1282 struct ll_inode_info *lli = ll_i2info(dir);
1283 struct ll_statahead_info *sai;
1285 LASSERT(lli->lli_opendir_key == key);
1286 LASSERT(lli->lli_opendir_pid != 0);
1288 CDEBUG(D_READA, "deauthorize statahead for "DFID"\n",
1289 PFID(&lli->lli_fid));
1291 spin_lock(&lli->lli_sa_lock);
1292 lli->lli_opendir_key = NULL;
1293 lli->lli_opendir_pid = 0;
1294 lli->lli_sa_enabled = 0;
1296 if (sai != NULL && thread_is_running(&sai->sai_thread)) {
1298 * statahead thread may not quit yet because it needs to cache
1299 * stated entries, now it's time to tell it to quit.
1301 thread_set_flags(&sai->sai_thread, SVC_STOPPING);
1302 wake_up(&sai->sai_thread.t_ctl_waitq);
1304 spin_unlock(&lli->lli_sa_lock);
1309 * not first dirent, or is "."
1311 LS_NONE_FIRST_DE = 0,
1313 * the first non-hidden dirent
1317 * the first hidden dirent, that is "."
1322 static int is_first_dirent(struct inode *dir, struct dentry *dentry)
1324 struct ll_dir_chain chain;
1325 struct qstr *target = &dentry->d_name;
1326 struct md_op_data *op_data;
1328 struct page *page = NULL;
1329 int rc = LS_NONE_FIRST_DE;
1333 op_data = ll_prep_md_op_data(NULL, dir, dir, NULL, 0, 0,
1334 LUSTRE_OPC_ANY, dir);
1335 if (IS_ERR(op_data))
1336 RETURN(PTR_ERR(op_data));
1338 *FIXME choose the start offset of the readdir
1340 op_data->op_stripe_offset = 0;
1341 op_data->op_max_pages = ll_i2sbi(dir)->ll_md_brw_pages;
1343 ll_dir_chain_init(&chain);
1344 page = ll_get_dir_page(dir, op_data, 0, &chain);
1347 struct lu_dirpage *dp;
1348 struct lu_dirent *ent;
1351 struct ll_inode_info *lli = ll_i2info(dir);
1354 CERROR("%s: reading dir "DFID" at "LPU64
1355 "opendir_pid = %u : rc = %d\n",
1356 ll_get_fsname(dir->i_sb, NULL, 0),
1357 PFID(ll_inode2fid(dir)), pos,
1358 lli->lli_opendir_pid, rc);
1362 dp = page_address(page);
1363 for (ent = lu_dirent_start(dp); ent != NULL;
1364 ent = lu_dirent_next(ent)) {
1369 hash = le64_to_cpu(ent->lde_hash);
1370 /* The ll_get_dir_page() can return any page containing
1371 * the given hash which may be not the start hash. */
1372 if (unlikely(hash < pos))
1375 namelen = le16_to_cpu(ent->lde_namelen);
1376 if (unlikely(namelen == 0))
1378 * skip dummy record.
1382 name = ent->lde_name;
1383 if (name[0] == '.') {
1389 else if (name[1] == '.' && namelen == 2)
1400 if (dot_de && target->name[0] != '.') {
1401 CDEBUG(D_READA, "%.*s skip hidden file %.*s\n",
1402 target->len, target->name,
1407 if (target->len != namelen ||
1408 memcmp(target->name, name, namelen) != 0)
1409 rc = LS_NONE_FIRST_DE;
1413 rc = LS_FIRST_DOT_DE;
1415 ll_release_page(dir, page, false);
1418 pos = le64_to_cpu(dp->ldp_hash_end);
1419 if (pos == MDS_DIR_END_OFF) {
1421 * End of directory reached.
1423 ll_release_page(dir, page, false);
1427 * chain is exhausted
1428 * Normal case: continue to the next page.
1430 ll_release_page(dir, page, le32_to_cpu(dp->ldp_flags) &
1432 page = ll_get_dir_page(dir, op_data, pos, &chain);
1437 ll_dir_chain_fini(&chain);
1438 ll_finish_md_op_data(op_data);
1443 ll_sai_unplug(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
1445 if (entry != NULL && entry->se_stat == SA_ENTRY_SUCC) {
1446 struct ll_sb_info *sbi = ll_i2sbi(sai->sai_inode);
1449 sai->sai_consecutive_miss = 0;
1450 sai->sai_max = min(2 * sai->sai_max, sbi->ll_sa_max);
1453 sai->sai_consecutive_miss++;
1455 ll_sa_entry_fini(sai, entry);
1456 wake_up(&sai->sai_thread.t_ctl_waitq);
1459 static int revalidate_statahead_dentry(struct inode *dir,
1460 struct ll_statahead_info *sai,
1461 struct dentry **dentryp,
1464 struct ll_sa_entry *entry = NULL;
1465 struct l_wait_info lwi = { 0 };
1469 if ((*dentryp)->d_name.name[0] == '.') {
1470 if (sai->sai_ls_all ||
1471 sai->sai_miss_hidden >= sai->sai_skip_hidden) {
1473 * Hidden dentry is the first one, or statahead
1474 * thread does not skip so many hidden dentries
1475 * before "sai_ls_all" enabled as below.
1478 if (!sai->sai_ls_all)
1480 * It maybe because hidden dentry is not
1481 * the first one, "sai_ls_all" was not
1482 * set, then "ls -al" missed. Enable
1483 * "sai_ls_all" for such case.
1485 sai->sai_ls_all = 1;
1488 * Such "getattr" has been skipped before
1489 * "sai_ls_all" enabled as above.
1491 sai->sai_miss_hidden++;
1496 entry = ll_sa_entry_get_byname(sai, &(*dentryp)->d_name);
1497 if (entry == NULL || only_unplug) {
1498 ll_sai_unplug(sai, entry);
1499 RETURN(entry ? 1 : -EAGAIN);
1502 /* if statahead is busy in readdir, help it do post-work */
1503 if (!ll_sa_entry_stated(entry) && sai->sai_in_readpage)
1504 ll_post_statahead(sai);
1506 if (!ll_sa_entry_stated(entry)) {
1507 sai->sai_index_wait = entry->se_index;
1508 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(30), NULL,
1509 LWI_ON_SIGNAL_NOOP, NULL);
1510 rc = l_wait_event(sai->sai_waitq,
1511 ll_sa_entry_stated(entry) ||
1512 thread_is_stopped(&sai->sai_thread),
1515 ll_sai_unplug(sai, entry);
1520 if (entry->se_stat == SA_ENTRY_SUCC && entry->se_inode != NULL) {
1521 struct inode *inode = entry->se_inode;
1522 struct lookup_intent it = { .it_op = IT_GETATTR,
1523 .d.lustre.it_lock_handle =
1527 rc = md_revalidate_lock(ll_i2mdexp(dir), &it,
1528 ll_inode2fid(inode), &bits);
1530 if ((*dentryp)->d_inode == NULL) {
1531 struct dentry *alias;
1533 alias = ll_splice_alias(inode, *dentryp);
1534 if (IS_ERR(alias)) {
1535 ll_sai_unplug(sai, entry);
1536 RETURN(PTR_ERR(alias));
1539 } else if ((*dentryp)->d_inode != inode) {
1540 /* revalidate, but inode is recreated */
1542 "%s: stale dentry %.*s inode "
1543 DFID", statahead inode "DFID
1545 ll_get_fsname((*dentryp)->d_inode->i_sb,
1547 (*dentryp)->d_name.len,
1548 (*dentryp)->d_name.name,
1549 PFID(ll_inode2fid((*dentryp)->d_inode)),
1550 PFID(ll_inode2fid(inode)));
1551 ll_sai_unplug(sai, entry);
1556 entry->se_inode = NULL;
1558 if ((bits & MDS_INODELOCK_LOOKUP) &&
1559 d_lustre_invalid(*dentryp))
1560 d_lustre_revalidate(*dentryp);
1561 ll_intent_release(&it);
1565 ll_sai_unplug(sai, entry);
1569 static int start_statahead_thread(struct inode *dir, struct dentry *dentry)
1571 struct ll_inode_info *lli = ll_i2info(dir);
1572 struct ll_statahead_info *sai = NULL;
1573 struct dentry *parent;
1574 struct ptlrpc_thread *thread;
1575 struct l_wait_info lwi = { 0 };
1576 struct task_struct *task;
1580 /* I am the "lli_opendir_pid" owner, only me can set "lli_sai". */
1581 rc = is_first_dirent(dir, dentry);
1582 if (rc == LS_NONE_FIRST_DE)
1583 /* It is not "ls -{a}l" operation, no need statahead for it. */
1584 GOTO(out, rc = -EAGAIN);
1586 sai = ll_sai_alloc();
1588 GOTO(out, rc = -ENOMEM);
1590 sai->sai_ls_all = (rc == LS_FIRST_DOT_DE);
1591 sai->sai_inode = igrab(dir);
1592 if (unlikely(sai->sai_inode == NULL)) {
1593 CWARN("Do not start stat ahead on dying inode "DFID"\n",
1594 PFID(&lli->lli_fid));
1595 GOTO(out, rc = -ESTALE);
1598 /* get parent reference count here, and put it in ll_statahead_thread */
1599 parent = dget(dentry->d_parent);
1600 if (unlikely(sai->sai_inode != parent->d_inode)) {
1601 struct ll_inode_info *nlli = ll_i2info(parent->d_inode);
1603 CWARN("Race condition, someone changed %.*s just now: "
1604 "old parent "DFID", new parent "DFID"\n",
1605 dentry->d_name.len, dentry->d_name.name,
1606 PFID(&lli->lli_fid), PFID(&nlli->lli_fid));
1608 iput(sai->sai_inode);
1609 GOTO(out, rc = -EAGAIN);
1612 CDEBUG(D_READA, "start statahead thread: sai %p, parent %.*s\n",
1613 sai, parent->d_name.len, parent->d_name.name);
1617 task = kthread_run(ll_statahead_thread, parent, "ll_sa_%u",
1618 lli->lli_opendir_pid);
1619 thread = &sai->sai_thread;
1622 CERROR("cannot start ll_sa thread: rc = %d\n", rc);
1624 lli->lli_opendir_key = NULL;
1625 thread_set_flags(thread, SVC_STOPPED);
1626 thread_set_flags(&sai->sai_agl_thread, SVC_STOPPED);
1628 LASSERT(lli->lli_sai == NULL);
1632 l_wait_event(thread->t_ctl_waitq,
1633 thread_is_running(thread) || thread_is_stopped(thread),
1635 atomic_inc(&ll_i2sbi(parent->d_inode)->ll_sa_running);
1639 * We don't stat-ahead for the first dirent since we are already in
1647 spin_lock(&lli->lli_sa_lock);
1648 lli->lli_opendir_key = NULL;
1649 lli->lli_opendir_pid = 0;
1650 lli->lli_sa_enabled = 0;
1651 spin_unlock(&lli->lli_sa_lock);
1657 * Start statahead thread if this is the first dir entry.
1658 * Otherwise if a thread is started already, wait it until it is ahead of me.
1659 * \retval 1 -- find entry with lock in cache, the caller needs to do
1661 * \retval 0 -- find entry in cache, but without lock, the caller needs
1663 * \retval others -- the caller need to process as non-statahead.
1665 int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
1668 struct ll_statahead_info *sai;
1670 sai = ll_sai_get(dir);
1674 rc = revalidate_statahead_dentry(dir, sai, dentryp,
1676 CDEBUG(D_READA, "revalidate statahead %.*s: %d.\n",
1677 (*dentryp)->d_name.len, (*dentryp)->d_name.name, rc);
1682 return start_statahead_thread(dir, *dentryp);