operation.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* 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. #define FSCACHE_DEBUG_LEVEL OPERATION
  14. #include <linux/module.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/slab.h>
  17. #include "internal.h"
  18. atomic_t fscache_op_debug_id;
  19. EXPORT_SYMBOL(fscache_op_debug_id);
  20. static void fscache_operation_dummy_cancel(struct fscache_operation *op)
  21. {
  22. }
  23. /**
  24. * fscache_operation_init - Do basic initialisation of an operation
  25. * @op: The operation to initialise
  26. * @release: The release function to assign
  27. *
  28. * Do basic initialisation of an operation. The caller must still set flags,
  29. * object and processor if needed.
  30. */
  31. void fscache_operation_init(struct fscache_cookie *cookie,
  32. struct fscache_operation *op,
  33. fscache_operation_processor_t processor,
  34. fscache_operation_cancel_t cancel,
  35. fscache_operation_release_t release)
  36. {
  37. INIT_WORK(&op->work, fscache_op_work_func);
  38. atomic_set(&op->usage, 1);
  39. op->state = FSCACHE_OP_ST_INITIALISED;
  40. op->debug_id = atomic_inc_return(&fscache_op_debug_id);
  41. op->processor = processor;
  42. op->cancel = cancel ?: fscache_operation_dummy_cancel;
  43. op->release = release;
  44. INIT_LIST_HEAD(&op->pend_link);
  45. fscache_stat(&fscache_n_op_initialised);
  46. trace_fscache_op(cookie, op, fscache_op_init);
  47. }
  48. EXPORT_SYMBOL(fscache_operation_init);
  49. /**
  50. * fscache_enqueue_operation - Enqueue an operation for processing
  51. * @op: The operation to enqueue
  52. *
  53. * Enqueue an operation for processing by the FS-Cache thread pool.
  54. *
  55. * This will get its own ref on the object.
  56. */
  57. void fscache_enqueue_operation(struct fscache_operation *op)
  58. {
  59. struct fscache_cookie *cookie = op->object->cookie;
  60. _enter("{OBJ%x OP%x,%u}",
  61. op->object->debug_id, op->debug_id, atomic_read(&op->usage));
  62. ASSERT(list_empty(&op->pend_link));
  63. ASSERT(op->processor != NULL);
  64. ASSERT(fscache_object_is_available(op->object));
  65. ASSERTCMP(atomic_read(&op->usage), >, 0);
  66. ASSERTIFCMP(op->state != FSCACHE_OP_ST_IN_PROGRESS,
  67. op->state, ==, FSCACHE_OP_ST_CANCELLED);
  68. fscache_stat(&fscache_n_op_enqueue);
  69. switch (op->flags & FSCACHE_OP_TYPE) {
  70. case FSCACHE_OP_ASYNC:
  71. trace_fscache_op(cookie, op, fscache_op_enqueue_async);
  72. _debug("queue async");
  73. atomic_inc(&op->usage);
  74. if (!queue_work(fscache_op_wq, &op->work))
  75. fscache_put_operation(op);
  76. break;
  77. case FSCACHE_OP_MYTHREAD:
  78. trace_fscache_op(cookie, op, fscache_op_enqueue_mythread);
  79. _debug("queue for caller's attention");
  80. break;
  81. default:
  82. pr_err("Unexpected op type %lx", op->flags);
  83. BUG();
  84. break;
  85. }
  86. }
  87. EXPORT_SYMBOL(fscache_enqueue_operation);
  88. /*
  89. * start an op running
  90. */
  91. static void fscache_run_op(struct fscache_object *object,
  92. struct fscache_operation *op)
  93. {
  94. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
  95. op->state = FSCACHE_OP_ST_IN_PROGRESS;
  96. object->n_in_progress++;
  97. if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
  98. wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
  99. if (op->processor)
  100. fscache_enqueue_operation(op);
  101. else
  102. trace_fscache_op(object->cookie, op, fscache_op_run);
  103. fscache_stat(&fscache_n_op_run);
  104. }
  105. /*
  106. * report an unexpected submission
  107. */
  108. static void fscache_report_unexpected_submission(struct fscache_object *object,
  109. struct fscache_operation *op,
  110. const struct fscache_state *ostate)
  111. {
  112. static bool once_only;
  113. struct fscache_operation *p;
  114. unsigned n;
  115. if (once_only)
  116. return;
  117. once_only = true;
  118. kdebug("unexpected submission OP%x [OBJ%x %s]",
  119. op->debug_id, object->debug_id, object->state->name);
  120. kdebug("objstate=%s [%s]", object->state->name, ostate->name);
  121. kdebug("objflags=%lx", object->flags);
  122. kdebug("objevent=%lx [%lx]", object->events, object->event_mask);
  123. kdebug("ops=%u inp=%u exc=%u",
  124. object->n_ops, object->n_in_progress, object->n_exclusive);
  125. if (!list_empty(&object->pending_ops)) {
  126. n = 0;
  127. list_for_each_entry(p, &object->pending_ops, pend_link) {
  128. ASSERTCMP(p->object, ==, object);
  129. kdebug("%p %p", op->processor, op->release);
  130. n++;
  131. }
  132. kdebug("n=%u", n);
  133. }
  134. dump_stack();
  135. }
  136. /*
  137. * submit an exclusive operation for an object
  138. * - other ops are excluded from running simultaneously with this one
  139. * - this gets any extra refs it needs on an op
  140. */
  141. int fscache_submit_exclusive_op(struct fscache_object *object,
  142. struct fscache_operation *op)
  143. {
  144. const struct fscache_state *ostate;
  145. unsigned long flags;
  146. int ret;
  147. _enter("{OBJ%x OP%x},", object->debug_id, op->debug_id);
  148. trace_fscache_op(object->cookie, op, fscache_op_submit_ex);
  149. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED);
  150. ASSERTCMP(atomic_read(&op->usage), >, 0);
  151. spin_lock(&object->lock);
  152. ASSERTCMP(object->n_ops, >=, object->n_in_progress);
  153. ASSERTCMP(object->n_ops, >=, object->n_exclusive);
  154. ASSERT(list_empty(&op->pend_link));
  155. ostate = object->state;
  156. smp_rmb();
  157. op->state = FSCACHE_OP_ST_PENDING;
  158. flags = READ_ONCE(object->flags);
  159. if (unlikely(!(flags & BIT(FSCACHE_OBJECT_IS_LIVE)))) {
  160. fscache_stat(&fscache_n_op_rejected);
  161. op->cancel(op);
  162. op->state = FSCACHE_OP_ST_CANCELLED;
  163. ret = -ENOBUFS;
  164. } else if (unlikely(fscache_cache_is_broken(object))) {
  165. op->cancel(op);
  166. op->state = FSCACHE_OP_ST_CANCELLED;
  167. ret = -EIO;
  168. } else if (flags & BIT(FSCACHE_OBJECT_IS_AVAILABLE)) {
  169. op->object = object;
  170. object->n_ops++;
  171. object->n_exclusive++; /* reads and writes must wait */
  172. if (object->n_in_progress > 0) {
  173. atomic_inc(&op->usage);
  174. list_add_tail(&op->pend_link, &object->pending_ops);
  175. fscache_stat(&fscache_n_op_pend);
  176. } else if (!list_empty(&object->pending_ops)) {
  177. atomic_inc(&op->usage);
  178. list_add_tail(&op->pend_link, &object->pending_ops);
  179. fscache_stat(&fscache_n_op_pend);
  180. fscache_start_operations(object);
  181. } else {
  182. ASSERTCMP(object->n_in_progress, ==, 0);
  183. fscache_run_op(object, op);
  184. }
  185. /* need to issue a new write op after this */
  186. clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
  187. ret = 0;
  188. } else if (flags & BIT(FSCACHE_OBJECT_IS_LOOKED_UP)) {
  189. op->object = object;
  190. object->n_ops++;
  191. object->n_exclusive++; /* reads and writes must wait */
  192. atomic_inc(&op->usage);
  193. list_add_tail(&op->pend_link, &object->pending_ops);
  194. fscache_stat(&fscache_n_op_pend);
  195. ret = 0;
  196. } else if (flags & BIT(FSCACHE_OBJECT_KILLED_BY_CACHE)) {
  197. op->cancel(op);
  198. op->state = FSCACHE_OP_ST_CANCELLED;
  199. ret = -ENOBUFS;
  200. } else {
  201. fscache_report_unexpected_submission(object, op, ostate);
  202. op->cancel(op);
  203. op->state = FSCACHE_OP_ST_CANCELLED;
  204. ret = -ENOBUFS;
  205. }
  206. spin_unlock(&object->lock);
  207. return ret;
  208. }
  209. /*
  210. * submit an operation for an object
  211. * - objects may be submitted only in the following states:
  212. * - during object creation (write ops may be submitted)
  213. * - whilst the object is active
  214. * - after an I/O error incurred in one of the two above states (op rejected)
  215. * - this gets any extra refs it needs on an op
  216. */
  217. int fscache_submit_op(struct fscache_object *object,
  218. struct fscache_operation *op)
  219. {
  220. const struct fscache_state *ostate;
  221. unsigned long flags;
  222. int ret;
  223. _enter("{OBJ%x OP%x},{%u}",
  224. object->debug_id, op->debug_id, atomic_read(&op->usage));
  225. trace_fscache_op(object->cookie, op, fscache_op_submit);
  226. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED);
  227. ASSERTCMP(atomic_read(&op->usage), >, 0);
  228. spin_lock(&object->lock);
  229. ASSERTCMP(object->n_ops, >=, object->n_in_progress);
  230. ASSERTCMP(object->n_ops, >=, object->n_exclusive);
  231. ASSERT(list_empty(&op->pend_link));
  232. ostate = object->state;
  233. smp_rmb();
  234. op->state = FSCACHE_OP_ST_PENDING;
  235. flags = READ_ONCE(object->flags);
  236. if (unlikely(!(flags & BIT(FSCACHE_OBJECT_IS_LIVE)))) {
  237. fscache_stat(&fscache_n_op_rejected);
  238. op->cancel(op);
  239. op->state = FSCACHE_OP_ST_CANCELLED;
  240. ret = -ENOBUFS;
  241. } else if (unlikely(fscache_cache_is_broken(object))) {
  242. op->cancel(op);
  243. op->state = FSCACHE_OP_ST_CANCELLED;
  244. ret = -EIO;
  245. } else if (flags & BIT(FSCACHE_OBJECT_IS_AVAILABLE)) {
  246. op->object = object;
  247. object->n_ops++;
  248. if (object->n_exclusive > 0) {
  249. atomic_inc(&op->usage);
  250. list_add_tail(&op->pend_link, &object->pending_ops);
  251. fscache_stat(&fscache_n_op_pend);
  252. } else if (!list_empty(&object->pending_ops)) {
  253. atomic_inc(&op->usage);
  254. list_add_tail(&op->pend_link, &object->pending_ops);
  255. fscache_stat(&fscache_n_op_pend);
  256. fscache_start_operations(object);
  257. } else {
  258. ASSERTCMP(object->n_exclusive, ==, 0);
  259. fscache_run_op(object, op);
  260. }
  261. ret = 0;
  262. } else if (flags & BIT(FSCACHE_OBJECT_IS_LOOKED_UP)) {
  263. op->object = object;
  264. object->n_ops++;
  265. atomic_inc(&op->usage);
  266. list_add_tail(&op->pend_link, &object->pending_ops);
  267. fscache_stat(&fscache_n_op_pend);
  268. ret = 0;
  269. } else if (flags & BIT(FSCACHE_OBJECT_KILLED_BY_CACHE)) {
  270. op->cancel(op);
  271. op->state = FSCACHE_OP_ST_CANCELLED;
  272. ret = -ENOBUFS;
  273. } else {
  274. fscache_report_unexpected_submission(object, op, ostate);
  275. ASSERT(!fscache_object_is_active(object));
  276. op->cancel(op);
  277. op->state = FSCACHE_OP_ST_CANCELLED;
  278. ret = -ENOBUFS;
  279. }
  280. spin_unlock(&object->lock);
  281. return ret;
  282. }
  283. /*
  284. * queue an object for withdrawal on error, aborting all following asynchronous
  285. * operations
  286. */
  287. void fscache_abort_object(struct fscache_object *object)
  288. {
  289. _enter("{OBJ%x}", object->debug_id);
  290. fscache_raise_event(object, FSCACHE_OBJECT_EV_ERROR);
  291. }
  292. /*
  293. * Jump start the operation processing on an object. The caller must hold
  294. * object->lock.
  295. */
  296. void fscache_start_operations(struct fscache_object *object)
  297. {
  298. struct fscache_operation *op;
  299. bool stop = false;
  300. while (!list_empty(&object->pending_ops) && !stop) {
  301. op = list_entry(object->pending_ops.next,
  302. struct fscache_operation, pend_link);
  303. if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) {
  304. if (object->n_in_progress > 0)
  305. break;
  306. stop = true;
  307. }
  308. list_del_init(&op->pend_link);
  309. fscache_run_op(object, op);
  310. /* the pending queue was holding a ref on the object */
  311. fscache_put_operation(op);
  312. }
  313. ASSERTCMP(object->n_in_progress, <=, object->n_ops);
  314. _debug("woke %d ops on OBJ%x",
  315. object->n_in_progress, object->debug_id);
  316. }
  317. /*
  318. * cancel an operation that's pending on an object
  319. */
  320. int fscache_cancel_op(struct fscache_operation *op,
  321. bool cancel_in_progress_op)
  322. {
  323. struct fscache_object *object = op->object;
  324. bool put = false;
  325. int ret;
  326. _enter("OBJ%x OP%x}", op->object->debug_id, op->debug_id);
  327. trace_fscache_op(object->cookie, op, fscache_op_cancel);
  328. ASSERTCMP(op->state, >=, FSCACHE_OP_ST_PENDING);
  329. ASSERTCMP(op->state, !=, FSCACHE_OP_ST_CANCELLED);
  330. ASSERTCMP(atomic_read(&op->usage), >, 0);
  331. spin_lock(&object->lock);
  332. ret = -EBUSY;
  333. if (op->state == FSCACHE_OP_ST_PENDING) {
  334. ASSERT(!list_empty(&op->pend_link));
  335. list_del_init(&op->pend_link);
  336. put = true;
  337. fscache_stat(&fscache_n_op_cancelled);
  338. op->cancel(op);
  339. op->state = FSCACHE_OP_ST_CANCELLED;
  340. if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
  341. object->n_exclusive--;
  342. if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
  343. wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
  344. ret = 0;
  345. } else if (op->state == FSCACHE_OP_ST_IN_PROGRESS && cancel_in_progress_op) {
  346. ASSERTCMP(object->n_in_progress, >, 0);
  347. if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
  348. object->n_exclusive--;
  349. object->n_in_progress--;
  350. if (object->n_in_progress == 0)
  351. fscache_start_operations(object);
  352. fscache_stat(&fscache_n_op_cancelled);
  353. op->cancel(op);
  354. op->state = FSCACHE_OP_ST_CANCELLED;
  355. if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
  356. object->n_exclusive--;
  357. if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
  358. wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
  359. ret = 0;
  360. }
  361. if (put)
  362. fscache_put_operation(op);
  363. spin_unlock(&object->lock);
  364. _leave(" = %d", ret);
  365. return ret;
  366. }
  367. /*
  368. * Cancel all pending operations on an object
  369. */
  370. void fscache_cancel_all_ops(struct fscache_object *object)
  371. {
  372. struct fscache_operation *op;
  373. _enter("OBJ%x", object->debug_id);
  374. spin_lock(&object->lock);
  375. while (!list_empty(&object->pending_ops)) {
  376. op = list_entry(object->pending_ops.next,
  377. struct fscache_operation, pend_link);
  378. fscache_stat(&fscache_n_op_cancelled);
  379. list_del_init(&op->pend_link);
  380. trace_fscache_op(object->cookie, op, fscache_op_cancel_all);
  381. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
  382. op->cancel(op);
  383. op->state = FSCACHE_OP_ST_CANCELLED;
  384. if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
  385. object->n_exclusive--;
  386. if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
  387. wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
  388. fscache_put_operation(op);
  389. cond_resched_lock(&object->lock);
  390. }
  391. spin_unlock(&object->lock);
  392. _leave("");
  393. }
  394. /*
  395. * Record the completion or cancellation of an in-progress operation.
  396. */
  397. void fscache_op_complete(struct fscache_operation *op, bool cancelled)
  398. {
  399. struct fscache_object *object = op->object;
  400. _enter("OBJ%x", object->debug_id);
  401. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
  402. ASSERTCMP(object->n_in_progress, >, 0);
  403. ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
  404. object->n_exclusive, >, 0);
  405. ASSERTIFCMP(test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags),
  406. object->n_in_progress, ==, 1);
  407. spin_lock(&object->lock);
  408. if (!cancelled) {
  409. trace_fscache_op(object->cookie, op, fscache_op_completed);
  410. op->state = FSCACHE_OP_ST_COMPLETE;
  411. } else {
  412. op->cancel(op);
  413. trace_fscache_op(object->cookie, op, fscache_op_cancelled);
  414. op->state = FSCACHE_OP_ST_CANCELLED;
  415. }
  416. if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
  417. object->n_exclusive--;
  418. object->n_in_progress--;
  419. if (object->n_in_progress == 0)
  420. fscache_start_operations(object);
  421. spin_unlock(&object->lock);
  422. _leave("");
  423. }
  424. EXPORT_SYMBOL(fscache_op_complete);
  425. /*
  426. * release an operation
  427. * - queues pending ops if this is the last in-progress op
  428. */
  429. void fscache_put_operation(struct fscache_operation *op)
  430. {
  431. struct fscache_object *object;
  432. struct fscache_cache *cache;
  433. _enter("{OBJ%x OP%x,%d}",
  434. op->object ? op->object->debug_id : 0,
  435. op->debug_id, atomic_read(&op->usage));
  436. ASSERTCMP(atomic_read(&op->usage), >, 0);
  437. if (!atomic_dec_and_test(&op->usage))
  438. return;
  439. trace_fscache_op(op->object ? op->object->cookie : NULL, op, fscache_op_put);
  440. _debug("PUT OP");
  441. ASSERTIFCMP(op->state != FSCACHE_OP_ST_INITIALISED &&
  442. op->state != FSCACHE_OP_ST_COMPLETE,
  443. op->state, ==, FSCACHE_OP_ST_CANCELLED);
  444. fscache_stat(&fscache_n_op_release);
  445. if (op->release) {
  446. op->release(op);
  447. op->release = NULL;
  448. }
  449. op->state = FSCACHE_OP_ST_DEAD;
  450. object = op->object;
  451. if (likely(object)) {
  452. if (test_bit(FSCACHE_OP_DEC_READ_CNT, &op->flags))
  453. atomic_dec(&object->n_reads);
  454. if (test_bit(FSCACHE_OP_UNUSE_COOKIE, &op->flags))
  455. fscache_unuse_cookie(object);
  456. /* now... we may get called with the object spinlock held, so we
  457. * complete the cleanup here only if we can immediately acquire the
  458. * lock, and defer it otherwise */
  459. if (!spin_trylock(&object->lock)) {
  460. _debug("defer put");
  461. fscache_stat(&fscache_n_op_deferred_release);
  462. cache = object->cache;
  463. spin_lock(&cache->op_gc_list_lock);
  464. list_add_tail(&op->pend_link, &cache->op_gc_list);
  465. spin_unlock(&cache->op_gc_list_lock);
  466. schedule_work(&cache->op_gc);
  467. _leave(" [defer]");
  468. return;
  469. }
  470. ASSERTCMP(object->n_ops, >, 0);
  471. object->n_ops--;
  472. if (object->n_ops == 0)
  473. fscache_raise_event(object, FSCACHE_OBJECT_EV_CLEARED);
  474. spin_unlock(&object->lock);
  475. }
  476. kfree(op);
  477. _leave(" [done]");
  478. }
  479. EXPORT_SYMBOL(fscache_put_operation);
  480. /*
  481. * garbage collect operations that have had their release deferred
  482. */
  483. void fscache_operation_gc(struct work_struct *work)
  484. {
  485. struct fscache_operation *op;
  486. struct fscache_object *object;
  487. struct fscache_cache *cache =
  488. container_of(work, struct fscache_cache, op_gc);
  489. int count = 0;
  490. _enter("");
  491. do {
  492. spin_lock(&cache->op_gc_list_lock);
  493. if (list_empty(&cache->op_gc_list)) {
  494. spin_unlock(&cache->op_gc_list_lock);
  495. break;
  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. object = op->object;
  502. trace_fscache_op(object->cookie, op, fscache_op_gc);
  503. spin_lock(&object->lock);
  504. _debug("GC DEFERRED REL OBJ%x OP%x",
  505. object->debug_id, op->debug_id);
  506. fscache_stat(&fscache_n_op_gc);
  507. ASSERTCMP(atomic_read(&op->usage), ==, 0);
  508. ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
  509. ASSERTCMP(object->n_ops, >, 0);
  510. object->n_ops--;
  511. if (object->n_ops == 0)
  512. fscache_raise_event(object, FSCACHE_OBJECT_EV_CLEARED);
  513. spin_unlock(&object->lock);
  514. kfree(op);
  515. } while (count++ < 20);
  516. if (!list_empty(&cache->op_gc_list))
  517. schedule_work(&cache->op_gc);
  518. _leave("");
  519. }
  520. /*
  521. * execute an operation using fs_op_wq to provide processing context -
  522. * the caller holds a ref to this object, so we don't need to hold one
  523. */
  524. void fscache_op_work_func(struct work_struct *work)
  525. {
  526. struct fscache_operation *op =
  527. container_of(work, struct fscache_operation, work);
  528. unsigned long start;
  529. _enter("{OBJ%x OP%x,%d}",
  530. op->object->debug_id, op->debug_id, atomic_read(&op->usage));
  531. trace_fscache_op(op->object->cookie, op, fscache_op_work);
  532. ASSERT(op->processor != NULL);
  533. start = jiffies;
  534. op->processor(op);
  535. fscache_hist(fscache_ops_histogram, start);
  536. fscache_put_operation(op);
  537. _leave("");
  538. }