summaryrefslogtreecommitdiff
path: root/ctree.h
Commit message (Collapse)AuthorAge
...
* 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: file: Introduce function to read out file contentQu Wenruo2017-03-16
| | | | | | | | | | | | | Introduce a new function, btrfs_read_file(), to read out data of a file inode. This function will iterate through EXTENT_DATA items and handle inline/prealloc/hole file extents. Compression is not supported yet. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from btrfs_lookup_inode_refDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused helpers from ctree.hDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop unused argument from btrfs_del_ptrDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop unused argument from btrfs_extend_itemDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop unused argument from btrfs_truncate_itemDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce kernel sizes to cleanup large intermediate numberQu Wenruo2017-03-08
| | | | | | | | | | | Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to waste one second to convert to 1G. Introduce kernel include/linux/sizes.h to replace any intermediate number larger than 4096 (not including 4096) to SZ_*. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: get the highest inode for lost+foundGoldwyn Rodrigues2017-01-25
| | | | | | | | | | | | | root->highest_inode is not accurate at the time of creating a lost+found and it fails because the highest_inode+1 is already present. This could be because of fixes after highest_inode is set. Instead, search for the highest inode in the tree and use it for lost+found. This makes root->highest_inode unnecessary and hence deleted. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make incompat bit wrappers more compactDavid Sterba2016-12-14
| | | | | | Use the same macro tricks as in kernel code. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add btrfs_clear_free_space_tree() from the kernelOmar Sandoval2016-11-23
| | | | | | 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: add the FREE_SPACE_TREE_VALID compat_ro bit definitionOmar Sandoval2016-11-23
| | | | | | | This is just the definition; we don't support it yet. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert bitfield to separate variables in btrfs_pathDavid Sterba2016-11-09
| | | | | | We don't have that many bitfields that would save space. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: reduce size of btrfs_path::lowest_levelDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: reduce size of btrfs_path::readaDavid Sterba2016-11-09
| | | | | | | We use only a few values, reada accessed not in performance critical contexts. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: reduce size of btrfs_path, locks are not usedDavid Sterba2016-11-09
| | | | | | | Size of btrfs_path can be reduced by 32 bytes as we don't use the locks array, down to 112 from 144 bytes. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add dev stats on-disk structureDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add balance status structuresDavid Sterba2016-11-09
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: switch dev stats item to the permanent item keyDavid Sterba2016-11-09
| | | | | [ kernel patch 242e2956e4afde7727fffe21adc0a7b198b77f96 ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce key type for persistent permanent itemsDavid Sterba2016-11-09
| | | | | | | | | | | | | | The number of distinct key types is not that big that we could waste one for something new we want to store in the tree. Similar to the temporary items, we'll introduce a new name for an existing key value and use the objectid for further extension. The victim is the BTRFS_DEV_STATS_KEY (248). The device stats are an example of a permanent item. [ kernel patch 50c2d5abe64c1726b48d292a2ab04f60e8238933 ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce key type for persistent temporary itemsDavid Sterba2016-11-09
| | | | | | | | | | | | | | The number of distinct key types is not that big that we could waste one for something new we want to store in the tree. We'll introduce a new name for an existing key value and use the objectid for further extension. The victim is the BTRFS_BALANCE_ITEM_KEY (248). The nature of the balance status item is a good example of the temporary item. It exists from beginning of the balance, keeps the status until it finishes. [ kernel patch 0bbbccb17fea86818e1a058faf5903aefd20b31a ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Copy btrfs inode flags from kernel headerQu Wenruo2016-10-24
| | | | | | | | Btrfs-progs header lacks quite a lot inode flags. Copy them from kernel for later use. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, kill trivial btrfs_key_type helperDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, kill trivial btrfs_set_key_type helperDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* Revert "btrfs-progs: fix compat_ro mask for free space tree"Omar Sandoval2016-09-21
| | | | | | | | | btrfs-progs can't mount space_cache=v2 filesystems read-write, which is why the compat bit wasn't added to the supported mask in the first place. Remove it. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add rest of stack operations for btrfs_dir_itemDavid Sterba2016-08-25
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: two staged filesystem creationDavid Sterba2016-08-24
| | | | | | | | | | | | | | | | | | | | | | | | The filesystem existence on a device is manifested by the signature, during the mkfs process we write it first and then create other structures. Such filesystem is not valid and should not be registered during device scan nor listed among devices from blkid. This patch will introduce two staged creation. In the first phase, the signature is wrong, but recognized as a partially created filesystem (by open or scan helpers). Once we successfully create and write everything, we fixup the signature. At this point automated scanning should find a valid filesystem on all devices. We can also rely on the partially created filesystem to do better error handling during creation. We can just bail out and do not need to clean up. The partial signature is '!BHRfS_M', can be shown by btrfs inspect-internal dump-super -F image Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: introduce signature for a partially set up filesystemDavid Sterba2016-08-24
| | | | | | | | | | | | Currently the superblock is created first, with a valid signaure, but the rest of the filesystem is missing. When the creation process is interrupted, the filesystem still might be considered as valid. To prevent that, create the filesytem with an invalid signature that would be still recognized during the mkfs process, and finalize at the end. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Fix a regression that ext2_save/image is not readonlyQu Wenruo2016-08-19
| | | | | | | | | | | | | | | | | | The new convert treats the convert image as a normal file, without any special flags and permissions. This is different from original code: 1) Permission changed from 0400 to 0600 2) Inode lacks READONLY flag This makes we can read-write mount the ext2 image and cause rollback failure. Follow old code behavior, use 0400 permission and add back READONLY flag to fix it. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: introduce function to check data backref in extent treeLu Fengqi2016-08-17
| | | | | | | | | | Introduce a new function check_data_extent_item() to check if the corresponding data backref exists in extent tree. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: write corrected qgroup info to diskMark Fasheh2016-07-13
| | | | | | | | | | | | | | | | Now that we can verify all qgroups, we can write the corrected qgroups out to disk when '--repair' is specified. The qgroup status item is also updated to clear any out-of-date state. The repair_ functions were modeled after the inode repair code in cmds-check.c. I also renamed the 'scan' member of qgroup_status_item to 'rescan' in order to keep consistency with the kernel. Testing this was easy, I just reproduced qgroup inconsistencies via the usual routes and had btrfsck fix them. Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Cleanup old btrfs-convertQu Wenruo2016-06-07
| | | | | | | | | | | | | | | | | | | | | | Cleanup all the old btrfs-convert facilities, including: 1) btrfs_convert_operations->alloc/free/test_extents* No need to do non-standard extent allocation. After init_btrfs() everything can be done by normal routine. Now only 4 functions are needed in btrfs_convert_operations. 1) open_fs 2) read_used_space 3) copy_inodes 4) close_fs 2) fs_info->extent_ops Same as above. 3) Old init_btrfs(), create_image(), create_file_image_range() Replaced with newer and cleaner one. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Strictly avoid meta or system chunk allocationQu Wenruo2016-06-07
| | | | | | | | | | | | | Before this patch, btrfs-convert only rely on large enough initial system/metadata chunk size to ensure no newer system/meta chunk will be created. But that's not safe enough. So add two new members in fs_info, avoid_sys/meta_chunk_alloc flags to prevent any newer system or meta chunks to be created before init_btrfs_v2(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: extent-tree: Enhance btrfs_record_file_extentQu Wenruo2016-06-07
| | | | | | | | | | | | | | Btrfs_record_file_extent() has some small problems like: 1) Can't handle overlapping extents 2) May create extent larger than BTRFS_MAX_EXTENT_SIZE So enhance it using previously added facilites. This is used for later btrfs-convert, as for new convert, we create saved image first, then copy inode. Which will also cause extent overlapping. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: extent-tree: Introduce function to find the first overlapping ↵Qu Wenruo2016-06-07
| | | | | | | | | | | | extent Introduce a new function, btrfs_search_overlap_extent() to find the first overlapping extent. It's useful for later btrfs-convert rework. Signed-off-by: Qu Wenruo <quwenruo@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: add getters for ioctl search_headerDavid Sterba2016-05-11
| | | | | | | The search header is usually accessed in an unaligned way, we could trigger errors (SIGBUS) on architectures that do not support that. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: deprecate and stop using btrfs_level_sizeDavid Sterba2016-05-02
| | | | | | Size of a b-tree node is always nodesize, regardless of the level. 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: Allow open_ctree to return fs_info even chunk tree is corruptedQu Wenruo2016-02-26
| | | | | | | | | | | | | | | | | | | | | | | | | Current open_ctree_fs_info() won't return anything if chunk tree root is corrupted. This makes some function, like btrfs-find-root, unable to find any older chunk tree root, even it is possible to use system_chunk_array in super block. And at least two users in mail list has reported such heavily chunk corruption. Although we have 'btrfs rescue chunk-recovery' but it's too time consuming and sometimes not able to cope with a specific filesystem corruption. This patch adds a new open ctree flag, OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR, allowing fs_info to be returned from open_ctree_fs_info() even there is no valid tree root in it. Also adds a new close_ctree() variant, close_ctree_fs_info() to handle possible fs_info without any root. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ adjusted error messages ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix compat_ro mask for free space treeDavid Sterba2016-01-25
| | | | | | | | | The BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE bit is supposed to be in the COMPAT_RO_SUPP bitmask. Reported-by: Holger Hoffstätte <holger.hoffstaette@googlemail.com> Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check the free space tree in btrfsckOmar Sandoval2016-01-12
| | | | | | | | | | This reuses the existing code for checking the free space cache, we just need to load the free space tree. While we do that, we check a couple of invariants on the free space tree itself. This requires pulling in some code from the kernel to exclude the super stripes. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add basic awareness of the free space treeOmar Sandoval2016-01-12
| | | | | | | | | | | To start, let's tell btrfs-progs to read the free space root and how to print the on-disk format of the free space tree. However, we're not adding the FREE_SPACE_TREE read-only compat bit to the set of supported bits because progs doesn't know how to keep the free space tree consistent. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Avoid uninitialized data in output of btrfs-convertZhao Lei2015-09-09
| | | | | | | | The sequence, transid and reserved fields of inode were writen to disk with uninitizlized value, this patch fixes it. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: fix typo in set/get of btrfs_inode_item::sequenceZhao Lei2015-09-09
| | | | | | | | s/generation/sequence/ for BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, ...) Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: convert: Avoid allocating metadata extent crossing stripe boundaryQu Wenruo2015-08-31
| | | | | | | | | | | As convert implement its own alloc extent, avoid such metadata problem too. Reported-by: Chris Murphy <lists@colorremedies.com> Reported-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* Btrfs-progs: add feature to get mininum size for resizing a fs/deviceFilipe Manana2015-08-31
| | | | | | | | | | | | | | | | | | | Currently there is not way for a user to know what is the minimum size a device of a btrfs filesystem can be resized to. Sometimes the value of total allocated space (sum of all allocated chunks/device extents), which can be parsed from 'btrfs filesystem show' and 'btrfs filesystem usage', works as the minimum size, but sometimes it does not, namely when device extents have to relocated to holes (unallocated space) within the new size of the device (the total allocated space sum). This change adds the ability to reliably compute such minimum value and extents 'btrfs filesystem resize' with the following syntax to get such value: btrfs filesystem resize [devid:]get_min_size Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: extent-tree: Introduce btrfs_free_block_group functionQu Wenruo2015-07-10
| | | | | | | | | This function will be used to free a empty chunk. This provides the basis for later temp chunk cleanup. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove non-exist csum size.Qu Wenruo2015-05-14
| | | | | | | | | | | Current btrfs only support CRC32 as checksum algorithm. But in btrfs_csum_sizes array, we have an extra 0 at tail, causing csum_type 1 can still be considered as supported csum type. Fix it by removing the tailing 0. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: Introduce change_header_uuid functionQu Wenruo2015-05-14
| | | | | | | | | | This function is used to change fsid and chunk_tree_uuid of a node/leaf. The function does it without transaction protection. This is the basis of offline uuid change. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>