+static inline void
+do_sai_entry_fini(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
+{
+ struct ll_inode_info *lli = ll_i2info(sai->sai_inode);
+
+ ll_sa_entry_unhash(sai, entry);
+
+ spin_lock(&lli->lli_sa_lock);
+ entry->se_stat = SA_ENTRY_DEST;
+ if (likely(!ll_sa_entry_unlinked(entry)))
+ cfs_list_del_init(&entry->se_list);
+ spin_unlock(&lli->lli_sa_lock);
+
+ ll_sa_entry_put(sai, entry);
+}
+
+/*
+ * Delete it from sai_entries_stated list when fini.
+ */
+static void
+ll_sa_entry_fini(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
+{
+ struct ll_sa_entry *pos, *next;
+
+ if (entry)
+ do_sai_entry_fini(sai, entry);
+
+ /* drop old entry from sent list */
+ cfs_list_for_each_entry_safe(pos, next, &sai->sai_entries_sent,
+ se_list) {
+ if (is_omitted_entry(sai, pos->se_index))
+ do_sai_entry_fini(sai, pos);
+ else
+ break;
+ }
+
+ /* drop old entry from stated list */
+ cfs_list_for_each_entry_safe(pos, next, &sai->sai_entries_stated,
+ se_list) {
+ if (is_omitted_entry(sai, pos->se_index))
+ do_sai_entry_fini(sai, pos);
+ else
+ break;
+ }
+}
+
+/*
+ * Inside lli_sa_lock.
+ */
+static void
+do_sai_entry_to_stated(struct ll_statahead_info *sai,
+ struct ll_sa_entry *entry, int rc)
+{
+ struct ll_sa_entry *se;
+ cfs_list_t *pos = &sai->sai_entries_stated;
+
+ if (!ll_sa_entry_unlinked(entry))
+ cfs_list_del_init(&entry->se_list);
+
+ cfs_list_for_each_entry_reverse(se, &sai->sai_entries_stated, se_list) {
+ if (se->se_index < entry->se_index) {
+ pos = &se->se_list;
+ break;
+ }
+ }
+
+ cfs_list_add(&entry->se_list, pos);
+ entry->se_stat = rc;
+}
+
+/*
+ * Move entry to sai_entries_stated and sort with the index.
+ * \retval 1 -- entry to be destroyed.
+ * \retval 0 -- entry is inserted into stated list.
+ */
+static int
+ll_sa_entry_to_stated(struct ll_statahead_info *sai,
+ struct ll_sa_entry *entry, int rc)
+{
+ struct ll_inode_info *lli = ll_i2info(sai->sai_inode);
+ int ret = 1;
+
+ ll_sa_entry_cleanup(sai, entry);
+
+ spin_lock(&lli->lli_sa_lock);
+ if (likely(entry->se_stat != SA_ENTRY_DEST)) {
+ do_sai_entry_to_stated(sai, entry, rc);
+ ret = 0;
+ }
+ spin_unlock(&lli->lli_sa_lock);
+
+ return ret;
+}
+
+/*
+ * Insert inode into the list of sai_entries_agl.
+ */
+static void ll_agl_add(struct ll_statahead_info *sai,
+ struct inode *inode, int index)
+{
+ struct ll_inode_info *child = ll_i2info(inode);
+ struct ll_inode_info *parent = ll_i2info(sai->sai_inode);
+ int added = 0;
+
+ spin_lock(&child->lli_agl_lock);
+ if (child->lli_agl_index == 0) {
+ child->lli_agl_index = index;
+ spin_unlock(&child->lli_agl_lock);
+
+ LASSERT(cfs_list_empty(&child->lli_agl_list));
+
+ igrab(inode);
+ spin_lock(&parent->lli_agl_lock);
+ if (agl_list_empty(sai))
+ added = 1;
+ cfs_list_add_tail(&child->lli_agl_list, &sai->sai_entries_agl);
+ spin_unlock(&parent->lli_agl_lock);
+ } else {
+ spin_unlock(&child->lli_agl_lock);
+ }
+
+ if (added > 0)
+ cfs_waitq_signal(&sai->sai_agl_thread.t_ctl_waitq);