1 /* FS-Cache netfs (client) registration
3 * Copyright (C) 2008 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 Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #define FSCACHE_DEBUG_LEVEL COOKIE
13 #include <linux/module.h>
14 #include <linux/slab.h>
17 static LIST_HEAD(fscache_netfs_list
);
20 * register a network filesystem for caching
22 int __fscache_register_netfs(struct fscache_netfs
*netfs
)
24 struct fscache_netfs
*ptr
;
27 _enter("{%s}", netfs
->name
);
29 INIT_LIST_HEAD(&netfs
->link
);
31 /* allocate a cookie for the primary index */
32 netfs
->primary_index
=
33 kmem_cache_zalloc(fscache_cookie_jar
, GFP_KERNEL
);
35 if (!netfs
->primary_index
) {
40 /* initialise the primary index cookie */
41 atomic_set(&netfs
->primary_index
->usage
, 1);
42 atomic_set(&netfs
->primary_index
->n_children
, 0);
43 atomic_set(&netfs
->primary_index
->n_active
, 1);
45 netfs
->primary_index
->def
= &fscache_fsdef_netfs_def
;
46 netfs
->primary_index
->parent
= &fscache_fsdef_index
;
47 netfs
->primary_index
->netfs_data
= netfs
;
49 atomic_inc(&netfs
->primary_index
->parent
->usage
);
50 atomic_inc(&netfs
->primary_index
->parent
->n_children
);
52 spin_lock_init(&netfs
->primary_index
->lock
);
53 INIT_HLIST_HEAD(&netfs
->primary_index
->backing_objects
);
55 /* check the netfs type is not already present */
56 down_write(&fscache_addremove_sem
);
59 list_for_each_entry(ptr
, &fscache_netfs_list
, link
) {
60 if (strcmp(ptr
->name
, netfs
->name
) == 0)
61 goto already_registered
;
64 list_add(&netfs
->link
, &fscache_netfs_list
);
67 printk(KERN_NOTICE
"FS-Cache: Netfs '%s' registered for caching\n",
71 up_write(&fscache_addremove_sem
);
74 netfs
->primary_index
->parent
= NULL
;
75 __fscache_cookie_put(netfs
->primary_index
);
76 netfs
->primary_index
= NULL
;
82 EXPORT_SYMBOL(__fscache_register_netfs
);
85 * unregister a network filesystem from the cache
86 * - all cookies must have been released first
88 void __fscache_unregister_netfs(struct fscache_netfs
*netfs
)
90 _enter("{%s.%u}", netfs
->name
, netfs
->version
);
92 down_write(&fscache_addremove_sem
);
94 list_del(&netfs
->link
);
95 fscache_relinquish_cookie(netfs
->primary_index
, 0);
97 up_write(&fscache_addremove_sem
);
99 printk(KERN_NOTICE
"FS-Cache: Netfs '%s' unregistered from caching\n",
104 EXPORT_SYMBOL(__fscache_unregister_netfs
);