aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fscache
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2009-04-03 11:42:38 -0400
committerDavid Howells <dhowells@redhat.com>2009-04-03 11:42:38 -0400
commit955d00917f0c094e0f2fb88df967e980ab66b8ca (patch)
treec6109684239fd45462e494fb4f26aa8e2e651922 /fs/fscache
parent4c515dd47ab41be3f89e757d441661795470b376 (diff)
FS-Cache: Provide a slab for cookie allocation
Provide a slab from which can be allocated the FS-Cache cookies that will be presented to the netfs. Also provide a slab constructor and a function to recursively discard a cookie and its ancestor chain. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Steve Dickson <steved@redhat.com> Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com> Acked-by: Al Viro <viro@zeniv.linux.org.uk> Tested-by: Daire Byrne <Daire.Byrne@framestore.com>
Diffstat (limited to 'fs/fscache')
-rw-r--r--fs/fscache/Makefile1
-rw-r--r--fs/fscache/cookie.c56
-rw-r--r--fs/fscache/internal.h8
-rw-r--r--fs/fscache/main.c15
4 files changed, 80 insertions, 0 deletions
diff --git a/fs/fscache/Makefile b/fs/fscache/Makefile
index 556708bb9796..f88ac1764ce3 100644
--- a/fs/fscache/Makefile
+++ b/fs/fscache/Makefile
@@ -4,6 +4,7 @@
4 4
5fscache-y := \ 5fscache-y := \
6 cache.o \ 6 cache.o \
7 cookie.o \
7 fsdef.o \ 8 fsdef.o \
8 main.o 9 main.o
9 10
diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
new file mode 100644
index 000000000000..47fd75b832e1
--- /dev/null
+++ b/fs/fscache/cookie.c
@@ -0,0 +1,56 @@
1/* netfs cookie management
2 *
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#define FSCACHE_DEBUG_LEVEL COOKIE
13#include <linux/module.h>
14#include <linux/slab.h>
15#include "internal.h"
16
17struct kmem_cache *fscache_cookie_jar;
18
19/*
20 * initialise an cookie jar slab element prior to any use
21 */
22void fscache_cookie_init_once(void *_cookie)
23{
24 struct fscache_cookie *cookie = _cookie;
25
26 memset(cookie, 0, sizeof(*cookie));
27 spin_lock_init(&cookie->lock);
28 INIT_HLIST_HEAD(&cookie->backing_objects);
29}
30
31/*
32 * destroy a cookie
33 */
34void __fscache_cookie_put(struct fscache_cookie *cookie)
35{
36 struct fscache_cookie *parent;
37
38 _enter("%p", cookie);
39
40 for (;;) {
41 _debug("FREE COOKIE %p", cookie);
42 parent = cookie->parent;
43 BUG_ON(!hlist_empty(&cookie->backing_objects));
44 kmem_cache_free(fscache_cookie_jar, cookie);
45
46 if (!parent)
47 break;
48
49 cookie = parent;
50 BUG_ON(atomic_read(&cookie->usage) <= 0);
51 if (!atomic_dec_and_test(&cookie->usage))
52 break;
53 }
54
55 _leave("");
56}
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index 0a2069afa417..4c6ba561e966 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -37,6 +37,14 @@ extern struct fscache_cache *fscache_select_cache_for_object(
37 struct fscache_cookie *); 37 struct fscache_cookie *);
38 38
39/* 39/*
40 * fsc-cookie.c
41 */
42extern struct kmem_cache *fscache_cookie_jar;
43
44extern void fscache_cookie_init_once(void *);
45extern void __fscache_cookie_put(struct fscache_cookie *);
46
47/*
40 * fsc-fsdef.c 48 * fsc-fsdef.c
41 */ 49 */
42extern struct fscache_cookie fscache_fsdef_index; 50extern struct fscache_cookie fscache_fsdef_index;
diff --git a/fs/fscache/main.c b/fs/fscache/main.c
index c2f3e637725d..48b79d2deac1 100644
--- a/fs/fscache/main.c
+++ b/fs/fscache/main.c
@@ -56,6 +56,18 @@ static int __init fscache_init(void)
56 if (ret < 0) 56 if (ret < 0)
57 goto error_proc; 57 goto error_proc;
58 58
59 fscache_cookie_jar = kmem_cache_create("fscache_cookie_jar",
60 sizeof(struct fscache_cookie),
61 0,
62 0,
63 fscache_cookie_init_once);
64 if (!fscache_cookie_jar) {
65 printk(KERN_NOTICE
66 "FS-Cache: Failed to allocate a cookie jar\n");
67 ret = -ENOMEM;
68 goto error_cookie_jar;
69 }
70
59 fscache_root = kobject_create_and_add("fscache", kernel_kobj); 71 fscache_root = kobject_create_and_add("fscache", kernel_kobj);
60 if (!fscache_root) 72 if (!fscache_root)
61 goto error_kobj; 73 goto error_kobj;
@@ -64,6 +76,8 @@ static int __init fscache_init(void)
64 return 0; 76 return 0;
65 77
66error_kobj: 78error_kobj:
79 kmem_cache_destroy(fscache_cookie_jar);
80error_cookie_jar:
67 fscache_proc_cleanup(); 81 fscache_proc_cleanup();
68error_proc: 82error_proc:
69 slow_work_unregister_user(); 83 slow_work_unregister_user();
@@ -81,6 +95,7 @@ static void __exit fscache_exit(void)
81 _enter(""); 95 _enter("");
82 96
83 kobject_put(fscache_root); 97 kobject_put(fscache_root);
98 kmem_cache_destroy(fscache_cookie_jar);
84 fscache_proc_cleanup(); 99 fscache_proc_cleanup();
85 slow_work_unregister_user(); 100 slow_work_unregister_user();
86 printk(KERN_NOTICE "FS-Cache: Unloaded\n"); 101 printk(KERN_NOTICE "FS-Cache: Unloaded\n");