* Copyright (C) 2016 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <darrick.wong@oracle.com>
*/
-#include <libxfs.h>
+#include "libxfs.h"
#include "btree.h"
#include "err_protos.h"
#include "libxlog.h"
rmap_needs_work(
struct xfs_mount *mp)
{
- return xfs_sb_version_hasreflink(&mp->m_sb) ||
- xfs_sb_version_hasrmapbt(&mp->m_sb);
+ return xfs_has_reflink(mp) ||
+ xfs_has_rmapbt(mp);
}
/*
/* inodes */
ino_rec = findfirst_inode_rec(agno);
for (; ino_rec != NULL; ino_rec = next_ino_rec(ino_rec)) {
- if (xfs_sb_version_hassparseinodes(&mp->m_sb)) {
+ if (xfs_has_sparseinodes(mp)) {
startidx = find_first_zero_bit(ino_rec->ir_sparse);
nr = XFS_INODES_PER_CHUNK - popcnt(ino_rec->ir_sparse);
} else {
struct bitmap *own_ag_bitmap = NULL;
int error = 0;
- if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
+ if (!xfs_has_rmapbt(mp))
return 0;
/* Release the ar_rmaps; they were put into the rmapbt during p5. */
error = init_slab_cursor(ag_rmap->ar_raw_rmaps, rmap_compare, &rm_cur);
if (error)
goto err;
- error = -bitmap_init(&own_ag_bitmap);
+ error = -bitmap_alloc(&own_ag_bitmap);
if (error)
goto err_slab;
while ((rm_rec = pop_slab_cursor(rm_cur)) != NULL) {
free_slab_cursor(&rm_cur);
/* Create rmaps for any AGFL blocks that aren't already rmapped. */
- agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agflbp);
+ agfl_bno = xfs_buf_to_agfl_bno(agflbp);
b = agfl_bno + ag_rmap->ar_flcount;
while (*b != cpu_to_be32(NULLAGBLOCK) &&
b - agfl_bno < libxfs_agfl_size(mp)) {
}
b++;
}
- libxfs_putbuf(agflbp);
+ libxfs_buf_relse(agflbp);
agflbp = NULL;
bitmap_free(&own_ag_bitmap);
rm_rec = pop_slab_cursor(rm_cur);
while (rm_rec) {
struct xfs_owner_info oinfo = {};
+ struct xfs_perag *pag;
error = -libxfs_trans_alloc_rollable(mp, 16, &tp);
if (error)
ASSERT(XFS_RMAP_NON_INODE_OWNER(rm_rec->rm_owner));
oinfo.oi_owner = rm_rec->rm_owner;
- error = -libxfs_rmap_alloc(tp, agbp, agno, rm_rec->rm_startblock,
+ pag = libxfs_perag_get(mp, agno);
+ error = -libxfs_rmap_alloc(tp, agbp, pag, rm_rec->rm_startblock,
rm_rec->rm_blockcount, &oinfo);
+ libxfs_perag_put(pag);
if (error)
goto err_trans;
free_slab_cursor(&rm_cur);
err:
if (agflbp)
- libxfs_putbuf(agflbp);
+ libxfs_buf_relse(agflbp);
if (own_ag_bitmap)
bitmap_free(&own_ag_bitmap);
return error;
size_t old_stack_nr;
int error;
- if (!xfs_sb_version_hasreflink(&mp->m_sb))
+ if (!xfs_has_reflink(mp))
return 0;
rmaps = ag_rmaps[agno].ar_rmaps;
struct xfs_rmap_irec *tmp,
int *have)
{
- int error;
-
/* Use the regular btree retrieval routine. */
- error = -libxfs_rmap_lookup_le(bt_cur, rm_rec->rm_startblock,
- rm_rec->rm_blockcount,
+ return -libxfs_rmap_lookup_le(bt_cur, rm_rec->rm_startblock,
rm_rec->rm_owner, rm_rec->rm_offset,
- rm_rec->rm_flags, have);
- if (error)
- return error;
- if (*have == 0)
- return error;
- return -libxfs_rmap_get_rec(bt_cur, tmp, have);
+ rm_rec->rm_flags, tmp, have);
}
/* Look for an rmap in the rmapbt that matches a given rmap. */
/*
* Compare the observed reverse mappings against what's in the ag btree.
*/
-int
+void
rmaps_verify_btree(
struct xfs_mount *mp,
xfs_agnumber_t agno)
{
+ struct xfs_rmap_irec tmp;
struct xfs_slab_cursor *rm_cur;
struct xfs_btree_cur *bt_cur = NULL;
- int error;
- int have;
struct xfs_buf *agbp = NULL;
struct xfs_rmap_irec *rm_rec;
- struct xfs_rmap_irec tmp;
- struct xfs_perag *pag; /* per allocation group data */
+ struct xfs_perag *pag = NULL;
+ int have;
+ int error;
- if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
- return 0;
+ if (!xfs_has_rmapbt(mp))
+ return;
if (rmapbt_suspect) {
if (no_modify && agno == 0)
do_warn(_("would rebuild corrupt rmap btrees.\n"));
- return 0;
+ return;
}
/* Create cursors to refcount structures */
error = rmap_init_cursor(agno, &rm_cur);
- if (error)
- return error;
+ if (error) {
+ do_warn(_("Not enough memory to check reverse mappings.\n"));
+ return;
+ }
error = -libxfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
- if (error)
+ if (error) {
+ do_warn(_("Could not read AGF %u to check rmap btree.\n"),
+ agno);
goto err;
+ }
/* Leave the per-ag data "uninitialized" since we rewrite it later */
pag = libxfs_perag_get(mp, agno);
pag->pagf_init = 0;
- libxfs_perag_put(pag);
- bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
+ bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, pag);
if (!bt_cur) {
- error = -ENOMEM;
+ do_warn(_("Not enough memory to check reverse mappings.\n"));
goto err;
}
rm_rec = pop_slab_cursor(rm_cur);
while (rm_rec) {
error = rmap_lookup(bt_cur, rm_rec, &tmp, &have);
- if (error)
+ if (error) {
+ do_warn(
+_("Could not read reverse-mapping record for (%u/%u).\n"),
+ agno, rm_rec->rm_startblock);
goto err;
+ }
+
/*
* Using the range query is expensive, so only do it if
* the regular lookup doesn't find anything or if it doesn't
* match the observed rmap.
*/
- if (xfs_sb_version_hasreflink(&bt_cur->bc_mp->m_sb) &&
+ if (xfs_has_reflink(bt_cur->bc_mp) &&
(!have || !rmap_is_good(rm_rec, &tmp))) {
error = rmap_lookup_overlapped(bt_cur, rm_rec,
&tmp, &have);
- if (error)
+ if (error) {
+ do_warn(
+_("Could not read reverse-mapping record for (%u/%u).\n"),
+ agno, rm_rec->rm_startblock);
goto err;
+ }
}
if (!have) {
do_warn(
err:
if (bt_cur)
libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
+ if (pag)
+ libxfs_perag_put(pag);
if (agbp)
- libxfs_putbuf(agbp);
+ libxfs_buf_relse(agbp);
free_slab_cursor(&rm_cur);
- return 0;
}
/*
else
dino->di_flags2 &= cpu_to_be64(~XFS_DIFLAG2_REFLINK);
libxfs_dinode_calc_crc(mp, dino);
- libxfs_writebuf(buf, 0);
+ libxfs_buf_mark_dirty(buf);
+ libxfs_buf_relse(buf);
return 0;
}
/*
* Compare the observed reference counts against what's in the ag btree.
*/
-int
+void
check_refcounts(
- struct xfs_mount *mp,
- xfs_agnumber_t agno)
+ struct xfs_mount *mp,
+ xfs_agnumber_t agno)
{
- struct xfs_slab_cursor *rl_cur;
- struct xfs_btree_cur *bt_cur = NULL;
- int error;
- int have;
- int i;
- struct xfs_buf *agbp = NULL;
- struct xfs_refcount_irec *rl_rec;
struct xfs_refcount_irec tmp;
- struct xfs_perag *pag; /* per allocation group data */
+ struct xfs_slab_cursor *rl_cur;
+ struct xfs_btree_cur *bt_cur = NULL;
+ struct xfs_buf *agbp = NULL;
+ struct xfs_perag *pag = NULL;
+ struct xfs_refcount_irec *rl_rec;
+ int have;
+ int i;
+ int error;
- if (!xfs_sb_version_hasreflink(&mp->m_sb))
- return 0;
+ if (!xfs_has_reflink(mp))
+ return;
if (refcbt_suspect) {
if (no_modify && agno == 0)
do_warn(_("would rebuild corrupt refcount btrees.\n"));
- return 0;
+ return;
}
/* Create cursors to refcount structures */
error = init_refcount_cursor(agno, &rl_cur);
- if (error)
- return error;
+ if (error) {
+ do_warn(_("Not enough memory to check refcount data.\n"));
+ return;
+ }
error = -libxfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
- if (error)
+ if (error) {
+ do_warn(_("Could not read AGF %u to check refcount btree.\n"),
+ agno);
goto err;
+ }
/* Leave the per-ag data "uninitialized" since we rewrite it later */
pag = libxfs_perag_get(mp, agno);
pag->pagf_init = 0;
- libxfs_perag_put(pag);
- bt_cur = libxfs_refcountbt_init_cursor(mp, NULL, agbp, agno);
+ bt_cur = libxfs_refcountbt_init_cursor(mp, NULL, agbp, pag);
if (!bt_cur) {
- error = -ENOMEM;
+ do_warn(_("Not enough memory to check refcount data.\n"));
goto err;
}
/* Look for a refcount record in the btree */
error = -libxfs_refcount_lookup_le(bt_cur,
rl_rec->rc_startblock, &have);
- if (error)
+ if (error) {
+ do_warn(
+_("Could not read reference count record for (%u/%u).\n"),
+ agno, rl_rec->rc_startblock);
goto err;
+ }
if (!have) {
do_warn(
_("Missing reference count record for (%u/%u) len %u count %u\n"),
}
error = -libxfs_refcount_get_rec(bt_cur, &tmp, &i);
- if (error)
+ if (error) {
+ do_warn(
+_("Could not read reference count record for (%u/%u).\n"),
+ agno, rl_rec->rc_startblock);
goto err;
+ }
if (!i) {
do_warn(
_("Missing reference count record for (%u/%u) len %u count %u\n"),
/* Compare each refcount observation against the btree's */
if (tmp.rc_startblock != rl_rec->rc_startblock ||
- tmp.rc_blockcount < rl_rec->rc_blockcount ||
- tmp.rc_refcount < rl_rec->rc_refcount)
+ tmp.rc_blockcount != rl_rec->rc_blockcount ||
+ tmp.rc_refcount != rl_rec->rc_refcount)
do_warn(
_("Incorrect reference count: saw (%u/%u) len %u nlinks %u; should be (%u/%u) len %u nlinks %u\n"),
agno, tmp.rc_startblock, tmp.rc_blockcount,
if (bt_cur)
libxfs_btree_del_cursor(bt_cur, error ? XFS_BTREE_ERROR :
XFS_BTREE_NOERROR);
+ if (pag)
+ libxfs_perag_put(pag);
if (agbp)
- libxfs_putbuf(agbp);
+ libxfs_buf_relse(agbp);
free_slab_cursor(&rl_cur);
- return 0;
}
/*