^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Bind and unbind a cache from the filesystem backing it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/statfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int cachefiles_daemon_add_cache(struct cachefiles_cache *caches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * bind a directory as a cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) _enter("{%u,%u,%u,%u,%u,%u},%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) cache->frun_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) cache->fcull_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) cache->fstop_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) cache->brun_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) cache->bcull_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) cache->bstop_percent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* start by checking things over */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ASSERT(cache->fstop_percent >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) cache->fstop_percent < cache->fcull_percent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) cache->fcull_percent < cache->frun_percent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) cache->frun_percent < 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ASSERT(cache->bstop_percent >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) cache->bstop_percent < cache->bcull_percent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) cache->bcull_percent < cache->brun_percent &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) cache->brun_percent < 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (*args) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) pr_err("'bind' command doesn't take an argument\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (!cache->rootdirname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) pr_err("No cache directory specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* don't permit already bound caches to be re-bound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (test_bit(CACHEFILES_READY, &cache->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) pr_err("Cache already bound\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* make sure we have copies of the tag and dirname strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!cache->tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* the tag string is released by the fops->release()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * function, so we don't release it on error here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) cache->tag = kstrdup("CacheFiles", GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!cache->tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* add the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return cachefiles_daemon_add_cache(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * add a cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct cachefiles_object *fsdef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct kstatfs stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct dentry *graveyard, *cachedir, *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) _enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* we want to work under the module's security ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ret = cachefiles_get_security_ID(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* allocate the root index object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) fsdef = kmem_cache_alloc(cachefiles_object_jar, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (!fsdef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) goto error_root_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ASSERTCMP(fsdef->backer, ==, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) atomic_set(&fsdef->usage, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) fsdef->type = FSCACHE_COOKIE_TYPE_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) _debug("- fsdef %p", fsdef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* look up the directory at the root of the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto error_open_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) cache->mnt = path.mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) root = path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* check parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (d_is_negative(root) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) !d_backing_inode(root)->i_op->lookup ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) !d_backing_inode(root)->i_op->mkdir ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) !(d_backing_inode(root)->i_opflags & IOP_XATTR) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) !root->d_sb->s_op->statfs ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) !root->d_sb->s_op->sync_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ret = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (sb_rdonly(root->d_sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* determine the security of the on-disk cache as this governs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * security ID of files we create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ret = cachefiles_determine_cache_security(cache, root, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* get the cache size and blocksize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret = vfs_statfs(&path, &stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (stats.f_bsize <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (stats.f_bsize > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) cache->bsize = stats.f_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) cache->bshift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (stats.f_bsize < PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) cache->bshift = PAGE_SHIFT - ilog2(stats.f_bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) _debug("blksize %u (shift %u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) cache->bsize, cache->bshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) _debug("size %llu, avail %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) (unsigned long long) stats.f_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) (unsigned long long) stats.f_bavail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* set up caching limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) do_div(stats.f_files, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) cache->fstop = stats.f_files * cache->fstop_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) cache->fcull = stats.f_files * cache->fcull_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cache->frun = stats.f_files * cache->frun_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) _debug("limits {%llu,%llu,%llu} files",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) (unsigned long long) cache->frun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) (unsigned long long) cache->fcull,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) (unsigned long long) cache->fstop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) stats.f_blocks >>= cache->bshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) do_div(stats.f_blocks, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cache->bstop = stats.f_blocks * cache->bstop_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) cache->bcull = stats.f_blocks * cache->bcull_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) cache->brun = stats.f_blocks * cache->brun_percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) _debug("limits {%llu,%llu,%llu} blocks",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) (unsigned long long) cache->brun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) (unsigned long long) cache->bcull,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) (unsigned long long) cache->bstop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* get the cache directory and check its type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) cachedir = cachefiles_get_directory(cache, root, "cache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (IS_ERR(cachedir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ret = PTR_ERR(cachedir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) fsdef->dentry = cachedir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) fsdef->fscache.cookie = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = cachefiles_check_object_type(fsdef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* get the graveyard directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) graveyard = cachefiles_get_directory(cache, root, "graveyard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (IS_ERR(graveyard)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ret = PTR_ERR(graveyard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) goto error_unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) cache->graveyard = graveyard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* publish the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) fscache_init_cache(&cache->cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) &cachefiles_cache_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) fsdef->dentry->d_sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) fscache_object_init(&fsdef->fscache, &fscache_fsdef_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) &cache->cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ret = fscache_add_cache(&cache->cache, &fsdef->fscache, cache->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto error_add_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) set_bit(CACHEFILES_READY, &cache->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) dput(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) pr_info("File cache on %s registered\n", cache->cache.identifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* check how much space the cache has */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) cachefiles_has_space(cache, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) error_add_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) dput(cache->graveyard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cache->graveyard = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) error_unsupported:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) mntput(cache->mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) cache->mnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) dput(fsdef->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) fsdef->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) dput(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) error_open_root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) kmem_cache_free(cachefiles_object_jar, fsdef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) error_root_object:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) pr_err("Failed to register: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * unbind a cache on fd release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) void cachefiles_daemon_unbind(struct cachefiles_cache *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) _enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (test_bit(CACHEFILES_READY, &cache->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) pr_info("File cache on %s unregistering\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) cache->cache.identifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) fscache_withdraw_cache(&cache->cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) dput(cache->graveyard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) mntput(cache->mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) kfree(cache->rootdirname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) kfree(cache->secctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) kfree(cache->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) _leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }