Skip to contentSkip to conversation

Btrfs scrub: print path to corrupted files and trigger nodatasum fixup

PATCH Superseded Jan Schmidt 3 participants 17 messages Jul 22, 2011 – Jul 27, 2011 7 messages not in the archive Btrfs file system

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover Btrfs scrub: print path to corrupted files and trigger nodatasum fixup

Please ignore v6, was sent while only half way through :-(

Changelog v6->v7:
- include everything that was stated to be in v6

Changelog v5->v6:
- fixed ioctl priviledge and input sanity checking (reported by Andi Kleen)

Original message follows:
------------------------
This patch set introduces two new features for scrub. They share the backref iteration code which is the reason they made it into the same patch set.

The first feature adds printk statements in case scrub finds an error which list all affected files. You will need patch 1, 2 and 3 for that.

The second feature adds the trigger which enables us to correct i/o errors in case the affected extent does not have a checksum (nodatasum), eventually. You will need patch 1, 4, 5 and 6 for that.

I tried to apply all patches to the current cmason/for-linus branch and to Arne's current for-chris branch. They do apply with no errors (some offsets possible).

The new ioctl()s can be tested from usermode by applying the patch series
[PATCH v2 0/3] Btrfs-progs: add the first "inspect-internal" commands
from this mailing list to the user land tools.

Please review.

Next I'm starting to make up my mind how to implement on-the-fly error correction correctly. This will enable us to rewrite good data whenever we encounter a bad copy. I have some preliminary patches already, the stress in the first sentence is on "correctly". The second feature mentioned in this patch series will then automatically use that code, too.

Changelog v1->v2:
- Various cleanup, sensible error codes as suggested by David Sterba

Changelog v2->v3:
- evaluation and iteration of shared refs
- support for in-tree refs (v2 iterated inline refs only)
- never call an interator function without releasing the path
- iterate_irefs now returns -ENOENT in case no refs are found
- some stupid bugs removed where release_path was called too early
- ioctls added to provide new functions to user mode
- bugfixes for cases where search_slot found the very end of a leaf
- bugfix: use right fs root for readpage instead of fs_root->fs_info
- based on current cmason/for-linus

Changelog v3->v4:
- fixed a regression with mirror_num that could prevent error correction
- based on current cmason/for-linus

Changelog v4->v5:
- fixed a deadlock when fixup is taking longer while scrub is about to end

Please try it and report errors (or confirm there are none, of course). I can provide a place to pull from if anyone likes.

-Jan

Jan Schmidt (8):
btrfs: added helper functions to iterate backrefs btrfs scrub: added unverified_errors
btrfs scrub: print paths of corrupted files
btrfs scrub: bugfix: mirror_num off by one
btrfs: add mirror_num to extent_read_full_page
btrfs scrub: use int for mirror_num, not u64
btrfs scrub: add fixup code for errors on nodatasum files
btrfs: new ioctls to do logical->inode and inode->path resolving

 fs/btrfs/Makefile    |    3 +-
 fs/btrfs/backref.c   |  748 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/backref.h   |   62 +++++
 fs/btrfs/disk-io.c   |    2 +-
 fs/btrfs/extent_io.c |    6 +-
 fs/btrfs/extent_io.h |    3 +-
 fs/btrfs/inode.c     |    2 +-
 fs/btrfs/ioctl.c     |  150 ++++++++++
 fs/btrfs/ioctl.h     |   29 ++
 fs/btrfs/scrub.c     |  414 +++++++++++++++++++++++++---
 10 files changed, 1379 insertions(+), 40 deletions(-)
 create mode 100644 fs/btrfs/backref.c
 create mode 100644 fs/btrfs/backref.h
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH v7 1/8 btrfs: added helper functions to iterate backrefs

These helper functions iterate back references and call a function for each backref. There is also a function to resolve an inode to a path in the file system.

---
 fs/btrfs/Makefile  |    3 +-
 fs/btrfs/backref.c |  748 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/backref.h |   62 +++++
 fs/btrfs/ioctl.h   |   10 +
 4 files changed, 822 insertions(+), 1 deletions(-)
fs/btrfs/Makefile +2 -1
index 9b72dcf..c63f649 100644
@@ -7,4 +7,5 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
 	   extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
 	   extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
 	   export.o tree-log.o acl.o free-space-cache.o zlib.o lzo.o \
-	   compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o
+	   compression.o delayed-ref.o relocation.o delayed-inode.o backref.o \
+	   scrub.o
fs/btrfs/backref.c new file +748 -0

748 lines not on this page · raw message

fs/btrfs/backref.h new file +62 -0

62 lines not on this page · raw message

fs/btrfs/ioctl.h +10 -0
index ad1ea78..4afb60b 100644
@@ -193,6 +193,16 @@ struct btrfs_ioctl_space_args {
 	struct btrfs_ioctl_space_info spaces[0];
 };
 
+struct btrfs_data_container {
+	__s32	size;		/* out */
+	__u32	elem_cnt;	/* out */
+	__u32	elem_missed;	/* out */
+	union {
+		char	*str[0];	/* out */
+		__u64	val[0];		/* out */
+	};
+};
+
 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
 				   struct btrfs_ioctl_vol_args)
 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [PATCH v7 1/8] btrfs: added helper functions to iterate backrefs

fs/btrfs/backref.c line 704

Quoted 9 lines
fs/btrfs/backref.c new file +9 -0
+struct btrfs_data_container *init_data_container(s32 total_bytes)
+{
+	struct btrfs_data_container *data;
+	unsigned long alloc_bytes;
+
+	if (total_bytes < 0)
+		return ERR_PTR(-EINVAL);
+
+	alloc_bytes = max((unsigned long)total_bytes, sizeof(*data));

The return type of sizeof() is unsigned int, so this will cause compile warning.

We can use max_t() instead.

Quoted 10 lines
fs/btrfs/backref.c new file +10 -0
+	data = kmalloc(alloc_bytes, GFP_NOFS);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+
+	data->size = total_bytes - sizeof(*data);
+	data->elem_cnt = 0;
+	data->elem_missed = 0;
+
+	return data;
+}
#3 lore raw

Re: [PATCH v7 1/8] btrfs: added helper functions to iterate backrefs

Quoted 7 lines

fs/btrfs/backref.c line 704

Quoted 1 line
fs/btrfs/backref.c new file +1 -0
+	alloc_bytes = max((unsigned long)total_bytes, sizeof(*data));

The return type of sizeof() is unsigned int, so this will cause compile warning.

We can use max_t() instead.

correct: type of sizeof is size_t (so may or may not be unsigned long)

#4 lore raw

Re: [PATCH v7 1/8] btrfs: added helper functions to iterate backrefs

Quoted 9 lines · Li Zefan
Quoted 7 lines

fs/btrfs/backref.c line 704

Quoted 1 line
fs/btrfs/backref.c new file +1 -0
+	alloc_bytes = max((unsigned long)total_bytes, sizeof(*data));

The return type of sizeof() is unsigned int, so this will cause compile warning.

We can use max_t() instead.

correct: type of sizeof is size_t (so may or may not be unsigned long)

Right, thanks. Changed for the next version.

-Jan

#5 lore raw

PATCH v7 2/8 btrfs scrub: added unverified_errors

In reply to Jan Schmidt

In normal operation, scrub is reading data sequentially in large portions. In case of an i/o error, we try to find the corrupted area(s) by issuing page sized read requests. With this commit we increment the unverified_errors counter if all of the small size requests succeed.

Userland patches carrying such conspicous events to the administrator should already be around.

---
 fs/btrfs/scrub.c |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)
fs/btrfs/scrub.c +26 -11
index a8d03d5..35099fa 100644
@@ -201,18 +201,25 @@ nomem:
  * recheck_error gets called for every page in the bio, even though only
  * one may be bad
  */
-static void scrub_recheck_error(struct scrub_bio *sbio, int ix)
+static int scrub_recheck_error(struct scrub_bio *sbio, int ix)
 {
+	struct scrub_dev *sdev = sbio->sdev;
+	u64 sector = (sbio->physical + ix * PAGE_SIZE) >> 9;
+
 	if (sbio->err) {
-		if (scrub_fixup_io(READ, sbio->sdev->dev->bdev,
-				   (sbio->physical + ix * PAGE_SIZE) >> 9,
+		if (scrub_fixup_io(READ, sbio->sdev->dev->bdev, sector,
 				   sbio->bio->bi_io_vec[ix].bv_page) == 0) {
 			if (scrub_fixup_check(sbio, ix) == 0)
-				return;
+				return 0;
 		}
 	}
 
+	spin_lock(&sdev->stat_lock);
+	++sdev->stat.read_errors;
+	spin_unlock(&sdev->stat_lock);
+
 	scrub_fixup(sbio, ix);
+	return 1;
 }
 
 static int scrub_fixup_check(struct scrub_bio *sbio, int ix)
@@ -382,8 +389,14 @@ static void scrub_checksum(struct btrfs_work *work)
 	int ret;
 
 	if (sbio->err) {
+		ret = 0;
 		for (i = 0; i < sbio->count; ++i)
-			scrub_recheck_error(sbio, i);
+			ret |= scrub_recheck_error(sbio, i);
+		if (!ret) {
+			spin_lock(&sdev->stat_lock);
+			++sdev->stat.unverified_errors;
+			spin_unlock(&sdev->stat_lock);
+		}
 
 		sbio->bio->bi_flags &= ~(BIO_POOL_MASK - 1);
 		sbio->bio->bi_flags |= 1 << BIO_UPTODATE;
@@ -396,10 +409,6 @@ static void scrub_checksum(struct btrfs_work *work)
 			bi->bv_offset = 0;
 			bi->bv_len = PAGE_SIZE;
 		}
-
-		spin_lock(&sdev->stat_lock);
-		++sdev->stat.read_errors;
-		spin_unlock(&sdev->stat_lock);
 		goto out;
 	}
 	for (i = 0; i < sbio->count; ++i) {
@@ -420,8 +429,14 @@ static void scrub_checksum(struct btrfs_work *work)
 			WARN_ON(1);
 		}
 		kunmap_atomic(buffer, KM_USER0);
-		if (ret)
-			scrub_recheck_error(sbio, i);
+		if (ret) {
+			ret = scrub_recheck_error(sbio, i);
+			if (!ret) {
+				spin_lock(&sdev->stat_lock);
+				++sdev->stat.unverified_errors;
+				spin_unlock(&sdev->stat_lock);
+			}
+		}
 	}
 
 out:
Signature · 1 line
1.7.3.4
#6 lore raw

PATCH v7 3/8 btrfs scrub: print paths of corrupted files

In reply to Jan Schmidt

While scrubbing, we may encounter various errors. Previously, a logical address was printed to the log only. Now, all paths belonging to that address are resolved and printed separately. That should work for hardlinks as well as reflinks.

---
 fs/btrfs/scrub.c |  169 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 163 insertions(+), 6 deletions(-)
fs/btrfs/scrub.c +163 -6
index 35099fa..221fd5c 100644
@@ -17,10 +17,12 @@
  */
 
 #include <linux/blkdev.h>
+#include <linux/ratelimit.h>
 #include "ctree.h"
 #include "volumes.h"
 #include "disk-io.h"
 #include "ordered-data.h"
+#include "backref.h"
 
 /*
  * This is only the first step towards a full-features scrub. It reads all
@@ -100,6 +102,19 @@ struct scrub_dev {
 	spinlock_t		stat_lock;
 };
 
+struct scrub_warning {
+	struct btrfs_path	*path;
+	u64			extent_item_size;
+	char			*scratch_buf;
+	char			*msg_buf;
+	const char		*errstr;
+	sector_t		sector;
+	u64			logical;
+	struct btrfs_device	*dev;
+	int			msg_bufsize;
+	int			scratch_bufsize;
+};
+
 static void scrub_free_csums(struct scrub_dev *sdev)
 {
 	while (!list_empty(&sdev->csum_list)) {
@@ -195,6 +210,143 @@ nomem:
 	return ERR_PTR(-ENOMEM);
 }
 
+static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, void *ctx)
+{
+	u64 isize;
+	u32 nlink;
+	int ret;
+	int i;
+	struct extent_buffer *eb;
+	struct btrfs_inode_item *inode_item;
+	struct scrub_warning *swarn = ctx;
+	struct btrfs_fs_info *fs_info = swarn->dev->dev_root->fs_info;
+	struct inode_fs_paths *ipath = NULL;
+	struct btrfs_root *local_root;
+	struct btrfs_key root_key;
+
+	root_key.objectid = root;
+	root_key.type = BTRFS_ROOT_ITEM_KEY;
+	root_key.offset = (u64)-1;
+	local_root = btrfs_read_fs_root_no_name(fs_info, &root_key);
+	if (IS_ERR(local_root)) {
+		ret = PTR_ERR(local_root);
+		goto err;
+	}
+
+	ret = inode_item_info(inum, 0, local_root, swarn->path);
+	if (ret) {
+		btrfs_release_path(swarn->path);
+		goto err;
+	}
+
+	eb = swarn->path->nodes[0];
+	inode_item = btrfs_item_ptr(eb, swarn->path->slots[0],
+					struct btrfs_inode_item);
+	isize = btrfs_inode_size(eb, inode_item);
+	nlink = btrfs_inode_nlink(eb, inode_item);
+	btrfs_release_path(swarn->path);
+
+	ipath = init_ipath(4096, local_root, swarn->path);
+	ret = paths_from_inode(inum, ipath);
+
+	if (ret < 0)
+		goto err;
+
+	/*
+	 * we deliberately ignore the bit ipath might have been too small to
+	 * hold all of the paths here
+	 */
+	for (i = 0; i < ipath->fspath->elem_cnt; ++i)
+		printk(KERN_WARNING "btrfs: %s at logical %llu on dev "
+			"%s, sector %llu, root %llu, inode %llu, offset %llu, "
+			"length %llu, links %u (path: %s)\n", swarn->errstr,
+			swarn->logical, swarn->dev->name,
+			(unsigned long long)swarn->sector, root, inum, offset,
+			min(isize - offset, (u64)PAGE_SIZE), nlink,
+			ipath->fspath->str[i]);
+
+	free_ipath(ipath);
+	return 0;
+
+err:
+	printk(KERN_WARNING "btrfs: %s at logical %llu on dev "
+		"%s, sector %llu, root %llu, inode %llu, offset %llu: path "
+		"resolving failed with ret=%d\n", swarn->errstr,
+		swarn->logical, swarn->dev->name,
+		(unsigned long long)swarn->sector, root, inum, offset, ret);
+
+	free_ipath(ipath);
+	return 0;
+}
+
+static void scrub_print_warning(const char *errstr, struct scrub_bio *sbio,
+				int ix)
+{
+	struct btrfs_device *dev = sbio->sdev->dev;
+	struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;
+	struct btrfs_path *path;
+	struct btrfs_key found_key;
+	struct extent_buffer *eb;
+	struct btrfs_extent_item *ei;
+	struct scrub_warning swarn;
+	u32 item_size;
+	int ret;
+	u64 ref_root;
+	u8 ref_level;
+	unsigned long ptr = 0;
+	const int bufsize = 4096;
+	u64 extent_offset;
+
+	path = btrfs_alloc_path();
+
+	swarn.scratch_buf = kmalloc(bufsize, GFP_NOFS);
+	swarn.msg_buf = kmalloc(bufsize, GFP_NOFS);
+	swarn.sector = (sbio->physical + ix * PAGE_SIZE) >> 9;
+	swarn.logical = sbio->logical + ix * PAGE_SIZE;
+	swarn.errstr = errstr;
+	swarn.dev = dev;
+	swarn.msg_bufsize = bufsize;
+	swarn.scratch_bufsize = bufsize;
+
+	if (!path || !swarn.scratch_buf || !swarn.msg_buf)
+		goto out;
+
+	ret = extent_from_logical(fs_info, swarn.logical, path, &found_key);
+	if (ret < 0)
+		goto out;
+
+	extent_offset = swarn.logical - found_key.objectid;
+	swarn.extent_item_size = found_key.offset;
+
+	eb = path->nodes[0];
+	ei = btrfs_item_ptr(eb, path->slots[0], struct btrfs_extent_item);
+	item_size = btrfs_item_size_nr(eb, path->slots[0]);
+
+	if (ret & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
+		do {
+			ret = tree_backref_for_extent(&ptr, eb, ei, item_size,
+							&ref_root, &ref_level);
+			printk(KERN_WARNING "%s at logical %llu on dev %s, "
+				"sector %llu: metadata %s (level %d) in tree "
+				"%llu\n", errstr, swarn.logical, dev->name,
+				(unsigned long long)swarn.sector,
+				ref_level ? "node" : "leaf",
+				ret < 0 ? -1 : ref_level,
+				ret < 0 ? -1 : ref_root);
+		} while (ret != 1);
+	} else {
+		swarn.path = path;
+		iterate_extent_inodes(fs_info, path, found_key.objectid,
+					extent_offset,
+					scrub_print_warning_inode, &swarn);
+	}
+
+out:
+	btrfs_free_path(path);
+	kfree(swarn.scratch_buf);
+	kfree(swarn.msg_buf);
+}
+
 /*
  * scrub_recheck_error gets called when either verification of the page
  * failed or the bio failed to read, e.g. with EIO. In the latter case,
@@ -205,6 +357,8 @@ static int scrub_recheck_error(struct scrub_bio *sbio, int ix)
 {
 	struct scrub_dev *sdev = sbio->sdev;
 	u64 sector = (sbio->physical + ix * PAGE_SIZE) >> 9;
+	static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL,
+					DEFAULT_RATELIMIT_BURST);
 
 	if (sbio->err) {
 		if (scrub_fixup_io(READ, sbio->sdev->dev->bdev, sector,
@@ -212,6 +366,11 @@ static int scrub_recheck_error(struct scrub_bio *sbio, int ix)
 			if (scrub_fixup_check(sbio, ix) == 0)
 				return 0;
 		}
+		if (__ratelimit(&_rs))
+			scrub_print_warning("i/o error", sbio, ix);
+	} else {
+		if (__ratelimit(&_rs))
+			scrub_print_warning("checksum error", sbio, ix);
 	}
 
 	spin_lock(&sdev->stat_lock);
@@ -326,9 +485,8 @@ static void scrub_fixup(struct scrub_bio *sbio, int ix)
 	++sdev->stat.corrected_errors;
 	spin_unlock(&sdev->stat_lock);
 
-	if (printk_ratelimit())
-		printk(KERN_ERR "btrfs: fixed up at %llu\n",
-		       (unsigned long long)logical);
+	printk_ratelimited(KERN_ERR "btrfs: fixed up error at logical %llu\n",
+			       (unsigned long long)logical);
 	return;
 
 uncorrectable:
@@ -337,9 +495,8 @@ uncorrectable:
 	++sdev->stat.uncorrectable_errors;
 	spin_unlock(&sdev->stat_lock);
 
-	if (printk_ratelimit())
-		printk(KERN_ERR "btrfs: unable to fixup at %llu\n",
-			 (unsigned long long)logical);
+	printk_ratelimited(KERN_ERR "btrfs: unable to fixup (regular) error at "
+				"logical %llu\n", (unsigned long long)logical);
 }
 
 static int scrub_fixup_io(int rw, struct block_device *bdev, sector_t sector,
Signature · 1 line
1.7.3.4
#7 lore raw

PATCH v7 4/8 btrfs scrub: bugfix: mirror_num off by one

In reply to Jan Schmidt

Fix the mirror_num determination in scrub_stripe. The rest of the scrub code did not use mirror_num for anything important and that error went unnoticed. The nodatasum fixup patch of this set depends on a correct mirror_num.

---
 fs/btrfs/scrub.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/scrub.c +6 -6
index 221fd5c..59caf8f 100644
@@ -452,7 +452,7 @@ static void scrub_fixup(struct scrub_bio *sbio, int ix)
 	 * first find a good copy
 	 */
 	for (i = 0; i < multi->num_stripes; ++i) {
-		if (i == sbio->spag[ix].mirror_num)
+		if (i + 1 == sbio->spag[ix].mirror_num)
 			continue;
 
 		if (scrub_fixup_io(READ, multi->stripes[i].dev->bdev,
@@ -930,21 +930,21 @@ static noinline_for_stack int scrub_stripe(struct scrub_dev *sdev,
 	if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
 		offset = map->stripe_len * num;
 		increment = map->stripe_len * map->num_stripes;
-		mirror_num = 0;
+		mirror_num = 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
 		int factor = map->num_stripes / map->sub_stripes;
 		offset = map->stripe_len * (num / map->sub_stripes);
 		increment = map->stripe_len * factor;
-		mirror_num = num % map->sub_stripes;
+		mirror_num = num % map->sub_stripes + 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
 		increment = map->stripe_len;
-		mirror_num = num % map->num_stripes;
+		mirror_num = num % map->num_stripes + 1;
 	} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
 		increment = map->stripe_len;
-		mirror_num = num % map->num_stripes;
+		mirror_num = num % map->num_stripes + 1;
 	} else {
 		increment = map->stripe_len;
-		mirror_num = 0;
+		mirror_num = 1;
 	}
 
 	path = btrfs_alloc_path();
Signature · 1 line
1.7.3.4
#8 lore raw

PATCH v7 5/8 btrfs: add mirror_num to extent_read_full_page

In reply to Jan Schmidt

Currently, extent_read_full_page always assumes we are trying to read mirror 0, which generally is the best we can do. To add flexibility, pass it as a parameter. This will be needed by scrub fixup code.

---
 fs/btrfs/disk-io.c   |    2 +-
 fs/btrfs/extent_io.c |    6 +++---
 fs/btrfs/extent_io.h |    2 +-
 fs/btrfs/inode.c     |    2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/disk-io.c +1 -1
index 1ac8db5d..b898319 100644
@@ -874,7 +874,7 @@ static int btree_readpage(struct file *file, struct page *page)
 {
 	struct extent_io_tree *tree;
 	tree = &BTRFS_I(page->mapping->host)->io_tree;
-	return extent_read_full_page(tree, page, btree_get_extent);
+	return extent_read_full_page(tree, page, btree_get_extent, 0);
 }
 
 static int btree_releasepage(struct page *page, gfp_t gfp_flags)
fs/btrfs/extent_io.c +3 -3
index b181a94..b78f665 100644
@@ -2111,16 +2111,16 @@ static int __extent_read_full_page(struct extent_io_tree *tree,
 }
 
 int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
-			    get_extent_t *get_extent)
+			    get_extent_t *get_extent, int mirror_num)
 {
 	struct bio *bio = NULL;
 	unsigned long bio_flags = 0;
 	int ret;
 
-	ret = __extent_read_full_page(tree, page, get_extent, &bio, 0,
+	ret = __extent_read_full_page(tree, page, get_extent, &bio, mirror_num,
 				      &bio_flags);
 	if (bio)
-		ret = submit_one_bio(READ, bio, 0, bio_flags);
+		ret = submit_one_bio(READ, bio, mirror_num, bio_flags);
 	return ret;
 }
 
fs/btrfs/extent_io.h +1 -1
index a11a92e..22bf366 100644
@@ -177,7 +177,7 @@ int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end,
 int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end,
 		    gfp_t mask);
 int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
-			  get_extent_t *get_extent);
+			  get_extent_t *get_extent, int mirror_num);
 int __init extent_io_init(void);
 void extent_io_exit(void);
 
fs/btrfs/inode.c +1 -1
index 4a13730..730ee3d 100644
@@ -6250,7 +6250,7 @@ int btrfs_readpage(struct file *file, struct page *page)
 {
 	struct extent_io_tree *tree;
 	tree = &BTRFS_I(page->mapping->host)->io_tree;
-	return extent_read_full_page(tree, page, btrfs_get_extent);
+	return extent_read_full_page(tree, page, btrfs_get_extent, 0);
 }
 
 static int btrfs_writepage(struct page *page, struct writeback_control *wbc)
Signature · 1 line
1.7.3.4
#9 lore raw

PATCH v7 6/8 btrfs scrub: use int for mirror_num, not u64

In reply to Jan Schmidt

the rest of the code uses int mirror_num, and so should scrub

---
 fs/btrfs/scrub.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/scrub.c +4 -4
index 59caf8f..41a0114 100644
@@ -65,7 +65,7 @@ static void scrub_fixup(struct scrub_bio *sbio, int ix);
 struct scrub_page {
 	u64			flags;  /* extent flags */
 	u64			generation;
-	u64			mirror_num;
+	int			mirror_num;
 	int			have_csum;
 	u8			csum[BTRFS_CSUM_SIZE];
 };
@@ -776,7 +776,7 @@ nomem:
 }
 
 static int scrub_page(struct scrub_dev *sdev, u64 logical, u64 len,
-		      u64 physical, u64 flags, u64 gen, u64 mirror_num,
+		      u64 physical, u64 flags, u64 gen, int mirror_num,
 		      u8 *csum, int force)
 {
 	struct scrub_bio *sbio;
@@ -873,7 +873,7 @@ static int scrub_find_csum(struct scrub_dev *sdev, u64 logical, u64 len,
 
 /* scrub extent tries to collect up to 64 kB for each bio */
 static int scrub_extent(struct scrub_dev *sdev, u64 logical, u64 len,
-			u64 physical, u64 flags, u64 gen, u64 mirror_num)
+			u64 physical, u64 flags, u64 gen, int mirror_num)
 {
 	int ret;
 	u8 csum[BTRFS_CSUM_SIZE];
@@ -919,7 +919,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_dev *sdev,
 	u64 physical;
 	u64 logical;
 	u64 generation;
-	u64 mirror_num;
+	int mirror_num;
 
 	u64 increment = map->stripe_len;
 	u64 offset;
Signature · 1 line
1.7.3.4
#10 lore raw

PATCH v7 7/8 btrfs scrub: add fixup code for errors on nodatasum files

In reply to Jan Schmidt

This removes a FIXME comment and introduces the first part of nodatasum
fixup: It gets the corresponding inode for a logical address and triggers a regular readpage for the corrupted sector.

Once we have on-the-fly error correction our error will be automatically corrected. The correction code is expected to clear the newly introduced EXTENT_DAMAGED flag, making scrub report that error as "corrected" instead of "uncorrectable" eventually.

---
 fs/btrfs/extent_io.h |    1 +
 fs/btrfs/scrub.c     |  188 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 183 insertions(+), 6 deletions(-)
fs/btrfs/extent_io.h +1 -0
index 22bf366..2734fd9 100644
@@ -17,6 +17,7 @@
 #define EXTENT_NODATASUM (1 << 10)
 #define EXTENT_DO_ACCOUNTING (1 << 11)
 #define EXTENT_FIRST_DELALLOC (1 << 12)
+#define EXTENT_DAMAGED (1 << 13)
 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
 #define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
 
fs/btrfs/scrub.c +182 -6

246 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#11 lore raw

PATCH v7 8/8 btrfs: new ioctls to do logical->inode and inode->path resolving

In reply to Jan Schmidt

these ioctls make use of the new functions initially added for scrub. they return all inodes belonging to a logical address (BTRFS_IOC_LOGICAL_INO) and all paths belonging to an inode (BTRFS_IOC_INO_PATHS).

---
 fs/btrfs/ioctl.c |  150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/ioctl.h |   19 +++++++
 2 files changed, 169 insertions(+), 0 deletions(-)
fs/btrfs/ioctl.c +150 -0
index a3c4751..798c8ed 100644
@@ -51,6 +51,7 @@
 #include "volumes.h"
 #include "locking.h"
 #include "inode-map.h"
+#include "backref.h"
 
 /* Mask out flags that are inappropriate for the given type of inode. */
 static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
@@ -2836,6 +2837,151 @@ static long btrfs_ioctl_scrub_progress(struct btrfs_root *root,
 	return ret;
 }
 
+static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
+{
+	int ret = 0;
+	int i;
+	unsigned long rel_ptr;
+	int size;
+	struct btrfs_ioctl_ino_path_args *ipa;
+	struct inode_fs_paths *ipath = NULL;
+	struct btrfs_path *path;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	path = btrfs_alloc_path();
+	if (!path) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	ipa = memdup_user(arg, sizeof(*ipa));
+	if (IS_ERR(ipa)) {
+		ret = PTR_ERR(ipa);
+		ipa = NULL;
+		goto out;
+	}
+
+	if (ipa->size <= 0) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	size = min(ipa->size, 4096);
+	ipath = init_ipath(size, root, path);
+	if (IS_ERR(ipath)) {
+		ret = PTR_ERR(ipath);
+		ipath = NULL;
+		goto out;
+	}
+
+	ret = paths_from_inode(ipa->inum, ipath);
+	if (ret < 0)
+		goto out;
+
+	for (i = 0; i < ipath->fspath->elem_cnt; ++i) {
+		rel_ptr = ipath->fspath->str[i] - (char *)ipath->fspath->str;
+		ipath->fspath->str[i] = (void *)rel_ptr;
+	}
+
+	ret = copy_to_user(ipa->fspath, ipath->fspath, size);
+	if (ret) {
+		ret = -EFAULT;
+		goto out;
+	}
+
+out:
+	btrfs_free_path(path);
+	free_ipath(ipath);
+	kfree(ipa);
+
+	return ret;
+}
+
+static int build_ino_list(u64 inum, u64 offset, u64 root, void *ctx)
+{
+	struct btrfs_data_container *inodes = ctx;
+
+	inodes->size -= 3 * sizeof(u64);
+	if (inodes->size > 0) {
+		inodes->val[inodes->elem_cnt] = inum;
+		inodes->val[inodes->elem_cnt + 1] = offset;
+		inodes->val[inodes->elem_cnt + 2] = root;
+		inodes->elem_cnt += 3;
+	} else {
+		inodes->elem_missed += 3;
+	}
+
+	return 0;
+}
+
+static long btrfs_ioctl_logical_to_ino(struct btrfs_root *root,
+					void __user *arg)
+{
+	int ret = 0;
+	int size;
+	u64 extent_offset;
+	struct btrfs_ioctl_logical_ino_args *loi;
+	struct btrfs_data_container *inodes = NULL;
+	struct btrfs_path *path = NULL;
+	struct btrfs_key key;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	loi = memdup_user(arg, sizeof(*loi));
+	if (IS_ERR(loi)) {
+		ret = PTR_ERR(loi);
+		loi = NULL;
+		goto out;
+	}
+
+	if (loi->size <= 0) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	path = btrfs_alloc_path();
+	if (!path) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	size = min(loi->size, 4096);
+	inodes = init_data_container(size);
+	if (IS_ERR(inodes)) {
+		ret = PTR_ERR(inodes);
+		inodes = NULL;
+		goto out;
+	}
+
+	ret = extent_from_logical(root->fs_info, loi->logical, path, &key);
+
+	if (ret & BTRFS_EXTENT_FLAG_TREE_BLOCK)
+		ret = -ENOENT;
+	if (ret < 0)
+		goto out;
+
+	extent_offset = loi->logical - key.objectid;
+	ret = iterate_extent_inodes(root->fs_info, path, key.objectid,
+					extent_offset, build_ino_list, inodes);
+
+	if (ret < 0)
+		goto out;
+
+	ret = copy_to_user(loi->inodes, inodes, size);
+	if (ret)
+		ret = -EFAULT;
+
+out:
+	btrfs_free_path(path);
+	kfree(inodes);
+	kfree(loi);
+
+	return ret;
+}
+
 long btrfs_ioctl(struct file *file, unsigned int
 		cmd, unsigned long arg)
 {
@@ -2893,6 +3039,10 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_tree_search(file, argp);
 	case BTRFS_IOC_INO_LOOKUP:
 		return btrfs_ioctl_ino_lookup(file, argp);
+	case BTRFS_IOC_INO_PATHS:
+		return btrfs_ioctl_ino_to_path(root, argp);
+	case BTRFS_IOC_LOGICAL_INO:
+		return btrfs_ioctl_logical_to_ino(root, argp);
 	case BTRFS_IOC_SPACE_INFO:
 		return btrfs_ioctl_space_info(root, argp);
 	case BTRFS_IOC_SYNC:
fs/btrfs/ioctl.h +19 -0
index 4afb60b..10a0c10 100644
@@ -203,6 +203,20 @@ struct btrfs_data_container {
 	};
 };
 
+struct btrfs_ioctl_ino_path_args {
+	__u64				inum;		/* in */
+	__s32				size;		/* in */
+	__u64				reserved[4];
+	struct btrfs_data_container	*fspath;	/* out */
+};
+
+struct btrfs_ioctl_logical_ino_args {
+	__u64				logical;	/* in */
+	__s32				size;		/* in */
+	__u64				reserved[4];
+	struct btrfs_data_container	*inodes;	/* out */
+};
+
 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
 				   struct btrfs_ioctl_vol_args)
 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -258,4 +272,9 @@ struct btrfs_data_container {
 				 struct btrfs_ioctl_dev_info_args)
 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
 			       struct btrfs_ioctl_fs_info_args)
+#define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
+					struct btrfs_ioctl_ino_path_args)
+#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
+					struct btrfs_ioctl_ino_path_args)
+
 #endif
Signature · 1 line
1.7.3.4
#12 lore raw
In reply to Jan Schmidt
Quoted 1 line · Jan Schmidt <list.btrfs <at> jan-o-sch.net> writes:

The first feature adds printk statements in case scrub finds an error which

list

Quoted 1 line

all affected files. You will need patch 1, 2 and 3 for that.

Jan, I tried to apply these patches against official 3.0 and crashed the system while doing a scrub (as reportet for Patchset v5 also). This time I've been able to save the kernel oops:

------------[ cut here ]------------
kernel BUG at fs/btrfs/ctree.h:1669!
invalid opcode: 0000 [#1] PREEMPT SMP 
CPU 1 
Modules linked in: i2c_core ext2 mbcache aesni_intel cryptd aes_x86_64 

aes_generic xts gf128mul dm_crypt acpi_cpufreq mperf lzo snd_hda_codec_hdmi snd_hda_codec_conexant arc4 sr_mod cdrom thinkpad_acpi snd_hda_intel snd_hda_codec sdhci_pci backlight snd_pcm_oss sdhci ehci_hcd intel_agp snd_hwdep psmouse evdev mmc_core usbcore snd_pcm snd_timer thermal intel_gtt nvram snd_page_alloc battery snd_mixer_oss snd ac power_supply soundcore processor thermal_sys button hwmon iwlagn mac80211 cfg80211 [last unloaded: nvidia]

Pid: 930, comm: btrfs-scrub-3 Tainted: P 3.0.0-ARCH #1 LENOVO
25223FG/25223FG

RIP: 0010:[<ffffffff811a6b13>]  [<ffffffff811a6b13>] 
__get_extent_inline_ref+0x113/0x120
RSP: 0018:ffff88012eb8fb10  EFLAGS: 00010283
RAX: 0000000000000009 RBX: ffff88012eb8fbd8 RCX: 0000000000000a56
RDX: 0000000000000a55 RSI: ffff88012e83c000 RDI: ffff88013304df80
RBP: ffff88013304df80 R08: ffff88012eb8fad0 R09: ffff88012eb8fad8
R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000a3d
R13: 0000000000000018 R14: ffff88012eb8fbec R15: 0000002a63679000
FS:  0000000000000000(0000) GS:ffff880137c80000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00000000006ac8f0 CR3: 000000012e98e000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process btrfs-scrub-3 (pid: 930, threadinfo ffff88012eb8e000, task 
ffff880131fc5160)
Stack:
 0000000000001000 ffff88012eb8fbe0 ffff8801331a7cf0 ffff88013304df80
 ffff880130ea8000 0000000000000a3d 0000000000000018 ffffffff811a7596
 ffff88012eb8fb90 00ff880100000004 0000000000000000 0000000000000001
Call Trace:
 [<ffffffff811a7596>] ? iterate_extent_inodes+0xc6/0x3f0
 [<ffffffff811a7fb0>] ? scrub_print_warning+0x2e0/0x2e0
 [<ffffffff811768ae>] ? btrfs_item_size+0xee/0x100
 [<ffffffff811a7e8e>] ? scrub_print_warning+0x1be/0x2e0
 [<ffffffff810373e2>] ? try_to_wake_up+0x1b2/0x260
 [<ffffffff811a8a06>] ? scrub_recheck_error+0x306/0x3e0
 [<ffffffff811a8385>] ? scrub_checksum_data+0xe5/0x120
 [<ffffffff811a937c>] ? scrub_checksum+0x39c/0x480
 [<ffffffff81047ce0>] ? usleep_range+0x40/0x40
 [<ffffffff81189bbe>] ? worker_loop+0x14e/0x4e0
 [<ffffffff81189a70>] ? btrfs_queue_worker+0x2d0/0x2d0
 [<ffffffff810574fe>] ? kthread+0x7e/0x90
 [<ffffffff81399994>] ? kernel_thread_helper+0x4/0x10
 [<ffffffff81057480>] ? kthread_worker_fn+0x180/0x180
 [<ffffffff81399990>] ? gs_change+0xb/0xb
Code: eb e7 66 0f 1f 44 00 00 b8 0d 00 00 00 e9 61 ff ff ff be ef 00 00 00 48 c7 

c7 bb c7 44 81 e8 95 4e e9 ff 48 8b 03 e9 5a ff ff ff <0f> 0b 66 66 2e 0f 1f 84 00 00 00 00 00 48 83 ec 28 48 89 6c 24
RIP [<ffffffff811a6b13>] __get_extent_inline_ref+0x113/0x120
RSP <ffff88012eb8fb10>

---[ end trace b662579b95afa75a ]---

The filesystem seems to be dead afterwards, doing a sync or trying to write data has not been possible. I've not seen any csum errors in dmesg while oder after doing the scrub but after rebooting the system:

btrfs no csum found for inode 199934 start 729088
btrfs csum failed ino 199934 off 729088 csum 3390946210 private 0 btrfs no csum found for inode 199934 start 24096768 btrfs csum failed ino 199934 off 24096768 csum 439962552 private 0 btrfs no csum found for inode 199934 start 24801280 btrfs no csum found for inode 199934 start 24805376 btrfs csum failed ino 199934 off 24801280 csum 158010657 private 0 btrfs csum failed ino 199934 off 24805376 csum 127231121 private 0

The scrub status has been reported as follows (after kernel crash, not rebooted):

scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca
scrub started at Sun Jul 24 00:07:58 2011, running for 932 seconds total bytes scrubbed: 165.86GB with 4 errors
error details: csum=4
corrected errors: 0, uncorrectable errors: 0

After rebooting the system the status is reported like this:

scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca
scrub started at Sun Jul 24 00:07:58 2011, running for 742 seconds total bytes scrubbed: 164.10GB with 0 errors

Interessting to note is the difference in time and scrubbed bytes.

As reported before, this filesystem has shown more than 2000 unrecoverable errors before which seemed to be gone after upgrading to official 3.0 and your patches. 3.0 seems very robust when it comes to btrfs (at least much more than 2.6).

I'm still very interested in knowing which of the files are corrupted.

HTH,
Jan

#13 lore raw
Quoted 8 lines · Jan Schubert
Quoted 1 line · Jan Schmidt <list.btrfs <at> jan-o-sch.net> writes:

The first feature adds printk statements in case scrub finds an error which

list

Quoted 1 line

all affected files. You will need patch 1, 2 and 3 for that.

Jan, I tried to apply these patches against official 3.0 and crashed the system while doing a scrub (as reportet for Patchset v5 also). This time I've been able to save the kernel oops:

I hope we can make something out of it. Thank you.

Quoted 54 lines
------------[ cut here ]------------
kernel BUG at fs/btrfs/ctree.h:1669!
invalid opcode: 0000 [#1] PREEMPT SMP 
CPU 1 
Modules linked in: i2c_core ext2 mbcache aesni_intel cryptd aes_x86_64 

aes_generic xts gf128mul dm_crypt acpi_cpufreq mperf lzo snd_hda_codec_hdmi snd_hda_codec_conexant arc4 sr_mod cdrom thinkpad_acpi snd_hda_intel snd_hda_codec sdhci_pci backlight snd_pcm_oss sdhci ehci_hcd intel_agp snd_hwdep psmouse evdev mmc_core usbcore snd_pcm snd_timer thermal intel_gtt nvram snd_page_alloc battery snd_mixer_oss snd ac power_supply soundcore processor thermal_sys button hwmon iwlagn mac80211 cfg80211 [last unloaded: nvidia]

Pid: 930, comm: btrfs-scrub-3 Tainted: P 3.0.0-ARCH #1 LENOVO
25223FG/25223FG

RIP: 0010:[<ffffffff811a6b13>]  [<ffffffff811a6b13>] 
__get_extent_inline_ref+0x113/0x120
RSP: 0018:ffff88012eb8fb10  EFLAGS: 00010283
RAX: 0000000000000009 RBX: ffff88012eb8fbd8 RCX: 0000000000000a56
RDX: 0000000000000a55 RSI: ffff88012e83c000 RDI: ffff88013304df80
RBP: ffff88013304df80 R08: ffff88012eb8fad0 R09: ffff88012eb8fad8
R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000a3d
R13: 0000000000000018 R14: ffff88012eb8fbec R15: 0000002a63679000
FS:  0000000000000000(0000) GS:ffff880137c80000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00000000006ac8f0 CR3: 000000012e98e000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process btrfs-scrub-3 (pid: 930, threadinfo ffff88012eb8e000, task 
ffff880131fc5160)
Stack:
 0000000000001000 ffff88012eb8fbe0 ffff8801331a7cf0 ffff88013304df80
 ffff880130ea8000 0000000000000a3d 0000000000000018 ffffffff811a7596
 ffff88012eb8fb90 00ff880100000004 0000000000000000 0000000000000001
Call Trace:
 [<ffffffff811a7596>] ? iterate_extent_inodes+0xc6/0x3f0
 [<ffffffff811a7fb0>] ? scrub_print_warning+0x2e0/0x2e0
 [<ffffffff811768ae>] ? btrfs_item_size+0xee/0x100
 [<ffffffff811a7e8e>] ? scrub_print_warning+0x1be/0x2e0
 [<ffffffff810373e2>] ? try_to_wake_up+0x1b2/0x260
 [<ffffffff811a8a06>] ? scrub_recheck_error+0x306/0x3e0
 [<ffffffff811a8385>] ? scrub_checksum_data+0xe5/0x120
 [<ffffffff811a937c>] ? scrub_checksum+0x39c/0x480
 [<ffffffff81047ce0>] ? usleep_range+0x40/0x40
 [<ffffffff81189bbe>] ? worker_loop+0x14e/0x4e0
 [<ffffffff81189a70>] ? btrfs_queue_worker+0x2d0/0x2d0
 [<ffffffff810574fe>] ? kthread+0x7e/0x90
 [<ffffffff81399994>] ? kernel_thread_helper+0x4/0x10
 [<ffffffff81057480>] ? kthread_worker_fn+0x180/0x180
 [<ffffffff81399990>] ? gs_change+0xb/0xb
Code: eb e7 66 0f 1f 44 00 00 b8 0d 00 00 00 e9 61 ff ff ff be ef 00 00 00 48 c7 

c7 bb c7 44 81 e8 95 4e e9 ff 48 8b 03 e9 5a ff ff ff <0f> 0b 66 66 2e 0f 1f 84 00 00 00 00 00 48 83 ec 28 48 89 6c 24
RIP [<ffffffff811a6b13>] __get_extent_inline_ref+0x113/0x120
RSP <ffff88012eb8fb10>

Quoted 5 lines
---[ end trace b662579b95afa75a ]---

The filesystem seems to be dead afterwards, doing a sync or trying to write data has not been possible. I've not seen any csum errors in dmesg while oder after doing the scrub but after rebooting the system:

That's expected behavior after an oops.

Quoted 9 lines

btrfs no csum found for inode 199934 start 729088
btrfs csum failed ino 199934 off 729088 csum 3390946210 private 0 btrfs no csum found for inode 199934 start 24096768 btrfs csum failed ino 199934 off 24096768 csum 439962552 private 0 btrfs no csum found for inode 199934 start 24801280 btrfs no csum found for inode 199934 start 24805376 btrfs csum failed ino 199934 off 24801280 csum 158010657 private 0 btrfs csum failed ino 199934 off 24805376 csum 127231121 private 0

Quoted 8 lines

The scrub status has been reported as follows (after kernel crash, not rebooted):

scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca
scrub started at Sun Jul 24 00:07:58 2011, running for 932 seconds total bytes scrubbed: 165.86GB with 4 errors
error details: csum=4
corrected errors: 0, uncorrectable errors: 0

I wouldn't give too much on that one, to be honest, I'm even surprised scrub managed to complete after the BUG triggered.

Quoted 7 lines

After rebooting the system the status is reported like this:

scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca
scrub started at Sun Jul 24 00:07:58 2011, running for 742 seconds total bytes scrubbed: 164.10GB with 0 errors

Interessting to note is the difference in time and scrubbed bytes.

In general, scrub will need significantly longer when encountering errors.

Quoted 4 lines

As reported before, this filesystem has shown more than 2000 unrecoverable errors before which seemed to be gone after upgrading to official 3.0 and your patches. 3.0 seems very robust when it comes to btrfs (at least much more than 2.6).

This is unexpected to me. I don't know currently whether scrub had any significant changes between the version you used before and the one included in 3.0, but I would have expected the errors to persist. At least, scrub should also produce "missing csum" errors when btrfs does so while in operation.

Quoted 1 line

I'm still very interested in knowing which of the files are corrupted.

And I'd like to help and find out what triggered the BUG. I'll try to reproduce here, was there anything else going on in the file system while scrubbing? Like heavy read load or write load?

Let me check if I got you right: You hit the BUG while scrubbing, then rebootet, found csum messages in your log, started another scrub which really told you that your file system was perfectly well?

What is the current state of the file system?

-Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw
Quoted 27 lines · Jan Schubert
Quoted 5 lines · Jan Schmidt

Yes, please check if that error solely depends on the state of your file system (which is what I expect). Please try another scrub while the system is as idle as you get it (also consider daemon processes, cron jobs etc.).

Jan, doing a new scrub using a clean kernel (without your patchset) the system did not crash. I'm back to my 2211 uncorrectable errors now and dmesg shows also the (some?) corresponding inodes:

btrfs: use lzo compression
btrfs: enabling disk space caching
btrfs: use ssd allocation scheme
Adding 4194300k swap on /dev/sda3. Priority:-1 extents:1 across:4194300k SS
btrfs: unable to fixup at 182245502976
btrfs: unable to fixup at 182245507072
btrfs: unable to fixup at 182245511168
btrfs: unable to fixup at 182245515264
btrfs: unable to fixup at 182245519360
btrfs: unable to fixup at 182245523456
btrfs: unable to fixup at 182245527552
btrfs: unable to fixup at 182245531648
btrfs: unable to fixup at 182245535744
btrfs: unable to fixup at 182245539840

Quoted 6 lines

scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca

        scrub started at Sun Jul 24 22:13:09 2011 and finished after 787

seconds
total bytes scrubbed: 173.92GB with 2211 errors error details: csum=2211
corrected errors: 0, uncorrectable errors: 2211

Okay, it's good that it's persistent.

Quoted 1 line

So there might be an issue with your patch concerning the kernel oops?

Yes, that seems quite likely.

Quoted 1 line

Any chance to resolve the inodes to affected files manualy?

That's cumbersome, but you can do it using the information contained in the debug-tree output. But I'd rather find the bug I must have introduced :-)

Quoted 2 lines

Did I mention that I just did apply your patches 1 to 3 from your patch set as suggested by you in the mailing list?

You did. And yes, that hasn't been tested as much as applying the whole patch set. I just double checked it's working for me, though. I don't expect it makes a difference if you apply all the patches.

Quoted 1 line

Are you interested in btrfs-debug-tree anyway?

Absolutely, yes.

Alternatively, if you have a lot of bandwidth and no private data in your file system, it would be even more helpful if you put the whole file system somewhere. But the btrfs-debug-tree output would help a lot, too.

-Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 11 lines · Jan Schubert
Quoted 5 lines · Jan Schmidt
Quoted 1 line · Jan Schubert

Any chance to resolve the inodes to affected files manualy?

That's cumbersome, but you can do it using the information contained in the debug-tree output. But I'd rather find the bug I must have introduced :-)

Thx, let me know when there is a new patch available. I did a search for the inodes listed in dmesg but could not find all of them in the debug tree. And for the ones I found it looks not soo easy to match them to filenames.

Look for "key (<inum> INODE_REF" in your output, replacing "<inum>" with the actual inode number. In the next line you'll find the name of the file. To construct the path, you need to go back to the parent and lookup its name the same way. The parent inode is the number behind the "INODE_REF" part in the key.

Quoted 5 lines

BTW: What is the option -e for btrfs-debug-tree meaning? If I try to use it I just get an segfault right after starting:

btrfs-debug-tre[1875]: segfault at c4 ip 000000000040a839 sp 00007fff9498ff50 error 4 in btrfs-debug-tree[400000+1c000]

No, never used it.

Quoted 11 lines
Quoted 7 lines
Quoted 1 line

Are you interested in btrfs-debug-tree anyway?

Absolutely, yes.

Alternatively, if you have a lot of bandwidth and no private data in your file system, it would be even more helpful if you put the whole file system somewhere. But the btrfs-debug-tree output would help a lot, too.

Jan, what if there are some private data inside? Will you use it for other purposes than debugging? I understood that there are "just" filenames listet in there, no content, right?

Whatever you provide will of course only be used for debugging purposes. But I can totally understand if you don't want to provide the full file system. I wouldn't either, I guess.

The debug tree output contains meta data only, including all file names but no actual data.

Quoted 2 lines

The bziped debugtree is about 39M in size, I would be able to provide a download for you!?

That would be great. Where can I get it? Send me an off-list reply or contact me on freenode irc (janosch) if you don't want it on the list.

-Jan

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#23 lore raw
Quoted 11 lines · Jan Schubert
Quoted 7 lines · Jan Schmidt
Quoted 3 lines · Jan Schubert

btrfs: unable to fixup at 182245531648
btrfs: unable to fixup at 182245535744
btrfs: unable to fixup at 182245539840

This is due to rate limitation of printk() to prevent flooding. I'd like to continue discussion of this problem on the list, but I didn't reply to the list this time due to the debug-tree link you gave me.

OK, go on Jan, no problem. Is there any chance to use the numbers above to identify related files?

Thanks for sending the debug-tree output. Turns out that there is a quite obvious bug in my code for extents that have refs but no inline ref at all.

I'll fix this up and send a new version (hooray).

Jan: It would be nice if you could try the new patch set once I've sent it. I don't need any additional input from you at the moment.

Chris: As you suggested, the new version will also include two separate size fields in struct btrfs_data_container, which then can both be unsigned.

-Jan