-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux-2.6-590-dcookies-mm.patch
318 lines (289 loc) · 7.56 KB
/
linux-2.6-590-dcookies-mm.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
diff -Nurb linux-2.6.27-580/fs/dcookies.c linux-2.6.27-590/fs/dcookies.c
--- linux-2.6.27-580/fs/dcookies.c 2009-07-23 10:51:40.000000000 -0400
+++ linux-2.6.27-590/fs/dcookies.c 2009-11-30 17:26:58.000000000 -0500
@@ -24,6 +24,7 @@
#include <linux/errno.h>
#include <linux/dcookies.h>
#include <linux/mutex.h>
+#include <linux/spinlock.h>
#include <linux/path.h>
#include <asm/uaccess.h>
@@ -38,15 +39,21 @@
static LIST_HEAD(dcookie_users);
static DEFINE_MUTEX(dcookie_mutex);
+spinlock_t dcookie_hash_write_lock = SPIN_LOCK_UNLOCKED;
static struct kmem_cache *dcookie_cache __read_mostly;
-static struct list_head *dcookie_hashtable __read_mostly;
+static struct list_head *dcookie_hashtable[3] __read_mostly;
static size_t hash_size __read_mostly;
+unsigned int current_hash = 1, old_hash = 0;
static inline int is_live(void)
{
return !(list_empty(&dcookie_users));
}
+static inline int is_shared(void)
+{
+ return !(list_empty(&dcookie_users)) && !(list_empty(dcookie_users.next));
+}
/* The dentry is locked, its address will do for the cookie */
static inline unsigned long dcookie_value(struct dcookie_struct * dcs)
@@ -68,7 +75,18 @@
struct list_head * pos;
struct list_head * list;
- list = dcookie_hashtable + dcookie_hash(dcookie);
+ list = dcookie_hashtable[current_hash] + dcookie_hash(dcookie);
+
+ list_for_each(pos, list) {
+ dcs = list_entry(pos, struct dcookie_struct, hash_list);
+ if (dcookie_value(dcs) == dcookie) {
+ found = dcs;
+ break;
+ }
+ }
+
+ if (!found) {
+ list = dcookie_hashtable[old_hash] + dcookie_hash(dcookie);
list_for_each(pos, list) {
dcs = list_entry(pos, struct dcookie_struct, hash_list);
@@ -77,6 +95,8 @@
break;
}
}
+ }
+
return found;
}
@@ -84,15 +104,14 @@
static void hash_dcookie(struct dcookie_struct * dcs)
{
- struct list_head * list = dcookie_hashtable + dcookie_hash(dcookie_value(dcs));
+ struct list_head * list = dcookie_hashtable[current_hash] + dcookie_hash(dcookie_value(dcs));
list_add(&dcs->hash_list, list);
}
static struct dcookie_struct *alloc_dcookie(struct path *path)
{
- struct dcookie_struct *dcs = kmem_cache_alloc(dcookie_cache,
- GFP_KERNEL);
+ struct dcookie_struct * dcs = kmem_cache_alloc(dcookie_cache, GFP_ATOMIC);
if (!dcs)
return NULL;
@@ -112,7 +131,7 @@
int err = 0;
struct dcookie_struct * dcs;
- mutex_lock(&dcookie_mutex);
+ spin_lock(&dcookie_hash_write_lock);
if (!is_live()) {
err = -EINVAL;
@@ -132,7 +151,7 @@
*cookie = dcookie_value(dcs);
out:
- mutex_unlock(&dcookie_mutex);
+ spin_unlock(&dcookie_hash_write_lock);
return err;
}
@@ -204,7 +223,7 @@
static int dcookie_init(void)
{
struct list_head * d;
- unsigned int i, hash_bits;
+ unsigned int i, j, hash_bits;
int err = -ENOMEM;
dcookie_cache = kmem_cache_create("dcookie_cache",
@@ -214,9 +233,11 @@
if (!dcookie_cache)
goto out;
- dcookie_hashtable = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if (!dcookie_hashtable)
+ for (i=0; i<3; i++) {
+ dcookie_hashtable[i] = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!dcookie_hashtable[i])
goto out_kmem;
+ }
err = 0;
@@ -239,13 +260,16 @@
hash_size = 1UL << hash_bits;
/* And initialize the newly allocated array */
- d = dcookie_hashtable;
- i = hash_size;
+
+ for (i=0; i<3; i++) {
+ d = dcookie_hashtable[i];
+ j = hash_size;
do {
INIT_LIST_HEAD(d);
d++;
- i--;
- } while (i);
+ j--;
+ } while (j);
+ }
out:
return err;
@@ -262,25 +286,61 @@
kmem_cache_free(dcookie_cache, dcs);
}
+int dcookie_swap(void) {
+ if (is_shared())
+ return -EAGAIN;
-static void dcookie_exit(void)
-{
+ old_hash=current_hash;
+ current_hash = (current_hash + 1) % 3;
+ return 0;
+}
+
+/* Switch to the second hash */
+int dcookie_garbage_collect(void) {
struct list_head * list;
struct list_head * pos;
struct list_head * pos2;
struct dcookie_struct * dcs;
size_t i;
+ int next_hash=(current_hash + 1) % 3;
+
+ if (is_shared())
+ return -EAGAIN;
+ /* XXX consider the consequence of dcookie allocation concurring with this cleanup */
for (i = 0; i < hash_size; ++i) {
- list = dcookie_hashtable + i;
+ list = dcookie_hashtable[next_hash] + i;
+ list_for_each_safe(pos, pos2, list) {
+ dcs = list_entry(pos, struct dcookie_struct, hash_list);
+ list_del(&dcs->hash_list);
+ free_dcookie(dcs);
+ }
+ }
+
+ return 0;
+}
+
+static void dcookie_exit(void)
+{
+ struct list_head * list;
+ struct list_head * pos;
+ struct list_head * pos2;
+ struct dcookie_struct * dcs;
+ size_t j;
+ unsigned int i;
+
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < hash_size; ++j) {
+ list = dcookie_hashtable[i] + j;
list_for_each_safe(pos, pos2, list) {
dcs = list_entry(pos, struct dcookie_struct, hash_list);
list_del(&dcs->hash_list);
free_dcookie(dcs);
}
}
+ kfree(dcookie_hashtable[i]);
+ }
- kfree(dcookie_hashtable);
kmem_cache_destroy(dcookie_cache);
}
@@ -330,3 +390,5 @@
EXPORT_SYMBOL_GPL(dcookie_register);
EXPORT_SYMBOL_GPL(dcookie_unregister);
EXPORT_SYMBOL_GPL(get_dcookie);
+EXPORT_SYMBOL_GPL(dcookie_garbage_collect);
+EXPORT_SYMBOL_GPL(dcookie_swap);
diff -Nurb linux-2.6.27-580/include/linux/dcookies.h linux-2.6.27-590/include/linux/dcookies.h
--- linux-2.6.27-580/include/linux/dcookies.h 2008-10-09 18:13:53.000000000 -0400
+++ linux-2.6.27-590/include/linux/dcookies.h 2009-11-30 16:42:59.000000000 -0500
@@ -46,6 +46,27 @@
*/
int get_dcookie(struct path *path, unsigned long *cookie);
+/**
+ * dcookie_swap - switch to the next dcookie epoch
+ *
+ * Deactivate the current dcookie hash table and activate
+ * the next one
+ *
+ * Returns 0 on success
+ */
+
+int dcookie_swap(void);
+
+/**
+ * dcookie_garbage_collect - clear the hash table next in line
+ *
+ * Clear the hash table to be activated in the next epoch.
+ *
+ * Returns 0 on success
+ */
+
+int dcookie_garbage_colect(void);
+
#else
static inline struct dcookie_user * dcookie_register(void)
diff -Nurb linux-2.6.27-580/include/linux/dcookies.h.orig linux-2.6.27-590/include/linux/dcookies.h.orig
--- linux-2.6.27-580/include/linux/dcookies.h.orig 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.27-590/include/linux/dcookies.h.orig 2008-10-09 18:13:53.000000000 -0400
@@ -0,0 +1,68 @@
+/*
+ * dcookies.h
+ *
+ * Persistent cookie-path mappings
+ *
+ * Copyright 2002 John Levon <levon@movementarian.org>
+ */
+
+#ifndef DCOOKIES_H
+#define DCOOKIES_H
+
+
+#ifdef CONFIG_PROFILING
+
+#include <linux/dcache.h>
+#include <linux/path.h>
+#include <linux/types.h>
+
+struct dcookie_user;
+
+/**
+ * dcookie_register - register a user of dcookies
+ *
+ * Register as a dcookie user. Returns %NULL on failure.
+ */
+struct dcookie_user * dcookie_register(void);
+
+/**
+ * dcookie_unregister - unregister a user of dcookies
+ *
+ * Unregister as a dcookie user. This may invalidate
+ * any dcookie values returned from get_dcookie().
+ */
+void dcookie_unregister(struct dcookie_user * user);
+
+/**
+ * get_dcookie - acquire a dcookie
+ *
+ * Convert the given dentry/vfsmount pair into
+ * a cookie value.
+ *
+ * Returns -EINVAL if no living task has registered as a
+ * dcookie user.
+ *
+ * Returns 0 on success, with *cookie filled in
+ */
+int get_dcookie(struct path *path, unsigned long *cookie);
+
+#else
+
+static inline struct dcookie_user * dcookie_register(void)
+{
+ return NULL;
+}
+
+static inline void dcookie_unregister(struct dcookie_user * user)
+{
+ return;
+}
+
+static inline int get_dcookie(struct path *path, unsigned long *cookie)
+{
+ return -ENOSYS;
+}
+
+#endif /* CONFIG_PROFILING */
+
+#endif /* DCOOKIES_H */