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 9 #ifdef CONFIG_XFS_ONLINE_REPAIR 10 int xrep_orphanage_create(struct xfs_scrub *sc); 11 12 /* 13 * If we're doing a repair, ensure that the orphanage exists and attach it to 14 * the scrub context. 15 */ 16 static inline int 17 xrep_orphanage_try_create( 18 struct xfs_scrub *sc) 19 { 20 int error; 21 22 ASSERT(sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR); 23 24 error = xrep_orphanage_create(sc); 25 switch (error) { 26 case 0: 27 case -ENOENT: 28 case -ENOTDIR: 29 case -ENOSPC: 30 /* 31 * If the orphanage can't be found or isn't a directory, we'll 32 * keep going, but we won't be able to attach the file to the 33 * orphanage if we can't find the parent. 34 */ 35 return 0; 36 } 37 38 return error; 39 } 40 41 int xrep_orphanage_iolock_two(struct xfs_scrub *sc); 42 43 void xrep_orphanage_ilock(struct xfs_scrub *sc, unsigned int ilock_flags); 44 bool xrep_orphanage_ilock_nowait(struct xfs_scrub *sc, 45 unsigned int ilock_flags); 46 void xrep_orphanage_iunlock(struct xfs_scrub *sc, unsigned int ilock_flags); 47 48 void xrep_orphanage_rele(struct xfs_scrub *sc); 49 50 /* Information about a request to add a file to the orphanage. */ 51 struct xrep_adoption { 52 struct xfs_scrub *sc; 53 54 /* Name used for the adoption. */ 55 struct xfs_name *xname; 56 57 /* Block reservations for orphanage and child (if directory). */ 58 unsigned int orphanage_blkres; 59 unsigned int child_blkres; 60 }; 61 62 bool xrep_orphanage_can_adopt(struct xfs_scrub *sc); 63 64 int xrep_adoption_trans_alloc(struct xfs_scrub *sc, 65 struct xrep_adoption *adopt); 66 int xrep_adoption_compute_name(struct xrep_adoption *adopt, 67 struct xfs_name *xname); 68 int xrep_adoption_move(struct xrep_adoption *adopt); 69 int xrep_adoption_trans_roll(struct xrep_adoption *adopt); 70 #else 71 struct xrep_adoption { /* empty */ }; 72 # define xrep_orphanage_rele(sc) ((void)0) 73 #endif /* CONFIG_XFS_ONLINE_REPAIR */ 74 75 #endif /* __XFS_SCRUB_ORPHANAGE_H__ */ 76