mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
Merge bdbc96c231 ("fsdax: dax_unshare_iter needs to copy entire blocks") into android14-6.1-lts
Steps on the way to 6.1.116 Resolves merge conflicts in: fs/iomap/buffered-io.c Change-Id: Ibe7e7f5a94bee171200931351878cf40e37b8bbc Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
49
fs/dax.c
49
fs/dax.c
@@ -1225,35 +1225,46 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
|
||||
{
|
||||
struct iomap *iomap = &iter->iomap;
|
||||
const struct iomap *srcmap = iomap_iter_srcmap(iter);
|
||||
loff_t pos = iter->pos;
|
||||
loff_t length = iomap_length(iter);
|
||||
loff_t copy_pos = iter->pos;
|
||||
u64 copy_len = iomap_length(iter);
|
||||
u32 mod;
|
||||
int id = 0;
|
||||
s64 ret = 0;
|
||||
void *daddr = NULL, *saddr = NULL;
|
||||
|
||||
/* don't bother with blocks that are not shared to start with */
|
||||
if (!(iomap->flags & IOMAP_F_SHARED))
|
||||
return length;
|
||||
if (!iomap_want_unshare_iter(iter))
|
||||
return iomap_length(iter);
|
||||
|
||||
id = dax_read_lock();
|
||||
ret = dax_iomap_direct_access(iomap, pos, length, &daddr, NULL);
|
||||
if (ret < 0)
|
||||
goto out_unlock;
|
||||
|
||||
/* zero the distance if srcmap is HOLE or UNWRITTEN */
|
||||
if (srcmap->flags & IOMAP_F_SHARED || srcmap->type == IOMAP_UNWRITTEN) {
|
||||
memset(daddr, 0, length);
|
||||
dax_flush(iomap->dax_dev, daddr, length);
|
||||
ret = length;
|
||||
goto out_unlock;
|
||||
/*
|
||||
* Extend the file range to be aligned to fsblock/pagesize, because
|
||||
* we need to copy entire blocks, not just the byte range specified.
|
||||
* Invalidate the mapping because we're about to CoW.
|
||||
*/
|
||||
mod = offset_in_page(copy_pos);
|
||||
if (mod) {
|
||||
copy_len += mod;
|
||||
copy_pos -= mod;
|
||||
}
|
||||
|
||||
ret = dax_iomap_direct_access(srcmap, pos, length, &saddr, NULL);
|
||||
mod = offset_in_page(copy_pos + copy_len);
|
||||
if (mod)
|
||||
copy_len += PAGE_SIZE - mod;
|
||||
|
||||
invalidate_inode_pages2_range(iter->inode->i_mapping,
|
||||
copy_pos >> PAGE_SHIFT,
|
||||
(copy_pos + copy_len - 1) >> PAGE_SHIFT);
|
||||
|
||||
id = dax_read_lock();
|
||||
ret = dax_iomap_direct_access(iomap, copy_pos, copy_len, &daddr, NULL);
|
||||
if (ret < 0)
|
||||
goto out_unlock;
|
||||
|
||||
if (copy_mc_to_kernel(daddr, saddr, length) == 0)
|
||||
ret = length;
|
||||
ret = dax_iomap_direct_access(srcmap, copy_pos, copy_len, &saddr, NULL);
|
||||
if (ret < 0)
|
||||
goto out_unlock;
|
||||
|
||||
if (copy_mc_to_kernel(daddr, saddr, copy_len) == 0)
|
||||
ret = iomap_length(iter);
|
||||
else
|
||||
ret = -EIO;
|
||||
|
||||
|
||||
@@ -1061,43 +1061,58 @@ int iomap_file_buffered_write_punch_delalloc(struct inode *inode,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iomap_file_buffered_write_punch_delalloc);
|
||||
|
||||
bool iomap_want_unshare_iter(const struct iomap_iter *iter)
|
||||
{
|
||||
/*
|
||||
* Don't bother with blocks that are not shared to start with; or
|
||||
* mappings that cannot be shared, such as inline data, 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
|
||||
* of one is a good indicator that unsharing is needed, unlike
|
||||
* IOMAP_F_SHARED which can be set for any data that goes into the COW
|
||||
* fork for XFS.
|
||||
*/
|
||||
return (iter->iomap.flags & IOMAP_F_SHARED) &&
|
||||
iter->srcmap.type == IOMAP_MAPPED;
|
||||
}
|
||||
|
||||
static loff_t iomap_unshare_iter(struct iomap_iter *iter)
|
||||
{
|
||||
struct iomap *iomap = &iter->iomap;
|
||||
const struct iomap *srcmap = iomap_iter_srcmap(iter);
|
||||
loff_t pos = iter->pos;
|
||||
loff_t length = iomap_length(iter);
|
||||
long status = 0;
|
||||
loff_t written = 0;
|
||||
|
||||
/* don't bother with blocks that are not shared to start with */
|
||||
if (!(iomap->flags & IOMAP_F_SHARED))
|
||||
return length;
|
||||
/* don't bother with holes or unwritten extents */
|
||||
if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN)
|
||||
if (!iomap_want_unshare_iter(iter))
|
||||
return length;
|
||||
|
||||
do {
|
||||
unsigned long offset = offset_in_page(pos);
|
||||
unsigned long bytes = min_t(loff_t, PAGE_SIZE - offset, length);
|
||||
struct folio *folio;
|
||||
int status;
|
||||
size_t offset;
|
||||
size_t bytes = min_t(u64, SIZE_MAX, length);
|
||||
|
||||
status = iomap_write_begin(iter, pos, bytes, &folio);
|
||||
if (unlikely(status))
|
||||
return status;
|
||||
|
||||
status = iomap_write_end(iter, pos, bytes, bytes, folio);
|
||||
if (WARN_ON_ONCE(status == 0))
|
||||
offset = offset_in_folio(folio, pos);
|
||||
if (bytes > folio_size(folio) - offset)
|
||||
bytes = folio_size(folio) - offset;
|
||||
|
||||
bytes = iomap_write_end(iter, pos, bytes, bytes, folio);
|
||||
if (WARN_ON_ONCE(bytes == 0))
|
||||
return -EIO;
|
||||
|
||||
cond_resched();
|
||||
|
||||
pos += status;
|
||||
written += status;
|
||||
length -= status;
|
||||
pos += bytes;
|
||||
written += bytes;
|
||||
length -= bytes;
|
||||
|
||||
balance_dirty_pages_ratelimited(iter->inode->i_mapping);
|
||||
} while (length);
|
||||
} while (length > 0);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
@@ -243,6 +243,7 @@ bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
|
||||
void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);
|
||||
int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
|
||||
const struct iomap_ops *ops);
|
||||
bool iomap_want_unshare_iter(const struct iomap_iter *iter);
|
||||
int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len,
|
||||
bool *did_zero, const struct iomap_ops *ops);
|
||||
int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
|
||||
|
||||
Reference in New Issue
Block a user