Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 2 | /* netfs cookie management |
| 3 | * |
| 4 | * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
| 6 | * |
Mauro Carvalho Chehab | efc930f | 2020-04-27 23:16:55 +0200 | [diff] [blame] | 7 | * See Documentation/filesystems/caching/netfs-api.rst for more information on |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 8 | * the netfs API. |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #define FSCACHE_DEBUG_LEVEL COOKIE |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include "internal.h" |
| 15 | |
| 16 | struct kmem_cache *fscache_cookie_jar; |
| 17 | |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 18 | static atomic_t fscache_object_debug_id = ATOMIC_INIT(0); |
| 19 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 20 | #define fscache_cookie_hash_shift 15 |
| 21 | static struct hlist_bl_head fscache_cookie_hash[1 << fscache_cookie_hash_shift]; |
David Howells | 884a768 | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 22 | static LIST_HEAD(fscache_cookies); |
| 23 | static DEFINE_RWLOCK(fscache_cookies_lock); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 24 | |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 25 | static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, |
| 26 | loff_t object_size); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 27 | static int fscache_alloc_object(struct fscache_cache *cache, |
| 28 | struct fscache_cookie *cookie); |
| 29 | static int fscache_attach_object(struct fscache_cookie *cookie, |
| 30 | struct fscache_object *object); |
| 31 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 32 | static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix) |
| 33 | { |
David Howells | 2908f5e | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 34 | struct fscache_object *object; |
| 35 | struct hlist_node *o; |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 36 | const u8 *k; |
| 37 | unsigned loop; |
| 38 | |
David Howells | 2908f5e | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 39 | pr_err("%c-cookie c=%08x [p=%08x fl=%lx nc=%u na=%u]\n", |
| 40 | prefix, |
| 41 | cookie->debug_id, |
| 42 | cookie->parent ? cookie->parent->debug_id : 0, |
| 43 | cookie->flags, |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 44 | atomic_read(&cookie->n_children), |
| 45 | atomic_read(&cookie->n_active)); |
David Howells | 2908f5e | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 46 | pr_err("%c-cookie d=%p{%s} n=%p\n", |
| 47 | prefix, |
| 48 | cookie->def, |
| 49 | cookie->def ? cookie->def->name : "?", |
| 50 | cookie->netfs_data); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 51 | |
David Howells | 2908f5e | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 52 | o = READ_ONCE(cookie->backing_objects.first); |
| 53 | if (o) { |
| 54 | object = hlist_entry(o, struct fscache_object, cookie_link); |
| 55 | pr_err("%c-cookie o=%u\n", prefix, object->debug_id); |
| 56 | } |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 57 | |
| 58 | pr_err("%c-key=[%u] '", prefix, cookie->key_len); |
| 59 | k = (cookie->key_len <= sizeof(cookie->inline_key)) ? |
| 60 | cookie->inline_key : cookie->key; |
| 61 | for (loop = 0; loop < cookie->key_len; loop++) |
| 62 | pr_cont("%02x", k[loop]); |
| 63 | pr_cont("'\n"); |
| 64 | } |
| 65 | |
| 66 | void fscache_free_cookie(struct fscache_cookie *cookie) |
| 67 | { |
| 68 | if (cookie) { |
| 69 | BUG_ON(!hlist_empty(&cookie->backing_objects)); |
David Howells | 884a768 | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 70 | write_lock(&fscache_cookies_lock); |
| 71 | list_del(&cookie->proc_link); |
| 72 | write_unlock(&fscache_cookies_lock); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 73 | if (cookie->aux_len > sizeof(cookie->inline_aux)) |
| 74 | kfree(cookie->aux); |
| 75 | if (cookie->key_len > sizeof(cookie->inline_key)) |
| 76 | kfree(cookie->key); |
| 77 | kmem_cache_free(fscache_cookie_jar, cookie); |
| 78 | } |
| 79 | } |
| 80 | |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 81 | /* |
Eric Sandeen | fa520c4 | 2018-10-17 15:23:59 +0100 | [diff] [blame] | 82 | * Set the index key in a cookie. The cookie struct has space for a 16-byte |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 83 | * key plus length and hash, but if that's not big enough, it's instead a |
| 84 | * pointer to a buffer containing 3 bytes of hash, 1 byte of length and then |
| 85 | * the key data. |
| 86 | */ |
| 87 | static int fscache_set_key(struct fscache_cookie *cookie, |
| 88 | const void *index_key, size_t index_key_len) |
| 89 | { |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 90 | u32 *buf; |
Eric Sandeen | fa520c4 | 2018-10-17 15:23:59 +0100 | [diff] [blame] | 91 | int bufs; |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 92 | |
Eric Sandeen | fa520c4 | 2018-10-17 15:23:59 +0100 | [diff] [blame] | 93 | bufs = DIV_ROUND_UP(index_key_len, sizeof(*buf)); |
| 94 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 95 | if (index_key_len > sizeof(cookie->inline_key)) { |
Eric Sandeen | fa520c4 | 2018-10-17 15:23:59 +0100 | [diff] [blame] | 96 | buf = kcalloc(bufs, sizeof(*buf), GFP_KERNEL); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 97 | if (!buf) |
| 98 | return -ENOMEM; |
| 99 | cookie->key = buf; |
| 100 | } else { |
| 101 | buf = (u32 *)cookie->inline_key; |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | memcpy(buf, index_key, index_key_len); |
David Howells | 35b7257 | 2021-06-17 14:21:00 +0100 | [diff] [blame] | 105 | cookie->key_hash = fscache_hash(0, buf, bufs); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static long fscache_compare_cookie(const struct fscache_cookie *a, |
| 110 | const struct fscache_cookie *b) |
| 111 | { |
| 112 | const void *ka, *kb; |
| 113 | |
| 114 | if (a->key_hash != b->key_hash) |
| 115 | return (long)a->key_hash - (long)b->key_hash; |
| 116 | if (a->parent != b->parent) |
| 117 | return (long)a->parent - (long)b->parent; |
| 118 | if (a->key_len != b->key_len) |
| 119 | return (long)a->key_len - (long)b->key_len; |
| 120 | if (a->type != b->type) |
| 121 | return (long)a->type - (long)b->type; |
| 122 | |
| 123 | if (a->key_len <= sizeof(a->inline_key)) { |
| 124 | ka = &a->inline_key; |
| 125 | kb = &b->inline_key; |
| 126 | } else { |
| 127 | ka = a->key; |
| 128 | kb = b->key; |
| 129 | } |
| 130 | return memcmp(ka, kb, a->key_len); |
| 131 | } |
| 132 | |
David Howells | 2908f5e | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 133 | static atomic_t fscache_cookie_debug_id = ATOMIC_INIT(1); |
| 134 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 135 | /* |
| 136 | * Allocate a cookie. |
| 137 | */ |
| 138 | struct fscache_cookie *fscache_alloc_cookie( |
| 139 | struct fscache_cookie *parent, |
| 140 | const struct fscache_cookie_def *def, |
| 141 | const void *index_key, size_t index_key_len, |
| 142 | const void *aux_data, size_t aux_data_len, |
| 143 | void *netfs_data, |
| 144 | loff_t object_size) |
| 145 | { |
| 146 | struct fscache_cookie *cookie; |
| 147 | |
| 148 | /* allocate and initialise a cookie */ |
David Howells | 1ff2288 | 2018-10-17 15:23:45 +0100 | [diff] [blame] | 149 | cookie = kmem_cache_zalloc(fscache_cookie_jar, GFP_KERNEL); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 150 | if (!cookie) |
| 151 | return NULL; |
| 152 | |
| 153 | cookie->key_len = index_key_len; |
| 154 | cookie->aux_len = aux_data_len; |
| 155 | |
| 156 | if (fscache_set_key(cookie, index_key, index_key_len) < 0) |
| 157 | goto nomem; |
| 158 | |
| 159 | if (cookie->aux_len <= sizeof(cookie->inline_aux)) { |
| 160 | memcpy(cookie->inline_aux, aux_data, cookie->aux_len); |
| 161 | } else { |
| 162 | cookie->aux = kmemdup(aux_data, cookie->aux_len, GFP_KERNEL); |
| 163 | if (!cookie->aux) |
| 164 | goto nomem; |
| 165 | } |
| 166 | |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 167 | refcount_set(&cookie->ref, 1); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 168 | atomic_set(&cookie->n_children, 0); |
David Howells | 2908f5e | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 169 | cookie->debug_id = atomic_inc_return(&fscache_cookie_debug_id); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 170 | |
| 171 | /* We keep the active count elevated until relinquishment to prevent an |
| 172 | * attempt to wake up every time the object operations queue quiesces. |
| 173 | */ |
| 174 | atomic_set(&cookie->n_active, 1); |
| 175 | |
| 176 | cookie->def = def; |
| 177 | cookie->parent = parent; |
| 178 | cookie->netfs_data = netfs_data; |
| 179 | cookie->flags = (1 << FSCACHE_COOKIE_NO_DATA_YET); |
| 180 | cookie->type = def->type; |
David Howells | 1ff2288 | 2018-10-17 15:23:45 +0100 | [diff] [blame] | 181 | spin_lock_init(&cookie->lock); |
| 182 | spin_lock_init(&cookie->stores_lock); |
| 183 | INIT_HLIST_HEAD(&cookie->backing_objects); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 184 | |
| 185 | /* radix tree insertion won't use the preallocation pool unless it's |
| 186 | * told it may not wait */ |
| 187 | INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); |
David Howells | 884a768 | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 188 | |
| 189 | write_lock(&fscache_cookies_lock); |
| 190 | list_add_tail(&cookie->proc_link, &fscache_cookies); |
| 191 | write_unlock(&fscache_cookies_lock); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 192 | return cookie; |
| 193 | |
| 194 | nomem: |
| 195 | fscache_free_cookie(cookie); |
| 196 | return NULL; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Attempt to insert the new cookie into the hash. If there's a collision, we |
| 201 | * return the old cookie if it's not in use and an error otherwise. |
| 202 | */ |
| 203 | struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate) |
| 204 | { |
| 205 | struct fscache_cookie *cursor; |
| 206 | struct hlist_bl_head *h; |
| 207 | struct hlist_bl_node *p; |
| 208 | unsigned int bucket; |
| 209 | |
| 210 | bucket = candidate->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); |
| 211 | h = &fscache_cookie_hash[bucket]; |
| 212 | |
| 213 | hlist_bl_lock(h); |
| 214 | hlist_bl_for_each_entry(cursor, p, h, hash_link) { |
| 215 | if (fscache_compare_cookie(candidate, cursor) == 0) |
| 216 | goto collision; |
| 217 | } |
| 218 | |
| 219 | __set_bit(FSCACHE_COOKIE_ACQUIRED, &candidate->flags); |
| 220 | fscache_cookie_get(candidate->parent, fscache_cookie_get_acquire_parent); |
| 221 | atomic_inc(&candidate->parent->n_children); |
| 222 | hlist_bl_add_head(&candidate->hash_link, h); |
| 223 | hlist_bl_unlock(h); |
| 224 | return candidate; |
| 225 | |
| 226 | collision: |
| 227 | if (test_and_set_bit(FSCACHE_COOKIE_ACQUIRED, &cursor->flags)) { |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 228 | trace_fscache_cookie(cursor->debug_id, refcount_read(&cursor->ref), |
David Howells | 33cba85 | 2021-06-18 11:19:49 +0100 | [diff] [blame] | 229 | fscache_cookie_collision); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 230 | pr_err("Duplicate cookie detected\n"); |
| 231 | fscache_print_cookie(cursor, 'O'); |
| 232 | fscache_print_cookie(candidate, 'N'); |
| 233 | hlist_bl_unlock(h); |
| 234 | return NULL; |
| 235 | } |
| 236 | |
| 237 | fscache_cookie_get(cursor, fscache_cookie_get_reacquire); |
| 238 | hlist_bl_unlock(h); |
| 239 | return cursor; |
| 240 | } |
| 241 | |
| 242 | /* |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 243 | * request a cookie to represent an object (index, datafile, xattr, etc) |
| 244 | * - parent specifies the parent object |
| 245 | * - the top level index cookie for each netfs is stored in the fscache_netfs |
| 246 | * struct upon registration |
| 247 | * - def points to the definition |
| 248 | * - the netfs_data will be passed to the functions pointed to in *def |
| 249 | * - all attached caches will be searched to see if they contain this object |
| 250 | * - index objects aren't stored on disk until there's a dependent file that |
| 251 | * needs storing |
| 252 | * - other objects are stored in a selected cache immediately, and all the |
| 253 | * indices forming the path to it are instantiated if necessary |
| 254 | * - we never let on to the netfs about errors |
| 255 | * - we may set a negative cookie pointer, but that's okay |
| 256 | */ |
| 257 | struct fscache_cookie *__fscache_acquire_cookie( |
| 258 | struct fscache_cookie *parent, |
| 259 | const struct fscache_cookie_def *def, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 260 | const void *index_key, size_t index_key_len, |
| 261 | const void *aux_data, size_t aux_data_len, |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 262 | void *netfs_data, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 263 | loff_t object_size, |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 264 | bool enable) |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 265 | { |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 266 | struct fscache_cookie *candidate, *cookie; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 267 | |
| 268 | BUG_ON(!def); |
| 269 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 270 | _enter("{%s},{%s},%p,%u", |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 271 | parent ? (char *) parent->def->name : "<no-parent>", |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 272 | def->name, netfs_data, enable); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 273 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 274 | if (!index_key || !index_key_len || index_key_len > 255 || aux_data_len > 255) |
| 275 | return NULL; |
| 276 | if (!aux_data || !aux_data_len) { |
| 277 | aux_data = NULL; |
| 278 | aux_data_len = 0; |
| 279 | } |
| 280 | |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 281 | fscache_stat(&fscache_n_acquires); |
| 282 | |
| 283 | /* if there's no parent cookie, then we don't create one here either */ |
| 284 | if (!parent) { |
| 285 | fscache_stat(&fscache_n_acquires_null); |
| 286 | _leave(" [no parent]"); |
| 287 | return NULL; |
| 288 | } |
| 289 | |
| 290 | /* validate the definition */ |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 291 | BUG_ON(!def->name[0]); |
| 292 | |
| 293 | BUG_ON(def->type == FSCACHE_COOKIE_TYPE_INDEX && |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 294 | parent->type != FSCACHE_COOKIE_TYPE_INDEX); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 295 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 296 | candidate = fscache_alloc_cookie(parent, def, |
| 297 | index_key, index_key_len, |
| 298 | aux_data, aux_data_len, |
| 299 | netfs_data, object_size); |
| 300 | if (!candidate) { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 301 | fscache_stat(&fscache_n_acquires_oom); |
| 302 | _leave(" [ENOMEM]"); |
| 303 | return NULL; |
| 304 | } |
| 305 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 306 | cookie = fscache_hash_cookie(candidate); |
| 307 | if (!cookie) { |
David Howells | 33cba85 | 2021-06-18 11:19:49 +0100 | [diff] [blame] | 308 | trace_fscache_cookie(candidate->debug_id, 1, |
| 309 | fscache_cookie_discard); |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 310 | goto out; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 311 | } |
| 312 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 313 | if (cookie == candidate) |
| 314 | candidate = NULL; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 315 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 316 | switch (cookie->type) { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 317 | case FSCACHE_COOKIE_TYPE_INDEX: |
| 318 | fscache_stat(&fscache_n_cookie_index); |
| 319 | break; |
| 320 | case FSCACHE_COOKIE_TYPE_DATAFILE: |
| 321 | fscache_stat(&fscache_n_cookie_data); |
| 322 | break; |
| 323 | default: |
| 324 | fscache_stat(&fscache_n_cookie_special); |
| 325 | break; |
| 326 | } |
| 327 | |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 328 | trace_fscache_acquire(cookie); |
| 329 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 330 | if (enable) { |
| 331 | /* if the object is an index then we need do nothing more here |
| 332 | * - we create indices on disk when we need them as an index |
| 333 | * may exist in multiple caches */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 334 | if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 335 | if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) { |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 336 | set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); |
| 337 | } else { |
| 338 | atomic_dec(&parent->n_children); |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 339 | fscache_cookie_put(cookie, |
| 340 | fscache_cookie_put_acquire_nobufs); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 341 | fscache_stat(&fscache_n_acquires_nobufs); |
| 342 | _leave(" = NULL"); |
| 343 | return NULL; |
| 344 | } |
| 345 | } else { |
| 346 | set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | fscache_stat(&fscache_n_acquires_ok); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 351 | |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 352 | out: |
| 353 | fscache_free_cookie(candidate); |
| 354 | return cookie; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 355 | } |
| 356 | EXPORT_SYMBOL(__fscache_acquire_cookie); |
| 357 | |
| 358 | /* |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 359 | * Enable a cookie to permit it to accept new operations. |
| 360 | */ |
| 361 | void __fscache_enable_cookie(struct fscache_cookie *cookie, |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 362 | const void *aux_data, |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 363 | loff_t object_size, |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 364 | bool (*can_enable)(void *data), |
| 365 | void *data) |
| 366 | { |
David Howells | c97a72d | 2020-10-19 21:32:55 +0100 | [diff] [blame] | 367 | _enter("%x", cookie->debug_id); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 368 | |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 369 | trace_fscache_enable(cookie); |
| 370 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 371 | wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 372 | TASK_UNINTERRUPTIBLE); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 373 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 374 | fscache_update_aux(cookie, aux_data); |
| 375 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 376 | if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) |
| 377 | goto out_unlock; |
| 378 | |
| 379 | if (can_enable && !can_enable(data)) { |
| 380 | /* The netfs decided it didn't want to enable after all */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 381 | } else if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) { |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 382 | /* Wait for outstanding disablement to complete */ |
| 383 | __fscache_wait_on_invalidate(cookie); |
| 384 | |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 385 | if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 386 | set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); |
| 387 | } else { |
| 388 | set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); |
| 389 | } |
| 390 | |
| 391 | out_unlock: |
| 392 | clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); |
| 393 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); |
| 394 | } |
| 395 | EXPORT_SYMBOL(__fscache_enable_cookie); |
| 396 | |
| 397 | /* |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 398 | * acquire a non-index cookie |
| 399 | * - this must make sure the index chain is instantiated and instantiate the |
| 400 | * object representation too |
| 401 | */ |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 402 | static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie, |
| 403 | loff_t object_size) |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 404 | { |
| 405 | struct fscache_object *object; |
| 406 | struct fscache_cache *cache; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 407 | int ret; |
| 408 | |
| 409 | _enter(""); |
| 410 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 411 | set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 412 | |
| 413 | /* now we need to see whether the backing objects for this cookie yet |
| 414 | * exist, if not there'll be nothing to search */ |
| 415 | down_read(&fscache_addremove_sem); |
| 416 | |
| 417 | if (list_empty(&fscache_cache_list)) { |
| 418 | up_read(&fscache_addremove_sem); |
| 419 | _leave(" = 0 [no caches]"); |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | /* select a cache in which to store the object */ |
| 424 | cache = fscache_select_cache_for_object(cookie->parent); |
| 425 | if (!cache) { |
| 426 | up_read(&fscache_addremove_sem); |
| 427 | fscache_stat(&fscache_n_acquires_no_cache); |
| 428 | _leave(" = -ENOMEDIUM [no cache]"); |
| 429 | return -ENOMEDIUM; |
| 430 | } |
| 431 | |
| 432 | _debug("cache %s", cache->tag->name); |
| 433 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 434 | set_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 435 | |
| 436 | /* ask the cache to allocate objects for this cookie and its parent |
| 437 | * chain */ |
| 438 | ret = fscache_alloc_object(cache, cookie); |
| 439 | if (ret < 0) { |
| 440 | up_read(&fscache_addremove_sem); |
| 441 | _leave(" = %d", ret); |
| 442 | return ret; |
| 443 | } |
| 444 | |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 445 | spin_lock(&cookie->lock); |
| 446 | if (hlist_empty(&cookie->backing_objects)) { |
| 447 | spin_unlock(&cookie->lock); |
| 448 | goto unavailable; |
| 449 | } |
| 450 | |
| 451 | object = hlist_entry(cookie->backing_objects.first, |
| 452 | struct fscache_object, cookie_link); |
| 453 | |
David Howells | ee1235a | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 454 | fscache_set_store_limit(object, object_size); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 455 | |
| 456 | /* initiate the process of looking up all the objects in the chain |
| 457 | * (done by fscache_initialise_object()) */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 458 | fscache_raise_event(object, FSCACHE_OBJECT_EV_NEW_CHILD); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 459 | |
| 460 | spin_unlock(&cookie->lock); |
| 461 | |
| 462 | /* we may be required to wait for lookup to complete at this point */ |
| 463 | if (!fscache_defer_lookup) { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 464 | wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP, |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 465 | TASK_UNINTERRUPTIBLE); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 466 | if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags)) |
| 467 | goto unavailable; |
| 468 | } |
| 469 | |
| 470 | up_read(&fscache_addremove_sem); |
| 471 | _leave(" = 0 [deferred]"); |
| 472 | return 0; |
| 473 | |
| 474 | unavailable: |
| 475 | up_read(&fscache_addremove_sem); |
| 476 | _leave(" = -ENOBUFS"); |
| 477 | return -ENOBUFS; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * recursively allocate cache object records for a cookie/cache combination |
| 482 | * - caller must be holding the addremove sem |
| 483 | */ |
| 484 | static int fscache_alloc_object(struct fscache_cache *cache, |
| 485 | struct fscache_cookie *cookie) |
| 486 | { |
| 487 | struct fscache_object *object; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 488 | int ret; |
| 489 | |
David Howells | c97a72d | 2020-10-19 21:32:55 +0100 | [diff] [blame] | 490 | _enter("%s,%x{%s}", cache->tag->name, cookie->debug_id, cookie->def->name); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 491 | |
| 492 | spin_lock(&cookie->lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 493 | hlist_for_each_entry(object, &cookie->backing_objects, |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 494 | cookie_link) { |
| 495 | if (object->cache == cache) |
| 496 | goto object_already_extant; |
| 497 | } |
| 498 | spin_unlock(&cookie->lock); |
| 499 | |
| 500 | /* ask the cache to allocate an object (we may end up with duplicate |
| 501 | * objects at this stage, but we sort that out later) */ |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 502 | fscache_stat(&fscache_n_cop_alloc_object); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 503 | object = cache->ops->alloc_object(cache, cookie); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 504 | fscache_stat_d(&fscache_n_cop_alloc_object); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 505 | if (IS_ERR(object)) { |
| 506 | fscache_stat(&fscache_n_object_no_alloc); |
| 507 | ret = PTR_ERR(object); |
| 508 | goto error; |
| 509 | } |
| 510 | |
Kiran Kumar Modukuri | f29507c | 2018-06-21 13:31:44 -0700 | [diff] [blame] | 511 | ASSERTCMP(object->cookie, ==, cookie); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 512 | fscache_stat(&fscache_n_object_alloc); |
| 513 | |
| 514 | object->debug_id = atomic_inc_return(&fscache_object_debug_id); |
| 515 | |
| 516 | _debug("ALLOC OBJ%x: %s {%lx}", |
| 517 | object->debug_id, cookie->def->name, object->events); |
| 518 | |
| 519 | ret = fscache_alloc_object(cache, cookie->parent); |
| 520 | if (ret < 0) |
| 521 | goto error_put; |
| 522 | |
| 523 | /* only attach if we managed to allocate all we needed, otherwise |
| 524 | * discard the object we just allocated and instead use the one |
| 525 | * attached to the cookie */ |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 526 | if (fscache_attach_object(cookie, object) < 0) { |
| 527 | fscache_stat(&fscache_n_cop_put_object); |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 528 | cache->ops->put_object(object, fscache_obj_put_attach_fail); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 529 | fscache_stat_d(&fscache_n_cop_put_object); |
| 530 | } |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 531 | |
| 532 | _leave(" = 0"); |
| 533 | return 0; |
| 534 | |
| 535 | object_already_extant: |
| 536 | ret = -ENOBUFS; |
David Howells | 8702152 | 2015-02-24 10:52:51 +0000 | [diff] [blame] | 537 | if (fscache_object_is_dying(object) || |
| 538 | fscache_cache_is_broken(object)) { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 539 | spin_unlock(&cookie->lock); |
| 540 | goto error; |
| 541 | } |
| 542 | spin_unlock(&cookie->lock); |
| 543 | _leave(" = 0 [found]"); |
| 544 | return 0; |
| 545 | |
| 546 | error_put: |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 547 | fscache_stat(&fscache_n_cop_put_object); |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 548 | cache->ops->put_object(object, fscache_obj_put_alloc_fail); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 549 | fscache_stat_d(&fscache_n_cop_put_object); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 550 | error: |
| 551 | _leave(" = %d", ret); |
| 552 | return ret; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * attach a cache object to a cookie |
| 557 | */ |
| 558 | static int fscache_attach_object(struct fscache_cookie *cookie, |
| 559 | struct fscache_object *object) |
| 560 | { |
| 561 | struct fscache_object *p; |
| 562 | struct fscache_cache *cache = object->cache; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 563 | int ret; |
| 564 | |
| 565 | _enter("{%s},{OBJ%x}", cookie->def->name, object->debug_id); |
| 566 | |
Kiran Kumar Modukuri | f29507c | 2018-06-21 13:31:44 -0700 | [diff] [blame] | 567 | ASSERTCMP(object->cookie, ==, cookie); |
| 568 | |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 569 | spin_lock(&cookie->lock); |
| 570 | |
| 571 | /* there may be multiple initial creations of this object, but we only |
| 572 | * want one */ |
| 573 | ret = -EEXIST; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 574 | hlist_for_each_entry(p, &cookie->backing_objects, cookie_link) { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 575 | if (p->cache == object->cache) { |
David Howells | 493f7bc | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 576 | if (fscache_object_is_dying(p)) |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 577 | ret = -ENOBUFS; |
| 578 | goto cant_attach_object; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | /* pin the parent object */ |
| 583 | spin_lock_nested(&cookie->parent->lock, 1); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 584 | hlist_for_each_entry(p, &cookie->parent->backing_objects, |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 585 | cookie_link) { |
| 586 | if (p->cache == object->cache) { |
David Howells | 493f7bc | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 587 | if (fscache_object_is_dying(p)) { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 588 | ret = -ENOBUFS; |
| 589 | spin_unlock(&cookie->parent->lock); |
| 590 | goto cant_attach_object; |
| 591 | } |
| 592 | object->parent = p; |
| 593 | spin_lock(&p->lock); |
| 594 | p->n_children++; |
| 595 | spin_unlock(&p->lock); |
| 596 | break; |
| 597 | } |
| 598 | } |
| 599 | spin_unlock(&cookie->parent->lock); |
| 600 | |
| 601 | /* attach to the cache's object list */ |
| 602 | if (list_empty(&object->cache_link)) { |
| 603 | spin_lock(&cache->object_list_lock); |
| 604 | list_add(&object->cache_link, &cache->object_list); |
| 605 | spin_unlock(&cache->object_list_lock); |
| 606 | } |
| 607 | |
Kiran Kumar Modukuri | f29507c | 2018-06-21 13:31:44 -0700 | [diff] [blame] | 608 | /* Attach to the cookie. The object already has a ref on it. */ |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 609 | hlist_add_head(&object->cookie_link, &cookie->backing_objects); |
| 610 | ret = 0; |
| 611 | |
| 612 | cant_attach_object: |
| 613 | spin_unlock(&cookie->lock); |
| 614 | _leave(" = %d", ret); |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | /* |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 619 | * Invalidate an object. Callable with spinlocks held. |
| 620 | */ |
| 621 | void __fscache_invalidate(struct fscache_cookie *cookie) |
| 622 | { |
| 623 | struct fscache_object *object; |
| 624 | |
| 625 | _enter("{%s}", cookie->def->name); |
| 626 | |
| 627 | fscache_stat(&fscache_n_invalidates); |
| 628 | |
| 629 | /* Only permit invalidation of data files. Invalidating an index will |
| 630 | * require the caller to release all its attachments to the tree rooted |
| 631 | * there, and if it's doing that, it may as well just retire the |
| 632 | * cookie. |
| 633 | */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 634 | ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 635 | |
| 636 | /* If there's an object, we tell the object state machine to handle the |
| 637 | * invalidation on our behalf, otherwise there's nothing to do. |
| 638 | */ |
| 639 | if (!hlist_empty(&cookie->backing_objects)) { |
| 640 | spin_lock(&cookie->lock); |
| 641 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 642 | if (fscache_cookie_enabled(cookie) && |
| 643 | !hlist_empty(&cookie->backing_objects) && |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 644 | !test_and_set_bit(FSCACHE_COOKIE_INVALIDATING, |
| 645 | &cookie->flags)) { |
| 646 | object = hlist_entry(cookie->backing_objects.first, |
| 647 | struct fscache_object, |
| 648 | cookie_link); |
David Howells | 493f7bc | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 649 | if (fscache_object_is_live(object)) |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 650 | fscache_raise_event( |
| 651 | object, FSCACHE_OBJECT_EV_INVALIDATE); |
| 652 | } |
| 653 | |
| 654 | spin_unlock(&cookie->lock); |
| 655 | } |
| 656 | |
| 657 | _leave(""); |
| 658 | } |
| 659 | EXPORT_SYMBOL(__fscache_invalidate); |
| 660 | |
| 661 | /* |
| 662 | * Wait for object invalidation to complete. |
| 663 | */ |
| 664 | void __fscache_wait_on_invalidate(struct fscache_cookie *cookie) |
| 665 | { |
David Howells | c97a72d | 2020-10-19 21:32:55 +0100 | [diff] [blame] | 666 | _enter("%x", cookie->debug_id); |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 667 | |
| 668 | wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING, |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 669 | TASK_UNINTERRUPTIBLE); |
| 670 | |
| 671 | _leave(""); |
| 672 | } |
| 673 | EXPORT_SYMBOL(__fscache_wait_on_invalidate); |
| 674 | |
| 675 | /* |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 676 | * update the index entries backing a cookie |
| 677 | */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 678 | void __fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data) |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 679 | { |
| 680 | struct fscache_object *object; |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 681 | |
| 682 | fscache_stat(&fscache_n_updates); |
| 683 | |
| 684 | if (!cookie) { |
| 685 | fscache_stat(&fscache_n_updates_null); |
| 686 | _leave(" [no cookie]"); |
| 687 | return; |
| 688 | } |
| 689 | |
| 690 | _enter("{%s}", cookie->def->name); |
| 691 | |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 692 | spin_lock(&cookie->lock); |
| 693 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 694 | fscache_update_aux(cookie, aux_data); |
| 695 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 696 | if (fscache_cookie_enabled(cookie)) { |
| 697 | /* update the index entry on disk in each cache backing this |
| 698 | * cookie. |
| 699 | */ |
| 700 | hlist_for_each_entry(object, |
| 701 | &cookie->backing_objects, cookie_link) { |
| 702 | fscache_raise_event(object, FSCACHE_OBJECT_EV_UPDATE); |
| 703 | } |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | spin_unlock(&cookie->lock); |
| 707 | _leave(""); |
| 708 | } |
| 709 | EXPORT_SYMBOL(__fscache_update_cookie); |
| 710 | |
| 711 | /* |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 712 | * Disable a cookie to stop it from accepting new requests from the netfs. |
| 713 | */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 714 | void __fscache_disable_cookie(struct fscache_cookie *cookie, |
| 715 | const void *aux_data, |
| 716 | bool invalidate) |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 717 | { |
| 718 | struct fscache_object *object; |
| 719 | bool awaken = false; |
| 720 | |
David Howells | c97a72d | 2020-10-19 21:32:55 +0100 | [diff] [blame] | 721 | _enter("%x,%u", cookie->debug_id, invalidate); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 722 | |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 723 | trace_fscache_disable(cookie); |
| 724 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 725 | ASSERTCMP(atomic_read(&cookie->n_active), >, 0); |
| 726 | |
| 727 | if (atomic_read(&cookie->n_children) != 0) { |
Fabian Frederick | 36dfd11 | 2014-06-04 16:05:38 -0700 | [diff] [blame] | 728 | pr_err("Cookie '%s' still has children\n", |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 729 | cookie->def->name); |
| 730 | BUG(); |
| 731 | } |
| 732 | |
| 733 | wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 734 | TASK_UNINTERRUPTIBLE); |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 735 | |
| 736 | fscache_update_aux(cookie, aux_data); |
| 737 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 738 | if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags)) |
| 739 | goto out_unlock_enable; |
| 740 | |
| 741 | /* If the cookie is being invalidated, wait for that to complete first |
| 742 | * so that we can reuse the flag. |
| 743 | */ |
| 744 | __fscache_wait_on_invalidate(cookie); |
| 745 | |
| 746 | /* Dispose of the backing objects */ |
| 747 | set_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags); |
| 748 | |
| 749 | spin_lock(&cookie->lock); |
| 750 | if (!hlist_empty(&cookie->backing_objects)) { |
| 751 | hlist_for_each_entry(object, &cookie->backing_objects, cookie_link) { |
| 752 | if (invalidate) |
| 753 | set_bit(FSCACHE_OBJECT_RETIRED, &object->flags); |
David Howells | 6bdded5 | 2017-01-18 14:29:25 +0000 | [diff] [blame] | 754 | clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 755 | fscache_raise_event(object, FSCACHE_OBJECT_EV_KILL); |
| 756 | } |
| 757 | } else { |
| 758 | if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) |
| 759 | awaken = true; |
| 760 | } |
| 761 | spin_unlock(&cookie->lock); |
| 762 | if (awaken) |
| 763 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); |
| 764 | |
| 765 | /* Wait for cessation of activity requiring access to the netfs (when |
| 766 | * n_active reaches 0). This makes sure outstanding reads and writes |
| 767 | * have completed. |
| 768 | */ |
Peter Zijlstra | dc5d4afb | 2018-03-15 11:43:43 +0100 | [diff] [blame] | 769 | if (!atomic_dec_and_test(&cookie->n_active)) { |
| 770 | wait_var_event(&cookie->n_active, |
| 771 | !atomic_read(&cookie->n_active)); |
| 772 | } |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 773 | |
David Howells | 6bdded5 | 2017-01-18 14:29:25 +0000 | [diff] [blame] | 774 | /* Make sure any pending writes are cancelled. */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 775 | if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) |
David Howells | 6bdded5 | 2017-01-18 14:29:25 +0000 | [diff] [blame] | 776 | fscache_invalidate_writes(cookie); |
| 777 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 778 | /* Reset the cookie state if it wasn't relinquished */ |
| 779 | if (!test_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) { |
| 780 | atomic_inc(&cookie->n_active); |
| 781 | set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); |
| 782 | } |
| 783 | |
| 784 | out_unlock_enable: |
| 785 | clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags); |
| 786 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK); |
| 787 | _leave(""); |
| 788 | } |
| 789 | EXPORT_SYMBOL(__fscache_disable_cookie); |
| 790 | |
| 791 | /* |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 792 | * release a cookie back to the cache |
| 793 | * - the object will be marked as recyclable on disk if retire is true |
| 794 | * - all dependents of this cookie must have already been unregistered |
| 795 | * (indices/files/pages) |
| 796 | */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 797 | void __fscache_relinquish_cookie(struct fscache_cookie *cookie, |
| 798 | const void *aux_data, |
| 799 | bool retire) |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 800 | { |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 801 | fscache_stat(&fscache_n_relinquishes); |
David Howells | 2175bb0 | 2009-11-19 18:11:38 +0000 | [diff] [blame] | 802 | if (retire) |
| 803 | fscache_stat(&fscache_n_relinquishes_retire); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 804 | |
| 805 | if (!cookie) { |
| 806 | fscache_stat(&fscache_n_relinquishes_null); |
| 807 | _leave(" [no cookie]"); |
| 808 | return; |
| 809 | } |
| 810 | |
David Howells | c97a72d | 2020-10-19 21:32:55 +0100 | [diff] [blame] | 811 | _enter("%x{%s,%d},%d", |
| 812 | cookie->debug_id, cookie->def->name, |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 813 | atomic_read(&cookie->n_active), retire); |
| 814 | |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 815 | trace_fscache_relinquish(cookie, retire); |
| 816 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 817 | /* No further netfs-accessing operations on this cookie permitted */ |
David Howells | d0fb31e | 2018-04-04 13:41:26 +0100 | [diff] [blame] | 818 | if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) |
| 819 | BUG(); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 820 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 821 | __fscache_disable_cookie(cookie, aux_data, retire); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 822 | |
| 823 | /* Clear pointers back to the netfs */ |
David Howells | 7e311a2 | 2009-11-19 18:11:11 +0000 | [diff] [blame] | 824 | cookie->netfs_data = NULL; |
| 825 | cookie->def = NULL; |
Matthew Wilcox | e5a9554 | 2018-04-10 16:36:48 -0700 | [diff] [blame] | 826 | BUG_ON(!radix_tree_empty(&cookie->stores)); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 827 | |
| 828 | if (cookie->parent) { |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 829 | ASSERTCMP(refcount_read(&cookie->parent->ref), >, 0); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 830 | ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0); |
| 831 | atomic_dec(&cookie->parent->n_children); |
| 832 | } |
| 833 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 834 | /* Dispose of the netfs's link to the cookie */ |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 835 | fscache_cookie_put(cookie, fscache_cookie_put_relinquish); |
David Howells | ccc4fc3 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 836 | |
| 837 | _leave(""); |
| 838 | } |
| 839 | EXPORT_SYMBOL(__fscache_relinquish_cookie); |
| 840 | |
| 841 | /* |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 842 | * Remove a cookie from the hash table. |
| 843 | */ |
| 844 | static void fscache_unhash_cookie(struct fscache_cookie *cookie) |
| 845 | { |
| 846 | struct hlist_bl_head *h; |
| 847 | unsigned int bucket; |
| 848 | |
| 849 | bucket = cookie->key_hash & (ARRAY_SIZE(fscache_cookie_hash) - 1); |
| 850 | h = &fscache_cookie_hash[bucket]; |
| 851 | |
| 852 | hlist_bl_lock(h); |
| 853 | hlist_bl_del(&cookie->hash_link); |
| 854 | hlist_bl_unlock(h); |
| 855 | } |
| 856 | |
| 857 | /* |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 858 | * Drop a reference to a cookie. |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 859 | */ |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 860 | void fscache_cookie_put(struct fscache_cookie *cookie, |
| 861 | enum fscache_cookie_trace where) |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 862 | { |
| 863 | struct fscache_cookie *parent; |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 864 | int ref; |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 865 | |
David Howells | c97a72d | 2020-10-19 21:32:55 +0100 | [diff] [blame] | 866 | _enter("%x", cookie->debug_id); |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 867 | |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 868 | do { |
David Howells | 33cba85 | 2021-06-18 11:19:49 +0100 | [diff] [blame] | 869 | unsigned int cookie_debug_id = cookie->debug_id; |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 870 | bool zero = __refcount_dec_and_test(&cookie->ref, &ref); |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 871 | |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 872 | trace_fscache_cookie(cookie_debug_id, ref - 1, where); |
| 873 | if (!zero) |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 874 | return; |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 875 | |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 876 | parent = cookie->parent; |
David Howells | ec0328e | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 877 | fscache_unhash_cookie(cookie); |
| 878 | fscache_free_cookie(cookie); |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 879 | |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 880 | cookie = parent; |
David Howells | a18feb5 | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 881 | where = fscache_cookie_put_parent; |
| 882 | } while (cookie); |
David Howells | 955d0091 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 883 | |
| 884 | _leave(""); |
| 885 | } |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 886 | |
| 887 | /* |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 888 | * Get a reference to a cookie. |
| 889 | */ |
| 890 | struct fscache_cookie *fscache_cookie_get(struct fscache_cookie *cookie, |
| 891 | enum fscache_cookie_trace where) |
| 892 | { |
| 893 | int ref; |
| 894 | |
| 895 | __refcount_inc(&cookie->ref, &ref); |
| 896 | trace_fscache_cookie(cookie->debug_id, ref + 1, where); |
| 897 | return cookie; |
| 898 | } |
| 899 | |
| 900 | /* |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 901 | * check the consistency between the netfs inode and the backing cache |
| 902 | * |
| 903 | * NOTE: it only serves no-index type |
| 904 | */ |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 905 | int __fscache_check_consistency(struct fscache_cookie *cookie, |
| 906 | const void *aux_data) |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 907 | { |
| 908 | struct fscache_operation *op; |
| 909 | struct fscache_object *object; |
David Howells | 8fb883f | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 910 | bool wake_cookie = false; |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 911 | int ret; |
| 912 | |
| 913 | _enter("%p,", cookie); |
| 914 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 915 | ASSERTCMP(cookie->type, ==, FSCACHE_COOKIE_TYPE_DATAFILE); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 916 | |
| 917 | if (fscache_wait_for_deferred_lookup(cookie) < 0) |
| 918 | return -ERESTARTSYS; |
| 919 | |
| 920 | if (hlist_empty(&cookie->backing_objects)) |
| 921 | return 0; |
| 922 | |
| 923 | op = kzalloc(sizeof(*op), GFP_NOIO | __GFP_NOMEMALLOC | __GFP_NORETRY); |
| 924 | if (!op) |
| 925 | return -ENOMEM; |
| 926 | |
David Howells | 08c2e3d | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 927 | fscache_operation_init(cookie, op, NULL, NULL, NULL); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 928 | op->flags = FSCACHE_OP_MYTHREAD | |
Milosz Tanski | 9c89d62 | 2013-09-09 14:28:57 -0400 | [diff] [blame] | 929 | (1 << FSCACHE_OP_WAITING) | |
| 930 | (1 << FSCACHE_OP_UNUSE_COOKIE); |
David Howells | 08c2e3d | 2018-04-04 13:41:27 +0100 | [diff] [blame] | 931 | trace_fscache_page_op(cookie, NULL, op, fscache_page_op_check_consistency); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 932 | |
| 933 | spin_lock(&cookie->lock); |
| 934 | |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 935 | fscache_update_aux(cookie, aux_data); |
| 936 | |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 937 | if (!fscache_cookie_enabled(cookie) || |
| 938 | hlist_empty(&cookie->backing_objects)) |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 939 | goto inconsistent; |
| 940 | object = hlist_entry(cookie->backing_objects.first, |
| 941 | struct fscache_object, cookie_link); |
| 942 | if (test_bit(FSCACHE_IOERROR, &object->cache->flags)) |
| 943 | goto inconsistent; |
| 944 | |
| 945 | op->debug_id = atomic_inc_return(&fscache_op_debug_id); |
| 946 | |
David Howells | 8fb883f | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 947 | __fscache_use_cookie(cookie); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 948 | if (fscache_submit_op(object, op) < 0) |
| 949 | goto submit_failed; |
| 950 | |
| 951 | /* the work queue now carries its own ref on the object */ |
| 952 | spin_unlock(&cookie->lock); |
| 953 | |
David Howells | d3b97ca | 2015-02-24 10:05:29 +0000 | [diff] [blame] | 954 | ret = fscache_wait_for_operation_activation(object, op, NULL, NULL); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 955 | if (ret == 0) { |
| 956 | /* ask the cache to honour the operation */ |
| 957 | ret = object->cache->ops->check_consistency(op); |
| 958 | fscache_op_complete(op, false); |
| 959 | } else if (ret == -ENOBUFS) { |
| 960 | ret = 0; |
| 961 | } |
| 962 | |
| 963 | fscache_put_operation(op); |
| 964 | _leave(" = %d", ret); |
| 965 | return ret; |
| 966 | |
| 967 | submit_failed: |
David Howells | 8fb883f | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 968 | wake_cookie = __fscache_unuse_cookie(cookie); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 969 | inconsistent: |
| 970 | spin_unlock(&cookie->lock); |
David Howells | 8fb883f | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 971 | if (wake_cookie) |
| 972 | __fscache_wake_unused_cookie(cookie); |
David Howells | da9803b | 2013-08-21 17:29:38 -0400 | [diff] [blame] | 973 | kfree(op); |
| 974 | _leave(" = -ESTALE"); |
| 975 | return -ESTALE; |
| 976 | } |
| 977 | EXPORT_SYMBOL(__fscache_check_consistency); |
David Howells | 884a768 | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | * Generate a list of extant cookies in /proc/fs/fscache/cookies |
| 981 | */ |
| 982 | static int fscache_cookies_seq_show(struct seq_file *m, void *v) |
| 983 | { |
| 984 | struct fscache_cookie *cookie; |
| 985 | unsigned int keylen = 0, auxlen = 0; |
| 986 | char _type[3], *type; |
| 987 | u8 *p; |
| 988 | |
| 989 | if (v == &fscache_cookies) { |
| 990 | seq_puts(m, |
| 991 | "COOKIE PARENT USAGE CHILD ACT TY FL DEF NETFS_DATA\n" |
| 992 | "======== ======== ===== ===== === == === ================ ==========\n" |
| 993 | ); |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | cookie = list_entry(v, struct fscache_cookie, proc_link); |
| 998 | |
| 999 | switch (cookie->type) { |
| 1000 | case 0: |
| 1001 | type = "IX"; |
| 1002 | break; |
| 1003 | case 1: |
| 1004 | type = "DT"; |
| 1005 | break; |
| 1006 | default: |
| 1007 | snprintf(_type, sizeof(_type), "%02u", |
| 1008 | cookie->type); |
| 1009 | type = _type; |
| 1010 | break; |
| 1011 | } |
| 1012 | |
| 1013 | seq_printf(m, |
| 1014 | "%08x %08x %5u %5u %3u %s %03lx %-16s %px", |
| 1015 | cookie->debug_id, |
| 1016 | cookie->parent ? cookie->parent->debug_id : 0, |
David Howells | 20ec197 | 2021-03-29 13:53:50 +0100 | [diff] [blame] | 1017 | refcount_read(&cookie->ref), |
David Howells | 884a768 | 2020-02-10 10:00:22 +0000 | [diff] [blame] | 1018 | atomic_read(&cookie->n_children), |
| 1019 | atomic_read(&cookie->n_active), |
| 1020 | type, |
| 1021 | cookie->flags, |
| 1022 | cookie->def->name, |
| 1023 | cookie->netfs_data); |
| 1024 | |
| 1025 | keylen = cookie->key_len; |
| 1026 | auxlen = cookie->aux_len; |
| 1027 | |
| 1028 | if (keylen > 0 || auxlen > 0) { |
| 1029 | seq_puts(m, " "); |
| 1030 | p = keylen <= sizeof(cookie->inline_key) ? |
| 1031 | cookie->inline_key : cookie->key; |
| 1032 | for (; keylen > 0; keylen--) |
| 1033 | seq_printf(m, "%02x", *p++); |
| 1034 | if (auxlen > 0) { |
| 1035 | seq_puts(m, ", "); |
| 1036 | p = auxlen <= sizeof(cookie->inline_aux) ? |
| 1037 | cookie->inline_aux : cookie->aux; |
| 1038 | for (; auxlen > 0; auxlen--) |
| 1039 | seq_printf(m, "%02x", *p++); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | seq_puts(m, "\n"); |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
| 1047 | static void *fscache_cookies_seq_start(struct seq_file *m, loff_t *_pos) |
| 1048 | __acquires(fscache_cookies_lock) |
| 1049 | { |
| 1050 | read_lock(&fscache_cookies_lock); |
| 1051 | return seq_list_start_head(&fscache_cookies, *_pos); |
| 1052 | } |
| 1053 | |
| 1054 | static void *fscache_cookies_seq_next(struct seq_file *m, void *v, loff_t *_pos) |
| 1055 | { |
| 1056 | return seq_list_next(v, &fscache_cookies, _pos); |
| 1057 | } |
| 1058 | |
| 1059 | static void fscache_cookies_seq_stop(struct seq_file *m, void *v) |
| 1060 | __releases(rcu) |
| 1061 | { |
| 1062 | read_unlock(&fscache_cookies_lock); |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | const struct seq_operations fscache_cookies_seq_ops = { |
| 1067 | .start = fscache_cookies_seq_start, |
| 1068 | .next = fscache_cookies_seq_next, |
| 1069 | .stop = fscache_cookies_seq_stop, |
| 1070 | .show = fscache_cookies_seq_show, |
| 1071 | }; |