xfs_reflink.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_REFLINK_H
  7. #define __XFS_REFLINK_H 1
  8. /*
  9. * Check whether it is safe to free COW fork blocks from an inode. It is unsafe
  10. * to do so when an inode has dirty cache or I/O in-flight, even if no shared
  11. * extents exist in the data fork, because outstanding I/O may target blocks
  12. * that were speculatively allocated to the COW fork.
  13. */
  14. static inline bool
  15. xfs_can_free_cowblocks(struct xfs_inode *ip)
  16. {
  17. struct inode *inode = VFS_I(ip);
  18. if ((inode_state_read_once(inode) & I_DIRTY_PAGES) ||
  19. mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ||
  20. mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
  21. atomic_read(&inode->i_dio_count))
  22. return false;
  23. return true;
  24. }
  25. int xfs_reflink_trim_around_shared(struct xfs_inode *ip,
  26. struct xfs_bmbt_irec *irec, bool *shared);
  27. int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
  28. bool *shared);
  29. int xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
  30. struct xfs_bmbt_irec *cmap, bool *shared, uint *lockmode,
  31. bool convert_now);
  32. extern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset,
  33. xfs_off_t count);
  34. int xfs_reflink_convert_cow_locked(struct xfs_inode *ip,
  35. xfs_fileoff_t offset_fsb, xfs_filblks_t count_fsb);
  36. extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip,
  37. struct xfs_trans **tpp, xfs_fileoff_t offset_fsb,
  38. xfs_fileoff_t end_fsb, bool cancel_real);
  39. extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
  40. xfs_off_t count, bool cancel_real);
  41. extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
  42. xfs_off_t count);
  43. int xfs_reflink_end_atomic_cow(struct xfs_inode *ip, xfs_off_t offset,
  44. xfs_off_t count);
  45. extern int xfs_reflink_recover_cow(struct xfs_mount *mp);
  46. extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
  47. struct file *file_out, loff_t pos_out, loff_t len,
  48. unsigned int remap_flags);
  49. extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp,
  50. struct xfs_inode *ip, bool *has_shared);
  51. extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
  52. struct xfs_trans **tpp);
  53. extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
  54. xfs_off_t len);
  55. extern int xfs_reflink_remap_prep(struct file *file_in, loff_t pos_in,
  56. struct file *file_out, loff_t pos_out, loff_t *len,
  57. unsigned int remap_flags);
  58. extern int xfs_reflink_remap_blocks(struct xfs_inode *src, loff_t pos_in,
  59. struct xfs_inode *dest, loff_t pos_out, loff_t remap_len,
  60. loff_t *remapped);
  61. extern int xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen,
  62. xfs_extlen_t cowextsize, unsigned int remap_flags);
  63. bool xfs_reflink_supports_rextsize(struct xfs_mount *mp, unsigned int rextsize);
  64. xfs_extlen_t xfs_reflink_max_atomic_cow(struct xfs_mount *mp);
  65. #endif /* __XFS_REFLINK_H */