• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Linaro Limited. All rights reserved.
4  * Author: Sumit Garg <sumit.garg@linaro.org>
5  */
6 
7 /*
8  * Test syncfs
9  *
10  * It basically tests syncfs() to sync filesystem having large dirty file
11  * pages to block device. Also, it tests all supported filesystems on a test
12  * block device.
13  */
14 
15 #define _GNU_SOURCE
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include "tst_test.h"
20 #include "lapi/syncfs.h"
21 #include "check_syncfs.h"
22 
23 #define MNTPOINT	"mnt_point"
24 #define FNAME		MNTPOINT"/test"
25 #define FILE_SIZE_MB	32
26 #define FILE_SIZE	(FILE_SIZE_MB * TST_MB)
27 #define MODE		0644
28 
verify_syncfs(void)29 static void verify_syncfs(void)
30 {
31 	int fd;
32 	unsigned long written;
33 
34 	fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
35 
36 	tst_dev_sync(fd);
37 	tst_dev_bytes_written(tst_device->dev);
38 
39 	tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB);
40 
41 	TEST(syncfs(fd));
42 
43 	if (TST_RET)
44 		tst_brk(TFAIL | TTERRNO, "syncfs(fd) failed");
45 
46 	written = tst_dev_bytes_written(tst_device->dev);
47 
48 	SAFE_CLOSE(fd);
49 
50 	if (written >= FILE_SIZE)
51 		tst_res(TPASS, "Test filesystem synced to device");
52 	else
53 		tst_res(TFAIL, "Synced %li, expected %i", written, FILE_SIZE);
54 }
55 
setup(void)56 static void setup(void)
57 {
58 	check_syncfs();
59 }
60 
61 static struct tst_test test = {
62 	.needs_root = 1,
63 	.mount_device = 1,
64 	.all_filesystems = 1,
65 	.skip_filesystems = (const char*[]) {
66 		"tmpfs",
67 		NULL
68 	},
69 	.mntpoint = MNTPOINT,
70 	.setup = setup,
71 	.test_all = verify_syncfs,
72 };
73