summaryrefslogtreecommitdiff
path: root/convert/main.c
Commit message (Collapse)AuthorAge
* btrfs-progs: convert: Add missing return for HOLE mode when checking convert ↵Qu Wenruo2017-03-31
| | | | | | | | | | | | | | image In check_convert_image(), for normal HOLE case, if the file extents are smaller than image size, we set ret to -EINVAL and print error message. But forget to return. This patch adds the missing return to fix it. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Make btrfs_reserved_ranges constQu Wenruo2017-03-16
| | | | | | | | | | | | Since btrfs_reserved_ranges array is just used to store btrfs reserved ranges, no one will nor should modify them at run time, make them static and const will be better. This also eliminates the use of immediate number 3. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ definition stays in source-fs.c ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Rework rollbackQu Wenruo2017-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rework rollback to a more easy to understand way. New convert behavior makes us to have a more flex chunk layout, which only data chunk containing old fs data will be at the same physical location, while new chunks (data/meta/sys) can be mapped anywhere else. This behavior makes old rollback behavior can't handle it. As old behavior assumes all data/meta is mapped in a large chunk, which is mapped 1:1 on disk. So rework rollback to handle new convert behavior, enhance the check by only checking all file extents of convert image, only to check if these file extents and therir chunks are mapped 1:1. This new rollback check behavior can handle both new and old convert behavior, as the new behavior is a superset of old behavior. Further more, introduce a simple rollback mechanisim: 1) Read reserved data (offset = file offset) from convert image 2) Write reserved data into disk (offset = physical offset) Since old fs image is a valid fs, and we only need to rollback superblocks (btrfs reserved ranges), then we just read out data in reserved range, and write it back. Due to the fact that all other file extents of converted image is mapped 1:1 on disk, we put the missing piece back, then the fs is as good as old one. Then what we do in btrfs is just another dream. With this new rollback mechanisim, we can open btrfs read-only, so we won't cause any damage to current btrfs, until the final piece (0~1M, containing 1st super block) is put back. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ port to v4.10 ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Introduce function to check if convert image is able ↵Qu Wenruo2017-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | to be rolled back Introduce a function, check_convert_image() to check if that image is rollback-able. This means all file extents except one of the btrfs reserved ranges, must be mapped 1:1 on disk. 1:1 mapped file extents must match the following conditions: 1) Their file_offset(key.offset) matches its disk_bytenr 2) The corresponding chunk must be mapped 1:1 on disk That's to say, it's a SINGLE chunk, and chunk logical matches with stripe physical. Above 2 conditions ensured that file extent lies the exactly the same position as in the old filesystem. For data in reserved ranges of btrfs, they are relocated to new places, and in that case, we use btrfs_read_file() to read out the content for later rollback use. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: convert: Introduce function to read out btrfs reserved rangeQu Wenruo2017-03-16
| | | | | | | Introduce a new function, read_reserved_ranges(), to allow later rollback to use these data to do rollback. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: convert: Use reserved ranges array to cleanup open codeQu Wenruo2017-03-16
| | | | | | | | | | | Since we have reserved ranges array now, we can use them to skip all these open codes. And add some comment and asciidoc art for related part. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ port to v4.10 ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Add comment for the overall convert designQu Wenruo2017-03-16
| | | | | | | | | | | | | Convert is now a little complex due to that fact we need to separate metadata and data chunks for different profiles. Add a comment with ascii art explaining the whole design and point out the really complex part, so any newcomers interested in convert can get a quick overview of it before digging into the hard to read code. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ wording and formatting adjustments ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from clear_extent_dirtyDavid 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 write_and_map_ebDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: rename members that clash with other functionsDavid Sterba2017-03-08
| | | | | | Rename 'free' and also 'used' for consistency. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: clear whole mkfs_cfg at onceDavid Sterba2017-03-08
| | | | | | Zero out the structure and set only the requested fields. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: use bit field for convert flagsDavid Sterba2017-03-08
| | | | | | | Use one flag field instead of several variables. The change cascades down to the callchain and modifies several functions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: remove unused includesDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: use on-stack buffer for subvol name dirDavid Sterba2017-03-08
| | | | | | Get rid of dynamic allocation. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: move struct initialization to the init functionDavid Sterba2017-03-08
| | | | | | | The context is zeroed in convert_open_fs after and overwrites the rbtree initialization, which accidentally is the same (NULL). Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: use wider types types for inode counts for progress ↵David Sterba2017-03-08
| | | | | | reports Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: make list of source fs more visibleDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: move implementation for interal conversion API to own fileDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: move ext2 conversion out of main.cDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: move ext2 definitions out of mainDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: move definitions for interal conversion API to own fileDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move fs features declarations to own header from utilsDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move convert definitions to own headerDavid Sterba2017-03-08
| | | | | | | Create a header for filesystem conversion API, the config and the main entry function. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move mkfs definitions to own headerDavid Sterba2017-03-08
| | | | | | | Create a header for filesystem creation API, the config and the main entry function. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs/convert: separate the convert part from make_btrfsDavid Sterba2017-01-27
| | | | | | | The regulare mkfs_btrfs does not anything special about convert and just passes the arguments. Make that two functions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: file-item: Fix wrong file extents insertedQu Wenruo2016-12-21
| | | | | | | | | | | | | | | | | | | If we specify NO_HOLES incompat feature when converting, the result image still uses hole file extents. And further more, the hole is incorrect as its disk_num_bytes is not zero. The problem is at btrfs_insert_file_extent() which doesn't check if we are going to insert hole file extent. Modify it to skip hole file extents to allow it follow restrict NO_HOLES flag. And since no_holes flag can be triggered on half-way, so current fsck won't report such error, as it consider it as old file holes. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Fix migrate_super_block() to work with 64k sectorsizeChandan Rajendra2016-12-14
| | | | | | | | | | | | | migrate_super_block() uses sectorsize to refer to the size of the superblock. Hence on 64k sectorsize filesystems, it ends up computing checksum beyond the super block length (i.e. BTRFS_SUPER_INFO_SIZE). This commit fixes the bug by using BTRFS_SUPER_INFO_SIZE instead of sectorsize of the underlying filesystem. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Prevent accounting blocks beyond end of deviceChandan Rajendra2016-12-14
| | | | | | | | | | | | When looping across data block bitmap, __ext2_add_one_block() may add blocks which do not exist on the underlying disk. This commit prevents this from happening by checking the block index against the maximum block count that was present in the ext4 filesystem instance that is being converted. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move btrfs-convert to own directoryDavid Sterba2016-12-14
Signed-off-by: David Sterba <dsterba@suse.com>