unsigned int is_root:1;
unsigned int metadata:1;
unsigned int bad_full_backref:1;
+ unsigned int crossing_stripes:1;
};
struct inode_backref {
if (errors & I_ERR_FILE_EXTENT_DISCOUNT) {
struct file_extent_hole *hole;
struct rb_node *node;
+ int found = 0;
node = rb_first(&rec->holes);
fprintf(stderr, "Found file extent holes:\n");
while (node) {
+ found = 1;
hole = rb_entry(node, struct file_extent_hole, node);
- fprintf(stderr, "\tstart: %llu, len:%llu\n",
+ fprintf(stderr, "\tstart: %llu, len: %llu\n",
hole->start, hole->len);
node = rb_next(node);
}
+ if (!found)
+ fprintf(stderr, "\tstart: 0, len: %llu\n",
+ round_up(rec->isize, root->sectorsize));
}
}
return ret;
}
+static int repair_inode_nbytes(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_path *path,
+ struct inode_record *rec)
+{
+ struct btrfs_inode_item *ei;
+ struct btrfs_key key;
+ int ret = 0;
+
+ key.objectid = rec->ino;
+ key.type = BTRFS_INODE_ITEM_KEY;
+ key.offset = 0;
+
+ ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
+ if (ret) {
+ if (ret > 0)
+ ret = -ENOENT;
+ goto out;
+ }
+
+ /* Since ret == 0, no need to check anything */
+ ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
+ struct btrfs_inode_item);
+ btrfs_set_inode_nbytes(path->nodes[0], ei, rec->found_size);
+ btrfs_mark_buffer_dirty(path->nodes[0]);
+ rec->errors &= ~I_ERR_FILE_NBYTES_WRONG;
+ printf("reset nbytes for ino %llu root %llu\n",
+ rec->ino, root->root_key.objectid);
+out:
+ btrfs_release_path(path);
+ return ret;
+}
+
static int add_missing_dir_index(struct btrfs_root *root,
struct cache_tree *inode_cache,
struct inode_record *rec,
BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino,
mode);
if (ret < 0) {
- fprintf(stderr, "Failed to create '%s' dir: %s",
+ fprintf(stderr, "Failed to create '%s' dir: %s\n",
dir_name, strerror(-ret));
goto out;
}
}
if (ret < 0) {
fprintf(stderr,
- "Failed to link the inode %llu to %s dir: %s",
+ "Failed to link the inode %llu to %s dir: %s\n",
rec->ino, dir_name, strerror(-ret));
goto out;
}
{
struct rb_node *node;
struct file_extent_hole *hole;
+ int found = 0;
int ret = 0;
node = rb_first(&rec->holes);
while (node) {
+ found = 1;
hole = rb_entry(node, struct file_extent_hole, node);
ret = btrfs_punch_hole(trans, root, rec->ino,
hole->start, hole->len);
rec->errors &= ~I_ERR_FILE_EXTENT_DISCOUNT;
node = rb_first(&rec->holes);
}
+ /* special case for a file losing all its file extent */
+ if (!found) {
+ ret = btrfs_punch_hole(trans, root, rec->ino, 0,
+ round_up(rec->isize, root->sectorsize));
+ if (ret < 0)
+ goto out;
+ }
printf("Fixed discount file extents for inode: %llu in root: %llu\n",
rec->ino, root->objectid);
out:
I_ERR_LINK_COUNT_WRONG |
I_ERR_NO_INODE_ITEM |
I_ERR_FILE_EXTENT_ORPHAN |
- I_ERR_FILE_EXTENT_DISCOUNT)))
+ I_ERR_FILE_EXTENT_DISCOUNT|
+ I_ERR_FILE_NBYTES_WRONG)))
return rec->errors;
path = btrfs_alloc_path();
ret = repair_inode_orphan_item(trans, root, path, rec);
if (!ret && rec->errors & I_ERR_LINK_COUNT_WRONG)
ret = repair_inode_nlinks(trans, root, path, rec);
+ if (!ret && rec->errors & I_ERR_FILE_NBYTES_WRONG)
+ ret = repair_inode_nbytes(trans, root, path, rec);
btrfs_commit_transaction(trans, root);
btrfs_free_path(path);
return ret;
if (rec->content_checked && rec->owner_ref_checked &&
rec->extent_item_refs == rec->refs && rec->refs > 0 &&
rec->num_duplicates == 0 && !all_backpointers_checked(rec, 0) &&
- !rec->bad_full_backref) {
+ !rec->bad_full_backref && !rec->crossing_stripes) {
remove_cache_extent(extent_cache, &rec->cache);
free_all_extent_backrefs(rec);
list_del_init(&rec->list);
if (rec->max_size < max_size)
rec->max_size = max_size;
+ /*
+ * A metadata extent can't cross stripe_len boundary, otherwise
+ * kernel scrub won't be able to handle it.
+ * As now stripe_len is fixed to BTRFS_STRIPE_LEN, just check
+ * it.
+ */
+ if (metadata && check_crossing_stripes(rec->start,
+ rec->max_size))
+ rec->crossing_stripes = 1;
maybe_free_extent_rec(extent_cache, rec);
return ret;
}
rec->metadata = metadata;
rec->flag_block_full_backref = -1;
rec->bad_full_backref = 0;
+ rec->crossing_stripes = 0;
INIT_LIST_HEAD(&rec->backrefs);
INIT_LIST_HEAD(&rec->dups);
INIT_LIST_HEAD(&rec->list);
rec->content_checked = 1;
rec->owner_ref_checked = 1;
}
+
+ if (metadata)
+ if (check_crossing_stripes(rec->start, rec->max_size))
+ rec->crossing_stripes = 1;
return ret;
}
err = 1;
cur_err = 1;
}
+ /*
+ * Although it's not a extent ref's problem, we reuse this
+ * routine for error reporting.
+ * No repair function yet.
+ */
+ if (rec->crossing_stripes) {
+ fprintf(stderr,
+ "bad metadata [%llu, %llu) crossing stripe boundary\n",
+ rec->start, rec->start + rec->max_size);
+ err = 1;
+ cur_err = 1;
+ }
remove_cache_extent(extent_cache, cache);
free_all_extent_backrefs(rec);
ret = 0;
out:
free_roots_info_cache();
- if (path)
- btrfs_free_path(path);
+ btrfs_free_path(path);
if (trans)
btrfs_commit_transaction(trans, info->tree_root);
if (ret < 0)
free_root_recs_tree(&root_cache);
close_out:
close_ctree(root);
+ btrfs_close_all_devices();
err_out:
return ret;
}