]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/fscache/netfs.c
fscache: Add tracepoints
[mirror_ubuntu-jammy-kernel.git] / fs / fscache / netfs.c
CommitLineData
726dd7ff
DH
1/* FS-Cache netfs (client) registration
2 *
3 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 */
11
12#define FSCACHE_DEBUG_LEVEL COOKIE
13#include <linux/module.h>
14#include <linux/slab.h>
15#include "internal.h"
16
17static LIST_HEAD(fscache_netfs_list);
18
19/*
20 * register a network filesystem for caching
21 */
22int __fscache_register_netfs(struct fscache_netfs *netfs)
23{
24 struct fscache_netfs *ptr;
b130ed59 25 struct fscache_cookie *cookie;
726dd7ff
DH
26 int ret;
27
28 _enter("{%s}", netfs->name);
29
30 INIT_LIST_HEAD(&netfs->link);
31
32 /* allocate a cookie for the primary index */
b130ed59 33 cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL);
726dd7ff 34
b130ed59 35 if (!cookie) {
726dd7ff
DH
36 _leave(" = -ENOMEM");
37 return -ENOMEM;
38 }
39
40 /* initialise the primary index cookie */
b130ed59
KM
41 atomic_set(&cookie->usage, 1);
42 atomic_set(&cookie->n_children, 0);
43 atomic_set(&cookie->n_active, 1);
726dd7ff 44
b130ed59
KM
45 cookie->def = &fscache_fsdef_netfs_def;
46 cookie->parent = &fscache_fsdef_index;
47 cookie->netfs_data = netfs;
48 cookie->flags = 1 << FSCACHE_COOKIE_ENABLED;
726dd7ff 49
b130ed59 50 spin_lock_init(&cookie->lock);
62deb818 51 spin_lock_init(&cookie->stores_lock);
b130ed59 52 INIT_HLIST_HEAD(&cookie->backing_objects);
726dd7ff
DH
53
54 /* check the netfs type is not already present */
55 down_write(&fscache_addremove_sem);
56
57 ret = -EEXIST;
58 list_for_each_entry(ptr, &fscache_netfs_list, link) {
59 if (strcmp(ptr->name, netfs->name) == 0)
60 goto already_registered;
61 }
62
a18feb55 63 fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
b130ed59 64 atomic_inc(&cookie->parent->n_children);
86108c2e 65
b130ed59 66 netfs->primary_index = cookie;
726dd7ff
DH
67 list_add(&netfs->link, &fscache_netfs_list);
68 ret = 0;
69
36dfd116 70 pr_notice("Netfs '%s' registered for caching\n", netfs->name);
a18feb55 71 trace_fscache_netfs(netfs);
726dd7ff
DH
72
73already_registered:
74 up_write(&fscache_addremove_sem);
75
b130ed59
KM
76 if (ret < 0)
77 kmem_cache_free(fscache_cookie_jar, cookie);
726dd7ff
DH
78
79 _leave(" = %d", ret);
80 return ret;
81}
82EXPORT_SYMBOL(__fscache_register_netfs);
83
84/*
85 * unregister a network filesystem from the cache
86 * - all cookies must have been released first
87 */
88void __fscache_unregister_netfs(struct fscache_netfs *netfs)
89{
90 _enter("{%s.%u}", netfs->name, netfs->version);
91
92 down_write(&fscache_addremove_sem);
93
94 list_del(&netfs->link);
95 fscache_relinquish_cookie(netfs->primary_index, 0);
96
97 up_write(&fscache_addremove_sem);
98
36dfd116
FF
99 pr_notice("Netfs '%s' unregistered from caching\n",
100 netfs->name);
726dd7ff
DH
101
102 _leave("");
103}
104EXPORT_SYMBOL(__fscache_unregister_netfs);