btrfs: scrub
v3 cover btrfs: scrub
This series adds an initial implementation for scrub. It works quite straightforward. The usermode issues an ioctl for each device in the fs. For each device, it enumerates the allocated device chunks. For each chunk, the contained extents are enumerated and the data checksums fetched. The extents are read sequentially and the checksums verified. If an error occurs (checksum or EIO), a good copy is searched for. If one is found, the bad copy will be rewritten.
All enumerations happen from the commit roots. During a transaction commit, the scrubs get paused and afterwards continue from the new roots.
For future improvements please see the inline comments.
The accompanying user mode patches will follow shortly.
V2 mainly changes the dev_info ioctl interface.
V3 corrects some EIO handling and cleanup issues.
Thanks,
Arne
Arne Jansen (5):
btrfs: add parameter to btrfs_lookup_csum_range
btrfs: make struct map_lookup public
btrfs: add scrub code and prototypes
btrfs: sync scrub with commit & device removal
btrfs: add state information for scrub
Jan Schmidt (1):
btrfs: new ioctls for scrub
fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 45 ++- fs/btrfs/disk-io.c | 16 + fs/btrfs/file-item.c | 8 +- fs/btrfs/inode.c | 2 +- fs/btrfs/ioctl.c | 131 +++++ fs/btrfs/ioctl.h | 55 ++ fs/btrfs/relocation.c | 2 +- fs/btrfs/scrub.c | 1497 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/transaction.c | 3 + fs/btrfs/tree-log.c | 6 +- fs/btrfs/volumes.c | 16 +- fs/btrfs/volumes.h | 17 + 13 files changed, 1776 insertions(+), 24 deletions(-) create mode 100644 fs/btrfs/scrub.c
Signature · 1 line
1.7.3.4
PATCH v3 1/6 btrfs: add parameter to btrfs_lookup_csum_range
A parameter is added to search the commit root instead of the live root.
--- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/file-item.c | 8 +++++++- fs/btrfs/inode.c | 2 +- fs/btrfs/relocation.c | 2 +- fs/btrfs/tree-log.c | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-)
fs/btrfs/ctree.h +2 -2
@@ -2450,8 +2450,8 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,int btrfs_csum_truncate (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct btrfs_path *path,u64 isize); -int btrfs_lookup_csums_range (struct btrfs_root *root,u64 start, -u64 end,struct list_head *list); +int btrfs_lookup_csums_range (struct btrfs_root *root,u64 start,u64 end, +struct list_head *list,int search_commit);/* inode.c */ /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */
fs/btrfs/file-item.c +7 -1
@@ -263,7 +263,7 @@ int btrfs_lookup_bio_sums_dio(struct btrfs_root *root, struct inode *inode, }int btrfs_lookup_csums_range (struct btrfs_root *root,u64 start,u64 end, -struct list_head *list) +struct list_head *list,int search_commit) {struct btrfs_key key;struct btrfs_path *path;
@@ -280,6 +280,12 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, path =btrfs_alloc_path ();BUG_ON (!path); +if (search_commit) { + path->skip_locking =1 ; + path->reada =2 ; + path->search_commit_root =1 ; + } + key.objectid =BTRFS_EXTENT_CSUM_OBJECTID ; key.offset = start; key.type =BTRFS_EXTENT_CSUM_KEY ;
fs/btrfs/inode.c +1 -1
@@ -1001,7 +1001,7 @@ static noinline int csum_exist_in_range(struct btrfs_root *root,LIST_HEAD (list); ret =btrfs_lookup_csums_range (root->fs_info->csum_root, bytenr, - bytenr + num_bytes -1 , &list); + bytenr + num_bytes -1 , &list,0 );if (ret ==0 &&list_empty (&list))return 0 ;
fs/btrfs/relocation.c +1 -1
@@ -4236,7 +4236,7 @@ int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len) disk_bytenr = file_pos +BTRFS_I (inode)->index_cnt; ret =btrfs_lookup_csums_range (root->fs_info->csum_root, disk_bytenr, - disk_bytenr + len -1 , &list); + disk_bytenr + len -1 , &list,0 );while (!list_empty (&list)) { sums = list_entry(list.next, struct btrfs_ordered_sum, list);
fs/btrfs/tree-log.c +2 -2
@@ -614,7 +614,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, ret =btrfs_lookup_csums_range (root->log_root, csum_start, csum_end -1 , - &ordered_sums); + &ordered_sums,0 );BUG_ON (ret);while (!list_empty (&ordered_sums)) {struct btrfs_ordered_sum *sums;
@@ -2691,7 +2691,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, ret =btrfs_lookup_csums_range ( log->fs_info->csum_root, ds + cs, ds + cs + cl -1 , - &ordered_sums); + &ordered_sums,0 );BUG_ON (ret); } }
Signature · 1 line
1.7.3.4
PATCH v3 2/6 btrfs: make struct map_lookup public
In reply to Arne Jansendefinition of struct map_lookup moved from volumes.c to the header
--- fs/btrfs/volumes.c | 14 -------------- fs/btrfs/volumes.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-)
fs/btrfs/volumes.c +0 -14
@@ -33,25 +33,11 @@#include "volumes.h" #include "async-thread.h" -struct map_lookup { -u64 type; -int io_align; -int io_width; -int stripe_len; -int sector_size; -int num_stripes; -int sub_stripes; -struct btrfs_bio_stripe stripes[]; -}; -static int init_first_rw_device (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct btrfs_device *device);static int btrfs_relocate_sys_chunks (struct btrfs_root *root); -#define map_lookup_size (n) (sizeof(struct map_lookup) + \ - (sizeof(struct btrfs_bio_stripe) * (n))) -static DEFINE_MUTEX (uuid_mutex);static LIST_HEAD (fs_uuids);
fs/btrfs/volumes.h +14 -0
@@ -129,6 +129,20 @@ struct btrfs_bio_stripe {u64 physical; }; +struct map_lookup { +u64 type; +int io_align; +int io_width; +int stripe_len; +int sector_size; +int num_stripes; +int sub_stripes; +struct btrfs_bio_stripe stripes[]; +}; + +#define map_lookup_size (n) (sizeof(struct map_lookup) + \ + (sizeof(struct btrfs_bio_stripe) * (n))) +struct btrfs_multi_bio {atomic_t stripes_pending;bio_end_io_t *end_io;
Signature · 1 line
1.7.3.4
PATCH v3 3/6 btrfs: add scrub code and prototypes
In reply to Arne JansenThis is the main scrub code.
Updates v3:
- fixed EIO handling, need to reallocate bio instead of reusing it
- Updated according to David Sterba's review
- don't clobber bi_flags on reuse, just set UPTODATE
- allocate long living bios with bio_kmalloc instead of bio_alloc
--- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 14 + fs/btrfs/scrub.c | 1497 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1512 insertions(+), 1 deletions(-)
fs/btrfs/Makefile +1 -1
@@ -7,4 +7,4 @@ 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 + compression.o delayed-ref.o relocation.o scrub.o
fs/btrfs/ctree.h +14 -0
@@ -2610,4 +2610,18 @@ void btrfs_reloc_pre_snapshot(struct btrfs_trans_handle *trans, u64 *bytes_to_reserve);void btrfs_reloc_post_snapshot (struct btrfs_trans_handle *trans,struct btrfs_pending_snapshot *pending); + +/* scrub.c */ +int btrfs_scrub_dev (struct btrfs_root *root,u64 devid,u64 start,u64 end, +struct btrfs_scrub_progress *progress); +int btrfs_scrub_pause (struct btrfs_root *root); +int btrfs_scrub_pause_super (struct btrfs_root *root); +int btrfs_scrub_continue (struct btrfs_root *root); +int btrfs_scrub_continue_super (struct btrfs_root *root); +int btrfs_scrub_cancel (struct btrfs_root *root); +int btrfs_scrub_cancel_dev (struct btrfs_root *root,struct btrfs_device *dev); +int btrfs_scrub_cancel_devid (struct btrfs_root *root,u64 devid); +int btrfs_scrub_progress (struct btrfs_root *root,u64 devid, +struct btrfs_scrub_progress *progress); +#endif
fs/btrfs/scrub.c new file +1497 -0
1,497 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
Quoted 15 lines · Arne Jansen
This is the main scrub code.
Updates v3:
- fixed EIO handling, need to reallocate bio instead of reusing it
- Updated according to David Sterba's review
- don't clobberbi_flagson reuse, just set UPTODATE
- allocate long living bios withbio_kmallocinstead ofbio_allocSigned-off-by Arne Jansen <[email protected]>--- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 14 + fs/btrfs/scrub.c | 1497 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1512 insertions(+), 1 deletions(-)
(snipped)
fs/btrfs/scrub.c line 858
Quoted 13 lines
fs/btrfs/scrub.c new file +13
-0+static noinline_for_stack int scrub_stripe(struct scrub_dev *sdev, +struct map_lookup *map,int num,u64 base,u64 length) +{ +struct btrfs_path *path; +struct btrfs_fs_info *fs_info = sdev->dev->dev_root->fs_info; +struct btrfs_root *root = fs_info->extent_root; +struct btrfs_root *csum_root = fs_info->csum_root; +struct btrfs_extent_item *extent; +u64 flags; +int ret; +int slot; +int i; +int nstripes;
It should be u64 nstripes. A few lines below you assign the stripe length, it is a 64 bit quantity, also do_div() expects a 64 bit dividend. This fixes a serious breakage on x86-32.
Overall, this function could use a good cleanup. I can send you a patch later unless you want to do it yourself.
fs/btrfs/scrub.c line 865
Quoted 7 lines
fs/btrfs/scrub.c new file +7
-0+int start_stripe; +struct extent_buffer *l; +struct btrfs_key key; +u64 physical; +u64 logical; +u64 generation; +u64 mirror_num;
And a minor thing on the whole series: u64 should be printed with %llu and explicit casting to unsigned long long.
Thanks,
Ilya
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
Quoted 8 lines · Ilya Dryomov
fs/btrfs/scrub.c line 858
Quoted 3 lines · Arne Jansen
This is the main scrub code.
fs/btrfs/scrub.c new file +1
-0+int nstripes;It should be u64 nstripes. A few lines below you assign the stripe length, it is a 64 bit quantity, also
do_div()expects a 64 bit dividend. This fixes a serious breakage on x86-32.
Thanks.
Quoted 3 lines
Overall, this function could use a good cleanup. I can send you a patch later unless you want to do it yourself.
Which parts do you have in mind? I see only potential for minor cleanup, but as I wrote it, I might as well be blind to it ;) So when you send the patch I'll probably see what you mean.
The part I'm not content with is the prefetching, as it is still too slow.
Quoted 11 lines
fs/btrfs/scrub.c line 865
Quoted 8 lines
fs/btrfs/scrub.c new file +7
-0+int start_stripe; +struct extent_buffer *l; +struct btrfs_key key; +u64 physical; +u64 logical; +u64 generation; +u64 mirror_num;And a minor thing on the whole series: u64 should be printed with %llu and explicit casting to unsigned long long.
fixed.
Quoted 6 lines
Thanks,
Ilya
Quoted 1 line
--
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
In reply to Arne JansenOn Sat, Mar 12, 2011 at 03:50:42PM +0100, Arne Jansen wrote:
All extent maps are leaked after unmount. lookup_extent_mapping() takes a reference, so they are all left with em->refs = 1. I suggest the following:
Quoted 21 lines
fs/btrfs/scrub.c new file +21
-0+static noinline_for_stack int scrub_chunk(struct scrub_dev *sdev, +u64 chunk_tree,u64 chunk_objectid,u64 chunk_offset,u64 length) +{ +struct btrfs_mapping_tree *map_tree = + &sdev->dev->dev_root->fs_info->mapping_tree; +struct map_lookup *map; +struct extent_map *em; +int i; +int ret; + +read_lock (&map_tree->map_tree.lock); + em =lookup_extent_mapping (&map_tree->map_tree, chunk_offset,1 ); +read_unlock (&map_tree->map_tree.lock); + +if (!em) +return -EINVAL ; + + map = (struct map_lookup *)em->bdev; +if (em->start != chunk_offset) +return -EINVAL ; +
fs/btrfs/scrub.c line 1134
Quoted 10 lines
fs/btrfs/scrub.c new file +10
-0+if (em->len < length) +return -EINVAL ; + +for (i =0 ; i < map->num_stripes; ++i) { +if (map->stripes[i].dev == sdev->dev) { + ret =scrub_stripe (sdev, map, i, chunk_offset, length); +if (ret) +return ret; + } + }
+ free_extent_map(em);
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
Thanks,
Ilya
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
Sorry, that was too fast. Here is the right patch.
fs/btrfs/scrub.c +14 -7
@@ -1111,7 +1111,7 @@ static noinline_for_stack int scrub_chunk(struct scrub_dev *sdev,struct map_lookup *map;struct extent_map *em;int i; -int ret; +int ret =0 ;read_lock (&map_tree->map_tree.lock); em =lookup_extent_mapping (&map_tree->map_tree, chunk_offset,1 );
@@ -1121,20 +1121,27 @@ static noinline_for_stack int scrub_chunk(struct scrub_dev *sdev,return -EINVAL ; map = (struct map_lookup *)em->bdev; -if (em->start != chunk_offset) -return -EINVAL ; +if (em->start != chunk_offset) { + ret = -EINVAL ; + goto out; + } -if (em->len < length) -return -EINVAL ; +if (em->len < length) { + ret = -EINVAL ; + goto out; + }for (i =0 ; i < map->num_stripes; ++i) {if (map->stripes[i].dev == sdev->dev) { ret =scrub_stripe (sdev, map, i, chunk_offset, length);if (ret) -return ret; + goto out; } } -return 0 ; + +out: +free_extent_map (em); +return ret; } static noinline_for_stack
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
In reply to Arne Jansenfs/btrfs/scrub.c line 254
Quoted 4 lines · Arne Jansen
fs/btrfs/scrub.c new file +4
-0+*/ +mutex_lock (&fs_info->scrub_lock); +atomic_inc (&fs_info->scrubs_running); +mutex_unlock (&fs_info->scrub_lock);
It seems odd to protect an atomic_inc with a mutex. Is that done for some side effect? Otherwise you either don't need atomic or don't need the lock.
That seems to be all over the source file.
fs/btrfs/scrub.c line 1380
Quoted 4 lines
fs/btrfs/scrub.c new file +4
-0+int btrfs_scrub_pause (struct btrfs_root *root) +{ +struct btrfs_fs_info *fs_info = root->fs_info; +mutex_lock (&fs_info->scrub_lock);
As I understand it you take that mutex on every transaction commit, which is a fast path for normal IO.
For me that looks like a scalability problem with enough cores. Did you do any performance testing of this on a system with a reasonable number of cores?
btrfs already has enough scalability problems, please don't add new ones.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
Quoted 9 lines · Andi Kleen
fs/btrfs/scrub.c line 254
Quoted 4 lines · Arne Jansen
fs/btrfs/scrub.c new file +4
-0+*/ +mutex_lock (&fs_info->scrub_lock); +atomic_inc (&fs_info->scrubs_running); +mutex_unlock (&fs_info->scrub_lock);It seems odd to protect an
atomic_incwith a mutex. Is that done for some side effect? Otherwise you either don't need atomic or don't need the lock.
The reason it is atomic is because it is checked inside a wait_event, where I can't hold a lock. The mutex is there to protect the check in btrfs_scrub_pause and btrfs_scrub_cancel. But, now that I think of it, there is still a race condition left. I'll rethink the locking there and see if I can eliminate some of the mutex_locks.
Quoted 10 lines
That seems to be all over the source file.
fs/btrfs/scrub.c line 1380
Quoted 4 lines
fs/btrfs/scrub.c new file +4
-0+int btrfs_scrub_pause (struct btrfs_root *root) +{ +struct btrfs_fs_info *fs_info = root->fs_info; +mutex_lock (&fs_info->scrub_lock);As I understand it you take that mutex on every transaction commit, which is a fast path for normal IO.
A transaction commit only happens every 30 seconds. At this point, all outstanding data gets flushed and the super blocks written. I only pause the scrub in a very late phase during commit. At this point, the commit is already single threaded.
Apart from that you can be sure that scrub will have an impact on the performance, as it keeps the disks at 100% busy.
To mitigate this, all scrub activity happens inside ioctls. The idea is that this way the user can control the impact of the scrub using ionice.
--Arne
Quoted 9 lines
For me that looks like a scalability problem with enough cores. Did you do any performance testing of this on a system with a reasonable number of cores?
btrfs already has enough scalability problems, please don't add new ones.
-Andi
Re: [PATCH v3 3/6] btrfs: add scrub code and prototypes
Quoted 10 lines · Arne Jansen
Quoted 9 lines · Andi Kleen
fs/btrfs/scrub.c line 254
Quoted 4 lines · Arne Jansen
fs/btrfs/scrub.c new file +4
-0+*/ +mutex_lock (&fs_info->scrub_lock); +atomic_inc (&fs_info->scrubs_running); +mutex_unlock (&fs_info->scrub_lock);It seems odd to protect an
atomic_incwith a mutex. Is that done for some side effect? Otherwise you either don't need atomic or don't need the lock.
Quoted 5 lines
The reason it is atomic is because it is checked inside a
wait_event, where I can't hold a lock. The mutex is there to protect the check inbtrfs_scrub_pauseandbtrfs_scrub_cancel. But, now that I think of it, there is still a race condition left. I'll rethink the locking there and see if I can eliminate some of themutex_locks.
On third look I can't find the race condition I thought was there... Just removing the locks around most inc/dec looks ok.
Thanks,
Arne
PATCH v3 4/6 btrfs: sync scrub with commit & device removal
In reply to Arne JansenThis adds several synchronizations:
- for a transaction commit, the scrub gets paused before the tree roots are committed until the super are safely on disk
- during a log commit, scrubbing of supers is disabled
- on unmount, the scrub gets cancelled
- on device removal, the scrub for the particular device gets cancelled
--- fs/btrfs/disk-io.c | 1 + fs/btrfs/transaction.c | 3 +++ fs/btrfs/tree-log.c | 2 ++ fs/btrfs/volumes.c | 2 ++ 4 files changed, 8 insertions(+), 0 deletions(-)
fs/btrfs/disk-io.c +1 -0
@@ -2493,6 +2493,7 @@ int close_ctree(struct btrfs_root *root) fs_info->closing =1 ;smp_mb (); +btrfs_scrub_cancel (root);btrfs_put_block_group_cache (fs_info);/*
fs/btrfs/transaction.c +3 -0
@@ -1310,6 +1310,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,WARN_ON (cur_trans != trans->transaction); +btrfs_scrub_pause (root);/* btrfs_commit_tree_roots is responsible for getting the * various roots consistent with each other. Every pointer * in the tree of tree roots has to point to the most up to date
@@ -1391,6 +1392,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,mutex_unlock (&root->fs_info->trans_mutex); +btrfs_scrub_continue (root); +if (current->journal_info == trans) current->journal_info =NULL ;
fs/btrfs/tree-log.c +2 -0
@@ -2098,7 +2098,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,* the running transaction open, so a full commit can't hop * in and cause problems either. */ +btrfs_scrub_pause_super (root);write_ctree_super (trans, root->fs_info->tree_root,1 ); +btrfs_scrub_continue_super (root); ret =0 ;mutex_lock (&root->log_mutex);
fs/btrfs/volumes.c +2 -0
@@ -1330,6 +1330,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) goto error_undo; device->in_fs_metadata =0 ; +smp_mb (); +btrfs_scrub_cancel_dev (root, device);/* * the device list mutex makes sure that we don't change
Signature · 1 line
1.7.3.4
PATCH v3 5/6 btrfs: add state information for scrub
In reply to Arne JansenAdd structures and state information needed for scrub
--- fs/btrfs/ctree.h | 25 +++++++++++++++++++++++++ fs/btrfs/disk-io.c | 15 +++++++++++++++ fs/btrfs/ioctl.h | 17 +++++++++++++++++ fs/btrfs/volumes.h | 3 +++ 4 files changed, 60 insertions(+), 0 deletions(-)
fs/btrfs/ctree.h +25 -0
@@ -23,6 +23,7 @@#include <linux/mm.h> #include <linux/highmem.h> #include <linux/fs.h> +#include <linux/rwsem.h> #include <linux/completion.h> #include <linux/backing-dev.h> #include <linux/wait.h>
@@ -32,6 +33,7 @@#include "extent_io.h" #include "extent_map.h" #include "async-thread.h" +#include "ioctl.h" struct btrfs_trans_handle ;struct btrfs_transaction ;
@@ -48,6 +50,8 @@ struct btrfs_ordered_sum;#define BTRFS_COMPAT_EXTENT_TREE_V0 +#define SCRUB_BTRFS_WORKER +/* * files bigger than this get some pre-flushing when they are added * to the ordered operations list. That way we limit the total
@@ -508,6 +512,12 @@ struct btrfs_extent_item_v0 {/* use full backrefs for extent pointers in the block */ #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8) +/* +* this flag is only used internally by scrub and may be changed at any time +* it is only declared here to avoid collisions +*/ +#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48) +struct btrfs_tree_block_info {struct btrfs_disk_key key;u8 level;
@@ -1067,6 +1077,21 @@ struct btrfs_fs_info {void *bdev_holder; +/* private scrub information */ +struct mutex scrub_lock; +atomic_t scrubs_running; +atomic_t scrub_pause_req; +atomic_t scrubs_paused; +atomic_t scrub_cancel_req; +wait_queue_head_t scrub_pause_wait; +struct rw_semaphore scrub_super_lock; +int scrub_workers_refcnt; +#ifdef SCRUB_BTRFS_WORKER +struct btrfs_workers scrub_workers; +#else +struct workqueue_struct *scrub_workers; +#endif +/* filesystem state */ u64 fs_state; };
fs/btrfs/disk-io.c +15 -0
@@ -1677,6 +1677,21 @@ struct btrfs_root *open_ctree(struct super_block *sb,INIT_LIST_HEAD (&fs_info->ordered_extents);spin_lock_init (&fs_info->ordered_extent_lock); +mutex_init (&fs_info->scrub_lock); +atomic_set (&fs_info->scrubs_running,0 ); +atomic_set (&fs_info->scrub_pause_req,0 ); +atomic_set (&fs_info->scrubs_paused,0 ); +atomic_set (&fs_info->scrub_cancel_req,0 ); +init_waitqueue_head (&fs_info->scrub_pause_wait); +init_rwsem (&fs_info->scrub_super_lock); + fs_info->scrub_workers_refcnt =0 ; +#ifdef SCRUB_BTRFS_WORKER +btrfs_init_workers (&fs_info->scrub_workers,"scrub" , + fs_info->thread_pool_size, &fs_info->generic_worker); +#else + fs_info->scrub_workers =NULL ; +#endif + sb->s_blocksize =4096 ; sb->s_blocksize_bits =blksize_bits (4096 ); sb->s_bdi = &fs_info->bdi;
fs/btrfs/ioctl.h +17 -0
@@ -42,6 +42,23 @@ struct btrfs_ioctl_vol_args_v2 {char name[BTRFS_SUBVOL_NAME_MAX +1 ]; }; +struct btrfs_scrub_progress { +__u64 data_extents_scrubbed; +__u64 tree_extents_scrubbed; +__u64 data_bytes_scrubbed; +__u64 tree_bytes_scrubbed; +__u64 read_errors; +__u64 csum_errors; +__u64 verify_errors; +__u64 no_csum; +__u64 csum_discards; +__u64 super_errors; +__u64 malloc_errors; +__u64 uncorrectable_errors; +__u64 corrected_errors; +__u64 last_physical; +}; +#define BTRFS_INO_LOOKUP_PATH_MAX 4080struct btrfs_ioctl_ino_lookup_args {__u64 treeid;
fs/btrfs/volumes.h +3 -0
@@ -86,6 +86,9 @@ struct btrfs_device {/* physical drive uuid (or lvm uuid) */ u8 uuid[BTRFS_UUID_SIZE ]; +/* per-device scrub information */ +struct scrub_dev *scrub_device; +struct btrfs_work work; };
Signature · 1 line
1.7.3.4
PATCH v3 6/6 btrfs: new ioctls for scrub
In reply to Arne JansenFrom: Jan Schmidt <[email protected]>
adds ioctls necessary to start and cancel scrubs, to get current progress and to get info about devices to be scrubbed. Note that the scrub is done per-device and that the ioctl only returns after the scrub for this devices is finished or has been canceled.
--- fs/btrfs/ctree.h | 2 - fs/btrfs/ioctl.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 38 ++++++++++++++++ 3 files changed, 169 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +0 -2
@@ -189,7 +189,6 @@ struct btrfs_mapping_tree {struct extent_map_tree map_tree; }; -#define BTRFS_UUID_SIZE 16struct btrfs_dev_item {/* the internal btrfs device id */ __le64 devid;
@@ -296,7 +295,6 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)sizeof (struct btrfs_stripe ) * (num_stripes -1 ); } -#define BTRFS_FSID_SIZE 16#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
fs/btrfs/ioctl.c +131 -0
155 lines not on this page · raw message
fs/btrfs/ioctl.h +38 -0
@@ -32,6 +32,8 @@ struct btrfs_ioctl_vol_args {#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)#define BTRFS_SUBVOL_RDONLY (1ULL << 1) +#define BTRFS_FSID_SIZE 16 +#define BTRFS_UUID_SIZE 16#define BTRFS_SUBVOL_NAME_MAX 4039struct btrfs_ioctl_vol_args_v2 {
@@ -59,6 +61,33 @@ struct btrfs_scrub_progress {__u64 last_physical; }; +struct btrfs_ioctl_scrub_args { +__u64 devid;/* in */ +__u64 start;/* in */ +__u64 end;/* in */ +__u64 flags;/* in */ +struct btrfs_scrub_progress progress;/* out */ +/* pad to 1k */ +__u64 unused[(1024 -32 -sizeof (struct btrfs_scrub_progress ))/8 ]; +}; + +#define BTRFS_DEVICE_PATH_NAME_MAX 1024 +struct btrfs_ioctl_dev_info_args { +__u64 devid;/* in/out */ +__u8 uuid[BTRFS_UUID_SIZE ];/* in/out */ +__u64 bytes_used;/* out */ +__u64 total_bytes;/* out */ +__u64 unused[379 ];/* pad to 4k */ +__u8 path[BTRFS_DEVICE_PATH_NAME_MAX ];/* out */ +}; + +struct btrfs_ioctl_fs_info_args { +__u64 max_id;/* out */ +__u64 num_devices;/* out */ +__u8 fsid[BTRFS_FSID_SIZE ];/* out */ +__u64 reserved[124 ];/* pad to 1k */ +}; +#define BTRFS_INO_LOOKUP_PATH_MAX 4080struct btrfs_ioctl_ino_lookup_args {__u64 treeid;
@@ -220,4 +249,13 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args_v2)#define BTRFS_IOC_SUBVOL_GETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 25, __u64)#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) +#define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \ + struct btrfs_ioctl_scrub_args) +#define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) +#define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \ + struct btrfs_ioctl_scrub_args) +#define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \ + struct btrfs_ioctl_dev_info_args) +#define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \ + struct btrfs_ioctl_fs_info_args)#endif
Signature · 1 line
1.7.3.4