X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fllite%2Fstatahead.c;h=315e7621d777693eb82e16a2ed18ff6d0ea5745b;hb=5d4ae6c905b8e8a38a6e4d3195f550a1e2b37ba8;hp=503235aa9374f6b161272d52678922f5530f0314;hpb=cc580d67ee72fce637374891714885c889dce026;p=fs%2Flustre-release.git diff --git a/lustre/llite/statahead.c b/lustre/llite/statahead.c index 503235a..315e762 100644 --- a/lustre/llite/statahead.c +++ b/lustre/llite/statahead.c @@ -26,7 +26,7 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. */ /* @@ -55,8 +55,6 @@ struct ll_sai_entry { int se_stat; struct ptlrpc_request *se_req; struct md_enqueue_info *se_minfo; - struct dentry *se_dentry; - struct inode *se_inode; }; enum { @@ -69,7 +67,7 @@ static cfs_spinlock_t sai_generation_lock = CFS_SPIN_LOCK_UNLOCKED; /** * Check whether first entry was stated already or not. - * No need to hold lli_lock, for: + * No need to hold lli_sa_lock, for: * (1) it is me that remove entry from the list * (2) the statahead thread only add new entry to the list */ @@ -94,7 +92,7 @@ static inline int sa_received_empty(struct ll_statahead_info *sai) static inline int sa_not_full(struct ll_statahead_info *sai) { - return (sai->sai_index < sai->sai_hit + sai->sai_miss + sai->sai_max); + return !!(sai->sai_index < sai->sai_index_next + sai->sai_max); } static inline int sa_is_running(struct ll_statahead_info *sai) @@ -123,23 +121,6 @@ static inline int sa_low_hit(struct ll_statahead_info *sai) (sai->sai_consecutive_miss > 8)); } -static void ll_sai_entry_free(struct ll_sai_entry *entry) -{ - struct dentry *dentry = entry->se_dentry; - struct inode *inode = entry->se_inode; - - if (dentry) { - entry->se_dentry = NULL; - dput(dentry); - } - if (inode) { - entry->se_inode = NULL; - iput(inode); - } - LASSERT(cfs_list_empty(&entry->se_list)); - OBD_FREE_PTR(entry); -} - /** * process the deleted entry's member and free the entry. * (1) release intent @@ -164,8 +145,10 @@ static void ll_sai_entry_cleanup(struct ll_sai_entry *entry, int free) entry->se_req = NULL; ptlrpc_req_finished(req); } - if (free) - ll_sai_entry_free(entry); + if (free) { + LASSERT(cfs_list_empty(&entry->se_list)); + OBD_FREE_PTR(entry); + } EXIT; } @@ -211,22 +194,20 @@ static void ll_sai_put(struct ll_statahead_info *sai) lli = ll_i2info(inode); LASSERT(lli->lli_sai == sai); - if (cfs_atomic_dec_and_test(&sai->sai_refcount)) { + if (cfs_atomic_dec_and_lock(&sai->sai_refcount, &lli->lli_sa_lock)) { struct ll_sai_entry *entry, *next; - cfs_spin_lock(&lli->lli_lock); if (unlikely(cfs_atomic_read(&sai->sai_refcount) > 0)) { /* It is race case, the interpret callback just hold * a reference count */ - cfs_spin_unlock(&lli->lli_lock); - EXIT; - return; + cfs_spin_unlock(&lli->lli_sa_lock); + RETURN_EXIT; } LASSERT(lli->lli_opendir_key == NULL); lli->lli_sai = NULL; lli->lli_opendir_pid = 0; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); LASSERT(sa_is_stopped(sai)); @@ -278,9 +259,9 @@ ll_sai_entry_init(struct ll_statahead_info *sai, unsigned int index) entry->se_index = index; entry->se_stat = SA_ENTRY_UNSTATED; - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); cfs_list_add_tail(&entry->se_list, &sai->sai_entries_sent); - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); RETURN(entry); } @@ -296,7 +277,7 @@ static int ll_sai_entry_fini(struct ll_statahead_info *sai) int rc = 0; ENTRY; - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); sai->sai_index_next++; if (likely(!cfs_list_empty(&sai->sai_entries_stated))) { entry = cfs_list_entry(sai->sai_entries_stated.next, @@ -304,18 +285,18 @@ static int ll_sai_entry_fini(struct ll_statahead_info *sai) if (entry->se_index < sai->sai_index_next) { cfs_list_del_init(&entry->se_list); rc = entry->se_stat; - ll_sai_entry_free(entry); + OBD_FREE_PTR(entry); } } else { LASSERT(sa_is_stopped(sai)); } - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); RETURN(rc); } /** - * inside lli_lock. + * inside lli_sa_lock. * \retval NULL : can not find the entry in sai_entries_sent with the index * \retval entry: find the entry in sai_entries_sent with the index */ @@ -343,7 +324,7 @@ ll_sai_entry_set(struct ll_statahead_info *sai, unsigned int index, int stat, } /** - * inside lli_lock. + * inside lli_sa_lock. * Move entry to sai_entries_received and * insert it into sai_entries_received tail. */ @@ -368,21 +349,21 @@ ll_sai_entry_to_stated(struct ll_statahead_info *sai, struct ll_sai_entry *entry ll_sai_entry_cleanup(entry, 0); - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); if (!cfs_list_empty(&entry->se_list)) cfs_list_del_init(&entry->se_list); /* stale entry */ if (unlikely(entry->se_index < sai->sai_index_next)) { - cfs_spin_unlock(&lli->lli_lock); - ll_sai_entry_free(entry); + cfs_spin_unlock(&lli->lli_sa_lock); + OBD_FREE_PTR(entry); RETURN(0); } cfs_list_for_each_entry_reverse(se, &sai->sai_entries_stated, se_list) { if (se->se_index < entry->se_index) { cfs_list_add(&entry->se_list, &se->se_list); - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); RETURN(1); } } @@ -391,7 +372,7 @@ ll_sai_entry_to_stated(struct ll_statahead_info *sai, struct ll_sai_entry *entry * I am the first entry. */ cfs_list_add(&entry->se_list, &sai->sai_entries_stated); - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); RETURN(1); } @@ -410,12 +391,12 @@ static int do_statahead_interpret(struct ll_statahead_info *sai) struct mdt_body *body; ENTRY; - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); LASSERT(!sa_received_empty(sai)); entry = cfs_list_entry(sai->sai_entries_received.next, struct ll_sai_entry, se_list); cfs_list_del_init(&entry->se_list); - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); if (unlikely(entry->se_index < sai->sai_index_next)) { CWARN("Found stale entry: [index %u] [next %u]\n", @@ -455,24 +436,14 @@ static int do_statahead_interpret(struct ll_statahead_info *sai) /* Here dentry->d_inode might be NULL, because the entry may * have been removed before we start doing stat ahead. */ + rc = ll_lookup_it_finish(req, it, &icbd); + if (!rc) + ll_lookup_finish_locks(it, dentry); - /* BUG 15962, 21739: since statahead thread does not hold - * parent's i_mutex, it can not alias the dentry to inode. - * Here we just create/update inode in memory, and let the - * main "ls -l" thread to alias such dentry to the inode with - * parent's i_mutex held. - * On the other hand, we hold ldlm ibits lock for the inode - * yet, to allow other operations to cancel such lock in time, - * we should drop the ldlm lock reference count, then the main - * "ls -l" thread should check/get such ldlm ibits lock before - * aliasing such dentry to the inode later. If we don't do such - * drop here, it maybe cause deadlock with i_muext held by - * others, just like bug 21739. */ - rc = ll_lookup_it_finish(req, it, &icbd, &entry->se_inode); - if (entry->se_inode != NULL) - entry->se_dentry = dget(dentry); - LASSERT(dentry == save); - ll_intent_drop_lock(it); + if (dentry != save) { + minfo->mi_dentry = dentry; + dput(save); + } } else { /* * revalidate. @@ -527,11 +498,11 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, CDEBUG(D_READA, "interpret statahead %.*s rc %d\n", dentry->d_name.len, dentry->d_name.name, rc); - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); /* stale entry */ if (unlikely(lli->lli_sai == NULL || lli->lli_sai->sai_generation != minfo->mi_generation)) { - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); ll_intent_release(it); dput(dentry); iput(dir); @@ -547,13 +518,13 @@ static int ll_statahead_interpret(struct ptlrpc_request *req, if (likely(sa_is_running(sai))) { ll_sai_entry_to_received(sai, entry); sai->sai_replied++; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); cfs_waitq_signal(&sai->sai_thread.t_ctl_waitq); } else { if (!cfs_list_empty(&entry->se_list)) cfs_list_del_init(&entry->se_list); sai->sai_replied++; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); ll_sai_entry_cleanup(entry, 1); } ll_sai_put(sai); @@ -683,8 +654,7 @@ static int do_sa_revalidate(struct inode *dir, struct dentry *dentry) if (unlikely(dentry == dentry->d_sb->s_root)) RETURN(1); - rc = md_revalidate_lock(ll_i2mdexp(dir), &it, ll_inode2fid(inode), - NULL); + rc = md_revalidate_lock(ll_i2mdexp(dir), &it, ll_inode2fid(inode)); if (rc == 1) { ll_intent_release(&it); RETURN(1); @@ -719,7 +689,7 @@ static int ll_statahead_one(struct dentry *parent, const char* entry_name, struct ll_inode_info *lli = ll_i2info(dir); struct ll_statahead_info *sai = lli->lli_sai; struct qstr name; - struct dentry *dentry; + struct dentry *dentry = NULL; struct ll_sai_entry *se; int rc; ENTRY; @@ -739,26 +709,23 @@ static int ll_statahead_one(struct dentry *parent, const char* entry_name, dentry = d_lookup(parent, &name); if (!dentry) { dentry = d_alloc(parent, &name); - if (dentry) { + if (dentry) rc = do_sa_lookup(dir, dentry); - if (rc) - dput(dentry); - } else { + else GOTO(out, rc = -ENOMEM); - } } else { rc = do_sa_revalidate(dir, dentry); - if (rc) - dput(dentry); } EXIT; out: if (rc) { + if (dentry != NULL) + dput(dentry); + se->se_stat = rc < 0 ? rc : SA_ENTRY_STATED; CDEBUG(D_READA, "set sai entry %p index %u stat %d rc %d\n", se, se->se_index, se->se_stat, rc); - se->se_stat = rc < 0 ? rc : SA_ENTRY_STATED; if (ll_sai_entry_to_stated(sai, se)) cfs_waitq_signal(&sai->sai_waitq); } else { @@ -791,14 +758,16 @@ static int ll_statahead_thread(void *arg) } atomic_inc(&sbi->ll_sa_total); - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); thread->t_flags = SVC_RUNNING; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); cfs_waitq_signal(&thread->t_ctl_waitq); CDEBUG(D_READA, "start doing statahead for %s\n", parent->d_name.name); + sai->sai_pid = cfs_curproc_pid(); + lli->lli_sa_pos = 0; ll_dir_chain_init(&chain); - page = ll_get_dir_page(dir, pos, 0, &chain); + page = ll_get_dir_page(NULL, dir, pos, 0, &chain); while (1) { struct l_wait_info lwi = { 0 }; @@ -817,15 +786,25 @@ static int ll_statahead_thread(void *arg) dp = page_address(page); for (ent = lu_dirent_start(dp); ent != NULL; ent = lu_dirent_next(ent)) { - char *name = ent->lde_name; - int namelen = le16_to_cpu(ent->lde_namelen); + __u64 hash; + int namelen; + char *name; + hash = le64_to_cpu(ent->lde_hash); + if (unlikely(hash < pos)) + /* + * Skip until we find target hash value. + */ + continue; + + namelen = le16_to_cpu(ent->lde_namelen); if (unlikely(namelen == 0)) /* * Skip dummy record. */ continue; + name = ent->lde_name; if (name[0] == '.') { if (namelen == 1) { /* @@ -903,7 +882,8 @@ keep_de: * chain is exhausted. * Normal case: continue to the next page. */ - page = ll_get_dir_page(dir, pos, 1, &chain); + lli->lli_sa_pos = pos; + page = ll_get_dir_page(NULL, dir, pos, 1, &chain); } else { /* * go into overflow page. @@ -914,9 +894,9 @@ keep_de: out: ll_dir_chain_fini(&chain); - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); thread->t_flags = SVC_STOPPED; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); cfs_waitq_signal(&sai->sai_waitq); cfs_waitq_signal(&thread->t_ctl_waitq); ll_sai_put(sai); @@ -929,16 +909,16 @@ out: /** * called in ll_file_release(). */ -void ll_stop_statahead(struct inode *inode, void *key) +void ll_stop_statahead(struct inode *dir, void *key) { - struct ll_inode_info *lli = ll_i2info(inode); + struct ll_inode_info *lli = ll_i2info(dir); if (unlikely(key == NULL)) return; - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); if (lli->lli_opendir_key != key || lli->lli_opendir_pid == 0) { - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); return; } @@ -950,7 +930,7 @@ void ll_stop_statahead(struct inode *inode, void *key) if (!sa_is_stopped(lli->lli_sai)) { thread->t_flags = SVC_STOPPING; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); cfs_waitq_signal(&thread->t_ctl_waitq); CDEBUG(D_READA, "stopping statahead thread, pid %d\n", @@ -959,7 +939,7 @@ void ll_stop_statahead(struct inode *inode, void *key) sa_is_stopped(lli->lli_sai), &lwi); } else { - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); } /* @@ -970,7 +950,7 @@ void ll_stop_statahead(struct inode *inode, void *key) ll_sai_put(lli->lli_sai); } else { lli->lli_opendir_pid = 0; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); } } @@ -991,6 +971,7 @@ enum { static int is_first_dirent(struct inode *dir, struct dentry *dentry) { + struct ll_inode_info *lli = ll_i2info(dir); struct ll_dir_chain chain; struct qstr *target = &dentry->d_name; struct page *page; @@ -999,8 +980,9 @@ static int is_first_dirent(struct inode *dir, struct dentry *dentry) int rc = LS_NONE_FIRST_DE; ENTRY; + lli->lli_sa_pos = 0; ll_dir_chain_init(&chain); - page = ll_get_dir_page(dir, pos, 0, &chain); + page = ll_get_dir_page(NULL, dir, pos, 0, &chain); while (1) { struct lu_dirpage *dp; @@ -1020,15 +1002,17 @@ static int is_first_dirent(struct inode *dir, struct dentry *dentry) dp = page_address(page); for (ent = lu_dirent_start(dp); ent != NULL; ent = lu_dirent_next(ent)) { - char *name = ent->lde_name; - int namelen = le16_to_cpu(ent->lde_namelen); + int namelen; + char *name; - if (namelen == 0) + namelen = le16_to_cpu(ent->lde_namelen); + if (unlikely(namelen == 0)) /* * skip dummy record. */ continue; + name = ent->lde_name; if (name[0] == '.') { if (namelen == 1) /* @@ -1076,7 +1060,8 @@ static int is_first_dirent(struct inode *dir, struct dentry *dentry) * chain is exhausted * Normal case: continue to the next page. */ - page = ll_get_dir_page(dir, pos, 1, &chain); + lli->lli_sa_pos = pos; + page = ll_get_dir_page(NULL, dir, pos, 1, &chain); } else { /* * go into overflow page. @@ -1090,23 +1075,11 @@ out: return rc; } -static int is_same_dentry(struct dentry *d1, struct dentry *d2) -{ - if (unlikely(d1 == d2)) - return 1; - if (d1->d_parent == d2->d_parent && - d1->d_name.hash == d2->d_name.hash && - d1->d_name.len == d2->d_name.len && - memcmp(d1->d_name.name, d2->d_name.name, d1->d_name.len) == 0) - return 1; - return 0; -} - /** * Start statahead thread if this is the first dir entry. * Otherwise if a thread is started already, wait it until it is ahead of me. - * \retval 0 -- stat ahead thread process such dentry, miss for lookup - * \retval 1 -- stat ahead thread process such dentry, hit for any case + * \retval 0 -- stat ahead thread process such dentry, for lookup, it miss + * \retval 1 -- stat ahead thread process such dentry, for lookup, it hit * \retval -EEXIST -- stat ahead thread started, and this is the first dentry * \retval -EBADFD -- statahead thread exit and not dentry available * \retval -EAGAIN -- try to stat by caller @@ -1171,73 +1144,6 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp, int lookup) RETURN(rc); } - if (ll_sai_entry_stated(sai)) { - struct ll_sai_entry *entry; - - entry = cfs_list_entry(sai->sai_entries_stated.next, - struct ll_sai_entry, se_list); - /* This is for statahead lookup */ - if (entry->se_inode != NULL) { - struct lookup_intent it = {.it_op = IT_GETATTR}; - struct dentry *dchild = entry->se_dentry; - struct inode *ichild = entry->se_inode; - int found = 0; - __u32 bits; - - LASSERT(dchild != *dentryp); - - if (!lookup) - mutex_lock(&dir->i_mutex); - - rc = md_revalidate_lock(ll_i2mdexp(dir), &it, - ll_inode2fid(ichild), - &bits); - if (rc == 1) { - struct dentry *save = dchild; - - ll_lookup_it_alias(&dchild, ichild, - bits); - ll_lookup_finish_locks(&it, dchild); - if (dchild != save) - dput(save); - found = is_same_dentry(dchild, - *dentryp); - } else { - /* Someone has canceled related ldlm - * lock before the real "revalidate" - * using it. - * Drop the inode reference count held - * by interpreter. */ - iput(ichild); - } - - if (!lookup) - mutex_unlock(&dir->i_mutex); - - entry->se_dentry = NULL; - entry->se_inode = NULL; - if (found) { - if (lookup) { - LASSERT(dchild != *dentryp); - /* VFS will drop the reference - * count for dchild and *dentryp - * by itself. */ - *dentryp = dchild; - } else { - LASSERT(dchild == *dentryp); - /* Drop the dentry reference - * count held by statahead. */ - dput(dchild); - } - RETURN(1); - } else { - /* Drop the dentry reference count held - * by statahead. */ - dput(dchild); - } - } - } - if (lookup) { struct dentry *result; @@ -1314,10 +1220,10 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp, int lookup) RETURN(-EEXIST); out: - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); lli->lli_opendir_key = NULL; lli->lli_opendir_pid = 0; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); return rc; } @@ -1364,10 +1270,10 @@ void ll_statahead_exit(struct inode *dir, struct dentry *dentry, int result) PFID(&lli->lli_fid), sai->sai_hit, sai->sai_miss, sai->sai_sent, sai->sai_replied, cfs_curproc_pid()); - cfs_spin_lock(&lli->lli_lock); + cfs_spin_lock(&lli->lli_sa_lock); if (!sa_is_stopped(sai)) sai->sai_thread.t_flags = SVC_STOPPING; - cfs_spin_unlock(&lli->lli_lock); + cfs_spin_unlock(&lli->lli_sa_lock); } }