Skip to content

Commit 7be3d20

Browse files
author
Darrick J. Wong
committed
xfs: adapt the orphanage code to handle parent pointers
Adapt the orphanage's adoption code to update the child file's parent pointers as part of the reparenting process. Also ensure that the child has an attr fork to receive the parent pointer update, since the runtime code assumes one exists. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent a26dc21 commit 7be3d20

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

fs/xfs/scrub/orphanage.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "xfs_icache.h"
2020
#include "xfs_bmap.h"
2121
#include "xfs_bmap_btree.h"
22+
#include "xfs_parent.h"
23+
#include "xfs_attr_sf.h"
2224
#include "scrub/scrub.h"
2325
#include "scrub/common.h"
2426
#include "scrub/repair.h"
@@ -330,6 +332,8 @@ xrep_adoption_trans_alloc(
330332
if (S_ISDIR(VFS_I(sc->ip)->i_mode))
331333
child_blkres = xfs_rename_space_res(mp, 0, false,
332334
xfs_name_dotdot.len, false);
335+
if (xfs_has_parent(mp))
336+
child_blkres += XFS_ADDAFORK_SPACE_RES(mp);
333337
adopt->child_blkres = child_blkres;
334338

335339
/*
@@ -503,6 +507,19 @@ xrep_adoption_zap_dcache(
503507
dput(d_orphanage);
504508
}
505509

510+
/*
511+
* If we have to add an attr fork ahead of a parent pointer update, how much
512+
* space should we ask for?
513+
*/
514+
static inline int
515+
xrep_adoption_attr_sizeof(
516+
const struct xrep_adoption *adopt)
517+
{
518+
return sizeof(struct xfs_attr_sf_hdr) +
519+
xfs_attr_sf_entsize_byname(sizeof(struct xfs_parent_rec),
520+
adopt->xname->len);
521+
}
522+
506523
/*
507524
* Move the current file to the orphanage under the computed name.
508525
*
@@ -524,6 +541,19 @@ xrep_adoption_move(
524541
if (error)
525542
return error;
526543

544+
/*
545+
* If this filesystem has parent pointers, ensure that the file being
546+
* moved to the orphanage has an attribute fork. This is required
547+
* because the parent pointer code does not itself add attr forks.
548+
*/
549+
if (!xfs_inode_has_attr_fork(sc->ip) && xfs_has_parent(sc->mp)) {
550+
int sf_size = xrep_adoption_attr_sizeof(adopt);
551+
552+
error = xfs_bmap_add_attrfork(sc->tp, sc->ip, sf_size, true);
553+
if (error)
554+
return error;
555+
}
556+
527557
/* Create the new name in the orphanage. */
528558
error = xfs_dir_createname(sc->tp, sc->orphanage, adopt->xname,
529559
sc->ip->i_ino, adopt->orphanage_blkres);
@@ -548,6 +578,14 @@ xrep_adoption_move(
548578
return error;
549579
}
550580

581+
/* Add a parent pointer from the file back to the lost+found. */
582+
if (xfs_has_parent(sc->mp)) {
583+
error = xfs_parent_addname(sc->tp, &adopt->ppargs,
584+
sc->orphanage, adopt->xname, sc->ip);
585+
if (error)
586+
return error;
587+
}
588+
551589
/*
552590
* Notify dirent hooks that we moved the file to /lost+found, and
553591
* finish all the deferred work so that we know the adoption is fully

fs/xfs/scrub/orphanage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ struct xrep_adoption {
5454
/* Name used for the adoption. */
5555
struct xfs_name *xname;
5656

57+
/* Parent pointer context tracking */
58+
struct xfs_parent_args ppargs;
59+
5760
/* Block reservations for orphanage and child (if directory). */
5861
unsigned int orphanage_blkres;
5962
unsigned int child_blkres;

fs/xfs/scrub/scrub.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "xfs_rmap.h"
2020
#include "xfs_exchrange.h"
2121
#include "xfs_exchmaps.h"
22+
#include "xfs_dir2.h"
23+
#include "xfs_parent.h"
2224
#include "scrub/scrub.h"
2325
#include "scrub/common.h"
2426
#include "scrub/trace.h"

0 commit comments

Comments
 (0)