Btrfs scrub: print path to corrupted files and trigger nodatasum fixup
v8 cover Btrfs scrub: print path to corrupted files and trigger nodatasum fixup
Changelog v7->v8:
- bugfix for the case where refs exist but none are inline (reported by Jan Schubert)
- use bytes_missing and bytes_left (unsigned) instead of size (signed) (wished by Chris Mason)
- alloc_bytes is now size_t (reported by Li Zefan)
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
Changelog v5->v6:
- fixed ioctl priviledge and input sanity checking (reported by Andi Kleen)
Changelog v6->v7:
- include everything that was stated to be in v6
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 | 764 ++++++++++++++++++++++++++++++++++++++++++++++++++ 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 | 143 ++++++++++ fs/btrfs/ioctl.h | 30 ++ fs/btrfs/scrub.c | 414 +++++++++++++++++++++++++--- 10 files changed, 1389 insertions(+), 40 deletions(-) create mode 100644 fs/btrfs/backref.c create mode 100644 fs/btrfs/backref.h
Signature · 1 line
1.7.3.4
PATCH v8 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 | 764 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/backref.h | 62 +++++ fs/btrfs/ioctl.h | 11 + 4 files changed, 839 insertions(+), 1 deletions(-)
fs/btrfs/Makefile +2 -1
@@ -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 +764 -0
764 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 +11 -0
@@ -193,6 +193,17 @@ struct btrfs_ioctl_space_args {struct btrfs_ioctl_space_info spaces[0 ]; }; +struct btrfs_data_container { +__u32 bytes_left;/* out -- bytes not needed to deliver output */ +__u32 bytes_missing;/* out -- additional bytes needed for result */ +__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
Re: [PATCH v8 1/8] btrfs: added helper functions to iterate backrefs
(as this is going to be merged into mainline..)
fs/btrfs/backref.c line 483
Quoted 11 lines
fs/btrfs/backref.c new file +11
-0+/* +* calls iterate() for every inode that references the extent identified by +* the given parameters. will use the path given as a parameter and return it +* released. +* when the iterator function returns a non-zero value, iteration stops. +*/ +int iterate_extent_inodes (struct btrfs_fs_info *fs_info, +struct btrfs_path *path, +u64 extent_item_objectid, +u64 extent_offset, +iterate_extent_inodes_t *iterate,void *ctx)
While trying to use this API, I found there's a big defect in this function.
fs_tree 1 fs_tree 2
\ /
\ /
\ /
\ /
node
|
|
leaf (EXTENT_DATA item)In the above case, the function will find only 1 reference.
Re: [PATCH v8 1/8] btrfs: added helper functions to iterate backrefs
Quoted 26 lines · Li Zefan
(as this is going to be merged into mainline..)
fs/btrfs/backref.c line 483
Quoted 11 lines
fs/btrfs/backref.c new file +11
-0+/* +* calls iterate() for every inode that references the extent identified by +* the given parameters. will use the path given as a parameter and return it +* released. +* when the iterator function returns a non-zero value, iteration stops. +*/ +int iterate_extent_inodes (struct btrfs_fs_info *fs_info, +struct btrfs_path *path, +u64 extent_item_objectid, +u64 extent_offset, +iterate_extent_inodes_t *iterate,void *ctx)While trying to use this API, I found there's a big defect in this function.
fs_tree1fs_tree2\ / \ / \ / \ / node | | leaf (EXTENT_DATA item)
Quoted 1 line
In the above case, the function will find only 1 reference.
Hum. You are right.
I'm convinced that I've been at this point months ago, only I cannot find code dealing with counts > 1 on nodes. I'll look for a fix in my branches or make a new one.
I also recognized that some "btrfs_" prefixes are missing for the exported functions. I'm going to change this on the next iteration as well.
Currently, this is more of a best-effort resolver. Support for delayed extents is missing, it should be used on commit roots to get a consistent state.
For the userspace part, at least the simple scenario outlined isn't crucial as "btrfs inspect-internal logical-resolve" will find each of the two paths, depending on the subvolume path you specify. It never finds both, though, which I agree it should.
Sigh,
-Jan
Re: [PATCH v8 1/8] btrfs: added helper functions to iterate backrefs
Quoted 31 lines · Jan Schmidt
Quoted 26 lines · Li Zefan
(as this is going to be merged into mainline..)
fs/btrfs/backref.c line 483
Quoted 11 lines
fs/btrfs/backref.c new file +11
-0+/* +* calls iterate() for every inode that references the extent identified by +* the given parameters. will use the path given as a parameter and return it +* released. +* when the iterator function returns a non-zero value, iteration stops. +*/ +int iterate_extent_inodes (struct btrfs_fs_info *fs_info, +struct btrfs_path *path, +u64 extent_item_objectid, +u64 extent_offset, +iterate_extent_inodes_t *iterate,void *ctx)While trying to use this API, I found there's a big defect in this function.
fs_tree1fs_tree2\ / \ / \ / \ / node | | leaf (EXTENT_DATA item)Quoted 1 line
In the above case, the function will find only 1 reference.
Hum. You are right.
Quoted 8 lines
I'm convinced that I've been at this point months ago, only I cannot find code dealing with counts > 1 on nodes. I'll look for a fix in my branches or make a new one.
Currently, this is more of a best-effort resolver. Support for delayed extents is missing, it should be used on commit roots to get a consistent state.
The qgroups patch contains an implementation to find all roots for a given extent. A quite extensive part of qgroups is needed for that, so it might be easiest to build a new version on top of qgroups. Otherwise I could split qgroups in 2 parts to factor out that half.
-Arne
PATCH v8 2/8 btrfs scrub: added unverified_errors
In reply to Jan SchmidtIn 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
@@ -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
PATCH v8 3/8 btrfs scrub: print paths of corrupted files
In reply to Jan SchmidtWhile 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
@@ -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
PATCH v8 4/8 btrfs scrub: bugfix: mirror_num off by one
In reply to Jan SchmidtFix 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
@@ -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
PATCH v8 5/8 btrfs: add mirror_num to extent_read_full_page
In reply to Jan SchmidtCurrently, 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v8 6/8 btrfs scrub: use int for mirror_num, not u64
In reply to Jan Schmidtthe 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
@@ -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
PATCH v8 7/8 btrfs scrub: add fixup code for errors on nodatasum files
In reply to Jan SchmidtThis 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
@@ -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
PATCH v8 8/8 btrfs: new ioctls to do logical->inode and inode->path resolving
In reply to Jan Schmidtthese 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 | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 19 +++++++ 2 files changed, 162 insertions(+), 0 deletions(-)
fs/btrfs/ioctl.c +143 -0
@@ -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,144 @@ 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; + } + + size =min_t (u32, 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; +const size_t c =3 *sizeof (u64); + +if (inodes->bytes_left >= c) { + inodes->bytes_left -= c; + 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->bytes_missing += c - inodes->bytes_left; + inodes->bytes_left =0 ; + 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; + } + + path =btrfs_alloc_path (); +if (!path) { + ret = -ENOMEM ; + goto out; + } + + size =min_t (u32, 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 +3032,10 @@ long btrfs_ioctl(struct file *file, unsigned intreturn 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
@@ -204,6 +204,20 @@ struct btrfs_data_container { }; }; +struct btrfs_ioctl_ino_path_args { +__u64 inum;/* in */ +__u32 size;/* in */ +__u64 reserved[4 ]; +struct btrfs_data_container *fspath;/* out */ +}; + +struct btrfs_ioctl_logical_ino_args { +__u64 logical;/* in */ +__u32 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, \
@@ -259,4 +273,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
Quoted 2 lines · Jan Schmidt <list.btrfs <at> jan-o-sch.net> writes:
- bugfix for the case where refs exist but none are inline (reported by Jan Schubert)
Thx Jan, will give it try as soon as possible.
Thx,
Jan
Quoted 6 lines · Jan Schubert <Jan.Schubert <at> GMX.li> writes:
Quoted 2 lines · Jan Schmidt <list.btrfs <at> jan-o-sch.net> writes:
- bugfix for the case where refs exist but none are inline (reported by Jan Schubert)
Thx Jan, will give it try as soon as possible.
OK, Patch 1 to 3 did apply and run successfully on 3.0-git8. I've sent Jan some more details about the output of the affected files (which is actually just one quite large one).
Thx,
Jan
Quoted 3 lines · Jan Schubert <Jan.Schubert <at> GMX.li> writes:
OK, Patch 1 to 3 did apply and run successfully on 3.0-git8. I've sent Jan some more details about the output of the affected files (which is actually just one quite large one).
Hooray:
scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca
scrub started at Thu Jul 28 15:00:54 2011 and finished after 656 seconds total bytes scrubbed: 143.40GB with 0 errors
Clean filesystem after deleting the (last) affected file, thx a lot!
Next issue: I have an other filesystem which is also reportet as error free by scrub:
scrub status for 62bab779-3a5e-4ad0-8f67-9d727813e7ea
scrub started at Thu Jul 28 16:16:26 2011 and finished after 131 seconds total bytes scrubbed: 28.91GB with 0 errors
Doing a btrfsck on the same filesystem I get:
root 5 inode 5067 errors 400
root 5 inode 5098 errors 400
root 5 inode 5123 errors 400
root 5 inode 5125 errors 400
root 5 inode 6082 errors 400 found 30889312256 bytes used err is 1 total csum bytes: 30113200
total tree bytes: 51560448
total fs tree bytes: 8212480 btree space waste bytes: 11638215 file data blocks allocated: 30991843328
referenced 31323025408
Btrfs v0.19-100-g4964d65
Is this something I should be concerned about (regarding the errors)?
Thx,
Jan
Quoted 5 lines · Jan Schubert
Quoted 3 lines · Jan Schubert <Jan.Schubert <at> GMX.li> writes:
OK, Patch 1 to 3 did apply and run successfully on 3.0-git8. I've sent Jan some more details about the output of the affected files (which is actually just one quite large one).
Quoted 7 lines
Hooray:
scrub status for 03201fc0-7695-4468-9a10-f61ad79f23ca
scrub started at Thu Jul 28 15:00:54 2011 and finished after 656 seconds total bytes scrubbed: 143.40GB with 0 errorsClean filesystem after deleting the (last) affected file, thx a lot!
:-)
Quoted 23 lines
Next issue: I have an other filesystem which is also reportet as error free by scrub:
scrub status for 62bab779-3a5e-4ad0-8f67-9d727813e7ea
scrub started at Thu Jul 28 16:16:26 2011 and finished after 131 seconds total bytes scrubbed: 28.91GB with 0 errorsDoing a btrfsck on the same filesystem I get:
root 5 inode 5067 errors 400
root 5 inode 5098 errors 400
root 5 inode 5123 errors 400
root 5 inode 5125 errors 400
root 5 inode 6082 errors 400 found 30889312256 bytes used err is 1 total csum bytes: 30113200
total tree bytes: 51560448
total fs tree bytes: 8212480 btree space waste bytes: 11638215 file data blocks allocated: 30991843328
referenced 31323025408
Btrfs v0.19-100-g4964d65
Quoted 1 line
Is this something I should be concerned about (regarding the errors)?
I think you shouldn't. The "errors 400" is reported constantly in #btrfs, it resolves to REF_ERR_NO_ROOT_BACKREF. There should be a backref, but I haven't heard of any negative impact.
If you are curious, you can try to grab the "inspect-internal" patches for btrfs-progs and use "btrfs inspect-internal resolve-inode 5067" to see what files are referenced by those inodes (given you are still running the kernel you used for scrubbing).
[... which reminds me I have to send a new version of the btrfs-progs patches since the api changed with v8. damn.]
-Jan
Quoted 8 lines · Jan Schmidt <list.btrfs <at> jan-o-sch.net> writes:
I think you shouldn't. The "errors 400" is reported constantly in #btrfs, it resolves to
REF_ERR_NO_ROOT_BACKREF. There should be a backref, but I haven't heard of any negative impact.If you are curious, you can try to grab the "inspect-internal" patches for btrfs-progs and use "btrfs inspect-internal resolve-inode 5067" to see what files are referenced by those inodes (given you are still running the kernel you used for scrubbing).
Thx Jan, I did not follow your advice but used the btrfs-debug-tree to determine the affected files. After deleting them it has been OK. Interessting thing is, that in one case copying the file has been possible to resolve one of these errors (after deleting the original file of course). Other affected file throw an input/output error when trying to access them.
Let me know when I can test some more things. I can offer to run the newest kernels and patches and report any issues!?
Thx,
Jan