87 lines · c
1// SPDX-License-Identifier: GPL-2.0-or-later2/*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_REPAIR10int xrep_orphanage_create(struct xfs_scrub *sc);11 12/*13 * If we're doing a repair, ensure that the orphanage exists and attach it to14 * the scrub context.15 */16static inline int17xrep_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'll32 * keep going, but we won't be able to attach the file to the33 * orphanage if we can't find the parent.34 */35 return 0;36 }37 38 return error;39}40 41int xrep_orphanage_iolock_two(struct xfs_scrub *sc);42 43void xrep_orphanage_ilock(struct xfs_scrub *sc, unsigned int ilock_flags);44bool xrep_orphanage_ilock_nowait(struct xfs_scrub *sc,45 unsigned int ilock_flags);46void xrep_orphanage_iunlock(struct xfs_scrub *sc, unsigned int ilock_flags);47 48void xrep_orphanage_rele(struct xfs_scrub *sc);49 50/* Information about a request to add a file to the orphanage. */51struct xrep_adoption {52 struct xfs_scrub *sc;53 54 /* Name used for the adoption. */55 struct xfs_name *xname;56 57 /* Parent pointer context tracking */58 struct xfs_parent_args ppargs;59 60 /* Block reservations for orphanage and child (if directory). */61 unsigned int orphanage_blkres;62 unsigned int child_blkres;63 64 /*65 * Does the caller want us to bump the child link count? This is not66 * needed when reattaching files that have become disconnected but have67 * nlink > 1. It is necessary when changing the directory tree68 * structure.69 */70 bool bump_child_nlink:1;71};72 73bool xrep_orphanage_can_adopt(struct xfs_scrub *sc);74 75int xrep_adoption_trans_alloc(struct xfs_scrub *sc,76 struct xrep_adoption *adopt);77int xrep_adoption_compute_name(struct xrep_adoption *adopt,78 struct xfs_name *xname);79int xrep_adoption_move(struct xrep_adoption *adopt);80int xrep_adoption_trans_roll(struct xrep_adoption *adopt);81#else82struct xrep_adoption { /* empty */ };83# define xrep_orphanage_rele(sc) ((void)0)84#endif /* CONFIG_XFS_ONLINE_REPAIR */85 86#endif /* __XFS_SCRUB_ORPHANAGE_H__ */87