Lines Matching defs: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 void cachefiles_flush_reqs(struct cachefiles_cache *cache)
138 struct xarray *xa = &cache->reqs;
166 xa_destroy(&cache->reqs);
167 xa_destroy(&cache->ondemand_ids);
170 void cachefiles_put_unbind_pincount(struct cachefiles_cache *cache)
172 if (refcount_dec_and_test(&cache->unbind_pincount)) {
173 cachefiles_daemon_unbind(cache);
175 kfree(cache);
179 void cachefiles_get_unbind_pincount(struct cachefiles_cache *cache)
181 refcount_inc(&cache->unbind_pincount);
185 * Release a cache.
189 struct cachefiles_cache *cache = file->private_data;
193 ASSERT(cache);
195 set_bit(CACHEFILES_DEAD, &cache->flags);
197 if (cachefiles_in_ondemand_mode(cache))
198 cachefiles_flush_reqs(cache);
201 cache->cachefilesd = NULL;
204 cachefiles_put_unbind_pincount(cache);
210 static ssize_t cachefiles_do_daemon_read(struct cachefiles_cache *cache,
218 /* check how much space the cache has */
219 cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check);
222 f_released = atomic_xchg(&cache->f_released, 0);
223 b_released = atomic_long_xchg(&cache->b_released, 0);
224 clear_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
236 test_bit(CACHEFILES_CULLING, &cache->flags) ? '1' : '0',
237 (unsigned long long) cache->frun,
238 (unsigned long long) cache->fcull,
239 (unsigned long long) cache->fstop,
240 (unsigned long long) cache->brun,
241 (unsigned long long) cache->bcull,
242 (unsigned long long) cache->bstop,
256 * Read the cache state.
261 struct cachefiles_cache *cache = file->private_data;
265 if (!test_bit(CACHEFILES_READY, &cache->flags))
268 if (cachefiles_in_ondemand_mode(cache))
269 return cachefiles_ondemand_daemon_read(cache, _buffer, buflen);
271 return cachefiles_do_daemon_read(cache, _buffer, buflen);
283 struct cachefiles_cache *cache = file->private_data;
289 ASSERT(cache);
291 if (test_bit(CACHEFILES_DEAD, &cache->flags))
339 mutex_lock(&cache->daemon_mutex);
342 if (!test_bit(CACHEFILES_DEAD, &cache->flags))
343 ret = cmd->handler(cache, args);
345 mutex_unlock(&cache->daemon_mutex);
359 struct cachefiles_cache *cache = file->private_data;
360 XA_STATE(xas, &cache->reqs, 0);
364 poll_wait(file, &cache->daemon_pollwq, poll);
367 if (cachefiles_in_ondemand_mode(cache)) {
368 if (!xa_empty(&cache->reqs)) {
379 if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))
383 if (test_bit(CACHEFILES_CULLING, &cache->flags))
390 * Give a range error for cache space constraints
393 static int cachefiles_daemon_range_error(struct cachefiles_cache *cache,
405 static int cachefiles_daemon_frun(struct cachefiles_cache *cache, char *args)
418 if (frun <= cache->fcull_percent || frun >= 100)
419 return cachefiles_daemon_range_error(cache, args);
421 cache->frun_percent = frun;
429 static int cachefiles_daemon_fcull(struct cachefiles_cache *cache, char *args)
442 if (fcull <= cache->fstop_percent || fcull >= cache->frun_percent)
443 return cachefiles_daemon_range_error(cache, args);
445 cache->fcull_percent = fcull;
453 static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
466 if (fstop >= cache->fcull_percent)
467 return cachefiles_daemon_range_error(cache, args);
469 cache->fstop_percent = fstop;
477 static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args)
490 if (brun <= cache->bcull_percent || brun >= 100)
491 return cachefiles_daemon_range_error(cache, args);
493 cache->brun_percent = brun;
501 static int cachefiles_daemon_bcull(struct cachefiles_cache *cache, char *args)
514 if (bcull <= cache->bstop_percent || bcull >= cache->brun_percent)
515 return cachefiles_daemon_range_error(cache, args);
517 cache->bcull_percent = bcull;
525 static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
538 if (bstop >= cache->bcull_percent)
539 return cachefiles_daemon_range_error(cache, args);
541 cache->bstop_percent = bstop;
546 * Set the cache directory
549 static int cachefiles_daemon_dir(struct cachefiles_cache *cache, char *args)
560 if (cache->rootdirname) {
561 pr_err("Second cache directory specified\n");
569 cache->rootdirname = dir;
574 * Set the cache security context
577 static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args)
588 if (cache->secctx) {
597 cache->secctx = secctx;
602 * Set the cache tag
605 static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args)
616 if (cache->tag)
623 cache->tag = tag;
628 * Request a node in the cache be culled from the current working directory
631 static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
642 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
643 pr_err("cull applied to unready cache\n");
647 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
648 pr_err("cull applied to dead cache\n");
657 cachefiles_begin_secure(cache, &saved_cred);
658 ret = cachefiles_cull(cache, path.dentry, args);
659 cachefiles_end_secure(cache, saved_cred);
679 static int cachefiles_daemon_debug(struct cachefiles_cache *cache, char *args)
702 static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
713 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
714 pr_err("inuse applied to unready cache\n");
718 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
719 pr_err("inuse applied to dead cache\n");
728 cachefiles_begin_secure(cache, &saved_cred);
729 ret = cachefiles_check_in_use(cache, path.dentry, args);
730 cachefiles_end_secure(cache, saved_cred);
747 * Bind a directory as a cache
749 static int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
752 cache->frun_percent,
753 cache->fcull_percent,
754 cache->fstop_percent,
755 cache->brun_percent,
756 cache->bcull_percent,
757 cache->bstop_percent,
760 if (cache->fstop_percent >= cache->fcull_percent ||
761 cache->fcull_percent >= cache->frun_percent ||
762 cache->frun_percent >= 100)
765 if (cache->bstop_percent >= cache->bcull_percent ||
766 cache->bcull_percent >= cache->brun_percent ||
767 cache->brun_percent >= 100)
770 if (!cache->rootdirname) {
771 pr_err("No cache directory specified\n");
776 if (test_bit(CACHEFILES_READY, &cache->flags)) {
783 set_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags);
794 if (!cache->tag) {
799 cache->tag = kstrdup("CacheFiles", GFP_KERNEL);
800 if (!cache->tag)
804 return cachefiles_add_cache(cache);
808 * Unbind a cache.
810 static void cachefiles_daemon_unbind(struct cachefiles_cache *cache)
814 if (test_bit(CACHEFILES_READY, &cache->flags))
815 cachefiles_withdraw_cache(cache);
817 cachefiles_put_directory(cache->graveyard);
818 cachefiles_put_directory(cache->store);
819 mntput(cache->mnt);
820 put_cred(cache->cache_cred);
822 kfree(cache->rootdirname);
823 kfree(cache->secctx);
824 kfree(cache->tag);