mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 10:58:48 +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;
|
struct iomap *iomap = &iter->iomap;
|
||||||
const struct iomap *srcmap = iomap_iter_srcmap(iter);
|
const struct iomap *srcmap = iomap_iter_srcmap(iter);
|
||||||
loff_t pos = iter->pos;
|
loff_t copy_pos = iter->pos;
|
||||||
loff_t length = iomap_length(iter);
|
u64 copy_len = iomap_length(iter);
|
||||||
|
u32 mod;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
s64 ret = 0;
|
s64 ret = 0;
|
||||||
void *daddr = NULL, *saddr = NULL;
|
void *daddr = NULL, *saddr = NULL;
|
||||||
|
|
||||||
/* don't bother with blocks that are not shared to start with */
|
if (!iomap_want_unshare_iter(iter))
|
||||||
if (!(iomap->flags & IOMAP_F_SHARED))
|
return iomap_length(iter);
|
||||||
return length;
|
|
||||||
|
|
||||||
id = dax_read_lock();
|
/*
|
||||||
ret = dax_iomap_direct_access(iomap, pos, length, &daddr, NULL);
|
* Extend the file range to be aligned to fsblock/pagesize, because
|
||||||
if (ret < 0)
|
* we need to copy entire blocks, not just the byte range specified.
|
||||||
goto out_unlock;
|
* Invalidate the mapping because we're about to CoW.
|
||||||
|
*/
|
||||||
/* zero the distance if srcmap is HOLE or UNWRITTEN */
|
mod = offset_in_page(copy_pos);
|
||||||
if (srcmap->flags & IOMAP_F_SHARED || srcmap->type == IOMAP_UNWRITTEN) {
|
if (mod) {
|
||||||
memset(daddr, 0, length);
|
copy_len += mod;
|
||||||
dax_flush(iomap->dax_dev, daddr, length);
|
copy_pos -= mod;
|
||||||
ret = length;
|
|
||||||
goto out_unlock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
if (ret < 0)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
if (copy_mc_to_kernel(daddr, saddr, length) == 0)
|
ret = dax_iomap_direct_access(srcmap, copy_pos, copy_len, &saddr, NULL);
|
||||||
ret = length;
|
if (ret < 0)
|
||||||
|
goto out_unlock;
|
||||||
|
|
||||||
|
if (copy_mc_to_kernel(daddr, saddr, copy_len) == 0)
|
||||||
|
ret = iomap_length(iter);
|
||||||
else
|
else
|
||||||
ret = -EIO;
|
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);
|
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)
|
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 pos = iter->pos;
|
||||||
loff_t length = iomap_length(iter);
|
loff_t length = iomap_length(iter);
|
||||||
long status = 0;
|
|
||||||
loff_t written = 0;
|
loff_t written = 0;
|
||||||
|
|
||||||
/* don't bother with blocks that are not shared to start with */
|
if (!iomap_want_unshare_iter(iter))
|
||||||
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)
|
|
||||||
return length;
|
return length;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned long offset = offset_in_page(pos);
|
|
||||||
unsigned long bytes = min_t(loff_t, PAGE_SIZE - offset, length);
|
|
||||||
struct folio *folio;
|
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);
|
status = iomap_write_begin(iter, pos, bytes, &folio);
|
||||||
if (unlikely(status))
|
if (unlikely(status))
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = iomap_write_end(iter, pos, bytes, bytes, folio);
|
offset = offset_in_folio(folio, pos);
|
||||||
if (WARN_ON_ONCE(status == 0))
|
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;
|
return -EIO;
|
||||||
|
|
||||||
cond_resched();
|
cond_resched();
|
||||||
|
|
||||||
pos += status;
|
pos += bytes;
|
||||||
written += status;
|
written += bytes;
|
||||||
length -= status;
|
length -= bytes;
|
||||||
|
|
||||||
balance_dirty_pages_ratelimited(iter->inode->i_mapping);
|
balance_dirty_pages_ratelimited(iter->inode->i_mapping);
|
||||||
} while (length);
|
} while (length > 0);
|
||||||
|
|
||||||
return written;
|
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);
|
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,
|
int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
|
||||||
const struct iomap_ops *ops);
|
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,
|
int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len,
|
||||||
bool *did_zero, const struct iomap_ops *ops);
|
bool *did_zero, const struct iomap_ops *ops);
|
||||||
int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
|
int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
|
||||||
|
|||||||
Reference in New Issue
Block a user