All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Satoru Takeuchi <satoru.takeuchi@gmail.com>,
	linux-btrfs@vger.kernel.org, dsterba@suse.cz, rich@shroop.net,
	rrauenza@gmail.com
Subject: Re: [PATCH] btrfs: Remove WARN_ON for unaligned device created before v4.13 and adds more user friendly output
Date: Thu, 19 Oct 2017 19:50:23 +0200	[thread overview]
Message-ID: <20171019175023.GP3521@twin.jikos.cz> (raw)
In-Reply-To: <ef36c960-d313-84ee-0bf7-fe716b0f73f9@gmx.com>

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.

      reply	other threads:[~2017-10-19 17:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-20  6:18 [PATCH] btrfs: Remove WARN_ON for unaligned device created before v4.13 and adds more user friendly output Qu Wenruo
2017-09-23  1:19 ` Satoru Takeuchi
2017-09-23  1:27   ` Satoru Takeuchi
2017-09-23  7:22     ` Qu Wenruo
2017-10-19 17:50       ` David Sterba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171019175023.GP3521@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=rich@shroop.net \
    --cc=rrauenza@gmail.com \
    --cc=satoru.takeuchi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.