summaryrefslogtreecommitdiff
path: root/btrfs-image.c
Commit message (Collapse)AuthorAge
* btrfs-progs: image: more verbose syntax erors for -t and -cDavid Sterba2016-09-05
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print help test to stdoutDavid Sterba2016-09-05
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: fix minor resource leakDavid Sterba2016-07-15
| | | | | | | It's on error exit path. Resolves-coverity-id: 1354246 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use new random number APIQu Wenruo2016-06-03
| | | | | | | | | | | | | Replace old and not so informal srand()/rand() calls to new random number API. Including btrfs-corrupt-block(main user), btrfs-image and btrfs-crc. Some tests like dir-test/random-test/quick-test is not modified. As random-test itself can't even pass build. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make btrfs-image restore to support dupLu Fengqi2016-06-01
| | | | | | | | | | | | | | Previously btrfs-image restore would set the chunk items to have 1 stripe, even if the chunk is dup. If you use btrfsck on the restored file system, some dev_extent will not find any relative chunk stripe, and the bytes-used of dev_item will not equal to the dev_extents's total_bytes. This patch store a additional physical just for the dup case when build the in-memory chunk-tree. Currently btrfsck on the restored file system, only single and dup is no problem. raid* support should be added in the future. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> 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: Add new option for specify chunk root bytenrLu Fengqi2016-03-14
| | | | | | | | | | Add new btrfsck option, '--chunk-root', to specify chunk root bytenr. And allow open_ctree_fs_info() function accept chunk_root_bytenr to override the bytenr in superblock. This will be mainly used when chunk tree corruption. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify argc min/max checkingDavid Sterba2016-03-14
| | | | | | We don't want to modify argc. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unnecessary errno temp variablesDavid Sterba2016-01-12
| | | | | | | We can read errno directly if it's not clobbered by any intermediate calls. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix endian bug in update_super()Byongho Lee2016-01-12
| | | | | | | | | In update_super() 'chunk->stripe.devid' and 'super->dev_item.devid' both are little endian. So we should not use endian helper btrfs_set_stack_stripe_devid(). Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: reorder initialization in metadump_initDavid Sterba2015-11-16
| | | | | | | Put the allocations first, move pthread cond and mutex last so we don't have to do cleanup. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: fix bogus check after cpu on-line detectionDavid Sterba2015-11-02
| | | | | | | | Comparing unsigned type for <= 0 does not make much sense, we should really check the signed value returned by sysconf. Resolves-coverity-id: 1324536 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: image: close all_devices at the endZhao Lei2015-09-11
| | | | | | | | Devices opened by check_mounted() in main() should closed before the exit of btrfs-image. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: don't create unused threadsZhao Lei2015-09-11
| | | | | | | | In case of creating an image without compression, we don't need to create unused threads. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: fix infinite looping with -t 0Zhao Lei2015-09-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bug: # btrfs-image -t0 -c9 /dev/sda6 /tmp/btrfs_image.img (hang) # btrfs-image -r -t0 /tmp/btrfs_image.img /dev/sda6 (hang) Reason: The program need to create at least 1 thread for compression/decompression. If the user specifies -t0, it overwrites the default value of 1, then the program really creates 0 thread, and ends up looping Fix: We can add a check, to make the program not to allow -t0 argument, but there is another problem: For example, on a node with 4 cpus: btrfs-image -c9 -t1: 4 threads (1 means use NR_CPUS) -c9 -t2: 2 threads -c9 -t3: 3 threads ... (-t1 has more threads than -t2 and -t3) So we change to use value of 0 as "use NR_CPUS threads", then: btrfs-image [no -t arg]: use NR_CPUS threads -t0: use NR_CPUS threads -t val: use val threads. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use on-stack buffer for superblockDavid Sterba2015-09-02
| | | | | | | In update_disk_super_on_device,the buffer size is small, allocate it onstack and get rid of one error path. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: better error handling in update_disk_super_on_deviceDavid Sterba2015-09-02
| | | | | | Return an error code instead of exitting, more verbose messages. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use existing facility to replace read_data_extent functionQu Wenruo2015-08-31
| | | | | | | | | | | | Function read_data_extent() in btrfs-image.c is using manual-and-read codes. Replace it with existing read_extent_data() to reduce duplication. Also, now we can use other mirror to try our best to do the dump, just like read_tree_block(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Avoid reading bad fd in case of missing device.Qu Wenruo2015-08-31
| | | | | | | | | | | | | | | | | Offline btrfs tools, like btrfs-image, will infinitely loop when there is missing device. The reason is, for missing device, it's fd will be set to -1, but before we reading, we only check the fd validation by checking if it's 0. So in that case, -1 will pass the validation check, and cause pread to return 0, and loop to read. Just change the validation check from "== 0" to "<= 0" to avoid such problem. Reported-by: Timothy Normand Miller <theosib@gmail.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: accept --help as option in the standalone utilitiesDavid Sterba2015-06-11
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* 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: make restore update dev itemsJosef Bacik2015-02-09
| | | | | | | | When we restore a multi disk image onto a single disk we need to update the dev items used and total bytes so that fsck doesn't freak out and that we get normal results from stuff like btrfs fi show. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* Btrfs-progs: Introduce metadump_v2Josef Bacik2015-02-09
| | | | | | | | | | The METADUMP super flag makes us skip doing the chunk tree reading which isn't helpful for the new restore since we have a valid chunk tree. But we still want to have a way for the kernel to know that this is a metadump restore so it doesn't do things like verify data checksums. We also want to skip some of the device extent checks in fsck since those will obviously not match. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* Btrfs-progs: multi-thread btrfs-image restoreJosef Bacik2015-02-09
| | | | | | | | For some reason we only allow btrfs-image restore to have one thread, which is incredibly slow with large images. So allow us to do work with more than just one thread. This made my restore go from 16 minutes to 3 minutes. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* btrfs-progs: fix btrfs-image overlapping chunksJosef Bacik2015-02-09
| | | | | | | | | | | | | | If you create a metadump from a striped volume you will have chunks that refer to different logical offsets with the same physical offset on different devices. So when we do the restore we just truncate the number of stripes in each chunk item and carry on, which causes problems because we then have chunks that point to the same physical offset for different logical offsets. To handle this problem we keep track of logical extents that overlap on physical extents. Then we go back and remap these extents into different physical extents on the disk we are restoring onto. This makes us actually able to restore a multi disk image onto a single disk and have everything work out properly. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* Btrfs-progs: read super properly in btrfs-imageJosef Bacik2015-02-09
| | | | | | | | | | | When btrfs-image makes a metadump it'll map all the blocks from their logical address to their physical. This works out fine with the exception of the super block, which is the physical offset. Normally this just works, but if the user has balanced their fs it'll either crash btrfs-image or it'll copy some completely arbitrary data. This forces btrfs-image to read the super directly from the disk. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* btrfs-progs: read_tree_block() and read_node_slot() cleanup.Qu Wenruo2015-02-02
| | | | | | | | | | | | Allow read_tree_block() and read_node_slot() to return error pointer. This should help caller to get more specified error number. For existing callers, change (!eb) judgmentt to (!extent_buffer_uptodate(eb)) to keep the compatibility, and for caller missing the check, use PTR_ERR(eb) if possible. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* 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: Doc: Add explain on 'source' and 'target' for btrfs-image.Qu Wenruo2015-01-21
| | | | | | | | | Add explain on 'source' and 'target', which is somewhat confusing for users who want to restore dumped image. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [reworded texts] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: add mount status check for btrfs-imageGui Hecheng2014-08-22
| | | | | | | | | | | When btrfs-image run on a mounted filesystem, the undergoing fs operations may change what you have imaged a while ago. In this case, give a warning to remind the user that he may not get a consistent image he wants. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> [tweaked the message] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: limit minimal num of args for btrfs-imageGui Hecheng2014-08-22
| | | | | | | | | | | The btrfs-image requires at least 2 args to run, one for the source dev/file, the other for the target dev/file. This patch depends on patch: btrfs-progs: move the check_argc_* functions into utils.c Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup unnecessary free if malloc fails in btrfs-imageGui Hecheng2014-08-22
| | | | | | | Don't bother free the buffer if the malloc failed. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix btrfs-image old_restore fsck failureGui Hecheng2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Steps to reproduce: # mkfs.btrfs -f <dev1> # btrfs-image <dev1> <image_file> # btrfs-image -r -o <image_file> <dev2> # btrfs check <dev2> btrfs check output: : read block failed check_tree_block : Couldn't read tree root : Couldn't open file system The btrfs-image should not mess with the chunk tree under the old_restore way. The new restore way was introduced by: commit d6f7e3da0dae7b60cb7565f8a47c3b9045c52d1d Btrfs-progs: make btrfs-image restore with a valid chunk tree V2 ... And the following commit enhanced the new restore on the valid chunk tree building stuff: commit ef2a8889ef813ba77061f6a92f4954d047a78932 Btrfs-progs: make image restore with the original device offsets ... But the second commit should not effect the old_restore way since the old_restore way doesn't try to build a valid chunk tree at all. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: use BTRFS_SUPER_INFO_SIZE to replace raw 4096 in btrfs-imageGui Hecheng2014-08-22
| | | | | Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup possible silent failure in btrfs-imageGui Hecheng2014-08-22
| | | | | | | | | | If the malloc above fails, the btrfs-image will exit directly without any error messages. Now just return the ENOMEM errno and let the caller prompt the error message. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: deal with malloc failure in btrfs-imageGui Hecheng2014-08-22
| | | | | | | | Handle the malloc failure for dump_worker in the same way as the restore worker. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: delete invalid output file when btrfs-image failedGui Hecheng2014-08-22
| | | | | | | | When btrfs-image failed to create an image, the invalid output file had better be deleted to prevent being used mistakenly in the future. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: deal with invalid option combinations for btrfs-imageGui Hecheng2014-08-22
| | | | | | | | | | | | For btrfs-image, dump may not come with option '-o' -r may not come with option '-c', '-s', '-w', dev_cnt != 1 -m may not come with dev_cnt < 2 All of the above should be regarded as invalid combinations, and the usage will show up. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: update manpage for btrfs-image with -m option addedGui Hecheng2014-08-22
| | | | | | | The btrfs-image support multiple devices with -m specified. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup duplicate assignment of variable leaf for btrfs-imageGui Hecheng2014-08-22
| | | | | | | | The value of variable leaf in while loop don't have to be set for every round. Just move it outside. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Properly size the leafsize field in the mdrestore_struct structAdam Buchbinder2014-08-22
| | | | | | | | | | It's 32 bits as defined in ctree.h, but the struct had it as 64 bits. Found using MemorySanitizer. Signed-off-by: Adam Buchbinder <abuchbinder@google.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-image: Fix a data race in build_chunk_tree.Adam Buchbinder2014-08-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A mdrestore_struct was being written to without its mutex being held. This race was found with ThreadSanitizer; the relevant part of the report looks like this: WARNING: ThreadSanitizer: data race (pid=18828) Write of size 8 at 0x7fffffc3d088 by main thread: #0 build_chunk_tree .../btrfs-progs/btrfs-image.c:2233 #1 __restore_metadump .../btrfs-progs/btrfs-image.c:2294 #2 restore_metadump .../btrfs-progs/btrfs-image.c:2345 #3 main .../btrfs-progs/btrfs-image.c:2545 Previous read of size 8 at 0x7fffffc3d088 by thread T1 (mutexes: write M0): #0 restore_worker .../btrfs-progs/btrfs-image.c:1636 Location is stack of main thread. Mutex M0 created at: #0 pthread_mutex_init ??:0 #1 mdrestore_init .../btrfs-progs/btrfs-image.c:1766 #2 __restore_metadump .../btrfs-progs/btrfs-image.c:2286 #3 restore_metadump .../btrfs-progs/btrfs-image.c:2345 #4 main .../btrfs-progs/btrfs-image.c:2545 Thread T1 (tid=18830, running) created by main thread at: #0 pthread_create ??:0 #1 mdrestore_init .../btrfs-progs/btrfs-image.c:1784 #2 __restore_metadump .../btrfs-progs/btrfs-image.c:2286 #3 restore_metadump .../btrfs-progs/btrfs-image.c:2345 #4 main .../btrfs-progs/btrfs-image.c:2545 Signed-off-by: Adam Buchbinder <abuchbinder@google.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: btrfs-image: don't call pthread_join on IDs not presentRakesh Pandit2014-04-22
| | | | | | | | | | | | | | | | If pthread_create fails in mdrestore_init, then number of threads created could be less then num of threads option. Hence pass number of successful pthread_create calls to mdrestore_destroy, so that we don't call pthread_join on IDs not present when pthread_create fails. metadump_init already had this fixed, but repeats code from metadump_destroy. Reuse metadump_destroy by passing number of threads created (successful pthread_create calls) and save repeated cleaup code. Had to move metadump_destroy before metadump_init for obvious reasons. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: remove unused variable and update btrfs-image man pageRakesh Pandit2014-03-21
| | | | | | | | | | | | | | | | | | | | | | | | Remove unused variable in btrfs-image.c (update_super) and update man page documentation about -r option. Running btrfsck on a restored image produces missing chunk information. This is because by default, btrfs-image fixes up chunk tree to use 1 stripe pointing to the primary device. This in turns results in btrfsck making some noise. $ ./mkfs.btrfs /dev/sdb2 -f $ ./btrfs-image /dev/sdb2 btrfs_image_output $ ./btrfs-image -r btrfs_image_output disk-image $ ./btrfsck disk-image Device extent[1, 29360128, 8388608] didn't find the relative chunk. Device extent[1, 1111490560, 1073741824] didn't find the relative chunk. Ideally btfsck should be updated to reflect this default behavior and not through these messages, but it isn't harmful and can be done later. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: don't remove BTRFS_BLOCK_GROUP_DUP in chunk typeRakesh Pandit2014-03-21
| | | | | | | | | | | | | | | | | | | | | | | | | | During restoring of image (-r using btrfs-image) we zero out RAID profile in chunk type but forget to save BTRFS_BLOCK_GROUP_DUP if present. This results in some false messages being printed by btrfsck. $ ./mkfs.btrfs /dev/sdb2 -f $ ./btrfs-image /dev/sdb2 btrfs_image_output $ ./btrfs-image -r btrfs_image_output disk-image $ ./btrfsck disk-image Checking filesystem on disk-image UUID: e644be2d-7701-4bd4-8804-7487f560d2a7 checking extents Chunk[256, 228, 20971520]: length(8388608), offset(20971520), type(2) mismatch with block group[20971520, 192, 8388608]: offset(8388608), objectid(20971520), flags(34) Chunk[256, 228, 29360128]: length(1073741824), offset(29360128), type(4) mismatch with block group[29360128, 192, 1073741824]: offset(1073741824), objectid(29360128), flags(36) Block group[20971520, 8388608] (flags = 34) didn't find the relative chunk. Block group[29360128, 1073741824] (flags = 36) didn't find the relative chunk. Even though ./btrfsck on /dev/sdb2 seemed fine. This is due to type mismatch above and type mismatch occured because we zero'ed out BTRFS_BLOCK_GROUP_DUP while handling chunk trees. Signed-off-by: Rakesh Pandit <rakesh@tuxera.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: switch to arg_strtou64() part2Wang Shilong2014-03-21
| | | | | | Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: use stripe_len define hereAnand Jain2014-01-31
| | | | | | Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>