summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c77
1 files changed, 27 insertions, 50 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 5af0971..9d1b4ed 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -81,9 +81,8 @@ static uint32_t rerror_overhead_for_version(enum lib9p_version version,
bool e;
e = lib9p_marshal(&empty_ctx, LIB9P_TYP_Rerror,
- 0, /* tag */
&empty_error, /* host_body */
- scratch); /* net_bytes */
+ scratch); /* net_bytes */
assert(!e);
uint32_t min_msg_size = decode_u32le(scratch);
@@ -105,6 +104,7 @@ static void respond_error(struct _lib9p_srv_req *req) {
ssize_t r;
struct lib9p_msg_Rerror host = {
+ .tag = req->tag,
.ename = {
.len = strnlen(req->ctx.basectx.err_msg,
CONFIG_9P_MAX_ERR_SIZE),
@@ -123,7 +123,7 @@ static void respond_error(struct _lib9p_srv_req *req) {
host.ename.len = sess->max_msg_size - sess->rerror_overhead;
lib9p_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror,
- req->tag, &host, req->net_bytes);
+ &host, req->net_bytes);
cr_mutex_lock(&sess->parent_conn->writelock);
r = netio_write(sess->parent_conn->fd,
@@ -345,7 +345,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) {
goto write;
}
lib9p_unmarshal(&ctx->ctx.basectx, ctx->net_bytes,
- &typ, &ctx->tag, host_req);
+ &typ, host_req);
/* Handle it. */
tmessage_handlers[typ](ctx, (void *)host_req, (void *)host_resp);
@@ -354,7 +354,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) {
if (lib9p_ctx_has_error(&ctx->ctx.basectx))
respond_error(ctx);
else {
- if (lib9p_marshal(&ctx->ctx.basectx, typ+1, ctx->tag, host_resp,
+ if (lib9p_marshal(&ctx->ctx.basectx, typ+1, host_resp,
ctx->net_bytes))
goto write;
@@ -440,12 +440,17 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx,
ctx->parent_sess->rerror_overhead = min_msg_size;
}
+#define handler_common(ctx, req, resp) do { \
+ assert(ctx); \
+ assert(req); \
+ assert(resp); \
+ resp->tag = req->tag; \
+ } while (0)
+
static void handle_Tauth(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tauth *req,
struct lib9p_msg_Rauth *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
ctx->ctx.uid = req->n_uname;
ctx->ctx.uname = req->uname.utf8;
@@ -465,9 +470,7 @@ static void handle_Tauth(struct _lib9p_srv_req *ctx,
static void handle_Tattach(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tattach *req,
struct lib9p_msg_Rattach *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
ctx->ctx.uid = req->n_uname;
ctx->ctx.uname = req->uname.utf8;
@@ -543,9 +546,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx,
static void handle_Tflush(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tflush *req,
struct lib9p_msg_Rflush *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);;
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "flush not yet implemented");
@@ -554,9 +555,7 @@ static void handle_Tflush(struct _lib9p_srv_req *ctx,
static void handle_Twalk(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Twalk *req,
struct lib9p_msg_Rwalk *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
struct lib9p_srv_file **dirpp = fidmap_load(&ctx->parent_sess->fids, req->fid);
if (!dirpp) {
@@ -627,9 +626,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx,
static void handle_Topen(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Topen *req,
struct lib9p_msg_Ropen *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);;
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "open not yet implemented");
@@ -638,9 +635,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx,
static void handle_Tcreate(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tcreate *req,
struct lib9p_msg_Rcreate *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "create not yet implemented");
@@ -649,9 +644,7 @@ static void handle_Tcreate(struct _lib9p_srv_req *ctx,
static void handle_Tread(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tread *req,
struct lib9p_msg_Rread *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "read not yet implemented");
@@ -660,9 +653,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx,
static void handle_Twrite(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Twrite *req,
struct lib9p_msg_Rwrite *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "write not yet implemented");
@@ -671,9 +662,7 @@ static void handle_Twrite(struct _lib9p_srv_req *ctx,
static void handle_Tclunk(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tclunk *req,
struct lib9p_msg_Rclunk *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
struct lib9p_srv_file **filepp = fidmap_load(&ctx->parent_sess->fids, req->fid);
if (!filepp) {
@@ -689,9 +678,7 @@ static void handle_Tclunk(struct _lib9p_srv_req *ctx,
static void handle_Tremove(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tremove *req,
struct lib9p_msg_Rremove *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "remove not yet implemented");
@@ -700,9 +687,7 @@ static void handle_Tremove(struct _lib9p_srv_req *ctx,
static void handle_Tstat(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tstat *req,
struct lib9p_msg_Rstat *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
struct lib9p_srv_file **filepp = fidmap_load(&ctx->parent_sess->fids, req->fid);
if (!filepp) {
@@ -717,9 +702,7 @@ static void handle_Tstat(struct _lib9p_srv_req *ctx,
static void handle_Twstat(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Twstat *req,
struct lib9p_msg_Rwstat *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);;
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "wstat not yet implemented");
@@ -728,9 +711,7 @@ static void handle_Twstat(struct _lib9p_srv_req *ctx,
static void handle_Tsession(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tsession *req,
struct lib9p_msg_Rsession *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "session not yet implemented");
@@ -739,9 +720,7 @@ static void handle_Tsession(struct _lib9p_srv_req *ctx,
static void handle_Tsread(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tsread *req,
struct lib9p_msg_Rsread *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "sread not yet implemented");
@@ -750,9 +729,7 @@ static void handle_Tsread(struct _lib9p_srv_req *ctx,
static void handle_Tswrite(struct _lib9p_srv_req *ctx,
struct lib9p_msg_Tswrite *req,
struct lib9p_msg_Rswrite *resp) {
- assert(ctx);
- assert(req);
- assert(resp);
+ handler_common(ctx, req, resp);
lib9p_error(&ctx->ctx.basectx,
LINUX_EOPNOTSUPP, "swrite not yet implemented");