Lines Matching refs:cache

61 	int (*handler)(struct cachefiles_cache *cache, char *args);
87 * Prepare a cache for caching.
91 struct cachefiles_cache *cache;
103 /* allocate a cache record */
104 cache = kzalloc(sizeof(struct cachefiles_cache), GFP_KERNEL);
105 if (!cache) {
110 mutex_init(&cache->daemon_mutex);
111 init_waitqueue_head(&cache->daemon_pollwq);
112 INIT_LIST_HEAD(&cache->volumes);
113 INIT_LIST_HEAD(&cache->object_list);
114 spin_lock_init(&cache->object_list_lock);
115 refcount_set(&cache->unbind_pincount, 1);
116 xa_init_flags(&cache->reqs, XA_FLAGS_ALLOC);
117 xa_init_flags(&cache->ondemand_ids, XA_FLAGS_ALLOC1);
124 cache->frun_percent = 7;
125 cache->fcull_percent = 5;
126 cache->fstop_percent = 1;
127 cache->brun_percent = 7;
128 cache->bcull_percent = 5;
129 cache->bstop_percent = 1;
131 file->private_data = cache;
132 cache->cachefilesd = file;
136 static void cachefiles_flush_reqs(struct cachefiles_cache *cache)
138 struct xarray *xa = &cache->reqs;
165 xa_destroy(&cache->reqs);
166 xa_destroy(&cache->ondemand_ids);
169 void cachefiles_put_unbind_pincount(struct cachefiles_cache *cache)
171 if (refcount_dec_and_test(&cache->unbind_pincount)) {
172 cachefiles_daemon_unbind(cache);
174 kfree(cache);
178 void cachefiles_get_unbind_pincount(struct cachefiles_cache *cache)
180 refcount_inc(&cache->unbind_pincount);
184 * Release a cache.
188 struct cachefiles_cache *cache = file->private_data;
192 ASSERT(cache);
194 set_bit(CACHEFILES_DEAD, &cache->flags);
196 if (cachefiles_in_ondemand_mode(cache))
197 cachefiles_flush_reqs(cache);
200 cache->cachefilesd = NULL;
203 cachefiles_put_unbind_pincount(cache);
209 static ssize_t cachefiles_do_daemon_read(struct cachefiles_cache *cache,
217 /* check how much space the cache has */
218 cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check);
221 f_released = atomic_xchg(&cache->f_released, 0);
222 b_released = atomic_long_xchg(&cache->b_released, 0);
223 clear_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
235 test_bit(CACHEFILES_CULLING, &cache->flags) ? '1' : '0',
236 (unsigned long long) cache->frun,
237 (unsigned long long) cache->fcull,
238 (unsigned long long) cache->fstop,
239 (unsigned long long) cache->brun,
240 (unsigned long long) cache->bcull,
241 (unsigned long long) cache->bstop,
255 * Read the cache state.
260 struct cachefiles_cache *cache = file->private_data;
264 if (!test_bit(CACHEFILES_READY, &cache->flags))
267 if (cachefiles_in_ondemand_mode(cache))
268 return cachefiles_ondemand_daemon_read(cache, _buffer, buflen);
270 return cachefiles_do_daemon_read(cache, _buffer, buflen);
282 struct cachefiles_cache *cache = file->private_data;
288 ASSERT(cache);
290 if (test_bit(CACHEFILES_DEAD, &cache->flags))
338 mutex_lock(&cache->daemon_mutex);
341 if (!test_bit(CACHEFILES_DEAD, &cache->flags))
342 ret = cmd->handler(cache, args);
344 mutex_unlock(&cache->daemon_mutex);
358 struct cachefiles_cache *cache = file->private_data;
359 XA_STATE(xas, &cache->reqs, 0);
363 poll_wait(file, &cache->daemon_pollwq, poll);
366 if (cachefiles_in_ondemand_mode(cache)) {
367 if (!xa_empty(&cache->reqs)) {
378 if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))
382 if (test_bit(CACHEFILES_CULLING, &cache->flags))
389 * Give a range error for cache space constraints
392 static int cachefiles_daemon_range_error(struct cachefiles_cache *cache,
404 static int cachefiles_daemon_frun(struct cachefiles_cache *cache, char *args)
417 if (frun <= cache->fcull_percent || frun >= 100)
418 return cachefiles_daemon_range_error(cache, args);
420 cache->frun_percent = frun;
428 static int cachefiles_daemon_fcull(struct cachefiles_cache *cache, char *args)
441 if (fcull <= cache->fstop_percent || fcull >= cache->frun_percent)
442 return cachefiles_daemon_range_error(cache, args);
444 cache->fcull_percent = fcull;
452 static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
465 if (fstop >= cache->fcull_percent)
466 return cachefiles_daemon_range_error(cache, args);
468 cache->fstop_percent = fstop;
476 static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args)
489 if (brun <= cache->bcull_percent || brun >= 100)
490 return cachefiles_daemon_range_error(cache, args);
492 cache->brun_percent = brun;
500 static int cachefiles_daemon_bcull(struct cachefiles_cache *cache, char *args)
513 if (bcull <= cache->bstop_percent || bcull >= cache->brun_percent)
514 return cachefiles_daemon_range_error(cache, args);
516 cache->bcull_percent = bcull;
524 static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
537 if (bstop >= cache->bcull_percent)
538 return cachefiles_daemon_range_error(cache, args);
540 cache->bstop_percent = bstop;
545 * Set the cache directory
548 static int cachefiles_daemon_dir(struct cachefiles_cache *cache, char *args)
559 if (cache->rootdirname) {
560 pr_err("Second cache directory specified\n");
568 cache->rootdirname = dir;
573 * Set the cache security context
576 static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args)
587 if (cache->secctx) {
596 cache->secctx = secctx;
601 * Set the cache tag
604 static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args)
615 if (cache->tag)
622 cache->tag = tag;
627 * Request a node in the cache be culled from the current working directory
630 static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
641 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
642 pr_err("cull applied to unready cache\n");
646 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
647 pr_err("cull applied to dead cache\n");
656 cachefiles_begin_secure(cache, &saved_cred);
657 ret = cachefiles_cull(cache, path.dentry, args);
658 cachefiles_end_secure(cache, saved_cred);
678 static int cachefiles_daemon_debug(struct cachefiles_cache *cache, char *args)
701 static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
712 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
713 pr_err("inuse applied to unready cache\n");
717 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
718 pr_err("inuse applied to dead cache\n");
727 cachefiles_begin_secure(cache, &saved_cred);
728 ret = cachefiles_check_in_use(cache, path.dentry, args);
729 cachefiles_end_secure(cache, saved_cred);
746 * Bind a directory as a cache
748 static int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
751 cache->frun_percent,
752 cache->fcull_percent,
753 cache->fstop_percent,
754 cache->brun_percent,
755 cache->bcull_percent,
756 cache->bstop_percent,
759 if (cache->fstop_percent >= cache->fcull_percent ||
760 cache->fcull_percent >= cache->frun_percent ||
761 cache->frun_percent >= 100)
764 if (cache->bstop_percent >= cache->bcull_percent ||
765 cache->bcull_percent >= cache->brun_percent ||
766 cache->brun_percent >= 100)
769 if (!cache->rootdirname) {
770 pr_err("No cache directory specified\n");
775 if (test_bit(CACHEFILES_READY, &cache->flags)) {
782 set_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags);
793 if (!cache->tag) {
798 cache->tag = kstrdup("CacheFiles", GFP_KERNEL);
799 if (!cache->tag)
803 return cachefiles_add_cache(cache);
807 * Unbind a cache.
809 static void cachefiles_daemon_unbind(struct cachefiles_cache *cache)
813 if (test_bit(CACHEFILES_READY, &cache->flags))
814 cachefiles_withdraw_cache(cache);
816 cachefiles_put_directory(cache->graveyard);
817 cachefiles_put_directory(cache->store);
818 mntput(cache->mnt);
819 put_cred(cache->cache_cred);
821 kfree(cache->rootdirname);
822 kfree(cache->secctx);
823 kfree(cache->tag);