Merge tag 'tty-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[linux-2.6-block.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
726dd7ff
DH
17/*
18 * register a network filesystem for caching
19 */
20int __fscache_register_netfs(struct fscache_netfs *netfs)
21{
ec0328e4 22 struct fscache_cookie *candidate, *cookie;
726dd7ff
DH
23
24 _enter("{%s}", netfs->name);
25
726dd7ff 26 /* allocate a cookie for the primary index */
ec0328e4
DH
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) {
726dd7ff
DH
33 _leave(" = -ENOMEM");
34 return -ENOMEM;
35 }
36
ec0328e4 37 candidate->flags = 1 << FSCACHE_COOKIE_ENABLED;
726dd7ff
DH
38
39 /* check the netfs type is not already present */
ec0328e4
DH
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);
726dd7ff
DH
46 }
47
a18feb55 48 fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
b130ed59 49 atomic_inc(&cookie->parent->n_children);
86108c2e 50
b130ed59 51 netfs->primary_index = cookie;
726dd7ff 52
36dfd116 53 pr_notice("Netfs '%s' registered for caching\n", netfs->name);
a18feb55 54 trace_fscache_netfs(netfs);
ec0328e4
DH
55 _leave(" = 0");
56 return 0;
726dd7ff
DH
57
58already_registered:
ec0328e4
DH
59 fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs);
60 _leave(" = -EEXIST");
61 return -EEXIST;
726dd7ff
DH
62}
63EXPORT_SYMBOL(__fscache_register_netfs);
64
65/*
66 * unregister a network filesystem from the cache
67 * - all cookies must have been released first
68 */
69void __fscache_unregister_netfs(struct fscache_netfs *netfs)
70{
71 _enter("{%s.%u}", netfs->name, netfs->version);
72
402cb8dd 73 fscache_relinquish_cookie(netfs->primary_index, NULL, false);
ec0328e4 74 pr_notice("Netfs '%s' unregistered from caching\n", netfs->name);
726dd7ff
DH
75
76 _leave("");
77}
78EXPORT_SYMBOL(__fscache_unregister_netfs);