summaryrefslogtreecommitdiff
path: root/fs/fscache/netfs.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-04-04 13:41:28 +0100
committerDavid Howells <dhowells@redhat.com>2018-04-04 13:41:28 +0100
commit402cb8dda949d9b8c0df20ad2527d139faad7ca1 (patch)
tree83cdb77f5490a0990eade886aa7f8dd087864996 /fs/fscache/netfs.c
parent08c2e3d087840cd1e7141b62d92f3dc897147984 (diff)
fscache: Attach the index key and aux data to the cookie
Attach copies of the index key and auxiliary data to the fscache cookie so that: (1) The callbacks to the netfs for this stuff can be eliminated. This can simplify things in the cache as the information is still available, even after the cache has relinquished the cookie. (2) Simplifies the locking requirements of accessing the information as we don't have to worry about the netfs object going away on us. (3) The cache can do lazy updating of the coherency information on disk. As long as the cache is flushed before reboot/poweroff, there's no need to update the coherency info on disk every time it changes. (4) Cookies can be hashed or put in a tree as the index key is easily available. This allows: (a) Checks for duplicate cookies can be made at the top fscache layer rather than down in the bowels of the cache backend. (b) Caching can be added to a netfs object that has a cookie if the cache is brought online after the netfs object is allocated. A certain amount of space is made in the cookie for inline copies of the data, but if it won't fit there, extra memory will be allocated for it. The downside of this is that live cache operation requires more memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Anna Schumaker <anna.schumaker@netapp.com> Tested-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'fs/fscache/netfs.c')
-rw-r--r--fs/fscache/netfs.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/fs/fscache/netfs.c b/fs/fscache/netfs.c
index c816600d1dde..a5998dfab7e7 100644
--- a/fs/fscache/netfs.c
+++ b/fs/fscache/netfs.c
@@ -37,6 +37,19 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
return -ENOMEM;
}
+ cookie->key_len = strlen(netfs->name);
+ if (cookie->key_len <= sizeof(cookie->inline_key)) {
+ memcpy(cookie->inline_key, netfs->name, strlen(netfs->name));
+ } else {
+ ret = -ENOMEM;
+ cookie->key = kmemdup(netfs->name, cookie->key_len, GFP_KERNEL);
+ if (!cookie->key)
+ goto nomem;
+ }
+
+ cookie->aux_len = sizeof(netfs->version);
+ memcpy(cookie->inline_aux, &netfs->version, cookie->aux_len);
+
/* initialise the primary index cookie */
atomic_set(&cookie->usage, 1);
atomic_set(&cookie->n_children, 0);
@@ -46,6 +59,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
cookie->parent = &fscache_fsdef_index;
cookie->netfs_data = netfs;
cookie->flags = 1 << FSCACHE_COOKIE_ENABLED;
+ cookie->type = FSCACHE_COOKIE_TYPE_INDEX;
spin_lock_init(&cookie->lock);
spin_lock_init(&cookie->stores_lock);
@@ -73,6 +87,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
already_registered:
up_write(&fscache_addremove_sem);
+nomem:
if (ret < 0)
kmem_cache_free(fscache_cookie_jar, cookie);
@@ -92,7 +107,7 @@ void __fscache_unregister_netfs(struct fscache_netfs *netfs)
down_write(&fscache_addremove_sem);
list_del(&netfs->link);
- fscache_relinquish_cookie(netfs->primary_index, 0);
+ fscache_relinquish_cookie(netfs->primary_index, NULL, false);
up_write(&fscache_addremove_sem);