aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cachefiles
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2013-08-21 17:29:21 -0400
committerDavid Howells <dhowells@redhat.com>2013-09-06 04:17:30 -0400
commit5002d7bef81c9646bbb06fb57db4a100aa5a57c5 (patch)
tree7894e28d5f50756b655acf46dbed6cdd41deccec /fs/cachefiles
parentda9803bc8812f5bd3b26baaa90e515b843c65ff7 (diff)
CacheFiles: Implement interface to check cache consistency
Implement the FS-Cache interface to check the consistency of a cache object in CacheFiles. Original-author: Hongyi Jia <jiayisuse@gmail.com> Signed-off-by: David Howells <dhowells@redhat.com> cc: Hongyi Jia <jiayisuse@gmail.com> cc: Milosz Tanski <milosz@adfin.com>
Diffstat (limited to 'fs/cachefiles')
-rw-r--r--fs/cachefiles/interface.c26
-rw-r--r--fs/cachefiles/internal.h1
-rw-r--r--fs/cachefiles/xattr.c36
3 files changed, 63 insertions, 0 deletions
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index d4c1206af9fc..43eb5592cdea 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -378,6 +378,31 @@ static void cachefiles_sync_cache(struct fscache_cache *_cache)
378} 378}
379 379
380/* 380/*
381 * check if the backing cache is updated to FS-Cache
382 * - called by FS-Cache when evaluates if need to invalidate the cache
383 */
384static bool cachefiles_check_consistency(struct fscache_operation *op)
385{
386 struct cachefiles_object *object;
387 struct cachefiles_cache *cache;
388 const struct cred *saved_cred;
389 int ret;
390
391 _enter("{OBJ%x}", op->object->debug_id);
392
393 object = container_of(op->object, struct cachefiles_object, fscache);
394 cache = container_of(object->fscache.cache,
395 struct cachefiles_cache, cache);
396
397 cachefiles_begin_secure(cache, &saved_cred);
398 ret = cachefiles_check_auxdata(object);
399 cachefiles_end_secure(cache, saved_cred);
400
401 _leave(" = %d", ret);
402 return ret;
403}
404
405/*
381 * notification the attributes on an object have changed 406 * notification the attributes on an object have changed
382 * - called with reads/writes excluded by FS-Cache 407 * - called with reads/writes excluded by FS-Cache
383 */ 408 */
@@ -522,4 +547,5 @@ const struct fscache_cache_ops cachefiles_cache_ops = {
522 .write_page = cachefiles_write_page, 547 .write_page = cachefiles_write_page,
523 .uncache_page = cachefiles_uncache_page, 548 .uncache_page = cachefiles_uncache_page,
524 .dissociate_pages = cachefiles_dissociate_pages, 549 .dissociate_pages = cachefiles_dissociate_pages,
550 .check_consistency = cachefiles_check_consistency,
525}; 551};
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index 49382519907a..5349473df1b1 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -235,6 +235,7 @@ extern int cachefiles_set_object_xattr(struct cachefiles_object *object,
235 struct cachefiles_xattr *auxdata); 235 struct cachefiles_xattr *auxdata);
236extern int cachefiles_update_object_xattr(struct cachefiles_object *object, 236extern int cachefiles_update_object_xattr(struct cachefiles_object *object,
237 struct cachefiles_xattr *auxdata); 237 struct cachefiles_xattr *auxdata);
238extern int cachefiles_check_auxdata(struct cachefiles_object *object);
238extern int cachefiles_check_object_xattr(struct cachefiles_object *object, 239extern int cachefiles_check_object_xattr(struct cachefiles_object *object,
239 struct cachefiles_xattr *auxdata); 240 struct cachefiles_xattr *auxdata);
240extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, 241extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index 2476e5162609..34c88b83e39f 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -157,6 +157,42 @@ int cachefiles_update_object_xattr(struct cachefiles_object *object,
157} 157}
158 158
159/* 159/*
160 * check the consistency between the backing cache and the FS-Cache cookie
161 */
162int cachefiles_check_auxdata(struct cachefiles_object *object)
163{
164 struct cachefiles_xattr *auxbuf;
165 struct dentry *dentry = object->dentry;
166 unsigned int dlen;
167 int ret;
168
169 ASSERT(dentry);
170 ASSERT(dentry->d_inode);
171 ASSERT(object->fscache.cookie->def->check_aux);
172
173 auxbuf = kmalloc(sizeof(struct cachefiles_xattr) + 512, GFP_KERNEL);
174 if (!auxbuf)
175 return -ENOMEM;
176
177 auxbuf->len = vfs_getxattr(dentry, cachefiles_xattr_cache,
178 &auxbuf->type, 512 + 1);
179 if (auxbuf->len < 1)
180 return -ESTALE;
181
182 if (auxbuf->type != object->fscache.cookie->def->type)
183 return -ESTALE;
184
185 dlen = auxbuf->len - 1;
186 ret = fscache_check_aux(&object->fscache, &auxbuf->data, dlen);
187
188 kfree(auxbuf);
189 if (ret != FSCACHE_CHECKAUX_OKAY)
190 return -ESTALE;
191
192 return 0;
193}
194
195/*
160 * check the state xattr on a cache file 196 * check the state xattr on a cache file
161 * - return -ESTALE if the object should be deleted 197 * - return -ESTALE if the object should be deleted
162 */ 198 */