dm-crypt: use __bio_add_page to add single page to clone bio
[linux-block.git] / fs / ksmbd / connection.h
CommitLineData
0626e664
NJ
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
4 */
5
6#ifndef __KSMBD_CONNECTION_H__
7#define __KSMBD_CONNECTION_H__
8
9#include <linux/list.h>
10#include <linux/ip.h>
11#include <net/sock.h>
12#include <net/tcp.h>
13#include <net/inet_connection_sock.h>
14#include <net/request_sock.h>
15#include <linux/kthread.h>
16#include <linux/nls.h>
dbab80e2 17#include <linux/unicode.h>
0626e664
NJ
18
19#include "smb_common.h"
20#include "ksmbd_work.h"
21
22#define KSMBD_SOCKET_BACKLOG 16
23
0626e664
NJ
24enum {
25 KSMBD_SESS_NEW = 0,
26 KSMBD_SESS_GOOD,
27 KSMBD_SESS_EXITING,
28 KSMBD_SESS_NEED_RECONNECT,
abcc506a
NJ
29 KSMBD_SESS_NEED_NEGOTIATE,
30 KSMBD_SESS_RELEASING
0626e664
NJ
31};
32
33struct ksmbd_stats {
34 atomic_t open_files_count;
35 atomic64_t request_served;
36};
37
38struct ksmbd_transport;
39
40struct ksmbd_conn {
41 struct smb_version_values *vals;
42 struct smb_version_ops *ops;
43 struct smb_version_cmds *cmds;
44 unsigned int max_cmds;
45 struct mutex srv_mutex;
46 int status;
47 unsigned int cli_cap;
48 char *request_buf;
49 struct ksmbd_transport *transport;
50 struct nls_table *local_nls;
16b5f54e 51 struct unicode_map *um;
0626e664
NJ
52 struct list_head conns_list;
53 /* smb session 1 per user */
e4d3e6b5 54 struct xarray sessions;
0626e664
NJ
55 unsigned long last_active;
56 /* How many request are running currently */
57 atomic_t req_running;
58 /* References which are made for this Server object*/
59 atomic_t r_count;
b589f5db
NJ
60 unsigned int total_credits;
61 unsigned int outstanding_credits;
0626e664
NJ
62 spinlock_t credits_lock;
63 wait_queue_head_t req_running_q;
a14c5738 64 wait_queue_head_t r_count_q;
0626e664
NJ
65 /* Lock to protect requests list*/
66 spinlock_t request_lock;
67 struct list_head requests;
68 struct list_head async_requests;
69 int connection_type;
70 struct ksmbd_stats stats;
71 char ClientGUID[SMB2_CLIENT_GUID_SIZE];
ce53d365 72 struct ntlmssp_auth ntlmssp;
0626e664 73
d63528eb
HL
74 spinlock_t llist_lock;
75 struct list_head lock_list;
76
0626e664
NJ
77 struct preauth_integrity_info *preauth_info;
78
79 bool need_neg;
80 unsigned int auth_mechs;
81 unsigned int preferred_auth_mech;
82 bool sign;
83 bool use_spnego:1;
84 __u16 cli_sec_mode;
85 __u16 srv_sec_mode;
86 /* dialect index that server chose */
87 __u16 dialect;
88
89 char *mechToken;
90
91 struct ksmbd_conn_ops *conn_ops;
92
93 /* Preauth Session Table */
94 struct list_head preauth_sess_table;
95
96 struct sockaddr_storage peer_addr;
97
98 /* Identifier for async message */
d40012a8 99 struct ida async_ida;
0626e664
NJ
100
101 __le16 cipher_type;
102 __le16 compress_algorithm;
103 bool posix_ext_supported;
378087cd
NJ
104 bool signing_negotiated;
105 __le16 signing_algorithm;
f5a544e3 106 bool binding;
0626e664
NJ
107};
108
109struct ksmbd_conn_ops {
110 int (*process_fn)(struct ksmbd_conn *conn);
111 int (*terminate_fn)(struct ksmbd_conn *conn);
112};
113
114struct ksmbd_transport_ops {
115 int (*prepare)(struct ksmbd_transport *t);
116 void (*disconnect)(struct ksmbd_transport *t);
136dff3a 117 void (*shutdown)(struct ksmbd_transport *t);
be6f42fa
NJ
118 int (*read)(struct ksmbd_transport *t, char *buf,
119 unsigned int size, int max_retries);
64b39f4a 120 int (*writev)(struct ksmbd_transport *t, struct kvec *iovs, int niov,
070fb21e
NJ
121 int size, bool need_invalidate_rkey,
122 unsigned int remote_key);
1807abcf
HL
123 int (*rdma_read)(struct ksmbd_transport *t,
124 void *buf, unsigned int len,
125 struct smb2_buffer_desc_v1 *desc,
126 unsigned int desc_len);
127 int (*rdma_write)(struct ksmbd_transport *t,
128 void *buf, unsigned int len,
129 struct smb2_buffer_desc_v1 *desc,
130 unsigned int desc_len);
0626e664
NJ
131};
132
133struct ksmbd_transport {
134 struct ksmbd_conn *conn;
135 struct ksmbd_transport_ops *ops;
136 struct task_struct *handler;
137};
138
139#define KSMBD_TCP_RECV_TIMEOUT (7 * HZ)
140#define KSMBD_TCP_SEND_TIMEOUT (5 * HZ)
141#define KSMBD_TCP_PEER_SOCKADDR(c) ((struct sockaddr *)&((c)->peer_addr))
142
d63528eb 143extern struct list_head conn_list;
abcc506a 144extern struct rw_semaphore conn_list_lock;
d63528eb 145
0626e664 146bool ksmbd_conn_alive(struct ksmbd_conn *conn);
abcc506a 147void ksmbd_conn_wait_idle(struct ksmbd_conn *conn, u64 sess_id);
0626e664
NJ
148struct ksmbd_conn *ksmbd_conn_alloc(void);
149void ksmbd_conn_free(struct ksmbd_conn *conn);
150bool ksmbd_conn_lookup_dialect(struct ksmbd_conn *c);
151int ksmbd_conn_write(struct ksmbd_work *work);
1807abcf
HL
152int ksmbd_conn_rdma_read(struct ksmbd_conn *conn,
153 void *buf, unsigned int buflen,
154 struct smb2_buffer_desc_v1 *desc,
155 unsigned int desc_len);
156int ksmbd_conn_rdma_write(struct ksmbd_conn *conn,
157 void *buf, unsigned int buflen,
158 struct smb2_buffer_desc_v1 *desc,
159 unsigned int desc_len);
0626e664
NJ
160void ksmbd_conn_enqueue_request(struct ksmbd_work *work);
161int ksmbd_conn_try_dequeue_request(struct ksmbd_work *work);
162void ksmbd_conn_init_server_callbacks(struct ksmbd_conn_ops *ops);
0626e664 163int ksmbd_conn_handler_loop(void *p);
0626e664
NJ
164int ksmbd_conn_transport_init(void);
165void ksmbd_conn_transport_destroy(void);
f5c779b7
NJ
166void ksmbd_conn_lock(struct ksmbd_conn *conn);
167void ksmbd_conn_unlock(struct ksmbd_conn *conn);
0626e664
NJ
168
169/*
170 * WARNING
171 *
172 * This is a hack. We will move status to a proper place once we land
173 * a multi-sessions support.
174 */
f5c779b7 175static inline bool ksmbd_conn_good(struct ksmbd_conn *conn)
0626e664 176{
f5c779b7 177 return READ_ONCE(conn->status) == KSMBD_SESS_GOOD;
0626e664
NJ
178}
179
f5c779b7 180static inline bool ksmbd_conn_need_negotiate(struct ksmbd_conn *conn)
0626e664 181{
f5c779b7 182 return READ_ONCE(conn->status) == KSMBD_SESS_NEED_NEGOTIATE;
0626e664
NJ
183}
184
f5c779b7 185static inline bool ksmbd_conn_need_reconnect(struct ksmbd_conn *conn)
0626e664 186{
f5c779b7 187 return READ_ONCE(conn->status) == KSMBD_SESS_NEED_RECONNECT;
0626e664
NJ
188}
189
f5c779b7 190static inline bool ksmbd_conn_exiting(struct ksmbd_conn *conn)
0626e664 191{
f5c779b7 192 return READ_ONCE(conn->status) == KSMBD_SESS_EXITING;
0626e664
NJ
193}
194
abcc506a
NJ
195static inline bool ksmbd_conn_releasing(struct ksmbd_conn *conn)
196{
197 return READ_ONCE(conn->status) == KSMBD_SESS_RELEASING;
198}
199
f5c779b7 200static inline void ksmbd_conn_set_new(struct ksmbd_conn *conn)
0626e664 201{
f5c779b7 202 WRITE_ONCE(conn->status, KSMBD_SESS_NEW);
0626e664
NJ
203}
204
f5c779b7 205static inline void ksmbd_conn_set_good(struct ksmbd_conn *conn)
0626e664 206{
f5c779b7 207 WRITE_ONCE(conn->status, KSMBD_SESS_GOOD);
0626e664
NJ
208}
209
f5c779b7 210static inline void ksmbd_conn_set_need_negotiate(struct ksmbd_conn *conn)
0626e664 211{
f5c779b7 212 WRITE_ONCE(conn->status, KSMBD_SESS_NEED_NEGOTIATE);
0626e664
NJ
213}
214
f5c779b7 215static inline void ksmbd_conn_set_need_reconnect(struct ksmbd_conn *conn)
0626e664 216{
f5c779b7
NJ
217 WRITE_ONCE(conn->status, KSMBD_SESS_NEED_RECONNECT);
218}
219
220static inline void ksmbd_conn_set_exiting(struct ksmbd_conn *conn)
221{
222 WRITE_ONCE(conn->status, KSMBD_SESS_EXITING);
0626e664 223}
abcc506a
NJ
224
225static inline void ksmbd_conn_set_releasing(struct ksmbd_conn *conn)
226{
227 WRITE_ONCE(conn->status, KSMBD_SESS_RELEASING);
228}
229
230void ksmbd_all_conn_set_status(u64 sess_id, u32 status);
0626e664 231#endif /* __CONNECTION_H__ */