Cifs: dara corruption fix for cache=none when reading a mmapped file
Subsystems (2)
Steve, List,
This issue is similar to kernel bugzilla 216301 but is the opposite case. For cache=none, before we perform a pread() we have to destage any dirty pages back to the server before we allow the pread() to be performed.
A simple test application for this:
===================================
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
void write_x_1(int fd, int offset) {
char b[] = {"x"};
printf("Writing 'x' at offset: %d. Result: %d\n", offset, pwrite(fd, &b\, 1, offset));
}
int main(int argc, char *argv[]){
char buf[32] = {};
int fd = open(argv[1], O_RDWR|O_CREAT, 0600);
printf("File descriptor: %d\n", fd);
char *m = mmap(NULL, 30, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE,\
fd, 0);
printf("Madvised: %d\n", madvise(m, 30, MADV_RANDOM));
printf("1. Reading file content after mmaping: \n%s\n", m);
write_x_1(fd, 4);
write_x_1(fd, 9);
write_x_1(fd, 14);
write_x_1(fd, 19);
write_x_1(fd, 24);
printf("\n");
printf("2. After updating file content: \n%s\n", m);
m[5] = 'a';
m[10] = 'a';
m[15] = 'a';
printf("\n");
pread(fd, buf, 32, 0);
printf("3. After updating file content: \n%s\n", buf);
munmap(m, 30);
close(fd);
}PATCH 1/1 cifs: invalidate and destage pages before re-reading them for cache=none
This is the opposite case of kernel bugzilla 216301.
If we mmap a file using cache=none and then proceed to update the mmapped area these updates are not reflected in a later pread() of that part of the file.
To fix this we must invalidate the mapping, forcing the changed pages to be destaged to the server before we allow the pread() to proceed.
--- fs/cifs/file.c | 3 +++ 1 file changed, 3 insertions(+)
fs/cifs/file.c +3 -0
@@ -4314,6 +4314,9 @@ static ssize_t __cifs_readv(ssize_t cifs_direct_readv (struct kiocb *iocb,struct iov_iter *to) { +struct file *file = iocb->ki_filp; + +cifs_revalidate_mapping (file->f_inode);return __cifs_readv (iocb, to, true); }
Signature · 1 line
2.35.3