summaryrefslogtreecommitdiff
path: root/chunk-recover.c
Commit message (Collapse)AuthorAge
* btrfs-progs: constify pathnames passed as argumentsJeff Mahoney2018-08-06
| | | | | | | | | It's unlikely we're going to modify a pathname argument, so codify that and use const. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Factor out common print_device_infoNikolay Borisov2018-01-31
| | | | | | | | | This function has been copied twice in chunk-recover and super-recover. Factor it out into utils.c/h and use it. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add crude error handling when transaction start failsDavid Sterba2017-09-08
| | | | | | | | | | Currently transaction bugs out insided btrfs_start_transaction in case of error, we want to lift the error handling to the callers. This patch adds the BUG_ON anywhere it's been missing so far. This is not the best way of course. Transforming BUG_ON to a proper error handling highly depends on the caller and should be dealt with case by case. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_add_system_chunk to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_find_device to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor block sizes users in chunk-recover.cQu Wenruo2017-07-03
| | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Refactor block sizes users in disk-io.cQu Wenruo2017-07-03
| | | | | | | | | Since we have cached block sizes in fs_info, there is no need to specify these sizes in btrfs_setup_root() function. And refactor all root->sector/node/stripesize users in disk-io.c. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Introduce sectorsize nodesize and stripesize members forQu Wenruo2017-07-03
| | | | | | | | | | | | | btrfs_fs_info Just like what we do in kernel, since we will not support different leaf/node/stripe size per tree, there is no need to store these block sizes in btrfs_root. This patch will introduce these block size members into btrfs_fs_info structure, allowing us to convert such usage in later patches. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Remove deprecated leafsize usageQu Wenruo2017-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | Leafsize is deprecated for a long time, and kernel has already updated ctree.h to rename sb->leafsize to sb->__unused_leafsize. This patch will remove normal users of leafsize: 1) Remove leafsize member from btrfs_root structure Now only root->nodesize and root->sectorisze. No longer root->leafsize. 2) Remove @leafsize parameter from btrfs_setup_root() function Since no root->leafsize, no need for @leafsize parameter. The remaining user of leafsize will be: 1) btrfs inspect-internal dump-super Reformat the "leafsize" output to "leafsize (deprecated)" and use le32_to_cpu() to do the cast manually. 2) mkfs We still need to set sb->__unused_leafsize to nodesize. Do the manual cast too. 3) convert Same as mkfs, these two superblock setup should be merged later Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: remove unused argument from set_extent_dirtyDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from btrfs_add_system_chunkDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from set_extent_bitsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from btrfs_csum_dataDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add OPEN_CTREE_INVALIDATE_FST flagOmar Sandoval2016-11-23
| | | | | | | | | | If this flag is passed to open_ctree(), we'll clear the FREE_SPACE_TREE_VALID compat_ro bit. The kernel will then reconstruct the free space tree the next time the filesystem is mounted. Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: chunk-recover: use on-stack path buffer in rebuild_block_groupDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename __setup_root and change to return voidDavid Sterba2016-10-05
| | | | | | Exported function should use a prefix. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: chunk-recover: handle duplicate cache entriesDavid Sterba2016-10-05
| | | | | | Triggered by fuzzed image bko-155621-bad-block-group-offset.raw . Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: change btrfs_csum_final result param type to u8Domagoj Tršan2016-10-03
| | | | | Signed-off-by: Domagoj Tršan <domagoj.trsan@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use standard allocation functions in non-kenrel codeDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: chunk-recover: improve error handling in insert_stripeDavid Sterba2016-09-21
| | | | | | Switch to negative errnos, the callchain handles errors. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make superblock reading/scanning api more genericDavid Sterba2016-08-24
| | | | | | We'll add more modes that affect scanning. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: typo review of strings and commentsNicholas D Steeves2016-06-01
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: replace leafsize with nodesizeDavid Sterba2016-05-02
| | | | | | | | Nodesize is used in kernel, the values are always equal. We have to keep leafsize in headers, similarly the tree setting functions still take and set leafsize, but it's effectively a no-op. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix endian bugs in chunk rebuildingByongho Lee2016-01-12
| | | | | | | | | | This is a same patch as Zach Brown's but we lost so I resend it based on current code. - 'commit 2cd95f945a61 ("fix endian bugs in chunk rebuilding")' Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: chunk-recovery: Fix a float point errorQu Wenruo2015-11-19
| | | | | | | | | | Fix a zero division causing chunk-recovery fail. Also fix a typo "strpie_length" -> "stripe_length". Reported-by: Scotty Edmonds <scotty@scottyedmonds.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use on-stack buffer in recover_prepareDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use on-stack variable in __rebuild_device_itemsDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix memory leak on error pathEryu Guan2015-11-02
| | | | | | | dev_scans and t_scans should be freed on malloc error. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use calloc instead of malloc+memsetSilvio Fricke2015-10-21
| | | | | | | | | | | | | | | | | | | | | | This patch is generated from a coccinelle semantic patch: identifier t; expression e; statement s; @@ -t = malloc(e); +t = calloc(1, e); ( if (!t) s | if (t == NULL) s | ) -memset(t, 0, e); Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> [squashed patches into one] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from block_group_free_all_extentZhao Lei2015-09-02
| | | | | Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix some spelling typos in chunk-recover.cZhao Lei2015-09-02
| | | | | | | Only comment, not big issue. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: stat info for btrfs rescue chunk-recoverZhao Lei2015-09-02
| | | | | | | | | | | | | | | | | | | chunk-recover need to use many many time in scan_devices(), and no output in screen: # btrfs rescue chunk-recover /dev/sda6 (no output here, but need long time) To notice user that "the command is not hang", this patch add dynamic updated stat information in above period: # btrfs rescue chunk-recover /dev/sda6 Scanning: DONE in dev[0], 19998441472 in dev[1], DONE in dev[2] (until) Scanning: DONE in dev0, DONE in dev1, DONE in dev2 Check chunks successfully with no orphans Recover the chunk tree successfully. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use long type to get thread's return valueZhao Lei2015-09-02
| | | | | | | | | | | pthread use void * to save return status, we can use this pointer to save our return value, but we need to keep the same length. This patch move to use long type variable to save return value of our thread, to avoid potential invalid memory access. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use for loop for scan_devicesZhao Lei2015-09-02
| | | | | | | for() is more suitable than while() in this code block. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use android compat headerDavid Sterba2015-09-01
| | | | | | Applies to sources where pthreads are used. Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: skip opening all devices with restoreJosef Bacik2015-02-09
| | | | | | | | | | | When we go to fixup the dev items after a restore we scan all existing devices. If you happen to be a btrfs developer you could possibly open up some random device that you didn't just restore onto, which gives you weird errors and makes you super cranky and waste a day trying to figure out what is failing. This will make it so that we use the fd we've already opened for opening our ctree. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* btrfs-progs: autoconf: use standard PACKAGE_* macrosKarel Zak2015-01-28
| | | | | | | | | | | | | - use standard PACKAGE_{NAME,VERSION,STRING,URL,...} autoconf macros rather than homemade BTRFS_BUILD_VERSION - don't #include version.h, now the file is necessary for library API only Note that "btrfs version" returns "btrfs-progs <version>" instead of the original confusing "btrfs <version>". Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: drop feature defines from C files, in favour of CFLAGS definesDimitri John Ledkov2015-01-27
| | | | | | | | | | | | | | | | | | | | | | glibc 2.10+ (5+ years old) enables all the desired features: _XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined. This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c). This patch thus cleans up all feature defines, and sets them at a consistent level. Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969 Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: rebuild missing block group during chunk recovery if possibleQu Wenruo2014-12-04
| | | | | | | | | | | | | | | | | | | Before the patch, chunk will be considered bad if the corresponding block group is missing, even the only uncertain data is the 'used' member of the block group. This patch will try to recalculate the 'used' value of the block group and rebuild it. So even only chunk item and dev extent item is found, the chunk can be recovered. Although if extent tree is damanged and needed extent item can't be read, the block group's 'used' value will be the block group length, to prevent any later write/block reserve damaging the block group. In that case, we will prompt user and recommend them to use '--init-extent-tree' to rebuild extent tree if possible. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: introduce a proper structure on which cli will call ↵Anand Jain2014-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | register-device ioctl As of now commands mentioned below (with in [..]) are calling call register-device ioctl BTRFS_IOC_SCAN_DEV for all the devices in the system. Some issues with it: BTRFS_IOC_SCAN_DEV: ioctl is a write operation, we don't want command like btrfs-debug-tree threads to do that.. eg: ---- $ cat /proc/fs/btrfs/devlist | egrep fsid | wc -l 0 $ btrfs-debug-tree /dev/sde (num_device > 1) $ cat /proc/fs/btrfs/devlist | egrep fsid | wc -l 5 ---- btrfs_scan_fs_devices() ends up calling this ioctl only when num_device > 1. That's inconsistency with in feature/bug. We don't have to register _all_ the btrfs devices (again) in the system without user consent. Why its inconsistent: function btrfs_scan_fs_devices() calls btrfs_scan_lblkid only when num_devices is > 1, which in turn calls BTRFS_IOC_SCAN_DEV ioctl, if conditions are met. But main issue is we have too many consumers of btrfs_scan_fs_devices() the names below with in [] is the cli leading to this function. open_ctree_broken() [btrfs-find-root] recover_prepare() [btrfs rescue super-recover] __open_ctree_fd (updates always except when flag OPEN_CTREE_RECOVER_SUPER is set and flag OPEN_CTREE_RECOVER_SUPER is set only by 'btrfs rescue super- recover' but still this thread sneaks through the open_ctree function to call register-device-ioctl as show below). open_ctree_fs_info [btrfs-debug-tree] [btrfs-image -r] [btrfs check] open_fs [btrfs restore] open_ctree [calc-size] [btrfs-corrupt-block] [btrfs-image] (create) [btrfs-map-logical] [btrfs-select-super] [btrfstune] [btrfs-zero-log] [tester] [mkfs] [quick-test.c] [btrfs label set unmounted] [btrfs get label unmounted] [btrfs rescue super-recover] open_ctree_fd [btrfs-convert] Fix: In an effort to make register-device consistent, all calls to btrfs_scan_fs_devices() will have 5th parameter set to 0. that means we don't need 5th parameter at all. And with this function not calling the register ioctl at all, finally we will have following two cli to call the ioctl BTRFS_IOC_SCAN_DEV. btrfs dev scan and mkfs.btrfs Threads needing to update kernel about a device would have to use btrfs_register_one_device() separately. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix uninitialized warning in btrfs_calc_stripe_indexAnand Jain2014-10-14
| | | | | | | | chunk-recover.c: In function btrfs_calc_stripe_index chunk-recover.c:1481: warning: index may be used uninitialized in this function Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Fix malloc size for superblock.Qu Wenruo2014-10-10
| | | | | | | | | | | recover_prepare() in chunk-recover.c alloc memory which only contains sizeof(struct btrfs_super_block). This will cause glibc malloc error after superblock csum is calculated. Use BTRFS_SUPER_INFO_SIZE to fix the bug. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Allow btrfs_read_dev_super() to read all 3 super for super_recover.Qu Wenruo2014-08-22
| | | | | | | | | | | | | | Btrfs-progs superblock checksum check is somewhat too restricted for super-recover, since current btrfs-progs will only read the 1st superblock and if you need super-recover the 1st superblock is possibly already damaged. The fix is introducing super_recover parameter for btrfs_read_dev_super() and callers to allow scan backup superblocks if needed. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: replace BTRFS_NUM_MIRRORS with BTRFS_MAX_MIRRORSGui Hecheng2014-08-22
| | | | | | | | | | | | | | | The chunk-recover.c/BTRFS_NUM_MIRRORS in the userspace means the same thing as ctree.h/BTRFS_MAX_MIRRORS in the kernelspace, so to stay consistent with the kernelspace, just make this movement in the userspace: chunk-recover.c/BTRFS_NUM_MIRRORS ===> ctree.h/BTRFS_MAX_MIRRORS This provides convenience for future use. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix max mirror number error for chunk-recoverGui Hecheng2014-08-22
| | | | | | | | | | | | | | | When run chunk-recover on a health btrfs(data profile raid0, with plenty of data), the program has a chance to abort on the number of mirrors of an extent. According to the kernel code, the max mirror number of an extent is 3 not 2: ctree.h: BTRFS_MAX_MIRRORS 3 chunk-recover.c : BTRFS_NUM_MIRRORS 2 just change BTRFS_NUM_MIRRORS to 3, and everything goes well. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix missing parity stripe for raid6 in chunk-recoverGui Hecheng2014-08-22
| | | | | | | | | | When deal with the p & q stripes for data profile raid6, chunk-recover forgets to insert them into the chunk record. Just insert them back freely. Also wrap the insert procedure into a new function, fill_chunk_up. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup unused assignment for chunk-recoverGui Hecheng2014-08-22
| | | | | | | | The 'num_unordered' will be recounted after 'goto out', just remove it. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix blindly goto failure for chunk-recoverGui Hecheng2014-08-22
| | | | | | | | | | | If the csum of one stripe is not able to judge the order of two device extents, the stripe may happen to belong to the device extent that is already kicked out as ordered. Take this condition into consideration, don't report failure and give more tries with the stripes following. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix uninitialized number count in chunk-recoverGui Hecheng2014-08-22
| | | | | | | | | When count the number of unordered device extents in chunk-recover, the counter should be reinitialized to be used. Also, introduce a new function for the counting job. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: chunk_recovery: fix mem leak and pthread_cancel callRakesh Pandit2014-04-22
| | | | | | | | | | | | | Free memory if open call fails. Prevent pthread_cancel on threads which have already finished successfully. If all calls to pthread_create and pthread_join are successful, we mistakenly call pthread_cancel because cancel_from and cancel_to are both zero. Make POSIX.1-2001 happy by supplying a non-NULL second argument to pthread_setcanceltype. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>