public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] src/aiocp.c: Fix buffer alignment
@ 2018-08-09  4:57 Xiao Yang
  2018-08-12 15:08 ` Eryu Guan
  0 siblings, 1 reply; 3+ messages in thread
From: Xiao Yang @ 2018-08-09  4:57 UTC (permalink / raw)
  To: fstests; +Cc: Xiao Yang

In generic/252, aiocp with DIRECT will fail and return EINVAL on
4096 sector size block device, because the default 512 alignment
defined in aiocp is not aligned with 4096.

Please see the following error:
----------------------------------------------------------
read missing bytes expect 8388608 got -22
----------------------------------------------------------

aiocp with DIRECT should set a proper alignment if -a option is not
specified.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 src/aio-dio-regress/aiocp.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/aio-dio-regress/aiocp.c b/src/aio-dio-regress/aiocp.c
index 7e71cc5..57e9d35 100644
--- a/src/aio-dio-regress/aiocp.c
+++ b/src/aio-dio-regress/aiocp.c
@@ -40,6 +40,8 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/select.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
 
 #include <libaio.h>
 
@@ -69,6 +71,28 @@ int alignment = 512;		/* buffer alignment */
 
 struct timeval delay;		/* delay between i/o */
 
+static int get_sector_size(void)
+{
+	int fd, ret;
+	int sector_size;
+	char *name;
+
+	name = getenv("TEST_DEV");
+	if (!name)
+		return alignment;
+
+	fd = open(name, O_RDONLY);
+	if (fd < 0)
+		return alignment;
+
+	ret = ioctl(fd, BLKSSZGET, &sector_size);
+	close(fd);
+	if (ret < 0)
+		return alignment;
+
+	return sector_size;
+}
+
 int init_iocb(int n, int iosize)
 {
 	void *buf;
@@ -259,6 +283,7 @@ int main(int argc, char *const *argv)
 	int c;
 	extern char *optarg;
 	extern int optind, opterr, optopt;
+	int aligned = 0;
 
 	while ((c = getopt(argc, argv, "a:b:df:n:s:wzD:")) != -1) {
 		char *endp;
@@ -268,6 +293,7 @@ int main(int argc, char *const *argv)
 			alignment = strtol(optarg, &endp, 0);
 			alignment = (long)scale_by_kmg((long long)alignment,
 							*endp);
+			aligned = 1;
 			break;
 		case 'f':	/* use these open flags */
 			if (strcmp(optarg, "LARGEFILE") == 0 ||
@@ -334,6 +360,10 @@ int main(int argc, char *const *argv)
     srcname = "junkdata";
     dstname = "ff2";
 #endif
+
+	if (!aligned && (source_open_flag & O_DIRECT))
+		alignment = get_sector_size();
+
 	if (!zero) {
 #ifndef DEBUG
 	       	if ((srcfd = open(srcname = *argv, source_open_flag)) < 0) {
-- 
1.8.3.1




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

* Re: [PATCH] src/aiocp.c: Fix buffer alignment
  2018-08-09  4:57 [PATCH] src/aiocp.c: Fix buffer alignment Xiao Yang
@ 2018-08-12 15:08 ` Eryu Guan
  2018-08-15  5:41   ` [PATCH v2] " Xiao Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Eryu Guan @ 2018-08-12 15:08 UTC (permalink / raw)
  To: Xiao Yang; +Cc: fstests

On Thu, Aug 09, 2018 at 12:57:07PM +0800, Xiao Yang wrote:
> In generic/252, aiocp with DIRECT will fail and return EINVAL on
> 4096 sector size block device, because the default 512 alignment
> defined in aiocp is not aligned with 4096.
> 
> Please see the following error:
> ----------------------------------------------------------
> read missing bytes expect 8388608 got -22
> ----------------------------------------------------------
> 
> aiocp with DIRECT should set a proper alignment if -a option is not
> specified.
> 
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
> ---
>  src/aio-dio-regress/aiocp.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/src/aio-dio-regress/aiocp.c b/src/aio-dio-regress/aiocp.c
> index 7e71cc5..57e9d35 100644
> --- a/src/aio-dio-regress/aiocp.c
> +++ b/src/aio-dio-regress/aiocp.c
> @@ -40,6 +40,8 @@
>  #include <errno.h>
>  #include <stdlib.h>
>  #include <sys/select.h>
> +#include <sys/ioctl.h>
> +#include <sys/mount.h>
>  
>  #include <libaio.h>
>  
> @@ -69,6 +71,28 @@ int alignment = 512;		/* buffer alignment */
>  
>  struct timeval delay;		/* delay between i/o */
>  
> +static int get_sector_size(void)
> +{
> +	int fd, ret;
> +	int sector_size;
> +	char *name;
> +
> +	name = getenv("TEST_DEV");

Hmm, I don't quite like the hardcoded "TEST_DEV", that means if we're
testing against SCRATCH_DEV the alignment is also based on TEST_DEV.

I'd rather do "alignment=`_min_dio_alignment <dev>`" and add
"-a $alignment" options to every aiocp test.

Thanks,
Eryu

> +	if (!name)
> +		return alignment;
> +
> +	fd = open(name, O_RDONLY);
> +	if (fd < 0)
> +		return alignment;
> +
> +	ret = ioctl(fd, BLKSSZGET, &sector_size);
> +	close(fd);
> +	if (ret < 0)
> +		return alignment;
> +
> +	return sector_size;
> +}
> +
>  int init_iocb(int n, int iosize)
>  {
>  	void *buf;
> @@ -259,6 +283,7 @@ int main(int argc, char *const *argv)
>  	int c;
>  	extern char *optarg;
>  	extern int optind, opterr, optopt;
> +	int aligned = 0;
>  
>  	while ((c = getopt(argc, argv, "a:b:df:n:s:wzD:")) != -1) {
>  		char *endp;
> @@ -268,6 +293,7 @@ int main(int argc, char *const *argv)
>  			alignment = strtol(optarg, &endp, 0);
>  			alignment = (long)scale_by_kmg((long long)alignment,
>  							*endp);
> +			aligned = 1;
>  			break;
>  		case 'f':	/* use these open flags */
>  			if (strcmp(optarg, "LARGEFILE") == 0 ||
> @@ -334,6 +360,10 @@ int main(int argc, char *const *argv)
>      srcname = "junkdata";
>      dstname = "ff2";
>  #endif
> +
> +	if (!aligned && (source_open_flag & O_DIRECT))
> +		alignment = get_sector_size();
> +
>  	if (!zero) {
>  #ifndef DEBUG
>  	       	if ((srcfd = open(srcname = *argv, source_open_flag)) < 0) {
> -- 
> 1.8.3.1
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2] src/aiocp.c: Fix buffer alignment
  2018-08-12 15:08 ` Eryu Guan
@ 2018-08-15  5:41   ` Xiao Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Xiao Yang @ 2018-08-15  5:41 UTC (permalink / raw)
  To: guaneryu; +Cc: fstests, Xiao Yang

In generic/252, aiocp with DIRECT will fail and return EINVAL on
4096 sector size block device, because the default 512 alignment
defined in aiocp is not aligned with 4096.

Please see the following error:
----------------------------------------------------------
read missing bytes expect 8388608 got -22
----------------------------------------------------------

We use '-a' option to specify a proper alignment size in all tests
that call aiocp with DIRECT.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 tests/generic/252 | 3 ++-
 tests/generic/329 | 3 ++-
 tests/generic/330 | 3 ++-
 tests/xfs/237     | 3 ++-
 tests/xfs/239     | 3 ++-
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tests/generic/252 b/tests/generic/252
index 9e7f442..991bbe3 100755
--- a/tests/generic/252
+++ b/tests/generic/252
@@ -59,6 +59,7 @@ nr=640
 bufnr=128
 filesize=$((blksz * nr))
 bufsize=$((blksz * bufnr))
+alignment=`_min_dio_alignment $TEST_DEV`
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 5 / 4))
 
@@ -75,7 +76,7 @@ $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
 sync
 _dmerror_load_error_table
-$AIO_TEST -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
+$AIO_TEST -a $alignment -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
 _dmerror_load_working_table
 _dmerror_unmount
 _dmerror_mount
diff --git a/tests/generic/329 b/tests/generic/329
index c68d94a..c618c2a 100755
--- a/tests/generic/329
+++ b/tests/generic/329
@@ -51,6 +51,7 @@ nr=640
 bufnr=128
 filesize=$((blksz * nr))
 bufsize=$((blksz * bufnr))
+alignment=`_min_dio_alignment $TEST_DEV`
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
 
@@ -69,7 +70,7 @@ $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
 sync
 _dmerror_load_error_table
-$AIO_TEST -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
+$AIO_TEST -a $alignment -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
 _dmerror_load_working_table
 _dmerror_unmount
 _dmerror_mount
diff --git a/tests/generic/330 b/tests/generic/330
index 334ac3c..7183d4c 100755
--- a/tests/generic/330
+++ b/tests/generic/330
@@ -47,6 +47,7 @@ nr=640
 bufnr=128
 filesize=$((blksz * nr))
 bufsize=$((blksz * bufnr))
+alignment=`_min_dio_alignment $TEST_DEV`
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
 
@@ -63,7 +64,7 @@ echo "CoW and unmount"
 $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
 sync
 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
-$AIO_TEST -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
+$AIO_TEST -a $alignment -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
 _scratch_cycle_mount
 
 echo "Compare files"
diff --git a/tests/xfs/237 b/tests/xfs/237
index 286fd68..94855f5 100755
--- a/tests/xfs/237
+++ b/tests/xfs/237
@@ -53,6 +53,7 @@ nr=640
 bufnr=128
 filesize=$((blksz * nr))
 bufsize=$((blksz * bufnr))
+alignment=`_min_dio_alignment $TEST_DEV`
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
 
@@ -72,7 +73,7 @@ $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
 sync
 _dmerror_load_error_table
-$AIO_TEST -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
+$AIO_TEST -a $alignment -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
 _dmerror_load_working_table
 _dmerror_unmount
 _dmerror_mount
diff --git a/tests/xfs/239 b/tests/xfs/239
index 6a13319..afe0d56 100755
--- a/tests/xfs/239
+++ b/tests/xfs/239
@@ -51,6 +51,7 @@ filesize=$((blksz * nr))
 bufsize=$((blksz * bufnr))
 filesize=$filesize
 bufsize=$bufsize
+alignment=`_min_dio_alignment $TEST_DEV`
 
 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
 
@@ -68,7 +69,7 @@ echo "CoW and unmount"
 $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
 sync
 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
-$AIO_TEST -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
+$AIO_TEST -a $alignment -f DIRECT -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
 _scratch_cycle_mount
 
 echo "Compare files"
-- 
1.8.3.1

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

end of thread, other threads:[~2018-08-16  3:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-09  4:57 [PATCH] src/aiocp.c: Fix buffer alignment Xiao Yang
2018-08-12 15:08 ` Eryu Guan
2018-08-15  5:41   ` [PATCH v2] " Xiao Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox