Skip to content

Lost of in-progress I/Os upon io_uring exit #19

@jacklee-cuhk

Description

@jacklee-cuhk

The current copy_file() does not wait for all submitted I/O's to complete before returning to main() which the latter closes the files and calls io_uring_queue_exit(). Any I/Os which are still in progress will be lost. This manifests as the output file having fewer bytes than the input file. This is tested and is repeatable in Ubuntu 20 running in a VM under VMWare Workstation, using liburing2_2.1-2build1_amd64.deb.

One way to fix this is to add the following codes before the return statement at the end of copy_file() to wait for all I/Os to complete before returning:

int num_pending = reads + writes; // # of I/O requests still pending.
for (int i=0; i<num_pending; i++) { // Wait for them to complete or else some may be discarded upon premature io_uring exit.
    io_uring_wait_cqe(ring, &cqe);
    io_uring_cqe_get_data(cqe);
    io_uring_cqe_seen(ring, cqe);
}

Cheers,
Jack

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions