1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
6 #include <linux/list.h>
7 #include <linux/slab.h>
8 #include <linux/xarray.h>
10 #include "../transport_ipc.h"
11 #include "../connection.h"
13 #include "tree_connect.h"
14 #include "user_config.h"
15 #include "share_config.h"
16 #include "user_session.h"
18 struct ksmbd_tree_conn_status
19 ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
22 struct ksmbd_tree_conn_status status = {-EINVAL, NULL};
23 struct ksmbd_tree_connect_response *resp = NULL;
24 struct ksmbd_share_config *sc;
25 struct ksmbd_tree_connect *tree_conn = NULL;
26 struct sockaddr *peer_addr;
29 sc = ksmbd_share_config_get(share_name);
33 tree_conn = kzalloc(sizeof(struct ksmbd_tree_connect), GFP_KERNEL);
39 tree_conn->id = ksmbd_acquire_tree_conn_id(sess);
40 if (tree_conn->id < 0) {
45 peer_addr = KSMBD_TCP_PEER_SOCKADDR(conn);
46 resp = ksmbd_ipc_tree_connect_request(sess,
55 status.ret = resp->status;
56 if (status.ret != KSMBD_TREE_CONN_STATUS_OK)
59 tree_conn->flags = resp->connection_flags;
60 tree_conn->user = sess->user;
61 tree_conn->share_conf = sc;
62 status.tree_conn = tree_conn;
64 ret = xa_err(xa_store(&sess->tree_conns, tree_conn->id, tree_conn,
75 ksmbd_release_tree_conn_id(sess, tree_conn->id);
76 ksmbd_share_config_put(sc);
82 int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
83 struct ksmbd_tree_connect *tree_conn)
87 ret = ksmbd_ipc_tree_disconnect_request(sess->id, tree_conn->id);
88 ksmbd_release_tree_conn_id(sess, tree_conn->id);
89 xa_erase(&sess->tree_conns, tree_conn->id);
90 ksmbd_share_config_put(tree_conn->share_conf);
95 struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess,
98 return xa_load(&sess->tree_conns, id);
101 struct ksmbd_share_config *ksmbd_tree_conn_share(struct ksmbd_session *sess,
104 struct ksmbd_tree_connect *tc;
106 tc = ksmbd_tree_conn_lookup(sess, id);
108 return tc->share_conf;
112 int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess)
115 struct ksmbd_tree_connect *tc;
118 xa_for_each(&sess->tree_conns, id, tc)
119 ret |= ksmbd_tree_conn_disconnect(sess, tc);
120 xa_destroy(&sess->tree_conns);