xfs_defer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2016 Oracle. All Rights Reserved.
  3. *
  4. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it would be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write the Free Software Foundation,
  18. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef __XFS_DEFER_H__
  21. #define __XFS_DEFER_H__
  22. struct xfs_defer_op_type;
  23. /*
  24. * Save a log intent item and a list of extents, so that we can replay
  25. * whatever action had to happen to the extent list and file the log done
  26. * item.
  27. */
  28. struct xfs_defer_pending {
  29. const struct xfs_defer_op_type *dfp_type; /* function pointers */
  30. struct list_head dfp_list; /* pending items */
  31. void *dfp_intent; /* log intent item */
  32. void *dfp_done; /* log done item */
  33. struct list_head dfp_work; /* work items */
  34. unsigned int dfp_count; /* # extent items */
  35. };
  36. /*
  37. * Header for deferred operation list.
  38. *
  39. * dop_low is used by the allocator to activate the lowspace algorithm -
  40. * when free space is running low the extent allocator may choose to
  41. * allocate an extent from an AG without leaving sufficient space for
  42. * a btree split when inserting the new extent. In this case the allocator
  43. * will enable the lowspace algorithm which is supposed to allow further
  44. * allocations (such as btree splits and newroots) to allocate from
  45. * sequential AGs. In order to avoid locking AGs out of order the lowspace
  46. * algorithm will start searching for free space from AG 0. If the correct
  47. * transaction reservations have been made then this algorithm will eventually
  48. * find all the space it needs.
  49. */
  50. enum xfs_defer_ops_type {
  51. XFS_DEFER_OPS_TYPE_BMAP,
  52. XFS_DEFER_OPS_TYPE_REFCOUNT,
  53. XFS_DEFER_OPS_TYPE_RMAP,
  54. XFS_DEFER_OPS_TYPE_FREE,
  55. XFS_DEFER_OPS_TYPE_MAX,
  56. };
  57. #define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */
  58. struct xfs_defer_ops {
  59. bool dop_committed; /* did any trans commit? */
  60. bool dop_low; /* alloc in low mode */
  61. struct list_head dop_intake; /* unlogged pending work */
  62. struct list_head dop_pending; /* logged pending work */
  63. /* relog these inodes with each roll */
  64. struct xfs_inode *dop_inodes[XFS_DEFER_OPS_NR_INODES];
  65. };
  66. void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type,
  67. struct list_head *h);
  68. int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop,
  69. struct xfs_inode *ip);
  70. void xfs_defer_cancel(struct xfs_defer_ops *dop);
  71. void xfs_defer_init(struct xfs_defer_ops *dop, xfs_fsblock_t *fbp);
  72. bool xfs_defer_has_unfinished_work(struct xfs_defer_ops *dop);
  73. int xfs_defer_join(struct xfs_defer_ops *dop, struct xfs_inode *ip);
  74. /* Description of a deferred type. */
  75. struct xfs_defer_op_type {
  76. enum xfs_defer_ops_type type;
  77. unsigned int max_items;
  78. void (*abort_intent)(void *);
  79. void *(*create_done)(struct xfs_trans *, void *, unsigned int);
  80. int (*finish_item)(struct xfs_trans *, struct xfs_defer_ops *,
  81. struct list_head *, void *, void **);
  82. void (*finish_cleanup)(struct xfs_trans *, void *, int);
  83. void (*cancel_item)(struct list_head *);
  84. int (*diff_items)(void *, struct list_head *, struct list_head *);
  85. void *(*create_intent)(struct xfs_trans *, uint);
  86. void (*log_item)(struct xfs_trans *, void *, struct list_head *);
  87. };
  88. void xfs_defer_init_op_type(const struct xfs_defer_op_type *type);
  89. #endif /* __XFS_DEFER_H__ */