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>
This commit is contained in:
parent
4c515dd47a
commit
955d00917f
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
fscache-y := \
|
fscache-y := \
|
||||||
cache.o \
|
cache.o \
|
||||||
|
cookie.o \
|
||||||
fsdef.o \
|
fsdef.o \
|
||||||
main.o
|
main.o
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* netfs cookie management
|
||||||
|
*
|
||||||
|
* Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
|
||||||
|
* Written by David Howells (dhowells@redhat.com)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version
|
||||||
|
* 2 of the License, or (at your option) any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FSCACHE_DEBUG_LEVEL COOKIE
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
|
struct kmem_cache *fscache_cookie_jar;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialise an cookie jar slab element prior to any use
|
||||||
|
*/
|
||||||
|
void fscache_cookie_init_once(void *_cookie)
|
||||||
|
{
|
||||||
|
struct fscache_cookie *cookie = _cookie;
|
||||||
|
|
||||||
|
memset(cookie, 0, sizeof(*cookie));
|
||||||
|
spin_lock_init(&cookie->lock);
|
||||||
|
INIT_HLIST_HEAD(&cookie->backing_objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* destroy a cookie
|
||||||
|
*/
|
||||||
|
void __fscache_cookie_put(struct fscache_cookie *cookie)
|
||||||
|
{
|
||||||
|
struct fscache_cookie *parent;
|
||||||
|
|
||||||
|
_enter("%p", cookie);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
_debug("FREE COOKIE %p", cookie);
|
||||||
|
parent = cookie->parent;
|
||||||
|
BUG_ON(!hlist_empty(&cookie->backing_objects));
|
||||||
|
kmem_cache_free(fscache_cookie_jar, cookie);
|
||||||
|
|
||||||
|
if (!parent)
|
||||||
|
break;
|
||||||
|
|
||||||
|
cookie = parent;
|
||||||
|
BUG_ON(atomic_read(&cookie->usage) <= 0);
|
||||||
|
if (!atomic_dec_and_test(&cookie->usage))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_leave("");
|
||||||
|
}
|
|
@ -36,6 +36,14 @@ extern struct rw_semaphore fscache_addremove_sem;
|
||||||
extern struct fscache_cache *fscache_select_cache_for_object(
|
extern struct fscache_cache *fscache_select_cache_for_object(
|
||||||
struct fscache_cookie *);
|
struct fscache_cookie *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fsc-cookie.c
|
||||||
|
*/
|
||||||
|
extern struct kmem_cache *fscache_cookie_jar;
|
||||||
|
|
||||||
|
extern void fscache_cookie_init_once(void *);
|
||||||
|
extern void __fscache_cookie_put(struct fscache_cookie *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fsc-fsdef.c
|
* fsc-fsdef.c
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -56,6 +56,18 @@ static int __init fscache_init(void)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error_proc;
|
goto error_proc;
|
||||||
|
|
||||||
|
fscache_cookie_jar = kmem_cache_create("fscache_cookie_jar",
|
||||||
|
sizeof(struct fscache_cookie),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
fscache_cookie_init_once);
|
||||||
|
if (!fscache_cookie_jar) {
|
||||||
|
printk(KERN_NOTICE
|
||||||
|
"FS-Cache: Failed to allocate a cookie jar\n");
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto error_cookie_jar;
|
||||||
|
}
|
||||||
|
|
||||||
fscache_root = kobject_create_and_add("fscache", kernel_kobj);
|
fscache_root = kobject_create_and_add("fscache", kernel_kobj);
|
||||||
if (!fscache_root)
|
if (!fscache_root)
|
||||||
goto error_kobj;
|
goto error_kobj;
|
||||||
|
@ -64,6 +76,8 @@ static int __init fscache_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_kobj:
|
error_kobj:
|
||||||
|
kmem_cache_destroy(fscache_cookie_jar);
|
||||||
|
error_cookie_jar:
|
||||||
fscache_proc_cleanup();
|
fscache_proc_cleanup();
|
||||||
error_proc:
|
error_proc:
|
||||||
slow_work_unregister_user();
|
slow_work_unregister_user();
|
||||||
|
@ -81,6 +95,7 @@ static void __exit fscache_exit(void)
|
||||||
_enter("");
|
_enter("");
|
||||||
|
|
||||||
kobject_put(fscache_root);
|
kobject_put(fscache_root);
|
||||||
|
kmem_cache_destroy(fscache_cookie_jar);
|
||||||
fscache_proc_cleanup();
|
fscache_proc_cleanup();
|
||||||
slow_work_unregister_user();
|
slow_work_unregister_user();
|
||||||
printk(KERN_NOTICE "FS-Cache: Unloaded\n");
|
printk(KERN_NOTICE "FS-Cache: Unloaded\n");
|
||||||
|
|
Loading…
Reference in New Issue