xref: /linux/fs/smb/server/ksmbd_work.h (revision 84b9b44b)
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 /* one of these for every pending CIFS request at the connection */
23 struct ksmbd_work {
24 	/* Server corresponding to this mid */
25 	struct ksmbd_conn               *conn;
26 	struct ksmbd_session            *sess;
27 	struct ksmbd_tree_connect       *tcon;
28 
29 	/* Pointer to received SMB header */
30 	void                            *request_buf;
31 	/* Response buffer */
32 	void                            *response_buf;
33 
34 	/* Read data buffer */
35 	void                            *aux_payload_buf;
36 
37 	/* Next cmd hdr in compound req buf*/
38 	int                             next_smb2_rcv_hdr_off;
39 	/* Next cmd hdr in compound rsp buf*/
40 	int                             next_smb2_rsp_hdr_off;
41 
42 	/*
43 	 * Current Local FID assigned compound response if SMB2 CREATE
44 	 * command is present in compound request
45 	 */
46 	u64				compound_fid;
47 	u64				compound_pfid;
48 	u64				compound_sid;
49 
50 	const struct cred		*saved_cred;
51 
52 	/* Number of granted credits */
53 	unsigned int			credits_granted;
54 
55 	/* response smb header size */
56 	unsigned int                    resp_hdr_sz;
57 	unsigned int                    response_sz;
58 	/* Read data count */
59 	unsigned int                    aux_payload_sz;
60 
61 	void				*tr_buf;
62 
63 	unsigned char			state;
64 	/* Multiple responses for one request e.g. SMB ECHO */
65 	bool                            multiRsp:1;
66 	/* No response for cancelled request */
67 	bool                            send_no_response:1;
68 	/* Request is encrypted */
69 	bool                            encrypted:1;
70 	/* Is this SYNC or ASYNC ksmbd_work */
71 	bool                            asynchronous:1;
72 	bool                            need_invalidate_rkey:1;
73 
74 	unsigned int                    remote_key;
75 	/* cancel works */
76 	int                             async_id;
77 	void                            **cancel_argv;
78 	void                            (*cancel_fn)(void **argv);
79 
80 	struct work_struct              work;
81 	/* List head at conn->requests */
82 	struct list_head                request_entry;
83 	/* List head at conn->async_requests */
84 	struct list_head                async_request_entry;
85 	struct list_head                fp_entry;
86 	struct list_head                interim_entry;
87 };
88 
89 /**
90  * ksmbd_resp_buf_next - Get next buffer on compound response.
91  * @work: smb work containing response buffer
92  */
93 static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
94 {
95 	return work->response_buf + work->next_smb2_rsp_hdr_off + 4;
96 }
97 
98 /**
99  * ksmbd_req_buf_next - Get next buffer on compound request.
100  * @work: smb work containing response buffer
101  */
102 static inline void *ksmbd_req_buf_next(struct ksmbd_work *work)
103 {
104 	return work->request_buf + work->next_smb2_rcv_hdr_off + 4;
105 }
106 
107 struct ksmbd_work *ksmbd_alloc_work_struct(void);
108 void ksmbd_free_work_struct(struct ksmbd_work *work);
109 
110 void ksmbd_work_pool_destroy(void);
111 int ksmbd_work_pool_init(void);
112 
113 int ksmbd_workqueue_init(void);
114 void ksmbd_workqueue_destroy(void);
115 bool ksmbd_queue_work(struct ksmbd_work *work);
116 
117 #endif /* __KSMBD_WORK_H__ */
118