xfs_exchmaps.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2020-2024 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #ifndef __XFS_EXCHMAPS_H__
  7. #define __XFS_EXCHMAPS_H__
  8. /* In-core deferred operation info about a file mapping exchange request. */
  9. struct xfs_exchmaps_intent {
  10. /* List of other incore deferred work. */
  11. struct list_head xmi_list;
  12. /* Inodes participating in the operation. */
  13. struct xfs_inode *xmi_ip1;
  14. struct xfs_inode *xmi_ip2;
  15. /* File offset range information. */
  16. xfs_fileoff_t xmi_startoff1;
  17. xfs_fileoff_t xmi_startoff2;
  18. xfs_filblks_t xmi_blockcount;
  19. /* Set these file sizes after the operation, unless negative. */
  20. xfs_fsize_t xmi_isize1;
  21. xfs_fsize_t xmi_isize2;
  22. uint64_t xmi_flags; /* XFS_EXCHMAPS_* flags */
  23. };
  24. /* Try to convert inode2 from block to short format at the end, if possible. */
  25. #define __XFS_EXCHMAPS_INO2_SHORTFORM (1ULL << 63)
  26. #define XFS_EXCHMAPS_INTERNAL_FLAGS (__XFS_EXCHMAPS_INO2_SHORTFORM)
  27. /* flags that can be passed to xfs_exchmaps_{estimate,mappings} */
  28. #define XFS_EXCHMAPS_PARAMS (XFS_EXCHMAPS_ATTR_FORK | \
  29. XFS_EXCHMAPS_SET_SIZES | \
  30. XFS_EXCHMAPS_INO1_WRITTEN)
  31. static inline int
  32. xfs_exchmaps_whichfork(const struct xfs_exchmaps_intent *xmi)
  33. {
  34. if (xmi->xmi_flags & XFS_EXCHMAPS_ATTR_FORK)
  35. return XFS_ATTR_FORK;
  36. return XFS_DATA_FORK;
  37. }
  38. /* Parameters for a mapping exchange request. */
  39. struct xfs_exchmaps_req {
  40. /* Inodes participating in the operation. */
  41. struct xfs_inode *ip1;
  42. struct xfs_inode *ip2;
  43. /* File offset range information. */
  44. xfs_fileoff_t startoff1;
  45. xfs_fileoff_t startoff2;
  46. xfs_filblks_t blockcount;
  47. /* XFS_EXCHMAPS_* operation flags */
  48. uint64_t flags;
  49. /*
  50. * Fields below this line are filled out by xfs_exchmaps_estimate;
  51. * callers should initialize this part of the struct to zero.
  52. */
  53. /*
  54. * Data device blocks to be moved out of ip1, and free space needed to
  55. * handle the bmbt changes.
  56. */
  57. xfs_filblks_t ip1_bcount;
  58. /*
  59. * Data device blocks to be moved out of ip2, and free space needed to
  60. * handle the bmbt changes.
  61. */
  62. xfs_filblks_t ip2_bcount;
  63. /* rt blocks to be moved out of ip1. */
  64. xfs_filblks_t ip1_rtbcount;
  65. /* rt blocks to be moved out of ip2. */
  66. xfs_filblks_t ip2_rtbcount;
  67. /* Free space needed to handle the bmbt changes */
  68. unsigned long long resblks;
  69. /* Number of exchanges needed to complete the operation */
  70. unsigned long long nr_exchanges;
  71. };
  72. static inline int
  73. xfs_exchmaps_reqfork(const struct xfs_exchmaps_req *req)
  74. {
  75. if (req->flags & XFS_EXCHMAPS_ATTR_FORK)
  76. return XFS_ATTR_FORK;
  77. return XFS_DATA_FORK;
  78. }
  79. int xfs_exchmaps_estimate_overhead(struct xfs_exchmaps_req *req);
  80. int xfs_exchmaps_estimate(struct xfs_exchmaps_req *req);
  81. extern struct kmem_cache *xfs_exchmaps_intent_cache;
  82. int __init xfs_exchmaps_intent_init_cache(void);
  83. void xfs_exchmaps_intent_destroy_cache(void);
  84. struct xfs_exchmaps_intent *xfs_exchmaps_init_intent(
  85. const struct xfs_exchmaps_req *req);
  86. void xfs_exchmaps_ensure_reflink(struct xfs_trans *tp,
  87. const struct xfs_exchmaps_intent *xmi);
  88. void xfs_exchmaps_upgrade_extent_counts(struct xfs_trans *tp,
  89. const struct xfs_exchmaps_intent *xmi);
  90. int xfs_exchmaps_finish_one(struct xfs_trans *tp,
  91. struct xfs_exchmaps_intent *xmi);
  92. int xfs_exchmaps_check_forks(struct xfs_mount *mp,
  93. const struct xfs_exchmaps_req *req);
  94. void xfs_exchange_mappings(struct xfs_trans *tp,
  95. const struct xfs_exchmaps_req *req);
  96. #endif /* __XFS_EXCHMAPS_H__ */