[PATCH 07/15] btrfs-progs: lowmem check: find_dir_item by di_key in check_dir_item()

2018-01-26 Thread Su Yue
In check_dir_item, we are going to search corresponding dir_item/index. @key shouldn't be used here. It should be @di_key. Signed-off-by: Su Yue --- cmds-check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index

Re: [PATCH 02/15] btrfs-progs: lowmem check: find and guess inode filetype

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > Introduce find_file_type_lowmem() and guess_file_type_lowmem(). > > find_file_type_lowmem() gets filetypes from inode_item, dir_item and > dir_index. If two of three's filetype are same and valid, it thinks > the value is correct. > >

Re: [PATCH 03/15] btrfs-progs: lowmem check: find filetype in repair_inode_missing()

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > If parameter @filetype is 0, repair_inode_missing will find filetype > automatically. > > And let it return -EEXIST instead of 0 if inode item is existed. > > Signed-off-by: Su Yue Reviewed-by: Qu Wenruo Thanks,

Re: [PATCH 06/15] btrfs-progs: lowmem check: let check_dir_item() return if repaired

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > If repair_dir_item deleted the item, goto last checked then returns > instead of searching di_key again then returns -ENOENT. > > Signed-off-by: Su Yue > --- > cmds-check.c | 4 ++-- > 1 file changed, 2 insertions(+), 2

Re: [PATCH 12/15] btrfs-progs: check: increase counter error in check_inode_recs()

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > Counter @error decides return values of check_inode_recs(). > > Previously, @error won't be incremented even repair_inode_recs() failed. > It causes 'btrfs check --repair' prints some error information but > returns 0. > > So, if root dir is missing and

[PATCH 04/15] btrfs-progs: lowmem check: repair complex cases in repair_dir_item()

2018-01-26 Thread Su Yue
If inode item is missing or filetype is corrupted maybe, and filetypes of dir_item and dir_index are corrupted too, lowmem repair may insert wrong inode item and dir_item/index. First, find and guess filetype of inode item, if failed, use BTRFS_REG_FILE as fallback for insertion. If filetype is

[PATCH 02/15] btrfs-progs: lowmem check: find and guess inode filetype

2018-01-26 Thread Su Yue
Introduce find_file_type_lowmem() and guess_file_type_lowmem(). find_file_type_lowmem() gets filetypes from inode_item, dir_item and dir_index. If two of three's filetype are same and valid, it thinks the value is correct. guess_file_type_lowmem() searches file_extent and dir_item/index then

[PATCH 15/15] btrfs-progs: fsck-tests: add image for original and lowmem check

2018-01-26 Thread Su Yue
This image have two cases mixed: 1) Both filetypes of dir_item and dir_index about inode 258 are corrupted. 2) inode item 258 is missing. Signed-off-by: Su Yue --- .../029-mismatched-filetype-no-inode/default_case.img| Bin 0 -> 3072 bytes 1 file changed, 0

Re: [PATCH 02/15] btrfs-progs: lowmem check: find and guess inode filetype

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > Introduce find_file_type_lowmem() and guess_file_type_lowmem(). > > find_file_type_lowmem() gets filetypes from inode_item, dir_item and > dir_index. If two of three's filetype are same and valid, it thinks > the value is correct. > >

Re: [PATCH 02/15] btrfs-progs: lowmem check: find and guess inode filetype

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 17:14, Qu Wenruo wrote: > > > On 2018年01月26日 16:35, Su Yue wrote: >> Introduce find_file_type_lowmem() and guess_file_type_lowmem(). >> >> find_file_type_lowmem() gets filetypes from inode_item, dir_item and >> dir_index. If two of three's filetype are same and valid, it thinks

Re: [PATCH 04/15] btrfs-progs: lowmem check: repair complex cases in repair_dir_item()

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > If inode item is missing or filetype is corrupted maybe, and filetypes > of dir_item and dir_index are corrupted too, lowmem repair may insert > wrong inode item and dir_item/index. > > First, find and guess filetype of inode item, if failed, use >

[PATCH 06/15] btrfs-progs: lowmem check: let check_dir_item() return if repaired

2018-01-26 Thread Su Yue
If repair_dir_item deleted the item, goto last checked then returns instead of searching di_key again then returns -ENOENT. Signed-off-by: Su Yue --- cmds-check.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index

Re: [PATCH] Btrfs: delete dead code in btrfs_orphan_add()

2018-01-26 Thread Nikolay Borisov
On 26.01.2018 01:56, Omar Sandoval wrote: > From: Omar Sandoval > > btrfs_orphan_add() has had this case commented out since it was first > introduced in commit d68fc57b7e32 ("Btrfs: Metadata reservation for > orphan inodes"). Most of the orphan cleanup code has been rewritten

Re: [PATCH 07/15] btrfs-progs: lowmem check: find_dir_item by di_key in check_dir_item()

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > In check_dir_item, we are going to search corresponding > dir_item/index. > @key shouldn't be used here. It should be @di_key. > > Signed-off-by: Su Yue Reviewed-by: Qu Wenruo Thanks, Qu > --- > cmds-check.c | 2

Re: [PATCH 09/15] btrfs-progs: lowmem check: change logic of leaf process if repair

2018-01-26 Thread Su Yue
On 01/26/2018 06:01 PM, Qu Wenruo wrote: On 2018年01月26日 16:35, Su Yue wrote: In lowmem check without repair, process_one_leaf_v2() will process one entire leaf and inner check_inode_item() leads path point next leaf. In the beginning, process_one_leaf_v2() will let path point fist inode

Re: [PATCH 15/15] btrfs-progs: fsck-tests: add image for original and lowmem check

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > This image have two cases mixed: > 1) Both filetypes of dir_item and dir_index about inode 258 >are corrupted. > 2) inode item 258 is missing. It would be better to provide some debug tree output in commit message. Something like: -- item 6

Re: btrfs check: backref lost, mismatch with its hash -- can't repair

2018-01-26 Thread ^m'e
On Thu, Jan 25, 2018 at 11:30 PM, Qu Wenruo wrote: > > Please provide dump for this: > > # btrfs inspect dump-tree -t 1399 | grep -C 20 18446744073709551615 > This gives nothing. > And > > # btrfs inspect dump-tree -t 1399 | grep -C 20 30039322 > This gives:

Re: [PATCH] Btrfs: fix btrfs_evict_inode to handle abnormal inodes correctly

2018-01-26 Thread Nikolay Borisov
On 25.01.2018 20:02, Liu Bo wrote: > This regression is introduced in > commit 3d48d9810de4 ("btrfs: Handle uninitialised inode eviction"). > > There are two problems, > > a) it is ->destroy_inode() that does the final free on inode, not >->evict_inode(), > b) clear_inode() must be called

Re: [PATCH 10/15] btrfs-progs: check: clear I_ERR_FILE_EXTENT_DISCOUNT after repair

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > Original check forgets to clear bit I_ERR_FILE_EXTENT_DISCOUNT > in rec->errors after repair. > > So just do it. > > Signed-off-by: Su Yue Reviewed-by: Qu Wenruo And a test case for this would help us to avoid

Re: [PATCH 02/15] btrfs-progs: lowmem check: find and guess inode filetype

2018-01-26 Thread Su Yue
On 01/26/2018 05:14 PM, Qu Wenruo wrote: On 2018年01月26日 16:35, Su Yue wrote: Introduce find_file_type_lowmem() and guess_file_type_lowmem(). find_file_type_lowmem() gets filetypes from inode_item, dir_item and dir_index. If two of three's filetype are same and valid, it thinks the value is

Re: [PATCH 02/15] btrfs-progs: lowmem check: find and guess inode filetype

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 17:31, Su Yue wrote: > > > On 01/26/2018 05:14 PM, Qu Wenruo wrote: >> >> >> On 2018年01月26日 16:35, Su Yue wrote: >>> Introduce find_file_type_lowmem() and guess_file_type_lowmem(). >>> >>> find_file_type_lowmem() gets filetypes from inode_item, dir_item and >>> dir_index. If two

Re: [PATCH 05/15] btrfs-progs: lowmem check: let check_dir_item() continue if find wrong inode_item

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > check_dir_item can handle missed/mismatched inode item well. > Let it continue to check corresponding dir_item/index and inode_ref. > > Signed-off-by: Su Yue Reviewed-by: Qu Wenruo Thanks, Qu > --- >

Re: [PATCH 09/15] btrfs-progs: lowmem check: change logic of leaf process if repair

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > In lowmem check without repair, process_one_leaf_v2() will process one > entire leaf and inner check_inode_item() leads path point next > leaf. > In the beginning, process_one_leaf_v2() will let path point fist inode > item or first position where inode id

Re: [PATCH 13/15] btrfs-progs: check: find inode filetype in create_inode_item()

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 16:35, Su Yue wrote: > Now, find_file_type() doesn't return 0 if mismatched filetype is in a > backref. > > Let create_inode_item() first call find_file_type() to get filetype. > If it failed, then guess filetype. > > Signed-off-by: Su Yue > --- >

[PATCH 00/15] btrfs-progs: fix filetype mismatch in check

2018-01-26 Thread Su Yue
This patchset is based on Qu Wenruo's "[PATCH v2 0/3] Lowmem fsck repair to fix filetype mismatch". It can be fetched from my github: https://github.com/Damenly/btrfs-progs/tree/mismatch_filetype Above Qu's patchset fixes mismatched filetype already. But both original and lowmem can't handle more

[PATCH 05/15] btrfs-progs: lowmem check: let check_dir_item() continue if find wrong inode_item

2018-01-26 Thread Su Yue
check_dir_item can handle missed/mismatched inode item well. Let it continue to check corresponding dir_item/index and inode_ref. Signed-off-by: Su Yue --- cmds-check.c | 15 ++- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cmds-check.c

[PATCH 13/15] btrfs-progs: check: find inode filetype in create_inode_item()

2018-01-26 Thread Su Yue
Now, find_file_type() doesn't return 0 if mismatched filetype is in a backref. Let create_inode_item() first call find_file_type() to get filetype. If it failed, then guess filetype. Signed-off-by: Su Yue --- cmds-check.c | 29 ++--- 1 file

[PATCH 11/15] btrfs-progs: check: modify indoe_rec and backref after repair

2018-01-26 Thread Su Yue
repair_inode_backrefs() forgets to modify backrefs and inode records after repair them. Signed-off-by: Su Yue --- cmds-check.c | 4 1 file changed, 4 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index d8d9a3227c06..b23a4493b12b 100644 --- a/cmds-check.c

[PATCH 09/15] btrfs-progs: lowmem check: change logic of leaf process if repair

2018-01-26 Thread Su Yue
In lowmem check without repair, process_one_leaf_v2() will process one entire leaf and inner check_inode_item() leads path point next leaf. In the beginning, process_one_leaf_v2() will let path point fist inode item or first position where inode id changed. However, in lowmem repair,

Re: [PATCH v2 0/7] btrfs-progs: Do some clean up to be consistent

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 15:25, Gu Jinxiang wrote: > Patch 1~4 and 7: clean up use of btrfs_root. > Patch 5: remove redundancy value assignment. > Patch 6: remove no longer be used function define. Overall it looks good, just one small nitpick, which should not need another update. > Changelog: >

[PATCH 10/15] btrfs-progs: check: clear I_ERR_FILE_EXTENT_DISCOUNT after repair

2018-01-26 Thread Su Yue
Original check forgets to clear bit I_ERR_FILE_EXTENT_DISCOUNT in rec->errors after repair. So just do it. Signed-off-by: Su Yue --- cmds-check.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cmds-check.c b/cmds-check.c index ae0a9e146399..d8d9a3227c06 100644 ---

[PATCH 08/15] btrfs-progs: lowmem check: call get_dir_isize() after repair

2018-01-26 Thread Su Yue
Since lowmem repair may change size of inode item, introduce get_dir_isize() to fetch isize after traversing items of inode. Signed-off-by: Su Yue --- cmds-check.c | 30 ++ 1 file changed, 30 insertions(+) diff --git a/cmds-check.c

[PATCH 01/15] btrfs-progs: lowmem check: introduce repair_inode_item_mismatch()

2018-01-26 Thread Su Yue
New function repair_inode_item_mismatch() only changes inode item' filetype. Signed-off-by: Su Yue --- cmds-check.c | 52 1 file changed, 52 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index

[PATCH 14/15] btrfs-progs: check: handle mismatched filetype in repair_inode_backref

2018-01-26 Thread Su Yue
Original can't handle mismatched well. Since it only records inode mode and one filetype of dir_item or dir_index. If backref has mismatched filetype, the one filetype is untrusted. The only trusted thing is inode mode. So, if we found mismatched filetype in a backref, just delete dir_index and

[PATCH 12/15] btrfs-progs: check: increase counter error in check_inode_recs()

2018-01-26 Thread Su Yue
Counter @error decides return values of check_inode_recs(). Previously, @error won't be incremented even repair_inode_recs() failed. It causes 'btrfs check --repair' prints some error information but returns 0. So, if root dir is missing and repair is disabled, @error should be incremented. And

Re: [PATCH] Btrfs: fix crash due to not cleaning up tree log block's dirty bits

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:51AM -0700, Liu Bo wrote: > In cases that the whole fs flips into readonly status due to failures in > critical sections, then log tree's blocks are still dirty, and this leads > to a crash during umount time, the crash is about use-after-free, > > umount > ->

Re: btrfs check: backref lost, mismatch with its hash -- can't repair

2018-01-26 Thread Qu Wenruo
Branch updated, problem in 1399 should be fixed. Seems the remaining problems are less and less now. Thanks, Qu On 2018年01月26日 19:19, ^m'e wrote: > On Thu, Jan 25, 2018 at 11:30 PM, Qu Wenruo wrote: >> >> Please provide dump for this: >> >> # btrfs inspect dump-tree -t

Re: [PATCH] Btrfs: fix deadlock in run_delalloc_nocow

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:50AM -0700, Liu Bo wrote: > @cur_offset is not set back to what it should be (@cow_start) if > btrfs_next_leaf() returns something wrong, and the range [cow_start, > cur_offset) remains locked forever. > > cc: > Signed-off-by: Liu Bo

degraded permanent mount option

2018-01-26 Thread Christophe Yayon
Hi all, I don't know if it the right place to ask. Sorry it's not... Just a little question about "degraded" mount option. Is it a good idea to add this option (permanent) in fstab and grub rootflags for raid1/10 array ? Just to allow the system to boot again if a single hdd fail. Of course,

Re: [PATCH] Btrfs: fix unexpected cow in run_delalloc_nocow

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:49AM -0700, Liu Bo wrote: > Fstests generic/475 provides a way to fail metadata reads while > checking if checksum exists for the inode inside run_delalloc_nocow(), > and csum_exist_in_range() interprets error (-EIO) as inode having > checksum and makes its caller

Re: [PATCH] Btrfs: fix extent state leak from tree log

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:52AM -0700, Liu Bo wrote: > It's possible that btrfs_sync_log() bails out after one of the two > btrfs_write_marked_extents() which convert extent state's state bit into > EXTENT_NEED_WAIT from EXTENT_DIRTY/EXTENT_NEW, however only EXTENT_DIRTY > and EXTENT_NEW are

Re: [PATCH] Btrfs: fix btrfs_evict_inode to handle abnormal inodes correctly

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:53AM -0700, Liu Bo wrote: > This regression is introduced in > commit 3d48d9810de4 ("btrfs: Handle uninitialised inode eviction"). > > There are two problems, > > a) it is ->destroy_inode() that does the final free on inode, not >->evict_inode(), > b)

Re: [PATCH] Btrfs: enhance leak debug checker for extent state and extent buffer

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:48AM -0700, Liu Bo wrote: > This prints out eb->bflags since it contains some useful information, > e.g. whether eb is dirty. > > Signed-off-by: Liu Bo Reviewed-by: Josef Bacik Thanks, Josef -- To unsubscribe from this list:

Re: degraded permanent mount option

2018-01-26 Thread Austin S. Hemmelgarn
On 2018-01-26 09:47, Christophe Yayon wrote: Hi Austin, Thanks for your answer. It was my opinion too as the "degraded" seems to be flagged as "Mostly OK" on btrfs wiki status page. I am running Archlinux with recent kernel on all my servers (because of use of btrfs as my main filesystem, i

Re: [PATCH] Btrfs: fix use-after-free on root->orphan_block_rsv

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:54AM -0700, Liu Bo wrote: > I got these from running generic/475, > > WARNING: CPU: 0 PID: 26384 at fs/btrfs/inode.c:3326 > btrfs_orphan_commit_root+0x1ac/0x2b0 [btrfs] > BUG: unable to handle kernel NULL pointer dereference at 0010 > IP:

Re: degraded permanent mount option

2018-01-26 Thread Austin S. Hemmelgarn
On 2018-01-26 09:02, Christophe Yayon wrote: Hi all, I don't know if it the right place to ask. Sorry it's not... No, it's just fine to ask here. Questions like this are part of why the mailing list exists. Just a little question about "degraded" mount option. Is it a good idea to add this

Re: [PATCH v2] btrfs: handle failure of add_pending_csums

2018-01-26 Thread Josef Bacik
On Mon, Jan 08, 2018 at 10:59:43AM +0200, Nikolay Borisov wrote: > add_pending_csums was added as part of the new data=ordered implementation in > e6dcd2dc9c48 ("Btrfs: New data=ordered implementation"). Even back then it > called the btrfs_csum_file_blocks which can fail but it never bothered >

Re: degraded permanent mount option

2018-01-26 Thread Christophe Yayon
Hi Austin, Thanks for your answer. It was my opinion too as the "degraded" seems to be flagged as "Mostly OK" on btrfs wiki status page. I am running Archlinux with recent kernel on all my servers (because of use of btrfs as my main filesystem, i need a recent kernel). Your idea to add a

[RFC PATCH] btrfs: Gracefully handle errors in btrfs_qgroup_trace_extent_post

2018-01-26 Thread Nikolay Borisov
Running generic/019 with qgroups on the scratch device enabled is almost guaranteed to trigger the BUG_ON in btrfs_free_tree_block. It's supposed to trigger only on -ENOMEM, in reality, however, it's possible to get -EIO from btrfs_qgroup_trace_extent_post. This function just finds the roots of

Re: [PATCH] Btrfs: do not check inode's runtime flags under root->orphan_lock

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:55AM -0700, Liu Bo wrote: > It's not necessary to hold ->orphan_lock when checking inode's runtime > flags. > > Signed-off-by: Liu Bo Reviewed-by: Josef Bacik Thanks, Josef -- To unsubscribe from this list: send the line

Re: [PATCH] Btrfs: fix unexpected -EEXIST when creating new inode

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 11:02:56AM -0700, Liu Bo wrote: > The highest objectid, which is assigned to new inode, is decided at > the time of initializing fs roots. However, in cases where log replay > gets processed, the btree which fs root owns might be changed, so we > have to search it again

Re: [PATCH] btrfs: tree-checker: Replace root parameter with fs_info

2018-01-26 Thread Josef Bacik
On Thu, Jan 25, 2018 at 02:56:18PM +0800, Qu Wenruo wrote: > When inspecting the error message with real corruption, the "root=%llu" > always shows "1" (root tree), instead of correct owner. > > The problem is that we are getting @root from page->mapping->host, which > points the same btree

Re: btrfs check: backref lost, mismatch with its hash -- can't repair

2018-01-26 Thread ^m'e
On Fri, Jan 26, 2018 at 12:16 PM, Qu Wenruo wrote: > Branch updated, problem in 1399 should be fixed. > > Seems the remaining problems are less and less now. > > Thanks, > Qu > Great! The fix worked, and repair goes throught at last :-) though we're still left with some

Re: [PATCH] Btrfs: fix unexpected -EEXIST when creating new inode

2018-01-26 Thread Nikolay Borisov
On 25.01.2018 20:02, Liu Bo wrote: > The highest objectid, which is assigned to new inode, is decided at > the time of initializing fs roots. However, in cases where log replay > gets processed, the btree which fs root owns might be changed, so we > have to search it again for the highest

[PATCH 03/26] libbtrfsutil: add Python bindings

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval The C libbtrfsutil library isn't very useful for scripting, so we also want bindings for Python. Writing unit tests in Python is also much easier than doing so in C. Only Python 3 is supported; if someone really wants Python 2 support, they can write their own

[PATCH 00/26] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library"

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Hello, One of the features requests I get most often is a library to do the sorts of operations that we do with btrfs-progs. We can shell out to btrfs-progs, but the output format isn't always easily parsasble, and shelling out isn't always ideal. There's

[PATCH 13/26] libbtrfsutil: add btrfs_util_deleted_subvolumes()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 19 +++ libbtrfsutil/python/btrfsutilpy.h | 3 + libbtrfsutil/python/module.c| 30 ++ libbtrfsutil/python/qgroup.c

[PATCH 12/26] libbtrfsutil: add btrfs_util_delete_subvolume()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval We also support recursive deletion using a subvolume iterator. Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 30 libbtrfsutil/python/btrfsutilpy.h | 1 + libbtrfsutil/python/module.c

[PATCH 16/26] btrfs-progs: use libbtrfsutil for sync ioctls

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Signed-off-by: Omar Sandoval --- cmds-filesystem.c | 20 ++-- cmds-qgroup.c | 7 --- cmds-subvolume.c | 23 ++- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/cmds-filesystem.c

[PATCH 05/26] libbtrfsutil: add qgroup inheritance helpers

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval We want to hide struct btrfs_qgroup_inherit from the user because that comes from the Btrfs UAPI headers. Instead, wrap it in a struct btrfs_util_qgroup_inherit and provide helpers to manipulate it. This will be used for subvolume and snapshot creation.

[PATCH 14/26] libbtrfsutil: add filesystem sync helpers

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Namely, sync, start_sync, and wait_sync. Signed-off-by: Omar Sandoval --- Makefile | 4 +- libbtrfsutil/btrfsutil.h | 44 libbtrfsutil/filesystem.c|

[PATCH 11/26] libbtrfsutil: add btrfs_util_create_snapshot()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Thanks to subvolume iterators, we can also implement recursive snapshot fairly easily. Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 55 + libbtrfsutil/python/btrfsutilpy.h | 1 +

[PATCH 09/26] libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval set_default_subvolume() is a trivial ioctl(), but there's no ioctl() for get_default_subvolume(), so we need to search the root tree. Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 37 +

[PATCH 15/26] btrfs-progs: use libbtrfsutil for read-only property

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Signed-off-by: Omar Sandoval --- props.c | 69 - 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/props.c b/props.c index cddbd927..e4edba06 100644 --- a/props.c

[PATCH 08/26] libbtrfsutil: add btrfs_util_[gs]et_read_only()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval In the future, btrfs_util_[gs]et_subvolume_flags() might be useful, but since these are the only subvolume flags we've defined in all this time, this will do for now. Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h

[PATCH 17/26] btrfs-progs: use libbtrfsutil for set-default

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 47 ++- messages.h | 14 ++ 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c

[PATCH 24/26] btrfs-progs: add recursive snapshot/delete using libbtrfsutil

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval And update the documentation. Signed-off-by: Omar Sandoval --- Documentation/btrfs-subvolume.asciidoc | 14 -- cmds-subvolume.c | 25 + 2 files changed, 33 insertions(+), 6

[PATCH 20/26] btrfs-progs: use libbtrfsutil for subvol delete

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Most of the interesting part of this command is the commit mode, so this only saves a little bit of code. Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 23 --- 1 file changed, 8 insertions(+), 15 deletions(-) diff

[PATCH 07/26] libbtrfsutil: add btrfs_util_subvolume_info()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval This gets the the information in `btrfs subvolume show` from the root item. Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 109 libbtrfsutil/python/btrfsutilpy.h | 3 +

[PATCH 04/26] libbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval These are the most trivial helpers in the library and will be used to implement several of the more involved functions. Signed-off-by: Omar Sandoval --- Makefile| 2 +- libbtrfsutil/btrfsutil.h

[PATCH 02/26] Add libbtrfsutil

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Currently, users wishing to manage Btrfs filesystems programatically have to shell out to btrfs-progs and parse the output. This isn't ideal. The goal of libbtrfsutil is to provide a library version of as many of the operations of btrfs-progs as possible and

[PATCH 06/26] libbtrfsutil: add btrfs_util_create_subvolume()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Doing the ioctl() directly isn't too bad, but passing in a full path is more convenient than opening the parent and passing the path component. Signed-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 52 ++

[PATCH 18/26] btrfs-progs: use libbtrfsutil for get-default

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval The only thing of note here is the "top level" column. This used to mean something else, but for a long time it has been equal to the parent ID. I preserved this for backwards compatability. Signed-off-by: Omar Sandoval --- cmds-subvolume.c

[PATCH 21/26] btrfs-progs: use libbtrfsutil for subvol show

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval Now implemented with btrfs_util_subvolume_path(), btrfs_util_subvolume_info(), and subvolume iterators. Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 150 --- utils.c | 118

[PATCH 10/26] libbtrfsutil: add subvolume iterator helpers

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval This is how we can implement stuff like `btrfs subvol list`. Rather than producing the entire list upfront, the iterator approach uses less memory in the common case where the whole list is not stored (O(max subvolume path length)). It supports both pre-order

[PATCH 26/26] btrfs-progs: use libbtrfsutil for subvolume list

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval This is the most involved conversion because it replaces the libbtrfs implementation entirely. I took care to preserve the existing behavior in all cases, warts and all. Signed-off-by: Omar Sandoval --- btrfs-list.c | 953

[PATCH 01/26] btrfs-progs: get rid of undocumented qgroup inheritance options

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval The -c option to subvol create and the -c and -x options to subvol snapshot have never been documented (and -x doesn't actually work because it's not in the getopt option string). The functionality is dubious and the kernel interface is being removed, so get

[PATCH 23/26] btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval This gets the remaining occurrences that weren't covered by previous conversions. Signed-off-by: Omar Sandoval --- cmds-qgroup.c| 13 ++--- cmds-subvolume.c | 11 --- utils.c | 34

[PATCH 25/26] btrfs-progs: deprecate libbtrfs helpers with libbtrfsutil equivalents

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval The old libbtrfs defines some helpers which do the same thing as some libbtrfsutil helpers. Reimplement the libbtrfs helpers in terms of the libbtrfsutil APIs and mark the libbtrfs versions as deprecated, which we could ideally get rid of eventually.

[PATCH 22/26] btrfs-progs: use libbtrfsutil for subvol sync

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval btrfs_util_f_deleted_subvolumes() replaces enumerate_dead_subvols() and btrfs_util_f_subvolume_info() replaces is_subvolume_cleaned(). Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 217

[PATCH 19/26] btrfs-progs: use libbtrfsutil for subvol create and snapshot

2018-01-26 Thread Omar Sandoval
From: Omar Sandoval These become trivial calls to the libbtrfsutil helpers, and we can get rid of the qgroup inherit code in progs. Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 225 ++- qgroup.c

Re: [PATCH 00/26] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library"

2018-01-26 Thread Hugo Mills
On Fri, Jan 26, 2018 at 10:40:48AM -0800, Omar Sandoval wrote: > From: Omar Sandoval > > Hello, > > One of the features requests I get most often is a library to do the > sorts of operations that we do with btrfs-progs. We can shell out to > btrfs-progs, but the output format

Re: [PATCH 11/26] libbtrfsutil: add btrfs_util_create_snapshot()

2018-01-26 Thread Goffredo Baroncelli
On 01/26/2018 07:40 PM, Omar Sandoval wrote: > From: Omar Sandoval Hi, this is a great work; only few comments: 1) I found not intuitive the naming of the function: i.e. you have btrfs_util_create_snapshot() btrfs_util_f_create_snapshot() To me it seems more clear to have

Re: [PATCH 11/26] libbtrfsutil: add btrfs_util_create_snapshot()

2018-01-26 Thread Omar Sandoval
On Fri, Jan 26, 2018 at 08:31:06PM +0100, Goffredo Baroncelli wrote: > On 01/26/2018 07:40 PM, Omar Sandoval wrote: > > From: Omar Sandoval > > > Hi, > > this is a great work; only few comments: > 1) I found not intuitive the naming of the function: i.e. you have > >

Re: degraded permanent mount option

2018-01-26 Thread Christophe Yayon
Hi Chris, Thanks for this complete answer. I have to do some benchmark with mdadm raid and btrfs native raid... Thanks -- Christophe Yayon > On 26 Jan 2018, at 22:54, Chris Murphy wrote: > >> On Fri, Jan 26, 2018 at 7:02 AM, Christophe Yayon

[PATCH] btrfs: print error if primary super block write fails

2018-01-26 Thread Howard McLauchlan
Presently, failing a primary super block write but succeeding in at least one super block write in general will appear to users as if nothing important went wrong. However, upon unmounting and re-mounting, the file system will be in a rolled back state. This was discovered with a BCC program that

Re: degraded permanent mount option

2018-01-26 Thread Chris Murphy
On Fri, Jan 26, 2018 at 7:02 AM, Christophe Yayon wrote: > Just a little question about "degraded" mount option. Is it a good idea to > add this option (permanent) in fstab and grub rootflags for raid1/10 array ? > Just to allow the system to boot again if a single hdd

Re: [RFC PATCH] btrfs: Gracefully handle errors in btrfs_qgroup_trace_extent_post

2018-01-26 Thread Qu Wenruo
On 2018年01月27日 10:26, Qu Wenruo wrote: > > > On 2018年01月26日 22:13, Nikolay Borisov wrote: >> Running generic/019 with qgroups on the scratch device enabled is >> almost guaranteed to trigger the BUG_ON in btrfs_free_tree_block. It's >> supposed to trigger only on -ENOMEM, in reality, however,

Re: [PATCH 01/26] btrfs-progs: get rid of undocumented qgroup inheritance options

2018-01-26 Thread Qu Wenruo
On 2018年01月27日 02:40, Omar Sandoval wrote: > From: Omar Sandoval > > The -c option to subvol create and the -c and -x options to subvol > snapshot have never been documented (and -x doesn't actually work > because it's not in the getopt option string). The functionality is >

Re: [PATCH 11/26] libbtrfsutil: add btrfs_util_create_snapshot()

2018-01-26 Thread Omar Sandoval
On Sat, Jan 27, 2018 at 01:00:58PM +0800, Qu Wenruo wrote: > > > On 2018年01月27日 03:46, Omar Sandoval wrote: > > On Fri, Jan 26, 2018 at 08:31:06PM +0100, Goffredo Baroncelli wrote: > >> On 01/26/2018 07:40 PM, Omar Sandoval wrote: > >>> From: Omar Sandoval > >> > >> > >> Hi, >

[PATCH] btrfs: Fix UAF

2018-01-26 Thread Nikolay Borisov
Commit 4fde46f0cc71 ("Btrfs: free the stale device") introduced btrfs_free_stale_device which iterates the device lists for all registered btrfs filesystems and deletes those devices which aren't mounted. In a btrfs_devices structure has only 1 device attached to it and it is unused then

Re: [PATCH] btrfs: print error if primary super block write fails

2018-01-26 Thread Qu Wenruo
On 2018年01月27日 06:47, Howard McLauchlan wrote: > Presently, failing a primary super block write but succeeding in at > least one super block write in general will appear to users as if > nothing important went wrong. However, upon unmounting and re-mounting, > the file system will be in a rolled

Re: degraded permanent mount option

2018-01-26 Thread Andrei Borzenkov
26.01.2018 17:47, Christophe Yayon пишет: > Hi Austin, > > Thanks for your answer. It was my opinion too as the "degraded" seems to be > flagged as "Mostly OK" on btrfs wiki status page. I am running Archlinux with > recent kernel on all my servers (because of use of btrfs as my main >

Re: [RFC PATCH] btrfs: Gracefully handle errors in btrfs_qgroup_trace_extent_post

2018-01-26 Thread Qu Wenruo
On 2018年01月26日 22:13, Nikolay Borisov wrote: > Running generic/019 with qgroups on the scratch device enabled is > almost guaranteed to trigger the BUG_ON in btrfs_free_tree_block. It's > supposed to trigger only on -ENOMEM, in reality, however, it's possible > to get -EIO from

Re: [PATCH 11/26] libbtrfsutil: add btrfs_util_create_snapshot()

2018-01-26 Thread Qu Wenruo
On 2018年01月27日 03:46, Omar Sandoval wrote: > On Fri, Jan 26, 2018 at 08:31:06PM +0100, Goffredo Baroncelli wrote: >> On 01/26/2018 07:40 PM, Omar Sandoval wrote: >>> From: Omar Sandoval >> >> >> Hi, >> >> this is a great work; only few comments: >> 1) I found not intuitive the

Re: degraded permanent mount option

2018-01-26 Thread Christophe Yayon
I think you are right, i do not see any systemd message when degraded option is missing and have to remount manually with degraded. It seems it is better to use mdadm for raid and btrfs over it as i understand. Even in recent kernel ? I hav me to do some bench and compare... Thanks --

Re: degraded permanent mount option

2018-01-26 Thread Andrei Borzenkov
27.01.2018 09:40, Christophe Yayon пишет: > Hi, > > I am using archlinux with kernel 4.14, there is btrfs module in initrd. > In fstab root is mounted via UUID. As far as I know the UUID is the same > for all devices in raid array. > The system boot with no problem with degraded and only 1/2