struct ptlrpc_request *req = NULL;
struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
struct obd_export *exp;
+ struct inode *parent = de->d_parent->d_inode;
int first = 0, rc;
ENTRY;
RETURN(0);
#endif
- rc = ll_have_md_lock(de->d_parent->d_inode,
- MDS_INODELOCK_UPDATE);
+ rc = ll_have_md_lock(parent, MDS_INODELOCK_UPDATE);
GOTO(out_sa, rc);
}
ll_frob_intent(&it, &lookup_it);
LASSERT(it);
- ll_prepare_mdc_op_data(&op_data, de->d_parent->d_inode, de->d_inode,
+ ll_prepare_mdc_op_data(&op_data, parent, de->d_inode,
de->d_name.name, de->d_name.len, 0, NULL);
if ((it->it_op == IT_OPEN) && de->d_inode) {
}
if (it->it_op == IT_GETATTR)
- first = ll_statahead_enter(de->d_parent->d_inode, &de, 0);
+ first = ll_statahead_enter(parent, &de, 0);
do_lock:
it->it_create_mode &= ~current->fs->umask;
/* If there are too many locks on client-side, then some
* locks taken by statahead maybe dropped automatically
* before the real "revalidate" using them. */
- ll_statahead_exit(de, req == NULL ? rc : 0);
+ ll_statahead_exit(parent, de, req == NULL ? rc : 0);
else if (first == -EEXIST)
- ll_statahead_mark(de);
+ ll_statahead_mark(parent, de);
/* If req is NULL, then mdc_intent_lock only tried to do a lock match;
* if all was well, it will return 1 if it found locks, 0 otherwise. */
it = &lookup_it;
}
/*do real lookup here */
- ll_prepare_mdc_op_data(&op_data, de->d_parent->d_inode, NULL,
+ ll_prepare_mdc_op_data(&op_data, parent, NULL,
de->d_name.name, de->d_name.len, 0, NULL);
rc = mdc_intent_lock(exp, &op_data, NULL, 0, it, 0, &req,
ll_mdc_blocking_ast, 0);
* statahead windows; for rc == 0 case, the "lookup" will be done later.
*/
if (it && it->it_op == IT_GETATTR && rc == 1) {
- first = ll_statahead_enter(de->d_parent->d_inode, &de, 0);
+ first = ll_statahead_enter(parent, &de, 0);
if (!first)
- ll_statahead_exit(de, 1);
+ ll_statahead_exit(parent, de, 1);
else if (first == -EEXIST)
- ll_statahead_mark(de);
+ ll_statahead_mark(parent, de);
}
return rc;
*/
static inline int sa_low_hit(struct ll_statahead_info *sai)
{
- return ((sai->sai_hit < 4 * sai->sai_miss && sai->sai_hit > 7) ||
+ return ((sai->sai_hit > 7 && sai->sai_hit < 4 * sai->sai_miss) ||
(sai->sai_consecutive_miss > 8));
}
*/
static void ll_sai_entry_cleanup(struct ll_sai_entry *entry, int free)
{
- struct ptlrpc_request *req = entry->se_req;
struct md_enqueue_info *minfo = entry->se_minfo;
+ struct ptlrpc_request *req = entry->se_req;
ENTRY;
if (minfo) {
- struct dentry *dentry = minfo->mi_dentry;
- struct lookup_intent *it = &minfo->mi_it;
-
entry->se_minfo = NULL;
- ll_intent_release(it);
+ ll_intent_release(&minfo->mi_it);
+ dput(minfo->mi_dentry);
+ iput(minfo->mi_dir);
OBD_FREE_PTR(minfo);
- dput(dentry);
}
if (req) {
entry->se_req = NULL;
LASSERT(inode != NULL);
lli = ll_i2info(inode);
- if (atomic_dec_and_lock(&sai->sai_refcount, &lli->lli_lock)) {
+ LASSERT(lli->lli_sai == sai);
+
+ if (atomic_dec_and_test(&sai->sai_refcount)) {
struct ll_sai_entry *entry, *next;
+ spin_lock(&lli->lli_lock);
+ if (unlikely(atomic_read(&sai->sai_refcount) > 0)) {
+ /* It is race case, the interpret callback just hold
+ * a reference count */
+ spin_unlock(&lli->lli_lock);
+ EXIT;
+ return;
+ }
+
LASSERT(lli->lli_opendir_key == NULL);
lli->lli_sai = NULL;
lli->lli_opendir_pid = 0;
list_del_init(&entry->se_list);
ll_sai_entry_cleanup(entry, 1);
}
- OBD_FREE_PTR(sai);
iput(inode);
+ OBD_FREE_PTR(sai);
}
EXIT;
}
struct ll_sai_entry *entry;
struct ptlrpc_request *req;
struct md_enqueue_info *minfo;
- struct dentry *dentry;
struct lookup_intent *it;
+ struct dentry *dentry;
int rc = 0;
ENTRY;
spin_unlock(&lli->lli_lock);
if (unlikely(entry->se_index < sai->sai_index_next)) {
+ CWARN("Found stale entry: [index %u] [next %u]\n",
+ entry->se_index, sai->sai_index_next);
ll_sai_entry_cleanup(entry, 1);
RETURN(0);
}
req = entry->se_req;
minfo = entry->se_minfo;
- dentry = minfo->mi_dentry;
it = &minfo->mi_it;
+ dentry = minfo->mi_dentry;
if (dentry->d_inode == NULL) {
/*
*/
struct dentry *save = dentry;
struct it_cb_data icbd = {
- .icbd_parent = dentry->d_parent->d_inode,
+ .icbd_parent = minfo->mi_dir,
.icbd_childp = &dentry
};
struct md_enqueue_info *minfo,
int rc)
{
- struct dentry *dentry = minfo->mi_dentry;
struct lookup_intent *it = &minfo->mi_it;
- struct inode *dir = dentry->d_parent->d_inode;
+ struct dentry *dentry = minfo->mi_dentry;
+ struct inode *dir = minfo->mi_dir;
struct ll_inode_info *lli = ll_i2info(dir);
struct ll_statahead_info *sai;
struct ll_sai_entry *entry;
spin_unlock(&lli->lli_lock);
ll_intent_release(it);
dput(dentry);
+ iput(dir);
OBD_FREE_PTR(minfo);
RETURN(-ESTALE);
} else {
sai = ll_sai_get(lli->lli_sai);
- if (rc || dir == NULL)
- rc = -ESTALE;
-
entry = ll_sai_entry_set(sai,
(unsigned int)(long)minfo->mi_cbdata,
rc ? SA_ENTRY_UNSTATED :
struct ldlm_enqueue_info *einfo)
{
LASSERT(minfo && einfo);
+ iput(minfo->mi_dir);
OBD_FREE_PTR(minfo);
OBD_FREE_PTR(einfo);
}
minfo->mi_it.it_op = IT_GETATTR;
minfo->mi_dentry = dentry;
+ minfo->mi_dir = igrab(dir);
minfo->mi_cb = ll_statahead_interpret;
minfo->mi_generation = lli->lli_sai->sai_generation;
minfo->mi_cbdata = (void *)(long)lli->lli_sai->sai_index;
* \retval 0 -- will send stat-ahead request
* \retval others -- prepare stat-ahead request failed
*/
-static int do_sa_revalidate(struct dentry *dentry)
+static int do_sa_revalidate(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
- struct inode *dir = dentry->d_parent->d_inode;
struct ll_fid fid;
struct lookup_intent it = { .it_op = IT_GETATTR };
struct md_enqueue_info *minfo;
if (rc)
RETURN(rc);
- rc = ll_prepare_mdc_op_data(&minfo->mi_data, dentry->d_parent->d_inode,
+ rc = ll_prepare_mdc_op_data(&minfo->mi_data, dir,
inode, dentry->d_name.name,
dentry->d_name.len, 0, NULL);
if (rc == 0)
GOTO(out, rc = -ENOMEM);
}
} else {
- rc = do_sa_revalidate(dentry);
+ rc = do_sa_revalidate(dir, dentry);
if (rc)
dput(dentry);
}
return rc;
}
-struct ll_sa_thread_args {
- struct dentry *sta_parent;
- pid_t sta_pid;
-};
-
static int ll_statahead_thread(void *arg)
{
- struct ll_sa_thread_args *sta = arg;
- struct dentry *parent = dget(sta->sta_parent);
+ struct dentry *parent = (struct dentry *)arg;
struct inode *dir = parent->d_inode;
struct ll_inode_info *lli = ll_i2info(dir);
struct ll_sb_info *sbi = ll_i2sbi(dir);
- struct ll_statahead_info *sai;
- struct ptlrpc_thread *thread;
+ struct ll_statahead_info *sai = ll_sai_get(lli->lli_sai);
+ struct ptlrpc_thread *thread = &sai->sai_thread;
unsigned long index = 0;
int first = 0;
int rc = 0;
ENTRY;
- spin_lock(&lli->lli_lock);
- if (unlikely(lli->lli_sai == NULL)) {
- spin_unlock(&lli->lli_lock);
- dput(parent);
- RETURN(-EAGAIN);
- } else {
- sai = ll_sai_get(lli->lli_sai);
- spin_unlock(&lli->lli_lock);
- }
-
{
char pname[16];
- snprintf(pname, 15, "ll_sa_%u", sta->sta_pid);
+ snprintf(pname, 15, "ll_sa_%u", lli->lli_opendir_pid);
cfs_daemonize(pname);
}
- thread = &sai->sai_thread;
sbi->ll_sa_total++;
spin_lock(&lli->lli_lock);
thread->t_flags = SVC_RUNNING;
*/
int do_statahead_enter(struct inode *dir, struct dentry **dentryp, int lookup)
{
- struct ll_sb_info *sbi = ll_i2sbi(dir);
- struct ll_inode_info *lli = ll_i2info(dir);
- struct ll_statahead_info *sai = lli->lli_sai;
- struct ll_sa_thread_args sta;
+ struct ll_inode_info *lli;
+ struct ll_statahead_info *sai;
+ struct dentry *parent;
struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
int rc = 0;
ENTRY;
+ LASSERT(dir != NULL);
+ lli = ll_i2info(dir);
LASSERT(lli->lli_opendir_pid == cfs_curproc_pid());
+ sai = lli->lli_sai;
if (sai) {
+ struct ll_sb_info *sbi;
+
if (unlikely(sa_is_stopped(sai) &&
list_empty(&sai->sai_entries_stated)))
RETURN(-EBADFD);
}
}
+ sbi = ll_i2sbi(dir);
if (ll_sai_entry_stated(sai)) {
sbi->ll_sa_cached++;
} else {
RETURN(rc);
}
- /*
- * I am the "lli_opendir_pid" owner, only me can set "lli_sai".
- */
- LASSERT(lli->lli_sai == NULL);
-
+ /* I am the "lli_opendir_pid" owner, only me can set "lli_sai". */
rc = is_first_dirent(dir, *dentryp);
- if (rc == LS_NONE_FIRST_DE) {
- /*
- * It is not "ls -{a}l" operation, no need statahead for it.
- */
- spin_lock(&lli->lli_lock);
- lli->lli_opendir_key = NULL;
- lli->lli_opendir_pid = 0;
- spin_unlock(&lli->lli_lock);
- RETURN(-EBADF);
- }
+ if (rc == LS_NONE_FIRST_DE)
+ /* It is not "ls -{a}l" operation, no need statahead for it. */
+ GOTO(out, rc = -EAGAIN);
sai = ll_sai_alloc();
if (sai == NULL)
- RETURN(-ENOMEM);
+ GOTO(out, rc = -ENOMEM);
sai->sai_ls_all = (rc == LS_FIRST_DOT_DE);
sai->sai_inode = igrab(dir);
CWARN("Do not start stat ahead on dying inode %lu/%u.\n",
dir->i_ino, dir->i_generation);
OBD_FREE_PTR(sai);
- RETURN(-ESTALE);
+ GOTO(out, rc = -ESTALE);
}
- LASSERT(sai->sai_inode == (*dentryp)->d_parent->d_inode);
+ /* get parent reference count here, and put it in ll_statahead_thread */
+ parent = dget((*dentryp)->d_parent);
+ if (unlikely(sai->sai_inode != parent->d_inode)) {
+ struct ll_inode_info *nlli = ll_i2info(parent->d_inode);
- sta.sta_parent = (*dentryp)->d_parent;
- sta.sta_pid = cfs_curproc_pid();
+ CWARN("Race condition, someone changed %.*s just now: "
+ "old parent "DFID", new parent "DFID" .\n",
+ (*dentryp)->d_name.len, (*dentryp)->d_name.name,
+ PFID(&lli->lli_fid), PFID(&nlli->lli_fid));
+ dput(parent);
+ iput(sai->sai_inode);
+ OBD_FREE_PTR(sai);
+ RETURN(-EAGAIN);
+ }
lli->lli_sai = sai;
- rc = cfs_kernel_thread(ll_statahead_thread, &sta, 0);
+ rc = cfs_kernel_thread(ll_statahead_thread, parent, 0);
if (rc < 0) {
CERROR("can't start ll_sa thread, rc: %d\n", rc);
+ dput(parent);
lli->lli_opendir_key = NULL;
sai->sai_thread.t_flags = SVC_STOPPED;
ll_sai_put(sai);
* lookup, and -EEXIST also indicates that this is the first dirent.
*/
RETURN(-EEXIST);
+
+out:
+ spin_lock(&lli->lli_lock);
+ lli->lli_opendir_key = NULL;
+ lli->lli_opendir_pid = 0;
+ spin_unlock(&lli->lli_lock);
+ return rc;
}
/**
* update hit/miss count.
*/
-void ll_statahead_exit(struct dentry *dentry, int result)
+void ll_statahead_exit(struct inode *dir, struct dentry *dentry, int result)
{
- struct dentry *parent = dentry->d_parent;
- struct ll_inode_info *lli = ll_i2info(parent->d_inode);
- struct ll_sb_info *sbi = ll_i2sbi(parent->d_inode);
- struct ll_statahead_info *sai = lli->lli_sai;
+ struct ll_inode_info *lli;
+ struct ll_statahead_info *sai;
+ struct ll_sb_info *sbi;
struct ll_dentry_data *ldd = ll_d2d(dentry);
ENTRY;
- if (lli->lli_opendir_pid == cfs_curproc_pid() && sai) {
- if (result >= 1) {
- sbi->ll_sa_hit++;
- sai->sai_hit++;
- sai->sai_consecutive_miss = 0;
- sai->sai_max = min(2 * sai->sai_max, sbi->ll_sa_max);
- } else {
- sbi->ll_sa_miss++;
- sai->sai_miss++;
- sai->sai_consecutive_miss++;
- if (sa_low_hit(sai) && sa_is_running(sai)) {
- sbi->ll_sa_wrong++;
- CDEBUG(D_READA, "statahead for dir %.*s hit "
- "ratio too low: hit/miss %u/%u, "
- "sent/replied %u/%u. stopping statahead "
- "thread: pid %d\n",
- parent->d_name.len, parent->d_name.name,
- sai->sai_hit, sai->sai_miss,
- sai->sai_sent, sai->sai_replied,
- cfs_curproc_pid());
- spin_lock(&lli->lli_lock);
- if (!sa_is_stopped(sai))
- sai->sai_thread.t_flags = SVC_STOPPING;
- spin_unlock(&lli->lli_lock);
- }
+ LASSERT(dir != NULL);
+ lli = ll_i2info(dir);
+ LASSERT(lli->lli_opendir_pid == cfs_curproc_pid());
+ sai = lli->lli_sai;
+ LASSERT(sai != NULL);
+ sbi = ll_i2sbi(dir);
+
+ if (result >= 1) {
+ sbi->ll_sa_hit++;
+ sai->sai_hit++;
+ sai->sai_consecutive_miss = 0;
+ sai->sai_max = min(2 * sai->sai_max, sbi->ll_sa_max);
+ } else {
+ sbi->ll_sa_miss++;
+ sai->sai_miss++;
+ sai->sai_consecutive_miss++;
+ if (sa_low_hit(sai) && sa_is_running(sai)) {
+ sbi->ll_sa_wrong++;
+ CDEBUG(D_READA, "Statahead for dir "DFID" hit ratio "
+ "too low: hit/miss %u/%u, sent/replied %u/%u, "
+ "stopping statahead thread: pid %d\n",
+ PFID(&lli->lli_fid), sai->sai_hit,
+ sai->sai_miss, sai->sai_sent,
+ sai->sai_replied, cfs_curproc_pid());
+ spin_lock(&lli->lli_lock);
+ if (!sa_is_stopped(sai))
+ sai->sai_thread.t_flags = SVC_STOPPING;
+ spin_unlock(&lli->lli_lock);
}
-
- if (!sa_is_stopped(sai))
- cfs_waitq_signal(&sai->sai_thread.t_ctl_waitq);
- ll_sai_entry_fini(sai);
- if (likely(ldd != NULL))
- ldd->lld_sa_generation = sai->sai_generation;
}
+
+ if (!sa_is_stopped(sai))
+ cfs_waitq_signal(&sai->sai_thread.t_ctl_waitq);
+ ll_sai_entry_fini(sai);
+ if (likely(ldd != NULL))
+ ldd->lld_sa_generation = sai->sai_generation;
+
EXIT;
}