diff options
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index 90791f3..cc4a048 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -14,15 +14,13 @@ #include <libcr_ipc/chan.h> #include <libcr_ipc/mutex.h> #include <libcr_ipc/select.h> -#include <libnet/libnet.h> +#include <libmisc/vcall.h> #include <lib9p/srv.h> #include "internal.h" /* structs ********************************************************************/ -#define MCALL(o, m, ...) (o)->vtable->m(o __VA_OPT__(,) __VA_ARGS__) - #define FIDFLAG_OPEN_R (1<<0) #define FIDFLAG_OPEN_W (1<<1) #define FIDFLAG_RCLOSE (1<<2) @@ -59,7 +57,7 @@ struct _srv_fidinfo { struct _srv_conn { /* immutable */ struct lib9p_srv *parent_srv; - struct libnet_conn *fd; + implements_net_conn *fd; cid_t reader; /* the lib9p_srv_read_cr() coroutine */ /* mutable */ cr_mutex_t writelock; @@ -151,7 +149,7 @@ static void respond_error(struct _lib9p_srv_req *req) { &host, req->net_bytes); cr_mutex_lock(&sess->parent_conn->writelock); - r = MCALL(sess->parent_conn->fd, write, + r = VCALL(sess->parent_conn->fd, write, req->net_bytes, decode_u32le(req->net_bytes)); cr_mutex_unlock(&sess->parent_conn->writelock); if (r < 0) @@ -160,12 +158,12 @@ static void respond_error(struct _lib9p_srv_req *req) { /* read coroutine *************************************************************/ -static bool read_at_least(struct libnet_conn *fd, uint8_t *buf, size_t goal, size_t *done) { +static bool read_at_least(implements_net_conn *fd, uint8_t *buf, size_t goal, size_t *done) { assert(buf); assert(goal); assert(done); while (*done < goal) { - ssize_t r = MCALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done); + ssize_t r = VCALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done); if (r < 0) { nonrespond_errorf("read: %s", strerror(-r)); return true; @@ -181,7 +179,7 @@ static bool read_at_least(struct libnet_conn *fd, uint8_t *buf, size_t goal, siz static void handle_message(struct _lib9p_srv_req *ctx); -__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct libnet_listener *listener) { +__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, implements_net_listener *listener) { uint8_t buf[CONFIG_9P_MAX_MSG_SIZE]; assert(srv); @@ -193,7 +191,7 @@ __attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct for (;;) { struct _srv_conn conn = { .parent_srv = srv, - .fd = MCALL(listener, accept), + .fd = VCALL(listener, accept), .reader = cr_getcid(), }; if (!conn.fd) { @@ -253,12 +251,12 @@ __attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct _lib9p_srv_reqch_send_req(&srv->_reqch, &req); } close: - MCALL(conn.fd, close, true, sess.reqs.len == 0); + VCALL(conn.fd, close, true, sess.reqs.len == 0); if (sess.reqs.len) { sess.closing = true; cr_pause_and_yield(); assert(sess.reqs.len == 0); - MCALL(conn.fd, close, true, true); + VCALL(conn.fd, close, true, true); } } } @@ -358,7 +356,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { if (typ % 2 != 0) { lib9p_errorf(&ctx->ctx.basectx, LINUX_EOPNOTSUPP, "expected a T-message but got an R-message: message_type=%s", - lib9p_msg_type_str(typ)); + lib9p_msg_type_str(&ctx->ctx.basectx, typ)); goto write; } ssize_t host_size = lib9p_validate(&ctx->ctx.basectx, ctx->net_bytes); @@ -385,17 +383,17 @@ static void handle_message(struct _lib9p_srv_req *ctx) { goto write; cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock); - MCALL(ctx->parent_sess->parent_conn->fd, write, + VCALL(ctx->parent_sess->parent_conn->fd, write, ctx->net_bytes, decode_u32le(ctx->net_bytes)); cr_mutex_unlock(&ctx->parent_sess->parent_conn->writelock); } } #define util_handler_common(ctx, req, resp) do { \ - assert(ctx); \ - assert(req); \ - assert(resp); \ - resp->tag = req->tag; \ + assert(ctx); \ + assert(req); \ + assert(resp); \ + resp->tag = req->tag; \ } while (0) static inline bool util_check_perm(struct lib9p_srv_ctx *ctx, struct lib9p_stat *stat, uint8_t action) { @@ -415,7 +413,7 @@ static inline bool util_release(struct lib9p_srv_ctx *ctx, struct lib9p_srv_file if (file->_refcount == 0) { if (file->_parent_dir != file) util_release(ctx, file->_parent_dir); - file->vtable->free(ctx, file); + VCALL(file, free, ctx); } return lib9p_ctx_has_error(&ctx->basectx); } @@ -437,11 +435,11 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx, (req->version.utf8[6] == '\0' || req->version.utf8[6] == '.')) { version = LIB9P_VER_9P2000; #ifdef CONFIG_9P_ENABLE_9P2000_u - if (strcmp((char *)&req->version.utf8[6], ".u") == 0) + if (strcmp(&req->version.utf8[6], ".u") == 0) version = LIB9P_VER_9P2000_u; #endif #ifdef CONFIG_9P_ENABLE_9P2000_e - if (strcmp((char *)&req->version.utf8[6], ".e") == 0) + if (strcmp(&req->version.utf8[6], ".e") == 0) version = LIB9P_VER_9P2000_e; #endif } @@ -458,7 +456,7 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx, #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" resp->version.utf8 = lib9p_version_str(version); #pragma GCC diagnostic pop - resp->version.len = strlen((char *)resp->version.utf8); + resp->version.len = strlen(resp->version.utf8); resp->max_msg_size = (CONFIG_9P_MAX_MSG_SIZE < req->max_msg_size) ? CONFIG_9P_MAX_MSG_SIZE : req->max_msg_size; @@ -583,7 +581,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, return; } - struct lib9p_stat stat = rootdir->vtable->stat(&ctx->ctx, rootdir); + struct lib9p_stat stat = VCALL(rootdir, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) { handle_Tclunk(ctx, &(struct lib9p_msg_Tclunk){.fid = req->fid}, @@ -627,7 +625,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, struct lib9p_srv_file *dir = fidinfo->file; if (req->newfid != req->fid) { - dir = dir->vtable->clone(&ctx->ctx, dir); + dir = VCALL(dir, clone, &ctx->ctx); assert((dir == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx)); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; @@ -647,7 +645,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, break; } - member = dir->vtable->dopen(&ctx->ctx, dir, req->wname[resp->nwqid].utf8); + member = VCALL(dir, dopen, &ctx->ctx, req->wname[resp->nwqid].utf8); assert((member == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx)); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) break; @@ -656,7 +654,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, } member->_refcount++; /* presumptively take ref-A */ - struct lib9p_stat stat = member->vtable->stat(&ctx->ctx, member); + struct lib9p_stat stat = VCALL(member, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) { util_release(&ctx->ctx, member); /* presumption of taking ref-A failed */ break; @@ -733,7 +731,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, /* Check permissions. */ if (reqmode & LIB9P_O_RCLOSE) { - struct lib9p_stat parent_stat = file->_parent_dir->vtable->stat(&ctx->ctx, file->_parent_dir); + struct lib9p_stat parent_stat = VCALL(file->_parent_dir, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; lib9p_assert_stat(parent_stat); @@ -744,7 +742,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, } fidflags = fidflags | FIDFLAG_RCLOSE; } - struct lib9p_stat stat = file->vtable->stat(&ctx->ctx, file); + struct lib9p_stat stat = VCALL(file, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; lib9p_assert_stat(stat); @@ -775,7 +773,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, } /* Actually make the call. */ - uint32_t iounit = file->vtable->io(&ctx->ctx, file, reqmode); + uint32_t iounit = VCALL(file, io, &ctx->ctx, reqmode); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; @@ -831,7 +829,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, return; } /* Do it. */ - size_t num = file->vtable->dread(&ctx->ctx, file, (uint8_t *)resp->data.dat, req->count, idx); + size_t num = VCALL(file, dread, &ctx->ctx, (uint8_t *)resp->data.dat, req->count, idx); /* Translate object-count back to byte-count. */ uint32_t len = 0; for (size_t i = 0; i < num; i++) { @@ -844,7 +842,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, fidinfo->dir_idx = idx+num; fidinfo->dir_off = req->offset + len; } else - resp->data.len = file->vtable->pread(&ctx->ctx, file, resp->data.dat, req->count, req->offset); + resp->data.len = VCALL(file, pread, &ctx->ctx, resp->data.dat, req->count, req->offset); } static void handle_Twrite(struct _lib9p_srv_req *ctx, @@ -869,7 +867,7 @@ static void handle_Twrite(struct _lib9p_srv_req *ctx, struct lib9p_srv_file *file = fidinfo->file; /* Do it. */ - resp->count = file->vtable->pwrite(&ctx->ctx, file, req->data.dat, req->data.len, req->offset); + resp->count = VCALL(file, pwrite, &ctx->ctx, req->data.dat, req->data.len, req->offset); } static void handle_Tclunk(struct _lib9p_srv_req *ctx, @@ -890,7 +888,7 @@ static void handle_Tclunk(struct _lib9p_srv_req *ctx, return; } - fidinfo->file->vtable->free(&ctx->ctx, fidinfo->file); + VCALL(fidinfo->file, free, &ctx->ctx); fidmap_del(&ctx->parent_sess->fids, req->fid); } @@ -915,7 +913,7 @@ static void handle_Tstat(struct _lib9p_srv_req *ctx, return; } - resp->stat = fidinfo->file->vtable->stat(&ctx->ctx, fidinfo->file); + resp->stat = VCALL(fidinfo->file, stat, &ctx->ctx); if (!lib9p_ctx_has_error(&ctx->ctx.basectx)) lib9p_assert_stat(resp->stat); } |