Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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) /* FS-Cache interface to CacheFiles
^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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) struct cachefiles_lookup_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	struct cachefiles_xattr	*auxdata;	/* auxiliary data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	char			*key;		/* key path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static int cachefiles_attr_changed(struct fscache_object *_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * allocate an object record for a cookie lookup and prepare the lookup data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct fscache_object *cachefiles_alloc_object(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct fscache_cache *_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct fscache_cookie *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct cachefiles_lookup_data *lookup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct cachefiles_xattr *auxdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned keylen, auxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	void *buffer, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	char *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	cache = container_of(_cache, struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	_enter("{%s},%p,", cache->cache.identifier, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	lookup_data = kmalloc(sizeof(*lookup_data), cachefiles_gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!lookup_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		goto nomem_lookup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	/* create a new object record and a temporary leaf image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	object = kmem_cache_alloc(cachefiles_object_jar, cachefiles_gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (!object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		goto nomem_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	ASSERTCMP(object->backer, ==, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	BUG_ON(test_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	atomic_set(&object->usage, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	fscache_object_init(&object->fscache, cookie, &cache->cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	object->type = cookie->def->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* get hold of the raw key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * - stick the length on the front and leave space on the back for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 *   encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	buffer = kmalloc((2 + 512) + 3, cachefiles_gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		goto nomem_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	keylen = cookie->key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (keylen <= sizeof(cookie->inline_key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		p = cookie->inline_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		p = cookie->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	memcpy(buffer + 2, p, keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	*(uint16_t *)buffer = keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	((char *)buffer)[keylen + 2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	((char *)buffer)[keylen + 3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	((char *)buffer)[keylen + 4] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* turn the raw key into something that can work with as a filename */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	key = cachefiles_cook_key(buffer, keylen + 2, object->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		goto nomem_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* get hold of the auxiliary data and prepend the object type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	auxdata = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	auxlen = cookie->aux_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (auxlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (auxlen <= sizeof(cookie->inline_aux))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			p = cookie->inline_aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			p = cookie->aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		memcpy(auxdata->data, p, auxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	auxdata->len = auxlen + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	auxdata->type = cookie->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	lookup_data->auxdata = auxdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	lookup_data->key = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	object->lookup_data = lookup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	_leave(" = %p [%p]", &object->fscache, lookup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return &object->fscache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) nomem_key:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) nomem_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	BUG_ON(test_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kmem_cache_free(cachefiles_object_jar, object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	fscache_object_destroyed(&cache->cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) nomem_object:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	kfree(lookup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) nomem_lookup_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	_leave(" = -ENOMEM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * attempt to look up the nominated node in this cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * - return -ETIMEDOUT to be scheduled again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int cachefiles_lookup_object(struct fscache_object *_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct cachefiles_lookup_data *lookup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct cachefiles_object *parent, *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	_enter("{OBJ%x}", _object->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	cache = container_of(_object->cache, struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	parent = container_of(_object->parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			      struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	object = container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	lookup_data = object->lookup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	ASSERTCMP(lookup_data, !=, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* look up the key, creating any missing bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ret = cachefiles_walk_to_object(parent, object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 					lookup_data->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 					lookup_data->auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/* polish off by setting the attributes of non-index files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (ret == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	    object->fscache.cookie->def->type != FSCACHE_COOKIE_TYPE_INDEX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		cachefiles_attr_changed(&object->fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (ret < 0 && ret != -ETIMEDOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (ret != -ENOBUFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			pr_warn("Lookup failed error %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		fscache_object_lookup_error(&object->fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	_leave(" [%d]", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * indication of lookup completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static void cachefiles_lookup_complete(struct fscache_object *_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	object = container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	_enter("{OBJ%x,%p}", object->fscache.debug_id, object->lookup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (object->lookup_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		kfree(object->lookup_data->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		kfree(object->lookup_data->auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		kfree(object->lookup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		object->lookup_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * increment the usage count on an inode object (may fail if unmounting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct fscache_object *cachefiles_grab_object(struct fscache_object *_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 					      enum fscache_obj_ref_trace why)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct cachefiles_object *object =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	_enter("{OBJ%x,%d}", _object->debug_id, atomic_read(&object->usage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #ifdef CACHEFILES_DEBUG_SLAB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ASSERT((atomic_read(&object->usage) & 0xffff0000) != 0x6b6b0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	u = atomic_inc_return(&object->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	trace_cachefiles_ref(object, _object->cookie,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			     (enum cachefiles_obj_ref_trace)why, u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return &object->fscache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * update the auxiliary data for an object object on disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static void cachefiles_update_object(struct fscache_object *_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct cachefiles_xattr *auxdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct fscache_cookie *cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	const void *aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	unsigned auxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	_enter("{OBJ%x}", _object->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	object = container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	cache = container_of(object->fscache.cache, struct cachefiles_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			     cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (!fscache_use_cookie(_object)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		_leave(" [relinq]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	cookie = object->fscache.cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	auxlen = cookie->aux_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (!auxlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		fscache_unuse_cookie(_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		_leave(" [no aux]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	auxdata = kmalloc(2 + auxlen + 3, cachefiles_gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!auxdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		fscache_unuse_cookie(_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		_leave(" [nomem]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	aux = (auxlen <= sizeof(cookie->inline_aux)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		cookie->inline_aux : cookie->aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	memcpy(auxdata->data, aux, auxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	fscache_unuse_cookie(_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	auxdata->len = auxlen + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	auxdata->type = cookie->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	cachefiles_update_object_xattr(object, auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	kfree(auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * discard the resources pinned by an object and effect retirement if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static void cachefiles_drop_object(struct fscache_object *_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	blkcnt_t i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	ASSERT(_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	object = container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	_enter("{OBJ%x,%d}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	       object->fscache.debug_id, atomic_read(&object->usage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	cache = container_of(object->fscache.cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			     struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #ifdef CACHEFILES_DEBUG_SLAB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	ASSERT((atomic_read(&object->usage) & 0xffff0000) != 0x6b6b0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	/* We need to tidy the object up if we did in fact manage to open it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 * It's possible for us to get here before the object is fully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	 * initialised if the parent goes away or the object gets retired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	 * before we set it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (object->dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		/* delete retired objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (test_bit(FSCACHE_OBJECT_RETIRED, &object->fscache.flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		    _object != cache->cache.fsdef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		    ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			_debug("- retire object OBJ%x", object->fscache.debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			inode = d_backing_inode(object->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				i_blocks = inode->i_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			cachefiles_delete_object(cache, object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		/* close the filesystem stuff attached to the object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		if (object->backer != object->dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			dput(object->backer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		object->backer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	/* note that the object is now inactive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (test_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		cachefiles_mark_object_inactive(cache, object, i_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	dput(object->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	object->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * dispose of a reference to an object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static void cachefiles_put_object(struct fscache_object *_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				  enum fscache_obj_ref_trace why)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct fscache_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	int u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	ASSERT(_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	object = container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	_enter("{OBJ%x,%d}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	       object->fscache.debug_id, atomic_read(&object->usage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) #ifdef CACHEFILES_DEBUG_SLAB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	ASSERT((atomic_read(&object->usage) & 0xffff0000) != 0x6b6b0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	ASSERTIFCMP(object->fscache.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		    object->fscache.parent->n_children, >, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	u = atomic_dec_return(&object->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	trace_cachefiles_ref(object, _object->cookie,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			     (enum cachefiles_obj_ref_trace)why, u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	ASSERTCMP(u, !=, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (u == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		_debug("- kill object OBJ%x", object->fscache.debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		ASSERT(!test_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		ASSERTCMP(object->fscache.parent, ==, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		ASSERTCMP(object->backer, ==, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		ASSERTCMP(object->dentry, ==, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		ASSERTCMP(object->fscache.n_ops, ==, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		ASSERTCMP(object->fscache.n_children, ==, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		if (object->lookup_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			kfree(object->lookup_data->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			kfree(object->lookup_data->auxdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			kfree(object->lookup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			object->lookup_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		cache = object->fscache.cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		fscache_object_destroy(&object->fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		kmem_cache_free(cachefiles_object_jar, object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		fscache_object_destroyed(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * sync a cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static void cachefiles_sync_cache(struct fscache_cache *_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	_enter("%p", _cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	cache = container_of(_cache, struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	/* make sure all pages pinned by operations on behalf of the netfs are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 * written to disc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	down_read(&cache->mnt->mnt_sb->s_umount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	ret = sync_filesystem(cache->mnt->mnt_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	up_read(&cache->mnt->mnt_sb->s_umount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (ret == -EIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		cachefiles_io_error(cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				    "Attempt to sync backing fs superblock"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 				    " returned error %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				    ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * check if the backing cache is updated to FS-Cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * - called by FS-Cache when evaluates if need to invalidate the cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int cachefiles_check_consistency(struct fscache_operation *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	_enter("{OBJ%x}", op->object->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	object = container_of(op->object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	cache = container_of(object->fscache.cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			     struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	ret = cachefiles_check_auxdata(object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	_leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * notification the attributes on an object have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  * - called with reads/writes excluded by FS-Cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int cachefiles_attr_changed(struct fscache_object *_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	struct iattr newattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	uint64_t ni_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	loff_t oi_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	ni_size = _object->store_limit_l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	_enter("{OBJ%x},[%llu]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	       _object->debug_id, (unsigned long long) ni_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	object = container_of(_object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	cache = container_of(object->fscache.cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			     struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (ni_size == object->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (!object->backer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	ASSERT(d_is_reg(object->backer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	fscache_set_store_limit(&object->fscache, ni_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	oi_size = i_size_read(d_backing_inode(object->backer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (oi_size == ni_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	inode_lock(d_inode(object->backer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	/* if there's an extension to a partial page at the end of the backing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	 * file, we need to discard the partial page so that we pick up new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	 * data after it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (oi_size & ~PAGE_MASK && ni_size > oi_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		_debug("discard tail %llx", oi_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		newattrs.ia_valid = ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		newattrs.ia_size = oi_size & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		ret = notify_change(object->backer, &newattrs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			goto truncate_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	newattrs.ia_valid = ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	newattrs.ia_size = ni_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	ret = notify_change(object->backer, &newattrs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) truncate_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	inode_unlock(d_inode(object->backer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (ret == -EIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		fscache_set_store_limit(&object->fscache, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		cachefiles_io_error_obj(object, "Size set failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	_leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  * Invalidate an object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static void cachefiles_invalidate_object(struct fscache_operation *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	struct cachefiles_object *object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	struct cachefiles_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	const struct cred *saved_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	uint64_t ni_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	object = container_of(op->object, struct cachefiles_object, fscache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	cache = container_of(object->fscache.cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			     struct cachefiles_cache, cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	ni_size = op->object->store_limit_l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	_enter("{OBJ%x},[%llu]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	       op->object->debug_id, (unsigned long long)ni_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (object->backer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		ASSERT(d_is_reg(object->backer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		fscache_set_store_limit(&object->fscache, ni_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		path.dentry = object->backer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		path.mnt = cache->mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		cachefiles_begin_secure(cache, &saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		ret = vfs_truncate(&path, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			ret = vfs_truncate(&path, ni_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		cachefiles_end_secure(cache, saved_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			fscache_set_store_limit(&object->fscache, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 			if (ret == -EIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 				cachefiles_io_error_obj(object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 							"Invalidate failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	fscache_op_complete(op, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * dissociate a cache from all the pages it was backing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static void cachefiles_dissociate_pages(struct fscache_cache *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) const struct fscache_cache_ops cachefiles_cache_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	.name			= "cachefiles",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	.alloc_object		= cachefiles_alloc_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.lookup_object		= cachefiles_lookup_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.lookup_complete	= cachefiles_lookup_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.grab_object		= cachefiles_grab_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.update_object		= cachefiles_update_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.invalidate_object	= cachefiles_invalidate_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	.drop_object		= cachefiles_drop_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.put_object		= cachefiles_put_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	.sync_cache		= cachefiles_sync_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	.attr_changed		= cachefiles_attr_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	.read_or_alloc_page	= cachefiles_read_or_alloc_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	.read_or_alloc_pages	= cachefiles_read_or_alloc_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	.allocate_page		= cachefiles_allocate_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	.allocate_pages		= cachefiles_allocate_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	.write_page		= cachefiles_write_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	.uncache_page		= cachefiles_uncache_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	.dissociate_pages	= cachefiles_dissociate_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	.check_consistency	= cachefiles_check_consistency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) };