public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Zorro Lang <zlang@kernel.org>
Cc: fstests@vger.kernel.org
Subject: Re: [PATCH v2 4/5] generic/591: use proper sector size
Date: Wed, 1 Jun 2022 10:41:04 -0700	[thread overview]
Message-ID: <YpeksFaXrJIYjrXO@magnolia> (raw)
In-Reply-To: <20220601063730.1726879-5-zlang@kernel.org>

On Wed, Jun 01, 2022 at 02:37:29PM +0800, Zorro Lang wrote:
> The generic/591 fails if the sector size of TEST_DEV isn't 512:
> 
>   splice-test: write: /mnt/test/a: Invalid argument
> 
> To fix this issue, this patch help src/splice-test.c to get a specify
> sector size from the test case. Then let g/591 give it a proper
> sector size which dio aligned.
> 
> Signed-off-by: Zorro Lang <zlang@kernel.org>

Looks good,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  src/splice-test.c | 37 +++++++++++++++++++++++++------------
>  tests/generic/591 |  6 ++++--
>  2 files changed, 29 insertions(+), 14 deletions(-)
> 
> diff --git a/src/splice-test.c b/src/splice-test.c
> index dc41b0f5..eb863673 100644
> --- a/src/splice-test.c
> +++ b/src/splice-test.c
> @@ -19,19 +19,20 @@
>  #include <errno.h>
>  #include <malloc.h>
>  
> -#define SECTOR_SIZE 512
> -#define BUFFER_SIZE (150 * SECTOR_SIZE)
> +unsigned int sector_size;
> +unsigned int buffer_size;
>  
>  void read_from_pipe(int fd, const char *filename, size_t size)
>  {
> -	char buffer[SECTOR_SIZE];
> +	char *buffer;
>  	size_t sz;
>  	ssize_t ret;
> +	buffer = malloc(buffer_size);
>  
>  	while (size) {
>  		sz = size;
> -		if (sz > sizeof buffer)
> -			sz = sizeof buffer;
> +		if (sz > buffer_size)
> +			sz = buffer_size;
>  		ret = read(fd, buffer, sz);
>  		if (ret < 0)
>  			err(1, "read: %s", filename);
> @@ -41,6 +42,7 @@ void read_from_pipe(int fd, const char *filename, size_t size)
>  		}
>  		size -= sz;
>  	}
> +	free(buffer);
>  }
>  
>  void do_splice1(int fd, const char *filename, size_t size)
> @@ -108,7 +110,7 @@ void do_splice2(int fd, const char *filename, size_t size)
>  
>  void usage(const char *argv0)
>  {
> -	fprintf(stderr, "USAGE: %s [-rd] {filename}\n", basename(argv0));
> +	fprintf(stderr, "USAGE: %s [-rd] [-s sectorsize] {filename}\n", basename(argv0));
>  	exit(2);
>  }
>  
> @@ -120,11 +122,22 @@ int main(int argc, char *argv[])
>  	int opt, open_flags, fd;
>  	ssize_t ret;
>  
> +	/*
> +	 * init default sector_size and buffer_size, might be changed if the -s
> +	 * option is specified
> +	 */
> +	sector_size = 512;
> +	buffer_size = 150 * sector_size;
> +
>  	do_splice = do_splice1;
>  	open_flags = O_CREAT | O_TRUNC | O_RDWR | O_DIRECT;
>  
> -	while ((opt = getopt(argc, argv, "rd")) != -1) {
> +	while ((opt = getopt(argc, argv, "rds:")) != -1) {
>  		switch(opt) {
> +		case 's':
> +			sector_size = strtol(optarg, NULL, 0);
> +			buffer_size = 150 * sector_size;
> +			break;
>  		case 'r':
>  			do_splice = do_splice2;
>  			break;
> @@ -146,7 +159,7 @@ int main(int argc, char *argv[])
>  		   do_splice == do_splice1 ? "sequential" : "concurrent",
>  		   (open_flags & O_DIRECT) ? "with" : "without");
>  
> -	buffer = memalign(SECTOR_SIZE, BUFFER_SIZE);
> +	buffer = memalign(sector_size, buffer_size);
>  	if (buffer == NULL)
>  		err(1, "memalign");
>  
> @@ -154,11 +167,11 @@ int main(int argc, char *argv[])
>  	if (fd == -1)
>  		err(1, "open: %s", filename);
>  
> -	memset(buffer, 'x', BUFFER_SIZE);
> -	ret = write(fd, buffer, BUFFER_SIZE);
> +	memset(buffer, 'x', buffer_size);
> +	ret = write(fd, buffer, buffer_size);
>  	if (ret < 0)
>  		err(1, "write: %s", filename);
> -	if (ret != BUFFER_SIZE) {
> +	if (ret != buffer_size) {
>  		fprintf(stderr, "%s: short write\n", filename);
>  		exit(1);
>  	}
> @@ -167,7 +180,7 @@ int main(int argc, char *argv[])
>  	if (ret != 0)
>  		err(1, "lseek: %s", filename);
>  
> -	do_splice(fd, filename, BUFFER_SIZE);
> +	do_splice(fd, filename, buffer_size);
>  
>  	if (unlink(filename) == -1)
>  		err(1, "unlink: %s", filename);
> diff --git a/tests/generic/591 b/tests/generic/591
> index 5efc5136..4de50e2a 100755
> --- a/tests/generic/591
> +++ b/tests/generic/591
> @@ -24,9 +24,11 @@ _require_test
>  _require_odirect
>  _require_test_program "splice-test"
>  
> -$here/src/splice-test -r $TEST_DIR/a
> +diosize=`_min_dio_alignment $TEST_DEV`
> +
> +$here/src/splice-test -s $diosize -r $TEST_DIR/a
>  $here/src/splice-test -rd $TEST_DIR/a
> -$here/src/splice-test $TEST_DIR/a
> +$here/src/splice-test -s $diosize $TEST_DIR/a
>  $here/src/splice-test -d $TEST_DIR/a
>  
>  # success, all done
> -- 
> 2.31.1
> 

  reply	other threads:[~2022-06-01 17:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01  6:37 [PATCH v2 0/5] random fixes for fstests Zorro Lang
2022-06-01  6:37 ` [PATCH v2 1/5] generic/139: require 512 bytes to be the minimum dio size Zorro Lang
2022-06-01 17:32   ` Darrick J. Wong
2022-06-02  5:17     ` [PATCH v3] " Zorro Lang
2022-06-02 16:40       ` Darrick J. Wong
2022-06-02 19:13         ` Zorro Lang
2022-06-01  6:37 ` [PATCH v2 2/5] generic/506: call _require_quota before _qmount Zorro Lang
2022-06-01 17:35   ` Darrick J. Wong
2022-06-01  6:37 ` [PATCH v2 3/5] generic/591: remove redundant output from golden image Zorro Lang
2022-06-01 17:38   ` Darrick J. Wong
2022-06-01  6:37 ` [PATCH v2 4/5] generic/591: use proper sector size Zorro Lang
2022-06-01 17:41   ` Darrick J. Wong [this message]
2022-06-01  6:37 ` [PATCH v2 5/5] gitignore: ignore missed binary files in src Zorro Lang
2022-06-01 17:42   ` Darrick J. Wong
2022-06-02  5:03     ` Zorro Lang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YpeksFaXrJIYjrXO@magnolia \
    --to=djwong@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=zlang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox