]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: introduce rmap extent operation stubs
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 10 Aug 2016 01:53:23 +0000 (11:53 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 10 Aug 2016 01:53:23 +0000 (11:53 +1000)
Source kernel commit: 673930c34a4500c616cf9b2bbe1ae131ead2e155

Originally-From: Dave Chinner <dchinner@redhat.com>

Add the stubs into the extent allocation and freeing paths that the
rmap btree implementation will hook into. While doing this, add the
trace points that will be used to track rmap btree extent
manipulations.

[darrick.wong@oracle.com: Extend the stubs to take full owner info.]

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/libxfs.h
include/xfs_trace.h
libxfs/Makefile
libxfs/xfs_alloc.c
libxfs/xfs_rmap.c [new file with mode: 0644]
libxfs/xfs_rmap.h
libxfs/xfs_rmap_btree.h [new file with mode: 0644]

index 9af40911222faa39b140b28223d9b24af3773187..c182fa159ca0720ef930aa3becfdcf392c82e90b 100644 (file)
@@ -77,6 +77,7 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
 #include "xfs_bmap.h"
 #include "xfs_trace.h"
 #include "xfs_trans.h"
+#include "xfs_rmap_btree.h"
 
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
index aa032328915ad6c5f2f1e9a967e46b32eb75ef35..2cf7b63d659d7698ab17b3ee7b34aeb2b225a98c 100644 (file)
 #define trace_xfs_defer_finish_error(a,b,c)    ((void) 0)
 #define trace_xfs_defer_finish_done(a,b)       ((void) 0)
 
-#define trace_xfs_bmap_free_defer(a,b,c,d,e)   ((void) 0)
-#define trace_xfs_bmap_free_deferred(a,b,c,d,e)        ((void) 0)
+#define trace_xfs_bmap_free_defer(...)         ((void) 0)
+#define trace_xfs_bmap_free_deferred(...)      ((void) 0)
+
+#define trace_xfs_rmap_map(...)                        ((void) 0)
+#define trace_xfs_rmap_map_error(...)          ((void) 0)
+#define trace_xfs_rmap_map_done(...)           ((void) 0)
+#define trace_xfs_rmap_unmap(...)              ((void) 0)
+#define trace_xfs_rmap_unmap_error(...)                ((void) 0)
+#define trace_xfs_rmap_unmap_done(...)         ((void) 0)
+
 
 #endif /* __TRACE_H__ */
index c575e91799eb1ecabb2384c3d3f2ca310dbf579a..16dfe3c2591f72c976b6b706b65c27908c479a95 100644 (file)
@@ -36,6 +36,7 @@ HFILES = \
        xfs_inode_fork.h \
        xfs_quota_defs.h \
        xfs_rmap.h \
+       xfs_rmap_btree.h \
        xfs_sb.h \
        xfs_shared.h \
        xfs_trans_resv.h \
@@ -82,6 +83,7 @@ CFILES = cache.c \
        xfs_inode_fork.c \
        xfs_ialloc_btree.c \
        xfs_log_rlimit.c \
+       xfs_rmap.c \
        xfs_rtbitmap.c \
        xfs_sb.c \
        xfs_symlink_remote.c \
index 9733035221780d7ef2b5a5fae45f019a2a1d660c..1678bc18e31a612b4107f07cb4931e10d58e7954 100644 (file)
 #include "xfs_defer.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
+#include "xfs_rmap.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_alloc.h"
 #include "xfs_cksum.h"
 #include "xfs_trace.h"
 #include "xfs_trans.h"
-#include "xfs_rmap.h"
 
 struct workqueue_struct *xfs_alloc_wq;
 
@@ -645,6 +645,14 @@ xfs_alloc_ag_vextent(
        ASSERT(!args->wasfromfl || !args->isfl);
        ASSERT(args->agbno % args->alignment == 0);
 
+       /* if not file data, insert new block into the reverse map btree */
+       if (args->oinfo.oi_owner != XFS_RMAP_OWN_UNKNOWN) {
+               error = xfs_rmap_alloc(args->tp, args->agbp, args->agno,
+                                      args->agbno, args->len, &args->oinfo);
+               if (error)
+                       return error;
+       }
+
        if (!args->wasfromfl) {
                error = xfs_alloc_update_counters(args->tp, args->pag,
                                                  args->agbp,
@@ -1611,12 +1619,19 @@ xfs_free_ag_extent(
        xfs_extlen_t    nlen;           /* new length of freespace */
        xfs_perag_t     *pag;           /* per allocation group data */
 
+       bno_cur = cnt_cur = NULL;
        mp = tp->t_mountp;
+
+       if (oinfo->oi_owner != XFS_RMAP_OWN_UNKNOWN) {
+               error = xfs_rmap_free(tp, agbp, agno, bno, len, oinfo);
+               if (error)
+                       goto error0;
+       }
+
        /*
         * Allocate and initialize a cursor for the by-block btree.
         */
        bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_BNO);
-       cnt_cur = NULL;
        /*
         * Look for a neighboring block on the left (lower block numbers)
         * that is contiguous with this space.
diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c
new file mode 100644 (file)
index 0000000..17e44b4
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include "libxfs_priv.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_bit.h"
+#include "xfs_sb.h"
+#include "xfs_mount.h"
+#include "xfs_defer.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
+#include "xfs_btree.h"
+#include "xfs_trans.h"
+#include "xfs_alloc.h"
+#include "xfs_rmap.h"
+#include "xfs_trans_space.h"
+#include "xfs_trace.h"
+
+int
+xfs_rmap_free(
+       struct xfs_trans        *tp,
+       struct xfs_buf          *agbp,
+       xfs_agnumber_t          agno,
+       xfs_agblock_t           bno,
+       xfs_extlen_t            len,
+       struct xfs_owner_info   *oinfo)
+{
+       struct xfs_mount        *mp = tp->t_mountp;
+       int                     error = 0;
+
+       if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
+               return 0;
+
+       trace_xfs_rmap_unmap(mp, agno, bno, len, false, oinfo);
+       if (1)
+               goto out_error;
+       trace_xfs_rmap_unmap_done(mp, agno, bno, len, false, oinfo);
+       return 0;
+
+out_error:
+       trace_xfs_rmap_unmap_error(mp, agno, error, _RET_IP_);
+       return error;
+}
+
+int
+xfs_rmap_alloc(
+       struct xfs_trans        *tp,
+       struct xfs_buf          *agbp,
+       xfs_agnumber_t          agno,
+       xfs_agblock_t           bno,
+       xfs_extlen_t            len,
+       struct xfs_owner_info   *oinfo)
+{
+       struct xfs_mount        *mp = tp->t_mountp;
+       int                     error = 0;
+
+       if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
+               return 0;
+
+       trace_xfs_rmap_map(mp, agno, bno, len, false, oinfo);
+       if (1)
+               goto out_error;
+       trace_xfs_rmap_map_done(mp, agno, bno, len, false, oinfo);
+       return 0;
+
+out_error:
+       trace_xfs_rmap_map_error(mp, agno, error, _RET_IP_);
+       return error;
+}
index b30e7ad6c7cc0711301f5d9bb65ed9f0e4d4d774..dbf0301e9ae154751f36255156e9c4b9c6836c38 100644 (file)
@@ -64,4 +64,15 @@ xfs_rmap_skip_owner_update(
        oi->oi_owner = XFS_RMAP_OWN_UNKNOWN;
 }
 
+/* Reverse mapping functions. */
+
+struct xfs_buf;
+
+int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
+                  xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
+                  struct xfs_owner_info *oinfo);
+int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
+                 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
+                 struct xfs_owner_info *oinfo);
+
 #endif /* __XFS_RMAP_H__ */
diff --git a/libxfs/xfs_rmap_btree.h b/libxfs/xfs_rmap_btree.h
new file mode 100644 (file)
index 0000000..92ebe46
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#ifndef __XFS_RMAP_BTREE_H__
+#define        __XFS_RMAP_BTREE_H__
+
+struct xfs_buf;
+
+int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
+                  xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
+                  struct xfs_owner_info *oinfo);
+int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
+                 xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len,
+                 struct xfs_owner_info *oinfo);
+
+#endif /* __XFS_RMAP_BTREE_H__ */