Whamcloud - gitweb
current branches now use lnet from HEAD
[fs/lustre-release.git] / lustre / obdclass / capa.c
index d235d01..3a5d75f 100644 (file)
@@ -61,11 +61,13 @@ static char *capa_type_name[] = { "client", "mds", "filter" };
  * in the future it will be moved to ll_sb_info to support multi-
  * mount point */
 struct timer_list ll_capa_timer;
+atomic_t ll_capa_stat = ATOMIC_INIT(0);
 
 EXPORT_SYMBOL(capa_lock);
 EXPORT_SYMBOL(capa_hash);
 EXPORT_SYMBOL(capa_list);
 EXPORT_SYMBOL(ll_capa_timer);
+EXPORT_SYMBOL(ll_capa_stat);
 
 static inline int const
 capa_hashfn(unsigned int uid, __u64 mdsid, unsigned long ino)
@@ -92,8 +94,6 @@ find_capa(struct hlist_head *head, uid_t uid, int capa_op, __u64 mdsid,
         struct obd_capa *ocapa;
         uid_t ouid;
 
-        CDEBUG(D_INODE, "find capa for (uid %u, op %d, mdsid "LPU64", ino %lu"
-               " igen %u, type %d\n", (unsigned) uid, capa_op, mdsid, ino, igen, type);
         hlist_for_each_entry(ocapa, pos, head, c_hash) {
                 if (ocapa->c_capa.lc_ino != ino)
                         continue;
@@ -123,6 +123,27 @@ find_capa(struct hlist_head *head, uid_t uid, int capa_op, __u64 mdsid,
         return NULL;
 }
 
+static struct obd_capa *
+filter_find_capa(struct hlist_head *head, struct lustre_capa *capa)
+{
+        struct hlist_node *pos;
+        struct obd_capa *ocapa;
+
+        hlist_for_each_entry(ocapa, pos, head, c_hash) {
+                if (ocapa->c_type != FILTER_CAPA)
+                        continue;
+
+                if (!memcmp(&ocapa->c_capa, capa,
+                            sizeof(struct lustre_capa_data))) {
+                        DEBUG_CAPA(D_INODE, &ocapa->c_capa, "found %s",
+                                   capa_type_name[ocapa->c_type]);
+                        return ocapa;
+                }
+        }
+
+        return NULL;
+}
+
 inline void __capa_get(struct obd_capa *ocapa)
 {
         if (ocapa->c_type != CLIENT_CAPA)
@@ -217,9 +238,11 @@ static inline void list_add_capa(struct obd_capa *ocapa, struct list_head *head)
                                 return;
                         }
                 }
+                list_add(&ocapa->c_list, head);
+                return;
         }
 
-        list_add(&ocapa->c_list, head);
+        list_add_tail(&ocapa->c_list, head);
 }
 
 static inline void do_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
@@ -241,7 +264,13 @@ get_new_capa_locked(struct hlist_head *head, int type, struct lustre_capa *capa)
                 return NULL;
 
         spin_lock(&capa_lock);
-        old = find_capa(head, uid, capa_op, mdsid, ino, capa->lc_igen, type);
+
+        if (type == FILTER_CAPA)
+                old = filter_find_capa(head, capa);
+        else
+                old = find_capa(head, uid, capa_op, mdsid, ino,
+                                capa->lc_igen, type);
+
         if (!old) {
                 do_update_capa(ocapa, capa);
                 ocapa->c_type = type;
@@ -295,17 +324,35 @@ capa_get(uid_t uid, int capa_op,__u64 mdsid, unsigned long ino,
 
         ocapa = find_capa_locked(head, uid, capa_op, mdsid, ino, igen, type);
         
+        if (type == CLIENT_CAPA && !ocapa && atomic_read(&ll_capa_stat)) {
+                CDEBUG(D_ERROR, "can't find capa for (uid %u, op %d, mdsid "
+                       LPU64", ino %lu igen %u, type %d)\n",
+                       (unsigned) uid, capa_op, mdsid, ino, igen, type);
+                atomic_set(&ll_capa_stat, 0);
+        }
+
         return ocapa;
 }
 
-void capa_put(struct obd_capa *ocapa)
+struct obd_capa * filter_capa_get(struct lustre_capa *capa)
 {
-        if (!ocapa)
-                return;
+        struct hlist_head *head = capa_hash +
+                capa_hashfn(capa->lc_uid, capa->lc_mdsid, capa->lc_ino);
+        struct obd_capa *ocapa;
 
+        spin_lock(&capa_lock);
+        ocapa = filter_find_capa(head, capa);
+        if (ocapa)
+                __capa_get(ocapa);
+        spin_unlock(&capa_lock);
+        return ocapa;
+}
+
+void capa_put_nolock(struct obd_capa *ocapa)
+{
         DEBUG_CAPA(D_INODE, &ocapa->c_capa, "put %s",
                    capa_type_name[ocapa->c_type]);
-        spin_lock(&capa_lock);
+
         if (ocapa->c_type == CLIENT_CAPA) {
                 list_del_init(&ocapa->c_lli_list);
                 __capa_put(ocapa);
@@ -313,6 +360,15 @@ void capa_put(struct obd_capa *ocapa)
         } else {
                 atomic_dec(&ocapa->c_refc);
         }
+}
+
+void capa_put(struct obd_capa *ocapa)
+{
+        if (!ocapa)
+                return;
+
+        spin_lock(&capa_lock);
+        capa_put_nolock(ocapa);
         spin_unlock(&capa_lock);
 }
 
@@ -327,20 +383,29 @@ struct obd_capa *capa_renew(struct lustre_capa *capa, int type)
         struct obd_capa *ocapa;
 
         spin_lock(&capa_lock);
-        ocapa = find_capa(head, uid, capa_op, mdsid, ino, capa->lc_igen, type);
+
+        if (type == FILTER_CAPA)
+                ocapa = filter_find_capa(head, capa);
+        else
+                ocapa = find_capa(head, uid, capa_op, mdsid, ino,
+                                  capa->lc_igen, type);
         if (ocapa) {
                 DEBUG_CAPA(D_INFO, capa, "renew %s", capa_type_name[type]);
                 do_update_capa(ocapa, capa);
         }
+
         spin_unlock(&capa_lock);
 
         if (!ocapa)
                 ocapa = get_new_capa_locked(head, type, capa);
 
+        if (type == CLIENT_CAPA)
+                atomic_set(&ll_capa_stat, 1);
+
         return ocapa;
 }
 
-void capa_hmac(struct crypto_tfm *_tfm, __u8 *key, struct lustre_capa *capa)
+void capa_hmac(__u8 *key, struct lustre_capa *capa)
 {
         struct crypto_tfm *tfm;
         int keylen = CAPA_KEY_LEN;
@@ -401,14 +466,27 @@ int capa_is_to_expire(struct obd_capa *ocapa)
         return rc;
 }
 
+void dump_capa_hmac(char *buf, char *key)
+{
+        int i, n = 0;
+
+        for (i = 0; i < CAPA_DIGEST_SIZE; i++)
+                n += sprintf(buf + n, "%02x", (unsigned char) key[i]);
+}
+
+
 EXPORT_SYMBOL(capa_op);
 EXPORT_SYMBOL(capa_get);
+EXPORT_SYMBOL(__capa_get);
+EXPORT_SYMBOL(filter_capa_get);
 EXPORT_SYMBOL(capa_put);
+EXPORT_SYMBOL(capa_put_nolock);
 EXPORT_SYMBOL(capa_renew);
-EXPORT_SYMBOL(__capa_get);
 EXPORT_SYMBOL(capa_hmac);
 EXPORT_SYMBOL(capa_dup);
 EXPORT_SYMBOL(capa_dup2);
 EXPORT_SYMBOL(capa_expired);
 EXPORT_SYMBOL(__capa_is_to_expire);
 EXPORT_SYMBOL(capa_is_to_expire);
+EXPORT_SYMBOL(dump_capa_hmac);
+