operation.c 17 KB

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