fscache, cachefiles: Store the volume coherency data

Store the volume coherency data in an xattr and check it when we rebind the
volume.  If it doesn't match the cache volume is moved to the graveyard and
rebuilt anew.

Changes
=======
ver #4:
 - Remove a couple of debugging prints.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/163967164397.1823006.2950539849831291830.stgit@warthog.procyon.org.uk/ # v3
Link: https://lore.kernel.org/r/164021563138.640689.15851092065380543119.stgit@warthog.procyon.org.uk/ # v4
This commit is contained in:
David Howells
2021-12-14 09:51:43 +00:00
parent 047487c947
commit 32e150037d
6 changed files with 157 additions and 6 deletions

View File

@@ -205,15 +205,22 @@ static struct fscache_volume *fscache_alloc_volume(const char *volume_key,
size_t klen, hlen;
char *key;
if (!coherency_data)
coherency_len = 0;
cache = fscache_lookup_cache(cache_name, false);
if (IS_ERR(cache))
return NULL;
volume = kzalloc(sizeof(*volume), GFP_KERNEL);
volume = kzalloc(struct_size(volume, coherency, coherency_len),
GFP_KERNEL);
if (!volume)
goto err_cache;
volume->cache = cache;
volume->coherency_len = coherency_len;
if (coherency_data)
memcpy(volume->coherency, coherency_data, coherency_len);
INIT_LIST_HEAD(&volume->proc_link);
INIT_WORK(&volume->work, fscache_create_volume_work);
refcount_set(&volume->ref, 1);
@@ -421,8 +428,11 @@ void __fscache_relinquish_volume(struct fscache_volume *volume,
if (WARN_ON(test_and_set_bit(FSCACHE_VOLUME_RELINQUISHED, &volume->flags)))
return;
if (invalidate)
if (invalidate) {
set_bit(FSCACHE_VOLUME_INVALIDATE, &volume->flags);
} else if (coherency_data) {
memcpy(volume->coherency, coherency_data, volume->coherency_len);
}
fscache_put_volume(volume, fscache_volume_put_relinquish);
}