On 2018/10/5 下午4:55, Nikolay Borisov wrote:
>
>
> On 5.10.2018 11:25, Qu Wenruo wrote:
>> Add extra dev extent end check against device boundary.
>>
>> Signed-off-by: Qu Wenruo <wqu@xxxxxxxx>
>> ---
>> fs/btrfs/volumes.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index bf0b2c16847a..9fb40e30be6a 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -7492,6 +7492,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
>> while (1) {
>> struct extent_buffer *leaf = path->nodes[0];
>> struct btrfs_dev_extent *dext;
>> + struct btrfs_device *dev;
>> int slot = path->slots[0];
>> u64 chunk_offset;
>> u64 physical_offset;
>> @@ -7517,6 +7518,22 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
>> goto out;
>> }
>>
>> + /* Make sure no dev extent is beyond device bondary */
>> + dev = btrfs_find_device(fs_info, devid, NULL, NULL);
>> + if (!dev) {
>> + btrfs_err(fs_info, "failed to find devid %llu", devid);
>> + ret = -EUCLEAN;
>> + goto out;
>> + }
>> + if (physical_offset + physical_len > dev->disk_total_bytes) {
>> + btrfs_err(fs_info,
>> +"dev extent devid %llu physical offset %llu len %llu is beyond device boundary %llu",
>> + devid, physical_offset, physical_len,
>> + dev->disk_total_bytes);
>> + ret = -EUCLEAN;
>> + goto out;
>> + }
>
> Why not move this code in verify_one_dev_extent, you already have all
> the necessary context in there - devid and physical_len/physical_offset,
> let's avoid scattering logically related code in different places. ?
Right, this part could be moved into verify_one_dev_extent().
It will go that way in next update.
Thanks,
Qu
>
>> +
>> ret = verify_one_dev_extent(fs_info, chunk_offset, devid,
>> physical_offset, physical_len);
>> if (ret < 0)
>>