diff --git a/fs/hmdfs/comm/connection.c b/fs/hmdfs/comm/connection.c index 7613da514c7c912d13d79d98a965bd38954b2168..aec9cabf69311e20792ee517459efb708fe2b302 100644 --- a/fs/hmdfs/comm/connection.c +++ b/fs/hmdfs/comm/connection.c @@ -361,8 +361,7 @@ static int do_send_handshake(struct connection *conn_impl, __u8 ops, sizeof(struct connection_handshake_req) + len; if (((ops == CONNECT_MESG_HANDSHAKE_RESPONSE) || - (ops == CONNECT_MESG_HANDSHAKE_ACK)) && - (conn_impl->node->version >= DFS_2_0)) { + (ops == CONNECT_MESG_HANDSHAKE_ACK))) { extend_len = hs_get_extend_data_len(); send_len += extend_len; } @@ -379,15 +378,14 @@ static int do_send_handshake(struct connection *conn_impl, __u8 ops, memcpy(hs_data->dev_id, buf, len); if (((ops == CONNECT_MESG_HANDSHAKE_RESPONSE) || - ops == CONNECT_MESG_HANDSHAKE_ACK) && - (conn_impl->node->version >= DFS_2_0)) { + ops == CONNECT_MESG_HANDSHAKE_ACK)) { hs_extend_data = (uint8_t *)hs_data + sizeof(struct connection_handshake_req) + len; hs_fill_extend_data(conn_impl, ops, hs_extend_data, extend_len); } hs_head->magic = HMDFS_MSG_MAGIC; - hs_head->version = DFS_2_0; + hs_head->version = HMDFS_VERSION; hs_head->flags |= 0x1; hmdfs_info("Send handshake message: ops = %d, fd = %d", ops, ((struct tcp_handle *)(conn_impl->connect_handle))->fd); @@ -612,48 +610,31 @@ void connection_to_working(struct hmdfs_peer *node) peer_online(node); } -static int connection_check_version(__u8 version) -{ - __u8 min_ver = USERSPACE_MAX_VER; - - if (version <= min_ver || version >= MAX_VERSION) { - hmdfs_info("version err. version %u", version); - return -1; - } - return 0; -} - void connection_handshake_recv_handler(struct connection *conn_impl, void *buf, void *data, __u32 data_len) { - __u8 version; __u8 ops; __u8 status; int fd = ((struct tcp_handle *)(conn_impl->connect_handle))->fd; struct connection_msg_head *head = (struct connection_msg_head *)buf; int ret; - version = head->version; - conn_impl->node->version = version; - if (connection_check_version(version) != 0) + if (head->version != HMDFS_VERSION) goto out; - conn_impl->node->conn_operations = hmdfs_get_peer_operation(version); + + conn_impl->node->version = head->version; ops = head->operations; status = conn_impl->status; switch (ops) { case CONNECT_MESG_HANDSHAKE_REQUEST: hmdfs_info( - "Recved handshake request: device_id = %llu, version = %d, head->len = %d, tcp->fd = %d", - conn_impl->node->device_id, version, head->datasize, fd); + "Recved handshake request: device_id = %llu, head->len = %d, tcp->fd = %d", + conn_impl->node->device_id, head->datasize, fd); connection_send_handshake(conn_impl, CONNECT_MESG_HANDSHAKE_RESPONSE, head->msg_id); - if (conn_impl->node->version >= DFS_2_0) { - conn_impl->status = CONNECT_STAT_WAIT_ACK; - conn_impl->node->status = NODE_STAT_SHAKING; - } else { - conn_impl->status = CONNECT_STAT_WORKING; - } + conn_impl->status = CONNECT_STAT_WAIT_ACK; + conn_impl->node->status = NODE_STAT_SHAKING; break; case CONNECT_MESG_HANDSHAKE_RESPONSE: hmdfs_info( @@ -665,45 +646,41 @@ void connection_handshake_recv_handler(struct connection *conn_impl, void *buf, goto out; } - if (conn_impl->node->version >= DFS_2_0) { - ret = hs_proc_msg_data(conn_impl, ops, data, data_len); - if (ret) - goto nego_err; - connection_send_handshake(conn_impl, - CONNECT_MESG_HANDSHAKE_ACK, - head->msg_id); - hmdfs_info("respon rcv handle,conn_impl->crypto=0x%0x", - conn_impl->crypto); + ret = hs_proc_msg_data(conn_impl, ops, data, data_len); + if (ret) + goto nego_err; + connection_send_handshake(conn_impl, + CONNECT_MESG_HANDSHAKE_ACK, + head->msg_id); + hmdfs_info("respon rcv handle,conn_impl->crypto=0x%0x", + conn_impl->crypto); #ifdef CONFIG_HMDFS_FS_ENCRYPTION - ret = connection_handshake_init_tls(conn_impl, ops); - if (ret) { - hmdfs_err("init_tls_key fail, ops %u", ops); - goto out; - } -#endif + ret = connection_handshake_init_tls(conn_impl, ops); + if (ret) { + hmdfs_err("init_tls_key fail, ops %u", ops); + goto out; } +#endif conn_impl->status = CONNECT_STAT_WORKING; peer_online(conn_impl->node); break; case CONNECT_MESG_HANDSHAKE_ACK: - if (conn_impl->node->version >= DFS_2_0) { - ret = hs_proc_msg_data(conn_impl, ops, data, data_len); - if (ret) - goto nego_err; - hmdfs_info("ack rcv handle, conn_impl->crypto=0x%0x", - conn_impl->crypto); + ret = hs_proc_msg_data(conn_impl, ops, data, data_len); + if (ret) + goto nego_err; + hmdfs_info("ack rcv handle, conn_impl->crypto=0x%0x", + conn_impl->crypto); #ifdef CONFIG_HMDFS_FS_ENCRYPTION - ret = connection_handshake_init_tls(conn_impl, ops); - if (ret) { - hmdfs_err("init_tls_key fail, ops %u", ops); - goto out; - } -#endif - conn_impl->status = CONNECT_STAT_WORKING; - peer_online(conn_impl->node); - break; + ret = connection_handshake_init_tls(conn_impl, ops); + if (ret) { + hmdfs_err("init_tls_key fail, ops %u", ops); + goto out; } +#endif + conn_impl->status = CONNECT_STAT_WORKING; + peer_online(conn_impl->node); + break; fallthrough; default: break; @@ -713,8 +690,7 @@ void connection_handshake_recv_handler(struct connection *conn_impl, void *buf, return; nego_err: conn_impl->status = CONNECT_STAT_NEGO_FAIL; - connection_handshake_notify(conn_impl->node, - NOTIFY_OFFLINE); + connection_handshake_notify(conn_impl->node, NOTIFY_OFFLINE); hmdfs_err("protocol negotiation failed, remote device_id = %llu, tcp->fd = %d", conn_impl->node->device_id, fd); goto out; @@ -750,10 +726,9 @@ static void update_tls_crypto_key(struct connection *conn, static bool cmd_update_tls_crypto_key(struct connection *conn, struct hmdfs_head_cmd *head) { - __u8 version = conn->node->version; struct tcp_handle *tcp = conn->connect_handle; - if (version < DFS_2_0 || conn->type != CONNECT_TYPE_TCP || !tcp) + if (conn->type != CONNECT_TYPE_TCP || !tcp) return false; return head->operations.command == F_CONNECT_REKEY; } @@ -768,7 +743,7 @@ void connection_working_recv_handler(struct connection *conn_impl, void *buf, return; } #endif - conn_impl->node->conn_operations->recvmsg(conn_impl->node, buf, data); + hmdfs_recv_mesg_callback(conn_impl->node, buf, data); } static void connection_release(struct kref *ref) @@ -1093,7 +1068,7 @@ static struct hmdfs_peer *add_peer_unsafe(struct hmdfs_sb_info *sbi, } static struct hmdfs_peer *alloc_peer(struct hmdfs_sb_info *sbi, uint8_t *cid, - const struct connection_operations *conn_operations, uint32_t devsl) + uint32_t devsl) { struct hmdfs_peer *node = kzalloc(sizeof(*node), GFP_KERNEL); @@ -1149,8 +1124,8 @@ static struct hmdfs_peer *alloc_peer(struct hmdfs_sb_info *sbi, uint8_t *cid, INIT_LIST_HEAD(&node->list); kref_init(&node->ref_cnt); node->owner = sbi->seq; - node->conn_operations = conn_operations; node->sbi = sbi; + node->version = HMDFS_VERSION; node->status = NODE_STAT_SHAKING; node->conn_time = jiffies; memcpy(node->cid, cid, HMDFS_CID_SIZE); @@ -1210,7 +1185,6 @@ struct hmdfs_peer *hmdfs_get_peer(struct hmdfs_sb_info *sbi, uint8_t *cid, uint32_t devsl) { struct hmdfs_peer *peer = NULL, *on_sbi_peer = NULL; - const struct connection_operations *conn_opr_ptr = NULL; mutex_lock(&sbi->connections.node_lock); peer = lookup_peer_by_cid_unsafe(sbi, cid); @@ -1221,12 +1195,7 @@ struct hmdfs_peer *hmdfs_get_peer(struct hmdfs_sb_info *sbi, uint8_t *cid, goto out; } - conn_opr_ptr = hmdfs_get_peer_operation(DFS_2_0); - if (unlikely(!conn_opr_ptr)) { - hmdfs_info("Fatal! Cannot get peer operation"); - goto out; - } - peer = alloc_peer(sbi, cid, conn_opr_ptr, devsl); + peer = alloc_peer(sbi, cid, devsl); if (unlikely(!peer)) { hmdfs_info("Failed to alloc a peer"); goto out; @@ -1290,13 +1259,12 @@ int hmdfs_alloc_msg_idr(struct hmdfs_peer *peer, enum MSG_IDR_TYPE type, { int ret = -EAGAIN; struct hmdfs_msg_idr_head *head = ptr; - int end = peer->version < DFS_2_0 ? (USHRT_MAX + 1) : 0; idr_preload(GFP_KERNEL); spin_lock(&peer->idr_lock); if (!peer->offline_start) ret = idr_alloc_cyclic(&peer->msg_idr, ptr, - 1, end, GFP_NOWAIT); + 1, 0, GFP_NOWAIT); if (ret >= 0) { kref_init(&head->ref); head->msg_id = ret; diff --git a/fs/hmdfs/comm/connection.h b/fs/hmdfs/comm/connection.h index 6137c549824c8972c19d8e898d0854b5178a0145..8178590d4e3d1aefe54423bfe406c03214d15763 100644 --- a/fs/hmdfs/comm/connection.h +++ b/fs/hmdfs/comm/connection.h @@ -169,7 +169,6 @@ struct hmdfs_peer { int recvbuf_maxsize; struct crypto_aead *tfm; char cid[HMDFS_CID_SIZE + 1]; - const struct connection_operations *conn_operations; struct hmdfs_sb_info *sbi; struct workqueue_struct *async_wq; struct workqueue_struct *req_handle_wq; diff --git a/fs/hmdfs/comm/crypto.c b/fs/hmdfs/comm/crypto.c index 33c4be338f741ec4c9bd7980a9fa4d99a2cfe23e..01d5d3febc20c9ba7a458f83a458b49dfc75fae8 100644 --- a/fs/hmdfs/comm/crypto.c +++ b/fs/hmdfs/comm/crypto.c @@ -59,7 +59,7 @@ int tls_crypto_info_init(struct connection *conn_impl) u8 key_meterial[HMDFS_KEY_SIZE]; struct tcp_handle *tcp = (struct tcp_handle *)(conn_impl->connect_handle); - if (conn_impl->node->version < DFS_2_0 || !tcp) + if (!tcp) return -EINVAL; // send update_key(conn_impl->send_key, key_meterial, HKDF_TYPE_IV); @@ -178,10 +178,9 @@ static int tls_set_rx(struct tcp_handle *tcp) int set_crypto_info(struct connection *conn_impl, int set_type) { int ret = 0; - __u8 version = conn_impl->node->version; struct tcp_handle *tcp = (struct tcp_handle *)(conn_impl->connect_handle); - if (version < DFS_2_0 || !tcp) + if (!tcp) return -EINVAL; if (set_type == SET_CRYPTO_SEND) { diff --git a/fs/hmdfs/comm/device_node.c b/fs/hmdfs/comm/device_node.c index d702e50275484e0ef58e153eb2ccb8c63b86809d..796e5cd09a728b4798953ee201df22d50d43a7f5 100644 --- a/fs/hmdfs/comm/device_node.c +++ b/fs/hmdfs/comm/device_node.c @@ -47,11 +47,11 @@ static void ctrl_cmd_update_socket_handler(const char *buf, size_t len, goto out; } memcpy(&cmd, buf, sizeof(cmd)); - if (cmd.status != CONNECT_STAT_WAIT_REQUEST && - cmd.status != CONNECT_STAT_WAIT_RESPONSE) { - hmdfs_err("invalid status"); - goto out; - } + if (cmd.status != CONNECT_STAT_WAIT_REQUEST && + cmd.status != CONNECT_STAT_WAIT_RESPONSE) { + hmdfs_err("invalid status"); + goto out; + } node = hmdfs_get_peer(sbi, cmd.cid, cmd.devsl); if (unlikely(!node)) { @@ -258,12 +258,12 @@ static ssize_t sbi_status_show(struct kobject *kobj, struct sbi_attribute *attr, struct tcp_handle *tcp = NULL; sbi = to_sbi(kobj); - size += sprintf(buf + size, "peers version status\n"); + size += sprintf(buf + size, "peers status\n"); mutex_lock(&sbi->connections.node_lock); list_for_each_entry(peer, &sbi->connections.node_list, list) { - size += sprintf(buf + size, "%llu %d %d\n", peer->device_id, - peer->version, peer->status); + size += sprintf(buf + size, "%llu %d\n", peer->device_id, + peer->status); // connection information size += sprintf( buf + size, diff --git a/fs/hmdfs/comm/message_verify.c b/fs/hmdfs/comm/message_verify.c index 0fd80c41629e10d7ce058d4dea1d9085dc28fcb9..fd1380e97e090e44e6cdc4d779eda2861a12b902 100644 --- a/fs/hmdfs/comm/message_verify.c +++ b/fs/hmdfs/comm/message_verify.c @@ -968,45 +968,41 @@ int hmdfs_message_verify(struct hmdfs_peer *con, struct hmdfs_head_cmd *head, goto handle_bad_msg; } - if (head->version != DFS_2_0) { - err = -EINVAL; + len = le32_to_cpu(head->data_len) - + sizeof(struct hmdfs_head_cmd); + min = message_length[flag][cmd][HMDFS_MESSAGE_MIN_INDEX]; + if (head->operations.command == F_ITERATE && flag == C_RESPONSE) + max = sizeof(struct slice_descriptor) + PAGE_SIZE; + else + max = message_length[flag][cmd][HMDFS_MESSAGE_MAX_INDEX]; + len_type = + message_length[flag][cmd][HMDFS_MESSAGE_LEN_JUDGE_INDEX]; + + if (len_type == MESSAGE_LEN_JUDGE_RANGE) { + if (len < min || len > max) { + hmdfs_err( + "cmd %d -> %d message verify fail, len = %zu", + cmd, flag, len); + err = -EINVAL; + goto handle_bad_msg; + } } else { - len = le32_to_cpu(head->data_len) - - sizeof(struct hmdfs_head_cmd); - min = message_length[flag][cmd][HMDFS_MESSAGE_MIN_INDEX]; - if (head->operations.command == F_ITERATE && flag == C_RESPONSE) - max = sizeof(struct slice_descriptor) + PAGE_SIZE; - else - max = message_length[flag][cmd][HMDFS_MESSAGE_MAX_INDEX]; - len_type = - message_length[flag][cmd][HMDFS_MESSAGE_LEN_JUDGE_INDEX]; - - if (len_type == MESSAGE_LEN_JUDGE_RANGE) { - if (len < min || len > max) { - hmdfs_err( - "cmd %d -> %d message verify fail, len = %zu", - cmd, flag, len); - err = -EINVAL; - goto handle_bad_msg; - } - } else { - if (len != min && len != max) { - hmdfs_err( - "cmd %d -> %d message verify fail, len = %zu", - cmd, flag, len); - err = -EINVAL; - goto handle_bad_msg; - } + if (len != min && len != max) { + hmdfs_err( + "cmd %d -> %d message verify fail, len = %zu", + cmd, flag, len); + err = -EINVAL; + goto handle_bad_msg; } + } - if (message_verify[cmd]) - err = message_verify[cmd](flag, len, data); + if (message_verify[cmd]) + err = message_verify[cmd](flag, len, data); - if (err) - goto handle_bad_msg; + if (err) + goto handle_bad_msg; - return err; - } + return err; handle_bad_msg: handle_bad_message(con, head, &err); diff --git a/fs/hmdfs/comm/node_cb.c b/fs/hmdfs/comm/node_cb.c index 21b84d2fff82af4217b88876aceb20605625c854..991ebde1d8cfe3b19d8de483f4e55f06ca43dbae 100644 --- a/fs/hmdfs/comm/node_cb.c +++ b/fs/hmdfs/comm/node_cb.c @@ -68,9 +68,6 @@ void hmdfs_node_call_evt_cb(struct hmdfs_peer *conn, int evt, bool sync, return; list_for_each_entry(desc, &cb_head[evt][sync], list) { - if (conn->version < desc->min_version) - continue; - desc->fn(conn, evt, seq); } } diff --git a/fs/hmdfs/comm/node_cb.h b/fs/hmdfs/comm/node_cb.h index fe53b946f66846909d9e328a6093b496c380e0cf..8bd6a4bbc08e4e2daab4cfe4f390478386772854 100644 --- a/fs/hmdfs/comm/node_cb.h +++ b/fs/hmdfs/comm/node_cb.h @@ -29,7 +29,6 @@ typedef void (*hmdfs_node_evt_cb)(struct hmdfs_peer *conn, struct hmdfs_node_cb_desc { int evt; bool sync; - unsigned char min_version; hmdfs_node_evt_cb fn; struct list_head list; }; diff --git a/fs/hmdfs/comm/protocol.h b/fs/hmdfs/comm/protocol.h index c63dd116253d5a025bbb6bf5e6a0faa10cb720f6..e140963989de9a4ff9da15c3dbc3d387413ae5fb 100644 --- a/fs/hmdfs/comm/protocol.h +++ b/fs/hmdfs/comm/protocol.h @@ -144,17 +144,10 @@ struct slice_descriptor { } __packed; enum DFS_VERSION { - INVALID_VERSION = 0, - DFS_1_0, - - USERSPACE_MAX_VER = 0x3F, - DFS_2_0, - + HMDFS_VERSION = 0x40, MAX_VERSION = 0xFF }; -enum CONN_OPERATIONS_VERSION { USERDFS_VERSION, PROTOCOL_VERSION }; - enum CMD_FLAG { C_REQUEST = 0, C_RESPONSE = 1, C_FLAG_SIZE }; enum FILE_CMD { diff --git a/fs/hmdfs/comm/socket_adapter.c b/fs/hmdfs/comm/socket_adapter.c index 944e9c12e5560cb24a6d9bc5b81a24e7d2aff2c0..e6b340b4ee72ac35592f8a67e323696218b8b312 100644 --- a/fs/hmdfs/comm/socket_adapter.c +++ b/fs/hmdfs/comm/socket_adapter.c @@ -191,12 +191,10 @@ int hmdfs_sendmessage(struct hmdfs_peer *node, struct hmdfs_send_data *msg) if (!ret) statistic_con_sb_dirty(node, &head->operations); out: - if (node->version == DFS_2_0 && - head->operations.cmd_flag == C_REQUEST) + if (head->operations.cmd_flag == C_REQUEST) hmdfs_client_snd_statis(node->sbi, head->operations.command, ret); - else if (node->version == DFS_2_0 && - head->operations.cmd_flag == C_RESPONSE) + else if (head->operations.cmd_flag == C_RESPONSE) hmdfs_server_snd_statis(node->sbi, head->operations.command, ret); out_err: @@ -212,7 +210,7 @@ int hmdfs_sendmessage_response(struct hmdfs_peer *con, struct hmdfs_head_cmd head; head.magic = HMDFS_MSG_MAGIC; - head.version = DFS_2_0; + head.version = HMDFS_VERSION; head.operations = cmd->operations; head.operations.cmd_flag = C_RESPONSE; head.data_len = cpu_to_le32(data_len + sizeof(struct hmdfs_head_cmd)); @@ -335,7 +333,7 @@ int hmdfs_send_async_request(struct hmdfs_peer *peer, if (IS_ERR(mp)) return PTR_ERR(mp); head.magic = HMDFS_MSG_MAGIC; - head.version = DFS_2_0; + head.version = HMDFS_VERSION; head.data_len = cpu_to_le32(msg_len); head.operations = mp->req.operations; head.msg_id = cpu_to_le32(mp->head.msg_id); @@ -427,7 +425,7 @@ int hmdfs_sendmessage_request(struct hmdfs_peer *con, sm->out_buf = NULL; head->magic = HMDFS_MSG_MAGIC; - head->version = DFS_2_0; + head->version = HMDFS_VERSION; head->operations = sm->operations; head->data_len = cpu_to_le32(outlen); head->ret_code = cpu_to_le32(sm->ret_code); @@ -526,7 +524,7 @@ static int hmdfs_send_slice(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, sizeof(struct slice_descriptor); head.magic = HMDFS_MSG_MAGIC; - head.version = DFS_2_0; + head.version = HMDFS_VERSION; head.operations = cmd->operations; head.operations.cmd_flag = C_RESPONSE; head.data_len = cpu_to_le32(msg_len); @@ -621,9 +619,8 @@ void hmdfs_recv_page_work_fn(struct work_struct *ptr) struct hmdfs_async_work *async_work = container_of(ptr, struct hmdfs_async_work, d_work.work); - if (async_work->head.peer->version >= DFS_2_0) - hmdfs_client_resp_statis(async_work->head.peer->sbi, - F_READPAGE, HMDFS_RESP_TIMEOUT, 0, 0); + hmdfs_client_resp_statis(async_work->head.peer->sbi, + F_READPAGE, HMDFS_RESP_TIMEOUT, 0, 0); hmdfs_err_ratelimited("timeout and release page, msg_id:%u", async_work->head.msg_id); asw_done(async_work); @@ -657,7 +654,7 @@ int hmdfs_sendpage_request(struct hmdfs_peer *con, memset(&head, 0, sizeof(head)); head.magic = HMDFS_MSG_MAGIC; - head.version = DFS_2_0; + head.version = HMDFS_VERSION; head.operations = sm->operations; head.data_len = cpu_to_le32(outlen); head.ret_code = cpu_to_le32(sm->ret_code); @@ -1063,7 +1060,7 @@ static int hmdfs_response_recv(struct hmdfs_peer *con, } } -static void hmdfs_recv_mesg_callback(struct hmdfs_peer *con, void *head, +void hmdfs_recv_mesg_callback(struct hmdfs_peer *con, void *head, void *buf) { struct hmdfs_head_cmd *hmdfs_head = (struct hmdfs_head_cmd *)head; @@ -1097,43 +1094,6 @@ static void hmdfs_recv_mesg_callback(struct hmdfs_peer *con, void *head, kfree(buf); } -static inline void hmdfs_recv_page_callback(struct hmdfs_peer *con, - struct hmdfs_head_cmd *head, - int err, void *data) -{ - if (head->operations.command == F_READPAGE) - hmdfs_client_recv_readpage(head, err, data); -} - -static const struct connection_operations conn_operations[] = { - [PROTOCOL_VERSION] = { - .recvmsg = hmdfs_recv_mesg_callback, - .recvpage = hmdfs_recv_page_callback, - /* remote device operations */ - .remote_file_fops = - &hmdfs_dev_file_fops_remote, - .remote_file_iops = - &hmdfs_dev_file_iops_remote, - .remote_file_aops = - &hmdfs_dev_file_aops_remote, - .remote_unlink = - hmdfs_dev_unlink_from_con, - .remote_readdir = - hmdfs_dev_readdir_from_con, - } -}; - -const struct connection_operations *hmdfs_get_peer_operation(__u8 version) -{ - if (version <= INVALID_VERSION || version >= MAX_VERSION) - return NULL; - - if (version <= USERSPACE_MAX_VER) - return &(conn_operations[USERDFS_VERSION]); - else - return &(conn_operations[PROTOCOL_VERSION]); -} - void hmdfs_wakeup_parasite(struct hmdfs_msg_parasite *mp) { hmdfs_wait_mp_wfired(mp); diff --git a/fs/hmdfs/comm/socket_adapter.h b/fs/hmdfs/comm/socket_adapter.h index ba4c672d7bcc998fd99b7ce9974003007fd1f49b..35275ccac2a6aab6773d0941fe8031dc9802f5c2 100644 --- a/fs/hmdfs/comm/socket_adapter.h +++ b/fs/hmdfs/comm/socket_adapter.h @@ -23,21 +23,6 @@ #define HMDFS_IDR_RESCHED_COUNT 512 -struct connection_operations { - void (*recvmsg)(struct hmdfs_peer *con, void *head, void *buf); - void (*recvpage)(struct hmdfs_peer *con, struct hmdfs_head_cmd *head, - int err, void *data); - const struct file_operations *remote_file_fops; - const struct inode_operations *remote_file_iops; - const struct address_space_operations *remote_file_aops; - int (*remote_unlink)(struct hmdfs_peer *con, struct dentry *dentry); - int (*remote_readdir)(struct hmdfs_peer *con, struct file *file, - struct dir_context *ctx); - struct hmdfs_lookup_ret *(*remote_lookup)(struct hmdfs_peer *con, - const char *relative_path, - const char *d_name); -}; - /***************************************************************************** * connections(TCP, UDP, .etc) adapter for RPC *****************************************************************************/ @@ -75,7 +60,6 @@ int hmdfs_sendmessage_response(struct hmdfs_peer *con, void *buf, __u32 ret_code); int hmdfs_readfile_response(struct hmdfs_peer *con, struct hmdfs_head_cmd *head, struct file *filp); -const struct connection_operations *hmdfs_get_peer_operation(__u8 version); void hmdfs_recv_page_work_fn(struct work_struct *ptr); @@ -168,6 +152,8 @@ static inline void set_cmd_timeout(struct hmdfs_sb_info *sbi, enum FILE_CMD cmd, sbi->s_cmd_timeout[cmd] = value; } +void hmdfs_recv_mesg_callback(struct hmdfs_peer *con, void *head, void *buf); + void hmdfs_response_wakeup(struct sendmsg_wait_queue *msg_info, __u32 ret_code, __u32 data_len, void *buf); diff --git a/fs/hmdfs/comm/transport.c b/fs/hmdfs/comm/transport.c index 75fb9797857e284283ad4a9cadc4e43a0a2c52ee..9f65f618a746d009378a757c1a2356e70e414761 100644 --- a/fs/hmdfs/comm/transport.c +++ b/fs/hmdfs/comm/transport.c @@ -250,7 +250,7 @@ static int tcp_recvpage_tls(struct connection *connect, if (ret) rd_err = ret; } - node->conn_operations->recvpage(node, recv, rd_err, async_work); + hmdfs_client_recv_readpage(recv, rd_err, async_work); asw_put(async_work); return ret; @@ -519,7 +519,7 @@ static int tcp_receive_from_sock(struct tcp_handle *tcp) tcp->connect->stat.recv_bytes += sizeof(struct hmdfs_head_cmd); tcp->connect->stat.recv_message_count++; - if (recv->magic != HMDFS_MSG_MAGIC) { + if (recv->magic != HMDFS_MSG_MAGIC || recv->version != HMDFS_VERSION) { hmdfs_info_ratelimited("tcp recv fd %d wrong magic. drop message", tcp->fd); goto out; @@ -533,16 +533,14 @@ static int tcp_receive_from_sock(struct tcp_handle *tcp) goto out; } - if (recv->version > USERSPACE_MAX_VER && - tcp->connect->status == CONNECT_STAT_WORKING && + if (tcp->connect->status == CONNECT_STAT_WORKING && recv->operations.command == F_READPAGE && recv->operations.cmd_flag == C_RESPONSE) { ret = tcp_recvpage_tls(tcp->connect, recv); goto out; } - if (tcp->connect->status == CONNECT_STAT_WORKING && - recv->version > USERSPACE_MAX_VER) + if (tcp->connect->status == CONNECT_STAT_WORKING) ret = tcp_recvbuffer_tls(tcp->connect, recv); else ret = tcp_recvbuffer_cipher(tcp->connect, recv); @@ -773,7 +771,7 @@ int tcp_send_rekey_request(struct connection *connect) rekey_request_param->update_request = cpu_to_le32(UPDATE_NOT_REQUESTED); head->magic = HMDFS_MSG_MAGIC; - head->version = DFS_2_0; + head->version = HMDFS_VERSION; head->operations = operations; head->data_len = cpu_to_le32(sizeof(*head) + sizeof(*rekey_request_param)); @@ -822,11 +820,9 @@ static int tcp_send_message(struct connection *connect, trace_hmdfs_tcp_send_message(msg->head); - if (connect->status == CONNECT_STAT_WORKING && - connect->node->version > USERSPACE_MAX_VER) + if (connect->status == CONNECT_STAT_WORKING) ret = tcp_send_message_sock_tls(tcp, msg); else - // Handshake status or version HMDFS1.0 ret = tcp_send_message_sock_cipher(tcp, msg); if (ret != 0) { @@ -835,8 +831,7 @@ static int tcp_send_message(struct connection *connect, } #ifdef CONFIG_HMDFS_FS_ENCRYPTION if (nowtime - connect->stat.rekey_time >= REKEY_LIFETIME && - connect->status == CONNECT_STAT_WORKING && - connect->node->version >= DFS_2_0) { + connect->status == CONNECT_STAT_WORKING) { hmdfs_info("send rekey message to devid %llu", connect->node->device_id); ret = tcp_send_rekey_request(connect); diff --git a/fs/hmdfs/file_remote.c b/fs/hmdfs/file_remote.c index aac6f508e18b6c826abd1a06fa7e3ec6f49f4232..137161d22daa36178c12cd830528c5ecdd63427a 100644 --- a/fs/hmdfs/file_remote.c +++ b/fs/hmdfs/file_remote.c @@ -994,7 +994,7 @@ static int hmdfs_iterate_remote(struct file *file, struct dir_context *ctx) con = hmdfs_lookup_from_devid(file->f_inode->i_sb->s_fs_info, dev_id); if (con) { // ctx->pos = 0; - err = con->conn_operations->remote_readdir(con, file, ctx); + err = hmdfs_dev_readdir_from_con(con, file, ctx); if (unlikely(!con)) { hmdfs_err("con is null"); goto done; @@ -1018,9 +1018,7 @@ int hmdfs_dir_open_remote(struct inode *inode, struct file *file) struct hmdfs_inode_info *info = hmdfs_i(inode); struct clearcache_item *cache_item = NULL; - if (info->conn && info->conn->version <= USERSPACE_MAX_VER) { - return 0; - } else if (info->conn) { + if (info->conn) { if (!hmdfs_cache_revalidate(READ_ONCE(info->conn->conn_time), info->conn->device_id, file->f_path.dentry)) diff --git a/fs/hmdfs/hmdfs_client.c b/fs/hmdfs/hmdfs_client.c index 02f33b93dd04c550406a4a1c99c13c517613b7a3..fa8e7435c1efe38d6de68695b3b16c75f6ef023e 100644 --- a/fs/hmdfs/hmdfs_client.c +++ b/fs/hmdfs/hmdfs_client.c @@ -1087,7 +1087,6 @@ static struct hmdfs_node_cb_desc client_cb[] = { { .evt = NODE_EVT_OFFLINE, .sync = true, - .min_version = DFS_1_0, .fn = hmdfs_client_offline_notify, }, }; diff --git a/fs/hmdfs/hmdfs_server.c b/fs/hmdfs/hmdfs_server.c index d2dec5c95ccb9abd85bc0685e419cbcee81200b7..b74ae87b9bf69c190c1673d105a88b3e1ab875c1 100644 --- a/fs/hmdfs/hmdfs_server.c +++ b/fs/hmdfs/hmdfs_server.c @@ -180,7 +180,6 @@ static struct hmdfs_node_cb_desc server_cb[] = { { .evt = NODE_EVT_OFFLINE, .sync = true, - .min_version = DFS_2_0, .fn = hmdfs_server_offline_notify }, }; diff --git a/fs/hmdfs/inode_remote.c b/fs/hmdfs/inode_remote.c index fb227d41abb6700bf0f9ba23ed75b4ac1d3c3388..70cee5d95c9b2f3e13faddc2ee73c462bef12429 100644 --- a/fs/hmdfs/inode_remote.c +++ b/fs/hmdfs/inode_remote.c @@ -175,48 +175,40 @@ struct hmdfs_lookup_ret *hmdfs_lookup_by_con(struct hmdfs_peer *con, { struct hmdfs_lookup_ret *result = NULL; - if (con->version > USERSPACE_MAX_VER) { + /* + * LOOKUP_REVAL means we found stale info from dentry file, thus + * we need to use remote getattr. + */ + if (flags & LOOKUP_REVAL) { /* - * LOOKUP_REVAL means we found stale info from dentry file, thus - * we need to use remote getattr. - */ - if (flags & LOOKUP_REVAL) { - /* - * HMDFS_LOOKUP_REVAL means we need to skip dentry cache - * in lookup, because dentry cache in server might have - * stale data. - */ - result = get_remote_inode_info(con, dentry, - HMDFS_LOOKUP_REVAL); - get_remote_dentry_file_in_wq(dentry->d_parent, con); - return result; - } - - /* If cache file is still valid */ - if (hmdfs_cache_revalidate(READ_ONCE(con->conn_time), - con->device_id, dentry->d_parent)) { - result = lookup_remote_dentry(dentry, qstr, - con->device_id); - /* - * If lookup from cache file failed, use getattr to see - * if remote have created the file. - */ - if (!(flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) && - !result) - result = get_remote_inode_info(con, dentry, 0); - /* If cache file expired, use getattr directly - * except create and rename opt - */ - } else { + * HMDFS_LOOKUP_REVAL means we need to skip dentry cache + * in lookup, because dentry cache in server might have + * stale data. + */ + result = get_remote_inode_info(con, dentry, + HMDFS_LOOKUP_REVAL); + get_remote_dentry_file_in_wq(dentry->d_parent, con); + return result; + } + + /* If cache file is still valid */ + if (hmdfs_cache_revalidate(READ_ONCE(con->conn_time), + con->device_id, dentry->d_parent)) { + result = lookup_remote_dentry(dentry, qstr, + con->device_id); + /* + * If lookup from cache file failed, use getattr to see + * if remote have created the file. + */ + if (!(flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) && + !result) result = get_remote_inode_info(con, dentry, 0); - get_remote_dentry_file_in_wq(dentry->d_parent, con); - } + /* If cache file expired, use getattr directly + * except create and rename opt + */ } else { - if (!relative_path) - return NULL; - - result = con->conn_operations->remote_lookup( - con, relative_path, dentry->d_name.name); + result = get_remote_inode_info(con, dentry, 0); + get_remote_dentry_file_in_wq(dentry->d_parent, con); } return result; @@ -352,17 +344,16 @@ struct inode *fill_inode_remote(struct super_block *sb, struct hmdfs_peer *con, info = hmdfs_i(inode); info->inode_type = HMDFS_LAYER_OTHER_REMOTE; - if (con->version > USERSPACE_MAX_VER) { - /* the inode was found in cache */ - if (!(inode->i_state & I_NEW)) { - hmdfs_fill_inode_remote(inode, dir, mode); - hmdfs_update_inode(inode, res); - return inode; - } - hmdfs_remote_init_stash_status(con, inode, mode); + /* the inode was found in cache */ + if (!(inode->i_state & I_NEW)) { + hmdfs_fill_inode_remote(inode, dir, mode); + hmdfs_update_inode(inode, res); + return inode; } + hmdfs_remote_init_stash_status(con, inode, mode); + inode->i_ctime.tv_sec = 0; inode->i_ctime.tv_nsec = 0; inode->i_mtime.tv_sec = res->i_mtime; @@ -383,8 +374,8 @@ struct inode *fill_inode_remote(struct super_block *sb, struct hmdfs_peer *con, } if (S_ISREG(mode) || S_ISLNK(mode)) { - inode->i_op = con->conn_operations->remote_file_iops; - inode->i_fop = con->conn_operations->remote_file_fops; + inode->i_op = &hmdfs_dev_file_iops_remote; + inode->i_fop = &hmdfs_dev_file_fops_remote; inode->i_size = res->i_size; set_nlink(inode, 1); } else if (S_ISDIR(mode)) { @@ -396,7 +387,7 @@ struct inode *fill_inode_remote(struct super_block *sb, struct hmdfs_peer *con, goto bad_inode; } - inode->i_mapping->a_ops = con->conn_operations->remote_file_aops; + inode->i_mapping->a_ops = &hmdfs_dev_file_aops_remote; hmdfs_fill_inode_remote(inode, dir, mode); unlock_new_inode(inode); @@ -590,10 +581,7 @@ int hmdfs_mkdir_remote(struct inode *dir, struct dentry *dentry, umode_t mode) hmdfs_warning("qpb_debug: con is null!"); goto out; } - if (con->version <= USERSPACE_MAX_VER) { - err = -EPERM; - goto out; - } + err = hmdfs_mkdir_remote_dentry(con, dentry, mode); if (!err) create_in_cache_file(con->device_id, dentry); @@ -664,10 +652,7 @@ int hmdfs_create_remote(struct inode *dir, struct dentry *dentry, umode_t mode, hmdfs_warning("qpb_debug: con is null!"); goto out; } - if (con->version <= USERSPACE_MAX_VER) { - err = -EPERM; - goto out; - } + err = hmdfs_create_remote_dentry(con, dentry, mode, want_excl); if (!err) create_in_cache_file(con->device_id, dentry); @@ -713,10 +698,7 @@ int hmdfs_rmdir_remote(struct inode *dir, struct dentry *dentry) err = -EACCES; goto out; } - if (con->version <= USERSPACE_MAX_VER) { - err = -EPERM; - goto out; - } + err = hmdfs_rmdir_remote_dentry(con, dentry); /* drop dentry even remote failed * it maybe cause that one remote devices disconnect @@ -765,7 +747,7 @@ int hmdfs_unlink_remote(struct inode *dir, struct dentry *dentry) if (conn->status != NODE_STAT_ONLINE) return 0; - return conn->conn_operations->remote_unlink(conn, dentry); + return hmdfs_dev_unlink_from_con(conn, dentry); } /* rename dentry in cache file */ @@ -835,20 +817,17 @@ int hmdfs_rename_remote(struct inode *old_dir, struct dentry *old_dentry, goto rename_out; } if (S_ISREG(old_dentry->d_inode->i_mode)) { - if (con->version > USERSPACE_MAX_VER) { - hmdfs_debug("send MSG to remote devID %llu", - con->device_id); - err = hmdfs_client_start_rename( - con, relative_old_dir_path, old_dentry_d_name, - relative_new_dir_path, new_dentry_d_name, - flags); - if (!err) - rename_in_cache_file(con->device_id, old_dentry, - new_dentry); - } + hmdfs_debug("send MSG to remote devID %llu", + con->device_id); + err = hmdfs_client_start_rename( + con, relative_old_dir_path, old_dentry_d_name, + relative_new_dir_path, new_dentry_d_name, + flags); + if (!err) + rename_in_cache_file(con->device_id, old_dentry, + new_dentry); } else if (S_ISDIR(old_dentry->d_inode->i_mode)) { - if ((con->status == NODE_STAT_ONLINE) && - (con->version > USERSPACE_MAX_VER)) { + if ((con->status == NODE_STAT_ONLINE)) { ret = hmdfs_client_start_rename( con, relative_old_dir_path, old_dentry_d_name, relative_new_dir_path, new_dentry_d_name, diff --git a/fs/hmdfs/main.c b/fs/hmdfs/main.c index 179ddfa7821824e0f9ce5bacc93976f603ce7321..da282cc28106a1577c635ccb6127a22764ae82c8 100644 --- a/fs/hmdfs/main.c +++ b/fs/hmdfs/main.c @@ -328,8 +328,7 @@ static int hmdfs_remote_statfs(struct dentry *dentry, struct kstatfs *buf) } mutex_lock(&sbi->connections.node_lock); list_for_each_entry(con, &sbi->connections.node_list, list) { - if (con->status == NODE_STAT_ONLINE && - con->version > USERSPACE_MAX_VER) { + if (con->status == NODE_STAT_ONLINE) { peer_get(con); mutex_unlock(&sbi->connections.node_lock); hmdfs_debug("send MSG to remote devID %llu", @@ -843,8 +842,8 @@ static int hmdfs_fill_super(struct super_block *sb, void *data, int silent) char ctrl_path[CTRL_PATH_MAX_LEN]; uint64_t ctrl_hash; - if (!raw_data) - return -EINVAL; + if (!raw_data) + return -EINVAL; sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi) { diff --git a/fs/hmdfs/stash.c b/fs/hmdfs/stash.c index c320af7f60e0d42372c39a74709e1cdff7f36c74..dd696201b8226c4cf8e253f4aa501928ff8a9c8b 100644 --- a/fs/hmdfs/stash.c +++ b/fs/hmdfs/stash.c @@ -2205,16 +2205,13 @@ static struct hmdfs_node_cb_desc stash_cb[] = { { .evt = NODE_EVT_OFFLINE, .sync = true, - .min_version = DFS_2_0, .fn = hmdfs_stash_offline_prepare, }, { .evt = NODE_EVT_OFFLINE, .sync = false, - .min_version = DFS_2_0, .fn = hmdfs_stash_offline_do_stash, }, - /* Don't known peer version yet, so min_version is 0 */ { .evt = NODE_EVT_ADD, .sync = true, @@ -2223,19 +2220,16 @@ static struct hmdfs_node_cb_desc stash_cb[] = { { .evt = NODE_EVT_ONLINE, .sync = false, - .min_version = DFS_2_0, .fn = hmdfs_stash_online_prepare, }, { .evt = NODE_EVT_ONLINE, .sync = false, - .min_version = DFS_2_0, .fn = hmdfs_stash_online_do_restore, }, { .evt = NODE_EVT_DEL, .sync = true, - .min_version = DFS_2_0, .fn = hmdfs_stash_del_do_cleanup, }, };