Lines Matching refs:cache
61 int (*handler)(struct cachefiles_cache *cache, char *args);
86 * Prepare a cache for caching.
90 struct cachefiles_cache *cache;
102 /* allocate a cache record */
103 cache = kzalloc(sizeof(struct cachefiles_cache), GFP_KERNEL);
104 if (!cache) {
109 mutex_init(&cache->daemon_mutex);
110 init_waitqueue_head(&cache->daemon_pollwq);
111 INIT_LIST_HEAD(&cache->volumes);
112 INIT_LIST_HEAD(&cache->object_list);
113 spin_lock_init(&cache->object_list_lock);
114 refcount_set(&cache->unbind_pincount, 1);
115 xa_init_flags(&cache->reqs, XA_FLAGS_ALLOC);
116 xa_init_flags(&cache->ondemand_ids, XA_FLAGS_ALLOC1);
123 cache->frun_percent = 7;
124 cache->fcull_percent = 5;
125 cache->fstop_percent = 1;
126 cache->brun_percent = 7;
127 cache->bcull_percent = 5;
128 cache->bstop_percent = 1;
130 file->private_data = cache;
131 cache->cachefilesd = file;
135 static void cachefiles_flush_reqs(struct cachefiles_cache *cache)
137 struct xarray *xa = &cache->reqs;
164 xa_destroy(&cache->reqs);
165 xa_destroy(&cache->ondemand_ids);
168 void cachefiles_put_unbind_pincount(struct cachefiles_cache *cache)
170 if (refcount_dec_and_test(&cache->unbind_pincount)) {
171 cachefiles_daemon_unbind(cache);
173 kfree(cache);
177 void cachefiles_get_unbind_pincount(struct cachefiles_cache *cache)
179 refcount_inc(&cache->unbind_pincount);
183 * Release a cache.
187 struct cachefiles_cache *cache = file->private_data;
191 ASSERT(cache);
193 set_bit(CACHEFILES_DEAD, &cache->flags);
195 if (cachefiles_in_ondemand_mode(cache))
196 cachefiles_flush_reqs(cache);
199 cache->cachefilesd = NULL;
202 cachefiles_put_unbind_pincount(cache);
208 static ssize_t cachefiles_do_daemon_read(struct cachefiles_cache *cache,
216 /* check how much space the cache has */
217 cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check);
220 f_released = atomic_xchg(&cache->f_released, 0);
221 b_released = atomic_long_xchg(&cache->b_released, 0);
222 clear_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
234 test_bit(CACHEFILES_CULLING, &cache->flags) ? '1' : '0',
235 (unsigned long long) cache->frun,
236 (unsigned long long) cache->fcull,
237 (unsigned long long) cache->fstop,
238 (unsigned long long) cache->brun,
239 (unsigned long long) cache->bcull,
240 (unsigned long long) cache->bstop,
254 * Read the cache state.
259 struct cachefiles_cache *cache = file->private_data;
263 if (!test_bit(CACHEFILES_READY, &cache->flags))
266 if (cachefiles_in_ondemand_mode(cache))
267 return cachefiles_ondemand_daemon_read(cache, _buffer, buflen);
269 return cachefiles_do_daemon_read(cache, _buffer, buflen);
281 struct cachefiles_cache *cache = file->private_data;
287 ASSERT(cache);
289 if (test_bit(CACHEFILES_DEAD, &cache->flags))
337 mutex_lock(&cache->daemon_mutex);
340 if (!test_bit(CACHEFILES_DEAD, &cache->flags))
341 ret = cmd->handler(cache, args);
343 mutex_unlock(&cache->daemon_mutex);
357 struct cachefiles_cache *cache = file->private_data;
360 poll_wait(file, &cache->daemon_pollwq, poll);
363 if (cachefiles_in_ondemand_mode(cache)) {
364 if (!xa_empty(&cache->reqs))
367 if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))
371 if (test_bit(CACHEFILES_CULLING, &cache->flags))
378 * Give a range error for cache space constraints
381 static int cachefiles_daemon_range_error(struct cachefiles_cache *cache,
393 static int cachefiles_daemon_frun(struct cachefiles_cache *cache, char *args)
406 if (frun <= cache->fcull_percent || frun >= 100)
407 return cachefiles_daemon_range_error(cache, args);
409 cache->frun_percent = frun;
417 static int cachefiles_daemon_fcull(struct cachefiles_cache *cache, char *args)
430 if (fcull <= cache->fstop_percent || fcull >= cache->frun_percent)
431 return cachefiles_daemon_range_error(cache, args);
433 cache->fcull_percent = fcull;
441 static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
454 if (fstop >= cache->fcull_percent)
455 return cachefiles_daemon_range_error(cache, args);
457 cache->fstop_percent = fstop;
465 static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args)
478 if (brun <= cache->bcull_percent || brun >= 100)
479 return cachefiles_daemon_range_error(cache, args);
481 cache->brun_percent = brun;
489 static int cachefiles_daemon_bcull(struct cachefiles_cache *cache, char *args)
502 if (bcull <= cache->bstop_percent || bcull >= cache->brun_percent)
503 return cachefiles_daemon_range_error(cache, args);
505 cache->bcull_percent = bcull;
513 static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
526 if (bstop >= cache->bcull_percent)
527 return cachefiles_daemon_range_error(cache, args);
529 cache->bstop_percent = bstop;
534 * Set the cache directory
537 static int cachefiles_daemon_dir(struct cachefiles_cache *cache, char *args)
548 if (cache->rootdirname) {
549 pr_err("Second cache directory specified\n");
557 cache->rootdirname = dir;
562 * Set the cache security context
565 static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args)
576 if (cache->secctx) {
585 cache->secctx = secctx;
590 * Set the cache tag
593 static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args)
604 if (cache->tag)
611 cache->tag = tag;
616 * Request a node in the cache be culled from the current working directory
619 static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
630 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
631 pr_err("cull applied to unready cache\n");
635 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
636 pr_err("cull applied to dead cache\n");
645 cachefiles_begin_secure(cache, &saved_cred);
646 ret = cachefiles_cull(cache, path.dentry, args);
647 cachefiles_end_secure(cache, saved_cred);
667 static int cachefiles_daemon_debug(struct cachefiles_cache *cache, char *args)
690 static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
701 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
702 pr_err("inuse applied to unready cache\n");
706 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
707 pr_err("inuse applied to dead cache\n");
716 cachefiles_begin_secure(cache, &saved_cred);
717 ret = cachefiles_check_in_use(cache, path.dentry, args);
718 cachefiles_end_secure(cache, saved_cred);
735 * Bind a directory as a cache
737 static int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
740 cache->frun_percent,
741 cache->fcull_percent,
742 cache->fstop_percent,
743 cache->brun_percent,
744 cache->bcull_percent,
745 cache->bstop_percent,
748 if (cache->fstop_percent >= cache->fcull_percent ||
749 cache->fcull_percent >= cache->frun_percent ||
750 cache->frun_percent >= 100)
753 if (cache->bstop_percent >= cache->bcull_percent ||
754 cache->bcull_percent >= cache->brun_percent ||
755 cache->brun_percent >= 100)
758 if (!cache->rootdirname) {
759 pr_err("No cache directory specified\n");
764 if (test_bit(CACHEFILES_READY, &cache->flags)) {
771 set_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags);
782 if (!cache->tag) {
787 cache->tag = kstrdup("CacheFiles", GFP_KERNEL);
788 if (!cache->tag)
792 return cachefiles_add_cache(cache);
796 * Unbind a cache.
798 static void cachefiles_daemon_unbind(struct cachefiles_cache *cache)
802 if (test_bit(CACHEFILES_READY, &cache->flags))
803 cachefiles_withdraw_cache(cache);
805 cachefiles_put_directory(cache->graveyard);
806 cachefiles_put_directory(cache->store);
807 mntput(cache->mnt);
808 put_cred(cache->cache_cred);
810 kfree(cache->rootdirname);
811 kfree(cache->secctx);
812 kfree(cache->tag);