linux: add IORING_OP_CLOSE support (#3964)

This commit is contained in:
Ben Noordhuis 2023-04-20 10:44:16 +02:00 committed by GitHub
parent 5ca5e475bb
commit dfae365f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -1821,6 +1821,9 @@ int uv_fs_chown(uv_loop_t* loop,
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
INIT(CLOSE);
req->file = file;
if (cb != NULL)
if (uv__iou_fs_close(loop, req))
return 0;
POST;
}

View File

@ -331,6 +331,7 @@ int uv__random_sysctl(void* buf, size_t buflen);
/* io_uring */
#ifdef __linux__
int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req);
int uv__iou_fs_fsync_or_fdatasync(uv_loop_t* loop,
uv_fs_t* req,
uint32_t fsync_flags);
@ -343,6 +344,7 @@ int uv__iou_fs_statx(uv_loop_t* loop,
int is_fstat,
int is_lstat);
#else
#define uv__iou_fs_close(loop, req) 0
#define uv__iou_fs_fsync_or_fdatasync(loop, req, fsync_flags) 0
#define uv__iou_fs_open(loop, req) 0
#define uv__iou_fs_read_or_write(loop, req, is_read) 0

View File

@ -147,6 +147,7 @@ enum {
UV__IORING_OP_WRITEV = 2,
UV__IORING_OP_FSYNC = 3,
UV__IORING_OP_OPENAT = 18,
UV__IORING_OP_CLOSE = 19,
UV__IORING_OP_STATX = 21,
};
@ -650,6 +651,25 @@ static void uv__iou_submit(struct uv__iou* iou) {
}
int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req) {
struct uv__io_uring_sqe* sqe;
struct uv__iou* iou;
iou = &uv__get_internal_fields(loop)->iou;
sqe = uv__iou_get_sqe(iou, loop, req);
if (sqe == NULL)
return 0;
sqe->fd = req->file;
sqe->opcode = UV__IORING_OP_CLOSE;
uv__iou_submit(iou);
return 1;
}
int uv__iou_fs_fsync_or_fdatasync(uv_loop_t* loop,
uv_fs_t* req,
uint32_t fsync_flags) {

View File

@ -94,6 +94,7 @@ static int known_broken(uv_req_t* req) {
#ifdef __linux__
/* TODO(bnoordhuis) make cancellation work with io_uring */
switch (((uv_fs_t*) req)->fs_type) {
case UV_FS_CLOSE:
case UV_FS_FDATASYNC:
case UV_FS_FSTAT:
case UV_FS_FSYNC: