1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* FS-Cache netfs (client) registration
4 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define FSCACHE_DEBUG_LEVEL COOKIE
9 #include <linux/module.h>
10 #include <linux/slab.h>
14 * register a network filesystem for caching
16 int __fscache_register_netfs(struct fscache_netfs
*netfs
)
18 struct fscache_cookie
*candidate
, *cookie
;
20 _enter("{%s}", netfs
->name
);
22 /* allocate a cookie for the primary index */
23 candidate
= fscache_alloc_cookie(&fscache_fsdef_index
,
24 &fscache_fsdef_netfs_def
,
25 netfs
->name
, strlen(netfs
->name
),
26 &netfs
->version
, sizeof(netfs
->version
),
33 candidate
->flags
= 1 << FSCACHE_COOKIE_ENABLED
;
35 /* check the netfs type is not already present */
36 cookie
= fscache_hash_cookie(candidate
);
38 goto already_registered
;
39 if (cookie
!= candidate
) {
40 trace_fscache_cookie(candidate
, fscache_cookie_discard
, 1);
41 fscache_free_cookie(candidate
);
44 fscache_cookie_get(cookie
->parent
, fscache_cookie_get_register_netfs
);
45 atomic_inc(&cookie
->parent
->n_children
);
47 netfs
->primary_index
= cookie
;
49 pr_notice("Netfs '%s' registered for caching\n", netfs
->name
);
50 trace_fscache_netfs(netfs
);
55 fscache_cookie_put(candidate
, fscache_cookie_put_dup_netfs
);
59 EXPORT_SYMBOL(__fscache_register_netfs
);
62 * unregister a network filesystem from the cache
63 * - all cookies must have been released first
65 void __fscache_unregister_netfs(struct fscache_netfs
*netfs
)
67 _enter("{%s.%u}", netfs
->name
, netfs
->version
);
69 fscache_relinquish_cookie(netfs
->primary_index
, NULL
, false);
70 pr_notice("Netfs '%s' unregistered from caching\n", netfs
->name
);
74 EXPORT_SYMBOL(__fscache_unregister_netfs
);