aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2009-04-03 11:42:36 -0400
committerDavid Howells <dhowells@redhat.com>2009-04-03 11:42:36 -0400
commit06b3db1b9bccdc8c2c743122a89745279e5ecc46 (patch)
treeb60850bd899c1a87b5b372cfbf1e72cf380c862a /fs
parent0dfc41d1efcc4180abfd32f68f0ade540e636ff6 (diff)
FS-Cache: Add main configuration option, module entry points and debugging
Add the main configuration option, allowing FS-Cache to be selected; the module entry and exit functions and the debugging stuff used by these patches. The two configuration options added are: CONFIG_FSCACHE CONFIG_FSCACHE_DEBUG The first enables the facility, and the second makes the debugging statements enableable through the "debug" module parameter. The value of this parameter is a bitmask as described in: Documentation/filesystems/caching/fscache.txt The module can be loaded at this point, but all it will do at this point in the patch series is to start up the slow work facility and shut it down again. 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')
-rw-r--r--fs/Kconfig6
-rw-r--r--fs/Makefile1
-rw-r--r--fs/fscache/Kconfig22
-rw-r--r--fs/fscache/Makefile8
-rw-r--r--fs/fscache/internal.h165
-rw-r--r--fs/fscache/main.c75
6 files changed, 277 insertions, 0 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index cef8b18ceaa3..3942df6ad04f 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -66,6 +66,12 @@ config GENERIC_ACL
66 bool 66 bool
67 select FS_POSIX_ACL 67 select FS_POSIX_ACL
68 68
69menu "Caches"
70
71source "fs/fscache/Kconfig"
72
73endmenu
74
69if BLOCK 75if BLOCK
70menu "CD-ROM/DVD Filesystems" 76menu "CD-ROM/DVD Filesystems"
71 77
diff --git a/fs/Makefile b/fs/Makefile
index b5cd8e18dd9f..ff5a10d898c6 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_PROFILING) += dcookies.o
63obj-$(CONFIG_DLM) += dlm/ 63obj-$(CONFIG_DLM) += dlm/
64 64
65# Do not add any filesystems before this line 65# Do not add any filesystems before this line
66obj-$(CONFIG_FSCACHE) += fscache/
66obj-$(CONFIG_REISERFS_FS) += reiserfs/ 67obj-$(CONFIG_REISERFS_FS) += reiserfs/
67obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3 68obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3
68obj-$(CONFIG_EXT2_FS) += ext2/ 69obj-$(CONFIG_EXT2_FS) += ext2/
diff --git a/fs/fscache/Kconfig b/fs/fscache/Kconfig
new file mode 100644
index 000000000000..7c7bccd5eee4
--- /dev/null
+++ b/fs/fscache/Kconfig
@@ -0,0 +1,22 @@
1
2config FSCACHE
3 tristate "General filesystem local caching manager"
4 depends on EXPERIMENTAL
5 select SLOW_WORK
6 help
7 This option enables a generic filesystem caching manager that can be
8 used by various network and other filesystems to cache data locally.
9 Different sorts of caches can be plugged in, depending on the
10 resources available.
11
12 See Documentation/filesystems/caching/fscache.txt for more information.
13
14config FSCACHE_DEBUG
15 bool "Debug FS-Cache"
16 depends on FSCACHE
17 help
18 This permits debugging to be dynamically enabled in the local caching
19 management module. If this is set, the debugging output may be
20 enabled by setting bits in /sys/modules/fscache/parameter/debug.
21
22 See Documentation/filesystems/caching/fscache.txt for more information.
diff --git a/fs/fscache/Makefile b/fs/fscache/Makefile
new file mode 100644
index 000000000000..f8038b83e0ef
--- /dev/null
+++ b/fs/fscache/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for general filesystem caching code
3#
4
5fscache-y := \
6 main.o
7
8obj-$(CONFIG_FSCACHE) := fscache.o
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
new file mode 100644
index 000000000000..95dc92da7152
--- /dev/null
+++ b/fs/fscache/internal.h
@@ -0,0 +1,165 @@
1/* Internal definitions for FS-Cache
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/*
13 * Lock order, in the order in which multiple locks should be obtained:
14 * - fscache_addremove_sem
15 * - cookie->lock
16 * - cookie->parent->lock
17 * - cache->object_list_lock
18 * - object->lock
19 * - object->parent->lock
20 * - fscache_thread_lock
21 *
22 */
23
24#include <linux/fscache-cache.h>
25#include <linux/sched.h>
26
27#define FSCACHE_MIN_THREADS 4
28#define FSCACHE_MAX_THREADS 32
29
30/*
31 * fsc-main.c
32 */
33extern unsigned fscache_defer_lookup;
34extern unsigned fscache_defer_create;
35extern unsigned fscache_debug;
36extern struct kobject *fscache_root;
37
38/*****************************************************************************/
39/*
40 * debug tracing
41 */
42#define dbgprintk(FMT, ...) \
43 printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
44
45/* make sure we maintain the format strings, even when debugging is disabled */
46static inline __attribute__((format(printf, 1, 2)))
47void _dbprintk(const char *fmt, ...)
48{
49}
50
51#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
52#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
53#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
54
55#define kjournal(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
56
57#ifdef __KDEBUG
58#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
59#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
60#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
61
62#elif defined(CONFIG_FSCACHE_DEBUG)
63#define _enter(FMT, ...) \
64do { \
65 if (__do_kdebug(ENTER)) \
66 kenter(FMT, ##__VA_ARGS__); \
67} while (0)
68
69#define _leave(FMT, ...) \
70do { \
71 if (__do_kdebug(LEAVE)) \
72 kleave(FMT, ##__VA_ARGS__); \
73} while (0)
74
75#define _debug(FMT, ...) \
76do { \
77 if (__do_kdebug(DEBUG)) \
78 kdebug(FMT, ##__VA_ARGS__); \
79} while (0)
80
81#else
82#define _enter(FMT, ...) _dbprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
83#define _leave(FMT, ...) _dbprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
84#define _debug(FMT, ...) _dbprintk(FMT, ##__VA_ARGS__)
85#endif
86
87/*
88 * determine whether a particular optional debugging point should be logged
89 * - we need to go through three steps to persuade cpp to correctly join the
90 * shorthand in FSCACHE_DEBUG_LEVEL with its prefix
91 */
92#define ____do_kdebug(LEVEL, POINT) \
93 unlikely((fscache_debug & \
94 (FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
95#define ___do_kdebug(LEVEL, POINT) \
96 ____do_kdebug(LEVEL, POINT)
97#define __do_kdebug(POINT) \
98 ___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
99
100#define FSCACHE_DEBUG_CACHE 0
101#define FSCACHE_DEBUG_COOKIE 1
102#define FSCACHE_DEBUG_PAGE 2
103#define FSCACHE_DEBUG_OPERATION 3
104
105#define FSCACHE_POINT_ENTER 1
106#define FSCACHE_POINT_LEAVE 2
107#define FSCACHE_POINT_DEBUG 4
108
109#ifndef FSCACHE_DEBUG_LEVEL
110#define FSCACHE_DEBUG_LEVEL CACHE
111#endif
112
113/*
114 * assertions
115 */
116#if 1 /* defined(__KDEBUGALL) */
117
118#define ASSERT(X) \
119do { \
120 if (unlikely(!(X))) { \
121 printk(KERN_ERR "\n"); \
122 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
123 BUG(); \
124 } \
125} while (0)
126
127#define ASSERTCMP(X, OP, Y) \
128do { \
129 if (unlikely(!((X) OP (Y)))) { \
130 printk(KERN_ERR "\n"); \
131 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
132 printk(KERN_ERR "%lx " #OP " %lx is false\n", \
133 (unsigned long)(X), (unsigned long)(Y)); \
134 BUG(); \
135 } \
136} while (0)
137
138#define ASSERTIF(C, X) \
139do { \
140 if (unlikely((C) && !(X))) { \
141 printk(KERN_ERR "\n"); \
142 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
143 BUG(); \
144 } \
145} while (0)
146
147#define ASSERTIFCMP(C, X, OP, Y) \
148do { \
149 if (unlikely((C) && !((X) OP (Y)))) { \
150 printk(KERN_ERR "\n"); \
151 printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
152 printk(KERN_ERR "%lx " #OP " %lx is false\n", \
153 (unsigned long)(X), (unsigned long)(Y)); \
154 BUG(); \
155 } \
156} while (0)
157
158#else
159
160#define ASSERT(X) do {} while (0)
161#define ASSERTCMP(X, OP, Y) do {} while (0)
162#define ASSERTIF(C, X) do {} while (0)
163#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
164
165#endif /* assert or not */
diff --git a/fs/fscache/main.c b/fs/fscache/main.c
new file mode 100644
index 000000000000..76f7c69079c0
--- /dev/null
+++ b/fs/fscache/main.c
@@ -0,0 +1,75 @@
1/* General filesystem local caching manager
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 CACHE
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/sched.h>
16#include <linux/completion.h>
17#include <linux/slab.h>
18#include "internal.h"
19
20MODULE_DESCRIPTION("FS Cache Manager");
21MODULE_AUTHOR("Red Hat, Inc.");
22MODULE_LICENSE("GPL");
23
24unsigned fscache_defer_lookup = 1;
25module_param_named(defer_lookup, fscache_defer_lookup, uint,
26 S_IWUSR | S_IRUGO);
27MODULE_PARM_DESC(fscache_defer_lookup,
28 "Defer cookie lookup to background thread");
29
30unsigned fscache_defer_create = 1;
31module_param_named(defer_create, fscache_defer_create, uint,
32 S_IWUSR | S_IRUGO);
33MODULE_PARM_DESC(fscache_defer_create,
34 "Defer cookie creation to background thread");
35
36unsigned fscache_debug;
37module_param_named(debug, fscache_debug, uint,
38 S_IWUSR | S_IRUGO);
39MODULE_PARM_DESC(fscache_debug,
40 "FS-Cache debugging mask");
41
42struct kobject *fscache_root;
43
44/*
45 * initialise the fs caching module
46 */
47static int __init fscache_init(void)
48{
49 int ret;
50
51 ret = slow_work_register_user();
52 if (ret < 0)
53 goto error_slow_work;
54
55 printk(KERN_NOTICE "FS-Cache: Loaded\n");
56 return 0;
57
58error_slow_work:
59 return ret;
60}
61
62fs_initcall(fscache_init);
63
64/*
65 * clean up on module removal
66 */
67static void __exit fscache_exit(void)
68{
69 _enter("");
70
71 slow_work_unregister_user();
72 printk(KERN_NOTICE "FS-Cache: Unloaded\n");
73}
74
75module_exit(fscache_exit);