summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-10 00:06:34 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-10 00:06:34 -0700
commit6cd125e1ffd44fdf62c44d22c519561a8c9d7268 (patch)
treebf2b4a8225fe0d6f00084a1577c70bb564a20600 /lib9p/srv.c
parentf466cff948ec638f26a9a77a391904ebe03c4dfb (diff)
parenta51875001eb672d73c9d84d44bb32abce327b931 (diff)
Merge branch 'lukeshu/libobj-simple'
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c91
1 files changed, 45 insertions, 46 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 47dd78d..0e58068 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -12,7 +12,6 @@
#include <libcr_ipc/mutex.h>
#include <libcr_ipc/select.h>
#include <libmisc/assert.h>
-#include <libmisc/vcall.h>
#include <libhw/generic/net.h>
#define LOG_NAME 9P_SRV
@@ -54,7 +53,7 @@ int lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx) {
typedef typeof( ((struct lib9p_qid){}).path ) srv_path_t;
struct srv_pathinfo {
- implements_lib9p_srv_file *file;
+ lo_interface lib9p_srv_file file;
srv_path_t parent_dir;
/* References from other srv_pathinfos (via .parent_dir) or
@@ -108,7 +107,7 @@ struct _srv_fidinfo {
struct _srv_conn {
/* immutable */
struct lib9p_srv *parent_srv;
- implements_net_stream_conn *fd;
+ lo_interface net_stream_conn fd;
cid_t reader; /* the lib9p_srv_read_cr() coroutine */
/* mutable */
cr_mutex_t writelock;
@@ -197,7 +196,7 @@ static void respond_error(struct _lib9p_srv_req *req) {
&host, req->net_bytes);
cr_mutex_lock(&sess->parent_conn->writelock);
- r = VCALL(sess->parent_conn->fd, write,
+ r = LO_CALL(sess->parent_conn->fd, write,
req->net_bytes, uint32le_decode(req->net_bytes));
cr_mutex_unlock(&sess->parent_conn->writelock);
if (r < 0)
@@ -206,12 +205,12 @@ static void respond_error(struct _lib9p_srv_req *req) {
/* read coroutine *************************************************************/
-static bool read_at_least(implements_net_stream_conn *fd, uint8_t *buf, size_t goal, size_t *done) {
+static bool read_at_least(lo_interface net_stream_conn fd, uint8_t *buf, size_t goal, size_t *done) {
assert(buf);
assert(goal);
assert(done);
while (*done < goal) {
- ssize_t r = VCALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done);
+ ssize_t r = LO_CALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done);
if (r < 0) {
nonrespond_errorf("read: %s", net_strerror(-r));
return true;
@@ -227,12 +226,12 @@ static bool read_at_least(implements_net_stream_conn *fd, uint8_t *buf, size_t g
static void handle_message(struct _lib9p_srv_req *ctx);
-[[noreturn]] void lib9p_srv_read_cr(struct lib9p_srv *srv, implements_net_stream_listener *listener) {
+[[noreturn]] void lib9p_srv_read_cr(struct lib9p_srv *srv, lo_interface net_stream_listener listener) {
uint8_t buf[CONFIG_9P_MAX_MSG_SIZE];
assert(srv);
assert(srv->rootdir);
- assert(listener);
+ assert(!LO_IS_NULL(listener));
srv->readers++;
@@ -241,10 +240,10 @@ static void handle_message(struct _lib9p_srv_req *ctx);
for (;;) {
struct _srv_conn conn = {
.parent_srv = srv,
- .fd = VCALL(listener, accept),
+ .fd = LO_CALL(listener, accept),
.reader = cr_getcid(),
};
- if (!conn.fd) {
+ if (LO_IS_NULL(conn.fd)) {
nonrespond_errorf("accept: error");
srv->readers--;
if (srv->readers == 0)
@@ -305,12 +304,12 @@ static void handle_message(struct _lib9p_srv_req *ctx);
_lib9p_srv_reqch_send_req(&srv->_reqch, &req);
}
close:
- VCALL(conn.fd, close, true, sess.reqs.len == 0);
+ LO_CALL(conn.fd, close, true, sess.reqs.len == 0);
if (sess.reqs.len) {
sess.closing = true;
cr_pause_and_yield();
assert(sess.reqs.len == 0);
- VCALL(conn.fd, close, true, true);
+ LO_CALL(conn.fd, close, true, true);
}
}
}
@@ -438,8 +437,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) {
goto write;
cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock);
- VCALL(ctx->parent_sess->parent_conn->fd, write,
- ctx->net_bytes, uint32le_decode(ctx->net_bytes));
+ LO_CALL(ctx->parent_sess->parent_conn->fd, write,
+ ctx->net_bytes, uint32le_decode(ctx->net_bytes));
cr_mutex_unlock(&ctx->parent_sess->parent_conn->writelock);
}
}
@@ -470,15 +469,15 @@ static inline bool srv_util_check_perm(struct _lib9p_srv_req *ctx, struct lib9p_
* Returns a pointer to the stored pathinfo.
*/
static inline struct srv_pathinfo *srv_util_pathsave(struct _lib9p_srv_req *ctx,
- implements_lib9p_srv_file *file,
+ lo_interface lib9p_srv_file file,
srv_path_t parent_path) {
assert(ctx);
- assert(file);
+ assert(!LO_IS_NULL(file));
- struct lib9p_qid qid = VCALL(file, qid);
+ struct lib9p_qid qid = LO_CALL(file, qid);
struct srv_pathinfo *pathinfo = pathmap_load(&ctx->parent_sess->paths, qid.path);
if (pathinfo)
- assert(pathinfo->file == file);
+ assert(LO_EQ(pathinfo->file, file));
else {
pathinfo = pathmap_store(&ctx->parent_sess->paths, qid.path,
(struct srv_pathinfo){
@@ -512,14 +511,14 @@ static inline void srv_util_pathfree(struct _lib9p_srv_req *ctx, srv_path_t path
if (pathinfo->gc_refcount == 0) {
if (pathinfo->parent_dir != path)
srv_util_pathfree(ctx, pathinfo->parent_dir);
- VCALL(pathinfo->file, free);
+ LO_CALL(pathinfo->file, free);
pathmap_del(&ctx->parent_sess->paths, path);
}
}
static inline bool srv_util_pathisdir(struct srv_pathinfo *pathinfo) {
assert(pathinfo);
- return VCALL(pathinfo->file, qid).type & LIB9P_QT_DIR;
+ return LO_CALL(pathinfo->file, qid).type & LIB9P_QT_DIR;
}
/**
@@ -532,7 +531,7 @@ static inline struct _srv_fidinfo *srv_util_fidsave(struct _lib9p_srv_req *ctx,
assert(fid != LIB9P_FID_NOFID);
assert(pathinfo);
- struct lib9p_qid qid = VCALL(pathinfo->file, qid);
+ struct lib9p_qid qid = LO_CALL(pathinfo->file, qid);
struct _srv_fidinfo *fidinfo = fidmap_load(&ctx->parent_sess->fids, fid);
if (fidinfo) {
@@ -703,12 +702,12 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx,
}
/* 1. File object */
- implements_lib9p_srv_file *root_file = srv->rootdir(&ctx->ctx, req->aname);
- assert((root_file == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx));
+ lo_interface lib9p_srv_file root_file = srv->rootdir(&ctx->ctx, req->aname);
+ assert(LO_IS_NULL(root_file) == lib9p_ctx_has_error(&ctx->ctx.basectx));
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
return;
- struct lib9p_qid root_qid = VCALL(root_file, qid);
+ struct lib9p_qid root_qid = LO_CALL(root_file, qid);
assert(root_qid.type & LIB9P_QT_DIR);
/* 2. pathinfo */
@@ -770,37 +769,37 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx,
break;
}
- implements_lib9p_srv_file *member_file = VCALL(pathinfo->file, dopen, &ctx->ctx, req->wname[resp->nwqid]);
- assert((member_file == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx));
+ lo_interface lib9p_srv_file member_file = LO_CALL(pathinfo->file, dopen, &ctx->ctx, req->wname[resp->nwqid]);
+ assert(LO_IS_NULL(member_file) == lib9p_ctx_has_error(&ctx->ctx.basectx));
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
break;
- new_pathinfo = srv_util_pathsave(ctx, member_file, VCALL(pathinfo->file, qid).path);
+ new_pathinfo = srv_util_pathsave(ctx, member_file, LO_CALL(pathinfo->file, qid).path);
}
if (srv_util_pathisdir(new_pathinfo)) {
- struct lib9p_stat stat = VCALL(new_pathinfo->file, stat, &ctx->ctx);
+ struct lib9p_stat stat = LO_CALL(new_pathinfo->file, stat, &ctx->ctx);
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
break;
lib9p_stat_assert(stat);
if (!srv_util_check_perm(ctx, &stat, 0b001)) {
lib9p_error(&ctx->ctx.basectx,
LINUX_EACCES, "you do not have execute permission on that directory");
- srv_util_pathfree(ctx, VCALL(new_pathinfo->file, qid).path);
+ srv_util_pathfree(ctx, LO_CALL(new_pathinfo->file, qid).path);
break;
}
}
- resp->wqid[resp->nwqid] = VCALL(new_pathinfo->file, qid);
+ resp->wqid[resp->nwqid] = LO_CALL(new_pathinfo->file, qid);
- srv_util_pathfree(ctx, VCALL(pathinfo->file, qid).path);
+ srv_util_pathfree(ctx, LO_CALL(pathinfo->file, qid).path);
pathinfo = new_pathinfo;
}
if (resp->nwqid == req->nwname) {
if (!srv_util_fidsave(ctx, req->newfid, pathinfo, req->newfid == req->fid))
- srv_util_pathfree(ctx, VCALL(pathinfo->file, qid).path);
+ srv_util_pathfree(ctx, LO_CALL(pathinfo->file, qid).path);
} else {
assert(lib9p_ctx_has_error(&ctx->ctx.basectx));
- srv_util_pathfree(ctx, VCALL(pathinfo->file, qid).path);
+ srv_util_pathfree(ctx, LO_CALL(pathinfo->file, qid).path);
if (resp->nwqid > 0)
lib9p_ctx_clear_error(&ctx->ctx.basectx);
}
@@ -844,7 +843,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx,
if (reqmode & LIB9P_O_RCLOSE) {
struct srv_pathinfo *parent = pathmap_load(&ctx->parent_sess->paths, pathinfo->parent_dir);
assert(parent);
- struct lib9p_stat parent_stat = VCALL(parent->file, stat, &ctx->ctx);
+ struct lib9p_stat parent_stat = LO_CALL(parent->file, stat, &ctx->ctx);
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
return;
lib9p_stat_assert(parent_stat);
@@ -855,7 +854,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx,
}
fidflags = fidflags | FIDFLAG_RCLOSE;
}
- struct lib9p_stat stat = VCALL(pathinfo->file, stat, &ctx->ctx);
+ struct lib9p_stat stat = LO_CALL(pathinfo->file, stat, &ctx->ctx);
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
return;
lib9p_stat_assert(stat);
@@ -893,10 +892,10 @@ static void handle_Topen(struct _lib9p_srv_req *ctx,
/* Actually make the call. */
if ((reqmode & LIB9P_O_TRUNC) || (rd && !pathinfo->rd_refcount) || (wr && !pathinfo->wr_refcount) ) {
- iounit = VCALL(pathinfo->file, chio, &ctx->ctx,
- fidflags & FIDFLAG_OPEN_R,
- fidflags & FIDFLAG_OPEN_W,
- reqmode & LIB9P_O_TRUNC);
+ iounit = LO_CALL(pathinfo->file, chio, &ctx->ctx,
+ fidflags & FIDFLAG_OPEN_R,
+ fidflags & FIDFLAG_OPEN_W,
+ reqmode & LIB9P_O_TRUNC);
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
return;
}
@@ -962,7 +961,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx,
return;
}
/* Do it. */
- size_t num = VCALL(pathinfo->file, dread, &ctx->ctx, (uint8_t *)resp->data, req->count, idx);
+ size_t num = LO_CALL(pathinfo->file, dread, &ctx->ctx, (uint8_t *)resp->data, req->count, idx);
/* Translate object-count back to byte-count. */
uint32_t len = 0;
for (size_t i = 0; i < num; i++) {
@@ -975,7 +974,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx,
fidinfo->dir_idx = idx+num;
fidinfo->dir_off = req->offset + len;
} else
- resp->count = VCALL(pathinfo->file, pread, &ctx->ctx, resp->data, req->count, req->offset);
+ resp->count = LO_CALL(pathinfo->file, pread, &ctx->ctx, resp->data, req->count, req->offset);
}
static void handle_Twrite(struct _lib9p_srv_req *ctx,
@@ -1001,7 +1000,7 @@ static void handle_Twrite(struct _lib9p_srv_req *ctx,
assert(pathinfo);
/* Do it. */
- resp->count = VCALL(pathinfo->file, pwrite, &ctx->ctx, req->data, req->count, req->offset);
+ resp->count = LO_CALL(pathinfo->file, pwrite, &ctx->ctx, req->data, req->count, req->offset);
}
static void clunkremove(struct _lib9p_srv_req *ctx, lib9p_fid_t fid, bool remove) {
@@ -1024,17 +1023,17 @@ static void clunkremove(struct _lib9p_srv_req *ctx, lib9p_fid_t fid, bool remove
}
struct srv_pathinfo *parent = pathmap_load(&ctx->parent_sess->paths, pathinfo->parent_dir);
assert(parent);
- struct lib9p_stat parent_stat = VCALL(parent->file, stat, &ctx->ctx);
+ struct lib9p_stat parent_stat = LO_CALL(parent->file, stat, &ctx->ctx);
if (!srv_util_check_perm(ctx, &parent_stat, 0b010)) {
lib9p_error(&ctx->ctx.basectx,
LINUX_EACCES, "you do not have write permission on the parent directory");
goto clunk;
}
- VCALL(pathinfo->file, remove, &ctx->ctx);
+ LO_CALL(pathinfo->file, remove, &ctx->ctx);
}
clunk:
- srv_util_pathfree(ctx, VCALL(pathinfo->file, qid).path);
+ srv_util_pathfree(ctx, LO_CALL(pathinfo->file, qid).path);
fidmap_del(&ctx->parent_sess->fids, fid);
}
@@ -1069,7 +1068,7 @@ static void handle_Tstat(struct _lib9p_srv_req *ctx,
struct srv_pathinfo *pathinfo = pathmap_load(&ctx->parent_sess->paths, fidinfo->path);
assert(pathinfo);
- resp->stat = VCALL(pathinfo->file, stat, &ctx->ctx);
+ resp->stat = LO_CALL(pathinfo->file, stat, &ctx->ctx);
if (!lib9p_ctx_has_error(&ctx->ctx.basectx))
lib9p_stat_assert(resp->stat);
}