1
2
3
4
5
6
7
8
9
10
11
12#define FSCACHE_DEBUG_LEVEL COOKIE
13#include <linux/module.h>
14#include <linux/slab.h>
15#include "internal.h"
16
17
18
19
20int __fscache_register_netfs(struct fscache_netfs *netfs)
21{
22 struct fscache_cookie *candidate, *cookie;
23
24 _enter("{%s}", netfs->name);
25
26
27 candidate = fscache_alloc_cookie(&fscache_fsdef_index,
28 &fscache_fsdef_netfs_def,
29 netfs->name, strlen(netfs->name),
30 &netfs->version, sizeof(netfs->version),
31 netfs, 0);
32 if (!candidate) {
33 _leave(" = -ENOMEM");
34 return -ENOMEM;
35 }
36
37 candidate->flags = 1 << FSCACHE_COOKIE_ENABLED;
38
39
40 cookie = fscache_hash_cookie(candidate);
41 if (!cookie)
42 goto already_registered;
43 if (cookie != candidate) {
44 trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
45 fscache_free_cookie(candidate);
46 }
47
48 fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
49 atomic_inc(&cookie->parent->n_children);
50
51 netfs->primary_index = cookie;
52
53 pr_notice("Netfs '%s' registered for caching\n", netfs->name);
54 trace_fscache_netfs(netfs);
55 _leave(" = 0");
56 return 0;
57
58already_registered:
59 fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs);
60 _leave(" = -EEXIST");
61 return -EEXIST;
62}
63EXPORT_SYMBOL(__fscache_register_netfs);
64
65
66
67
68
69void __fscache_unregister_netfs(struct fscache_netfs *netfs)
70{
71 _enter("{%s.%u}", netfs->name, netfs->version);
72
73 fscache_relinquish_cookie(netfs->primary_index, NULL, false);
74 pr_notice("Netfs '%s' unregistered from caching\n", netfs->name);
75
76 _leave("");
77}
78EXPORT_SYMBOL(__fscache_unregister_netfs);
79