12 #include <linux/slab.h>
16 #define list_to_page(head) (list_entry((head)->prev, struct page, lru))
23 static int cachefiles_attr_changed(
struct fscache_object *_object);
36 unsigned keylen, auxlen;
42 _enter(
"{%s},%p,", cache->
cache.identifier, cookie);
46 goto nomem_lookup_data;
58 fscache_object_init(&object->
fscache, cookie, &cache->
cache);
60 object->type = cookie->
def->type;
70 keylen = cookie->
def->get_key(cookie->
netfs_data, buffer + 2, 512);
74 ((
char *)buffer)[keylen + 2] = 0;
75 ((
char *)buffer)[keylen + 3] = 0;
76 ((
char *)buffer)[keylen + 4] = 0;
86 if (cookie->
def->get_aux) {
92 auxdata->
len = auxlen + 1;
93 auxdata->
type = cookie->
def->type;
97 object->lookup_data = lookup_data;
100 return &
object->fscache;
107 fscache_object_destroyed(&cache->
cache);
119 static int cachefiles_lookup_object(
struct fscache_object *_object)
124 const struct cred *saved_cred;
133 lookup_data =
object->lookup_data;
138 cachefiles_begin_secure(cache, &saved_cred);
142 cachefiles_end_secure(cache, saved_cred);
147 cachefiles_attr_changed(&object->
fscache);
152 "CacheFiles: Lookup failed error %d\n", ret);
153 fscache_object_lookup_error(&object->
fscache);
163 static void cachefiles_lookup_complete(
struct fscache_object *_object)
175 object->lookup_data =
NULL;
190 #ifdef CACHEFILES_DEBUG_SLAB
195 return &
object->fscache;
201 static void cachefiles_update_object(
struct fscache_object *_object)
207 const struct cred *saved_cred;
215 cookie =
object->fscache.cookie;
217 if (!cookie->
def->get_aux) {
231 auxdata->
len = auxlen + 1;
232 auxdata->
type = cookie->
def->type;
234 cachefiles_begin_secure(cache, &saved_cred);
236 cachefiles_end_secure(cache, saved_cred);
245 static void cachefiles_drop_object(
struct fscache_object *_object)
249 const struct cred *saved_cred;
261 #ifdef CACHEFILES_DEBUG_SLAB
266 if (object->
fscache.state == FSCACHE_OBJECT_RECYCLING &&
267 _object != cache->
cache.fsdef
270 cachefiles_begin_secure(cache, &saved_cred);
272 cachefiles_end_secure(cache, saved_cred);
278 object->backer =
NULL;
292 object->dentry =
NULL;
312 #ifdef CACHEFILES_DEBUG_SLAB
317 object->
fscache.parent->n_children, >, 0);
333 object->lookup_data =
NULL;
336 cache =
object->fscache.cache;
339 fscache_object_destroyed(cache);
348 static void cachefiles_sync_cache(
struct fscache_cache *_cache)
351 const struct cred *saved_cred;
360 cachefiles_begin_secure(cache, &saved_cred);
364 cachefiles_end_secure(cache, saved_cred);
368 "Attempt to sync backing fs superblock"
369 " returned error %d",
377 static int cachefiles_attr_changed(
struct fscache_object *_object)
381 const struct cred *saved_cred;
382 struct iattr newattrs;
387 _object->
cookie->def->get_attr(_object->
cookie->netfs_data, &ni_size);
390 _object->
debug_id, (
unsigned long long) ni_size);
396 if (ni_size == object->
i_size)
404 fscache_set_store_limit(&object->
fscache, ni_size);
406 oi_size = i_size_read(object->
backer->d_inode);
407 if (oi_size == ni_size)
410 cachefiles_begin_secure(cache, &saved_cred);
416 if (oi_size & ~
PAGE_MASK && ni_size > oi_size) {
417 _debug(
"discard tail %llx", oi_size);
422 goto truncate_failed;
426 newattrs.ia_size = ni_size;
431 cachefiles_end_secure(cache, saved_cred);
434 fscache_set_store_limit(&object->
fscache, 0);
446 static void cachefiles_dissociate_pages(
struct fscache_cache *cache)
452 .name =
"cachefiles",
453 .alloc_object = cachefiles_alloc_object,
454 .lookup_object = cachefiles_lookup_object,
455 .lookup_complete = cachefiles_lookup_complete,
456 .grab_object = cachefiles_grab_object,
457 .update_object = cachefiles_update_object,
458 .drop_object = cachefiles_drop_object,
459 .put_object = cachefiles_put_object,
460 .sync_cache = cachefiles_sync_cache,
461 .attr_changed = cachefiles_attr_changed,
468 .dissociate_pages = cachefiles_dissociate_pages,