1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) Christoph Hellwig. All Rights Reserved.
14 #include <sys/ioctl.h>
20 #define FICLONE _IOW(0x94, 9, int)
23 #define IO_PATTERN 0xab
25 int main(int argc, char *argv[])
27 struct io_context *ctx = NULL;
28 struct io_event evs[4];
29 struct iocb iocb1, iocb2, iocb3, iocb4;
30 struct iocb *iocbs[] = { &iocb1, &iocb2, &iocb3, &iocb4 };
32 int fd, clone, err = 0;
33 unsigned long buf_size = getpagesize() * 2;
34 char *filename, *clonename;
37 fprintf(stderr, "usage: %s filename clonename\n", argv[0]);
41 err = posix_memalign(&buf, getpagesize(), buf_size);
43 fprintf(stderr, "error %s during %s\n",
44 strerror(err), "posix_memalign");
47 memset(buf, IO_PATTERN, buf_size);
50 fd = open(filename, O_DIRECT | O_CREAT | O_TRUNC | O_RDWR, 0600);
56 if (write(fd, buf, buf_size) != buf_size) {
62 clone = open(clonename, O_DIRECT | O_CREAT | O_TRUNC | O_RDWR, 0600);
68 if (ioctl(clone, FICLONE, fd)) {
73 err = io_setup(4, &ctx);
75 fprintf(stderr, "io_setup error: %s\n", strerror(err));
80 * Test overlapping aio writes, where an earlier one clears the whole
81 * range of a later aio, thus leaving nothing to do for the I/O
82 * completion to do. To make things harder also make sure there is
83 * other outstanding COW I/O.
85 io_prep_pwrite(&iocb1, fd, buf, buf_size, 0);
86 io_prep_pwrite(&iocb2, fd, buf, buf_size / 2, 0);
87 io_prep_pwrite(&iocb3, fd, buf, buf_size / 2, buf_size);
88 io_prep_pwrite(&iocb4, fd, buf, buf_size, 0);
90 err = io_submit(ctx, 4, iocbs);
92 fprintf(stderr, "io_submit error: %s\n", strerror(err));
96 err = io_getevents(ctx, 4, 4, evs, NULL);
98 fprintf(stderr, "io_getevents error: %s\n", strerror(err));