From: yu kuai <yukuai3@huawei.com>
To: <darrick.wong@oracle.com>, <bfoster@redhat.com>,
<dchinner@redhat.com>, <sandeen@sandeen.net>,
<cmaiolino@redhat.com>, <hch@lst.de>
Cc: <linux-xfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yukuai3@huawei.com>, <zhengbin13@huawei.com>,
<yi.zhang@huawei.com>, <houtao1@huawei.com>
Subject: [PATCH 1/2] xfs: introduce xfs_bmap_split_da_extent
Date: Thu, 26 Dec 2019 21:47:20 +0800 [thread overview]
Message-ID: <20191226134721.43797-2-yukuai3@huawei.com> (raw)
In-Reply-To: <20191226134721.43797-1-yukuai3@huawei.com>
Add a new function xfs_bmap_split_da_extent to split a delalloc extent
into two delalloc extents.
Signed-off-by: yu kuai <yukuai3@huawei.com>
---
fs/xfs/libxfs/xfs_bmap.c | 26 ++++++++++++++++++++++++--
fs/xfs/libxfs/xfs_bmap.h | 1 +
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 4c2e046fbfad..8247054c1e2b 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -6117,7 +6117,7 @@ xfs_bmap_split_extent_at(
/*
* Convert to a btree if necessary.
*/
- if (xfs_bmap_needs_btree(ip, whichfork)) {
+ if (tp && xfs_bmap_needs_btree(ip, whichfork)) {
int tmp_logflags; /* partial log flag return val */
ASSERT(cur == NULL);
@@ -6132,7 +6132,7 @@ xfs_bmap_split_extent_at(
xfs_btree_del_cursor(cur, error);
}
- if (logflags)
+ if (tp && logflags)
xfs_trans_log_inode(tp, ip, logflags);
return error;
}
@@ -6165,6 +6165,28 @@ xfs_bmap_split_extent(
return error;
}
+/*
+ * Splits a delalloc extent into two delalloc extents at split_fsb block
+ * such that it is the first block of the current_ext. Caller has to make
+ * sure split_fsb belong to a delalloc extent.
+ * If split_fsb is not the first block of the extent, caller need to sub
+ * the @ip->i_d.di_nextents to prevent crash in log recovery.
+ */
+int
+xfs_bmap_split_da_extent(
+ struct xfs_inode *ip,
+ xfs_fileoff_t split_fsb)
+{
+ struct xfs_trans *tp = NULL;
+ int error;
+
+ xfs_ilock(ip, XFS_ILOCK_EXCL);
+ error = xfs_bmap_split_extent_at(tp, ip, split_fsb);
+ xfs_iunlock(ip, XFS_ILOCK_EXCL);
+
+ return error;
+}
+
/* Deferred mapping is only for real extents in the data fork. */
static bool
xfs_bmap_is_update_needed(
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index 14d25e0b7d9c..d8d969aa17ef 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -223,6 +223,7 @@ int xfs_bmap_insert_extents(struct xfs_trans *tp, struct xfs_inode *ip,
xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb,
bool *done, xfs_fileoff_t stop_fsb);
int xfs_bmap_split_extent(struct xfs_inode *ip, xfs_fileoff_t split_offset);
+int xfs_bmap_split_da_extent(struct xfs_inode *ip, xfs_fileoff_t split_offset);
int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork,
xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,
struct xfs_bmbt_irec *got, struct xfs_iext_cursor *cur,
--
2.17.2
next prev parent reply other threads:[~2019-12-26 13:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-26 13:47 [PATCH 0/2] fix stale data exposure problem yu kuai
2019-12-26 13:47 ` yu kuai [this message]
2020-01-05 21:04 ` [PATCH 1/2] xfs: introduce xfs_bmap_split_da_extent Dave Chinner
2019-12-26 13:47 ` [PATCH 2/2] xfs: fix stale data exposure problem when punch hole, collapse range or zero range across a delalloc extent yu kuai
2019-12-27 0:17 ` kbuild test robot
2019-12-27 0:17 ` [RFC PATCH] xfs: try_split_da_extent can be static kbuild test robot
2019-12-27 14:25 ` [xfs] 1c6c6a28e3: Assertion_failed kernel test robot
2020-01-06 21:57 ` [PATCH 2/2] xfs: fix stale data exposure problem when punch hole, collapse range or zero range across a delalloc extent Darrick J. Wong
2020-01-07 2:09 ` yukuai (C)
2020-01-07 18:17 ` 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=20191226134721.43797-2-yukuai3@huawei.com \
--to=yukuai3@huawei.com \
--cc=bfoster@redhat.com \
--cc=cmaiolino@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=dchinner@redhat.com \
--cc=hch@lst.de \
--cc=houtao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
--cc=yi.zhang@huawei.com \
--cc=zhengbin13@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).