From patchwork Wed Oct 2 15:00:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13819891 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9B4C10E9; Wed, 2 Oct 2024 15:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881240; cv=none; b=basKsrr+6ZKurDnF15lnVLEuxBw3uOUx7+Jg3Y+eMmGu9fBL2ySeAbE02D6V3yBJcx6k5nyVWeK1xoxDT736TOSJyIL71NLeDbkuji/wBOjPlg3m9J0G2+TEwp1V2G5PP9AyM5SzETrre9vIAXFqoZbODhbPVfgrzg3fXIl5nJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881240; c=relaxed/simple; bh=tXnFgNCaLBW8SJWvyMBianXDwLFKOg09fZTo/9GFZ10=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=RJ91F9rjeJcAV3zrhSUh0mzyNj5ndeGFVpDTFeeI7JVZHgkPWpWtK8SNkLJtA+rLBE0Gp4bhIIAe3tyX+Baa+DG7mlaLtYCo2xWLM3haRifPIdt0b9QGg8zuPuXcTwsDrzSHcgqhTIlQz7F0Q1gMOWS7XBXDttGESO8RU0NRi28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mOuc1o9i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mOuc1o9i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B098FC4CEC2; Wed, 2 Oct 2024 15:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881240; bh=tXnFgNCaLBW8SJWvyMBianXDwLFKOg09fZTo/9GFZ10=; h=Date:From:To:Cc:Subject:From; b=mOuc1o9iDPjOe2rihsONpiBJ/yfWC3hlENrHd6bpNCLGNKdgQOXIhESj4oz5fbnnW ZPdy+QNVNBtb+WSGJBxT2WjScC5C3fw3bKxW1Frvtir49JR4z930EVJkT+X8V43WFW 8fnvyDBI2Y6QZxFBwjxymgrlXGwKgdnWV1COziw4mb6QWmLuRUjDhQlUBPgzb1tmVH llcUVbYu/Xz00YE7fny5C+/4CYaAjvU11N0klnthSJI/kSMWr+lqq1+Cx2020NWK/D GHp7/kGh16WEiSst1v4jl+q6R4jBsL3jsLs9lCnjcsDBhB6HzTISWR33Cl/q7HV29N 5fQgMSGfVNF0g== Date: Wed, 2 Oct 2024 08:00:40 -0700 From: "Darrick J. Wong" To: Christian Brauner Cc: linux-fsdevel , xfs , Christoph Hellwig Subject: [PATCH 1/2] iomap: don't bother unsharing delalloc extents Message-ID: <20241002150040.GB21853@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline From: Darrick J. Wong If unshare encounters a delalloc reservation in the srcmap, that means that the file range isn't shared because delalloc reservations cannot be reflinked. Therefore, don't try to unshare them. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Brian Foster --- fs/iomap/buffered-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 11ea747228aee..c1c559e0cc07c 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1321,7 +1321,7 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) return length; /* - * Don't bother with holes or unwritten extents. + * Don't bother with delalloc reservations, holes or unwritten extents. * * Note that we use srcmap directly instead of iomap_iter_srcmap as * unsharing requires providing a separate source map, and the presence @@ -1330,6 +1330,7 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) * fork for XFS. */ if (iter->srcmap.type == IOMAP_HOLE || + iter->srcmap.type == IOMAP_DELALLOC || iter->srcmap.type == IOMAP_UNWRITTEN) return length; From patchwork Wed Oct 2 15:02:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13819897 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE69F1CEEAF; Wed, 2 Oct 2024 15:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881334; cv=none; b=hPv7QV3Dqdi432TLa+6RRkqBqqv2m77+Z5O3SXHEUPCSmG2BelG7uzM94jIc/4bBNUvIh5pLWH26MguzRL1942ZuVCxqe+Yk0AvyRFMZnihcafn+Qbpr86bKVLS9Jj4KThqfJ1InpxKKZ72U0UUKvKRkQA/CCL0E9RuwPnh00m0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881334; c=relaxed/simple; bh=33ahCZ9A/K133WBezUAOVM2T9X8TWw5GgYn6tGWsLAw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UmeFkEdu0RIOMtRm99NmNMEgSB1j3ej5Y9CUCf5ptx7ahZods6ZjaU1FuqKwsIH9da2NGSRqamQEGrXM3VsPLbexcbImq7BXyfDmv57NCv0HtRox98PvxEZcjmbxgkW4o70PsGAwOB+8TjqYqaRGJkjdgt5OHjBvL4czEf6xcGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JL3KTzbs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JL3KTzbs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBDEAC4CEC2; Wed, 2 Oct 2024 15:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881333; bh=33ahCZ9A/K133WBezUAOVM2T9X8TWw5GgYn6tGWsLAw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JL3KTzbssJsZsw6QWg9KZ6ux70TOFLrZLH5kOd+y4m106Ytk5n99OWWhQQBcEjyMT nGnF635tTjj38JVNM+HjFQJxbUVssS02FOMbjvw0t+w7sDe6lhAyepCiei7YHMnbc4 lr4AHiB8KVZHjocFejHgue/h7O2sTO35uCmOoh5Qb2m/Tonw7+nBUtwyNUYtSPHD4u R6nRqqTEptiXAkD8Q+VbZHCESadkPylo3Ad4deLOE4Nwt6bCGpveXkrSXrop3+wTD5 Kws+ZhFFC8CcJjRYNqK5hQqR7V8GOXbtQa0xj9h7+ALnIc2TdsLGUupc3QJrOA4IGr DNGjXNyMbZ6UQ== Date: Wed, 2 Oct 2024 08:02:13 -0700 From: "Darrick J. Wong" To: Christian Brauner Cc: linux-fsdevel , xfs , Christoph Hellwig , Brian Foster , sunjunchao2870@gmail.com, jack@suse.cz Subject: [PATCH 2/2] iomap: constrain the file range passed to iomap_file_unshare Message-ID: <20241002150213.GC21853@frogsfrogsfrogs> References: <20241002150040.GB21853@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20241002150040.GB21853@frogsfrogsfrogs> From: Darrick J. Wong File contents can only be shared (i.e. reflinked) below EOF, so it makes no sense to try to unshare ranges beyond EOF. Constrain the file range parameters here so that we don't have to do that in the callers. Fixes: 5f4e5752a8a3 ("fs: add iomap_file_dirty") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Brian Foster --- fs/dax.c | 6 +++++- fs/iomap/buffered-io.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index becb4a6920c6a..c62acd2812f8d 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1305,11 +1305,15 @@ int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, struct iomap_iter iter = { .inode = inode, .pos = pos, - .len = len, .flags = IOMAP_WRITE | IOMAP_UNSHARE | IOMAP_DAX, }; + loff_t size = i_size_read(inode); int ret; + if (pos < 0 || pos >= size) + return 0; + + iter.len = min(len, size - pos); while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = dax_unshare_iter(&iter); return ret; diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index c1c559e0cc07c..78ebd265f4259 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1375,11 +1375,15 @@ iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, struct iomap_iter iter = { .inode = inode, .pos = pos, - .len = len, .flags = IOMAP_WRITE | IOMAP_UNSHARE, }; + loff_t size = i_size_read(inode); int ret; + if (pos < 0 || pos >= size) + return 0; + + iter.len = min(len, size - pos); while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_unshare_iter(&iter); return ret;