aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/xfs_alloc_btree.c50
-rw-r--r--fs/xfs/xfs_bmap_btree.c49
-rw-r--r--fs/xfs/xfs_btree.c87
-rw-r--r--fs/xfs/xfs_btree.h1
-rw-r--r--fs/xfs/xfs_ialloc_btree.c50
5 files changed, 103 insertions, 134 deletions
diff --git a/fs/xfs/xfs_alloc_btree.c b/fs/xfs/xfs_alloc_btree.c
index b81fbf1216ed..28c6a698f562 100644
--- a/fs/xfs/xfs_alloc_btree.c
+++ b/fs/xfs/xfs_alloc_btree.c
@@ -52,7 +52,6 @@ STATIC int xfs_alloc_newroot(xfs_btree_cur_t *, int *);
52STATIC int xfs_alloc_rshift(xfs_btree_cur_t *, int, int *); 52STATIC int xfs_alloc_rshift(xfs_btree_cur_t *, int, int *);
53STATIC int xfs_alloc_split(xfs_btree_cur_t *, int, xfs_agblock_t *, 53STATIC int xfs_alloc_split(xfs_btree_cur_t *, int, xfs_agblock_t *,
54 xfs_alloc_key_t *, xfs_btree_cur_t **, int *); 54 xfs_alloc_key_t *, xfs_btree_cur_t **, int *);
55STATIC int xfs_alloc_updkey(xfs_btree_cur_t *, xfs_alloc_key_t *, int);
56 55
57/* 56/*
58 * Internal functions. 57 * Internal functions.
@@ -265,7 +264,7 @@ xfs_alloc_delrec(
265 * If we deleted the leftmost entry in the block, update the 264 * If we deleted the leftmost entry in the block, update the
266 * key values above us in the tree. 265 * key values above us in the tree.
267 */ 266 */
268 if (ptr == 1 && (error = xfs_alloc_updkey(cur, lkp, level + 1))) 267 if (ptr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)lkp, level + 1)))
269 return error; 268 return error;
270 /* 269 /*
271 * If the number of records remaining in the block is at least 270 * If the number of records remaining in the block is at least
@@ -798,7 +797,7 @@ xfs_alloc_insrec(
798 /* 797 /*
799 * If we inserted at the start of a block, update the parents' keys. 798 * If we inserted at the start of a block, update the parents' keys.
800 */ 799 */
801 if (optr == 1 && (error = xfs_alloc_updkey(cur, &key, level + 1))) 800 if (optr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, level + 1)))
802 return error; 801 return error;
803 /* 802 /*
804 * Look to see if the longest extent in the allocation group 803 * Look to see if the longest extent in the allocation group
@@ -1068,7 +1067,7 @@ xfs_alloc_lshift(
1068 /* 1067 /*
1069 * Update the parent key values of right. 1068 * Update the parent key values of right.
1070 */ 1069 */
1071 if ((error = xfs_alloc_updkey(cur, rkp, level + 1))) 1070 if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)rkp, level + 1)))
1072 return error; 1071 return error;
1073 /* 1072 /*
1074 * Slide the cursor value left one. 1073 * Slide the cursor value left one.
@@ -1354,7 +1353,7 @@ xfs_alloc_rshift(
1354 i = xfs_btree_lastrec(tcur, level); 1353 i = xfs_btree_lastrec(tcur, level);
1355 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1354 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
1356 if ((error = xfs_btree_increment(tcur, level, &i)) || 1355 if ((error = xfs_btree_increment(tcur, level, &i)) ||
1357 (error = xfs_alloc_updkey(tcur, rkp, level + 1))) 1356 (error = xfs_btree_updkey(tcur, (union xfs_btree_key *)rkp, level + 1)))
1358 goto error0; 1357 goto error0;
1359 xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR); 1358 xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR);
1360 *stat = 1; 1359 *stat = 1;
@@ -1520,45 +1519,6 @@ xfs_alloc_split(
1520} 1519}
1521 1520
1522/* 1521/*
1523 * Update keys at all levels from here to the root along the cursor's path.
1524 */
1525STATIC int /* error */
1526xfs_alloc_updkey(
1527 xfs_btree_cur_t *cur, /* btree cursor */
1528 xfs_alloc_key_t *keyp, /* new key value to update to */
1529 int level) /* starting level for update */
1530{
1531 int ptr; /* index of key in block */
1532
1533 /*
1534 * Go up the tree from this level toward the root.
1535 * At each level, update the key value to the value input.
1536 * Stop when we reach a level where the cursor isn't pointing
1537 * at the first entry in the block.
1538 */
1539 for (ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) {
1540 xfs_alloc_block_t *block; /* btree block */
1541 xfs_buf_t *bp; /* buffer for block */
1542#ifdef DEBUG
1543 int error; /* error return value */
1544#endif
1545 xfs_alloc_key_t *kp; /* ptr to btree block keys */
1546
1547 bp = cur->bc_bufs[level];
1548 block = XFS_BUF_TO_ALLOC_BLOCK(bp);
1549#ifdef DEBUG
1550 if ((error = xfs_btree_check_sblock(cur, block, level, bp)))
1551 return error;
1552#endif
1553 ptr = cur->bc_ptrs[level];
1554 kp = XFS_ALLOC_KEY_ADDR(block, ptr, cur);
1555 *kp = *keyp;
1556 xfs_alloc_log_keys(cur, bp, ptr, ptr);
1557 }
1558 return 0;
1559}
1560
1561/*
1562 * Externally visible routines. 1522 * Externally visible routines.
1563 */ 1523 */
1564 1524
@@ -1765,7 +1725,7 @@ xfs_alloc_update(
1765 1725
1766 key.ar_startblock = cpu_to_be32(bno); 1726 key.ar_startblock = cpu_to_be32(bno);
1767 key.ar_blockcount = cpu_to_be32(len); 1727 key.ar_blockcount = cpu_to_be32(len);
1768 if ((error = xfs_alloc_updkey(cur, &key, 1))) 1728 if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, 1)))
1769 return error; 1729 return error;
1770 } 1730 }
1771 return 0; 1731 return 0;
diff --git a/fs/xfs/xfs_bmap_btree.c b/fs/xfs/xfs_bmap_btree.c
index 8403d154ae09..0a56257b7fd5 100644
--- a/fs/xfs/xfs_bmap_btree.c
+++ b/fs/xfs/xfs_bmap_btree.c
@@ -56,7 +56,6 @@ STATIC int xfs_bmbt_lshift(xfs_btree_cur_t *, int, int *);
56STATIC int xfs_bmbt_rshift(xfs_btree_cur_t *, int, int *); 56STATIC int xfs_bmbt_rshift(xfs_btree_cur_t *, int, int *);
57STATIC int xfs_bmbt_split(xfs_btree_cur_t *, int, xfs_fsblock_t *, 57STATIC int xfs_bmbt_split(xfs_btree_cur_t *, int, xfs_fsblock_t *,
58 __uint64_t *, xfs_btree_cur_t **, int *); 58 __uint64_t *, xfs_btree_cur_t **, int *);
59STATIC int xfs_bmbt_updkey(xfs_btree_cur_t *, xfs_bmbt_key_t *, int);
60 59
61#undef EXIT 60#undef EXIT
62 61
@@ -211,7 +210,7 @@ xfs_bmbt_delrec(
211 *stat = 1; 210 *stat = 1;
212 return 0; 211 return 0;
213 } 212 }
214 if (ptr == 1 && (error = xfs_bmbt_updkey(cur, kp, level + 1))) { 213 if (ptr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)kp, level + 1))) {
215 XFS_BMBT_TRACE_CURSOR(cur, ERROR); 214 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
216 goto error0; 215 goto error0;
217 } 216 }
@@ -635,7 +634,7 @@ xfs_bmbt_insrec(
635 kp + ptr); 634 kp + ptr);
636 } 635 }
637#endif 636#endif
638 if (optr == 1 && (error = xfs_bmbt_updkey(cur, &key, level + 1))) { 637 if (optr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, level + 1))) {
639 XFS_BMBT_TRACE_CURSOR(cur, ERROR); 638 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
640 return error; 639 return error;
641 } 640 }
@@ -935,7 +934,7 @@ xfs_bmbt_lshift(
935 key.br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(rrp)); 934 key.br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(rrp));
936 rkp = &key; 935 rkp = &key;
937 } 936 }
938 if ((error = xfs_bmbt_updkey(cur, rkp, level + 1))) { 937 if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)rkp, level + 1))) {
939 XFS_BMBT_TRACE_CURSOR(cur, ERROR); 938 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
940 return error; 939 return error;
941 } 940 }
@@ -1067,7 +1066,7 @@ xfs_bmbt_rshift(
1067 goto error1; 1066 goto error1;
1068 } 1067 }
1069 XFS_WANT_CORRUPTED_GOTO(i == 1, error0); 1068 XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
1070 if ((error = xfs_bmbt_updkey(tcur, rkp, level + 1))) { 1069 if ((error = xfs_btree_updkey(tcur, (union xfs_btree_key *)rkp, level + 1))) {
1071 XFS_BMBT_TRACE_CURSOR(tcur, ERROR); 1070 XFS_BMBT_TRACE_CURSOR(tcur, ERROR);
1072 goto error1; 1071 goto error1;
1073 } 1072 }
@@ -1276,44 +1275,6 @@ xfs_bmbt_split(
1276 return 0; 1275 return 0;
1277} 1276}
1278 1277
1279
1280/*
1281 * Update keys for the record.
1282 */
1283STATIC int
1284xfs_bmbt_updkey(
1285 xfs_btree_cur_t *cur,
1286 xfs_bmbt_key_t *keyp, /* on-disk format */
1287 int level)
1288{
1289 xfs_bmbt_block_t *block;
1290 xfs_buf_t *bp;
1291#ifdef DEBUG
1292 int error;
1293#endif
1294 xfs_bmbt_key_t *kp;
1295 int ptr;
1296
1297 ASSERT(level >= 1);
1298 XFS_BMBT_TRACE_CURSOR(cur, ENTRY);
1299 XFS_BMBT_TRACE_ARGIK(cur, level, keyp);
1300 for (ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) {
1301 block = xfs_bmbt_get_block(cur, level, &bp);
1302#ifdef DEBUG
1303 if ((error = xfs_btree_check_lblock(cur, block, level, bp))) {
1304 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
1305 return error;
1306 }
1307#endif
1308 ptr = cur->bc_ptrs[level];
1309 kp = XFS_BMAP_KEY_IADDR(block, ptr, cur);
1310 *kp = *keyp;
1311 xfs_bmbt_log_keys(cur, bp, ptr, ptr);
1312 }
1313 XFS_BMBT_TRACE_CURSOR(cur, EXIT);
1314 return 0;
1315}
1316
1317/* 1278/*
1318 * Convert on-disk form of btree root to in-memory form. 1279 * Convert on-disk form of btree root to in-memory form.
1319 */ 1280 */
@@ -2039,7 +2000,7 @@ xfs_bmbt_update(
2039 return 0; 2000 return 0;
2040 } 2001 }
2041 key.br_startoff = cpu_to_be64(off); 2002 key.br_startoff = cpu_to_be64(off);
2042 if ((error = xfs_bmbt_updkey(cur, &key, 1))) { 2003 if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, 1))) {
2043 XFS_BMBT_TRACE_CURSOR(cur, ERROR); 2004 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
2044 return error; 2005 return error;
2045 } 2006 }
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c
index 41912a01bec7..1459a2b9a729 100644
--- a/fs/xfs/xfs_btree.c
+++ b/fs/xfs/xfs_btree.c
@@ -34,6 +34,7 @@
34#include "xfs_attr_sf.h" 34#include "xfs_attr_sf.h"
35#include "xfs_dinode.h" 35#include "xfs_dinode.h"
36#include "xfs_inode.h" 36#include "xfs_inode.h"
37#include "xfs_inode_item.h"
37#include "xfs_btree.h" 38#include "xfs_btree.h"
38#include "xfs_btree_trace.h" 39#include "xfs_btree_trace.h"
39#include "xfs_ialloc.h" 40#include "xfs_ialloc.h"
@@ -1065,6 +1066,45 @@ xfs_btree_read_buf_block(
1065} 1066}
1066 1067
1067/* 1068/*
1069 * Copy keys from one btree block to another.
1070 */
1071STATIC void
1072xfs_btree_copy_keys(
1073 struct xfs_btree_cur *cur,
1074 union xfs_btree_key *dst_key,
1075 union xfs_btree_key *src_key,
1076 int numkeys)
1077{
1078 ASSERT(numkeys >= 0);
1079 memcpy(dst_key, src_key, numkeys * cur->bc_ops->key_len);
1080}
1081
1082/*
1083 * Log key values from the btree block.
1084 */
1085STATIC void
1086xfs_btree_log_keys(
1087 struct xfs_btree_cur *cur,
1088 struct xfs_buf *bp,
1089 int first,
1090 int last)
1091{
1092 XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
1093 XFS_BTREE_TRACE_ARGBII(cur, bp, first, last);
1094
1095 if (bp) {
1096 xfs_trans_log_buf(cur->bc_tp, bp,
1097 xfs_btree_key_offset(cur, first),
1098 xfs_btree_key_offset(cur, last + 1) - 1);
1099 } else {
1100 xfs_trans_log_inode(cur->bc_tp, cur->bc_private.b.ip,
1101 xfs_ilog_fbroot(cur->bc_private.b.whichfork));
1102 }
1103
1104 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
1105}
1106
1107/*
1068 * Increment cursor by one record at the level. 1108 * Increment cursor by one record at the level.
1069 * For nonzero levels the leaf-ward information is untouched. 1109 * For nonzero levels the leaf-ward information is untouched.
1070 */ 1110 */
@@ -1489,3 +1529,50 @@ error0:
1489 XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR); 1529 XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
1490 return error; 1530 return error;
1491} 1531}
1532
1533/*
1534 * Update keys at all levels from here to the root along the cursor's path.
1535 */
1536int
1537xfs_btree_updkey(
1538 struct xfs_btree_cur *cur,
1539 union xfs_btree_key *keyp,
1540 int level)
1541{
1542 struct xfs_btree_block *block;
1543 struct xfs_buf *bp;
1544 union xfs_btree_key *kp;
1545 int ptr;
1546
1547 XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
1548 XFS_BTREE_TRACE_ARGIK(cur, level, keyp);
1549
1550 ASSERT(!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) || level >= 1);
1551
1552 /*
1553 * Go up the tree from this level toward the root.
1554 * At each level, update the key value to the value input.
1555 * Stop when we reach a level where the cursor isn't pointing
1556 * at the first entry in the block.
1557 */
1558 for (ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) {
1559#ifdef DEBUG
1560 int error;
1561#endif
1562 block = xfs_btree_get_block(cur, level, &bp);
1563#ifdef DEBUG
1564 error = xfs_btree_check_block(cur, block, level, bp);
1565 if (error) {
1566 XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
1567 return error;
1568 }
1569#endif
1570 ptr = cur->bc_ptrs[level];
1571 kp = xfs_btree_key_addr(cur, ptr, block);
1572 xfs_btree_copy_keys(cur, kp, keyp, 1);
1573 xfs_btree_log_keys(cur, bp, ptr, ptr);
1574 }
1575
1576 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
1577 return 0;
1578}
diff --git a/fs/xfs/xfs_btree.h b/fs/xfs/xfs_btree.h
index c151175a5fd0..ac3f527b0ac4 100644
--- a/fs/xfs/xfs_btree.h
+++ b/fs/xfs/xfs_btree.h
@@ -518,6 +518,7 @@ xfs_btree_setbuf(
518int xfs_btree_increment(struct xfs_btree_cur *, int, int *); 518int xfs_btree_increment(struct xfs_btree_cur *, int, int *);
519int xfs_btree_decrement(struct xfs_btree_cur *, int, int *); 519int xfs_btree_decrement(struct xfs_btree_cur *, int, int *);
520int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *); 520int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *);
521int xfs_btree_updkey(struct xfs_btree_cur *, union xfs_btree_key *, int);
521 522
522/* 523/*
523 * Helpers. 524 * Helpers.
diff --git a/fs/xfs/xfs_ialloc_btree.c b/fs/xfs/xfs_ialloc_btree.c
index 161c3b2e245f..cd8bb519cb5f 100644
--- a/fs/xfs/xfs_ialloc_btree.c
+++ b/fs/xfs/xfs_ialloc_btree.c
@@ -48,7 +48,6 @@ STATIC int xfs_inobt_newroot(xfs_btree_cur_t *, int *);
48STATIC int xfs_inobt_rshift(xfs_btree_cur_t *, int, int *); 48STATIC int xfs_inobt_rshift(xfs_btree_cur_t *, int, int *);
49STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *, 49STATIC int xfs_inobt_split(xfs_btree_cur_t *, int, xfs_agblock_t *,
50 xfs_inobt_key_t *, xfs_btree_cur_t **, int *); 50 xfs_inobt_key_t *, xfs_btree_cur_t **, int *);
51STATIC int xfs_inobt_updkey(xfs_btree_cur_t *, xfs_inobt_key_t *, int);
52 51
53/* 52/*
54 * Single level of the xfs_inobt_delete record deletion routine. 53 * Single level of the xfs_inobt_delete record deletion routine.
@@ -214,7 +213,7 @@ xfs_inobt_delrec(
214 * If we deleted the leftmost entry in the block, update the 213 * If we deleted the leftmost entry in the block, update the
215 * key values above us in the tree. 214 * key values above us in the tree.
216 */ 215 */
217 if (ptr == 1 && (error = xfs_inobt_updkey(cur, kp, level + 1))) 216 if (ptr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)kp, level + 1)))
218 return error; 217 return error;
219 /* 218 /*
220 * If the number of records remaining in the block is at least 219 * If the number of records remaining in the block is at least
@@ -723,7 +722,7 @@ xfs_inobt_insrec(
723 /* 722 /*
724 * If we inserted at the start of a block, update the parents' keys. 723 * If we inserted at the start of a block, update the parents' keys.
725 */ 724 */
726 if (optr == 1 && (error = xfs_inobt_updkey(cur, &key, level + 1))) 725 if (optr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, level + 1)))
727 return error; 726 return error;
728 /* 727 /*
729 * Return the new block number, if any. 728 * Return the new block number, if any.
@@ -960,7 +959,7 @@ xfs_inobt_lshift(
960 /* 959 /*
961 * Update the parent key values of right. 960 * Update the parent key values of right.
962 */ 961 */
963 if ((error = xfs_inobt_updkey(cur, rkp, level + 1))) 962 if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)rkp, level + 1)))
964 return error; 963 return error;
965 /* 964 /*
966 * Slide the cursor value left one. 965 * Slide the cursor value left one.
@@ -1238,7 +1237,7 @@ xfs_inobt_rshift(
1238 return error; 1237 return error;
1239 xfs_btree_lastrec(tcur, level); 1238 xfs_btree_lastrec(tcur, level);
1240 if ((error = xfs_btree_increment(tcur, level, &i)) || 1239 if ((error = xfs_btree_increment(tcur, level, &i)) ||
1241 (error = xfs_inobt_updkey(tcur, rkp, level + 1))) { 1240 (error = xfs_btree_updkey(tcur, (union xfs_btree_key *)rkp, level + 1))) {
1242 xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR); 1241 xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR);
1243 return error; 1242 return error;
1244 } 1243 }
@@ -1407,45 +1406,6 @@ xfs_inobt_split(
1407} 1406}
1408 1407
1409/* 1408/*
1410 * Update keys at all levels from here to the root along the cursor's path.
1411 */
1412STATIC int /* error */
1413xfs_inobt_updkey(
1414 xfs_btree_cur_t *cur, /* btree cursor */
1415 xfs_inobt_key_t *keyp, /* new key value to update to */
1416 int level) /* starting level for update */
1417{
1418 int ptr; /* index of key in block */
1419
1420 /*
1421 * Go up the tree from this level toward the root.
1422 * At each level, update the key value to the value input.
1423 * Stop when we reach a level where the cursor isn't pointing
1424 * at the first entry in the block.
1425 */
1426 for (ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) {
1427 xfs_buf_t *bp; /* buffer for block */
1428 xfs_inobt_block_t *block; /* btree block */
1429#ifdef DEBUG
1430 int error; /* error return value */
1431#endif
1432 xfs_inobt_key_t *kp; /* ptr to btree block keys */
1433
1434 bp = cur->bc_bufs[level];
1435 block = XFS_BUF_TO_INOBT_BLOCK(bp);
1436#ifdef DEBUG
1437 if ((error = xfs_btree_check_sblock(cur, block, level, bp)))
1438 return error;
1439#endif
1440 ptr = cur->bc_ptrs[level];
1441 kp = XFS_INOBT_KEY_ADDR(block, ptr, cur);
1442 *kp = *keyp;
1443 xfs_inobt_log_keys(cur, bp, ptr, ptr);
1444 }
1445 return 0;
1446}
1447
1448/*
1449 * Externally visible routines. 1409 * Externally visible routines.
1450 */ 1410 */
1451 1411
@@ -1637,7 +1597,7 @@ xfs_inobt_update(
1637 xfs_inobt_key_t key; /* key containing [ino] */ 1597 xfs_inobt_key_t key; /* key containing [ino] */
1638 1598
1639 key.ir_startino = cpu_to_be32(ino); 1599 key.ir_startino = cpu_to_be32(ino);
1640 if ((error = xfs_inobt_updkey(cur, &key, 1))) 1600 if ((error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, 1)))
1641 return error; 1601 return error;
1642 } 1602 }
1643 return 0; 1603 return 0;