blob: 18658fffbba17f11cffbdf8d2249eefe9557badc [file] [log] [blame]
David Howells952efe72009-04-03 16:42:39 +01001/* FS-Cache worker operation management routines
2 *
3 * Copyright (C) 2008 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/operations.txt
12 */
13
14#define FSCACHE_DEBUG_LEVEL OPERATION
15#include <linux/module.h>
David Howells440f0af2009-11-19 18:11:01 +000016#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
David Howells952efe72009-04-03 16:42:39 +010018#include "internal.h"
19
20atomic_t fscache_op_debug_id;
21EXPORT_SYMBOL(fscache_op_debug_id);
22
23/**
24 * fscache_enqueue_operation - Enqueue an operation for processing
25 * @op: The operation to enqueue
26 *
27 * Enqueue an operation for processing by the FS-Cache thread pool.
28 *
29 * This will get its own ref on the object.
30 */
31void fscache_enqueue_operation(struct fscache_operation *op)
32{
33 _enter("{OBJ%x OP%x,%u}",
34 op->object->debug_id, op->debug_id, atomic_read(&op->usage));
35
David Howells5753c442009-11-19 18:11:19 +000036 ASSERT(list_empty(&op->pend_link));
David Howells952efe72009-04-03 16:42:39 +010037 ASSERT(op->processor != NULL);
David Howells493f7bc2013-05-10 19:50:26 +010038 ASSERT(fscache_object_is_available(op->object));
David Howells952efe72009-04-03 16:42:39 +010039 ASSERTCMP(atomic_read(&op->usage), >, 0);
David Howells9f105232012-12-20 21:52:35 +000040 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
David Howells952efe72009-04-03 16:42:39 +010041
David Howells5753c442009-11-19 18:11:19 +000042 fscache_stat(&fscache_n_op_enqueue);
43 switch (op->flags & FSCACHE_OP_TYPE) {
Tejun Heo8af7c122010-07-20 22:09:01 +020044 case FSCACHE_OP_ASYNC:
45 _debug("queue async");
David Howells5753c442009-11-19 18:11:19 +000046 atomic_inc(&op->usage);
Tejun Heo8af7c122010-07-20 22:09:01 +020047 if (!queue_work(fscache_op_wq, &op->work))
David Howells5753c442009-11-19 18:11:19 +000048 fscache_put_operation(op);
49 break;
David Howells5753c442009-11-19 18:11:19 +000050 case FSCACHE_OP_MYTHREAD:
51 _debug("queue for caller's attention");
52 break;
53 default:
Fabian Frederick36dfd112014-06-04 16:05:38 -070054 pr_err("Unexpected op type %lx", op->flags);
David Howells5753c442009-11-19 18:11:19 +000055 BUG();
56 break;
David Howells952efe72009-04-03 16:42:39 +010057 }
58}
59EXPORT_SYMBOL(fscache_enqueue_operation);
60
61/*
62 * start an op running
63 */
64static void fscache_run_op(struct fscache_object *object,
65 struct fscache_operation *op)
66{
David Howells9f105232012-12-20 21:52:35 +000067 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
68
69 op->state = FSCACHE_OP_ST_IN_PROGRESS;
David Howells952efe72009-04-03 16:42:39 +010070 object->n_in_progress++;
71 if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
72 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
73 if (op->processor)
74 fscache_enqueue_operation(op);
75 fscache_stat(&fscache_n_op_run);
76}
77
78/*
David Howells3c305982015-02-24 10:39:28 +000079 * report an unexpected submission
80 */
81static void fscache_report_unexpected_submission(struct fscache_object *object,
82 struct fscache_operation *op,
83 const struct fscache_state *ostate)
84{
85 static bool once_only;
86 struct fscache_operation *p;
87 unsigned n;
88
89 if (once_only)
90 return;
91 once_only = true;
92
93 kdebug("unexpected submission OP%x [OBJ%x %s]",
94 op->debug_id, object->debug_id, object->state->name);
95 kdebug("objstate=%s [%s]", object->state->name, ostate->name);
96 kdebug("objflags=%lx", object->flags);
97 kdebug("objevent=%lx [%lx]", object->events, object->event_mask);
98 kdebug("ops=%u inp=%u exc=%u",
99 object->n_ops, object->n_in_progress, object->n_exclusive);
100
101 if (!list_empty(&object->pending_ops)) {
102 n = 0;
103 list_for_each_entry(p, &object->pending_ops, pend_link) {
104 ASSERTCMP(p->object, ==, object);
105 kdebug("%p %p", op->processor, op->release);
106 n++;
107 }
108
109 kdebug("n=%u", n);
110 }
111
112 dump_stack();
113}
114
115/*
David Howells952efe72009-04-03 16:42:39 +0100116 * submit an exclusive operation for an object
117 * - other ops are excluded from running simultaneously with this one
118 * - this gets any extra refs it needs on an op
119 */
120int fscache_submit_exclusive_op(struct fscache_object *object,
121 struct fscache_operation *op)
122{
David Howells30ceec62015-02-24 10:05:27 +0000123 const struct fscache_state *ostate;
124 unsigned long flags;
David Howells8d763492012-12-05 13:34:48 +0000125 int ret;
126
David Howells952efe72009-04-03 16:42:39 +0100127 _enter("{OBJ%x OP%x},", object->debug_id, op->debug_id);
128
David Howells9f105232012-12-20 21:52:35 +0000129 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED);
130 ASSERTCMP(atomic_read(&op->usage), >, 0);
131
David Howells952efe72009-04-03 16:42:39 +0100132 spin_lock(&object->lock);
133 ASSERTCMP(object->n_ops, >=, object->n_in_progress);
134 ASSERTCMP(object->n_ops, >=, object->n_exclusive);
David Howells5753c442009-11-19 18:11:19 +0000135 ASSERT(list_empty(&op->pend_link));
David Howells952efe72009-04-03 16:42:39 +0100136
David Howells30ceec62015-02-24 10:05:27 +0000137 ostate = object->state;
138 smp_rmb();
139
David Howells9f105232012-12-20 21:52:35 +0000140 op->state = FSCACHE_OP_ST_PENDING;
David Howells30ceec62015-02-24 10:05:27 +0000141 flags = READ_ONCE(object->flags);
142 if (unlikely(!(flags & BIT(FSCACHE_OBJECT_IS_LIVE)))) {
143 fscache_stat(&fscache_n_op_rejected);
144 op->state = FSCACHE_OP_ST_CANCELLED;
145 ret = -ENOBUFS;
146 } else if (unlikely(fscache_cache_is_broken(object))) {
147 op->state = FSCACHE_OP_ST_CANCELLED;
148 ret = -EIO;
149 } else if (flags & BIT(FSCACHE_OBJECT_IS_AVAILABLE)) {
David Howells952efe72009-04-03 16:42:39 +0100150 op->object = object;
151 object->n_ops++;
152 object->n_exclusive++; /* reads and writes must wait */
153
David Howells9f105232012-12-20 21:52:35 +0000154 if (object->n_in_progress > 0) {
David Howells952efe72009-04-03 16:42:39 +0100155 atomic_inc(&op->usage);
156 list_add_tail(&op->pend_link, &object->pending_ops);
157 fscache_stat(&fscache_n_op_pend);
158 } else if (!list_empty(&object->pending_ops)) {
159 atomic_inc(&op->usage);
160 list_add_tail(&op->pend_link, &object->pending_ops);
161 fscache_stat(&fscache_n_op_pend);
162 fscache_start_operations(object);
163 } else {
164 ASSERTCMP(object->n_in_progress, ==, 0);
165 fscache_run_op(object, op);
166 }
167
168 /* need to issue a new write op after this */
169 clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
David Howells8d763492012-12-05 13:34:48 +0000170 ret = 0;
David Howells30ceec62015-02-24 10:05:27 +0000171 } else if (flags & BIT(FSCACHE_OBJECT_IS_LOOKED_UP)) {
David Howells952efe72009-04-03 16:42:39 +0100172 op->object = object;
173 object->n_ops++;
174 object->n_exclusive++; /* reads and writes must wait */
175 atomic_inc(&op->usage);
176 list_add_tail(&op->pend_link, &object->pending_ops);
177 fscache_stat(&fscache_n_op_pend);
David Howells8d763492012-12-05 13:34:48 +0000178 ret = 0;
David Howells6515d1d2015-02-25 11:53:57 +0000179 } else if (flags & BIT(FSCACHE_OBJECT_KILLED_BY_CACHE)) {
180 op->state = FSCACHE_OP_ST_CANCELLED;
181 ret = -ENOBUFS;
David Howells952efe72009-04-03 16:42:39 +0100182 } else {
David Howells30ceec62015-02-24 10:05:27 +0000183 fscache_report_unexpected_submission(object, op, ostate);
184 op->state = FSCACHE_OP_ST_CANCELLED;
185 ret = -ENOBUFS;
David Howells952efe72009-04-03 16:42:39 +0100186 }
187
188 spin_unlock(&object->lock);
David Howells8d763492012-12-05 13:34:48 +0000189 return ret;
David Howells952efe72009-04-03 16:42:39 +0100190}
191
192/*
David Howells952efe72009-04-03 16:42:39 +0100193 * submit an operation for an object
194 * - objects may be submitted only in the following states:
195 * - during object creation (write ops may be submitted)
196 * - whilst the object is active
197 * - after an I/O error incurred in one of the two above states (op rejected)
198 * - this gets any extra refs it needs on an op
199 */
200int fscache_submit_op(struct fscache_object *object,
201 struct fscache_operation *op)
202{
David Howellscaaef692013-05-10 19:50:26 +0100203 const struct fscache_state *ostate;
David Howells30ceec62015-02-24 10:05:27 +0000204 unsigned long flags;
David Howells952efe72009-04-03 16:42:39 +0100205 int ret;
206
207 _enter("{OBJ%x OP%x},{%u}",
208 object->debug_id, op->debug_id, atomic_read(&op->usage));
209
David Howells9f105232012-12-20 21:52:35 +0000210 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED);
David Howells952efe72009-04-03 16:42:39 +0100211 ASSERTCMP(atomic_read(&op->usage), >, 0);
212
213 spin_lock(&object->lock);
214 ASSERTCMP(object->n_ops, >=, object->n_in_progress);
215 ASSERTCMP(object->n_ops, >=, object->n_exclusive);
David Howells5753c442009-11-19 18:11:19 +0000216 ASSERT(list_empty(&op->pend_link));
David Howells952efe72009-04-03 16:42:39 +0100217
218 ostate = object->state;
219 smp_rmb();
220
David Howells9f105232012-12-20 21:52:35 +0000221 op->state = FSCACHE_OP_ST_PENDING;
David Howells30ceec62015-02-24 10:05:27 +0000222 flags = READ_ONCE(object->flags);
223 if (unlikely(!(flags & BIT(FSCACHE_OBJECT_IS_LIVE)))) {
224 fscache_stat(&fscache_n_op_rejected);
225 op->state = FSCACHE_OP_ST_CANCELLED;
226 ret = -ENOBUFS;
227 } else if (unlikely(fscache_cache_is_broken(object))) {
228 op->state = FSCACHE_OP_ST_CANCELLED;
229 ret = -EIO;
230 } else if (flags & BIT(FSCACHE_OBJECT_IS_AVAILABLE)) {
David Howells952efe72009-04-03 16:42:39 +0100231 op->object = object;
232 object->n_ops++;
233
234 if (object->n_exclusive > 0) {
235 atomic_inc(&op->usage);
236 list_add_tail(&op->pend_link, &object->pending_ops);
237 fscache_stat(&fscache_n_op_pend);
238 } else if (!list_empty(&object->pending_ops)) {
239 atomic_inc(&op->usage);
240 list_add_tail(&op->pend_link, &object->pending_ops);
241 fscache_stat(&fscache_n_op_pend);
242 fscache_start_operations(object);
243 } else {
244 ASSERTCMP(object->n_exclusive, ==, 0);
245 fscache_run_op(object, op);
246 }
247 ret = 0;
David Howells30ceec62015-02-24 10:05:27 +0000248 } else if (flags & BIT(FSCACHE_OBJECT_IS_LOOKED_UP)) {
David Howells952efe72009-04-03 16:42:39 +0100249 op->object = object;
250 object->n_ops++;
251 atomic_inc(&op->usage);
252 list_add_tail(&op->pend_link, &object->pending_ops);
253 fscache_stat(&fscache_n_op_pend);
254 ret = 0;
David Howells6515d1d2015-02-25 11:53:57 +0000255 } else if (flags & BIT(FSCACHE_OBJECT_KILLED_BY_CACHE)) {
256 op->state = FSCACHE_OP_ST_CANCELLED;
257 ret = -ENOBUFS;
David Howells30ceec62015-02-24 10:05:27 +0000258 } else {
David Howells952efe72009-04-03 16:42:39 +0100259 fscache_report_unexpected_submission(object, op, ostate);
260 ASSERT(!fscache_object_is_active(object));
David Howells9f105232012-12-20 21:52:35 +0000261 op->state = FSCACHE_OP_ST_CANCELLED;
David Howells952efe72009-04-03 16:42:39 +0100262 ret = -ENOBUFS;
David Howells952efe72009-04-03 16:42:39 +0100263 }
264
265 spin_unlock(&object->lock);
266 return ret;
267}
268
269/*
270 * queue an object for withdrawal on error, aborting all following asynchronous
271 * operations
272 */
273void fscache_abort_object(struct fscache_object *object)
274{
275 _enter("{OBJ%x}", object->debug_id);
276
277 fscache_raise_event(object, FSCACHE_OBJECT_EV_ERROR);
278}
279
280/*
David Howellsdcfae322013-05-24 12:45:31 +0100281 * Jump start the operation processing on an object. The caller must hold
282 * object->lock.
David Howells952efe72009-04-03 16:42:39 +0100283 */
284void fscache_start_operations(struct fscache_object *object)
285{
286 struct fscache_operation *op;
287 bool stop = false;
288
289 while (!list_empty(&object->pending_ops) && !stop) {
290 op = list_entry(object->pending_ops.next,
291 struct fscache_operation, pend_link);
292
293 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) {
294 if (object->n_in_progress > 0)
295 break;
296 stop = true;
297 }
298 list_del_init(&op->pend_link);
David Howells5753c442009-11-19 18:11:19 +0000299 fscache_run_op(object, op);
David Howells952efe72009-04-03 16:42:39 +0100300
301 /* the pending queue was holding a ref on the object */
302 fscache_put_operation(op);
303 }
304
305 ASSERTCMP(object->n_in_progress, <=, object->n_ops);
306
307 _debug("woke %d ops on OBJ%x",
308 object->n_in_progress, object->debug_id);
309}
310
311/*
David Howells5753c442009-11-19 18:11:19 +0000312 * cancel an operation that's pending on an object
313 */
David Howells91c7fbb2012-12-14 11:02:22 +0000314int fscache_cancel_op(struct fscache_operation *op,
315 void (*do_cancel)(struct fscache_operation *))
David Howells5753c442009-11-19 18:11:19 +0000316{
317 struct fscache_object *object = op->object;
318 int ret;
319
320 _enter("OBJ%x OP%x}", op->object->debug_id, op->debug_id);
321
David Howells9f105232012-12-20 21:52:35 +0000322 ASSERTCMP(op->state, >=, FSCACHE_OP_ST_PENDING);
323 ASSERTCMP(op->state, !=, FSCACHE_OP_ST_CANCELLED);
324 ASSERTCMP(atomic_read(&op->usage), >, 0);
325
David Howells5753c442009-11-19 18:11:19 +0000326 spin_lock(&object->lock);
327
328 ret = -EBUSY;
David Howells9f105232012-12-20 21:52:35 +0000329 if (op->state == FSCACHE_OP_ST_PENDING) {
330 ASSERT(!list_empty(&op->pend_link));
David Howells5753c442009-11-19 18:11:19 +0000331 fscache_stat(&fscache_n_op_cancelled);
332 list_del_init(&op->pend_link);
David Howells91c7fbb2012-12-14 11:02:22 +0000333 if (do_cancel)
334 do_cancel(op);
David Howells9f105232012-12-20 21:52:35 +0000335 op->state = FSCACHE_OP_ST_CANCELLED;
David Howells5753c442009-11-19 18:11:19 +0000336 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
337 object->n_exclusive--;
338 if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
339 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
340 fscache_put_operation(op);
341 ret = 0;
342 }
343
344 spin_unlock(&object->lock);
345 _leave(" = %d", ret);
346 return ret;
347}
348
349/*
David Howellsef778e72012-12-20 21:52:36 +0000350 * Cancel all pending operations on an object
351 */
352void fscache_cancel_all_ops(struct fscache_object *object)
353{
354 struct fscache_operation *op;
355
356 _enter("OBJ%x", object->debug_id);
357
358 spin_lock(&object->lock);
359
360 while (!list_empty(&object->pending_ops)) {
361 op = list_entry(object->pending_ops.next,
362 struct fscache_operation, pend_link);
363 fscache_stat(&fscache_n_op_cancelled);
364 list_del_init(&op->pend_link);
365
366 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
367 op->state = FSCACHE_OP_ST_CANCELLED;
368
369 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
370 object->n_exclusive--;
371 if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
372 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
373 fscache_put_operation(op);
374 cond_resched_lock(&object->lock);
375 }
376
377 spin_unlock(&object->lock);
378 _leave("");
379}
380
381/*
David Howells1f372df2012-12-13 20:03:13 +0000382 * Record the completion or cancellation of an in-progress operation.
David Howells9f105232012-12-20 21:52:35 +0000383 */
David Howells1f372df2012-12-13 20:03:13 +0000384void fscache_op_complete(struct fscache_operation *op, bool cancelled)
David Howells9f105232012-12-20 21:52:35 +0000385{
386 struct fscache_object *object = op->object;
387
388 _enter("OBJ%x", object->debug_id);
389
390 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
391 ASSERTCMP(object->n_in_progress, >, 0);
392 ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
393 object->n_exclusive, >, 0);
394 ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
395 object->n_in_progress, ==, 1);
396
397 spin_lock(&object->lock);
398
David Howells1f372df2012-12-13 20:03:13 +0000399 op->state = cancelled ?
400 FSCACHE_OP_ST_CANCELLED : FSCACHE_OP_ST_COMPLETE;
David Howells9f105232012-12-20 21:52:35 +0000401
402 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
403 object->n_exclusive--;
404 object->n_in_progress--;
405 if (object->n_in_progress == 0)
406 fscache_start_operations(object);
407
408 spin_unlock(&object->lock);
409 _leave("");
410}
411EXPORT_SYMBOL(fscache_op_complete);
412
413/*
David Howells952efe72009-04-03 16:42:39 +0100414 * release an operation
415 * - queues pending ops if this is the last in-progress op
416 */
417void fscache_put_operation(struct fscache_operation *op)
418{
419 struct fscache_object *object;
420 struct fscache_cache *cache;
421
422 _enter("{OBJ%x OP%x,%d}",
423 op->object->debug_id, op->debug_id, atomic_read(&op->usage));
424
425 ASSERTCMP(atomic_read(&op->usage), >, 0);
426
427 if (!atomic_dec_and_test(&op->usage))
428 return;
429
430 _debug("PUT OP");
David Howells9f105232012-12-20 21:52:35 +0000431 ASSERTIFCMP(op->state != FSCACHE_OP_ST_COMPLETE,
432 op->state, ==, FSCACHE_OP_ST_CANCELLED);
433 op->state = FSCACHE_OP_ST_DEAD;
David Howells952efe72009-04-03 16:42:39 +0100434
435 fscache_stat(&fscache_n_op_release);
436
437 if (op->release) {
438 op->release(op);
439 op->release = NULL;
440 }
441
442 object = op->object;
443
David Howells13627292013-05-10 19:50:26 +0100444 if (test_bit(FSCACHE_OP_DEC_READ_CNT, &op->flags))
445 atomic_dec(&object->n_reads);
446 if (test_bit(FSCACHE_OP_UNUSE_COOKIE, &op->flags))
447 fscache_unuse_cookie(object);
David Howells4fbf4292009-11-19 18:11:04 +0000448
David Howells952efe72009-04-03 16:42:39 +0100449 /* now... we may get called with the object spinlock held, so we
450 * complete the cleanup here only if we can immediately acquire the
451 * lock, and defer it otherwise */
452 if (!spin_trylock(&object->lock)) {
453 _debug("defer put");
454 fscache_stat(&fscache_n_op_deferred_release);
455
456 cache = object->cache;
457 spin_lock(&cache->op_gc_list_lock);
458 list_add_tail(&op->pend_link, &cache->op_gc_list);
459 spin_unlock(&cache->op_gc_list_lock);
460 schedule_work(&cache->op_gc);
461 _leave(" [defer]");
462 return;
463 }
464
David Howells952efe72009-04-03 16:42:39 +0100465 ASSERTCMP(object->n_ops, >, 0);
466 object->n_ops--;
467 if (object->n_ops == 0)
468 fscache_raise_event(object, FSCACHE_OBJECT_EV_CLEARED);
469
470 spin_unlock(&object->lock);
471
472 kfree(op);
473 _leave(" [done]");
474}
475EXPORT_SYMBOL(fscache_put_operation);
476
477/*
478 * garbage collect operations that have had their release deferred
479 */
480void fscache_operation_gc(struct work_struct *work)
481{
482 struct fscache_operation *op;
483 struct fscache_object *object;
484 struct fscache_cache *cache =
485 container_of(work, struct fscache_cache, op_gc);
486 int count = 0;
487
488 _enter("");
489
490 do {
491 spin_lock(&cache->op_gc_list_lock);
492 if (list_empty(&cache->op_gc_list)) {
493 spin_unlock(&cache->op_gc_list_lock);
494 break;
495 }
496
497 op = list_entry(cache->op_gc_list.next,
498 struct fscache_operation, pend_link);
499 list_del(&op->pend_link);
500 spin_unlock(&cache->op_gc_list_lock);
501
502 object = op->object;
David Howells9f105232012-12-20 21:52:35 +0000503 spin_lock(&object->lock);
David Howells952efe72009-04-03 16:42:39 +0100504
505 _debug("GC DEFERRED REL OBJ%x OP%x",
506 object->debug_id, op->debug_id);
507 fscache_stat(&fscache_n_op_gc);
508
509 ASSERTCMP(atomic_read(&op->usage), ==, 0);
David Howells9f105232012-12-20 21:52:35 +0000510 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
David Howells952efe72009-04-03 16:42:39 +0100511
512 ASSERTCMP(object->n_ops, >, 0);
513 object->n_ops--;
514 if (object->n_ops == 0)
515 fscache_raise_event(object, FSCACHE_OBJECT_EV_CLEARED);
516
517 spin_unlock(&object->lock);
David Howells9f105232012-12-20 21:52:35 +0000518 kfree(op);
David Howells952efe72009-04-03 16:42:39 +0100519
520 } while (count++ < 20);
521
522 if (!list_empty(&cache->op_gc_list))
523 schedule_work(&cache->op_gc);
524
525 _leave("");
526}
527
528/*
Tejun Heo8af7c122010-07-20 22:09:01 +0200529 * execute an operation using fs_op_wq to provide processing context -
530 * the caller holds a ref to this object, so we don't need to hold one
David Howells952efe72009-04-03 16:42:39 +0100531 */
Tejun Heo8af7c122010-07-20 22:09:01 +0200532void fscache_op_work_func(struct work_struct *work)
David Howells952efe72009-04-03 16:42:39 +0100533{
534 struct fscache_operation *op =
Tejun Heo8af7c122010-07-20 22:09:01 +0200535 container_of(work, struct fscache_operation, work);
David Howells952efe72009-04-03 16:42:39 +0100536 unsigned long start;
537
538 _enter("{OBJ%x OP%x,%d}",
539 op->object->debug_id, op->debug_id, atomic_read(&op->usage));
540
541 ASSERT(op->processor != NULL);
542 start = jiffies;
543 op->processor(op);
544 fscache_hist(fscache_ops_histogram, start);
Tejun Heo8af7c122010-07-20 22:09:01 +0200545 fscache_put_operation(op);
David Howells952efe72009-04-03 16:42:39 +0100546
547 _leave("");
548}