mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 19:51:31 -04:00
iomap: report collisions between directio and buffered writes to userspace
If two programs simultaneously try to write to the same part of a file via direct IO and buffered IO, there's a chance that the post-diowrite pagecache invalidation will fail on the dirty page. When this happens, the dio write succeeded, which means that the page cache is no longer coherent with the disk! Programs are not supposed to mix IO types and this is a clear case of data corruption, so store an EIO which will be reflected to userspace during the next fsync. Replace the WARN_ON with a ratelimited pr_crit so that the developers have /some/ kind of breadcrumb to track down the offending program(s) and file(s) involved. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Liu Bo <[email protected]>
This commit is contained in:
parent
c017cb5ddf
commit
5a9d929d6e
3 changed files with 34 additions and 3 deletions
|
|
@ -219,6 +219,27 @@ static inline struct page *dio_get_page(struct dio *dio,
|
|||
return dio->pages[sdio->head];
|
||||
}
|
||||
|
||||
/*
|
||||
* Warn about a page cache invalidation failure during a direct io write.
|
||||
*/
|
||||
void dio_warn_stale_pagecache(struct file *filp)
|
||||
{
|
||||
static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST);
|
||||
char pathname[128];
|
||||
struct inode *inode = file_inode(filp);
|
||||
char *path;
|
||||
|
||||
errseq_set(&inode->i_mapping->wb_err, -EIO);
|
||||
if (__ratelimit(&_rs)) {
|
||||
path = file_path(filp, pathname, sizeof(pathname));
|
||||
if (IS_ERR(path))
|
||||
path = "(unknown)";
|
||||
pr_crit("Page cache invalidation failure on direct I/O. Possible data corruption due to collision with buffered I/O!\n");
|
||||
pr_crit("File: %s PID: %d Comm: %.20s\n", path, current->pid,
|
||||
current->comm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dio_complete() - called when all DIO BIO I/O has been completed
|
||||
* @offset: the byte offset in the file of the completed operation
|
||||
|
|
@ -290,7 +311,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags)
|
|||
err = invalidate_inode_pages2_range(dio->inode->i_mapping,
|
||||
offset >> PAGE_SHIFT,
|
||||
(offset + ret - 1) >> PAGE_SHIFT);
|
||||
WARN_ON_ONCE(err);
|
||||
if (err)
|
||||
dio_warn_stale_pagecache(dio->iocb->ki_filp);
|
||||
}
|
||||
|
||||
if (!(dio->flags & DIO_SKIP_DIO_COUNT))
|
||||
|
|
|
|||
Loading…
Reference in a new issue