Skip to content

Commit

Permalink
msync04: Check disk content if dirty bit check failed
Browse files Browse the repository at this point in the history
msync04 test is inherently racy and nothing guarantees that the page
is not written out before get_dirty_page() manages to read the page state.
Hence the test should be reworked to verify the page contents is on disk
when it finds dirty bit isn't set anymore...

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Jan Kara <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Wei Gao <[email protected]>
[ pvorel: remove dirty variable ]
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
coolgw authored and pevik committed May 28, 2024
1 parent e85ec87 commit 66517b8
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions testcases/kernel/syscalls/msync/msync04.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static uint64_t get_dirty_bit(void *data)

static void test_msync(void)
{
uint64_t dirty;
char buffer[20];

test_fd = SAFE_OPEN("msync04/testfile", O_CREAT | O_TRUNC | O_RDWR,
0644);
Expand All @@ -54,22 +54,26 @@ static void test_msync(void)
MAP_SHARED, test_fd, 0);
SAFE_CLOSE(test_fd);
mmaped_area[8] = 'B';
dirty = get_dirty_bit(mmaped_area);
if (!dirty) {
tst_res(TFAIL, "Expected dirty bit to be set after writing to"
" mmap()-ed area");
goto clean;
}
if (msync(mmaped_area, pagesize, MS_SYNC) < 0) {
tst_res(TFAIL | TERRNO, "msync() failed");
goto clean;

if (!get_dirty_bit(mmaped_area)) {
tst_res(TINFO, "Not see dirty bit so we check content of file instead");
test_fd = SAFE_OPEN("msync04/testfile", O_RDONLY);
SAFE_READ(0, test_fd, buffer, 9);
if (buffer[8] == 'B')
tst_res(TCONF, "write file ok but msync couldn't be tested"
" because the storage was written to too quickly");
else
tst_res(TFAIL, "write file failed");
} else {
if (msync(mmaped_area, pagesize, MS_SYNC) < 0) {
tst_res(TFAIL | TERRNO, "msync() failed");
goto clean;
}
if (get_dirty_bit(mmaped_area))
tst_res(TFAIL, "msync() failed to write dirty page despite succeeding");
else
tst_res(TPASS, "msync() working correctly");
}
dirty = get_dirty_bit(mmaped_area);
if (dirty)
tst_res(TFAIL, "msync() failed to write dirty page despite"
" succeeding");
else
tst_res(TPASS, "msync() working correctly");

clean:
SAFE_MUNMAP(mmaped_area, pagesize);
Expand Down

0 comments on commit 66517b8

Please sign in to comment.