On Sat, Sep 23, 2017 at 03:22:36PM +0800, Qu Wenruo wrote:
> >>> --- a/fs/btrfs/volumes.c
> >>> +++ b/fs/btrfs/volumes.c
> >>> @@ -6472,15 +6472,23 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
> >>> return 0;
> >>> }
> >>>
> >>> -static void fill_device_from_item(struct extent_buffer *leaf,
> >>> - struct btrfs_dev_item *dev_item,
> >>> - struct btrfs_device *device)
> >>> +static void fill_device_from_item(struct btrfs_fs_info *fs_info,
> >>> + struct extent_buffer *leaf,
> >>> + struct btrfs_dev_item *dev_item,
> >>> + struct btrfs_device *device)
> >>> {
> >>> unsigned long ptr;
> >>>
> >>> device->devid = btrfs_device_id(leaf, dev_item);
> >>> device->disk_total_bytes = btrfs_device_total_bytes(leaf, dev_item);
> >>> device->total_bytes = device->disk_total_bytes;
> >>> + if (!IS_ALIGNED(device->total_bytes, fs_info->sectorsize)) {
> >>> + btrfs_warn(fs_info,
> >>> + "devid %llu has unaligned total bytes %llu",
> >>> + device->devid, device->disk_total_bytes);
> >>> + btrfs_warn(fs_info,
> >>> + "please shrink the device a little and resize back to fix it");
> >>> + }
> >>
> >> How about telling uses to know device->total_bytes should be alligned
> >> to fs_info->sectorsize here?
> >>
> >> Thanks,
> >
> > I should make my comment clearer, sorry.
> >
> > ===
> > + if (!IS_ALIGNED(device->total_bytes, fs_info->sectorsize)) {
> > + btrfs_warn(fs_info,
> > + "devid %llu: total bytes %llu should be aligned to %u bytes",
> > + device->devid, device->disk_total_bytes, fs_info->sectorsize);
> > + btrfs_warn(fs_info,
> > + "please shrink the device a little and resize back to fix it");
> > + }
> > ===
>
> That's better.
>
> But I'm also considering modifying the total_bytes directly here.
Yeah, I think it would be better to fix here, without a warning even.
The rounding error is below 4k and nodesize, we would never use this
space for block groups so no accidental data loss.
> So that any time DEV_ITEM and super block get updated, new aligned value
> will be written back to disk, and since the value is aligned in memory,
> it won't cause WARN_ON() any longer.
>
> I'll test and check the code for confirmation before updating the patch.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html