[2.6.29-rc2] insert_dir_item hitting assertion during log replay
When rebooting from a crash, thus during log replay on 2.6.29-rc2, btrfs_insert_dir_item caused an assertion failure [1]. The fs was being mounted clear_cache on an SSD. Probably it's not so easy to reproduce, but better to report it... --- [1] kernel BUG at fs/btrfs/inode.c:4665! invalid opcode: [#1] PREEMPT SMP DEBUG_PAGEALLOC last sysfs file: /sys/devices/virtual/wmi/A80593CE-A997-11DA-B012-B622A1EF5492/uevent CPU 3 Modules linked in: video sdhci_pci sdhci mmc_core Pid: 328, comm: mount Not tainted 2.6.39-rc2-350cd+ #1 Dell Inc. Latitude E5420/0H5TG2 RIP: 0010:[812a2962] [812a2962] btrfs_add_link+0x132/0x190 RSP: 0018:88021e1097d8 EFLAGS: 00010282 RAX: ffef RBX: 88021d965f70 RCX: 0006 RDX: ffef RSI: 88021efe4710 RDI: 88021efe4020 RBP: 88021e109848 R08: R09: 88022d7c03f0 R10: 0001 R11: 0001 R12: 88021d966720 R13: 88021e0261b0 R14: 000f R15: 88021d959000 FS: 7fcee7b3d800() GS:88022ec6() knlGS: CS: 0010 DS: ES: CR0: 8005003b CR2: 7f5e5700 CR3: 00021e6ef000 CR4: 000406e0 DR0: DR1: DR2: DR3: DR6: 0ff0 DR7: 0400 Process mount (pid: 328, threadinfo 88021e108000, task 88021efe4020) Stack: 88020001 0016 88021e109978 0016 0010555e 0001 1000 88021e03a000 00b0 88021e109ae8 Call Trace: [812ccb45] add_inode_ref+0x2f5/0x3b0 [81058e61] ? get_parent_ip+0x11/0x50 [812cdff6] replay_one_buffer+0x2c6/0x3a0 [81099fd0] ? mark_held_locks+0x70/0xa0 [81058e61] ? get_parent_ip+0x11/0x50 [812ca978] walk_up_log_tree+0x168/0x320 [812cdd30] ? replay_one_dir_item+0xe0/0xe0 [812cb188] walk_log_tree+0xe8/0x290 [8109a18d] ? trace_hardirqs_on+0xd/0x10 [812d] btrfs_recover_log_trees+0x220/0x320 [812cdd30] ? replay_one_dir_item+0xe0/0xe0 [81295521] open_ctree+0x1301/0x16b0 [81331ab4] ? snprintf+0x34/0x40 [812701e3] btrfs_fill_super.clone.14+0x73/0x130 [811a4aaf] ? disk_name+0x5f/0xc0 [8132ef77] ? strlcpy+0x47/0x60 [812705e0] btrfs_mount+0x340/0x3e0 [81143e9b] mount_fs+0x1b/0xd0 [8115fece] vfs_kern_mount+0x5e/0xd0 [8116045f] do_kern_mount+0x4f/0x100 [81161ea4] do_mount+0x1e4/0x220 [8116228b] sys_mount+0x8b/0xe0 [8170adfb] system_call_fastpath+0x16/0x1b Code: 4c 89 d2 44 89 f1 4c 89 ee 4c 89 1c 24 4c 89 55 a8 4c 89 5d a0 e8 5f c6 fe ff 4c 8b 5d a0 4c 8b 55 a8 85 c0 75 bc e9 31 ff ff ff 0f 0b 48 8b b2 d0 fc ff ff 48 8d 7d b0 b9 11 00 00 00 4d 89 d9 RIP [812a2962] btrfs_add_link+0x132/0x190 RSP 88021e1097d8 -- Daniel J Blueman -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
btrfs does not work on usermode linux
According to https://btrfs.wiki.kernel.org/index.php/Debugging_Btrfs_with_GDB UML did work once. Now it corrupts data and triggers BUG_ON once you start to use it. I tried both 2.6.38 and 2.6.39-rc2 (x86_64) I need some help to track it down. doing 'touch `seq 1 11`; rm 11' kills the kernel: #run mount -t btrfs /dev/ubda /mnt/btr/ [2.22] device fsid 754599771c9b69eb-66689f77c1542bb9 devid 1 transid 7 /dev/ubda #status: 0 #run cd /mnt/btr/ #status: 0 touching files 1 .. 11 #run touch 1 2 3 4 5 6 7 8 9 10 11 #status: 0 #run ls [2.22] btrfS: invalid dir item name len: 12594 [2.22] btrfS: invalid dir item name len: 0 [2.22] btrfS: invalid dir item name len: 0 11 #status: 0 Fasten your belts: removing file 11 #run rm 11 [2.22] btrfs failed to delete reference to 11, inode 267 parent 256 [2.22] Kernel panic - not syncing: Kernel mode signal 4 [2.22] Call Trace: [2.22] 6024b918: [601b2567] panic+0xea/0x1dc [2.22] 6024b9c8: [601b491e] _raw_spin_unlock_irqrestore+0x18/0x1c [2.22] 6024b9e8: [60017d00] free_irqs+0x74/0xde [2.22] 6024ba18: [60015faa] relay_signal+0x38/0x79 [2.22] 6024ba28: [60013c8e] sigio_handler+0x5a/0x60 [2.22] 6024ba48: [6001f224] sig_handler_common+0x84/0x98 [2.22] 6024ba68: [6001f2d1] real_alarm_handler+0x3c/0x3e [2.22] 6024baf0: [600579f7] get_page_from_freelist+0x129/0x478 [2.22] 6024bb78: [6001f36a] sig_handler+0x30/0x3b [2.22] 6024bb98: [6001f59c] handle_signal+0x6d/0xa3 [2.22] 6024bbe8: [600203b0] hard_handler+0x10/0x14 [2.22] 6024bca8: [600e04c3] btrfs_unlink+0x77/0xef == I've cooked whole root into small archive (3.1MB): https://slyfox.ath.cx/btrfs/linux-2.6-um-x86_64-fs.tar.gz You just need to start './run' to enter into UML root fs and there to issue ./kill_btr to get fault above. Archive contains minimal .config for kernel 2.6.39-rc2, statically linked busybox binary and fresh image of btrfs. It also has tiny script, which will help you to generate the same rootfs if you are afraid to run suspicious binaries. -- Sergei signature.asc Description: PGP signature
Re: btrfs does not work on usermode linux
On Sun, 10 Apr 2011 13:37:10 +0300 Sergei Trofimovich sly...@gmail.com wrote: According to https://btrfs.wiki.kernel.org/index.php/Debugging_Btrfs_with_GDB UML did work once. Now it corrupts data and triggers BUG_ON once you start to use it. I tried both 2.6.38 and 2.6.39-rc2 (x86_64) I need some help to track it down. doing 'touch `seq 1 11`; rm 11' kills the kernel: 2.6.36 works 2.6.37 doesn't. bsecting -- Sergei signature.asc Description: PGP signature
Re: btrfs does not work on usermode linux
According to https://btrfs.wiki.kernel.org/index.php/Debugging_Btrfs_with_GDB UML did work once. Now it corrupts data and triggers BUG_ON once you start to use it. I tried both 2.6.38 and 2.6.39-rc2 (x86_64) I need some help to track it down. doing 'touch `seq 1 11`; rm 11' kills the kernel: 2.6.36 works 2.6.37 doesn't. bsecting Bisected down to: commit 59daa706fbec745684702741b9f5373142dd9fdc (v2.6.36-rc2-2-g59daa70) Author: Ma Ling ling...@intel.com Date: Tue Jun 29 03:24:25 2010 +0800 x86, mem: Optimize memcpy by avoiding memory false dependece Which means btrfs passes overlapping areas to memcpy. I've added some debug info and found out rough place: touching files 1 .. 11 #run touch 1 2 3 4 5 6 7 8 9 10 11 [2.27] memcpy overlap detected: memcpy(dst=70654e8a, src=70654ea9, size=171) [delta=31] [2.27] [ cut here ] [2.27] WARNING: at /home/slyfox/linux-2.6/fs/btrfs/memcpy_debug.c:18 btrfs_memcpy+0x52/0x68() [2.27] Call Trace: [2.27] 7064b748: [600eff46] map_extent_buffer+0x62/0x9e [2.27] 7064b758: [60029ad9] warn_slowpath_common+0x59/0x70 [2.27] 7064b798: [60029b05] warn_slowpath_null+0x15/0x17 [2.27] 7064b7a8: [6011129e] btrfs_memcpy+0x52/0x68 [2.27] 7064b7d8: [600efa01] memcpy_extent_buffer+0x18d/0x1da [2.27] 7064b858: [600efae2] memmove_extent_buffer+0x94/0x208 [2.27] 7064b8d8: [600bc4b0] setup_items_for_insert+0x2b8/0x426 [2.27] 7064b8e8: [600bb25a] btrfs_leaf_free_space+0x62/0xa6 [2.27] 7064b9c8: [600c13f3] btrfs_insert_empty_items+0xa3/0xb5 [2.27] 7064ba38: [600ce690] insert_with_overflow+0x33/0xf1 [2.27] 7064ba88: [600ce7d4] btrfs_insert_dir_item+0x86/0x268 [2.27] 7064bae8: [601b498b] _raw_spin_unlock+0x9/0xb [2.27] 7064bb48: [600ddef1] btrfs_add_link+0x10d/0x170 [2.27] 7064bbc8: [600ddf7a] btrfs_add_nondir+0x26/0x52 [2.27] 7064bc08: [600de73f] btrfs_create+0xf2/0x1c0 [2.27] 7064bc18: [6007ccff] generic_permission+0x57/0x9d [2.27] 7064bc68: [6007cf60] vfs_create+0x6a/0x75 which is in extent_io:copy_pages. I haven't dig further only made sure the following patch below (practically converts copy_pages to move_pages). It certainly does not look the right thing, but I don't understand extent_io contents yet to understand what actually happened. diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 20ddb28..4cab7db 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3893,14 +3893,17 @@ static void copy_pages(struct page *dst_page, struct page *src_page, char *src_kaddr; if (dst_page != src_page) + { src_kaddr = kmap_atomic(src_page, KM_USER1); + memcpy(dst_kaddr + dst_off, src_kaddr + src_off, len); + kunmap_atomic(src_kaddr, KM_USER1); + } else + { src_kaddr = dst_kaddr; - - memcpy(dst_kaddr + dst_off, src_kaddr + src_off, len); + memmove(dst_kaddr + dst_off, src_kaddr + src_off, len); + } kunmap_atomic(dst_kaddr, KM_USER0); - if (dst_page != src_page) - kunmap_atomic(src_kaddr, KM_USER1); } void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, -- Sergei signature.asc Description: PGP signature
[PATCH v2] Re: btrfs does not work on usermode linux
On Sun, 10 Apr 2011 23:24:03 +0300 Sergei Trofimovich sly...@gmail.com wrote: Fix data corruption caused by memcpy() usage on overlapping data. I've observed it first when found out usermode linux crash on btrfs. Changes since v1: else src_kaddr = dst_kaddr; + BUG_ON(abs(src_off - dst_off) len); memcpy(dst_kaddr + dst_off, src_kaddr + src_off, len); Too eager BUG_ON. Now used only for src_page == dst_page. - if (dst_offset src_offset) { + if (abs(dst_offset - src_offset) = len) { abs() is not a good thing to use un unsigned values. aded helper overlapping_areas. -- Sergei From 2ac9dd9cc54cee51c5c5219e35cca18a9f3f3a3f Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich sly...@gentoo.org Date: Sun, 10 Apr 2011 23:19:53 +0300 Subject: [PATCH] btrfs: properly handle overlapping areas in memmove_extent_buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix data corruption caused by memcpy() usage on overlapping data. I've observed it first when found out usermode linux crash on btrfs. Сall chain is the following: [ cut here ] WARNING: at /home/slyfox/linux-2.6/fs/btrfs/extent_io.c:3900 memcpy_extent_buffer+0x1a5/0x219() Call Trace: 6fa39a58: [601b495e] _raw_spin_unlock_irqrestore+0x18/0x1c 6fa39a68: [60029ad9] warn_slowpath_common+0x59/0x70 6fa39aa8: [60029b05] warn_slowpath_null+0x15/0x17 6fa39ab8: [600efc97] memcpy_extent_buffer+0x1a5/0x219 6fa39b48: [600efd9f] memmove_extent_buffer+0x94/0x208 6fa39bc8: [600becbf] btrfs_del_items+0x214/0x473 6fa39c78: [600ce1b0] btrfs_delete_one_dir_name+0x7c/0xda 6fa39cc8: [600dad6b] __btrfs_unlink_inode+0xad/0x25d 6fa39d08: [600d7864] btrfs_start_transaction+0xe/0x10 6fa39d48: [600dc9ff] btrfs_unlink_inode+0x1b/0x3b 6fa39d78: [600e04bc] btrfs_unlink+0x70/0xef 6fa39dc8: [6007f0d0] vfs_unlink+0x58/0xa3 6fa39df8: [60080278] do_unlinkat+0xd4/0x162 6fa39e48: [600517db] call_rcu_sched+0xe/0x10 6fa39e58: [600452a8] __put_cred+0x58/0x5a 6fa39e78: [6007446c] sys_faccessat+0x154/0x166 6fa39ed8: [60080317] sys_unlink+0x11/0x13 6fa39ee8: [60016b80] handle_syscall+0x58/0x70 6fa39f08: [60021377] userspace+0x2d4/0x381 6fa39fc8: [60014507] fork_handler+0x62/0x69 ---[ end trace 70b0ca2ef0266b93 ]--- http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg09302.html Signed-off-by: Sergei Trofimovich sly...@gentoo.org --- fs/btrfs/extent_io.c | 11 ++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 20ddb28..786a0f7 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3878,31 +3878,40 @@ static void move_pages(struct page *dst_page, struct page *src_page, char *s = src_kaddr + src_off + len; while (len--) *--p = *--s; kunmap_atomic(src_kaddr, KM_USER1); } kunmap_atomic(dst_kaddr, KM_USER0); } +static inline bool areas_overlap(unsigned long src, unsigned long dst, unsigned long len) +{ + unsigned long distance = (src dst) ? src - dst : dst - src; + return distance len; +} + static void copy_pages(struct page *dst_page, struct page *src_page, unsigned long dst_off, unsigned long src_off, unsigned long len) { char *dst_kaddr = kmap_atomic(dst_page, KM_USER0); char *src_kaddr; if (dst_page != src_page) src_kaddr = kmap_atomic(src_page, KM_USER1); else + { src_kaddr = dst_kaddr; + BUG_ON(areas_overlap(src_off, dst_off, len)); + } memcpy(dst_kaddr + dst_off, src_kaddr + src_off, len); kunmap_atomic(dst_kaddr, KM_USER0); if (dst_page != src_page) kunmap_atomic(src_kaddr, KM_USER1); } void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, unsigned long src_offset, unsigned long len) { @@ -3963,21 +3972,21 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, if (src_offset + len dst-len) { printk(KERN_ERR btrfs memmove bogus src_offset %lu move len %lu len %lu\n, src_offset, len, dst-len); BUG_ON(1); } if (dst_offset + len dst-len) { printk(KERN_ERR btrfs memmove bogus dst_offset %lu move len %lu len %lu\n, dst_offset, len, dst-len); BUG_ON(1); } - if (dst_offset src_offset) { + if (!areas_overlap(src_offset, dst_offset, len)) { memcpy_extent_buffer(dst, dst_offset, src_offset, len); return; } while (len 0) { dst_i = (start_offset + dst_end) PAGE_CACHE_SHIFT; src_i = (start_offset + src_end) PAGE_CACHE_SHIFT; dst_off_in_page = (start_offset + dst_end) ((unsigned long)PAGE_CACHE_SIZE - 1); src_off_in_page = (start_offset + src_end) -- 1.7.3.4 signature.asc Description: PGP signature
[PATCH v5 6/8] btrfs: Balance filter for virtual address ranges
Allow the balancing of chunks where some part of the chunk lies within the virtual (i.e. btrfs-internal) address range passed. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/ioctl.h |9 +++-- fs/btrfs/volumes.c |6 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 54523c0..50d4801 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -167,7 +167,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 1) #define BTRFS_BALANCE_FILTER_DEVID (1 2) -#define BTRFS_BALANCE_FILTER_MASK ((1 3) - 1) /* Logical or of all filter +#define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE (1 3) +#define BTRFS_BALANCE_FILTER_MASK ((1 4) - 1) /* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */ @@ -187,7 +188,11 @@ struct btrfs_ioctl_balance_start { /* For FILTER_DEVID */ __u64 devid; - __u64 spare[505]; /* Make up the size of the structure to 4088 + /* For FILTER_VIRTUAL_ADDRESS_RANGE */ + __u64 vrange_start; + __u64 vrange_end; + + __u64 spare[503]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e7fa2ab..230d100 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2070,6 +2070,12 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, if (!res) return 0; } + if (filter-flags BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE) { + u64 start = key-offset; + u64 end = start + btrfs_chunk_length(eb, chunk); + if (filter-vrange_start = end || start = filter-vrange_end) + return 0; + } return 1; } -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 8/8] btrfs: Balance filter for physical device address
Add a filter for balancing which allows the selection of chunks with data in the given byte range on any block device in the filesystem. On its own, this filter is of little use, but when used with the devid filter, it can be used to rebalance all chunks which lie on a part of a specific device. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/ioctl.h |9 +++-- fs/btrfs/volumes.c | 19 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 50d4801..a037714 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -168,7 +168,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 1) #define BTRFS_BALANCE_FILTER_DEVID (1 2) #define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE (1 3) -#define BTRFS_BALANCE_FILTER_MASK ((1 4) - 1) /* Logical or of all filter +#define BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE (1 4) +#define BTRFS_BALANCE_FILTER_MASK ((1 5) - 1) /* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */ @@ -192,7 +193,11 @@ struct btrfs_ioctl_balance_start { __u64 vrange_start; __u64 vrange_end; - __u64 spare[503]; /* Make up the size of the structure to 4088 + /* For FILTER_DEVICE_ADDRESS_RANGE */ + __u64 drange_start; + __u64 drange_end; + + __u64 spare[501]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9216ad85..19dc117 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2124,6 +2124,25 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, if (filter-vrange_start = end || start = filter-vrange_end) return 0; } + if (filter-flags BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE) { + int num_stripes = btrfs_chunk_num_stripes(eb, chunk); + int stripe_length = btrfs_chunk_length(eb, chunk) + * num_stripes / replinfo.num_copies; + int res = 0; + + for (i = 0; i num_stripes; i++) { + struct btrfs_stripe *stripe = btrfs_stripe_nr(chunk, i); + u64 start = btrfs_stripe_offset(eb, stripe); + u64 end = start + stripe_length; + if (filter-drange_start end +start filter-drange_end) { + res = 1; + break; + } + } + if (!res) + return 0; + } return 1; } -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 0/8] Balance mangement
Hi, Chris, Another iteration of the balance management patches. This includes suggestions from David Sterba, who did a fairly comprehensive review of the patch series on IRC. It also includes fixes for comments from Josef, and Li Zefan. The only thing I've not included here is Li's suggestion of keeping track of the size of the chunks and the data in them -- I'm working on the patch for that, and it'll be along once I've had a chance to test it sensibly. Hugo. --- Hugo Mills (8): btrfs: Balance progress monitoring btrfs: Cancel filesystem balance btrfs: Factor out enumeration of chunks to a separate function btrfs: Implement filtered balance ioctl btrfs: Balance filter for device ID btrfs: Balance filter for virtual address ranges btrfs: Replication-type information btrfs: Balance filter for physical device address fs/btrfs/ctree.h | 10 ++ fs/btrfs/disk-io.c |2 + fs/btrfs/ioctl.c | 104 +++- fs/btrfs/ioctl.h | 49 +++ fs/btrfs/super.c | 16 +-- fs/btrfs/volumes.c | 354 +--- fs/btrfs/volumes.h | 21 +++- 7 files changed, 468 insertions(+), 88 deletions(-) -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 3/8] btrfs: Factor out enumeration of chunks to a separate function
The main balance function has two loops which are functionally identical in their looping mechanism, but which perform a different operation on the chunks they loop over. To avoid repeating code more than necessary, factor this loop out into a separate iterator function which takes a function parameter for the action to be performed. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/volumes.c | 174 +-- 1 files changed, 99 insertions(+), 75 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index cf019af..20c2772 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2029,6 +2029,97 @@ static u64 div_factor(u64 num, int factor) return num; } +/* Define a type, and two functions which can be used for the two + * phases of the balance operation: one for counting chunks, and one + * for actually moving them. */ +typedef void (*balance_iterator_function)(struct btrfs_root *, + struct btrfs_balance_info *, + struct btrfs_path *, + struct btrfs_key *); + +static void balance_count_chunks(struct btrfs_root *chunk_root, + struct btrfs_balance_info *bal_info, + struct btrfs_path *path, + struct btrfs_key *key) +{ + spin_lock(chunk_root-fs_info-balance_info_lock); + bal_info-expected++; + spin_unlock(chunk_root-fs_info-balance_info_lock); +} + +static void balance_move_chunks(struct btrfs_root *chunk_root, +struct btrfs_balance_info *bal_info, +struct btrfs_path *path, +struct btrfs_key *key) +{ + int ret; + + ret = btrfs_relocate_chunk(chunk_root, + chunk_root-root_key.objectid, + key-objectid, + key-offset); + BUG_ON(ret ret != -ENOSPC); + spin_lock(chunk_root-fs_info-balance_info_lock); + bal_info-completed++; + spin_unlock(chunk_root-fs_info-balance_info_lock); + printk(KERN_INFO btrfs: balance: %llu/%llu block groups completed\n, + bal_info-completed, bal_info-expected); +} + +/* Iterate through all chunks, performing some function on each one. */ +static int balance_iterate_chunks(struct btrfs_root *chunk_root, + struct btrfs_balance_info *bal_info, + balance_iterator_function iterator_fn) +{ + int ret = 0; + struct btrfs_path *path; + struct btrfs_key key; + struct btrfs_key found_key; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; + key.offset = (u64)-1; + key.type = BTRFS_CHUNK_ITEM_KEY; + + while (!bal_info-cancel_pending) { + ret = btrfs_search_slot(NULL, chunk_root, key, path, 0, 0); + if (ret 0) + break; + /* +* this shouldn't happen, it means the last relocate +* failed +*/ + if (ret == 0) + break; + + ret = btrfs_previous_item(chunk_root, path, 0, + BTRFS_CHUNK_ITEM_KEY); + if (ret) + break; + + btrfs_item_key_to_cpu(path-nodes[0], found_key, + path-slots[0]); + if (found_key.objectid != key.objectid) + break; + + /* chunk zero is special */ + if (found_key.offset == 0) + break; + + /* Call the function to do the work for this chunk */ + btrfs_release_path(chunk_root, path); + iterator_fn(chunk_root, bal_info, path, found_key); + + key.offset = found_key.offset - 1; + } + + btrfs_free_path(path); + return ret; +} + int btrfs_balance(struct btrfs_root *dev_root) { int ret; @@ -2036,11 +2127,8 @@ int btrfs_balance(struct btrfs_root *dev_root) struct btrfs_device *device; u64 old_size; u64 size_to_free; - struct btrfs_path *path; - struct btrfs_key key; struct btrfs_root *chunk_root = dev_root-fs_info-chunk_root; struct btrfs_trans_handle *trans; - struct btrfs_key found_key; struct btrfs_balance_info *bal_info; if (dev_root-fs_info-sb-s_flags MS_RDONLY) @@ -2061,8 +2149,7 @@ int btrfs_balance(struct btrfs_root *dev_root) } spin_lock(dev_root-fs_info-balance_info_lock); dev_root-fs_info-balance_info = bal_info; - bal_info-expected = -1; /* One less than actually counted, - because chunk 0 is special */ +
[PATCH v5 4/8] btrfs: Implement filtered balance ioctl
The filtered balance ioctl provides a facility to perform a balance operation on a subset of the chunks in the filesystem. This patch implements the base ioctl for this operation, and one filter type. The filter in this patch selects chunks on the basis of their chunk flags field, and can select any combination of bits set or unset. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/ioctl.c | 42 - fs/btrfs/ioctl.h | 27 + fs/btrfs/volumes.c | 65 +-- fs/btrfs/volumes.h |4 ++- 4 files changed, 128 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index aef6329..4bc4da2 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2433,6 +2433,44 @@ error: return err; } +long btrfs_ioctl_balance(struct btrfs_root *dev_root, +struct btrfs_ioctl_balance_start __user *user_filters) +{ + int ret = 0; + struct btrfs_ioctl_balance_start *dest; + + dest = kmalloc(sizeof(struct btrfs_ioctl_balance_start), GFP_KERNEL); + if (!dest) + return -ENOMEM; + + if (copy_from_user(dest, user_filters, + sizeof(struct btrfs_ioctl_balance_start))) { + ret = -EFAULT; + goto error; + } + + /* Basic sanity checking: has the user requested anything outside +* the range we know about? */ + if (dest-flags ~BTRFS_BALANCE_FILTER_MASK) { + ret = -ENOTSUPP; + goto error; + } + + /* Do the balance */ + ret = btrfs_balance(dev_root, dest); + if (ret) + goto error; + + if (copy_to_user(user_filters, dest, +sizeof(struct btrfs_ioctl_balance_start))) { + ret = -EFAULT; + } + +error: + kfree(dest); + return ret; +} + long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -2471,11 +2509,13 @@ long btrfs_ioctl(struct file *file, unsigned int case BTRFS_IOC_RM_DEV: return btrfs_ioctl_rm_dev(root, argp); case BTRFS_IOC_BALANCE: - return btrfs_balance(root-fs_info-dev_root); + return btrfs_ioctl_balance(root-fs_info-dev_root, NULL); case BTRFS_IOC_BALANCE_PROGRESS: return btrfs_ioctl_balance_progress(root-fs_info, argp); case BTRFS_IOC_BALANCE_CANCEL: return btrfs_ioctl_balance_cancel(root-fs_info); + case BTRFS_IOC_BALANCE_FILTERED: + return btrfs_ioctl_balance(root-fs_info-dev_root, argp); case BTRFS_IOC_CLONE: return btrfs_ioctl_clone(file, arg, 0, 0, 0); case BTRFS_IOC_CLONE_RANGE: diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 2c49add..eb91d20 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -162,6 +162,31 @@ struct btrfs_ioctl_balance_progress { __u32 completed; }; +/* Types of balance filter */ +#define BTRFS_BALANCE_FILTER_COUNT_ONLY (1 0) + +#define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 1) +#define BTRFS_BALANCE_FILTER_MASK ((1 2) - 1) /* Logical or of all filter + * flags -- effectively versions + * the filtered balance ioctl */ + +/* All the possible options for a filter */ +struct btrfs_ioctl_balance_start { + __u64 flags; /* Bit field indicating which fields of this struct + are filled */ + + /* Output values: chunk counts */ + __u64 examined; + __u64 balanced; + + /* For FILTER_CHUNK_TYPE */ + __u64 chunk_type; /* Flag bits required */ + __u64 chunk_type_mask; /* Mask of bits to examine */ + + __u64 spare[506]; /* Make up the size of the structure to 4088 + * bytes for future expansion */ +}; + #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args) #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ @@ -211,4 +236,6 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress) #define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) +#define BTRFS_IOC_BALANCE_FILTERED _IOWR(BTRFS_IOCTL_MAGIC, 29, \ + struct btrfs_ioctl_balance_start) #endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 20c2772..95c603a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2029,6 +2029,37 @@ static u64 div_factor(u64 num, int factor) return num; } +int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, +struct btrfs_root *chunk_root, +struct btrfs_path *path, +
[PATCH v5 5/8] btrfs: Balance filter for device ID
Balance filter to take only chunks which have (or had) a stripe on the given device. Useful if a device has been forcibly removed from the filesystem, and the data from that device needs rebuilding. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/ioctl.h |8 ++-- fs/btrfs/volumes.c | 16 +++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index eb91d20..54523c0 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -166,7 +166,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_COUNT_ONLY (1 0) #define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 1) -#define BTRFS_BALANCE_FILTER_MASK ((1 2) - 1) /* Logical or of all filter +#define BTRFS_BALANCE_FILTER_DEVID (1 2) +#define BTRFS_BALANCE_FILTER_MASK ((1 3) - 1) /* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */ @@ -183,7 +184,10 @@ struct btrfs_ioctl_balance_start { __u64 chunk_type; /* Flag bits required */ __u64 chunk_type_mask; /* Mask of bits to examine */ - __u64 spare[506]; /* Make up the size of the structure to 4088 + /* For FILTER_DEVID */ + __u64 devid; + + __u64 spare[505]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 95c603a..e7fa2ab 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2036,6 +2036,7 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, { struct extent_buffer *eb; struct btrfs_chunk *chunk; + int i; /* No filter defined, everything matches */ if (!filter) @@ -2056,8 +2057,21 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, return 0; } } + if (filter-flags BTRFS_BALANCE_FILTER_DEVID) { + int num_stripes = btrfs_chunk_num_stripes(eb, chunk); + int res = 0; + for (i = 0; i num_stripes; i++) { + struct btrfs_stripe *stripe = btrfs_stripe_nr(chunk, i); + if (btrfs_stripe_devid(eb, stripe) == filter-devid) { + res = 1; + break; + } + } + if (!res) + return 0; + } - return ret; + return 1; } /* Define a type, and two functions which can be used for the two -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 7/8] btrfs: Replication-type information
There are a few places in btrfs where knowledge of the various parameters of a replication type is needed. Factor this out into a single function which can supply all the relevant information. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/super.c | 16 +++- fs/btrfs/volumes.c | 97 +++- fs/btrfs/volumes.h | 17 + 3 files changed, 88 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d39a989..4341730 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -879,12 +879,12 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) struct btrfs_device_info *devices_info; struct btrfs_fs_devices *fs_devices = fs_info-fs_devices; struct btrfs_device *device; + struct btrfs_replication_info repl_info; u64 skip_space; u64 type; u64 avail_space; u64 used_space; u64 min_stripe_size; - int min_stripes = 1; int i = 0, nr_devices; int ret; @@ -898,12 +898,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) /* calc min stripe number for data space alloction */ type = btrfs_get_alloc_profile(root, 1); - if (type BTRFS_BLOCK_GROUP_RAID0) - min_stripes = 2; - else if (type BTRFS_BLOCK_GROUP_RAID1) - min_stripes = 2; - else if (type BTRFS_BLOCK_GROUP_RAID10) - min_stripes = 4; + btrfs_get_replication_info(repl_info, type); if (type BTRFS_BLOCK_GROUP_DUP) min_stripe_size = 2 * BTRFS_STRIPE_LEN; @@ -971,14 +966,15 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) i = nr_devices - 1; avail_space = 0; - while (nr_devices = min_stripes) { + while (nr_devices = repl_info.devs_min) { if (devices_info[i].max_avail = min_stripe_size) { int j; u64 alloc_size; - avail_space += devices_info[i].max_avail * min_stripes; + avail_space += devices_info[i].max_avail + * repl_info.devs_min; alloc_size = devices_info[i].max_avail; - for (j = i + 1 - min_stripes; j = i; j++) + for (j = i + 1 - repl_info.devs_min; j = i; j++) devices_info[j].max_avail -= alloc_size; } i--; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 230d100..9216ad85 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -141,6 +141,52 @@ static void requeue_list(struct btrfs_pending_bios *pending_bios, pending_bios-tail = tail; } +void btrfs_get_replication_info(struct btrfs_replication_info *info, + u64 type) +{ + info-sub_stripes = 1; + info-dev_stripes = 1; + info-devs_increment = 1; + info-num_copies = 1; + info-devs_max = 0; /* 0 == as many as possible */ + info-devs_min = 1; + + if (type BTRFS_BLOCK_GROUP_DUP) { + info-dev_stripes = 2; + info-num_copies = 2; + info-devs_max = 1; + } else if (type BTRFS_BLOCK_GROUP_RAID0) { + info-devs_min = 2; + } else if (type BTRFS_BLOCK_GROUP_RAID1) { + info-devs_increment = 2; + info-num_copies = 2; + info-devs_max = 2; + info-devs_min = 2; + } else if (type BTRFS_BLOCK_GROUP_RAID10) { + info-sub_stripes = 2; + info-devs_increment = 2; + info-num_copies = 2; + info-devs_min = 4; + } + + if (type BTRFS_BLOCK_GROUP_DATA) { + info-max_stripe_size = 1024 * 1024 * 1024; + info-min_stripe_size = 64 * 1024 * 1024; + info-max_chunk_size = 10 * info-max_stripe_size; + } else if (type BTRFS_BLOCK_GROUP_METADATA) { + info-max_stripe_size = 256 * 1024 * 1024; + info-min_stripe_size = 32 * 1024 * 1024; + info-max_chunk_size = info-max_stripe_size; + } else if (type BTRFS_BLOCK_GROUP_SYSTEM) { + info-max_stripe_size = 8 * 1024 * 1024; + info-min_stripe_size = 1 * 1024 * 1024; + info-max_chunk_size = 2 * info-max_stripe_size; + } else { + printk(KERN_ERR Block group is of an unknown usage type: not data, metadata or system.\n); + BUG_ON(1); + } +} + /* * we try to collect pending bios for a device so we don't get a large * number of procs sending bios down to the same device. This greatly @@ -1248,6 +1294,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) struct block_device *bdev;
[PATCH v5 1/8] btrfs: Balance progress monitoring
This patch introduces a basic form of progress monitoring for balance operations, by counting the number of block groups remaining. The information is exposed to userspace by an ioctl. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/ctree.h |9 fs/btrfs/disk-io.c |2 + fs/btrfs/ioctl.c | 34 +++ fs/btrfs/ioctl.h |7 ++ fs/btrfs/volumes.c | 56 ++- 5 files changed, 106 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 7f78cc7..17c7ecc 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -865,6 +865,11 @@ struct btrfs_block_group_cache { struct list_head cluster_list; }; +struct btrfs_balance_info { + u32 expected; + u32 completed; +}; + struct reloc_control; struct btrfs_device; struct btrfs_fs_devices; @@ -1078,6 +1083,10 @@ struct btrfs_fs_info { /* filesystem state */ u64 fs_state; + + /* Keep track of any rebalance operations on this FS */ + spinlock_t balance_info_lock; + struct btrfs_balance_info *balance_info; }; /* diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 100b07f..3d690de 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1645,6 +1645,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, spin_lock_init(fs_info-ref_cache_lock); spin_lock_init(fs_info-fs_roots_radix_lock); spin_lock_init(fs_info-delayed_iput_lock); + spin_lock_init(fs_info-balance_info_lock); init_completion(fs_info-kobj_unregister); fs_info-tree_root = tree_root; @@ -1670,6 +1671,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, fs_info-sb = sb; fs_info-max_inline = 8192 * 1024; fs_info-metadata_ratio = 0; + fs_info-balance_info = NULL; fs_info-thread_pool_size = min_t(unsigned long, num_online_cpus() + 2, 8); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 5fdb2ab..a8fbb07 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2375,6 +2375,38 @@ static noinline long btrfs_ioctl_wait_sync(struct file *file, void __user *argp) return btrfs_wait_for_commit(root, transid); } +/* + * Return the current status of any balance operation + */ +long btrfs_ioctl_balance_progress( + struct btrfs_fs_info *fs_info, + struct btrfs_ioctl_balance_progress __user *user_dest) +{ + int ret = 0; + struct btrfs_ioctl_balance_progress dest; + + spin_lock(fs_info-balance_info_lock); + if (!fs_info-balance_info) { + ret = -EINVAL; + goto error; + } + + dest.expected = fs_info-balance_info-expected; + dest.completed = fs_info-balance_info-completed; + + spin_unlock(fs_info-balance_info_lock); + + if (copy_to_user(user_dest, dest, +sizeof(struct btrfs_ioctl_balance_progress))) + return -EFAULT; + + return 0; + +error: + spin_unlock(fs_info-balance_info_lock); + return ret; +} + long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -2414,6 +2446,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_ioctl_rm_dev(root, argp); case BTRFS_IOC_BALANCE: return btrfs_balance(root-fs_info-dev_root); + case BTRFS_IOC_BALANCE_PROGRESS: + return btrfs_ioctl_balance_progress(root-fs_info, argp); case BTRFS_IOC_CLONE: return btrfs_ioctl_clone(file, arg, 0, 0, 0); case BTRFS_IOC_CLONE_RANGE: diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 8fb3821..7c37c6b 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -157,6 +157,11 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_space_info spaces[0]; }; +struct btrfs_ioctl_balance_progress { + __u32 expected; + __u32 completed; +}; + #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args) #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ @@ -203,4 +208,6 @@ 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_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ + struct btrfs_ioctl_balance_progress) #endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index dd13eb8..bb2ffed 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2041,6 +2041,7 @@ int btrfs_balance(struct btrfs_root *dev_root) struct btrfs_root *chunk_root = dev_root-fs_info-chunk_root; struct btrfs_trans_handle *trans; struct btrfs_key found_key; + struct btrfs_balance_info
[PATCH v5 2/8] btrfs: Cancel filesystem balance
This patch adds an ioctl for cancelling a btrfs balance operation mid-flight. The ioctl simply sets a flag, and the operation terminates after the current block group move has completed. Signed-off-by: Hugo Mills h...@carfax.org.uk --- fs/btrfs/ctree.h |1 + fs/btrfs/ioctl.c | 28 fs/btrfs/ioctl.h |1 + fs/btrfs/volumes.c |7 ++- 4 files changed, 36 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 17c7ecc..1d26cfd 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -868,6 +868,7 @@ struct btrfs_block_group_cache { struct btrfs_balance_info { u32 expected; u32 completed; + int cancel_pending; }; struct reloc_control; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a8fbb07..aef6329 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2407,6 +2407,32 @@ error: return ret; } +/* + * Cancel a running balance operation + */ +long btrfs_ioctl_balance_cancel(struct btrfs_fs_info *fs_info) +{ + int err = 0; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + spin_lock(fs_info-balance_info_lock); + if (!fs_info-balance_info) { + err = -EINVAL; + goto error; + } + if (fs_info-balance_info-cancel_pending) { + err = -ECANCELED; + goto error; + } + fs_info-balance_info-cancel_pending = 1; + +error: + spin_unlock(fs_info-balance_info_lock); + return err; +} + long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -2448,6 +2474,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_balance(root-fs_info-dev_root); case BTRFS_IOC_BALANCE_PROGRESS: return btrfs_ioctl_balance_progress(root-fs_info, argp); + case BTRFS_IOC_BALANCE_CANCEL: + return btrfs_ioctl_balance_cancel(root-fs_info); case BTRFS_IOC_CLONE: return btrfs_ioctl_clone(file, arg, 0, 0, 0); case BTRFS_IOC_CLONE_RANGE: diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 7c37c6b..2c49add 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -210,4 +210,5 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) #endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bb2ffed..cf019af 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2064,6 +2064,7 @@ int btrfs_balance(struct btrfs_root *dev_root) bal_info-expected = -1; /* One less than actually counted, because chunk 0 is special */ bal_info-completed = 0; + bal_info-cancel_pending = 0; spin_unlock(dev_root-fs_info-balance_info_lock); /* step one make some room on all the devices */ @@ -2124,7 +2125,7 @@ int btrfs_balance(struct btrfs_root *dev_root) key.offset = (u64)-1; key.type = BTRFS_CHUNK_ITEM_KEY; - while (1) { + while (!bal_info-cancel_pending) { ret = btrfs_search_slot(NULL, chunk_root, key, path, 0, 0); if (ret 0) goto error; @@ -2164,6 +2165,10 @@ int btrfs_balance(struct btrfs_root *dev_root) bal_info-completed, bal_info-expected); } ret = 0; + if (bal_info-cancel_pending) { + printk(KERN_INFO btrfs: balance cancelled\n); + ret = -EINTR; + } error: btrfs_free_path(path); spin_lock(dev_root-fs_info-balance_info_lock); -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Required Kernel version to compile git btrfs with DKMS? Problems with Ubuntu 10.10
Hi all, I'd like to look into btrfs code and try some things, so I followed the instructions on the wiki (link below) to setup git and get a dkms build against my kernel. I'm using Ubuntu 10.10 with a 2.6.35 Kernel, which I assume is too old. What version do I need? https://btrfs.wiki.kernel.org/index.php/Btrfs_source_repositories I've followed the guide (skipped initrd) until the dkms build command, which fails with the following error: dkms build -m btrfs -v git root@chris-desktop:/home/chris/workspace/btrfs/git-repo/btrfs-unstable# cat /var/lib/dkms/btrfs/git/build/make.log DKMS make.log for btrfs-git for kernel 2.6.35-28-generic (i686) So 10. Apr 22:05:11 CEST 2011 make: Gehe in Verzeichnis '/usr/src/linux-headers-2.6.35-28-generic' LD /var/lib/dkms/btrfs/git/build/built-in.o CC [M] /var/lib/dkms/btrfs/git/build/super.o In file included from /var/lib/dkms/btrfs/git/build/super.c:43: /var/lib/dkms/btrfs/git/build/ctree.h:31: fatal error: trace/events/btrfs.h: Datei oder Verzeichnis nicht gefunden compilation terminated. make[1]: *** [/var/lib/dkms/btrfs/git/build/super.o] Fehler 1 make: *** [_module_/var/lib/dkms/btrfs/git/build] Fehler 2 make: Verlasse Verzeichnis '/usr/src/linux-headers-2.6.35-28-generic' This seems to be fairly new (related to initial tracepoint support), from the two Mailing list threads [PATCH] Btrfs: add initial tracepoint support for btrfs and [GIT PULL] Btrfs updates for 2.6.39. The attached make.log is when I simply copy the missing file over from the btrfs git tree (fails with among others /var/lib/dkms/btrfs/git/build/super.c:578: error: ‘struct super_block’ has no member named ‘s_d_op’). So I am guessing that my Ubuntu 10.10 2.6.35 Kernel is too old? Will the 2.6.38 from the next Ubuntu release work? Regards, Christian Aßfalg DKMS make.log for btrfs-git for kernel 2.6.35-28-generic (i686) So 10. Apr 22:15:02 CEST 2011 make: Gehe in Verzeichnis '/usr/src/linux-headers-2.6.35-28-generic' LD /var/lib/dkms/btrfs/git/build/built-in.o CC [M] /var/lib/dkms/btrfs/git/build/super.o In file included from /var/lib/dkms/btrfs/git/build/super.c:43: /var/lib/dkms/btrfs/git/build/ctree.h:2237: warning: ‘struct fstrim_range’ declared inside parameter list /var/lib/dkms/btrfs/git/build/ctree.h:2237: warning: its scope is only this definition or declaration, which is probably not what you want In file included from include/trace/ftrace.h:285, from include/trace/define_trace.h:73, from include/trace/events/btrfs.h:667, from /var/lib/dkms/btrfs/git/build/super.c:56: include/trace/events/btrfs.h: In function ‘ftrace_raw_output_btrfs_transaction_commit’: include/trace/events/btrfs.h:47: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:47: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:47: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h: In function ‘ftrace_raw_output_btrfs__inode’: include/trace/events/btrfs.h:68: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:68: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:68: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h: In function ‘ftrace_raw_output_btrfs_get_extent’: include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:144: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h: In function ‘ftrace_raw_output_btrfs__ordered_extent’: include/trace/events/btrfs.h:197: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:197: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:197: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h: In function ‘ftrace_raw_output_btrfs__writepage’: include/trace/events/btrfs.h:273: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:273: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h:273: warning: large integer implicitly truncated to unsigned type include/trace/events/btrfs.h: In function ‘ftrace_raw_output_btrfs_writepage_end_io_hook’: include/trace/events/btrfs.h:332: warning: large integer implicitly truncated to unsigned type
[PATCH v5 0/8] Balance management, userspace
Hi, Chris, These patches form the userspace side of the balance management work. This includes two patches to add one-off and polled monitoring, a fork-to-background patch, and a sequence implementing the user interface to handle the various types of balance filtering implemented in the kernel-side patches. Hugo. --- Hugo Mills (8): Balance progress monitoring. Add --monitor option to btrfs balance progress. User-space tool for cancelling balance operations. Run userspace tool in background for balances. Initial implementation of userspace interface for filtered balancing. Balance filter by device ID Balance filter for virtual address range Interface for device range balance filter btrfs.c| 18 ++- btrfs_cmds.c | 463 +++- btrfs_cmds.h |2 + ioctl.h| 46 ++ man/btrfs.8.in | 79 +- 5 files changed, 596 insertions(+), 12 deletions(-) -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 3/8] User-space tool for cancelling balance operations.
Add an option to the btrfs tool to use the ioctl for cancelling balance operations. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs.c|4 btrfs_cmds.c | 41 + btrfs_cmds.h |1 + ioctl.h|1 + man/btrfs.8.in |6 ++ 5 files changed, 53 insertions(+), 0 deletions(-) diff --git a/btrfs.c b/btrfs.c index 0b6186c..93f7886 100644 --- a/btrfs.c +++ b/btrfs.c @@ -103,6 +103,10 @@ static struct Command commands[] = { balance progress, [-m|--monitor] path\n Show progress of the balance operation running on path. }, + { do_balance_cancel, 1, + balance cancel, path\n + Cancel the balance operation running on path. + }, { do_scan, 999, device scan, [device [device..]\n Scan all device for or the passed device for a btrfs\n diff --git a/btrfs_cmds.c b/btrfs_cmds.c index c681b5a..d246a8b 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -922,6 +922,47 @@ int do_balance_progress(int argc, char **argv) return 0; } +int do_balance_cancel(int nargs, char **argv) +{ + char *path = argv[1]; + int fdmnt; + int ret = 0; + int err = 0; + + fdmnt = open_file_or_dir(path); + if(fdmnt 0) { + fprintf(stderr, ERROR: can't access '%s'\n, path); + return 12; + } + + ret = ioctl(fdmnt, BTRFS_IOC_BALANCE_CANCEL, NULL); + err = errno; + + if(ret) { + switch(err) { + case 0: + break; + case EINVAL: + fprintf(stderr, ERROR: no balance in progress.\n); + err = 20; + break; + case ECANCELED: + fprintf(stderr, ERROR: operation already cancelled.\n); + err = 21; + break; + default: + fprintf(stderr, ERROR: ioctl returned error '%d'.\n, + err); + err = 22; + break; + } + } + + close(fdmnt); + + return err; +} + int do_remove_volume(int nargs, char **args) { diff --git a/btrfs_cmds.h b/btrfs_cmds.h index 47b0a27..5cb0d9c 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -24,6 +24,7 @@ int do_show_filesystem(int nargs, char **argv); int do_add_volume(int nargs, char **args); int do_balance(int nargs, char **argv); int do_balance_progress(int nargs, char **argv); +int do_balance_cancel(int nargs, char **argv); int do_remove_volume(int nargs, char **args); int do_scan(int nargs, char **argv); int do_resize(int nargs, char **argv); diff --git a/ioctl.h b/ioctl.h index 3eeaa33..40c0b57 100644 --- a/ioctl.h +++ b/ioctl.h @@ -176,4 +176,5 @@ struct btrfs_ioctl_balance_progress { struct btrfs_ioctl_space_args) #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) #endif diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 90be97e..d7fab80 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -25,6 +25,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fIpath\fP .PP +\fBbtrfs\fP \fBbalance cancel\fP \fIpath\fP +.PP \fBbtrfs\fP \fBdevice show\fP\fI dev|label [dev|label...]\fP .PP \fBbtrfs\fP \fBdevice balance\fP\fI path \fP @@ -168,6 +170,10 @@ Report progress on the currently-running balance operation on the filesystem mounted at \fIpath\fP. Use --monitor to report progress continually, including an estimate of completion time. +\fbalance cancel\fP \fIpath\fP +Cancel the balance currently running on the filesystem mounted at +\fIpath\fP. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure. -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 1/8] Balance progress monitoring.
This patch introduces a basic form of progress monitoring for balance operations, by counting the number of block groups remaining. The information is exposed to userspace by an ioctl. We also add btrfs balance start as an alias for btrfs filesystem balance, so that all balance-related functions are available under one prefix. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs.c|8 +++ btrfs_cmds.c | 60 btrfs_cmds.h |1 + ioctl.h|7 ++ man/btrfs.8.in | 11 ++ 5 files changed, 87 insertions(+), 0 deletions(-) diff --git a/btrfs.c b/btrfs.c index 46314cf..0b6186c 100644 --- a/btrfs.c +++ b/btrfs.c @@ -95,6 +95,14 @@ static struct Command commands[] = { filesystem balance, path\n Balance the chunks across the device. }, + { do_balance, 1, + balance start, path\n + Synonym for \btrfs filesystem balance\. + }, + { do_balance_progress, -1, + balance progress, [-m|--monitor] path\n + Show progress of the balance operation running on path. + }, { do_scan, 999, device scan, [device [device..]\n Scan all device for or the passed device for a btrfs\n diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 8031c58..2745d64 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -28,6 +28,7 @@ #include limits.h #include uuid/uuid.h #include ctype.h +#include getopt.h #undef ULONG_MAX @@ -776,6 +777,65 @@ int do_balance(int argc, char **argv) } return 0; } + +int get_balance_progress(char *path, struct btrfs_ioctl_balance_progress *bal) +{ + int fdmnt; + int ret = 0; + int err = 0; + + fdmnt = open_file_or_dir(path); + if(fdmnt 0) { + return -1; + } + + ret = ioctl(fdmnt, BTRFS_IOC_BALANCE_PROGRESS, bal); + if(ret) + err = errno; + close(fdmnt); + + return err; +} + +int do_balance_progress(int argc, char **argv) +{ + char *path; + int ret = 0; + int err = 0; + struct btrfs_ioctl_balance_progress bal; + + path = argv[1]; + + ret = get_balance_progress(path, bal); + if (!ret) + printf(\r%llu/%llu block groups moved, + %0.2f%% complete.\n, + bal.completed, + bal.expected, + (float)bal.completed/bal.expected*100.0); + + switch(ret) { + case 0: + break; + case -1: + fprintf(stderr, ERROR: can't access '%s'\n, path); + return 13; + case EINVAL: + if (!monitor) { + fprintf(stderr, + No balance operation running on '%s'.\n, + path); + return 20; + } + break; + default: + fprintf(stderr, ERROR: ioctl returned error %d., err); + return 21; + } + + return 0; +} + int do_remove_volume(int nargs, char **args) { diff --git a/btrfs_cmds.h b/btrfs_cmds.h index 7bde191..47b0a27 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -23,6 +23,7 @@ int do_defrag(int argc, char **argv); int do_show_filesystem(int nargs, char **argv); int do_add_volume(int nargs, char **args); int do_balance(int nargs, char **argv); +int do_balance_progress(int nargs, char **argv); int do_remove_volume(int nargs, char **args); int do_scan(int nargs, char **argv); int do_resize(int nargs, char **argv); diff --git a/ioctl.h b/ioctl.h index 776d7a9..f07d3a2 100644 --- a/ioctl.h +++ b/ioctl.h @@ -132,6 +132,11 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_space_info spaces[0]; }; +struct btrfs_ioctl_balance_progress { + __u32 expected; + __u32 completed; +}; + #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args) #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ @@ -169,4 +174,6 @@ struct btrfs_ioctl_space_args { #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64) #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 25, \ + struct btrfs_ioctl_balance_progress) #endif diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 26ef982..5c953ca 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -23,6 +23,8 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice scan\fP\fI [device [device..]]\fP .PP +\fBbtrfs\fP \fBbalance progress\fP\fI path\fP +.PP \fBbtrfs\fP \fBdevice show\fP\fI dev|label [dev|label...]\fP .PP \fBbtrfs\fP \fBdevice balance\fP\fI path \fP @@ -152,10 +154,19 @@ across the devices. Add device(s) to the
[PATCH v5 2/8] Add --monitor option to btrfs balance progress.
For the impatient, this patch introduces the pot-watching --monitor option, which checks the balance progress at regular intervals, and updates a single status line with the current progress and an estimated completion time. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs_cmds.c | 102 +++ ioctl.h|2 +- man/btrfs.8.in |7 ++-- 3 files changed, 99 insertions(+), 12 deletions(-) diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 2745d64..c681b5a 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -797,22 +797,108 @@ int get_balance_progress(char *path, struct btrfs_ioctl_balance_progress *bal) return err; } +const struct option progress_options[] = { + { monitor, 0, NULL, 'm' }, + { NULL, 0, NULL, 0 } +}; + int do_balance_progress(int argc, char **argv) { char *path; int ret = 0; int err = 0; struct btrfs_ioctl_balance_progress bal; + __u64 last_completed = -1; + __u64 initial_completed = -1; + struct timeval now; + struct timeval started; + int monitor = 0; + + optind = 1; + while(1) { + int c = getopt_long(argc, argv, m, progress_options, NULL); + if (c 0) + break; + switch(c) { + case 'm': + monitor = 1; + break; + default: + fprintf(stderr, Invalid arguments for balance progress\n); + free(argv); + return 1; + } + } + + if(optind = argc) { + fprintf(stderr, No filesystem path given for progress\n); + return 1; + } - path = argv[1]; + path = argv[optind]; + do { + int prs = 0; - ret = get_balance_progress(path, bal); - if (!ret) - printf(\r%llu/%llu block groups moved, - %0.2f%% complete.\n, - bal.completed, - bal.expected, - (float)bal.completed/bal.expected*100.0); + ret = get_balance_progress(path, bal); + if (ret) + break; + + if (last_completed != bal.completed) { + printf(\r%llu/%llu block groups moved, + %0.2f%% complete., + bal.completed, + bal.expected, + (float)bal.completed/bal.expected*100.0); + } + + if (initial_completed != -1 +initial_completed != bal.completed) { + ret = gettimeofday(now, NULL); + if (ret) { + fprintf(stderr, Can't read current time\n); + return 22; + } + /* Seconds per block */ + float rate = (float)(now.tv_sec - started.tv_sec) + / (bal.completed - initial_completed); + int secs_remaining = rate + * (bal.expected - bal.completed); + printf( Time remaining); + if (secs_remaining = 60*60*24) { + printf( %dd, secs_remaining / (60*60*24)); + secs_remaining %= 60*60*24; + prs = 1; + } + if (prs || secs_remaining = 60*60) { + printf( %dh, secs_remaining / (60*60)); + secs_remaining %= 60*60; + prs = 1; + } + if (prs || secs_remaining 60) { + printf( %dm, secs_remaining / 60); + secs_remaining %= 60; + } + printf( %ds\x1b[K, secs_remaining); + } + + if (last_completed != -1 last_completed != bal.completed) { + initial_completed = bal.completed; + ret = gettimeofday(started, NULL); + if (ret) { + fprintf(stderr, Can't read current time\n); + return 22; + } + } + + last_completed = bal.completed; + + if (monitor) { + fflush(stdout); + sleep(1); + } else { + printf(\n); + } + } while(monitor); switch(ret) { case 0: diff --git a/ioctl.h b/ioctl.h index f07d3a2..3eeaa33 100644 --- a/ioctl.h +++ b/ioctl.h @@ -174,6 +174,6 @@ struct btrfs_ioctl_balance_progress {
[PATCH v5 5/8] Initial implementation of userspace interface for filtered balancing.
It is useful to be able to balance a subset of the full filesystem. This patch implements the infrastructure for filtering block groups on different criteria when balancing the filesystem. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs.c|4 +- btrfs_cmds.c | 169 ++- ioctl.h| 24 man/btrfs.8.in | 40 +++-- 4 files changed, 225 insertions(+), 12 deletions(-) diff --git a/btrfs.c b/btrfs.c index 7b42658..19b0e56 100644 --- a/btrfs.c +++ b/btrfs.c @@ -92,8 +92,8 @@ static struct Command commands[] = { Show space usage information for a mount point\n. }, { do_balance, -1, - filesystem balance, [-w|--wait] path\n - Balance the chunks across the device. + filesystem balance, [-w|--wait] [-f|--filter=filter:...] path\n + Balance chunks across the devices. --filter=help for help on filters.\n }, { do_balance, -1, balance start, [-w|--wait] path\n diff --git a/btrfs_cmds.c b/btrfs_cmds.c index fadcb4f..f0588d2 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -756,26 +756,175 @@ int do_add_volume(int nargs, char **args) const struct option balance_options[] = { { wait, 0, NULL, 'w' }, + { filter, 1, NULL, 'f' }, + { count, 0, NULL, 'c' }, + { verbose, 0, NULL, 'v' }, { NULL, 0, NULL, 0 } }; +struct filter_class_desc { + char *keyword; + char *description; + int flag; +}; + +const struct filter_class_desc filter_class[] = { + { type, + type=[~]flagname[,...]\n + \tWhere flagname is one of:\n + \t\tmeta, sys, data, raid0, raid1, raid10, dup\n + \tPrefix a flagname with ~ to negate the match.\n, + BTRFS_BALANCE_FILTER_CHUNK_TYPE }, + { NULL, NULL, 0 } +}; + +struct type_filter_desc { + char *keyword; + __u64 mask; + __u64 set; + __u64 unset; +}; + +#define BTRFS_BLOCK_GROUP_SINGLE \ + BTRFS_BLOCK_GROUP_RAID0 | \ + BTRFS_BLOCK_GROUP_RAID1 | \ + BTRFS_BLOCK_GROUP_RAID10 | \ + BTRFS_BLOCK_GROUP_DUP + +const struct type_filter_desc type_filters[] = { + { data, BTRFS_BLOCK_GROUP_DATA, BTRFS_BLOCK_GROUP_DATA, 0 }, + { sys, BTRFS_BLOCK_GROUP_SYSTEM, BTRFS_BLOCK_GROUP_SYSTEM, 0 }, + { meta, BTRFS_BLOCK_GROUP_METADATA, BTRFS_BLOCK_GROUP_METADATA, 0 }, + { raid0, BTRFS_BLOCK_GROUP_RAID0, BTRFS_BLOCK_GROUP_RAID0, 0 }, + { raid1, BTRFS_BLOCK_GROUP_RAID1, BTRFS_BLOCK_GROUP_RAID1, 0 }, + { raid10, BTRFS_BLOCK_GROUP_RAID10, BTRFS_BLOCK_GROUP_RAID10, 0 }, + { dup, BTRFS_BLOCK_GROUP_DUP, BTRFS_BLOCK_GROUP_DUP, 0 }, + { single, BTRFS_BLOCK_GROUP_SINGLE, 0, BTRFS_BLOCK_GROUP_SINGLE }, + { NULL, 0, 0, 0 } +}; + +int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string) +{ + char *this_filter_string; + char *saveptr; + + printf((entry) %s Args: required %llx, mask %llx\n, filters_string, args-chunk_type, args-chunk_type_mask); + + /* Parse the filters string, if there is one */ + this_filter_string = strtok_r(filters_string, :, saveptr); + while(this_filter_string) { + char *subsave; + char *part; + char *type = strtok_r(this_filter_string, =,, subsave); + int class_id = -1; + + /* Work out what filter type we're looking at */ + if(strcmp(type, help) == 0) { + while(filter_class[++class_id].keyword) { + printf(%s, filter_class[class_id].description); + } + return 1; + } + + while(filter_class[++class_id].keyword) { + if(strcmp(type, filter_class[class_id].keyword) == 0) + break; + } + if(filter_class[class_id].keyword == NULL) { + fprintf(stderr, ERROR: Unknown filter type '%s'\n, type); + free(args); + return 14; + } + + /* Mark this filter class as being in use */ + args-flags |= filter_class[class_id].flag; + + /* Parse the arguments for this filter */ + part = strtok_r(NULL, =,, subsave); + + switch(filter_class[class_id].flag) { + case BTRFS_BALANCE_FILTER_CHUNK_TYPE: + while(part) { + int negated = 0; + int i = 0; + if(part[0] == '~') { + negated = 1; + part += 1; + } + while(type_filters[i].keyword) { + if(strcmp(part,
[PATCH v5 4/8] Run userspace tool in background for balances.
This patch makes a balance operation fork and detach from the current terminal, to run the userspace side of the balance in the background. Introduce a --wait switch so that a synchronous balance can be done if the user requires. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs.c|8 btrfs_cmds.c | 52 ++-- man/btrfs.8.in | 19 ++- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/btrfs.c b/btrfs.c index 93f7886..7b42658 100644 --- a/btrfs.c +++ b/btrfs.c @@ -91,12 +91,12 @@ static struct Command commands[] = { filesystem df, path\n Show space usage information for a mount point\n. }, - { do_balance, 1, - filesystem balance, path\n + { do_balance, -1, + filesystem balance, [-w|--wait] path\n Balance the chunks across the device. }, - { do_balance, 1, - balance start, path\n + { do_balance, -1, + balance start, [-w|--wait] path\n Synonym for \btrfs filesystem balance\. }, { do_balance_progress, -1, diff --git a/btrfs_cmds.c b/btrfs_cmds.c index d246a8b..fadcb4f 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -754,12 +754,41 @@ int do_add_volume(int nargs, char **args) } +const struct option balance_options[] = { + { wait, 0, NULL, 'w' }, + { NULL, 0, NULL, 0 } +}; + int do_balance(int argc, char **argv) { - int fdmnt, ret=0; + int background = 1; struct btrfs_ioctl_vol_args args; - char*path = argv[1]; + char *path; + int ttyfd; + + optind = 1; + while(1) { + int c = getopt_long(argc, argv, w, balance_options, NULL); + if (c 0) + break; + switch(c) { + case 'w': + background = 0; + break; + default: + fprintf(stderr, Invalid arguments for balance\n); + free(argv); + return 1; + } + } + + if(optind = argc) { + fprintf(stderr, No filesystem path given for balance\n); + return 1; + } + + path = argv[optind]; fdmnt = open_file_or_dir(path); if (fdmnt 0) { @@ -767,6 +796,25 @@ int do_balance(int argc, char **argv) return 12; } + if (background) { + int pid = fork(); + if (pid == 0) { + /* We're in the child, and can run in the background */ + ttyfd = open(/dev/tty, O_RDWR); + if (ttyfd 0) + ioctl(ttyfd, TIOCNOTTY, 0); + /* Fall through to the BTRFS_IOC_BALANCE ioctl */ + } else if (pid 0) { + /* We're in the parent, and the fork succeeded */ + printf(Background balance started\n); + return 0; + } else { + /* We're in the parent, and the fork failed */ + fprintf(stderr, ERROR: can't start background process -- %s\n, + strerror(errno)); + } + } + memset(args, 0, sizeof(args)); ret = ioctl(fdmnt, BTRFS_IOC_BALANCE, args); close(fdmnt); diff --git a/man/btrfs.8.in b/man/btrfs.8.in index d7fab80..95e39c3 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -23,13 +23,15 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBdevice scan\fP\fI [device [device..]]\fP .PP +\fBbtrfs\fP \fBbalance start\fP [\fB-w\fP|\fB--wait\fP] \fIpath\fP +.PP \fBbtrfs\fP \fBbalance progress\fP [\fB-m\fP|\fB--monitor\fP] \fIpath\fP .PP \fBbtrfs\fP \fBbalance cancel\fP \fIpath\fP .PP \fBbtrfs\fP \fBdevice show\fP\fI dev|label [dev|label...]\fP .PP -\fBbtrfs\fP \fBdevice balance\fP\fI path \fP +\fBbtrfs\fP \fBfilesystem balance\fP [\fB-w\fP|\fB--wait\fP] \fIpath\fP .PP \fBbtrfs\fP \fBdevice add\fP\fI dev [dev..] path \fP .PP @@ -147,20 +149,19 @@ Show the btrfs filesystem with some additional info. If no UUID or label is passed, \fBbtrfs\fR show info of all the btrfs filesystem. .TP -\fBdevice balance\fR \fIpath\fR -Balance the chunks of the filesystem identified by \fIpath\fR -across the devices. +\fBdevice balance\fR [\fB-w\fP|\fB--wait\fP] \fIpath\fR + +\fBbalance start\fR [\fB-w\fP|\fB--wait\fP] \fIpath\fR + +Balance the chunks of the filesystem identified by \fIpath\fR across +the devices. The process runs in the background. Use \fB--wait\fP to +wait in the foreground for completion of the balance. .TP \fBdevice add\fR\fI dev [dev..] path\fR Add device(s) to the filesystem identified by \fIpath\fR. .TP -.SS -\fBdevice balance \fIpath\fP -Balance the chunks of the filesystem identified by \fIpath\fP
[PATCH v5 7/8] Balance filter for virtual address range
Implement the userspace side of the virtual address range filter. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs_cmds.c | 22 ++ ioctl.h|9 +++-- man/btrfs.8.in |9 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/btrfs_cmds.c b/btrfs_cmds.c index ffca32b..e5f2c39 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -779,6 +779,12 @@ const struct filter_class_desc filter_class[] = { devid=n\n \tBalance only chunks which have a stripe on device n.\n, BTRFS_BALANCE_FILTER_DEVID }, + { vrange, + vrange=start,end\n + \tBalances only chunks which have any bytes within the given\n + \trange of the filesystem's virtual address space.\n + \tstart is inclusive, end is exclusive.\n, + BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE }, { NULL, NULL, 0 } }; @@ -885,6 +891,22 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string) return 15; } break; + + case BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE: + errno = 0; + args-vrange_start = strtoull(part, NULL, 10); + if (errno != 0) { + fprintf(stderr, ERROR: '%s' is not a valid start address\n, part); + return 15; + } + part = strtok_r(NULL, =,, subsave); + errno = 0; + args-vrange_end = strtoull(part, NULL, 10); + if (errno != 0) { + fprintf(stderr, ERROR: '%s' is not a valid end address\n, part); + return 15; + } + break; } this_filter_string = strtok_r(NULL, :, saveptr); diff --git a/ioctl.h b/ioctl.h index cb605c0..71fa90e 100644 --- a/ioctl.h +++ b/ioctl.h @@ -142,7 +142,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2 #define BTRFS_BALANCE_FILTER_DEVID 0x4 -#define BTRFS_BALANCE_FILTER_MASK 0x7 +#define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE 0x8 +#define BTRFS_BALANCE_FILTER_MASK 0xf /* All the possible options for a filter */ struct btrfs_ioctl_balance_start { @@ -159,7 +160,11 @@ struct btrfs_ioctl_balance_start { /* For FILTER_DEVID */ __u64 devid; - __u64 spare[505]; /* Make up the size of the structure to 4088 + /* For FILTER_VIRTUAL_ADDRESS_RANGE */ + __u64 vrange_start; + __u64 vrange_end; + + __u64 spare[503]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 94114a9..1031af6 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -210,6 +210,15 @@ Select chunks which have data on device ID \fIn\fR. This can be used, for example, to reduplicate data in a mirrored configuration where one drive has been lost due to hardware failure. +.TP +\fBvrange\fR=\fIstart\fB,\fIend\fR + +Select chunks which have btrfs-internal virtual addresses within the +range \fIstart\fR (inclusive) to \fIend\fR (exclusive). Given the +address of the last chunk moved, this filter can be used to restart a +cancelled or interrupted balance operation, by supplying a range of +\fB0,\fIchunkaddr+1\fR. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure. -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 8/8] Interface for device range balance filter
Implement the userspace side of the balance filter for a range of bytes on any device. Note that this will match the same range on any device, so the use of the devid filter is recommended where this filter is used. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs_cmds.c | 22 ++ ioctl.h|9 +++-- man/btrfs.8.in |8 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/btrfs_cmds.c b/btrfs_cmds.c index e5f2c39..e82c103 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -785,6 +785,12 @@ const struct filter_class_desc filter_class[] = { \trange of the filesystem's virtual address space.\n \tstart is inclusive, end is exclusive.\n, BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE }, + { drange, + drange=start,end\n + \tBalances chunks which have any bytes within the given\n + \tbyte range on any of the filesystem's underlying devices.\n + \tstart is inclusive, end is exclusive.\n, + BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE }, { NULL, NULL, 0 } }; @@ -907,6 +913,22 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string) return 15; } break; + + case BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE: + errno = 0; + args-drange_start = strtoull(part, NULL, 10); + if (errno != 0) { + fprintf(stderr, ERROR: '%s' is not a valid start address\n, part); + return 15; + } + part = strtok_r(NULL, =,, subsave); + errno = 0; + args-drange_end = strtoull(part, NULL, 10); + if (errno != 0) { + fprintf(stderr, ERROR: '%s' is not a valid end address\n, part); + return 15; + } + break; } this_filter_string = strtok_r(NULL, :, saveptr); diff --git a/ioctl.h b/ioctl.h index 71fa90e..a99c225 100644 --- a/ioctl.h +++ b/ioctl.h @@ -143,7 +143,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2 #define BTRFS_BALANCE_FILTER_DEVID 0x4 #define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE 0x8 -#define BTRFS_BALANCE_FILTER_MASK 0xf +#define BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE 0x10 +#define BTRFS_BALANCE_FILTER_MASK 0x1f /* All the possible options for a filter */ struct btrfs_ioctl_balance_start { @@ -164,7 +165,11 @@ struct btrfs_ioctl_balance_start { __u64 vrange_start; __u64 vrange_end; - __u64 spare[503]; /* Make up the size of the structure to 4088 + /* For FILTER_DEVICE_ADDRESS_RANGE */ + __u64 drange_start; + __u64 drange_end; + + __u64 spare[501]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 1031af6..6adf8bb 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -219,6 +219,14 @@ address of the last chunk moved, this filter can be used to restart a cancelled or interrupted balance operation, by supplying a range of \fB0,\fIchunkaddr+1\fR. +.TP +\fBdrange\fR=\fIstart\fB,\fIend\fR + +Select chunks which contain data in the address range \fIstart\fR +(inclusive) to \fIend\fR (exclusive) on \fIany\fR block device in +the filesystem. Can be mixed with the \fBdevid\fR filter to select +chunks in a given address range on a specific device. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure. -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 6/8] Balance filter by device ID
Add the userspace implementation for filtering balances by device ID. Signed-off-by: Hugo Mills h...@carfax.org.uk --- btrfs_cmds.c | 13 + ioctl.h|8 ++-- man/btrfs.8.in |7 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/btrfs_cmds.c b/btrfs_cmds.c index f0588d2..ffca32b 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -775,6 +775,10 @@ const struct filter_class_desc filter_class[] = { \t\tmeta, sys, data, raid0, raid1, raid10, dup\n \tPrefix a flagname with ~ to negate the match.\n, BTRFS_BALANCE_FILTER_CHUNK_TYPE }, + { devid, + devid=n\n + \tBalance only chunks which have a stripe on device n.\n, + BTRFS_BALANCE_FILTER_DEVID }, { NULL, NULL, 0 } }; @@ -872,6 +876,15 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string) part = strtok_r(NULL, =,, subsave); } break; + + case BTRFS_BALANCE_FILTER_DEVID: + errno = 0; + args-devid = strtoull(part, NULL, 10); + if (errno != 0) { + fprintf(stderr, ERROR: '%s' is not a valid device ID\n, part); + return 15; + } + break; } this_filter_string = strtok_r(NULL, :, saveptr); diff --git a/ioctl.h b/ioctl.h index 6488e82..cb605c0 100644 --- a/ioctl.h +++ b/ioctl.h @@ -141,7 +141,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_COUNT_ONLY 0x1 #define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2 -#define BTRFS_BALANCE_FILTER_MASK 0x3 +#define BTRFS_BALANCE_FILTER_DEVID 0x4 +#define BTRFS_BALANCE_FILTER_MASK 0x7 /* All the possible options for a filter */ struct btrfs_ioctl_balance_start { @@ -155,7 +156,10 @@ struct btrfs_ioctl_balance_start { __u64 chunk_type; /* Flag bits required */ __u64 chunk_type_mask; /* Mask of bits to examine */ - __u64 spare[506]; /* Make up the size of the structure to 4088 + /* For FILTER_DEVID */ + __u64 devid; + + __u64 spare[505]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 3023eb5..94114a9 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -203,6 +203,13 @@ chunk types. \fBraid0\fR, \fBraid1\fR, \fBraid10\fR, \fBdup\fR for chunks of the given replication levels. +.TP +\fBdevid\fR=\fIn\fR + +Select chunks which have data on device ID \fIn\fR. This can be +used, for example, to reduplicate data in a mirrored configuration +where one drive has been lost due to hardware failure. + .SH EXIT STATUS \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in case of failure. -- 1.7.2.5 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 3/8] btrfs: Factor out enumeration of chunks to a separate function
On Sun, Apr 10, 2011 at 10:06:06PM +0100, Hugo Mills wrote: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index cf019af..20c2772 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2029,6 +2029,97 @@ static u64 div_factor(u64 num, int factor) +static void balance_move_chunks(struct btrfs_root *chunk_root, + struct btrfs_balance_info *bal_info, + struct btrfs_path *path, + struct btrfs_key *key) +{ + int ret; + + ret = btrfs_relocate_chunk(chunk_root, +chunk_root-root_key.objectid, +key-objectid, +key-offset); + BUG_ON(ret ret != -ENOSPC); + spin_lock(chunk_root-fs_info-balance_info_lock); + bal_info-completed++; + spin_unlock(chunk_root-fs_info-balance_info_lock); + printk(KERN_INFO btrfs: balance: %llu/%llu block groups completed\n, +bal_info-completed, bal_info-expected); as you've changed 'completed' and 'expected' members to 32bit, change %llu to %u. d/ -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] Btrfs: fix memory leaks in btrfs_new_inode()
Yoshinori Sano wrote: This patch fixes memory leaks in btrfs_new_inode(). Signed-off-by: Yoshinori Sano yoshinori.s...@gmail.com --- fs/btrfs/inode.c |5 - 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index aa116dc..d8c93c1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4536,14 +4536,17 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, return ERR_PTR(-ENOMEM); inode = new_inode(root-fs_info-sb); - if (!inode) + if (!inode) { + btrfs_free_path(path); return ERR_PTR(-ENOMEM); + } if (dir) { trace_btrfs_inode_request(dir); ret = btrfs_set_inode_index(dir, index); if (ret) { + btrfs_free_path(path); iput(inode); return ERR_PTR(ret); } It would be better to avoid multiple returns here: fail_free_path: btrfs_free_path(path); fail_put_inode: iput(inode); fail: ... -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] Btrfs: cleanup btrfs_alloc_path()'s caller code
(2011/04/09 11:23), Yoshinori Sano wrote: This patch checks return value of btrfs_alloc_path() and removes BUG_ON(). Signed-off-by: Yoshinori Sano yoshinori.s...@gmail.com --- fs/btrfs/dir-item.c|2 ++ fs/btrfs/extent-tree.c | 12 fs/btrfs/file-item.c |6 -- fs/btrfs/file.c|3 ++- fs/btrfs/inode.c | 34 -- fs/btrfs/relocation.c |1 + fs/btrfs/root-tree.c |6 -- fs/btrfs/tree-log.c|3 ++- fs/btrfs/volumes.c |8 ++-- 9 files changed, 53 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index c62f02f..e60bf8e 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -142,6 +142,8 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root key.offset = btrfs_name_hash(name, name_len); path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; path-leave_spinning = 1; data_size = sizeof(*dir_item) + name_len; diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f619c3c..b830db8 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -645,7 +645,8 @@ int btrfs_lookup_extent(struct btrfs_root *root, u64 start, u64 len) struct btrfs_path *path; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; key.objectid = start; key.offset = len; btrfs_set_key_type(key, BTRFS_EXTENT_ITEM_KEY); @@ -5531,7 +5532,8 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, u32 size = sizeof(*extent_item) + sizeof(*block_info) + sizeof(*iref); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; path-leave_spinning = 1; ret = btrfs_insert_empty_item(trans, fs_info-extent_root, path, @@ -6302,7 +6304,8 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int level; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; If you change this, I think that it is better to change the following caller. for example: fs/btrfs/relocation.c: 2231 btrfs_drop_snapshot(reloc_root, rc-block_rsv, 0); wc = kzalloc(sizeof(*wc), GFP_NOFS); BUG_ON(!wc); @@ -8699,7 +8702,8 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, spin_unlock(cluster-refill_lock); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; inode = lookup_free_space_inode(root, block_group, path); if (!IS_ERR(inode)) { diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index a6a9d4e..097911e 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -281,7 +281,8 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, u16 csum_size = btrfs_super_csum_size(root-fs_info-super_copy); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; key.offset = start; @@ -665,7 +666,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, btrfs_super_csum_size(root-fs_info-super_copy); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; sector_sum = sums-sums; again: next_offset = (u64)-1; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index e621ea5..fe623ea 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -599,7 +599,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, btrfs_drop_extent_cache(inode, start, end - 1, 0); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; again: recow = 0; split = start; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cc60228..aa116dc 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1007,6 +1007,7 @@ static noinline int csum_exist_in_range(struct btrfs_root *root, ret = btrfs_lookup_csums_range(root-fs_info-csum_root, bytenr, bytenr + num_bytes - 1, list); + BUG_ON(ret); if (ret == 0 list_empty(list)) return 0; @@ -1050,7 +1051,8 @@ static noinline int run_delalloc_nocow(struct inode *inode, bool nolock = false; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; if (root == root-fs_info-tree_root) { nolock = true; trans = btrfs_join_transaction_nolock(root, 1); @@ -1496,13 +1498,15 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans, struct inode *inode, u64 file_offset,
Re: [PATCH v5 1/8] btrfs: Balance progress monitoring
Hallo, Hugo, Du meintest am 10.04.11: This patch introduces a basic form of progress monitoring for balance operations, by counting the number of block groups remaining. The information is exposed to userspace by an ioctl. Just for curiosity: If I remember correct then btrfs device delete shows growing and shrinking numbers, resp. on the remaining and on the deleting partition(s). Can this patch show the remaining number of block groups too? Viele Gruesse! Helmut -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v5 4/8] Run userspace tool in background for balances.
Hallo, Hugo, Du meintest am 10.04.11: This patch makes a balance operation fork and detach from the current terminal, to run the userspace side of the balance in the background. Fine! Viele Gruesse! Helmut -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html