aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_bmap_btree.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2008-10-30 01:57:28 -0400
committerLachlan McIlroy <lachlan@sgi.com>2008-10-30 01:57:28 -0400
commitea77b0a66e6c910ef265d9af522d6303ea6b3055 (patch)
tree632039ecbbe4e0368f31c17cda5063155281b826 /fs/xfs/xfs_bmap_btree.c
parent344207ce8474b79be331eb93e6df4cb5bdd48ab2 (diff)
[XFS] move xfs_bmbt_newroot to common code
xfs_bmbt_newroot is a mostly generic implementation of moving from an inode root to a real block based root. So move it to xfs_btree.c where it can use all the nice infrastructure there and make it pointer size agnostic The new name for it is xfs_btree_new_iroot, following the old naming but making it clear we're dealing with the root in inode case here, and to avoid confusion with xfs_btree_new_root which is used for the not inode rooted case. SGI-PV: 985583 SGI-Modid: xfs-linux-melb:xfs-kern:32201a Signed-off-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Lachlan McIlroy <lachlan@sgi.com> Signed-off-by: Bill O'Donnell <billodo@sgi.com> Signed-off-by: David Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_bmap_btree.c')
-rw-r--r--fs/xfs/xfs_bmap_btree.c113
1 files changed, 1 insertions, 112 deletions
diff --git a/fs/xfs/xfs_bmap_btree.c b/fs/xfs/xfs_bmap_btree.c
index e7539263457f..204f276aeaad 100644
--- a/fs/xfs/xfs_bmap_btree.c
+++ b/fs/xfs/xfs_bmap_btree.c
@@ -525,7 +525,7 @@ xfs_bmbt_insrec(
525 cur->bc_private.b.whichfork); 525 cur->bc_private.b.whichfork);
526 block = xfs_bmbt_get_block(cur, level, &bp); 526 block = xfs_bmbt_get_block(cur, level, &bp);
527 } else if (level == cur->bc_nlevels - 1) { 527 } else if (level == cur->bc_nlevels - 1) {
528 if ((error = xfs_bmbt_newroot(cur, &logflags, stat)) || 528 if ((error = xfs_btree_new_iroot(cur, &logflags, stat)) ||
529 *stat == 0) { 529 *stat == 0) {
530 XFS_BMBT_TRACE_CURSOR(cur, ERROR); 530 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
531 return error; 531 return error;
@@ -1183,117 +1183,6 @@ xfs_bmbt_log_recs(
1183} 1183}
1184 1184
1185/* 1185/*
1186 * Give the bmap btree a new root block. Copy the old broot contents
1187 * down into a real block and make the broot point to it.
1188 */
1189int /* error */
1190xfs_bmbt_newroot(
1191 xfs_btree_cur_t *cur, /* btree cursor */
1192 int *logflags, /* logging flags for inode */
1193 int *stat) /* return status - 0 fail */
1194{
1195 xfs_alloc_arg_t args; /* allocation arguments */
1196 xfs_bmbt_block_t *block; /* bmap btree block */
1197 xfs_buf_t *bp; /* buffer for block */
1198 xfs_bmbt_block_t *cblock; /* child btree block */
1199 xfs_bmbt_key_t *ckp; /* child key pointer */
1200 xfs_bmbt_ptr_t *cpp; /* child ptr pointer */
1201 int error; /* error return code */
1202#ifdef DEBUG
1203 int i; /* loop counter */
1204#endif
1205 xfs_bmbt_key_t *kp; /* pointer to bmap btree key */
1206 int level; /* btree level */
1207 xfs_bmbt_ptr_t *pp; /* pointer to bmap block addr */
1208
1209 XFS_BMBT_TRACE_CURSOR(cur, ENTRY);
1210 level = cur->bc_nlevels - 1;
1211 block = xfs_bmbt_get_block(cur, level, &bp);
1212 /*
1213 * Copy the root into a real block.
1214 */
1215 args.mp = cur->bc_mp;
1216 pp = XFS_BMAP_PTR_IADDR(block, 1, cur);
1217 args.tp = cur->bc_tp;
1218 args.fsbno = cur->bc_private.b.firstblock;
1219 args.mod = args.minleft = args.alignment = args.total = args.isfl =
1220 args.userdata = args.minalignslop = 0;
1221 args.minlen = args.maxlen = args.prod = 1;
1222 args.wasdel = cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL;
1223 args.firstblock = args.fsbno;
1224 if (args.fsbno == NULLFSBLOCK) {
1225#ifdef DEBUG
1226 if ((error = xfs_btree_check_lptr_disk(cur, *pp, level))) {
1227 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
1228 return error;
1229 }
1230#endif
1231 args.fsbno = be64_to_cpu(*pp);
1232 args.type = XFS_ALLOCTYPE_START_BNO;
1233 } else if (cur->bc_private.b.flist->xbf_low)
1234 args.type = XFS_ALLOCTYPE_START_BNO;
1235 else
1236 args.type = XFS_ALLOCTYPE_NEAR_BNO;
1237 if ((error = xfs_alloc_vextent(&args))) {
1238 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
1239 return error;
1240 }
1241 if (args.fsbno == NULLFSBLOCK) {
1242 XFS_BMBT_TRACE_CURSOR(cur, EXIT);
1243 *stat = 0;
1244 return 0;
1245 }
1246 ASSERT(args.len == 1);
1247 cur->bc_private.b.firstblock = args.fsbno;
1248 cur->bc_private.b.allocated++;
1249 cur->bc_private.b.ip->i_d.di_nblocks++;
1250 XFS_TRANS_MOD_DQUOT_BYINO(args.mp, args.tp, cur->bc_private.b.ip,
1251 XFS_TRANS_DQ_BCOUNT, 1L);
1252 bp = xfs_btree_get_bufl(args.mp, cur->bc_tp, args.fsbno, 0);
1253 cblock = XFS_BUF_TO_BMBT_BLOCK(bp);
1254 *cblock = *block;
1255 be16_add_cpu(&block->bb_level, 1);
1256 block->bb_numrecs = cpu_to_be16(1);
1257 cur->bc_nlevels++;
1258 cur->bc_ptrs[level + 1] = 1;
1259 kp = XFS_BMAP_KEY_IADDR(block, 1, cur);
1260 ckp = XFS_BMAP_KEY_IADDR(cblock, 1, cur);
1261 memcpy(ckp, kp, be16_to_cpu(cblock->bb_numrecs) * sizeof(*kp));
1262 cpp = XFS_BMAP_PTR_IADDR(cblock, 1, cur);
1263#ifdef DEBUG
1264 for (i = 0; i < be16_to_cpu(cblock->bb_numrecs); i++) {
1265 if ((error = xfs_btree_check_lptr_disk(cur, pp[i], level))) {
1266 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
1267 return error;
1268 }
1269 }
1270#endif
1271 memcpy(cpp, pp, be16_to_cpu(cblock->bb_numrecs) * sizeof(*pp));
1272#ifdef DEBUG
1273 if ((error = xfs_btree_check_lptr(cur, args.fsbno, level))) {
1274 XFS_BMBT_TRACE_CURSOR(cur, ERROR);
1275 return error;
1276 }
1277#endif
1278 *pp = cpu_to_be64(args.fsbno);
1279 xfs_iroot_realloc(cur->bc_private.b.ip, 1 - be16_to_cpu(cblock->bb_numrecs),
1280 cur->bc_private.b.whichfork);
1281 xfs_btree_setbuf(cur, level, bp);
1282 /*
1283 * Do all this logging at the end so that
1284 * the root is at the right level.
1285 */
1286 xfs_bmbt_log_block(cur, bp, XFS_BB_ALL_BITS);
1287 xfs_bmbt_log_keys(cur, bp, 1, be16_to_cpu(cblock->bb_numrecs));
1288 xfs_bmbt_log_ptrs(cur, bp, 1, be16_to_cpu(cblock->bb_numrecs));
1289 XFS_BMBT_TRACE_CURSOR(cur, EXIT);
1290 *logflags |=
1291 XFS_ILOG_CORE | XFS_ILOG_FBROOT(cur->bc_private.b.whichfork);
1292 *stat = 1;
1293 return 0;
1294}
1295
1296/*
1297 * Set all the fields in a bmap extent record from the arguments. 1186 * Set all the fields in a bmap extent record from the arguments.
1298 */ 1187 */
1299void 1188void