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>
18 * register a network filesystem for caching
20 int __fscache_register_netfs(struct fscache_netfs
*netfs
)
22 struct fscache_cookie
*candidate
, *cookie
;
24 _enter("{%s}", netfs
->name
);
26 /* allocate a cookie for the primary index */
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
),
37 candidate
->flags
= 1 << FSCACHE_COOKIE_ENABLED
;
39 /* check the netfs type is not already present */
40 cookie
= fscache_hash_cookie(candidate
);
42 goto already_registered
;
43 if (cookie
!= candidate
) {
44 trace_fscache_cookie(candidate
, fscache_cookie_discard
, 1);
45 fscache_free_cookie(candidate
);
48 fscache_cookie_get(cookie
->parent
, fscache_cookie_get_register_netfs
);
49 atomic_inc(&cookie
->parent
->n_children
);
51 netfs
->primary_index
= cookie
;
53 pr_notice("Netfs '%s' registered for caching\n", netfs
->name
);
54 trace_fscache_netfs(netfs
);
59 fscache_cookie_put(candidate
, fscache_cookie_put_dup_netfs
);
63 EXPORT_SYMBOL(__fscache_register_netfs
);
66 * unregister a network filesystem from the cache
67 * - all cookies must have been released first
69 void __fscache_unregister_netfs(struct fscache_netfs
*netfs
)
71 _enter("{%s.%u}", netfs
->name
, netfs
->version
);
73 fscache_relinquish_cookie(netfs
->primary_index
, NULL
, false);
74 pr_notice("Netfs '%s' unregistered from caching\n", netfs
->name
);
78 EXPORT_SYMBOL(__fscache_unregister_netfs
);