^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Simple test program that demonstrates a file copy through io_uring. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * uses the API exposed by liburing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2018-2019 Jens Axboe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <assert.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sys/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "liburing.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define QD 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define BS (32*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int infd, outfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct io_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) off_t first_offset, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) size_t first_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct iovec iov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static int setup_context(unsigned entries, struct io_uring *ring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ret = io_uring_queue_init(entries, ring, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) fprintf(stderr, "queue_init: %s\n", strerror(-ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int get_file_size(int fd, off_t *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct stat st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (fstat(fd, &st) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (S_ISREG(st.st_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *size = st.st_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) } else if (S_ISBLK(st.st_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long long bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (ioctl(fd, BLKGETSIZE64, &bytes) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *size = bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static void queue_prepped(struct io_uring *ring, struct io_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct io_uring_sqe *sqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sqe = io_uring_get_sqe(ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) assert(sqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (data->read)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) io_uring_prep_readv(sqe, infd, &data->iov, 1, data->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) io_uring_prep_writev(sqe, outfd, &data->iov, 1, data->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) io_uring_sqe_set_data(sqe, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int queue_read(struct io_uring *ring, off_t size, off_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct io_uring_sqe *sqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct io_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) data = malloc(size + sizeof(*data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) sqe = io_uring_get_sqe(ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!sqe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) data->read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) data->offset = data->first_offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) data->iov.iov_base = data + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) data->iov.iov_len = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) data->first_len = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) io_uring_prep_readv(sqe, infd, &data->iov, 1, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) io_uring_sqe_set_data(sqe, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void queue_write(struct io_uring *ring, struct io_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) data->read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) data->offset = data->first_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) data->iov.iov_base = data + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) data->iov.iov_len = data->first_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) queue_prepped(ring, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) io_uring_submit(ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int copy_file(struct io_uring *ring, off_t insize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) unsigned long reads, writes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct io_uring_cqe *cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) off_t write_left, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) write_left = insize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) writes = reads = offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) while (insize || write_left) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned long had_reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int got_comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * Queue up as many reads as we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) had_reads = reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) while (insize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) off_t this_size = insize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (reads + writes >= QD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (this_size > BS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) this_size = BS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) else if (!this_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (queue_read(ring, this_size, offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) insize -= this_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) offset += this_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) reads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (had_reads != reads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ret = io_uring_submit(ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) fprintf(stderr, "io_uring_submit: %s\n", strerror(-ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Queue is full at this point. Find at least one completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) got_comp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) while (write_left) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct io_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (!got_comp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = io_uring_wait_cqe(ring, &cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) got_comp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ret = io_uring_peek_cqe(ring, &cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) fprintf(stderr, "io_uring_peek_cqe: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) strerror(-ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!cqe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) data = io_uring_cqe_get_data(cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (cqe->res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (cqe->res == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) queue_prepped(ring, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) io_uring_cqe_seen(ring, cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) fprintf(stderr, "cqe failed: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) strerror(-cqe->res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) } else if ((size_t) cqe->res != data->iov.iov_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Short read/write, adjust and requeue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) data->iov.iov_base += cqe->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) data->iov.iov_len -= cqe->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) data->offset += cqe->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) queue_prepped(ring, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) io_uring_cqe_seen(ring, cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * All done. if write, nothing else to do. if read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * queue up corresponding write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (data->read) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) queue_write(ring, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) write_left -= data->first_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) reads--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) writes++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) writes--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) io_uring_cqe_seen(ring, cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int main(int argc, char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct io_uring ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) off_t insize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (argc < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) printf("%s: infile outfile\n", argv[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) infd = open(argv[1], O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (infd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) perror("open infile");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) outfd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (outfd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) perror("open outfile");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (setup_context(QD, &ring))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (get_file_size(infd, &insize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ret = copy_file(&ring, insize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) close(infd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) close(outfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) io_uring_queue_exit(&ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }