Whamcloud - gitweb
bonsai test; please ignore
[fs/lustre-release.git] / lustre / sec / upcall_cache.c
index 059fc61..9e500a0 100644 (file)
@@ -68,7 +68,7 @@ static void free_entry(struct upcall_cache_entry *entry)
         LASSERT(cache->free_entry);
         LASSERT(atomic_read(&entry->ue_refcount) == 0);
 
-        CDEBUG(D_OTHER, "destroy %s entry %p for key "LPU64"\n",
+        CDEBUG(D_SEC, "%s: destroy entry %p for key "LPU64"\n",
                cache->uc_name, entry, entry->ue_key);
 
         list_del(&entry->ue_hash);
@@ -100,14 +100,22 @@ static inline int refresh_entry(struct upcall_cache_entry *entry)
 
 static int check_unlink_entry(struct upcall_cache_entry *entry)
 {
+        /* upcall will be issued upon new entries immediately
+         * after they are created
+         */
+        LASSERT(!UC_CACHE_IS_NEW(entry));
+
         if (UC_CACHE_IS_VALID(entry) &&
             time_before(get_seconds(), entry->ue_expire))
                 return 0;
 
-        if (UC_CACHE_IS_ACQUIRING(entry) &&
-            time_after(get_seconds(), entry->ue_acquire_expire)) {
-                UC_CACHE_SET_EXPIRED(entry);
-                wake_up_all(&entry->ue_waitq);
+        if (UC_CACHE_IS_ACQUIRING(entry)) {
+                if (time_before(get_seconds(), entry->ue_acquire_expire))
+                        return 0;
+                else {
+                        UC_CACHE_SET_EXPIRED(entry);
+                        wake_up_all(&entry->ue_waitq);
+                }
         } else if (!UC_CACHE_IS_INVALID(entry)) {
                 UC_CACHE_SET_EXPIRED(entry);
         }
@@ -127,14 +135,14 @@ __get_entry(struct upcall_cache *cache, unsigned int hash, __u64 key,
 {
         struct list_head *head;
         struct upcall_cache_entry *entry, *next, *new = NULL;
-        int found = 0, rc;
+        int found, rc;
         ENTRY;
 
         LASSERT(hash < cache->uc_hashsize);
-
         head = &cache->uc_hashtable[hash];
 
 find_again:
+        found = 0;
         write_lock(&cache->uc_hashlock);
         list_for_each_entry_safe(entry, next, head, ue_hash) {
                 if (check_unlink_entry(entry))
@@ -179,6 +187,9 @@ find_again:
                 UC_CACHE_CLEAR_NEW(entry);
                 entry->ue_acquire_expire = get_seconds() +
                                            cache->uc_acquire_expire;
+                CWARN("%s: %p: cur %lu(%lu), cache ex %ld\n",
+                      cache->uc_name, entry, get_seconds(), jiffies,
+                      entry->ue_acquire_expire); //XXX
 
                 write_unlock(&cache->uc_hashlock);
                 rc = refresh_entry(entry);
@@ -199,6 +210,7 @@ find_again:
          * this item, just wait it complete
          */
         if (UC_CACHE_IS_ACQUIRING(entry)) {
+                signed long tmp1;
                 wait_queue_t wait;
 
                 init_waitqueue_entry(&wait, current);
@@ -206,7 +218,7 @@ find_again:
                 set_current_state(TASK_INTERRUPTIBLE);
                 write_unlock(&cache->uc_hashlock);
 
-                schedule_timeout(cache->uc_acquire_expire * HZ);
+                tmp1 = schedule_timeout(cache->uc_acquire_expire * HZ);
 
                 write_lock(&cache->uc_hashlock);
                 remove_wait_queue(&entry->ue_waitq, &wait);
@@ -214,12 +226,15 @@ find_again:
                         /* we're interrupted or upcall failed
                          * in the middle
                          */
-                        CERROR("entry %p not refreshed: cur %lu, key "LPU64", "
-                               "ref %d fl %u, ac %ld, ex %ld\n",
-                               entry, get_seconds(), entry->ue_key,
+                        CERROR("cur %lu(%ld), scheduled %ld, sigpending %d\n",
+                               get_seconds(), jiffies, tmp1,
+                               signal_pending(current)); //XXX
+                        CERROR("%s: entry %p not refreshed: key "LPU64", "
+                               "ref %d fl %u, cur %lu, ex %ld/%ld\n",
+                               cache->uc_name, entry, entry->ue_key,
                                atomic_read(&entry->ue_refcount),
-                               entry->ue_flags, entry->ue_acquire_expire,
-                               entry->ue_expire);
+                               entry->ue_flags, get_seconds(),
+                               entry->ue_acquire_expire, entry->ue_expire);
                         put_entry(entry);
                         write_unlock(&cache->uc_hashlock);
                         CERROR("Interrupted? Or check whether %s is in place\n",
@@ -255,7 +270,6 @@ find_again:
         }
         
         /* Now we know it's good */
-        LASSERT(UC_CACHE_IS_VALID(entry));
         write_unlock(&cache->uc_hashlock);
 
         RETURN(entry);
@@ -280,7 +294,8 @@ void upcall_cache_put_entry(struct upcall_cache_entry *entry)
 
         write_lock(&cache->uc_hashlock);
         LASSERTF(atomic_read(&entry->ue_refcount) > 0,
-                 "entry %p: ref %d\n", entry, atomic_read(&entry->ue_refcount));
+                 "%s: entry %p: ref %d\n", cache->uc_name, entry,
+                 atomic_read(&entry->ue_refcount));
         put_entry(entry);
         write_unlock(&cache->uc_hashlock);
 }
@@ -309,18 +324,41 @@ int upcall_cache_downcall(struct upcall_cache *cache, __u64 key, void *args)
         if (!found) {
                 /* haven't found, it's possible */
                 write_unlock(&cache->uc_hashlock);
-                CWARN("key "LPU64" entry dosen't found\n", key);
+                CWARN("%s: key "LPU64" entry dosen't found\n",
+                      cache->uc_name, key);
                 RETURN(-EINVAL);
         }
 
+        if (!UC_CACHE_IS_ACQUIRING(entry)) {
+                if (UC_CACHE_IS_VALID(entry)) {
+                        /* This should not happen, just give a warning
+                         * at this moment.
+                         */
+                        CWARN("%s: entry %p(key "LPU64", cur %lu, ex %ld/%ld) "
+                              "already valid\n", cache->uc_name,
+                              entry, entry->ue_key, get_seconds(),
+                              entry->ue_acquire_expire, entry->ue_expire);
+                        GOTO(out, rc = 0);
+                }
+
+                CWARN("%s: stale entry %p: key "LPU64", ref %d, fl %u, "
+                      "cur %lu, ex %ld/%ld\n",
+                      cache->uc_name, entry, entry->ue_key,
+                      atomic_read(&entry->ue_refcount),
+                      entry->ue_flags, get_seconds(),
+                      entry->ue_acquire_expire, entry->ue_expire);
+                GOTO(out, rc = -EINVAL);
+        }
+
         if (!UC_CACHE_IS_ACQUIRING(entry) ||
             UC_CACHE_IS_INVALID(entry) ||
             UC_CACHE_IS_EXPIRED(entry)) {
-                CWARN("stale entry %p: cur %lu, key "LPU64", ref %d, "
-                      "fl %u, ac %ld, ex %ld\n",
-                       entry, get_seconds(), entry->ue_key,
-                       atomic_read(&entry->ue_refcount), entry->ue_flags,
-                       entry->ue_acquire_expire, entry->ue_expire);
+                CWARN("%s: invalid entry %p: key "LPU64", ref %d, fl %u, "
+                      "cur %lu, ex %ld/%ld\n",
+                      cache->uc_name, entry, entry->ue_key,
+                      atomic_read(&entry->ue_refcount),
+                      entry->ue_flags, get_seconds(), 
+                      entry->ue_acquire_expire, entry->ue_expire);
                 GOTO(out, rc = -EINVAL);
         }
 
@@ -341,8 +379,8 @@ int upcall_cache_downcall(struct upcall_cache *cache, __u64 key, void *args)
         }
 
         UC_CACHE_SET_VALID(entry);
-        CDEBUG(D_OTHER, "create ucache entry %p(key "LPU64")\n",
-               entry, entry->ue_key);
+        CDEBUG(D_SEC, "%s: create ucache entry %p(key "LPU64")\n",
+               cache->uc_name, entry, entry->ue_key);
 out:
         wake_up_all(&entry->ue_waitq);
         write_unlock(&cache->uc_hashlock);
@@ -360,7 +398,6 @@ void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key)
 
         hash = cache->hash(cache, key);
         LASSERT(hash < cache->uc_hashsize);
-
         head = &cache->uc_hashtable[hash];
 
         write_lock(&cache->uc_hashlock);
@@ -372,6 +409,12 @@ void upcall_cache_flush_one(struct upcall_cache *cache, __u64 key)
         }
 
         if (found) {
+                CWARN("%s: flush entry %p: key "LPU64", ref %d, fl %x, "
+                      "cur %lu, ex %ld/%ld\n",
+                      cache->uc_name, entry, entry->ue_key,
+                      atomic_read(&entry->ue_refcount), entry->ue_flags,
+                      get_seconds(), entry->ue_acquire_expire,
+                      entry->ue_expire);
                 UC_CACHE_SET_EXPIRED(entry);
                 if (!atomic_read(&entry->ue_refcount))
                         free_entry(entry);