Skip to contentSkip to conversation

aiocp: Filter out O_DIRECT before read

PATCH In review Ping Fang 5 participants 5 messages Feb 9, 2023 – Feb 10, 2023

lore
Share & tools
lore

Ping Fang

author
#0 lore raw

PATCH 1/1 aiocp: Filter out O_DIRECT before read

When aiocp executed with -f DIRECT will fail.

<<<test_start>>>
tag=AD049 stime=1675520824
cmdline="aiocp -b 8k -n 8 -f DIRECT"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1560: TINFO: Timeout per run is 0h 30m 30s
aiocp.c:211: TINFO: Maximum AIO blocks: 65536
tst_device.c:585: TINFO: Use uevent strategy
aiocp.c:250: TINFO: Fill srcfile.bin with random data
aiocp.c:279: TINFO: Copy srcfile.bin -> dstfile.bin
aiocp.c:291: TINFO: Comparing srcfile.bin with dstfile.bin aiocp.c:306: TBROK: read(3,0x7ffcd743abe0,4096) failed, returned -1: EINVAL (22)
...

syscall read manual ERROR section said that:
EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the file offset is not suitably aligned.

We need filter out O_DIRECT flag before read.

---
 testcases/kernel/io/ltp-aiodio/aiocp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/io/ltp-aiodio/aiocp.c +2 -2
index bc0e209b2..e4252d641 100644
@@ -297,8 +297,8 @@ static void run(void)
 		return;
 	}
 
-	srcfd = SAFE_OPEN(srcname, srcflags | O_RDONLY, 0666);
-	dstfd = SAFE_OPEN(dstname, srcflags | O_RDONLY, 0666);
+	srcfd = SAFE_OPEN(srcname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);
+	dstfd = SAFE_OPEN(dstname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);
 
 	reads = howmany(filesize, buffsize);
 
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 17 lines

When aiocp executed with -f DIRECT will fail.

<<<test_start>>>
tag=AD049 stime=1675520824
cmdline="aiocp -b 8k -n 8 -f DIRECT"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1560: TINFO: Timeout per run is 0h 30m 30s
aiocp.c:211: TINFO: Maximum AIO blocks: 65536
tst_device.c:585: TINFO: Use uevent strategy
aiocp.c:250: TINFO: Fill srcfile.bin with random data
aiocp.c:279: TINFO: Copy srcfile.bin -> dstfile.bin
aiocp.c:291: TINFO: Comparing srcfile.bin with dstfile.bin aiocp.c:306: TBROK: read(3,0x7ffcd743abe0,4096) failed, returned -1: EINVAL (22)
...

Quoted 7 lines

syscall read manual ERROR section said that:
EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the file offset is not suitably aligned.

We need filter out O_DIRECT flag before read.

This is not very good changelog, I had to look closely at the source to figure out why we may need this.

Better description should say that the code which checks that the data has been written correctly does not use aligned buffers, which may cause a failure like the one above.

Quoted 10 lines
---
 testcases/kernel/io/ltp-aiodio/aiocp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -0
index bc0e209b2..e4252d641 100644

testcases/kernel/io/ltp-aiodio/aiocp.c static void run(void) · line 301

Quoted 7 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +2 -2
@@ -297,8 +297,8 @@ static void run(void)
 		return;
 	}
 
-	srcfd = SAFE_OPEN(srcname, srcflags | O_RDONLY, 0666);
-	dstfd = SAFE_OPEN(dstname, srcflags | O_RDONLY, 0666);
+	srcfd = SAFE_OPEN(srcname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);
+	dstfd = SAFE_OPEN(dstname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);

I guess that we can as well just remove the srcflags and keep just the O_RDONLY since the srcflags are by definition either O_RDONLY or O_DIRECT | O_RDONLY.

I suppose that using scrflags and dstflags for anything else than the filedescriptors passed to the async_run() is actually a mistake.

Quoted 8 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -0
 	reads = howmany(filesize, buffsize);
 
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi,

Quoted 53 lines · Cyril Hrubis

Hi!

Quoted 17 lines

When aiocp executed with -f DIRECT will fail.

<<<test_start>>>
tag=AD049 stime=1675520824
cmdline="aiocp -b 8k -n 8 -f DIRECT"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1560: TINFO: Timeout per run is 0h 30m 30s
aiocp.c:211: TINFO: Maximum AIO blocks: 65536
tst_device.c:585: TINFO: Use uevent strategy
aiocp.c:250: TINFO: Fill srcfile.bin with random data
aiocp.c:279: TINFO: Copy srcfile.bin -> dstfile.bin
aiocp.c:291: TINFO: Comparing srcfile.bin with dstfile.bin aiocp.c:306: TBROK: read(3,0x7ffcd743abe0,4096) failed, returned -1: EINVAL (22)
...

Quoted 7 lines

syscall read manual ERROR section said that:
EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the file offset is not suitably aligned.

We need filter out O_DIRECT flag before read.

This is not very good changelog, I had to look closely at the source to figure out why we may need this.

Better description should say that the code which checks that the data has been written correctly does not use aligned buffers, which may cause a failure like the one above.

Quoted 10 lines
---
  testcases/kernel/io/ltp-aiodio/aiocp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -0
index bc0e209b2..e4252d641 100644

testcases/kernel/io/ltp-aiodio/aiocp.c static void run(void) · line 301

Quoted 7 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +2 -2
@@ -297,8 +297,8 @@ static void run(void)
  		return;
  	}
 
-	srcfd = SAFE_OPEN(srcname, srcflags | O_RDONLY, 0666);
-	dstfd = SAFE_OPEN(dstname, srcflags | O_RDONLY, 0666);
+	srcfd = SAFE_OPEN(srcname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);
+	dstfd = SAFE_OPEN(dstname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);

I guess that we can as well just remove the srcflags and keep just the O_RDONLY since the srcflags are by definition either O_RDONLY or O_DIRECT | O_RDONLY.

Quoted 3 lines

I suppose that using scrflags and dstflags for anything else than the filedescriptors passed to the async_run() is actually a mistake.

I agree with this. Probably we only need:

    srcfd = SAFE_OPEN(srcname, O_RDONLY, 0666);
    dstfd = SAFE_OPEN(dstname, O_RDONLY, 0666);

Quoted 8 lines
Quoted 8 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -0
  	reads = howmany(filesize, buffsize);
 
Signature · 5 lines
2.31.1


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

Regards,
Andrea Cervesato

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Cyril Hrubis
Quoted 25 lines · Cyril Hrubis

Hi!

Quoted 23 lines

When aiocp executed with -f DIRECT will fail.

<<<test_start>>>
tag=AD049 stime=1675520824
cmdline="aiocp -b 8k -n 8 -f DIRECT"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1560: TINFO: Timeout per run is 0h 30m 30s
aiocp.c:211: TINFO: Maximum AIO blocks: 65536
tst_device.c:585: TINFO: Use uevent strategy
aiocp.c:250: TINFO: Fill srcfile.bin with random data
aiocp.c:279: TINFO: Copy srcfile.bin -> dstfile.bin
aiocp.c:291: TINFO: Comparing srcfile.bin with dstfile.bin aiocp.c:306: TBROK: read(3,0x7ffcd743abe0,4096) failed, returned -1: EINVAL (22)
...

syscall read manual ERROR section said that:
EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the file offset is not suitably aligned.

Quoted 8 lines
Quoted 1 line

We need filter out O_DIRECT flag before read.

This is not very good changelog, I had to look closely at the source to figure out why we may need this.

Better description should say that the code which checks that the data has been written correctly does not use aligned buffers, which may cause a failure like the one above.

+1, I also found it confusing (do we pass DIRECT as parameter just to ignore it?)

Quoted 42 lines
Quoted 11 lines
---
 testcases/kernel/io/ltp-aiodio/aiocp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -0
index bc0e209b2..e4252d641 100644

testcases/kernel/io/ltp-aiodio/aiocp.c static void run(void) · line 301

Quoted 7 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +2 -2
@@ -297,8 +297,8 @@ static void run(void)
              return;
      }
 
-     srcfd = SAFE_OPEN(srcname, srcflags | O_RDONLY, 0666);
-     dstfd = SAFE_OPEN(dstname, srcflags | O_RDONLY, 0666);
+     srcfd = SAFE_OPEN(srcname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);
+     dstfd = SAFE_OPEN(dstname, (srcflags & ~O_DIRECT) | O_RDONLY, 0666);

I guess that we can as well just remove the srcflags and keep just the O_RDONLY since the srcflags are by definition either O_RDONLY or O_DIRECT | O_RDONLY.

I suppose that using scrflags and dstflags for anything else than the filedescriptors passed to the async_run() is actually a mistake.

Quoted 8 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -1
      reads = howmany(filesize, buffsize);
 
--

2.31.1

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

--
Cyril Hrubis
[email protected]

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 32 lines · Jan Stancek
Quoted 17 lines · Cyril Hrubis

Hi!

Quoted 15 lines

When aiocp executed with -f DIRECT will fail.

<<<test_start>>>
tag=AD049 stime=1675520824
cmdline="aiocp -b 8k -n 8 -f DIRECT"
contacts=""
analysis=exit
<<<test_output>>>
tst_test.c:1560: TINFO: Timeout per run is 0h 30m 30s aiocp.c:211: TINFO: Maximum AIO blocks: 65536 tst_device.c:585: TINFO: Use uevent strategy
aiocp.c:250: TINFO: Fill srcfile.bin with random data aiocp.c:279: TINFO: Copy srcfile.bin -> dstfile.bin aiocp.c:291: TINFO: Comparing srcfile.bin with dstfile.bin aiocp.c:306: TBROK: read(3,0x7ffcd743abe0,4096) failed, returned -1:

EINVAL (22)

Quoted 13 lines
Quoted 9 lines

...

syscall read manual ERROR section said that:
EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the file offset is not suitably aligned.

We need filter out O_DIRECT flag before read.

This is not very good changelog, I had to look closely at the source to figure out why we may need this.

Quoted 7 lines
Quoted 3 lines

Better description should say that the code which checks that the data has been written correctly does not use aligned buffers, which may cause a failure like the one above.

+1, I also found it confusing (do we pass DIRECT as parameter just to ignore it?)

The data has been written successfully with DIRECT, the failure happens when reading it again with DIRECT flag.

Quoted 48 lines
Quoted 8 lines

Review

Quoted 8 lines
---
 testcases/kernel/io/ltp-aiodio/aiocp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/testcases/kernel/io/ltp-aiodio/aiocp.c

Quoted 10 lines

testcases/kernel/io/ltp-aiodio/aiocp.c static void run(void) · line 300

Quoted 10 lines

index bc0e209b2..e4252d641 100644

testcases/kernel/io/ltp-aiodio/aiocp.c +1 -2
@@ -297,8 +297,8 @@ static void run(void)
              return;
      }
 
-     srcfd = SAFE_OPEN(srcname, srcflags | O_RDONLY, 0666);
-     dstfd = SAFE_OPEN(dstname, srcflags | O_RDONLY, 0666);
+     srcfd = SAFE_OPEN(srcname, (srcflags & ~O_DIRECT) | O_RDONLY,

0666);

Quoted 1 line

testcases/kernel/io/ltp-aiodio/aiocp.c static void run(void) · line 301

Quoted 1 line
testcases/kernel/io/ltp-aiodio/aiocp.c +1 -0
+     dstfd = SAFE_OPEN(dstname, (srcflags & ~O_DIRECT) | O_RDONLY,

0666);

Quoted 24 lines

I guess that we can as well just remove the srcflags and keep just the O_RDONLY since the srcflags are by definition either O_RDONLY or O_DIRECT | O_RDONLY.

I suppose that using scrflags and dstflags for anything else than the filedescriptors passed to the async_run() is actually a mistake.

Quoted 8 lines
testcases/kernel/io/ltp-aiodio/aiocp.c +0 -1
      reads = howmany(filesize, buffsize);
 
--

2.31.1

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

--
Cyril Hrubis
[email protected]

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

Signature · 5 lines
Regards,
Li Wang

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