xfs_extfree_item.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_buf_item.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_dmapi.h"
  27. #include "xfs_mount.h"
  28. #include "xfs_trans_priv.h"
  29. #include "xfs_extfree_item.h"
  30. kmem_zone_t *xfs_efi_zone;
  31. kmem_zone_t *xfs_efd_zone;
  32. STATIC void xfs_efi_item_unlock(xfs_efi_log_item_t *);
  33. STATIC void xfs_efi_item_abort(xfs_efi_log_item_t *);
  34. STATIC void xfs_efd_item_abort(xfs_efd_log_item_t *);
  35. void
  36. xfs_efi_item_free(xfs_efi_log_item_t *efip)
  37. {
  38. int nexts = efip->efi_format.efi_nextents;
  39. if (nexts > XFS_EFI_MAX_FAST_EXTENTS) {
  40. kmem_free(efip, sizeof(xfs_efi_log_item_t) +
  41. (nexts - 1) * sizeof(xfs_extent_t));
  42. } else {
  43. kmem_zone_free(xfs_efi_zone, efip);
  44. }
  45. }
  46. /*
  47. * This returns the number of iovecs needed to log the given efi item.
  48. * We only need 1 iovec for an efi item. It just logs the efi_log_format
  49. * structure.
  50. */
  51. /*ARGSUSED*/
  52. STATIC uint
  53. xfs_efi_item_size(xfs_efi_log_item_t *efip)
  54. {
  55. return 1;
  56. }
  57. /*
  58. * This is called to fill in the vector of log iovecs for the
  59. * given efi log item. We use only 1 iovec, and we point that
  60. * at the efi_log_format structure embedded in the efi item.
  61. * It is at this point that we assert that all of the extent
  62. * slots in the efi item have been filled.
  63. */
  64. STATIC void
  65. xfs_efi_item_format(xfs_efi_log_item_t *efip,
  66. xfs_log_iovec_t *log_vector)
  67. {
  68. uint size;
  69. ASSERT(efip->efi_next_extent == efip->efi_format.efi_nextents);
  70. efip->efi_format.efi_type = XFS_LI_EFI;
  71. size = sizeof(xfs_efi_log_format_t);
  72. size += (efip->efi_format.efi_nextents - 1) * sizeof(xfs_extent_t);
  73. efip->efi_format.efi_size = 1;
  74. log_vector->i_addr = (xfs_caddr_t)&(efip->efi_format);
  75. log_vector->i_len = size;
  76. XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_EFI_FORMAT);
  77. ASSERT(size >= sizeof(xfs_efi_log_format_t));
  78. }
  79. /*
  80. * Pinning has no meaning for an efi item, so just return.
  81. */
  82. /*ARGSUSED*/
  83. STATIC void
  84. xfs_efi_item_pin(xfs_efi_log_item_t *efip)
  85. {
  86. return;
  87. }
  88. /*
  89. * While EFIs cannot really be pinned, the unpin operation is the
  90. * last place at which the EFI is manipulated during a transaction.
  91. * Here we coordinate with xfs_efi_cancel() to determine who gets to
  92. * free the EFI.
  93. */
  94. /*ARGSUSED*/
  95. STATIC void
  96. xfs_efi_item_unpin(xfs_efi_log_item_t *efip, int stale)
  97. {
  98. xfs_mount_t *mp;
  99. SPLDECL(s);
  100. mp = efip->efi_item.li_mountp;
  101. AIL_LOCK(mp, s);
  102. if (efip->efi_flags & XFS_EFI_CANCELED) {
  103. /*
  104. * xfs_trans_delete_ail() drops the AIL lock.
  105. */
  106. xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
  107. xfs_efi_item_free(efip);
  108. } else {
  109. efip->efi_flags |= XFS_EFI_COMMITTED;
  110. AIL_UNLOCK(mp, s);
  111. }
  112. }
  113. /*
  114. * like unpin only we have to also clear the xaction descriptor
  115. * pointing the log item if we free the item. This routine duplicates
  116. * unpin because efi_flags is protected by the AIL lock. Freeing
  117. * the descriptor and then calling unpin would force us to drop the AIL
  118. * lock which would open up a race condition.
  119. */
  120. STATIC void
  121. xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp)
  122. {
  123. xfs_mount_t *mp;
  124. xfs_log_item_desc_t *lidp;
  125. SPLDECL(s);
  126. mp = efip->efi_item.li_mountp;
  127. AIL_LOCK(mp, s);
  128. if (efip->efi_flags & XFS_EFI_CANCELED) {
  129. /*
  130. * free the xaction descriptor pointing to this item
  131. */
  132. lidp = xfs_trans_find_item(tp, (xfs_log_item_t *) efip);
  133. xfs_trans_free_item(tp, lidp);
  134. /*
  135. * pull the item off the AIL.
  136. * xfs_trans_delete_ail() drops the AIL lock.
  137. */
  138. xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
  139. xfs_efi_item_free(efip);
  140. } else {
  141. efip->efi_flags |= XFS_EFI_COMMITTED;
  142. AIL_UNLOCK(mp, s);
  143. }
  144. }
  145. /*
  146. * Efi items have no locking or pushing. However, since EFIs are
  147. * pulled from the AIL when their corresponding EFDs are committed
  148. * to disk, their situation is very similar to being pinned. Return
  149. * XFS_ITEM_PINNED so that the caller will eventually flush the log.
  150. * This should help in getting the EFI out of the AIL.
  151. */
  152. /*ARGSUSED*/
  153. STATIC uint
  154. xfs_efi_item_trylock(xfs_efi_log_item_t *efip)
  155. {
  156. return XFS_ITEM_PINNED;
  157. }
  158. /*
  159. * Efi items have no locking, so just return.
  160. */
  161. /*ARGSUSED*/
  162. STATIC void
  163. xfs_efi_item_unlock(xfs_efi_log_item_t *efip)
  164. {
  165. if (efip->efi_item.li_flags & XFS_LI_ABORTED)
  166. xfs_efi_item_abort(efip);
  167. return;
  168. }
  169. /*
  170. * The EFI is logged only once and cannot be moved in the log, so
  171. * simply return the lsn at which it's been logged. The canceled
  172. * flag is not paid any attention here. Checking for that is delayed
  173. * until the EFI is unpinned.
  174. */
  175. /*ARGSUSED*/
  176. STATIC xfs_lsn_t
  177. xfs_efi_item_committed(xfs_efi_log_item_t *efip, xfs_lsn_t lsn)
  178. {
  179. return lsn;
  180. }
  181. /*
  182. * This is called when the transaction logging the EFI is aborted.
  183. * Free up the EFI and return. No need to clean up the slot for
  184. * the item in the transaction. That was done by the unpin code
  185. * which is called prior to this routine in the abort/fs-shutdown path.
  186. */
  187. STATIC void
  188. xfs_efi_item_abort(xfs_efi_log_item_t *efip)
  189. {
  190. xfs_efi_item_free(efip);
  191. }
  192. /*
  193. * There isn't much you can do to push on an efi item. It is simply
  194. * stuck waiting for all of its corresponding efd items to be
  195. * committed to disk.
  196. */
  197. /*ARGSUSED*/
  198. STATIC void
  199. xfs_efi_item_push(xfs_efi_log_item_t *efip)
  200. {
  201. return;
  202. }
  203. /*
  204. * The EFI dependency tracking op doesn't do squat. It can't because
  205. * it doesn't know where the free extent is coming from. The dependency
  206. * tracking has to be handled by the "enclosing" metadata object. For
  207. * example, for inodes, the inode is locked throughout the extent freeing
  208. * so the dependency should be recorded there.
  209. */
  210. /*ARGSUSED*/
  211. STATIC void
  212. xfs_efi_item_committing(xfs_efi_log_item_t *efip, xfs_lsn_t lsn)
  213. {
  214. return;
  215. }
  216. /*
  217. * This is the ops vector shared by all efi log items.
  218. */
  219. STATIC struct xfs_item_ops xfs_efi_item_ops = {
  220. .iop_size = (uint(*)(xfs_log_item_t*))xfs_efi_item_size,
  221. .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
  222. xfs_efi_item_format,
  223. .iop_pin = (void(*)(xfs_log_item_t*))xfs_efi_item_pin,
  224. .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efi_item_unpin,
  225. .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t *))
  226. xfs_efi_item_unpin_remove,
  227. .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efi_item_trylock,
  228. .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efi_item_unlock,
  229. .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
  230. xfs_efi_item_committed,
  231. .iop_push = (void(*)(xfs_log_item_t*))xfs_efi_item_push,
  232. .iop_abort = (void(*)(xfs_log_item_t*))xfs_efi_item_abort,
  233. .iop_pushbuf = NULL,
  234. .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
  235. xfs_efi_item_committing
  236. };
  237. /*
  238. * Allocate and initialize an efi item with the given number of extents.
  239. */
  240. xfs_efi_log_item_t *
  241. xfs_efi_init(xfs_mount_t *mp,
  242. uint nextents)
  243. {
  244. xfs_efi_log_item_t *efip;
  245. uint size;
  246. ASSERT(nextents > 0);
  247. if (nextents > XFS_EFI_MAX_FAST_EXTENTS) {
  248. size = (uint)(sizeof(xfs_efi_log_item_t) +
  249. ((nextents - 1) * sizeof(xfs_extent_t)));
  250. efip = (xfs_efi_log_item_t*)kmem_zalloc(size, KM_SLEEP);
  251. } else {
  252. efip = (xfs_efi_log_item_t*)kmem_zone_zalloc(xfs_efi_zone,
  253. KM_SLEEP);
  254. }
  255. efip->efi_item.li_type = XFS_LI_EFI;
  256. efip->efi_item.li_ops = &xfs_efi_item_ops;
  257. efip->efi_item.li_mountp = mp;
  258. efip->efi_format.efi_nextents = nextents;
  259. efip->efi_format.efi_id = (__psint_t)(void*)efip;
  260. return (efip);
  261. }
  262. /*
  263. * Copy an EFI format buffer from the given buf, and into the destination
  264. * EFI format structure.
  265. * The given buffer can be in 32 bit or 64 bit form (which has different padding),
  266. * one of which will be the native format for this kernel.
  267. * It will handle the conversion of formats if necessary.
  268. */
  269. int
  270. xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
  271. {
  272. xfs_efi_log_format_t *src_efi_fmt = (xfs_efi_log_format_t *)buf->i_addr;
  273. uint i;
  274. uint len = sizeof(xfs_efi_log_format_t) +
  275. (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_t);
  276. uint len32 = sizeof(xfs_efi_log_format_32_t) +
  277. (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_32_t);
  278. uint len64 = sizeof(xfs_efi_log_format_64_t) +
  279. (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_64_t);
  280. if (buf->i_len == len) {
  281. memcpy((char *)dst_efi_fmt, (char*)src_efi_fmt, len);
  282. return 0;
  283. } else if (buf->i_len == len32) {
  284. xfs_efi_log_format_32_t *src_efi_fmt_32 =
  285. (xfs_efi_log_format_32_t *)buf->i_addr;
  286. dst_efi_fmt->efi_type = src_efi_fmt_32->efi_type;
  287. dst_efi_fmt->efi_size = src_efi_fmt_32->efi_size;
  288. dst_efi_fmt->efi_nextents = src_efi_fmt_32->efi_nextents;
  289. dst_efi_fmt->efi_id = src_efi_fmt_32->efi_id;
  290. for (i = 0; i < dst_efi_fmt->efi_nextents; i++) {
  291. dst_efi_fmt->efi_extents[i].ext_start =
  292. src_efi_fmt_32->efi_extents[i].ext_start;
  293. dst_efi_fmt->efi_extents[i].ext_len =
  294. src_efi_fmt_32->efi_extents[i].ext_len;
  295. }
  296. return 0;
  297. } else if (buf->i_len == len64) {
  298. xfs_efi_log_format_64_t *src_efi_fmt_64 =
  299. (xfs_efi_log_format_64_t *)buf->i_addr;
  300. dst_efi_fmt->efi_type = src_efi_fmt_64->efi_type;
  301. dst_efi_fmt->efi_size = src_efi_fmt_64->efi_size;
  302. dst_efi_fmt->efi_nextents = src_efi_fmt_64->efi_nextents;
  303. dst_efi_fmt->efi_id = src_efi_fmt_64->efi_id;
  304. for (i = 0; i < dst_efi_fmt->efi_nextents; i++) {
  305. dst_efi_fmt->efi_extents[i].ext_start =
  306. src_efi_fmt_64->efi_extents[i].ext_start;
  307. dst_efi_fmt->efi_extents[i].ext_len =
  308. src_efi_fmt_64->efi_extents[i].ext_len;
  309. }
  310. return 0;
  311. }
  312. return EFSCORRUPTED;
  313. }
  314. /*
  315. * This is called by the efd item code below to release references to
  316. * the given efi item. Each efd calls this with the number of
  317. * extents that it has logged, and when the sum of these reaches
  318. * the total number of extents logged by this efi item we can free
  319. * the efi item.
  320. *
  321. * Freeing the efi item requires that we remove it from the AIL.
  322. * We'll use the AIL lock to protect our counters as well as
  323. * the removal from the AIL.
  324. */
  325. void
  326. xfs_efi_release(xfs_efi_log_item_t *efip,
  327. uint nextents)
  328. {
  329. xfs_mount_t *mp;
  330. int extents_left;
  331. SPLDECL(s);
  332. mp = efip->efi_item.li_mountp;
  333. ASSERT(efip->efi_next_extent > 0);
  334. ASSERT(efip->efi_flags & XFS_EFI_COMMITTED);
  335. AIL_LOCK(mp, s);
  336. ASSERT(efip->efi_next_extent >= nextents);
  337. efip->efi_next_extent -= nextents;
  338. extents_left = efip->efi_next_extent;
  339. if (extents_left == 0) {
  340. /*
  341. * xfs_trans_delete_ail() drops the AIL lock.
  342. */
  343. xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
  344. xfs_efi_item_free(efip);
  345. } else {
  346. AIL_UNLOCK(mp, s);
  347. }
  348. }
  349. /*
  350. * This is called when the transaction that should be committing the
  351. * EFD corresponding to the given EFI is aborted. The committed and
  352. * canceled flags are used to coordinate the freeing of the EFI and
  353. * the references by the transaction that committed it.
  354. */
  355. STATIC void
  356. xfs_efi_cancel(
  357. xfs_efi_log_item_t *efip)
  358. {
  359. xfs_mount_t *mp;
  360. SPLDECL(s);
  361. mp = efip->efi_item.li_mountp;
  362. AIL_LOCK(mp, s);
  363. if (efip->efi_flags & XFS_EFI_COMMITTED) {
  364. /*
  365. * xfs_trans_delete_ail() drops the AIL lock.
  366. */
  367. xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
  368. xfs_efi_item_free(efip);
  369. } else {
  370. efip->efi_flags |= XFS_EFI_CANCELED;
  371. AIL_UNLOCK(mp, s);
  372. }
  373. }
  374. STATIC void
  375. xfs_efd_item_free(xfs_efd_log_item_t *efdp)
  376. {
  377. int nexts = efdp->efd_format.efd_nextents;
  378. if (nexts > XFS_EFD_MAX_FAST_EXTENTS) {
  379. kmem_free(efdp, sizeof(xfs_efd_log_item_t) +
  380. (nexts - 1) * sizeof(xfs_extent_t));
  381. } else {
  382. kmem_zone_free(xfs_efd_zone, efdp);
  383. }
  384. }
  385. /*
  386. * This returns the number of iovecs needed to log the given efd item.
  387. * We only need 1 iovec for an efd item. It just logs the efd_log_format
  388. * structure.
  389. */
  390. /*ARGSUSED*/
  391. STATIC uint
  392. xfs_efd_item_size(xfs_efd_log_item_t *efdp)
  393. {
  394. return 1;
  395. }
  396. /*
  397. * This is called to fill in the vector of log iovecs for the
  398. * given efd log item. We use only 1 iovec, and we point that
  399. * at the efd_log_format structure embedded in the efd item.
  400. * It is at this point that we assert that all of the extent
  401. * slots in the efd item have been filled.
  402. */
  403. STATIC void
  404. xfs_efd_item_format(xfs_efd_log_item_t *efdp,
  405. xfs_log_iovec_t *log_vector)
  406. {
  407. uint size;
  408. ASSERT(efdp->efd_next_extent == efdp->efd_format.efd_nextents);
  409. efdp->efd_format.efd_type = XFS_LI_EFD;
  410. size = sizeof(xfs_efd_log_format_t);
  411. size += (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t);
  412. efdp->efd_format.efd_size = 1;
  413. log_vector->i_addr = (xfs_caddr_t)&(efdp->efd_format);
  414. log_vector->i_len = size;
  415. XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_EFD_FORMAT);
  416. ASSERT(size >= sizeof(xfs_efd_log_format_t));
  417. }
  418. /*
  419. * Pinning has no meaning for an efd item, so just return.
  420. */
  421. /*ARGSUSED*/
  422. STATIC void
  423. xfs_efd_item_pin(xfs_efd_log_item_t *efdp)
  424. {
  425. return;
  426. }
  427. /*
  428. * Since pinning has no meaning for an efd item, unpinning does
  429. * not either.
  430. */
  431. /*ARGSUSED*/
  432. STATIC void
  433. xfs_efd_item_unpin(xfs_efd_log_item_t *efdp, int stale)
  434. {
  435. return;
  436. }
  437. /*ARGSUSED*/
  438. STATIC void
  439. xfs_efd_item_unpin_remove(xfs_efd_log_item_t *efdp, xfs_trans_t *tp)
  440. {
  441. return;
  442. }
  443. /*
  444. * Efd items have no locking, so just return success.
  445. */
  446. /*ARGSUSED*/
  447. STATIC uint
  448. xfs_efd_item_trylock(xfs_efd_log_item_t *efdp)
  449. {
  450. return XFS_ITEM_LOCKED;
  451. }
  452. /*
  453. * Efd items have no locking or pushing, so return failure
  454. * so that the caller doesn't bother with us.
  455. */
  456. /*ARGSUSED*/
  457. STATIC void
  458. xfs_efd_item_unlock(xfs_efd_log_item_t *efdp)
  459. {
  460. if (efdp->efd_item.li_flags & XFS_LI_ABORTED)
  461. xfs_efd_item_abort(efdp);
  462. return;
  463. }
  464. /*
  465. * When the efd item is committed to disk, all we need to do
  466. * is delete our reference to our partner efi item and then
  467. * free ourselves. Since we're freeing ourselves we must
  468. * return -1 to keep the transaction code from further referencing
  469. * this item.
  470. */
  471. /*ARGSUSED*/
  472. STATIC xfs_lsn_t
  473. xfs_efd_item_committed(xfs_efd_log_item_t *efdp, xfs_lsn_t lsn)
  474. {
  475. /*
  476. * If we got a log I/O error, it's always the case that the LR with the
  477. * EFI got unpinned and freed before the EFD got aborted.
  478. */
  479. if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0)
  480. xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
  481. xfs_efd_item_free(efdp);
  482. return (xfs_lsn_t)-1;
  483. }
  484. /*
  485. * The transaction of which this EFD is a part has been aborted.
  486. * Inform its companion EFI of this fact and then clean up after
  487. * ourselves. No need to clean up the slot for the item in the
  488. * transaction. That was done by the unpin code which is called
  489. * prior to this routine in the abort/fs-shutdown path.
  490. */
  491. STATIC void
  492. xfs_efd_item_abort(xfs_efd_log_item_t *efdp)
  493. {
  494. /*
  495. * If we got a log I/O error, it's always the case that the LR with the
  496. * EFI got unpinned and freed before the EFD got aborted. So don't
  497. * reference the EFI at all in that case.
  498. */
  499. if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0)
  500. xfs_efi_cancel(efdp->efd_efip);
  501. xfs_efd_item_free(efdp);
  502. }
  503. /*
  504. * There isn't much you can do to push on an efd item. It is simply
  505. * stuck waiting for the log to be flushed to disk.
  506. */
  507. /*ARGSUSED*/
  508. STATIC void
  509. xfs_efd_item_push(xfs_efd_log_item_t *efdp)
  510. {
  511. return;
  512. }
  513. /*
  514. * The EFD dependency tracking op doesn't do squat. It can't because
  515. * it doesn't know where the free extent is coming from. The dependency
  516. * tracking has to be handled by the "enclosing" metadata object. For
  517. * example, for inodes, the inode is locked throughout the extent freeing
  518. * so the dependency should be recorded there.
  519. */
  520. /*ARGSUSED*/
  521. STATIC void
  522. xfs_efd_item_committing(xfs_efd_log_item_t *efip, xfs_lsn_t lsn)
  523. {
  524. return;
  525. }
  526. /*
  527. * This is the ops vector shared by all efd log items.
  528. */
  529. STATIC struct xfs_item_ops xfs_efd_item_ops = {
  530. .iop_size = (uint(*)(xfs_log_item_t*))xfs_efd_item_size,
  531. .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
  532. xfs_efd_item_format,
  533. .iop_pin = (void(*)(xfs_log_item_t*))xfs_efd_item_pin,
  534. .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efd_item_unpin,
  535. .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
  536. xfs_efd_item_unpin_remove,
  537. .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efd_item_trylock,
  538. .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efd_item_unlock,
  539. .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
  540. xfs_efd_item_committed,
  541. .iop_push = (void(*)(xfs_log_item_t*))xfs_efd_item_push,
  542. .iop_abort = (void(*)(xfs_log_item_t*))xfs_efd_item_abort,
  543. .iop_pushbuf = NULL,
  544. .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
  545. xfs_efd_item_committing
  546. };
  547. /*
  548. * Allocate and initialize an efd item with the given number of extents.
  549. */
  550. xfs_efd_log_item_t *
  551. xfs_efd_init(xfs_mount_t *mp,
  552. xfs_efi_log_item_t *efip,
  553. uint nextents)
  554. {
  555. xfs_efd_log_item_t *efdp;
  556. uint size;
  557. ASSERT(nextents > 0);
  558. if (nextents > XFS_EFD_MAX_FAST_EXTENTS) {
  559. size = (uint)(sizeof(xfs_efd_log_item_t) +
  560. ((nextents - 1) * sizeof(xfs_extent_t)));
  561. efdp = (xfs_efd_log_item_t*)kmem_zalloc(size, KM_SLEEP);
  562. } else {
  563. efdp = (xfs_efd_log_item_t*)kmem_zone_zalloc(xfs_efd_zone,
  564. KM_SLEEP);
  565. }
  566. efdp->efd_item.li_type = XFS_LI_EFD;
  567. efdp->efd_item.li_ops = &xfs_efd_item_ops;
  568. efdp->efd_item.li_mountp = mp;
  569. efdp->efd_efip = efip;
  570. efdp->efd_format.efd_nextents = nextents;
  571. efdp->efd_format.efd_efi_id = efip->efi_format.efi_id;
  572. return (efdp);
  573. }