@@ -20,6 +20,11 @@
#include "rmap.h"
#include "bload.h"
+struct lost_fsb {
+ xfs_fsblock_t fsbno;
+ xfs_extlen_t len;
+};
+
struct bt_rebuild {
struct xrep_newbt newbt;
struct xfs_btree_bload bload;
@@ -301,21 +306,24 @@ static void
finish_rebuild(
struct xfs_mount *mp,
struct bt_rebuild *btr,
- struct xfs_slab *lost_fsb)
+ struct xfs_slab *lost_fsbs)
{
struct xrep_newbt_resv *resv, *n;
for_each_xrep_newbt_reservation(&btr->newbt, resv, n) {
- while (resv->used < resv->len) {
- xfs_fsblock_t fsb = resv->fsbno + resv->used;
- int error;
+ struct lost_fsb lost;
+ int error;
- error = slab_add(lost_fsb, &fsb);
- if (error)
- do_error(
+ if (resv->used == resv->len)
+ continue;
+
+ lost.fsbno = resv->fsbno + resv->used;
+ lost.len = resv->len - resv->used;
+ error = slab_add(lost_fsbs, &lost);
+ if (error)
+ do_error(
_("Insufficient memory saving lost blocks.\n"));
- resv->used++;
- }
+ resv->used = resv->len;
}
xrep_newbt_destroy(&btr->newbt, 0);
@@ -1039,7 +1047,7 @@ build_agf_agfl(
int lostblocks, /* # blocks that will be lost */
struct bt_rebuild *btr_rmap,
struct bt_rebuild *btr_refcount,
- struct xfs_slab *lost_fsb)
+ struct xfs_slab *lost_fsbs)
{
struct extent_tree_node *ext_ptr;
struct xfs_buf *agf_buf, *agfl_buf;
@@ -1238,7 +1246,7 @@ static void
phase5_func(
struct xfs_mount *mp,
xfs_agnumber_t agno,
- struct xfs_slab *lost_fsb)
+ struct xfs_slab *lost_fsbs)
{
struct repair_ctx sc = { .mp = mp, };
struct agi_stat agi_stat = {0,};
@@ -1373,7 +1381,7 @@ phase5_func(
* set up agf and agfl
*/
build_agf_agfl(mp, agno, &btr_bno, &btr_cnt, freeblks1, extra_blocks,
- &btr_rmap, &btr_refcount, lost_fsb);
+ &btr_rmap, &btr_refcount, lost_fsbs);
/*
* build inode allocation trees.
@@ -1388,15 +1396,15 @@ phase5_func(
/*
* tear down cursors
*/
- finish_rebuild(mp, &btr_bno, lost_fsb);
- finish_rebuild(mp, &btr_cnt, lost_fsb);
- finish_rebuild(mp, &btr_ino, lost_fsb);
+ finish_rebuild(mp, &btr_bno, lost_fsbs);
+ finish_rebuild(mp, &btr_cnt, lost_fsbs);
+ finish_rebuild(mp, &btr_ino, lost_fsbs);
if (xfs_sb_version_hasfinobt(&mp->m_sb))
- finish_rebuild(mp, &btr_fino, lost_fsb);
+ finish_rebuild(mp, &btr_fino, lost_fsbs);
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
- finish_rebuild(mp, &btr_rmap, lost_fsb);
+ finish_rebuild(mp, &btr_rmap, lost_fsbs);
if (xfs_sb_version_hasreflink(&mp->m_sb))
- finish_rebuild(mp, &btr_refcount, lost_fsb);
+ finish_rebuild(mp, &btr_refcount, lost_fsbs);
/*
* release the incore per-AG bno/bcnt trees so
@@ -1416,19 +1424,19 @@ inject_lost_blocks(
{
struct xfs_trans *tp = NULL;
struct xfs_slab_cursor *cur = NULL;
- xfs_fsblock_t *fsb;
+ struct lost_fsb *lost;
int error;
error = init_slab_cursor(lost_fsbs, NULL, &cur);
if (error)
return error;
- while ((fsb = pop_slab_cursor(cur)) != NULL) {
+ while ((lost = pop_slab_cursor(cur)) != NULL) {
error = -libxfs_trans_alloc_rollable(mp, 16, &tp);
if (error)
goto out_cancel;
- error = -libxfs_free_extent(tp, *fsb, 1,
+ error = -libxfs_free_extent(tp, lost->fsbno, lost->len,
&XFS_RMAP_OINFO_ANY_OWNER, XFS_AG_RESV_NONE);
if (error)
goto out_cancel;
@@ -1449,7 +1457,7 @@ inject_lost_blocks(
void
phase5(xfs_mount_t *mp)
{
- struct xfs_slab *lost_fsb;
+ struct xfs_slab *lost_fsbs;
xfs_agnumber_t agno;
int error;
@@ -1492,12 +1500,12 @@ phase5(xfs_mount_t *mp)
if (sb_fdblocks_ag == NULL)
do_error(_("cannot alloc sb_fdblocks_ag buffers\n"));
- error = init_slab(&lost_fsb, sizeof(xfs_fsblock_t));
+ error = init_slab(&lost_fsbs, sizeof(struct lost_fsb));
if (error)
do_error(_("cannot alloc lost block slab\n"));
for (agno = 0; agno < mp->m_sb.sb_agcount; agno++)
- phase5_func(mp, agno, lost_fsb);
+ phase5_func(mp, agno, lost_fsbs);
print_final_rpt();
@@ -1540,10 +1548,10 @@ _("unable to add AG %u reverse-mapping data to btree.\n"), agno);
* Put blocks that were unnecessarily reserved for btree
* reconstruction back into the filesystem free space data.
*/
- error = inject_lost_blocks(mp, lost_fsb);
+ error = inject_lost_blocks(mp, lost_fsbs);
if (error)
do_error(_("Unable to reinsert lost blocks into filesystem.\n"));
- free_slab(&lost_fsb);
+ free_slab(&lost_fsbs);
bad_ino_btree = 0;