From 81626165ada62e660cfc0eaa80dfe0a6f53dba38 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 6 May 2020 03:12:24 -0700 Subject: [PATCH] HACK vfs_io_uring: add debugging for bug 14361 --- source3/modules/vfs_io_uring.c | 93 +++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/source3/modules/vfs_io_uring.c b/source3/modules/vfs_io_uring.c index b409d0753379..1a9b8e442213 100644 --- a/source3/modules/vfs_io_uring.c +++ b/source3/modules/vfs_io_uring.c @@ -35,6 +35,8 @@ struct vfs_io_uring_config { struct tevent_fd *fde; struct vfs_io_uring_request *queue; struct vfs_io_uring_request *pending; + bool check_ff; + size_t truncate_pread; }; struct vfs_io_uring_request { @@ -48,6 +50,11 @@ struct vfs_io_uring_request { struct timespec start_time; struct timespec end_time; SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes); + const char *opname; + struct files_struct *fsp; + uint8_t *data; + size_t len; + off_t ofs; }; static void vfs_io_uring_finish_req(struct vfs_io_uring_request *cur, @@ -69,6 +76,77 @@ static void vfs_io_uring_finish_req(struct vfs_io_uring_request *cur, SMBPROFILE_BYTES_ASYNC_SET_IDLE(cur->profile_bytes); cur->end_time = end_time; + if (cur->opname == NULL) { + goto done; + } + + if (cqe->res < 0) { + goto done; + } + + if ((size_t)cqe->res != (size_t)cur->len) { + DBG_ERR("Invalid %s ofs=%zu (0x%zx) len=%zu (0x%zx) nread=%zu (0x%zu) eof=%zu (0x%zx) blks=%zu blocks=%zu %s %s\n", + cur->opname, + (size_t)cur->ofs, + (size_t)cur->ofs, + (size_t)cur->len, + (size_t)cur->len, + (size_t)cqe->res, + (size_t)cqe->res, + (size_t)cur->fsp->fsp_name->st.st_ex_size, + (size_t)cur->fsp->fsp_name->st.st_ex_size, + (size_t)cur->fsp->fsp_name->st.st_ex_blksize, + (size_t)cur->fsp->fsp_name->st.st_ex_blocks, + fsp_str_dbg(cur->fsp), + fsp_fnum_dbg(cur->fsp)); + } else { + DBG_WARNING("%s ofs=%zu (0x%zx) len=%zu (0x%zx) nread=%zu (0x%zu) eof=%zu (0x%zx) blks=%zu blocks=%zu %s %s\n", + cur->opname, + (size_t)cur->ofs, + (size_t)cur->ofs, + (size_t)cur->len, + (size_t)cur->len, + (size_t)cqe->res, + (size_t)cqe->res, + (size_t)cur->fsp->fsp_name->st.st_ex_size, + (size_t)cur->fsp->fsp_name->st.st_ex_size, + (size_t)cur->fsp->fsp_name->st.st_ex_blksize, + (size_t)cur->fsp->fsp_name->st.st_ex_blocks, + fsp_str_dbg(cur->fsp), + fsp_fnum_dbg(cur->fsp)); + } + + if (cur->config->check_ff) { + size_t i; + size_t len = MIN(cur->len, ((size_t)cqe->res)); + for (i = 0; i < len; i++) { + size_t fofs; + if (cur->data[i] == 0xff) { + continue; + } + + fofs = cur->ofs + i; + DBG_ERR("%s invalid byte[0x%x] at fofs=%zu (0x%zx) ofs=%zu (0x%zx) len=%zu (0x%zx) nread=%zu (0x%zu) eof=%zu (0x%zx) blks=%zu blocks=%zu %s %s\n", + cur->opname, + cur->data[i], + (size_t)fofs, + (size_t)fofs, + (size_t)cur->ofs, + (size_t)cur->ofs, + (size_t)cur->len, + (size_t)cur->len, + (size_t)cqe->res, + (size_t)cqe->res, + (size_t)cur->fsp->fsp_name->st.st_ex_size, + (size_t)cur->fsp->fsp_name->st.st_ex_size, + (size_t)cur->fsp->fsp_name->st.st_ex_blksize, + (size_t)cur->fsp->fsp_name->st.st_ex_blocks, + fsp_str_dbg(cur->fsp), + fsp_fnum_dbg(cur->fsp)); + break; + } + } +done: /* * We rely on being inside the _send() function * or tevent_req_defer_callback() being called @@ -216,6 +294,14 @@ static int vfs_io_uring_connect(vfs_handle_struct *handle, const char *service, return -1; } + config->check_ff = lp_parm_bool(SNUM(handle->conn), + "io_uring", + "check_ff", + false); + config->truncate_pread = lp_parm_ulonglong(SNUM(handle->conn), + "io_uring", + "truncate_pread", + UINT64_MAX); return 0; } @@ -319,13 +405,18 @@ static struct tevent_req *vfs_io_uring_pread_send(struct vfs_handle_struct *hand state->ur.config = config; state->ur.req = req; state->ur.state = state; + state->ur.opname = "pread"; + state->ur.fsp = fsp; + state->ur.data = data; + state->ur.len = n; + state->ur.ofs = offset; SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pread, profile_p, state->ur.profile_bytes, n); SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->ur.profile_bytes); state->iov.iov_base = (void *)data; - state->iov.iov_len = n; + state->iov.iov_len = MIN(n, config->truncate_pread); io_uring_prep_readv(&state->ur.sqe, fsp->fh->fd, &state->iov, 1, -- 2.17.1