Skip to contentSkip to conversation

pwritev201: Add check for RWF_APPEND

PATCH Superseded Wei Gao via ltp 2 participants 3 messages Oct 26, 2023 – Feb 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwritev201: Add check for RWF_APPEND

---
 .../kernel/syscalls/pwritev2/pwritev201.c      | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/pwritev2/pwritev201.c +11 -7
index eba45b7d3..96572ba73 100644
@@ -39,13 +39,15 @@ static struct tcase {
 	off_t write_off;
 	ssize_t size;
 	off_t exp_off;
+	int flag;
 } tcases[] = {
-	{0,     1, 0,          CHUNK, 0},
-	{CHUNK, 2, 0,          CHUNK, CHUNK},
-	{0,     1, CHUNK / 2,  CHUNK, 0},
-	{0,     1, -1,         CHUNK, CHUNK},
-	{0,     2, -1,         CHUNK, CHUNK},
-	{CHUNK, 1, -1,         CHUNK, CHUNK * 2},
+	{0,     1, 0,          CHUNK, 0, 0},
+	{CHUNK, 2, 0,          CHUNK, CHUNK, 0},
+	{0,     1, CHUNK / 2,  CHUNK, 0, 0},
+	{0,     1, -1,         CHUNK, CHUNK, 0},
+	{0,     2, -1,         CHUNK, CHUNK, 0},
+	{CHUNK, 1, -1,         CHUNK, CHUNK * 2, 0},
+	{CHUNK, 1, -1,         CHUNK, CHUNK * 3, RWF_APPEND},
 };
 
 static void verify_pwritev2(unsigned int n)
@@ -57,7 +59,7 @@ static void verify_pwritev2(unsigned int n)
 	SAFE_PWRITE(1, fd, initbuf, sizeof(initbuf), 0);
 	SAFE_LSEEK(fd, tc->seek_off, SEEK_SET);
 
-	TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, 0));
+	TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, tc->flag));
 	if (TST_RET < 0) {
 		tst_res(TFAIL | TTERRNO, "pwritev2() failed");
 		return;
@@ -78,6 +80,8 @@ static void verify_pwritev2(unsigned int n)
 
 	if (tc->write_off != -1)
 		SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off);
+	else if (tc->flag == RWF_APPEND)
+		SAFE_PREAD(1, fd, preadbuf, tc->size, sizeof(initbuf));
 	else
 		SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off);
 
Signature · 5 lines
2.35.3


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

PATCH v2 1/1 pwritev201: Add check for RWF_APPEND

---
 .../kernel/syscalls/pwritev2/pwritev201.c     | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/pwritev2/pwritev201.c +12 -8
index eba45b7d3..1494e2925 100644
@@ -39,13 +39,15 @@ static struct tcase {
 	off_t write_off;
 	ssize_t size;
 	off_t exp_off;
+	int flag;
 } tcases[] = {
-	{0,     1, 0,          CHUNK, 0},
-	{CHUNK, 2, 0,          CHUNK, CHUNK},
-	{0,     1, CHUNK / 2,  CHUNK, 0},
-	{0,     1, -1,         CHUNK, CHUNK},
-	{0,     2, -1,         CHUNK, CHUNK},
-	{CHUNK, 1, -1,         CHUNK, CHUNK * 2},
+	{0,     1, 0,          CHUNK, 0, 0},
+	{CHUNK, 2, 0,          CHUNK, CHUNK, 0},
+	{0,     1, CHUNK / 2,  CHUNK, 0, 0},
+	{0,     1, -1,         CHUNK, CHUNK, 0},
+	{0,     2, -1,         CHUNK, CHUNK, 0},
+	{CHUNK, 1, -1,         CHUNK, CHUNK * 2, 0},
+	{CHUNK, 1, -1,         CHUNK, CHUNK * 3, RWF_APPEND},
 };
 
 static void verify_pwritev2(unsigned int n)
@@ -57,7 +59,7 @@ static void verify_pwritev2(unsigned int n)
 	SAFE_PWRITE(1, fd, initbuf, sizeof(initbuf), 0);
 	SAFE_LSEEK(fd, tc->seek_off, SEEK_SET);
 
-	TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, 0));
+	TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, tc->flag));
 	if (TST_RET < 0) {
 		tst_res(TFAIL | TTERRNO, "pwritev2() failed");
 		return;
@@ -76,7 +78,9 @@ static void verify_pwritev2(unsigned int n)
 
 	memset(preadbuf, 0, CHUNK);
 
-	if (tc->write_off != -1)
+	if (tc->flag == RWF_APPEND)
+		SAFE_PREAD(1, fd, preadbuf, tc->size, sizeof(initbuf));
+	else if (tc->write_off != -1)
 		SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off);
 	else
 		SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off);
Signature · 5 lines
2.35.3


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

Hi Wei,

according to man readv(2) RWF_APPEND was added in kernel 4.16 (to <linux/fs.h>, thus this fails openSUSE Leap 42.2 [1], we would need to add this to LAPI include/lapi/fs.h (as a separate patch) and use it in the test.

It also fails for the same reason on MUSL, which does not include <linux/fs.h>, I suppose adding <linux/fs.h> to the test would fix it on MUSL, which would be solved by previous change (because include/lapi/fs.h already includes <linux/fs.h>).

[1] https://github.com/pevik/ltp/actions/runs/7799206926/job/21269505359
[2] https://github.com/pevik/ltp/actions/runs/7799206926/job/21269504848

Quoted 18 lines
---
 .../kernel/syscalls/pwritev2/pwritev201.c     | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/pwritev2/pwritev201.c +1 -3
index eba45b7d3..1494e2925 100644
@@ -39,13 +39,15 @@ static struct tcase {
 	off_t write_off;
 	ssize_t size;
 	off_t exp_off;
+	int flag;
 } tcases[] = {
-	{0,     1, 0,          CHUNK, 0},
-	{CHUNK, 2, 0,          CHUNK, CHUNK},
-	{0,     1, CHUNK / 2,  CHUNK, 0},

testcases/kernel/syscalls/pwritev2/pwritev201.c static struct tcase { · line 50

Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +7 -3
-	{0,     1, -1,         CHUNK, CHUNK},
-	{0,     2, -1,         CHUNK, CHUNK},
-	{CHUNK, 1, -1,         CHUNK, CHUNK * 2},
+	{0,     1, 0,          CHUNK, 0, 0},
+	{CHUNK, 2, 0,          CHUNK, CHUNK, 0},
+	{0,     1, CHUNK / 2,  CHUNK, 0, 0},
+	{0,     1, -1,         CHUNK, CHUNK, 0},
+	{0,     2, -1,         CHUNK, CHUNK, 0},
+	{CHUNK, 1, -1,         CHUNK, CHUNK * 2, 0},
+	{CHUNK, 1, -1,         CHUNK, CHUNK * 3, RWF_APPEND},

I wonder how hard would be to cover more flags (man mentions 4 other flags). But on a first look only RWF_APPEND looks to be easy to be added (if complicated, it's probably better to have a separate test for them).

Also, while at it, maybe:

	TST_EXP_FD_SILENT(pwritev2(fd, wr_iovec, tc->count, tc->write_off, 0));
	if (!TST_PASS)
		return;

instead of:

	TEST(pwritev2(fd, wr_iovec, tc->count - 1, tc->write_off, 0));
	if (TST_RET < 0) {
		tst_res(TFAIL | TTERRNO, "pwritev2() failed");
		return;
	}

Kind regards,
Petr

Quoted 23 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c +4 -2
 };
 
 static void verify_pwritev2(unsigned int n)
@@ -57,7 +59,7 @@ static void verify_pwritev2(unsigned int n)
 	SAFE_PWRITE(1, fd, initbuf, sizeof(initbuf), 0);
 	SAFE_LSEEK(fd, tc->seek_off, SEEK_SET);
 
-	TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, 0));
+	TEST(pwritev2(fd, wr_iovec, tc->count, tc->write_off, tc->flag));
 	if (TST_RET < 0) {
 		tst_res(TFAIL | TTERRNO, "pwritev2() failed");
 		return;
@@ -76,7 +78,9 @@ static void verify_pwritev2(unsigned int n)
 
 	memset(preadbuf, 0, CHUNK);
 
-	if (tc->write_off != -1)
+	if (tc->flag == RWF_APPEND)
+		SAFE_PREAD(1, fd, preadbuf, tc->size, sizeof(initbuf));
+	else if (tc->write_off != -1)
 		SAFE_PREAD(1, fd, preadbuf, tc->size, tc->write_off);
 	else
 		SAFE_PREAD(1, fd, preadbuf, tc->size, tc->seek_off);
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp