summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAge
* btrfs-progs: move check_arg_type() to util.cGui Hecheng2014-12-29
| | | | | | | | | The check_arg_type() function does quite generic thing, move it to utils.c. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix btrfs fi show by uuid and labelJustin Maggard2014-12-29
| | | | | | | | | | | | | | | | Commit 8be2fff (btrfs-progs: apply realpath for btrfs fi show when mount point is given) changed the behavior of btrfs fi show to return an error if the call to realpath() failed. This broke the ability to specify a filesystem by uuid or label. So let's not consider a failed call to realpath() as an error. If the user really specified a bad device, just return nothing like we did before. Signed-off-by: Justin Maggard <jmaggard10@gmail.com> Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix a bug in reset_nlink() which may deletes the recovered fileQu Wenruo2014-12-29
| | | | | | | | | | | | | | | | In reset_nlink(), we believe rec->found_link as accurate number of the valid links. However it only records the number of found DIR_ITEM, so we can't use it as reliable value. Before this patch, in some case, leaf corruption recovery will believe there is a valid backref but don't add_link() since it can't find any valid one and don't put it into the lost+found dir. So the recovered inode will be considered as an orphan item without orphan item and repair_inode_orphan_item() will add orphan item for it, causing all the filename/filetype we recovered being a waste of time. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs fix wrong memory free on check_is_rootSatoru Takeuchi2014-12-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When "/" is Btrfs, "btrfs property <subcommand> /" regards it as non-root by mistake. check_is_root() regards @object as a file system root if the following two conditions are satisfied. a) Both @object and its parent directory are Btrfs object (file system root, subvolume, inode, and device used for Btrfs). b) fsid of the above mentioned two objects are different. It doesn't work if @object is "/" because, in this case, fsid of "/" and its parent (it's also "/"), are the same. * Test environment Two Btrfs file system (not subvolume) "/" and "/home/sat/mnt". * How to reproduce Submit "btrfs prop get" against the above mentioned file systems. * Test Result ** Actual result (without my patch) ========================== ro=false label= # label is displayed because it's a file system root ro=false # label is not displayed even if it's a file system root ========================== ** Expected result (with my patch) ========================== ro=false label= ro=false label=foo # label is displayed =========================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Reported-by: Naohiro Aota <naota@elisp.net> Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: let btrfs_free_path accept NULLDavid Sterba2014-12-19
| | | | | | | | Same in kernel and matches semantics of free(). Resolves-Coverity-CID: 1054881 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: check allocation result in add_clone_sourceDavid Sterba2014-12-19
| | | | | | Resolves-Coverity-CID: 1054894 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: check result of first_cache_extentDavid Sterba2014-12-19
| | | | | | | | If the tree's empty, we'll get NULL and dereference it. Resolves-Coverity-CID: 1248828 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fragments, close output file on errorDavid Sterba2014-12-19
| | | | | | Resolves-Coverity-CID: 1258794 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: corrupt block, add break after option UDavid Sterba2014-12-19
| | | | | | Resolves-Coverity-CID: 1258793 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: corrupt block, add missing break to option IDavid Sterba2014-12-19
| | | | | | | | Using -I would imply -d. Resolves-Coverity-CID: 1258792 Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: move contents of math.h to utils.h and deleteDavid Sterba2014-12-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup: avoid to use literal for getopt valSatoru Takeuchi2014-12-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Enhance the document of btrfs propertySatoru Takeuchi2014-12-19
| | | | | | | | | | | | Enhance the document of btrfs property as follows. - Add the description about the candidates of <name>. - Enrich the description of <object>. - Fix typos and some redundancy. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Reported-by: Naohiro Aota <naota@elisp.net> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Remove deprecated _BSD_SOURCE macro.Qu Wenruo2014-12-19
| | | | | | | | | | | | | | | | Fix the following gcc(>4.9) and clang warning: In file included from cmds-receive.c:24: In file included from ./kerncompat.h:22: In file included from /usr/include/stdio.h:27: /usr/include/features.h:148:3: warning: "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-W#warnings] ^ 1 warning generated. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Remove a unused function offset_to_bitmap()Qu Wenruo2014-12-19
| | | | | | | | | | | | | | Fix the following clang warning: free-space-cache.c:464:19: warning: unused function 'offset_to_bitmap' [-Wunused-function] static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, ^ 1 warning generated. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Remove a unused function root_gtp_mask().Qu Wenruo2014-12-19
| | | | | | | | | | | | | | Fix the following clang warning when compiling btrfs-progs: radix-tree.c:78:21: warning: unused function 'root_gfp_mask' [-Wunused-function] static inline gfp_t root_gfp_mask(struct radix_tree_root *root) ^ 1 warning generated. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix a clang dead-judgement warning in disk-io.c.Qu Wenruo2014-12-19
| | | | | | | | | | | | | | | | | | | | When compiled with clang, the following warning is outputted. disk-io.c:1017:15: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (dev_size < 0) ~~~~~~~~ ^ ~ 1 warning generated. This is because dev_size is defined as unsigned type, but lseek() will return singed valued. So the judgement will always to false. Use temporary off_t return value to solve it. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Makefile: Move linker only option to LDFLAGSQu Wenruo2014-12-19
| | | | | | | | | | Move the linker only option -rdynamic to LDFLAGS. This resolve lots of the following warning if using clang as CC: clang: warning: argument unused during compilation: '-rdynamic' Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove false dependency on libmDavid Sterba2014-12-19
| | | | | | It ends up in the final binary, but there are not math functions used. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: disable backtrace and define __always_inlineMerlijn Wajer2014-12-18
| | | | | | | | | Disable backtrace and define __always_inline when glibc is not used as libc. This, together with some header changes allows btrfs-progs to compile with musl-libc. Signed-off-by: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: include headers required for musl-libcMerlijn Wajer2014-12-18
| | | | | | | | This fixes various compilation errors where PATH_MAX and XATTR_SIZE_MAX were missing. To my knowledge, this should have no bad side effects. Signed-off-by: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add testcase for leaf-corrupted btrfsck repairing.Qu Wenruo2014-12-18
| | | | | | | Add testcase for leaf-corrupted btrfsck repairing using the new generate_image.sh method. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* Btrfs-progs: add two new test imagesJosef Bacik2014-12-18
| | | | | | | | | | | | | | | | This adds two new test images 1) 008-bad-offset-snapshots. This has a corrupt item with multiple snapshots pointing to it, to make sure the bad block repair stuff doesn't loop and actually repairs stuff. It also requires the dir index repair stuff to pass our built in tests which is why it's not tied to the same commit. 2) 009-bad-dir-index-name.img. This has a corrupt name in a dir index to make sure our dir index repair stuff is working properly. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* btrfs-progs: check, update documentationDavid Sterba2014-12-18
| | | | | | Add recently added options to manpage, a few other rewordings. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: unify unit mode parameters and variablesDavid Sterba2014-12-18
| | | | | | Use unsigned type and a common name everywhere. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: dev usage, update manpageDavid Sterba2014-12-18
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: dev usage, add switches to set output unitsDavid Sterba2014-12-18
| | | | | | | Same set of options as 'fi df': binary and decimal bases, human readable options etc. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fi usage, update manpageDavid Sterba2014-12-18
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fi usage, add switches to set output unitsDavid Sterba2014-12-18
| | | | | | | Same set of options as 'fi df': binary and decimal bases, human readable options etc. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fi usage, change option for tabular output to TDavid Sterba2014-12-17
| | | | | | We're going to use -t for tera- units prefix, same as 'fi df' does. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add a brief explanation of btrfs property in man 8 btrfsSatoru Takeuchi2014-12-17
| | | | | | | | | | | | As Chris reported at the following mail, although btrfs property has its own manpage, man 8 btrfs-property, there is no explanation about it in man 8 btrfs. https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg40134.html Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Reported-by: Chris Murphy <lists@colorremedies.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix typedefKarel Zak2014-12-17
| | | | | Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: tests: build prerequisities, btrfs-image and btrfsDavid Sterba2014-12-12
| | | | | | | Build required utilities from the main Makefile and just check in the test scripts. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: tests: use 'btrfs check' instead of btrfsckDavid Sterba2014-12-12
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: subvol delete: rename variable to match the option nameDavid Sterba2014-12-10
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: subvol delete: add verbosity optionDavid Sterba2014-12-10
| | | | | | Add an the option -v and use it for the transaction commit mode message. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: let subvol delete print commit mode inlineDavid Sterba2014-12-10
| | | | | | | | | | | | There are options to specify if the subvolume deletion should wait for commit after each subvol or at the end. This is reported at the beginning and considered as a noise. We'd like to report the mode for each subvolume instead. http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34617.html Reported-by: Marc MERLIN <marc@merlins.org Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs, fsck: move root items repair after root rebuildingWang Shilong2014-12-10
| | | | | | | | If some critical roots are corrupt, reapr_root_items() will fail, this is detected by fsck_tests.sh's extent rebuilding tests. Signed-off-by: Wang Shilong <wangshilong1991@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fsck: add ability to rebuild extent tree with snapshotsWang Shilong2014-12-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes us to rebuild a really corrupt extent tree with snapshots. To implement this, we have to verify whether a block is FULL BACKREF. This idea come from Josef Bacik: 1) We walk down the original tree, every eb we encounter has btrfs_header_owner(eb) == root->objectid. We add normal references for this root (BTRFS_TREE_BLOCK_REF_KEY) for this root. World peace is achieved. 2) We walk down the snapshotted tree. Say we didn't change anything at all, it was just a clean snapshot and then boom. So the btrfs_header_owner(root->node) == root->objectid, so normal backref. We walk down to the next level, where btrfs_header_owner(eb) != root->objectid, but the level above did, so we add normal refs for all of these blocks. We go down the next level, now our btrfs_header_owner(parent) != root->objectid and btrfs_header_owner(eb) != root->objectid. This is where we need to now go back and see if btrfs_header_owner(eb) currently has a ref on eb. If it does we are done, move on to the next block in this same level, we don't have to go further down. 3) Harder case, we snapshotted and then changed things in the original root. Do the same thing as in step 2, but now we get down to btrfs_header_owner(eb) != root->objectid && btrfs_header_owner(parent) != root->objectid. We lookup the references we have for eb and notice that btrfs_header_owner(eb) no longer refers to eb. So now we must set FULL_BACKREF on this extent reference and add a SHARED_BLOCK_REF_KEY for this eb using the parent->start as the offset. And we need to keep walking down and doing the same thing until we either hit level 0 or btrfs_header_owner(eb) has a ref on the block. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: Wang Shilong <wangshilong1991@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: fsck: deal with snapshot one by one when rebuilding extent treeWang Shilong2014-12-10
| | | | | | | | | | | | | Previously, we deal with node block firstly and then leaf block which can maximize readahead. However, to rebuild extent tree, we need deal with snapshot one by one. This patch makes us deal with snapshot one by one if we need rebuild extent tree otherwise we drop into previous way. Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: Wang Shilong <wangshilong1991@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: basic support for TREE_SEARCH_V2 ioctlDavid Sterba2014-12-10
| | | | | | Add the interface and helper that checks if the v2 ioctl is supported. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: mkfs: make skinny-metadata defaultDavid Sterba2014-12-10
| | | | | | | According to public poll, this is desired and deemed to be safe. Feature introduced in kernel 3.10 (Jun 2013). Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add inode item rebuild function.Qu Wenruo2014-12-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a basic inode item rebuild function for I_ERR_NO_INODE_ITEM. The main use case is to repair btrfs which fs root has corrupted leaf, but it is already working for case if the corrupteed fs root leaf/node contains no inode extent_data. The repair needs 3 elements for inode rebuild: 1. inode number This is quite easy, existing inode_record codes will detect it quite well. 2. inode type This is the trick part. The only reliable method is to recovery it from parent's dir_index/item. The remaining method will search for regular file extent for FILE type or child's backref for DIR(todo). Fallback will be FILE. Inode name(inode_ref) will be recoverd by nlink repair function. This is just a fundamental implement, some advanced recovery can be improved later with btrfs-progs infrastructure change. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Recover btree by dropping corrupted leaf/node.Qu Wenruo2014-12-10
| | | | | | | | | | | | | | | | | Current btrfsck can skip corrupted leaf and even repair some corrupted one if their bytenr or key order is wrong. However when it comes to csum error leaf, btrfsck can only skip them, which is OK for read-only iteration, but is bad for write. This patch introduce the new repair_btree() function to recover the btree, deleting all the corrupted leaf/node including corresponding extent, allowing later write into the btree. This patch provides the basis for later recovery with corrupted leaves. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: record and report leaf/node corruption in fs/subvol treeQu Wenruo2014-12-10
| | | | | | | | | | | | | | When leaf/node is corrupted in fs/subvolume root, btrfsck can ignore it without much pain except some stderr messages complaining about it. But this works fine doing read-only works, if we want to do deeper recovery like rebuild missing inodes in the b+tree, it will cause problem. At least, info user that there is something wrong in the btree, and this patch provides the base for later btree repair. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add fixing function for inodes whose nlink dismatchQu Wenruo2014-12-10
| | | | | | | | | | | | | | | | | | | | | [BUG] At least two users have already hit a bug in btrfs causing file missing(Chromium config file). The missing file's nlink is still 1 but its backref points to non-exist parent inode. This should be a kernel bug, but btrfsck fix is needed anyway. [FIX] For such nlink mismatch inode, we will reset all the inode_ref with its dir_index/item (including valid one), and re-add the valids. If there is no valid backref for it, create 'lost+found' under the root of the subvolume and add link to the directory. Reported-by: Mike Gavrilov <mikhail.v.gavrilov@gmail.com> Reported-by: Ed Tomlinson <edt@aei.ca> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add helper function find_file_name/type for nlink and ↵Qu Wenruo2014-12-10
| | | | | | | | | | | | | | | | inode_item repair. Add find_file_name() and find_file_type() function for later nlink and inode_item repair. Later nlink repair will use both function and and inode_item repair will use find_file_type(). They are done by searching the backref list, dir_item/index for type search and dir_item/index or inode_ref for name search. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add count_digits() function to help calculate filename len.Qu Wenruo2014-12-10
| | | | | | | | Add count_digits() function in utils.h to help calculate filename with ino suffix. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add btrfs_mkdir() function for the incoming 'lost+found' fsck ↵Qu Wenruo2014-12-10
| | | | | | | | | | | | | mechanism. With the previous btrfs inode operations patches, now we can use btrfs_mkdir() to create the 'lost+found' dir to do some data salvage in btrfsck. This patch along with previous ones will make data salvage easier. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Add btrfs_unlink() and btrfs_add_link() functions.Qu Wenruo2014-12-10
| | | | | | | | Add btrfs_unlink() and btrfs_add_link() functions in inode.c, for the incoming btrfs_mkdir() and later inode operations functions. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>