Skip to content

Commit d1f27c6

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: do not check ram_bytes for non-compressed data extents
This patch reverts the following 3 commits: d0cc40d ("btrfs-progs: tests: add test case for ram_bytes detection and repair") 7313573 ("btrfs-progs: check: original, detect and repair ram_bytes mismatch") 97bf7a5 ("btrfs-progs: check: lowmem, detect and repair mismatched ram_bytes") The problem with the ram_bytes check is, kernel can handle it without any problem, and the original objective for this is to detect such problem as I immaturelly believe the problem is fixed. But it turns out to be incorrect and this check is already causing problems. Fix it by doing a full revert for now. Pull-request: #828 Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 322929e commit d1f27c6

File tree

5 files changed

+4
-200
lines changed

5 files changed

+4
-200
lines changed

check/main.c

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -493,33 +493,6 @@ static int device_record_compare(const struct rb_node *node1, const struct rb_no
493493
return 0;
494494
}
495495

496-
static int add_mismatch_ram_bytes_record(struct inode_record *inode_rec,
497-
struct btrfs_key *key)
498-
{
499-
struct mismatch_ram_bytes_record *record;
500-
501-
record = malloc(sizeof(*record));
502-
if (!record) {
503-
error_msg(ERROR_MSG_MEMORY, "mismatch ram bytes record");
504-
return -ENOMEM;
505-
}
506-
memcpy(&record->key, key, sizeof(*key));
507-
list_add_tail(&record->list, &inode_rec->mismatch_ram_bytes);
508-
return 0;
509-
}
510-
511-
static void free_mismatch_ram_bytes_records(struct inode_record *inode_rec)
512-
{
513-
if (!list_empty(&inode_rec->mismatch_ram_bytes)) {
514-
struct mismatch_ram_bytes_record *ram;
515-
516-
ram = list_entry(inode_rec->mismatch_ram_bytes.next,
517-
struct mismatch_ram_bytes_record, list);
518-
list_del(&ram->list);
519-
free(ram);
520-
}
521-
}
522-
523496
static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
524497
{
525498
struct inode_record *rec;
@@ -528,7 +501,6 @@ static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
528501
struct inode_backref *tmp;
529502
struct mismatch_dir_hash_record *hash_record;
530503
struct mismatch_dir_hash_record *new_record;
531-
struct mismatch_ram_bytes_record *ram_record;
532504
struct unaligned_extent_rec_t *src;
533505
struct unaligned_extent_rec_t *dst;
534506
struct rb_node *rb;
@@ -542,7 +514,6 @@ static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
542514
rec->refs = 1;
543515
INIT_LIST_HEAD(&rec->backrefs);
544516
INIT_LIST_HEAD(&rec->mismatch_dir_hash);
545-
INIT_LIST_HEAD(&rec->mismatch_ram_bytes);
546517
INIT_LIST_HEAD(&rec->unaligned_extent_recs);
547518
rec->holes = RB_ROOT;
548519

@@ -566,11 +537,6 @@ static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
566537
memcpy(&new_record, hash_record, size);
567538
list_add_tail(&new_record->list, &rec->mismatch_dir_hash);
568539
}
569-
list_for_each_entry(ram_record, &orig_rec->mismatch_ram_bytes, list) {
570-
ret = add_mismatch_ram_bytes_record(rec, &ram_record->key);
571-
if (ret < 0)
572-
goto cleanup;
573-
}
574540
list_for_each_entry(src, &orig_rec->unaligned_extent_recs, list) {
575541
size = sizeof(*src);
576542
dst = malloc(size);
@@ -612,7 +578,6 @@ static struct inode_record *clone_inode_rec(struct inode_record *orig_rec)
612578
free(hash_record);
613579
}
614580
}
615-
free_mismatch_ram_bytes_records(rec);
616581
if (!list_empty(&rec->unaligned_extent_recs))
617582
list_for_each_entry_safe(src, dst, &rec->unaligned_extent_recs,
618583
list) {
@@ -654,8 +619,6 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
654619
fprintf(stderr, ", odd file extent");
655620
if (errors & I_ERR_BAD_FILE_EXTENT)
656621
fprintf(stderr, ", bad file extent");
657-
if (errors & I_ERR_RAM_BYTES_MISMATCH)
658-
fprintf(stderr, ", bad ram bytes for non-compressed extents");
659622
if (errors & I_ERR_FILE_EXTENT_OVERLAP)
660623
fprintf(stderr, ", file extent overlap");
661624
if (errors & I_ERR_FILE_EXTENT_TOO_LARGE)
@@ -674,6 +637,8 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
674637
fprintf(stderr, ", link count wrong");
675638
if (errors & I_ERR_ODD_INODE_FLAGS)
676639
fprintf(stderr, ", odd inode flags");
640+
if (errors & I_ERR_INLINE_RAM_BYTES_WRONG)
641+
fprintf(stderr, ", invalid inline ram bytes");
677642
if (errors & I_ERR_INVALID_IMODE)
678643
fprintf(stderr, ", invalid inode mode bit 0%o",
679644
rec->imode & ~07777);
@@ -734,17 +699,6 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
734699
hash_record->key.offset);
735700
}
736701
}
737-
if (errors & I_ERR_RAM_BYTES_MISMATCH) {
738-
struct mismatch_ram_bytes_record *ram_record;
739-
740-
fprintf(stderr,
741-
"Non-compressed file extents with invalid ram_bytes (minor errors):\n");
742-
list_for_each_entry(ram_record, &rec->mismatch_ram_bytes, list) {
743-
fprintf(stderr, "\tino=%llu offset=%llu\n",
744-
ram_record->key.objectid,
745-
ram_record->key.offset);
746-
}
747-
}
748702
}
749703

750704
static void print_ref_error(int errors)
@@ -806,7 +760,6 @@ static struct inode_record *get_inode_rec(struct cache_tree *inode_cache,
806760
rec->refs = 1;
807761
INIT_LIST_HEAD(&rec->backrefs);
808762
INIT_LIST_HEAD(&rec->mismatch_dir_hash);
809-
INIT_LIST_HEAD(&rec->mismatch_ram_bytes);
810763
INIT_LIST_HEAD(&rec->unaligned_extent_recs);
811764
rec->holes = RB_ROOT;
812765

@@ -858,14 +811,6 @@ static void free_inode_rec(struct inode_record *rec)
858811
list_del(&backref->list);
859812
free(backref);
860813
}
861-
while (!list_empty(&rec->mismatch_ram_bytes)) {
862-
struct mismatch_ram_bytes_record *ram;
863-
864-
ram = list_entry(rec->mismatch_ram_bytes.next,
865-
struct mismatch_ram_bytes_record, list);
866-
list_del(&ram->list);
867-
free(ram);
868-
}
869814
list_for_each_entry_safe(hash, next, &rec->mismatch_dir_hash, list)
870815
free(hash);
871816
free_unaligned_extent_recs(&rec->unaligned_extent_recs);
@@ -876,8 +821,7 @@ static void free_inode_rec(struct inode_record *rec)
876821
static bool can_free_inode_rec(struct inode_record *rec)
877822
{
878823
if (!rec->errors && rec->checked && rec->found_inode_item &&
879-
rec->nlink == rec->found_link && list_empty(&rec->backrefs) &&
880-
list_empty(&rec->mismatch_ram_bytes))
824+
rec->nlink == rec->found_link && list_empty(&rec->backrefs))
881825
return true;
882826
return false;
883827
}
@@ -1798,14 +1742,6 @@ static int process_file_extent(struct btrfs_root *root,
17981742
rec->errors |= I_ERR_BAD_FILE_EXTENT;
17991743
if (compression && rec->nodatasum)
18001744
rec->errors |= I_ERR_BAD_FILE_EXTENT;
1801-
if (disk_bytenr && !compression &&
1802-
btrfs_file_extent_ram_bytes(eb, fi) !=
1803-
btrfs_file_extent_disk_num_bytes(eb, fi)) {
1804-
rec->errors |= I_ERR_RAM_BYTES_MISMATCH;
1805-
ret = add_mismatch_ram_bytes_record(rec, key);
1806-
if (ret < 0)
1807-
return ret;
1808-
}
18091745
if (disk_bytenr > 0)
18101746
rec->found_size += num_bytes;
18111747
} else {
@@ -3076,57 +3012,6 @@ static int repair_inode_gen_original(struct btrfs_trans_handle *trans,
30763012
return 0;
30773013
}
30783014

3079-
static int repair_ram_bytes(struct btrfs_trans_handle *trans,
3080-
struct btrfs_root *root,
3081-
struct btrfs_path *path,
3082-
struct inode_record *rec)
3083-
{
3084-
struct mismatch_ram_bytes_record *record;
3085-
struct mismatch_ram_bytes_record *tmp;
3086-
int ret = 0;
3087-
3088-
btrfs_release_path(path);
3089-
list_for_each_entry_safe(record, tmp, &rec->mismatch_ram_bytes, list) {
3090-
struct btrfs_file_extent_item *fi;
3091-
struct extent_buffer *leaf;
3092-
int type;
3093-
int slot;
3094-
int search_ret;
3095-
3096-
search_ret = btrfs_search_slot(trans, root, &record->key, path, 0, 1);
3097-
if (search_ret > 0)
3098-
search_ret = -ENOENT;
3099-
if (search_ret < 0) {
3100-
ret = search_ret;
3101-
btrfs_release_path(path);
3102-
continue;
3103-
}
3104-
leaf = path->nodes[0];
3105-
slot = path->slots[0];
3106-
fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
3107-
type = btrfs_file_extent_type(leaf, fi);
3108-
if (type != BTRFS_FILE_EXTENT_REG &&
3109-
type != BTRFS_FILE_EXTENT_PREALLOC) {
3110-
ret = -EUCLEAN;
3111-
btrfs_release_path(path);
3112-
continue;
3113-
}
3114-
if (btrfs_file_extent_disk_bytenr(path->nodes[0], fi) == 0 ||
3115-
btrfs_file_extent_compression(path->nodes[0], fi)) {
3116-
ret = -EUCLEAN;
3117-
btrfs_release_path(path);
3118-
continue;
3119-
}
3120-
btrfs_set_file_extent_ram_bytes(leaf, fi,
3121-
btrfs_file_extent_disk_num_bytes(leaf, fi));
3122-
btrfs_mark_buffer_dirty(leaf);
3123-
btrfs_release_path(path);
3124-
}
3125-
if (!ret)
3126-
rec->errors &= ~I_ERR_RAM_BYTES_MISMATCH;
3127-
return ret;
3128-
}
3129-
31303015
static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
31313016
{
31323017
struct btrfs_trans_handle *trans;
@@ -3149,8 +3034,7 @@ static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
31493034
I_ERR_MISMATCH_DIR_HASH |
31503035
I_ERR_UNALIGNED_EXTENT_REC |
31513036
I_ERR_INVALID_IMODE |
3152-
I_ERR_INVALID_GEN |
3153-
I_ERR_RAM_BYTES_MISMATCH)))
3037+
I_ERR_INVALID_GEN)))
31543038
return rec->errors;
31553039

31563040
/*
@@ -3190,8 +3074,6 @@ static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
31903074
ret = repair_unaligned_extent_recs(trans, root, &path, rec);
31913075
if (!ret && rec->errors & I_ERR_INVALID_GEN)
31923076
ret = repair_inode_gen_original(trans, root, &path, rec);
3193-
if (!ret && rec->errors & I_ERR_RAM_BYTES_MISMATCH)
3194-
ret = repair_ram_bytes(trans, root, &path, rec);
31953077
btrfs_commit_transaction(trans, root);
31963078
btrfs_release_path(&path);
31973079
return ret;

check/mode-lowmem.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,61 +2018,6 @@ static int check_file_extent_inline(struct btrfs_root *root,
20182018
return err;
20192019
}
20202020

2021-
static int repair_ram_bytes_mismatch(struct btrfs_root *root,
2022-
struct btrfs_path *path)
2023-
{
2024-
struct btrfs_trans_handle *trans;
2025-
struct btrfs_key key;
2026-
struct btrfs_file_extent_item *fi;
2027-
u64 disk_num_bytes;
2028-
int recover_ret;
2029-
int ret;
2030-
2031-
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
2032-
btrfs_release_path(path);
2033-
UASSERT(key.type == BTRFS_EXTENT_DATA_KEY);
2034-
2035-
trans = btrfs_start_transaction(root, 1);
2036-
if (IS_ERR(trans)) {
2037-
ret = PTR_ERR(trans);
2038-
errno = -ret;
2039-
error_msg(ERROR_MSG_START_TRANS, "%m");
2040-
return ret;
2041-
}
2042-
2043-
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
2044-
/* Not really possible. */
2045-
if (ret > 0) {
2046-
ret = -ENOENT;
2047-
btrfs_release_path(path);
2048-
goto recover;
2049-
}
2050-
2051-
if (ret < 0)
2052-
goto recover;
2053-
2054-
fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
2055-
struct btrfs_file_extent_item);
2056-
disk_num_bytes = btrfs_file_extent_disk_num_bytes(path->nodes[0], fi);
2057-
btrfs_set_file_extent_ram_bytes(path->nodes[0], fi, disk_num_bytes);
2058-
btrfs_mark_buffer_dirty(path->nodes[0]);
2059-
2060-
ret = btrfs_commit_transaction(trans, root);
2061-
if (ret < 0) {
2062-
errno = -ret;
2063-
error_msg(ERROR_MSG_COMMIT_TRANS, "%m");
2064-
} else {
2065-
printf(
2066-
"Successfully repaired ram_bytes for non-compressed extent at root %llu ino %llu file_pos %llu\n",
2067-
root->objectid, key.objectid, key.offset);
2068-
}
2069-
return ret;
2070-
recover:
2071-
recover_ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
2072-
UASSERT(recover_ret == 0);
2073-
return ret;
2074-
}
2075-
20762021
/*
20772022
* Check file extent datasum/hole, update the size of the file extents,
20782023
* check and update the last offset of the file extent.
@@ -2098,7 +2043,6 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
20982043
u64 csum_found; /* In byte size, sectorsize aligned */
20992044
u64 search_start; /* Logical range start we search for csum */
21002045
u64 search_len; /* Logical range len we search for csum */
2101-
u64 ram_bytes;
21022046
u64 gen;
21032047
u64 super_gen;
21042048
unsigned int extent_type;
@@ -2133,7 +2077,6 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
21332077
extent_num_bytes = btrfs_file_extent_num_bytes(node, fi);
21342078
extent_offset = btrfs_file_extent_offset(node, fi);
21352079
compressed = btrfs_file_extent_compression(node, fi);
2136-
ram_bytes = btrfs_file_extent_ram_bytes(node, fi);
21372080
is_hole = (disk_bytenr == 0) && (disk_num_bytes == 0);
21382081
super_gen = btrfs_super_generation(gfs_info->super_copy);
21392082

@@ -2144,18 +2087,6 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
21442087
err |= INVALID_GENERATION;
21452088
}
21462089

2147-
if (!compressed && disk_bytenr && disk_num_bytes != ram_bytes) {
2148-
error(
2149-
"minor ram_bytes mismatch for non-compressed data extents, have %llu expect %llu",
2150-
ram_bytes, disk_num_bytes);
2151-
if (opt_check_repair) {
2152-
ret = repair_ram_bytes_mismatch(root, path);
2153-
if (ret < 0)
2154-
err |= RAM_BYTES_MISMATCH;
2155-
} else {
2156-
err |= RAM_BYTES_MISMATCH;
2157-
}
2158-
}
21592090
/*
21602091
* Check EXTENT_DATA csum
21612092
*

check/mode-lowmem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#define INODE_MODE_ERROR (1U << 25) /* Bad inode mode */
4848
#define INVALID_GENERATION (1U << 26) /* Generation is too new */
4949
#define SUPER_BYTES_USED_ERROR (1U << 27) /* Super bytes_used is invalid */
50-
#define RAM_BYTES_MISMATCH (1U << 27) /* Non-compressed extent has wrong ram_bytes */
5150

5251
/*
5352
* Error bit for low memory mode check.

check/mode-original.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ struct unaligned_extent_rec_t {
189189
#define I_ERR_INVALID_GEN (1U << 20)
190190
#define I_ERR_INVALID_NLINK (1U << 21)
191191
#define I_ERR_INVALID_XATTR (1U << 22)
192-
/* Ram_bytes mismatch for non-compressed data extents. */
193-
#define I_ERR_RAM_BYTES_MISMATCH (1U << 23)
194192

195193
struct inode_record {
196194
struct list_head backrefs;
@@ -218,7 +216,6 @@ struct inode_record {
218216
u64 extent_end;
219217
struct rb_root holes;
220218
struct list_head mismatch_dir_hash;
221-
struct list_head mismatch_ram_bytes;
222219

223220
u32 refs;
224221
};
@@ -235,11 +232,6 @@ struct mismatch_dir_hash_record {
235232
/* namebuf follows here */
236233
};
237234

238-
struct mismatch_ram_bytes_record {
239-
struct list_head list;
240-
struct btrfs_key key;
241-
};
242-
243235
struct root_backref {
244236
struct list_head list;
245237
unsigned int found_dir_item:1;
Binary file not shown.

0 commit comments

Comments
 (0)