xref: /linux/fs/smb/server/ksmbd_work.h (revision 08f641e2e2e092cbda5ce7f7b5280e327e46823d)
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 
16 enum {
17 	KSMBD_WORK_ACTIVE = 0,
18 	KSMBD_WORK_CANCELLED,
19 	KSMBD_WORK_CLOSED,
20 };
21 
22 struct aux_read {
23 	void *buf;
24 	struct list_head entry;
25 };
26 
27 /* one of these for every pending CIFS request at the connection */
28 struct ksmbd_work {
29 	/* Server corresponding to this mid */
30 	struct ksmbd_conn               *conn;
31 	struct ksmbd_session            *sess;
32 	struct ksmbd_tree_connect       *tcon;
33 
34 	/* Pointer to received SMB header */
35 	void                            *request_buf;
36 	/* Response buffer */
37 	void                            *response_buf;
38 
39 	struct list_head		aux_read_list;
40 
41 	struct kvec			*iov;
42 	int				iov_alloc_cnt;
43 	int				iov_cnt;
44 	int				iov_idx;
45 
46 	/* Next cmd hdr in compound req buf*/
47 	int                             next_smb2_rcv_hdr_off;
48 	/* Next cmd hdr in compound rsp buf*/
49 	int                             next_smb2_rsp_hdr_off;
50 	/* Current cmd hdr in compound rsp buf*/
51 	int                             curr_smb2_rsp_hdr_off;
52 
53 	/*
54 	 * Current Local FID assigned compound response if SMB2 CREATE
55 	 * command is present in compound request
56 	 */
57 	u64				compound_fid;
58 	u64				compound_pfid;
59 	u64				compound_sid;
60 
61 	const struct cred		*saved_cred;
62 
63 	/* Number of granted credits */
64 	unsigned int			credits_granted;
65 
66 	/* response smb header size */
67 	unsigned int                    response_sz;
68 
69 	void				*tr_buf;
70 	/* Contiguous SMB2 compression transform owned by this work item. */
71 	void				*compress_buf;
72 
73 	unsigned char			state;
74 	/* No response for cancelled request */
75 	bool                            send_no_response:1;
76 	/* Request is encrypted */
77 	bool                            encrypted:1;
78 	/* READ response should be wrapped in a compression transform. */
79 	bool                            compress_response:1;
80 	/* Is this SYNC or ASYNC ksmbd_work */
81 	bool                            asynchronous:1;
82 	bool                            need_invalidate_rkey:1;
83 
84 	unsigned int                    remote_key;
85 	/* cancel works */
86 	int                             async_id;
87 	void                            **cancel_argv;
88 	void                            (*cancel_fn)(void **argv);
89 
90 	struct work_struct              work;
91 	/* List head at conn->requests */
92 	struct list_head                request_entry;
93 	/* List head at conn->async_requests */
94 	struct list_head                async_request_entry;
95 	struct list_head                fp_entry;
96 };
97 
98 /**
99  * ksmbd_resp_buf_next - Get next buffer on compound response.
100  * @work: smb work containing response buffer
101  */
102 static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
103 {
104 	return work->response_buf + work->next_smb2_rsp_hdr_off + 4;
105 }
106 
107 /**
108  * ksmbd_resp_buf_curr - Get current buffer on compound response.
109  * @work: smb work containing response buffer
110  */
111 static inline void *ksmbd_resp_buf_curr(struct ksmbd_work *work)
112 {
113 	return work->response_buf + work->curr_smb2_rsp_hdr_off + 4;
114 }
115 
116 /**
117  * ksmbd_req_buf_next - Get next buffer on compound request.
118  * @work: smb work containing response buffer
119  */
120 static inline void *ksmbd_req_buf_next(struct ksmbd_work *work)
121 {
122 	return work->request_buf + work->next_smb2_rcv_hdr_off + 4;
123 }
124 
125 struct ksmbd_work *ksmbd_alloc_work_struct(void);
126 void ksmbd_free_work_struct(struct ksmbd_work *work);
127 
128 void ksmbd_work_pool_destroy(void);
129 int ksmbd_work_pool_init(void);
130 
131 int ksmbd_workqueue_init(void);
132 void ksmbd_workqueue_destroy(void);
133 bool ksmbd_queue_work(struct ksmbd_work *work);
134 int ksmbd_iov_pin_rsp_read(struct ksmbd_work *work, void *ib, int len,
135 			   void *aux_buf, unsigned int aux_size);
136 int ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len);
137 int allocate_interim_rsp_buf(struct ksmbd_work *work);
138 #endif /* __KSMBD_WORK_H__ */
139