| 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org> |
| 4 | * Copyright (C) 2018 Samsung Electronics Co., Ltd. |
| 5 | */ |
| 6 | |
| 7 | #include "glob.h" |
| 8 | #include "oplock.h" |
| 9 | #include "misc.h" |
| 10 | #include <linux/sched/signal.h> |
| 11 | #include <linux/workqueue.h> |
| 12 | #include <linux/sysfs.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | |
| 16 | #include "server.h" |
| 17 | #include "smb_common.h" |
| 18 | #include "../common/smb2status.h" |
| 19 | #include "connection.h" |
| 20 | #include "transport_ipc.h" |
| 21 | #include "mgmt/user_session.h" |
| 22 | #include "crypto_ctx.h" |
| 23 | #include "auth.h" |
| 24 | |
| 25 | int ksmbd_debug_types; |
| 26 | |
| 27 | struct ksmbd_server_config server_conf; |
| 28 | |
| 29 | enum SERVER_CTRL_TYPE { |
| 30 | SERVER_CTRL_TYPE_INIT, |
| 31 | SERVER_CTRL_TYPE_RESET, |
| 32 | }; |
| 33 | |
| 34 | struct server_ctrl_struct { |
| 35 | int type; |
| 36 | struct work_struct ctrl_work; |
| 37 | }; |
| 38 | |
| 39 | static DEFINE_MUTEX(ctrl_lock); |
| 40 | |
| 41 | static int ___server_conf_set(int idx, char *val) |
| 42 | { |
| 43 | if (idx >= ARRAY_SIZE(server_conf.conf)) |
| 44 | return -EINVAL; |
| 45 | |
| 46 | if (!val || val[0] == 0x00) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | kfree(objp: server_conf.conf[idx]); |
| 50 | server_conf.conf[idx] = kstrdup(s: val, KSMBD_DEFAULT_GFP); |
| 51 | if (!server_conf.conf[idx]) |
| 52 | return -ENOMEM; |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int ksmbd_set_netbios_name(char *v) |
| 57 | { |
| 58 | return ___server_conf_set(idx: SERVER_CONF_NETBIOS_NAME, val: v); |
| 59 | } |
| 60 | |
| 61 | int ksmbd_set_server_string(char *v) |
| 62 | { |
| 63 | return ___server_conf_set(idx: SERVER_CONF_SERVER_STRING, val: v); |
| 64 | } |
| 65 | |
| 66 | int ksmbd_set_work_group(char *v) |
| 67 | { |
| 68 | return ___server_conf_set(idx: SERVER_CONF_WORK_GROUP, val: v); |
| 69 | } |
| 70 | |
| 71 | char *ksmbd_netbios_name(void) |
| 72 | { |
| 73 | return server_conf.conf[SERVER_CONF_NETBIOS_NAME]; |
| 74 | } |
| 75 | |
| 76 | char *ksmbd_server_string(void) |
| 77 | { |
| 78 | return server_conf.conf[SERVER_CONF_SERVER_STRING]; |
| 79 | } |
| 80 | |
| 81 | char *ksmbd_work_group(void) |
| 82 | { |
| 83 | return server_conf.conf[SERVER_CONF_WORK_GROUP]; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * check_conn_state() - check state of server thread connection |
| 88 | * @work: smb work containing server thread information |
| 89 | * |
| 90 | * Return: 0 on valid connection, otherwise 1 to reconnect |
| 91 | */ |
| 92 | static inline int check_conn_state(struct ksmbd_work *work) |
| 93 | { |
| 94 | struct smb_hdr *rsp_hdr; |
| 95 | |
| 96 | if (ksmbd_conn_exiting(conn: work->conn) || |
| 97 | ksmbd_conn_need_reconnect(conn: work->conn)) { |
| 98 | rsp_hdr = smb_get_msg(buf: work->response_buf); |
| 99 | rsp_hdr->Status.CifsError = STATUS_CONNECTION_DISCONNECTED; |
| 100 | return 1; |
| 101 | } |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | #define SERVER_HANDLER_CONTINUE 0 |
| 106 | #define SERVER_HANDLER_ABORT 1 |
| 107 | |
| 108 | static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn, |
| 109 | u16 *cmd) |
| 110 | { |
| 111 | struct smb_version_cmds *cmds; |
| 112 | u16 command; |
| 113 | int ret; |
| 114 | |
| 115 | if (check_conn_state(work)) |
| 116 | return SERVER_HANDLER_CONTINUE; |
| 117 | |
| 118 | if (ksmbd_verify_smb_message(work)) { |
| 119 | conn->ops->set_rsp_status(work, STATUS_INVALID_PARAMETER); |
| 120 | return SERVER_HANDLER_ABORT; |
| 121 | } |
| 122 | |
| 123 | command = conn->ops->get_cmd_val(work); |
| 124 | *cmd = command; |
| 125 | |
| 126 | andx_again: |
| 127 | if (command >= conn->max_cmds) { |
| 128 | conn->ops->set_rsp_status(work, STATUS_INVALID_PARAMETER); |
| 129 | return SERVER_HANDLER_CONTINUE; |
| 130 | } |
| 131 | |
| 132 | cmds = &conn->cmds[command]; |
| 133 | if (!cmds->proc) { |
| 134 | ksmbd_debug(SMB, "*** not implemented yet cmd = %x\n" , command); |
| 135 | conn->ops->set_rsp_status(work, STATUS_NOT_IMPLEMENTED); |
| 136 | return SERVER_HANDLER_CONTINUE; |
| 137 | } |
| 138 | |
| 139 | if (work->sess && conn->ops->is_sign_req(work, command)) { |
| 140 | ret = conn->ops->check_sign_req(work); |
| 141 | if (!ret) { |
| 142 | conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED); |
| 143 | return SERVER_HANDLER_CONTINUE; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | ret = cmds->proc(work); |
| 148 | |
| 149 | if (ret < 0) |
| 150 | ksmbd_debug(CONN, "Failed to process %u [%d]\n" , command, ret); |
| 151 | /* AndX commands - chained request can return positive values */ |
| 152 | else if (ret > 0) { |
| 153 | command = ret; |
| 154 | *cmd = command; |
| 155 | goto andx_again; |
| 156 | } |
| 157 | |
| 158 | if (work->send_no_response) |
| 159 | return SERVER_HANDLER_ABORT; |
| 160 | return SERVER_HANDLER_CONTINUE; |
| 161 | } |
| 162 | |
| 163 | static void __handle_ksmbd_work(struct ksmbd_work *work, |
| 164 | struct ksmbd_conn *conn) |
| 165 | { |
| 166 | u16 command = 0; |
| 167 | int rc; |
| 168 | bool is_chained = false; |
| 169 | |
| 170 | if (conn->ops->is_transform_hdr && |
| 171 | conn->ops->is_transform_hdr(work->request_buf)) { |
| 172 | rc = conn->ops->decrypt_req(work); |
| 173 | if (rc < 0) |
| 174 | return; |
| 175 | work->encrypted = true; |
| 176 | } |
| 177 | |
| 178 | if (conn->ops->allocate_rsp_buf(work)) |
| 179 | return; |
| 180 | |
| 181 | rc = conn->ops->init_rsp_hdr(work); |
| 182 | if (rc) { |
| 183 | /* either uid or tid is not correct */ |
| 184 | conn->ops->set_rsp_status(work, STATUS_INVALID_HANDLE); |
| 185 | goto send; |
| 186 | } |
| 187 | |
| 188 | do { |
| 189 | if (conn->ops->check_user_session) { |
| 190 | rc = conn->ops->check_user_session(work); |
| 191 | if (rc < 0) { |
| 192 | if (rc == -EINVAL) |
| 193 | conn->ops->set_rsp_status(work, |
| 194 | STATUS_INVALID_PARAMETER); |
| 195 | else |
| 196 | conn->ops->set_rsp_status(work, |
| 197 | STATUS_USER_SESSION_DELETED); |
| 198 | goto send; |
| 199 | } else if (rc > 0) { |
| 200 | rc = conn->ops->get_ksmbd_tcon(work); |
| 201 | if (rc < 0) { |
| 202 | if (rc == -EINVAL) |
| 203 | conn->ops->set_rsp_status(work, |
| 204 | STATUS_INVALID_PARAMETER); |
| 205 | else |
| 206 | conn->ops->set_rsp_status(work, |
| 207 | STATUS_NETWORK_NAME_DELETED); |
| 208 | goto send; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | rc = __process_request(work, conn, cmd: &command); |
| 214 | if (rc == SERVER_HANDLER_ABORT) |
| 215 | break; |
| 216 | |
| 217 | /* |
| 218 | * Call smb2_set_rsp_credits() function to set number of credits |
| 219 | * granted in hdr of smb2 response. |
| 220 | */ |
| 221 | if (conn->ops->set_rsp_credits) { |
| 222 | spin_lock(lock: &conn->credits_lock); |
| 223 | rc = conn->ops->set_rsp_credits(work); |
| 224 | spin_unlock(lock: &conn->credits_lock); |
| 225 | if (rc < 0) { |
| 226 | conn->ops->set_rsp_status(work, |
| 227 | STATUS_INVALID_PARAMETER); |
| 228 | goto send; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | is_chained = is_chained_smb2_message(work); |
| 233 | |
| 234 | if (work->sess && |
| 235 | (work->sess->sign || smb3_11_final_sess_setup_resp(work) || |
| 236 | conn->ops->is_sign_req(work, command))) |
| 237 | conn->ops->set_sign_rsp(work); |
| 238 | } while (is_chained == true); |
| 239 | |
| 240 | send: |
| 241 | if (work->tcon) |
| 242 | ksmbd_tree_connect_put(tcon: work->tcon); |
| 243 | smb3_preauth_hash_rsp(work); |
| 244 | if (work->sess && work->sess->enc && work->encrypted && |
| 245 | conn->ops->encrypt_resp) { |
| 246 | rc = conn->ops->encrypt_resp(work); |
| 247 | if (rc < 0) |
| 248 | conn->ops->set_rsp_status(work, STATUS_DATA_ERROR); |
| 249 | } |
| 250 | if (work->sess) |
| 251 | ksmbd_user_session_put(sess: work->sess); |
| 252 | |
| 253 | ksmbd_conn_write(work); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * handle_ksmbd_work() - process pending smb work requests |
| 258 | * @wk: smb work containing request command buffer |
| 259 | * |
| 260 | * called by kworker threads to processing remaining smb work requests |
| 261 | */ |
| 262 | static void handle_ksmbd_work(struct work_struct *wk) |
| 263 | { |
| 264 | struct ksmbd_work *work = container_of(wk, struct ksmbd_work, work); |
| 265 | struct ksmbd_conn *conn = work->conn; |
| 266 | |
| 267 | atomic64_inc(v: &conn->stats.request_served); |
| 268 | |
| 269 | __handle_ksmbd_work(work, conn); |
| 270 | |
| 271 | ksmbd_conn_try_dequeue_request(work); |
| 272 | ksmbd_free_work_struct(work); |
| 273 | ksmbd_conn_r_count_dec(conn); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * queue_ksmbd_work() - queue a smb request to worker thread queue |
| 278 | * for processing smb command and sending response |
| 279 | * @conn: connection instance |
| 280 | * |
| 281 | * read remaining data from socket create and submit work. |
| 282 | */ |
| 283 | static int queue_ksmbd_work(struct ksmbd_conn *conn) |
| 284 | { |
| 285 | struct ksmbd_work *work; |
| 286 | int err; |
| 287 | |
| 288 | err = ksmbd_init_smb_server(conn); |
| 289 | if (err) |
| 290 | return 0; |
| 291 | |
| 292 | work = ksmbd_alloc_work_struct(); |
| 293 | if (!work) { |
| 294 | pr_err("allocation for work failed\n" ); |
| 295 | return -ENOMEM; |
| 296 | } |
| 297 | |
| 298 | work->conn = conn; |
| 299 | work->request_buf = conn->request_buf; |
| 300 | conn->request_buf = NULL; |
| 301 | |
| 302 | ksmbd_conn_enqueue_request(work); |
| 303 | ksmbd_conn_r_count_inc(conn); |
| 304 | /* update activity on connection */ |
| 305 | conn->last_active = jiffies; |
| 306 | INIT_WORK(&work->work, handle_ksmbd_work); |
| 307 | ksmbd_queue_work(work); |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int ksmbd_server_process_request(struct ksmbd_conn *conn) |
| 312 | { |
| 313 | return queue_ksmbd_work(conn); |
| 314 | } |
| 315 | |
| 316 | static int ksmbd_server_terminate_conn(struct ksmbd_conn *conn) |
| 317 | { |
| 318 | ksmbd_sessions_deregister(conn); |
| 319 | destroy_lease_table(conn); |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static void ksmbd_server_tcp_callbacks_init(void) |
| 324 | { |
| 325 | struct ksmbd_conn_ops ops; |
| 326 | |
| 327 | ops.process_fn = ksmbd_server_process_request; |
| 328 | ops.terminate_fn = ksmbd_server_terminate_conn; |
| 329 | |
| 330 | ksmbd_conn_init_server_callbacks(ops: &ops); |
| 331 | } |
| 332 | |
| 333 | static void server_conf_free(void) |
| 334 | { |
| 335 | int i; |
| 336 | |
| 337 | for (i = 0; i < ARRAY_SIZE(server_conf.conf); i++) { |
| 338 | kfree(objp: server_conf.conf[i]); |
| 339 | server_conf.conf[i] = NULL; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | static int server_conf_init(void) |
| 344 | { |
| 345 | WRITE_ONCE(server_conf.state, SERVER_STATE_STARTING_UP); |
| 346 | server_conf.enforced_signing = 0; |
| 347 | server_conf.min_protocol = ksmbd_min_protocol(); |
| 348 | server_conf.max_protocol = ksmbd_max_protocol(); |
| 349 | server_conf.auth_mechs = KSMBD_AUTH_NTLMSSP; |
| 350 | #ifdef CONFIG_SMB_SERVER_KERBEROS5 |
| 351 | server_conf.auth_mechs |= KSMBD_AUTH_KRB5 | |
| 352 | KSMBD_AUTH_MSKRB5; |
| 353 | #endif |
| 354 | server_conf.max_inflight_req = SMB2_MAX_CREDITS; |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static void server_ctrl_handle_init(struct server_ctrl_struct *ctrl) |
| 359 | { |
| 360 | int ret; |
| 361 | |
| 362 | ret = ksmbd_conn_transport_init(); |
| 363 | if (ret) { |
| 364 | server_queue_ctrl_reset_work(); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | pr_info("running\n" ); |
| 369 | WRITE_ONCE(server_conf.state, SERVER_STATE_RUNNING); |
| 370 | } |
| 371 | |
| 372 | static void server_ctrl_handle_reset(struct server_ctrl_struct *ctrl) |
| 373 | { |
| 374 | ksmbd_ipc_soft_reset(); |
| 375 | ksmbd_conn_transport_destroy(); |
| 376 | ksmbd_stop_durable_scavenger(); |
| 377 | server_conf_free(); |
| 378 | server_conf_init(); |
| 379 | WRITE_ONCE(server_conf.state, SERVER_STATE_STARTING_UP); |
| 380 | } |
| 381 | |
| 382 | static void server_ctrl_handle_work(struct work_struct *work) |
| 383 | { |
| 384 | struct server_ctrl_struct *ctrl; |
| 385 | |
| 386 | ctrl = container_of(work, struct server_ctrl_struct, ctrl_work); |
| 387 | |
| 388 | mutex_lock(&ctrl_lock); |
| 389 | switch (ctrl->type) { |
| 390 | case SERVER_CTRL_TYPE_INIT: |
| 391 | server_ctrl_handle_init(ctrl); |
| 392 | break; |
| 393 | case SERVER_CTRL_TYPE_RESET: |
| 394 | server_ctrl_handle_reset(ctrl); |
| 395 | break; |
| 396 | default: |
| 397 | pr_err("Unknown server work type: %d\n" , ctrl->type); |
| 398 | } |
| 399 | mutex_unlock(lock: &ctrl_lock); |
| 400 | kfree(objp: ctrl); |
| 401 | module_put(THIS_MODULE); |
| 402 | } |
| 403 | |
| 404 | static int __queue_ctrl_work(int type) |
| 405 | { |
| 406 | struct server_ctrl_struct *ctrl; |
| 407 | |
| 408 | ctrl = kmalloc(sizeof(struct server_ctrl_struct), KSMBD_DEFAULT_GFP); |
| 409 | if (!ctrl) |
| 410 | return -ENOMEM; |
| 411 | |
| 412 | __module_get(THIS_MODULE); |
| 413 | ctrl->type = type; |
| 414 | INIT_WORK(&ctrl->ctrl_work, server_ctrl_handle_work); |
| 415 | queue_work(wq: system_long_wq, work: &ctrl->ctrl_work); |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | int server_queue_ctrl_init_work(void) |
| 420 | { |
| 421 | return __queue_ctrl_work(type: SERVER_CTRL_TYPE_INIT); |
| 422 | } |
| 423 | |
| 424 | int server_queue_ctrl_reset_work(void) |
| 425 | { |
| 426 | return __queue_ctrl_work(type: SERVER_CTRL_TYPE_RESET); |
| 427 | } |
| 428 | |
| 429 | static ssize_t stats_show(const struct class *class, const struct class_attribute *attr, |
| 430 | char *buf) |
| 431 | { |
| 432 | /* |
| 433 | * Inc this each time you change stats output format, |
| 434 | * so user space will know what to do. |
| 435 | */ |
| 436 | static int stats_version = 2; |
| 437 | static const char * const state[] = { |
| 438 | "startup" , |
| 439 | "running" , |
| 440 | "reset" , |
| 441 | "shutdown" |
| 442 | }; |
| 443 | return sysfs_emit(buf, fmt: "%d %s %d %lu\n" , stats_version, |
| 444 | state[server_conf.state], server_conf.tcp_port, |
| 445 | server_conf.ipc_last_active / HZ); |
| 446 | } |
| 447 | |
| 448 | static ssize_t kill_server_store(const struct class *class, |
| 449 | const struct class_attribute *attr, const char *buf, |
| 450 | size_t len) |
| 451 | { |
| 452 | if (!sysfs_streq(s1: buf, s2: "hard" )) |
| 453 | return len; |
| 454 | |
| 455 | pr_info("kill command received\n" ); |
| 456 | mutex_lock(&ctrl_lock); |
| 457 | WRITE_ONCE(server_conf.state, SERVER_STATE_RESETTING); |
| 458 | __module_get(THIS_MODULE); |
| 459 | server_ctrl_handle_reset(NULL); |
| 460 | module_put(THIS_MODULE); |
| 461 | mutex_unlock(lock: &ctrl_lock); |
| 462 | return len; |
| 463 | } |
| 464 | |
| 465 | static const char * const debug_type_strings[] = {"smb" , "auth" , "vfs" , |
| 466 | "oplock" , "ipc" , "conn" , |
| 467 | "rdma" }; |
| 468 | |
| 469 | static ssize_t debug_show(const struct class *class, const struct class_attribute *attr, |
| 470 | char *buf) |
| 471 | { |
| 472 | ssize_t sz = 0; |
| 473 | int i, pos = 0; |
| 474 | |
| 475 | for (i = 0; i < ARRAY_SIZE(debug_type_strings); i++) { |
| 476 | if ((ksmbd_debug_types >> i) & 1) { |
| 477 | pos = sysfs_emit_at(buf, at: sz, fmt: "[%s] " , debug_type_strings[i]); |
| 478 | } else { |
| 479 | pos = sysfs_emit_at(buf, at: sz, fmt: "%s " , debug_type_strings[i]); |
| 480 | } |
| 481 | sz += pos; |
| 482 | } |
| 483 | sz += sysfs_emit_at(buf, at: sz, fmt: "\n" ); |
| 484 | return sz; |
| 485 | } |
| 486 | |
| 487 | static ssize_t debug_store(const struct class *class, const struct class_attribute *attr, |
| 488 | const char *buf, size_t len) |
| 489 | { |
| 490 | int i; |
| 491 | |
| 492 | for (i = 0; i < ARRAY_SIZE(debug_type_strings); i++) { |
| 493 | if (sysfs_streq(s1: buf, s2: "all" )) { |
| 494 | if (ksmbd_debug_types == KSMBD_DEBUG_ALL) |
| 495 | ksmbd_debug_types = 0; |
| 496 | else |
| 497 | ksmbd_debug_types = KSMBD_DEBUG_ALL; |
| 498 | break; |
| 499 | } |
| 500 | |
| 501 | if (sysfs_streq(s1: buf, s2: debug_type_strings[i])) { |
| 502 | if (ksmbd_debug_types & (1 << i)) |
| 503 | ksmbd_debug_types &= ~(1 << i); |
| 504 | else |
| 505 | ksmbd_debug_types |= (1 << i); |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | return len; |
| 511 | } |
| 512 | |
| 513 | static CLASS_ATTR_RO(stats); |
| 514 | static CLASS_ATTR_WO(kill_server); |
| 515 | static CLASS_ATTR_RW(debug); |
| 516 | |
| 517 | static struct attribute *ksmbd_control_class_attrs[] = { |
| 518 | &class_attr_stats.attr, |
| 519 | &class_attr_kill_server.attr, |
| 520 | &class_attr_debug.attr, |
| 521 | NULL, |
| 522 | }; |
| 523 | ATTRIBUTE_GROUPS(ksmbd_control_class); |
| 524 | |
| 525 | static struct class ksmbd_control_class = { |
| 526 | .name = "ksmbd-control" , |
| 527 | .class_groups = ksmbd_control_class_groups, |
| 528 | }; |
| 529 | |
| 530 | static int ksmbd_server_shutdown(void) |
| 531 | { |
| 532 | WRITE_ONCE(server_conf.state, SERVER_STATE_SHUTTING_DOWN); |
| 533 | |
| 534 | class_unregister(class: &ksmbd_control_class); |
| 535 | ksmbd_workqueue_destroy(); |
| 536 | ksmbd_ipc_release(); |
| 537 | ksmbd_conn_transport_destroy(); |
| 538 | ksmbd_crypto_destroy(); |
| 539 | ksmbd_free_global_file_table(); |
| 540 | destroy_lease_table(NULL); |
| 541 | ksmbd_work_pool_destroy(); |
| 542 | ksmbd_exit_file_cache(); |
| 543 | server_conf_free(); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | static int __init ksmbd_server_init(void) |
| 548 | { |
| 549 | int ret; |
| 550 | |
| 551 | ret = class_register(class: &ksmbd_control_class); |
| 552 | if (ret) { |
| 553 | pr_err("Unable to register ksmbd-control class\n" ); |
| 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | ksmbd_server_tcp_callbacks_init(); |
| 558 | |
| 559 | ret = server_conf_init(); |
| 560 | if (ret) |
| 561 | goto err_unregister; |
| 562 | |
| 563 | ret = ksmbd_work_pool_init(); |
| 564 | if (ret) |
| 565 | goto err_unregister; |
| 566 | |
| 567 | ret = ksmbd_init_file_cache(); |
| 568 | if (ret) |
| 569 | goto err_destroy_work_pools; |
| 570 | |
| 571 | ret = ksmbd_ipc_init(); |
| 572 | if (ret) |
| 573 | goto err_exit_file_cache; |
| 574 | |
| 575 | ret = ksmbd_init_global_file_table(); |
| 576 | if (ret) |
| 577 | goto err_ipc_release; |
| 578 | |
| 579 | ret = ksmbd_inode_hash_init(); |
| 580 | if (ret) |
| 581 | goto err_destroy_file_table; |
| 582 | |
| 583 | ret = ksmbd_crypto_create(); |
| 584 | if (ret) |
| 585 | goto err_release_inode_hash; |
| 586 | |
| 587 | ret = ksmbd_workqueue_init(); |
| 588 | if (ret) |
| 589 | goto err_crypto_destroy; |
| 590 | |
| 591 | return 0; |
| 592 | |
| 593 | err_crypto_destroy: |
| 594 | ksmbd_crypto_destroy(); |
| 595 | err_release_inode_hash: |
| 596 | ksmbd_release_inode_hash(); |
| 597 | err_destroy_file_table: |
| 598 | ksmbd_free_global_file_table(); |
| 599 | err_ipc_release: |
| 600 | ksmbd_ipc_release(); |
| 601 | err_exit_file_cache: |
| 602 | ksmbd_exit_file_cache(); |
| 603 | err_destroy_work_pools: |
| 604 | ksmbd_work_pool_destroy(); |
| 605 | err_unregister: |
| 606 | class_unregister(class: &ksmbd_control_class); |
| 607 | |
| 608 | return ret; |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * ksmbd_server_exit() - shutdown forker thread and free memory at module exit |
| 613 | */ |
| 614 | static void __exit ksmbd_server_exit(void) |
| 615 | { |
| 616 | ksmbd_server_shutdown(); |
| 617 | rcu_barrier(); |
| 618 | ksmbd_release_inode_hash(); |
| 619 | } |
| 620 | |
| 621 | MODULE_AUTHOR("Namjae Jeon <linkinjeon@kernel.org>" ); |
| 622 | MODULE_DESCRIPTION("Linux kernel CIFS/SMB SERVER" ); |
| 623 | MODULE_LICENSE("GPL" ); |
| 624 | MODULE_SOFTDEP("pre: ecb" ); |
| 625 | MODULE_SOFTDEP("pre: nls" ); |
| 626 | MODULE_SOFTDEP("pre: aes" ); |
| 627 | MODULE_SOFTDEP("pre: cmac" ); |
| 628 | MODULE_SOFTDEP("pre: aead2" ); |
| 629 | MODULE_SOFTDEP("pre: ccm" ); |
| 630 | MODULE_SOFTDEP("pre: gcm" ); |
| 631 | module_init(ksmbd_server_init) |
| 632 | module_exit(ksmbd_server_exit) |
| 633 | |