aboutsummaryrefslogtreecommitdiffstats
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
commit726dd7ff10c217dd74329c94643dc8ebea27334b (patch)
tree9bd5b011f945fca4f1b057f7e7750414b1fd9fbd
parent955d00917f0c094e0f2fb88df967e980ab66b8ca (diff)
FS-Cache: Add netfs registration
Add functions to register and unregister a network filesystem or other client of the FS-Cache service. This allocates and releases the cookie representing the top-level index for a netfs, and makes it available to the netfs. If the FS-Cache facility is disabled, then the calls are optimised away at compile time. Note that whilst this patch may appear to work with FS-Cache enabled and a netfs attempting to use it, it will leak the cookie it allocates for the netfs as fscache_relinquish_cookie() is implemented in a later patch. This will cause the slab code to emit a warning when the module is removed. 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>
-rw-r--r--fs/fscache/Makefile3
-rw-r--r--fs/fscache/netfs.c103
-rw-r--r--include/linux/fscache.h9
3 files changed, 113 insertions, 2 deletions
diff --git a/fs/fscache/Makefile b/fs/fscache/Makefile
index f88ac1764ce3..ecf6946eaeb3 100644
--- a/fs/fscache/Makefile
+++ b/fs/fscache/Makefile
@@ -6,7 +6,8 @@ fscache-y := \
6 cache.o \ 6 cache.o \
7 cookie.o \ 7 cookie.o \
8 fsdef.o \ 8 fsdef.o \
9 main.o 9 main.o \
10 netfs.o
10 11
11fscache-$(CONFIG_PROC_FS) += proc.o 12fscache-$(CONFIG_PROC_FS) += proc.o
12fscache-$(CONFIG_FSCACHE_STATS) += stats.o 13fscache-$(CONFIG_FSCACHE_STATS) += stats.o
diff --git a/fs/fscache/netfs.c b/fs/fscache/netfs.c
new file mode 100644
index 000000000000..e028b8eb1c40
--- /dev/null
+++ b/fs/fscache/netfs.c
@@ -0,0 +1,103 @@
1/* FS-Cache netfs (client) registration
2 *
3 * Copyright (C) 2008 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 Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, 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
17static LIST_HEAD(fscache_netfs_list);
18
19/*
20 * register a network filesystem for caching
21 */
22int __fscache_register_netfs(struct fscache_netfs *netfs)
23{
24 struct fscache_netfs *ptr;
25 int ret;
26
27 _enter("{%s}", netfs->name);
28
29 INIT_LIST_HEAD(&netfs->link);
30
31 /* allocate a cookie for the primary index */
32 netfs->primary_index =
33 kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL);
34
35 if (!netfs->primary_index) {
36 _leave(" = -ENOMEM");
37 return -ENOMEM;
38 }
39
40 /* initialise the primary index cookie */
41 atomic_set(&netfs->primary_index->usage, 1);
42 atomic_set(&netfs->primary_index->n_children, 0);
43
44 netfs->primary_index->def = &fscache_fsdef_netfs_def;
45 netfs->primary_index->parent = &fscache_fsdef_index;
46 netfs->primary_index->netfs_data = netfs;
47
48 atomic_inc(&netfs->primary_index->parent->usage);
49 atomic_inc(&netfs->primary_index->parent->n_children);
50
51 spin_lock_init(&netfs->primary_index->lock);
52 INIT_HLIST_HEAD(&netfs->primary_index->backing_objects);
53
54 /* check the netfs type is not already present */
55 down_write(&fscache_addremove_sem);
56
57 ret = -EEXIST;
58 list_for_each_entry(ptr, &fscache_netfs_list, link) {
59 if (strcmp(ptr->name, netfs->name) == 0)
60 goto already_registered;
61 }
62
63 list_add(&netfs->link, &fscache_netfs_list);
64 ret = 0;
65
66 printk(KERN_NOTICE "FS-Cache: Netfs '%s' registered for caching\n",
67 netfs->name);
68
69already_registered:
70 up_write(&fscache_addremove_sem);
71
72 if (ret < 0) {
73 netfs->primary_index->parent = NULL;
74 __fscache_cookie_put(netfs->primary_index);
75 netfs->primary_index = NULL;
76 }
77
78 _leave(" = %d", ret);
79 return ret;
80}
81EXPORT_SYMBOL(__fscache_register_netfs);
82
83/*
84 * unregister a network filesystem from the cache
85 * - all cookies must have been released first
86 */
87void __fscache_unregister_netfs(struct fscache_netfs *netfs)
88{
89 _enter("{%s.%u}", netfs->name, netfs->version);
90
91 down_write(&fscache_addremove_sem);
92
93 list_del(&netfs->link);
94 fscache_relinquish_cookie(netfs->primary_index, 0);
95
96 up_write(&fscache_addremove_sem);
97
98 printk(KERN_NOTICE "FS-Cache: Netfs '%s' unregistered from caching\n",
99 netfs->name);
100
101 _leave("");
102}
103EXPORT_SYMBOL(__fscache_unregister_netfs);
diff --git a/include/linux/fscache.h b/include/linux/fscache.h
index 9584c094d69f..b195c2e1ef6a 100644
--- a/include/linux/fscache.h
+++ b/include/linux/fscache.h
@@ -173,6 +173,8 @@ struct fscache_netfs {
173 * - these are undefined symbols when FS-Cache is not configured and the 173 * - these are undefined symbols when FS-Cache is not configured and the
174 * optimiser takes care of not using them 174 * optimiser takes care of not using them
175 */ 175 */
176extern int __fscache_register_netfs(struct fscache_netfs *);
177extern void __fscache_unregister_netfs(struct fscache_netfs *);
176extern struct fscache_cache_tag *__fscache_lookup_cache_tag(const char *); 178extern struct fscache_cache_tag *__fscache_lookup_cache_tag(const char *);
177extern void __fscache_release_cache_tag(struct fscache_cache_tag *); 179extern void __fscache_release_cache_tag(struct fscache_cache_tag *);
178 180
@@ -188,7 +190,10 @@ extern void __fscache_release_cache_tag(struct fscache_cache_tag *);
188static inline 190static inline
189int fscache_register_netfs(struct fscache_netfs *netfs) 191int fscache_register_netfs(struct fscache_netfs *netfs)
190{ 192{
191 return 0; 193 if (fscache_available())
194 return __fscache_register_netfs(netfs);
195 else
196 return 0;
192} 197}
193 198
194/** 199/**
@@ -205,6 +210,8 @@ int fscache_register_netfs(struct fscache_netfs *netfs)
205static inline 210static inline
206void fscache_unregister_netfs(struct fscache_netfs *netfs) 211void fscache_unregister_netfs(struct fscache_netfs *netfs)
207{ 212{
213 if (fscache_available())
214 __fscache_unregister_netfs(netfs);
208} 215}
209 216
210/** 217/**