MCPcopy Create free account
hub / github.com/axboe/liburing / copy_file

Function copy_file

examples/io_uring-cp.c:119–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119static int copy_file(struct io_uring *ring, off_t insize)
120{
121 unsigned long reads, writes;
122 struct io_uring_cqe *cqe;
123 off_t write_left, offset;
124 int ret;
125
126 write_left = insize;
127 writes = reads = offset = 0;
128
129 while (insize || write_left) {
130 unsigned long had_reads;
131 int got_comp;
132
133 /*
134 * Queue up as many reads as we can
135 */
136 had_reads = reads;
137 while (insize) {
138 off_t this_size = insize;
139
140 if (reads + writes >= QD)
141 break;
142 if (this_size > BS)
143 this_size = BS;
144 else if (!this_size)
145 break;
146
147 if (queue_read(ring, this_size, offset))
148 break;
149
150 insize -= this_size;
151 offset += this_size;
152 reads++;
153 }
154
155 if (had_reads != reads) {
156 ret = io_uring_submit(ring);
157 if (ret < 0) {
158 fprintf(stderr, "io_uring_submit: %s\n", strerror(-ret));
159 break;
160 }
161 }
162
163 /*
164 * Queue is full at this point. Find at least one completion.
165 */
166 got_comp = 0;
167 while (write_left) {
168 struct io_data *data;
169
170 if (!got_comp) {
171 ret = io_uring_wait_cqe(ring, &cqe);
172 got_comp = 1;
173 } else {
174 ret = io_uring_peek_cqe(ring, &cqe);
175 if (ret == -EAGAIN) {
176 cqe = NULL;

Callers 1

mainFunction · 0.70

Calls 5

queue_readFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_cqe_get_dataFunction · 0.85
queue_preppedFunction · 0.85
queue_writeFunction · 0.85

Tested by

no test coverage detected