Merge tag 'v3.10.97' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.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;
25 int ret;
26
27 _enter("{%s}", netfs->name);
28
29 INIT_LIST_HEAD(&netfs->link);
30
31 /* allocate a cookie for the primary index */
32 netfs->primary_index =
33 kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL);
34
35 if (!netfs->primary_index) {
36 _leave(" = -ENOMEM");
37 return -ENOMEM;
38 }
39
40 /* initialise the primary index cookie */
41 atomic_set(&netfs->primary_index->usage, 1);
42 atomic_set(&netfs->primary_index->n_children, 0);
43
44 netfs->primary_index->def = &fscache_fsdef_netfs_def;
45 netfs->primary_index->parent = &fscache_fsdef_index;
46 netfs->primary_index->netfs_data = netfs;
47
726dd7ff
DH
48 spin_lock_init(&netfs->primary_index->lock);
49 INIT_HLIST_HEAD(&netfs->primary_index->backing_objects);
50
51 /* check the netfs type is not already present */
52 down_write(&fscache_addremove_sem);
53
54 ret = -EEXIST;
55 list_for_each_entry(ptr, &fscache_netfs_list, link) {
56 if (strcmp(ptr->name, netfs->name) == 0)
57 goto already_registered;
58 }
59
669e0b00
KM
60 atomic_inc(&netfs->primary_index->parent->usage);
61 atomic_inc(&netfs->primary_index->parent->n_children);
62
726dd7ff
DH
63 list_add(&netfs->link, &fscache_netfs_list);
64 ret = 0;
65
66 printk(KERN_NOTICE "FS-Cache: Netfs '%s' registered for caching\n",
67 netfs->name);
68
69already_registered:
70 up_write(&fscache_addremove_sem);
71
72 if (ret < 0) {
669e0b00 73 kmem_cache_free(fscache_cookie_jar, netfs->primary_index);
726dd7ff
DH
74 netfs->primary_index = NULL;
75 }
76
77 _leave(" = %d", ret);
78 return ret;
79}
80EXPORT_SYMBOL(__fscache_register_netfs);
81
82/*
83 * unregister a network filesystem from the cache
84 * - all cookies must have been released first
85 */
86void __fscache_unregister_netfs(struct fscache_netfs *netfs)
87{
88 _enter("{%s.%u}", netfs->name, netfs->version);
89
90 down_write(&fscache_addremove_sem);
91
92 list_del(&netfs->link);
93 fscache_relinquish_cookie(netfs->primary_index, 0);
94
95 up_write(&fscache_addremove_sem);
96
97 printk(KERN_NOTICE "FS-Cache: Netfs '%s' unregistered from caching\n",
98 netfs->name);
99
100 _leave("");
101}
102EXPORT_SYMBOL(__fscache_unregister_netfs);