Commit 8f2746bb authored by Kinglong Mee's avatar Kinglong Mee Committed by Ben Hutchings

FS-Cache: Don't override netfs's primary_index if registering failed

commit b130ed59 upstream.

Only override netfs->primary_index when registering success.
Signed-off-by: default avatarKinglong Mee <kinglongmee@gmail.com>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
[bwh: Backported to 3.2: no n_active or flags fields in fscache_cookie]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent bdb28a40
...@@ -22,6 +22,7 @@ static LIST_HEAD(fscache_netfs_list); ...@@ -22,6 +22,7 @@ static LIST_HEAD(fscache_netfs_list);
int __fscache_register_netfs(struct fscache_netfs *netfs) int __fscache_register_netfs(struct fscache_netfs *netfs)
{ {
struct fscache_netfs *ptr; struct fscache_netfs *ptr;
struct fscache_cookie *cookie;
int ret; int ret;
_enter("{%s}", netfs->name); _enter("{%s}", netfs->name);
...@@ -29,24 +30,23 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) ...@@ -29,24 +30,23 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
INIT_LIST_HEAD(&netfs->link); INIT_LIST_HEAD(&netfs->link);
/* allocate a cookie for the primary index */ /* allocate a cookie for the primary index */
netfs->primary_index = cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL);
kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL);
if (!netfs->primary_index) { if (!cookie) {
_leave(" = -ENOMEM"); _leave(" = -ENOMEM");
return -ENOMEM; return -ENOMEM;
} }
/* initialise the primary index cookie */ /* initialise the primary index cookie */
atomic_set(&netfs->primary_index->usage, 1); atomic_set(&cookie->usage, 1);
atomic_set(&netfs->primary_index->n_children, 0); atomic_set(&cookie->n_children, 0);
netfs->primary_index->def = &fscache_fsdef_netfs_def; cookie->def = &fscache_fsdef_netfs_def;
netfs->primary_index->parent = &fscache_fsdef_index; cookie->parent = &fscache_fsdef_index;
netfs->primary_index->netfs_data = netfs; cookie->netfs_data = netfs;
spin_lock_init(&netfs->primary_index->lock); spin_lock_init(&cookie->lock);
INIT_HLIST_HEAD(&netfs->primary_index->backing_objects); INIT_HLIST_HEAD(&cookie->backing_objects);
/* check the netfs type is not already present */ /* check the netfs type is not already present */
down_write(&fscache_addremove_sem); down_write(&fscache_addremove_sem);
...@@ -57,9 +57,10 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) ...@@ -57,9 +57,10 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
goto already_registered; goto already_registered;
} }
atomic_inc(&netfs->primary_index->parent->usage); atomic_inc(&cookie->parent->usage);
atomic_inc(&netfs->primary_index->parent->n_children); atomic_inc(&cookie->parent->n_children);
netfs->primary_index = cookie;
list_add(&netfs->link, &fscache_netfs_list); list_add(&netfs->link, &fscache_netfs_list);
ret = 0; ret = 0;
...@@ -69,10 +70,8 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) ...@@ -69,10 +70,8 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
already_registered: already_registered:
up_write(&fscache_addremove_sem); up_write(&fscache_addremove_sem);
if (ret < 0) { if (ret < 0)
kmem_cache_free(fscache_cookie_jar, netfs->primary_index); kmem_cache_free(fscache_cookie_jar, cookie);
netfs->primary_index = NULL;
}
_leave(" = %d", ret); _leave(" = %d", ret);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment