From 4a4c44190057cef139c2cde5c7258854caa7558b Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 15 Mar 2025 20:46:11 -0600 Subject: lib9p: Have separate IO objects, so they can have their own state --- lib9p_util/static.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'lib9p_util/static.c') diff --git a/lib9p_util/static.c b/lib9p_util/static.c index a6ea8f6..50bb129 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -12,6 +12,12 @@ LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir, static); LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_file, util9p_static_file, static); +LO_IMPLEMENTATION_H(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dir); +LO_IMPLEMENTATION_C(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dir, static); + +LO_IMPLEMENTATION_H(lib9p_srv_fio, struct util9p_static_file, util9p_static_file); +LO_IMPLEMENTATION_C(lib9p_srv_fio, struct util9p_static_file, util9p_static_file, static); + /* dir ************************************************************************/ static void util9p_static_dir_free(struct util9p_static_dir *self) { @@ -26,11 +32,6 @@ static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { .path = self->pathnum, }; } -static uint32_t util9p_static_dir_chio(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { - assert(self); - assert(ctx); - return 0; -} static struct lib9p_stat util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); @@ -68,7 +69,7 @@ static void util9p_static_dir_remove(struct util9p_static_dir *self, struct lib9 lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); } -static lo_interface lib9p_srv_file util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, +static lo_interface lib9p_srv_file util9p_static_dir_dwalk(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, struct lib9p_s childname) { assert(self); assert(ctx); @@ -97,6 +98,16 @@ static lo_interface lib9p_srv_file util9p_static_dir_dcreate(struct util9p_stati return LO_NULL(lib9p_srv_file); } +LIB9P_SRV_NOTFILE(struct util9p_static_dir, util9p_static_dir); + +static lo_interface lib9p_srv_dio util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { + assert(self); + assert(ctx); + return lo_box_util9p_static_dir_as_lib9p_srv_dio(self); +} +static void util9p_static_dir_iofree(struct util9p_static_dir *self) { + assert(self); +} static size_t util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, uint8_t *buf, uint32_t byte_count, @@ -126,8 +137,6 @@ static size_t util9p_static_dir_dread(struct util9p_static_dir *self, struct lib return obj_offset - _obj_offset; } -LIB9P_SRV_NOTFILE(struct util9p_static_dir, util9p_static_dir) - /* file ***********************************************************************/ static void util9p_static_file_free(struct util9p_static_file *self) { @@ -142,11 +151,6 @@ static struct lib9p_qid util9p_static_file_qid(struct util9p_static_file *self) .path = self->pathnum, }; } -static uint32_t util9p_static_file_chio(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { - assert(self); - assert(ctx); - return 0; -} static inline size_t util9p_static_file_size(struct util9p_static_file *file) { assert(file); @@ -196,8 +200,24 @@ static void util9p_static_file_remove(struct util9p_static_file *self, struct li lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); } -LIB9P_SRV_NOTDIR(struct util9p_static_file, util9p_static_file) +LIB9P_SRV_NOTDIR(struct util9p_static_file, util9p_static_file); +static lo_interface lib9p_srv_fio util9p_static_file_fopen(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, + bool rd, bool wr, bool trunc) { + assert(self); + assert(ctx); + assert(rd); + assert(!wr); + assert(!trunc); + return lo_box_util9p_static_file_as_lib9p_srv_fio(self); +} +static void util9p_static_file_iofree(struct util9p_static_file *self) { + assert(self); +} +static uint32_t util9p_static_file_iounit(struct util9p_static_file *self) { + assert(self); + return 0; +} static uint32_t util9p_static_file_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, void *buf, uint32_t byte_count, @@ -220,7 +240,6 @@ static uint32_t util9p_static_file_pread(struct util9p_static_file *self, struct memcpy(buf, &self->data_start[beg_off], end_off-beg_off); return (uint32_t)(end_off-beg_off); } - static uint32_t util9p_static_file_pwrite(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, void *LM_UNUSED(buf), uint32_t LM_UNUSED(byte_count), -- cgit v1.2.3-2-g168b 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_util/static.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib9p_util/static.c') diff --git a/lib9p_util/static.c b/lib9p_util/static.c index 50bb129..7f1e6b7 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -218,27 +218,27 @@ static uint32_t util9p_static_file_iounit(struct util9p_static_file *self) { assert(self); return 0; } -static uint32_t util9p_static_file_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, - void *buf, - uint32_t byte_count, - uint64_t byte_offset) { +static void util9p_static_file_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, + uint32_t byte_count, uint64_t byte_offset, + struct iovec *ret) { assert(self); assert(ctx); + assert(ret); size_t data_size = util9p_static_file_size(self); if (byte_offset > (uint64_t)data_size) { lib9p_error(&ctx->basectx, LINUX_EINVAL, "offset is past end-of-file length"); - return 0; + return; } size_t beg_off = (size_t)byte_offset; size_t end_off = beg_off + (size_t)byte_count; if (end_off > data_size) end_off = data_size; - memcpy(buf, &self->data_start[beg_off], end_off-beg_off); - return (uint32_t)(end_off-beg_off); + ret->iov_base = &self->data_start[beg_off]; + ret->iov_len = end_off-beg_off; } static uint32_t util9p_static_file_pwrite(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, void *LM_UNUSED(buf), -- cgit v1.2.3-2-g168b