ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v7] Refactor aiocp using new LTP API
Date: Mon, 15 Aug 2022 17:30:34 +0200	[thread overview]
Message-ID: <YvpmmrnIif0aIxzF@yuki> (raw)
In-Reply-To: <20220812122758.25605-1-andrea.cervesato@suse.com>

Hi!
> -static int dev_block_size_by_path(const char *path)
> +static void fill_with_rand_data(int fd, long long size)
>  {
> -	FILE *f;
> -	struct mntent *mnt;
> -	size_t prefix_len, prefix_max = 0;
> -	char dev_name[1024];
> -	int fd, size;
> +	int lower = 'a';
> +	int upper = 'z';
> +	int bufsize = 1024 * 1024;
> +	char buf[bufsize];
> +	long long i = 0, j;
> +	int start;
>  
> -	if (!path)
> -		return 0;
> +	srand(time(NULL));
>  
> -	f = setmntent("/proc/mounts", "r");
> -	if (!f) {
> -		fprintf(stderr, "Failed to open /proc/mounts\n");
> -		return 0;
> -	}
> -
> -	while ((mnt = getmntent(f))) {
> -		/* Skip pseudo fs */
> -		if (mnt->mnt_fsname[0] != '/')
> -			continue;
> +	for (j = 0; j < bufsize; j++)
> +		buf[j] = (rand() % (upper - lower + 1)) + lower;
>  
> -		prefix_len = strlen(mnt->mnt_dir);
> -
> -		if (prefix_len > prefix_max &&
> -		    !strncmp(path, mnt->mnt_dir, prefix_len)) {
> -			prefix_max = prefix_len;
> -			strncpy(dev_name, mnt->mnt_fsname, sizeof(dev_name));
> -			dev_name[sizeof(dev_name)-1] = '\0';
> -		}
> +	if (size <= bufsize) {
> +		SAFE_WRITE(0, fd, buf, size);
> +		return;
>  	}
>  
> -	endmntent(f);
> +	while (i < size) {
> +		if (!tst_remaining_runtime())
> +			tst_brk(TCONF, "Out of runtime!");
>  
> -	if (!prefix_max) {
> -		fprintf(stderr, "Path '%s' not found in /proc/mounts\n", path);
> -		return 0;
> -	}
> +		start = rand() % (bufsize / 2);
>  
> -	printf("Path '%s' is on device '%s'\n", path, dev_name);
> +		for (j = 0; j < start; j++) {
> +			buf[start - j] = buf[bufsize - start + j];
> +			i++;
>  
> -	fd = open(dev_name, O_RDONLY);
> -	if (!fd) {
> -		fprintf(stderr, "open('%s'): %s\n", dev_name, strerror(errno));
> -		return 0;
> -	}
> +			if (i > size)
> +				break;
> +		}

Huh, why do we change the buffer here at all?

What about much simpler:

#define SIZE (64 * 1024)

static void fill_with_rand_data(int fd, long long size)
{
	char buf[2 * SIZE];
	size_t i, off, to_write;

	for (i = 0; i < sizeof(buf); i++)
                buf[i] = (rand() % (upper - lower + 1)) + lower;

	do {
		if (!tst_remaning_runtime())
			tst_brk(TCONF, "Out of runtime!");

		off = rand() % SIZE;
		to_write = MIN(size, SIZE);

		SAFE_WRITE(1, fd, buf + off, to_write);

		size -= to_write;
	} while (size);

	SAFE_FSYNC(fd);
}

-- 
Cyril Hrubis
chrubis@suse.cz

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

      reply	other threads:[~2022-08-15 15:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12 12:27 [LTP] [PATCH v7] Refactor aiocp using new LTP API Andrea Cervesato via ltp
2022-08-15 15:30 ` Cyril Hrubis [this message]

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=YvpmmrnIif0aIxzF@yuki \
    --to=chrubis@suse.cz \
    --cc=andrea.cervesato@suse.com \
    --cc=ltp@lists.linux.it \
    /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;
as well as URLs for NNTP newsgroup(s).