+
+/**
+ * lqs<->qctxt hash operations
+ */
+
+/**
+ * string hashing using djb2 hash algorithm
+ */
+static unsigned
+lqs_hash(lustre_hash_t *lh, void *key, unsigned mask)
+{
+ struct quota_adjust_qunit *lqs_key;
+ unsigned hash;
+ ENTRY;
+
+ LASSERT(key);
+ lqs_key = (struct quota_adjust_qunit *)key;
+ hash = (QAQ_IS_GRP(lqs_key) ? 5381 : 5387) * lqs_key->qaq_id;
+
+ RETURN(hash & mask);
+}
+
+static int
+lqs_compare(void *key, struct hlist_node *hnode)
+{
+ struct quota_adjust_qunit *lqs_key;
+ struct lustre_qunit_size *q;
+ int rc;
+ ENTRY;
+
+ LASSERT(key);
+ lqs_key = (struct quota_adjust_qunit *)key;
+ q = hlist_entry(hnode, struct lustre_qunit_size, lqs_hash);
+
+ spin_lock(&q->lqs_lock);
+ rc = ((lqs_key->qaq_id == q->lqs_id) &&
+ (QAQ_IS_GRP(lqs_key) == LQS_IS_GRP(q)));
+ spin_unlock(&q->lqs_lock);
+
+ RETURN(rc);
+}
+
+static void *
+lqs_get(struct hlist_node *hnode)
+{
+ struct lustre_qunit_size *q =
+ hlist_entry(hnode, struct lustre_qunit_size, lqs_hash);
+ ENTRY;
+
+ atomic_inc(&q->lqs_refcount);
+ CDEBUG(D_QUOTA, "lqs=%p refcount %d\n",
+ q, atomic_read(&q->lqs_refcount));
+
+ RETURN(q);
+}
+
+static void *
+lqs_put(struct hlist_node *hnode)
+{
+ struct lustre_qunit_size *q =
+ hlist_entry(hnode, struct lustre_qunit_size, lqs_hash);
+ ENTRY;
+
+ LASSERT(atomic_read(&q->lqs_refcount) > 0);
+ atomic_dec(&q->lqs_refcount);
+ CDEBUG(D_QUOTA, "lqs=%p refcount %d\n",
+ q, atomic_read(&q->lqs_refcount));
+
+ RETURN(q);
+}
+
+static void
+lqs_exit(struct hlist_node *hnode)
+{
+ struct lustre_qunit_size *q;
+ ENTRY;
+
+ q = hlist_entry(hnode, struct lustre_qunit_size, lqs_hash);
+ /*
+ * Nothing should be left. User of lqs put it and
+ * lqs also was deleted from table by this time
+ * so we should have 0 refs.
+ */
+ LASSERTF(atomic_read(&q->lqs_refcount) == 0,
+ "Busy lqs %p with %d refs\n", q,
+ atomic_read(&q->lqs_refcount));
+ OBD_FREE_PTR(q);
+ EXIT;
+}
+
+static lustre_hash_ops_t lqs_hash_ops = {
+ .lh_hash = lqs_hash,
+ .lh_compare = lqs_compare,
+ .lh_get = lqs_get,
+ .lh_put = lqs_put,
+ .lh_exit = lqs_exit
+};
+#endif /* HAVE_QUOTA_SUPPORT */