All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems
@ 2018-03-30  8:53 Xiao Yang
  2018-03-30  8:53 ` [LTP] [PATCH 2/2] syscalls/pwritev01: " Xiao Yang
  2018-04-05  9:52 ` [LTP] [PATCH 1/2] syscalls/preadv01: " Cyril Hrubis
  0 siblings, 2 replies; 16+ messages in thread
From: Xiao Yang @ 2018-03-30  8:53 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/preadv/preadv01.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/preadv/preadv01.c b/testcases/kernel/syscalls/preadv/preadv01.c
index 5ee27fb..1f3f714 100644
--- a/testcases/kernel/syscalls/preadv/preadv01.c
+++ b/testcases/kernel/syscalls/preadv/preadv01.c
@@ -30,6 +30,8 @@
 #include "preadv.h"
 
 #define CHUNK           64
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
 
 static int fd;
 static char buf[CHUNK];
@@ -97,7 +99,7 @@ void setup(void)
 {
 	char buf[CHUNK];
 
-	fd = SAFE_OPEN("file", O_RDWR | O_CREAT, 0644);
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0644);
 
 	memset(buf, 'a', sizeof(buf));
 	SAFE_WRITE(1, fd, buf, sizeof(buf));
@@ -119,4 +121,7 @@ static struct tst_test test = {
 	.test = verify_preadv,
 	.min_kver = "2.6.30",
 	.needs_tmpdir = 1,
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
 };
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH 2/2] syscalls/pwritev01: Run test for all filesystems
  2018-03-30  8:53 [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems Xiao Yang
@ 2018-03-30  8:53 ` Xiao Yang
  2018-04-05  9:52 ` [LTP] [PATCH 1/2] syscalls/preadv01: " Cyril Hrubis
  1 sibling, 0 replies; 16+ messages in thread
From: Xiao Yang @ 2018-03-30  8:53 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/pwritev/pwritev01.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/pwritev/pwritev01.c b/testcases/kernel/syscalls/pwritev/pwritev01.c
index 7c97f72..aeff995 100644
--- a/testcases/kernel/syscalls/pwritev/pwritev01.c
+++ b/testcases/kernel/syscalls/pwritev/pwritev01.c
@@ -31,6 +31,8 @@
 #include "tst_safe_prw.h"
 
 #define	CHUNK		64
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
 
 static char buf[CHUNK];
 static char initbuf[CHUNK * 2];
@@ -99,7 +101,7 @@ static void setup(void)
 {
 	memset(&buf, 0x61, CHUNK);
 
-	fd = SAFE_OPEN("file", O_RDWR | O_CREAT, 0644);
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0644);
 }
 
 static void cleanup(void)
@@ -115,4 +117,7 @@ static struct tst_test test = {
 	.test = verify_pwritev,
 	.min_kver = "2.6.30",
 	.needs_tmpdir = 1,
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
 };
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems
  2018-03-30  8:53 [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems Xiao Yang
  2018-03-30  8:53 ` [LTP] [PATCH 2/2] syscalls/pwritev01: " Xiao Yang
@ 2018-04-05  9:52 ` Cyril Hrubis
  2018-04-05 10:56   ` Xiao Yang
  1 sibling, 1 reply; 16+ messages in thread
From: Cyril Hrubis @ 2018-04-05  9:52 UTC (permalink / raw)
  To: ltp

Hi!
Looking at the test running it for all filesystems would not make much
sense as it is since as far as I can tell:

1) setup() creates a file and writes data to it
   - dirty pagecache record is created

2) test() reads data from the file
   - kernel will copy the data from pagecache

3) test library cleanup will umount() the device
   - dirty pagecache is written at this point

So we will not reach any filesystem specific code at all.

I guess that we may fix that by opening second file descriptor with
O_DIRECT which would bypass pagecache so each read/write request would
trigger I/O request from the block device.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems
  2018-04-05  9:52 ` [LTP] [PATCH 1/2] syscalls/preadv01: " Cyril Hrubis
@ 2018-04-05 10:56   ` Xiao Yang
  2018-04-05 11:02     ` Cyril Hrubis
  0 siblings, 1 reply; 16+ messages in thread
From: Xiao Yang @ 2018-04-05 10:56 UTC (permalink / raw)
  To: ltp

On 2018/04/05 17:52, Cyril Hrubis wrote:
> Hi!
> Looking at the test running it for all filesystems would not make much
> sense as it is since as far as I can tell:
>
> 1) setup() creates a file and writes data to it
>     - dirty pagecache record is created
>
> 2) test() reads data from the file
>     - kernel will copy the data from pagecache
>
> 3) test library cleanup will umount() the device
>     - dirty pagecache is written at this point
>
> So we will not reach any filesystem specific code at all.
>
> I guess that we may fix that by opening second file descriptor with
> O_DIRECT which would bypass pagecache so each read/write request would
> trigger I/O request from the block device.
Hi Cyril,

Sorry, i ignored the fact that they use pagecache.
Can we just keep them and add two new tests as you suggested?

Thanks,
Xiao Yang



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems
  2018-04-05 10:56   ` Xiao Yang
@ 2018-04-05 11:02     ` Cyril Hrubis
  2018-04-06 10:50       ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase Xiao Yang
  0 siblings, 1 reply; 16+ messages in thread
From: Cyril Hrubis @ 2018-04-05 11:02 UTC (permalink / raw)
  To: ltp

Hi!
> > Looking at the test running it for all filesystems would not make much
> > sense as it is since as far as I can tell:
> >
> > 1) setup() creates a file and writes data to it
> >     - dirty pagecache record is created
> >
> > 2) test() reads data from the file
> >     - kernel will copy the data from pagecache
> >
> > 3) test library cleanup will umount() the device
> >     - dirty pagecache is written at this point
> >
> > So we will not reach any filesystem specific code at all.
> >
> > I guess that we may fix that by opening second file descriptor with
> > O_DIRECT which would bypass pagecache so each read/write request would
> > trigger I/O request from the block device.
> Hi Cyril,
> 
> Sorry, i ignored the fact that they use pagecache.
> Can we just keep them and add two new tests as you suggested?

I was simply thinking about opening second fd with O_DIRECT in the test
setup and running the test twice, once for the regular fd and once for
the O_DIRECT one, however creating new test would work as well and may
be even cleaner solution.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase
  2018-04-05 11:02     ` Cyril Hrubis
@ 2018-04-06 10:50       ` Xiao Yang
  2018-04-06 10:50         ` [LTP] [PATCH v2 2/2] pwritev/pwritev03.c: " Xiao Yang
  2018-04-06 13:02         ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: " Cyril Hrubis
  0 siblings, 2 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-06 10:50 UTC (permalink / raw)
  To: ltp

Check the basic functionality of the preadv(2) for the file
opened with O_DIRECT in all filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 +
 runtest/stress.part3                        |   1 +
 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/.gitignore        |   2 +
 testcases/kernel/syscalls/preadv/preadv03.c | 143 ++++++++++++++++++++++++++++
 5 files changed, 149 insertions(+)
 create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 15dc0c2..e8c6900 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -589,6 +589,7 @@ pread03 pread03
 
 preadv01 preadv01
 preadv02 preadv02
+preadv03 preadv03
 
 profil01 profil01
 
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 2a7747c..be912c8 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -496,6 +496,7 @@ pread03 pread03
 
 preadv01 preadv01
 preadv02 preadv02
+preadv03 preadv03
 
 profil01 profil01
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 76ab082..fb71c38 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -821,6 +821,8 @@ preadv01 preadv01
 preadv01_64 preadv01_64
 preadv02 preadv02
 preadv02_64 preadv02_64
+preadv03 preadv03
+preadv03_64 preadv03_64
 
 profil01 profil01
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index eea606e..ec2af68 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -696,6 +696,8 @@
 /preadv/preadv01_64
 /preadv/preadv02
 /preadv/preadv02_64
+/preadv/preadv03
+/preadv/preadv03_64
 /profil/profil01
 /pselect/pselect01
 /pselect/pselect01_64
diff --git a/testcases/kernel/syscalls/preadv/preadv03.c b/testcases/kernel/syscalls/preadv/preadv03.c
new file mode 100644
index 0000000..3963d07
--- /dev/null
+++ b/testcases/kernel/syscalls/preadv/preadv03.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * Test Name: preadv03
+ *
+ * Test Description:
+ * Check the basic functionality of the preadv(2) for the file
+ * opened with O_DIRECT in all filesystem.
+ * Preadv(2) should succeed to read the expected content of data
+ * and after reading the file, the file offset is not changed.
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/uio.h>
+#include "tst_test.h"
+#include "preadv.h"
+
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
+
+static int fd, pgsz;
+static off_t org_off, tst_off1, tst_off2;
+static ssize_t exp_sz1, exp_sz2;
+static char *pop_buf;
+static struct iovec *rd_iovec;
+
+static struct tcase {
+	int count;
+	off_t *offset;
+	ssize_t *size;
+	char content;
+} tcases[] = {
+	{1, &org_off, &exp_sz1, 0x61},
+	{2, &org_off, &exp_sz1, 0x61},
+	{1, &tst_off1, &exp_sz1, 0x62},
+	{1, &tst_off2, &exp_sz2, 0x62},
+};
+
+static void verify_direct_preadv(unsigned int n)
+{
+	int i;
+	char *vec;
+	struct tcase *tc = &tcases[n];
+
+	vec = rd_iovec->iov_base;
+	memset(vec, 0x00, pgsz);
+
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+
+	TEST(preadv(fd, rd_iovec, tc->count, *tc->offset));
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "Preadv(O_DIRECT) fails");
+		return;
+	}
+
+	if (TEST_RETURN != *tc->size) {
+		tst_res(TFAIL, "Preadv(O_DIRECT) read %li bytes, expected %zi",
+			 TEST_RETURN, *tc->size);
+		return;
+	}
+
+	for (i = 0; i < *tc->size; i++) {
+		if (vec[i] != tc->content)
+			break;
+	}
+
+	if (i < *tc->size) {
+		tst_res(TFAIL, "Buffer wrong at %i have %02x expected %02x",
+			 i, vec[i], tc->content);
+		return;
+	}
+
+	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
+		tst_res(TFAIL, "Preadv(O_DIRECT) has changed file offset");
+		return;
+	}
+
+	tst_res(TPASS, "Preadv(O_DIRECT) read %zi bytes successfully "
+		 "with content '%c' expectedly", *tc->size, tc->content);
+}
+
+static void setup(void)
+{
+	pgsz = getpagesize();
+	tst_off1 = pgsz;
+	tst_off2 = pgsz * 3 / 2;
+	exp_sz1 = pgsz;
+	exp_sz2 = pgsz / 2;
+
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
+
+	pop_buf = SAFE_MEMALIGN(pgsz, pgsz);
+	memset(pop_buf, 0x61, pgsz);
+	SAFE_WRITE(1, fd, pop_buf, pgsz);
+
+	memset(pop_buf, 0x62, pgsz);
+	SAFE_WRITE(1, fd, pop_buf, pgsz);
+
+	rd_iovec = SAFE_MEMALIGN(pgsz, pgsz + sizeof(size_t));
+	rd_iovec->iov_base = SAFE_MEMALIGN(pgsz, pgsz);
+	rd_iovec->iov_len = pgsz;
+}
+
+static void cleanup(void)
+{
+	free(pop_buf);
+	free(rd_iovec->iov_base);
+	free(rd_iovec);
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_direct_preadv,
+	.min_kver = "2.6.30",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v2 2/2] pwritev/pwritev03.c: Add new testcase
  2018-04-06 10:50       ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase Xiao Yang
@ 2018-04-06 10:50         ` Xiao Yang
  2018-04-06 13:02         ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: " Cyril Hrubis
  1 sibling, 0 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-06 10:50 UTC (permalink / raw)
  To: ltp

Check the basic functionality of the pwritev(2) for the file
opened with O_DIRECT in all filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                               |   1 +
 runtest/stress.part3                          |   1 +
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/.gitignore          |   2 +
 testcases/kernel/syscalls/pwritev/pwritev03.c | 137 ++++++++++++++++++++++++++
 5 files changed, 143 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index e8c6900..1f4d91c 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64
 
 pwritev01 pwritev01
 pwritev02 pwritev02
+pwritev03 pwritev03
 
 read01 read01
 read02 read02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index be912c8..96f7953 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64
 
 pwritev01 pwritev01
 pwritev02 pwritev02
+pwritev03 pwritev03
 
 read01 read01
 read02 read02
diff --git a/runtest/syscalls b/runtest/syscalls
index fb71c38..8461b94 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -865,6 +865,8 @@ pwritev01 pwritev01
 pwritev01_64 pwritev01_64
 pwritev02 pwritev02
 pwritev02_64 pwritev02_64
+pwritev03 pwritev03
+pwritev03_64 pwritev03_64
 
 quotactl01 quotactl01
 quotactl02 quotactl02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index ec2af68..c3bc662 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -726,6 +726,8 @@
 /pwritev/pwritev01_64
 /pwritev/pwritev02
 /pwritev/pwritev02_64
+/pwritev/pwritev03
+/pwritev/pwritev03_64
 /quotactl/quotactl01
 /quotactl/quotactl02
 /quotactl/quotactl03
diff --git a/testcases/kernel/syscalls/pwritev/pwritev03.c b/testcases/kernel/syscalls/pwritev/pwritev03.c
new file mode 100644
index 0000000..0d955c2
--- /dev/null
+++ b/testcases/kernel/syscalls/pwritev/pwritev03.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * Test Name: pwritev03
+ *
+ * Test Description:
+ * Check the basic functionality of the pwritev(2) for the file
+ * opened with O_DIRECT in all filesystem.
+ * pwritev(2) should succeed to write the expected content of data
+ * and after writing the file, the file offset is not changed.
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/uio.h>
+#include "tst_test.h"
+#include "pwritev.h"
+#include "tst_safe_prw.h"
+
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
+
+static char *initbuf;
+static char *preadbuf;
+static struct iovec *wr_iovec;
+static int fd, pgsz;
+static off_t org_off, tst_off;
+static ssize_t exp_sz;
+
+static struct tcase {
+	int count;
+	off_t *offset;
+	ssize_t *size;
+} tcases[] = {
+	{1, &org_off, &exp_sz},
+	{2, &org_off, &exp_sz},
+	{1, &tst_off, &exp_sz},
+};
+
+static void verify_direct_pwritev(unsigned int n)
+{
+	int i;
+	struct tcase *tc = &tcases[n];
+
+	SAFE_PWRITE(1, fd, initbuf, pgsz, 0);
+
+	TEST(pwritev(fd, wr_iovec, tc->count, *tc->offset));
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "Pwritev(O_DIRECT) fails");
+		return;
+	}
+
+	if (TEST_RETURN != *tc->size) {
+		tst_res(TFAIL, "Pwritev(O_DIRECT) wrote %li bytes, expected %zi",
+			 TEST_RETURN, *tc->size);
+		return;
+	}
+
+	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
+		tst_res(TFAIL, "Pwritev(O_DIRECT) had changed file offset");
+		return;
+	}
+
+	memset(preadbuf, 0x00, pgsz);
+	SAFE_PREAD(1, fd, preadbuf, *tc->size, *tc->offset);
+
+	for (i = 0; i < *tc->size; i++) {
+		if (preadbuf[i] != 0x61)
+			break;
+	}
+
+	if (i != *tc->size) {
+		tst_res(TFAIL, "Buffer wrong at %i have %02x expected 0x61",
+			 i, preadbuf[i]);
+		return;
+	}
+
+	tst_res(TPASS, "Pwritev(O_DIRECT) wrote %zi bytes successfully "
+		 "with content 'a' expectedly ", *tc->size);
+}
+
+static void setup(void)
+{
+	pgsz = getpagesize();
+	tst_off = pgsz / 2;
+	exp_sz = pgsz;
+
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
+
+	initbuf = SAFE_MEMALIGN(pgsz, pgsz);
+	memset(initbuf, 0x00, pgsz);
+
+	preadbuf = SAFE_MEMALIGN(pgsz, pgsz);
+
+	wr_iovec = SAFE_MEMALIGN(pgsz, pgsz + sizeof(size_t));
+	wr_iovec->iov_base = SAFE_MEMALIGN(pgsz, pgsz);
+	wr_iovec->iov_len = pgsz;
+	memset(wr_iovec->iov_base, 0x61, pgsz);
+}
+
+static void cleanup(void)
+{
+	free(initbuf);
+	free(preadbuf);
+	free(wr_iovec->iov_base);
+	free(wr_iovec);
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_direct_pwritev,
+	.min_kver = "2.6.30",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase
  2018-04-06 10:50       ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase Xiao Yang
  2018-04-06 10:50         ` [LTP] [PATCH v2 2/2] pwritev/pwritev03.c: " Xiao Yang
@ 2018-04-06 13:02         ` Cyril Hrubis
  2018-04-09  3:24           ` [LTP] [PATCH v3 " Xiao Yang
  2018-04-09  3:34           ` [LTP] [PATCH v2 " Xiao Yang
  1 sibling, 2 replies; 16+ messages in thread
From: Cyril Hrubis @ 2018-04-06 13:02 UTC (permalink / raw)
  To: ltp

Hi!
> +static void setup(void)
> +{
> +	pgsz = getpagesize();
> +	tst_off1 = pgsz;
> +	tst_off2 = pgsz * 3 / 2;
> +	exp_sz1 = pgsz;
> +	exp_sz2 = pgsz / 2;
> +
> +	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
> +
> +	pop_buf = SAFE_MEMALIGN(pgsz, pgsz);
> +	memset(pop_buf, 0x61, pgsz);
> +	SAFE_WRITE(1, fd, pop_buf, pgsz);
> +
> +	memset(pop_buf, 0x62, pgsz);
> +	SAFE_WRITE(1, fd, pop_buf, pgsz);
> +
> +	rd_iovec = SAFE_MEMALIGN(pgsz, pgsz + sizeof(size_t));
> +	rd_iovec->iov_base = SAFE_MEMALIGN(pgsz, pgsz);
> +	rd_iovec->iov_len = pgsz;

The open(2) manual page says that O_DIRECT buffers should be aligned to
disk block size which can be queried by BLKSSZGET ioctl(). And I suppose
that the offsets should be multiple of the disk block size as well.

> +}
> +
> +static void cleanup(void)
> +{
> +	free(pop_buf);
> +	free(rd_iovec->iov_base);
> +	free(rd_iovec);
> +
> +	if (fd > 0)
> +		SAFE_CLOSE(fd);
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v3 1/2] preadv/preadv03.c: Add new testcase
  2018-04-06 13:02         ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: " Cyril Hrubis
@ 2018-04-09  3:24           ` Xiao Yang
  2018-04-09  3:24             ` [LTP] [PATCH v3 2/2] pwritev/pwritev03.c: " Xiao Yang
  2018-04-09 12:57             ` [LTP] [PATCH v3 1/2] preadv/preadv03.c: " Cyril Hrubis
  2018-04-09  3:34           ` [LTP] [PATCH v2 " Xiao Yang
  1 sibling, 2 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-09  3:24 UTC (permalink / raw)
  To: ltp

Check the basic functionality of the preadv(2) for the file
opened with O_DIRECT in all filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 +
 runtest/stress.part3                        |   1 +
 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/.gitignore        |   2 +
 testcases/kernel/syscalls/preadv/preadv03.c | 146 ++++++++++++++++++++++++++++
 5 files changed, 152 insertions(+)
 create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 15dc0c2..e8c6900 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -589,6 +589,7 @@ pread03 pread03
 
 preadv01 preadv01
 preadv02 preadv02
+preadv03 preadv03
 
 profil01 profil01
 
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 2a7747c..be912c8 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -496,6 +496,7 @@ pread03 pread03
 
 preadv01 preadv01
 preadv02 preadv02
+preadv03 preadv03
 
 profil01 profil01
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 76ab082..fb71c38 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -821,6 +821,8 @@ preadv01 preadv01
 preadv01_64 preadv01_64
 preadv02 preadv02
 preadv02_64 preadv02_64
+preadv03 preadv03
+preadv03_64 preadv03_64
 
 profil01 profil01
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index eea606e..ec2af68 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -696,6 +696,8 @@
 /preadv/preadv01_64
 /preadv/preadv02
 /preadv/preadv02_64
+/preadv/preadv03
+/preadv/preadv03_64
 /profil/profil01
 /pselect/pselect01
 /pselect/pselect01_64
diff --git a/testcases/kernel/syscalls/preadv/preadv03.c b/testcases/kernel/syscalls/preadv/preadv03.c
new file mode 100644
index 0000000..077063a
--- /dev/null
+++ b/testcases/kernel/syscalls/preadv/preadv03.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * Test Name: preadv03
+ *
+ * Test Description:
+ * Check the basic functionality of the preadv(2) for the file
+ * opened with O_DIRECT in all filesystem.
+ * Preadv(2) should succeed to read the expected content of data
+ * and after reading the file, the file offset is not changed.
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <string.h>
+#include <sys/uio.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "tst_test.h"
+#include "preadv.h"
+
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
+
+static int fd, blksz;
+static off_t org_off, tst_off;
+static ssize_t exp_sz;
+static char *pop_buf;
+static struct iovec *rd_iovec;
+
+static struct tcase {
+	int count;
+	off_t *offset;
+	ssize_t *size;
+	char content;
+} tcases[] = {
+	{1, &org_off, &exp_sz, 0x61},
+	{2, &org_off, &exp_sz, 0x61},
+	{1, &tst_off, &exp_sz, 0x62},
+};
+
+static void verify_direct_preadv(unsigned int n)
+{
+	int i;
+	char *vec;
+	struct tcase *tc = &tcases[n];
+
+	vec = rd_iovec->iov_base;
+	memset(vec, 0x00, blksz);
+
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+
+	TEST(preadv(fd, rd_iovec, tc->count, *tc->offset));
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "Preadv(O_DIRECT) fails");
+		return;
+	}
+
+	if (TEST_RETURN != *tc->size) {
+		tst_res(TFAIL, "Preadv(O_DIRECT) read %li bytes, expected %zi",
+			 TEST_RETURN, *tc->size);
+		return;
+	}
+
+	for (i = 0; i < *tc->size; i++) {
+		if (vec[i] != tc->content)
+			break;
+	}
+
+	if (i < *tc->size) {
+		tst_res(TFAIL, "Buffer wrong at %i have %02x expected %02x",
+			 i, vec[i], tc->content);
+		return;
+	}
+
+	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
+		tst_res(TFAIL, "Preadv(O_DIRECT) has changed file offset");
+		return;
+	}
+
+	tst_res(TPASS, "Preadv(O_DIRECT) read %zi bytes successfully "
+		 "with content '%c' expectedly", *tc->size, tc->content);
+}
+
+static void setup(void)
+{
+	int dev_fd;
+
+	dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR);
+	if (ioctl(dev_fd, BLKSSZGET, &blksz)) {
+		SAFE_CLOSE(dev_fd);
+		tst_brk(TBROK | TERRNO, "ioctl(%s, BLKSSZGET) failed",
+			tst_device->dev);
+	}
+	SAFE_CLOSE(dev_fd);
+	tst_off = blksz;
+	exp_sz = blksz;
+
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
+
+	pop_buf = SAFE_MEMALIGN(blksz, blksz);
+	memset(pop_buf, 0x61, blksz);
+	SAFE_WRITE(1, fd, pop_buf, blksz);
+
+	memset(pop_buf, 0x62, blksz);
+	SAFE_WRITE(1, fd, pop_buf, blksz);
+
+	rd_iovec = SAFE_MEMALIGN(blksz, blksz + sizeof(size_t));
+	rd_iovec->iov_base = SAFE_MEMALIGN(blksz, blksz);
+	rd_iovec->iov_len = blksz;
+}
+
+static void cleanup(void)
+{
+	free(pop_buf);
+	free(rd_iovec->iov_base);
+	free(rd_iovec);
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_direct_preadv,
+	.min_kver = "2.6.30",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v3 2/2] pwritev/pwritev03.c: Add new testcase
  2018-04-09  3:24           ` [LTP] [PATCH v3 " Xiao Yang
@ 2018-04-09  3:24             ` Xiao Yang
  2018-04-09 12:57             ` [LTP] [PATCH v3 1/2] preadv/preadv03.c: " Cyril Hrubis
  1 sibling, 0 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-09  3:24 UTC (permalink / raw)
  To: ltp

Check the basic functionality of the pwritev(2) for the file
opened with O_DIRECT in all filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                               |   1 +
 runtest/stress.part3                          |   1 +
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/.gitignore          |   2 +
 testcases/kernel/syscalls/pwritev/pwritev03.c | 146 ++++++++++++++++++++++++++
 5 files changed, 152 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index e8c6900..1f4d91c 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64
 
 pwritev01 pwritev01
 pwritev02 pwritev02
+pwritev03 pwritev03
 
 read01 read01
 read02 read02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index be912c8..96f7953 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64
 
 pwritev01 pwritev01
 pwritev02 pwritev02
+pwritev03 pwritev03
 
 read01 read01
 read02 read02
diff --git a/runtest/syscalls b/runtest/syscalls
index fb71c38..8461b94 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -865,6 +865,8 @@ pwritev01 pwritev01
 pwritev01_64 pwritev01_64
 pwritev02 pwritev02
 pwritev02_64 pwritev02_64
+pwritev03 pwritev03
+pwritev03_64 pwritev03_64
 
 quotactl01 quotactl01
 quotactl02 quotactl02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index ec2af68..c3bc662 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -726,6 +726,8 @@
 /pwritev/pwritev01_64
 /pwritev/pwritev02
 /pwritev/pwritev02_64
+/pwritev/pwritev03
+/pwritev/pwritev03_64
 /quotactl/quotactl01
 /quotactl/quotactl02
 /quotactl/quotactl03
diff --git a/testcases/kernel/syscalls/pwritev/pwritev03.c b/testcases/kernel/syscalls/pwritev/pwritev03.c
new file mode 100644
index 0000000..8ec9aca
--- /dev/null
+++ b/testcases/kernel/syscalls/pwritev/pwritev03.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License
+ * alone with this program.
+ */
+
+/*
+ * Test Name: pwritev03
+ *
+ * Test Description:
+ * Check the basic functionality of the pwritev(2) for the file
+ * opened with O_DIRECT in all filesystem.
+ * pwritev(2) should succeed to write the expected content of data
+ * and after writing the file, the file offset is not changed.
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <string.h>
+#include <sys/uio.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "tst_test.h"
+#include "pwritev.h"
+#include "tst_safe_prw.h"
+
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
+
+static char *initbuf;
+static char *preadbuf;
+static struct iovec *wr_iovec;
+static int fd, blksz;
+static off_t org_off, tst_off;
+static ssize_t exp_sz;
+
+static struct tcase {
+	int count;
+	off_t *offset;
+	ssize_t *size;
+} tcases[] = {
+	{1, &org_off, &exp_sz},
+	{2, &org_off, &exp_sz},
+	{1, &tst_off, &exp_sz},
+};
+
+static void verify_direct_pwritev(unsigned int n)
+{
+	int i;
+	struct tcase *tc = &tcases[n];
+
+	SAFE_PWRITE(1, fd, initbuf, blksz * 2, 0);
+
+	TEST(pwritev(fd, wr_iovec, tc->count, *tc->offset));
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "Pwritev(O_DIRECT) fails");
+		return;
+	}
+
+	if (TEST_RETURN != *tc->size) {
+		tst_res(TFAIL, "Pwritev(O_DIRECT) wrote %li bytes, expected %zi",
+			 TEST_RETURN, *tc->size);
+		return;
+	}
+
+	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
+		tst_res(TFAIL, "Pwritev(O_DIRECT) had changed file offset");
+		return;
+	}
+
+	memset(preadbuf, 0x00, blksz);
+	SAFE_PREAD(1, fd, preadbuf, *tc->size, *tc->offset);
+
+	for (i = 0; i < *tc->size; i++) {
+		if (preadbuf[i] != 0x61)
+			break;
+	}
+
+	if (i != *tc->size) {
+		tst_res(TFAIL, "Buffer wrong at %i have %02x expected 0x61",
+			 i, preadbuf[i]);
+		return;
+	}
+
+	tst_res(TPASS, "Pwritev(O_DIRECT) wrote %zi bytes successfully "
+		 "with content 'a' expectedly ", *tc->size);
+}
+
+static void setup(void)
+{
+	int dev_fd;
+
+	dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR);
+	if (ioctl(dev_fd, BLKSSZGET, &blksz)) {
+		SAFE_CLOSE(dev_fd);
+		tst_brk(TBROK | TERRNO, "ioctl(%s, BLKSSZGET) failed",
+			tst_device->dev);
+	}
+	SAFE_CLOSE(dev_fd);
+	tst_off = blksz;
+	exp_sz = blksz;
+
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
+
+	initbuf = SAFE_MEMALIGN(blksz, blksz * 2);
+	memset(initbuf, 0x00, blksz * 2);
+
+	preadbuf = SAFE_MEMALIGN(blksz, blksz);
+
+	wr_iovec = SAFE_MEMALIGN(blksz, blksz + sizeof(size_t));
+	wr_iovec->iov_base = SAFE_MEMALIGN(blksz, blksz);
+	wr_iovec->iov_len = blksz;
+	memset(wr_iovec->iov_base, 0x61, blksz);
+}
+
+static void cleanup(void)
+{
+	free(initbuf);
+	free(preadbuf);
+	free(wr_iovec->iov_base);
+	free(wr_iovec);
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_direct_pwritev,
+	.min_kver = "2.6.30",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase
  2018-04-06 13:02         ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: " Cyril Hrubis
  2018-04-09  3:24           ` [LTP] [PATCH v3 " Xiao Yang
@ 2018-04-09  3:34           ` Xiao Yang
  1 sibling, 0 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-09  3:34 UTC (permalink / raw)
  To: ltp

On 2018/04/06 21:02, Cyril Hrubis wrote:
> Hi!
>> +static void setup(void)
>> +{
>> +	pgsz = getpagesize();
>> +	tst_off1 = pgsz;
>> +	tst_off2 = pgsz * 3 / 2;
>> +	exp_sz1 = pgsz;
>> +	exp_sz2 = pgsz / 2;
>> +
>> +	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
>> +
>> +	pop_buf = SAFE_MEMALIGN(pgsz, pgsz);
>> +	memset(pop_buf, 0x61, pgsz);
>> +	SAFE_WRITE(1, fd, pop_buf, pgsz);
>> +
>> +	memset(pop_buf, 0x62, pgsz);
>> +	SAFE_WRITE(1, fd, pop_buf, pgsz);
>> +
>> +	rd_iovec = SAFE_MEMALIGN(pgsz, pgsz + sizeof(size_t));
>> +	rd_iovec->iov_base = SAFE_MEMALIGN(pgsz, pgsz);
>> +	rd_iovec->iov_len = pgsz;
> The open(2) manual page says that O_DIRECT buffers should be aligned to
> disk block size which can be queried by BLKSSZGET ioctl(). And I suppose
> that the offsets should be multiple of the disk block size as well.
Hi Cyril,

OK, i will replace page size with block size as you suggested.

Thanks,
Xiao Yang
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	free(pop_buf);
>> +	free(rd_iovec->iov_base);
>> +	free(rd_iovec);
>> +
>> +	if (fd>  0)
>> +		SAFE_CLOSE(fd);
>> +}




^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v3 1/2] preadv/preadv03.c: Add new testcase
  2018-04-09  3:24           ` [LTP] [PATCH v3 " Xiao Yang
  2018-04-09  3:24             ` [LTP] [PATCH v3 2/2] pwritev/pwritev03.c: " Xiao Yang
@ 2018-04-09 12:57             ` Cyril Hrubis
  2018-04-10  2:32               ` [LTP] [PATCH v4 " Xiao Yang
  2018-04-10  2:42               ` [LTP] [PATCH v3 " Xiao Yang
  1 sibling, 2 replies; 16+ messages in thread
From: Cyril Hrubis @ 2018-04-09 12:57 UTC (permalink / raw)
  To: ltp

Hi!
> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
> index eea606e..ec2af68 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -696,6 +696,8 @@
>  /preadv/preadv01_64
>  /preadv/preadv02
>  /preadv/preadv02_64
> +/preadv/preadv03
> +/preadv/preadv03_64
>  /profil/profil01
>  /pselect/pselect01
>  /pselect/pselect01_64
> diff --git a/testcases/kernel/syscalls/preadv/preadv03.c b/testcases/kernel/syscalls/preadv/preadv03.c
> new file mode 100644
> index 0000000..077063a
> --- /dev/null
> +++ b/testcases/kernel/syscalls/preadv/preadv03.c
> @@ -0,0 +1,146 @@
> +/*
> + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
> + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.

Can we use GPLv2+ instead of GPLv2 please?

> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License
> + * alone with this program.
> + */
> +
> +/*
> + * Test Name: preadv03

I would avoid the test name here as it does not add any useful
information.

> + * Test Description:
> + * Check the basic functionality of the preadv(2) for the file
> + * opened with O_DIRECT in all filesystem.
> + * Preadv(2) should succeed to read the expected content of data
> + * and after reading the file, the file offset is not changed.
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/uio.h>
> +#include <sys/ioctl.h>
> +#include <sys/mount.h>
> +#include "tst_test.h"
> +#include "preadv.h"
> +
> +#define MNTPOINT	"mntpoint"
> +#define FNAME	MNTPOINT"/file"
> +
> +static int fd, blksz;
> +static off_t org_off, tst_off;
                          ^
	  The tst_ prefix is reserved for the test library, you should
	  not use it when naming test variables/functions.

> +static ssize_t exp_sz;
> +static char *pop_buf;
> +static struct iovec *rd_iovec;
> +
> +static struct tcase {
> +	int count;
> +	off_t *offset;
> +	ssize_t *size;
> +	char content;
> +} tcases[] = {
> +	{1, &org_off, &exp_sz, 0x61},
> +	{2, &org_off, &exp_sz, 0x61},
> +	{1, &tst_off, &exp_sz, 0x62},
> +};
> +
> +static void verify_direct_preadv(unsigned int n)
> +{
> +	int i;
> +	char *vec;
> +	struct tcase *tc = &tcases[n];
> +
> +	vec = rd_iovec->iov_base;
> +	memset(vec, 0x00, blksz);
> +
> +	SAFE_LSEEK(fd, 0, SEEK_SET);
> +
> +	TEST(preadv(fd, rd_iovec, tc->count, *tc->offset));
> +	if (TEST_RETURN < 0) {
> +		tst_res(TFAIL | TTERRNO, "Preadv(O_DIRECT) fails");
> +		return;
> +	}
> +
> +	if (TEST_RETURN != *tc->size) {
> +		tst_res(TFAIL, "Preadv(O_DIRECT) read %li bytes, expected %zi",
> +			 TEST_RETURN, *tc->size);
> +		return;
> +	}
> +
> +	for (i = 0; i < *tc->size; i++) {
> +		if (vec[i] != tc->content)
> +			break;
> +	}
> +
> +	if (i < *tc->size) {
> +		tst_res(TFAIL, "Buffer wrong at %i have %02x expected %02x",
> +			 i, vec[i], tc->content);
> +		return;
> +	}
> +
> +	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
> +		tst_res(TFAIL, "Preadv(O_DIRECT) has changed file offset");
> +		return;
> +	}
> +
> +	tst_res(TPASS, "Preadv(O_DIRECT) read %zi bytes successfully "
> +		 "with content '%c' expectedly", *tc->size, tc->content);
> +}
> +
> +static void setup(void)
> +{
> +	int dev_fd;
> +
> +	dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR);
> +	if (ioctl(dev_fd, BLKSSZGET, &blksz)) {
> +		SAFE_CLOSE(dev_fd);
> +		tst_brk(TBROK | TERRNO, "ioctl(%s, BLKSSZGET) failed",
> +			tst_device->dev);
> +	}

We do have SAFE_IOCTL() now :-).

> +	SAFE_CLOSE(dev_fd);
> +	tst_off = blksz;
> +	exp_sz = blksz;
> +
> +	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
> +
> +	pop_buf = SAFE_MEMALIGN(blksz, blksz);
> +	memset(pop_buf, 0x61, blksz);
> +	SAFE_WRITE(1, fd, pop_buf, blksz);
> +
> +	memset(pop_buf, 0x62, blksz);
> +	SAFE_WRITE(1, fd, pop_buf, blksz);
> +
> +	rd_iovec = SAFE_MEMALIGN(blksz, blksz + sizeof(size_t));

Also I do not think that we actually have to align the iovec structure,
AFAIC only the actual buffer, i.e. iov_base.

> +	rd_iovec->iov_base = SAFE_MEMALIGN(blksz, blksz);
> +	rd_iovec->iov_len = blksz;

Also looking at the testcase definition, we pass iovcnt == 2 there but
initialize only the first one here. I suppose that for the original
testcase we relied on the fact that the global variable rd_iovec was
initialized to 0 but that does not hold true for allocated memory.

Anyway we should either set rd_iovec[1].iov_base = NULL and
rd_iovec[1].iov_len = 0 or make it static global variable again...

> +}
> +
> +static void cleanup(void)
> +{
> +	free(pop_buf);
> +	free(rd_iovec->iov_base);
> +	free(rd_iovec);
> +
> +	if (fd > 0)
> +		SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test = verify_direct_preadv,
> +	.min_kver = "2.6.30",
> +	.mntpoint = MNTPOINT,
> +	.mount_device = 1,
> +	.all_filesystems = 1,
> +};
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v4 1/2] preadv/preadv03.c: Add new testcase
  2018-04-09 12:57             ` [LTP] [PATCH v3 1/2] preadv/preadv03.c: " Cyril Hrubis
@ 2018-04-10  2:32               ` Xiao Yang
  2018-04-10  2:32                 ` [LTP] [PATCH v4 2/2] pwritev/pwritev03.c: " Xiao Yang
  2018-04-12 11:15                 ` [LTP] [PATCH v4 1/2] preadv/preadv03.c: " Cyril Hrubis
  2018-04-10  2:42               ` [LTP] [PATCH v3 " Xiao Yang
  1 sibling, 2 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-10  2:32 UTC (permalink / raw)
  To: ltp

Check the basic functionality of the preadv(2) for the file
opened with O_DIRECT in all filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 +
 runtest/stress.part3                        |   1 +
 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/.gitignore        |   2 +
 testcases/kernel/syscalls/preadv/preadv03.c | 140 ++++++++++++++++++++++++++++
 5 files changed, 146 insertions(+)
 create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 15dc0c2..e8c6900 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -589,6 +589,7 @@ pread03 pread03
 
 preadv01 preadv01
 preadv02 preadv02
+preadv03 preadv03
 
 profil01 profil01
 
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 2a7747c..be912c8 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -496,6 +496,7 @@ pread03 pread03
 
 preadv01 preadv01
 preadv02 preadv02
+preadv03 preadv03
 
 profil01 profil01
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 76ab082..fb71c38 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -821,6 +821,8 @@ preadv01 preadv01
 preadv01_64 preadv01_64
 preadv02 preadv02
 preadv02_64 preadv02_64
+preadv03 preadv03
+preadv03_64 preadv03_64
 
 profil01 profil01
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index eea606e..ec2af68 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -696,6 +696,8 @@
 /preadv/preadv01_64
 /preadv/preadv02
 /preadv/preadv02_64
+/preadv/preadv03
+/preadv/preadv03_64
 /profil/profil01
 /pselect/pselect01
 /pselect/pselect01_64
diff --git a/testcases/kernel/syscalls/preadv/preadv03.c b/testcases/kernel/syscalls/preadv/preadv03.c
new file mode 100644
index 0000000..f7850e3
--- /dev/null
+++ b/testcases/kernel/syscalls/preadv/preadv03.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Description:
+ * Check the basic functionality of the preadv(2) for the file
+ * opened with O_DIRECT in all filesystem.
+ * Preadv(2) should succeed to read the expected content of data
+ * and after reading the file, the file offset is not changed.
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <string.h>
+#include <sys/uio.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "tst_test.h"
+#include "preadv.h"
+
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
+
+static int fd, dev_fd;
+static long blksz, org_off;
+static char *pop_buf;
+
+static struct iovec rd_iovec[] = {
+	{NULL, 0},
+	{NULL, 0},
+};
+
+static struct tcase {
+	int count;
+	off_t *offset;
+	ssize_t *size;
+	char content;
+} tcases[] = {
+	{1, &org_off, &blksz, 0x61},
+	{2, &org_off, &blksz, 0x61},
+	{1, &blksz, &blksz, 0x62},
+};
+
+static void verify_direct_preadv(unsigned int n)
+{
+	int i;
+	char *vec;
+	struct tcase *tc = &tcases[n];
+
+	vec = rd_iovec[0].iov_base;
+	memset(vec, 0x00, blksz);
+
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+
+	TEST(preadv(fd, rd_iovec, tc->count, *tc->offset));
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "Preadv(O_DIRECT) fails");
+		return;
+	}
+
+	if (TEST_RETURN != *tc->size) {
+		tst_res(TFAIL, "Preadv(O_DIRECT) read %li bytes, expected %zi",
+			 TEST_RETURN, *tc->size);
+		return;
+	}
+
+	for (i = 0; i < *tc->size; i++) {
+		if (vec[i] != tc->content)
+			break;
+	}
+
+	if (i < *tc->size) {
+		tst_res(TFAIL, "Buffer wrong at %i have %02x expected %02x",
+			 i, vec[i], tc->content);
+		return;
+	}
+
+	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
+		tst_res(TFAIL, "Preadv(O_DIRECT) has changed file offset");
+		return;
+	}
+
+	tst_res(TPASS, "Preadv(O_DIRECT) read %zi bytes successfully "
+		 "with content '%c' expectedly", *tc->size, tc->content);
+}
+
+static void setup(void)
+{
+	dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR);
+	SAFE_IOCTL(dev_fd, BLKSSZGET, &blksz);
+
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
+
+	pop_buf = SAFE_MEMALIGN(blksz, blksz);
+	memset(pop_buf, 0x61, blksz);
+	SAFE_WRITE(1, fd, pop_buf, blksz);
+
+	memset(pop_buf, 0x62, blksz);
+	SAFE_WRITE(1, fd, pop_buf, blksz);
+
+	rd_iovec[0].iov_base = SAFE_MEMALIGN(blksz, blksz);
+	rd_iovec[0].iov_len = blksz;
+}
+
+static void cleanup(void)
+{
+	free(pop_buf);
+	free(rd_iovec[0].iov_base);
+
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_direct_preadv,
+	.min_kver = "2.6.30",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v4 2/2] pwritev/pwritev03.c: Add new testcase
  2018-04-10  2:32               ` [LTP] [PATCH v4 " Xiao Yang
@ 2018-04-10  2:32                 ` Xiao Yang
  2018-04-12 11:15                 ` [LTP] [PATCH v4 1/2] preadv/preadv03.c: " Cyril Hrubis
  1 sibling, 0 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-10  2:32 UTC (permalink / raw)
  To: ltp

Check the basic functionality of the pwritev(2) for the file
opened with O_DIRECT in all filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                               |   1 +
 runtest/stress.part3                          |   1 +
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/.gitignore          |   2 +
 testcases/kernel/syscalls/pwritev/pwritev03.c | 139 ++++++++++++++++++++++++++
 5 files changed, 145 insertions(+)
 create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index e8c6900..1f4d91c 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64
 
 pwritev01 pwritev01
 pwritev02 pwritev02
+pwritev03 pwritev03
 
 read01 read01
 read02 read02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index be912c8..96f7953 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64
 
 pwritev01 pwritev01
 pwritev02 pwritev02
+pwritev03 pwritev03
 
 read01 read01
 read02 read02
diff --git a/runtest/syscalls b/runtest/syscalls
index fb71c38..8461b94 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -865,6 +865,8 @@ pwritev01 pwritev01
 pwritev01_64 pwritev01_64
 pwritev02 pwritev02
 pwritev02_64 pwritev02_64
+pwritev03 pwritev03
+pwritev03_64 pwritev03_64
 
 quotactl01 quotactl01
 quotactl02 quotactl02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index ec2af68..c3bc662 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -726,6 +726,8 @@
 /pwritev/pwritev01_64
 /pwritev/pwritev02
 /pwritev/pwritev02_64
+/pwritev/pwritev03
+/pwritev/pwritev03_64
 /quotactl/quotactl01
 /quotactl/quotactl02
 /quotactl/quotactl03
diff --git a/testcases/kernel/syscalls/pwritev/pwritev03.c b/testcases/kernel/syscalls/pwritev/pwritev03.c
new file mode 100644
index 0000000..2dacde9
--- /dev/null
+++ b/testcases/kernel/syscalls/pwritev/pwritev03.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Description:
+ * Check the basic functionality of the pwritev(2) for the file
+ * opened with O_DIRECT in all filesystem.
+ * pwritev(2) should succeed to write the expected content of data
+ * and after writing the file, the file offset is not changed.
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <string.h>
+#include <sys/uio.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "tst_test.h"
+#include "pwritev.h"
+#include "tst_safe_prw.h"
+
+#define MNTPOINT	"mntpoint"
+#define FNAME	MNTPOINT"/file"
+
+static char *initbuf, *preadbuf;
+static int fd, dev_fd;
+static long blksz, org_off;
+
+static struct iovec wr_iovec[] = {
+	{NULL, 0},
+	{NULL, 0},
+};
+
+static struct tcase {
+	int count;
+	off_t *offset;
+	ssize_t *size;
+} tcases[] = {
+	{1, &org_off, &blksz},
+	{2, &org_off, &blksz},
+	{1, &blksz, &blksz},
+};
+
+static void verify_direct_pwritev(unsigned int n)
+{
+	int i;
+	struct tcase *tc = &tcases[n];
+
+	SAFE_PWRITE(1, fd, initbuf, blksz * 2, 0);
+
+	TEST(pwritev(fd, wr_iovec, tc->count, *tc->offset));
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "Pwritev(O_DIRECT) fails");
+		return;
+	}
+
+	if (TEST_RETURN != *tc->size) {
+		tst_res(TFAIL, "Pwritev(O_DIRECT) wrote %li bytes, expected %zi",
+			 TEST_RETURN, *tc->size);
+		return;
+	}
+
+	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
+		tst_res(TFAIL, "Pwritev(O_DIRECT) had changed file offset");
+		return;
+	}
+
+	memset(preadbuf, 0x00, blksz);
+	SAFE_PREAD(1, fd, preadbuf, *tc->size, *tc->offset);
+
+	for (i = 0; i < *tc->size; i++) {
+		if (preadbuf[i] != 0x61)
+			break;
+	}
+
+	if (i != *tc->size) {
+		tst_res(TFAIL, "Buffer wrong at %i have %02x expected 0x61",
+			 i, preadbuf[i]);
+		return;
+	}
+
+	tst_res(TPASS, "Pwritev(O_DIRECT) wrote %zi bytes successfully "
+		 "with content 'a' expectedly ", *tc->size);
+}
+
+static void setup(void)
+{
+	dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR);
+	SAFE_IOCTL(dev_fd, BLKSSZGET, &blksz);
+
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
+
+	initbuf = SAFE_MEMALIGN(blksz, blksz * 2);
+	memset(initbuf, 0x00, blksz * 2);
+
+	preadbuf = SAFE_MEMALIGN(blksz, blksz);
+
+	wr_iovec[0].iov_base = SAFE_MEMALIGN(blksz, blksz);
+	wr_iovec[0].iov_len = blksz;
+	memset(wr_iovec[0].iov_base, 0x61, blksz);
+}
+
+static void cleanup(void)
+{
+	free(initbuf);
+	free(preadbuf);
+	free(wr_iovec[0].iov_base);
+
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_direct_pwritev,
+	.min_kver = "2.6.30",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v3 1/2] preadv/preadv03.c: Add new testcase
  2018-04-09 12:57             ` [LTP] [PATCH v3 1/2] preadv/preadv03.c: " Cyril Hrubis
  2018-04-10  2:32               ` [LTP] [PATCH v4 " Xiao Yang
@ 2018-04-10  2:42               ` Xiao Yang
  1 sibling, 0 replies; 16+ messages in thread
From: Xiao Yang @ 2018-04-10  2:42 UTC (permalink / raw)
  To: ltp

Hi Cyril,

Thanks for your detailed review, and i will send v4 patch soon. :-)

Thanks,
Xiao Yang
On 2018/04/09 20:57, Cyril Hrubis wrote:
> Hi!
>> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
>> index eea606e..ec2af68 100644
>> --- a/testcases/kernel/syscalls/.gitignore
>> +++ b/testcases/kernel/syscalls/.gitignore
>> @@ -696,6 +696,8 @@
>>   /preadv/preadv01_64
>>   /preadv/preadv02
>>   /preadv/preadv02_64
>> +/preadv/preadv03
>> +/preadv/preadv03_64
>>   /profil/profil01
>>   /pselect/pselect01
>>   /pselect/pselect01_64
>> diff --git a/testcases/kernel/syscalls/preadv/preadv03.c b/testcases/kernel/syscalls/preadv/preadv03.c
>> new file mode 100644
>> index 0000000..077063a
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/preadv/preadv03.c
>> @@ -0,0 +1,146 @@
>> +/*
>> + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
>> + * Author: Xiao Yang<yangx.jy@cn.fujitsu.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify it
>> + * under the terms of version 2 of the GNU General Public License as
>> + * published by the Free Software Foundation.
> Can we use GPLv2+ instead of GPLv2 please?
>
>> + * This program is distributed in the hope that it would be useful, but
>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * alone with this program.
>> + */
>> +
>> +/*
>> + * Test Name: preadv03
> I would avoid the test name here as it does not add any useful
> information.
>
>> + * Test Description:
>> + * Check the basic functionality of the preadv(2) for the file
>> + * opened with O_DIRECT in all filesystem.
>> + * Preadv(2) should succeed to read the expected content of data
>> + * and after reading the file, the file offset is not changed.
>> + */
>> +
>> +#define _GNU_SOURCE
>> +#include<stdlib.h>
>> +#include<string.h>
>> +#include<sys/uio.h>
>> +#include<sys/ioctl.h>
>> +#include<sys/mount.h>
>> +#include "tst_test.h"
>> +#include "preadv.h"
>> +
>> +#define MNTPOINT	"mntpoint"
>> +#define FNAME	MNTPOINT"/file"
>> +
>> +static int fd, blksz;
>> +static off_t org_off, tst_off;
>                            ^
> 	  The tst_ prefix is reserved for the test library, you should
> 	  not use it when naming test variables/functions.
>
>> +static ssize_t exp_sz;
>> +static char *pop_buf;
>> +static struct iovec *rd_iovec;
>> +
>> +static struct tcase {
>> +	int count;
>> +	off_t *offset;
>> +	ssize_t *size;
>> +	char content;
>> +} tcases[] = {
>> +	{1,&org_off,&exp_sz, 0x61},
>> +	{2,&org_off,&exp_sz, 0x61},
>> +	{1,&tst_off,&exp_sz, 0x62},
>> +};
>> +
>> +static void verify_direct_preadv(unsigned int n)
>> +{
>> +	int i;
>> +	char *vec;
>> +	struct tcase *tc =&tcases[n];
>> +
>> +	vec = rd_iovec->iov_base;
>> +	memset(vec, 0x00, blksz);
>> +
>> +	SAFE_LSEEK(fd, 0, SEEK_SET);
>> +
>> +	TEST(preadv(fd, rd_iovec, tc->count, *tc->offset));
>> +	if (TEST_RETURN<  0) {
>> +		tst_res(TFAIL | TTERRNO, "Preadv(O_DIRECT) fails");
>> +		return;
>> +	}
>> +
>> +	if (TEST_RETURN != *tc->size) {
>> +		tst_res(TFAIL, "Preadv(O_DIRECT) read %li bytes, expected %zi",
>> +			 TEST_RETURN, *tc->size);
>> +		return;
>> +	}
>> +
>> +	for (i = 0; i<  *tc->size; i++) {
>> +		if (vec[i] != tc->content)
>> +			break;
>> +	}
>> +
>> +	if (i<  *tc->size) {
>> +		tst_res(TFAIL, "Buffer wrong at %i have %02x expected %02x",
>> +			 i, vec[i], tc->content);
>> +		return;
>> +	}
>> +
>> +	if (SAFE_LSEEK(fd, 0, SEEK_CUR) != 0) {
>> +		tst_res(TFAIL, "Preadv(O_DIRECT) has changed file offset");
>> +		return;
>> +	}
>> +
>> +	tst_res(TPASS, "Preadv(O_DIRECT) read %zi bytes successfully "
>> +		 "with content '%c' expectedly", *tc->size, tc->content);
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	int dev_fd;
>> +
>> +	dev_fd = SAFE_OPEN(tst_device->dev, O_RDWR);
>> +	if (ioctl(dev_fd, BLKSSZGET,&blksz)) {
>> +		SAFE_CLOSE(dev_fd);
>> +		tst_brk(TBROK | TERRNO, "ioctl(%s, BLKSSZGET) failed",
>> +			tst_device->dev);
>> +	}
> We do have SAFE_IOCTL() now :-).
>
>> +	SAFE_CLOSE(dev_fd);
>> +	tst_off = blksz;
>> +	exp_sz = blksz;
>> +
>> +	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT | O_DIRECT, 0644);
>> +
>> +	pop_buf = SAFE_MEMALIGN(blksz, blksz);
>> +	memset(pop_buf, 0x61, blksz);
>> +	SAFE_WRITE(1, fd, pop_buf, blksz);
>> +
>> +	memset(pop_buf, 0x62, blksz);
>> +	SAFE_WRITE(1, fd, pop_buf, blksz);
>> +
>> +	rd_iovec = SAFE_MEMALIGN(blksz, blksz + sizeof(size_t));
> Also I do not think that we actually have to align the iovec structure,
> AFAIC only the actual buffer, i.e. iov_base.
>
>> +	rd_iovec->iov_base = SAFE_MEMALIGN(blksz, blksz);
>> +	rd_iovec->iov_len = blksz;
> Also looking at the testcase definition, we pass iovcnt == 2 there but
> initialize only the first one here. I suppose that for the original
> testcase we relied on the fact that the global variable rd_iovec was
> initialized to 0 but that does not hold true for allocated memory.
>
> Anyway we should either set rd_iovec[1].iov_base = NULL and
> rd_iovec[1].iov_len = 0 or make it static global variable again...
>
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	free(pop_buf);
>> +	free(rd_iovec->iov_base);
>> +	free(rd_iovec);
>> +
>> +	if (fd>  0)
>> +		SAFE_CLOSE(fd);
>> +}
>> +
>> +static struct tst_test test = {
>> +	.tcnt = ARRAY_SIZE(tcases),
>> +	.setup = setup,
>> +	.cleanup = cleanup,
>> +	.test = verify_direct_preadv,
>> +	.min_kver = "2.6.30",
>> +	.mntpoint = MNTPOINT,
>> +	.mount_device = 1,
>> +	.all_filesystems = 1,
>> +};
>> -- 
>> 1.8.3.1
>>
>>
>>




^ permalink raw reply	[flat|nested] 16+ messages in thread

* [LTP] [PATCH v4 1/2] preadv/preadv03.c: Add new testcase
  2018-04-10  2:32               ` [LTP] [PATCH v4 " Xiao Yang
  2018-04-10  2:32                 ` [LTP] [PATCH v4 2/2] pwritev/pwritev03.c: " Xiao Yang
@ 2018-04-12 11:15                 ` Cyril Hrubis
  1 sibling, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2018-04-12 11:15 UTC (permalink / raw)
  To: ltp

Hi!
Both pushed with a minor changes, thanks.

I've changed the test to close the dev_fd in the test setup() as there
is no need to keep it open during the test. And also removed the
capitalization of the first letter of the syscall from the messages,
which may have caused confusing when grepping the logs.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-04-12 11:15 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-30  8:53 [LTP] [PATCH 1/2] syscalls/preadv01: Run test for all filesystems Xiao Yang
2018-03-30  8:53 ` [LTP] [PATCH 2/2] syscalls/pwritev01: " Xiao Yang
2018-04-05  9:52 ` [LTP] [PATCH 1/2] syscalls/preadv01: " Cyril Hrubis
2018-04-05 10:56   ` Xiao Yang
2018-04-05 11:02     ` Cyril Hrubis
2018-04-06 10:50       ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: Add new testcase Xiao Yang
2018-04-06 10:50         ` [LTP] [PATCH v2 2/2] pwritev/pwritev03.c: " Xiao Yang
2018-04-06 13:02         ` [LTP] [PATCH v2 1/2] preadv/preadv03.c: " Cyril Hrubis
2018-04-09  3:24           ` [LTP] [PATCH v3 " Xiao Yang
2018-04-09  3:24             ` [LTP] [PATCH v3 2/2] pwritev/pwritev03.c: " Xiao Yang
2018-04-09 12:57             ` [LTP] [PATCH v3 1/2] preadv/preadv03.c: " Cyril Hrubis
2018-04-10  2:32               ` [LTP] [PATCH v4 " Xiao Yang
2018-04-10  2:32                 ` [LTP] [PATCH v4 2/2] pwritev/pwritev03.c: " Xiao Yang
2018-04-12 11:15                 ` [LTP] [PATCH v4 1/2] preadv/preadv03.c: " Cyril Hrubis
2018-04-10  2:42               ` [LTP] [PATCH v3 " Xiao Yang
2018-04-09  3:34           ` [LTP] [PATCH v2 " Xiao Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.