RE: [PATCH 2/5] btrfs: use a separate variable to store the num_bytes of the qgroup_reserve
> -Original Message- > From: David Sterba [mailto:dste...@suse.cz] > Sent: Wednesday, August 08, 2018 12:19 AM > To: Lu, Fengqi/陆 丰麒 > Cc: linux-btrfs@vger.kernel.org; Gu, Jinxiang/顾 金香 > Subject: Re: [PATCH 2/5] btrfs: use a separate variable to store the > num_bytes of the qgroup_reserve > > On Sat, Aug 04, 2018 at 09:10:54PM +0800, Lu Fengqi wrote: > > After btrfs_qgroup_reserve_meta_prealloc(), num_bytes will be assigned > > again by btrfs_calc_trans_metadata_size(). Therefore, once block_rsv > > fails, we cannot properly free the num_bytes of the previous > > qgroup_reserve. > > This does not look like a trivial cleanup at all. There was an unused > parameter, removed in c4c129db5da8f070147f175 ("btrfs: drop unused > parameter qgroup_reserved"), that introduced the bug. Yes. It was introduced by fix above. I missed the second assignment of num_bytes. And it should use two variable to record reserve size of qgroup and blockgroup. >This was in this > rc1 so it's a regression and I'll consider pushing it to the 4.18 final. > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
[PATCH v2] btrfs: fix bug of chunk type check
chunk type BTRFS_BLOCK_GROUP_METADATA and BTRFS_BLOCK_GROUP_DATA should not be set in a non-mixed chunk at the same time. Since BTRFS_BLOCK_GROUP_METADATA is 0x4 and BTRFS_BLOCK_GROUP_DATA is 0x1, BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA will be 0x0, so we should judge type is one of them separately. Reported-by: Dan Carpenter Signed-off-by: Gu Jinxiang --- Changelog: v2: As comment by Qu, change the print format of bit from %llu to 0x%llx. fs/btrfs/volumes.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3f2f01ad9356..d61c604b280c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6360,7 +6360,7 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, } if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) & type) { - btrfs_err(fs_info, "unrecognized chunk type: %llu", + btrfs_err(fs_info, "unrecognized chunk type: 0x%llx", ~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) & btrfs_chunk_type(leaf, chunk)); @@ -6368,14 +6368,14 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, } if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) { - btrfs_err(fs_info, "missing chunk type flag: %llu", type); + btrfs_err(fs_info, "missing chunk type flag: 0x%llx", type); return -EIO; } if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) { btrfs_err(fs_info, - "system chunk with data or metadata type: %llu", type); + "system chunk with data or metadata type: 0x%llx", type); return -EIO; } @@ -6384,10 +6384,10 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, mixed = 1; if (!mixed) { - if (type & - (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) { + if ((type & BTRFS_BLOCK_GROUP_METADATA) && + (type & BTRFS_BLOCK_GROUP_DATA)) { btrfs_err(fs_info, - "mixed chunk type in non-mixed mode: %llu", type); + "mixed chunk type in non-mixed mode: 0x%llx", type); return -EIO; } } @@ -6400,7 +6400,7 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && num_stripes != 1)) { btrfs_err(fs_info, - "invalid num_stripes:sub_stripes %u:%u for profile %llu", + "invalid num_stripes:sub_stripes %u:%u for profile 0x%llx", num_stripes, sub_stripes, type & BTRFS_BLOCK_GROUP_PROFILE_MASK); return -EIO; -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [bug report] btrfs: Add type check when reading a chunk
> -Original Message- > From: David Sterba [mailto:dste...@suse.cz] > Sent: Thursday, July 19, 2018 6:14 PM > To: dste...@suse.cz; Gu, Jinxiang/顾 金香 ; Dan Carpenter > ; > linux-btrfs@vger.kernel.org > Subject: Re: [bug report] btrfs: Add type check when reading a chunk > > On Thu, Jul 19, 2018 at 11:22:01AM +0200, David Sterba wrote: > > On Thu, Jul 19, 2018 at 08:18:25AM +, Gu, Jinxiang wrote: > > > > > > > > > > -Original Message- > > > > From: Dan Carpenter [mailto:dan.carpen...@oracle.com] > > > > Sent: Thursday, July 19, 2018 4:11 PM > > > > To: Gu, Jinxiang/顾 金香 > > > > Cc: linux-btrfs@vger.kernel.org > > > > Subject: [bug report] btrfs: Add type check when reading a chunk > > > > > > > > Hello Gu Jinxiang, > > > > > > > > The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk" > > > > from Jul 4, 2018, leads to the following static checker warning: > > > > > > > > fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid() > > > > warn: AND to zero '0x4 & 0x1' > > > > > > > > fs/btrfs/volumes.c > > > > 6356 if (!is_power_of_2(stripe_len) || stripe_len != > > > > BTRFS_STRIPE_LEN) { > > > > 6357 btrfs_err(fs_info, "invalid chunk stripe > > > > length: %llu", > > > > 6358stripe_len); > > > > 6359 return -EIO; > > > > 6360 } > > > > 6361 if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | > > > > BTRFS_BLOCK_GROUP_PROFILE_MASK) & > > > > 6362 type) { > > > > 6363 btrfs_err(fs_info, "unrecognized chunk type: > > > > %llu", > > > > 6364~(BTRFS_BLOCK_GROUP_TYPE_MASK | > > > > 6365 BTRFS_BLOCK_GROUP_PROFILE_MASK) & > > > > 6366btrfs_chunk_type(leaf, chunk)); > > > > 6367 return -EIO; > > > > 6368 } > > > > 6369 > > > > 6370 if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) { > > > > 6371 btrfs_err(fs_info, "missing chunk type flag: > > > > %llu", type); > > > > 6372 return -EIO; > > > > 6373 } > > > > 6374 > > > > 6375 if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && > > > > 6376 (type & (BTRFS_BLOCK_GROUP_METADATA | > > > > BTRFS_BLOCK_GROUP_DATA))) { > > > > 6377 btrfs_err(fs_info, > > > > 6378 "system chunk with data or metadata > > > > type: %llu", type); > > > > 6379 return -EIO; > > > > 6380 } > > > > 6381 > > > > 6382 features = > > > > btrfs_super_incompat_flags(fs_info->super_copy); > > > > 6383 if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) > > > > 6384 mixed = 1; > > > > 6385 > > > > 6386 if (!mixed) { > > > > 6387 if (type & > > > > 6388 (BTRFS_BLOCK_GROUP_METADATA & > > > > BTRFS_BLOCK_GROUP_DATA)) { > > > > > > > > ^^^ > > > > Was this supposed to be | or perhaps check that both are set? > > > Yes. It should be |. > > > Thank you, I'll send a patch to fix it. > > > > Not needed, I'll fix the patch directly. > > And that leads to failed mount: > > [ 10.867868] BTRFS error (device vda): mixed chunk type in non-mixed mode: 1 > [ 10.871084] BTRFS error (device vda): failed to read chunk tree: -5 > [ 10.908541] BTRFS error (device vda): open_ctree failed > > Please send fixed version. I send a patch to fix this. Patch: btrfs: fix bug of chunk type check And, if possible, please just fold it into 72e75ed03c8d: "btrfs: Add type check when reading a chunk". Thanks, Gu Jinxiang >
[PATCH] btrfs: fix bug of chunk type check
chunk type BTRFS_BLOCK_GROUP_METADATA and BTRFS_BLOCK_GROUP_DATA should not be set in a non-mixed chunk at the same time. Since BTRFS_BLOCK_GROUP_METADATA is 0x4 and BTRFS_BLOCK_GROUP_DATA is 0x1, BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA will be 0x0, so we should judge type is one of them separately. Reported-by: Dan Carpenter Signed-off-by: Gu Jinxiang --- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3f2f01ad9356..c7d009e45472 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6384,8 +6384,8 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, mixed = 1; if (!mixed) { - if (type & - (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) { + if ((type & BTRFS_BLOCK_GROUP_METADATA) && + (type & BTRFS_BLOCK_GROUP_DATA)) { btrfs_err(fs_info, "mixed chunk type in non-mixed mode: %llu", type); return -EIO; -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [bug report] btrfs: Add type check when reading a chunk
> -Original Message- > From: Dan Carpenter [mailto:dan.carpen...@oracle.com] > Sent: Thursday, July 19, 2018 4:11 PM > To: Gu, Jinxiang/顾 金香 > Cc: linux-btrfs@vger.kernel.org > Subject: [bug report] btrfs: Add type check when reading a chunk > > Hello Gu Jinxiang, > > The patch 72e75ed03c8d: "btrfs: Add type check when reading a chunk" > from Jul 4, 2018, leads to the following static checker warning: > > fs/btrfs/volumes.c:6388 btrfs_check_chunk_valid() > warn: AND to zero '0x4 & 0x1' > > fs/btrfs/volumes.c > 6356 if (!is_power_of_2(stripe_len) || stripe_len != > BTRFS_STRIPE_LEN) { > 6357 btrfs_err(fs_info, "invalid chunk stripe length: > %llu", > 6358stripe_len); > 6359 return -EIO; > 6360 } > 6361 if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | > BTRFS_BLOCK_GROUP_PROFILE_MASK) & > 6362 type) { > 6363 btrfs_err(fs_info, "unrecognized chunk type: %llu", > 6364~(BTRFS_BLOCK_GROUP_TYPE_MASK | > 6365 BTRFS_BLOCK_GROUP_PROFILE_MASK) & > 6366btrfs_chunk_type(leaf, chunk)); > 6367 return -EIO; > 6368 } > 6369 > 6370 if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) { > 6371 btrfs_err(fs_info, "missing chunk type flag: %llu", > type); > 6372 return -EIO; > 6373 } > 6374 > 6375 if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && > 6376 (type & (BTRFS_BLOCK_GROUP_METADATA | > BTRFS_BLOCK_GROUP_DATA))) { > 6377 btrfs_err(fs_info, > 6378 "system chunk with data or metadata type: > %llu", type); > 6379 return -EIO; > 6380 } > 6381 > 6382 features = btrfs_super_incompat_flags(fs_info->super_copy); > 6383 if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) > 6384 mixed = 1; > 6385 > 6386 if (!mixed) { > 6387 if (type & > 6388 (BTRFS_BLOCK_GROUP_METADATA & > BTRFS_BLOCK_GROUP_DATA)) { > > ^^^ > Was this supposed to be | or perhaps check that both are set? Yes. It should be |. Thank you, I'll send a patch to fix it. > > 6389 btrfs_err(fs_info, > 6390 "mixed chunk type in non-mixed mode: %llu", > type); > 6391 return -EIO; > 6392 } > 6393 } > > regards, > dan carpenter >
RE: [PATCH v5 2/2] btrfs: get device pointer from btrfs_scan_one_device
> -Original Message- > From: David Sterba [mailto:dste...@suse.cz] > Sent: Monday, July 16, 2018 8:34 PM > To: Gu, Jinxiang/顾 金香 > Cc: linux-btrfs@vger.kernel.org; anand.j...@oracle.com > Subject: Re: [PATCH v5 2/2] btrfs: get device pointer from > btrfs_scan_one_device > > On Mon, Jul 16, 2018 at 05:11:17PM +0800, Gu Jinxiang wrote: > > Instead of pointer to btrfs_fs_devices as an arg in > > btrfs_scan_one_device, better to make it as a return value. > > > > And since btrfs_fs_devices can be get by btrfs_device, > > better to return btrfs_device than fs_btrfs_devices. > > > > Signed-off-by: Gu Jinxiang > > --- > > > > Changelog: > > v5: rebase to misc-next. > > v4: as suggested by Anand, change return value of > > btrfs_scan_one_device from btrfs_fs_devices to btrfs_device. > > v3: as comment by robot, use PTR_ERR_OR_ZERO, and rebase to misc-next. > > v2: as comment by Nikolay, use ERR_CAST instead of cast type manually. > > > > fs/btrfs/super.c | 35 ++- > > fs/btrfs/volumes.c | 22 -- > > fs/btrfs/volumes.h | 4 ++-- > > 3 files changed, 32 insertions(+), 29 deletions(-) > > > > diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c > > index dcab4a0244e5..413bbe2d6db2 100644 > > --- a/fs/btrfs/super.c > > +++ b/fs/btrfs/super.c > > @@ -888,7 +888,7 @@ static int btrfs_parse_early_options(const char > > *options, fmode_t flags, > > { > > substring_t args[MAX_OPT_ARGS]; > > char *device_name, *opts, *orig, *p; > > - struct btrfs_fs_devices *fs_devices = NULL; > > + struct btrfs_device *device = NULL; > > int error = 0; > > > > lockdep_assert_held(_mutex); > > @@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char > > *options, fmode_t flags, > > error = -ENOMEM; > > goto out; > > } > > - error = btrfs_scan_one_device(device_name, flags, > > - holder, _devices); > > + device = btrfs_scan_one_device(device_name, flags, > > + holder); > > kfree(device_name); > > - if (error) > > + if (IS_ERR(device)) { > > + error = PTR_ERR(device); > > goto out; > > + } > > } > > } > > > > @@ -1518,6 +1520,7 @@ static struct dentry *btrfs_mount_root(struct > > file_system_type *fs_type, > > { > > struct block_device *bdev = NULL; > > struct super_block *s; > > + struct btrfs_device *device = NULL; > > struct btrfs_fs_devices *fs_devices = NULL; > > struct btrfs_fs_info *fs_info = NULL; > > struct security_mnt_opts new_sec_opts; > > @@ -1561,12 +1564,15 @@ static struct dentry *btrfs_mount_root(struct > > file_system_type *fs_type, > > goto error_fs_info; > > } > > > > - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); > > - if (error) { > > + device = btrfs_scan_one_device(device_name, mode, fs_type); > > + if (IS_ERR(device)) { > > + error = PTR_ERR(device); > > mutex_unlock(_mutex); > > goto error_fs_info; > > } > > > > + fs_devices = device->fs_devices; > > + > > fs_info->fs_devices = fs_devices; > > > > error = btrfs_open_devices(fs_devices, mode, fs_type); > > @@ -2227,7 +2233,7 @@ static long btrfs_control_ioctl(struct file *file, > > unsigned int cmd, > > unsigned long arg) > > { > > struct btrfs_ioctl_vol_args *vol; > > - struct btrfs_fs_devices *fs_devices; > > + struct btrfs_device *device = NULL; > > int ret = -ENOTTY; > > > > if (!capable(CAP_SYS_ADMIN)) > > @@ -2240,19 +2246,22 @@ static long btrfs_control_ioctl(struct file *file, > > unsigned int cmd, > > switch (cmd) { > > case BTRFS_IOC_SCAN_DEV: > > mutex_lock(_mutex); > > - ret = btrfs_scan_one_device(vol->name, FMODE_READ, > > - _root_fs_type, _devices); > > + device = btrfs_scan_one_device(vol->name, FMODE_READ, > > + _root_fs_type); > > + ret = PTR_ERR_OR_ZERO(device); > >
[PATCH v5 0/2] btrfs: do some parameters optimization
Do parameters optimization for function btrfs_parse_early_options and btrfs_scan_one_device. Gu Jinxiang (2): btrfs: make fs_devices to be a local variable btrfs: get device pointer from btrfs_scan_one_device fs/btrfs/super.c | 38 -- fs/btrfs/volumes.c | 22 -- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 34 insertions(+), 30 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 2/2] btrfs: get device pointer from btrfs_scan_one_device
Instead of pointer to btrfs_fs_devices as an arg in btrfs_scan_one_device, better to make it as a return value. And since btrfs_fs_devices can be get by btrfs_device, better to return btrfs_device than fs_btrfs_devices. Signed-off-by: Gu Jinxiang --- Changelog: v5: rebase to misc-next. v4: as suggested by Anand, change return value of btrfs_scan_one_device from btrfs_fs_devices to btrfs_device. v3: as comment by robot, use PTR_ERR_OR_ZERO, and rebase to misc-next. v2: as comment by Nikolay, use ERR_CAST instead of cast type manually. fs/btrfs/super.c | 35 ++- fs/btrfs/volumes.c | 22 -- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index dcab4a0244e5..413bbe2d6db2 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -888,7 +888,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; - struct btrfs_fs_devices *fs_devices = NULL; + struct btrfs_device *device = NULL; int error = 0; lockdep_assert_held(_mutex); @@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, flags, - holder, _devices); + device = btrfs_scan_one_device(device_name, flags, + holder); kfree(device_name); - if (error) + if (IS_ERR(device)) { + error = PTR_ERR(device); goto out; + } } } @@ -1518,6 +1520,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, { struct block_device *bdev = NULL; struct super_block *s; + struct btrfs_device *device = NULL; struct btrfs_fs_devices *fs_devices = NULL; struct btrfs_fs_info *fs_info = NULL; struct security_mnt_opts new_sec_opts; @@ -1561,12 +1564,15 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, goto error_fs_info; } - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); - if (error) { + device = btrfs_scan_one_device(device_name, mode, fs_type); + if (IS_ERR(device)) { + error = PTR_ERR(device); mutex_unlock(_mutex); goto error_fs_info; } + fs_devices = device->fs_devices; + fs_info->fs_devices = fs_devices; error = btrfs_open_devices(fs_devices, mode, fs_type); @@ -2227,7 +2233,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct btrfs_ioctl_vol_args *vol; - struct btrfs_fs_devices *fs_devices; + struct btrfs_device *device = NULL; int ret = -ENOTTY; if (!capable(CAP_SYS_ADMIN)) @@ -2240,19 +2246,22 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case BTRFS_IOC_SCAN_DEV: mutex_lock(_mutex); - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); + device = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + ret = PTR_ERR_OR_ZERO(device); mutex_unlock(_mutex); break; case BTRFS_IOC_DEVICES_READY: mutex_lock(_mutex); - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); - if (ret) { + device = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + if (IS_ERR(device)) { + ret = PTR_ERR(device); mutex_unlock(_mutex); break; } - ret = !(fs_devices->num_devices == fs_devices->total_devices); + ret = !(device->fs_devices->num_devices == + device->fs_devices->total_devices); mutex_unlock(_mutex); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 88d37bfa99c8..9f485696461b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1213,15 +1213,14 @@ static int btrfs_read_disk_super(struct block_d
[PATCH v5 1/2] btrfs: make fs_devices to be a local variable
fs_devices is always passed to btrfs_scan_one_device which overrides it. And in the call stack below fs_devices is passed to btrfs_scan_one_device from btrfs_mount_root. And in btrfs_mount_root the output fs_devices of this call stack is not used. btrfs_mount_root -> btrfs_parse_early_options ->btrfs_scan_one_device So, there is no necessary to pass fs_devices from btrfs_mount_root, use a local variable in btrfs_parse_early_options is enough. Signed-off-by: Gu Jinxiang Reviewed-by: Anand Jain --- Changelog: v5: change a line wrap, and rebase to misc-next. v4: changed a line warp, and adjusted the order of two rows. v3: rebase to misc-next. v2: deal with Nikolay's comment, make changelog more clair. fs/btrfs/super.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 28ab75ebb983..dcab4a0244e5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -884,10 +884,11 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * only when we need to allocate a new super block. */ static int btrfs_parse_early_options(const char *options, fmode_t flags, - void *holder, struct btrfs_fs_devices **fs_devices) + void *holder) { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; + struct btrfs_fs_devices *fs_devices = NULL; int error = 0; lockdep_assert_held(_mutex); @@ -917,8 +918,8 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, - flags, holder, fs_devices); + error = btrfs_scan_one_device(device_name, flags, + holder, _devices); kfree(device_name); if (error) goto out; @@ -1554,7 +1555,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, } mutex_lock(_mutex); - error = btrfs_parse_early_options(data, mode, fs_type, _devices); + error = btrfs_parse_early_options(data, mode, fs_type); if (error) { mutex_unlock(_mutex); goto error_fs_info; -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 2/2] btrfs: get device pointer from btrfs_scan_one_device
Instead of pointer to btrfs_fs_devices as an arg in btrfs_scan_one_device, better to make it as a return value. And since btrfs_fs_devices can be get by btrfs_device, better to return btrfs_device than fs_btrfs_devices. Signed-off-by: Gu Jinxiang --- Changelog: v4: as suggested by Anand, change return value of btrfs_scan_one_device from btrfs_fs_devices to btrfs_device. v3: as comment by robot, use PTR_ERR_OR_ZERO, and rebase to misc-next. v2: as comment by Nikolay, use ERR_CAST instead of cast type manually. fs/btrfs/super.c | 37 - fs/btrfs/volumes.c | 17 ++--- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 44f58bdb5fa6..e73d547eacff 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -888,7 +888,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; - struct btrfs_fs_devices *fs_devices = NULL; + struct btrfs_device *device = NULL; int error = 0; if (!options) @@ -916,11 +916,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, - flags, holder, _devices); + device = btrfs_scan_one_device(device_name, + flags, holder); kfree(device_name); - if (error) + if (IS_ERR(device)) { + error = PTR_ERR(device); goto out; + } } } @@ -1516,6 +1518,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, { struct block_device *bdev = NULL; struct super_block *s; + struct btrfs_device *device = NULL; struct btrfs_fs_devices *fs_devices = NULL; struct btrfs_fs_info *fs_info = NULL; struct security_mnt_opts new_sec_opts; @@ -1537,9 +1540,13 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, return ERR_PTR(error); } - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); - if (error) + device = btrfs_scan_one_device(device_name, mode, fs_type); + if (IS_ERR(device)) { + error = PTR_ERR(device); goto error_sec_opts; + } + + fs_devices = device->fs_devices; /* * Setup a dummy root and fs_info for test/set super. This is because @@ -2220,7 +2227,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct btrfs_ioctl_vol_args *vol; - struct btrfs_fs_devices *fs_devices; + struct btrfs_device *device = NULL; int ret = -ENOTTY; if (!capable(CAP_SYS_ADMIN)) @@ -2232,15 +2239,19 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case BTRFS_IOC_SCAN_DEV: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); + device = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + ret = PTR_ERR_OR_ZERO(device); break; case BTRFS_IOC_DEVICES_READY: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); - if (ret) + device = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + if (IS_ERR(device)) { + ret = PTR_ERR(device); break; - ret = !(fs_devices->num_devices == fs_devices->total_devices); + } + ret = !(device->fs_devices->num_devices == + device->fs_devices->total_devices); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: ret = btrfs_ioctl_get_supported_features((void __user*)arg); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 52abada5c789..3bc479e8cc22 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1212,14 +1212,13 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, * and we are not allowed to call set_blocksize during the scan. The superblock * is read via pagecache */ -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, - struct
[PATCH v4 1/2] btrfs: make fs_devices to be a local variable
fs_devices is always passed to btrfs_scan_one_device which overrides it. And in the call stack below fs_devices is passed to btrfs_scan_one_device from btrfs_mount_root. And in btrfs_mount_root the output fs_devices of this call stack is not used. btrfs_mount_root -> btrfs_parse_early_options ->btrfs_scan_one_device So, there is no necessary to pass fs_devices from btrfs_mount_root, use a local variable in btrfs_parse_early_options is enough. Signed-off-by: Gu Jinxiang Reviewed-by: Anand Jain --- Changelog: v4: changed a line warp, and adjusted the order of two rows. v3: rebase to misc-next. v2: deal with Nikolay's comment, make changelog more clair. fs/btrfs/super.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 39d8e39b2fe1..44f58bdb5fa6 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -884,10 +884,11 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * only when we need to allocate a new super block. */ static int btrfs_parse_early_options(const char *options, fmode_t flags, - void *holder, struct btrfs_fs_devices **fs_devices) + void *holder) { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; + struct btrfs_fs_devices *fs_devices = NULL; int error = 0; if (!options) @@ -916,7 +917,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, goto out; } error = btrfs_scan_one_device(device_name, - flags, holder, fs_devices); + flags, holder, _devices); kfree(device_name); if (error) goto out; @@ -1524,8 +1525,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - error = btrfs_parse_early_options(data, mode, fs_type, - _devices); + error = btrfs_parse_early_options(data, mode, fs_type); if (error) { return ERR_PTR(error); } -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 2/2] btrfs: get fs_devices pointer form btrfs_scan_one_device
Instead of pointer to btrfs_fs_devices as an arg in btrfs_scan_one_device, better to make it as a return value. Signed-off-by: Gu Jinxiang --- Changelog: v3: as comment by robot, use PTR_ERR_OR_ZERO, and rebase to misc-next. v2: as comment by Nikolay, use ERR_CAST instead of cast type manually. fs/btrfs/super.c | 29 ++--- fs/btrfs/volumes.c | 14 +++--- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 78b5d51c7bc7..20e1ee338a95 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -916,11 +916,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, - flags, holder, _devices); + fs_devices = btrfs_scan_one_device(device_name, + flags, holder); kfree(device_name); - if (error) + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto out; + } } } @@ -1537,9 +1539,11 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, return ERR_PTR(error); } - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); - if (error) + fs_devices = btrfs_scan_one_device(device_name, mode, fs_type); + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto error_sec_opts; + } /* * Setup a dummy root and fs_info for test/set super. This is because @@ -2220,7 +2224,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct btrfs_ioctl_vol_args *vol; - struct btrfs_fs_devices *fs_devices; + struct btrfs_fs_devices *fs_devices = NULL; int ret = -ENOTTY; if (!capable(CAP_SYS_ADMIN)) @@ -2232,14 +2236,17 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case BTRFS_IOC_SCAN_DEV: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + ret = PTR_ERR_OR_ZERO(fs_devices); break; case BTRFS_IOC_DEVICES_READY: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); - if (ret) + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + if (IS_ERR(fs_devices)) { + ret = PTR_ERR(fs_devices); break; + } ret = !(fs_devices->num_devices == fs_devices->total_devices); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index af2704de9ff9..6a6321e41f1b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1212,14 +1212,14 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, * and we are not allowed to call set_blocksize during the scan. The superblock * is read via pagecache */ -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, - struct btrfs_fs_devices **fs_devices_ret) +struct btrfs_fs_devices *btrfs_scan_one_device(const char *path, fmode_t flags, + void *holder) { struct btrfs_super_block *disk_super; struct btrfs_device *device; struct block_device *bdev; struct page *page; - int ret = 0; + struct btrfs_fs_devices *ret = NULL; u64 bytenr; /* @@ -1233,19 +1233,19 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, bdev = blkdev_get_by_path(path, flags, holder); if (IS_ERR(bdev)) - return PTR_ERR(bdev); + return ERR_CAST(bdev); if (btrfs_read_disk_super(bdev, bytenr, , _super)) { - ret = -EINVAL; + ret = ERR_PTR(-EINVAL); goto error_bdev_put; } mutex_lock(_mutex); device = device_list_add(path, disk_super); if (IS_ERR(device)) - ret = PTR_ERR(device); + ret = ERR_CAST(device); else - *fs_devices_ret = device->fs_devices; + ret
[PATCH v3 1/2] btrfs: make fs_devices to be a local variable
fs_devices is always passed to btrfs_scan_one_device which overrides it. And in the call stack below fs_devices is passed to btrfs_scan_one_device from btrfs_mount_root. And in btrfs_mount_root the output fs_devices of this call stack is not used. btrfs_mount_root -> btrfs_parse_early_options ->btrfs_scan_one_device So, there is no necessary to pass fs_devices from btrfs_mount_root, use a local variable in btrfs_parse_early_options is enough. Signed-off-by: Gu Jinxiang --- Changelog: v3: rebase to misc-next. v2: deal with Nikolay's comment, make changelog more clair. fs/btrfs/super.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index e04bcf0b0ed4..78b5d51c7bc7 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -884,11 +884,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * only when we need to allocate a new super block. */ static int btrfs_parse_early_options(const char *options, fmode_t flags, - void *holder, struct btrfs_fs_devices **fs_devices) + void *holder) { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; int error = 0; + struct btrfs_fs_devices *fs_devices = NULL; if (!options) return 0; @@ -916,7 +917,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, goto out; } error = btrfs_scan_one_device(device_name, - flags, holder, fs_devices); + flags, holder, _devices); kfree(device_name); if (error) goto out; @@ -1524,8 +1525,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - error = btrfs_parse_early_options(data, mode, fs_type, - _devices); + error = btrfs_parse_early_options(data, mode, fs_type); if (error) { return ERR_PTR(error); } -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 2/2] btrfs: get fs_devices pointer form btrfs_scan_one_device
Duplicate one, please ignore this. > -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Gu Jinxiang > Sent: Tuesday, July 10, 2018 6:27 PM > To: linux-btrfs@vger.kernel.org > Cc: nbori...@suse.com > Subject: [PATCH 2/2] btrfs: get fs_devices pointer form btrfs_scan_one_device > > Instead of pointer to btrfs_fs_devices as an arg in > btrfs_scan_one_device, better to make it as a return value. > > Signed-off-by: Gu Jinxiang > --- > fs/btrfs/super.c | 29 ++--- > fs/btrfs/volumes.c | 14 +++--- > fs/btrfs/volumes.h | 4 ++-- > 3 files changed, 27 insertions(+), 20 deletions(-) > > diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c > index 4ee082e96d51..a5ddeb6836e3 100644 > --- a/fs/btrfs/super.c > +++ b/fs/btrfs/super.c > @@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char > *options, fmode_t flags, > error = -ENOMEM; > goto out; > } > - error = btrfs_scan_one_device(device_name, > - flags, holder, _devices); > + fs_devices = btrfs_scan_one_device(device_name, > + flags, holder); > kfree(device_name); > - if (error) > + if (IS_ERR(fs_devices)) { > + error = PTR_ERR(fs_devices); > goto out; > + } > } > } > > @@ -1539,9 +1541,11 @@ static struct dentry *btrfs_mount_root(struct > file_system_type *fs_type, > return ERR_PTR(error); > } > > - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); > - if (error) > + fs_devices = btrfs_scan_one_device(device_name, mode, fs_type); > + if (IS_ERR(fs_devices)) { > + error = PTR_ERR(fs_devices); > goto error_sec_opts; > + } > > /* >* Setup a dummy root and fs_info for test/set super. This is because > @@ -,7 +2226,7 @@ static long btrfs_control_ioctl(struct file *file, > unsigned int cmd, > unsigned long arg) > { > struct btrfs_ioctl_vol_args *vol; > - struct btrfs_fs_devices *fs_devices; > + struct btrfs_fs_devices *fs_devices = NULL; > int ret = -ENOTTY; > > if (!capable(CAP_SYS_ADMIN)) > @@ -2234,14 +2238,17 @@ static long btrfs_control_ioctl(struct file *file, > unsigned int cmd, > > switch (cmd) { > case BTRFS_IOC_SCAN_DEV: > - ret = btrfs_scan_one_device(vol->name, FMODE_READ, > - _root_fs_type, _devices); > + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, > + _root_fs_type); > + ret = IS_ERR(fs_devices) ? PTR_ERR(fs_devices) : 0; > break; > case BTRFS_IOC_DEVICES_READY: > - ret = btrfs_scan_one_device(vol->name, FMODE_READ, > - _root_fs_type, _devices); > - if (ret) > + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, > + _root_fs_type); > + if (IS_ERR(fs_devices)) { > + ret = PTR_ERR(fs_devices); > break; > + } > ret = !(fs_devices->num_devices == fs_devices->total_devices); > break; > case BTRFS_IOC_GET_SUPPORTED_FEATURES: > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index b33bf29130b6..ea1ca4da413d 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -1215,14 +1215,14 @@ static int btrfs_read_disk_super(struct block_device > *bdev, u64 bytenr, > * and we are not allowed to call set_blocksize during the scan. The > superblock > * is read via pagecache > */ > -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, > - struct btrfs_fs_devices **fs_devices_ret) > +struct btrfs_fs_devices *btrfs_scan_one_device(const char *path, fmode_t > flags, > + void *holder) > { > struct btrfs_super_block *disk_super; > struct btrfs_device *device; > struct block_device *bdev; > struct page *page; > - int ret = 0; > + struct btrfs_fs_devices *ret = NULL; > u64 bytenr; > > /* > @@ -1236,19 +1236,19 @@ int btrfs_scan_one_device(const char *path, f
[PATCH v2 1/2] btrfs: make fs_devices to be a local variable
fs_devices is always passed to btrfs_scan_one_device which overrides it. And in the call stack below fs_devices is passed to btrfs_scan_one_device from btrfs_mount_root. And in btrfs_mount_root the output fs_devices of this call stack is not used. btrfs_mount_root -> btrfs_parse_early_options ->btrfs_scan_one_device So, there is no necessary to pass fs_devices from btrfs_mount_root, use a local variable in btrfs_parse_early_options is enough. Signed-off-by: Gu Jinxiang --- changelog: v2: deal with Nikolay's comment, make changelog more clair. fs/btrfs/super.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index bf546d6c286c..4ee082e96d51 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -886,11 +886,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * only when we need to allocate a new super block. */ static int btrfs_parse_early_options(const char *options, fmode_t flags, - void *holder, struct btrfs_fs_devices **fs_devices) + void *holder) { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; int error = 0; + struct btrfs_fs_devices *fs_devices = NULL; if (!options) return 0; @@ -918,7 +919,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, goto out; } error = btrfs_scan_one_device(device_name, - flags, holder, fs_devices); + flags, holder, _devices); kfree(device_name); if (error) goto out; @@ -1526,8 +1527,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - error = btrfs_parse_early_options(data, mode, fs_type, - _devices); + error = btrfs_parse_early_options(data, mode, fs_type); if (error) { return ERR_PTR(error); } -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] btrfs: get fs_devices pointer form btrfs_scan_one_device
Instead of pointer to btrfs_fs_devices as an arg in btrfs_scan_one_device, better to make it as a return value. Signed-off-by: Gu Jinxiang --- fs/btrfs/super.c | 29 ++--- fs/btrfs/volumes.c | 14 +++--- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4ee082e96d51..a5ddeb6836e3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, - flags, holder, _devices); + fs_devices = btrfs_scan_one_device(device_name, + flags, holder); kfree(device_name); - if (error) + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto out; + } } } @@ -1539,9 +1541,11 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, return ERR_PTR(error); } - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); - if (error) + fs_devices = btrfs_scan_one_device(device_name, mode, fs_type); + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto error_sec_opts; + } /* * Setup a dummy root and fs_info for test/set super. This is because @@ -,7 +2226,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct btrfs_ioctl_vol_args *vol; - struct btrfs_fs_devices *fs_devices; + struct btrfs_fs_devices *fs_devices = NULL; int ret = -ENOTTY; if (!capable(CAP_SYS_ADMIN)) @@ -2234,14 +2238,17 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case BTRFS_IOC_SCAN_DEV: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + ret = IS_ERR(fs_devices) ? PTR_ERR(fs_devices) : 0; break; case BTRFS_IOC_DEVICES_READY: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); - if (ret) + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + if (IS_ERR(fs_devices)) { + ret = PTR_ERR(fs_devices); break; + } ret = !(fs_devices->num_devices == fs_devices->total_devices); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b33bf29130b6..ea1ca4da413d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1215,14 +1215,14 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, * and we are not allowed to call set_blocksize during the scan. The superblock * is read via pagecache */ -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, - struct btrfs_fs_devices **fs_devices_ret) +struct btrfs_fs_devices *btrfs_scan_one_device(const char *path, fmode_t flags, + void *holder) { struct btrfs_super_block *disk_super; struct btrfs_device *device; struct block_device *bdev; struct page *page; - int ret = 0; + struct btrfs_fs_devices *ret = NULL; u64 bytenr; /* @@ -1236,19 +1236,19 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, bdev = blkdev_get_by_path(path, flags, holder); if (IS_ERR(bdev)) - return PTR_ERR(bdev); + return ERR_CAST(bdev); if (btrfs_read_disk_super(bdev, bytenr, , _super)) { - ret = -EINVAL; + ret = ERR_PTR(-EINVAL); goto error_bdev_put; } mutex_lock(_mutex); device = device_list_add(path, disk_super); if (IS_ERR(device)) - ret = PTR_ERR(device); + ret = ERR_CAST(device); else - *fs_devices_ret = device->fs_devices; + ret = device->fs_devices; mutex_unlock(_mutex); btrfs_release_disk_super(page); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volu
[PATCH v2 2/2] btrfs: get fs_devices pointer form btrfs_scan_one_device
Instead of pointer to btrfs_fs_devices as an arg in btrfs_scan_one_device, better to make it as a return value. Signed-off-by: Gu Jinxiang --- changelog: v2: as comment by Nikolay, use ERR_CAST instead of cast type manually. fs/btrfs/super.c | 29 ++--- fs/btrfs/volumes.c | 14 +++--- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4ee082e96d51..a5ddeb6836e3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, - flags, holder, _devices); + fs_devices = btrfs_scan_one_device(device_name, + flags, holder); kfree(device_name); - if (error) + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto out; + } } } @@ -1539,9 +1541,11 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, return ERR_PTR(error); } - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); - if (error) + fs_devices = btrfs_scan_one_device(device_name, mode, fs_type); + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto error_sec_opts; + } /* * Setup a dummy root and fs_info for test/set super. This is because @@ -,7 +2226,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct btrfs_ioctl_vol_args *vol; - struct btrfs_fs_devices *fs_devices; + struct btrfs_fs_devices *fs_devices = NULL; int ret = -ENOTTY; if (!capable(CAP_SYS_ADMIN)) @@ -2234,14 +2238,17 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case BTRFS_IOC_SCAN_DEV: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + ret = IS_ERR(fs_devices) ? PTR_ERR(fs_devices) : 0; break; case BTRFS_IOC_DEVICES_READY: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); - if (ret) + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + if (IS_ERR(fs_devices)) { + ret = PTR_ERR(fs_devices); break; + } ret = !(fs_devices->num_devices == fs_devices->total_devices); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b33bf29130b6..ea1ca4da413d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1215,14 +1215,14 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, * and we are not allowed to call set_blocksize during the scan. The superblock * is read via pagecache */ -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, - struct btrfs_fs_devices **fs_devices_ret) +struct btrfs_fs_devices *btrfs_scan_one_device(const char *path, fmode_t flags, + void *holder) { struct btrfs_super_block *disk_super; struct btrfs_device *device; struct block_device *bdev; struct page *page; - int ret = 0; + struct btrfs_fs_devices *ret = NULL; u64 bytenr; /* @@ -1236,19 +1236,19 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, bdev = blkdev_get_by_path(path, flags, holder); if (IS_ERR(bdev)) - return PTR_ERR(bdev); + return ERR_CAST(bdev); if (btrfs_read_disk_super(bdev, bytenr, , _super)) { - ret = -EINVAL; + ret = ERR_PTR(-EINVAL); goto error_bdev_put; } mutex_lock(_mutex); device = device_list_add(path, disk_super); if (IS_ERR(device)) - ret = PTR_ERR(device); + ret = ERR_CAST(device); else - *fs_devices_ret = device->fs_devices; + ret = device->fs_devices; mutex_unlock(_mutex); btrfs
[PATCH 1/2] btrfs: make fs_devices to be a local variable
Since output parameter fs_devices of btrfs_parse_early_options is not used in the caller, make it be a local variable. Signed-off-by: Gu Jinxiang --- fs/btrfs/super.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index bf546d6c286c..4ee082e96d51 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -886,11 +886,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * only when we need to allocate a new super block. */ static int btrfs_parse_early_options(const char *options, fmode_t flags, - void *holder, struct btrfs_fs_devices **fs_devices) + void *holder) { substring_t args[MAX_OPT_ARGS]; char *device_name, *opts, *orig, *p; int error = 0; + struct btrfs_fs_devices *fs_devices = NULL; if (!options) return 0; @@ -918,7 +919,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, goto out; } error = btrfs_scan_one_device(device_name, - flags, holder, fs_devices); + flags, holder, _devices); kfree(device_name); if (error) goto out; @@ -1526,8 +1527,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - error = btrfs_parse_early_options(data, mode, fs_type, - _devices); + error = btrfs_parse_early_options(data, mode, fs_type); if (error) { return ERR_PTR(error); } -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] btrfs: get fs_devices pointer form btrfs_scan_one_device
Instead of pointer to btrfs_fs_devices as an arg in btrfs_scan_one_device, better to make it as a return value. Signed-off-by: Gu Jinxiang --- fs/btrfs/super.c | 29 ++--- fs/btrfs/volumes.c | 14 +++--- fs/btrfs/volumes.h | 4 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4ee082e96d51..a5ddeb6836e3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -918,11 +918,13 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, error = -ENOMEM; goto out; } - error = btrfs_scan_one_device(device_name, - flags, holder, _devices); + fs_devices = btrfs_scan_one_device(device_name, + flags, holder); kfree(device_name); - if (error) + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto out; + } } } @@ -1539,9 +1541,11 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, return ERR_PTR(error); } - error = btrfs_scan_one_device(device_name, mode, fs_type, _devices); - if (error) + fs_devices = btrfs_scan_one_device(device_name, mode, fs_type); + if (IS_ERR(fs_devices)) { + error = PTR_ERR(fs_devices); goto error_sec_opts; + } /* * Setup a dummy root and fs_info for test/set super. This is because @@ -,7 +2226,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct btrfs_ioctl_vol_args *vol; - struct btrfs_fs_devices *fs_devices; + struct btrfs_fs_devices *fs_devices = NULL; int ret = -ENOTTY; if (!capable(CAP_SYS_ADMIN)) @@ -2234,14 +2238,17 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case BTRFS_IOC_SCAN_DEV: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + ret = IS_ERR(fs_devices) ? PTR_ERR(fs_devices) : 0; break; case BTRFS_IOC_DEVICES_READY: - ret = btrfs_scan_one_device(vol->name, FMODE_READ, - _root_fs_type, _devices); - if (ret) + fs_devices = btrfs_scan_one_device(vol->name, FMODE_READ, + _root_fs_type); + if (IS_ERR(fs_devices)) { + ret = PTR_ERR(fs_devices); break; + } ret = !(fs_devices->num_devices == fs_devices->total_devices); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b33bf29130b6..922c4ad6d421 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1215,14 +1215,14 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, * and we are not allowed to call set_blocksize during the scan. The superblock * is read via pagecache */ -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, - struct btrfs_fs_devices **fs_devices_ret) +struct btrfs_fs_devices *btrfs_scan_one_device(const char *path, fmode_t flags, + void *holder) { struct btrfs_super_block *disk_super; struct btrfs_device *device; struct block_device *bdev; struct page *page; - int ret = 0; + struct btrfs_fs_devices *ret = NULL; u64 bytenr; /* @@ -1236,19 +1236,19 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, bdev = blkdev_get_by_path(path, flags, holder); if (IS_ERR(bdev)) - return PTR_ERR(bdev); + return (struct btrfs_fs_devices *)bdev; if (btrfs_read_disk_super(bdev, bytenr, , _super)) { - ret = -EINVAL; + ret = ERR_PTR(-EINVAL); goto error_bdev_put; } mutex_lock(_mutex); device = device_list_add(path, disk_super); if (IS_ERR(device)) - ret = PTR_ERR(device); + ret = (struct btrfs_fs_devices *)device; else - *fs_devices_ret = device->fs_devices; + ret = device->fs_devices; mutex_unlock(_mutex); btrfs_release_disk_super(page); diff --git a/fs/bt
[PATCH] btrfs: remove unused parameter
Since parameter flags is no more used since commit d7407606564c ("btrfs: split parse_early_options() in two"), remove it. Signed-off-by: Gu Jinxiang --- fs/btrfs/super.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 81107ad49f3a..bf546d6c286c 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -935,8 +935,8 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, * * The value is later passed to mount_subvol() */ -static int btrfs_parse_subvol_options(const char *options, fmode_t flags, - char **subvol_name, u64 *subvol_objectid) +static int btrfs_parse_subvol_options(const char *options, char **subvol_name, + u64 *subvol_objectid) { substring_t args[MAX_OPT_ARGS]; char *opts, *orig, *p; @@ -1650,8 +1650,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - error = btrfs_parse_subvol_options(data, mode, - _name, _objectid); + error = btrfs_parse_subvol_options(data, _name, + _objectid); if (error) { kfree(subvol_name); return ERR_PTR(error); -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v2 1/2] btrfs: Check each block group has corresponding chunk at mount time
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Friday, July 06, 2018 1:36 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH v2 1/2] btrfs: Check each block group has corresponding chunk > at mount time > > A crafted btrfs with incorrect chunk<->block group mapping, it could leads > to a lot of unexpected behavior. > > Although the crafted image can be catched by block group item checker > added in "[PATCH] btrfs: tree-checker: Verify block_group_item", if one > crafted a valid enough block group item which can pass above check but > still mismatch with existing chunk, it could cause a lot of undefined > behavior. > > This patch will add extra block group -> chunk mapping check, to ensure > we have a completely matching (start, len, flags) chunk for each block > group at mount time. > > Here we reuse the original find_first_block_group(), which is already > doing basic bg -> chunk check, adding more check on start/len and type > flags. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199837 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > changelog: > v2: > Reuse existing find_first_block_group() to do the verification, > pointed out by Gu. > --- > fs/btrfs/extent-tree.c | 29 - > 1 file changed, 28 insertions(+), 1 deletion(-) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 3d9fe58c0080..63a6b5d36ac1 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -9717,6 +9717,8 @@ static int find_first_block_group(struct btrfs_fs_info > *fs_info, > int ret = 0; > struct btrfs_key found_key; > struct extent_buffer *leaf; > + struct btrfs_block_group_item bg; > + u64 flags; > int slot; > > ret = btrfs_search_slot(NULL, root, key, path, 0, 0); > @@ -9751,8 +9753,33 @@ static int find_first_block_group(struct btrfs_fs_info > *fs_info, > "logical %llu len %llu found bg but no related chunk", > found_key.objectid, found_key.offset); > ret = -ENOENT; > + } else if (em->start != found_key.objectid || > +em->len != found_key.offset) { > + btrfs_err(fs_info, > + "block group %llu len %llu mismatch with chunk %llu len %llu", > + found_key.objectid, found_key.offset, > + em->start, em->len); > + ret = -EUCLEAN; > } else { > - ret = 0; > + read_extent_buffer(leaf, , > + btrfs_item_ptr_offset(leaf, slot), > + sizeof(bg)); > + flags = btrfs_block_group_flags() & > + BTRFS_BLOCK_GROUP_TYPE_MASK; > + > + if (flags != (em->map_lookup->type & > + BTRFS_BLOCK_GROUP_TYPE_MASK)) { > + btrfs_err(fs_info, > +"block group %llu len %llu type flags 0x%llx mismatch with chunk type flags > 0x%llx", > + found_key.objectid, > + found_key.offset, > + flags, > + (BTRFS_BLOCK_GROUP_TYPE_MASK & > + em->map_lookup->type)); > + ret = -EUCLEAN; > + } else { > + ret = 0; > + } > } > free_extent_map(em); > goto out; > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
RE: [PATCH 4/4] btrfs-progs: check/original: Don't overwrite return value when we failed to repair
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Thursday, July 05, 2018 3:38 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 4/4] btrfs-progs: check/original: Don't overwrite return > value when we failed to repair > > In check_inode_recs(), for repair mode we always reset @ret to 0. > It makes no sense and later we check@ret to determine if the repair is > successful. > > Fix it by removing the offending overwrite. > > Signed-off-by: Qu Wenruo > --- > check/main.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/check/main.c b/check/main.c > index 2b5abb2d025b..08476968aaba 100644 > --- a/check/main.c > +++ b/check/main.c > @@ -2764,7 +2764,6 @@ static int check_inode_recs(struct btrfs_root *root, > free_inode_rec(rec); > continue; > } > - ret = 0; > } > > if (!(repair && ret == 0)) > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
RE: [PATCH 3/4] btrfs-progs: check/original: Avoid infinite loop when failed to repair inode
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Thursday, July 05, 2018 3:38 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 3/4] btrfs-progs: check/original: Avoid infinite loop when > failed to repair inode > > Exposed by fuzz-tests/003-multi-check-unmounted/ on fuzzed image > bko-161811.raw.xz. > > It's caused by the fact when check_fs_roots() finds tree root is > modified, it re-search tree root by goto again: tag. > However again: tag will also reset root objectid to 0. > If we failed to repair one fs root but still modified tree root, we will > go into such infinite loop. > > Fix it by record which root we should skip for repair mode. > > Signed-off-by: Qu Wenruo > --- > check/main.c | 19 +-- > 1 file changed, 17 insertions(+), 2 deletions(-) > > diff --git a/check/main.c b/check/main.c > index c8c347236543..2b5abb2d025b 100644 > --- a/check/main.c > +++ b/check/main.c > @@ -3380,6 +3380,7 @@ static int check_fs_roots(struct btrfs_fs_info *fs_info, > struct extent_buffer *leaf, *tree_node; > struct btrfs_root *tmp_root; > struct btrfs_root *tree_root = fs_info->tree_root; > + u64 skip_root = 0; > int ret; > int err = 0; > > @@ -3400,7 +3401,10 @@ static int check_fs_roots(struct btrfs_fs_info > *fs_info, > > again: > key.offset = 0; > - key.objectid = 0; > + if (skip_root) > + key.objectid = skip_root + 1; > + else > + key.objectid = 0; > key.type = BTRFS_ROOT_ITEM_KEY; > ret = btrfs_search_slot(NULL, tree_root, , , 0, 0); > if (ret < 0) { > @@ -3409,6 +3413,7 @@ again: > } > tree_node = tree_root->node; > while (1) { > + > if (tree_node != tree_root->node) { > free_root_recs_tree(root_cache); > btrfs_release_path(); > @@ -3445,8 +3450,18 @@ again: > btrfs_release_path(); > goto again; > } > - if (ret) > + if (ret) { > err = 1; > + > + /* > + * We failed to repair this root but modified > tree > + * root, after again: tag we will still hit this > + * root and fail to repair, must skip this root > to > + * avoid infinite loop > + */ > + if (repair) > + skip_root = key.objectid; > + } > if (key.objectid == BTRFS_TREE_RELOC_OBJECTID) > btrfs_free_fs_root(tmp_root); > } else if (key.type == BTRFS_ROOT_REF_KEY || > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild root overwritting existing tree blocks
> -Original Message- > From: Qu Wenruo [mailto:quwenruo.bt...@gmx.com] > Sent: Thursday, July 05, 2018 5:41 PM > To: Gu, Jinxiang/顾 金香 ; Qu Wenruo ; > linux-btrfs@vger.kernel.org > Subject: Re: [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild > root overwritting existing tree blocks > > > > On 2018年07月05日 16:50, Gu, Jinxiang wrote: > > > > > >> -Original Message- > >> From: linux-btrfs-ow...@vger.kernel.org > >> [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > >> Sent: Thursday, July 05, 2018 3:37 PM > >> To: linux-btrfs@vger.kernel.org > >> Subject: [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild > >> root overwritting existing tree blocks > >> > >> We have function btrfs_fsck_reinit_root() to reinit csum or extent tree. > > > > Nit: > > or fs/file tree > > Nope, btrfs check is only capable of reinit csum or extent tree. Sorry, not fs/file tree. But DATA RELOC TREE. Call stack is reset_balance -> btrfs_fsck_reinit_root, and the root is get by btrfs_read_fs_root(fs_info, ), which key is (BTRFS_DATA_RELOC_TREE_OBJECTID, BTRFS_ROOT_ITEM_KEY , (u64)-1) > > Thanks, > Qu > > > > >> However this function allows us to let it overwrite existing tree blocks > >> using @overwrite parameter. > >> > >> Such behavior is pretty dangerous while no caller is using this feature > >> explicitly. > >> > >> So just remove @overwrite parameter and allow btrfs_fsck_reinit_root() > >> to error out when it fails to allocate tree block. > >> > >> Signed-off-by: Qu Wenruo > >> --- > >> check/main.c | 26 -- > >> 1 file changed, 8 insertions(+), 18 deletions(-) > >> > >> diff --git a/check/main.c b/check/main.c > >> index 8db300abb825..c8c347236543 100644 > >> --- a/check/main.c > >> +++ b/check/main.c > >> @@ -8379,7 +8379,7 @@ static int do_check_chunks_and_extents(struct > >> btrfs_fs_info *fs_info) > >> } > >> > >> static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, > >> - struct btrfs_root *root, int overwrite) > >> +struct btrfs_root *root) > >> { > >>struct extent_buffer *c; > >>struct extent_buffer *old = root->node; > >> @@ -8389,21 +8389,13 @@ static int btrfs_fsck_reinit_root(struct > >> btrfs_trans_handle *trans, > >> > >>level = 0; > >> > >> - if (overwrite) { > >> - c = old; > >> - extent_buffer_get(c); > >> - goto init; > >> - } > >>c = btrfs_alloc_free_block(trans, root, > >> root->fs_info->nodesize, > >> root->root_key.objectid, > >> _key, level, 0, 0); > >> - if (IS_ERR(c)) { > >> - c = old; > >> - extent_buffer_get(c); > >> - overwrite = 1; > >> - } > >> -init: > >> + if (IS_ERR(c)) > >> + return PTR_ERR(c); > >> + > >>memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header)); > >>btrfs_set_header_level(c, level); > >>btrfs_set_header_bytenr(c, c->start); > >> @@ -8422,9 +8414,7 @@ init: > >>/* > >> * this case can happen in the following case: > >> * > >> - * 1.overwrite previous root. > >> - * > >> - * 2.reinit reloc data root, this is because we skip pin > >> + * reinit reloc data root, this is because we skip pin > >> * down reloc data tree before which means we can allocate > >> * same block bytenr here. > >> */ > >> @@ -8609,7 +8599,7 @@ reinit_data_reloc: > >>goto out; > >>} > >>record_root_in_trans(trans, root); > >> - ret = btrfs_fsck_reinit_root(trans, root, 0); > >> + ret = btrfs_fsck_reinit_root(trans, root); > >>if (ret) > >>goto out; > >>ret = btrfs_make_root_dir(trans, root, BTRFS_FIRST_FREE_OBJECTID); > >> @@ -8675,7 +8665,7 @@ again: > >>} > >> > >>/* Ok we can allocate now, reinit the extent root */ > >> - ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root, 0); > >> + ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root); > >>if (ret) { > >
RE: [PATCH 2/4] btrfs-progs: transaction: Error out other than panic when committing transaction
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Thursday, July 05, 2018 3:37 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 2/4] btrfs-progs: transaction: Error out other than panic > when committing transaction > > There are cases that btrfs_commit_transaction() itself can fail, mostly > due to ENOSPC when allocating space. > > Don't panic out in this case. > > Signed-off-by: Qu Wenruo > --- > transaction.c | 19 +-- > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/transaction.c b/transaction.c > index 9619265ef6e8..b82d346b52c8 100644 > --- a/transaction.c > +++ b/transaction.c > @@ -73,7 +73,8 @@ static int update_cowonly_root(struct btrfs_trans_handle > *trans, > ret = btrfs_update_root(trans, tree_root, > >root_key, > >root_item); > - BUG_ON(ret); > + if (ret < 0) > + return ret; > btrfs_write_dirty_block_groups(trans, root); > } > return 0; > @@ -101,9 +102,11 @@ int commit_tree_roots(struct btrfs_trans_handle *trans, > next = fs_info->dirty_cowonly_roots.next; > list_del_init(next); > root = list_entry(next, struct btrfs_root, dirty_list); > - update_cowonly_root(trans, root); > + ret = update_cowonly_root(trans, root); > free_extent_buffer(root->commit_root); > root->commit_root = NULL; > + if (ret < 0) > + return ret; > } > > return 0; > @@ -162,12 +165,15 @@ int btrfs_commit_transaction(struct btrfs_trans_handle > *trans, > root->root_item.level = btrfs_header_level(root->node); > ret = btrfs_update_root(trans, root->fs_info->tree_root, > >root_key, >root_item); > - BUG_ON(ret); > + if (ret < 0) > + goto out; > commit_tree: > ret = commit_tree_roots(trans, fs_info); > - BUG_ON(ret); > + if (ret < 0) > + goto out; > ret = __commit_transaction(trans, root); > - BUG_ON(ret); > + if (ret < 0) > + goto out; > write_ctree_super(trans); > btrfs_finish_extent_commit(trans, fs_info->extent_root, > _info->pinned_extents); > @@ -176,7 +182,8 @@ commit_tree: > root->commit_root = NULL; > fs_info->running_transaction = NULL; > fs_info->last_trans_committed = transid; > - return 0; > +out: > + return ret; > } > > void btrfs_abort_transaction(struct btrfs_trans_handle *trans, int error) > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild root overwritting existing tree blocks
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Thursday, July 05, 2018 3:37 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild root > overwritting existing tree blocks > > We have function btrfs_fsck_reinit_root() to reinit csum or extent tree. Nit: or fs/file tree > However this function allows us to let it overwrite existing tree blocks > using @overwrite parameter. > > Such behavior is pretty dangerous while no caller is using this feature > explicitly. > > So just remove @overwrite parameter and allow btrfs_fsck_reinit_root() > to error out when it fails to allocate tree block. > > Signed-off-by: Qu Wenruo > --- > check/main.c | 26 -- > 1 file changed, 8 insertions(+), 18 deletions(-) > > diff --git a/check/main.c b/check/main.c > index 8db300abb825..c8c347236543 100644 > --- a/check/main.c > +++ b/check/main.c > @@ -8379,7 +8379,7 @@ static int do_check_chunks_and_extents(struct > btrfs_fs_info *fs_info) > } > > static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, > -struct btrfs_root *root, int overwrite) > + struct btrfs_root *root) > { > struct extent_buffer *c; > struct extent_buffer *old = root->node; > @@ -8389,21 +8389,13 @@ static int btrfs_fsck_reinit_root(struct > btrfs_trans_handle *trans, > > level = 0; > > - if (overwrite) { > - c = old; > - extent_buffer_get(c); > - goto init; > - } > c = btrfs_alloc_free_block(trans, root, > root->fs_info->nodesize, > root->root_key.objectid, > _key, level, 0, 0); > - if (IS_ERR(c)) { > - c = old; > - extent_buffer_get(c); > - overwrite = 1; > - } > -init: > + if (IS_ERR(c)) > + return PTR_ERR(c); > + > memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header)); > btrfs_set_header_level(c, level); > btrfs_set_header_bytenr(c, c->start); > @@ -8422,9 +8414,7 @@ init: > /* >* this case can happen in the following case: >* > - * 1.overwrite previous root. > - * > - * 2.reinit reloc data root, this is because we skip pin > + * reinit reloc data root, this is because we skip pin >* down reloc data tree before which means we can allocate >* same block bytenr here. >*/ > @@ -8609,7 +8599,7 @@ reinit_data_reloc: > goto out; > } > record_root_in_trans(trans, root); > - ret = btrfs_fsck_reinit_root(trans, root, 0); > + ret = btrfs_fsck_reinit_root(trans, root); > if (ret) > goto out; > ret = btrfs_make_root_dir(trans, root, BTRFS_FIRST_FREE_OBJECTID); > @@ -8675,7 +8665,7 @@ again: > } > > /* Ok we can allocate now, reinit the extent root */ > - ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root, 0); > + ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root); > if (ret) { > fprintf(stderr, "extent root initialization failed\n"); > /* > @@ -9764,7 +9754,7 @@ int cmd_check(int argc, char **argv) > > if (init_csum_tree) { > printf("Reinitialize checksum tree\n"); > - ret = btrfs_fsck_reinit_root(trans, info->csum_root, 0); > + ret = btrfs_fsck_reinit_root(trans, info->csum_root); > if (ret) { > error("checksum tree initialization failed: %d", > ret); > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
[PATCH v3] btrfs: Add chunk type check in read a chunk
Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839, which has a invalid chunk, not return error opportunlly. Add chunk type check in btrfs_check_chunk_valid, to make error be returned in advance. Reported-by: Xu Wen Signed-off-by: Gu Jinxiang Reviewed-by: Qu Wenruo --- changelog: v3: deal with comment by Nikolay Borisov, change the error message more appropriate. v2: deal with comment by Qu, add precise check for chunk type. fs/btrfs/volumes.c | 29 + 1 file changed, 29 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b33bf29130b6..deea169cc276 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6401,6 +6401,8 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, u16 num_stripes; u16 sub_stripes; u64 type; + u64 features; + int mixed = 0; length = btrfs_chunk_length(leaf, chunk); stripe_len = btrfs_chunk_stripe_len(leaf, chunk); @@ -6439,6 +6441,33 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, btrfs_chunk_type(leaf, chunk)); return -EIO; } + + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(fs_info, "missing chunk type flag: %llu", type); + return -EIO; + } + + if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && + (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) { + btrfs_err(fs_info, +"system chunk type, meanwhile with metadata or data chunk type flag: %llu", + type); + return -EIO; + } + + features = btrfs_super_incompat_flags(fs_info->super_copy); + if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) + mixed = 1; + + if (!mixed) { + if (type & + (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) { + btrfs_err(fs_info, + "mixed chunk type flag in non-mixed mode: %llu", type); + return -EIO; + } + } + if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v2] btrfs: Add chunk type check in read a chunk
> -Original Message- > From: Nikolay Borisov [mailto:nbori...@suse.com] > Sent: Wednesday, July 04, 2018 4:15 PM > To: Gu, Jinxiang/顾 金香 ; linux-btrfs@vger.kernel.org > Cc: quwenruo.bt...@gmx.com; wen...@gatech.edu; xuwen.s...@gmail.com > Subject: Re: [PATCH v2] btrfs: Add chunk type check in read a chunk > > > > On 3.07.2018 09:20, Gu Jinxiang wrote: > > Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839, > > which has a invalid chunk, not return error opportunlly. > > > > Add chunk type check in btrfs_check_chunk_valid, > > to make error be returned in advance. > > > > Reported-by: Xu Wen > > Signed-off-by: Gu Jinxiang > > --- > > changelog: > > v2: > > deal with comment by Qu, add precise check for chunk type. > > > > fs/btrfs/volumes.c | 27 +++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > > index e034ad9e23b4..fcdb1a75d653 100644 > > --- a/fs/btrfs/volumes.c > > +++ b/fs/btrfs/volumes.c > > @@ -6401,6 +6401,8 @@ static int btrfs_check_chunk_valid(struct > > btrfs_fs_info *fs_info, > > u16 num_stripes; > > u16 sub_stripes; > > u64 type; > > + u64 features; > > + int mixed = 0; > > > > length = btrfs_chunk_length(leaf, chunk); > > stripe_len = btrfs_chunk_stripe_len(leaf, chunk); > > @@ -6439,6 +6441,31 @@ static int btrfs_check_chunk_valid(struct > > btrfs_fs_info *fs_info, > > btrfs_chunk_type(leaf, chunk)); > > return -EIO; > > } > > + > > + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { > > + btrfs_err(fs_info, "missing chunk type flag: %llu", type); > > + return -EIO; > > + } > > + > > + if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && > > + (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) { > > + btrfs_err(fs_info, "duplicate chunk type flag: %llu", type); > > This is not really a duplicate chunk type flag but instead an invalid > combination. SYSTEM is always a dedicated chunk, rephrase the error > message. Yes. This message should be updated. But [PATCH 1/5] btrfs: tree-checker: Verify block_group_item sent by Qu, checks the chunk type in tree checker, which be called when read a bio. So this patch should not be merged. > > > + return -EIO; > > + } > > + > > + features = btrfs_super_incompat_flags(fs_info->super_copy); > > + if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) > > + mixed = 1; > > + > > + if (!mixed) { > > + if (type & > > + (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) { > > + btrfs_err(fs_info, > > + "mixed chunk type flag in non-mixed mode: %llu", type); > > + return -EIO; > > + } > > + } > > + > > if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || > > (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || > > (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || > > >
RE: [PATCH 2/5] btrfs: tree-checker: Detect invalid empty essential tree
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Tuesday, July 03, 2018 5:10 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 2/5] btrfs: tree-checker: Detect invalid empty essential tree > > A crafted image has empty root tree block, which will cause later NULL > pointer dereference. > > The following trees should never be empty: > 1) Tree root >Must contain at least root items for extent tree, device tree and fs >tree > > 2) Chunk tree >Or we can't even bootstrap. > > 3) Fs tree >At least inode item for top level inode (.). > > 4) Device tree >Dev extents for chunks > > 5) Extent tree >Must has corresponding extent for each chunk. > > If any is empty, we are sure the fs is corrupted and no need to mount > it. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199847 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > fs/btrfs/tree-checker.c | 12 > 1 file changed, 12 insertions(+) > > diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c > index 1cd735b099df..3a307efab46b 100644 > --- a/fs/btrfs/tree-checker.c > +++ b/fs/btrfs/tree-checker.c > @@ -497,8 +497,20 @@ static int check_leaf(struct btrfs_fs_info *fs_info, > struct extent_buffer *leaf, >* skip this check for relocation trees. >*/ > if (nritems == 0 && !btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_RELOC)) { > + u64 owner = btrfs_header_owner(leaf); > struct btrfs_root *check_root; > > + /* These trees should never be empty */ > + if (owner == BTRFS_ROOT_TREE_OBJECTID || > + owner == BTRFS_CHUNK_TREE_OBJECTID || > + owner == BTRFS_EXTENT_TREE_OBJECTID || > + owner == BTRFS_DEV_TREE_OBJECTID || > + owner == BTRFS_FS_TREE_OBJECTID) { > + generic_err(fs_info, leaf, 0, > + "invalid root, root %llu should never be empty", > + owner); > + return -EUCLEAN; > + } > key.objectid = btrfs_header_owner(leaf); > key.type = BTRFS_ROOT_ITEM_KEY; > key.offset = (u64)-1; > -- Tested-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH 3/5] btrfs: relocation: Only remove reloc rb_trees if reloc control has been initialized
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Tuesday, July 03, 2018 5:10 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 3/5] btrfs: relocation: Only remove reloc rb_trees if reloc > control has been initialized > > Invalid tree reloc tree can cause kernel NULL pointer dereference when > btrfs does some cleanup for reloc roots. > > It turns out that fs_info->reloc_ctl can be NULL in > btrfs_recover_relocation() as we allocate relocation control after all > reloc roots are verified. > So when we hit out: tag, we haven't call set_reloc_control() thus > fs_info->reloc_ctl is still NULL. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199833 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > fs/btrfs/relocation.c | 23 --- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c > index 879b76fa881a..be94c65bb4d2 100644 > --- a/fs/btrfs/relocation.c > +++ b/fs/btrfs/relocation.c > @@ -1321,18 +1321,19 @@ static void __del_reloc_root(struct btrfs_root *root) > struct mapping_node *node = NULL; > struct reloc_control *rc = fs_info->reloc_ctl; > > - spin_lock(>reloc_root_tree.lock); > - rb_node = tree_search(>reloc_root_tree.rb_root, > - root->node->start); > - if (rb_node) { > - node = rb_entry(rb_node, struct mapping_node, rb_node); > - rb_erase(>rb_node, >reloc_root_tree.rb_root); > + if (rc) { > + spin_lock(>reloc_root_tree.lock); > + rb_node = tree_search(>reloc_root_tree.rb_root, > + root->node->start); > + if (rb_node) { > + node = rb_entry(rb_node, struct mapping_node, rb_node); > + rb_erase(>rb_node, >reloc_root_tree.rb_root); > + } > + spin_unlock(>reloc_root_tree.lock); > + if (!node) > + return; > + BUG_ON((struct btrfs_root *)node->data != root); > } > - spin_unlock(>reloc_root_tree.lock); > - > - if (!node) > - return; > - BUG_ON((struct btrfs_root *)node->data != root); > > spin_lock(_info->trans_lock); > list_del_init(>root_list); > -- Tested-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH 1/5] btrfs: tree-checker: Verify block_group_item
+ if (hweight64(flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) > 1) { > + block_group_err(fs_info, leaf, slot, > +"invalid profile flags, have 0x%llx (%lu bits set) expect no more than 1 bit > set", > + flags & BTRFS_BLOCK_GROUP_PROFILE_MASK, > + hweight64(flags & BTRFS_BLOCK_GROUP_PROFILE_MASK)); > + return -EUCLEAN; > + } > + > + type_flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK; > + if (type_flags != BTRFS_BLOCK_GROUP_DATA && > + type_flags != BTRFS_BLOCK_GROUP_METADATA && > + type_flags != BTRFS_BLOCK_GROUP_SYSTEM && > + type_flags != (BTRFS_BLOCK_GROUP_METADATA | > +BTRFS_BLOCK_GROUP_DATA)) { > + block_group_err(fs_info, leaf, slot, > +"invalid type flags, have 0x%llx (%lu bits set) expect either 0x%llx, > 0x%llx, 0x%llu or 0x%llx", > + type_flags, hweight64(type_flags), > + BTRFS_BLOCK_GROUP_DATA, BTRFS_BLOCK_GROUP_METADATA, > + BTRFS_BLOCK_GROUP_SYSTEM, > + BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA); > + return -EUCLEAN; > + } > + return 0; > +} > + > /* > * Common point to switch the item-specific validation. > */ > @@ -374,6 +472,9 @@ static int check_leaf_item(struct btrfs_fs_info *fs_info, > case BTRFS_XATTR_ITEM_KEY: > ret = check_dir_item(fs_info, leaf, key, slot); > break; > + case BTRFS_BLOCK_GROUP_ITEM_KEY: > + ret = check_block_group_item(fs_info, leaf, key, slot); > + break; > } > return ret; > } > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index e034ad9e23b4..b33bf29130b6 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -4690,7 +4690,7 @@ static int __btrfs_alloc_chunk(struct > btrfs_trans_handle *trans, > > if (type & BTRFS_BLOCK_GROUP_DATA) { > max_stripe_size = SZ_1G; > - max_chunk_size = 10 * max_stripe_size; > + max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE; > if (!devs_max) > devs_max = BTRFS_MAX_DEVS(info); > } else if (type & BTRFS_BLOCK_GROUP_METADATA) { > diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h > index 5139ec8daf4c..77e6004b6cb9 100644 > --- a/fs/btrfs/volumes.h > +++ b/fs/btrfs/volumes.h > @@ -11,6 +11,8 @@ > #include > #include "async-thread.h" > > +#define BTRFS_MAX_DATA_CHUNK_SIZE(10ULL * SZ_1G) > + > extern struct mutex uuid_mutex; > > #define BTRFS_STRIPE_LEN SZ_64K > -- Tested-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH 5/5] btrfs: Verify every chunk has corresponding block group at mount time
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Tuesday, July 03, 2018 5:10 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 5/5] btrfs: Verify every chunk has corresponding block group > at mount time > > If a crafted btrfs has missing block group items, it could cause > unexpected behavior and breaks our expectation on 1:1 > chunk<->block group mapping. > > Although we added block group -> chunk mapping check, we still need > chunk -> block group mapping check. > > This patch will do extra check to ensure each chunk has its > corresponding block group. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199847 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > fs/btrfs/extent-tree.c | 52 +- > 1 file changed, 51 insertions(+), 1 deletion(-) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 82b446f014b9..746095034ca2 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -10038,6 +10038,56 @@ static int check_exist_chunk(struct btrfs_fs_info > *fs_info, u64 start, u64 len, > return ret; > } > > +/* > + * Iterate all chunks and verify each of them has corresponding block group > + */ > +static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info) > +{ > + struct btrfs_mapping_tree *map_tree = _info->mapping_tree; > + struct extent_map *em; > + struct btrfs_block_group_cache *bg; > + u64 start = 0; > + int ret = 0; > + > + while (1) { > + read_lock(_tree->map_tree.lock); > + em = lookup_extent_mapping(_tree->map_tree, start, > +(u64)-1 - start); > + read_unlock(_tree->map_tree.lock); > + if (!em) > + break; > + > + bg = btrfs_lookup_block_group(fs_info, em->start); > + if (!bg) { > + btrfs_err_rl(fs_info, > + "chunk start=%llu len=%llu doesn't have corresponding block group", > + em->start, em->len); > + ret = -ENOENT; > + free_extent_map(em); > + break; > + } > + if (bg->key.objectid != em->start || > + bg->key.offset != em->len || > + (bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK) != > + (em->map_lookup->type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { > + btrfs_err_rl(fs_info, > +"chunk start=%llu len=%llu flags=0x%llx doesn't match with block group > start=%llu len=%llu flags=0x%llx", > + em->start, em->len, > + em->map_lookup->type & > BTRFS_BLOCK_GROUP_TYPE_MASK, > + bg->key.objectid, bg->key.offset, > + bg->flags & BTRFS_BLOCK_GROUP_TYPE_MASK); > + ret = -EUCLEAN; > + free_extent_map(em); > + btrfs_put_block_group(bg); > + break; > + } > + start = em->start + em->len; > + free_extent_map(em); > + btrfs_put_block_group(bg); > + } > + return ret; > +} > + > int btrfs_read_block_groups(struct btrfs_fs_info *info) > { > struct btrfs_path *path; > @@ -10227,7 +10277,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info > *info) > > btrfs_add_raid_kobjects(info); > init_global_block_rsv(info); > - ret = 0; > + ret = check_chunk_block_group_mappings(info); > error: > btrfs_free_path(path); > return ret; > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH 4/5] btrfs: Check each block group has corresponding chunk at mount time
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Tuesday, July 03, 2018 5:10 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 4/5] btrfs: Check each block group has corresponding chunk at > mount time > > A crafted btrfs with incorrect chunk<->block group mapping, it could leads > to a lot of unexpected behavior. > > Although the crafted image can be catched by block group item checker > added in "[PATCH] btrfs: tree-checker: Verify block_group_item", if one > crafted a valid enough block group item which can pass above check but > still mismatch with existing chunk, it could cause a lot of undefined > behavior. > > This patch will add extra block group -> chunk mapping check, to ensure > we have a completely matching (start, len, flags) chunk for each block > group at mount time. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199837 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > fs/btrfs/extent-tree.c | 55 -- > 1 file changed, 53 insertions(+), 2 deletions(-) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 3d9fe58c0080..82b446f014b9 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -10003,6 +10003,41 @@ btrfs_create_block_group_cache(struct btrfs_fs_info > *fs_info, > return cache; > } > > +static int check_exist_chunk(struct btrfs_fs_info *fs_info, u64 start, u64 > len, > + u64 flags) > +{ > + struct btrfs_mapping_tree *map_tree = _info->mapping_tree; > + struct extent_map *em; > + int ret; > + > + read_lock(_tree->map_tree.lock); > + em = lookup_extent_mapping(_tree->map_tree, start, len); > + read_unlock(_tree->map_tree.lock); > + > + if (!em) { > + btrfs_err_rl(fs_info, > + "block group start=%llu len=%llu doesn't have corresponding chunk", > + start, len); > + ret = -ENOENT; > + goto out; > + } This check has been done in find_first_block_group which has been called before check_exist_chunk be called. > + if (em->start != start || em->len != len || > + (em->map_lookup->type & BTRFS_BLOCK_GROUP_TYPE_MASK) != > + (flags & BTRFS_BLOCK_GROUP_TYPE_MASK)) { > + btrfs_err_rl(fs_info, > +"block group start=%llu len=%llu flags=0x%llx doesn't match with chunk > start=%llu len=%llu flags=0x%llx", > + start, len , flags & BTRFS_BLOCK_GROUP_TYPE_MASK, > + em->start, em->len, em->map_lookup->type & > + BTRFS_BLOCK_GROUP_TYPE_MASK); > + ret = -EUCLEAN; > + goto out; > + } Should this check also be added to find_first_block_group? > + ret = 0; > +out: > + free_extent_map(em); > + return ret; > +} > + > int btrfs_read_block_groups(struct btrfs_fs_info *info) > { > struct btrfs_path *path; > @@ -10036,6 +10071,9 @@ int btrfs_read_block_groups(struct btrfs_fs_info > *info) > need_clear = 1; > > while (1) { > + struct btrfs_block_group_item bg; > + int slot; > + > ret = find_first_block_group(info, path, ); > if (ret > 0) > break; > @@ -10043,7 +10081,20 @@ int btrfs_read_block_groups(struct btrfs_fs_info > *info) > goto error; > > leaf = path->nodes[0]; > - btrfs_item_key_to_cpu(leaf, _key, path->slots[0]); > + slot = path->slots[0]; > + btrfs_item_key_to_cpu(leaf, _key, slot); > + > + read_extent_buffer(leaf, , btrfs_item_ptr_offset(leaf, slot), > +sizeof(bg)); > + /* > + * Chunk and block group must have 1:1 mapping. > + * So there must be a chunk for this block group. > + */ > + ret = check_exist_chunk(info, found_key.objectid, > + found_key.offset, > + btrfs_block_group_flags()); > + if (ret < 0) > + goto error; > > cache = btrfs_create_block_group_cache(info, found_key.objectid, > found_key.offset); > @@ -10068,7 +10119,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info > *info) > } > > read_extent_buffer(leaf, >item, > -btrfs_item_ptr_offset(leaf, path->slots[0]), > +btrfs_item_ptr_offset(leaf, slot), > sizeof(cache->item)); > cache->flags = btrfs_block_group_flags(>item); > if (!mixed && > -- > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to
RE: [PATCH 3/5] btrfs: relocation: Only remove reloc rb_trees if reloc control has been initialized
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Tuesday, July 03, 2018 5:10 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 3/5] btrfs: relocation: Only remove reloc rb_trees if reloc > control has been initialized > > Invalid tree reloc tree can cause kernel NULL pointer dereference when > btrfs does some cleanup for reloc roots. > > It turns out that fs_info->reloc_ctl can be NULL in > btrfs_recover_relocation() as we allocate relocation control after all > reloc roots are verified. > So when we hit out: tag, we haven't call set_reloc_control() thus > fs_info->reloc_ctl is still NULL. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199833 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > fs/btrfs/relocation.c | 23 --- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c > index 879b76fa881a..be94c65bb4d2 100644 > --- a/fs/btrfs/relocation.c > +++ b/fs/btrfs/relocation.c > @@ -1321,18 +1321,19 @@ static void __del_reloc_root(struct btrfs_root *root) > struct mapping_node *node = NULL; > struct reloc_control *rc = fs_info->reloc_ctl; > > - spin_lock(>reloc_root_tree.lock); > - rb_node = tree_search(>reloc_root_tree.rb_root, > - root->node->start); > - if (rb_node) { > - node = rb_entry(rb_node, struct mapping_node, rb_node); > - rb_erase(>rb_node, >reloc_root_tree.rb_root); > + if (rc) { > + spin_lock(>reloc_root_tree.lock); > + rb_node = tree_search(>reloc_root_tree.rb_root, > + root->node->start); > + if (rb_node) { > + node = rb_entry(rb_node, struct mapping_node, rb_node); > + rb_erase(>rb_node, >reloc_root_tree.rb_root); > + } > + spin_unlock(>reloc_root_tree.lock); > + if (!node) > + return; > + BUG_ON((struct btrfs_root *)node->data != root); > } > - spin_unlock(>reloc_root_tree.lock); > - > - if (!node) > - return; > - BUG_ON((struct btrfs_root *)node->data != root); > > spin_lock(_info->trans_lock); > list_del_init(>root_list); > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
RE: [PATCH 2/5] btrfs: tree-checker: Detect invalid empty essential tree
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Qu Wenruo > Sent: Tuesday, July 03, 2018 5:10 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH 2/5] btrfs: tree-checker: Detect invalid empty essential tree > > A crafted image has empty root tree block, which will cause later NULL > pointer dereference. > > The following trees should never be empty: > 1) Tree root >Must contain at least root items for extent tree, device tree and fs >tree > > 2) Chunk tree >Or we can't even bootstrap. > > 3) Fs tree >At least inode item for top level inode (.). > > 4) Device tree >Dev extents for chunks > > 5) Extent tree >Must has corresponding extent for each chunk. > > If any is empty, we are sure the fs is corrupted and no need to mount > it. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=199847 > Reported-by: Xu Wen > Signed-off-by: Qu Wenruo > --- > fs/btrfs/tree-checker.c | 12 > 1 file changed, 12 insertions(+) > > diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c > index 1cd735b099df..3a307efab46b 100644 > --- a/fs/btrfs/tree-checker.c > +++ b/fs/btrfs/tree-checker.c > @@ -497,8 +497,20 @@ static int check_leaf(struct btrfs_fs_info *fs_info, > struct extent_buffer *leaf, >* skip this check for relocation trees. >*/ > if (nritems == 0 && !btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_RELOC)) { > + u64 owner = btrfs_header_owner(leaf); > struct btrfs_root *check_root; > > + /* These trees should never be empty */ > + if (owner == BTRFS_ROOT_TREE_OBJECTID || > + owner == BTRFS_CHUNK_TREE_OBJECTID || > + owner == BTRFS_EXTENT_TREE_OBJECTID || > + owner == BTRFS_DEV_TREE_OBJECTID || > + owner == BTRFS_FS_TREE_OBJECTID) { > + generic_err(fs_info, leaf, 0, > + "invalid root, root %llu should never be empty", > + owner); > + return -EUCLEAN; > + } > key.objectid = btrfs_header_owner(leaf); > key.type = BTRFS_ROOT_ITEM_KEY; > key.offset = (u64)-1; > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
RE: [PATCH 1/5] btrfs: tree-checker: Verify block_group_item
+ if (hweight64(flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) > 1) { > + block_group_err(fs_info, leaf, slot, > +"invalid profile flags, have 0x%llx (%lu bits set) expect no more than 1 bit > set", > + flags & BTRFS_BLOCK_GROUP_PROFILE_MASK, > + hweight64(flags & BTRFS_BLOCK_GROUP_PROFILE_MASK)); > + return -EUCLEAN; > + } > + > + type_flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK; > + if (type_flags != BTRFS_BLOCK_GROUP_DATA && > + type_flags != BTRFS_BLOCK_GROUP_METADATA && > + type_flags != BTRFS_BLOCK_GROUP_SYSTEM && > + type_flags != (BTRFS_BLOCK_GROUP_METADATA | > +BTRFS_BLOCK_GROUP_DATA)) { > + block_group_err(fs_info, leaf, slot, > +"invalid type flags, have 0x%llx (%lu bits set) expect either 0x%llx, > 0x%llx, 0x%llu or 0x%llx", > + type_flags, hweight64(type_flags), > + BTRFS_BLOCK_GROUP_DATA, BTRFS_BLOCK_GROUP_METADATA, > + BTRFS_BLOCK_GROUP_SYSTEM, > + BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA); > + return -EUCLEAN; > + } > + return 0; > +} > + > /* > * Common point to switch the item-specific validation. > */ > @@ -374,6 +472,9 @@ static int check_leaf_item(struct btrfs_fs_info *fs_info, > case BTRFS_XATTR_ITEM_KEY: > ret = check_dir_item(fs_info, leaf, key, slot); > break; > + case BTRFS_BLOCK_GROUP_ITEM_KEY: > + ret = check_block_group_item(fs_info, leaf, key, slot); > + break; > } > return ret; > } > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index e034ad9e23b4..b33bf29130b6 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -4690,7 +4690,7 @@ static int __btrfs_alloc_chunk(struct > btrfs_trans_handle *trans, > > if (type & BTRFS_BLOCK_GROUP_DATA) { > max_stripe_size = SZ_1G; > - max_chunk_size = 10 * max_stripe_size; > + max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE; > if (!devs_max) > devs_max = BTRFS_MAX_DEVS(info); > } else if (type & BTRFS_BLOCK_GROUP_METADATA) { > diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h > index 5139ec8daf4c..77e6004b6cb9 100644 > --- a/fs/btrfs/volumes.h > +++ b/fs/btrfs/volumes.h > @@ -11,6 +11,8 @@ > #include > #include "async-thread.h" > > +#define BTRFS_MAX_DATA_CHUNK_SIZE(10ULL * SZ_1G) > + > extern struct mutex uuid_mutex; > > #define BTRFS_STRIPE_LEN SZ_64K > -- Reviewed-by: Gu Jinxiang > 2.18.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
[PATCH v2] btrfs: Add chunk type check in read a chunk
Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839, which has a invalid chunk, not return error opportunlly. Add chunk type check in btrfs_check_chunk_valid, to make error be returned in advance. Reported-by: Xu Wen Signed-off-by: Gu Jinxiang --- changelog: v2: deal with comment by Qu, add precise check for chunk type. fs/btrfs/volumes.c | 27 +++ 1 file changed, 27 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e034ad9e23b4..fcdb1a75d653 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6401,6 +6401,8 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, u16 num_stripes; u16 sub_stripes; u64 type; + u64 features; + int mixed = 0; length = btrfs_chunk_length(leaf, chunk); stripe_len = btrfs_chunk_stripe_len(leaf, chunk); @@ -6439,6 +6441,31 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, btrfs_chunk_type(leaf, chunk)); return -EIO; } + + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(fs_info, "missing chunk type flag: %llu", type); + return -EIO; + } + + if ((type & BTRFS_BLOCK_GROUP_SYSTEM) && + (type & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA))) { + btrfs_err(fs_info, "duplicate chunk type flag: %llu", type); + return -EIO; + } + + features = btrfs_super_incompat_flags(fs_info->super_copy); + if (features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) + mixed = 1; + + if (!mixed) { + if (type & + (BTRFS_BLOCK_GROUP_METADATA & BTRFS_BLOCK_GROUP_DATA)) { + btrfs_err(fs_info, + "mixed chunk type flag in non-mixed mode: %llu", type); + return -EIO; + } + } + if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs: Add chunk type check in read a chunk
Reported in https://bugzilla.kernel.org/show_bug.cgi?id=199839, which has a invalid chunk, not return error opportunlly. Add chunk type check in btrfs_check_chunk_valid, to make error be returned in advance. Signed-off-by: Gu Jinxiang --- fs/btrfs/volumes.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e034ad9e23b4..67732c910c3d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6439,6 +6439,12 @@ static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, btrfs_chunk_type(leaf, chunk)); return -EIO; } + + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(fs_info, "missing chunk type flag: %llu", type); + return -EIO; + } + if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes != 2) || (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) || (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) || -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] btrfs: drop useless member qgroup_reserved of btrfs_pending_snapshot
From: Gu JinXiang Since there is no more use of qgroup_reserved member in struct btrfs_pending_snapshot, remove it. Signed-off-by: Gu JinXiang --- fs/btrfs/transaction.h | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index d8c0826bc2c7..94439482a0ec 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -139,7 +139,6 @@ struct btrfs_pending_snapshot { struct btrfs_path *path; /* block reservation for the operation */ struct btrfs_block_rsv block_rsv; - u64 qgroup_reserved; /* extra metadata reservation for relocation */ int error; bool readonly; -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] btrfs: drop unused parameter qgroup_reserved
From: Gu JinXiang Since commit 7775c8184ec0 ("btrfs: remove unused parameter from btrfs_subvolume_release_metadata") parameter qgroup_reserved is not used by caller of function btrfs_subvolume_reserve_metadata. So remove it. Signed-off-by: Gu JinXiang --- fs/btrfs/ctree.h | 3 +-- fs/btrfs/extent-tree.c | 7 ++- fs/btrfs/inode.c | 4 +--- fs/btrfs/ioctl.c | 5 + 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 05829a351117..3ff9458f53a6 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2767,8 +2767,7 @@ void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start, void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans); int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, struct btrfs_block_rsv *rsv, -int nitems, -u64 *qgroup_reserved, bool use_global_rsv); +int nitems, bool use_global_rsv); void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *rsv); void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes, diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index fb9d5ad22bf0..25c48aed39f6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5986,7 +5986,6 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, struct btrfs_block_rsv *rsv, int items, -u64 *qgroup_reserved, bool use_global_rsv) { u64 num_bytes; @@ -6004,8 +6003,6 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, num_bytes = 0; } - *qgroup_reserved = num_bytes; - num_bytes = btrfs_calc_trans_metadata_size(fs_info, items); rsv->space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA); @@ -6015,8 +6012,8 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, if (ret == -ENOSPC && use_global_rsv) ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, 1); - if (ret && *qgroup_reserved) - btrfs_qgroup_free_meta_prealloc(root, *qgroup_reserved); + if (ret && num_bytes) + btrfs_qgroup_free_meta_prealloc(root, num_bytes); return ret; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ec600f986bfb..b7e49e2fdcbf 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4293,7 +4293,6 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) struct btrfs_trans_handle *trans; struct btrfs_block_rsv block_rsv; u64 root_flags; - u64 qgroup_reserved; int ret; int err; @@ -4328,8 +4327,7 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) * two for dir entries, * two for root ref/backref. */ - err = btrfs_subvolume_reserve_metadata(root, _rsv, - 5, _reserved, true); + err = btrfs_subvolume_reserve_metadata(root, _rsv, 5, true); if (err) goto out_up_write; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 4560f8deefed..326374b664be 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -569,7 +569,6 @@ static noinline int create_subvol(struct inode *dir, u64 objectid; u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID; u64 index = 0; - u64 qgroup_reserved; uuid_le new_uuid; root_item = kzalloc(sizeof(*root_item), GFP_KERNEL); @@ -594,8 +593,7 @@ static noinline int create_subvol(struct inode *dir, * The same as the snapshot creation, please see the comment * of create_snapshot(). */ - ret = btrfs_subvolume_reserve_metadata(root, _rsv, - 8, _reserved, false); + ret = btrfs_subvolume_reserve_metadata(root, _rsv, 8, false); if (ret) goto fail_free; @@ -803,7 +801,6 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, */ ret = btrfs_subvolume_reserve_metadata(BTRFS_I(dir)->root, _snapshot->block_rsv, 8, - _snapshot->qgroup_reserved, false); if (ret) goto dec_and_free; -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs: set device state reappearing missing device
From: Gu JinXiang patch for commit 921518924084 ("btrfs: handle dynamically reappearing missing device"). Since BTRFS_DEV_STATE_IN_FS_METADATA will be clear in btrfs_open_one_device, and when alloc a new chunk in __btrfs_alloc_chunk, device with BTRFS_DEV_STATE_IN_FS_METADATA not be set will be skipped, so it can not alloc chunk correctly. And from the source logic, BTRFS_DEV_STATE_IN_FS_METADATA should be also set when reapearing a missing device. And with this patch, xfstests-dev/tests/btrfs/154 should run successfully. Signed-off-by: Gu JinXiang --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 8699080ef505..bf8a41b2847e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -849,6 +849,8 @@ static noinline struct btrfs_device *device_list_add(const char *path, fs_devices->missing_devices--; clear_bit(BTRFS_DEV_STATE_MISSING, >dev_state); + set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, + >dev_state); if (test_bit(BTRFS_DEV_STATE_WRITEABLE, >dev_state) && -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] btrfs: handle failures of set_extent_bits in add_excluded_extent
set_extent_bits may fail, return the result in add_excluded_extent. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> Changelog: v2-v1: 1.remove goto to make the function run linearly. 2.change commit description not pointing out the failure detail, since set_extent_bits's failure type may be added. --- fs/btrfs/extent-tree.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 75cfb80d2551..65ef3456fa62 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -215,11 +215,15 @@ static int add_excluded_extent(struct btrfs_fs_info *fs_info, u64 start, u64 num_bytes) { u64 end = start + num_bytes - 1; - set_extent_bits(_info->freed_extents[0], + int ret = 0; + + ret = set_extent_bits(_info->freed_extents[0], start, end, EXTENT_UPTODATE); - set_extent_bits(_info->freed_extents[1], + if (ret) + return ret; + ret = set_extent_bits(_info->freed_extents[1], start, end, EXTENT_UPTODATE); - return 0; + return ret; } static void free_excluded_extents(struct btrfs_fs_info *fs_info, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller
Function btrfs_exclude_logged_extents may call __exclude_logged_extent which may fail. Propagate the failures of __exclude_logged_extent to upper caller. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- fs/btrfs/extent-tree.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2e85e99b5e6f..28fd71579141 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -6468,6 +6468,7 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, struct btrfs_key key; int found_type; int i; + int ret = 0; if (!btrfs_fs_incompat(fs_info, MIXED_GROUPS)) return 0; @@ -6484,10 +6485,14 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, continue; key.objectid = btrfs_file_extent_disk_bytenr(eb, item); key.offset = btrfs_file_extent_disk_num_bytes(eb, item); - __exclude_logged_extent(fs_info, key.objectid, key.offset); + ret = __exclude_logged_extent(fs_info, key.objectid, + key.offset); + if (ret) + goto out; } - return 0; +out: + return ret; } static void -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent
set_extent_bits may return 0/-EEXIST, so return the result in add_excluded_extent. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- fs/btrfs/extent-tree.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 75cfb80d2551..2e85e99b5e6f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -215,11 +215,16 @@ static int add_excluded_extent(struct btrfs_fs_info *fs_info, u64 start, u64 num_bytes) { u64 end = start + num_bytes - 1; - set_extent_bits(_info->freed_extents[0], + int ret = 0; + + ret = set_extent_bits(_info->freed_extents[0], start, end, EXTENT_UPTODATE); - set_extent_bits(_info->freed_extents[1], + if (ret) + goto out; + ret = set_extent_bits(_info->freed_extents[1], start, end, EXTENT_UPTODATE); - return 0; +out: + return ret; } static void free_excluded_extents(struct btrfs_fs_info *fs_info, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs: handle failures of set_extent_bits in add_excluded_extent
set_extent_bits may return 0/-EEXIST, so return the result in add_excluded_extent. And handle the failures in upper callers. Caller of add_excluded_extent and failure process currently: exclude_super_stripes <- btrfs_make_block_group //handles the failure <- btrfs_read_block_groups //handles the failure __exclude_logged_extent <- btrfs_exclude_logged_extents <- btrfs_alloc_logged_file_extent //propagate failure to upper caller Add logic of propagate return value of __exclude_logged_extent to btrfs_exclude_logged_extents. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- fs/btrfs/extent-tree.c | 20 +++- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 75cfb80d2551..28fd71579141 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -215,11 +215,16 @@ static int add_excluded_extent(struct btrfs_fs_info *fs_info, u64 start, u64 num_bytes) { u64 end = start + num_bytes - 1; - set_extent_bits(_info->freed_extents[0], + int ret = 0; + + ret = set_extent_bits(_info->freed_extents[0], start, end, EXTENT_UPTODATE); - set_extent_bits(_info->freed_extents[1], + if (ret) + goto out; + ret = set_extent_bits(_info->freed_extents[1], start, end, EXTENT_UPTODATE); - return 0; +out: + return ret; } static void free_excluded_extents(struct btrfs_fs_info *fs_info, @@ -6463,6 +6468,7 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, struct btrfs_key key; int found_type; int i; + int ret = 0; if (!btrfs_fs_incompat(fs_info, MIXED_GROUPS)) return 0; @@ -6479,10 +6485,14 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, continue; key.objectid = btrfs_file_extent_disk_bytenr(eb, item); key.offset = btrfs_file_extent_disk_num_bytes(eb, item); - __exclude_logged_extent(fs_info, key.objectid, key.offset); + ret = __exclude_logged_extent(fs_info, key.objectid, + key.offset); + if (ret) + goto out; } - return 0; +out: + return ret; } static void -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs: remove unnecessary if judge
Since add_excluded_extent always returns 0, no need to judge ret. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- fs/btrfs/extent-tree.c | 6 -- 1 file changed, 6 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 75cfb80d2551..4d876b32e136 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -249,8 +249,6 @@ static int exclude_super_stripes(struct btrfs_fs_info *fs_info, cache->bytes_super += stripe_len; ret = add_excluded_extent(fs_info, cache->key.objectid, stripe_len); - if (ret) - return ret; } for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { @@ -282,10 +280,6 @@ static int exclude_super_stripes(struct btrfs_fs_info *fs_info, cache->bytes_super += len; ret = add_excluded_extent(fs_info, start, len); - if (ret) { - kfree(logical); - return ret; - } } kfree(logical); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v6 3/3] btrfs: Add unprivileged version of ino_lookup ioctl
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Tomohiro Misono > Sent: Friday, May 18, 2018 10:55 AM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH v6 3/3] btrfs: Add unprivileged version of ino_lookup ioctl > > Add unprivileged version of ino_lookup ioctl BTRFS_IOC_INO_LOOKUP_USER to > allow normal users to call "btrfs subvolume list/show" etc. > in combination with BTRFS_IOC_GET_SUBVOL_INFO/BTRFS_IOC_GET_SUBVOL_ROOTREF. > > This can be used like BTRFS_IOC_INO_LOOKUP but the argument is different. > This is because it always searches the fs/file tree > correspoinding to the fd with which this ioctl is called and also returns the > name of bottom subvolume. > > The main differences from original ino_lookup ioctl are: > 1. Read + Exec permission will be checked using inode_permission() > during path construction. -EACCES will be returned in case > of failure. > 2. Path construction will be stopped at the inode number which > corresponds to the fd with which this ioctl is called. If > constructed path does not exist under fd's inode, -EACCES > will be returned. > 3. The name of bottom subvolume is also searched and filled. > > Note that the maximum length of path is shorter 256 (BTRFS_VOL_NAME_MAX+1) > bytes than ino_lookup ioctl because of space of > subvolume's name. > > Reviewed-by: Gu Jinxiang <g...@cn.fujitsu.com> > Reviewed-by: Qu Wenruo <w...@suse.com> > Signed-off-by: Tomohiro Misono <misono.tomoh...@jp.fujitsu.com> > --- > fs/btrfs/ioctl.c | 204 > + > include/uapi/linux/btrfs.h | 17 > 2 files changed, 221 insertions(+) > > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index > 463ddedd90da..5e8dfa816ba9 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -2200,6 +2200,166 @@ static noinline int btrfs_search_path_in_tree(struct > btrfs_fs_info *info, > return ret; > } > > +static noinline int btrfs_search_path_in_tree_user(struct inode *inode, > + struct btrfs_ioctl_ino_lookup_user_args *args) { > + struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; > + struct super_block *sb = inode->i_sb; > + struct btrfs_key upper_limit = BTRFS_I(inode)->location; > + u64 treeid = BTRFS_I(inode)->root->root_key.objectid; > + u64 dirid = args->dirid; > + > + unsigned long item_off; > + unsigned long item_len; > + struct btrfs_inode_ref *iref; > + struct btrfs_root_ref *rref; > + struct btrfs_root *root; > + struct btrfs_path *path; > + struct btrfs_key key, key2; > + struct extent_buffer *l; > + struct inode *temp_inode; > + char *ptr; > + int slot; > + int len; > + int total_len = 0; > + int ret; > + > + path = btrfs_alloc_path(); > + if (!path) > + return -ENOMEM; > + > + /* > + * If the bottom subvolume does not exist directly under upper_limit, > + * construct the path in bottomup way. > + */ > + if (dirid != upper_limit.objectid) { > + ptr = >path[BTRFS_INO_LOOKUP_USER_PATH_MAX - 1]; > + > + key.objectid = treeid; > + key.type = BTRFS_ROOT_ITEM_KEY; > + key.offset = (u64)-1; > + root = btrfs_read_fs_root_no_name(fs_info, ); > + if (IS_ERR(root)) { > + ret = -ENOENT; > + goto out; > + } > + > + key.objectid = dirid; > + key.type = BTRFS_INODE_REF_KEY; > + key.offset = (u64)-1; > + while (1) { > + ret = btrfs_search_slot(NULL, root, , path, 0, 0); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = btrfs_previous_item(root, path, dirid, > + BTRFS_INODE_REF_KEY); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = -ENOENT; > + goto out; > + } > + } > + > + l = path->nodes[0]; > + slot = path->slots[0]; > + btrfs_item_key_to_cpu(l, , slot); > + > + ire
RE: [PATCH v6 2/3] btrfs: Add unprivileged ioctl which returns subvolume's ROOT_REF
tems = found; > + /* update min_id for next search */ > + if (found) > + rootrefs->min_id = > + rootrefs->rootref[found - 1].subvolid + 1; > + if (copy_to_user(argp, rootrefs, sizeof(*rootrefs))) > + ret = -EFAULT; > + } > + > + btrfs_free_path(path); > + kfree(rootrefs); > + return ret; > +} > + > static noinline int btrfs_ioctl_snap_destroy(struct file *file, >void __user *arg) > { > @@ -5499,6 +5599,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_set_features(file, argp); > case BTRFS_IOC_GET_SUBVOL_INFO: > return btrfs_ioctl_get_subvol_info(file, argp); > + case BTRFS_IOC_GET_SUBVOL_ROOTREF: > + return btrfs_ioctl_get_subvol_rootref(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > 02cd1f1994e8..b6633f5d4847 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -774,6 +774,20 @@ struct btrfs_ioctl_get_subvol_info_args { > __u64 reserved[8]; > }; > > +#define BTRFS_MAX_ROOTREF_BUFFER_NUM 255 struct > +btrfs_ioctl_get_subvol_rootref_args { > + /* in/out, min id of rootref's subvolid to be searched */ > + __u64 min_id; > + /* out */ > + struct { > + __u64 subvolid; > + __u64 dirid; > + } rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM]; > + /* out, number of found items */ > + __u8 num_items; > + __u8 align[7]; > +}; > + > /* Error codes as returned by the kernel */ enum btrfs_err_code { > BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, @@ -894,5 +908,7 @@ enum > btrfs_err_code { > struct btrfs_ioctl_logical_ino_args) > #define BTRFS_IOC_GET_SUBVOL_INFO > _IOR(BTRFS_IOCTL_MAGIC, 60, \ > struct btrfs_ioctl_get_subvol_info_args) > +#define BTRFS_IOC_GET_SUBVOL_ROOTREF _IOWR(BTRFS_IOCTL_MAGIC, 61, \ > + struct btrfs_ioctl_get_subvol_rootref_args) > > #endif /* _UAPI_LINUX_BTRFS_H */ > -- Tested-by: Gu Jinxiang <g...@cn.fujitsu.com> > 2.14.3 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [PATCH v6 1/3] btrfs: Add unprivileged ioctl which returns subvolume information
path->slots[0] >= > + btrfs_header_nritems(path->nodes[0])) { > + ret = btrfs_next_leaf(root, path); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = -EUCLEAN; > + goto out; > + } > + } > + > + l = path->nodes[0]; > + slot = path->slots[0]; > + btrfs_item_key_to_cpu(l, , slot); > + if (key.objectid == subvol_info->id && > + key.type == BTRFS_ROOT_BACKREF_KEY) { > + subvol_info->parent_id = key.offset; > + > + rref = btrfs_item_ptr(l, slot, struct btrfs_root_ref); > + subvol_info->dirid = btrfs_root_ref_dirid(l, rref); > + > + item_off = btrfs_item_ptr_offset(l, slot) > + + sizeof(struct btrfs_root_ref); > + item_len = btrfs_item_size_nr(l, slot) > + - sizeof(struct btrfs_root_ref); > + read_extent_buffer(l, subvol_info->name, > +item_off, item_len); > + } else { > + ret = -ENOENT; > + goto out; > + } > + } > + > + if (copy_to_user(argp, subvol_info, sizeof(*subvol_info))) > + ret = -EFAULT; > + > +out: > + kzfree(subvol_info); > + btrfs_free_path(path); > + return ret; > +} > + > static noinline int btrfs_ioctl_snap_destroy(struct file *file, >void __user *arg) > { > @@ -5374,6 +5497,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_get_features(file, argp); > case BTRFS_IOC_SET_FEATURES: > return btrfs_ioctl_set_features(file, argp); > + case BTRFS_IOC_GET_SUBVOL_INFO: > + return btrfs_ioctl_get_subvol_info(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > c8d99b9ca550..02cd1f1994e8 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -725,6 +725,55 @@ struct btrfs_ioctl_send_args { > __u64 reserved[4]; /* in */ > }; > > +struct btrfs_ioctl_get_subvol_info_args { > + /* All field is out */ > + /* Id of this subvolume */ > + __u64 id; > + /* Name of this subvolume, used to get the real name at mount point */ > + char name[BTRFS_VOL_NAME_MAX + 1]; > + /* > + * Id of the subvolume which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 parent_id; > + /* > + * Inode number of the directory which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 dirid; > + > + /* Latest transaction id of this subvolume */ > + __u64 generation; > + /* Flags of this subvolume */ > + __u64 flags; > + > + /* uuid of this subvolume */ > + __u8 uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume of which this subvolume is a snapshot. > + * All zero for non-snapshot subvolume > + */ > + __u8 parent_uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume from which this subvolume is received. > + * All zero for non-received subvolume > + */ > + __u8 received_uuid[BTRFS_UUID_SIZE]; > + > + /* Transaction id indicates when change/create/send/receive happens */ > + __u64 ctransid; > + __u64 otransid; > + __u64 stransid; > + __u64 rtransid; > + /* Time corresponds to c/o/s/rtransid */ > + struct btrfs_ioctl_timespec ctime; > + struct btrfs_ioctl_timespec otime; > + struct btrfs_ioctl_timespec stime; > + struct btrfs_ioctl_timespec rtime; > + > + __u64 reserved[8]; > +}; > + > /* Error codes as returned by the kernel */ enum btrfs_err_code { > BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, @@ -843,5 +892,7 @@ enum > btrfs_err_code { > struct btrfs_ioctl_vol_args_v2) > #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \ > struct btrfs_ioctl_logical_ino_args) > +#define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \ > + struct btrfs_ioctl_get_subvol_info_args) > > #endif /* _UAPI_LINUX_BTRFS_H */ > -- Tested-by: Gu Jinxiang <g...@cn.fujitsu.com> > 2.14.3 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
[PATCH] btrfs-progs: Add DEBUG_CFLAGS_INTERNAL for libbtrfsutil
From: Gu JinXiang <g...@cn.fujitsu.com> Add DEBUG_CFLAGS_INTERNAL to LIBBTRFSUTIL_CFLAGS for libbtrfsutil's build. Signed-off-by: Gu JinXiang <g...@cn.fujitsu.com> --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index cbd85533..1e38a56f 100644 --- a/Makefile +++ b/Makefile @@ -85,6 +85,7 @@ LIBBTRFSUTIL_CFLAGS = $(SUBST_CFLAGS) \ -fvisibility=hidden \ -I$(TOPDIR)/libbtrfsutil \ $(EXTRAWARN_CFLAGS) \ + $(DEBUG_CFLAGS_INTERNAL) \ $(EXTRA_CFLAGS) LDFLAGS = $(SUBST_LDFLAGS) \ -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v6 2/3] btrfs: Add unprivileged ioctl which returns subvolume's ROOT_REF
tems = found; > + /* update min_id for next search */ > + if (found) > + rootrefs->min_id = > + rootrefs->rootref[found - 1].subvolid + 1; > + if (copy_to_user(argp, rootrefs, sizeof(*rootrefs))) > + ret = -EFAULT; > + } > + > + btrfs_free_path(path); > + kfree(rootrefs); > + return ret; > +} > + > static noinline int btrfs_ioctl_snap_destroy(struct file *file, >void __user *arg) > { > @@ -5499,6 +5599,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_set_features(file, argp); > case BTRFS_IOC_GET_SUBVOL_INFO: > return btrfs_ioctl_get_subvol_info(file, argp); > + case BTRFS_IOC_GET_SUBVOL_ROOTREF: > + return btrfs_ioctl_get_subvol_rootref(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > 02cd1f1994e8..b6633f5d4847 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -774,6 +774,20 @@ struct btrfs_ioctl_get_subvol_info_args { > __u64 reserved[8]; > }; > > +#define BTRFS_MAX_ROOTREF_BUFFER_NUM 255 struct > +btrfs_ioctl_get_subvol_rootref_args { > + /* in/out, min id of rootref's subvolid to be searched */ > + __u64 min_id; > + /* out */ > + struct { > + __u64 subvolid; > + __u64 dirid; > + } rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM]; > + /* out, number of found items */ > + __u8 num_items; > + __u8 align[7]; > +}; > + > /* Error codes as returned by the kernel */ enum btrfs_err_code { > BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, @@ -894,5 +908,7 @@ enum > btrfs_err_code { > struct btrfs_ioctl_logical_ino_args) > #define BTRFS_IOC_GET_SUBVOL_INFO > _IOR(BTRFS_IOCTL_MAGIC, 60, \ > struct btrfs_ioctl_get_subvol_info_args) > +#define BTRFS_IOC_GET_SUBVOL_ROOTREF _IOWR(BTRFS_IOCTL_MAGIC, 61, \ > + struct btrfs_ioctl_get_subvol_rootref_args) > > #endif /* _UAPI_LINUX_BTRFS_H */ > -- Looks good to me. Reviewed-by: Gu Jinxiang <g...@cn.fujitsu.com> > 2.14.3 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
RE: [PATCH v6 1/3] btrfs: Add unprivileged ioctl which returns subvolume information
path->slots[0] >= > + btrfs_header_nritems(path->nodes[0])) { > + ret = btrfs_next_leaf(root, path); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = -EUCLEAN; > + goto out; > + } > + } > + > + l = path->nodes[0]; > + slot = path->slots[0]; > + btrfs_item_key_to_cpu(l, , slot); > + if (key.objectid == subvol_info->id && > + key.type == BTRFS_ROOT_BACKREF_KEY) { > + subvol_info->parent_id = key.offset; > + > + rref = btrfs_item_ptr(l, slot, struct btrfs_root_ref); > + subvol_info->dirid = btrfs_root_ref_dirid(l, rref); > + > + item_off = btrfs_item_ptr_offset(l, slot) > + + sizeof(struct btrfs_root_ref); > + item_len = btrfs_item_size_nr(l, slot) > + - sizeof(struct btrfs_root_ref); > + read_extent_buffer(l, subvol_info->name, > +item_off, item_len); > + } else { > + ret = -ENOENT; > + goto out; > + } > + } > + > + if (copy_to_user(argp, subvol_info, sizeof(*subvol_info))) > + ret = -EFAULT; > + > +out: > + kzfree(subvol_info); > + btrfs_free_path(path); > + return ret; > +} > + > static noinline int btrfs_ioctl_snap_destroy(struct file *file, >void __user *arg) > { > @@ -5374,6 +5497,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_get_features(file, argp); > case BTRFS_IOC_SET_FEATURES: > return btrfs_ioctl_set_features(file, argp); > + case BTRFS_IOC_GET_SUBVOL_INFO: > + return btrfs_ioctl_get_subvol_info(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > c8d99b9ca550..02cd1f1994e8 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -725,6 +725,55 @@ struct btrfs_ioctl_send_args { > __u64 reserved[4]; /* in */ > }; > > +struct btrfs_ioctl_get_subvol_info_args { > + /* All field is out */ > + /* Id of this subvolume */ > + __u64 id; > + /* Name of this subvolume, used to get the real name at mount point */ > + char name[BTRFS_VOL_NAME_MAX + 1]; > + /* > + * Id of the subvolume which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 parent_id; > + /* > + * Inode number of the directory which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 dirid; > + > + /* Latest transaction id of this subvolume */ > + __u64 generation; > + /* Flags of this subvolume */ > + __u64 flags; > + > + /* uuid of this subvolume */ > + __u8 uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume of which this subvolume is a snapshot. > + * All zero for non-snapshot subvolume > + */ > + __u8 parent_uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume from which this subvolume is received. > + * All zero for non-received subvolume > + */ > + __u8 received_uuid[BTRFS_UUID_SIZE]; > + > + /* Transaction id indicates when change/create/send/receive happens */ > + __u64 ctransid; > + __u64 otransid; > + __u64 stransid; > + __u64 rtransid; > + /* Time corresponds to c/o/s/rtransid */ > + struct btrfs_ioctl_timespec ctime; > + struct btrfs_ioctl_timespec otime; > + struct btrfs_ioctl_timespec stime; > + struct btrfs_ioctl_timespec rtime; > + > + __u64 reserved[8]; > +}; > + > /* Error codes as returned by the kernel */ enum btrfs_err_code { > BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, @@ -843,5 +892,7 @@ enum > btrfs_err_code { > struct btrfs_ioctl_vol_args_v2) > #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \ > struct btrfs_ioctl_logical_ino_args) > +#define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \ > + struct btrfs_ioctl_get_subvol_info_args) > > #endif /* _UAPI_LINUX_BTRFS_H */ > -- Looks good to me. Reviewed-by: Gu Jinxiang <g...@cn.fujitsu.com> > 2.14.3 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
RE: [PATCH v5 2/3] btrfs: Add unprivileged ioctl which returns subvolume's ROOT_REF
Hi, > -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Tomohiro Misono > Sent: Wednesday, May 16, 2018 1:50 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH v5 2/3] btrfs: Add unprivileged ioctl which returns > subvolume's ROOT_REF > > Add unprivileged ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF which returns ROOT_REF > information of the subvolume containing this inode > except the subvolume name (this is because to prevent potential name leak). > The subvolume name will be gained by user version of > ino_lookup ioctl (BTRFS_IOC_INO_LOOKUP_USER) which also performs permission > check. > > The min id of root ref's subvolume to be searched is specified by @min_id in > struct btrfs_ioctl_get_subvol_rootref_args. After the search > ends, @min_id is set to the last searched root ref's subvolid + 1. Also, if > there are more root refs than > BTRFS_MAX_ROOTREF_BUFFER_NUM, -EOVERFLOW is returned. Therefore the caller > can just call this ioctl again without changing the > argument to continue search. > > Signed-off-by: Tomohiro Misono> --- > v4 -> v5 > - Update error handling of btrfs_next_leaf() to cover all cases > - Use btrfs_next_item() to reduce the call of btrfs_search_slot() > > fs/btrfs/ioctl.c | 102 > + > include/uapi/linux/btrfs.h | 16 +++ > 2 files changed, 118 insertions(+) > > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index > c1c9ae9a937d..db5de77540e1 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -2386,6 +2386,106 @@ static noinline int > btrfs_ioctl_get_subvol_info(struct file *file, > return ret; > } > > +/* > + * Return ROOT_REF information of the subvolume containing this inode > + * except the subvolume name. > + */ > +static noinline int btrfs_ioctl_get_subvol_rootref(struct file *file, > +void __user *argp) > +{ > + struct btrfs_ioctl_get_subvol_rootref_args *rootrefs; > + struct btrfs_root_ref *rref; > + struct btrfs_root *root; > + struct btrfs_path *path; > + struct btrfs_key key; > + > + struct extent_buffer *l; > + int slot; > + > + struct inode *inode; > + int ret; > + u64 objectid; > + u8 found; > + > + path = btrfs_alloc_path(); > + if (!path) > + return -ENOMEM; > + > + rootrefs = memdup_user(argp, sizeof(*rootrefs)); > + if (!rootrefs) { > + btrfs_free_path(path); > + return -ENOMEM; > + } > + > + inode = file_inode(file); > + root = BTRFS_I(inode)->root->fs_info->tree_root; > + objectid = BTRFS_I(inode)->root->root_key.objectid; > + > + key.objectid = objectid; > + key.type = BTRFS_ROOT_REF_KEY; > + key.offset = rootrefs->min_id; > + found = 0; > + > + ret = btrfs_search_slot(NULL, root, , path, 0, 0); > + if (ret < 0) { > + goto out; > + } else if (path->slots[0] >= > + btrfs_header_nritems(path->nodes[0])) { > + ret = btrfs_next_leaf(root, path); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = -ENOENT; > + goto out; > + } > + } > + while (1) { > + l = path->nodes[0]; > + slot = path->slots[0]; > + > + btrfs_item_key_to_cpu(l, , slot); > + if (key.objectid != objectid || > + key.type != BTRFS_ROOT_REF_KEY) { > + ret = 0; > + goto out; > + } > + > + if (found == BTRFS_MAX_ROOTREF_BUFFER_NUM) { > + ret = -EOVERFLOW; > + goto out; > + } > + > + rref = btrfs_item_ptr(l, slot, struct btrfs_root_ref); > + rootrefs->rootref[found].subvolid = key.offset; > + rootrefs->rootref[found].dirid = > + btrfs_root_ref_dirid(l, rref); > + found++; > + > + ret = btrfs_next_item(root, path); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = -ENOENT; Should return -EUCLEAN in this scenario. > + goto out; > + } > + } > + > +out: > + if (!ret || ret == -EOVERFLOW) { > + rootrefs->num_items = found; > + /* update min_id for next search */ > + if (found) > + rootrefs->min_id = > + rootrefs->rootref[found - 1].subvolid + 1; > + if (copy_to_user(argp, rootrefs, sizeof(*rootrefs))) > + ret = -EFAULT; > + } > + > + btrfs_free_path(path); > + kfree(rootrefs); > + return ret; > +} > + > static noinline int
RE: [PATCH v5 1/3] btrfs: Add unprivileged ioctl which returns subvolume information
stime); > + subvol_info->stime.nsec = btrfs_stack_timespec_nsec(_item.stime); > + > + subvol_info->rtransid = btrfs_root_rtransid(_item); > + subvol_info->rtime.sec = btrfs_stack_timespec_sec(_item.rtime); > + subvol_info->rtime.nsec = btrfs_stack_timespec_nsec(_item.rtime); > + > + btrfs_release_path(path); > + if (key.objectid != BTRFS_FS_TREE_OBJECTID) { > + key.type = BTRFS_ROOT_BACKREF_KEY; > + key.offset = 0; > + ret = btrfs_search_slot(NULL, root, , path, 0, 0); > + if (ret < 0) { > + goto out; > + } else if (path->slots[0] >= > + btrfs_header_nritems(path->nodes[0])) { > + ret = btrfs_next_leaf(root, path); > + if (ret < 0) { > + goto out; > + } else if (ret > 0) { > + ret = -ENOENT; > + goto out; > + } > + } > + > + l = path->nodes[0]; > + slot = path->slots[0]; > + btrfs_item_key_to_cpu(l, , slot); > + if (key.objectid == subvol_info->id && > + key.type == BTRFS_ROOT_BACKREF_KEY) { > + subvol_info->parent_id = key.offset; > + > + rref = btrfs_item_ptr(l, slot, struct btrfs_root_ref); > + subvol_info->dirid = btrfs_root_ref_dirid(l, rref); > + > + item_off = btrfs_item_ptr_offset(l, slot) > + + sizeof(struct btrfs_root_ref); > + item_len = btrfs_item_size_nr(l, slot) > + - sizeof(struct btrfs_root_ref); > + read_extent_buffer(l, subvol_info->name, > +item_off, item_len); > + } else { > + ret = -ENOENT; > + goto out; > + } > + } > + > + if (copy_to_user(argp, subvol_info, sizeof(*subvol_info))) > + ret = -EFAULT; > + > +out: > + kzfree(subvol_info); > + btrfs_free_path(path); > + return ret; > +} > + > static noinline int btrfs_ioctl_snap_destroy(struct file *file, >void __user *arg) > { > @@ -5374,6 +5518,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_get_features(file, argp); > case BTRFS_IOC_SET_FEATURES: > return btrfs_ioctl_set_features(file, argp); > + case BTRFS_IOC_GET_SUBVOL_INFO: > + return btrfs_ioctl_get_subvol_info(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > c8d99b9ca550..02cd1f1994e8 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -725,6 +725,55 @@ struct btrfs_ioctl_send_args { > __u64 reserved[4]; /* in */ > }; > > +struct btrfs_ioctl_get_subvol_info_args { > + /* All field is out */ > + /* Id of this subvolume */ > + __u64 id; > + /* Name of this subvolume, used to get the real name at mount point */ > + char name[BTRFS_VOL_NAME_MAX + 1]; > + /* > + * Id of the subvolume which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 parent_id; > + /* > + * Inode number of the directory which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 dirid; > + > + /* Latest transaction id of this subvolume */ > + __u64 generation; > + /* Flags of this subvolume */ > + __u64 flags; > + > + /* uuid of this subvolume */ > + __u8 uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume of which this subvolume is a snapshot. > + * All zero for non-snapshot subvolume > + */ > + __u8 parent_uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume from which this subvolume is received. > + * All zero for non-received subvolume > + */ > + __u8 received_uuid[BTRFS_UUID_SIZE]; > + > + /* Transaction id indicates when change/create/send/receive happens */ > + __u64 ctransid; > + __u64 otransid; > + __u64 stransid; > + __u64 rtransid; > + /* Time corresponds to c/o/s/rtransid */ > + struct btrfs_ioctl_timespec ctime; > + struct btrfs_ioctl_timespec otime; > + struct btrfs_ioctl_timespec stime; > +
RE: [PATCH v4 3/3] btrfs: Add unprivileged version of ino_lookup ioctl
if (IS_ERR(args)) > + return PTR_ERR(args); > + > + inode = file_inode(file); > + > + if (args->dirid == BTRFS_FIRST_FREE_OBJECTID && > + BTRFS_I(inode)->location.objectid != BTRFS_FIRST_FREE_OBJECTID) { > + /* The subvolume does not exist under fd with which this is called */ > + kfree(args); > + return -EACCES; > + } > + > + ret = btrfs_search_path_in_tree_user(inode, args); > + > + if (ret == 0 && copy_to_user(argp, args, sizeof(*args))) > + ret = -EFAULT; > + > + kfree(args); > + return ret; > +} > + > /* Get the subvolume information in BTRFS_ROOT_ITEM and BTRFS_ROOT_BACKREF > */ static noinline int > btrfs_ioctl_get_subvol_info(struct file *file, > void __user *argp) > @@ -5605,6 +5807,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_get_subvol_info(file, argp); > case BTRFS_IOC_GET_SUBVOL_ROOTREF: > return btrfs_ioctl_get_subvol_rootref(file, argp); > + case BTRFS_IOC_INO_LOOKUP_USER: > + return btrfs_ioctl_ino_lookup_user(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > 82c88d52d6e6..5f91de93dd5a 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -422,6 +422,21 @@ struct btrfs_ioctl_ino_lookup_args { > char name[BTRFS_INO_LOOKUP_PATH_MAX]; > }; > > +#define BTRFS_INO_LOOKUP_USER_PATH_MAX (4080-BTRFS_VOL_NAME_MAX-1) > +struct btrfs_ioctl_ino_lookup_user_args { > + /* in, inode number containing the subvolume of 'subvolid' */ > + __u64 dirid; > + /* in */ > + __u64 subvolid; > + /* out, name of the subvolume of 'subvolid' */ > + char name[BTRFS_VOL_NAME_MAX + 1]; > + /* > + * out, constructed path from the directory with which > + * the ioctl is called to dirid > + */ > + char path[BTRFS_INO_LOOKUP_USER_PATH_MAX]; > +}; > + > /* Search criteria for the btrfs SEARCH ioctl family. */ struct > btrfs_ioctl_search_key { > /* > @@ -910,5 +925,7 @@ enum btrfs_err_code { > struct btrfs_ioctl_get_subvol_info_args) > #define BTRFS_IOC_GET_SUBVOL_ROOTREF > _IOWR(BTRFS_IOCTL_MAGIC, 61, \ > struct btrfs_ioctl_get_subvol_rootref_args) > +#define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \ > + struct btrfs_ioctl_ino_lookup_user_args) > > #endif /* _UAPI_LINUX_BTRFS_H */ > -- Seems good to me. Reviewed-by: Gu Jinxiang <g...@cn.fujitsu.com> > 2.14.3 > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
[PATCH] btrfs-progs: remove BTRFS_LIST_LAYOUT_RAW
Since commit 9005b603d723 ("btrfs-progs: use libbtrfsutil for subvol show"), BTRFS_LIST_LAYOUT_RAW has no usage. So, remove it. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- btrfs-list.c | 20 btrfs-list.h | 3 +-- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index e01c5899..16be6b2f 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1374,23 +1374,6 @@ static void print_subvolume_column(struct root_info *subv, } } -static void print_one_subvol_info_raw(struct root_info *subv, - const char *raw_prefix) -{ - int i; - - for (i = 0; i < BTRFS_LIST_ALL; i++) { - if (!btrfs_list_columns[i].need_print) - continue; - - if (raw_prefix) - printf("%s",raw_prefix); - - print_subvolume_column(subv, i); - } - printf("\n"); -} - static void print_one_subvol_info_table(struct root_info *subv) { int i; @@ -1480,9 +1463,6 @@ static void print_all_subvol_info(struct root_lookup *sorted_tree, case BTRFS_LIST_LAYOUT_TABLE: print_one_subvol_info_table(entry); break; - case BTRFS_LIST_LAYOUT_RAW: - print_one_subvol_info_raw(entry, raw_prefix); - break; } next: n = rb_next(n); diff --git a/btrfs-list.h b/btrfs-list.h index 6e5fc778..299e3122 100644 --- a/btrfs-list.h +++ b/btrfs-list.h @@ -33,8 +33,7 @@ enum btrfs_list_layout { BTRFS_LIST_LAYOUT_DEFAULT = 0, - BTRFS_LIST_LAYOUT_TABLE, - BTRFS_LIST_LAYOUT_RAW + BTRFS_LIST_LAYOUT_TABLE }; /* -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v4 1/3] btrfs: Add unprivileged ioctl which returns subvolume information
Hi, add a missed a comment. > -Original Message- > From: Misono Tomohiro [mailto:misono.tomoh...@jp.fujitsu.com] > Sent: Tuesday, May 15, 2018 3:04 PM > To: Gu, Jinxiang/顾 金香 <g...@cn.fujitsu.com>; linux-btrfs@vger.kernel.org > Subject: Re: [PATCH v4 1/3] btrfs: Add unprivileged ioctl which returns > subvolume information > > On 2018/05/15 15:31, Gu, Jinxiang/顾 金香 wrote: > > Hi, > > > >> -Original Message- > >> From: linux-btrfs-ow...@vger.kernel.org > >> [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Tomohiro > >> Misono > >> Sent: Friday, May 11, 2018 3:26 PM > >> To: linux-btrfs@vger.kernel.org > >> Subject: [PATCH v4 1/3] btrfs: Add unprivileged ioctl which returns > >> subvolume information > >> > >> Add new unprivileged ioctl BTRFS_IOC_GET_SUBVOL_INFO which returns the > >> information of subvolume containing this inode. > >> (i.e. returns the information in ROOT_ITEM and ROOT_BACKREF.) > >> > >> Signed-off-by: Tomohiro Misono <misono.tomoh...@jp.fujitsu.com> > >> --- > >> fs/btrfs/ioctl.c | 129 > >> + > >> include/uapi/linux/btrfs.h | 51 ++ > >> 2 files changed, 180 insertions(+) > >> > >> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index > >> 48e2ddff32bd..64b23e22852f 100644 > >> --- a/fs/btrfs/ioctl.c > >> +++ b/fs/btrfs/ioctl.c > >> @@ -2242,6 +2242,133 @@ static noinline int btrfs_ioctl_ino_lookup(struct > >> file *file, > >>return ret; > >> } > >> > >> +/* Get the subvolume information in BTRFS_ROOT_ITEM and > >> +BTRFS_ROOT_BACKREF */ static noinline int > >> btrfs_ioctl_get_subvol_info(struct file *file, > >> + void __user *argp) > >> +{ > >> + struct btrfs_ioctl_get_subvol_info_args *subvol_info; > >> + struct btrfs_root *root; > >> + struct btrfs_path *path; > >> + struct btrfs_key key; > >> + > >> + struct btrfs_root_item root_item; > >> + struct btrfs_root_ref *rref; > >> + struct extent_buffer *l; > >> + int slot; > >> + > >> + unsigned long item_off; > >> + unsigned long item_len; > >> + > >> + struct inode *inode; > >> + int ret; > >> + > >> + path = btrfs_alloc_path(); > >> + if (!path) > >> + return -ENOMEM; > >> + > >> + subvol_info = kzalloc(sizeof(*subvol_info), GFP_KERNEL); > >> + if (!subvol_info) { > >> + btrfs_free_path(path); > >> + return -ENOMEM; > >> + } > >> + inode = file_inode(file); > >> + > >> + root = BTRFS_I(inode)->root->fs_info->tree_root; > >> + key.objectid = BTRFS_I(inode)->root->root_key.objectid; > >> + key.type = BTRFS_ROOT_ITEM_KEY; > >> + key.offset = 0; > >> + ret = btrfs_search_slot(NULL, root, , path, 0, 0); > >> + if (ret < 0) { > >> + goto out; > >> + } else if (ret > 0) { > >> + u64 objectid = key.objectid; > >> + > >> + if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { > >> + ret = btrfs_next_leaf(root, path); > >> + if (ret < 0) > >> + return ret; > > Should goto out; to free subvol_info and path. > Thanks, will update both. > Since btrfs_next_leaf may return 1 when nritems of next leaf is 0, So, btrfs_item_key_to_cpu(path->nodes[0], , path->slots[0]); may goes wrong. And I think it should add a judge before btrfs_item_key_to_cpu. > >> + } > >> + > >> + /* If the subvolume is a snapshot, offset is not zero */ > >> + btrfs_item_key_to_cpu(path->nodes[0], , path->slots[0]); > >> + if (key.objectid != objectid || > >> + key.type != BTRFS_ROOT_ITEM_KEY) { > >> + ret = -ENOENT; > >> + goto out; > >> + } > >> + } > >> + > >> + l = path->nodes[0]; > >> + slot = path->slots[0]; > >> + item_off = btrfs_item_ptr_offset(l, slot); > >> + item_len = btrfs_item_size_nr(l, slot); > >> + read_extent_buffer(l, _item, item_off, item_len); > >> + > >> + subvol_info->id = key.objectid; > >> + > >> + subvol_info-
RE: [PATCH v4 2/3] btrfs: Add unprivileged ioctl which returns subvolume's ROOT_REF
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Tomohiro Misono > Sent: Friday, May 11, 2018 3:26 PM > To: linux-btrfs@vger.kernel.org > Subject: [PATCH v4 2/3] btrfs: Add unprivileged ioctl which returns > subvolume's ROOT_REF > > Add unprivileged ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF which returns ROOT_REF > information of the subvolume containing this inode > except the subvolume name (this is because to prevent potential name leak). > The subvolume name will be gained by user version of > ino_lookup ioctl (BTRFS_IOC_INO_LOOKUP_USER) which also performs permission > check. > > The min id of root ref's subvolume to be searched is specified by @min_id in > struct btrfs_ioctl_get_subvol_rootref_args. After the search > ends, @min_id is set to the last searched root ref's subvolid + 1. Also, if > there are more root refs than > BTRFS_MAX_ROOTREF_BUFFER_NUM, -EOVERFLOW is returned. Therefore the caller > can just call this ioctl again without changing the > argument to continue search. > > Signed-off-by: Tomohiro Misono> --- > fs/btrfs/ioctl.c | 102 > + > include/uapi/linux/btrfs.h | 16 +++ > 2 files changed, 118 insertions(+) > > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index > 64b23e22852f..7988d328aed5 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -2369,6 +2369,106 @@ static noinline int > btrfs_ioctl_get_subvol_info(struct file *file, > return ret; > } > > +/* > + * Return ROOT_REF information of the subvolume contining this inode s/contining/containing > + * except the subvolume name. > + */ > +static noinline int btrfs_ioctl_get_subvol_rootref(struct file *file, > +void __user *argp) > +{ > + struct btrfs_ioctl_get_subvol_rootref_args *rootrefs; > + struct btrfs_root_ref *rref; > + struct btrfs_root *root; > + struct btrfs_path *path; > + struct btrfs_key key; > + > + struct extent_buffer *l; > + int slot; > + > + struct inode *inode; > + int i, nritems; > + int ret; > + u64 objectid; > + u8 found; > + > + path = btrfs_alloc_path(); > + if (!path) > + return -ENOMEM; > + > + rootrefs = memdup_user(argp, sizeof(*rootrefs)); > + if (!rootrefs) { > + btrfs_free_path(path); > + return -ENOMEM; > + } > + > + inode = file_inode(file); > + root = BTRFS_I(inode)->root->fs_info->tree_root; > + objectid = BTRFS_I(inode)->root->root_key.objectid; > + > + key.objectid = objectid; > + key.type = BTRFS_ROOT_REF_KEY; > + key.offset = rootrefs->min_id; > + found = 0; > + while (1) { > + ret = btrfs_search_slot(NULL, root, , path, 0, 0); > + if (ret < 0) { > + goto out; > + } else if (path->slots[0] >= > + btrfs_header_nritems(path->nodes[0])) { > + ret = btrfs_next_leaf(root, path); > + if (ret < 0) > + return ret; Should goto out; to do free work. > + } > + > + l = path->nodes[0]; > + slot = path->slots[0]; > + nritems = btrfs_header_nritems(l); > + if (nritems - slot == 0) { > + ret = 0; > + goto out; > + } > + > + for (i = slot; i < nritems; i++) { > + btrfs_item_key_to_cpu(l, , i); > + if (key.objectid != objectid || > + key.type != BTRFS_ROOT_REF_KEY) { > + ret = 0; > + goto out; > + } > + > + if (found == BTRFS_MAX_ROOTREF_BUFFER_NUM) { > + ret = -EOVERFLOW; > + goto out; > + } > + > + rref = btrfs_item_ptr(l, i, struct btrfs_root_ref); > + rootrefs->rootref[found].subvolid = key.offset; > + rootrefs->rootref[found].dirid = > + btrfs_root_ref_dirid(l, rref); > + found++; > + } > + > + btrfs_release_path(path); > + key.offset++; > + } Suggest to use btrfs_search_slot and btrfs_next_item to reduce counts of btrfs_search_slot. > + > +out: > + if (!ret || ret == -EOVERFLOW) { > + rootrefs->num_items = found; > + /* update min_id for next search */ > + if (found) > + rootrefs->min_id = > + rootrefs->rootref[found - 1].subvolid + 1; > + if (copy_to_user(argp, rootrefs, sizeof(*rootrefs))) > + ret = -EFAULT; > + } > + > +
RE: [PATCH v4 1/3] btrfs: Add unprivileged ioctl which returns subvolume information
me); > + > + btrfs_release_path(path); > + key.type = BTRFS_ROOT_BACKREF_KEY; > + key.offset = 0; > + ret = btrfs_search_slot(NULL, root, , path, 0, 0); > + if (ret < 0) { > + goto out; > + } else if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { > + ret = btrfs_next_leaf(root, path); > + if (ret < 0) > + return ret; Should goto out; to free subvol_info and path. > + } > + > + l = path->nodes[0]; > + slot = path->slots[0]; > + btrfs_item_key_to_cpu(l, , slot); > + if (key.objectid == subvol_info->id && > + key.type == BTRFS_ROOT_BACKREF_KEY){ > + subvol_info->parent_id = key.offset; > + > + rref = btrfs_item_ptr(l, slot, struct btrfs_root_ref); > + subvol_info->dirid = btrfs_root_ref_dirid(l, rref); > + > + item_off = btrfs_item_ptr_offset(l, slot) > + + sizeof(struct btrfs_root_ref); > + item_len = btrfs_item_size_nr(l, slot) > + - sizeof(struct btrfs_root_ref); > + read_extent_buffer(l, subvol_info->name, item_off, item_len); > + } If this if is not correct(ex. corrupt filesystem without backref), should it return -ENOENT, or its be ok without parent_id, dirid and name. Suggest to add logic of else. > + > + if (copy_to_user(argp, subvol_info, sizeof(*subvol_info))) > + ret = -EFAULT; > + > +out: > + kzfree(subvol_info); > + btrfs_free_path(path); > + return ret; > +} > + > static noinline int btrfs_ioctl_snap_destroy(struct file *file, >void __user *arg) > { > @@ -5374,6 +5501,8 @@ long btrfs_ioctl(struct file *file, unsigned int > return btrfs_ioctl_get_features(file, argp); > case BTRFS_IOC_SET_FEATURES: > return btrfs_ioctl_set_features(file, argp); > + case BTRFS_IOC_GET_SUBVOL_INFO: > + return btrfs_ioctl_get_subvol_info(file, argp); > } > > return -ENOTTY; > diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index > c8d99b9ca550..ed053852c71f 100644 > --- a/include/uapi/linux/btrfs.h > +++ b/include/uapi/linux/btrfs.h > @@ -725,6 +725,55 @@ struct btrfs_ioctl_send_args { > __u64 reserved[4]; /* in */ > }; > > +struct btrfs_ioctl_get_subvol_info_args { > + /* All filed is out */ > + /* Id of this subvolume */ > + __u64 id; > + /* Name of this subvolume, used to get the real name at mount point */ > + char name[BTRFS_VOL_NAME_MAX + 1]; > + /* > + * Id of the subvolume which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 parent_id; > + /* > + * Inode number of the directory which contains this subvolume. > + * Zero for top-level subvolume or deleted subvolume > + */ > + __u64 dirid; > + > + /* Latest transaction id of this subvolume */ > + __u64 generation; > + /* Flags of this subvolume */ > + __u64 flags; > + > + /* uuid of this subvolume */ > + __u8 uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume of which this subvolume is a snapshot. > + * All zero for non-snapshot subvolume > + */ > + __u8 parent_uuid[BTRFS_UUID_SIZE]; > + /* > + * uuid of the subvolume from which this subvolume is received. > + * All zero for non-received subvolume > + */ > + __u8 received_uuid[BTRFS_UUID_SIZE]; > + > + /* Transaction id indicates when change/create/send/receive happens */ > + __u64 ctransid; > + __u64 otransid; > + __u64 stransid; > + __u64 rtransid; > + /* Time corresponds to c/o/s/rtransid */ > + struct btrfs_ioctl_timespec ctime; > + struct btrfs_ioctl_timespec otime; > + struct btrfs_ioctl_timespec stime; > + struct btrfs_ioctl_timespec rtime; > + > + __u64 reserved[8]; > +}; > + > /* Error codes as returned by the kernel */ enum btrfs_err_code { > BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, @@ -843,5 +892,7 @@ enum > btrfs_err_code { > struct btrfs_ioctl_vol_args_v2) > #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \ > struct btrfs_ioctl_logical_ino_args) > +#define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \ > + struct btrfs_ioctl_get_subvol_info_args) > > #endif /* _UAPI_LINUX_BTRFS_H */ > -- > 2.14.3 > Reviewed-by: Gu Jinxiang <g...@cn.fujitsu.com> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
[PATCH] btrfs: modify path->reada in btrfs_shrink_device to READA_BACK
In btrfs_shrink_device, before btrfs_search_slot, path->reada is set to READA_FORWARD. But I think READA_BACK is correct. Since, 1.key.offset is set to (u64)-1 2.After btrfs_search_slot, btrfs_previous_item is called. So, for readahead previous items, READA_BACK is correct one. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- fs/btrfs/volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 292266f6ab9c..1a3506a3003d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4473,7 +4473,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) if (!path) return -ENOMEM; - path->reada = READA_FORWARD; + path->reada = READA_BACK; mutex_lock(_info->chunk_mutex); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs: remove unused fs_info parameter
Since the commit below parameter fs_info in alloc_reloc_control be no used. So remove it. commit c6100a4b4e3d ("Btrfs: replace tree->mapping with tree->private_data") Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- fs/btrfs/relocation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 00b7d3231821..d7b7b86f4931 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4299,7 +4299,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info, return inode; } -static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info) +static struct reloc_control *alloc_reloc_control(void) { struct reloc_control *rc; @@ -4366,7 +4366,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) int rw = 0; int err = 0; - rc = alloc_reloc_control(fs_info); + rc = alloc_reloc_control(); if (!rc) return -ENOMEM; @@ -4562,7 +4562,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) if (list_empty(_roots)) goto out; - rc = alloc_reloc_control(fs_info); + rc = alloc_reloc_control(); if (!rc) { err = -ENOMEM; goto out; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: btrfs check : check/main.c:3654: check_owner_ref: BUG_ON `rec->is_root` triggered, value `
Hi Thanks for reporting. May be the same bug reproduced by using $sudo TEST=003\* make test-fuzz in btrfs-progs. More details in: https://patchwork.kernel.org/patch/10073937/ > -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Patrick Mitchell > Sent: Monday, April 23, 2018 12:17 PM > To: linux-btrfs@vger.kernel.org > Subject: btrfs check : check/main.c:3654: check_owner_ref: BUG_ON > `rec->is_root` triggered, value ` > > Arch, kernel 4.15.14, btrfs progs 4.15.1. > > Had some SATA drives dropout. Have a few btrfs volumes with parent transid > verify failed errors, that all mount. > > This volume has nothing I care about, so I'm just reporting it since it looks > like a bug. None of my other volumes having issues cause core > dumps. Happy to send whatever other info might help track it down. > > > # btrfs check /dev/lvm/snapper1 > Checking filesystem on /dev/lvm/snapper1 > UUID: ef6f4923-0a03-4e41-9655-e24a13a1d879 > parent transid verify failed on 862240768 wanted 29524 found 29182 parent > transid verify failed on 862240768 wanted 29524 found 29182 > checking extents > check/main.c:3654: check_owner_ref: BUG_ON `rec->is_root` triggered, value 1 > btrfs(+0x5f98c)[0x55ec9db9198c] > btrfs(+0x12ad6)[0x55ec9db44ad6] btrfs(+0x18c7f)[0x55ec9db4ac7f] > btrfs(+0x199c6)[0x55ec9db4b9c6] btrfs(+0x19fc0)[0x55ec9db4bfc0] > btrfs(cmd_check+0xf63)[0x55ec9db94423] > btrfs(main+0x81)[0x55ec9db4e441] > /usr/lib/libc.so.6(__libc_start_main+0xea)[0x7f6923f2ff4a] > btrfs(_start+0x2a)[0x55ec9db4e55a] > [1]9612 abort (core dumped) btrfs check /dev/lvm/snapper1 > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the > body of a message to majord...@vger.kernel.org More > majordomo info at http://vger.kernel.org/majordomo-info.html > N�r��yb�X��ǧv�^�){.n�+{�n�߲)w*jg����ݢj/���z�ޖ��2�ޙ&�)ߡ�a�����G���h��j:+v���w��٥
[bug report] btrfs fail when run xfstests-dev/btrfs/007
Hi, Here's a bug report. Kernel v4.17-rc1 failed xfstests-dev/btrfs/007. It is not always happens.( occurred times/test times: 1/20) And I confirmed this test using kernel v4.16-rc1. It also occurred sometimes. LOG when using kernel v4.17-rc1. btrfs/007[failed, exit status 1] - output mismatch (see /home/gujx/xfstests-dev/results//btrfs/007.out.bad) --- tests/btrfs/007.out 2017-08-18 12:45:06.560413266 +0800 +++ /home/gujx/xfstests-dev/results//btrfs/007.out.bad 2018-04-17 13:24:06.887089998 +0800 @@ -1,4 +1,5 @@ QA output created by 007 *** test send / receive -*** done +failed: '/home/gujx/xfstests-dev/src/fssum -r /tmp/tmp.SkEUIXw683/incr.fssum /mnt/scratch/incr' +(see /home/gujx/xfstests-dev/results//btrfs/007.full for details) *** unmount ... (Run 'diff -u tests/btrfs/007.out /home/gujx/xfstests-dev/results//btrfs/007.out.bad' to see the entire diff) And the detail can be found in the attachment. Thanks, Gu Jinxiang 007.full Description: 007.full
RE: [PATCH RESEND v4 0/4] device_list_add() peparation to add reappearing missing device
Hi, I reproduced this using kernel v4.17-rc1. It is not always happens.( occurred times/test times: 1/20) > -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of Anand Jain > Sent: Tuesday, January 23, 2018 5:53 AM > To: dste...@suse.cz; linux-btrfs@vger.kernel.org > Subject: Re: [PATCH RESEND v4 0/4] device_list_add() peparation to add > reappearing missing device > > > > On 01/22/2018 11:26 PM, David Sterba wrote: > > On Mon, Jan 22, 2018 at 09:31:47PM +0800, Anand Jain wrote: > >>Problem was mainly due to the patch 3/4, which tried to access the > >>return pointer even for the failed condition. The fix is to bring the > >>device point access under the else part as show below [2]. I have > >>included this fix in V5. Which is tested with btrfs xfstests. > >>Pls could you consider v5 for 4.16 ? > > > > Hm ok, thre's still some time to test it. One more fstests report that > > appeared before and also with the v5: > > I will try to nail it down. It passes on bare metal and a VM here. > btrfs-progs: I am using your latest master at > (git://github.com/kdave/btrfs-progs.git). > > > > btrfs/007 4s ...[16:38:09] [16:38:12] [failed, exit status 1] - > > output mismatch (see > /root/test/mmtests/work/sources/xfstests-git-installed/results//btrfs/007.out.bad) > > --- tests/btrfs/007.out 2017-09-20 14:24:58.334716658 +0200 > > +++ > > /root/test/mmtests/work/sources/xfstests-git-installed/results//btrfs/007.out.bad > >2018-01-22 16:38:12.883931593 > +0100 > > @@ -1,4 +1,5 @@ > > QA output created by 007 > > *** test send / receive > > -*** done > > +failed: > > '/root/test/mmtests/work/sources/xfstests-git-installed/src/fssum -r > > /tmp/tmp.eZcr17wqNn/incr.fssum > /root/test/mmtests/scratch_mnt/incr' > > Looks like fssum on the reverse copied file failed. > > > +(see > > /root/test/mmtests/work/sources/xfstests-git-installed/results//btrfs/ > > 007.full for details) > > Can you pls send me this ? Please see the attachment. And I confirmed btrfs/007 using kernel v4.16-rc1. It also occurred sometimes > > Thanks, Anand > > > *** unmount > > ... > > (Run 'diff -u tests/btrfs/007.out > > /root/test/mmtests/work/sources/xfstests-git-installed/results//btrfs/ > > 007.out.bad' to see the entire diff) > > -- > > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" > > in the body of a message to majord...@vger.kernel.org More majordomo > > info at http://vger.kernel.org/majordomo-info.html > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the > body of a message to majord...@vger.kernel.org More > majordomo info at http://vger.kernel.org/majordomo-info.html > 007.full Description: 007.full
[PATCH v2] btrfs-progs: remove meaningless process
Variable do_wait is synchronized with the variable do_background, when if(do_background) is true, if(!do_wait) is also true, so parent process will goto out immediately. The following wait never be run. And if option -B is chosen, when do_background is 0 and do_wait is 1, there is no need to fork a child process to wait for scrub over. So remove unnecessary process. Since parent process go out immediately, so remove SIGINT process of parent process too. Changelog: v2: remove the SIGINT process of parent process. v1: remove do_wait variable and wait process Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- cmds-scrub.c | 30 -- 1 file changed, 30 deletions(-) diff --git a/cmds-scrub.c b/cmds-scrub.c index efd7db94..c5f908f4 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -312,16 +312,6 @@ static void scrub_sigint_record_progress(int signal) perror("Scrub cancel failed"); } -static int scrub_handle_sigint_parent(void) -{ - struct sigaction sa = { - .sa_handler = SIG_IGN, - .sa_flags = SA_RESTART, - }; - - return sigaction(SIGINT, , NULL); -} - static int scrub_handle_sigint_child(int fd) { struct sigaction sa = { @@ -1109,7 +1099,6 @@ static int scrub_start(int argc, char **argv, int resume) int print_raw = 0; char *path; int do_background = 1; - int do_wait = 0; int do_print = 0; int do_quiet = 0; int do_record = 1; @@ -1147,7 +1136,6 @@ static int scrub_start(int argc, char **argv, int resume) switch (c) { case 'B': do_background = 0; - do_wait = 1; do_print = 1; break; case 'd': @@ -1374,28 +1362,10 @@ static int scrub_start(int argc, char **argv, int resume) } if (pid) { - int stat; - scrub_handle_sigint_parent(); if (!do_quiet) printf("scrub %s on %s, fsid %s (pid=%d)\n", n_start ? "started" : "resumed", path, fsid, pid); - if (!do_wait) { - err = 0; - goto out; - } - ret = wait(); - if (ret != pid) { - error_on(!do_quiet, "wait failed (ret=%d): %m", - ret); - err = 1; - goto out; - } - if (!WIFEXITED(stat) || WEXITSTATUS(stat)) { - error_on(!do_quiet, "scrub process failed"); - err = WIFEXITED(stat) ? WEXITSTATUS(stat) : -1; - goto out; - } err = 0; goto out; } -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: remove meaningless process
Variable do_wait is synchronized with the variable do_background, when if(do_background) is true, if(!do_wait) is also true, so parent process will goto out immediately. The following wait never be run. And if option -B is chosen, when do_background is 0 and do_wait is 1, there is no need to fork a child process to wait for scrub over. So remove unnecessary process. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- cmds-scrub.c | 19 --- 1 file changed, 19 deletions(-) diff --git a/cmds-scrub.c b/cmds-scrub.c index efd7db94..3fb16887 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -1109,7 +1109,6 @@ static int scrub_start(int argc, char **argv, int resume) int print_raw = 0; char *path; int do_background = 1; - int do_wait = 0; int do_print = 0; int do_quiet = 0; int do_record = 1; @@ -1147,7 +1146,6 @@ static int scrub_start(int argc, char **argv, int resume) switch (c) { case 'B': do_background = 0; - do_wait = 1; do_print = 1; break; case 'd': @@ -1374,28 +1372,11 @@ static int scrub_start(int argc, char **argv, int resume) } if (pid) { - int stat; scrub_handle_sigint_parent(); if (!do_quiet) printf("scrub %s on %s, fsid %s (pid=%d)\n", n_start ? "started" : "resumed", path, fsid, pid); - if (!do_wait) { - err = 0; - goto out; - } - ret = wait(); - if (ret != pid) { - error_on(!do_quiet, "wait failed (ret=%d): %m", - ret); - err = 1; - goto out; - } - if (!WIFEXITED(stat) || WEXITSTATUS(stat)) { - error_on(!do_quiet, "scrub process failed"); - err = WIFEXITED(stat) ? WEXITSTATUS(stat) : -1; - goto out; - } err = 0; goto out; } -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: remove meaningless field write of scrub status file
Since ret must be 0 when goes to scrub status file's write, so scrub_write_buf(fd, buf, ret) writes nothing. And when I check the process for read scrub status file, there is no process for this field. So, remove it. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- cmds-scrub.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cmds-scrub.c b/cmds-scrub.c index 8cf1e5df..efd7db94 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -753,7 +753,6 @@ static int scrub_write_file(int fd, const char *fsid, scrub_write_buf(fd, ":", 1) || scrub_writev(fd, buf, sizeof(buf), "%lld", use->scrub_args.devid) || - scrub_write_buf(fd, buf, ret) || _SCRUB_KVWRITE(fd, buf, data_extents_scrubbed, use) || _SCRUB_KVWRITE(fd, buf, tree_extents_scrubbed, use) || _SCRUB_KVWRITE(fd, buf, data_bytes_scrubbed, use) || -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: remove unused function path_cat and path_cat3
Since function path_cat and path_cat3 are not used anymore, remove them. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- send-utils.c | 25 - send-utils.h | 9 - 2 files changed, 34 deletions(-) diff --git a/send-utils.c b/send-utils.c index b5289e76..3ecbdea6 100644 --- a/send-utils.c +++ b/send-utils.c @@ -757,18 +757,6 @@ int path_cat_out(char *out, const char *p1, const char *p2) return 0; } -__attribute__((deprecated)) -char *path_cat(const char *p1, const char *p2) -{ - int p1_len = strlen(p1); - int p2_len = strlen(p2); - char *new = malloc(p1_len + p2_len + 2); - - path_cat_out(new, p1, p2); - - return new; -} - int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3) { int p1_len = strlen(p1); @@ -788,16 +776,3 @@ int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3) return 0; } - -__attribute__((deprecated)) -char *path_cat3(const char *p1, const char *p2, const char *p3) -{ - int p1_len = strlen(p1); - int p2_len = strlen(p2); - int p3_len = strlen(p3); - char *new = malloc(p1_len + p2_len + p3_len + 3); - - path_cat3_out(new, p1, p2, p3); - - return new; -} diff --git a/send-utils.h b/send-utils.h index e8f86912..5f5e096f 100644 --- a/send-utils.h +++ b/send-utils.h @@ -104,15 +104,6 @@ void subvol_uuid_search_add(struct subvol_uuid_search *s, int btrfs_subvolid_resolve(int fd, char *path, size_t path_len, u64 subvol_id); -/* - * DEPRECATED: the functions path_cat and path_cat3 are unsafe and should not - * be used, use the _out variants and always check the return code. - */ -__attribute__((deprecated)) -char *path_cat(const char *p1, const char *p2); -__attribute__((deprecated)) -char *path_cat3(const char *p1, const char *p2, const char *p3); - int path_cat_out(char *out, const char *p1, const char *p2); int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3); -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: mark -f option of btrfs scrub start deprecated
Since in the commit below detect the scrub information automatically, -f option is no more need. Let's make it deprecated. commit d5fd05a773e2 ("btrfs-progs: scrub, detect stale information in the status file") Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- Documentation/btrfs-scrub.asciidoc | 9 ++--- cmds-scrub.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Documentation/btrfs-scrub.asciidoc b/Documentation/btrfs-scrub.asciidoc index d2d20627..89bca18e 100644 --- a/Documentation/btrfs-scrub.asciidoc +++ b/Documentation/btrfs-scrub.asciidoc @@ -75,9 +75,12 @@ set IO priority class (see `ionice`(1) manpage) -n set IO priority classdata (see `ionice`(1) manpage) -f -force starting new scrub even if a scrub is already running, -this can useful when scrub status file is damaged and reports a running -scrub although it is not, but should not normally be necessary +*deprecated, will be removed.* ++ +An option to force starting new scrub when scrub status file is damaged and +reports a running scrub although it is not, since whether a scrub is really +running can be judged automatically now, this option should not be necessary +anymore. *status* [-d] |:: Show status of a running scrub for the filesystem identified by 'path' or diff --git a/cmds-scrub.c b/cmds-scrub.c index 6b909f20..8cf1e5df 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -1569,7 +1569,7 @@ static const char * const cmd_scrub_start_usage[] = { "-R raw print mode, print full data instead of summary", "-c set ioprio class (see ionice(1) manpage)", "-n set ioprio classdata (see ionice(1) manpage)", - "-f force starting new scrub even if a scrub is already running", + "-f (deprecated) force starting new scrub even if a scrub is already running", " this is useful when scrub stats record file is damaged", NULL }; -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: Remove duplicate value-get for data_extents_scrubbed
Get data_extents_scrubbed value for twice, since there is only one data_extents_scrubbed in struct btrfs_scrub_progress, remove the duplicate one. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- cmds-scrub.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmds-scrub.c b/cmds-scrub.c index dabe7d9a..6b909f20 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -589,8 +589,6 @@ again: /* fall through */ case 5: /* read key/value pair */ ret = 0; - _SCRUB_KVREAD(ret, , data_extents_scrubbed, avail, l, - [curr]->p); _SCRUB_KVREAD(ret, , data_extents_scrubbed, avail, l, [curr]->p); _SCRUB_KVREAD(ret, , tree_extents_scrubbed, avail, l, -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: Let function find_device to be consistent with kernel
Make find_device to be consistent with kernel according 35c70103a528 ("btrfs: refactor find_device helper") And, modify the compare condition from both devid and uuid to devid or devid and uuid according 8f18cf13396c ("Btrfs: Make the resizer work based on shrinking and growing devices") Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- volumes.c | 19 +-- 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/volumes.c b/volumes.c index edad367b..1320b55b 100644 --- a/volumes.c +++ b/volumes.c @@ -54,14 +54,22 @@ static inline int nr_data_stripes(struct map_lookup *map) static LIST_HEAD(fs_uuids); -static struct btrfs_device *__find_device(struct list_head *head, u64 devid, - u8 *uuid) +/* + * Find a device specified by @devid or @uuid in the list of @fs_devices, or + * return NULL. + * + * If devid and uuid are both specified, the match must be exact, otherwise + * only devid is used. + */ +static struct btrfs_device *find_device(struct btrfs_fs_devices *fs_devices, + u64 devid, u8 *uuid) { + struct list_head *head = _devices->devices; struct btrfs_device *dev; list_for_each_entry(dev, head, dev_list) { if (dev->devid == devid && - !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE)) { + (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) { return dev; } } @@ -100,7 +108,7 @@ static int device_list_add(const char *path, fs_devices->lowest_devid = (u64)-1; device = NULL; } else { - device = __find_device(_devices->devices, devid, + device = find_device(fs_devices, devid, disk_super->dev_item.uuid); } if (!device) { @@ -1616,8 +1624,7 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, if (!fsid || (!memcmp(cur_devices->fsid, fsid, BTRFS_UUID_SIZE) || fs_info->ignore_fsid_mismatch)) { - device = __find_device(_devices->devices, - devid, uuid); + device = find_device(cur_devices, devid, uuid); if (device) return device; } -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: Remove unused parameter
Parameter usagestr is not used, remove it. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- cmds-filesystem.c | 2 +- help.c| 2 +- help.h| 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 467aff11..5fa8cf2b 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -1093,7 +1093,7 @@ static int cmd_filesystem_resize(int argc, char **argv) DIR *dirstream = NULL; struct stat st; - clean_args_no_options_relaxed(argc, argv, cmd_filesystem_resize_usage); + clean_args_no_options_relaxed(argc, argv); if (check_argc_exact(argc - optind, 2)) usage(cmd_filesystem_resize_usage); diff --git a/help.c b/help.c index 311a4320..f1dd3946 100644 --- a/help.c +++ b/help.c @@ -115,7 +115,7 @@ void clean_args_no_options(int argc, char *argv[], const char * const *usagestr) * - "-- option1 option2 ..." * - "option1 option2 ..." */ -void clean_args_no_options_relaxed(int argc, char *argv[], const char * const *usagestr) +void clean_args_no_options_relaxed(int argc, char *argv[]) { if (argc <= 1) return; diff --git a/help.h b/help.h index efeded30..a1405942 100644 --- a/help.h +++ b/help.h @@ -72,8 +72,7 @@ int check_argc_exact(int nargs, int expected); int check_argc_min(int nargs, int expected); int check_argc_max(int nargs, int expected); void clean_args_no_options(int argc, char *argv[], const char * const *usage); -void clean_args_no_options_relaxed(int argc, char *argv[], - const char * const *usagestr); +void clean_args_no_options_relaxed(int argc, char *argv[]); void fixup_argv0(char **argv, const char *token); void set_argv0(char **argv); -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] btrfs-progs: Do not add extra slash if given path end with it
When use a given path end with a slash like below, the output of path will have double slash. Do not add extra slash if there is already one in the given path. $ btrfs filesystem du ./test/ output: Total Exclusive Set shared Filename 0.00B 0.00B - /home/gujx/device/tmp/test//foo Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- cmds-fi-du.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds-fi-du.c b/cmds-fi-du.c index 8a44665c..74f57320 100644 --- a/cmds-fi-du.c +++ b/cmds-fi-du.c @@ -449,7 +449,7 @@ static int du_add_file(const char *filename, int dirfd, } pathtmp = pathp; - if (pathp == path) + if (pathp == path || *(pathp-1) == '/') ret = sprintf(pathp, "%s", filename); else ret = sprintf(pathp, "/%s", filename); -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v5 0/3] Add support for export testsuits
Hi, > -Original Message- > From: David Sterba [mailto:dste...@suse.cz] > Sent: Friday, February 09, 2018 2:02 AM > To: Gu, Jinxiang/顾 金香 <g...@cn.fujitsu.com> > Cc: linux-btrfs@vger.kernel.org; dste...@suse.cz > Subject: Re: [PATCH v5 0/3] Add support for export testsuits > > On Thu, Feb 08, 2018 at 02:34:17PM +0800, Gu Jinxiang wrote: > > Achieved: > > 1. export testsuite by: > > $ make testsuite > > files list in testsuites-list will be added into tarball > > btrfs-progs-tests.tar.gz. > > > > 2. after decompress btrfs-progs-tests.tar.gz, run test by: > > $ TEST=`MASK` ./tests/mkfs-tests.sh > > and, without MASK also be ok. > > replenish: > > $ tar -xzvf ./btrfs-progs-tests.tar.gz $ ls > >btrfs-progs > > tests directory and other files is in btrfs-progs. > > > > Changelog: > > v5->v4: modify patch2. > > make TEST_TOP to represent tests directory. > > and introduce INTERNAL_BIN for internal binaries. > > Patches 1 and 2 applied. I reworked most of 1, my idea of the end result of > the testsutie is different. In patch 2, I've added quotes to all lines > that changed the variables on 'source ..' line. In such cases please also > look at the resulting code and do not just mechanically apply the > suggestion to rename a variable. Patch 3 does not bring much information so I > did not apply it and wrote the section myself. Thank you for the change. My idea was keep the structure as git when export testsuite. But I saw the modification, they are more reasonable indeed. > > The project idea lacked details, as the cards on the github Projects page are > supposed to be short. Not all of the tasks there are simple, so > if you'd want to work on something found there and see that's not clear what > to do, it would be better to open an issue so I can fill in. OK. Got it. Thanks. >
[PATCH v5 3/3] btrfs-progs: Add readme for export testsuits
Add the readme of command for export testsuits. And add the excute method of exported testsuits. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/README.md | 13 + 1 file changed, 13 insertions(+) diff --git a/tests/README.md b/tests/README.md index 04d2ce2a..23f35cfc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -48,6 +48,19 @@ $ TEST=001\* ./fsck-tests.sh will run the first test in fsck-tests subdirectory. +## Package testsuit + +The tests can be export as a btrfs-progs-tests.tar.gz current path. Use: + +```shell +$ make testsuite +``` + + +And, after decompress btrfs-progs-tests.tar.gz, test can be run selectively +from `tests/` directory introduced above. + + ## Test structure *tests/fsck-tests/:* -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 1/3] btrfs-progs: Add make testsuite command for export tests
Export the testsuite files to a separate tar. Since fsck tests depend on btrfs-corrupt-block, and misc tests depends on both btrfs-corrupt-block and fssum, so set it as prerequisites for package commad. Because, althougth fssum can be generated by source that are all in tests directory, and has no rely on the btrfs's structure. But btrfs-corrupt-block deeply relys on btrfs's structure. For consistency, at the present stage, generete the two when create test tar. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- .gitignore| 1 + Makefile | 4 tests/export-tests.sh | 37 + testsuites-list | 22 ++ 4 files changed, 64 insertions(+) create mode 100755 tests/export-tests.sh create mode 100644 testsuites-list diff --git a/.gitignore b/.gitignore index 8e607f6e..a41ad8ce 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ libbtrfs.so.0.1 library-test library-test-static /fssum +testsuites-id /tests/*-tests-results.txt /tests/test-console.txt diff --git a/Makefile b/Makefile index 6369e8f4..7eab0f4f 100644 --- a/Makefile +++ b/Makefile @@ -333,6 +333,10 @@ test-inst: all test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli +testsuite: btrfs-corrupt-block fssum + @echo "Export tests as a package" + $(Q)bash tests/export-tests.sh + # # NOTE: For static compiles, you need to have all the required libs # static equivalent available diff --git a/tests/export-tests.sh b/tests/export-tests.sh new file mode 100755 index ..0ed7dd99 --- /dev/null +++ b/tests/export-tests.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# export the testsuite files to a separate tar + +TESTSUITES_LIST_FILE=$PWD/testsuites-list +if ! [ -f $TESTSUITES_LIST_FILE ];then + echo "testsuites list file is not exsit." + exit 1 +fi + +TESTSUITES_LIST=$(cat $TESTSUITES_LIST_FILE) +if [ -z "$TESTSUITES_LIST" ]; then + echo "no file be list in testsuites-list" + exit 1 +fi + +DEST="btrfs-progs-tests.tar.gz" +if [ -f $DEST ];then + echo "remove exsit package: " $DEST + rm $DEST +fi + +TEST_ID=$PWD/testsuites-id +if [ -f $TEST_ID ];then + rm $TEST_ID +fi +VERSION=`./version.sh` +TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"` + +echo "git version: " $VERSION > $TEST_ID +echo "this tar is created in: " $TIMESTAMP >> $TEST_ID + +echo "begin create tar: " $DEST +tar --exclude-vcs-ignores -zScf $DEST -C ../ $TESTSUITES_LIST +if [ $? -eq 0 ]; then + echo "create tar successfully." +fi +rm $TEST_ID diff --git a/testsuites-list b/testsuites-list new file mode 100644 index ..a24591f5 --- /dev/null +++ b/testsuites-list @@ -0,0 +1,22 @@ +btrfs-progs/testsuites-id +btrfs-progs/fssum +btrfs-progs/btrfs-corrupt-block +btrfs-progs/Documentation/ +btrfs-progs/tests/cli-tests +btrfs-progs/tests/cli-tests.sh +btrfs-progs/tests/common +btrfs-progs/tests/common.convert +btrfs-progs/tests/common.local +btrfs-progs/tests/convert-tests +btrfs-progs/tests/convert-tests.sh +btrfs-progs/tests/fsck-tests +btrfs-progs/tests/fsck-tests.sh +btrfs-progs/tests/fuzz-tests/ +btrfs-progs/tests/fuzz-tests.sh +btrfs-progs/tests/misc-tests/ +btrfs-progs/tests/misc-tests.sh +btrfs-progs/tests/mkfs-tests/ +btrfs-progs/tests/mkfs-tests.sh +btrfs-progs/tests/README.md +btrfs-progs/tests/scan-results.sh +btrfs-progs/tests/test-console.sh -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v5 0/3] Add support for export testsuits
Achieved: 1. export testsuite by: $ make testsuite files list in testsuites-list will be added into tarball btrfs-progs-tests.tar.gz. 2. after decompress btrfs-progs-tests.tar.gz, run test by: $ TEST=`MASK` ./tests/mkfs-tests.sh and, without MASK also be ok. replenish: $ tar -xzvf ./btrfs-progs-tests.tar.gz $ ls btrfs-progs tests directory and other files is in btrfs-progs. Changelog: v5->v4: modify patch2. make TEST_TOP to represent tests directory. and introduce INTERNAL_BIN for internal binaries. v4->v3: modify patch2. 1.keep TOP used for binaries, and introduce TEST_TOP for other resources. v3->v2: patch1: 1.change command from `make package` to `make testsuite` 2.create btrfs-progs-tests.tar.gz in the current directory, so remove EXPORT variable. 3.add a listfile which list files to be added into tarball. and, add Documentation into the list. And revert the patch3 in v2. 4.add some identification info of tarball 5.add temporary file testsuites-id to .gitignore patch3: modify the readme according to the change of patch1. v2->v1: big change of realize idea. from use EXEC parameter given to run the testsuite to export the testsuite files to a separate tar, run from a script. Gu Jinxiang (3): btrfs-progs: Add make testsuite command for export tests btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests directory and internal binaries btrfs-progs: Add readme for export testsuits .gitignore | 1 + Makefile | 4 +++ tests/README.md| 13 tests/cli-tests.sh | 15 ++--- tests/cli-tests/001-btrfs/test.sh | 2 +- .../cli-tests/002-balance-full-no-filters/test.sh | 2 +- tests/cli-tests/003-fi-resize-args/test.sh | 2 +- .../cli-tests/004-send-parent-multi-subvol/test.sh | 2 +- tests/cli-tests/005-qgroup-show/test.sh| 2 +- tests/cli-tests/006-qgroup-show-sync/test.sh | 2 +- tests/cli-tests/007-check-force/test.sh| 2 +- .../008-subvolume-get-set-default/test.sh | 2 +- tests/common | 16 ++ tests/convert-tests.sh | 15 ++--- tests/convert-tests/001-ext2-basic/test.sh | 4 +-- tests/convert-tests/002-ext3-basic/test.sh | 4 +-- tests/convert-tests/003-ext4-basic/test.sh | 4 +-- .../004-ext2-backup-superblock-ranges/test.sh | 2 +- .../convert-tests/005-delete-all-rollback/test.sh | 4 +-- tests/convert-tests/006-large-hole-extent/test.sh | 4 +-- .../007-unsupported-block-sizes/test.sh| 4 +-- tests/convert-tests/008-readonly-image/test.sh | 4 +-- tests/convert-tests/009-common-inode-flags/test.sh | 4 +-- tests/convert-tests/010-reiserfs-basic/test.sh | 4 +-- .../011-reiserfs-delete-all-rollback/test.sh | 4 +-- .../012-reiserfs-large-hole-extent/test.sh | 4 +-- .../013-reiserfs-common-inode-flags/test.sh| 4 +-- .../014-reiserfs-tail-handling/test.sh | 4 +-- .../015-no-rollback-after-balance/test.sh | 4 +-- tests/export-tests.sh | 37 ++ tests/fsck-tests.sh| 17 +++--- tests/fsck-tests/006-bad-root-items/test.sh| 2 +- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 4 +-- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- .../fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh| 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 2 +- tests/fsck-tests/025-file-extents/test.sh | 2 +- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh | 2 +- .../028-unaligned-super-dev-sizes/test.sh | 2 +- tests/fuzz-tests.sh| 15 ++--- .../fuzz-tests/001-simple-check-unmounted/test.sh | 4 +-- tests/fuzz-tests/002-simple-image/test.sh | 4 +-- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 4 +-- tests/fuzz-tests/004-simple-dump-tree/test.sh | 4 +-- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 +-- tests/fuzz-tests/006-simple-tree-stats/test.sh | 4 +-- tests/fuzz-tests/007-simple-super-recover/test.sh | 4 +-- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 4 +-- tests/fuzz-tests/009-simple-zero-log/test.sh | 4 +-- tests/misc-tests.sh| 17 +++---
[PATCH v5 2/3] btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests directory and internal binaries
Use TEST_TOP for tests directory. And INTERNAL_BIN for internal binaries. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/cli-tests.sh | 15 ++- tests/cli-tests/001-btrfs/test.sh | 2 +- tests/cli-tests/002-balance-full-no-filters/test.sh | 2 +- tests/cli-tests/003-fi-resize-args/test.sh | 2 +- tests/cli-tests/004-send-parent-multi-subvol/test.sh| 2 +- tests/cli-tests/005-qgroup-show/test.sh | 2 +- tests/cli-tests/006-qgroup-show-sync/test.sh| 2 +- tests/cli-tests/007-check-force/test.sh | 2 +- tests/cli-tests/008-subvolume-get-set-default/test.sh | 2 +- tests/common| 16 ++-- tests/convert-tests.sh | 15 ++- tests/convert-tests/001-ext2-basic/test.sh | 4 ++-- tests/convert-tests/002-ext3-basic/test.sh | 4 ++-- tests/convert-tests/003-ext4-basic/test.sh | 4 ++-- .../004-ext2-backup-superblock-ranges/test.sh | 2 +- tests/convert-tests/005-delete-all-rollback/test.sh | 4 ++-- tests/convert-tests/006-large-hole-extent/test.sh | 4 ++-- tests/convert-tests/007-unsupported-block-sizes/test.sh | 4 ++-- tests/convert-tests/008-readonly-image/test.sh | 4 ++-- tests/convert-tests/009-common-inode-flags/test.sh | 4 ++-- tests/convert-tests/010-reiserfs-basic/test.sh | 4 ++-- .../011-reiserfs-delete-all-rollback/test.sh| 4 ++-- .../012-reiserfs-large-hole-extent/test.sh | 4 ++-- .../013-reiserfs-common-inode-flags/test.sh | 4 ++-- tests/convert-tests/014-reiserfs-tail-handling/test.sh | 4 ++-- .../convert-tests/015-no-rollback-after-balance/test.sh | 4 ++-- tests/fsck-tests.sh | 17 - tests/fsck-tests/006-bad-root-items/test.sh | 2 +- tests/fsck-tests/012-leaf-corruption/test.sh| 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh| 4 ++-- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- tests/fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh | 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 2 +- tests/fsck-tests/025-file-extents/test.sh | 2 +- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh| 2 +- tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh | 2 +- tests/fuzz-tests.sh | 15 ++- tests/fuzz-tests/001-simple-check-unmounted/test.sh | 4 ++-- tests/fuzz-tests/002-simple-image/test.sh | 4 ++-- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 4 ++-- tests/fuzz-tests/004-simple-dump-tree/test.sh | 4 ++-- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 ++-- tests/fuzz-tests/006-simple-tree-stats/test.sh | 4 ++-- tests/fuzz-tests/007-simple-super-recover/test.sh | 4 ++-- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 4 ++-- tests/fuzz-tests/009-simple-zero-log/test.sh| 4 ++-- tests/misc-tests.sh | 17 - tests/misc-tests/001-btrfstune-features/test.sh | 2 +- tests/misc-tests/002-uuid-rewrite/test.sh | 6 +++--- tests/misc-tests/003-zero-log/test.sh | 4 ++-- tests/misc-tests/004-shrink-fs/test.sh | 2 +- .../005-convert-progress-thread-crash/test.sh | 2 +- tests/misc-tests/006-image-on-missing-device/test.sh| 2 +- tests/misc-tests/007-subvolume-sync/test.sh | 2 +- tests/misc-tests/008-leaf-crossing-stripes/test.sh | 2 +- tests/misc-tests/009-subvolume-sync-must-wait/test.sh | 2 +- tests/misc-tests/010-convert-delete-ext2-subvol/test.sh | 2 +- tests/misc-tests/011-delete-missing-device/test.sh | 2 +- tests/misc-tests/012-find-root-no-result/test.sh| 2 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 2 +- tests/misc-tests/014-filesystem-label/test.sh | 2 +- tests/misc-tests/015-dump-super-garbage/test.sh | 2 +- tests/misc-tests/016-send-clone-src/test.sh | 2 +- tests/misc-tests/017-recv-stream-malformatted/test.sh | 2 +- tests/misc-tests/018-recv-end-of-stream/test.sh | 2 +- .../019-receive-clones-on-mounted-subvol/test.sh| 4 ++-- tests/misc-tests/020-fix-superblock-corruption/test.sh | 2 +- tests/misc-tests/021-image-multi-devices/t
[PATCH 1/3] btrfs-progs: add prerequisite mkfs.btrfs for test-cli
Since tests/cli-tests/002-balance-full-no-filters/test.sh need the mkfs.btrfs for prerequisite. So add the dependency in Makefile. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 00e2137..034c943 100644 --- a/Makefile +++ b/Makefile @@ -315,7 +315,7 @@ test-fuzz: btrfs @echo "[TEST] fuzz-tests.sh" $(Q)bash tests/fuzz-tests.sh -test-cli: btrfs +test-cli: btrfs mkfs.btrfs @echo "[TEST] cli-tests.sh" $(Q)bash tests/cli-tests.sh -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/3] btrfs-progs: add prerequisite btrfs-convert for test-misc
Since tests/misc-tests/005-convert-progress-thread-crash/test.sh need the btrfs-convert for prerequisite. So add the dependency in Makefile. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9299411..7ccba62 100644 --- a/Makefile +++ b/Makefile @@ -303,7 +303,7 @@ test-fsck: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune $(Q)bash tests/fsck-tests.sh test-misc: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune fssum \ - btrfs-zero-log btrfs-find-root btrfs-select-super + btrfs-zero-log btrfs-find-root btrfs-select-super btrfs-convert @echo "[TEST] misc-tests.sh" $(Q)bash tests/misc-tests.sh -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/3] btrfs-progs: add prerequisite btrfs-image for test-fuzz
Since tests/fuzz-tests/002-simple-image/test.sh need the btrfs-image for prerequisite. So add the dependency in Makefile. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 034c943..9299411 100644 --- a/Makefile +++ b/Makefile @@ -311,7 +311,7 @@ test-mkfs: btrfs mkfs.btrfs @echo "[TEST] mkfs-tests.sh" $(Q)bash tests/mkfs-tests.sh -test-fuzz: btrfs +test-fuzz: btrfs btrfs-image @echo "[TEST] fuzz-tests.sh" $(Q)bash tests/fuzz-tests.sh -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 3/3] btrfs-progs: Add readme for export testsuits
Add the readme of command for export testsuits. And add the excute method of exported testsuits. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/README.md | 13 + 1 file changed, 13 insertions(+) diff --git a/tests/README.md b/tests/README.md index 04d2ce2a..23f35cfc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -48,6 +48,19 @@ $ TEST=001\* ./fsck-tests.sh will run the first test in fsck-tests subdirectory. +## Package testsuit + +The tests can be export as a btrfs-progs-tests.tar.gz current path. Use: + +```shell +$ make testsuite +``` + + +And, after decompress btrfs-progs-tests.tar.gz, test can be run selectively +from `tests/` directory introduced above. + + ## Test structure *tests/fsck-tests/:* -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v4 0/3] Add support for export testsuits
Achieved: 1. export testsuite by: $ make testsuite files list in testsuites-list will be added into tarball btrfs-progs-tests.tar.gz. 2. after decompress btrfs-progs-tests.tar.gz, run test by: $ TEST=`MASK` ./tests/mkfs-tests.sh and, without MASK also be ok. replenish: $ tar -xzvf ./btrfs-progs-tests.tar.gz $ ls btrfs-progs tests directory and other files is in btrfs-progs. Changelog: v4->v3: modify patch2. 1.keep TOP used for binaries, and introduce TEST_TOP for other resources. v3->v2: patch1: 1.change command from `make package` to `make testsuite` 2.create btrfs-progs-tests.tar.gz in the current directory, so remove EXPORT variable. 3.add a listfile which list files to be added into tarball. and, add Documentation into the list. And revert the patch3 in v2. 4.add some identification info of tarball 5.add temporary file testsuites-id to .gitignore patch3: modify the readme according to the change of patch1. v2->v1: big change of realize idea. from use EXEC parameter given to run the testsuite to export the testsuite files to a separate tar, run from a script. Gu Jinxiang (3): btrfs-progs: Add make testsuite command for export tests btrfs-progs: introduce TEST_TOP for resources except binaries btrfs-progs: Add readme for export testsuits .gitignore | 1 + Makefile | 4 +++ tests/README.md| 13 tests/cli-tests.sh | 15 ++--- tests/cli-tests/001-btrfs/test.sh | 2 +- .../cli-tests/002-balance-full-no-filters/test.sh | 2 +- tests/cli-tests/003-fi-resize-args/test.sh | 2 +- .../cli-tests/004-send-parent-multi-subvol/test.sh | 2 +- tests/cli-tests/005-qgroup-show/test.sh| 2 +- tests/cli-tests/006-qgroup-show-sync/test.sh | 2 +- tests/cli-tests/007-check-force/test.sh| 2 +- .../008-subvolume-get-set-default/test.sh | 2 +- tests/common | 16 ++ tests/convert-tests.sh | 15 ++--- tests/convert-tests/001-ext2-basic/test.sh | 4 +-- tests/convert-tests/002-ext3-basic/test.sh | 4 +-- tests/convert-tests/003-ext4-basic/test.sh | 4 +-- .../004-ext2-backup-superblock-ranges/test.sh | 2 +- .../convert-tests/005-delete-all-rollback/test.sh | 4 +-- tests/convert-tests/006-large-hole-extent/test.sh | 4 +-- .../007-unsupported-block-sizes/test.sh| 4 +-- tests/convert-tests/008-readonly-image/test.sh | 4 +-- tests/convert-tests/009-common-inode-flags/test.sh | 4 +-- tests/convert-tests/010-reiserfs-basic/test.sh | 4 +-- .../011-reiserfs-delete-all-rollback/test.sh | 4 +-- .../012-reiserfs-large-hole-extent/test.sh | 4 +-- .../013-reiserfs-common-inode-flags/test.sh| 4 +-- .../014-reiserfs-tail-handling/test.sh | 4 +-- .../015-no-rollback-after-balance/test.sh | 4 +-- tests/export-tests.sh | 37 ++ tests/fsck-tests.sh| 15 ++--- tests/fsck-tests/006-bad-root-items/test.sh| 2 +- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 4 +-- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- .../fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh| 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 2 +- tests/fsck-tests/025-file-extents/test.sh | 2 +- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh | 2 +- .../028-unaligned-super-dev-sizes/test.sh | 2 +- tests/fuzz-tests.sh| 15 ++--- .../fuzz-tests/001-simple-check-unmounted/test.sh | 4 +-- tests/fuzz-tests/002-simple-image/test.sh | 4 +-- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 4 +-- tests/fuzz-tests/004-simple-dump-tree/test.sh | 4 +-- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 +-- tests/fuzz-tests/006-simple-tree-stats/test.sh | 4 +-- tests/fuzz-tests/007-simple-super-recover/test.sh | 4 +-- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 4 +-- tests/fuzz-tests/009-simple-zero-log/test.sh | 4 +-- tests/misc-tests.sh| 15 ++--- tests/misc-tests/001-btrfstune-features/test.sh| 2 +- tests/misc-tests/002-uuid-rewrite/test.sh | 6 ++-- tests/misc-tests/003-zero-lo
[PATCH v4 1/3] btrfs-progs: Add make testsuite command for export tests
Export the testsuite files to a separate tar. Since fsck tests depend on btrfs-corrupt-block, and misc tests depends on both btrfs-corrupt-block and fssum, so set it as prerequisites for package commad. Because, althougth fssum can be generated by source that are all in tests directory, and has no rely on the btrfs's structure. But btrfs-corrupt-block deeply relys on btrfs's structure. For consistency, at the present stage, generete the two when create test tar. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- .gitignore| 1 + Makefile | 4 tests/export-tests.sh | 37 + testsuites-list | 22 ++ 4 files changed, 64 insertions(+) create mode 100755 tests/export-tests.sh create mode 100644 testsuites-list diff --git a/.gitignore b/.gitignore index 8e607f6e..a41ad8ce 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ libbtrfs.so.0.1 library-test library-test-static /fssum +testsuites-id /tests/*-tests-results.txt /tests/test-console.txt diff --git a/Makefile b/Makefile index 6369e8f4..7eab0f4f 100644 --- a/Makefile +++ b/Makefile @@ -333,6 +333,10 @@ test-inst: all test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli +testsuite: btrfs-corrupt-block fssum + @echo "Export tests as a package" + $(Q)bash tests/export-tests.sh + # # NOTE: For static compiles, you need to have all the required libs # static equivalent available diff --git a/tests/export-tests.sh b/tests/export-tests.sh new file mode 100755 index ..0ed7dd99 --- /dev/null +++ b/tests/export-tests.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# export the testsuite files to a separate tar + +TESTSUITES_LIST_FILE=$PWD/testsuites-list +if ! [ -f $TESTSUITES_LIST_FILE ];then + echo "testsuites list file is not exsit." + exit 1 +fi + +TESTSUITES_LIST=$(cat $TESTSUITES_LIST_FILE) +if [ -z "$TESTSUITES_LIST" ]; then + echo "no file be list in testsuites-list" + exit 1 +fi + +DEST="btrfs-progs-tests.tar.gz" +if [ -f $DEST ];then + echo "remove exsit package: " $DEST + rm $DEST +fi + +TEST_ID=$PWD/testsuites-id +if [ -f $TEST_ID ];then + rm $TEST_ID +fi +VERSION=`./version.sh` +TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"` + +echo "git version: " $VERSION > $TEST_ID +echo "this tar is created in: " $TIMESTAMP >> $TEST_ID + +echo "begin create tar: " $DEST +tar --exclude-vcs-ignores -zScf $DEST -C ../ $TESTSUITES_LIST +if [ $? -eq 0 ]; then + echo "create tar successfully." +fi +rm $TEST_ID diff --git a/testsuites-list b/testsuites-list new file mode 100644 index ..a24591f5 --- /dev/null +++ b/testsuites-list @@ -0,0 +1,22 @@ +btrfs-progs/testsuites-id +btrfs-progs/fssum +btrfs-progs/btrfs-corrupt-block +btrfs-progs/Documentation/ +btrfs-progs/tests/cli-tests +btrfs-progs/tests/cli-tests.sh +btrfs-progs/tests/common +btrfs-progs/tests/common.convert +btrfs-progs/tests/common.local +btrfs-progs/tests/convert-tests +btrfs-progs/tests/convert-tests.sh +btrfs-progs/tests/fsck-tests +btrfs-progs/tests/fsck-tests.sh +btrfs-progs/tests/fuzz-tests/ +btrfs-progs/tests/fuzz-tests.sh +btrfs-progs/tests/misc-tests/ +btrfs-progs/tests/misc-tests.sh +btrfs-progs/tests/mkfs-tests/ +btrfs-progs/tests/mkfs-tests.sh +btrfs-progs/tests/README.md +btrfs-progs/tests/scan-results.sh +btrfs-progs/tests/test-console.sh -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 0/3] Add support for export testsuits
Achieved: 1. export testsuite by: $ make testsuite files list in testsuites-list will be added into tarball btrfs-progs-tests.tar.gz. 2. after decompress btrfs-progs-tests.tar.gz, run test by: $ TEST=`MASK` ./tests/mkfs-tests.sh and, without MASK also be ok. replenish: $ tar -xzvf ./btrfs-progs-tests.tar.gz $ ls btrfs-progs tests directory and other files is in btrfs-progs. Changelog: v3->v2: patch1: 1.change command from `make package` to `make testsuite` 2.create btrfs-progs-tests.tar.gz in the current directory, so remove EXPORT variable. 3.add a listfile which list files to be added into tarball. and, add Documentation into the list. And revert the patch3 in v2. 4.add some identification info of tarball 5.add temporary file testsuites-id to .gitignore patch3: modify the readme according to the change of patch1. v2->v1: big change of realize idea. from use EXEC parameter given to run the testsuite to export the testsuite files to a separate tar, run from a script. Gu Jinxiang (3): btrfs-progs: Add make testsuite command for export tests btrfs-progs: Add EXEC represent path of executable file btrfs-progs: Add readme for export testsuits .gitignore | 1 + Makefile | 4 ++ tests/README.md| 13 + tests/cli-tests.sh | 5 ++ tests/cli-tests/001-btrfs/test.sh | 20 .../cli-tests/002-balance-full-no-filters/test.sh | 10 ++-- tests/cli-tests/003-fi-resize-args/test.sh | 30 +-- .../cli-tests/004-send-parent-multi-subvol/test.sh | 12 ++--- tests/cli-tests/005-qgroup-show/test.sh| 14 ++--- tests/cli-tests/006-qgroup-show-sync/test.sh | 14 ++--- tests/cli-tests/007-check-force/test.sh| 14 ++--- .../008-subvolume-get-set-default/test.sh | 20 tests/common | 16 +++--- tests/common.convert | 8 +-- tests/convert-tests.sh | 5 ++ .../004-ext2-backup-superblock-ranges/test.sh | 10 ++-- .../convert-tests/005-delete-all-rollback/test.sh | 2 +- .../007-unsupported-block-sizes/test.sh| 2 +- .../011-reiserfs-delete-all-rollback/test.sh | 2 +- .../015-no-rollback-after-balance/test.sh | 6 +-- tests/export-tests.sh | 37 + tests/fsck-tests.sh| 5 ++ tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 12 ++--- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- .../fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh| 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 10 ++-- tests/fsck-tests/025-file-extents/test.sh | 14 ++--- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh | 2 +- .../028-unaligned-super-dev-sizes/test.sh | 6 +-- tests/fuzz-tests.sh| 5 ++ .../fuzz-tests/001-simple-check-unmounted/test.sh | 2 +- tests/fuzz-tests/002-simple-image/test.sh | 2 +- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 12 ++--- tests/fuzz-tests/004-simple-dump-tree/test.sh | 2 +- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 +- tests/fuzz-tests/006-simple-tree-stats/test.sh | 2 +- tests/fuzz-tests/007-simple-super-recover/test.sh | 2 +- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 2 +- tests/fuzz-tests/009-simple-zero-log/test.sh | 2 +- tests/misc-tests.sh| 5 ++ tests/misc-tests/001-btrfstune-features/test.sh| 10 ++-- tests/misc-tests/002-uuid-rewrite/test.sh | 20 tests/misc-tests/003-zero-log/test.sh | 16 +++--- tests/misc-tests/004-shrink-fs/test.sh | 14 ++--- .../005-convert-progress-thread-crash/test.sh | 2 +- .../misc-tests/006-image-on-missing-device/test.sh | 10 ++-- tests/misc-tests/007-subvolume-sync/test.sh| 18 +++ tests/misc-tests/008-leaf-crossing-stripes/test.sh | 4 +- .../009-subvolume-sync-must-wait/test.sh | 22 .../010-convert-delete-ext2-subvol/test.sh | 10 ++-- tests/misc-tests/011-delete-missing-device/test.sh | 18 +++ tests/misc-tests/012-find-root-no-result/test.sh | 4 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 20 tests/misc-tests/014-filesystem-label/test.sh | 22 tests/misc-tests/01
[PATCH v3 2/3] btrfs-progs: Add EXEC represent path of executable file
Use EXEC instead of TOP to represent the path of excutable file. EXEC is set to TOP by default, but when there is no excutable file in TOP, use the path where btrfs is install as EXEC. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/cli-tests.sh | 5 ++ tests/cli-tests/001-btrfs/test.sh | 20 .../cli-tests/002-balance-full-no-filters/test.sh | 10 ++-- tests/cli-tests/003-fi-resize-args/test.sh | 30 +-- .../cli-tests/004-send-parent-multi-subvol/test.sh | 12 ++--- tests/cli-tests/005-qgroup-show/test.sh| 14 ++--- tests/cli-tests/006-qgroup-show-sync/test.sh | 14 ++--- tests/cli-tests/007-check-force/test.sh| 14 ++--- .../008-subvolume-get-set-default/test.sh | 20 tests/common | 16 +++--- tests/common.convert | 8 +-- tests/convert-tests.sh | 5 ++ .../004-ext2-backup-superblock-ranges/test.sh | 10 ++-- .../convert-tests/005-delete-all-rollback/test.sh | 2 +- .../007-unsupported-block-sizes/test.sh| 2 +- .../011-reiserfs-delete-all-rollback/test.sh | 2 +- .../015-no-rollback-after-balance/test.sh | 6 +-- tests/fsck-tests.sh| 5 ++ tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 12 ++--- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- .../fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh| 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 10 ++-- tests/fsck-tests/025-file-extents/test.sh | 14 ++--- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh | 2 +- .../028-unaligned-super-dev-sizes/test.sh | 6 +-- tests/fuzz-tests.sh| 5 ++ .../fuzz-tests/001-simple-check-unmounted/test.sh | 2 +- tests/fuzz-tests/002-simple-image/test.sh | 2 +- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 12 ++--- tests/fuzz-tests/004-simple-dump-tree/test.sh | 2 +- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 +- tests/fuzz-tests/006-simple-tree-stats/test.sh | 2 +- tests/fuzz-tests/007-simple-super-recover/test.sh | 2 +- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 2 +- tests/fuzz-tests/009-simple-zero-log/test.sh | 2 +- tests/misc-tests.sh| 5 ++ tests/misc-tests/001-btrfstune-features/test.sh| 10 ++-- tests/misc-tests/002-uuid-rewrite/test.sh | 20 tests/misc-tests/003-zero-log/test.sh | 16 +++--- tests/misc-tests/004-shrink-fs/test.sh | 14 ++--- .../005-convert-progress-thread-crash/test.sh | 2 +- .../misc-tests/006-image-on-missing-device/test.sh | 10 ++-- tests/misc-tests/007-subvolume-sync/test.sh| 18 +++ tests/misc-tests/008-leaf-crossing-stripes/test.sh | 4 +- .../009-subvolume-sync-must-wait/test.sh | 22 .../010-convert-delete-ext2-subvol/test.sh | 10 ++-- tests/misc-tests/011-delete-missing-device/test.sh | 18 +++ tests/misc-tests/012-find-root-no-result/test.sh | 4 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 20 tests/misc-tests/014-filesystem-label/test.sh | 22 tests/misc-tests/015-dump-super-garbage/test.sh| 18 +++ tests/misc-tests/016-send-clone-src/test.sh| 12 ++--- .../017-recv-stream-malformatted/test.sh | 8 +-- tests/misc-tests/018-recv-end-of-stream/test.sh| 60 +++--- .../019-receive-clones-on-mounted-subvol/test.sh | 38 +++--- .../020-fix-superblock-corruption/test.sh | 8 +-- tests/misc-tests/021-image-multi-devices/test.sh | 6 +-- .../022-filesystem-du-on-empty-subvol/test.sh | 12 ++--- .../023-device-usage-with-missing-device/test.sh | 10 ++-- .../misc-tests/024-inspect-internal-rootid/test.sh | 24 - tests/misc-tests/025-zstd-compression/test.sh | 6 +-- .../026-image-non-printable-chars/test.sh | 8 +-- .../027-subvol-list-deleted-toplevel/test.sh | 6 +-- tests/mkfs-tests.sh| 5 ++ tests/mkfs-tests/001-basic-profiles/test.sh| 12 ++--- .../002-no-force-mixed-on-small-volume/test.sh | 2 +- .../003-mixed-with-wrong-nodesize/test.sh | 2 +- tests/mkfs-tests/004-rootdir-keeps-size/test.sh| 2 +- .../005-long-device-name-for-ssd/test.sh | 4 +- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 4 +- .../mkfs-tests/007-mix-no
[PATCH v3 1/3] btrfs-progs: Add make testsuite command for export tests
Export the testsuite files to a separate tar. Since fsck tests depend on btrfs-corrupt-block, and misc tests depends on both btrfs-corrupt-block and fssum, so set it as prerequisites for package commad. Because, althougth fssum can be generated by source that are all in tests directory, and has no rely on the btrfs's structure. But btrfs-corrupt-block deeply relys on btrfs's structure. For consistency, at the present stage, generete the two when create test tar. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- .gitignore| 1 + Makefile | 4 tests/export-tests.sh | 37 + testsuites-list | 22 ++ 4 files changed, 64 insertions(+) create mode 100755 tests/export-tests.sh create mode 100644 testsuites-list diff --git a/.gitignore b/.gitignore index 8e607f6e..a41ad8ce 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ libbtrfs.so.0.1 library-test library-test-static /fssum +testsuites-id /tests/*-tests-results.txt /tests/test-console.txt diff --git a/Makefile b/Makefile index 6369e8f4..7eab0f4f 100644 --- a/Makefile +++ b/Makefile @@ -333,6 +333,10 @@ test-inst: all test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli +testsuite: btrfs-corrupt-block fssum + @echo "Export tests as a package" + $(Q)bash tests/export-tests.sh + # # NOTE: For static compiles, you need to have all the required libs # static equivalent available diff --git a/tests/export-tests.sh b/tests/export-tests.sh new file mode 100755 index ..0ed7dd99 --- /dev/null +++ b/tests/export-tests.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# export the testsuite files to a separate tar + +TESTSUITES_LIST_FILE=$PWD/testsuites-list +if ! [ -f $TESTSUITES_LIST_FILE ];then + echo "testsuites list file is not exsit." + exit 1 +fi + +TESTSUITES_LIST=$(cat $TESTSUITES_LIST_FILE) +if [ -z "$TESTSUITES_LIST" ]; then + echo "no file be list in testsuites-list" + exit 1 +fi + +DEST="btrfs-progs-tests.tar.gz" +if [ -f $DEST ];then + echo "remove exsit package: " $DEST + rm $DEST +fi + +TEST_ID=$PWD/testsuites-id +if [ -f $TEST_ID ];then + rm $TEST_ID +fi +VERSION=`./version.sh` +TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"` + +echo "git version: " $VERSION > $TEST_ID +echo "this tar is created in: " $TIMESTAMP >> $TEST_ID + +echo "begin create tar: " $DEST +tar --exclude-vcs-ignores -zScf $DEST -C ../ $TESTSUITES_LIST +if [ $? -eq 0 ]; then + echo "create tar successfully." +fi +rm $TEST_ID diff --git a/testsuites-list b/testsuites-list new file mode 100644 index ..a24591f5 --- /dev/null +++ b/testsuites-list @@ -0,0 +1,22 @@ +btrfs-progs/testsuites-id +btrfs-progs/fssum +btrfs-progs/btrfs-corrupt-block +btrfs-progs/Documentation/ +btrfs-progs/tests/cli-tests +btrfs-progs/tests/cli-tests.sh +btrfs-progs/tests/common +btrfs-progs/tests/common.convert +btrfs-progs/tests/common.local +btrfs-progs/tests/convert-tests +btrfs-progs/tests/convert-tests.sh +btrfs-progs/tests/fsck-tests +btrfs-progs/tests/fsck-tests.sh +btrfs-progs/tests/fuzz-tests/ +btrfs-progs/tests/fuzz-tests.sh +btrfs-progs/tests/misc-tests/ +btrfs-progs/tests/misc-tests.sh +btrfs-progs/tests/mkfs-tests/ +btrfs-progs/tests/mkfs-tests.sh +btrfs-progs/tests/README.md +btrfs-progs/tests/scan-results.sh +btrfs-progs/tests/test-console.sh -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 3/3] btrfs-progs: Add readme for export testsuits
Add the readme of command for export testsuits. And add the excute method of exported testsuits. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/README.md | 13 + 1 file changed, 13 insertions(+) diff --git a/tests/README.md b/tests/README.md index 04d2ce2a..23f35cfc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -48,6 +48,19 @@ $ TEST=001\* ./fsck-tests.sh will run the first test in fsck-tests subdirectory. +## Package testsuit + +The tests can be export as a btrfs-progs-tests.tar.gz current path. Use: + +```shell +$ make testsuite +``` + + +And, after decompress btrfs-progs-tests.tar.gz, test can be run selectively +from `tests/` directory introduced above. + + ## Test structure *tests/fsck-tests/:* -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [RFC PATCH v2 2/4] btrfs-progs: Add EXEC represent path of executable file
> -Original Message- > From: David Sterba [mailto:dste...@suse.cz] > Sent: Saturday, February 03, 2018 2:08 AM > To: Gu, Jinxiang/顾 金香 <g...@cn.fujitsu.com> > Cc: linux-btrfs@vger.kernel.org; dste...@suse.cz; quwenruo.bt...@gmx.com > Subject: Re: [RFC PATCH v2 2/4] btrfs-progs: Add EXEC represent path of > executable file > > On Fri, Feb 02, 2018 at 04:34:03PM +0800, Gu Jinxiang wrote: > > Use EXEC instead of TOP to represent the path of excutable file. > > EXEC is set to TOP by default, but when there is no excutable file in > > TOP, use the path where btrfs is install as EXEC. > > What if we just allow to change TOP (ie. do not overwrite it in the test > driver scripts)? The logic will be the same as with EXEC, but we won't > have to rewrite essentailly all paths in the testsuite. > Since besides executable files, TOP is also used to find $TOP/tests/common, $TOP/Documentation, $TOP/tests/fuzz-tests/images, i.e. so, change TOP will also effect on those resources. So, I introduce EXEC to differentiate executable files and other resources.
RE: [RFC PATCH v2 0/4] Add support for export testsuits
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] On Behalf Of David Sterba > Sent: Saturday, February 03, 2018 2:47 AM > To: Gu, Jinxiang/顾 金香 <g...@cn.fujitsu.com> > Cc: linux-btrfs@vger.kernel.org; dste...@suse.cz; quwenruo.bt...@gmx.com > Subject: Re: [RFC PATCH v2 0/4] Add support for export testsuits > > On Fri, Feb 02, 2018 at 04:34:01PM +0800, Gu Jinxiang wrote: > > Achieved: > > 1. export testsuit by: > > $ make EXPORT=/where/you/want/to/generate/tests.tar.gz package > > relative path and absolute path both be ok. > > Besides tests itself, fssum and btrfs-corrupt-block will also be > > included in tests.tar.gz, since misc and fsck tests depend on > > btrfs-corrupt-block, and misc tests depend on fssum. > > My idea was: > > $ make testuite > > that will build all dependencies, ie. fssum and btrfs-corrupt-block, and > create btrfs-progs-tests.tar.gz in the current directory, ie. no need for > the EXPORT variable. > > The tar command you used would add anything that's under tessts/ but we don't > need everything. So I'd expect there's a file that lists all files > and directories that we want in the testsuite tarball. > > Some sort of identification should be put to the tarball, eg. what git > describe says and timestamp of generation. I will deal with those comments in the next version. > > > 2. after decompress tests.tar.gz, run test by: > > $ TEST=`MASK` ./mkfs-tests.sh > > and, without MASK also be ok. > > replenish: > > The directory Structure after decompress tests.tar.gz is: > > $ tar -xzvf ./tests.tar.gz > > $ ls > >tests fssum btrfs-corrupt-block > > The structure could be reduced by one directory level if the contents of > tests is moved one directory up. That way all the test driver scritps > are in the same place as fssum and btrfs-corrupt-block. This would need to be > reflected in the test scripts. I will deal with those comments in the next version. > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the > body of a message to majord...@vger.kernel.org More > majordomo info at http://vger.kernel.org/majordomo-info.html >
RE: [RFC PATCH v2 3/4] btrfs-progs: Modify rootdir files when use mkfs.btrfs
> -Original Message- > From: David Sterba [mailto:dste...@suse.cz] > Sent: Saturday, February 03, 2018 2:11 AM > To: Gu, Jinxiang/顾 金香 <g...@cn.fujitsu.com> > Cc: linux-btrfs@vger.kernel.org; dste...@suse.cz; quwenruo.bt...@gmx.com > Subject: Re: [RFC PATCH v2 3/4] btrfs-progs: Modify rootdir files when use > mkfs.btrfs > > On Fri, Feb 02, 2018 at 04:34:04PM +0800, Gu Jinxiang wrote: > > Since there is no $TOP/Documentation file after package the testsuite. > > So use a common file that is usually exsits. > > > > Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> > > --- > > tests/misc-tests/002-uuid-rewrite/test.sh | 4 ++-- > > tests/misc-tests/003-zero-log/test.sh | 2 +- > > tests/mkfs-tests/004-rootdir-keeps-size/test.sh | 2 +- > > 3 files changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh > > b/tests/misc-tests/002-uuid-rewrite/test.sh > > index 158bda90..27341322 100755 > > --- a/tests/misc-tests/002-uuid-rewrite/test.sh > > +++ b/tests/misc-tests/002-uuid-rewrite/test.sh > > @@ -25,7 +25,7 @@ test_uuid_random() > > > > run_check $SUDO_HELPER $EXEC/mkfs.btrfs -f \ > > --uuid $origuuid \ > > - --rootdir $TOP/Documentation \ > > + --rootdir /lib/modules/`uname -r`/ \ > > As an easy source of filesystem data it's ok, maybe in the log term something > more deterministic should be implemented. The size of the > modules is unpredictable and may not fit on the filesystem and the test would > fail. > > The size of the Documentation/ is 388KiB on my system, the modules are > +260MiB, that also makes the test run longer for no reason. > I'll add Documentation into the list which will be add to tarball. And revert this patch. N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{�n谶�)��骅w*jg�报�茛j/�赇z罐���2���ㄨ��&�)摺�a囤���G���h��j:+v���w��佶
[RFC PATCH v2 0/4] Add support for export testsuits
Achieved: 1. export testsuit by: $ make EXPORT=/where/you/want/to/generate/tests.tar.gz package relative path and absolute path both be ok. Besides tests itself, fssum and btrfs-corrupt-block will also be included in tests.tar.gz, since misc and fsck tests depend on btrfs-corrupt-block, and misc tests depend on fssum. 2. after decompress tests.tar.gz, run test by: $ TEST=`MASK` ./mkfs-tests.sh and, without MASK also be ok. replenish: The directory Structure after decompress tests.tar.gz is: $ tar -xzvf ./tests.tar.gz $ ls tests fssum btrfs-corrupt-block Gu Jinxiang (4): btrfs-progs: Add package command for packaging tests btrfs-progs: Add EXEC represent path of executable file btrfs-progs: Modify rootdir files when use mkfs.btrfs btrfs-progs: Add readme for export testsuits Makefile | 4 ++ tests/README.md| 20 tests/cli-tests.sh | 5 ++ tests/cli-tests/001-btrfs/test.sh | 20 .../cli-tests/002-balance-full-no-filters/test.sh | 10 ++-- tests/cli-tests/003-fi-resize-args/test.sh | 30 +-- .../cli-tests/004-send-parent-multi-subvol/test.sh | 12 ++--- tests/cli-tests/005-qgroup-show/test.sh| 14 ++--- tests/cli-tests/006-qgroup-show-sync/test.sh | 14 ++--- tests/cli-tests/007-check-force/test.sh| 14 ++--- .../008-subvolume-get-set-default/test.sh | 20 tests/common | 16 +++--- tests/common.convert | 8 +-- tests/convert-tests.sh | 5 ++ .../004-ext2-backup-superblock-ranges/test.sh | 10 ++-- .../convert-tests/005-delete-all-rollback/test.sh | 2 +- .../007-unsupported-block-sizes/test.sh| 2 +- .../011-reiserfs-delete-all-rollback/test.sh | 2 +- .../015-no-rollback-after-balance/test.sh | 6 +-- tests/export-tests.sh | 28 ++ tests/fsck-tests.sh| 5 ++ tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 12 ++--- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- .../fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh| 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 10 ++-- tests/fsck-tests/025-file-extents/test.sh | 14 ++--- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh | 2 +- .../028-unaligned-super-dev-sizes/test.sh | 6 +-- tests/fuzz-tests.sh| 5 ++ .../fuzz-tests/001-simple-check-unmounted/test.sh | 2 +- tests/fuzz-tests/002-simple-image/test.sh | 2 +- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 12 ++--- tests/fuzz-tests/004-simple-dump-tree/test.sh | 2 +- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 +- tests/fuzz-tests/006-simple-tree-stats/test.sh | 2 +- tests/fuzz-tests/007-simple-super-recover/test.sh | 2 +- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 2 +- tests/fuzz-tests/009-simple-zero-log/test.sh | 2 +- tests/misc-tests.sh| 5 ++ tests/misc-tests/001-btrfstune-features/test.sh| 10 ++-- tests/misc-tests/002-uuid-rewrite/test.sh | 24 - tests/misc-tests/003-zero-log/test.sh | 18 +++ tests/misc-tests/004-shrink-fs/test.sh | 14 ++--- .../005-convert-progress-thread-crash/test.sh | 2 +- .../misc-tests/006-image-on-missing-device/test.sh | 10 ++-- tests/misc-tests/007-subvolume-sync/test.sh| 18 +++ tests/misc-tests/008-leaf-crossing-stripes/test.sh | 4 +- .../009-subvolume-sync-must-wait/test.sh | 22 .../010-convert-delete-ext2-subvol/test.sh | 10 ++-- tests/misc-tests/011-delete-missing-device/test.sh | 18 +++ tests/misc-tests/012-find-root-no-result/test.sh | 4 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 20 tests/misc-tests/014-filesystem-label/test.sh | 22 tests/misc-tests/015-dump-super-garbage/test.sh| 18 +++ tests/misc-tests/016-send-clone-src/test.sh| 12 ++--- .../017-recv-stream-malformatted/test.sh | 8 +-- tests/misc-tests/018-recv-end-of-stream/test.sh| 60 +++--- .../019-receive-clones-on-mounted-subvol/test.sh | 38 +++--- .../020-fix-superblock-corruption/test.sh | 8 +-- tests/misc-tests/021-image-multi-devices/test.sh | 6 +-- .../022-filesystem-du-on-empty-subvol/test.sh | 12 ++--- .../023
[RFC PATCH v2 2/4] btrfs-progs: Add EXEC represent path of executable file
Use EXEC instead of TOP to represent the path of excutable file. EXEC is set to TOP by default, but when there is no excutable file in TOP, use the path where btrfs is install as EXEC. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/cli-tests.sh | 5 ++ tests/cli-tests/001-btrfs/test.sh | 20 .../cli-tests/002-balance-full-no-filters/test.sh | 10 ++-- tests/cli-tests/003-fi-resize-args/test.sh | 30 +-- .../cli-tests/004-send-parent-multi-subvol/test.sh | 12 ++--- tests/cli-tests/005-qgroup-show/test.sh| 14 ++--- tests/cli-tests/006-qgroup-show-sync/test.sh | 14 ++--- tests/cli-tests/007-check-force/test.sh| 14 ++--- .../008-subvolume-get-set-default/test.sh | 20 tests/common | 16 +++--- tests/common.convert | 8 +-- tests/convert-tests.sh | 5 ++ .../004-ext2-backup-superblock-ranges/test.sh | 10 ++-- .../convert-tests/005-delete-all-rollback/test.sh | 2 +- .../007-unsupported-block-sizes/test.sh| 2 +- .../011-reiserfs-delete-all-rollback/test.sh | 2 +- .../015-no-rollback-after-balance/test.sh | 6 +-- tests/fsck-tests.sh| 5 ++ tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 12 ++--- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- .../fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh| 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 10 ++-- tests/fsck-tests/025-file-extents/test.sh | 14 ++--- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/027-tree-reloc-tree/test.sh | 2 +- .../028-unaligned-super-dev-sizes/test.sh | 6 +-- tests/fuzz-tests.sh| 5 ++ .../fuzz-tests/001-simple-check-unmounted/test.sh | 2 +- tests/fuzz-tests/002-simple-image/test.sh | 2 +- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 12 ++--- tests/fuzz-tests/004-simple-dump-tree/test.sh | 2 +- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 +- tests/fuzz-tests/006-simple-tree-stats/test.sh | 2 +- tests/fuzz-tests/007-simple-super-recover/test.sh | 2 +- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 2 +- tests/fuzz-tests/009-simple-zero-log/test.sh | 2 +- tests/misc-tests.sh| 5 ++ tests/misc-tests/001-btrfstune-features/test.sh| 10 ++-- tests/misc-tests/002-uuid-rewrite/test.sh | 20 tests/misc-tests/003-zero-log/test.sh | 16 +++--- tests/misc-tests/004-shrink-fs/test.sh | 14 ++--- .../005-convert-progress-thread-crash/test.sh | 2 +- .../misc-tests/006-image-on-missing-device/test.sh | 10 ++-- tests/misc-tests/007-subvolume-sync/test.sh| 18 +++ tests/misc-tests/008-leaf-crossing-stripes/test.sh | 4 +- .../009-subvolume-sync-must-wait/test.sh | 22 .../010-convert-delete-ext2-subvol/test.sh | 10 ++-- tests/misc-tests/011-delete-missing-device/test.sh | 18 +++ tests/misc-tests/012-find-root-no-result/test.sh | 4 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 20 tests/misc-tests/014-filesystem-label/test.sh | 22 tests/misc-tests/015-dump-super-garbage/test.sh| 18 +++ tests/misc-tests/016-send-clone-src/test.sh| 12 ++--- .../017-recv-stream-malformatted/test.sh | 8 +-- tests/misc-tests/018-recv-end-of-stream/test.sh| 60 +++--- .../019-receive-clones-on-mounted-subvol/test.sh | 38 +++--- .../020-fix-superblock-corruption/test.sh | 8 +-- tests/misc-tests/021-image-multi-devices/test.sh | 6 +-- .../022-filesystem-du-on-empty-subvol/test.sh | 12 ++--- .../023-device-usage-with-missing-device/test.sh | 10 ++-- .../misc-tests/024-inspect-internal-rootid/test.sh | 24 - tests/misc-tests/025-zstd-compression/test.sh | 6 +-- .../026-image-non-printable-chars/test.sh | 8 +-- .../027-subvol-list-deleted-toplevel/test.sh | 6 +-- tests/mkfs-tests.sh| 5 ++ tests/mkfs-tests/001-basic-profiles/test.sh| 12 ++--- .../002-no-force-mixed-on-small-volume/test.sh | 2 +- .../003-mixed-with-wrong-nodesize/test.sh | 2 +- tests/mkfs-tests/004-rootdir-keeps-size/test.sh| 4 +- .../005-long-device-name-for-ssd/test.sh | 4 +- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 4 +- .../mkfs-tests/007-mix-no
[RFC PATCH v2 4/4] btrfs-progs: Add readme for export testsuits
Add the readme of command for export testsuits. And add the excute method of exported testsuits. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/README.md | 20 1 file changed, 20 insertions(+) diff --git a/tests/README.md b/tests/README.md index 04d2ce2a..9f4c01ac 100644 --- a/tests/README.md +++ b/tests/README.md @@ -48,6 +48,26 @@ $ TEST=001\* ./fsck-tests.sh will run the first test in fsck-tests subdirectory. +## Package testsuit + +The tests can be export as a tests.tar.gz into path given. Use: + +```shell +$ make EXPORT=PATH package +``` + +where `PATH` is a directory where tests.tar.gz be genereated. +Here comes handy: + +```shell +$ make EXPORT=/home/user/ package +$ make EXPORT=../../dir/ package +``` + +And, after decompress tests.tar.gz, test can be run selectively +from `tests/` directory introduced above. + + ## Test structure *tests/fsck-tests/:* -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[RFC PATCH v2 3/4] btrfs-progs: Modify rootdir files when use mkfs.btrfs
Since there is no $TOP/Documentation file after package the testsuite. So use a common file that is usually exsits. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- tests/misc-tests/002-uuid-rewrite/test.sh | 4 ++-- tests/misc-tests/003-zero-log/test.sh | 2 +- tests/mkfs-tests/004-rootdir-keeps-size/test.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 158bda90..27341322 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -25,7 +25,7 @@ test_uuid_random() run_check $SUDO_HELPER $EXEC/mkfs.btrfs -f \ --uuid $origuuid \ - --rootdir $TOP/Documentation \ + --rootdir /lib/modules/`uname -r`/ \ $TEST_DEV run_check $EXEC/btrfs inspect-internal dump-super "$TEST_DEV" currentfsid=$(run_check_stdout $EXEC/btrfstune -f -u $TEST_DEV | \ @@ -47,7 +47,7 @@ test_uuid_user() run_check $SUDO_HELPER $EXEC/mkfs.btrfs -f \ --uuid $origuuid \ - --rootdir $TOP/Documentation \ + --rootdir /lib/modules/`uname -r`/ \ $TEST_DEV run_check $EXEC/btrfs inspect-internal dump-super "$TEST_DEV" run_check $EXEC/btrfstune -f -U $newuuid \ diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index 0f3d3cd6..db1b1c67 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -27,7 +27,7 @@ test_zero_log() { # FIXME: we need an image with existing log_root run_check $SUDO_HELPER $EXEC/mkfs.btrfs -f \ - --rootdir $TOP/Documentation \ + --rootdir /lib/modules/`uname -r`/ \ $TEST_DEV run_check $EXEC/btrfs inspect-internal dump-super $TEST_DEV if [ "$1" = 'standalone' ]; then diff --git a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh index c8d920a5..3c53a1a7 100755 --- a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh +++ b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh @@ -16,7 +16,7 @@ test_mkfs_with_size() { run_check truncate -s$size $TEST_DEV imgsize=$(run_check_stdout stat --format=%s $TEST_DEV) run_check $SUDO_HELPER $EXEC/mkfs.btrfs -f \ - --rootdir $EXEC/Documentation \ + --rootdir /lib/modules/`uname -r`/ \ $TEST_DEV tmp=$(run_check_stdout stat --format=%s $TEST_DEV) if ! [ "$imgsize" = "$tmp" ]; then -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[RFC PATCH v2 1/4] btrfs-progs: Add package command for packaging tests
Export the testsuite files to a separate tar. Since fsck tests depend on btrfs-corrupt-block, and misc tests depends on both btrfs-corrupt-block and fssum, so set it as prerequisites for package commad. Because, althougth fssum can be generated by source that are all in tests directory, and has no rely on the btrfs's structure. But btrfs-corrupt-block deeply relys on btrfs's structure. For consistency, at the present stage, generete the two when create test tar. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> --- Makefile | 4 tests/export-tests.sh | 28 2 files changed, 32 insertions(+) create mode 100755 tests/export-tests.sh diff --git a/Makefile b/Makefile index 6369e8f4..23decc4d 100644 --- a/Makefile +++ b/Makefile @@ -333,6 +333,10 @@ test-inst: all test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli +package: btrfs-corrupt-block fssum + @echo "Export tests as a package" + $(Q)bash tests/export-tests.sh + # # NOTE: For static compiles, you need to have all the required libs # static equivalent available diff --git a/tests/export-tests.sh b/tests/export-tests.sh new file mode 100755 index ..d7f6ca17 --- /dev/null +++ b/tests/export-tests.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# export the testsuite files to a separate tar + +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TESTDIR=$(basename $SCRIPT_DIR) +FSSUM=fssum +CORRUPT=btrfs-corrupt-block +DESTNAME="tests.tar.gz" +DESTDIR="." + +test -n "$EXPORT" && DESTDIR=$(realpath "$EXPORT") +if [ ! -d $DESTDIR ]; then + echo "dest directory is not exsit." + exit 1 +fi + +DEST=$DESTDIR/$DESTNAME + +if [ -f $DEST ];then + echo "remove exsit package: " $DEST + rm $DEST +fi + +echo "begin create tar: " $DEST +tar --exclude-vcs-ignores -zScf $DEST $TESTDIR $FSSUM $CORRUPT +if [ $? -eq 0 ]; then + echo "create tar successfully." +fi -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH] btrfs: volumes: Cleanup stripe size calculation
> -Original Message- > From: linux-btrfs-ow...@vger.kernel.org > [mailto:linux-btrfs-ow...@vger.kernel.org] > On Behalf Of Qu Wenruo > Sent: Wednesday, January 31, 2018 2:17 PM > To: linux-btrfs@vger.kernel.org; dste...@suse.cz > Subject: [PATCH] btrfs: volumes: Cleanup stripe size calculation > > Cleanup the following things: > 1) open coded SZ_16M round up > 2) use min() to replace open-coded size comparison > 3) code style > > Signed-off-by: Qu Wenruo <w...@suse.com> > --- > fs/btrfs/volumes.c | 11 +-- > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index > cb0a8d27661b..90ad716d2b50 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -4761,18 +4761,17 @@ static int __btrfs_alloc_chunk(struct > btrfs_trans_handle > *trans, >* and compare that answer with the max chunk size >*/ > if (stripe_size * data_stripes > max_chunk_size) { > - u64 mask = (1ULL << 24) - 1; > - > stripe_size = div_u64(max_chunk_size, data_stripes); > > /* bump the answer up to a 16MB boundary */ > - stripe_size = (stripe_size + mask) & ~mask; > + stripe_size = round_up(stripe_size, SZ_16M); > > - /* but don't go higher than the limits we found > + /* > + * but don't go higher than the limits we found >* while searching for free extents >*/ > - if (stripe_size > devices_info[ndevs-1].max_avail) > - stripe_size = devices_info[ndevs-1].max_avail; > + stripe_size = min(devices_info[ndevs - 1].max_avail, > + stripe_size); > } > > stripe_size = div_u64(stripe_size, dev_stripes); > -- Reviewed-by: Gu Jinxiang <g...@cn.fujitsu.com> > 2.16.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the > body of a > message to majord...@vger.kernel.org More majordomo info at > http://vger.kernel.org/majordomo-info.html >
[PATCH v3 7/7] btrfs-progs: Cleanup use of root in leaf_data_end
In function leaf_data_end, root is just used to get fs_info, so change the parameter of this function from btrfs_root to btrfs_fs_info. And also make it consistent with kernel. Changelog: v3->v2: Add const to parameter leaf of function btrfs_item_offset_nr to keep type consistent with leaf_data_end. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> Reviewed-by: Qu Wenruo <w...@suse.com> --- ctree.c | 32 +--- ctree.h | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ctree.c b/ctree.c index 4efc96f..45b368c 100644 --- a/ctree.c +++ b/ctree.c @@ -408,12 +408,12 @@ static int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2) * this returns the address of the start of the last item, * which is the stop of the leaf data stack */ -static inline unsigned int leaf_data_end(struct btrfs_root *root, -struct extent_buffer *leaf) +static inline unsigned int leaf_data_end(const struct btrfs_fs_info *fs_info, +const struct extent_buffer *leaf) { u32 nr = btrfs_header_nritems(leaf); if (nr == 0) - return BTRFS_LEAF_DATA_SIZE(root->fs_info); + return BTRFS_LEAF_DATA_SIZE(fs_info); return btrfs_item_offset_nr(leaf, nr - 1); } @@ -1735,10 +1735,10 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root right_nritems = btrfs_header_nritems(right); push_space = btrfs_item_end_nr(left, left_nritems - push_items); - push_space -= leaf_data_end(root, left); + push_space -= leaf_data_end(fs_info, left); /* make room in the right data area */ - data_end = leaf_data_end(root, right); + data_end = leaf_data_end(fs_info, right); memmove_extent_buffer(right, btrfs_leaf_data(right) + data_end - push_space, btrfs_leaf_data(right) + data_end, @@ -1747,7 +1747,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root /* copy from the left data area */ copy_extent_buffer(right, left, btrfs_leaf_data(right) + BTRFS_LEAF_DATA_SIZE(root->fs_info) - push_space, -btrfs_leaf_data(left) + leaf_data_end(root, left), +btrfs_leaf_data(left) + leaf_data_end(fs_info, left), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(push_items), @@ -1885,7 +1885,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root btrfs_item_offset_nr(right, push_items -1); copy_extent_buffer(left, right, btrfs_leaf_data(left) + -leaf_data_end(root, left) - push_space, +leaf_data_end(fs_info, left) - push_space, btrfs_leaf_data(right) + btrfs_item_offset_nr(right, push_items - 1), push_space); @@ -1912,12 +1912,13 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root if (push_items < right_nritems) { push_space = btrfs_item_offset_nr(right, push_items - 1) - - leaf_data_end(root, right); + leaf_data_end(fs_info, right); memmove_extent_buffer(right, btrfs_leaf_data(right) + BTRFS_LEAF_DATA_SIZE(root->fs_info) - push_space, btrfs_leaf_data(right) + - leaf_data_end(root, right), push_space); + leaf_data_end(fs_info, right), + push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(0), btrfs_item_nr_offset(push_items), @@ -1976,7 +1977,8 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans, nritems = nritems - mid; btrfs_set_header_nritems(right, nritems); - data_copy_size = btrfs_item_end_nr(l, mid) - leaf_data_end(root, l); + data_copy_size = btrfs_item_end_nr(l, mid) - + leaf_data_end(root->fs_info, l); copy_extent_buffer(right, l, btrfs_item_nr_offset(0), btrfs_item_nr_offset(mid), @@ -1986,7 +1988,7 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans, btrfs_leaf_data(right) + BTRFS_LEAF_DATA_SIZE(root->fs_info) - data_copy_size, btrfs_leaf_data(l) + -leaf_data_end(root, l), data_copy_size); +leaf_data_end(root->fs_info, l), data_copy_size); rt_data_off = BTRFS_LEAF_DATA_SIZE(root->fs_info) -
[PATCH v3 3/7] btrfs-progs: Sync code with kernel for BTRFS_MAX_INLINE_DATA_SIZE
Do a cleanup. Also make it consistent with kernel. Use fs_info instead of root for BTRFS_MAX_INLINE_DATA_SIZE, since maybe in some situation we do not know root, but just know fs_info. Changelog: v2->v1: Change macro to inline function to be consistent with kernel. And change the function body to match kernel. v3->v2: Change the title of this commit to make it more exact. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> Reviewed-by: Qu Wenruo <w...@suse.com> --- convert/source-ext2.c | 2 +- convert/source-reiserfs.c | 2 +- ctree.h | 17 ++--- mkfs/main.c | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/convert/source-ext2.c b/convert/source-ext2.c index e5c2a94..f5ecd8c 100644 --- a/convert/source-ext2.c +++ b/convert/source-ext2.c @@ -309,7 +309,7 @@ static int ext2_create_file_extents(struct btrfs_trans_handle *trans, goto fail; if ((convert_flags & CONVERT_FLAG_INLINE_DATA) && data.first_block == 0 && data.num_blocks > 0 - && inode_size <= BTRFS_MAX_INLINE_DATA_SIZE(root)) { + && inode_size <= BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info)) { u64 num_bytes = data.num_blocks * sectorsize; u64 disk_bytenr = data.disk_block * sectorsize; u64 nbytes; diff --git a/convert/source-reiserfs.c b/convert/source-reiserfs.c index e3582bd..39d6f07 100644 --- a/convert/source-reiserfs.c +++ b/convert/source-reiserfs.c @@ -376,7 +376,7 @@ static int reiserfs_convert_tail(struct btrfs_trans_handle *trans, u64 isize; int ret; - if (length >= BTRFS_MAX_INLINE_DATA_SIZE(root)) + if (length >= BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info)) return convert_direct(trans, root, objectid, inode, body, length, offset, convert_flags); diff --git a/ctree.h b/ctree.h index f3964f1..7be48e2 100644 --- a/ctree.h +++ b/ctree.h @@ -359,9 +359,6 @@ struct btrfs_header { #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) #define BTRFS_LEAF_DATA_SIZE(fs_info) \ (__BTRFS_LEAF_DATA_SIZE(fs_info->nodesize)) -#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r->fs_info) - \ - sizeof(struct btrfs_item) - \ - sizeof(struct btrfs_file_extent_item)) #define BTRFS_MAX_XATTR_SIZE(r)(BTRFS_LEAF_DATA_SIZE(r->fs_info) - \ sizeof(struct btrfs_item) -\ sizeof(struct btrfs_dir_item)) @@ -1188,10 +1185,24 @@ struct btrfs_root { struct rb_node rb_node; }; +static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info) +{ + return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item); +} + static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info) { return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr); } + +#define BTRFS_FILE_EXTENT_INLINE_DATA_START\ + (offsetof(struct btrfs_file_extent_item, disk_bytenr)) +static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info) +{ + return BTRFS_MAX_ITEM_SIZE(info) - + BTRFS_FILE_EXTENT_INLINE_DATA_START; +} + /* * inode items have the data typically returned from stat and store other * info about object characteristics. There is one for every file and dir in diff --git a/mkfs/main.c b/mkfs/main.c index d817ad8..a301efc 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -498,7 +498,7 @@ static int fill_inode_item(struct btrfs_trans_handle *trans, } if (S_ISREG(src->st_mode)) { btrfs_set_stack_inode_size(dst, (u64)src->st_size); - if (src->st_size <= BTRFS_MAX_INLINE_DATA_SIZE(root)) + if (src->st_size <= BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info)) btrfs_set_stack_inode_nbytes(dst, src->st_size); else { blocks = src->st_size / sectorsize; @@ -686,7 +686,7 @@ static int add_file_items(struct btrfs_trans_handle *trans, if (st->st_size % sectorsize) blocks += 1; - if (st->st_size <= BTRFS_MAX_INLINE_DATA_SIZE(root)) { + if (st->st_size <= BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info)) { char *buffer = malloc(st->st_size); if (!buffer) { -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 2/7] btrfs-progs: Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK
Do a cleanup. Also make it consistent with kernel. Use fs_info instead of root for BTRFS_NODEPTRS_PER_BLOCK, since maybe in some situation we do not know root, but just know fs_info. Changelog: v2->v1: To be consistent with kernel, change macro to inline function. Signed-off-by: Gu Jinxiang <g...@cn.fujitsu.com> Reviewed-by: Qu Wenruo <w...@suse.com> --- cmds-check.c | 4 ++-- ctree.c | 18 +- ctree.h | 7 --- print-tree.c | 2 +- quick-test.c | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 8d54564..5495dbe 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -2517,7 +2517,7 @@ static void account_bytes(struct btrfs_root *root, struct btrfs_path *path, if (level == 0) { btree_space_waste += btrfs_leaf_free_space(root, eb); } else { - free_nrs = (BTRFS_NODEPTRS_PER_BLOCK(root) - + free_nrs = (BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - btrfs_header_nritems(eb)); btree_space_waste += free_nrs * sizeof(struct btrfs_key_ptr); } @@ -9475,7 +9475,7 @@ static int run_next_block(struct btrfs_root *root, add_pending(pending, seen, ptr, size); } } - btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(root) - + btree_space_waste += (BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nritems) * sizeof(struct btrfs_key_ptr); } total_btree_bytes += buf->len; diff --git a/ctree.c b/ctree.c index 6d130f5..4efc96f 100644 --- a/ctree.c +++ b/ctree.c @@ -427,7 +427,7 @@ btrfs_check_node(struct btrfs_root *root, struct btrfs_disk_key *parent_key, u32 nritems = btrfs_header_nritems(buf); enum btrfs_tree_block_status ret = BTRFS_TREE_BLOCK_INVALID_NRITEMS; - if (nritems == 0 || nritems > BTRFS_NODEPTRS_PER_BLOCK(root)) + if (nritems == 0 || nritems > BTRFS_NODEPTRS_PER_BLOCK(root->fs_info)) goto fail; ret = BTRFS_TREE_BLOCK_INVALID_PARENT_KEY; @@ -714,7 +714,7 @@ static int balance_level(struct btrfs_trans_handle *trans, return ret; } if (btrfs_header_nritems(mid) > - BTRFS_NODEPTRS_PER_BLOCK(root) / 4) + BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4) return 0; left = read_node_slot(fs_info, parent, pslot - 1); @@ -882,7 +882,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans, if (extent_buffer_uptodate(left)) { u32 left_nr; left_nr = btrfs_header_nritems(left); - if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) { + if (left_nr >= BTRFS_NODEPTRS_PER_BLOCK(fs_info) - 1) { wret = 1; } else { ret = btrfs_cow_block(trans, root, left, parent, @@ -925,7 +925,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans, if (extent_buffer_uptodate(right)) { u32 right_nr; right_nr = btrfs_header_nritems(right); - if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root) - 1) { + if (right_nr >= BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - 1) { wret = 1; } else { ret = btrfs_cow_block(trans, root, right, @@ -1144,7 +1144,7 @@ again: p->slots[level] = slot; if ((p->search_for_split || ins_len > 0) && btrfs_header_nritems(b) >= - BTRFS_NODEPTRS_PER_BLOCK(root) - 3) { + BTRFS_NODEPTRS_PER_BLOCK(fs_info) - 3) { int sret = split_node(trans, root, p, level); BUG_ON(sret > 0); if (sret) @@ -1290,7 +1290,7 @@ static int push_node_left(struct btrfs_trans_handle *trans, src_nritems = btrfs_header_nritems(src); dst_nritems = btrfs_header_nritems(dst); - push_items = BTRFS_NODEPTRS_PER_BLOCK(root) - dst_nritems; + push_items = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - dst_nritems; WARN_ON(btrfs_header_generation(src) != trans->transid); WARN_ON(btrfs_header_generation(dst) != trans->transid); @@ -1360,7 +1360,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans, src_nritems = btrfs_header_nritems(src); dst_nritems = btrfs_header_nritems(dst); - push_items = BTRFS_NODEPTRS_PER_BLOCK(root) - dst_nritems; + push_items = BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - dst_nritems; if (push_items <= 0) { return 1; } @@ -1488,7 +1488,7 @@ static int insert_ptr(struct btrf