xfs_defer.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  5. */
  6. #ifndef __XFS_DEFER_H__
  7. #define __XFS_DEFER_H__
  8. struct xfs_defer_op_type;
  9. /*
  10. * Save a log intent item and a list of extents, so that we can replay
  11. * whatever action had to happen to the extent list and file the log done
  12. * item.
  13. */
  14. struct xfs_defer_pending {
  15. const struct xfs_defer_op_type *dfp_type; /* function pointers */
  16. struct list_head dfp_list; /* pending items */
  17. void *dfp_intent; /* log intent item */
  18. void *dfp_done; /* log done item */
  19. struct list_head dfp_work; /* work items */
  20. unsigned int dfp_count; /* # extent items */
  21. };
  22. /*
  23. * Header for deferred operation list.
  24. *
  25. * dop_low is used by the allocator to activate the lowspace algorithm -
  26. * when free space is running low the extent allocator may choose to
  27. * allocate an extent from an AG without leaving sufficient space for
  28. * a btree split when inserting the new extent. In this case the allocator
  29. * will enable the lowspace algorithm which is supposed to allow further
  30. * allocations (such as btree splits and newroots) to allocate from
  31. * sequential AGs. In order to avoid locking AGs out of order the lowspace
  32. * algorithm will start searching for free space from AG 0. If the correct
  33. * transaction reservations have been made then this algorithm will eventually
  34. * find all the space it needs.
  35. */
  36. enum xfs_defer_ops_type {
  37. XFS_DEFER_OPS_TYPE_BMAP,
  38. XFS_DEFER_OPS_TYPE_REFCOUNT,
  39. XFS_DEFER_OPS_TYPE_RMAP,
  40. XFS_DEFER_OPS_TYPE_FREE,
  41. XFS_DEFER_OPS_TYPE_AGFL_FREE,
  42. XFS_DEFER_OPS_TYPE_MAX,
  43. };
  44. #define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */
  45. #define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */
  46. struct xfs_defer_ops {
  47. bool dop_committed; /* did any trans commit? */
  48. bool dop_low; /* alloc in low mode */
  49. struct list_head dop_intake; /* unlogged pending work */
  50. struct list_head dop_pending; /* logged pending work */
  51. /* relog these with each roll */
  52. struct xfs_inode *dop_inodes[XFS_DEFER_OPS_NR_INODES];
  53. struct xfs_buf *dop_bufs[XFS_DEFER_OPS_NR_BUFS];
  54. };
  55. void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type,
  56. struct list_head *h);
  57. int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop);
  58. void xfs_defer_cancel(struct xfs_defer_ops *dop);
  59. void xfs_defer_init(struct xfs_defer_ops *dop, xfs_fsblock_t *fbp);
  60. bool xfs_defer_has_unfinished_work(struct xfs_defer_ops *dop);
  61. int xfs_defer_ijoin(struct xfs_defer_ops *dop, struct xfs_inode *ip);
  62. int xfs_defer_bjoin(struct xfs_defer_ops *dop, struct xfs_buf *bp);
  63. /* Description of a deferred type. */
  64. struct xfs_defer_op_type {
  65. enum xfs_defer_ops_type type;
  66. unsigned int max_items;
  67. void (*abort_intent)(void *);
  68. void *(*create_done)(struct xfs_trans *, void *, unsigned int);
  69. int (*finish_item)(struct xfs_trans *, struct xfs_defer_ops *,
  70. struct list_head *, void *, void **);
  71. void (*finish_cleanup)(struct xfs_trans *, void *, int);
  72. void (*cancel_item)(struct list_head *);
  73. int (*diff_items)(void *, struct list_head *, struct list_head *);
  74. void *(*create_intent)(struct xfs_trans *, uint);
  75. void (*log_item)(struct xfs_trans *, void *, struct list_head *);
  76. };
  77. void xfs_defer_init_op_type(const struct xfs_defer_op_type *type);
  78. #endif /* __XFS_DEFER_H__ */