diff options
author | Kinglong Mee <kinglongmee@gmail.com> | 2015-11-04 10:20:24 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2015-11-11 02:07:51 -0500 |
commit | b130ed5998e62879a66bad08931a2b5e832da95c (patch) | |
tree | 199f61e2d9822d5bbde3ba1bbda2a54bead3628c | |
parent | 86108c2e34a26e4bec3c6ddb23390bf8cedcf391 (diff) |
FS-Cache: Don't override netfs's primary_index if registering failed
Only override netfs->primary_index when registering success.
Cc: stable@vger.kernel.org # v2.6.30+
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/fscache/netfs.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/fs/fscache/netfs.c b/fs/fscache/netfs.c index 458cc968d9a0..9b28649df3a1 100644 --- a/fs/fscache/netfs.c +++ b/fs/fscache/netfs.c | |||
@@ -22,6 +22,7 @@ static LIST_HEAD(fscache_netfs_list); | |||
22 | int __fscache_register_netfs(struct fscache_netfs *netfs) | 22 | int __fscache_register_netfs(struct fscache_netfs *netfs) |
23 | { | 23 | { |
24 | struct fscache_netfs *ptr; | 24 | struct fscache_netfs *ptr; |
25 | struct fscache_cookie *cookie; | ||
25 | int ret; | 26 | int ret; |
26 | 27 | ||
27 | _enter("{%s}", netfs->name); | 28 | _enter("{%s}", netfs->name); |
@@ -29,26 +30,25 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) | |||
29 | INIT_LIST_HEAD(&netfs->link); | 30 | INIT_LIST_HEAD(&netfs->link); |
30 | 31 | ||
31 | /* allocate a cookie for the primary index */ | 32 | /* allocate a cookie for the primary index */ |
32 | netfs->primary_index = | 33 | cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); |
33 | kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); | ||
34 | 34 | ||
35 | if (!netfs->primary_index) { | 35 | if (!cookie) { |
36 | _leave(" = -ENOMEM"); | 36 | _leave(" = -ENOMEM"); |
37 | return -ENOMEM; | 37 | return -ENOMEM; |
38 | } | 38 | } |
39 | 39 | ||
40 | /* initialise the primary index cookie */ | 40 | /* initialise the primary index cookie */ |
41 | atomic_set(&netfs->primary_index->usage, 1); | 41 | atomic_set(&cookie->usage, 1); |
42 | atomic_set(&netfs->primary_index->n_children, 0); | 42 | atomic_set(&cookie->n_children, 0); |
43 | atomic_set(&netfs->primary_index->n_active, 1); | 43 | atomic_set(&cookie->n_active, 1); |
44 | 44 | ||
45 | netfs->primary_index->def = &fscache_fsdef_netfs_def; | 45 | cookie->def = &fscache_fsdef_netfs_def; |
46 | netfs->primary_index->parent = &fscache_fsdef_index; | 46 | cookie->parent = &fscache_fsdef_index; |
47 | netfs->primary_index->netfs_data = netfs; | 47 | cookie->netfs_data = netfs; |
48 | netfs->primary_index->flags = 1 << FSCACHE_COOKIE_ENABLED; | 48 | cookie->flags = 1 << FSCACHE_COOKIE_ENABLED; |
49 | 49 | ||
50 | spin_lock_init(&netfs->primary_index->lock); | 50 | spin_lock_init(&cookie->lock); |
51 | INIT_HLIST_HEAD(&netfs->primary_index->backing_objects); | 51 | INIT_HLIST_HEAD(&cookie->backing_objects); |
52 | 52 | ||
53 | /* check the netfs type is not already present */ | 53 | /* check the netfs type is not already present */ |
54 | down_write(&fscache_addremove_sem); | 54 | down_write(&fscache_addremove_sem); |
@@ -59,9 +59,10 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) | |||
59 | goto already_registered; | 59 | goto already_registered; |
60 | } | 60 | } |
61 | 61 | ||
62 | atomic_inc(&netfs->primary_index->parent->usage); | 62 | atomic_inc(&cookie->parent->usage); |
63 | atomic_inc(&netfs->primary_index->parent->n_children); | 63 | atomic_inc(&cookie->parent->n_children); |
64 | 64 | ||
65 | netfs->primary_index = cookie; | ||
65 | list_add(&netfs->link, &fscache_netfs_list); | 66 | list_add(&netfs->link, &fscache_netfs_list); |
66 | ret = 0; | 67 | ret = 0; |
67 | 68 | ||
@@ -70,10 +71,8 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) | |||
70 | already_registered: | 71 | already_registered: |
71 | up_write(&fscache_addremove_sem); | 72 | up_write(&fscache_addremove_sem); |
72 | 73 | ||
73 | if (ret < 0) { | 74 | if (ret < 0) |
74 | kmem_cache_free(fscache_cookie_jar, netfs->primary_index); | 75 | kmem_cache_free(fscache_cookie_jar, cookie); |
75 | netfs->primary_index = NULL; | ||
76 | } | ||
77 | 76 | ||
78 | _leave(" = %d", ret); | 77 | _leave(" = %d", ret); |
79 | return ret; | 78 | return ret; |