Whamcloud - gitweb
- add resource and lock counters to the namespace
authorpschwan <pschwan>
Mon, 16 Sep 2002 18:13:03 +0000 (18:13 +0000)
committerpschwan <pschwan>
Mon, 16 Sep 2002 18:13:03 +0000 (18:13 +0000)
- add them to the namespace proc directories (which are, tragically, in the
  top level of the /proc tree until lprocfs gets sorted out)
- fix a dangling resource refcount bug in ldlm_cli_cancel_unused

lustre/include/linux/lustre_dlm.h
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_request.c
lustre/ldlm/ldlm_resource.c

index 86f339d..7404dda 100644 (file)
@@ -92,6 +92,10 @@ struct ldlm_namespace {
         struct lustre_lock     ns_lock; /* protects hash, refcount, list */
         struct list_head       ns_list_chain; /* position in global NS list */
         struct proc_dir_entry *ns_proc_dir;
+
+        spinlock_t             ns_counter_lock;
+        __u64                  ns_locks;
+        __u64                  ns_resources;
 };
 
 /* 
index c1a05d1..02cf2a2 100644 (file)
@@ -136,10 +136,10 @@ struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock)
 
 void ldlm_lock_put(struct ldlm_lock *lock)
 {
-        struct lustre_lock *nslock = &lock->l_resource->lr_namespace->ns_lock;
+        struct ldlm_namespace *ns = lock->l_resource->lr_namespace;
         ENTRY;
 
-        l_lock(nslock);
+        l_lock(&ns->ns_lock);
         lock->l_refc--;
         //LDLM_DEBUG(lock, "after refc--");
         if (lock->l_refc < 0)
@@ -150,6 +150,10 @@ void ldlm_lock_put(struct ldlm_lock *lock)
                 LDLM_LOCK_PUT(lock->l_parent);
 
         if (lock->l_refc == 0 && (lock->l_flags & LDLM_FL_DESTROYED)) {
+                spin_lock(&ns->ns_counter_lock);
+                ns->ns_locks--;
+                spin_unlock(&ns->ns_counter_lock);
+
                 lock->l_resource = NULL;
                 LDLM_DEBUG(lock, "final lock_put on destroyed lock, freeing");
                 if (lock->l_export && lock->l_export->exp_connection)
@@ -158,7 +162,7 @@ void ldlm_lock_put(struct ldlm_lock *lock)
                 CDEBUG(D_MALLOC, "kfreed 'lock': %d at %p (tot 0).\n",
                        sizeof(*lock), lock);
         }
-        l_unlock(nslock);
+        l_unlock(&ns->ns_lock);
         EXIT;
 }
 
@@ -233,6 +237,10 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_lock *parent,
         INIT_LIST_HEAD(&lock->l_pending_chain);
         init_waitqueue_head(&lock->l_waitq);
 
+        spin_lock(&resource->lr_namespace->ns_counter_lock);
+        resource->lr_namespace->ns_locks++;
+        spin_unlock(&resource->lr_namespace->ns_counter_lock);
+
         if (parent != NULL) {
                 l_lock(&parent->l_resource->lr_namespace->ns_lock);
                 lock->l_parent = parent;
index de84253..d7cb958 100644 (file)
@@ -673,6 +673,7 @@ EXPORT_SYMBOL(ldlm_lock_change_resource);
 EXPORT_SYMBOL(ldlm_cli_convert);
 EXPORT_SYMBOL(ldlm_cli_enqueue);
 EXPORT_SYMBOL(ldlm_cli_cancel);
+EXPORT_SYMBOL(ldlm_cli_cancel_unused);
 EXPORT_SYMBOL(ldlm_match_or_enqueue);
 EXPORT_SYMBOL(ldlm_it2str);
 EXPORT_SYMBOL(ldlm_test);
index 400da08..e273834 100644 (file)
@@ -450,5 +450,7 @@ int ldlm_cli_cancel_unused(struct ldlm_namespace *ns, __u64 *res_id)
                 OBD_FREE(w, sizeof(*w));
         }
 
+        ldlm_resource_put(res);
+
         RETURN(0);
 }
index ac53d84..3bf0c84 100644 (file)
@@ -40,10 +40,23 @@ void ldlm_proc_cleanup(struct obd_device *obd)
         proc_lustre_remove_obd_entry("namespaces", obd);
 }
 
+/* FIXME: This can go away when we start to really use lprocfs */
+static int lprocfs_ll_rd(char *page, char **start, off_t off,
+                         int count, int *eof, void *data)
+{
+        int len;
+        __u64 *temp = (__u64 *)data;
+
+        len = snprintf(page, count, "%Lu\n", *temp);
+
+        return len;
+}
+
 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
 {
         struct ldlm_namespace *ns = NULL;
         struct list_head *bucket;
+        struct proc_dir_entry *proc_entry;
 
         OBD_ALLOC(ns, sizeof(*ns));
         if (!ns) {
@@ -69,6 +82,9 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
         l_lock_init(&ns->ns_lock);
         ns->ns_refcount = 0;
         ns->ns_client = client;
+        spin_lock_init(&ns->ns_counter_lock);
+        ns->ns_locks = 0;
+        ns->ns_resources = 0;
 
         for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
              bucket--)
@@ -76,10 +92,17 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
 
         spin_lock(&ldlm_namespace_lock);
         list_add(&ns->ns_list_chain, &ldlm_namespace_list);
+        spin_unlock(&ldlm_namespace_lock);
+
         ns->ns_proc_dir = proc_mkdir(ns->ns_name, ldlm_ns_proc_dir);
         if (ns->ns_proc_dir == NULL)
                 CERROR("Unable to create proc directory for namespace.\n");
-        spin_unlock(&ldlm_namespace_lock);
+        proc_entry = create_proc_entry("resource_count", 0444, ns->ns_proc_dir);
+        proc_entry->read_proc = lprocfs_ll_rd;
+        proc_entry->data = &ns->ns_resources;
+        proc_entry = create_proc_entry("lock_count", 0444, ns->ns_proc_dir);
+        proc_entry->read_proc = lprocfs_ll_rd;
+        proc_entry->data = &ns->ns_locks;
 
         RETURN(ns);
 
@@ -140,6 +163,8 @@ int ldlm_namespace_free(struct ldlm_namespace *ns)
 
         spin_lock(&ldlm_namespace_lock);
         list_del(&ns->ns_list_chain);
+        remove_proc_entry("resource_count", ns->ns_proc_dir);
+        remove_proc_entry("lock_count", ns->ns_proc_dir);
         remove_proc_entry(ns->ns_name, ldlm_ns_proc_dir);
         spin_unlock(&ldlm_namespace_lock);
 
@@ -237,6 +262,10 @@ static struct ldlm_resource *ldlm_resource_add(struct ldlm_namespace *ns,
                 RETURN(NULL);
         }
 
+        spin_lock(&ns->ns_counter_lock);
+        ns->ns_resources++;
+        spin_unlock(&ns->ns_counter_lock);
+
         memcpy(res->lr_name, name, sizeof(res->lr_name));
         res->lr_namespace = ns;
         ns->ns_refcount++;
@@ -337,6 +366,11 @@ int ldlm_resource_put(struct ldlm_resource *res)
 
                 kmem_cache_free(ldlm_resource_slab, res);
                 l_unlock(&ns->ns_lock);
+
+                spin_lock(&ns->ns_counter_lock);
+                ns->ns_resources--;
+                spin_unlock(&ns->ns_counter_lock);
+
                 rc = 1;
         } else {
                 ENTRY;