xfs_extfree_item.c 17 KB

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