From: Darrick J. Wong Date: Tue, 25 Oct 2016 22:14:34 +0000 (-0700) Subject: xfs_repair: record reflink inode state X-Git-Tag: v4.9.0-rc1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e174ec71c37b129aa4e494a916d625f8f268d30;p=thirdparty%2Fxfsprogs-dev.git xfs_repair: record reflink inode state Record the state of the per-inode reflink flag, so that we can compare against the rmap data and update the flags accordingly. Clear the (reflink) state if we clear the inode. Signed-off-by: Darrick J. Wong --- diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 7dbaca667..4db9512a2 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -931,6 +931,7 @@ next_readbuf: do_warn(_("would have cleared inode %" PRIu64 "\n"), ino); } + clear_inode_was_rl(ino_rec, irec_offset); } process_next: diff --git a/repair/dinode.c b/repair/dinode.c index 259f133cb..d1da6d0ed 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -2633,6 +2633,12 @@ _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64 ", "), if (process_check_inode_forkoff(mp, dino, lino) != 0) goto clear_bad_out; + /* + * record the state of the reflink flag + */ + if (collect_rmaps) + record_inode_reflink_flag(mp, dino, agno, ino, lino); + /* * check data fork -- if it's bad, clear the inode */ diff --git a/repair/incore.h b/repair/incore.h index b6c4b4fc9..bcd2f4b71 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -283,6 +283,8 @@ typedef struct ino_tree_node { __uint64_t ir_sparse; /* sparse inode bitmask */ __uint64_t ino_confirmed; /* confirmed bitmask */ __uint64_t ino_isa_dir; /* bit == 1 if a directory */ + __uint64_t ino_was_rl; /* bit == 1 if reflink flag set */ + __uint64_t ino_is_rl; /* bit == 1 if reflink flag should be set */ __uint8_t nlink_size; union ino_nlink disk_nlinks; /* on-disk nlinks, set in P3 */ union { @@ -493,6 +495,42 @@ static inline bool is_inode_sparse(struct ino_tree_node *irec, int offset) return irec->ir_sparse & XFS_INOBT_MASK(offset); } +/* + * set/clear/test was inode marked as reflinked + */ +static inline void set_inode_was_rl(struct ino_tree_node *irec, int offset) +{ + irec->ino_was_rl |= IREC_MASK(offset); +} + +static inline void clear_inode_was_rl(struct ino_tree_node *irec, int offset) +{ + irec->ino_was_rl &= ~IREC_MASK(offset); +} + +static inline int inode_was_rl(struct ino_tree_node *irec, int offset) +{ + return (irec->ino_was_rl & IREC_MASK(offset)) != 0; +} + +/* + * set/clear/test should inode be marked as reflinked + */ +static inline void set_inode_is_rl(struct ino_tree_node *irec, int offset) +{ + irec->ino_is_rl |= IREC_MASK(offset); +} + +static inline void clear_inode_is_rl(struct ino_tree_node *irec, int offset) +{ + irec->ino_is_rl &= ~IREC_MASK(offset); +} + +static inline int inode_is_rl(struct ino_tree_node *irec, int offset) +{ + return (irec->ino_is_rl & IREC_MASK(offset)) != 0; +} + /* * add_inode_reached() is set on inode I only if I has been reached * by an inode P claiming to be the parent and if I is a directory, diff --git a/repair/incore_ino.c b/repair/incore_ino.c index 1898257cc..2ec176573 100644 --- a/repair/incore_ino.c +++ b/repair/incore_ino.c @@ -257,6 +257,8 @@ alloc_ino_node( irec->ino_startnum = starting_ino; irec->ino_confirmed = 0; irec->ino_isa_dir = 0; + irec->ino_was_rl = 0; + irec->ino_is_rl = 0; irec->ir_free = (xfs_inofree_t) - 1; irec->ir_sparse = 0; irec->ino_un.ex_data = NULL; diff --git a/repair/rmap.c b/repair/rmap.c index c6ebcb734..9df671704 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -1083,6 +1083,32 @@ rmap_high_key_from_rec( key->rm_offset += adj; } +/* + * Record that an inode had the reflink flag set when repair started. The + * inode reflink flag will be adjusted as necessary. + */ +void +record_inode_reflink_flag( + struct xfs_mount *mp, + struct xfs_dinode *dino, + xfs_agnumber_t agno, + xfs_agino_t ino, + xfs_ino_t lino) +{ + struct ino_tree_node *irec; + int off; + + ASSERT(XFS_AGINO_TO_INO(mp, agno, ino) == be64_to_cpu(dino->di_ino)); + if (!(be64_to_cpu(dino->di_flags2) & XFS_DIFLAG2_REFLINK)) + return; + irec = find_inode_rec(mp, agno, ino); + off = get_inode_offset(mp, lino, irec); + ASSERT(!inode_was_rl(irec, off)); + set_inode_was_rl(irec, off); + dbg_printf("set was_rl lino=%llu was=0x%llx\n", + (unsigned long long)lino, (unsigned long long)irec->ino_was_rl); +} + /* * Regenerate the AGFL so that we don't run out of it while rebuilding the * rmap btree. If skip_rmapbt is true, don't update the rmapbt (most probably diff --git a/repair/rmap.h b/repair/rmap.h index 01dec9f2a..ab6f4346d 100644 --- a/repair/rmap.h +++ b/repair/rmap.h @@ -50,6 +50,8 @@ extern void rmap_high_key_from_rec(struct xfs_rmap_irec *rec, struct xfs_rmap_irec *key); extern int compute_refcounts(struct xfs_mount *, xfs_agnumber_t); +extern void record_inode_reflink_flag(struct xfs_mount *, struct xfs_dinode *, + xfs_agnumber_t, xfs_agino_t, xfs_ino_t); extern void fix_freelist(struct xfs_mount *, xfs_agnumber_t, bool); extern void rmap_store_agflcount(struct xfs_mount *, xfs_agnumber_t, int);