Merge tag 'rcu-fixes-v6.7' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[linux-block.git] / fs / smb / server / oplock.h
CommitLineData
e2f34481
NJ
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
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
64b39f4a 12#define OPLOCK_WAIT_TIME (35 * HZ)
e2f34481 13
e2f34481
NJ
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
20
21/* Oplock states */
22#define OPLOCK_STATE_NONE 0x00
23#define OPLOCK_ACK_WAIT 0x01
24#define OPLOCK_CLOSING 0x02
25
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
30
e2f34481 31struct lease_ctx_info {
ade62d8b
NJ
32 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
33 __le32 req_state;
34 __le32 flags;
35 __le64 duration;
36 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
37 int version;
e2f34481
NJ
38};
39
40struct lease_table {
41 char client_guid[SMB2_CLIENT_GUID_SIZE];
42 struct list_head lease_list;
43 struct list_head l_entry;
44 spinlock_t lb_lock;
45};
46
47struct lease {
48 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
49 __le32 state;
50 __le32 new_state;
51 __le32 flags;
52 __le64 duration;
ade62d8b
NJ
53 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
54 int version;
55 unsigned short epoch;
e2f34481
NJ
56 struct lease_table *l_lb;
57};
58
59struct oplock_info {
60 struct ksmbd_conn *conn;
61 struct ksmbd_session *sess;
62 struct ksmbd_work *work;
63 struct ksmbd_file *o_fp;
64 int level;
65 int op_state;
66 unsigned long pending_break;
64b39f4a 67 u64 fid;
e2f34481
NJ
68 atomic_t breaking_cnt;
69 atomic_t refcount;
70 __u16 Tid;
71 bool is_lease;
72 bool open_trunc; /* truncate on open */
73 struct lease *o_lease;
74 struct list_head interim_list;
75 struct list_head op_entry;
76 struct list_head lease_entry;
77 wait_queue_head_t oplock_q; /* Other server threads */
78 wait_queue_head_t oplock_brk; /* oplock breaking wait */
79 struct rcu_head rcu_head;
80};
81
82struct lease_break_info {
83 __le32 curr_state;
84 __le32 new_state;
ade62d8b 85 __le16 epoch;
e2f34481
NJ
86 char lease_key[SMB2_LEASE_KEY_SIZE];
87};
88
89struct oplock_break_info {
90 int level;
91 int open_trunc;
92 int fid;
93};
94
64b39f4a 95int smb_grant_oplock(struct ksmbd_work *work, int req_op_level,
070fb21e
NJ
96 u64 pid, struct ksmbd_file *fp, __u16 tid,
97 struct lease_ctx_info *lctx, int share_ret);
64b39f4a 98void smb_break_all_levII_oplock(struct ksmbd_work *work,
070fb21e 99 struct ksmbd_file *fp, int is_trunc);
e2f34481
NJ
100int opinfo_write_to_read(struct oplock_info *opinfo);
101int opinfo_read_handle_to_read(struct oplock_info *opinfo);
102int opinfo_write_to_none(struct oplock_info *opinfo);
103int opinfo_read_to_none(struct oplock_info *opinfo);
104void close_id_del_oplock(struct ksmbd_file *fp);
105void smb_break_all_oplock(struct ksmbd_work *work, struct ksmbd_file *fp);
106struct oplock_info *opinfo_get(struct ksmbd_file *fp);
107void opinfo_put(struct oplock_info *opinfo);
108
109/* Lease related functions */
110void create_lease_buf(u8 *rbuf, struct lease *lease);
111struct lease_ctx_info *parse_lease_state(void *open_req);
112__u8 smb2_map_lease_to_oplock(__le32 lease_state);
113int lease_read_to_write(struct oplock_info *opinfo);
114
115/* Durable related functions */
116void create_durable_rsp_buf(char *cc);
117void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp);
118void create_mxac_rsp_buf(char *cc, int maximal_access);
119void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id);
120void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp);
02f76c40 121struct create_context *smb2_find_context_vals(void *open_req, const char *tag, int tag_len);
e2f34481 122struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
070fb21e 123 char *lease_key);
e2f34481 124int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
070fb21e 125 struct lease_ctx_info *lctx);
e2f34481 126void destroy_lease_table(struct ksmbd_conn *conn);
e2f34481 127#endif /* __KSMBD_OPLOCK_H */