aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2016-08-02 21:02:39 -0400
committerDave Chinner <david@fromorbit.com>2016-08-02 21:02:39 -0400
commite5821e57af54abc36ea299bde6c101a804cfac27 (patch)
tree3c5e2137fd2e92fb01b463a6e2b8c6bd46aa1db3
parent0d309791bdc0a92f1db5dfc171d884a6b8583702 (diff)
xfs: during btree split, save new block key & ptr for future insertion
When a btree block has to be split, we pass the new block's ptr from xfs_btree_split() back to xfs_btree_insert() via a pointer parameter; however, we pass the block's key through the cursor's record. It is a little weird to "initialize" a record from a key since the non-key attributes will have garbage values. When we go to add support for interval queries, we have to be able to pass the lowest and highest keys accessible via a pointer. There's no clean way to pass this back through the cursor's record field. Therefore, pass the key directly back to xfs_btree_insert() the same way that we pass the btree_ptr. As a bonus, we no longer need init_rec_from_key and can drop it from the codebase. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r--fs/xfs/libxfs/xfs_alloc_btree.c12
-rw-r--r--fs/xfs/libxfs/xfs_bmap_btree.c12
-rw-r--r--fs/xfs/libxfs/xfs_btree.c40
-rw-r--r--fs/xfs/libxfs/xfs_btree.h2
-rw-r--r--fs/xfs/libxfs/xfs_ialloc_btree.c10
5 files changed, 20 insertions, 56 deletions
diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btree.c
index d9b42425291e..5ba2dac5e67c 100644
--- a/fs/xfs/libxfs/xfs_alloc_btree.c
+++ b/fs/xfs/libxfs/xfs_alloc_btree.c
@@ -212,17 +212,6 @@ xfs_allocbt_init_key_from_rec(
212} 212}
213 213
214STATIC void 214STATIC void
215xfs_allocbt_init_rec_from_key(
216 union xfs_btree_key *key,
217 union xfs_btree_rec *rec)
218{
219 ASSERT(key->alloc.ar_startblock != 0);
220
221 rec->alloc.ar_startblock = key->alloc.ar_startblock;
222 rec->alloc.ar_blockcount = key->alloc.ar_blockcount;
223}
224
225STATIC void
226xfs_allocbt_init_rec_from_cur( 215xfs_allocbt_init_rec_from_cur(
227 struct xfs_btree_cur *cur, 216 struct xfs_btree_cur *cur,
228 union xfs_btree_rec *rec) 217 union xfs_btree_rec *rec)
@@ -406,7 +395,6 @@ static const struct xfs_btree_ops xfs_allocbt_ops = {
406 .get_minrecs = xfs_allocbt_get_minrecs, 395 .get_minrecs = xfs_allocbt_get_minrecs,
407 .get_maxrecs = xfs_allocbt_get_maxrecs, 396 .get_maxrecs = xfs_allocbt_get_maxrecs,
408 .init_key_from_rec = xfs_allocbt_init_key_from_rec, 397 .init_key_from_rec = xfs_allocbt_init_key_from_rec,
409 .init_rec_from_key = xfs_allocbt_init_rec_from_key,
410 .init_rec_from_cur = xfs_allocbt_init_rec_from_cur, 398 .init_rec_from_cur = xfs_allocbt_init_rec_from_cur,
411 .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, 399 .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur,
412 .key_diff = xfs_allocbt_key_diff, 400 .key_diff = xfs_allocbt_key_diff,
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c
index db0c71e470c9..714b387e11ad 100644
--- a/fs/xfs/libxfs/xfs_bmap_btree.c
+++ b/fs/xfs/libxfs/xfs_bmap_btree.c
@@ -600,17 +600,6 @@ xfs_bmbt_init_key_from_rec(
600} 600}
601 601
602STATIC void 602STATIC void
603xfs_bmbt_init_rec_from_key(
604 union xfs_btree_key *key,
605 union xfs_btree_rec *rec)
606{
607 ASSERT(key->bmbt.br_startoff != 0);
608
609 xfs_bmbt_disk_set_allf(&rec->bmbt, be64_to_cpu(key->bmbt.br_startoff),
610 0, 0, XFS_EXT_NORM);
611}
612
613STATIC void
614xfs_bmbt_init_rec_from_cur( 603xfs_bmbt_init_rec_from_cur(
615 struct xfs_btree_cur *cur, 604 struct xfs_btree_cur *cur,
616 union xfs_btree_rec *rec) 605 union xfs_btree_rec *rec)
@@ -760,7 +749,6 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
760 .get_minrecs = xfs_bmbt_get_minrecs, 749 .get_minrecs = xfs_bmbt_get_minrecs,
761 .get_dmaxrecs = xfs_bmbt_get_dmaxrecs, 750 .get_dmaxrecs = xfs_bmbt_get_dmaxrecs,
762 .init_key_from_rec = xfs_bmbt_init_key_from_rec, 751 .init_key_from_rec = xfs_bmbt_init_key_from_rec,
763 .init_rec_from_key = xfs_bmbt_init_rec_from_key,
764 .init_rec_from_cur = xfs_bmbt_init_rec_from_cur, 752 .init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
765 .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur, 753 .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
766 .key_diff = xfs_bmbt_key_diff, 754 .key_diff = xfs_bmbt_key_diff,
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index f5ff95a18e9d..8d8e3625c365 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -2858,10 +2858,9 @@ xfs_btree_make_block_unfull(
2858 int *index, /* new tree index */ 2858 int *index, /* new tree index */
2859 union xfs_btree_ptr *nptr, /* new btree ptr */ 2859 union xfs_btree_ptr *nptr, /* new btree ptr */
2860 struct xfs_btree_cur **ncur, /* new btree cursor */ 2860 struct xfs_btree_cur **ncur, /* new btree cursor */
2861 union xfs_btree_rec *nrec, /* new record */ 2861 union xfs_btree_key *key, /* key of new block */
2862 int *stat) 2862 int *stat)
2863{ 2863{
2864 union xfs_btree_key key; /* new btree key value */
2865 int error = 0; 2864 int error = 0;
2866 2865
2867 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && 2866 if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) &&
@@ -2907,13 +2906,12 @@ xfs_btree_make_block_unfull(
2907 * If this works we have to re-set our variables because we 2906 * If this works we have to re-set our variables because we
2908 * could be in a different block now. 2907 * could be in a different block now.
2909 */ 2908 */
2910 error = xfs_btree_split(cur, level, nptr, &key, ncur, stat); 2909 error = xfs_btree_split(cur, level, nptr, key, ncur, stat);
2911 if (error || *stat == 0) 2910 if (error || *stat == 0)
2912 return error; 2911 return error;
2913 2912
2914 2913
2915 *index = cur->bc_ptrs[level]; 2914 *index = cur->bc_ptrs[level];
2916 cur->bc_ops->init_rec_from_key(&key, nrec);
2917 return 0; 2915 return 0;
2918} 2916}
2919 2917
@@ -2926,16 +2924,16 @@ xfs_btree_insrec(
2926 struct xfs_btree_cur *cur, /* btree cursor */ 2924 struct xfs_btree_cur *cur, /* btree cursor */
2927 int level, /* level to insert record at */ 2925 int level, /* level to insert record at */
2928 union xfs_btree_ptr *ptrp, /* i/o: block number inserted */ 2926 union xfs_btree_ptr *ptrp, /* i/o: block number inserted */
2929 union xfs_btree_rec *recp, /* i/o: record data inserted */ 2927 union xfs_btree_rec *rec, /* record to insert */
2928 union xfs_btree_key *key, /* i/o: block key for ptrp */
2930 struct xfs_btree_cur **curp, /* output: new cursor replacing cur */ 2929 struct xfs_btree_cur **curp, /* output: new cursor replacing cur */
2931 int *stat) /* success/failure */ 2930 int *stat) /* success/failure */
2932{ 2931{
2933 struct xfs_btree_block *block; /* btree block */ 2932 struct xfs_btree_block *block; /* btree block */
2934 struct xfs_buf *bp; /* buffer for block */ 2933 struct xfs_buf *bp; /* buffer for block */
2935 union xfs_btree_key key; /* btree key */
2936 union xfs_btree_ptr nptr; /* new block ptr */ 2934 union xfs_btree_ptr nptr; /* new block ptr */
2937 struct xfs_btree_cur *ncur; /* new btree cursor */ 2935 struct xfs_btree_cur *ncur; /* new btree cursor */
2938 union xfs_btree_rec nrec; /* new record count */ 2936 union xfs_btree_key nkey; /* new block key */
2939 int optr; /* old key/record index */ 2937 int optr; /* old key/record index */
2940 int ptr; /* key/record index */ 2938 int ptr; /* key/record index */
2941 int numrecs;/* number of records */ 2939 int numrecs;/* number of records */
@@ -2945,7 +2943,7 @@ xfs_btree_insrec(
2945#endif 2943#endif
2946 2944
2947 XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY); 2945 XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
2948 XFS_BTREE_TRACE_ARGIPR(cur, level, *ptrp, recp); 2946 XFS_BTREE_TRACE_ARGIPR(cur, level, *ptrp, &rec);
2949 2947
2950 ncur = NULL; 2948 ncur = NULL;
2951 2949
@@ -2970,9 +2968,6 @@ xfs_btree_insrec(
2970 return 0; 2968 return 0;
2971 } 2969 }
2972 2970
2973 /* Make a key out of the record data to be inserted, and save it. */
2974 cur->bc_ops->init_key_from_rec(&key, recp);
2975
2976 optr = ptr; 2971 optr = ptr;
2977 2972
2978 XFS_BTREE_STATS_INC(cur, insrec); 2973 XFS_BTREE_STATS_INC(cur, insrec);
@@ -2989,10 +2984,10 @@ xfs_btree_insrec(
2989 /* Check that the new entry is being inserted in the right place. */ 2984 /* Check that the new entry is being inserted in the right place. */
2990 if (ptr <= numrecs) { 2985 if (ptr <= numrecs) {
2991 if (level == 0) { 2986 if (level == 0) {
2992 ASSERT(cur->bc_ops->recs_inorder(cur, recp, 2987 ASSERT(cur->bc_ops->recs_inorder(cur, rec,
2993 xfs_btree_rec_addr(cur, ptr, block))); 2988 xfs_btree_rec_addr(cur, ptr, block)));
2994 } else { 2989 } else {
2995 ASSERT(cur->bc_ops->keys_inorder(cur, &key, 2990 ASSERT(cur->bc_ops->keys_inorder(cur, key,
2996 xfs_btree_key_addr(cur, ptr, block))); 2991 xfs_btree_key_addr(cur, ptr, block)));
2997 } 2992 }
2998 } 2993 }
@@ -3005,7 +3000,7 @@ xfs_btree_insrec(
3005 xfs_btree_set_ptr_null(cur, &nptr); 3000 xfs_btree_set_ptr_null(cur, &nptr);
3006 if (numrecs == cur->bc_ops->get_maxrecs(cur, level)) { 3001 if (numrecs == cur->bc_ops->get_maxrecs(cur, level)) {
3007 error = xfs_btree_make_block_unfull(cur, level, numrecs, 3002 error = xfs_btree_make_block_unfull(cur, level, numrecs,
3008 &optr, &ptr, &nptr, &ncur, &nrec, stat); 3003 &optr, &ptr, &nptr, &ncur, &nkey, stat);
3009 if (error || *stat == 0) 3004 if (error || *stat == 0)
3010 goto error0; 3005 goto error0;
3011 } 3006 }
@@ -3055,7 +3050,7 @@ xfs_btree_insrec(
3055#endif 3050#endif
3056 3051
3057 /* Now put the new data in, bump numrecs and log it. */ 3052 /* Now put the new data in, bump numrecs and log it. */
3058 xfs_btree_copy_keys(cur, kp, &key, 1); 3053 xfs_btree_copy_keys(cur, kp, key, 1);
3059 xfs_btree_copy_ptrs(cur, pp, ptrp, 1); 3054 xfs_btree_copy_ptrs(cur, pp, ptrp, 1);
3060 numrecs++; 3055 numrecs++;
3061 xfs_btree_set_numrecs(block, numrecs); 3056 xfs_btree_set_numrecs(block, numrecs);
@@ -3076,7 +3071,7 @@ xfs_btree_insrec(
3076 xfs_btree_shift_recs(cur, rp, 1, numrecs - ptr + 1); 3071 xfs_btree_shift_recs(cur, rp, 1, numrecs - ptr + 1);
3077 3072
3078 /* Now put the new data in, bump numrecs and log it. */ 3073 /* Now put the new data in, bump numrecs and log it. */
3079 xfs_btree_copy_recs(cur, rp, recp, 1); 3074 xfs_btree_copy_recs(cur, rp, rec, 1);
3080 xfs_btree_set_numrecs(block, ++numrecs); 3075 xfs_btree_set_numrecs(block, ++numrecs);
3081 xfs_btree_log_recs(cur, bp, ptr, numrecs); 3076 xfs_btree_log_recs(cur, bp, ptr, numrecs);
3082#ifdef DEBUG 3077#ifdef DEBUG
@@ -3092,7 +3087,7 @@ xfs_btree_insrec(
3092 3087
3093 /* If we inserted at the start of a block, update the parents' keys. */ 3088 /* If we inserted at the start of a block, update the parents' keys. */
3094 if (optr == 1) { 3089 if (optr == 1) {
3095 error = xfs_btree_updkey(cur, &key, level + 1); 3090 error = xfs_btree_updkey(cur, key, level + 1);
3096 if (error) 3091 if (error)
3097 goto error0; 3092 goto error0;
3098 } 3093 }
@@ -3102,7 +3097,7 @@ xfs_btree_insrec(
3102 * we are at the far right edge of the tree, update it. 3097 * we are at the far right edge of the tree, update it.
3103 */ 3098 */
3104 if (xfs_btree_is_lastrec(cur, block, level)) { 3099 if (xfs_btree_is_lastrec(cur, block, level)) {
3105 cur->bc_ops->update_lastrec(cur, block, recp, 3100 cur->bc_ops->update_lastrec(cur, block, rec,
3106 ptr, LASTREC_INSREC); 3101 ptr, LASTREC_INSREC);
3107 } 3102 }
3108 3103
@@ -3112,7 +3107,7 @@ xfs_btree_insrec(
3112 */ 3107 */
3113 *ptrp = nptr; 3108 *ptrp = nptr;
3114 if (!xfs_btree_ptr_is_null(cur, &nptr)) { 3109 if (!xfs_btree_ptr_is_null(cur, &nptr)) {
3115 *recp = nrec; 3110 *key = nkey;
3116 *curp = ncur; 3111 *curp = ncur;
3117 } 3112 }
3118 3113
@@ -3143,6 +3138,7 @@ xfs_btree_insert(
3143 union xfs_btree_ptr nptr; /* new block number (split result) */ 3138 union xfs_btree_ptr nptr; /* new block number (split result) */
3144 struct xfs_btree_cur *ncur; /* new cursor (split result) */ 3139 struct xfs_btree_cur *ncur; /* new cursor (split result) */
3145 struct xfs_btree_cur *pcur; /* previous level's cursor */ 3140 struct xfs_btree_cur *pcur; /* previous level's cursor */
3141 union xfs_btree_key key; /* key of block to insert */
3146 union xfs_btree_rec rec; /* record to insert */ 3142 union xfs_btree_rec rec; /* record to insert */
3147 3143
3148 level = 0; 3144 level = 0;
@@ -3150,7 +3146,10 @@ xfs_btree_insert(
3150 pcur = cur; 3146 pcur = cur;
3151 3147
3152 xfs_btree_set_ptr_null(cur, &nptr); 3148 xfs_btree_set_ptr_null(cur, &nptr);
3149
3150 /* Make a key out of the record data to be inserted, and save it. */
3153 cur->bc_ops->init_rec_from_cur(cur, &rec); 3151 cur->bc_ops->init_rec_from_cur(cur, &rec);
3152 cur->bc_ops->init_key_from_rec(&key, &rec);
3154 3153
3155 /* 3154 /*
3156 * Loop going up the tree, starting at the leaf level. 3155 * Loop going up the tree, starting at the leaf level.
@@ -3162,7 +3161,8 @@ xfs_btree_insert(
3162 * Insert nrec/nptr into this level of the tree. 3161 * Insert nrec/nptr into this level of the tree.
3163 * Note if we fail, nptr will be null. 3162 * Note if we fail, nptr will be null.
3164 */ 3163 */
3165 error = xfs_btree_insrec(pcur, level, &nptr, &rec, &ncur, &i); 3164 error = xfs_btree_insrec(pcur, level, &nptr, &rec, &key,
3165 &ncur, &i);
3166 if (error) { 3166 if (error) {
3167 if (pcur != cur) 3167 if (pcur != cur)
3168 xfs_btree_del_cursor(pcur, XFS_BTREE_ERROR); 3168 xfs_btree_del_cursor(pcur, XFS_BTREE_ERROR);
diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
index 785a99682159..b4f3035ae05e 100644
--- a/fs/xfs/libxfs/xfs_btree.h
+++ b/fs/xfs/libxfs/xfs_btree.h
@@ -158,8 +158,6 @@ struct xfs_btree_ops {
158 /* init values of btree structures */ 158 /* init values of btree structures */
159 void (*init_key_from_rec)(union xfs_btree_key *key, 159 void (*init_key_from_rec)(union xfs_btree_key *key,
160 union xfs_btree_rec *rec); 160 union xfs_btree_rec *rec);
161 void (*init_rec_from_key)(union xfs_btree_key *key,
162 union xfs_btree_rec *rec);
163 void (*init_rec_from_cur)(struct xfs_btree_cur *cur, 161 void (*init_rec_from_cur)(struct xfs_btree_cur *cur,
164 union xfs_btree_rec *rec); 162 union xfs_btree_rec *rec);
165 void (*init_ptr_from_cur)(struct xfs_btree_cur *cur, 163 void (*init_ptr_from_cur)(struct xfs_btree_cur *cur,
diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c
index 89c21d771e35..88da2ad939d4 100644
--- a/fs/xfs/libxfs/xfs_ialloc_btree.c
+++ b/fs/xfs/libxfs/xfs_ialloc_btree.c
@@ -146,14 +146,6 @@ xfs_inobt_init_key_from_rec(
146} 146}
147 147
148STATIC void 148STATIC void
149xfs_inobt_init_rec_from_key(
150 union xfs_btree_key *key,
151 union xfs_btree_rec *rec)
152{
153 rec->inobt.ir_startino = key->inobt.ir_startino;
154}
155
156STATIC void
157xfs_inobt_init_rec_from_cur( 149xfs_inobt_init_rec_from_cur(
158 struct xfs_btree_cur *cur, 150 struct xfs_btree_cur *cur,
159 union xfs_btree_rec *rec) 151 union xfs_btree_rec *rec)
@@ -314,7 +306,6 @@ static const struct xfs_btree_ops xfs_inobt_ops = {
314 .get_minrecs = xfs_inobt_get_minrecs, 306 .get_minrecs = xfs_inobt_get_minrecs,
315 .get_maxrecs = xfs_inobt_get_maxrecs, 307 .get_maxrecs = xfs_inobt_get_maxrecs,
316 .init_key_from_rec = xfs_inobt_init_key_from_rec, 308 .init_key_from_rec = xfs_inobt_init_key_from_rec,
317 .init_rec_from_key = xfs_inobt_init_rec_from_key,
318 .init_rec_from_cur = xfs_inobt_init_rec_from_cur, 309 .init_rec_from_cur = xfs_inobt_init_rec_from_cur,
319 .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur, 310 .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur,
320 .key_diff = xfs_inobt_key_diff, 311 .key_diff = xfs_inobt_key_diff,
@@ -336,7 +327,6 @@ static const struct xfs_btree_ops xfs_finobt_ops = {
336 .get_minrecs = xfs_inobt_get_minrecs, 327 .get_minrecs = xfs_inobt_get_minrecs,
337 .get_maxrecs = xfs_inobt_get_maxrecs, 328 .get_maxrecs = xfs_inobt_get_maxrecs,
338 .init_key_from_rec = xfs_inobt_init_key_from_rec, 329 .init_key_from_rec = xfs_inobt_init_key_from_rec,
339 .init_rec_from_key = xfs_inobt_init_rec_from_key,
340 .init_rec_from_cur = xfs_inobt_init_rec_from_cur, 330 .init_rec_from_cur = xfs_inobt_init_rec_from_cur,
341 .init_ptr_from_cur = xfs_finobt_init_ptr_from_cur, 331 .init_ptr_from_cur = xfs_finobt_init_ptr_from_cur,
342 .key_diff = xfs_inobt_key_diff, 332 .key_diff = xfs_inobt_key_diff,