xref: /linux/fs/smb/server/ksmbd_work.h (revision 318cd7461a7facb9cd5f7a5d1580fd874440e035)
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 	/* FileId generated or used by the previous operation in a compound. */
58 	u64				compound_fid;
59 	u64				compound_pfid;
60 	u64				compound_sid;
61 	__le32				compound_status;
62 
63 	const struct cred		*saved_cred;
64 
65 	/* Number of granted credits */
66 	unsigned int			credits_granted;
67 
68 	/*
69 	 * Credit charge added to conn->outstanding_credits at receive time
70 	 * for the SMB2 PDU currently being processed, pending release.  Zero
71 	 * once the charge has been returned (on the response or error path).
72 	 */
73 	unsigned short			credit_charge;
74 
75 	/* response smb header size */
76 	unsigned int                    response_sz;
77 
78 	void				*tr_buf;
79 	/* Contiguous SMB2 compression transform owned by this work item. */
80 	void				*compress_buf;
81 
82 	unsigned int			state;
83 	/* No response for cancelled request */
84 	bool                            send_no_response:1;
85 	/* Request is encrypted */
86 	bool                            encrypted:1;
87 	/* READ response should be wrapped in a compression transform. */
88 	bool                            compress_response:1;
89 	/* Is this SYNC or ASYNC ksmbd_work */
90 	bool                            asynchronous:1;
91 	bool                            need_invalidate_rkey:1;
92 	bool				request_open_chseq_tracked:1;
93 	/* The previous command carries a FileId or is a CREATE. */
94 	bool				compound_fid_present:1;
95 	/* A related command failed because there was no FileId to inherit. */
96 	bool				compound_fid_missing:1;
97 	bool				session_setup_reauth:1;
98 	/* Retain the binding decision for response signing and preauth hashing. */
99 	bool				session_setup_binding:1;
100 
101 	unsigned int                    remote_key;
102 	/* cancel works */
103 	int                             async_id;
104 	void                            **cancel_argv;
105 	void                            (*cancel_fn)(void **argv);
106 
107 	/*
108 	 * Refcounted open associated with the SMB2 command currently being
109 	 * processed.
110 	 */
111 	struct ksmbd_file		*request_open;
112 	__le16				request_open_chseq;
113 
114 	struct work_struct              work;
115 	/* List head at conn->requests */
116 	struct list_head                request_entry;
117 	/* List head at conn->async_requests */
118 	struct list_head                async_request_entry;
119 	/* List head at ksmbd_file->blocked_works */
120 	struct list_head                fp_entry;
121 };
122 
123 /**
124  * ksmbd_resp_buf_next - Get next buffer on compound response.
125  * @work: smb work containing response buffer
126  */
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  */
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  */
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 void ksmbd_queue_io_work(struct work_struct *work);
160 void ksmbd_queue_break_work(struct work_struct *work);
161 int ksmbd_iov_pin_rsp_read(struct ksmbd_work *work, void *ib, int len,
162 			   void *aux_buf, unsigned int aux_size);
163 int ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len);
164 int allocate_interim_rsp_buf(struct ksmbd_work *work);
165 #endif /* __KSMBD_WORK_H__ */
166