From 865bb702f828784a0225b5eae9ed8803094140d5 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 18 Mar 2025 10:53:12 -0600 Subject: lib9p: Adjust for reads to be zero-copy --- lib9p/srv.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib9p/srv.c') diff --git a/lib9p/srv.c b/lib9p/srv.c index 9c679b6..50d0b78 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -950,7 +950,6 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, /* Variables. */ struct srv_pathinfo *pathinfo = pathmap_load(&ctx->parent_sess->paths, fidinfo->path); assert(pathinfo); - resp->data = (char *)(&resp[1]); /* Do it. */ if (srv_util_pathisdir(pathinfo)) { @@ -967,6 +966,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, return; } /* Do it. */ + resp->data = (char *)(&resp[1]); size_t num = LO_CALL(fidinfo->dir.io, dread, &ctx->ctx, (uint8_t *)resp->data, req->count, idx); /* Translate object-count back to byte-count. */ uint32_t len = 0; @@ -979,8 +979,16 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, /* Remember. */ fidinfo->dir.idx = idx+num; fidinfo->dir.off = req->offset + len; - } else - resp->count = LO_CALL(fidinfo->file.io, pread, &ctx->ctx, resp->data, req->count, req->offset); + } else { + struct iovec iov; + LO_CALL(fidinfo->file.io, pread, &ctx->ctx, req->count, req->offset, &iov); + if (!lib9p_ctx_has_error(&ctx->ctx.basectx)) { + resp->count = iov.iov_len; + resp->data = iov.iov_base; + if (resp->count > req->count) + resp->count = req->count; + } + } } static void handle_Twrite(struct _lib9p_srv_req *ctx, -- cgit v1.2.3-2-g168b