Debian Codegraph @

fs/smb/server/oplock.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) 2016 Namjae Jeon <[email protected]>
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
5 */
6
7 #ifndef __KSMBD_OPLOCK_H
8 #define __KSMBD_OPLOCK_H
9
10 #include "smb_common.h"
11
12 #define OPLOCK_WAIT_TIME (35 * HZ)
13
14 /* Oplock states */
15 #define OPLOCK_STATE_NONE 0x00
16 #define OPLOCK_ACK_WAIT 0x01
17 #define OPLOCK_CLOSING 0x02
18
19 #define OPLOCK_WRITE_TO_READ 0x01
20 #define OPLOCK_READ_HANDLE_TO_READ 0x02
21 #define OPLOCK_WRITE_TO_NONE 0x04
22 #define OPLOCK_READ_TO_NONE 0x08
23
24 struct lease_ctx_info {
25 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
26 __le32 req_state;
27 __le32 flags;
28 __le64 duration;
29 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
30 __le16 epoch;
31 int version;
32 bool is_dir;
33 };
34
35 struct lease_table {
36 char client_guid[SMB2_CLIENT_GUID_SIZE];
37 struct list_head lease_list;
38 struct list_head l_entry;
39 spinlock_t lb_lock;
40 };
41
42 struct lease {
43 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
44 __le32 state;
45 __le32 new_state;
46 __le32 flags;
47 __le64 duration;
48 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
49 int version;
50 unsigned short epoch;
51 bool is_dir;
52 struct lease_table *l_lb;
53 };
54
55 struct oplock_info {
56 struct ksmbd_conn *conn;
57 struct ksmbd_session *sess;
58 struct ksmbd_work *work;
59 struct ksmbd_file *o_fp;
60 int level;
61 int op_state;
62 unsigned long pending_break;
63 u64 fid;
64 atomic_t breaking_cnt;
65 atomic_t refcount;
66 __u16 Tid;
67 bool is_lease;
68 bool open_trunc; /* truncate on open */
69 struct lease *o_lease;
70 struct list_head op_entry;
71 struct list_head lease_entry;
72 wait_queue_head_t oplock_q; /* Other server threads */
73 wait_queue_head_t oplock_brk; /* oplock breaking wait */
74 struct rcu_head rcu;
75 };
76
77 struct lease_break_info {
78 __le32 curr_state;
79 __le32 new_state;
80 __le16 epoch;
81 char lease_key[SMB2_LEASE_KEY_SIZE];
82 };
83
84 struct oplock_break_info {
85 int level;
86 int open_trunc;
87 int fid;
88 };
89
90 int smb_grant_oplock(struct ksmbd_work *work, int req_op_level,
91 u64 pid, struct ksmbd_file *fp, __u16 tid,
92 struct lease_ctx_info *lctx, int share_ret);
93 void smb_break_all_levII_oplock(struct ksmbd_work *work,
94 struct ksmbd_file *fp, int is_trunc);
95 int opinfo_write_to_read(struct oplock_info *opinfo);
96 int opinfo_read_handle_to_read(struct oplock_info *opinfo);
97 int opinfo_write_to_none(struct oplock_info *opinfo);
98 int opinfo_read_to_none(struct oplock_info *opinfo);
99 void close_id_del_oplock(struct ksmbd_file *fp);
100 void smb_break_all_oplock(struct ksmbd_work *work, struct ksmbd_file *fp);
101 struct oplock_info *opinfo_get(struct ksmbd_file *fp);
102 void opinfo_put(struct oplock_info *opinfo);
103
104 /* Lease related functions */
105 void create_lease_buf(u8 *rbuf, struct lease *lease);
106 struct lease_ctx_info *parse_lease_state(void *open_req);
107 __u8 smb2_map_lease_to_oplock(__le32 lease_state);
108 int lease_read_to_write(struct oplock_info *opinfo);
109
110 /* Durable related functions */
111 void create_durable_rsp_buf(char *cc);
112 void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp);
113 void create_mxac_rsp_buf(char *cc, int maximal_access);
114 void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id);
115 void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp);
116 struct create_context *smb2_find_context_vals(void *open_req, const char *tag, int tag_len);
117 struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
118 char *lease_key);
119 int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
120 struct lease_ctx_info *lctx);
121 void destroy_lease_table(struct ksmbd_conn *conn);
122 void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
123 struct lease_ctx_info *lctx);
124 void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp);
125 int smb2_check_durable_oplock(struct ksmbd_conn *conn,
126 struct ksmbd_share_config *share,
127 struct ksmbd_file *fp,
128 struct lease_ctx_info *lctx,
129 struct ksmbd_user *user,
130 char *name);
131 #endif /* __KSMBD_OPLOCK_H */