Skip to contentSkip to conversation

syscalls/sync_file_range: add partial file sync test-cases

PATCH Superseded Sumit Garg 3 participants 8 messages Mar 7, 2019 – Jun 10, 2019

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Add partial file sync tests as part of sync_file_range02 test-case.

---

Changes in v3:
1. Add upper bound check for synced size to device.
2. Refactor tests for more code reuse.
3. Add another test to check sync over partial write.

Changes in v2:
1. Do full file write instead of partial and test sync partial file.

 .../syscalls/sync_file_range/sync_file_range02.c   | 47 +++++++++++++++++-----
 1 file changed, 37 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +37 -10
index 82d77f7..334ea5e 100644
@@ -22,23 +22,36 @@
 #include "check_sync_file_range.h"
 
 #define MNTPOINT		"mnt_point"
-#define FNAME		MNTPOINT"/test"
-#define FILE_SIZE_MB	32
-#define FILE_SIZE (FILE_SIZE_MB * TST_MB)
+#define FNAME1			MNTPOINT"/test1"
+#define FNAME2			MNTPOINT"/test2"
+#define FNAME3			MNTPOINT"/test3"
+#define FILE_SZ_MB		32
+#define FILE_SZ			(FILE_SZ_MB * TST_MB)
 #define MODE			0644
 
-static void verify_sync_file_range(void)
+struct testcase {
+	char *fname;
+	off64_t sync_off;
+	off64_t sync_size;
+	size_t exp_sync_size;
+	off64_t write_off;
+	size_t write_size_mb;
+};
+
+static void verify_sync_file_range(struct testcase *tc)
 {
 	int fd;
 	unsigned long written;
 
-	fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
+	fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
+
+	lseek(fd, tc->write_off, SEEK_SET);
 
 	tst_dev_bytes_written(tst_device->dev);
 
-	tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB);
+	tst_fill_fd(fd, 0, TST_MB, tc->write_size_mb);
 
-	TEST(sync_file_range(fd, 0, FILE_SIZE,
+	TEST(sync_file_range(fd, tc->sync_off, tc->sync_size,
 			     SYNC_FILE_RANGE_WAIT_BEFORE |
 			     SYNC_FILE_RANGE_WRITE |
 			     SYNC_FILE_RANGE_WAIT_AFTER));
@@ -50,10 +63,23 @@ static void verify_sync_file_range(void)
 
 	SAFE_CLOSE(fd);
 
-	if (written >= FILE_SIZE)
+	if ((written >= tc->exp_sync_size) &&
+	    (written <= (tc->exp_sync_size + tc->exp_sync_size/10)))
 		tst_res(TPASS, "Test file range synced to device");
 	else
-		tst_res(TFAIL, "Synced %li, expected %i", written, FILE_SIZE);
+		tst_res(TFAIL, "Synced %li, expected %li", written,
+			tc->exp_sync_size);
+}
+
+static struct testcase testcases[] = {
+	{ FNAME1, 0, FILE_SZ, FILE_SZ, 0, FILE_SZ_MB },
+	{ FNAME2, FILE_SZ/4, FILE_SZ/2, FILE_SZ/2, 0, FILE_SZ_MB },
+	{ FNAME3, FILE_SZ/4, FILE_SZ/2, FILE_SZ/4, FILE_SZ/2, FILE_SZ_MB/4 },
+};
+
+static void run(unsigned int i)
+{
+	verify_sync_file_range(&testcases[i]);
 }
 
 static void setup(void)
@@ -63,10 +89,11 @@ static void setup(void)
 }
 
 static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(testcases),
 	.needs_root = 1,
 	.mount_device = 1,
 	.all_filesystems = 1,
 	.mntpoint = MNTPOINT,
 	.setup = setup,
-	.test_all = verify_sync_file_range,
+	.test = run,
 };
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Hi!
Sorry for the long delay.

This is altmost perfect, the only problem is that the third test fails on vfat. As far as I can tell the reason is that vfat does not support sparse files, hence seeking to the middle of file and writing there also schedulles I/O to write zeros from the start of the file to the offset we started writing to.

Following ugly patch solves the problem:

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -0
index 334ea5e88..774524c2f 100644
@@ -45,6 +45,12 @@ static void verify_sync_file_range(struct testcase *tc)
 
        fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
 
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_fd(fd, 0, tc->write_off, 1);
+               fsync(fd);
+       }
+
        lseek(fd, tc->write_off, SEEK_SET);
 
 

So either we limit the tests so that the sync region does not overlap with the possible hole at the start of the file and loose some test coverage.

Or we can add a function to the test library that would return true/false if sparse files are supported for a given FS.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Quoted 10 lines · Cyril Hrubis

Hi!
Sorry for the long delay.

This is altmost perfect, the only problem is that the third test fails on vfat. As far as I can tell the reason is that vfat does not support sparse files, hence seeking to the middle of file and writing there also schedulles I/O to write zeros from the start of the file to the offset we started writing to.

Hmm, I see.

Quoted 22 lines

Following ugly patch solves the problem:

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -0
index 334ea5e88..774524c2f 100644
@@ -45,6 +45,12 @@ static void verify_sync_file_range(struct testcase *tc)
 
        fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
 
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_fd(fd, 0, tc->write_off, 1);
+               fsync(fd);
+       }
+
        lseek(fd, tc->write_off, SEEK_SET);
 
 

So either we limit the tests so that the sync region does not overlap with the possible hole at the start of the file and loose some test coverage.

Quoted 3 lines

Or we can add a function to the test library that would return true/false if sparse files are supported for a given FS.

My initial thought behind this test-case was to run sync over a range which is partially written. The other partial region not being written could either be a hole or already synced data. So pre-fill file in case of vfat looks sane option, but how about if we add pre-fill as part of setup? Something like:

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -1
@@ -86,6 +86,12 @@ static void setup(void)
 {
        if (!check_sync_file_range())
                tst_brk(TCONF, "sync_file_range() not supported");
+
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_file(FNAME3, 0, TST_MB, FILE_SZ_MB);
+               sync();
+       }
 }
 
-Sumit
Quoted 3 lines

--
Cyril Hrubis
[email protected]

#3 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Quoted 42 lines · Sumit Garg
Quoted 10 lines · Cyril Hrubis

Hi!
Sorry for the long delay.

This is altmost perfect, the only problem is that the third test fails on vfat. As far as I can tell the reason is that vfat does not support sparse files, hence seeking to the middle of file and writing there also schedulles I/O to write zeros from the start of the file to the offset we started writing to.

Hmm, I see.

Quoted 3 lines

Following ugly patch solves the problem:

diff --git

a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c static void verify_sync_file_range(struct testcase

Quoted 4 lines

index 334ea5e88..774524c2f 100644

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +0 -0
@@ -45,6 +45,12 @@ static void verify_sync_file_range(struct testcase

*tc)

Quoted 12 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -0
        fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
 
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_fd(fd, 0, tc->write_off, 1);
+               fsync(fd);
+       }
+
        lseek(fd, tc->write_off, SEEK_SET);
 
 
Quoted 1 line

So either we limit the tests so that the sync region does not overlap

with the

Quoted 3 lines

possible hole at the start of the file and loose some test coverage.

Or we can add a function to the test library that would return

true/false if

Quoted 9 lines
Quoted 2 lines

sparse files are supported for a given FS.

My initial thought behind this test-case was to run sync over a range which is partially written. The other partial region not being written could either be a hole or already synced data. So pre-fill file in case of vfat looks sane option, but how about if we add pre-fill as part of setup? Something like:

I think this is a bit better. Could u send a new patch version?

Quoted 23 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -1
@@ -86,6 +86,12 @@ static void setup(void)
 {
        if (!check_sync_file_range())
                tst_brk(TCONF, "sync_file_range() not supported");
+
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_file(FNAME3, 0, TST_MB, FILE_SZ_MB);
+               sync();
+       }
 }
 
-Sumit
Quoted 4 lines

--
Cyril Hrubis
[email protected]

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190610/e8d4b01a/attachment-0001.html>
author
#4 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Quoted 52 lines · Li Wang
Quoted 37 lines · Sumit Garg
Quoted 10 lines · Cyril Hrubis

Hi!
Sorry for the long delay.

This is altmost perfect, the only problem is that the third test fails on vfat. As far as I can tell the reason is that vfat does not support sparse files, hence seeking to the middle of file and writing there also schedulles I/O to write zeros from the start of the file to the offset we started writing to.

Hmm, I see.

Quoted 22 lines

Following ugly patch solves the problem:

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -0
index 334ea5e88..774524c2f 100644
@@ -45,6 +45,12 @@ static void verify_sync_file_range(struct testcase *tc)
 
        fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
 
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_fd(fd, 0, tc->write_off, 1);
+               fsync(fd);
+       }
+
        lseek(fd, tc->write_off, SEEK_SET);
 
 

So either we limit the tests so that the sync region does not overlap with the possible hole at the start of the file and loose some test coverage.

Quoted 9 lines
Quoted 3 lines

Or we can add a function to the test library that would return true/false if sparse files are supported for a given FS.

My initial thought behind this test-case was to run sync over a range which is partially written. The other partial region not being written could either be a hole or already synced data. So pre-fill file in case of vfat looks sane option, but how about if we add pre-fill as part of setup? Something like:

Quoted 2 lines

I think this is a bit better. Could u send a new patch version?

Sure. BTW, apologies for the delay as I was busy with some other tasks.

-Sumit

Quoted 29 lines
Quoted 17 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +6 -1
@@ -86,6 +86,12 @@ static void setup(void)
 {
        if (!check_sync_file_range())
                tst_brk(TCONF, "sync_file_range() not supported");
+
+       if (!strcmp(tst_device->fs_type, "vfat")) {
+               tst_res(TINFO, "Pre-filling file");
+               tst_fill_file(FNAME3, 0, TST_MB, FILE_SZ_MB);
+               sync();
+       }
 }
 
-Sumit
Quoted 6 lines
Quoted 3 lines

--
Cyril Hrubis
[email protected]

--
Mailing list info: https://lists.linux.it/listinfo/ltp

--
Regards,
Li Wang

#5 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

In reply to Sumit Garg

Hi Sumit,

Quoted 51 lines · Sumit Garg

Add partial file sync tests as part of sync_file_range02 test-case.

---

Changes in v3:
1. Add upper bound check for synced size to device.
2. Refactor tests for more code reuse.
3. Add another test to check sync over partial write.

Changes in v2:
1. Do full file write instead of partial and test sync partial file.

 .../syscalls/sync_file_range/sync_file_range02.c   | 47
+++++++++++++++++-----
 1 file changed, 37 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +15 -4
index 82d77f7..334ea5e 100644
@@ -22,23 +22,36 @@
 #include "check_sync_file_range.h"
 
 #define MNTPOINT               "mnt_point"
-#define FNAME          MNTPOINT"/test"
-#define FILE_SIZE_MB   32
-#define FILE_SIZE (FILE_SIZE_MB * TST_MB)
+#define FNAME1                 MNTPOINT"/test1"
+#define FNAME2                 MNTPOINT"/test2"
+#define FNAME3                 MNTPOINT"/test3"
+#define FILE_SZ_MB             32
+#define FILE_SZ                        (FILE_SZ_MB * TST_MB)
 #define MODE                   0644
 
-static void verify_sync_file_range(void)
+struct testcase {
+       char *fname;
+       off64_t sync_off;
+       off64_t sync_size;
+       size_t exp_sync_size;
+       off64_t write_off;
+       size_t write_size_mb;
+};
+
+static void verify_sync_file_range(struct testcase *tc)
 {
        int fd;
        unsigned long written;
 

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c line 53

Quoted 10 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +4 -2
-       fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
+       fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
+
+       lseek(fd, tc->write_off, SEEK_SET);
 
        tst_dev_bytes_written(tst_device->dev);
 
-       tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB);
+       tst_fill_fd(fd, 0, TST_MB, tc->write_size_mb);
 

I'm just thinking that is probably more precise if we reverse the order of tst_fill_fd() and tst_dev_bytes_written()? Because that does counting the dev_bytes_writen only before and after sync_file_range(), we cann't garantee system does not wirte back to deviece when do fill_fd(), isn't it?

Quoted 54 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +16 -3
-       TEST(sync_file_range(fd, 0, FILE_SIZE,
+       TEST(sync_file_range(fd, tc->sync_off, tc->sync_size,
                             SYNC_FILE_RANGE_WAIT_BEFORE |
                             SYNC_FILE_RANGE_WRITE |
                             SYNC_FILE_RANGE_WAIT_AFTER));
@@ -50,10 +63,23 @@ static void verify_sync_file_range(void)
 
        SAFE_CLOSE(fd);
 
-       if (written >= FILE_SIZE)
+       if ((written >= tc->exp_sync_size) &&
+           (written <= (tc->exp_sync_size + tc->exp_sync_size/10)))
                tst_res(TPASS, "Test file range synced to device");
        else
-               tst_res(TFAIL, "Synced %li, expected %i", written,
 FILE_SIZE);
+               tst_res(TFAIL, "Synced %li, expected %li", written,
+                       tc->exp_sync_size);
+}
+
+static struct testcase testcases[] = {
+       { FNAME1, 0, FILE_SZ, FILE_SZ, 0, FILE_SZ_MB },
+       { FNAME2, FILE_SZ/4, FILE_SZ/2, FILE_SZ/2, 0, FILE_SZ_MB },
+       { FNAME3, FILE_SZ/4, FILE_SZ/2, FILE_SZ/4, FILE_SZ/2, FILE_SZ_MB/4
 },
+};
+
+static void run(unsigned int i)
+{
+       verify_sync_file_range(&testcases[i]);
 }

static void setup(void)

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +2 -2
@@ -63,10 +89,11 @@ static void setup(void)
 }
 
 static struct tst_test test = {
+       .tcnt = ARRAY_SIZE(testcases),
        .needs_root = 1,
        .mount_device = 1,
        .all_filesystems = 1,
        .mntpoint = MNTPOINT,
        .setup = setup,
-       .test_all = verify_sync_file_range,
+       .test = run,
 };
--

2.7.4

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190401/2c6a5a02/attachment.html>
author
#6 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Hi Li,

Firstly apologies for the late reply due to travelling for Linaro Connect BKK19.

Quoted 59 lines · Li Wang

Hi Sumit,

Quoted 55 lines · Sumit Garg

Add partial file sync tests as part of sync_file_range02 test-case.

---

Changes in v3:
1. Add upper bound check for synced size to device.
2. Refactor tests for more code reuse.
3. Add another test to check sync over partial write.

Changes in v2:
1. Do full file write instead of partial and test sync partial file.

 .../syscalls/sync_file_range/sync_file_range02.c   | 47 +++++++++++++++++-----
 1 file changed, 37 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +18 -5
index 82d77f7..334ea5e 100644
@@ -22,23 +22,36 @@
 #include "check_sync_file_range.h"
 
 #define MNTPOINT               "mnt_point"
-#define FNAME          MNTPOINT"/test"
-#define FILE_SIZE_MB   32
-#define FILE_SIZE (FILE_SIZE_MB * TST_MB)
+#define FNAME1                 MNTPOINT"/test1"
+#define FNAME2                 MNTPOINT"/test2"
+#define FNAME3                 MNTPOINT"/test3"
+#define FILE_SZ_MB             32
+#define FILE_SZ                        (FILE_SZ_MB * TST_MB)
 #define MODE                   0644
 
-static void verify_sync_file_range(void)
+struct testcase {
+       char *fname;
+       off64_t sync_off;
+       off64_t sync_size;
+       size_t exp_sync_size;
+       off64_t write_off;
+       size_t write_size_mb;
+};
+
+static void verify_sync_file_range(struct testcase *tc)
 {
        int fd;
        unsigned long written;
 
-       fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
+       fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
+
+       lseek(fd, tc->write_off, SEEK_SET);
 
Quoted 7 lines

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c line 52

Quoted 4 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +1 -1
        tst_dev_bytes_written(tst_device->dev);
 
-       tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB);
+       tst_fill_fd(fd, 0, TST_MB, tc->write_size_mb);

I'm just thinking that is probably more precise if we reverse the order of tst_fill_fd() and tst_dev_bytes_written()? Because that does counting the dev_bytes_writen only before and after sync_file_range(), we cann't garantee system does not wirte back to deviece when do fill_fd(), isn't it?

There is another aspect to this if we move tst_dev_bytes_written() after tst_fill_fd() then we may miss count for actual data that may be written back during tst_fill_fd() operation.

AFAIU, LTP uses test-device for all device specific tests of which it has full control and also the tests run sequentially. So I think there are pretty rare chances to have such scenario that you referred too.

-Sumit

Quoted 59 lines
Quoted 51 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +18 -5
-       TEST(sync_file_range(fd, 0, FILE_SIZE,
+       TEST(sync_file_range(fd, tc->sync_off, tc->sync_size,
                             SYNC_FILE_RANGE_WAIT_BEFORE |
                             SYNC_FILE_RANGE_WRITE |
                             SYNC_FILE_RANGE_WAIT_AFTER));
@@ -50,10 +63,23 @@ static void verify_sync_file_range(void)
 
        SAFE_CLOSE(fd);
 
-       if (written >= FILE_SIZE)
+       if ((written >= tc->exp_sync_size) &&
+           (written <= (tc->exp_sync_size + tc->exp_sync_size/10)))
                tst_res(TPASS, "Test file range synced to device");
        else
-               tst_res(TFAIL, "Synced %li, expected %i", written, FILE_SIZE);
+               tst_res(TFAIL, "Synced %li, expected %li", written,
+                       tc->exp_sync_size);
+}
+
+static struct testcase testcases[] = {
+       { FNAME1, 0, FILE_SZ, FILE_SZ, 0, FILE_SZ_MB },
+       { FNAME2, FILE_SZ/4, FILE_SZ/2, FILE_SZ/2, 0, FILE_SZ_MB },
+       { FNAME3, FILE_SZ/4, FILE_SZ/2, FILE_SZ/4, FILE_SZ/2, FILE_SZ_MB/4 },
+};
+
+static void run(unsigned int i)
+{
+       verify_sync_file_range(&testcases[i]);
 }
 
 static void setup(void)
@@ -63,10 +89,11 @@ static void setup(void)
 }
 
 static struct tst_test test = {
+       .tcnt = ARRAY_SIZE(testcases),
        .needs_root = 1,
        .mount_device = 1,
        .all_filesystems = 1,
        .mntpoint = MNTPOINT,
        .setup = setup,
-       .test_all = verify_sync_file_range,
+       .test = run,
 };
--

2.7.4

Quoted 2 lines

--
Mailing list info: https://lists.linux.it/listinfo/ltp

--
Regards,
Li Wang

#7 lore raw

PATCH v3 1/1 syscalls/sync_file_range: add partial file sync test-cases

Quoted 75 lines · Sumit Garg

Hi Li,

Firstly apologies for the late reply due to travelling for Linaro Connect BKK19.

Quoted 19 lines · Li Wang

Hi Sumit,

Quoted 15 lines · Sumit Garg

Add partial file sync tests as part of sync_file_range02 test-case.

---

Changes in v3:
1. Add upper bound check for synced size to device.
2. Refactor tests for more code reuse.
3. Add another test to check sync over partial write.

Changes in v2:
1. Do full file write instead of partial and test sync partial file.

 .../syscalls/sync_file_range/sync_file_range02.c   | 47

+++++++++++++++++-----

Quoted 3 lines
Quoted 3 lines
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git

a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c

Quoted 37 lines
Quoted 37 lines

index 82d77f7..334ea5e 100644

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +18 -5
@@ -22,23 +22,36 @@
 #include "check_sync_file_range.h"
 
 #define MNTPOINT               "mnt_point"
-#define FNAME          MNTPOINT"/test"
-#define FILE_SIZE_MB   32
-#define FILE_SIZE (FILE_SIZE_MB * TST_MB)
+#define FNAME1                 MNTPOINT"/test1"
+#define FNAME2                 MNTPOINT"/test2"
+#define FNAME3                 MNTPOINT"/test3"
+#define FILE_SZ_MB             32
+#define FILE_SZ                        (FILE_SZ_MB * TST_MB)
 #define MODE                   0644
 
-static void verify_sync_file_range(void)
+struct testcase {
+       char *fname;
+       off64_t sync_off;
+       off64_t sync_size;
+       size_t exp_sync_size;
+       off64_t write_off;
+       size_t write_size_mb;
+};
+
+static void verify_sync_file_range(struct testcase *tc)
 {
        int fd;
        unsigned long written;
 
-       fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
+       fd = SAFE_OPEN(tc->fname, O_RDWR|O_CREAT, MODE);
+
+       lseek(fd, tc->write_off, SEEK_SET);
 
Quoted 7 lines

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c line 52

Quoted 4 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c +1 -1
        tst_dev_bytes_written(tst_device->dev);
 
-       tst_fill_fd(fd, 0, TST_MB, FILE_SIZE_MB);
+       tst_fill_fd(fd, 0, TST_MB, tc->write_size_mb);

I'm just thinking that is probably more precise if we reverse the order

Quoted 9 lines

of tst_fill_fd() and tst_dev_bytes_written()? Because that does counting the dev_bytes_writen only before and after sync_file_range(), we cann't garantee system does not wirte back to deviece when do fill_fd(), isn't it?

There is another aspect to this if we move tst_dev_bytes_written() after tst_fill_fd() then we may miss count for actual data that may be written back during tst_fill_fd() operation.

Sounds reasonable, thanks for the clarification.

Quoted 6 lines

AFAIU, LTP uses test-device for all device specific tests of which it has full control and also the tests run sequentially. So I think there are pretty rare chances to have such scenario that you referred too.

-Sumit

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190418/ec9ddc16/attachment-0001.html>