FS-Cache: Debug object lifetime
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index 7a9d574..b1f0634 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -103,6 +103,7 @@
kfree(buffer);
nomem_buffer:
BUG_ON(test_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags));
+ fscache_object_destroy(&object->fscache);
kmem_cache_free(cachefiles_object_jar, object);
fscache_object_destroyed(&cache->cache);
nomem_object:
diff --git a/fs/fscache/cache.c b/fs/fscache/cache.c
index b52aed1..98bca68 100644
--- a/fs/fscache/cache.c
+++ b/fs/fscache/cache.c
@@ -263,7 +263,6 @@
spin_lock(&cache->object_list_lock);
list_add_tail(&ifsdef->cache_link, &cache->object_list);
spin_unlock(&cache->object_list_lock);
- fscache_objlist_add(ifsdef);
/* add the cache's netfs definition index object to the top level index
* cookie as a known backing object */
diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index 8dcb114..47d8cde 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -360,7 +360,6 @@
atomic_inc(&cookie->usage);
hlist_add_head(&object->cookie_link, &cookie->backing_objects);
- fscache_objlist_add(object);
ret = 0;
cant_attach_object:
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index f27c89d..f8fbb32 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -69,6 +69,7 @@
write_unlock(&fscache_object_list_lock);
}
+EXPORT_SYMBOL(fscache_objlist_add);
/**
* fscache_object_destroy - Note that a cache object is about to be destroyed
diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
index 0c772ad..2d355e9 100644
--- a/include/linux/fscache-cache.h
+++ b/include/linux/fscache-cache.h
@@ -440,6 +440,14 @@
extern void fscache_object_work_func(struct work_struct *work);
+#ifdef CONFIG_FSCACHE_OBJECT_LIST
+extern void fscache_objlist_add(struct fscache_object *obj);
+extern void fscache_object_destroy(struct fscache_object *object);
+#else
+#define fscache_object_destroy(object) do {} while(0)
+#define fscache_objlist_add(object) do {} while(0)
+#endif
+
/**
* fscache_object_init - Initialise a cache object description
* @object: Object description
@@ -454,8 +462,6 @@
struct fscache_cookie *cookie,
struct fscache_cache *cache)
{
- atomic_inc(&cache->object_count);
-
object->state = FSCACHE_OBJECT_INIT;
spin_lock_init(&object->lock);
INIT_LIST_HEAD(&object->cache_link);
@@ -473,17 +479,14 @@
object->cache = cache;
object->cookie = cookie;
object->parent = NULL;
+
+ atomic_inc(&cache->object_count);
+ fscache_objlist_add(object);
}
extern void fscache_object_lookup_negative(struct fscache_object *object);
extern void fscache_obtained_object(struct fscache_object *object);
-#ifdef CONFIG_FSCACHE_OBJECT_LIST
-extern void fscache_object_destroy(struct fscache_object *object);
-#else
-#define fscache_object_destroy(object) do {} while(0)
-#endif
-
/**
* fscache_object_destroyed - Note destruction of an object in a cache
* @cache: The cache from which the object came