David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 1 | /* FS-Cache object state machine handler |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * See Documentation/filesystems/caching/object.txt for a description of the |
| 12 | * object state machine and the in-kernel representations. |
| 13 | */ |
| 14 | |
| 15 | #define FSCACHE_DEBUG_LEVEL COOKIE |
| 16 | #include <linux/module.h> |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 17 | #include <linux/slab.h> |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 18 | #include <linux/prefetch.h> |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 19 | #include "internal.h" |
| 20 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 21 | static const struct fscache_state *fscache_abort_initialisation(struct fscache_object *, int); |
| 22 | static const struct fscache_state *fscache_kill_dependents(struct fscache_object *, int); |
| 23 | static const struct fscache_state *fscache_drop_object(struct fscache_object *, int); |
| 24 | static const struct fscache_state *fscache_initialise_object(struct fscache_object *, int); |
| 25 | static const struct fscache_state *fscache_invalidate_object(struct fscache_object *, int); |
| 26 | static const struct fscache_state *fscache_jumpstart_dependents(struct fscache_object *, int); |
| 27 | static const struct fscache_state *fscache_kill_object(struct fscache_object *, int); |
| 28 | static const struct fscache_state *fscache_lookup_failure(struct fscache_object *, int); |
| 29 | static const struct fscache_state *fscache_look_up_object(struct fscache_object *, int); |
| 30 | static const struct fscache_state *fscache_object_available(struct fscache_object *, int); |
| 31 | static const struct fscache_state *fscache_parent_ready(struct fscache_object *, int); |
| 32 | static const struct fscache_state *fscache_update_object(struct fscache_object *, int); |
David Howells | e26bfeb | 2017-01-31 09:45:28 +0000 | [diff] [blame] | 33 | static const struct fscache_state *fscache_object_dead(struct fscache_object *, int); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 34 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 35 | #define __STATE_NAME(n) fscache_osm_##n |
| 36 | #define STATE(n) (&__STATE_NAME(n)) |
| 37 | |
| 38 | /* |
| 39 | * Define a work state. Work states are execution states. No event processing |
| 40 | * is performed by them. The function attached to a work state returns a |
| 41 | * pointer indicating the next state to which the state machine should |
| 42 | * transition. Returning NO_TRANSIT repeats the current state, but goes back |
| 43 | * to the scheduler first. |
| 44 | */ |
| 45 | #define WORK_STATE(n, sn, f) \ |
| 46 | const struct fscache_state __STATE_NAME(n) = { \ |
| 47 | .name = #n, \ |
| 48 | .short_name = sn, \ |
| 49 | .work = f \ |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Returns from work states. |
| 54 | */ |
| 55 | #define transit_to(state) ({ prefetch(&STATE(state)->work); STATE(state); }) |
| 56 | |
| 57 | #define NO_TRANSIT ((struct fscache_state *)NULL) |
| 58 | |
| 59 | /* |
| 60 | * Define a wait state. Wait states are event processing states. No execution |
| 61 | * is performed by them. Wait states are just tables of "if event X occurs, |
| 62 | * clear it and transition to state Y". The dispatcher returns to the |
| 63 | * scheduler if none of the events in which the wait state has an interest are |
| 64 | * currently pending. |
| 65 | */ |
| 66 | #define WAIT_STATE(n, sn, ...) \ |
| 67 | const struct fscache_state __STATE_NAME(n) = { \ |
| 68 | .name = #n, \ |
| 69 | .short_name = sn, \ |
| 70 | .work = NULL, \ |
| 71 | .transitions = { __VA_ARGS__, { 0, NULL } } \ |
| 72 | } |
| 73 | |
| 74 | #define TRANSIT_TO(state, emask) \ |
| 75 | { .events = (emask), .transit_to = STATE(state) } |
| 76 | |
| 77 | /* |
| 78 | * The object state machine. |
| 79 | */ |
| 80 | static WORK_STATE(INIT_OBJECT, "INIT", fscache_initialise_object); |
| 81 | static WORK_STATE(PARENT_READY, "PRDY", fscache_parent_ready); |
| 82 | static WORK_STATE(ABORT_INIT, "ABRT", fscache_abort_initialisation); |
| 83 | static WORK_STATE(LOOK_UP_OBJECT, "LOOK", fscache_look_up_object); |
| 84 | static WORK_STATE(CREATE_OBJECT, "CRTO", fscache_look_up_object); |
| 85 | static WORK_STATE(OBJECT_AVAILABLE, "AVBL", fscache_object_available); |
| 86 | static WORK_STATE(JUMPSTART_DEPS, "JUMP", fscache_jumpstart_dependents); |
| 87 | |
| 88 | static WORK_STATE(INVALIDATE_OBJECT, "INVL", fscache_invalidate_object); |
| 89 | static WORK_STATE(UPDATE_OBJECT, "UPDT", fscache_update_object); |
| 90 | |
| 91 | static WORK_STATE(LOOKUP_FAILURE, "LCFL", fscache_lookup_failure); |
| 92 | static WORK_STATE(KILL_OBJECT, "KILL", fscache_kill_object); |
| 93 | static WORK_STATE(KILL_DEPENDENTS, "KDEP", fscache_kill_dependents); |
| 94 | static WORK_STATE(DROP_OBJECT, "DROP", fscache_drop_object); |
David Howells | e26bfeb | 2017-01-31 09:45:28 +0000 | [diff] [blame] | 95 | static WORK_STATE(OBJECT_DEAD, "DEAD", fscache_object_dead); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 96 | |
| 97 | static WAIT_STATE(WAIT_FOR_INIT, "?INI", |
| 98 | TRANSIT_TO(INIT_OBJECT, 1 << FSCACHE_OBJECT_EV_NEW_CHILD)); |
| 99 | |
| 100 | static WAIT_STATE(WAIT_FOR_PARENT, "?PRN", |
| 101 | TRANSIT_TO(PARENT_READY, 1 << FSCACHE_OBJECT_EV_PARENT_READY)); |
| 102 | |
| 103 | static WAIT_STATE(WAIT_FOR_CMD, "?CMD", |
| 104 | TRANSIT_TO(INVALIDATE_OBJECT, 1 << FSCACHE_OBJECT_EV_INVALIDATE), |
| 105 | TRANSIT_TO(UPDATE_OBJECT, 1 << FSCACHE_OBJECT_EV_UPDATE), |
| 106 | TRANSIT_TO(JUMPSTART_DEPS, 1 << FSCACHE_OBJECT_EV_NEW_CHILD)); |
| 107 | |
| 108 | static WAIT_STATE(WAIT_FOR_CLEARANCE, "?CLR", |
| 109 | TRANSIT_TO(KILL_OBJECT, 1 << FSCACHE_OBJECT_EV_CLEARED)); |
| 110 | |
| 111 | /* |
| 112 | * Out-of-band event transition tables. These are for handling unexpected |
| 113 | * events, such as an I/O error. If an OOB event occurs, the state machine |
| 114 | * clears and disables the event and forces a transition to the nominated work |
| 115 | * state (acurrently executing work states will complete first). |
| 116 | * |
| 117 | * In such a situation, object->state remembers the state the machine should |
| 118 | * have been in/gone to and returning NO_TRANSIT returns to that. |
| 119 | */ |
| 120 | static const struct fscache_transition fscache_osm_init_oob[] = { |
| 121 | TRANSIT_TO(ABORT_INIT, |
| 122 | (1 << FSCACHE_OBJECT_EV_ERROR) | |
| 123 | (1 << FSCACHE_OBJECT_EV_KILL)), |
| 124 | { 0, NULL } |
| 125 | }; |
| 126 | |
| 127 | static const struct fscache_transition fscache_osm_lookup_oob[] = { |
| 128 | TRANSIT_TO(LOOKUP_FAILURE, |
| 129 | (1 << FSCACHE_OBJECT_EV_ERROR) | |
| 130 | (1 << FSCACHE_OBJECT_EV_KILL)), |
| 131 | { 0, NULL } |
| 132 | }; |
| 133 | |
| 134 | static const struct fscache_transition fscache_osm_run_oob[] = { |
| 135 | TRANSIT_TO(KILL_OBJECT, |
| 136 | (1 << FSCACHE_OBJECT_EV_ERROR) | |
| 137 | (1 << FSCACHE_OBJECT_EV_KILL)), |
| 138 | { 0, NULL } |
David Howells | 440f0af | 2009-11-19 18:11:01 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 141 | static int fscache_get_object(struct fscache_object *); |
| 142 | static void fscache_put_object(struct fscache_object *); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 143 | static bool fscache_enqueue_dependents(struct fscache_object *, int); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 144 | static void fscache_dequeue_object(struct fscache_object *); |
| 145 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 146 | /* |
| 147 | * we need to notify the parent when an op completes that we had outstanding |
| 148 | * upon it |
| 149 | */ |
| 150 | static inline void fscache_done_parent_op(struct fscache_object *object) |
| 151 | { |
| 152 | struct fscache_object *parent = object->parent; |
| 153 | |
| 154 | _enter("OBJ%x {OBJ%x,%x}", |
| 155 | object->debug_id, parent->debug_id, parent->n_ops); |
| 156 | |
| 157 | spin_lock_nested(&parent->lock, 1); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 158 | parent->n_obj_ops--; |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 159 | parent->n_ops--; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 160 | if (parent->n_ops == 0) |
| 161 | fscache_raise_event(parent, FSCACHE_OBJECT_EV_CLEARED); |
| 162 | spin_unlock(&parent->lock); |
| 163 | } |
| 164 | |
| 165 | /* |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 166 | * Object state machine dispatcher. |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 167 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 168 | static void fscache_object_sm_dispatcher(struct fscache_object *object) |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 169 | { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 170 | const struct fscache_transition *t; |
| 171 | const struct fscache_state *state, *new_state; |
| 172 | unsigned long events, event_mask; |
| 173 | int event = -1; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 174 | |
| 175 | ASSERT(object != NULL); |
| 176 | |
| 177 | _enter("{OBJ%x,%s,%lx}", |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 178 | object->debug_id, object->state->name, object->events); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 179 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 180 | event_mask = object->event_mask; |
| 181 | restart: |
| 182 | object->event_mask = 0; /* Mask normal event handling */ |
| 183 | state = object->state; |
| 184 | restart_masked: |
| 185 | events = object->events; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 186 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 187 | /* Handle any out-of-band events (typically an error) */ |
| 188 | if (events & object->oob_event_mask) { |
| 189 | _debug("{OBJ%x} oob %lx", |
| 190 | object->debug_id, events & object->oob_event_mask); |
| 191 | for (t = object->oob_table; t->events; t++) { |
| 192 | if (events & t->events) { |
| 193 | state = t->transit_to; |
| 194 | ASSERT(state->work != NULL); |
| 195 | event = fls(events & t->events) - 1; |
| 196 | __clear_bit(event, &object->oob_event_mask); |
| 197 | clear_bit(event, &object->events); |
| 198 | goto execute_work_state; |
| 199 | } |
David Howells | d461d26 | 2009-11-19 18:11:41 +0000 | [diff] [blame] | 200 | } |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 201 | } |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 202 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 203 | /* Wait states are just transition tables */ |
| 204 | if (!state->work) { |
| 205 | if (events & event_mask) { |
| 206 | for (t = state->transitions; t->events; t++) { |
| 207 | if (events & t->events) { |
| 208 | new_state = t->transit_to; |
| 209 | event = fls(events & t->events) - 1; |
| 210 | clear_bit(event, &object->events); |
| 211 | _debug("{OBJ%x} ev %d: %s -> %s", |
| 212 | object->debug_id, event, |
| 213 | state->name, new_state->name); |
| 214 | object->state = state = new_state; |
| 215 | goto execute_work_state; |
| 216 | } |
| 217 | } |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 218 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 219 | /* The event mask didn't include all the tabled bits */ |
| 220 | BUG(); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 221 | } |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 222 | /* Randomly woke up */ |
| 223 | goto unmask_events; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 224 | } |
| 225 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 226 | execute_work_state: |
| 227 | _debug("{OBJ%x} exec %s", object->debug_id, state->name); |
| 228 | |
| 229 | new_state = state->work(object, event); |
| 230 | event = -1; |
| 231 | if (new_state == NO_TRANSIT) { |
| 232 | _debug("{OBJ%x} %s notrans", object->debug_id, state->name); |
David Howells | e26bfeb | 2017-01-31 09:45:28 +0000 | [diff] [blame] | 233 | if (unlikely(state == STATE(OBJECT_DEAD))) { |
| 234 | _leave(" [dead]"); |
| 235 | return; |
| 236 | } |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 237 | fscache_enqueue_object(object); |
| 238 | event_mask = object->oob_event_mask; |
| 239 | goto unmask_events; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 240 | } |
| 241 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 242 | _debug("{OBJ%x} %s -> %s", |
| 243 | object->debug_id, state->name, new_state->name); |
| 244 | object->state = state = new_state; |
| 245 | |
| 246 | if (state->work) { |
David Howells | e26bfeb | 2017-01-31 09:45:28 +0000 | [diff] [blame] | 247 | if (unlikely(state == STATE(OBJECT_DEAD))) { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 248 | _leave(" [dead]"); |
| 249 | return; |
| 250 | } |
| 251 | goto restart_masked; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 252 | } |
| 253 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 254 | /* Transited to wait state */ |
| 255 | event_mask = object->oob_event_mask; |
| 256 | for (t = state->transitions; t->events; t++) |
| 257 | event_mask |= t->events; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 258 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 259 | unmask_events: |
| 260 | object->event_mask = event_mask; |
| 261 | smp_mb(); |
| 262 | events = object->events; |
| 263 | if (events & event_mask) |
| 264 | goto restart; |
| 265 | _leave(" [msk %lx]", event_mask); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* |
| 269 | * execute an object |
| 270 | */ |
David Howells | 610be24 | 2013-05-10 19:50:25 +0100 | [diff] [blame] | 271 | static void fscache_object_work_func(struct work_struct *work) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 272 | { |
| 273 | struct fscache_object *object = |
| 274 | container_of(work, struct fscache_object, work); |
| 275 | unsigned long start; |
| 276 | |
| 277 | _enter("{OBJ%x}", object->debug_id); |
| 278 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 279 | start = jiffies; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 280 | fscache_object_sm_dispatcher(object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 281 | fscache_hist(fscache_objs_histogram, start); |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 282 | fscache_put_object(object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 283 | } |
David Howells | 610be24 | 2013-05-10 19:50:25 +0100 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * fscache_object_init - Initialise a cache object description |
| 287 | * @object: Object description |
| 288 | * @cookie: Cookie object will be attached to |
| 289 | * @cache: Cache in which backing object will be found |
| 290 | * |
| 291 | * Initialise a cache object description to its basic values. |
| 292 | * |
| 293 | * See Documentation/filesystems/caching/backend-api.txt for a complete |
| 294 | * description. |
| 295 | */ |
| 296 | void fscache_object_init(struct fscache_object *object, |
| 297 | struct fscache_cookie *cookie, |
| 298 | struct fscache_cache *cache) |
| 299 | { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 300 | const struct fscache_transition *t; |
| 301 | |
David Howells | 610be24 | 2013-05-10 19:50:25 +0100 | [diff] [blame] | 302 | atomic_inc(&cache->object_count); |
| 303 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 304 | object->state = STATE(WAIT_FOR_INIT); |
| 305 | object->oob_table = fscache_osm_init_oob; |
| 306 | object->flags = 1 << FSCACHE_OBJECT_IS_LIVE; |
David Howells | 610be24 | 2013-05-10 19:50:25 +0100 | [diff] [blame] | 307 | spin_lock_init(&object->lock); |
| 308 | INIT_LIST_HEAD(&object->cache_link); |
| 309 | INIT_HLIST_NODE(&object->cookie_link); |
| 310 | INIT_WORK(&object->work, fscache_object_work_func); |
| 311 | INIT_LIST_HEAD(&object->dependents); |
| 312 | INIT_LIST_HEAD(&object->dep_link); |
| 313 | INIT_LIST_HEAD(&object->pending_ops); |
| 314 | object->n_children = 0; |
| 315 | object->n_ops = object->n_in_progress = object->n_exclusive = 0; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 316 | object->events = 0; |
David Howells | 610be24 | 2013-05-10 19:50:25 +0100 | [diff] [blame] | 317 | object->store_limit = 0; |
| 318 | object->store_limit_l = 0; |
| 319 | object->cache = cache; |
| 320 | object->cookie = cookie; |
| 321 | object->parent = NULL; |
David Howells | 7026f19 | 2014-02-17 15:01:47 +0000 | [diff] [blame] | 322 | #ifdef CONFIG_FSCACHE_OBJECT_LIST |
| 323 | RB_CLEAR_NODE(&object->objlist_link); |
| 324 | #endif |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 325 | |
| 326 | object->oob_event_mask = 0; |
| 327 | for (t = object->oob_table; t->events; t++) |
| 328 | object->oob_event_mask |= t->events; |
| 329 | object->event_mask = object->oob_event_mask; |
| 330 | for (t = object->state->transitions; t->events; t++) |
| 331 | object->event_mask |= t->events; |
David Howells | 610be24 | 2013-05-10 19:50:25 +0100 | [diff] [blame] | 332 | } |
| 333 | EXPORT_SYMBOL(fscache_object_init); |
David Howells | 440f0af | 2009-11-19 18:11:01 +0000 | [diff] [blame] | 334 | |
| 335 | /* |
David Howells | f09b443 | 2015-02-24 10:05:28 +0000 | [diff] [blame] | 336 | * Mark the object as no longer being live, making sure that we synchronise |
| 337 | * against op submission. |
| 338 | */ |
| 339 | static inline void fscache_mark_object_dead(struct fscache_object *object) |
| 340 | { |
| 341 | spin_lock(&object->lock); |
| 342 | clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); |
| 343 | spin_unlock(&object->lock); |
| 344 | } |
| 345 | |
| 346 | /* |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 347 | * Abort object initialisation before we start it. |
| 348 | */ |
| 349 | static const struct fscache_state *fscache_abort_initialisation(struct fscache_object *object, |
| 350 | int event) |
| 351 | { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 352 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 353 | |
| 354 | object->oob_event_mask = 0; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 355 | fscache_dequeue_object(object); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 356 | return transit_to(KILL_OBJECT); |
| 357 | } |
| 358 | |
| 359 | /* |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 360 | * initialise an object |
| 361 | * - check the specified object's parent to see if we can make use of it |
| 362 | * immediately to do a creation |
| 363 | * - we may need to start the process of creating a parent and we need to wait |
| 364 | * for the parent's lookup and creation to complete if it's not there yet |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 365 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 366 | static const struct fscache_state *fscache_initialise_object(struct fscache_object *object, |
| 367 | int event) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 368 | { |
| 369 | struct fscache_object *parent; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 370 | bool success; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 371 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 372 | _enter("{OBJ%x},%d", object->debug_id, event); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 373 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 374 | ASSERT(list_empty(&object->dep_link)); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 375 | |
| 376 | parent = object->parent; |
| 377 | if (!parent) { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 378 | _leave(" [no parent]"); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 379 | return transit_to(DROP_OBJECT); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 380 | } |
| 381 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 382 | _debug("parent: %s of:%lx", parent->state->name, parent->flags); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 383 | |
| 384 | if (fscache_object_is_dying(parent)) { |
| 385 | _leave(" [bad parent]"); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 386 | return transit_to(DROP_OBJECT); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if (fscache_object_is_available(parent)) { |
| 390 | _leave(" [ready]"); |
| 391 | return transit_to(PARENT_READY); |
| 392 | } |
| 393 | |
| 394 | _debug("wait"); |
| 395 | |
| 396 | spin_lock(&parent->lock); |
| 397 | fscache_stat(&fscache_n_cop_grab_object); |
| 398 | success = false; |
| 399 | if (fscache_object_is_live(parent) && |
| 400 | object->cache->ops->grab_object(object)) { |
| 401 | list_add(&object->dep_link, &parent->dependents); |
| 402 | success = true; |
| 403 | } |
| 404 | fscache_stat_d(&fscache_n_cop_grab_object); |
| 405 | spin_unlock(&parent->lock); |
| 406 | if (!success) { |
| 407 | _leave(" [grab failed]"); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 408 | return transit_to(DROP_OBJECT); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /* fscache_acquire_non_index_cookie() uses this |
| 412 | * to wake the chain up */ |
| 413 | fscache_raise_event(parent, FSCACHE_OBJECT_EV_NEW_CHILD); |
| 414 | _leave(" [wait]"); |
| 415 | return transit_to(WAIT_FOR_PARENT); |
| 416 | } |
| 417 | |
| 418 | /* |
| 419 | * Once the parent object is ready, we should kick off our lookup op. |
| 420 | */ |
| 421 | static const struct fscache_state *fscache_parent_ready(struct fscache_object *object, |
| 422 | int event) |
| 423 | { |
| 424 | struct fscache_object *parent = object->parent; |
| 425 | |
| 426 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 427 | |
| 428 | ASSERT(parent != NULL); |
| 429 | |
| 430 | spin_lock(&parent->lock); |
| 431 | parent->n_ops++; |
| 432 | parent->n_obj_ops++; |
| 433 | object->lookup_jif = jiffies; |
| 434 | spin_unlock(&parent->lock); |
| 435 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 436 | _leave(""); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 437 | return transit_to(LOOK_UP_OBJECT); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* |
| 441 | * look an object up in the cache from which it was allocated |
| 442 | * - we hold an "access lock" on the parent object, so the parent object cannot |
| 443 | * be withdrawn by either party till we've finished |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 444 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 445 | static const struct fscache_state *fscache_look_up_object(struct fscache_object *object, |
| 446 | int event) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 447 | { |
| 448 | struct fscache_cookie *cookie = object->cookie; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 449 | struct fscache_object *parent = object->parent; |
David Howells | fee096d | 2009-11-19 18:12:05 +0000 | [diff] [blame] | 450 | int ret; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 451 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 452 | _enter("{OBJ%x},%d", object->debug_id, event); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 453 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 454 | object->oob_table = fscache_osm_lookup_oob; |
| 455 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 456 | ASSERT(parent != NULL); |
| 457 | ASSERTCMP(parent->n_ops, >, 0); |
| 458 | ASSERTCMP(parent->n_obj_ops, >, 0); |
| 459 | |
| 460 | /* make sure the parent is still available */ |
David Howells | 493f7bc | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 461 | ASSERT(fscache_object_is_available(parent)); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 462 | |
David Howells | 493f7bc | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 463 | if (fscache_object_is_dying(parent) || |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 464 | test_bit(FSCACHE_IOERROR, &object->cache->flags) || |
| 465 | !fscache_use_cookie(object)) { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 466 | _leave(" [unavailable]"); |
| 467 | return transit_to(LOOKUP_FAILURE); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 468 | } |
| 469 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 470 | _debug("LOOKUP \"%s\" in \"%s\"", |
| 471 | cookie->def->name, object->cache->tag->name); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 472 | |
| 473 | fscache_stat(&fscache_n_object_lookups); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 474 | fscache_stat(&fscache_n_cop_lookup_object); |
David Howells | fee096d | 2009-11-19 18:12:05 +0000 | [diff] [blame] | 475 | ret = object->cache->ops->lookup_object(object); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 476 | fscache_stat_d(&fscache_n_cop_lookup_object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 477 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 478 | fscache_unuse_cookie(object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 479 | |
David Howells | fee096d | 2009-11-19 18:12:05 +0000 | [diff] [blame] | 480 | if (ret == -ETIMEDOUT) { |
| 481 | /* probably stuck behind another object, so move this one to |
| 482 | * the back of the queue */ |
| 483 | fscache_stat(&fscache_n_object_lookups_timed_out); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 484 | _leave(" [timeout]"); |
| 485 | return NO_TRANSIT; |
David Howells | fee096d | 2009-11-19 18:12:05 +0000 | [diff] [blame] | 486 | } |
| 487 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 488 | if (ret < 0) { |
| 489 | _leave(" [error]"); |
| 490 | return transit_to(LOOKUP_FAILURE); |
| 491 | } |
| 492 | |
| 493 | _leave(" [ok]"); |
| 494 | return transit_to(OBJECT_AVAILABLE); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
| 498 | * fscache_object_lookup_negative - Note negative cookie lookup |
| 499 | * @object: Object pointing to cookie to mark |
| 500 | * |
| 501 | * Note negative lookup, permitting those waiting to read data from an already |
| 502 | * existing backing object to continue as there's no data for them to read. |
| 503 | */ |
| 504 | void fscache_object_lookup_negative(struct fscache_object *object) |
| 505 | { |
| 506 | struct fscache_cookie *cookie = object->cookie; |
| 507 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 508 | _enter("{OBJ%x,%s}", object->debug_id, object->state->name); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 509 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 510 | if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 511 | fscache_stat(&fscache_n_object_lookups_negative); |
| 512 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 513 | /* Allow write requests to begin stacking up and read requests to begin |
| 514 | * returning ENODATA. |
| 515 | */ |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 516 | set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 517 | clear_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 518 | |
| 519 | _debug("wake up lookup %p", &cookie->flags); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 520 | clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 521 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 522 | } |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 523 | _leave(""); |
| 524 | } |
| 525 | EXPORT_SYMBOL(fscache_object_lookup_negative); |
| 526 | |
| 527 | /** |
| 528 | * fscache_obtained_object - Note successful object lookup or creation |
| 529 | * @object: Object pointing to cookie to mark |
| 530 | * |
| 531 | * Note successful lookup and/or creation, permitting those waiting to write |
| 532 | * data to a backing object to continue. |
| 533 | * |
| 534 | * Note that after calling this, an object's cookie may be relinquished by the |
| 535 | * netfs, and so must be accessed with object lock held. |
| 536 | */ |
| 537 | void fscache_obtained_object(struct fscache_object *object) |
| 538 | { |
| 539 | struct fscache_cookie *cookie = object->cookie; |
| 540 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 541 | _enter("{OBJ%x,%s}", object->debug_id, object->state->name); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 542 | |
| 543 | /* if we were still looking up, then we must have a positive lookup |
| 544 | * result, in which case there may be data available */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 545 | if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 546 | fscache_stat(&fscache_n_object_lookups_positive); |
| 547 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 548 | /* We do (presumably) have data */ |
| 549 | clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 550 | clear_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 551 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 552 | /* Allow write requests to begin stacking up and read requests |
| 553 | * to begin shovelling data. |
| 554 | */ |
| 555 | clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 556 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 557 | } else { |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 558 | fscache_stat(&fscache_n_object_created); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 559 | } |
| 560 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 561 | set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 562 | _leave(""); |
| 563 | } |
| 564 | EXPORT_SYMBOL(fscache_obtained_object); |
| 565 | |
| 566 | /* |
| 567 | * handle an object that has just become available |
| 568 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 569 | static const struct fscache_state *fscache_object_available(struct fscache_object *object, |
| 570 | int event) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 571 | { |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 572 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 573 | |
| 574 | object->oob_table = fscache_osm_run_oob; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 575 | |
| 576 | spin_lock(&object->lock); |
| 577 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 578 | fscache_done_parent_op(object); |
| 579 | if (object->n_in_progress == 0) { |
| 580 | if (object->n_ops > 0) { |
| 581 | ASSERTCMP(object->n_ops, >=, object->n_obj_ops); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 582 | fscache_start_operations(object); |
| 583 | } else { |
| 584 | ASSERT(list_empty(&object->pending_ops)); |
| 585 | } |
| 586 | } |
| 587 | spin_unlock(&object->lock); |
| 588 | |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 589 | fscache_stat(&fscache_n_cop_lookup_complete); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 590 | object->cache->ops->lookup_complete(object); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 591 | fscache_stat_d(&fscache_n_cop_lookup_complete); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 592 | |
| 593 | fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif); |
| 594 | fscache_stat(&fscache_n_object_avail); |
| 595 | |
| 596 | _leave(""); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 597 | return transit_to(JUMPSTART_DEPS); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /* |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 601 | * Wake up this object's dependent objects now that we've become available. |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 602 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 603 | static const struct fscache_state *fscache_jumpstart_dependents(struct fscache_object *object, |
| 604 | int event) |
| 605 | { |
| 606 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 607 | |
| 608 | if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_PARENT_READY)) |
| 609 | return NO_TRANSIT; /* Not finished; requeue */ |
| 610 | return transit_to(WAIT_FOR_CMD); |
| 611 | } |
| 612 | |
| 613 | /* |
| 614 | * Handle lookup or creation failute. |
| 615 | */ |
| 616 | static const struct fscache_state *fscache_lookup_failure(struct fscache_object *object, |
| 617 | int event) |
| 618 | { |
| 619 | struct fscache_cookie *cookie; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 620 | |
| 621 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 622 | |
| 623 | object->oob_event_mask = 0; |
| 624 | |
| 625 | fscache_stat(&fscache_n_cop_lookup_complete); |
| 626 | object->cache->ops->lookup_complete(object); |
| 627 | fscache_stat_d(&fscache_n_cop_lookup_complete); |
| 628 | |
David Howells | 6515d1d | 2015-02-25 11:53:57 +0000 | [diff] [blame] | 629 | set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags); |
| 630 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 631 | cookie = object->cookie; |
| 632 | set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 633 | if (test_and_clear_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags)) |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 634 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 635 | |
| 636 | fscache_done_parent_op(object); |
| 637 | return transit_to(KILL_OBJECT); |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | * Wait for completion of all active operations on this object and the death of |
| 642 | * all child objects of this object. |
| 643 | */ |
| 644 | static const struct fscache_state *fscache_kill_object(struct fscache_object *object, |
| 645 | int event) |
| 646 | { |
| 647 | _enter("{OBJ%x,%d,%d},%d", |
| 648 | object->debug_id, object->n_ops, object->n_children, event); |
| 649 | |
David Howells | f09b443 | 2015-02-24 10:05:28 +0000 | [diff] [blame] | 650 | fscache_mark_object_dead(object); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 651 | object->oob_event_mask = 0; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 652 | |
David Howells | 6bdded5 | 2017-01-18 14:29:25 +0000 | [diff] [blame] | 653 | if (test_bit(FSCACHE_OBJECT_RETIRED, &object->flags)) { |
| 654 | /* Reject any new read/write ops and abort any that are pending. */ |
| 655 | clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); |
| 656 | fscache_cancel_all_ops(object); |
| 657 | } |
| 658 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 659 | if (list_empty(&object->dependents) && |
| 660 | object->n_ops == 0 && |
| 661 | object->n_children == 0) |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 662 | return transit_to(DROP_OBJECT); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 663 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 664 | if (object->n_in_progress == 0) { |
| 665 | spin_lock(&object->lock); |
| 666 | if (object->n_ops > 0 && object->n_in_progress == 0) |
| 667 | fscache_start_operations(object); |
| 668 | spin_unlock(&object->lock); |
| 669 | } |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 670 | |
| 671 | if (!list_empty(&object->dependents)) |
| 672 | return transit_to(KILL_DEPENDENTS); |
| 673 | |
| 674 | return transit_to(WAIT_FOR_CLEARANCE); |
| 675 | } |
| 676 | |
| 677 | /* |
| 678 | * Kill dependent objects. |
| 679 | */ |
| 680 | static const struct fscache_state *fscache_kill_dependents(struct fscache_object *object, |
| 681 | int event) |
| 682 | { |
| 683 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 684 | |
| 685 | if (!fscache_enqueue_dependents(object, FSCACHE_OBJECT_EV_KILL)) |
| 686 | return NO_TRANSIT; /* Not finished */ |
| 687 | return transit_to(WAIT_FOR_CLEARANCE); |
| 688 | } |
| 689 | |
| 690 | /* |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 691 | * Drop an object's attachments |
| 692 | */ |
| 693 | static const struct fscache_state *fscache_drop_object(struct fscache_object *object, |
| 694 | int event) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 695 | { |
| 696 | struct fscache_object *parent = object->parent; |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 697 | struct fscache_cookie *cookie = object->cookie; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 698 | struct fscache_cache *cache = object->cache; |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 699 | bool awaken = false; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 700 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 701 | _enter("{OBJ%x,%d},%d", object->debug_id, object->n_children, event); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 702 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 703 | ASSERT(cookie != NULL); |
| 704 | ASSERT(!hlist_unhashed(&object->cookie_link)); |
| 705 | |
| 706 | /* Make sure the cookie no longer points here and that the netfs isn't |
| 707 | * waiting for us. |
| 708 | */ |
| 709 | spin_lock(&cookie->lock); |
| 710 | hlist_del_init(&object->cookie_link); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 711 | if (hlist_empty(&cookie->backing_objects) && |
| 712 | test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 713 | awaken = true; |
| 714 | spin_unlock(&cookie->lock); |
| 715 | |
| 716 | if (awaken) |
| 717 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); |
David Howells | 6897e3d | 2009-11-19 18:11:22 +0000 | [diff] [blame] | 718 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 719 | /* Prevent a race with our last child, which has to signal EV_CLEARED |
| 720 | * before dropping our spinlock. |
| 721 | */ |
| 722 | spin_lock(&object->lock); |
| 723 | spin_unlock(&object->lock); |
| 724 | |
| 725 | /* Discard from the cache's collection of objects */ |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 726 | spin_lock(&cache->object_list_lock); |
| 727 | list_del_init(&object->cache_link); |
| 728 | spin_unlock(&cache->object_list_lock); |
| 729 | |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 730 | fscache_stat(&fscache_n_cop_drop_object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 731 | cache->ops->drop_object(object); |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 732 | fscache_stat_d(&fscache_n_cop_drop_object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 733 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 734 | /* The parent object wants to know when all it dependents have gone */ |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 735 | if (parent) { |
| 736 | _debug("release parent OBJ%x {%d}", |
| 737 | parent->debug_id, parent->n_children); |
| 738 | |
| 739 | spin_lock(&parent->lock); |
| 740 | parent->n_children--; |
| 741 | if (parent->n_children == 0) |
| 742 | fscache_raise_event(parent, FSCACHE_OBJECT_EV_CLEARED); |
| 743 | spin_unlock(&parent->lock); |
| 744 | object->parent = NULL; |
| 745 | } |
| 746 | |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 747 | /* this just shifts the object release to the work processor */ |
| 748 | fscache_put_object(object); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 749 | fscache_stat(&fscache_n_object_dead); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 750 | |
| 751 | _leave(""); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 752 | return transit_to(OBJECT_DEAD); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /* |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 756 | * get a ref on an object |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 757 | */ |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 758 | static int fscache_get_object(struct fscache_object *object) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 759 | { |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 760 | int ret; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 761 | |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 762 | fscache_stat(&fscache_n_cop_grab_object); |
| 763 | ret = object->cache->ops->grab_object(object) ? 0 : -EAGAIN; |
| 764 | fscache_stat_d(&fscache_n_cop_grab_object); |
| 765 | return ret; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /* |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 769 | * Discard a ref on an object |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 770 | */ |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 771 | static void fscache_put_object(struct fscache_object *object) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 772 | { |
David Howells | 52bd75f | 2009-11-19 18:11:08 +0000 | [diff] [blame] | 773 | fscache_stat(&fscache_n_cop_put_object); |
| 774 | object->cache->ops->put_object(object); |
| 775 | fscache_stat_d(&fscache_n_cop_put_object); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 776 | } |
| 777 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 778 | /** |
| 779 | * fscache_object_destroy - Note that a cache object is about to be destroyed |
| 780 | * @object: The object to be destroyed |
| 781 | * |
| 782 | * Note the imminent destruction and deallocation of a cache object record. |
| 783 | */ |
| 784 | void fscache_object_destroy(struct fscache_object *object) |
| 785 | { |
| 786 | fscache_objlist_remove(object); |
| 787 | |
| 788 | /* We can get rid of the cookie now */ |
| 789 | fscache_cookie_put(object->cookie); |
| 790 | object->cookie = NULL; |
| 791 | } |
| 792 | EXPORT_SYMBOL(fscache_object_destroy); |
| 793 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 794 | /* |
| 795 | * enqueue an object for metadata-type processing |
| 796 | */ |
| 797 | void fscache_enqueue_object(struct fscache_object *object) |
| 798 | { |
| 799 | _enter("{OBJ%x}", object->debug_id); |
| 800 | |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 801 | if (fscache_get_object(object) >= 0) { |
| 802 | wait_queue_head_t *cong_wq = |
| 803 | &get_cpu_var(fscache_object_cong_wait); |
| 804 | |
| 805 | if (queue_work(fscache_object_wq, &object->work)) { |
| 806 | if (fscache_object_congested()) |
| 807 | wake_up(cong_wq); |
| 808 | } else |
| 809 | fscache_put_object(object); |
| 810 | |
| 811 | put_cpu_var(fscache_object_cong_wait); |
| 812 | } |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 815 | /** |
| 816 | * fscache_object_sleep_till_congested - Sleep until object wq is congested |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 817 | * @timeoutp: Scheduler sleep timeout |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 818 | * |
| 819 | * Allow an object handler to sleep until the object workqueue is congested. |
| 820 | * |
| 821 | * The caller must set up a wake up event before calling this and must have set |
| 822 | * the appropriate sleep mode (such as TASK_UNINTERRUPTIBLE) and tested its own |
| 823 | * condition before calling this function as no test is made here. |
| 824 | * |
| 825 | * %true is returned if the object wq is congested, %false otherwise. |
| 826 | */ |
| 827 | bool fscache_object_sleep_till_congested(signed long *timeoutp) |
| 828 | { |
Christoph Lameter | 170d800 | 2013-10-15 12:22:29 -0600 | [diff] [blame] | 829 | wait_queue_head_t *cong_wq = this_cpu_ptr(&fscache_object_cong_wait); |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 830 | DEFINE_WAIT(wait); |
| 831 | |
| 832 | if (fscache_object_congested()) |
| 833 | return true; |
| 834 | |
| 835 | add_wait_queue_exclusive(cong_wq, &wait); |
| 836 | if (!fscache_object_congested()) |
| 837 | *timeoutp = schedule_timeout(*timeoutp); |
| 838 | finish_wait(cong_wq, &wait); |
| 839 | |
| 840 | return fscache_object_congested(); |
| 841 | } |
| 842 | EXPORT_SYMBOL_GPL(fscache_object_sleep_till_congested); |
| 843 | |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 844 | /* |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 845 | * Enqueue the dependents of an object for metadata-type processing. |
| 846 | * |
| 847 | * If we don't manage to finish the list before the scheduler wants to run |
| 848 | * again then return false immediately. We return true if the list was |
| 849 | * cleared. |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 850 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 851 | static bool fscache_enqueue_dependents(struct fscache_object *object, int event) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 852 | { |
| 853 | struct fscache_object *dep; |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 854 | bool ret = true; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 855 | |
| 856 | _enter("{OBJ%x}", object->debug_id); |
| 857 | |
| 858 | if (list_empty(&object->dependents)) |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 859 | return true; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 860 | |
| 861 | spin_lock(&object->lock); |
| 862 | |
| 863 | while (!list_empty(&object->dependents)) { |
| 864 | dep = list_entry(object->dependents.next, |
| 865 | struct fscache_object, dep_link); |
| 866 | list_del_init(&dep->dep_link); |
| 867 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 868 | fscache_raise_event(dep, event); |
Tejun Heo | 8b8edef | 2010-07-20 22:09:01 +0200 | [diff] [blame] | 869 | fscache_put_object(dep); |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 870 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 871 | if (!list_empty(&object->dependents) && need_resched()) { |
| 872 | ret = false; |
| 873 | break; |
| 874 | } |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | spin_unlock(&object->lock); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 878 | return ret; |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /* |
| 882 | * remove an object from whatever queue it's waiting on |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 883 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 884 | static void fscache_dequeue_object(struct fscache_object *object) |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 885 | { |
| 886 | _enter("{OBJ%x}", object->debug_id); |
| 887 | |
| 888 | if (!list_empty(&object->dep_link)) { |
| 889 | spin_lock(&object->parent->lock); |
| 890 | list_del_init(&object->dep_link); |
| 891 | spin_unlock(&object->parent->lock); |
| 892 | } |
| 893 | |
| 894 | _leave(""); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * fscache_check_aux - Ask the netfs whether an object on disk is still valid |
| 899 | * @object: The object to ask about |
| 900 | * @data: The auxiliary data for the object |
| 901 | * @datalen: The size of the auxiliary data |
| 902 | * |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 903 | * This function consults the netfs about the coherency state of an object. |
| 904 | * The caller must be holding a ref on cookie->n_active (held by |
| 905 | * fscache_look_up_object() on behalf of the cache backend during object lookup |
| 906 | * and creation). |
David Howells | 36c9559 | 2009-04-03 16:42:38 +0100 | [diff] [blame] | 907 | */ |
| 908 | enum fscache_checkaux fscache_check_aux(struct fscache_object *object, |
| 909 | const void *data, uint16_t datalen) |
| 910 | { |
| 911 | enum fscache_checkaux result; |
| 912 | |
| 913 | if (!object->cookie->def->check_aux) { |
| 914 | fscache_stat(&fscache_n_checkaux_none); |
| 915 | return FSCACHE_CHECKAUX_OKAY; |
| 916 | } |
| 917 | |
| 918 | result = object->cookie->def->check_aux(object->cookie->netfs_data, |
| 919 | data, datalen); |
| 920 | switch (result) { |
| 921 | /* entry okay as is */ |
| 922 | case FSCACHE_CHECKAUX_OKAY: |
| 923 | fscache_stat(&fscache_n_checkaux_okay); |
| 924 | break; |
| 925 | |
| 926 | /* entry requires update */ |
| 927 | case FSCACHE_CHECKAUX_NEEDS_UPDATE: |
| 928 | fscache_stat(&fscache_n_checkaux_update); |
| 929 | break; |
| 930 | |
| 931 | /* entry requires deletion */ |
| 932 | case FSCACHE_CHECKAUX_OBSOLETE: |
| 933 | fscache_stat(&fscache_n_checkaux_obsolete); |
| 934 | break; |
| 935 | |
| 936 | default: |
| 937 | BUG(); |
| 938 | } |
| 939 | |
| 940 | return result; |
| 941 | } |
| 942 | EXPORT_SYMBOL(fscache_check_aux); |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 943 | |
| 944 | /* |
| 945 | * Asynchronously invalidate an object. |
| 946 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 947 | static const struct fscache_state *_fscache_invalidate_object(struct fscache_object *object, |
| 948 | int event) |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 949 | { |
| 950 | struct fscache_operation *op; |
| 951 | struct fscache_cookie *cookie = object->cookie; |
| 952 | |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 953 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 954 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 955 | /* We're going to need the cookie. If the cookie is not available then |
| 956 | * retire the object instead. |
| 957 | */ |
| 958 | if (!fscache_use_cookie(object)) { |
| 959 | ASSERT(object->cookie->stores.rnode == NULL); |
David Howells | 94d30ae | 2013-09-21 00:09:31 +0100 | [diff] [blame] | 960 | set_bit(FSCACHE_OBJECT_RETIRED, &object->flags); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 961 | _leave(" [no cookie]"); |
| 962 | return transit_to(KILL_OBJECT); |
| 963 | } |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 964 | |
| 965 | /* Reject any new read/write ops and abort any that are pending. */ |
| 966 | fscache_invalidate_writes(cookie); |
| 967 | clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); |
| 968 | fscache_cancel_all_ops(object); |
| 969 | |
| 970 | /* Now we have to wait for in-progress reads and writes */ |
| 971 | op = kzalloc(sizeof(*op), GFP_KERNEL); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 972 | if (!op) |
| 973 | goto nomem; |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 974 | |
David Howells | d3b97ca | 2015-02-24 10:05:29 +0000 | [diff] [blame] | 975 | fscache_operation_init(op, object->cache->ops->invalidate_object, |
| 976 | NULL, NULL); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 977 | op->flags = FSCACHE_OP_ASYNC | |
| 978 | (1 << FSCACHE_OP_EXCLUSIVE) | |
| 979 | (1 << FSCACHE_OP_UNUSE_COOKIE); |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 980 | |
| 981 | spin_lock(&cookie->lock); |
| 982 | if (fscache_submit_exclusive_op(object, op) < 0) |
David Howells | 8d76349 | 2012-12-05 13:34:48 +0000 | [diff] [blame] | 983 | goto submit_op_failed; |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 984 | spin_unlock(&cookie->lock); |
| 985 | fscache_put_operation(op); |
| 986 | |
| 987 | /* Once we've completed the invalidation, we know there will be no data |
| 988 | * stored in the cache and thus we can reinstate the data-check-skip |
| 989 | * optimisation. |
| 990 | */ |
| 991 | set_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags); |
| 992 | |
| 993 | /* We can allow read and write requests to come in once again. They'll |
| 994 | * queue up behind our exclusive invalidation operation. |
| 995 | */ |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 996 | if (test_and_clear_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) |
| 997 | wake_up_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING); |
| 998 | _leave(" [ok]"); |
| 999 | return transit_to(UPDATE_OBJECT); |
David Howells | 8d76349 | 2012-12-05 13:34:48 +0000 | [diff] [blame] | 1000 | |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 1001 | nomem: |
David Howells | f09b443 | 2015-02-24 10:05:28 +0000 | [diff] [blame] | 1002 | fscache_mark_object_dead(object); |
David Howells | 1362729 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 1003 | fscache_unuse_cookie(object); |
| 1004 | _leave(" [ENOMEM]"); |
| 1005 | return transit_to(KILL_OBJECT); |
| 1006 | |
David Howells | 8d76349 | 2012-12-05 13:34:48 +0000 | [diff] [blame] | 1007 | submit_op_failed: |
David Howells | f09b443 | 2015-02-24 10:05:28 +0000 | [diff] [blame] | 1008 | fscache_mark_object_dead(object); |
David Howells | 8d76349 | 2012-12-05 13:34:48 +0000 | [diff] [blame] | 1009 | spin_unlock(&cookie->lock); |
Milosz Tanski | 920bce2 | 2014-08-13 12:58:21 -0400 | [diff] [blame] | 1010 | fscache_unuse_cookie(object); |
David Howells | 8d76349 | 2012-12-05 13:34:48 +0000 | [diff] [blame] | 1011 | kfree(op); |
David Howells | 8d76349 | 2012-12-05 13:34:48 +0000 | [diff] [blame] | 1012 | _leave(" [EIO]"); |
David Howells | caaef69 | 2013-05-10 19:50:26 +0100 | [diff] [blame] | 1013 | return transit_to(KILL_OBJECT); |
| 1014 | } |
| 1015 | |
| 1016 | static const struct fscache_state *fscache_invalidate_object(struct fscache_object *object, |
| 1017 | int event) |
| 1018 | { |
| 1019 | const struct fscache_state *s; |
| 1020 | |
| 1021 | fscache_stat(&fscache_n_invalidates_run); |
| 1022 | fscache_stat(&fscache_n_cop_invalidate_object); |
| 1023 | s = _fscache_invalidate_object(object, event); |
| 1024 | fscache_stat_d(&fscache_n_cop_invalidate_object); |
| 1025 | return s; |
| 1026 | } |
| 1027 | |
| 1028 | /* |
| 1029 | * Asynchronously update an object. |
| 1030 | */ |
| 1031 | static const struct fscache_state *fscache_update_object(struct fscache_object *object, |
| 1032 | int event) |
| 1033 | { |
| 1034 | _enter("{OBJ%x},%d", object->debug_id, event); |
| 1035 | |
| 1036 | fscache_stat(&fscache_n_updates_run); |
| 1037 | fscache_stat(&fscache_n_cop_update_object); |
| 1038 | object->cache->ops->update_object(object); |
| 1039 | fscache_stat_d(&fscache_n_cop_update_object); |
| 1040 | |
| 1041 | _leave(""); |
| 1042 | return transit_to(WAIT_FOR_CMD); |
David Howells | ef778e7 | 2012-12-20 21:52:36 +0000 | [diff] [blame] | 1043 | } |
David Howells | 182d919 | 2015-02-19 23:47:31 +0000 | [diff] [blame] | 1044 | |
| 1045 | /** |
| 1046 | * fscache_object_retrying_stale - Note retrying stale object |
| 1047 | * @object: The object that will be retried |
| 1048 | * |
| 1049 | * Note that an object lookup found an on-disk object that was adjudged to be |
| 1050 | * stale and has been deleted. The lookup will be retried. |
| 1051 | */ |
| 1052 | void fscache_object_retrying_stale(struct fscache_object *object) |
| 1053 | { |
| 1054 | fscache_stat(&fscache_n_cache_no_space_reject); |
| 1055 | } |
| 1056 | EXPORT_SYMBOL(fscache_object_retrying_stale); |
| 1057 | |
| 1058 | /** |
| 1059 | * fscache_object_mark_killed - Note that an object was killed |
| 1060 | * @object: The object that was culled |
| 1061 | * @why: The reason the object was killed. |
| 1062 | * |
| 1063 | * Note that an object was killed. Returns true if the object was |
| 1064 | * already marked killed, false if it wasn't. |
| 1065 | */ |
| 1066 | void fscache_object_mark_killed(struct fscache_object *object, |
| 1067 | enum fscache_why_object_killed why) |
| 1068 | { |
| 1069 | if (test_and_set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags)) { |
| 1070 | pr_err("Error: Object already killed by cache [%s]\n", |
| 1071 | object->cache->identifier); |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | switch (why) { |
| 1076 | case FSCACHE_OBJECT_NO_SPACE: |
| 1077 | fscache_stat(&fscache_n_cache_no_space_reject); |
| 1078 | break; |
| 1079 | case FSCACHE_OBJECT_IS_STALE: |
| 1080 | fscache_stat(&fscache_n_cache_stale_objects); |
| 1081 | break; |
| 1082 | case FSCACHE_OBJECT_WAS_RETIRED: |
| 1083 | fscache_stat(&fscache_n_cache_retired_objects); |
| 1084 | break; |
| 1085 | case FSCACHE_OBJECT_WAS_CULLED: |
| 1086 | fscache_stat(&fscache_n_cache_culled_objects); |
| 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | EXPORT_SYMBOL(fscache_object_mark_killed); |
David Howells | e26bfeb | 2017-01-31 09:45:28 +0000 | [diff] [blame] | 1091 | |
| 1092 | /* |
| 1093 | * The object is dead. We can get here if an object gets queued by an event |
| 1094 | * that would lead to its death (such as EV_KILL) when the dispatcher is |
| 1095 | * already running (and so can be requeued) but hasn't yet cleared the event |
| 1096 | * mask. |
| 1097 | */ |
| 1098 | static const struct fscache_state *fscache_object_dead(struct fscache_object *object, |
| 1099 | int event) |
| 1100 | { |
| 1101 | if (!test_and_set_bit(FSCACHE_OBJECT_RUN_AFTER_DEAD, |
| 1102 | &object->flags)) |
| 1103 | return NO_TRANSIT; |
| 1104 | |
| 1105 | WARN(true, "FS-Cache object redispatched after death"); |
| 1106 | return NO_TRANSIT; |
| 1107 | } |