1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 #ifndef __KSMBD_OPLOCK_H
8 #define __KSMBD_OPLOCK_H
10 #include "smb_common.h"
12 #define OPLOCK_WAIT_TIME (35 * HZ)
14 /* SMB2 Oplock levels */
15 #define SMB2_OPLOCK_LEVEL_NONE 0x00
16 #define SMB2_OPLOCK_LEVEL_II 0x01
17 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
18 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
19 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
22 #define OPLOCK_STATE_NONE 0x00
23 #define OPLOCK_ACK_WAIT 0x01
24 #define OPLOCK_CLOSING 0x02
26 #define OPLOCK_WRITE_TO_READ 0x01
27 #define OPLOCK_READ_HANDLE_TO_READ 0x02
28 #define OPLOCK_WRITE_TO_NONE 0x04
29 #define OPLOCK_READ_TO_NONE 0x08
31 struct lease_ctx_info {
32 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
36 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
43 char client_guid[SMB2_CLIENT_GUID_SIZE];
44 struct list_head lease_list;
45 struct list_head l_entry;
50 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
55 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
59 struct lease_table *l_lb;
63 struct ksmbd_conn *conn;
64 struct ksmbd_session *sess;
65 struct ksmbd_work *work;
66 struct ksmbd_file *o_fp;
69 unsigned long pending_break;
71 atomic_t breaking_cnt;
75 bool open_trunc; /* truncate on open */
76 struct lease *o_lease;
77 struct list_head interim_list;
78 struct list_head op_entry;
79 struct list_head lease_entry;
80 wait_queue_head_t oplock_q; /* Other server threads */
81 wait_queue_head_t oplock_brk; /* oplock breaking wait */
82 struct rcu_head rcu_head;
85 struct lease_break_info {
89 char lease_key[SMB2_LEASE_KEY_SIZE];
92 struct oplock_break_info {
98 int smb_grant_oplock(struct ksmbd_work *work, int req_op_level,
99 u64 pid, struct ksmbd_file *fp, __u16 tid,
100 struct lease_ctx_info *lctx, int share_ret);
101 void smb_break_all_levII_oplock(struct ksmbd_work *work,
102 struct ksmbd_file *fp, int is_trunc);
103 int opinfo_write_to_read(struct oplock_info *opinfo);
104 int opinfo_read_handle_to_read(struct oplock_info *opinfo);
105 int opinfo_write_to_none(struct oplock_info *opinfo);
106 int opinfo_read_to_none(struct oplock_info *opinfo);
107 void close_id_del_oplock(struct ksmbd_file *fp);
108 void smb_break_all_oplock(struct ksmbd_work *work, struct ksmbd_file *fp);
109 struct oplock_info *opinfo_get(struct ksmbd_file *fp);
110 void opinfo_put(struct oplock_info *opinfo);
112 /* Lease related functions */
113 void create_lease_buf(u8 *rbuf, struct lease *lease);
114 struct lease_ctx_info *parse_lease_state(void *open_req, bool is_dir);
115 __u8 smb2_map_lease_to_oplock(__le32 lease_state);
116 int lease_read_to_write(struct oplock_info *opinfo);
118 /* Durable related functions */
119 void create_durable_rsp_buf(char *cc);
120 void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp);
121 void create_mxac_rsp_buf(char *cc, int maximal_access);
122 void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id);
123 void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp);
124 struct create_context *smb2_find_context_vals(void *open_req, const char *tag, int tag_len);
125 struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
127 int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
128 struct lease_ctx_info *lctx);
129 void destroy_lease_table(struct ksmbd_conn *conn);
130 void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
131 struct lease_ctx_info *lctx);
132 void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp);
133 #endif /* __KSMBD_OPLOCK_H */