xfs_log_cil.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * Copyright (c) 2010 Red Hat, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write the Free Software Foundation,
  15. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #include "xfs.h"
  18. #include "xfs_fs.h"
  19. #include "xfs_format.h"
  20. #include "xfs_log_format.h"
  21. #include "xfs_shared.h"
  22. #include "xfs_trans_resv.h"
  23. #include "xfs_mount.h"
  24. #include "xfs_error.h"
  25. #include "xfs_alloc.h"
  26. #include "xfs_extent_busy.h"
  27. #include "xfs_discard.h"
  28. #include "xfs_trans.h"
  29. #include "xfs_trans_priv.h"
  30. #include "xfs_log.h"
  31. #include "xfs_log_priv.h"
  32. #include "xfs_trace.h"
  33. struct workqueue_struct *xfs_discard_wq;
  34. /*
  35. * Allocate a new ticket. Failing to get a new ticket makes it really hard to
  36. * recover, so we don't allow failure here. Also, we allocate in a context that
  37. * we don't want to be issuing transactions from, so we need to tell the
  38. * allocation code this as well.
  39. *
  40. * We don't reserve any space for the ticket - we are going to steal whatever
  41. * space we require from transactions as they commit. To ensure we reserve all
  42. * the space required, we need to set the current reservation of the ticket to
  43. * zero so that we know to steal the initial transaction overhead from the
  44. * first transaction commit.
  45. */
  46. static struct xlog_ticket *
  47. xlog_cil_ticket_alloc(
  48. struct xlog *log)
  49. {
  50. struct xlog_ticket *tic;
  51. tic = xlog_ticket_alloc(log, 0, 1, XFS_TRANSACTION, 0,
  52. KM_SLEEP|KM_NOFS);
  53. /*
  54. * set the current reservation to zero so we know to steal the basic
  55. * transaction overhead reservation from the first transaction commit.
  56. */
  57. tic->t_curr_res = 0;
  58. return tic;
  59. }
  60. /*
  61. * After the first stage of log recovery is done, we know where the head and
  62. * tail of the log are. We need this log initialisation done before we can
  63. * initialise the first CIL checkpoint context.
  64. *
  65. * Here we allocate a log ticket to track space usage during a CIL push. This
  66. * ticket is passed to xlog_write() directly so that we don't slowly leak log
  67. * space by failing to account for space used by log headers and additional
  68. * region headers for split regions.
  69. */
  70. void
  71. xlog_cil_init_post_recovery(
  72. struct xlog *log)
  73. {
  74. log->l_cilp->xc_ctx->ticket = xlog_cil_ticket_alloc(log);
  75. log->l_cilp->xc_ctx->sequence = 1;
  76. }
  77. static inline int
  78. xlog_cil_iovec_space(
  79. uint niovecs)
  80. {
  81. return round_up((sizeof(struct xfs_log_vec) +
  82. niovecs * sizeof(struct xfs_log_iovec)),
  83. sizeof(uint64_t));
  84. }
  85. /*
  86. * Allocate or pin log vector buffers for CIL insertion.
  87. *
  88. * The CIL currently uses disposable buffers for copying a snapshot of the
  89. * modified items into the log during a push. The biggest problem with this is
  90. * the requirement to allocate the disposable buffer during the commit if:
  91. * a) does not exist; or
  92. * b) it is too small
  93. *
  94. * If we do this allocation within xlog_cil_insert_format_items(), it is done
  95. * under the xc_ctx_lock, which means that a CIL push cannot occur during
  96. * the memory allocation. This means that we have a potential deadlock situation
  97. * under low memory conditions when we have lots of dirty metadata pinned in
  98. * the CIL and we need a CIL commit to occur to free memory.
  99. *
  100. * To avoid this, we need to move the memory allocation outside the
  101. * xc_ctx_lock, but because the log vector buffers are disposable, that opens
  102. * up a TOCTOU race condition w.r.t. the CIL committing and removing the log
  103. * vector buffers between the check and the formatting of the item into the
  104. * log vector buffer within the xc_ctx_lock.
  105. *
  106. * Because the log vector buffer needs to be unchanged during the CIL push
  107. * process, we cannot share the buffer between the transaction commit (which
  108. * modifies the buffer) and the CIL push context that is writing the changes
  109. * into the log. This means skipping preallocation of buffer space is
  110. * unreliable, but we most definitely do not want to be allocating and freeing
  111. * buffers unnecessarily during commits when overwrites can be done safely.
  112. *
  113. * The simplest solution to this problem is to allocate a shadow buffer when a
  114. * log item is committed for the second time, and then to only use this buffer
  115. * if necessary. The buffer can remain attached to the log item until such time
  116. * it is needed, and this is the buffer that is reallocated to match the size of
  117. * the incoming modification. Then during the formatting of the item we can swap
  118. * the active buffer with the new one if we can't reuse the existing buffer. We
  119. * don't free the old buffer as it may be reused on the next modification if
  120. * it's size is right, otherwise we'll free and reallocate it at that point.
  121. *
  122. * This function builds a vector for the changes in each log item in the
  123. * transaction. It then works out the length of the buffer needed for each log
  124. * item, allocates them and attaches the vector to the log item in preparation
  125. * for the formatting step which occurs under the xc_ctx_lock.
  126. *
  127. * While this means the memory footprint goes up, it avoids the repeated
  128. * alloc/free pattern that repeated modifications of an item would otherwise
  129. * cause, and hence minimises the CPU overhead of such behaviour.
  130. */
  131. static void
  132. xlog_cil_alloc_shadow_bufs(
  133. struct xlog *log,
  134. struct xfs_trans *tp)
  135. {
  136. struct xfs_log_item_desc *lidp;
  137. list_for_each_entry(lidp, &tp->t_items, lid_trans) {
  138. struct xfs_log_item *lip = lidp->lid_item;
  139. struct xfs_log_vec *lv;
  140. int niovecs = 0;
  141. int nbytes = 0;
  142. int buf_size;
  143. bool ordered = false;
  144. /* Skip items which aren't dirty in this transaction. */
  145. if (!(lidp->lid_flags & XFS_LID_DIRTY))
  146. continue;
  147. /* get number of vecs and size of data to be stored */
  148. lip->li_ops->iop_size(lip, &niovecs, &nbytes);
  149. /*
  150. * Ordered items need to be tracked but we do not wish to write
  151. * them. We need a logvec to track the object, but we do not
  152. * need an iovec or buffer to be allocated for copying data.
  153. */
  154. if (niovecs == XFS_LOG_VEC_ORDERED) {
  155. ordered = true;
  156. niovecs = 0;
  157. nbytes = 0;
  158. }
  159. /*
  160. * We 64-bit align the length of each iovec so that the start
  161. * of the next one is naturally aligned. We'll need to
  162. * account for that slack space here. Then round nbytes up
  163. * to 64-bit alignment so that the initial buffer alignment is
  164. * easy to calculate and verify.
  165. */
  166. nbytes += niovecs * sizeof(uint64_t);
  167. nbytes = round_up(nbytes, sizeof(uint64_t));
  168. /*
  169. * The data buffer needs to start 64-bit aligned, so round up
  170. * that space to ensure we can align it appropriately and not
  171. * overrun the buffer.
  172. */
  173. buf_size = nbytes + xlog_cil_iovec_space(niovecs);
  174. /*
  175. * if we have no shadow buffer, or it is too small, we need to
  176. * reallocate it.
  177. */
  178. if (!lip->li_lv_shadow ||
  179. buf_size > lip->li_lv_shadow->lv_size) {
  180. /*
  181. * We free and allocate here as a realloc would copy
  182. * unecessary data. We don't use kmem_zalloc() for the
  183. * same reason - we don't need to zero the data area in
  184. * the buffer, only the log vector header and the iovec
  185. * storage.
  186. */
  187. kmem_free(lip->li_lv_shadow);
  188. lv = kmem_alloc_large(buf_size, KM_SLEEP | KM_NOFS);
  189. memset(lv, 0, xlog_cil_iovec_space(niovecs));
  190. lv->lv_item = lip;
  191. lv->lv_size = buf_size;
  192. if (ordered)
  193. lv->lv_buf_len = XFS_LOG_VEC_ORDERED;
  194. else
  195. lv->lv_iovecp = (struct xfs_log_iovec *)&lv[1];
  196. lip->li_lv_shadow = lv;
  197. } else {
  198. /* same or smaller, optimise common overwrite case */
  199. lv = lip->li_lv_shadow;
  200. if (ordered)
  201. lv->lv_buf_len = XFS_LOG_VEC_ORDERED;
  202. else
  203. lv->lv_buf_len = 0;
  204. lv->lv_bytes = 0;
  205. lv->lv_next = NULL;
  206. }
  207. /* Ensure the lv is set up according to ->iop_size */
  208. lv->lv_niovecs = niovecs;
  209. /* The allocated data region lies beyond the iovec region */
  210. lv->lv_buf = (char *)lv + xlog_cil_iovec_space(niovecs);
  211. }
  212. }
  213. /*
  214. * Prepare the log item for insertion into the CIL. Calculate the difference in
  215. * log space and vectors it will consume, and if it is a new item pin it as
  216. * well.
  217. */
  218. STATIC void
  219. xfs_cil_prepare_item(
  220. struct xlog *log,
  221. struct xfs_log_vec *lv,
  222. struct xfs_log_vec *old_lv,
  223. int *diff_len,
  224. int *diff_iovecs)
  225. {
  226. /* Account for the new LV being passed in */
  227. if (lv->lv_buf_len != XFS_LOG_VEC_ORDERED) {
  228. *diff_len += lv->lv_bytes;
  229. *diff_iovecs += lv->lv_niovecs;
  230. }
  231. /*
  232. * If there is no old LV, this is the first time we've seen the item in
  233. * this CIL context and so we need to pin it. If we are replacing the
  234. * old_lv, then remove the space it accounts for and make it the shadow
  235. * buffer for later freeing. In both cases we are now switching to the
  236. * shadow buffer, so update the the pointer to it appropriately.
  237. */
  238. if (!old_lv) {
  239. lv->lv_item->li_ops->iop_pin(lv->lv_item);
  240. lv->lv_item->li_lv_shadow = NULL;
  241. } else if (old_lv != lv) {
  242. ASSERT(lv->lv_buf_len != XFS_LOG_VEC_ORDERED);
  243. *diff_len -= old_lv->lv_bytes;
  244. *diff_iovecs -= old_lv->lv_niovecs;
  245. lv->lv_item->li_lv_shadow = old_lv;
  246. }
  247. /* attach new log vector to log item */
  248. lv->lv_item->li_lv = lv;
  249. /*
  250. * If this is the first time the item is being committed to the
  251. * CIL, store the sequence number on the log item so we can
  252. * tell in future commits whether this is the first checkpoint
  253. * the item is being committed into.
  254. */
  255. if (!lv->lv_item->li_seq)
  256. lv->lv_item->li_seq = log->l_cilp->xc_ctx->sequence;
  257. }
  258. /*
  259. * Format log item into a flat buffers
  260. *
  261. * For delayed logging, we need to hold a formatted buffer containing all the
  262. * changes on the log item. This enables us to relog the item in memory and
  263. * write it out asynchronously without needing to relock the object that was
  264. * modified at the time it gets written into the iclog.
  265. *
  266. * This function takes the prepared log vectors attached to each log item, and
  267. * formats the changes into the log vector buffer. The buffer it uses is
  268. * dependent on the current state of the vector in the CIL - the shadow lv is
  269. * guaranteed to be large enough for the current modification, but we will only
  270. * use that if we can't reuse the existing lv. If we can't reuse the existing
  271. * lv, then simple swap it out for the shadow lv. We don't free it - that is
  272. * done lazily either by th enext modification or the freeing of the log item.
  273. *
  274. * We don't set up region headers during this process; we simply copy the
  275. * regions into the flat buffer. We can do this because we still have to do a
  276. * formatting step to write the regions into the iclog buffer. Writing the
  277. * ophdrs during the iclog write means that we can support splitting large
  278. * regions across iclog boundares without needing a change in the format of the
  279. * item/region encapsulation.
  280. *
  281. * Hence what we need to do now is change the rewrite the vector array to point
  282. * to the copied region inside the buffer we just allocated. This allows us to
  283. * format the regions into the iclog as though they are being formatted
  284. * directly out of the objects themselves.
  285. */
  286. static void
  287. xlog_cil_insert_format_items(
  288. struct xlog *log,
  289. struct xfs_trans *tp,
  290. int *diff_len,
  291. int *diff_iovecs)
  292. {
  293. struct xfs_log_item_desc *lidp;
  294. /* Bail out if we didn't find a log item. */
  295. if (list_empty(&tp->t_items)) {
  296. ASSERT(0);
  297. return;
  298. }
  299. list_for_each_entry(lidp, &tp->t_items, lid_trans) {
  300. struct xfs_log_item *lip = lidp->lid_item;
  301. struct xfs_log_vec *lv;
  302. struct xfs_log_vec *old_lv = NULL;
  303. struct xfs_log_vec *shadow;
  304. bool ordered = false;
  305. /* Skip items which aren't dirty in this transaction. */
  306. if (!(lidp->lid_flags & XFS_LID_DIRTY))
  307. continue;
  308. /*
  309. * The formatting size information is already attached to
  310. * the shadow lv on the log item.
  311. */
  312. shadow = lip->li_lv_shadow;
  313. if (shadow->lv_buf_len == XFS_LOG_VEC_ORDERED)
  314. ordered = true;
  315. /* Skip items that do not have any vectors for writing */
  316. if (!shadow->lv_niovecs && !ordered)
  317. continue;
  318. /* compare to existing item size */
  319. old_lv = lip->li_lv;
  320. if (lip->li_lv && shadow->lv_size <= lip->li_lv->lv_size) {
  321. /* same or smaller, optimise common overwrite case */
  322. lv = lip->li_lv;
  323. lv->lv_next = NULL;
  324. if (ordered)
  325. goto insert;
  326. /*
  327. * set the item up as though it is a new insertion so
  328. * that the space reservation accounting is correct.
  329. */
  330. *diff_iovecs -= lv->lv_niovecs;
  331. *diff_len -= lv->lv_bytes;
  332. /* Ensure the lv is set up according to ->iop_size */
  333. lv->lv_niovecs = shadow->lv_niovecs;
  334. /* reset the lv buffer information for new formatting */
  335. lv->lv_buf_len = 0;
  336. lv->lv_bytes = 0;
  337. lv->lv_buf = (char *)lv +
  338. xlog_cil_iovec_space(lv->lv_niovecs);
  339. } else {
  340. /* switch to shadow buffer! */
  341. lv = shadow;
  342. lv->lv_item = lip;
  343. if (ordered) {
  344. /* track as an ordered logvec */
  345. ASSERT(lip->li_lv == NULL);
  346. goto insert;
  347. }
  348. }
  349. ASSERT(IS_ALIGNED((unsigned long)lv->lv_buf, sizeof(uint64_t)));
  350. lip->li_ops->iop_format(lip, lv);
  351. insert:
  352. xfs_cil_prepare_item(log, lv, old_lv, diff_len, diff_iovecs);
  353. }
  354. }
  355. /*
  356. * Insert the log items into the CIL and calculate the difference in space
  357. * consumed by the item. Add the space to the checkpoint ticket and calculate
  358. * if the change requires additional log metadata. If it does, take that space
  359. * as well. Remove the amount of space we added to the checkpoint ticket from
  360. * the current transaction ticket so that the accounting works out correctly.
  361. */
  362. static void
  363. xlog_cil_insert_items(
  364. struct xlog *log,
  365. struct xfs_trans *tp)
  366. {
  367. struct xfs_cil *cil = log->l_cilp;
  368. struct xfs_cil_ctx *ctx = cil->xc_ctx;
  369. struct xfs_log_item_desc *lidp;
  370. int len = 0;
  371. int diff_iovecs = 0;
  372. int iclog_space;
  373. int iovhdr_res = 0, split_res = 0, ctx_res = 0;
  374. ASSERT(tp);
  375. /*
  376. * We can do this safely because the context can't checkpoint until we
  377. * are done so it doesn't matter exactly how we update the CIL.
  378. */
  379. xlog_cil_insert_format_items(log, tp, &len, &diff_iovecs);
  380. spin_lock(&cil->xc_cil_lock);
  381. /* account for space used by new iovec headers */
  382. iovhdr_res = diff_iovecs * sizeof(xlog_op_header_t);
  383. len += iovhdr_res;
  384. ctx->nvecs += diff_iovecs;
  385. /* attach the transaction to the CIL if it has any busy extents */
  386. if (!list_empty(&tp->t_busy))
  387. list_splice_init(&tp->t_busy, &ctx->busy_extents);
  388. /*
  389. * Now transfer enough transaction reservation to the context ticket
  390. * for the checkpoint. The context ticket is special - the unit
  391. * reservation has to grow as well as the current reservation as we
  392. * steal from tickets so we can correctly determine the space used
  393. * during the transaction commit.
  394. */
  395. if (ctx->ticket->t_curr_res == 0) {
  396. ctx_res = ctx->ticket->t_unit_res;
  397. ctx->ticket->t_curr_res = ctx_res;
  398. tp->t_ticket->t_curr_res -= ctx_res;
  399. }
  400. /* do we need space for more log record headers? */
  401. iclog_space = log->l_iclog_size - log->l_iclog_hsize;
  402. if (len > 0 && (ctx->space_used / iclog_space !=
  403. (ctx->space_used + len) / iclog_space)) {
  404. split_res = (len + iclog_space - 1) / iclog_space;
  405. /* need to take into account split region headers, too */
  406. split_res *= log->l_iclog_hsize + sizeof(struct xlog_op_header);
  407. ctx->ticket->t_unit_res += split_res;
  408. ctx->ticket->t_curr_res += split_res;
  409. tp->t_ticket->t_curr_res -= split_res;
  410. ASSERT(tp->t_ticket->t_curr_res >= len);
  411. }
  412. tp->t_ticket->t_curr_res -= len;
  413. ctx->space_used += len;
  414. /*
  415. * If we've overrun the reservation, dump the tx details before we move
  416. * the log items. Shutdown is imminent...
  417. */
  418. if (WARN_ON(tp->t_ticket->t_curr_res < 0)) {
  419. xfs_warn(log->l_mp, "Transaction log reservation overrun:");
  420. xfs_warn(log->l_mp,
  421. " log items: %d bytes (iov hdrs: %d bytes)",
  422. len, iovhdr_res);
  423. xfs_warn(log->l_mp, " split region headers: %d bytes",
  424. split_res);
  425. xfs_warn(log->l_mp, " ctx ticket: %d bytes", ctx_res);
  426. xlog_print_trans(tp);
  427. }
  428. /*
  429. * Now (re-)position everything modified at the tail of the CIL.
  430. * We do this here so we only need to take the CIL lock once during
  431. * the transaction commit.
  432. */
  433. list_for_each_entry(lidp, &tp->t_items, lid_trans) {
  434. struct xfs_log_item *lip = lidp->lid_item;
  435. /* Skip items which aren't dirty in this transaction. */
  436. if (!(lidp->lid_flags & XFS_LID_DIRTY))
  437. continue;
  438. /*
  439. * Only move the item if it isn't already at the tail. This is
  440. * to prevent a transient list_empty() state when reinserting
  441. * an item that is already the only item in the CIL.
  442. */
  443. if (!list_is_last(&lip->li_cil, &cil->xc_cil))
  444. list_move_tail(&lip->li_cil, &cil->xc_cil);
  445. }
  446. spin_unlock(&cil->xc_cil_lock);
  447. if (tp->t_ticket->t_curr_res < 0)
  448. xfs_force_shutdown(log->l_mp, SHUTDOWN_LOG_IO_ERROR);
  449. }
  450. static void
  451. xlog_cil_free_logvec(
  452. struct xfs_log_vec *log_vector)
  453. {
  454. struct xfs_log_vec *lv;
  455. for (lv = log_vector; lv; ) {
  456. struct xfs_log_vec *next = lv->lv_next;
  457. kmem_free(lv);
  458. lv = next;
  459. }
  460. }
  461. static void
  462. xlog_discard_endio_work(
  463. struct work_struct *work)
  464. {
  465. struct xfs_cil_ctx *ctx =
  466. container_of(work, struct xfs_cil_ctx, discard_endio_work);
  467. struct xfs_mount *mp = ctx->cil->xc_log->l_mp;
  468. xfs_extent_busy_clear(mp, &ctx->busy_extents, false);
  469. kmem_free(ctx);
  470. }
  471. /*
  472. * Queue up the actual completion to a thread to avoid IRQ-safe locking for
  473. * pagb_lock. Note that we need a unbounded workqueue, otherwise we might
  474. * get the execution delayed up to 30 seconds for weird reasons.
  475. */
  476. static void
  477. xlog_discard_endio(
  478. struct bio *bio)
  479. {
  480. struct xfs_cil_ctx *ctx = bio->bi_private;
  481. INIT_WORK(&ctx->discard_endio_work, xlog_discard_endio_work);
  482. queue_work(xfs_discard_wq, &ctx->discard_endio_work);
  483. bio_put(bio);
  484. }
  485. static void
  486. xlog_discard_busy_extents(
  487. struct xfs_mount *mp,
  488. struct xfs_cil_ctx *ctx)
  489. {
  490. struct list_head *list = &ctx->busy_extents;
  491. struct xfs_extent_busy *busyp;
  492. struct bio *bio = NULL;
  493. struct blk_plug plug;
  494. int error = 0;
  495. ASSERT(mp->m_flags & XFS_MOUNT_DISCARD);
  496. blk_start_plug(&plug);
  497. list_for_each_entry(busyp, list, list) {
  498. trace_xfs_discard_extent(mp, busyp->agno, busyp->bno,
  499. busyp->length);
  500. error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev,
  501. XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno),
  502. XFS_FSB_TO_BB(mp, busyp->length),
  503. GFP_NOFS, 0, &bio);
  504. if (error && error != -EOPNOTSUPP) {
  505. xfs_info(mp,
  506. "discard failed for extent [0x%llx,%u], error %d",
  507. (unsigned long long)busyp->bno,
  508. busyp->length,
  509. error);
  510. break;
  511. }
  512. }
  513. if (bio) {
  514. bio->bi_private = ctx;
  515. bio->bi_end_io = xlog_discard_endio;
  516. submit_bio(bio);
  517. } else {
  518. xlog_discard_endio_work(&ctx->discard_endio_work);
  519. }
  520. blk_finish_plug(&plug);
  521. }
  522. /*
  523. * Mark all items committed and clear busy extents. We free the log vector
  524. * chains in a separate pass so that we unpin the log items as quickly as
  525. * possible.
  526. */
  527. static void
  528. xlog_cil_committed(
  529. void *args,
  530. int abort)
  531. {
  532. struct xfs_cil_ctx *ctx = args;
  533. struct xfs_mount *mp = ctx->cil->xc_log->l_mp;
  534. xfs_trans_committed_bulk(ctx->cil->xc_log->l_ailp, ctx->lv_chain,
  535. ctx->start_lsn, abort);
  536. xfs_extent_busy_sort(&ctx->busy_extents);
  537. xfs_extent_busy_clear(mp, &ctx->busy_extents,
  538. (mp->m_flags & XFS_MOUNT_DISCARD) && !abort);
  539. /*
  540. * If we are aborting the commit, wake up anyone waiting on the
  541. * committing list. If we don't, then a shutdown we can leave processes
  542. * waiting in xlog_cil_force_lsn() waiting on a sequence commit that
  543. * will never happen because we aborted it.
  544. */
  545. spin_lock(&ctx->cil->xc_push_lock);
  546. if (abort)
  547. wake_up_all(&ctx->cil->xc_commit_wait);
  548. list_del(&ctx->committing);
  549. spin_unlock(&ctx->cil->xc_push_lock);
  550. xlog_cil_free_logvec(ctx->lv_chain);
  551. if (!list_empty(&ctx->busy_extents))
  552. xlog_discard_busy_extents(mp, ctx);
  553. else
  554. kmem_free(ctx);
  555. }
  556. /*
  557. * Push the Committed Item List to the log. If @push_seq flag is zero, then it
  558. * is a background flush and so we can chose to ignore it. Otherwise, if the
  559. * current sequence is the same as @push_seq we need to do a flush. If
  560. * @push_seq is less than the current sequence, then it has already been
  561. * flushed and we don't need to do anything - the caller will wait for it to
  562. * complete if necessary.
  563. *
  564. * @push_seq is a value rather than a flag because that allows us to do an
  565. * unlocked check of the sequence number for a match. Hence we can allows log
  566. * forces to run racily and not issue pushes for the same sequence twice. If we
  567. * get a race between multiple pushes for the same sequence they will block on
  568. * the first one and then abort, hence avoiding needless pushes.
  569. */
  570. STATIC int
  571. xlog_cil_push(
  572. struct xlog *log)
  573. {
  574. struct xfs_cil *cil = log->l_cilp;
  575. struct xfs_log_vec *lv;
  576. struct xfs_cil_ctx *ctx;
  577. struct xfs_cil_ctx *new_ctx;
  578. struct xlog_in_core *commit_iclog;
  579. struct xlog_ticket *tic;
  580. int num_iovecs;
  581. int error = 0;
  582. struct xfs_trans_header thdr;
  583. struct xfs_log_iovec lhdr;
  584. struct xfs_log_vec lvhdr = { NULL };
  585. xfs_lsn_t commit_lsn;
  586. xfs_lsn_t push_seq;
  587. if (!cil)
  588. return 0;
  589. new_ctx = kmem_zalloc(sizeof(*new_ctx), KM_SLEEP|KM_NOFS);
  590. new_ctx->ticket = xlog_cil_ticket_alloc(log);
  591. down_write(&cil->xc_ctx_lock);
  592. ctx = cil->xc_ctx;
  593. spin_lock(&cil->xc_push_lock);
  594. push_seq = cil->xc_push_seq;
  595. ASSERT(push_seq <= ctx->sequence);
  596. /*
  597. * Check if we've anything to push. If there is nothing, then we don't
  598. * move on to a new sequence number and so we have to be able to push
  599. * this sequence again later.
  600. */
  601. if (list_empty(&cil->xc_cil)) {
  602. cil->xc_push_seq = 0;
  603. spin_unlock(&cil->xc_push_lock);
  604. goto out_skip;
  605. }
  606. /* check for a previously pushed seqeunce */
  607. if (push_seq < cil->xc_ctx->sequence) {
  608. spin_unlock(&cil->xc_push_lock);
  609. goto out_skip;
  610. }
  611. /*
  612. * We are now going to push this context, so add it to the committing
  613. * list before we do anything else. This ensures that anyone waiting on
  614. * this push can easily detect the difference between a "push in
  615. * progress" and "CIL is empty, nothing to do".
  616. *
  617. * IOWs, a wait loop can now check for:
  618. * the current sequence not being found on the committing list;
  619. * an empty CIL; and
  620. * an unchanged sequence number
  621. * to detect a push that had nothing to do and therefore does not need
  622. * waiting on. If the CIL is not empty, we get put on the committing
  623. * list before emptying the CIL and bumping the sequence number. Hence
  624. * an empty CIL and an unchanged sequence number means we jumped out
  625. * above after doing nothing.
  626. *
  627. * Hence the waiter will either find the commit sequence on the
  628. * committing list or the sequence number will be unchanged and the CIL
  629. * still dirty. In that latter case, the push has not yet started, and
  630. * so the waiter will have to continue trying to check the CIL
  631. * committing list until it is found. In extreme cases of delay, the
  632. * sequence may fully commit between the attempts the wait makes to wait
  633. * on the commit sequence.
  634. */
  635. list_add(&ctx->committing, &cil->xc_committing);
  636. spin_unlock(&cil->xc_push_lock);
  637. /*
  638. * pull all the log vectors off the items in the CIL, and
  639. * remove the items from the CIL. We don't need the CIL lock
  640. * here because it's only needed on the transaction commit
  641. * side which is currently locked out by the flush lock.
  642. */
  643. lv = NULL;
  644. num_iovecs = 0;
  645. while (!list_empty(&cil->xc_cil)) {
  646. struct xfs_log_item *item;
  647. item = list_first_entry(&cil->xc_cil,
  648. struct xfs_log_item, li_cil);
  649. list_del_init(&item->li_cil);
  650. if (!ctx->lv_chain)
  651. ctx->lv_chain = item->li_lv;
  652. else
  653. lv->lv_next = item->li_lv;
  654. lv = item->li_lv;
  655. item->li_lv = NULL;
  656. num_iovecs += lv->lv_niovecs;
  657. }
  658. /*
  659. * initialise the new context and attach it to the CIL. Then attach
  660. * the current context to the CIL committing lsit so it can be found
  661. * during log forces to extract the commit lsn of the sequence that
  662. * needs to be forced.
  663. */
  664. INIT_LIST_HEAD(&new_ctx->committing);
  665. INIT_LIST_HEAD(&new_ctx->busy_extents);
  666. new_ctx->sequence = ctx->sequence + 1;
  667. new_ctx->cil = cil;
  668. cil->xc_ctx = new_ctx;
  669. /*
  670. * The switch is now done, so we can drop the context lock and move out
  671. * of a shared context. We can't just go straight to the commit record,
  672. * though - we need to synchronise with previous and future commits so
  673. * that the commit records are correctly ordered in the log to ensure
  674. * that we process items during log IO completion in the correct order.
  675. *
  676. * For example, if we get an EFI in one checkpoint and the EFD in the
  677. * next (e.g. due to log forces), we do not want the checkpoint with
  678. * the EFD to be committed before the checkpoint with the EFI. Hence
  679. * we must strictly order the commit records of the checkpoints so
  680. * that: a) the checkpoint callbacks are attached to the iclogs in the
  681. * correct order; and b) the checkpoints are replayed in correct order
  682. * in log recovery.
  683. *
  684. * Hence we need to add this context to the committing context list so
  685. * that higher sequences will wait for us to write out a commit record
  686. * before they do.
  687. *
  688. * xfs_log_force_lsn requires us to mirror the new sequence into the cil
  689. * structure atomically with the addition of this sequence to the
  690. * committing list. This also ensures that we can do unlocked checks
  691. * against the current sequence in log forces without risking
  692. * deferencing a freed context pointer.
  693. */
  694. spin_lock(&cil->xc_push_lock);
  695. cil->xc_current_sequence = new_ctx->sequence;
  696. spin_unlock(&cil->xc_push_lock);
  697. up_write(&cil->xc_ctx_lock);
  698. /*
  699. * Build a checkpoint transaction header and write it to the log to
  700. * begin the transaction. We need to account for the space used by the
  701. * transaction header here as it is not accounted for in xlog_write().
  702. *
  703. * The LSN we need to pass to the log items on transaction commit is
  704. * the LSN reported by the first log vector write. If we use the commit
  705. * record lsn then we can move the tail beyond the grant write head.
  706. */
  707. tic = ctx->ticket;
  708. thdr.th_magic = XFS_TRANS_HEADER_MAGIC;
  709. thdr.th_type = XFS_TRANS_CHECKPOINT;
  710. thdr.th_tid = tic->t_tid;
  711. thdr.th_num_items = num_iovecs;
  712. lhdr.i_addr = &thdr;
  713. lhdr.i_len = sizeof(xfs_trans_header_t);
  714. lhdr.i_type = XLOG_REG_TYPE_TRANSHDR;
  715. tic->t_curr_res -= lhdr.i_len + sizeof(xlog_op_header_t);
  716. lvhdr.lv_niovecs = 1;
  717. lvhdr.lv_iovecp = &lhdr;
  718. lvhdr.lv_next = ctx->lv_chain;
  719. error = xlog_write(log, &lvhdr, tic, &ctx->start_lsn, NULL, 0);
  720. if (error)
  721. goto out_abort_free_ticket;
  722. /*
  723. * now that we've written the checkpoint into the log, strictly
  724. * order the commit records so replay will get them in the right order.
  725. */
  726. restart:
  727. spin_lock(&cil->xc_push_lock);
  728. list_for_each_entry(new_ctx, &cil->xc_committing, committing) {
  729. /*
  730. * Avoid getting stuck in this loop because we were woken by the
  731. * shutdown, but then went back to sleep once already in the
  732. * shutdown state.
  733. */
  734. if (XLOG_FORCED_SHUTDOWN(log)) {
  735. spin_unlock(&cil->xc_push_lock);
  736. goto out_abort_free_ticket;
  737. }
  738. /*
  739. * Higher sequences will wait for this one so skip them.
  740. * Don't wait for our own sequence, either.
  741. */
  742. if (new_ctx->sequence >= ctx->sequence)
  743. continue;
  744. if (!new_ctx->commit_lsn) {
  745. /*
  746. * It is still being pushed! Wait for the push to
  747. * complete, then start again from the beginning.
  748. */
  749. xlog_wait(&cil->xc_commit_wait, &cil->xc_push_lock);
  750. goto restart;
  751. }
  752. }
  753. spin_unlock(&cil->xc_push_lock);
  754. /* xfs_log_done always frees the ticket on error. */
  755. commit_lsn = xfs_log_done(log->l_mp, tic, &commit_iclog, false);
  756. if (commit_lsn == -1)
  757. goto out_abort;
  758. /* attach all the transactions w/ busy extents to iclog */
  759. ctx->log_cb.cb_func = xlog_cil_committed;
  760. ctx->log_cb.cb_arg = ctx;
  761. error = xfs_log_notify(log->l_mp, commit_iclog, &ctx->log_cb);
  762. if (error)
  763. goto out_abort;
  764. /*
  765. * now the checkpoint commit is complete and we've attached the
  766. * callbacks to the iclog we can assign the commit LSN to the context
  767. * and wake up anyone who is waiting for the commit to complete.
  768. */
  769. spin_lock(&cil->xc_push_lock);
  770. ctx->commit_lsn = commit_lsn;
  771. wake_up_all(&cil->xc_commit_wait);
  772. spin_unlock(&cil->xc_push_lock);
  773. /* release the hounds! */
  774. return xfs_log_release_iclog(log->l_mp, commit_iclog);
  775. out_skip:
  776. up_write(&cil->xc_ctx_lock);
  777. xfs_log_ticket_put(new_ctx->ticket);
  778. kmem_free(new_ctx);
  779. return 0;
  780. out_abort_free_ticket:
  781. xfs_log_ticket_put(tic);
  782. out_abort:
  783. xlog_cil_committed(ctx, XFS_LI_ABORTED);
  784. return -EIO;
  785. }
  786. static void
  787. xlog_cil_push_work(
  788. struct work_struct *work)
  789. {
  790. struct xfs_cil *cil = container_of(work, struct xfs_cil,
  791. xc_push_work);
  792. xlog_cil_push(cil->xc_log);
  793. }
  794. /*
  795. * We need to push CIL every so often so we don't cache more than we can fit in
  796. * the log. The limit really is that a checkpoint can't be more than half the
  797. * log (the current checkpoint is not allowed to overwrite the previous
  798. * checkpoint), but commit latency and memory usage limit this to a smaller
  799. * size.
  800. */
  801. static void
  802. xlog_cil_push_background(
  803. struct xlog *log)
  804. {
  805. struct xfs_cil *cil = log->l_cilp;
  806. /*
  807. * The cil won't be empty because we are called while holding the
  808. * context lock so whatever we added to the CIL will still be there
  809. */
  810. ASSERT(!list_empty(&cil->xc_cil));
  811. /*
  812. * don't do a background push if we haven't used up all the
  813. * space available yet.
  814. */
  815. if (cil->xc_ctx->space_used < XLOG_CIL_SPACE_LIMIT(log))
  816. return;
  817. spin_lock(&cil->xc_push_lock);
  818. if (cil->xc_push_seq < cil->xc_current_sequence) {
  819. cil->xc_push_seq = cil->xc_current_sequence;
  820. queue_work(log->l_mp->m_cil_workqueue, &cil->xc_push_work);
  821. }
  822. spin_unlock(&cil->xc_push_lock);
  823. }
  824. /*
  825. * xlog_cil_push_now() is used to trigger an immediate CIL push to the sequence
  826. * number that is passed. When it returns, the work will be queued for
  827. * @push_seq, but it won't be completed. The caller is expected to do any
  828. * waiting for push_seq to complete if it is required.
  829. */
  830. static void
  831. xlog_cil_push_now(
  832. struct xlog *log,
  833. xfs_lsn_t push_seq)
  834. {
  835. struct xfs_cil *cil = log->l_cilp;
  836. if (!cil)
  837. return;
  838. ASSERT(push_seq && push_seq <= cil->xc_current_sequence);
  839. /* start on any pending background push to minimise wait time on it */
  840. flush_work(&cil->xc_push_work);
  841. /*
  842. * If the CIL is empty or we've already pushed the sequence then
  843. * there's no work we need to do.
  844. */
  845. spin_lock(&cil->xc_push_lock);
  846. if (list_empty(&cil->xc_cil) || push_seq <= cil->xc_push_seq) {
  847. spin_unlock(&cil->xc_push_lock);
  848. return;
  849. }
  850. cil->xc_push_seq = push_seq;
  851. queue_work(log->l_mp->m_cil_workqueue, &cil->xc_push_work);
  852. spin_unlock(&cil->xc_push_lock);
  853. }
  854. bool
  855. xlog_cil_empty(
  856. struct xlog *log)
  857. {
  858. struct xfs_cil *cil = log->l_cilp;
  859. bool empty = false;
  860. spin_lock(&cil->xc_push_lock);
  861. if (list_empty(&cil->xc_cil))
  862. empty = true;
  863. spin_unlock(&cil->xc_push_lock);
  864. return empty;
  865. }
  866. /*
  867. * Commit a transaction with the given vector to the Committed Item List.
  868. *
  869. * To do this, we need to format the item, pin it in memory if required and
  870. * account for the space used by the transaction. Once we have done that we
  871. * need to release the unused reservation for the transaction, attach the
  872. * transaction to the checkpoint context so we carry the busy extents through
  873. * to checkpoint completion, and then unlock all the items in the transaction.
  874. *
  875. * Called with the context lock already held in read mode to lock out
  876. * background commit, returns without it held once background commits are
  877. * allowed again.
  878. */
  879. void
  880. xfs_log_commit_cil(
  881. struct xfs_mount *mp,
  882. struct xfs_trans *tp,
  883. xfs_lsn_t *commit_lsn,
  884. bool regrant)
  885. {
  886. struct xlog *log = mp->m_log;
  887. struct xfs_cil *cil = log->l_cilp;
  888. xfs_lsn_t xc_commit_lsn;
  889. /*
  890. * Do all necessary memory allocation before we lock the CIL.
  891. * This ensures the allocation does not deadlock with a CIL
  892. * push in memory reclaim (e.g. from kswapd).
  893. */
  894. xlog_cil_alloc_shadow_bufs(log, tp);
  895. /* lock out background commit */
  896. down_read(&cil->xc_ctx_lock);
  897. xlog_cil_insert_items(log, tp);
  898. xc_commit_lsn = cil->xc_ctx->sequence;
  899. if (commit_lsn)
  900. *commit_lsn = xc_commit_lsn;
  901. xfs_log_done(mp, tp->t_ticket, NULL, regrant);
  902. xfs_trans_unreserve_and_mod_sb(tp);
  903. /*
  904. * Once all the items of the transaction have been copied to the CIL,
  905. * the items can be unlocked and freed.
  906. *
  907. * This needs to be done before we drop the CIL context lock because we
  908. * have to update state in the log items and unlock them before they go
  909. * to disk. If we don't, then the CIL checkpoint can race with us and
  910. * we can run checkpoint completion before we've updated and unlocked
  911. * the log items. This affects (at least) processing of stale buffers,
  912. * inodes and EFIs.
  913. */
  914. xfs_trans_free_items(tp, xc_commit_lsn, false);
  915. xlog_cil_push_background(log);
  916. up_read(&cil->xc_ctx_lock);
  917. }
  918. /*
  919. * Conditionally push the CIL based on the sequence passed in.
  920. *
  921. * We only need to push if we haven't already pushed the sequence
  922. * number given. Hence the only time we will trigger a push here is
  923. * if the push sequence is the same as the current context.
  924. *
  925. * We return the current commit lsn to allow the callers to determine if a
  926. * iclog flush is necessary following this call.
  927. */
  928. xfs_lsn_t
  929. xlog_cil_force_lsn(
  930. struct xlog *log,
  931. xfs_lsn_t sequence)
  932. {
  933. struct xfs_cil *cil = log->l_cilp;
  934. struct xfs_cil_ctx *ctx;
  935. xfs_lsn_t commit_lsn = NULLCOMMITLSN;
  936. ASSERT(sequence <= cil->xc_current_sequence);
  937. /*
  938. * check to see if we need to force out the current context.
  939. * xlog_cil_push() handles racing pushes for the same sequence,
  940. * so no need to deal with it here.
  941. */
  942. restart:
  943. xlog_cil_push_now(log, sequence);
  944. /*
  945. * See if we can find a previous sequence still committing.
  946. * We need to wait for all previous sequence commits to complete
  947. * before allowing the force of push_seq to go ahead. Hence block
  948. * on commits for those as well.
  949. */
  950. spin_lock(&cil->xc_push_lock);
  951. list_for_each_entry(ctx, &cil->xc_committing, committing) {
  952. /*
  953. * Avoid getting stuck in this loop because we were woken by the
  954. * shutdown, but then went back to sleep once already in the
  955. * shutdown state.
  956. */
  957. if (XLOG_FORCED_SHUTDOWN(log))
  958. goto out_shutdown;
  959. if (ctx->sequence > sequence)
  960. continue;
  961. if (!ctx->commit_lsn) {
  962. /*
  963. * It is still being pushed! Wait for the push to
  964. * complete, then start again from the beginning.
  965. */
  966. xlog_wait(&cil->xc_commit_wait, &cil->xc_push_lock);
  967. goto restart;
  968. }
  969. if (ctx->sequence != sequence)
  970. continue;
  971. /* found it! */
  972. commit_lsn = ctx->commit_lsn;
  973. }
  974. /*
  975. * The call to xlog_cil_push_now() executes the push in the background.
  976. * Hence by the time we have got here it our sequence may not have been
  977. * pushed yet. This is true if the current sequence still matches the
  978. * push sequence after the above wait loop and the CIL still contains
  979. * dirty objects. This is guaranteed by the push code first adding the
  980. * context to the committing list before emptying the CIL.
  981. *
  982. * Hence if we don't find the context in the committing list and the
  983. * current sequence number is unchanged then the CIL contents are
  984. * significant. If the CIL is empty, if means there was nothing to push
  985. * and that means there is nothing to wait for. If the CIL is not empty,
  986. * it means we haven't yet started the push, because if it had started
  987. * we would have found the context on the committing list.
  988. */
  989. if (sequence == cil->xc_current_sequence &&
  990. !list_empty(&cil->xc_cil)) {
  991. spin_unlock(&cil->xc_push_lock);
  992. goto restart;
  993. }
  994. spin_unlock(&cil->xc_push_lock);
  995. return commit_lsn;
  996. /*
  997. * We detected a shutdown in progress. We need to trigger the log force
  998. * to pass through it's iclog state machine error handling, even though
  999. * we are already in a shutdown state. Hence we can't return
  1000. * NULLCOMMITLSN here as that has special meaning to log forces (i.e.
  1001. * LSN is already stable), so we return a zero LSN instead.
  1002. */
  1003. out_shutdown:
  1004. spin_unlock(&cil->xc_push_lock);
  1005. return 0;
  1006. }
  1007. /*
  1008. * Check if the current log item was first committed in this sequence.
  1009. * We can't rely on just the log item being in the CIL, we have to check
  1010. * the recorded commit sequence number.
  1011. *
  1012. * Note: for this to be used in a non-racy manner, it has to be called with
  1013. * CIL flushing locked out. As a result, it should only be used during the
  1014. * transaction commit process when deciding what to format into the item.
  1015. */
  1016. bool
  1017. xfs_log_item_in_current_chkpt(
  1018. struct xfs_log_item *lip)
  1019. {
  1020. struct xfs_cil_ctx *ctx;
  1021. if (list_empty(&lip->li_cil))
  1022. return false;
  1023. ctx = lip->li_mountp->m_log->l_cilp->xc_ctx;
  1024. /*
  1025. * li_seq is written on the first commit of a log item to record the
  1026. * first checkpoint it is written to. Hence if it is different to the
  1027. * current sequence, we're in a new checkpoint.
  1028. */
  1029. if (XFS_LSN_CMP(lip->li_seq, ctx->sequence) != 0)
  1030. return false;
  1031. return true;
  1032. }
  1033. /*
  1034. * Perform initial CIL structure initialisation.
  1035. */
  1036. int
  1037. xlog_cil_init(
  1038. struct xlog *log)
  1039. {
  1040. struct xfs_cil *cil;
  1041. struct xfs_cil_ctx *ctx;
  1042. cil = kmem_zalloc(sizeof(*cil), KM_SLEEP|KM_MAYFAIL);
  1043. if (!cil)
  1044. return -ENOMEM;
  1045. ctx = kmem_zalloc(sizeof(*ctx), KM_SLEEP|KM_MAYFAIL);
  1046. if (!ctx) {
  1047. kmem_free(cil);
  1048. return -ENOMEM;
  1049. }
  1050. INIT_WORK(&cil->xc_push_work, xlog_cil_push_work);
  1051. INIT_LIST_HEAD(&cil->xc_cil);
  1052. INIT_LIST_HEAD(&cil->xc_committing);
  1053. spin_lock_init(&cil->xc_cil_lock);
  1054. spin_lock_init(&cil->xc_push_lock);
  1055. init_rwsem(&cil->xc_ctx_lock);
  1056. init_waitqueue_head(&cil->xc_commit_wait);
  1057. INIT_LIST_HEAD(&ctx->committing);
  1058. INIT_LIST_HEAD(&ctx->busy_extents);
  1059. ctx->sequence = 1;
  1060. ctx->cil = cil;
  1061. cil->xc_ctx = ctx;
  1062. cil->xc_current_sequence = ctx->sequence;
  1063. cil->xc_log = log;
  1064. log->l_cilp = cil;
  1065. return 0;
  1066. }
  1067. void
  1068. xlog_cil_destroy(
  1069. struct xlog *log)
  1070. {
  1071. if (log->l_cilp->xc_ctx) {
  1072. if (log->l_cilp->xc_ctx->ticket)
  1073. xfs_log_ticket_put(log->l_cilp->xc_ctx->ticket);
  1074. kmem_free(log->l_cilp->xc_ctx);
  1075. }
  1076. ASSERT(list_empty(&log->l_cilp->xc_cil));
  1077. kmem_free(log->l_cilp);
  1078. }