From 0c5b5daa38aeb0b4f77b88ef3caa046521336c58 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Thu, 11 Jul 2019 09:34:43 +0200 Subject: [PATCH] infra: {send,recv}ing mars_cmd via wrapper --- kernel/mars_client.c | 6 +++--- kernel/mars_net.c | 20 +++++++++++++++++--- kernel/mars_net.h | 10 ++++++++-- kernel/mars_server.c | 6 +++--- kernel/sy_old/mars_main.c | 4 ++-- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/kernel/mars_client.c b/kernel/mars_client.c index 4a30d27c..12ccbeb9 100644 --- a/kernel/mars_client.c +++ b/kernel/mars_client.c @@ -299,7 +299,7 @@ struct client_channel *_get_channel(struct client_bundle *bundle, int min_channe .cmd_code = CMD_CONNECT, .cmd_str1 = bundle->path, }; - int status = mars_send_struct(&res->socket, &cmd, mars_cmd_meta, false); + int status = mars_send_cmd(&res->socket, &cmd, false); MARS_DBG("send CMD_CONNECT status = %d\n", status); if (unlikely(status < 0)) { MARS_WRN("connect '%s' @%s on channel %d failed, status = %d\n", @@ -330,7 +330,7 @@ int _request_info(struct client_channel *ch) int status; MARS_DBG("\n"); - status = mars_send_struct(&ch->socket, &cmd, mars_cmd_meta, false); + status = mars_send_cmd(&ch->socket, &cmd, false); MARS_DBG("send CMD_GETINFO status = %d\n", status); if (unlikely(status < 0)) { MARS_DBG("send of getinfo failed, status = %d\n", status); @@ -553,7 +553,7 @@ int receiver_thread(void *data) continue; } - status = mars_recv_struct(&ch->socket, &cmd, mars_cmd_meta); + status = mars_recv_cmd(&ch->socket, &cmd); MARS_IO("got cmd = %d status = %d\n", cmd.cmd_code, status); if (status <= 0) { if (brick->power.button && diff --git a/kernel/mars_net.c b/kernel/mars_net.c index 54bc9595..66a6a561 100644 --- a/kernel/mars_net.c +++ b/kernel/mars_net.c @@ -1186,8 +1186,22 @@ const struct meta mars_cmd_meta[] = { META_INI(cmd_str1, struct mars_cmd, FIELD_STRING), {} }; -EXPORT_SYMBOL_GPL(mars_cmd_meta); +int mars_send_cmd(struct mars_socket *msock, struct mars_cmd *cmd, bool cork) +{ + int status; + + status = desc_send_struct(msock, cmd, mars_cmd_meta, cork); + return status; +} + +int _mars_recv_cmd(struct mars_socket *msock, struct mars_cmd *cmd, int line) +{ + int status; + + status = desc_recv_struct(msock, cmd, mars_cmd_meta, line); + return status; +} int mars_send_mref(struct mars_socket *msock, struct mref_object *mref, bool cork) { @@ -1204,7 +1218,7 @@ int mars_send_mref(struct mars_socket *msock, struct mref_object *mref, bool cor if (!cork || !msock->s_pos) get_lamport(NULL, &cmd.cmd_stamp); - status = desc_send_struct(msock, &cmd, mars_cmd_meta, true); + status = mars_send_cmd(msock, &cmd, true); if (status < 0) goto done; @@ -1263,7 +1277,7 @@ int mars_send_cb(struct mars_socket *msock, struct mref_object *mref, bool cork) if (!cork || !msock->s_pos) get_lamport(NULL, &cmd.cmd_stamp); - status = desc_send_struct(msock, &cmd, mars_cmd_meta, true); + status = mars_send_cmd(msock, &cmd, true); if (status < 0) goto done; diff --git a/kernel/mars_net.h b/kernel/mars_net.h index 4ddda908..23bec4a9 100644 --- a/kernel/mars_net.h +++ b/kernel/mars_net.h @@ -119,8 +119,6 @@ struct mars_cmd { //char *cmd_str3; }; -extern const struct meta mars_cmd_meta[]; - extern char *(*mars_translate_hostname)(const char *name); /* Low-level network traffic @@ -154,6 +152,14 @@ extern int _mars_recv_struct(struct mars_socket *msock, void *data, const struct /* High-level transport of mars structures */ + +extern int mars_send_cmd(struct mars_socket *msock, struct mars_cmd *cmd, bool cork); +extern int _mars_recv_cmd(struct mars_socket *msock, struct mars_cmd *cmd, int line); +#define mars_recv_cmd(_sock_,_cmd_) \ + ({ \ + _mars_recv_cmd(_sock_, _cmd_, __LINE__); \ + }) + extern int mars_send_dent_list(struct mars_socket *msock, struct list_head *anchor); extern int mars_recv_dent_list(struct mars_socket *msock, struct list_head *anchor); diff --git a/kernel/mars_server.c b/kernel/mars_server.c index d4b29cee..539198b4 100644 --- a/kernel/mars_server.c +++ b/kernel/mars_server.c @@ -444,7 +444,7 @@ int handler_thread(void *data) goto clean; } - status = mars_recv_struct(sock, &cmd, mars_cmd_meta); + status = mars_recv_cmd(sock, &cmd); if (unlikely(status < 0)) { MARS_WRN("#%d recv cmd status = %d\n", sock->s_debug_nr, status); goto clean_unlock; @@ -476,7 +476,7 @@ int handler_thread(void *data) break; } down(&brick->socket_sem); - status = mars_send_struct(sock, &cmd, mars_cmd_meta, true); + status = mars_send_cmd(sock, &cmd, true); if (status >= 0) { status = mars_send_struct(sock, &info, mars_info_meta, false); } @@ -552,7 +552,7 @@ int handler_thread(void *data) err: cmd.cmd_int1 = status; down(&brick->socket_sem); - status = mars_send_struct(sock, &cmd, mars_cmd_meta, false); + status = mars_send_cmd(sock, &cmd, false); up(&brick->socket_sem); break; } diff --git a/kernel/sy_old/mars_main.c b/kernel/sy_old/mars_main.c index 3e0305de..1b35fd40 100644 --- a/kernel/sy_old/mars_main.c +++ b/kernel/sy_old/mars_main.c @@ -2499,7 +2499,7 @@ int peer_thread(void *data) pause_time = 0; MARS_DBG("sending notify to peer...\n"); cmd.cmd_code = CMD_NOTIFY; - status = mars_send_struct(&peer->socket, &cmd, mars_cmd_meta, true); + status = mars_send_cmd(&peer->socket, &cmd, true); } if (likely(status >= 0)) { @@ -2522,7 +2522,7 @@ int peer_thread(void *data) } MARS_DBG("fetching dents from '%s' paths '%s'\n", peer->peer, cmd.cmd_str1); - status = mars_send_struct(&peer->socket, &cmd, mars_cmd_meta, false); + status = mars_send_cmd(&peer->socket, &cmd, false); } if (unlikely(status < 0)) { MARS_WRN("communication error on send, status = %d\n", status);