Lines Matching refs:cache
59 int (*handler)(struct cachefiles_cache *cache, char *args);
85 struct cachefiles_cache *cache;
97 /* allocate a cache record */
98 cache = kzalloc(sizeof(struct cachefiles_cache), GFP_KERNEL);
99 if (!cache) {
104 mutex_init(&cache->daemon_mutex);
105 cache->active_nodes = RB_ROOT;
106 rwlock_init(&cache->active_lock);
107 init_waitqueue_head(&cache->daemon_pollwq);
114 cache->frun_percent = 7;
115 cache->fcull_percent = 5;
116 cache->fstop_percent = 1;
117 cache->brun_percent = 7;
118 cache->bcull_percent = 5;
119 cache->bstop_percent = 1;
121 file->private_data = cache;
122 cache->cachefilesd = file;
127 * release a cache
131 struct cachefiles_cache *cache = file->private_data;
135 ASSERT(cache);
137 set_bit(CACHEFILES_DEAD, &cache->flags);
139 cachefiles_daemon_unbind(cache);
141 ASSERT(!cache->active_nodes.rb_node);
144 cache->cachefilesd = NULL;
148 kfree(cache);
155 * read the cache state
160 struct cachefiles_cache *cache = file->private_data;
168 if (!test_bit(CACHEFILES_READY, &cache->flags))
171 /* check how much space the cache has */
172 cachefiles_has_space(cache, 0, 0);
175 f_released = atomic_xchg(&cache->f_released, 0);
176 b_released = atomic_long_xchg(&cache->b_released, 0);
177 clear_bit(CACHEFILES_STATE_CHANGED, &cache->flags);
189 test_bit(CACHEFILES_CULLING, &cache->flags) ? '1' : '0',
190 (unsigned long long) cache->frun,
191 (unsigned long long) cache->fcull,
192 (unsigned long long) cache->fstop,
193 (unsigned long long) cache->brun,
194 (unsigned long long) cache->bcull,
195 (unsigned long long) cache->bstop,
209 * command the cache
217 struct cachefiles_cache *cache = file->private_data;
223 ASSERT(cache);
225 if (test_bit(CACHEFILES_DEAD, &cache->flags))
273 mutex_lock(&cache->daemon_mutex);
276 if (!test_bit(CACHEFILES_DEAD, &cache->flags))
277 ret = cmd->handler(cache, args);
279 mutex_unlock(&cache->daemon_mutex);
293 struct cachefiles_cache *cache = file->private_data;
296 poll_wait(file, &cache->daemon_pollwq, poll);
299 if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags))
302 if (test_bit(CACHEFILES_CULLING, &cache->flags))
309 * give a range error for cache space constraints
312 static int cachefiles_daemon_range_error(struct cachefiles_cache *cache,
324 static int cachefiles_daemon_frun(struct cachefiles_cache *cache, char *args)
337 if (frun <= cache->fcull_percent || frun >= 100)
338 return cachefiles_daemon_range_error(cache, args);
340 cache->frun_percent = frun;
348 static int cachefiles_daemon_fcull(struct cachefiles_cache *cache, char *args)
361 if (fcull <= cache->fstop_percent || fcull >= cache->frun_percent)
362 return cachefiles_daemon_range_error(cache, args);
364 cache->fcull_percent = fcull;
372 static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
385 if (fstop < 0 || fstop >= cache->fcull_percent)
386 return cachefiles_daemon_range_error(cache, args);
388 cache->fstop_percent = fstop;
396 static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args)
409 if (brun <= cache->bcull_percent || brun >= 100)
410 return cachefiles_daemon_range_error(cache, args);
412 cache->brun_percent = brun;
420 static int cachefiles_daemon_bcull(struct cachefiles_cache *cache, char *args)
433 if (bcull <= cache->bstop_percent || bcull >= cache->brun_percent)
434 return cachefiles_daemon_range_error(cache, args);
436 cache->bcull_percent = bcull;
444 static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
457 if (bstop < 0 || bstop >= cache->bcull_percent)
458 return cachefiles_daemon_range_error(cache, args);
460 cache->bstop_percent = bstop;
465 * set the cache directory
468 static int cachefiles_daemon_dir(struct cachefiles_cache *cache, char *args)
479 if (cache->rootdirname) {
480 pr_err("Second cache directory specified\n");
488 cache->rootdirname = dir;
493 * set the cache security context
496 static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args)
507 if (cache->secctx) {
516 cache->secctx = secctx;
521 * set the cache tag
524 static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args)
535 if (cache->tag)
542 cache->tag = tag;
547 * request a node in the cache be culled from the current working directory
550 static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
561 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
562 pr_err("cull applied to unready cache\n");
566 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
567 pr_err("cull applied to dead cache\n");
577 cachefiles_begin_secure(cache, &saved_cred);
578 ret = cachefiles_cull(cache, path.dentry, args);
579 cachefiles_end_secure(cache, saved_cred);
599 static int cachefiles_daemon_debug(struct cachefiles_cache *cache, char *args)
622 static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
633 if (!test_bit(CACHEFILES_READY, &cache->flags)) {
634 pr_err("inuse applied to unready cache\n");
638 if (test_bit(CACHEFILES_DEAD, &cache->flags)) {
639 pr_err("inuse applied to dead cache\n");
649 cachefiles_begin_secure(cache, &saved_cred);
650 ret = cachefiles_check_in_use(cache, path.dentry, args);
651 cachefiles_end_secure(cache, saved_cred);
669 * cache
671 int cachefiles_has_space(struct cachefiles_cache *cache,
676 .mnt = cache->mnt,
677 .dentry = cache->mnt->mnt_root,
682 // (unsigned long long) cache->frun,
683 // (unsigned long long) cache->fcull,
684 // (unsigned long long) cache->fstop,
685 // (unsigned long long) cache->brun,
686 // (unsigned long long) cache->bcull,
687 // (unsigned long long) cache->bstop,
696 cachefiles_io_error(cache, "statfs failed");
701 stats.f_bavail >>= cache->bshift;
719 if (stats.f_ffree < cache->fstop ||
720 stats.f_bavail < cache->bstop)
724 if (stats.f_ffree < cache->fcull ||
725 stats.f_bavail < cache->bcull)
728 if (test_bit(CACHEFILES_CULLING, &cache->flags) &&
729 stats.f_ffree >= cache->frun &&
730 stats.f_bavail >= cache->brun &&
731 test_and_clear_bit(CACHEFILES_CULLING, &cache->flags)
734 cachefiles_state_changed(cache);
741 if (!test_and_set_bit(CACHEFILES_CULLING, &cache->flags)) {
743 cachefiles_state_changed(cache);