]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: record reflink inode state
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 25 Oct 2016 22:14:34 +0000 (15:14 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 26 Oct 2016 23:41:07 +0000 (16:41 -0700)
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 <darrick.wong@oracle.com>
repair/dino_chunks.c
repair/dinode.c
repair/incore.h
repair/incore_ino.c
repair/rmap.c
repair/rmap.h

index 7dbaca667446607bd6f670dbe1364a5004fd403e..4db9512a2f1520aca8dbf0050d04e7839cd9289d 100644 (file)
@@ -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:
index 259f133cb48ade8b1c28a0cbad2663739a21821d..d1da6d0ed30edac9de80f9e8df662dd459146907 100644 (file)
@@ -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
         */
index b6c4b4fc98dba98a84017ba1a93ebccaea917445..bcd2f4b7193fb744fe122628a239b70e3088c113 100644 (file)
@@ -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,
index 1898257cc177bfbd52f18bf640c0509f00f08f75..2ec1765736720e5a935ff0544b2d8b0e2b595a28 100644 (file)
@@ -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;
index c6ebcb73431ed836e66d59472443188d8b73bfd8..9df67170428d9fb68961ad14571894fcf4944104 100644 (file)
@@ -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
index 01dec9f2a53bd31ba47a21676ba2d56586ed5f84..ab6f4346d768362d928422bfd7ee26551898cd20 100644 (file)
@@ -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);