Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP4:GA
btrfsprogs
3001-btrfs-progs-Introduce-function-to-fix-unal...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 3001-btrfs-progs-Introduce-function-to-fix-unaligned-devi.patch of Package btrfsprogs
From: Qu Wenruo <wqu@suse.com> Date: Tue, 17 Oct 2017 13:00:41 +0800 Subject: btrfs-progs: Introduce function to fix unaligned device size Git-commit: ea9cd9df2be56041e2d62b0e72c77695b03261f7 Patch-mainline: v4.14 References: bsc#1083287 Recent kernel introduced alignment check for dev item, however older kernel doesn't align device size when adding new device or shrinking existing device. This makes noisy kernel warning every time when any DEV_ITEM gets updated. Introduce function to fix device size on an unmounted filesystem. Reported-by: Asif Youssuff <yoasif@gmail.com> Reported-by: Rich Rauenzahn <rrauenza@gmail.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> --- volumes.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ volumes.h | 2 ++ 2 files changed, 71 insertions(+) Index: btrfs-progs-v4.5.3/volumes.c =================================================================== --- btrfs-progs-v4.5.3.orig/volumes.c +++ btrfs-progs-v4.5.3/volumes.c @@ -2148,3 +2148,72 @@ int write_raid56_with_parity(struct btrf return 0; } + +/* + * Return 0 if size of @device is already good + * Return >0 if size of @device is not aligned but fixed without problems + * Return <0 if something wrong happened when aligning the size of @device + */ +int btrfs_fix_device_size(struct btrfs_fs_info *fs_info, + struct btrfs_device *device) +{ + struct btrfs_trans_handle *trans; + struct btrfs_key key; + struct btrfs_path path; + struct btrfs_root *chunk_root = fs_info->chunk_root; + struct btrfs_dev_item *di; + u64 old_bytes = device->total_bytes; + u32 sectorsize = chunk_root->sectorsize; + int ret; + + if (IS_ALIGNED(old_bytes, sectorsize)) + return 0; + + /* Align the in-memory total_bytes first, and use it as correct size */ + device->total_bytes = round_down(device->total_bytes, sectorsize); + + key.objectid = BTRFS_DEV_ITEMS_OBJECTID; + key.type = BTRFS_DEV_ITEM_KEY; + key.offset = device->devid; + + trans = btrfs_start_transaction(chunk_root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + error("error starting transaction: %d (%s)", + ret, strerror(-ret)); + return ret; + } + + btrfs_init_path(&path); + ret = btrfs_search_slot(trans, chunk_root, &key, &path, 0, 1); + if (ret > 0) { + error("failed to find DEV_ITEM for devid %llu", device->devid); + ret = -ENOENT; + goto err; + } + if (ret < 0) { + error("failed to search chunk root: %d (%s)", + ret, strerror(-ret)); + goto err; + } + di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dev_item); + btrfs_set_device_total_bytes(path.nodes[0], di, device->total_bytes); + btrfs_mark_buffer_dirty(path.nodes[0]); + ret = btrfs_commit_transaction(trans, chunk_root); + if (ret < 0) { + error("failed to commit current transaction: %d (%s)", + ret, strerror(-ret)); + btrfs_release_path(&path); + return ret; + } + btrfs_release_path(&path); + printf("Fixed device size for devid %llu, old size: %llu new size: %llu\n", + device->devid, old_bytes, device->total_bytes); + return 1; + +err: + /* We haven't modified anything, it's OK to commit current trans */ + btrfs_commit_transaction(trans, chunk_root); + btrfs_release_path(&path); + return ret; +} Index: btrfs-progs-v4.5.3/volumes.h =================================================================== --- btrfs-progs-v4.5.3.orig/volumes.h +++ btrfs-progs-v4.5.3/volumes.h @@ -226,4 +226,6 @@ int write_raid56_with_parity(struct btrf struct extent_buffer *eb, struct btrfs_multi_bio *multi, u64 stripe_len, u64 *raid_map); +int btrfs_fix_device_size(struct btrfs_fs_info *fs_info, + struct btrfs_device *device); #endif
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor