[LTP] [PATCH v2 1/2] syscalls/sync_file_range: add partial file sync test-case

Cyril Hrubis chrubis@suse.cz
Tue Mar 5 15:19:03 CET 2019


Hi!
> +static void verify_sync_partial_file(void)
> +{
> +	int fd;
> +	unsigned long written;
> +
> +	fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE);
> +
> +	tst_dev_bytes_written(tst_device->dev);
> +
> +	tst_fill_fd(fd, 0xff, TST_MB, FILE_SIZE_MB);
> +
> +	TEST(sync_file_range(fd, FILE_SIZE/4, FILE_SIZE/2,
> +			     SYNC_FILE_RANGE_WAIT_BEFORE |
> +			     SYNC_FILE_RANGE_WRITE |
> +			     SYNC_FILE_RANGE_WAIT_AFTER));
> +
> +	if (TST_RET)
> +		tst_brk(TFAIL | TTERRNO, "sync_file_range() failed");
> +
> +	written = tst_dev_bytes_written(tst_device->dev);
> +
> +	SAFE_CLOSE(fd);
> +
> +	if (written >= FILE_SIZE/2)
> +		tst_res(TPASS, "Test file range synced to device");
> +	else
> +		tst_res(TFAIL, "Synced %li, expected %i", written,
> +			FILE_SIZE/2);
> +}


Looking at this the function is nearly the same as the other one, I
guess that we may as well define the function as:

static void verify_sync_file_range(off64_t off, off64_t size, char byte)
{
	...
}

Also I'm not sure I was clear enough, but I was suggesting to check for
upper bound for the synced size as well, which is why I suggested to do
full write, sync only part of it, then check that the size was within
bounds, i.e. >= size and  <= size + epsilon.

I guess that we can even extend this to call the sync over a range that
has been only partially written, but for that we would have to be
careful and make sure all the data has been either synced at the end of
the test function or use a different file for each test.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list