Lines Matching full:cache

2 /* Manage high-level VFS aspects of a cache.
15 * Bring a cache online.
17 int cachefiles_add_cache(struct cachefiles_cache *cache) in cachefiles_add_cache() argument
28 cache_cookie = fscache_acquire_cache(cache->tag); in cachefiles_add_cache()
33 ret = cachefiles_get_security_ID(cache); in cachefiles_add_cache()
37 cachefiles_begin_secure(cache, &saved_cred); in cachefiles_add_cache()
39 /* look up the directory at the root of the cache */ in cachefiles_add_cache()
40 ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path); in cachefiles_add_cache()
44 cache->mnt = path.mnt; in cachefiles_add_cache()
49 pr_warn("File cache on idmapped mounts not supported"); in cachefiles_add_cache()
58 * - We want to be able to sync the filesystem when stopping the cache in cachefiles_add_cache()
76 /* determine the security of the on-disk cache as this governs in cachefiles_add_cache()
78 ret = cachefiles_determine_cache_security(cache, root, &saved_cred); in cachefiles_add_cache()
82 /* get the cache size and blocksize */ in cachefiles_add_cache()
95 cache->bsize = stats.f_bsize; in cachefiles_add_cache()
96 cache->bshift = ilog2(stats.f_bsize); in cachefiles_add_cache()
99 cache->bsize, cache->bshift); in cachefiles_add_cache()
107 cache->fstop = stats.f_files * cache->fstop_percent; in cachefiles_add_cache()
108 cache->fcull = stats.f_files * cache->fcull_percent; in cachefiles_add_cache()
109 cache->frun = stats.f_files * cache->frun_percent; in cachefiles_add_cache()
112 (unsigned long long) cache->frun, in cachefiles_add_cache()
113 (unsigned long long) cache->fcull, in cachefiles_add_cache()
114 (unsigned long long) cache->fstop); in cachefiles_add_cache()
117 cache->bstop = stats.f_blocks * cache->bstop_percent; in cachefiles_add_cache()
118 cache->bcull = stats.f_blocks * cache->bcull_percent; in cachefiles_add_cache()
119 cache->brun = stats.f_blocks * cache->brun_percent; in cachefiles_add_cache()
122 (unsigned long long) cache->brun, in cachefiles_add_cache()
123 (unsigned long long) cache->bcull, in cachefiles_add_cache()
124 (unsigned long long) cache->bstop); in cachefiles_add_cache()
126 /* get the cache directory and check its type */ in cachefiles_add_cache()
127 cachedir = cachefiles_get_directory(cache, root, "cache", NULL); in cachefiles_add_cache()
133 cache->store = cachedir; in cachefiles_add_cache()
136 graveyard = cachefiles_get_directory(cache, root, "graveyard", NULL); in cachefiles_add_cache()
142 cache->graveyard = graveyard; in cachefiles_add_cache()
143 cache->cache = cache_cookie; in cachefiles_add_cache()
145 ret = fscache_add_cache(cache_cookie, &cachefiles_cache_ops, cache); in cachefiles_add_cache()
150 set_bit(CACHEFILES_READY, &cache->flags); in cachefiles_add_cache()
153 pr_info("File cache on %s registered\n", cache_cookie->name); in cachefiles_add_cache()
155 /* check how much space the cache has */ in cachefiles_add_cache()
156 cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check); in cachefiles_add_cache()
157 cachefiles_end_secure(cache, saved_cred); in cachefiles_add_cache()
158 _leave(" = 0 [%px]", cache->cache); in cachefiles_add_cache()
162 cachefiles_put_directory(cache->graveyard); in cachefiles_add_cache()
163 cache->graveyard = NULL; in cachefiles_add_cache()
165 cachefiles_put_directory(cache->store); in cachefiles_add_cache()
166 cache->store = NULL; in cachefiles_add_cache()
167 mntput(cache->mnt); in cachefiles_add_cache()
168 cache->mnt = NULL; in cachefiles_add_cache()
171 cachefiles_end_secure(cache, saved_cred); in cachefiles_add_cache()
172 put_cred(cache->cache_cred); in cachefiles_add_cache()
173 cache->cache_cred = NULL; in cachefiles_add_cache()
176 cache->cache = NULL; in cachefiles_add_cache()
183 * cache
185 int cachefiles_has_space(struct cachefiles_cache *cache, in cachefiles_has_space() argument
194 .mnt = cache->mnt, in cachefiles_has_space()
195 .dentry = cache->mnt->mnt_root, in cachefiles_has_space()
199 // (unsigned long long) cache->frun, in cachefiles_has_space()
200 // (unsigned long long) cache->fcull, in cachefiles_has_space()
201 // (unsigned long long) cache->fstop, in cachefiles_has_space()
202 // (unsigned long long) cache->brun, in cachefiles_has_space()
203 // (unsigned long long) cache->bcull, in cachefiles_has_space()
204 // (unsigned long long) cache->bstop, in cachefiles_has_space()
215 cachefiles_io_error(cache, "statfs failed"); in cachefiles_has_space()
221 b_writing = atomic_long_read(&cache->b_writing); in cachefiles_has_space()
243 if (stats.f_ffree < cache->fstop || in cachefiles_has_space()
244 b_avail < cache->bstop) in cachefiles_has_space()
248 if (stats.f_ffree < cache->fcull || in cachefiles_has_space()
249 b_avail < cache->bcull) in cachefiles_has_space()
252 if (test_bit(CACHEFILES_CULLING, &cache->flags) && in cachefiles_has_space()
253 stats.f_ffree >= cache->frun && in cachefiles_has_space()
254 b_avail >= cache->brun && in cachefiles_has_space()
255 test_and_clear_bit(CACHEFILES_CULLING, &cache->flags) in cachefiles_has_space()
258 cachefiles_state_changed(cache); in cachefiles_has_space()
276 if (!test_and_set_bit(CACHEFILES_CULLING, &cache->flags)) { in cachefiles_has_space()
277 _debug("### CULL CACHE ###"); in cachefiles_has_space()
278 cachefiles_state_changed(cache); in cachefiles_has_space()
288 static void cachefiles_withdraw_objects(struct cachefiles_cache *cache) in cachefiles_withdraw_objects() argument
295 spin_lock(&cache->object_list_lock); in cachefiles_withdraw_objects()
297 while (!list_empty(&cache->object_list)) { in cachefiles_withdraw_objects()
298 object = list_first_entry(&cache->object_list, in cachefiles_withdraw_objects()
305 spin_unlock(&cache->object_list_lock); in cachefiles_withdraw_objects()
307 spin_lock(&cache->object_list_lock); in cachefiles_withdraw_objects()
311 spin_unlock(&cache->object_list_lock); in cachefiles_withdraw_objects()
318 static void cachefiles_withdraw_fscache_volumes(struct cachefiles_cache *cache) in cachefiles_withdraw_fscache_volumes() argument
326 spin_lock(&cache->object_list_lock); in cachefiles_withdraw_fscache_volumes()
327 list_for_each(cur, &cache->volumes) { in cachefiles_withdraw_fscache_volumes()
336 spin_unlock(&cache->object_list_lock); in cachefiles_withdraw_fscache_volumes()
342 spin_unlock(&cache->object_list_lock); in cachefiles_withdraw_fscache_volumes()
350 static void cachefiles_withdraw_volumes(struct cachefiles_cache *cache) in cachefiles_withdraw_volumes() argument
358 spin_lock(&cache->object_list_lock); in cachefiles_withdraw_volumes()
359 if (!list_empty(&cache->volumes)) { in cachefiles_withdraw_volumes()
360 volume = list_first_entry(&cache->volumes, in cachefiles_withdraw_volumes()
365 spin_unlock(&cache->object_list_lock); in cachefiles_withdraw_volumes()
371 spin_unlock(&cache->object_list_lock); in cachefiles_withdraw_volumes()
383 * Sync a cache to backing disk.
385 static void cachefiles_sync_cache(struct cachefiles_cache *cache) in cachefiles_sync_cache() argument
390 _enter("%s", cache->cache->name); in cachefiles_sync_cache()
394 cachefiles_begin_secure(cache, &saved_cred); in cachefiles_sync_cache()
395 down_read(&cache->mnt->mnt_sb->s_umount); in cachefiles_sync_cache()
396 ret = sync_filesystem(cache->mnt->mnt_sb); in cachefiles_sync_cache()
397 up_read(&cache->mnt->mnt_sb->s_umount); in cachefiles_sync_cache()
398 cachefiles_end_secure(cache, saved_cred); in cachefiles_sync_cache()
401 cachefiles_io_error(cache, in cachefiles_sync_cache()
407 * Withdraw cache objects.
409 void cachefiles_withdraw_cache(struct cachefiles_cache *cache) in cachefiles_withdraw_cache() argument
411 struct fscache_cache *fscache = cache->cache; in cachefiles_withdraw_cache()
413 pr_info("File cache on %s unregistering\n", fscache->name); in cachefiles_withdraw_cache()
416 cachefiles_withdraw_fscache_volumes(cache); in cachefiles_withdraw_cache()
419 * cache - which we do by passing them off to thread pool to be in cachefiles_withdraw_cache()
421 cachefiles_withdraw_objects(cache); in cachefiles_withdraw_cache()
424 cachefiles_withdraw_volumes(cache); in cachefiles_withdraw_cache()
425 cachefiles_sync_cache(cache); in cachefiles_withdraw_cache()
426 cache->cache = NULL; in cachefiles_withdraw_cache()