All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 5/8] xfs: recheck reflink state after grabbing ILOCK_SHARED for a write
Date: Thu, 21 Jun 2018 11:31:35 -0700	[thread overview]
Message-ID: <152960589497.26246.2694743986896972501.stgit@magnolia> (raw)
In-Reply-To: <152960586416.26246.8634761888260524091.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

The reflink iflag could have changed since the earlier unlocked check,
so if we got ILOCK_SHARED for a write and but we're now a reflink inode
we have to switch to ILOCK_EXCL and relock.

This helps us avoid blowing lock assertions in things like generic/166:

XFS: Assertion failed: xfs_isilocked(ip, XFS_ILOCK_EXCL), file: fs/xfs/xfs_reflink.c, line: 383
WARNING: CPU: 1 PID: 24707 at fs/xfs/xfs_message.c:104 assfail+0x25/0x30 [xfs]
Modules linked in: deadline_iosched dm_snapshot dm_bufio ext4 mbcache jbd2 dm_flakey xfs libcrc32c dax_pmem device_dax nd_pmem sch_fq_codel af_packet [last unloaded: scsi_debug]
CPU: 1 PID: 24707 Comm: xfs_io Not tainted 4.18.0-rc1-djw #1
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.10.2-1ubuntu1 04/01/2014
RIP: 0010:assfail+0x25/0x30 [xfs]
Code: ff 0f 0b c3 90 66 66 66 66 90 48 89 f1 41 89 d0 48 c7 c6 e8 ef 1b a0 48 89 fa 31 ff e8 54 f9 ff ff 80 3d fd ba 0f 00 00 75 03 <0f> 0b c3 0f 0b 66 0f 1f 44 00 00 66 66 66 66 90 48 63 f6 49 89 f9
RSP: 0018:ffffc90006423ad8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffff880030b65e80 RCX: 0000000000000000
RDX: 00000000ffffffc0 RSI: 000000000000000a RDI: ffffffffa01b0447
RBP: ffffc90006423c10 R08: 0000000000000000 R09: 0000000000000000
R10: ffff88003d43fc30 R11: f000000000000000 R12: ffff880077cda000
R13: 0000000000000000 R14: ffffc90006423c30 R15: ffffc90006423bf9
FS:  00007feba8986800(0000) GS:ffff88003ec00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000138ab58 CR3: 000000003d40a000 CR4: 00000000000006a0
Call Trace:
 xfs_reflink_allocate_cow+0x24c/0x3d0 [xfs]
 xfs_file_iomap_begin+0x6d2/0xeb0 [xfs]
 ? iomap_to_fiemap+0x80/0x80
 iomap_apply+0x5e/0x130
 iomap_dio_rw+0x2e0/0x400
 ? iomap_to_fiemap+0x80/0x80
 ? xfs_file_dio_aio_write+0x133/0x4a0 [xfs]
 xfs_file_dio_aio_write+0x133/0x4a0 [xfs]
 xfs_file_write_iter+0x7b/0xb0 [xfs]
 __vfs_write+0x16f/0x1f0
 vfs_write+0xc8/0x1c0
 ksys_pwrite64+0x74/0x90
 do_syscall_64+0x56/0x180
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_iomap.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)


diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 49f5492eed3b..55876dd02f0c 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -963,12 +963,13 @@ xfs_ilock_for_iomap(
 	unsigned		*lockmode)
 {
 	unsigned		mode = XFS_ILOCK_SHARED;
+	bool			is_write = flags & (IOMAP_WRITE | IOMAP_ZERO);
 
 	/*
 	 * COW writes may allocate delalloc space or convert unwritten COW
 	 * extents, so we need to make sure to take the lock exclusively here.
 	 */
-	if (xfs_is_reflink_inode(ip) && (flags & (IOMAP_WRITE | IOMAP_ZERO))) {
+	if (xfs_is_reflink_inode(ip) && is_write) {
 		/*
 		 * FIXME: It could still overwrite on unshared extents and not
 		 * need allocation.
@@ -989,6 +990,7 @@ xfs_ilock_for_iomap(
 		mode = XFS_ILOCK_EXCL;
 	}
 
+relock:
 	if (flags & IOMAP_NOWAIT) {
 		if (!xfs_ilock_nowait(ip, mode))
 			return -EAGAIN;
@@ -996,6 +998,17 @@ xfs_ilock_for_iomap(
 		xfs_ilock(ip, mode);
 	}
 
+	/*
+	 * The reflink iflag could have changed since the earlier unlocked
+	 * check, so if we got ILOCK_SHARED for a write and but we're now a
+	 * reflink inode we have to switch to ILOCK_EXCL and relock.
+	 */
+	if (mode == XFS_ILOCK_SHARED && is_write && xfs_is_reflink_inode(ip)) {
+		xfs_iunlock(ip, mode);
+		mode = XFS_ILOCK_EXCL;
+		goto relock;
+	}
+
 	*lockmode = mode;
 	return 0;
 }


  parent reply	other threads:[~2018-06-21 18:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-21 18:31 [PATCH 0/8] xfs-4.18: various fixes Darrick J. Wong
2018-06-21 18:31 ` [PATCH 1/8] xfs: allow empty transactions while frozen Darrick J. Wong
2018-06-22  6:18   ` Allison Henderson
2018-06-22  6:31   ` Christoph Hellwig
2018-06-21 18:31 ` [PATCH 2/8] xfs: fix fdblocks accounting w/ RMAPBT per-AG reservation Darrick J. Wong
2018-06-22  6:21   ` Allison Henderson
2018-06-21 18:31 ` [PATCH 3/8] xfs: don't trip over negative free space in xfs_reserve_blocks Darrick J. Wong
2018-06-22  6:31   ` Christoph Hellwig
2018-06-22  6:32   ` Allison Henderson
2018-06-21 18:31 ` [PATCH 4/8] xfs: don't allow insert-range to shift extents past the maximum offset Darrick J. Wong
2018-06-22  6:33   ` Allison Henderson
2018-06-22  6:39   ` Christoph Hellwig
2018-06-22  6:47     ` Darrick J. Wong
2018-06-22 21:21   ` [PATCH v2 " Darrick J. Wong
2018-06-23  6:47     ` Christoph Hellwig
2018-06-21 18:31 ` Darrick J. Wong [this message]
2018-06-22  6:40   ` [PATCH 5/8] xfs: recheck reflink state after grabbing ILOCK_SHARED for a write Christoph Hellwig
2018-06-21 18:31 ` [PATCH 6/8] xfs: fix uninitialized field in rtbitmap fsmap backend Darrick J. Wong
2018-06-22  6:37   ` Allison Henderson
2018-06-22  6:41   ` Christoph Hellwig
2018-06-22  6:47     ` Darrick J. Wong
2018-06-22 21:22   ` [PATCH v2 " Darrick J. Wong
2018-06-23  6:47     ` Christoph Hellwig
2018-06-21 18:31 ` [PATCH 7/8] xfs: fix off-by-one error in xfs_rtalloc_query_range Darrick J. Wong
2018-06-22  6:41   ` Christoph Hellwig
2018-06-22  6:41   ` Allison Henderson
2018-06-21 18:31 ` [PATCH 8/8] xfs: ensure post-EOF zeroing happens after zeroing part of a file Darrick J. Wong
2018-06-22  6:29   ` Christoph Hellwig
2018-06-22  6:49     ` Darrick J. Wong
2018-06-22  6:42   ` Allison Henderson
2018-06-22  6:21 ` [PATCH 9/8] xfs: check leaf attribute block freemap in verifier Darrick J. Wong
2018-06-21 18:32 [PATCH 0/4] fstests: fixes and new tests Darrick J. Wong
2018-06-21 18:32 ` [PATCH 2/4] xfs: regression test for rmapbt fdblocks accounting problems Darrick J. Wong
2018-06-22  6:35   ` [PATCH 5/8] xfs: recheck reflink state after grabbing ILOCK_SHARED for a write Allison Henderson
2018-06-22  6:39     ` 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=152960589497.26246.2694743986896972501.stgit@magnolia \
    --to=darrick.wong@oracle.com \
    --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 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.