1 /* netfs cookie management
3 * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #define FSCACHE_DEBUG_LEVEL COOKIE
13 #include <linux/module.h>
14 #include <linux/slab.h>
17 struct kmem_cache *fscache_cookie_jar;
20 * initialise an cookie jar slab element prior to any use
22 void fscache_cookie_init_once(void *_cookie)
24 struct fscache_cookie *cookie = _cookie;
26 memset(cookie, 0, sizeof(*cookie));
27 spin_lock_init(&cookie->lock);
28 INIT_HLIST_HEAD(&cookie->backing_objects);
34 void __fscache_cookie_put(struct fscache_cookie *cookie)
36 struct fscache_cookie *parent;
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);
50 BUG_ON(atomic_read(&cookie->usage) <= 0);
51 if (!atomic_dec_and_test(&cookie->usage))