When opening O_DIRECT, tell the kernel to invalidate its cache
This commit is contained in:
parent
30de09b7d2
commit
5bd839e022
@ -21,6 +21,7 @@ To test from the cmdline:
|
|||||||
echo "hello world" > ~/corrupt-fs/hello.txt
|
echo "hello world" > ~/corrupt-fs/hello.txt
|
||||||
cat ~/corrupt-fs/hello.txt # returns good data from fscache
|
cat ~/corrupt-fs/hello.txt # returns good data from fscache
|
||||||
dd if=~/corrupt-fs/hello.txt iflag=direct # returns bad data
|
dd if=~/corrupt-fs/hello.txt iflag=direct # returns bad data
|
||||||
|
cat ~/corrupt-fs/hello.txt # returns bad data
|
||||||
```
|
```
|
||||||
|
|
||||||
Limitations:
|
Limitations:
|
||||||
|
22
src/fs.rs
22
src/fs.rs
@ -245,11 +245,12 @@ impl Filesystem for CorruptFs {
|
|||||||
let open_file = OpenFile { ino, flags };
|
let open_file = OpenFile { ino, flags };
|
||||||
self.open_fds.insert(fh, OpenFd::File(open_file));
|
self.open_fds.insert(fh, OpenFd::File(open_file));
|
||||||
|
|
||||||
let mut o_flags = FOPEN_KEEP_CACHE;
|
let o_flags =
|
||||||
if (flags & O_DIRECT) != 0 {
|
if (flags & O_DIRECT) != 0 {
|
||||||
o_flags |= FOPEN_DIRECT_IO;
|
FOPEN_DIRECT_IO
|
||||||
}
|
} else {
|
||||||
|
FOPEN_KEEP_CACHE
|
||||||
|
};
|
||||||
reply.opened(fh, o_flags);
|
reply.opened(fh, o_flags);
|
||||||
} else {
|
} else {
|
||||||
reply.error(ENOENT);
|
reply.error(ENOENT);
|
||||||
@ -296,11 +297,12 @@ impl Filesystem for CorruptFs {
|
|||||||
};
|
};
|
||||||
self.open_fds.insert(fh, OpenFd::File(open_file));
|
self.open_fds.insert(fh, OpenFd::File(open_file));
|
||||||
|
|
||||||
let mut cr_flags = FOPEN_KEEP_CACHE;
|
let cr_flags =
|
||||||
if (flags & O_DIRECT) != 0 {
|
if (flags & O_DIRECT) != 0 {
|
||||||
cr_flags |= FOPEN_DIRECT_IO;
|
FOPEN_DIRECT_IO
|
||||||
}
|
} else {
|
||||||
|
FOPEN_KEEP_CACHE
|
||||||
|
};
|
||||||
reply.created(&TTL, &attr, 0, fh, cr_flags);
|
reply.created(&TTL, &attr, 0, fh, cr_flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user