From: Darrick J. Wong Date: Wed, 10 Aug 2016 04:49:13 +0000 (+1000) Subject: xfs: add rmap btree insert and delete helpers X-Git-Tag: v4.8.0-rc1~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b26675c4a56402c45d4890d42168251290d080ef;p=thirdparty%2Fxfsprogs-dev.git xfs: add rmap btree insert and delete helpers Source kernel commit: abf09233817b5ea1241db0c187136d3b4738d218 Add a couple of helper functions to encapsulate rmap btree insert and delete operations. Add tracepoints to the update function. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Brian Foster Signed-off-by: Dave Chinner --- diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 82ecb82de..f163854d8 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -198,11 +198,14 @@ #define trace_xfs_rmap_unmap_error(...) ((void) 0) #define trace_xfs_rmap_unmap_done(...) ((void) 0) #define trace_xfs_rmap_insert(...) ((void) 0) +#define trace_xfs_rmap_insert_error(...) ((void) 0) #define trace_xfs_rmap_delete(...) ((void) 0) #define trace_xfs_rmap_convert(...) ((void) 0) #define trace_xfs_rmap_convert_state(...) ((void) 0) #define trace_xfs_rmap_convert_done(...) ((void) 0) #define trace_xfs_rmap_convert_error(...) ((void) 0) +#define trace_xfs_rmap_update(...) ((void) 0) +#define trace_xfs_rmap_update_error(...) ((void) 0) #define trace_xfs_rmap_find_right_neighbor_result(...) ((void) 0) #define trace_xfs_rmap_find_left_neighbor_result(...) ((void) 0) #define trace_xfs_rmap_lookup_le_range_result(...) ((void) 0) diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index 32b893fc3..62dc34dff 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -90,13 +90,58 @@ xfs_rmap_update( struct xfs_rmap_irec *irec) { union xfs_btree_rec rec; + int error; + + trace_xfs_rmap_update(cur->bc_mp, cur->bc_private.a.agno, + irec->rm_startblock, irec->rm_blockcount, + irec->rm_owner, irec->rm_offset, irec->rm_flags); rec.rmap.rm_startblock = cpu_to_be32(irec->rm_startblock); rec.rmap.rm_blockcount = cpu_to_be32(irec->rm_blockcount); rec.rmap.rm_owner = cpu_to_be64(irec->rm_owner); rec.rmap.rm_offset = cpu_to_be64( xfs_rmap_irec_offset_pack(irec)); - return xfs_btree_update(cur, &rec); + error = xfs_btree_update(cur, &rec); + if (error) + trace_xfs_rmap_update_error(cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); + return error; +} + +int +xfs_rmap_insert( + struct xfs_btree_cur *rcur, + xfs_agblock_t agbno, + xfs_extlen_t len, + uint64_t owner, + uint64_t offset, + unsigned int flags) +{ + int i; + int error; + + trace_xfs_rmap_insert(rcur->bc_mp, rcur->bc_private.a.agno, agbno, + len, owner, offset, flags); + + error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i); + if (error) + goto done; + XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 0, done); + + rcur->bc_rec.r.rm_startblock = agbno; + rcur->bc_rec.r.rm_blockcount = len; + rcur->bc_rec.r.rm_owner = owner; + rcur->bc_rec.r.rm_offset = offset; + rcur->bc_rec.r.rm_flags = flags; + error = xfs_btree_insert(rcur, &i); + if (error) + goto done; + XFS_WANT_CORRUPTED_GOTO(rcur->bc_mp, i == 1, done); +done: + if (error) + trace_xfs_rmap_insert_error(rcur->bc_mp, + rcur->bc_private.a.agno, error, _RET_IP_); + return error; } static int diff --git a/libxfs/xfs_rmap.h b/libxfs/xfs_rmap.h index 34c811a2d..92ac067da 100644 --- a/libxfs/xfs_rmap.h +++ b/libxfs/xfs_rmap.h @@ -148,6 +148,9 @@ int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno, int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner, uint64_t offset, unsigned int flags, int *stat); +int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno, + xfs_extlen_t len, uint64_t owner, uint64_t offset, + unsigned int flags); int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec, int *stat);