Merge branch 'for-linus-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad...
[linux-2.6-block.git] / fs / fscache / netfs.c
CommitLineData
b4d0d230 1// SPDX-License-Identifier: GPL-2.0-or-later
726dd7ff
DH
2/* FS-Cache netfs (client) registration
3 *
4 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
726dd7ff
DH
6 */
7
8#define FSCACHE_DEBUG_LEVEL COOKIE
9#include <linux/module.h>
10#include <linux/slab.h>
11#include "internal.h"
12
726dd7ff
DH
13/*
14 * register a network filesystem for caching
15 */
16int __fscache_register_netfs(struct fscache_netfs *netfs)
17{
ec0328e4 18 struct fscache_cookie *candidate, *cookie;
726dd7ff
DH
19
20 _enter("{%s}", netfs->name);
21
726dd7ff 22 /* allocate a cookie for the primary index */
ec0328e4
DH
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),
27 netfs, 0);
28 if (!candidate) {
726dd7ff
DH
29 _leave(" = -ENOMEM");
30 return -ENOMEM;
31 }
32
ec0328e4 33 candidate->flags = 1 << FSCACHE_COOKIE_ENABLED;
726dd7ff
DH
34
35 /* check the netfs type is not already present */
ec0328e4
DH
36 cookie = fscache_hash_cookie(candidate);
37 if (!cookie)
38 goto already_registered;
39 if (cookie != candidate) {
40 trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
41 fscache_free_cookie(candidate);
726dd7ff
DH
42 }
43
a18feb55 44 fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
b130ed59 45 atomic_inc(&cookie->parent->n_children);
86108c2e 46
b130ed59 47 netfs->primary_index = cookie;
726dd7ff 48
36dfd116 49 pr_notice("Netfs '%s' registered for caching\n", netfs->name);
a18feb55 50 trace_fscache_netfs(netfs);
ec0328e4
DH
51 _leave(" = 0");
52 return 0;
726dd7ff
DH
53
54already_registered:
ec0328e4
DH
55 fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs);
56 _leave(" = -EEXIST");
57 return -EEXIST;
726dd7ff
DH
58}
59EXPORT_SYMBOL(__fscache_register_netfs);
60
61/*
62 * unregister a network filesystem from the cache
63 * - all cookies must have been released first
64 */
65void __fscache_unregister_netfs(struct fscache_netfs *netfs)
66{
67 _enter("{%s.%u}", netfs->name, netfs->version);
68
402cb8dd 69 fscache_relinquish_cookie(netfs->primary_index, NULL, false);
ec0328e4 70 pr_notice("Netfs '%s' unregistered from caching\n", netfs->name);
726dd7ff
DH
71
72 _leave("");
73}
74EXPORT_SYMBOL(__fscache_unregister_netfs);