xref: /linux/fs/smb/server/ksmbd_work.h (revision b49024d79fb7304f646003fcd8846ef26dea7e92)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   Copyright (C) 2019 Samsung Electronics Co., Ltd.
4  */
5 
6 #ifndef __KSMBD_WORK_H__
7 #define __KSMBD_WORK_H__
8 
9 #include <linux/ctype.h>
10 #include <linux/workqueue.h>
11 
12 struct ksmbd_conn;
13 struct ksmbd_session;
14 struct ksmbd_tree_connect;
15 struct ksmbd_file;
16 
17 #define KSMBD_WORK_INLINE_IOVS	4
18 
19 enum {
20 	KSMBD_WORK_ACTIVE = 0,
21 	KSMBD_WORK_CANCELLED,
22 	KSMBD_WORK_CLOSED,
23 };
24 
25 struct aux_read {
26 	void *buf;
27 	struct list_head entry;
28 };
29 
30 /* one of these for every pending CIFS request at the connection */
31 struct ksmbd_work {
32 	/* Server corresponding to this mid */
33 	struct ksmbd_conn               *conn;
34 	struct ksmbd_session            *sess;
35 	struct ksmbd_tree_connect       *tcon;
36 
37 	/* Pointer to received SMB header */
38 	void                            *request_buf;
39 	/* Response buffer */
40 	void                            *response_buf;
41 
42 	struct list_head		aux_read_list;
43 
44 	struct kvec			*iov;
45 	int				iov_alloc_cnt;
46 	int				iov_cnt;
47 	int				iov_idx;
48 	struct kvec			iov_inline[KSMBD_WORK_INLINE_IOVS];
49 
50 	/* Next cmd hdr in compound req buf*/
51 	int                             next_smb2_rcv_hdr_off;
52 	/* Next cmd hdr in compound rsp buf*/
53 	int                             next_smb2_rsp_hdr_off;
54 	/* Current cmd hdr in compound rsp buf*/
55 	int                             curr_smb2_rsp_hdr_off;
56 
57 	/*
58 	 * Current Local FID assigned compound response if SMB2 CREATE
59 	 * command is present in compound request
60 	 */
61 	u64				compound_fid;
62 	u64				compound_pfid;
63 	u64				compound_sid;
64 	__le32				compound_status;
65 
66 	const struct cred		*saved_cred;
67 
68 	/* Number of granted credits */
69 	unsigned int			credits_granted;
70 
71 	/*
72 	 * Credit charge added to conn->outstanding_credits at receive time
73 	 * for the SMB2 PDU currently being processed, pending release.  Zero
74 	 * once the charge has been returned (on the response or error path).
75 	 */
76 	unsigned short			credit_charge;
77 
78 	/* response smb header size */
79 	unsigned int                    response_sz;
80 
81 	void				*tr_buf;
82 	/* Contiguous SMB2 compression transform owned by this work item. */
83 	void				*compress_buf;
84 
85 	unsigned char			state;
86 	/* No response for cancelled request */
87 	bool                            send_no_response:1;
88 	/* Request is encrypted */
89 	bool                            encrypted:1;
90 	/* READ response should be wrapped in a compression transform. */
91 	bool                            compress_response:1;
92 	/* Is this SYNC or ASYNC ksmbd_work */
93 	bool                            asynchronous:1;
94 	/* Work owns a reference to @conn. */
95 	bool				owns_conn_ref:1;
96 	bool                            need_invalidate_rkey:1;
97 	bool				request_open_chseq_tracked:1;
98 	bool				session_setup_reauth:1;
99 
100 	unsigned int                    remote_key;
101 	/* cancel works */
102 	int                             async_id;
103 	void                            **cancel_argv;
104 	void                            (*cancel_fn)(void **argv);
105 
106 	/*
107 	 * Refcounted open associated with the SMB2 command currently being
108 	 * processed.
109 	 */
110 	struct ksmbd_file		*request_open;
111 	__le16				request_open_chseq;
112 
113 	struct work_struct              work;
114 	/* List head at conn->requests */
115 	struct list_head                request_entry;
116 	/* List head at conn->async_requests */
117 	struct list_head                async_request_entry;
118 	struct list_head                fp_entry;
119 	/* List head at ksmbd_file->notify_pendings */
120 	struct list_head                notify_entry;
121 };
122 
123 /**
124  * ksmbd_resp_buf_next - Get next buffer on compound response.
125  * @work: smb work containing response buffer
126  */
ksmbd_resp_buf_next(struct ksmbd_work * work)127 static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
128 {
129 	return work->response_buf + work->next_smb2_rsp_hdr_off + 4;
130 }
131 
132 /**
133  * ksmbd_resp_buf_curr - Get current buffer on compound response.
134  * @work: smb work containing response buffer
135  */
ksmbd_resp_buf_curr(struct ksmbd_work * work)136 static inline void *ksmbd_resp_buf_curr(struct ksmbd_work *work)
137 {
138 	return work->response_buf + work->curr_smb2_rsp_hdr_off + 4;
139 }
140 
141 /**
142  * ksmbd_req_buf_next - Get next buffer on compound request.
143  * @work: smb work containing response buffer
144  */
ksmbd_req_buf_next(struct ksmbd_work * work)145 static inline void *ksmbd_req_buf_next(struct ksmbd_work *work)
146 {
147 	return work->request_buf + work->next_smb2_rcv_hdr_off + 4;
148 }
149 
150 struct ksmbd_work *ksmbd_alloc_work_struct(void);
151 void ksmbd_free_work_struct(struct ksmbd_work *work);
152 
153 void ksmbd_work_pool_destroy(void);
154 int ksmbd_work_pool_init(void);
155 
156 int ksmbd_workqueue_init(void);
157 void ksmbd_workqueue_destroy(void);
158 bool ksmbd_queue_work(struct ksmbd_work *work);
159 int ksmbd_iov_pin_rsp_read(struct ksmbd_work *work, void *ib, int len,
160 			   void *aux_buf, unsigned int aux_size);
161 int ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len);
162 int allocate_interim_rsp_buf(struct ksmbd_work *work);
163 #endif /* __KSMBD_WORK_H__ */
164