orphanage.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2021-2024 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #ifndef __XFS_SCRUB_ORPHANAGE_H__
  7. #define __XFS_SCRUB_ORPHANAGE_H__
  8. #ifdef CONFIG_XFS_ONLINE_REPAIR
  9. int xrep_orphanage_create(struct xfs_scrub *sc);
  10. /*
  11. * If we're doing a repair, ensure that the orphanage exists and attach it to
  12. * the scrub context.
  13. */
  14. static inline int
  15. xrep_orphanage_try_create(
  16. struct xfs_scrub *sc)
  17. {
  18. int error;
  19. ASSERT(sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR);
  20. error = xrep_orphanage_create(sc);
  21. switch (error) {
  22. case 0:
  23. case -ENOENT:
  24. case -ENOTDIR:
  25. case -ENOSPC:
  26. /*
  27. * If the orphanage can't be found or isn't a directory, we'll
  28. * keep going, but we won't be able to attach the file to the
  29. * orphanage if we can't find the parent.
  30. */
  31. return 0;
  32. }
  33. return error;
  34. }
  35. int xrep_orphanage_iolock_two(struct xfs_scrub *sc);
  36. void xrep_orphanage_ilock(struct xfs_scrub *sc, unsigned int ilock_flags);
  37. bool xrep_orphanage_ilock_nowait(struct xfs_scrub *sc,
  38. unsigned int ilock_flags);
  39. void xrep_orphanage_iunlock(struct xfs_scrub *sc, unsigned int ilock_flags);
  40. void xrep_orphanage_rele(struct xfs_scrub *sc);
  41. /* Information about a request to add a file to the orphanage. */
  42. struct xrep_adoption {
  43. struct xfs_scrub *sc;
  44. /* Name used for the adoption. */
  45. struct xfs_name *xname;
  46. /* Parent pointer context tracking */
  47. struct xfs_parent_args ppargs;
  48. /* Block reservations for orphanage and child (if directory). */
  49. unsigned int orphanage_blkres;
  50. unsigned int child_blkres;
  51. /*
  52. * Does the caller want us to bump the child link count? This is not
  53. * needed when reattaching files that have become disconnected but have
  54. * nlink > 1. It is necessary when changing the directory tree
  55. * structure.
  56. */
  57. bool bump_child_nlink:1;
  58. };
  59. bool xrep_orphanage_can_adopt(struct xfs_scrub *sc);
  60. int xrep_adoption_trans_alloc(struct xfs_scrub *sc,
  61. struct xrep_adoption *adopt);
  62. int xrep_adoption_compute_name(struct xrep_adoption *adopt,
  63. struct xfs_name *xname);
  64. int xrep_adoption_move(struct xrep_adoption *adopt);
  65. int xrep_adoption_trans_roll(struct xrep_adoption *adopt);
  66. #else
  67. struct xrep_adoption { /* empty */ };
  68. # define xrep_orphanage_rele(sc) ((void)0)
  69. #endif /* CONFIG_XFS_ONLINE_REPAIR */
  70. #endif /* __XFS_SCRUB_ORPHANAGE_H__ */