public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] xfs: don't allow log writes if the data device is readonly
Date: Fri, 30 Apr 2021 09:32:48 -0400	[thread overview]
Message-ID: <YIwHAGXOZSO+DnBw@bfoster> (raw)
In-Reply-To: <20210430004012.GO3122264@magnolia>

On Thu, Apr 29, 2021 at 05:40:12PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> While running generic/050 with an external log, I observed this warning
> in dmesg:
> 
> Trying to write to read-only block-device sda4 (partno 4)
> WARNING: CPU: 2 PID: 215677 at block/blk-core.c:704 submit_bio_checks+0x256/0x510
> Call Trace:
>  submit_bio_noacct+0x2c/0x430
>  _xfs_buf_ioapply+0x283/0x3c0 [xfs]
>  __xfs_buf_submit+0x6a/0x210 [xfs]
>  xfs_buf_delwri_submit_buffers+0xf8/0x270 [xfs]
>  xfsaild+0x2db/0xc50 [xfs]
>  kthread+0x14b/0x170
> 
> I think this happened because we tried to cover the log after a readonly
> mount, and the AIL tried to write the primary superblock to the data
> device.  The test marks the data device readonly, but it doesn't do the
> same to the external log device.  Therefore, XFS thinks that the log is
> writable, even though AIL writes whine to dmesg because the data device
> is read only.
> 
> Fix this by amending xfs_log_writable to prevent writes when the AIL
> can't possible write anything into the filesystem.
> 
> Note: As for the external log or the rt devices being readonly--
> xfs_blkdev_get will complain about that if we aren't doing a norecovery
> mount.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  fs/xfs/xfs_log.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
> index 06041834daa3..e4839f22ec07 100644
> --- a/fs/xfs/xfs_log.c
> +++ b/fs/xfs/xfs_log.c
> @@ -358,12 +358,14 @@ xfs_log_writable(
>  	 * Never write to the log on norecovery mounts, if the block device is
>  	 * read-only, or if the filesystem is shutdown. Read-only mounts still
>  	 * allow internal writes for log recovery and unmount purposes, so don't
> -	 * restrict that case here.
> +	 * restrict that case here unless the data device is also readonly.
>  	 */

The comment update is a little confusing because that second sentence
explicitly refers to the read-only mount case (i.e., why we don't check
XFS_MOUNT_RDONLY here), and that logic/reasoning remains independent of
this change. Perhaps instead change the first part to something like
"... if the data or log device is read-only, ..." ?

With that fixed up:

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  	if (mp->m_flags & XFS_MOUNT_NORECOVERY)
>  		return false;
>  	if (xfs_readonly_buftarg(mp->m_log->l_targ))
>  		return false;
> +	if (xfs_readonly_buftarg(mp->m_ddev_targp))
> +		return false;
>  	if (XFS_FORCED_SHUTDOWN(mp))
>  		return false;
>  	return true;
> 


  reply	other threads:[~2021-04-30 13:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30  0:40 [PATCH] xfs: don't allow log writes if the data device is readonly Darrick J. Wong
2021-04-30 13:32 ` Brian Foster [this message]
2021-04-30 15:14   ` Darrick J. Wong
2021-04-30 15:15 ` [PATCH v2] " Darrick J. Wong

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=YIwHAGXOZSO+DnBw@bfoster \
    --to=bfoster@redhat.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox